Gdb Find Bus Error
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 Learn more about hiring developers or bus error c++ posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
Bus Error (core Dumped) Linux
Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only
Bus Error In Linux
takes a minute: Sign up What is a bus error? up vote 156 down vote favorite 49 What does the "bus error" message mean, and how does it differ from a segfault? c unix segmentation-fault bus-error share|improve this question edited Oct
How To Debug Bus Error
18 '15 at 10:44 Cool Guy 15.7k51952 asked Oct 17 '08 at 14:48 raldi 7,252216178 add a comment| 15 Answers 15 active oldest votes up vote 151 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 alignment requirements. Segmentation faults occur when accessing memory which does not belong to your process, they are very common how to solve bus error in linux 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,72322336 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 58 down vote A segfault is accessing memory that you're not allowed to access. It's read-only, you don't have permission, etc... A bus error is trying to access memory that can't possibly be there. You've used an address that's meaningless to the system, or the wrong kind of address for that operation. share|improve this answer an
code with the -g option. This tells the compiler to annotate your executtable with the names of variables, locations in the code etc. Then type gdb. At the prompt type bus error vs segmentation fault file nameOfExecutable. Then use the set command to set any parameters that you would type bus error core dumped c after the executable. For example if you would normally type fred arg1 arg2 then you can do: gdb file [filename] set args bus error 10 mac [arg1] [arg2] r or gdb [filename] run arg1 arg2 The r command will run the debugger. When it gets the bus error, seg fault or whatever, the location in your source code will be displayed. If you http://stackoverflow.com/questions/212466/what-is-a-bus-error want to see the whole stack to help find out where the failing routine was called from etc you can use the bt command which backtraces the execution stack. quit gets you out of the debugger. Go to the gnu documention on the web for details or just type help in gdb. The Man Page for gdb Here is the man page for gdb. As you can see it can do a lot http://marvin.cs.uidaho.edu/Teaching/CS445/gdb.html more than just the tiny example above. GNU Tools gdb(1) NAME gdb - The GNU Debugger SYNOPSIS gdb [-help] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps] [-tty=dev] [-s symfile] [-e prog] [-se prog] [-c core] [-x cmds] [-d dir] [prog[core|procID]] DESCRIPTION The purpose of a debugger such as GDB is to allow you to see what is going on ``inside'' another program while it executes-or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: o Start your program, specifying anything that might affect its behavior. o Make your program stop on specified conditions. o Examine what has happened, when your program has stopped. o Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. You can use GDB to debug programs written in C, C++, and Modula-2. Fortran support will be added when a GNU Fortran compiler is ready. GDB is invoked with the shell command gdb. Once started, it reads commands from the terminal until you tell it to exit with the GDB command quit. You can get online help from gdb itself by using the command help. You can run gdb w
Programming Boards C Programming help needed on debugging "bus error" Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: help needed on http://cboard.cprogramming.com/c-programming/90001-help-needed-debugging-bus-error.html debugging "bus error" Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 05-18-2007 #1 wuhua View Profile View Forum Posts Registered User Join Date May 2007 Posts 2 help needed on debugging "bus error" Hello. This is my first post here. Thanks for your help. I have been coding a program which handles many arrays of strings. The program sometimes (there is a random number generator bus error in the codes) will crash with a message "bus error". I am guessing it's caused by those strings. I tried to find out where exactly the error occurs by adding print lines inbetween coding blocks like the following: 100 printf("100\n"); codes... 200 printf("200\n"); codes... 300 printf("300\n"); However, it didn't help because the output will be something like 100 200 300 100 20 which means it crashes in the middle of printing 200? Anyway, because i can't exactly pin down which part bus error in of the code causes the problem, it is very hard for me to fix it. Any ideas? Thanks a lot. 05-18-2007 #2 Salem View Profile View Forum Posts and the hat of int overfl Join Date Aug 2001 Location The edge of the known universe Posts 34,484 > there is a random number generator in the codes I would avoid calling srand() until you're sure everything works. At least then you'll get some measure of repeatability. As for the bus error, that is much harder. If you run it inside the debugger, it will trap the BE and stop the program where the problem is first identified. Unfortunately, this is seldom related to the root cause of the problem which is likely to be somewhere else in the code. First check that all your pointers are at least initialised to NULL, if you don't initialise them when you declare them. Also check all loops which subscript into arrays, to make sure they're in bounds as well. int arr[N]; would be indexed with for ( i = 0 ; i < N ; i++ ) Starting at 1, or doing <= N are common mistakes. If you're still stuck and the code isn't too long, then post it. If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. If at first you don't succeed, try writing your phone number on the exam