Next: Recordings In Python, Previous: Events In Python, Up: Python API
Python scripts can access information about, and manipulate inferior threads
controlled by gdb, via objects of the gdb.InferiorThread class.
The following thread-related functions are available in the gdb
module:
This function returns the thread object for the selected thread. If there is no selected thread, this will return
None.
To get the list of threads for an inferior, use the Inferior.threads()
method. See Inferiors In Python.
A gdb.InferiorThread object has the following attributes:
The name of the thread. If the user specified a name using
thread name, then this returns that name. Otherwise, if an OS-supplied name is available, then it is returned. Otherwise, this returnsNone.This attribute can be assigned to. The new value must be a string object, which sets the new name, or
None, which removes any user-specified thread name.
The global ID of the thread, as assigned by GDB. You can use this to make Python breakpoints thread-specific, for example (see The Breakpoint.thread attribute).
ID of the thread, as assigned by the operating system. This attribute is a tuple containing three integers. The first is the Process ID (PID); the second is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID). Either the LWPID or TID may be 0, which indicates that the operating system does not use that identifier.
The inferior this thread belongs to. This attribute is represented as a
gdb.Inferiorobject. This attribute is not writable.
A string containing target specific thread state information. The format of this string varies by target. If there is no additional state information for this thread, then this attribute contains
None.For example, on a gnu/Linux system, a thread that is in the process of exiting will return the string `Exiting'. For remote targets the
detailsstring will be obtained with the `qThreadExtraInfo' remote packet, if the target supports it (see `qThreadExtraInfo').gdb displays the
detailsstring as part of the `Target Id' column, in theinfo threadsoutput (see `info threads').
A gdb.InferiorThread object has the following methods:
Returns
Trueif thegdb.InferiorThreadobject is valid,Falseif not. Agdb.InferiorThreadobject will become invalid if the thread exits, or the inferior that the thread belongs is deleted. All othergdb.InferiorThreadmethods will throw an exception if it is invalid at the time the method is called.
This changes gdb's currently selected thread to the one represented by this object.
Return the thread object's handle, represented as a Python
bytesobject. Agdb.Valuerepresentation of the handle may be constructed viagdb.Value(bufobj, type)where bufobj is the Pythonbytesrepresentation of the handle and type is agdb.Typefor the handle type.