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.

415 lines
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>Commands In Guile (Debugging with GDB)</title>
  17. <meta name="description" content="Commands In Guile (Debugging with GDB)">
  18. <meta name="keywords" content="Commands In Guile (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="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="Parameters-In-Guile.html#Parameters-In-Guile" rel="next" title="Parameters In Guile">
  27. <link href="Writing-a-Guile-Pretty_002dPrinter.html#Writing-a-Guile-Pretty_002dPrinter" rel="prev" title="Writing a Guile Pretty-Printer">
  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="Commands-In-Guile"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Parameters-In-Guile.html#Parameters-In-Guile" accesskey="n" rel="next">Parameters In Guile</a>, Previous: <a href="Writing-a-Guile-Pretty_002dPrinter.html#Writing-a-Guile-Pretty_002dPrinter" accesskey="p" rel="prev">Writing a Guile Pretty-Printer</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile 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="Commands-In-Guile-1"></a>
  64. <h4 class="subsubsection">23.3.3.11 Commands In Guile</h4>
  65. <a name="index-commands-in-guile"></a>
  66. <a name="index-guile-commands-1"></a>
  67. <p>You can implement new <small>GDB</small> CLI commands in Guile. A CLI
  68. command object is created with the <code>make-command</code> Guile function,
  69. and added to <small>GDB</small> with the <code>register-command!</code> Guile function.
  70. This two-step approach is taken to separate out the side-effect of adding
  71. the command to <small>GDB</small> from <code>make-command</code>.
  72. </p>
  73. <p>There is no support for multi-line commands, that is commands that
  74. consist of multiple lines and are terminated with <code>end</code>.
  75. </p>
  76. <dl>
  77. <dt><a name="index-_0028make_002dcommand"></a>Scheme Procedure: <strong>(make-command</strong> <em>name <span class="roman">[</span>#:invoke invoke] <span class="roman">[</span>#:command-class command-class<span class="roman">]</span> <span class="roman">[</span>#:completer-class completer] <span class="roman">[</span>#:prefix? prefix<span class="roman">]</span> <span class="roman">[</span>#:doc doc-string])</em></dt>
  78. <dd>
  79. <p>The argument <var>name</var> is the name of the command. If <var>name</var> consists of
  80. multiple words, then the initial words are looked for as prefix
  81. commands. In this case, if one of the prefix commands does not exist,
  82. an exception is raised.
  83. </p>
  84. <p>The result is the <code>&lt;gdb:command&gt;</code> object representing the command.
  85. The command is not usable until it has been registered with <small>GDB</small>
  86. with <code>register-command!</code>.
  87. </p>
  88. <p>The rest of the arguments are optional.
  89. </p>
  90. <p>The argument <var>invoke</var> is a procedure of three arguments: <var>self</var>,
  91. <var>args</var> and <var>from-tty</var>. The argument <var>self</var> is the
  92. <code>&lt;gdb:command&gt;</code> object representing the command.
  93. The argument <var>args</var> is a string representing the arguments passed to
  94. the command, after leading and trailing whitespace has been stripped.
  95. The argument <var>from-tty</var> is a boolean flag and specifies whether the
  96. command should consider itself to have been originated from the user
  97. invoking it interactively. If this function throws an exception,
  98. it is turned into a <small>GDB</small> <code>error</code> call.
  99. Otherwise, the return value is ignored.
  100. </p>
  101. <p>The argument <var>command-class</var> is one of the &lsquo;<samp>COMMAND_</samp>&rsquo; constants
  102. defined below. This argument tells <small>GDB</small> how to categorize the
  103. new command in the help system. The default is <code>COMMAND_NONE</code>.
  104. </p>
  105. <p>The argument <var>completer</var> is either <code>#f</code>, one of the &lsquo;<samp>COMPLETE_</samp>&rsquo;
  106. constants defined below, or a procedure, also defined below.
  107. This argument tells <small>GDB</small> how to perform completion
  108. for this command. If not provided or if the value is <code>#f</code>,
  109. then no completion is performed on the command.
  110. </p>
  111. <p>The argument <var>prefix</var> is a boolean flag indicating whether the new
  112. command is a prefix command; sub-commands of this command may be
  113. registered.
  114. </p>
  115. <p>The argument <var>doc-string</var> is help text for the new command.
  116. If no documentation string is provided, the default value &ldquo;This command is
  117. not documented.&rdquo; is used.
  118. </p></dd></dl>
  119. <dl>
  120. <dt><a name="index-register_002dcommand_0021"></a>Scheme Procedure: <strong>register-command!</strong> <em>command</em></dt>
  121. <dd><p>Add <var>command</var>, a <code>&lt;gdb:command&gt;</code> object, to <small>GDB</small>&rsquo;s
  122. list of commands.
  123. It is an error to register a command more than once.
  124. The result is unspecified.
  125. </p></dd></dl>
  126. <dl>
  127. <dt><a name="index-command_003f"></a>Scheme Procedure: <strong>command?</strong> <em>object</em></dt>
  128. <dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:command&gt;</code> object.
  129. Otherwise return <code>#f</code>.
  130. </p></dd></dl>
  131. <a name="index-don_0027t-repeat-Guile-command"></a>
  132. <dl>
  133. <dt><a name="index-dont_002drepeat"></a>Scheme Procedure: <strong>dont-repeat</strong></dt>
  134. <dd><p>By default, a <small>GDB</small> command is repeated when the user enters a
  135. blank line at the command prompt. A command can suppress this
  136. behavior by invoking the <code>dont-repeat</code> function. This is similar
  137. to the user command <code>dont-repeat</code>, see <a href="Define.html#Define">dont-repeat</a>.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-string_002d_003eargv"></a>Scheme Procedure: <strong>string-&gt;argv</strong> <em>string</em></dt>
  141. <dd><p>Convert a string to a list of strings split up according to
  142. <small>GDB</small>&rsquo;s argv parsing rules.
  143. It is recommended to use this for consistency.
  144. Arguments are separated by spaces and may be quoted.
  145. Example:
  146. </p>
  147. <div class="smallexample">
  148. <pre class="smallexample">scheme@(guile-user)&gt; (string-&gt;argv &quot;1 2\\ \\\&quot;3 '4 \&quot;5' \&quot;6 '7\&quot;&quot;)
  149. $1 = (&quot;1&quot; &quot;2 \&quot;3&quot; &quot;4 \&quot;5&quot; &quot;6 '7&quot;)
  150. </pre></div>
  151. </dd></dl>
  152. <dl>
  153. <dt><a name="index-throw_002duser_002derror"></a>Scheme Procedure: <strong>throw-user-error</strong> <em>message . args</em></dt>
  154. <dd><p>Throw a <code>gdb:user-error</code> exception.
  155. The argument <var>message</var> is the error message as a format string, like the
  156. <var>fmt</var> argument to the <code>format</code> Scheme function.
  157. See <a href="http://www.gnu.org/software/guile/manual/html_node/Formatted-Output.html#Formatted-Output">Formatted Output</a> in <cite>GNU Guile Reference Manual</cite>.
  158. The argument <var>args</var> is a list of the optional arguments of <var>message</var>.
  159. </p>
  160. <p>This is used when the command detects a user error of some kind,
  161. say a bad command argument.
  162. </p>
  163. <div class="smallexample">
  164. <pre class="smallexample">(gdb) guile (use-modules (gdb))
  165. (gdb) guile
  166. (register-command! (make-command &quot;test-user-error&quot;
  167. #:command-class COMMAND_OBSCURE
  168. #:invoke (lambda (self arg from-tty)
  169. (throw-user-error &quot;Bad argument ~a&quot; arg))))
  170. end
  171. (gdb) test-user-error ugh
  172. ERROR: Bad argument ugh
  173. </pre></div>
  174. </dd></dl>
  175. <a name="index-completion-of-Guile-commands"></a>
  176. <dl>
  177. <dt><a name="index-self"></a>completer: <strong>self</strong> <em>text word</em></dt>
  178. <dd><p>If the <var>completer</var> option to <code>make-command</code> is a procedure,
  179. it takes three arguments: <var>self</var> which is the <code>&lt;gdb:command&gt;</code>
  180. object, and <var>text</var> and <var>word</var> which are both strings.
  181. The argument <var>text</var> holds the complete command line up to the cursor&rsquo;s
  182. location. The argument <var>word</var> holds the last word of the command line;
  183. this is computed using a word-breaking heuristic.
  184. </p>
  185. <p>All forms of completion are handled by this function, that is,
  186. the <tt class="key">TAB</tt> and <tt class="key">M-?</tt> key bindings (see <a href="Completion.html#Completion">Completion</a>),
  187. and the <code>complete</code> command (see <a href="Help.html#Help">complete</a>).
  188. </p>
  189. <p>This procedure can return several kinds of values:
  190. </p>
  191. <ul>
  192. <li> If the return value is a list, the contents of the list are used as the
  193. completions. It is up to <var>completer</var> to ensure that the
  194. contents actually do complete the word. An empty list is
  195. allowed, it means that there were no completions available. Only
  196. string elements of the list are used; other elements in the
  197. list are ignored.
  198. </li><li> If the return value is a <code>&lt;gdb:iterator&gt;</code> object, it is iterated over to
  199. obtain the completions. It is up to <code>completer-procedure</code> to ensure
  200. that the results actually do complete the word. Only
  201. string elements of the result are used; other elements in the
  202. sequence are ignored.
  203. </li><li> All other results are treated as though there were no available
  204. completions.
  205. </li></ul>
  206. </dd></dl>
  207. <p>When a new command is registered, it will have been declared as a member of
  208. some general class of commands. This is used to classify top-level
  209. commands in the on-line help system; note that prefix commands are not
  210. listed under their own category but rather that of their top-level
  211. command. The available classifications are represented by constants
  212. defined in the <code>gdb</code> module:
  213. </p>
  214. <dl compact="compact">
  215. <dt><code>COMMAND_NONE</code>
  216. <a name="index-COMMAND_005fNONE-1"></a>
  217. </dt>
  218. <dd><p>The command does not belong to any particular class. A command in
  219. this category will not be displayed in any of the help categories.
  220. This is the default.
  221. </p>
  222. </dd>
  223. <dt><code>COMMAND_RUNNING</code>
  224. <a name="index-COMMAND_005fRUNNING-1"></a>
  225. </dt>
  226. <dd><p>The command is related to running the inferior. For example,
  227. <code>start</code>, <code>step</code>, and <code>continue</code> are in this category.
  228. Type <kbd>help running</kbd> at the <small>GDB</small> prompt to see a list of
  229. commands in this category.
  230. </p>
  231. </dd>
  232. <dt><code>COMMAND_DATA</code>
  233. <a name="index-COMMAND_005fDATA-1"></a>
  234. </dt>
  235. <dd><p>The command is related to data or variables. For example,
  236. <code>call</code>, <code>find</code>, and <code>print</code> are in this category. Type
  237. <kbd>help data</kbd> at the <small>GDB</small> prompt to see a list of commands
  238. in this category.
  239. </p>
  240. </dd>
  241. <dt><code>COMMAND_STACK</code>
  242. <a name="index-COMMAND_005fSTACK-1"></a>
  243. </dt>
  244. <dd><p>The command has to do with manipulation of the stack. For example,
  245. <code>backtrace</code>, <code>frame</code>, and <code>return</code> are in this
  246. category. Type <kbd>help stack</kbd> at the <small>GDB</small> prompt to see a
  247. list of commands in this category.
  248. </p>
  249. </dd>
  250. <dt><code>COMMAND_FILES</code>
  251. <a name="index-COMMAND_005fFILES-1"></a>
  252. </dt>
  253. <dd><p>This class is used for file-related commands. For example,
  254. <code>file</code>, <code>list</code> and <code>section</code> are in this category.
  255. Type <kbd>help files</kbd> at the <small>GDB</small> prompt to see a list of
  256. commands in this category.
  257. </p>
  258. </dd>
  259. <dt><code>COMMAND_SUPPORT</code>
  260. <a name="index-COMMAND_005fSUPPORT-1"></a>
  261. </dt>
  262. <dd><p>This should be used for &ldquo;support facilities&rdquo;, generally meaning
  263. things that are useful to the user when interacting with <small>GDB</small>,
  264. but not related to the state of the inferior. For example,
  265. <code>help</code>, <code>make</code>, and <code>shell</code> are in this category. Type
  266. <kbd>help support</kbd> at the <small>GDB</small> prompt to see a list of
  267. commands in this category.
  268. </p>
  269. </dd>
  270. <dt><code>COMMAND_STATUS</code>
  271. <a name="index-COMMAND_005fSTATUS-1"></a>
  272. </dt>
  273. <dd><p>The command is an &lsquo;<samp>info</samp>&rsquo;-related command, that is, related to the
  274. state of <small>GDB</small> itself. For example, <code>info</code>, <code>macro</code>,
  275. and <code>show</code> are in this category. Type <kbd>help status</kbd> at the
  276. <small>GDB</small> prompt to see a list of commands in this category.
  277. </p>
  278. </dd>
  279. <dt><code>COMMAND_BREAKPOINTS</code>
  280. <a name="index-COMMAND_005fBREAKPOINTS-1"></a>
  281. </dt>
  282. <dd><p>The command has to do with breakpoints. For example, <code>break</code>,
  283. <code>clear</code>, and <code>delete</code> are in this category. Type <kbd>help
  284. breakpoints</kbd> at the <small>GDB</small> prompt to see a list of commands in
  285. this category.
  286. </p>
  287. </dd>
  288. <dt><code>COMMAND_TRACEPOINTS</code>
  289. <a name="index-COMMAND_005fTRACEPOINTS-1"></a>
  290. </dt>
  291. <dd><p>The command has to do with tracepoints. For example, <code>trace</code>,
  292. <code>actions</code>, and <code>tfind</code> are in this category. Type
  293. <kbd>help tracepoints</kbd> at the <small>GDB</small> prompt to see a list of
  294. commands in this category.
  295. </p>
  296. </dd>
  297. <dt><code>COMMAND_USER</code>
  298. <a name="index-COMMAND_005fUSER-1"></a>
  299. </dt>
  300. <dd><p>The command is a general purpose command for the user, and typically
  301. does not fit in one of the other categories.
  302. Type <kbd>help user-defined</kbd> at the <small>GDB</small> prompt to see
  303. a list of commands in this category, as well as the list of gdb macros
  304. (see <a href="Sequences.html#Sequences">Sequences</a>).
  305. </p>
  306. </dd>
  307. <dt><code>COMMAND_OBSCURE</code>
  308. <a name="index-COMMAND_005fOBSCURE-1"></a>
  309. </dt>
  310. <dd><p>The command is only used in unusual circumstances, or is not of
  311. general interest to users. For example, <code>checkpoint</code>,
  312. <code>fork</code>, and <code>stop</code> are in this category. Type <kbd>help
  313. obscure</kbd> at the <small>GDB</small> prompt to see a list of commands in this
  314. category.
  315. </p>
  316. </dd>
  317. <dt><code>COMMAND_MAINTENANCE</code>
  318. <a name="index-COMMAND_005fMAINTENANCE-1"></a>
  319. </dt>
  320. <dd><p>The command is only useful to <small>GDB</small> maintainers. The
  321. <code>maintenance</code> and <code>flushregs</code> commands are in this category.
  322. Type <kbd>help internals</kbd> at the <small>GDB</small> prompt to see a list of
  323. commands in this category.
  324. </p></dd>
  325. </dl>
  326. <p>A new command can use a predefined completion function, either by
  327. specifying it via an argument at initialization, or by returning it
  328. from the <code>completer</code> procedure. These predefined completion
  329. constants are all defined in the <code>gdb</code> module:
  330. </p>
  331. <dl compact="compact">
  332. <dt><code>COMPLETE_NONE</code>
  333. <a name="index-COMPLETE_005fNONE-1"></a>
  334. </dt>
  335. <dd><p>This constant means that no completion should be done.
  336. </p>
  337. </dd>
  338. <dt><code>COMPLETE_FILENAME</code>
  339. <a name="index-COMPLETE_005fFILENAME-1"></a>
  340. </dt>
  341. <dd><p>This constant means that filename completion should be performed.
  342. </p>
  343. </dd>
  344. <dt><code>COMPLETE_LOCATION</code>
  345. <a name="index-COMPLETE_005fLOCATION-1"></a>
  346. </dt>
  347. <dd><p>This constant means that location completion should be done.
  348. See <a href="Specify-Location.html#Specify-Location">Specify Location</a>.
  349. </p>
  350. </dd>
  351. <dt><code>COMPLETE_COMMAND</code>
  352. <a name="index-COMPLETE_005fCOMMAND-1"></a>
  353. </dt>
  354. <dd><p>This constant means that completion should examine <small>GDB</small>
  355. command names.
  356. </p>
  357. </dd>
  358. <dt><code>COMPLETE_SYMBOL</code>
  359. <a name="index-COMPLETE_005fSYMBOL-1"></a>
  360. </dt>
  361. <dd><p>This constant means that completion should be done using symbol names
  362. as the source.
  363. </p>
  364. </dd>
  365. <dt><code>COMPLETE_EXPRESSION</code>
  366. <a name="index-COMPLETE_005fEXPRESSION-1"></a>
  367. </dt>
  368. <dd><p>This constant means that completion should be done on expressions.
  369. Often this means completing on symbol names, but some language
  370. parsers also have support for completing on field names.
  371. </p></dd>
  372. </dl>
  373. <p>The following code snippet shows how a trivial CLI command can be
  374. implemented in Guile:
  375. </p>
  376. <div class="smallexample">
  377. <pre class="smallexample">(gdb) guile
  378. (register-command! (make-command &quot;hello-world&quot;
  379. #:command-class COMMAND_USER
  380. #:doc &quot;Greet the whole world.&quot;
  381. #:invoke (lambda (self args from-tty) (display &quot;Hello, World!\n&quot;))))
  382. end
  383. (gdb) hello-world
  384. Hello, World!
  385. </pre></div>
  386. <hr>
  387. <div class="header">
  388. <p>
  389. Next: <a href="Parameters-In-Guile.html#Parameters-In-Guile" accesskey="n" rel="next">Parameters In Guile</a>, Previous: <a href="Writing-a-Guile-Pretty_002dPrinter.html#Writing-a-Guile-Pretty_002dPrinter" accesskey="p" rel="prev">Writing a Guile Pretty-Printer</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile 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>
  390. </div>
  391. </body>
  392. </html>