...

/

Use GDB with a Multi-Threaded Application I

Use GDB with a Multi-Threaded Application I

Learn to analyze a multi-threaded application’s stack traces and functions.

This lesson will allow us to get familiar with the GDB commands that we will often use in our analysis.

Application source code

We have created a multi-threaded application and captured its core dump to demonstrate how we can use GDB on it.

Press + to interact
// Build:
// gcc main.c -pthread -static -o App1
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define THREAD_DECLARE(num) void bar_##num()\
{\
sleep(-1);\
}\
\
void foo_##num()\
{\
bar_##num();\
}\
\
void * thread_##num (void *arg)\
{\
foo_##num();\
\
return 0;\
}
THREAD_DECLARE(one)
THREAD_DECLARE(two)
THREAD_DECLARE(three)
THREAD_DECLARE(four)
THREAD_DECLARE(five)
#define THREAD_CREATE(num) {pthread_t threadID_##num; pthread_create (&threadID_##num, NULL, thread_##num, NULL);}
int main(int argc, const char * argv[])
{
THREAD_CREATE(one)
THREAD_CREATE(two)
THREAD_CREATE(three)
THREAD_CREATE(four)
THREAD_CREATE(five)
sleep(-1);
return 0;
}

Loading the core dump file

First, we’ll load a core dump file App1.core.253 that is already prepared for this exercise. We can do so using the following command:

gdb -c App1.core.253 -se App1

The above command will output the following to the terminal:

Congratulations! We’ve just loaded the core dump file and can start working on it! We should be able to see an output similar to the one given ...

Access this course and 1400+ top-rated courses and projects.