The powerful GNU Debugger GDB returns to the front stage.

Join us for an all-new, more advanced introduction to GDB.

What IsGDB?

synology nas

This article will continue to build further on the information presented there.

It sounds likeapples, pie, and pancakes!

(And to some extent, it is.)

Terminal window showing the manual page for the Mutt email client on Linux

If this sounds a little complicated, have a look atDebugging with GDB: Getting Startedfirst.

Single-threaded or Multithreaded?

The program was single-threaded: No other execution threads wereforkedfrom within the code.

The main page of the Homepage homelab dashboard with services running on it.

There are only occasional instances where GDB will mistake the crashing thread for another.

For example, this might happen if the program has crashed in two threads at the same time.

The termLWPstands forLight Weight Process.

Article image

Shutterstock/Nicescene

Note that GDB must do this upfront so that it might find the crashing thread as described earlier.

Additionally, no variable readouts would be presented for those function names.

This can be achieved by using the commands

or

, respectively.

Using GDB to debug a MySQL Server (mysqld) produced core dump

We can swap the

in the last command to access another thread, etc.

This is a real skill.

It’s quite clear: This thread is waiting for input.

GDB startup reads debug symbols and shows threads in the form of LWP’s (Light Weight Processes)

In other words, there would be as good as zero value in continuing to debug this thread.

All we have to do to start our debugging adventure is to get a backtrace.

Then, when analyzing multiple threads and their interaction, it makes sense to jump between threads with thethreadcommand.

A GDB backtrace with bt showing various 18 frames (function calls)

The information is stored to

by default.

Some care has to be taken here.

It’s quite easy to mismatch binaries, code, and core dumps.

Switching to another thread and running a backtrace in GDB

There’s one other small exception here, and that is stack smashing.

Most of the time, it will be quite clear.

At times, a really bad bug can cause stack smashing.

A backtrace of an OS/IO based looping waiting thread

Accessing a frame in GDB and insights into printing variables at the GDB command line

GDB: Obtaining the desired variables from the correct frame which has them available