gdb fail

Sep. 11th, 2009 08:07 pm
torkell: (Default)
[personal profile] torkell
It never ceases to amaze me just how backward the Linux development environment is.

Today I attempted to debug a test program that segfaults about 5 minutes after startup for no apparent reason. I managed to get a core dump of it, and loaded it into gdb in the hope of finding what was going on. Hahaha.

gdb could give me a valid stack trace showing the error, and could disassemble the program around the error to show me the actual instructions involved. However, gdb could not tell me the value of all the variables there (it claimed that some variables weren't even defined, nevermind that the program uses them all over the place!), nor could it actually match the disassembly up to the source.

Come on, folks, Visual C++ has been able to do this for decades! The Windows debugging tools are so far ahead it's embarassing for Linux.

I did actually discover a patch to gdb to achieve this, submitted April last year. Unfortuantly it's not in the latest released version of gdb (released March last year), and I really don't fancy building gdb from source myself.

Date: 2009-09-11 08:06 pm (UTC)
From: [identity profile] 13th-einherjar.livejournal.com
I wonder if this is at all related to any of the randomization techniques applied a while ago to make buffer overflows fail most of the time. In that it's supposed to be non-trivial to figure out how all of the variables are laid out in memory, because that way hackers can't write 8 bytes to 4 byte int a and know that the next 4 bytes are definitely going to int b. Probably no relation.

I find this strange, because one of my first reasons for switching to Linux was the ease of compiling and developing software. Back then, Linux systems still assumed you wanted to compile something, so the toolchain was already installed and pretty well standardized. And Windows offered 2 options a) pay thousands of dollars to have your IDE installed for you b) spend several days groping through undocumented system calls and crippleware compiler toolchains to write "Hello World" in the language and library of choice.

Date: 2009-09-14 07:29 pm (UTC)
From: [identity profile] pewterfish.livejournal.com
To be entirely fair, that the program uses them doesn't necessarily mean the variables were defined :D GCC and GDB have been known to disagree on this sort of thing from time to time.

In general, though, gdb is ... not the friendliest program in the world. The few times I've investigated it, its output has been so terse and unreadable that I've ended up going back to the tried and tested "print statements and see where they go wrong" method eventually. I hear there are a few third-party front-ends that make it more usable, though.

Since I'm about to get back into programming AVRs under Linux, I should probably get some more time in with gdb. Gonna be useful...

January 2026

S M T W T F S
     123
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 8th, 2026 10:52 am
Powered by Dreamwidth Studios