This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Examining threads with Python extensions
- From: Paul Smith <psmith at gnu dot org>
- To: gdb at sourceware dot org
- Date: Sat, 04 Mar 2017 16:43:44 -0500
- Subject: Examining threads with Python extensions
- Authentication-results: sourceware.org; auth=none
- Reply-to: psmith at gnu dot org
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!