ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Am facing the worst bug i've ever encountered. It's in a gcc program which analyzes several grids of binary data read from a file. I can read and analyze each single grid, but when i try to read hundreds or sometimes just dozens of grids in succession, at some point the program crashes with a segmentation fault. Obviously, I'm failing to initialize some variable or array netween grids, but can't see where. to save my soul.
gdb doesn't seem to be available to me, and, anyway, it would be a task beyond my patience to step in a debugger through hundreds of grids, each one of which involves some very heavy looping, only to find that the memory corruption under a debugger may be very different than without it.
My question is: is there a gcc compile option or some other way that i could somehow catch the segmentation fault and dump to standard output or to a file something to indicate where the fault is occurring?
You could also try the -fbounds-check option in gcc to crash (with applicable debugging information) if you step outside of the bounds of an array. It WILL slow down the code significantly, but it can be very helpful for catching that occasional indexing error that ultimately leads to a seg fault.
A brute force method would be to start commenting out chunks of code until the seg fault disappears, and then narrow in on which section of code is causing it. This is painful and time consuming, but it can be used as a last resort when gdb, valgrind, and array bounds checking all fails.
Last edited by suicidaleggroll; 02-17-2015 at 02:22 PM.
I neglected to mention that I'm using a rather old development platform, and do not have Electric Fence. I may try the -fbounds-check option, just to familiarize myself with it for future use.
Meanwhile, after looking at NevemTeve's suggestion and before seeing suicidaleggroll's comment, i was already using the brute force method and have located the offending code, a recently added array for which i was failing to reset the index. A noobie oversight that i was unable to see at first.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.