Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

374 lines
17KB

  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>Breakpoints In Python (Debugging with GDB)</title>
  17. <meta name="description" content="Breakpoints In Python (Debugging with GDB)">
  18. <meta name="keywords" content="Breakpoints 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="Finish-Breakpoints-in-Python.html#Finish-Breakpoints-in-Python" rel="next" title="Finish Breakpoints in Python">
  27. <link href="Line-Tables-In-Python.html#Line-Tables-In-Python" rel="prev" title="Line Tables 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="Breakpoints-In-Python"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Finish-Breakpoints-in-Python.html#Finish-Breakpoints-in-Python" accesskey="n" rel="next">Finish Breakpoints in Python</a>, Previous: <a href="Line-Tables-In-Python.html#Line-Tables-In-Python" accesskey="p" rel="prev">Line Tables 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="Manipulating-breakpoints-using-Python"></a>
  64. <h4 class="subsubsection">23.2.2.30 Manipulating breakpoints using Python</h4>
  65. <a name="index-breakpoints-in-python"></a>
  66. <a name="index-gdb_002eBreakpoint"></a>
  67. <p>Python code can manipulate breakpoints via the <code>gdb.Breakpoint</code>
  68. class.
  69. </p>
  70. <p>A breakpoint can be created using one of the two forms of the
  71. <code>gdb.Breakpoint</code> constructor. The first one accepts a string
  72. like one would pass to the <code>break</code>
  73. (see <a href="Set-Breaks.html#Set-Breaks">Setting Breakpoints</a>) and <code>watch</code>
  74. (see <a href="Set-Watchpoints.html#Set-Watchpoints">Setting Watchpoints</a>) commands, and can be used to
  75. create both breakpoints and watchpoints. The second accepts separate Python
  76. arguments similar to <a href="Explicit-Locations.html#Explicit-Locations">Explicit Locations</a>, and can only be used to create
  77. breakpoints.
  78. </p>
  79. <dl>
  80. <dt><a name="index-Breakpoint_002e_005f_005finit_005f_005f"></a>Function: <strong>Breakpoint.__init__</strong> <em>(spec <span class="roman">[</span>, type <span class="roman">][</span>, wp_class <span class="roman">][</span>, internal <span class="roman">][</span>, temporary <span class="roman">][</span>, qualified <span class="roman">]</span>)</em></dt>
  81. <dd><p>Create a new breakpoint according to <var>spec</var>, which is a string naming the
  82. location of a breakpoint, or an expression that defines a watchpoint. The
  83. string should describe a location in a format recognized by the <code>break</code>
  84. command (see <a href="Set-Breaks.html#Set-Breaks">Setting Breakpoints</a>) or, in the case of a
  85. watchpoint, by the <code>watch</code> command
  86. (see <a href="Set-Watchpoints.html#Set-Watchpoints">Setting Watchpoints</a>).
  87. </p>
  88. <p>The optional <var>type</var> argument specifies the type of the breakpoint to create,
  89. as defined below.
  90. </p>
  91. <p>The optional <var>wp_class</var> argument defines the class of watchpoint to create,
  92. if <var>type</var> is <code>gdb.BP_WATCHPOINT</code>. If <var>wp_class</var> is omitted, it
  93. defaults to <code>gdb.WP_WRITE</code>.
  94. </p>
  95. <p>The optional <var>internal</var> argument allows the breakpoint to become invisible
  96. to the user. The breakpoint will neither be reported when created, nor will it
  97. be listed in the output from <code>info breakpoints</code> (but will be listed with
  98. the <code>maint info breakpoints</code> command).
  99. </p>
  100. <p>The optional <var>temporary</var> argument makes the breakpoint a temporary
  101. breakpoint. Temporary breakpoints are deleted after they have been hit. Any
  102. further access to the Python breakpoint after it has been hit will result in a
  103. runtime error (as that breakpoint has now been automatically deleted).
  104. </p>
  105. <p>The optional <var>qualified</var> argument is a boolean that allows interpreting
  106. the function passed in <code>spec</code> as a fully-qualified name. It is equivalent
  107. to <code>break</code>&rsquo;s <code>-qualified</code> flag (see <a href="Linespec-Locations.html#Linespec-Locations">Linespec Locations</a> and
  108. <a href="Explicit-Locations.html#Explicit-Locations">Explicit Locations</a>).
  109. </p>
  110. </dd></dl>
  111. <dl>
  112. <dt><a name="index-Breakpoint_002e_005f_005finit_005f_005f-1"></a>Function: <strong>Breakpoint.__init__</strong> <em>(<span class="roman">[</span> source <span class="roman">][</span>, function <span class="roman">][</span>, label <span class="roman">][</span>, line <span class="roman">]</span>, <span class="roman">][</span> internal <span class="roman">][</span>, temporary <span class="roman">][</span>, qualified <span class="roman">]</span>)</em></dt>
  113. <dd><p>This second form of creating a new breakpoint specifies the explicit
  114. location (see <a href="Explicit-Locations.html#Explicit-Locations">Explicit Locations</a>) using keywords. The new breakpoint will
  115. be created in the specified source file <var>source</var>, at the specified
  116. <var>function</var>, <var>label</var> and <var>line</var>.
  117. </p>
  118. <p><var>internal</var>, <var>temporary</var> and <var>qualified</var> have the same usage as
  119. explained previously.
  120. </p></dd></dl>
  121. <p>The available types are represented by constants defined in the <code>gdb</code>
  122. module:
  123. </p>
  124. <dl compact="compact">
  125. <dd><a name="index-BP_005fBREAKPOINT"></a>
  126. </dd>
  127. <dt><code>gdb.BP_BREAKPOINT</code>
  128. <a name="index-gdb_002eBP_005fBREAKPOINT"></a>
  129. </dt>
  130. <dd><p>Normal code breakpoint.
  131. </p>
  132. <a name="index-BP_005fWATCHPOINT"></a>
  133. </dd>
  134. <dt><code>gdb.BP_WATCHPOINT</code>
  135. <a name="index-gdb_002eBP_005fWATCHPOINT"></a>
  136. </dt>
  137. <dd><p>Watchpoint breakpoint.
  138. </p>
  139. <a name="index-BP_005fHARDWARE_005fWATCHPOINT"></a>
  140. </dd>
  141. <dt><code>gdb.BP_HARDWARE_WATCHPOINT</code>
  142. <a name="index-gdb_002eBP_005fHARDWARE_005fWATCHPOINT"></a>
  143. </dt>
  144. <dd><p>Hardware assisted watchpoint.
  145. </p>
  146. <a name="index-BP_005fREAD_005fWATCHPOINT"></a>
  147. </dd>
  148. <dt><code>gdb.BP_READ_WATCHPOINT</code>
  149. <a name="index-gdb_002eBP_005fREAD_005fWATCHPOINT"></a>
  150. </dt>
  151. <dd><p>Hardware assisted read watchpoint.
  152. </p>
  153. <a name="index-BP_005fACCESS_005fWATCHPOINT"></a>
  154. </dd>
  155. <dt><code>gdb.BP_ACCESS_WATCHPOINT</code>
  156. <a name="index-gdb_002eBP_005fACCESS_005fWATCHPOINT"></a>
  157. </dt>
  158. <dd><p>Hardware assisted access watchpoint.
  159. </p></dd>
  160. </dl>
  161. <p>The available watchpoint types represented by constants are defined in the
  162. <code>gdb</code> module:
  163. </p>
  164. <dl compact="compact">
  165. <dd><a name="index-WP_005fREAD"></a>
  166. </dd>
  167. <dt><code>gdb.WP_READ</code>
  168. <a name="index-gdb_002eWP_005fREAD"></a>
  169. </dt>
  170. <dd><p>Read only watchpoint.
  171. </p>
  172. <a name="index-WP_005fWRITE"></a>
  173. </dd>
  174. <dt><code>gdb.WP_WRITE</code>
  175. <a name="index-gdb_002eWP_005fWRITE"></a>
  176. </dt>
  177. <dd><p>Write only watchpoint.
  178. </p>
  179. <a name="index-WP_005fACCESS"></a>
  180. </dd>
  181. <dt><code>gdb.WP_ACCESS</code>
  182. <a name="index-gdb_002eWP_005fACCESS"></a>
  183. </dt>
  184. <dd><p>Read/Write watchpoint.
  185. </p></dd>
  186. </dl>
  187. <dl>
  188. <dt><a name="index-Breakpoint_002estop"></a>Function: <strong>Breakpoint.stop</strong> <em>(self)</em></dt>
  189. <dd><p>The <code>gdb.Breakpoint</code> class can be sub-classed and, in
  190. particular, you may choose to implement the <code>stop</code> method.
  191. If this method is defined in a sub-class of <code>gdb.Breakpoint</code>,
  192. it will be called when the inferior reaches any location of a
  193. breakpoint which instantiates that sub-class. If the method returns
  194. <code>True</code>, the inferior will be stopped at the location of the
  195. breakpoint, otherwise the inferior will continue.
  196. </p>
  197. <p>If there are multiple breakpoints at the same location with a
  198. <code>stop</code> method, each one will be called regardless of the
  199. return status of the previous. This ensures that all <code>stop</code>
  200. methods have a chance to execute at that location. In this scenario
  201. if one of the methods returns <code>True</code> but the others return
  202. <code>False</code>, the inferior will still be stopped.
  203. </p>
  204. <p>You should not alter the execution state of the inferior (i.e., step,
  205. next, etc.), alter the current frame context (i.e., change the current
  206. active frame), or alter, add or delete any breakpoint. As a general
  207. rule, you should not alter any data within <small>GDB</small> or the inferior
  208. at this time.
  209. </p>
  210. <p>Example <code>stop</code> implementation:
  211. </p>
  212. <div class="smallexample">
  213. <pre class="smallexample">class MyBreakpoint (gdb.Breakpoint):
  214. def stop (self):
  215. inf_val = gdb.parse_and_eval(&quot;foo&quot;)
  216. if inf_val == 3:
  217. return True
  218. return False
  219. </pre></div>
  220. </dd></dl>
  221. <dl>
  222. <dt><a name="index-Breakpoint_002eis_005fvalid"></a>Function: <strong>Breakpoint.is_valid</strong> <em>()</em></dt>
  223. <dd><p>Return <code>True</code> if this <code>Breakpoint</code> object is valid,
  224. <code>False</code> otherwise. A <code>Breakpoint</code> object can become invalid
  225. if the user deletes the breakpoint. In this case, the object still
  226. exists, but the underlying breakpoint does not. In the cases of
  227. watchpoint scope, the watchpoint remains valid even if execution of the
  228. inferior leaves the scope of that watchpoint.
  229. </p></dd></dl>
  230. <dl>
  231. <dt><a name="index-Breakpoint_002edelete"></a>Function: <strong>Breakpoint.delete</strong> <em>()</em></dt>
  232. <dd><p>Permanently deletes the <small>GDB</small> breakpoint. This also
  233. invalidates the Python <code>Breakpoint</code> object. Any further access
  234. to this object&rsquo;s attributes or methods will raise an error.
  235. </p></dd></dl>
  236. <dl>
  237. <dt><a name="index-Breakpoint_002eenabled"></a>Variable: <strong>Breakpoint.enabled</strong></dt>
  238. <dd><p>This attribute is <code>True</code> if the breakpoint is enabled, and
  239. <code>False</code> otherwise. This attribute is writable. You can use it to enable
  240. or disable the breakpoint.
  241. </p></dd></dl>
  242. <dl>
  243. <dt><a name="index-Breakpoint_002esilent"></a>Variable: <strong>Breakpoint.silent</strong></dt>
  244. <dd><p>This attribute is <code>True</code> if the breakpoint is silent, and
  245. <code>False</code> otherwise. This attribute is writable.
  246. </p>
  247. <p>Note that a breakpoint can also be silent if it has commands and the
  248. first command is <code>silent</code>. This is not reported by the
  249. <code>silent</code> attribute.
  250. </p></dd></dl>
  251. <dl>
  252. <dt><a name="index-Breakpoint_002epending"></a>Variable: <strong>Breakpoint.pending</strong></dt>
  253. <dd><p>This attribute is <code>True</code> if the breakpoint is pending, and
  254. <code>False</code> otherwise. See <a href="Set-Breaks.html#Set-Breaks">Set Breaks</a>. This attribute is
  255. read-only.
  256. </p></dd></dl>
  257. <a name="python_005fbreakpoint_005fthread"></a><dl>
  258. <dt><a name="index-Breakpoint_002ethread"></a>Variable: <strong>Breakpoint.thread</strong></dt>
  259. <dd><p>If the breakpoint is thread-specific, this attribute holds the
  260. thread&rsquo;s global id. If the breakpoint is not thread-specific, this
  261. attribute is <code>None</code>. This attribute is writable.
  262. </p></dd></dl>
  263. <dl>
  264. <dt><a name="index-Breakpoint_002etask"></a>Variable: <strong>Breakpoint.task</strong></dt>
  265. <dd><p>If the breakpoint is Ada task-specific, this attribute holds the Ada task
  266. id. If the breakpoint is not task-specific (or the underlying
  267. language is not Ada), this attribute is <code>None</code>. This attribute
  268. is writable.
  269. </p></dd></dl>
  270. <dl>
  271. <dt><a name="index-Breakpoint_002eignore_005fcount"></a>Variable: <strong>Breakpoint.ignore_count</strong></dt>
  272. <dd><p>This attribute holds the ignore count for the breakpoint, an integer.
  273. This attribute is writable.
  274. </p></dd></dl>
  275. <dl>
  276. <dt><a name="index-Breakpoint_002enumber"></a>Variable: <strong>Breakpoint.number</strong></dt>
  277. <dd><p>This attribute holds the breakpoint&rsquo;s number &mdash; the identifier used by
  278. the user to manipulate the breakpoint. This attribute is not writable.
  279. </p></dd></dl>
  280. <dl>
  281. <dt><a name="index-Breakpoint_002etype"></a>Variable: <strong>Breakpoint.type</strong></dt>
  282. <dd><p>This attribute holds the breakpoint&rsquo;s type &mdash; the identifier used to
  283. determine the actual breakpoint type or use-case. This attribute is not
  284. writable.
  285. </p></dd></dl>
  286. <dl>
  287. <dt><a name="index-Breakpoint_002evisible"></a>Variable: <strong>Breakpoint.visible</strong></dt>
  288. <dd><p>This attribute tells whether the breakpoint is visible to the user
  289. when set, or when the &lsquo;<samp>info breakpoints</samp>&rsquo; command is run. This
  290. attribute is not writable.
  291. </p></dd></dl>
  292. <dl>
  293. <dt><a name="index-Breakpoint_002etemporary"></a>Variable: <strong>Breakpoint.temporary</strong></dt>
  294. <dd><p>This attribute indicates whether the breakpoint was created as a
  295. temporary breakpoint. Temporary breakpoints are automatically deleted
  296. after that breakpoint has been hit. Access to this attribute, and all
  297. other attributes and functions other than the <code>is_valid</code>
  298. function, will result in an error after the breakpoint has been hit
  299. (as it has been automatically deleted). This attribute is not
  300. writable.
  301. </p></dd></dl>
  302. <dl>
  303. <dt><a name="index-Breakpoint_002ehit_005fcount"></a>Variable: <strong>Breakpoint.hit_count</strong></dt>
  304. <dd><p>This attribute holds the hit count for the breakpoint, an integer.
  305. This attribute is writable, but currently it can only be set to zero.
  306. </p></dd></dl>
  307. <dl>
  308. <dt><a name="index-Breakpoint_002elocation"></a>Variable: <strong>Breakpoint.location</strong></dt>
  309. <dd><p>This attribute holds the location of the breakpoint, as specified by
  310. the user. It is a string. If the breakpoint does not have a location
  311. (that is, it is a watchpoint) the attribute&rsquo;s value is <code>None</code>. This
  312. attribute is not writable.
  313. </p></dd></dl>
  314. <dl>
  315. <dt><a name="index-Breakpoint_002eexpression"></a>Variable: <strong>Breakpoint.expression</strong></dt>
  316. <dd><p>This attribute holds a breakpoint expression, as specified by
  317. the user. It is a string. If the breakpoint does not have an
  318. expression (the breakpoint is not a watchpoint) the attribute&rsquo;s value
  319. is <code>None</code>. This attribute is not writable.
  320. </p></dd></dl>
  321. <dl>
  322. <dt><a name="index-Breakpoint_002econdition"></a>Variable: <strong>Breakpoint.condition</strong></dt>
  323. <dd><p>This attribute holds the condition of the breakpoint, as specified by
  324. the user. It is a string. If there is no condition, this attribute&rsquo;s
  325. value is <code>None</code>. This attribute is writable.
  326. </p></dd></dl>
  327. <dl>
  328. <dt><a name="index-Breakpoint_002ecommands"></a>Variable: <strong>Breakpoint.commands</strong></dt>
  329. <dd><p>This attribute holds the commands attached to the breakpoint. If
  330. there are commands, this attribute&rsquo;s value is a string holding all the
  331. commands, separated by newlines. If there are no commands, this
  332. attribute is <code>None</code>. This attribute is writable.
  333. </p></dd></dl>
  334. <hr>
  335. <div class="header">
  336. <p>
  337. Next: <a href="Finish-Breakpoints-in-Python.html#Finish-Breakpoints-in-Python" accesskey="n" rel="next">Finish Breakpoints in Python</a>, Previous: <a href="Line-Tables-In-Python.html#Line-Tables-In-Python" accesskey="p" rel="prev">Line Tables 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>
  338. </div>
  339. </body>
  340. </html>