1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Threads In Python</title>
18
19<meta name="description" content="Debugging with GDB: Threads In Python">
20<meta name="keywords" content="Debugging with GDB: Threads In Python">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Python-API.html#Python-API" rel="up" title="Python API">
29<link href="Recordings-In-Python.html#Recordings-In-Python" rel="next" title="Recordings In Python">
30<link href="Events-In-Python.html#Events-In-Python" rel="previous" title="Events In Python">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Threads-In-Python"></a>
65<div class="header">
66<p>
67Next: <a href="Recordings-In-Python.html#Recordings-In-Python" accesskey="n" rel="next">Recordings In Python</a>, Previous: <a href="Events-In-Python.html#Events-In-Python" accesskey="p" rel="previous">Events In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
68</div>
69<hr>
70<a name="Threads-In-Python-1"></a>
71<h4 class="subsubsection">23.2.2.18 Threads In Python</h4>
72<a name="index-threads-in-python"></a>
73
74<a name="index-gdb_002eInferiorThread"></a>
75<p>Python scripts can access information about, and manipulate inferior threads
76controlled by <small>GDB</small>, via objects of the <code>gdb.InferiorThread</code> class.
77</p>
78<p>The following thread-related functions are available in the <code>gdb</code>
79module:
80</p>
81<a name="index-gdb_002eselected_005fthread"></a>
82<dl>
83<dt><a name="index-gdb_002eselected_005fthread-1"></a>Function: <strong>gdb.selected_thread</strong> <em>()</em></dt>
84<dd><p>This function returns the thread object for the selected thread.  If there
85is no selected thread, this will return <code>None</code>.
86</p></dd></dl>
87
88<p>To get the list of threads for an inferior, use the <code>Inferior.threads()</code>
89method.  See <a href="Inferiors-In-Python.html#Inferiors-In-Python">Inferiors In Python</a>.
90</p>
91<p>A <code>gdb.InferiorThread</code> object has the following attributes:
92</p>
93<dl>
94<dt><a name="index-InferiorThread_002ename"></a>Variable: <strong>InferiorThread.name</strong></dt>
95<dd><p>The name of the thread.  If the user specified a name using
96<code>thread name</code>, then this returns that name.  Otherwise, if an
97OS-supplied name is available, then it is returned.  Otherwise, this
98returns <code>None</code>.
99</p>
100<p>This attribute can be assigned to.  The new value must be a string
101object, which sets the new name, or <code>None</code>, which removes any
102user-specified thread name.
103</p></dd></dl>
104
105<dl>
106<dt><a name="index-InferiorThread_002enum"></a>Variable: <strong>InferiorThread.num</strong></dt>
107<dd><p>The per-inferior number of the thread, as assigned by GDB.
108</p></dd></dl>
109
110<dl>
111<dt><a name="index-InferiorThread_002eglobal_005fnum"></a>Variable: <strong>InferiorThread.global_num</strong></dt>
112<dd><p>The global ID of the thread, as assigned by GDB.  You can use this to
113make Python breakpoints thread-specific, for example
114(see <a href="Breakpoints-In-Python.html#python_005fbreakpoint_005fthread">The Breakpoint.thread attribute</a>).
115</p></dd></dl>
116
117<dl>
118<dt><a name="index-InferiorThread_002eptid"></a>Variable: <strong>InferiorThread.ptid</strong></dt>
119<dd><p>ID of the thread, as assigned by the operating system.  This attribute is a
120tuple containing three integers.  The first is the Process ID (PID); the second
121is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
122Either the LWPID or TID may be 0, which indicates that the operating system
123does not  use that identifier.
124</p></dd></dl>
125
126<dl>
127<dt><a name="index-InferiorThread_002einferior"></a>Variable: <strong>InferiorThread.inferior</strong></dt>
128<dd><p>The inferior this thread belongs to.  This attribute is represented as
129a <code>gdb.Inferior</code> object.  This attribute is not writable.
130</p></dd></dl>
131
132<p>A <code>gdb.InferiorThread</code> object has the following methods:
133</p>
134<dl>
135<dt><a name="index-InferiorThread_002eis_005fvalid"></a>Function: <strong>InferiorThread.is_valid</strong> <em>()</em></dt>
136<dd><p>Returns <code>True</code> if the <code>gdb.InferiorThread</code> object is valid,
137<code>False</code> if not.  A <code>gdb.InferiorThread</code> object will become
138invalid if the thread exits, or the inferior that the thread belongs
139is deleted.  All other <code>gdb.InferiorThread</code> methods will throw an
140exception if it is invalid at the time the method is called.
141</p></dd></dl>
142
143<dl>
144<dt><a name="index-InferiorThread_002eswitch"></a>Function: <strong>InferiorThread.switch</strong> <em>()</em></dt>
145<dd><p>This changes <small>GDB</small>&rsquo;s currently selected thread to the one represented
146by this object.
147</p></dd></dl>
148
149<dl>
150<dt><a name="index-InferiorThread_002eis_005fstopped"></a>Function: <strong>InferiorThread.is_stopped</strong> <em>()</em></dt>
151<dd><p>Return a Boolean indicating whether the thread is stopped.
152</p></dd></dl>
153
154<dl>
155<dt><a name="index-InferiorThread_002eis_005frunning"></a>Function: <strong>InferiorThread.is_running</strong> <em>()</em></dt>
156<dd><p>Return a Boolean indicating whether the thread is running.
157</p></dd></dl>
158
159<dl>
160<dt><a name="index-InferiorThread_002eis_005fexited"></a>Function: <strong>InferiorThread.is_exited</strong> <em>()</em></dt>
161<dd><p>Return a Boolean indicating whether the thread is exited.
162</p></dd></dl>
163
164<dl>
165<dt><a name="index-InferiorThread_002ehandle"></a>Function: <strong>InferiorThread.handle</strong> <em>()</em></dt>
166<dd><p>Return the thread object&rsquo;s handle, represented as a Python <code>bytes</code>
167object.  A <code>gdb.Value</code> representation of the handle may be
168constructed via <code>gdb.Value(bufobj, type)</code> where <var>bufobj</var> is
169the Python <code>bytes</code> representation of the handle and <var>type</var> is
170a <code>gdb.Type</code> for the handle type.
171</p></dd></dl>
172
173<hr>
174<div class="header">
175<p>
176Next: <a href="Recordings-In-Python.html#Recordings-In-Python" accesskey="n" rel="next">Recordings In Python</a>, Previous: <a href="Events-In-Python.html#Events-In-Python" accesskey="p" rel="previous">Events In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
177</div>
178
179
180
181</body>
182</html>
183