Bus Error Debugging
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business bus error c++ Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs bus error linux Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just
Bus Error (core Dumped) Linux
like you, helping each other. Join them; it only takes a minute: Sign up What is a bus error? up vote 155 down vote favorite 49 What does the "bus error" message mean, and how does it
Bus Error (core Dumped) C
differ from a segfault? c unix segmentation-fault bus-error share|improve this question edited Oct 18 '15 at 10:44 Cool Guy 15.8k51952 asked Oct 17 '08 at 14:48 raldi 7,239216178 add a comment| 15 Answers 15 active oldest votes up vote 150 down vote accepted Bus errors are rare nowadays on x86 and occur when your processor cannot even attempt the memory access requested, typically: using a processor instruction with an address that does not satisfy its how to solve bus error in linux alignment requirements. Segmentation faults occur when accessing memory which does not belong to your process, they are very common and are typically the result of: using a pointer to something that was deallocated. using an uninitialized hence bogus pointer. using a null pointer. overflowing a buffer. PS: To be more precise this is not manipulating the pointer itself that will cause issues, it's accessing the memory it points to (dereferencing). share|improve this answer edited Oct 17 '08 at 15:18 answered Oct 17 '08 at 15:12 bltxd 5,70322336 52 They aren't rare; I'm just at Exercise 9 from How to Learn C the Hard Way and already encountered one... –11684 Mar 26 '13 at 20:12 5 Another cause of bus errors (on Linux anyway) is when the operating system can't back a virtual page with physical memory (e.g. low-memory conditions or out of huge pages when using huge page memory.) Typically mmap (and malloc) just reserve the virtual address space, and the kernel assigns the physical memory on demand (so called soft page faults.) Make a large enough malloc, and then write to enough of it and you'll get a bus error. –Eloff Jul 14 '15 at 0:09 add a comment| up vote 55 down vote A segfault is accessing memory that you're not allowed to access. It's read-only, you don'
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with
Bus Error Vs Segmentation Fault
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow bus error core dumped c++ Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Debugging bus error 10 mac SIGBUS on x86 Linux up vote 9 down vote favorite 2 What can cause SIGBUS (bus error) on a generic x86 userland application in Linux? All of the discussion I've been able to find online is regarding memory alignment errors, which from http://stackoverflow.com/questions/212466/what-is-a-bus-error what I understand doesn't really apply to x86. (My code is running on a Geode, in case there are any relevant processor-specific quirks there.) linux debugging bus-error sigbus share|improve this question asked Jan 18 '10 at 20:58 Josh Kelley 34.3k1273147 add a comment| 6 Answers 6 active oldest votes up vote 12 down vote accepted You can get a SIGBUS from an unaligned access if you turn on the unaligned access trap, but normally that's off on an x86. You can also get it http://stackoverflow.com/questions/2089167/debugging-sigbus-on-x86-linux from accessing a memory mapped device if there's an error of some kind. Your best bet is using a debugger to identify the faulting instruction (SIGBUS is synchronous), and trying to see what it was trying to do. share|improve this answer answered Jan 18 '10 at 21:10 Chris Dodd 2,274710 1 The debugger showed that the SIGBUS occurred immediately upon entering the function. Maybe I have some memory corruption, or maybe one of the function parameters is bad? I'll have to check the disassembly in the debugger for more details if the error occurs again. –Josh Kelley Jan 18 '10 at 22:13 1 @Josh -- check to see what the actual failing instruction is -- if its a push or pop, then your stack pointer is corrupted. If its something else, then the address in the instruction is the issue. –Chris Dodd Jan 19 '10 at 19:04 add a comment| up vote 14 down vote SIGBUS can happen in Linux for quite a few reasons other than memory alignment faults - for example, if you attempt to access an mmap region beyond the end of the mapped file. Are you using anything like mmap, shared memory regions, or similar? share|improve this answer answered Jan 19 '10 at 0:10 caf 155k14192324 2 Yes, we're using shared memory regions. I'll investigate that possibility the next time this error comes up. Thanks. –Josh Kelley Jan 19 '10 at 13:20 add a comment| up vote 2 down vote Oh yes there's one
program yourself, you can skip the rest of this section. For College-supported software, you can report the bug by contacting a consultant through olc or "mail staff". ------------------------------------------------------------------------------- If http://www.glue.umd.edu/afs/glue.umd.edu/system/info/olh/Utilities/Unix_answers/unix_bus_or_seg.html the program displays this message: Bus error or Segmentation fault or Core dump ... then the program was trying to access a memory location outside its address space. The computer detected this problem and http://kb.mit.edu/confluence/pages/viewpage.action?pageId=3907165 sent a signal to your program, which caused it to abort. Things that cause bus errors and segmentation violations are typically out-of-bounds array references and/or references through uninitialized or mangled pointers. Look very closely bus error in your program for bizarre things like that. A common example in C is: int c; scanf("%d", c); instead of the correct version: int c; scanf("%d", &c); An example from C++ is: int* p=new int[100]; cout<< p[100]; instead of the correct version: int* p=new int[100]; cout << p[99] (remember array referances in C and C++ start with 0 ) There are a number of methods for finding out where bus error (core the program went out of bounds. One method is to use printf() statements to determine how far the program is getting before it crashes, and to print out the contents of interesting variables. A more sophisticated method is using 'dbx', a source level symbolic debugger. C and C++ programmers can also use 'gdb'. To learn about 'dbx', you can read the manual pages by using the 'man' command, as in: man dbx To learn about 'gdb', you can read the manual node in the 'xinfo' program, or using 'M-x info' in Emacs. If you need to debug your program, you may want to enable a core dump. Usually, those two messages above would also have "(core dumped)" by them, indicating that the program wrote an image of its current memory into a file called "core" in that directory. You might want to type 'fs lq' and find out how many blocks (kilobytes) you have available in your quota. Then you can type, say: limit coredumpsize 100 .. to limit your core dump size to 100K for your current login. BE CAREFUL not to let yourself go over quota, as you would then not be able to create or edit files. You should delete the
view Printable view Export to Adobe Acrobat (PDF) Export to Microsoft Word Email this page Other pagesHome page Dashboard News Recent updates RSS feed builder Index Site map Labels Attachments index People Directory AccountLog in History History What does "Bus Error" or "Segmentation Fault" mean? These statements mean that there's a bug in the program. If you're able to consistently reproduce this bug in a piece of supported software, please submit a bug report using the "sendbug" command. If you're interested in learning more details and how to debug your own programs, read on. These errors often mean that the program was trying to access a memory location outside its address space. The computer detected this problem and sent a signal to your program, which caused it to abort. Things that cause bus errors and segmentation violations are typically out-of-bounds array references and/or references through uninitialized or mangled pointers. Look very closely in your program for bizarre things like that. A common example is: int c; scanf("%d", c); instead of the correct version: int c; scanf("%d", &c); There are a number of methods for finding out where the program went out of bounds. One method is to use printf() statements to determine how far the program is getting before it crashes, and to print out the contents of interesting variables. A more sophisticated method is using a debugger, such as "gdb". If you need to debug your program, you may want to enable a core dump. Usually, those two messages above would also have "(core dumped)" by them, indicating that the program wrote an image of its current memory into a file called "core" in that directory. Athena turned this off by default, since for most people "core" is just a waste of disk space. If you want to turn it back on again, type 'quota -v' and find out how many blocks (kilobytes) you have available in your quota. Then you can type, say: limit coredumpsize 100 .. to limit your core dump size to 100K for your current login. BE CAREFUL not to let yourself go over quota, as you would then not be able to create or edit files. You should delete the "core" file when you don't need it any more. To allow core dumps and still not have quota worries, you can make a symbolic link from the name core into the /tmp directory. Core dumps created this way will not take up quota, and they will automatically vanish when you log out.The dump will also occur more quickly since it doesn't have to go over the network to your directory. To set up a core link in a directory: ln