GDB tricks
blogs.oracle.com
GDB tricks
1–10 of 35 posts
Re: GDB tricks
#2Re: GDB tricks
#3Don't bother having a external GUI, just use the built-in Ncruses one.
Re: GDB tricks
#4This lack the best option: ctrl-x a Don't bother having a external GUI, just use the built-in Ncruses one.
Re: GDB tricks
#5Re: GDB tricks
#6 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...Re: GDB tricks
#7I 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
#8My 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...
Re: GDB tricks
#9Heh. 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".
Re: GDB tricks
#10Buried lede: Oracle uses GDB.