This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Examining threads with Python extensions


On 2017-03-04 16:43, Paul Smith wrote:
Hi all.

I'm trying to write some useful commands for my debugging using the
Python API in GDB.

What I want to do is write a Python command that will visit each of the
threads in my process (or coredump) and examine the stacktrace, etc. for
interesting content and display that.  I have a lot of threads, and
there are certain ones that are always present, plus thread pools, etc.
I'd like to be able to generate a summary of the thread numbers (GDB
thread IDs), what that thread is for in my process, and what its status
is, etc.

I can see https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html and
I can walk all stack frames in the currently selected thread, using the
gdb.newest() / Frame.older() etc. methods, which I can use to figure out
what the current thread is doing.

However, I can't seem to find any way to operate on all the threads. In
https://sourceware.org/gdb/onlinedocs/gdb/Threads-In-Python.html the
only thread function available to me, from what I can see, is
gdb.selected_thread() which gives me an InferiorThread object for the
selected thread.

But I can't find any methods that would switch to the "next" thread or
whatever.  There's InferiorThread.switch() but that makes the current
InferiorThread object be the current thread... but how do I get the
InferiorThread objects for all the threads so I can use it?!

Help?  Thanks!

The Inferior object has a .threads() method that returns its threads. I think that's what you are looking for. So you can do something like (pseudo python):

  for inf in gdb.inferiors():
    for th in inf.threads():
     print(th)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]