Examining threads with Python extensions

Paul Smith paul@mad-scientist.net
Mon Mar 6 22:58:00 GMT 2017


Don't mean to be a noodge but I wonder if anyone has any thoughts about
this?  Is it not possible to write a function that works with multiple
threads using the GDB Python extensions?


On Sat, 2017-03-04 at 16:43 -0500, 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!



More information about the Gdb mailing list