Readit News logoReadit News
brendangregg · 7 years ago
Looks like a great guide. If people are interested in something similar, here's one I wrote recently http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncur...
pixelbeat__ · 7 years ago
Very nice guide, debugging a practical example

My own debugging with gdb summary: http://www.pixelbeat.org/programming/debugger/

chris_wot · 7 years ago
Thanks! Great writeup
rdtsc · 7 years ago
That's a good summary. Anything from Beej is very good usually.

Watches are incredibly useful. I remember struggling with a bug, wasted days or even weeks on it. Then during lunch an older more experience engineer told me to use watchpoints, and just like that I could see the trace of what was writing over that particular memory address and the problem was solved. It's like in the movies where the master utters some cryptic koan and the struggling apprentice is suddenly enlightened.

Speaking of corrupted memory, another command to add is "x" it stands for "examine memory" and it does just that. Then after examining the memory, for fun, set a watchpoint to see what code ends writing or reading from it.

exDM69 · 7 years ago
Remote debugging and especially the extended-remote mode are worth knowing.

That is usually my default workflow. The debugger (client and frontend) run on my desktop box while the app is running under gdbserver on an ARM board on the network.

The other day I was debugging a Windows game on my Linux laptop, editing in vim, compiling with x86_64-w64-mingw-clang and gdbserver running on my desktop PC. Not the most comfortable development environment but sure as hell beats learning another debugger and installing dev tools on Windows.

vvanders · 7 years ago
As someone who's spent a good amount of time in both GDB and Visual Studio don't be so quick to knock the dev tools on Windows, they're really quite good.
exDM69 · 7 years ago
Windows is a platform I very seldom use. I had a few hour debugging job, so not worth installing the dev tools. I could just use the tools I always do.
mesarvagya · 7 years ago
Beej is the man. I liked his networking guide.
davidw · 7 years ago
Beej is the man in Bend, Oregon. He regularly hosts hacker nights!
AdmiralAsshat · 7 years ago
Conditional breakpoints would be a good GDB skill to cover as well (e.g. b foo if(bar==5) ). Particularly because I usually forget how to do it properly when checking string values with memcmp and have to google around for a few minutes...
tptacek · 7 years ago
The only thing I'd add to this is "commands", which executes a series of GDB commands when a breakpoint gets hit, and has been supremely useful for me for all sorts of debugging tasks.
spicymaki · 7 years ago
I never knew gdb had a tui mode. It is not even specified in the man page as an option.
atso · 7 years ago
The manual is worth a read. This is a software (as gcc) in which the "man" page or the information displayed with "--help" is not near the bunch of things there are described in the complete documentation.
jcelerier · 7 years ago
(for those who don't know, the full manual can be read with `info gdb` - `man gdb` is only a short help)
tomjakubowski · 7 years ago
Yes. The GNU manuals tend to be excellent sources. GNU Make's is particularly great. https://www.gnu.org/software/make/manual/make.html
toomanybeersies · 7 years ago
This guide was a lifesaver when I had to learn how to use GDB on the fly for my 4th year embedded systems paper back at university.

His networking and IPC guides are also one of the sole reasons I managed to pass my 3rd year operating systems paper. From memory we were actually recommended to use his networking guide instead of any particular textbook.