Skip to main content

GDB Tips

· 2 min read
Hreniuc Cristian-Alexandru

GDB cheatsheet

Start gdb with coredump:

gdb ./executable coredump

Print all bracktrace:

bt full

Go to a specific frame:

frame 3

Content of an oject of a specific type from a specific address:

print *(class::client::client_data*)0x7f2a10000c50

Content of a variable:

print conn_ptr

Print the content of the object stored in a shared_ptr:

print *shared_ptr_obj._M_ptr

Print the content of std::string:

# 0x7fdaa000f690 is the address of the string.

print *(char**)0x7fdaa000f690

Print a specific element from a vector:

# A shared_ptr to a vector
print *((*vector_shared_ptr._M_ptr)._M_impl._M_start+0)

print *((vector_obj)._M_impl._M_start+0)

Print multiple elements from a vector(ex 9 elements):

# A shared_ptr to a vector
print *((*vector_shared_ptr._M_ptr)._M_impl._M_start)@9

print *((vector_obj)._M_impl._M_start)@9


Type info variables to list "All global and static variable names".

Type info locals to list "Local variables of current stack frame" (names and values), including static variables in that function.

Type info args to list "Arguments of the current stack frame" (names and values).

Print long string(more here):

set print elements 0
print string

Print variable value in a file(more here):

set logging on

print string

set logging off

# The content can be found in gdb.txt
# If you want to change the file run:
set logging file my_god_object.log