Live data from Hacker News

GDB tricks

blogs.oracle.com

1–10 of 35 posts

Re: GDB tricks

#2
I would add the skip command to register a function or file as something you don't want the step command to go into in the future. Really handy for all those trivial operator*s you get in C++ smart pointers and such.

Re: GDB tricks

#4
post #3

This lack the best option: ctrl-x a Don't bother having a external GUI, just use the built-in Ncruses one.

I find the built in one extremely flakey and hard to use. I usually have better luck with cgdb.

Re: GDB tricks

#7
These are all useful, and I would even say fundamental, commands. But, as such, these are also very basic commands, not tricks. If you're looking for something more advanced, you'll be disappointed.

I strongly suggest to anyone using gdb to just read the manual [0]. Or at least skim it quickly and find a dozen of such useful "tricks" in as many minutes. The time gained in debugging later is well worth knowing and mastering your tools.

Here's a quick summary of the article, most of this stuff is covered in the first few chapters of the manual :

1. conditional breakpoints, yes, they exist

2. execute commands each time a breakpoint is hit, yes, that's possible

3. pass commands to the program directly from gdb's command line

4. define source directories

5. debug macros with the right compile options

6. you can use the results of commands, and even define variables !

7. you can access cpu registers

8. you can even examine memory

[0] http://sourceware.org/gdb/current/onlinedocs/gdb.pdf.gz : it looks big but a lot of it is annexes at the end, or how to extend GDB with your own scripts, which can be interesting but can easily be skipped in the beginning. The important chapters to begin with would be :

- Getting in and out of gdb

- gdb commands

- Running programs under gdb

- Stopping and continuing - Examining the stack

- Examining source files

- Examining data - Altering execution

Re: GDB tricks

#8

My favourite one: attach to the process in question using gdb, and run: p dup2(open("/dev/null", 0), 1) p dup2(open("/dev/null", 0), 2) detach quit From: https://stackoverflow.com/questions/593724/redirect-stderr-s...

reattach without gdb http://unix.stackexchange.com/questions/4034/how-can-i-disow...

Re: GDB tricks

#9
> By Ksplice Post Importer on Jan 24, 2011

Heh. When interning at Ksplice/Oracle in 2011, I was tasked to import all of the blog posts from the old Ksplice Wordpress blog into Oracle's system. By hand, because they didn't want to turn on the Apache Roller API, or something.

I couldn't set a custom author for each post, so instead I changed my name to "Importer, Ksplice Post".

Post reply on HN