GDB kind of doesn’t work on macOS Sierra

This is how I easily fixed the issue. [Update: based on feedback received and yet to be verified, it seems that this solution works with macOS Sierra 10.12 but not with macOS Sierra 10.12.2] See video instructions here Quit gdb Using your text editor e.g. Sublime Text, save a file called .gdbinit in your user … Read more

How to highlight and color gdb output during interactive debugging?

.gdbinit You can tweak your ~/.gdbinit to have colors. You can use mammon’s .gdbinit which is available here: https://github.com/gdbinit/gdbinit You can tweak it as much as you want too. I found this thanks to this SO answer. Here’s the kind of output that you can obtain: A GitHub repository is also available: https://github.com/gdbinit/Gdbinit On a … Read more

gdb split view with code

It’s called the TUI (no kidding). Start for example with gdbtui or gdb -tui … Please also see this answer by Ciro Santilli. It wasn’t available in 2012 to the best of my knowledge, but definitely worth a look.

How do I run a program with commandline arguments using GDB within a Bash script?

You can run gdb with –args parameter: gdb –args executablename arg1 arg2 arg3 If you are doing this often (e.g. when running GDB from a script), you might want to consider the following arguments to automate things further. First, you can place your GDB commands (such as ‘run’) in a text file and provide the … Read more

Can we define a new data type in a GDB session

Yes, here is how to make this work: // sample.h struct sample { int i; struct sample *less; struct sample *more; }; // main.c #include <stdio.h> #include <assert.h> #include “sample.h” int main() { struct sample sm; sm.i = 42; sm.less = sm.more = &sm; printf(“&sm = %p\n”, &sm); assert(sm.i == 0); // will fail } … Read more

Stopping at the first machine code instruction in GDB

Starting with GDB 8.1, there’s a special command for this: starti. Example GDB session: $ gdb /bin/true Reading symbols from /bin/true…(no debugging symbols found)…done. (gdb) starti Starting program: /bin/true Program stopped. 0xf7fdd800 in _start () from /lib/ld-linux.so.2 (gdb) x/5i $pc => 0xf7fdd800 <_start>: mov eax,esp 0xf7fdd802 <_start+2>: call 0xf7fe2160 <_dl_start> 0xf7fdd807 <_dl_start_user>: mov edi,eax 0xf7fdd809 … Read more

Core dump file analysis [duplicate]

You just need a binary (with debugging symbols included) that is identical to the one that generated the core dump file. Then you can run gdb path/to/the/binary path/to/the/core/dump/file to debug it. When it starts up, you can use bt (for backtrace) to get a stack trace from the time of the crash. In the backtrace, … Read more