How do I print the elements of a C++ vector in GDB?

With GCC 4.1.2, to print the whole of a std::vector<int> called myVector, do the following: print *(myVector._M_impl._M_start)@myVector.size() To print only the first N elements, do: print *(myVector._M_impl._M_start)@N Explanation This is probably heavily dependent on your compiler version, but for GCC 4.1.2, the pointer to the internal array is: myVector._M_impl._M_start And the GDB command to print … Read more

How to enable gdb pretty printing for C++ STL objects in Eclipse CDT?

This is the solution that works for me. Download ( http://www.gnu.org/software/gdb/download/) and install latest gdb (i.e. with –prefix $HOME). It supports python scripting. Get python pretty printers by executing svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python in a directory of your choice (i.e. $(HOME)/distribs/gdb_printers). You will get ‘python’ subdirectory in the checkout directory. Put this in your $(HOME)/.gdbinit file … 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

Are “EXC_BREAKPOINT (SIGTRAP)” exceptions caused by debugging breakpoints?

Are “EXC_BREAKPOINT (SIGTRAP)” exceptions caused by debugging breakpoints? No. Other way around, actually: A SIGTRAP (trace trap) will cause the debugger to break (interrupt) your program, the same way an actual breakpoint would. But that’s because the debugger always breaks on a crash, and a SIGTRAP (like several other signals) is one type of crash. … Read more

GDB complaining about missing raise.c

To do full source code debugging of the C library on Ubuntu, there are just a few steps to take: Install the debuginfo version of libc6. It’s probably already installed – the gdb package on Ubuntu has a dependency on it – but in case it isn’t, run sudo apt install libc6-dbg. Prepare the package … 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