From: Simon Marchi <simon.marchi@polymtl.ca>
To: psmith@gnu.org
Cc: gdb@sourceware.org
Subject: Re: Examining threads with Python extensions
Date: Mon, 06 Mar 2017 23:05:00 -0000 [thread overview]
Message-ID: <cd7fd7b4d5949cccd4e87b97160bfd87@polymtl.ca> (raw)
In-Reply-To: <1488663824.3228.154.camel@gnu.org>
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)
prev parent reply other threads:[~2017-03-06 23:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-04 21:43 Paul Smith
2017-03-06 22:58 ` Paul Smith
2017-03-06 23:05 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd7fd7b4d5949cccd4e87b97160bfd87@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb@sourceware.org \
--cc=psmith@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox