Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Examining threads with Python extensions
@ 2017-03-04 21:43 Paul Smith
  2017-03-06 22:58 ` Paul Smith
  2017-03-06 23:05 ` Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Smith @ 2017-03-04 21:43 UTC (permalink / raw)
  To: gdb

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!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Examining threads with Python extensions
  2017-03-04 21:43 Examining threads with Python extensions Paul Smith
@ 2017-03-06 22:58 ` Paul Smith
  2017-03-06 23:05 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Smith @ 2017-03-06 22:58 UTC (permalink / raw)
  To: gdb

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!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Examining threads with Python extensions
  2017-03-04 21:43 Examining threads with Python extensions Paul Smith
  2017-03-06 22:58 ` Paul Smith
@ 2017-03-06 23:05 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2017-03-06 23:05 UTC (permalink / raw)
  To: psmith; +Cc: gdb

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)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-06 23:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-04 21:43 Examining threads with Python extensions Paul Smith
2017-03-06 22:58 ` Paul Smith
2017-03-06 23:05 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox