Skip to main content

5 posts tagged with "gdb"

View All Tags

· One min read
Hreniuc Cristian-Alexandru

Source: https://doc.qt.io/qtcreator/creator-debugging-helpers.html#adding-custom-debugging-helpers

find ~ -name personaltypes.py

/home/cristi/Qt/Tools/QtCreator/share/qtcreator/debugger/personaltypes.py

Add there the following contents:

def qdump__ClassType1(d, value):
m_member1 = value["m_member1"].integer()
m_member2 = value["m_member2"].integer()
miliseconds = int(m_member1 * 1000 / m_member2)
d.putNumChild(0)
d.putValue(str(miliseconds) + str("ms (")+ str(m_member1) + str("m1, ") + str(m_member2) + str("m2)"))

def qdump__ClassType2(d, value):
position = value["m_position"]
d.putNumChild(0)
qdump__FramesDuration(d, position)

The ClassType2 will be displayed like this: 3642331ms (160626834m1, 44100m2).

For more examples, check: /home/cristi/Qt/Tools/QtCreator/share/qtcreator/debugger/stdtypes.py.

· 3 min read
Hreniuc Cristian-Alexandru

Some things were taken from this post, be sure to check it out.

Prepare pretty printers for GDB

The first thing you should always do is to get the pretty printers and use them to print the variables in gdb. To do this you will need to find the install path of thec gcc that was used to build the executable that has generated a coredump, and inside that path there should be some pretty printers. Usually, this path can be found here(on ubuntu): /usr/share/gcc-10/python/.

In my case it was in /opt/gcc/9.2.0/share/gcc-9.2.0/python/, because the gcc that I was using was built from sources.

That folder contains a folder called: libstdcxx which contains some python scripts that are used to print the variables nicer.

If you are investigating a coredump on a different server, you can copy that folder to the server using scp: scp -r /usr/share/gcc-10/python/ user@server:/path/to/server/.

Activate the pretty printers from the gdb config file

Pretty printers, added this in ~/.gdbinit:

python
import sys
# gcc-9
sys.path.insert(0, '/usr/share/gcc/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

# Will print the whoile object
set pagination off
set print array on

# It will format the output
set print pretty on

· One min read
Hreniuc Cristian-Alexandru

Source: https://stackoverflow.com/a/19537899

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

Source: https://stackoverflow.com/questions/6261392/printing-all-global-variables-local-variables

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