Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

434 rindas
18KB

  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>Set Catchpoints (Debugging with GDB)</title>
  17. <meta name="description" content="Set Catchpoints (Debugging with GDB)">
  18. <meta name="keywords" content="Set Catchpoints (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="Breakpoints.html#Breakpoints" rel="up" title="Breakpoints">
  26. <link href="Delete-Breaks.html#Delete-Breaks" rel="next" title="Delete Breaks">
  27. <link href="Set-Watchpoints.html#Set-Watchpoints" rel="prev" title="Set Watchpoints">
  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="Set-Catchpoints"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Delete-Breaks.html#Delete-Breaks" accesskey="n" rel="next">Delete Breaks</a>, Previous: <a href="Set-Watchpoints.html#Set-Watchpoints" accesskey="p" rel="prev">Set Watchpoints</a>, Up: <a href="Breakpoints.html#Breakpoints" accesskey="u" rel="up">Breakpoints</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="Setting-Catchpoints"></a>
  64. <h4 class="subsection">5.1.3 Setting Catchpoints</h4>
  65. <a name="index-catchpoints_002c-setting"></a>
  66. <a name="index-exception-handlers"></a>
  67. <a name="index-event-handling"></a>
  68. <p>You can use <em>catchpoints</em> to cause the debugger to stop for certain
  69. kinds of program events, such as C<tt>++</tt> exceptions or the loading of a
  70. shared library. Use the <code>catch</code> command to set a catchpoint.
  71. </p>
  72. <dl compact="compact">
  73. <dd><a name="index-catch"></a>
  74. </dd>
  75. <dt><code>catch <var>event</var></code></dt>
  76. <dd><p>Stop when <var>event</var> occurs. The <var>event</var> can be any of the following:
  77. </p>
  78. <dl compact="compact">
  79. <dt><code>throw <span class="roman">[</span><var>regexp</var><span class="roman">]</span></code></dt>
  80. <dt><code>rethrow <span class="roman">[</span><var>regexp</var><span class="roman">]</span></code></dt>
  81. <dt><code>catch <span class="roman">[</span><var>regexp</var><span class="roman">]</span></code></dt>
  82. <dd><a name="index-catch-throw"></a>
  83. <a name="index-catch-rethrow"></a>
  84. <a name="index-catch-catch"></a>
  85. <a name="index-stop-on-C_002b_002b-exceptions"></a>
  86. <p>The throwing, re-throwing, or catching of a C<tt>++</tt> exception.
  87. </p>
  88. <p>If <var>regexp</var> is given, then only exceptions whose type matches the
  89. regular expression will be caught.
  90. </p>
  91. <a name="index-_0024_005fexception_002c-convenience-variable"></a>
  92. <p>The convenience variable <code>$_exception</code> is available at an
  93. exception-related catchpoint, on some systems. This holds the
  94. exception being thrown.
  95. </p>
  96. <p>There are currently some limitations to C<tt>++</tt> exception handling in
  97. <small>GDB</small>:
  98. </p>
  99. <ul>
  100. <li> The support for these commands is system-dependent. Currently, only
  101. systems using the &lsquo;<samp>gnu-v3</samp>&rsquo; C<tt>++</tt> ABI (see <a href="ABI.html#ABI">ABI</a>) are
  102. supported.
  103. </li><li> The regular expression feature and the <code>$_exception</code> convenience
  104. variable rely on the presence of some SDT probes in <code>libstdc++</code>.
  105. If these probes are not present, then these features cannot be used.
  106. These probes were first available in the GCC 4.8 release, but whether
  107. or not they are available in your GCC also depends on how it was
  108. built.
  109. </li><li> The <code>$_exception</code> convenience variable is only valid at the
  110. instruction at which an exception-related catchpoint is set.
  111. </li><li> When an exception-related catchpoint is hit, <small>GDB</small> stops at a
  112. location in the system library which implements runtime exception
  113. support for C<tt>++</tt>, usually <code>libstdc++</code>. You can use <code>up</code>
  114. (see <a href="Selection.html#Selection">Selection</a>) to get to your code.
  115. </li><li> If you call a function interactively, <small>GDB</small> normally returns
  116. control to you when the function has finished executing. If the call
  117. raises an exception, however, the call may bypass the mechanism that
  118. returns control to you and cause your program either to abort or to
  119. simply continue running until it hits a breakpoint, catches a signal
  120. that <small>GDB</small> is listening for, or exits. This is the case even if
  121. you set a catchpoint for the exception; catchpoints on exceptions are
  122. disabled within interactive calls. See <a href="Calling.html#Calling">Calling</a>, for information on
  123. controlling this with <code>set unwind-on-terminating-exception</code>.
  124. </li><li> You cannot raise an exception interactively.
  125. </li><li> You cannot install an exception handler interactively.
  126. </li></ul>
  127. </dd>
  128. <dt><code>exception <span class="roman">[</span><var>name</var><span class="roman">]</span></code></dt>
  129. <dd><a name="index-catch-exception"></a>
  130. <a name="index-Ada-exception-catching"></a>
  131. <a name="index-catch-Ada-exceptions"></a>
  132. <p>An Ada exception being raised. If an exception name is specified
  133. at the end of the command (eg <code>catch exception Program_Error</code>),
  134. the debugger will stop only when this specific exception is raised.
  135. Otherwise, the debugger stops execution when any Ada exception is raised.
  136. </p>
  137. <p>When inserting an exception catchpoint on a user-defined exception whose
  138. name is identical to one of the exceptions defined by the language, the
  139. fully qualified name must be used as the exception name. Otherwise,
  140. <small>GDB</small> will assume that it should stop on the pre-defined exception
  141. rather than the user-defined one. For instance, assuming an exception
  142. called <code>Constraint_Error</code> is defined in package <code>Pck</code>, then
  143. the command to use to catch such exceptions is <kbd>catch exception
  144. Pck.Constraint_Error</kbd>.
  145. </p>
  146. <a name="index-_0024_005fada_005fexception_002c-convenience-variable"></a>
  147. <p>The convenience variable <code>$_ada_exception</code> holds the address of
  148. the exception being thrown. This can be useful when setting a
  149. condition for such a catchpoint.
  150. </p>
  151. </dd>
  152. <dt><code>exception unhandled</code></dt>
  153. <dd><a name="index-catch-exception-unhandled"></a>
  154. <p>An exception that was raised but is not handled by the program. The
  155. convenience variable <code>$_ada_exception</code> is set as for <code>catch
  156. exception</code>.
  157. </p>
  158. </dd>
  159. <dt><code>handlers <span class="roman">[</span><var>name</var><span class="roman">]</span></code></dt>
  160. <dd><a name="index-catch-handlers"></a>
  161. <a name="index-Ada-exception-handlers-catching"></a>
  162. <a name="index-catch-Ada-exceptions-when-handled"></a>
  163. <p>An Ada exception being handled. If an exception name is
  164. specified at the end of the command
  165. (eg <kbd>catch handlers Program_Error</kbd>), the debugger will stop
  166. only when this specific exception is handled.
  167. Otherwise, the debugger stops execution when any Ada exception is handled.
  168. </p>
  169. <p>When inserting a handlers catchpoint on a user-defined
  170. exception whose name is identical to one of the exceptions
  171. defined by the language, the fully qualified name must be used
  172. as the exception name. Otherwise, <small>GDB</small> will assume that it
  173. should stop on the pre-defined exception rather than the
  174. user-defined one. For instance, assuming an exception called
  175. <code>Constraint_Error</code> is defined in package <code>Pck</code>, then the
  176. command to use to catch such exceptions handling is
  177. <kbd>catch handlers Pck.Constraint_Error</kbd>.
  178. </p>
  179. <p>The convenience variable <code>$_ada_exception</code> is set as for
  180. <code>catch exception</code>.
  181. </p>
  182. </dd>
  183. <dt><code>assert</code></dt>
  184. <dd><a name="index-catch-assert"></a>
  185. <p>A failed Ada assertion. Note that the convenience variable
  186. <code>$_ada_exception</code> is <em>not</em> set by this catchpoint.
  187. </p>
  188. </dd>
  189. <dt><code>exec</code></dt>
  190. <dd><a name="index-catch-exec"></a>
  191. <a name="index-break-on-fork_002fexec"></a>
  192. <p>A call to <code>exec</code>.
  193. </p>
  194. <a name="catch-syscall"></a></dd>
  195. <dt><code>syscall</code></dt>
  196. <dt><code>syscall <span class="roman">[</span><var>name</var> <span class="roman">|</span> <var>number</var> <span class="roman">|</span> <span class="roman">group:</span><var>groupname</var> <span class="roman">|</span> <span class="roman">g:</span><var>groupname</var><span class="roman">]</span> &hellip;</code></dt>
  197. <dd><a name="index-catch-syscall"></a>
  198. <a name="index-break-on-a-system-call_002e"></a>
  199. <p>A call to or return from a system call, a.k.a. <em>syscall</em>. A
  200. syscall is a mechanism for application programs to request a service
  201. from the operating system (OS) or one of the OS system services.
  202. <small>GDB</small> can catch some or all of the syscalls issued by the
  203. debuggee, and show the related information for each syscall. If no
  204. argument is specified, calls to and returns from all system calls
  205. will be caught.
  206. </p>
  207. <p><var>name</var> can be any system call name that is valid for the
  208. underlying OS. Just what syscalls are valid depends on the OS. On
  209. GNU and Unix systems, you can find the full list of valid syscall
  210. names on <samp>/usr/include/asm/unistd.h</samp>.
  211. </p>
  212. <p>Normally, <small>GDB</small> knows in advance which syscalls are valid for
  213. each OS, so you can use the <small>GDB</small> command-line completion
  214. facilities (see <a href="Completion.html#Completion">command completion</a>) to list the
  215. available choices.
  216. </p>
  217. <p>You may also specify the system call numerically. A syscall&rsquo;s
  218. number is the value passed to the OS&rsquo;s syscall dispatcher to
  219. identify the requested service. When you specify the syscall by its
  220. name, <small>GDB</small> uses its database of syscalls to convert the name
  221. into the corresponding numeric code, but using the number directly
  222. may be useful if <small>GDB</small>&rsquo;s database does not have the complete
  223. list of syscalls on your system (e.g., because <small>GDB</small> lags
  224. behind the OS upgrades).
  225. </p>
  226. <p>You may specify a group of related syscalls to be caught at once using
  227. the <code>group:</code> syntax (<code>g:</code> is a shorter equivalent). For
  228. instance, on some platforms <small>GDB</small> allows you to catch all
  229. network related syscalls, by passing the argument <code>group:network</code>
  230. to <code>catch syscall</code>. Note that not all syscall groups are
  231. available in every system. You can use the command completion
  232. facilities (see <a href="Completion.html#Completion">command completion</a>) to list the
  233. syscall groups available on your environment.
  234. </p>
  235. <p>The example below illustrates how this command works if you don&rsquo;t provide
  236. arguments to it:
  237. </p>
  238. <div class="smallexample">
  239. <pre class="smallexample">(gdb) catch syscall
  240. Catchpoint 1 (syscall)
  241. (gdb) r
  242. Starting program: /tmp/catch-syscall
  243. Catchpoint 1 (call to syscall 'close'), \
  244. 0xffffe424 in __kernel_vsyscall ()
  245. (gdb) c
  246. Continuing.
  247. Catchpoint 1 (returned from syscall 'close'), \
  248. 0xffffe424 in __kernel_vsyscall ()
  249. (gdb)
  250. </pre></div>
  251. <p>Here is an example of catching a system call by name:
  252. </p>
  253. <div class="smallexample">
  254. <pre class="smallexample">(gdb) catch syscall chroot
  255. Catchpoint 1 (syscall 'chroot' [61])
  256. (gdb) r
  257. Starting program: /tmp/catch-syscall
  258. Catchpoint 1 (call to syscall 'chroot'), \
  259. 0xffffe424 in __kernel_vsyscall ()
  260. (gdb) c
  261. Continuing.
  262. Catchpoint 1 (returned from syscall 'chroot'), \
  263. 0xffffe424 in __kernel_vsyscall ()
  264. (gdb)
  265. </pre></div>
  266. <p>An example of specifying a system call numerically. In the case
  267. below, the syscall number has a corresponding entry in the XML
  268. file, so <small>GDB</small> finds its name and prints it:
  269. </p>
  270. <div class="smallexample">
  271. <pre class="smallexample">(gdb) catch syscall 252
  272. Catchpoint 1 (syscall(s) 'exit_group')
  273. (gdb) r
  274. Starting program: /tmp/catch-syscall
  275. Catchpoint 1 (call to syscall 'exit_group'), \
  276. 0xffffe424 in __kernel_vsyscall ()
  277. (gdb) c
  278. Continuing.
  279. Program exited normally.
  280. (gdb)
  281. </pre></div>
  282. <p>Here is an example of catching a syscall group:
  283. </p>
  284. <div class="smallexample">
  285. <pre class="smallexample">(gdb) catch syscall group:process
  286. Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
  287. 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
  288. 'exit_group' [252] 'waitid' [284] 'unshare' [310])
  289. (gdb) r
  290. Starting program: /tmp/catch-syscall
  291. Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
  292. from /lib64/ld-linux-x86-64.so.2
  293. (gdb) c
  294. Continuing.
  295. </pre></div>
  296. <p>However, there can be situations when there is no corresponding name
  297. in XML file for that syscall number. In this case, <small>GDB</small> prints
  298. a warning message saying that it was not able to find the syscall name,
  299. but the catchpoint will be set anyway. See the example below:
  300. </p>
  301. <div class="smallexample">
  302. <pre class="smallexample">(gdb) catch syscall 764
  303. warning: The number '764' does not represent a known syscall.
  304. Catchpoint 2 (syscall 764)
  305. (gdb)
  306. </pre></div>
  307. <p>If you configure <small>GDB</small> using the &lsquo;<samp>--without-expat</samp>&rsquo; option,
  308. it will not be able to display syscall names. Also, if your
  309. architecture does not have an XML file describing its system calls,
  310. you will not be able to see the syscall names. It is important to
  311. notice that these two features are used for accessing the syscall
  312. name database. In either case, you will see a warning like this:
  313. </p>
  314. <div class="smallexample">
  315. <pre class="smallexample">(gdb) catch syscall
  316. warning: Could not open &quot;syscalls/i386-linux.xml&quot;
  317. warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
  318. GDB will not be able to display syscall names.
  319. Catchpoint 1 (syscall)
  320. (gdb)
  321. </pre></div>
  322. <p>Of course, the file name will change depending on your architecture and system.
  323. </p>
  324. <p>Still using the example above, you can also try to catch a syscall by its
  325. number. In this case, you would see something like:
  326. </p>
  327. <div class="smallexample">
  328. <pre class="smallexample">(gdb) catch syscall 252
  329. Catchpoint 1 (syscall(s) 252)
  330. </pre></div>
  331. <p>Again, in this case <small>GDB</small> would not be able to display syscall&rsquo;s names.
  332. </p>
  333. </dd>
  334. <dt><code>fork</code></dt>
  335. <dd><a name="index-catch-fork"></a>
  336. <p>A call to <code>fork</code>.
  337. </p>
  338. </dd>
  339. <dt><code>vfork</code></dt>
  340. <dd><a name="index-catch-vfork"></a>
  341. <p>A call to <code>vfork</code>.
  342. </p>
  343. </dd>
  344. <dt><code>load <span class="roman">[</span><var>regexp</var><span class="roman">]</span></code></dt>
  345. <dt><code>unload <span class="roman">[</span><var>regexp</var><span class="roman">]</span></code></dt>
  346. <dd><a name="index-catch-load"></a>
  347. <a name="index-catch-unload"></a>
  348. <p>The loading or unloading of a shared library. If <var>regexp</var> is
  349. given, then the catchpoint will stop only if the regular expression
  350. matches one of the affected libraries.
  351. </p>
  352. </dd>
  353. <dt><code>signal <span class="roman">[</span><var>signal</var>&hellip; <span class="roman">|</span> &lsquo;<samp>all</samp>&rsquo;<span class="roman">]</span></code></dt>
  354. <dd><a name="index-catch-signal"></a>
  355. <p>The delivery of a signal.
  356. </p>
  357. <p>With no arguments, this catchpoint will catch any signal that is not
  358. used internally by <small>GDB</small>, specifically, all signals except
  359. &lsquo;<samp>SIGTRAP</samp>&rsquo; and &lsquo;<samp>SIGINT</samp>&rsquo;.
  360. </p>
  361. <p>With the argument &lsquo;<samp>all</samp>&rsquo;, all signals, including those used by
  362. <small>GDB</small>, will be caught. This argument cannot be used with other
  363. signal names.
  364. </p>
  365. <p>Otherwise, the arguments are a list of signal names as given to
  366. <code>handle</code> (see <a href="Signals.html#Signals">Signals</a>). Only signals specified in this list
  367. will be caught.
  368. </p>
  369. <p>One reason that <code>catch signal</code> can be more useful than
  370. <code>handle</code> is that you can attach commands and conditions to the
  371. catchpoint.
  372. </p>
  373. <p>When a signal is caught by a catchpoint, the signal&rsquo;s <code>stop</code> and
  374. <code>print</code> settings, as specified by <code>handle</code>, are ignored.
  375. However, whether the signal is still delivered to the inferior depends
  376. on the <code>pass</code> setting; this can be changed in the catchpoint&rsquo;s
  377. commands.
  378. </p>
  379. </dd>
  380. </dl>
  381. </dd>
  382. <dt><code>tcatch <var>event</var></code></dt>
  383. <dd><a name="index-tcatch"></a>
  384. <p>Set a catchpoint that is enabled only for one stop. The catchpoint is
  385. automatically deleted after the first time the event is caught.
  386. </p>
  387. </dd>
  388. </dl>
  389. <p>Use the <code>info break</code> command to list the current catchpoints.
  390. </p>
  391. <hr>
  392. <div class="header">
  393. <p>
  394. Next: <a href="Delete-Breaks.html#Delete-Breaks" accesskey="n" rel="next">Delete Breaks</a>, Previous: <a href="Set-Watchpoints.html#Set-Watchpoints" accesskey="p" rel="prev">Set Watchpoints</a>, Up: <a href="Breakpoints.html#Breakpoints" accesskey="u" rel="up">Breakpoints</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>
  395. </div>
  396. </body>
  397. </html>