1

I am trying to understand more deeply how GDB knows about threads.

  • How is it able to tell which one is the current thread ?
  • How does it know all the context information relative to each thread ?

My question aims at how it works internally in GDB, I do not have any problem debugging threads, it is all really about GDB's internals.

I found the GDB internals documentation, but the threads part is empty as for now.
All my other research lead me to question about debugging multi-threaded programs and I cannot seem to dig the precise information I am looking for.

Edit :

So far it seems that GDB intercepts signals (thanks to ptrace?) and finds out when threads are created. But I would like to know more precisely how it is actually done.

I also have a particular architecture that comes with a GDB that was configured with --enable-threads=single. That GDB is however able to list the current threads. How is this possible ?

Every knowledge, useful links or documentations are welcomed.

Thanks.


Update March 5 '14

I have looked into the libthread_db and found out that GDB allows providing a custom built library to debug threads (see doc for information)

I have tried to do that and am able to provide gdb information about my thread (ID, start function, stack and such) by implementing the td_thr_get_info function defined in gdb/common/gdb_thread_db.h.

Still i am not able to give gdb any information about the context of my threads and still looking for any clue on that issue.

Thanks.

PS: This question seem to address the same questions but has unfortunately no directions too.

Community
  • 1
  • 1
d6bels
  • 1,432
  • 2
  • 18
  • 30
  • FYI, I am working in a Linux environment, but I'd like to keep the information as much generic as possible. – d6bels Aug 22 '13 at 07:46
  • 1
    What do you mean by "current" thread? I would imagine the thread creating routines are intercepted, so GDB finds out about stack and other properties from certain memory locations in the process memory (heap). – Patrik Beck Aug 26 '13 at 14:45
  • Yes, I came across such assertions during my researchs although I am looking for more precision in how this is actually done in GDB. Studying its source code gives information, but it is quite a wild jungle. I also edited the question to focus more on the problem I am facing. – d6bels Aug 26 '13 at 18:31

1 Answers1

2

Try to search for information about libthread_db.

wilx
  • 17,697
  • 6
  • 59
  • 114