GDB not showing any own code in stack trace when debugging a FPC app on Linux

193 views Asked by At

I'm trying to debug a deadlock situation on a FPC app running on Linux using GDB, but for some of my own threads, it's not showing any of my own code in the call stack.

What I do is I check info threads to find a thread that is currently waiting for a critical section lock. Such thread looks like this:

37 Thread 0x7fe3d07e16c0 (LWP 52933) "THREADNAME" futex_wait (private=0, expected=2, futex_word=0x7fe3df3006e8) at ../sysdeps/nptl/futex-internal.h:146

Then I navigate to that thread t 37 and use where to see the call stack. It shows me which file and which line in that file is currently waiting for the critical section lock:

#0  futex_wait (private=0, expected=2, futex_word=0x7fe328340448) at ../sysdeps/nptl/futex-internal.h:146
#1  __GI___lll_lock_wait (futex=futex@entry=0x7fe328340448, private=0) at ./nptl/lowlevellock.c:49
#2  0x00007fe3df4e12ba in lll_mutex_lock_optimized (mutex=0x7fe328340448) at ./nptl/pthread_mutex_lock.c:48
#3  ___pthread_mutex_lock (mutex=0x7fe328340448) at ./nptl/pthread_mutex_lock.c:128
.
.
.

... at #12 there's my code.

Next I go to frame 3 f 3 and print print mutex.__data.__owner which will give me this output: $2 = 53348

Then I use thread find to see which thread is currently owning the critical section:

(gdb) thread find 53348
Thread 438 has target id 'Thread 0x7fe2712f46c0 (LWP 53348)'

Finally I do the same thing for this other thread which also waits for a critical section. BUT that thread does not show any of my own code in the call stack, even though it is one of my own threads. This is all that I can see:

(gdb) where
#0  futex_wait (private=0, expected=2, futex_word=0x7fe3641d48c8) at ../sysdeps/nptl/futex-internal.h:146
#1  __GI___lll_lock_wait (futex=futex@entry=0x7fe3641d48c8, private=0) at ./nptl/lowlevellock.c:49
#2  0x00007fe3df4e12ba in lll_mutex_lock_optimized (mutex=0x7fe3641d48c8) at ./nptl/pthread_mutex_lock.c:48
#3  ___pthread_mutex_lock (mutex=0x7fe3641d48c8) at ./nptl/pthread_mutex_lock.c:128
#4  0x000000000042a81b in CTHREADS_$$_CENTERCRITICALSECTION$formal ()
#5  0x0000000000000000 in ?? ()

When I look further to again see which thread owns that critical section, it's showing my own code again. I use these arguments for FPC when creating a debug build: -dDEBUG -MDelphi -gl -gp -gw3 GDB Version: GNU gdb (Debian 13.1-2) 13.1

Why is GDB not showing my own code? Also any other hints for resolving deadlocks are very welcome.

UPDATE: I was able to solve my deadlock issue by using TEvent instead of TCriticalSection.

0

There are 0 answers