Skip to main content

2 posts tagged with "debugger"

View All Tags

· One min read
Hreniuc Cristian-Alexandru


My server(started from qtcreator in Debug) was sending data to a client and the client crashed ungracefully(CTRL+C), this resulted in two things:

  • SIGPIPE signal was generated(which was handled in my code, but before getting to my code GDB was handleling it, and crashed my server)
  • The server crashed with SEGFAULT when I was running it in terminal with no GDB attached.

So, to investigate the SEGFAULT easier, inside QtCreator, I had to force GDB to ignore the first signal SIGPIPE, I did this by doing thse two steps:

  • uncheck the box "Show a message box when receiving a signal" in Tools -> Options... -> Debugger -> GDB.
  • If you want gdb not to catch a signal but pass it to your program, you need to give gdb a command like the following:handle SIGPIPE pass nostop noprint(see Window -> Views -> Debugger Log or Tools -> Options... -> Debugger -> GDB -> GDB startup script Debugging Helper Customization or Tools -> Options... -> Debugger -> GDB -> Locals & Expressions (like the image below for the SIGPIPE signal)).

· 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