Threads-In-Python.html 8.6 KB

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