You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

364 lines
16KB

  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Events In Python (Debugging with GDB)</title>
  17. <meta name="description" content="Events In Python (Debugging with GDB)">
  18. <meta name="keywords" content="Events In Python (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="Threads-In-Python.html#Threads-In-Python" rel="next" title="Threads In Python">
  27. <link href="Inferiors-In-Python.html#Inferiors-In-Python" rel="prev" title="Inferiors In Python">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Events-In-Python"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Threads-In-Python.html#Threads-In-Python" accesskey="n" rel="next">Threads In Python</a>, Previous: <a href="Inferiors-In-Python.html#Inferiors-In-Python" accesskey="p" rel="prev">Inferiors 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>
  61. </div>
  62. <hr>
  63. <a name="Events-In-Python-1"></a>
  64. <h4 class="subsubsection">23.2.2.17 Events In Python</h4>
  65. <a name="index-inferior-events-in-Python"></a>
  66. <p><small>GDB</small> provides a general event facility so that Python code can be
  67. notified of various state changes, particularly changes that occur in
  68. the inferior.
  69. </p>
  70. <p>An <em>event</em> is just an object that describes some state change. The
  71. type of the object and its attributes will vary depending on the details
  72. of the change. All the existing events are described below.
  73. </p>
  74. <p>In order to be notified of an event, you must register an event handler
  75. with an <em>event registry</em>. An event registry is an object in the
  76. <code>gdb.events</code> module which dispatches particular events. A registry
  77. provides methods to register and unregister event handlers:
  78. </p>
  79. <dl>
  80. <dt><a name="index-EventRegistry_002econnect"></a>Function: <strong>EventRegistry.connect</strong> <em>(object)</em></dt>
  81. <dd><p>Add the given callable <var>object</var> to the registry. This object will be
  82. called when an event corresponding to this registry occurs.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-EventRegistry_002edisconnect"></a>Function: <strong>EventRegistry.disconnect</strong> <em>(object)</em></dt>
  86. <dd><p>Remove the given <var>object</var> from the registry. Once removed, the object
  87. will no longer receive notifications of events.
  88. </p></dd></dl>
  89. <p>Here is an example:
  90. </p>
  91. <div class="smallexample">
  92. <pre class="smallexample">def exit_handler (event):
  93. print &quot;event type: exit&quot;
  94. print &quot;exit code: %d&quot; % (event.exit_code)
  95. gdb.events.exited.connect (exit_handler)
  96. </pre></div>
  97. <p>In the above example we connect our handler <code>exit_handler</code> to the
  98. registry <code>events.exited</code>. Once connected, <code>exit_handler</code> gets
  99. called when the inferior exits. The argument <em>event</em> in this example is
  100. of type <code>gdb.ExitedEvent</code>. As you can see in the example the
  101. <code>ExitedEvent</code> object has an attribute which indicates the exit code of
  102. the inferior.
  103. </p>
  104. <p>The following is a listing of the event registries that are available and
  105. details of the events they emit:
  106. </p>
  107. <dl compact="compact">
  108. <dt><code>events.cont</code></dt>
  109. <dd><p>Emits <code>gdb.ThreadEvent</code>.
  110. </p>
  111. <p>Some events can be thread specific when <small>GDB</small> is running in non-stop
  112. mode. When represented in Python, these events all extend
  113. <code>gdb.ThreadEvent</code>. Note, this event is not emitted directly; instead,
  114. events which are emitted by this or other modules might extend this event.
  115. Examples of these events are <code>gdb.BreakpointEvent</code> and
  116. <code>gdb.ContinueEvent</code>.
  117. </p>
  118. <dl>
  119. <dt><a name="index-ThreadEvent_002einferior_005fthread"></a>Variable: <strong>ThreadEvent.inferior_thread</strong></dt>
  120. <dd><p>In non-stop mode this attribute will be set to the specific thread which was
  121. involved in the emitted event. Otherwise, it will be set to <code>None</code>.
  122. </p></dd></dl>
  123. <p>Emits <code>gdb.ContinueEvent</code> which extends <code>gdb.ThreadEvent</code>.
  124. </p>
  125. <p>This event indicates that the inferior has been continued after a stop. For
  126. inherited attribute refer to <code>gdb.ThreadEvent</code> above.
  127. </p>
  128. </dd>
  129. <dt><code>events.exited</code></dt>
  130. <dd><p>Emits <code>events.ExitedEvent</code> which indicates that the inferior has exited.
  131. <code>events.ExitedEvent</code> has two attributes:
  132. </p><dl>
  133. <dt><a name="index-ExitedEvent_002eexit_005fcode"></a>Variable: <strong>ExitedEvent.exit_code</strong></dt>
  134. <dd><p>An integer representing the exit code, if available, which the inferior
  135. has returned. (The exit code could be unavailable if, for example,
  136. <small>GDB</small> detaches from the inferior.) If the exit code is unavailable,
  137. the attribute does not exist.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-ExitedEvent_002einferior"></a>Variable: <strong>ExitedEvent.inferior</strong></dt>
  141. <dd><p>A reference to the inferior which triggered the <code>exited</code> event.
  142. </p></dd></dl>
  143. </dd>
  144. <dt><code>events.stop</code></dt>
  145. <dd><p>Emits <code>gdb.StopEvent</code> which extends <code>gdb.ThreadEvent</code>.
  146. </p>
  147. <p>Indicates that the inferior has stopped. All events emitted by this registry
  148. extend StopEvent. As a child of <code>gdb.ThreadEvent</code>, <code>gdb.StopEvent</code>
  149. will indicate the stopped thread when <small>GDB</small> is running in non-stop
  150. mode. Refer to <code>gdb.ThreadEvent</code> above for more details.
  151. </p>
  152. <p>Emits <code>gdb.SignalEvent</code> which extends <code>gdb.StopEvent</code>.
  153. </p>
  154. <p>This event indicates that the inferior or one of its threads has received as
  155. signal. <code>gdb.SignalEvent</code> has the following attributes:
  156. </p>
  157. <dl>
  158. <dt><a name="index-SignalEvent_002estop_005fsignal"></a>Variable: <strong>SignalEvent.stop_signal</strong></dt>
  159. <dd><p>A string representing the signal received by the inferior. A list of possible
  160. signal values can be obtained by running the command <code>info signals</code> in
  161. the <small>GDB</small> command prompt.
  162. </p></dd></dl>
  163. <p>Also emits <code>gdb.BreakpointEvent</code> which extends <code>gdb.StopEvent</code>.
  164. </p>
  165. <p><code>gdb.BreakpointEvent</code> event indicates that one or more breakpoints have
  166. been hit, and has the following attributes:
  167. </p>
  168. <dl>
  169. <dt><a name="index-BreakpointEvent_002ebreakpoints"></a>Variable: <strong>BreakpointEvent.breakpoints</strong></dt>
  170. <dd><p>A sequence containing references to all the breakpoints (type
  171. <code>gdb.Breakpoint</code>) that were hit.
  172. See <a href="Breakpoints-In-Python.html#Breakpoints-In-Python">Breakpoints In Python</a>, for details of the <code>gdb.Breakpoint</code> object.
  173. </p></dd></dl>
  174. <dl>
  175. <dt><a name="index-BreakpointEvent_002ebreakpoint"></a>Variable: <strong>BreakpointEvent.breakpoint</strong></dt>
  176. <dd><p>A reference to the first breakpoint that was hit.
  177. This function is maintained for backward compatibility and is now deprecated
  178. in favor of the <code>gdb.BreakpointEvent.breakpoints</code> attribute.
  179. </p></dd></dl>
  180. </dd>
  181. <dt><code>events.new_objfile</code></dt>
  182. <dd><p>Emits <code>gdb.NewObjFileEvent</code> which indicates that a new object file has
  183. been loaded by <small>GDB</small>. <code>gdb.NewObjFileEvent</code> has one attribute:
  184. </p>
  185. <dl>
  186. <dt><a name="index-NewObjFileEvent_002enew_005fobjfile"></a>Variable: <strong>NewObjFileEvent.new_objfile</strong></dt>
  187. <dd><p>A reference to the object file (<code>gdb.Objfile</code>) which has been loaded.
  188. See <a href="Objfiles-In-Python.html#Objfiles-In-Python">Objfiles In Python</a>, for details of the <code>gdb.Objfile</code> object.
  189. </p></dd></dl>
  190. </dd>
  191. <dt><code>events.clear_objfiles</code></dt>
  192. <dd><p>Emits <code>gdb.ClearObjFilesEvent</code> which indicates that the list of object
  193. files for a program space has been reset.
  194. <code>gdb.ClearObjFilesEvent</code> has one attribute:
  195. </p>
  196. <dl>
  197. <dt><a name="index-ClearObjFilesEvent_002eprogspace"></a>Variable: <strong>ClearObjFilesEvent.progspace</strong></dt>
  198. <dd><p>A reference to the program space (<code>gdb.Progspace</code>) whose objfile list has
  199. been cleared. See <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>.
  200. </p></dd></dl>
  201. </dd>
  202. <dt><code>events.inferior_call</code></dt>
  203. <dd><p>Emits events just before and after a function in the inferior is
  204. called by <small>GDB</small>. Before an inferior call, this emits an event
  205. of type <code>gdb.InferiorCallPreEvent</code>, and after an inferior call,
  206. this emits an event of type <code>gdb.InferiorCallPostEvent</code>.
  207. </p>
  208. <dl compact="compact">
  209. <dd><a name="index-gdb_002eInferiorCallPreEvent"></a>
  210. </dd>
  211. <dt><code><code>gdb.InferiorCallPreEvent</code></code></dt>
  212. <dd><p>Indicates that a function in the inferior is about to be called.
  213. </p>
  214. <dl>
  215. <dt><a name="index-InferiorCallPreEvent_002eptid"></a>Variable: <strong>InferiorCallPreEvent.ptid</strong></dt>
  216. <dd><p>The thread in which the call will be run.
  217. </p></dd></dl>
  218. <dl>
  219. <dt><a name="index-InferiorCallPreEvent_002eaddress"></a>Variable: <strong>InferiorCallPreEvent.address</strong></dt>
  220. <dd><p>The location of the function to be called.
  221. </p></dd></dl>
  222. <a name="index-gdb_002eInferiorCallPostEvent"></a>
  223. </dd>
  224. <dt><code><code>gdb.InferiorCallPostEvent</code></code></dt>
  225. <dd><p>Indicates that a function in the inferior has just been called.
  226. </p>
  227. <dl>
  228. <dt><a name="index-InferiorCallPostEvent_002eptid"></a>Variable: <strong>InferiorCallPostEvent.ptid</strong></dt>
  229. <dd><p>The thread in which the call was run.
  230. </p></dd></dl>
  231. <dl>
  232. <dt><a name="index-InferiorCallPostEvent_002eaddress"></a>Variable: <strong>InferiorCallPostEvent.address</strong></dt>
  233. <dd><p>The location of the function that was called.
  234. </p></dd></dl>
  235. </dd>
  236. </dl>
  237. </dd>
  238. <dt><code>events.memory_changed</code></dt>
  239. <dd><p>Emits <code>gdb.MemoryChangedEvent</code> which indicates that the memory of the
  240. inferior has been modified by the <small>GDB</small> user, for instance via a
  241. command like <code>set&nbsp;*addr&nbsp;=&nbsp;value</code><!-- /@w -->. The event has the following
  242. attributes:
  243. </p>
  244. <dl>
  245. <dt><a name="index-MemoryChangedEvent_002eaddress"></a>Variable: <strong>MemoryChangedEvent.address</strong></dt>
  246. <dd><p>The start address of the changed region.
  247. </p></dd></dl>
  248. <dl>
  249. <dt><a name="index-MemoryChangedEvent_002elength"></a>Variable: <strong>MemoryChangedEvent.length</strong></dt>
  250. <dd><p>Length in bytes of the changed region.
  251. </p></dd></dl>
  252. </dd>
  253. <dt><code>events.register_changed</code></dt>
  254. <dd><p>Emits <code>gdb.RegisterChangedEvent</code> which indicates that a register in the
  255. inferior has been modified by the <small>GDB</small> user.
  256. </p>
  257. <dl>
  258. <dt><a name="index-RegisterChangedEvent_002eframe"></a>Variable: <strong>RegisterChangedEvent.frame</strong></dt>
  259. <dd><p>A gdb.Frame object representing the frame in which the register was modified.
  260. </p></dd></dl>
  261. <dl>
  262. <dt><a name="index-RegisterChangedEvent_002eregnum"></a>Variable: <strong>RegisterChangedEvent.regnum</strong></dt>
  263. <dd><p>Denotes which register was modified.
  264. </p></dd></dl>
  265. </dd>
  266. <dt><code>events.breakpoint_created</code></dt>
  267. <dd><p>This is emitted when a new breakpoint has been created. The argument
  268. that is passed is the new <code>gdb.Breakpoint</code> object.
  269. </p>
  270. </dd>
  271. <dt><code>events.breakpoint_modified</code></dt>
  272. <dd><p>This is emitted when a breakpoint has been modified in some way. The
  273. argument that is passed is the new <code>gdb.Breakpoint</code> object.
  274. </p>
  275. </dd>
  276. <dt><code>events.breakpoint_deleted</code></dt>
  277. <dd><p>This is emitted when a breakpoint has been deleted. The argument that
  278. is passed is the <code>gdb.Breakpoint</code> object. When this event is
  279. emitted, the <code>gdb.Breakpoint</code> object will already be in its
  280. invalid state; that is, the <code>is_valid</code> method will return
  281. <code>False</code>.
  282. </p>
  283. </dd>
  284. <dt><code>events.before_prompt</code></dt>
  285. <dd><p>This event carries no payload. It is emitted each time <small>GDB</small>
  286. presents a prompt to the user.
  287. </p>
  288. </dd>
  289. <dt><code>events.new_inferior</code></dt>
  290. <dd><p>This is emitted when a new inferior is created. Note that the
  291. inferior is not necessarily running; in fact, it may not even have an
  292. associated executable.
  293. </p>
  294. <p>The event is of type <code>gdb.NewInferiorEvent</code>. This has a single
  295. attribute:
  296. </p>
  297. <dl>
  298. <dt><a name="index-NewInferiorEvent_002einferior"></a>Variable: <strong>NewInferiorEvent.inferior</strong></dt>
  299. <dd><p>The new inferior, a <code>gdb.Inferior</code> object.
  300. </p></dd></dl>
  301. </dd>
  302. <dt><code>events.inferior_deleted</code></dt>
  303. <dd><p>This is emitted when an inferior has been deleted. Note that this is
  304. not the same as process exit; it is notified when the inferior itself
  305. is removed, say via <code>remove-inferiors</code>.
  306. </p>
  307. <p>The event is of type <code>gdb.InferiorDeletedEvent</code>. This has a single
  308. attribute:
  309. </p>
  310. <dl>
  311. <dt><a name="index-NewInferiorEvent_002einferior-1"></a>Variable: <strong>NewInferiorEvent.inferior</strong></dt>
  312. <dd><p>The inferior that is being removed, a <code>gdb.Inferior</code> object.
  313. </p></dd></dl>
  314. </dd>
  315. <dt><code>events.new_thread</code></dt>
  316. <dd><p>This is emitted when <small>GDB</small> notices a new thread. The event is of
  317. type <code>gdb.NewThreadEvent</code>, which extends <code>gdb.ThreadEvent</code>.
  318. This has a single attribute:
  319. </p>
  320. <dl>
  321. <dt><a name="index-NewThreadEvent_002einferior_005fthread"></a>Variable: <strong>NewThreadEvent.inferior_thread</strong></dt>
  322. <dd><p>The new thread.
  323. </p></dd></dl>
  324. </dd>
  325. </dl>
  326. <hr>
  327. <div class="header">
  328. <p>
  329. Next: <a href="Threads-In-Python.html#Threads-In-Python" accesskey="n" rel="next">Threads In Python</a>, Previous: <a href="Inferiors-In-Python.html#Inferiors-In-Python" accesskey="p" rel="prev">Inferiors 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>
  330. </div>
  331. </body>
  332. </html>