1<html lang="en"> 2<head> 3<title>Breakpoints In Python - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Python-API.html#Python-API" title="Python API"> 9<link rel="prev" href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python" title="Symbol Tables In Python"> 10<link rel="next" href="Finish-Breakpoints-in-Python.html#Finish-Breakpoints-in-Python" title="Finish Breakpoints in Python"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988-2013 Free Software Foundation, Inc. 14 15Permission is granted to copy, distribute and/or modify this document 16under the terms of the GNU Free Documentation License, Version 1.3 or 17any later version published by the Free Software Foundation; with the 18Invariant Sections being ``Free Software'' and ``Free Software Needs 19Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 20and with the Back-Cover Texts as in (a) below. 21 22(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 23this GNU Manual. Buying copies from GNU Press supports the FSF in 24developing GNU and promoting software freedom.'' 25--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Breakpoints-In-Python"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Finish-Breakpoints-in-Python.html#Finish-Breakpoints-in-Python">Finish Breakpoints in Python</a>, 45Previous: <a rel="previous" accesskey="p" href="Symbol-Tables-In-Python.html#Symbol-Tables-In-Python">Symbol Tables In Python</a>, 46Up: <a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a> 47<hr> 48</div> 49 50<h5 class="subsubsection">23.2.2.24 Manipulating breakpoints using Python</h5> 51 52<p><a name="index-breakpoints-in-python-2146"></a><a name="index-gdb_002eBreakpoint-2147"></a> 53Python code can manipulate breakpoints via the <code>gdb.Breakpoint</code> 54class. 55 56<div class="defun"> 57— Function: <b>Breakpoint.__init__</b> (<var>spec </var><span class="roman">[</span><var>, type </var><span class="roman">[</span><var>, wp_class </var><span class="roman">[</span><var>,internal</var><span class="roman">]]]</span>)<var><a name="index-Breakpoint_002e_005f_005finit_005f_005f-2148"></a></var><br> 58<blockquote><p>Create a new breakpoint. <var>spec</var> is a string naming the 59location of the breakpoint, or an expression that defines a 60watchpoint. The contents can be any location recognized by the 61<code>break</code> command, or in the case of a watchpoint, by the <code>watch</code> 62command. The optional <var>type</var> denotes the breakpoint to create 63from the types defined later in this chapter. This argument can be 64either: <code>gdb.BP_BREAKPOINT</code> or <code>gdb.BP_WATCHPOINT</code>. <var>type</var> 65defaults to <code>gdb.BP_BREAKPOINT</code>. The optional <var>internal</var> argument 66allows the breakpoint to become invisible to the user. The breakpoint 67will neither be reported when created, nor will it be listed in the 68output from <code>info breakpoints</code> (but will be listed with the 69<code>maint info breakpoints</code> command). The optional <var>wp_class</var> 70argument defines the class of watchpoint to create, if <var>type</var> is 71<code>gdb.BP_WATCHPOINT</code>. If a watchpoint class is not provided, it is 72assumed to be a <code>gdb.WP_WRITE</code> class. 73</p></blockquote></div> 74 75<div class="defun"> 76— Function: <b>Breakpoint.stop</b> (<var>self</var>)<var><a name="index-Breakpoint_002estop-2149"></a></var><br> 77<blockquote><p>The <code>gdb.Breakpoint</code> class can be sub-classed and, in 78particular, you may choose to implement the <code>stop</code> method. 79If this method is defined as a sub-class of <code>gdb.Breakpoint</code>, 80it will be called when the inferior reaches any location of a 81breakpoint which instantiates that sub-class. If the method returns 82<code>True</code>, the inferior will be stopped at the location of the 83breakpoint, otherwise the inferior will continue. 84 85 <p>If there are multiple breakpoints at the same location with a 86<code>stop</code> method, each one will be called regardless of the 87return status of the previous. This ensures that all <code>stop</code> 88methods have a chance to execute at that location. In this scenario 89if one of the methods returns <code>True</code> but the others return 90<code>False</code>, the inferior will still be stopped. 91 92 <p>You should not alter the execution state of the inferior (i.e., step, 93next, etc.), alter the current frame context (i.e., change the current 94active frame), or alter, add or delete any breakpoint. As a general 95rule, you should not alter any data within <span class="sc">gdb</span> or the inferior 96at this time. 97 98 <p>Example <code>stop</code> implementation: 99 100 <pre class="smallexample"> class MyBreakpoint (gdb.Breakpoint): 101 def stop (self): 102 inf_val = gdb.parse_and_eval("foo") 103 if inf_val == 3: 104 return True 105 return False 106</pre> 107 </blockquote></div> 108 109 <p>The available watchpoint types represented by constants are defined in the 110<code>gdb</code> module: 111 112 113<a name="index-WP_005fREAD-2150"></a> 114<a name="index-gdb_002eWP_005fREAD-2151"></a> 115<dl><dt><code>gdb.WP_READ</code><dd>Read only watchpoint. 116 117 <p><a name="index-WP_005fWRITE-2152"></a><a name="index-gdb_002eWP_005fWRITE-2153"></a><br><dt><code>gdb.WP_WRITE</code><dd>Write only watchpoint. 118 119 <p><a name="index-WP_005fACCESS-2154"></a><a name="index-gdb_002eWP_005fACCESS-2155"></a><br><dt><code>gdb.WP_ACCESS</code><dd>Read/Write watchpoint. 120</dl> 121 122<div class="defun"> 123— Function: <b>Breakpoint.is_valid</b> ()<var><a name="index-Breakpoint_002eis_005fvalid-2156"></a></var><br> 124<blockquote><p>Return <code>True</code> if this <code>Breakpoint</code> object is valid, 125<code>False</code> otherwise. A <code>Breakpoint</code> object can become invalid 126if the user deletes the breakpoint. In this case, the object still 127exists, but the underlying breakpoint does not. In the cases of 128watchpoint scope, the watchpoint remains valid even if execution of the 129inferior leaves the scope of that watchpoint. 130</p></blockquote></div> 131 132<div class="defun"> 133— Function: <b>Breakpoint.delete</b><var><a name="index-Breakpoint_002edelete-2157"></a></var><br> 134<blockquote><p>Permanently deletes the <span class="sc">gdb</span> breakpoint. This also 135invalidates the Python <code>Breakpoint</code> object. Any further access 136to this object's attributes or methods will raise an error. 137</p></blockquote></div> 138 139<div class="defun"> 140— Variable: <b>Breakpoint.enabled</b><var><a name="index-Breakpoint_002eenabled-2158"></a></var><br> 141<blockquote><p>This attribute is <code>True</code> if the breakpoint is enabled, and 142<code>False</code> otherwise. This attribute is writable. 143</p></blockquote></div> 144 145<div class="defun"> 146— Variable: <b>Breakpoint.silent</b><var><a name="index-Breakpoint_002esilent-2159"></a></var><br> 147<blockquote><p>This attribute is <code>True</code> if the breakpoint is silent, and 148<code>False</code> otherwise. This attribute is writable. 149 150 <p>Note that a breakpoint can also be silent if it has commands and the 151first command is <code>silent</code>. This is not reported by the 152<code>silent</code> attribute. 153</p></blockquote></div> 154 155<div class="defun"> 156— Variable: <b>Breakpoint.thread</b><var><a name="index-Breakpoint_002ethread-2160"></a></var><br> 157<blockquote><p>If the breakpoint is thread-specific, this attribute holds the thread 158id. If the breakpoint is not thread-specific, this attribute is 159<code>None</code>. This attribute is writable. 160</p></blockquote></div> 161 162<div class="defun"> 163— Variable: <b>Breakpoint.task</b><var><a name="index-Breakpoint_002etask-2161"></a></var><br> 164<blockquote><p>If the breakpoint is Ada task-specific, this attribute holds the Ada task 165id. If the breakpoint is not task-specific (or the underlying 166language is not Ada), this attribute is <code>None</code>. This attribute 167is writable. 168</p></blockquote></div> 169 170<div class="defun"> 171— Variable: <b>Breakpoint.ignore_count</b><var><a name="index-Breakpoint_002eignore_005fcount-2162"></a></var><br> 172<blockquote><p>This attribute holds the ignore count for the breakpoint, an integer. 173This attribute is writable. 174</p></blockquote></div> 175 176<div class="defun"> 177— Variable: <b>Breakpoint.number</b><var><a name="index-Breakpoint_002enumber-2163"></a></var><br> 178<blockquote><p>This attribute holds the breakpoint's number — the identifier used by 179the user to manipulate the breakpoint. This attribute is not writable. 180</p></blockquote></div> 181 182<div class="defun"> 183— Variable: <b>Breakpoint.type</b><var><a name="index-Breakpoint_002etype-2164"></a></var><br> 184<blockquote><p>This attribute holds the breakpoint's type — the identifier used to 185determine the actual breakpoint type or use-case. This attribute is not 186writable. 187</p></blockquote></div> 188 189<div class="defun"> 190— Variable: <b>Breakpoint.visible</b><var><a name="index-Breakpoint_002evisible-2165"></a></var><br> 191<blockquote><p>This attribute tells whether the breakpoint is visible to the user 192when set, or when the ‘<samp><span class="samp">info breakpoints</span></samp>’ command is run. This 193attribute is not writable. 194</p></blockquote></div> 195 196 <p>The available types are represented by constants defined in the <code>gdb</code> 197module: 198 199 200<a name="index-BP_005fBREAKPOINT-2166"></a> 201<a name="index-gdb_002eBP_005fBREAKPOINT-2167"></a> 202<dl><dt><code>gdb.BP_BREAKPOINT</code><dd>Normal code breakpoint. 203 204 <p><a name="index-BP_005fWATCHPOINT-2168"></a><a name="index-gdb_002eBP_005fWATCHPOINT-2169"></a><br><dt><code>gdb.BP_WATCHPOINT</code><dd>Watchpoint breakpoint. 205 206 <p><a name="index-BP_005fHARDWARE_005fWATCHPOINT-2170"></a><a name="index-gdb_002eBP_005fHARDWARE_005fWATCHPOINT-2171"></a><br><dt><code>gdb.BP_HARDWARE_WATCHPOINT</code><dd>Hardware assisted watchpoint. 207 208 <p><a name="index-BP_005fREAD_005fWATCHPOINT-2172"></a><a name="index-gdb_002eBP_005fREAD_005fWATCHPOINT-2173"></a><br><dt><code>gdb.BP_READ_WATCHPOINT</code><dd>Hardware assisted read watchpoint. 209 210 <p><a name="index-BP_005fACCESS_005fWATCHPOINT-2174"></a><a name="index-gdb_002eBP_005fACCESS_005fWATCHPOINT-2175"></a><br><dt><code>gdb.BP_ACCESS_WATCHPOINT</code><dd>Hardware assisted access watchpoint. 211</dl> 212 213<div class="defun"> 214— Variable: <b>Breakpoint.hit_count</b><var><a name="index-Breakpoint_002ehit_005fcount-2176"></a></var><br> 215<blockquote><p>This attribute holds the hit count for the breakpoint, an integer. 216This attribute is writable, but currently it can only be set to zero. 217</p></blockquote></div> 218 219<div class="defun"> 220— Variable: <b>Breakpoint.location</b><var><a name="index-Breakpoint_002elocation-2177"></a></var><br> 221<blockquote><p>This attribute holds the location of the breakpoint, as specified by 222the user. It is a string. If the breakpoint does not have a location 223(that is, it is a watchpoint) the attribute's value is <code>None</code>. This 224attribute is not writable. 225</p></blockquote></div> 226 227<div class="defun"> 228— Variable: <b>Breakpoint.expression</b><var><a name="index-Breakpoint_002eexpression-2178"></a></var><br> 229<blockquote><p>This attribute holds a breakpoint expression, as specified by 230the user. It is a string. If the breakpoint does not have an 231expression (the breakpoint is not a watchpoint) the attribute's value 232is <code>None</code>. This attribute is not writable. 233</p></blockquote></div> 234 235<div class="defun"> 236— Variable: <b>Breakpoint.condition</b><var><a name="index-Breakpoint_002econdition-2179"></a></var><br> 237<blockquote><p>This attribute holds the condition of the breakpoint, as specified by 238the user. It is a string. If there is no condition, this attribute's 239value is <code>None</code>. This attribute is writable. 240</p></blockquote></div> 241 242<div class="defun"> 243— Variable: <b>Breakpoint.commands</b><var><a name="index-Breakpoint_002ecommands-2180"></a></var><br> 244<blockquote><p>This attribute holds the commands attached to the breakpoint. If 245there are commands, this attribute's value is a string holding all the 246commands, separated by newlines. If there are no commands, this 247attribute is <code>None</code>. This attribute is not writable. 248</p></blockquote></div> 249 250 </body></html> 251 252