| <html lang="en"> |
| <head> |
| <title>Commands In Guile - Debugging with GDB</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Debugging with GDB"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Guile-API.html#Guile-API" title="Guile API"> |
| <link rel="prev" href="Writing-a-Guile-Pretty_002dPrinter.html#Writing-a-Guile-Pretty_002dPrinter" title="Writing a Guile Pretty-Printer"> |
| <link rel="next" href="Parameters-In-Guile.html#Parameters-In-Guile" title="Parameters In Guile"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1988-2019 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software'' and ``Free Software Needs |
| Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' |
| and with the Back-Cover Texts as in (a) below. |
| |
| (a) The FSF's Back-Cover Text is: ``You are free to copy and modify |
| this GNU Manual. Buying copies from GNU Press supports the FSF in |
| developing GNU and promoting software freedom.'' |
| --> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Commands-In-Guile"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="Parameters-In-Guile.html#Parameters-In-Guile">Parameters In Guile</a>, |
| Previous: <a rel="previous" accesskey="p" href="Writing-a-Guile-Pretty_002dPrinter.html#Writing-a-Guile-Pretty_002dPrinter">Writing a Guile Pretty-Printer</a>, |
| Up: <a rel="up" accesskey="u" href="Guile-API.html#Guile-API">Guile API</a> |
| <hr> |
| </div> |
| |
| <h5 class="subsubsection">23.3.3.11 Commands In Guile</h5> |
| |
| <p><a name="index-commands-in-guile-2606"></a><a name="index-guile-commands-2607"></a>You can implement new <span class="sc">gdb</span> CLI commands in Guile. A CLI |
| command object is created with the <code>make-command</code> Guile function, |
| and added to <span class="sc">gdb</span> with the <code>register-command!</code> Guile function. |
| This two-step approach is taken to separate out the side-effect of adding |
| the command to <span class="sc">gdb</span> from <code>make-command</code>. |
| |
| <p>There is no support for multi-line commands, that is commands that |
| consist of multiple lines and are terminated with <code>end</code>. |
| |
| <!-- TODO: line length --> |
| <div class="defun"> |
| — Scheme Procedure: <b>(</b><var>make-command name </var><span class="roman">[</span><var>#:invoke invoke</var>] <span class="roman">[</span><var>#:command-class command-class</var><span class="roman">]</span> <span class="roman">[</span><var>#:completer-class completer</var>] <span class="roman">[</span><var>#:prefix? prefix</var><span class="roman">]</span> <span class="roman">[</span><var>#:doc doc-string</var>])<var><a name="index-g_t_0028-2608"></a></var><br> |
| <blockquote> |
| <p>The argument <var>name</var> is the name of the command. If <var>name</var> consists of |
| multiple words, then the initial words are looked for as prefix |
| commands. In this case, if one of the prefix commands does not exist, |
| an exception is raised. |
| |
| <p>The result is the <code><gdb:command></code> object representing the command. |
| The command is not usable until it has been registered with <span class="sc">gdb</span> |
| with <code>register-command!</code>. |
| |
| <p>The rest of the arguments are optional. |
| |
| <p>The argument <var>invoke</var> is a procedure of three arguments: <var>self</var>, |
| <var>args</var> and <var>from-tty</var>. The argument <var>self</var> is the |
| <code><gdb:command></code> object representing the command. |
| The argument <var>args</var> is a string representing the arguments passed to |
| the command, after leading and trailing whitespace has been stripped. |
| The argument <var>from-tty</var> is a boolean flag and specifies whether the |
| command should consider itself to have been originated from the user |
| invoking it interactively. If this function throws an exception, |
| it is turned into a <span class="sc">gdb</span> <code>error</code> call. |
| Otherwise, the return value is ignored. |
| |
| <p>The argument <var>command-class</var> is one of the ‘<samp><span class="samp">COMMAND_</span></samp>’ constants |
| defined below. This argument tells <span class="sc">gdb</span> how to categorize the |
| new command in the help system. The default is <code>COMMAND_NONE</code>. |
| |
| <p>The argument <var>completer</var> is either <code>#f</code>, one of the ‘<samp><span class="samp">COMPLETE_</span></samp>’ |
| constants defined below, or a procedure, also defined below. |
| This argument tells <span class="sc">gdb</span> how to perform completion |
| for this command. If not provided or if the value is <code>#f</code>, |
| then no completion is performed on the command. |
| |
| <p>The argument <var>prefix</var> is a boolean flag indicating whether the new |
| command is a prefix command; sub-commands of this command may be |
| registered. |
| |
| <p>The argument <var>doc-string</var> is help text for the new command. |
| If no documentation string is provided, the default value “This command is |
| not documented.” is used. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>register-command!</b><var> command<a name="index-register_002dcommand_0021-2609"></a></var><br> |
| <blockquote><p>Add <var>command</var>, a <code><gdb:command></code> object, to <span class="sc">gdb</span>'s |
| list of commands. |
| It is an error to register a command more than once. |
| The result is unspecified. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>command?</b><var> object<a name="index-command_003f-2610"></a></var><br> |
| <blockquote><p>Return <code>#t</code> if <var>object</var> is a <code><gdb:command></code> object. |
| Otherwise return <code>#f</code>. |
| </p></blockquote></div> |
| |
| <p><a name="index-don_0027t-repeat-Guile-command-2611"></a> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>dont-repeat</b><var><a name="index-dont_002drepeat-2612"></a></var><br> |
| <blockquote><p>By default, a <span class="sc">gdb</span> command is repeated when the user enters a |
| blank line at the command prompt. A command can suppress this |
| behavior by invoking the <code>dont-repeat</code> function. This is similar |
| to the user command <code>dont-repeat</code>, see <a href="Define.html#Define">dont-repeat</a>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>string->argv</b><var> string<a name="index-string_002d_003eargv-2613"></a></var><br> |
| <blockquote><p>Convert a string to a list of strings split up according to |
| <span class="sc">gdb</span>'s argv parsing rules. |
| It is recommended to use this for consistency. |
| Arguments are separated by spaces and may be quoted. |
| Example: |
| |
| <pre class="smallexample"> scheme@(guile-user)> (string->argv "1 2\\ \\\"3 '4 \"5' \"6 '7\"") |
| $1 = ("1" "2 \"3" "4 \"5" "6 '7") |
| </pre> |
| </blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>throw-user-error</b><var> message . args<a name="index-throw_002duser_002derror-2614"></a></var><br> |
| <blockquote><p>Throw a <code>gdb:user-error</code> exception. |
| The argument <var>message</var> is the error message as a format string, like the |
| <var>fmt</var> argument to the <code>format</code> Scheme function. |
| See <a href="../guile/Formatted-Output.html#Formatted-Output">Formatted Output</a>. |
| The argument <var>args</var> is a list of the optional arguments of <var>message</var>. |
| |
| <p>This is used when the command detects a user error of some kind, |
| say a bad command argument. |
| |
| <pre class="smallexample"> (gdb) guile (use-modules (gdb)) |
| (gdb) guile |
| (register-command! (make-command "test-user-error" |
| #:command-class COMMAND_OBSCURE |
| #:invoke (lambda (self arg from-tty) |
| (throw-user-error "Bad argument ~a" arg)))) |
| end |
| (gdb) test-user-error ugh |
| ERROR: Bad argument ugh |
| </pre> |
| </blockquote></div> |
| |
| <p><a name="index-completion-of-Guile-commands-2615"></a> |
| |
| <div class="defun"> |
| — completer: <b>self</b><var> text word<a name="index-self-2616"></a></var><br> |
| <blockquote><p>If the <var>completer</var> option to <code>make-command</code> is a procedure, |
| it takes three arguments: <var>self</var> which is the <code><gdb:command></code> |
| object, and <var>text</var> and <var>word</var> which are both strings. |
| The argument <var>text</var> holds the complete command line up to the cursor's |
| location. The argument <var>word</var> holds the last word of the command line; |
| this is computed using a word-breaking heuristic. |
| |
| <p>All forms of completion are handled by this function, that is, |
| the <TAB> and <M-?> key bindings (see <a href="Completion.html#Completion">Completion</a>), |
| and the <code>complete</code> command (see <a href="Help.html#Help">complete</a>). |
| |
| <p>This procedure can return several kinds of values: |
| |
| <ul> |
| <li>If the return value is a list, the contents of the list are used as the |
| completions. It is up to <var>completer</var> to ensure that the |
| contents actually do complete the word. An empty list is |
| allowed, it means that there were no completions available. Only |
| string elements of the list are used; other elements in the |
| list are ignored. |
| |
| <li>If the return value is a <code><gdb:iterator></code> object, it is iterated over to |
| obtain the completions. It is up to <code>completer-procedure</code> to ensure |
| that the results actually do complete the word. Only |
| string elements of the result are used; other elements in the |
| sequence are ignored. |
| |
| <li>All other results are treated as though there were no available |
| completions. |
| </ul> |
| </p></blockquote></div> |
| |
| <p>When a new command is registered, it will have been declared as a member of |
| some general class of commands. This is used to classify top-level |
| commands in the on-line help system; note that prefix commands are not |
| listed under their own category but rather that of their top-level |
| command. The available classifications are represented by constants |
| defined in the <code>gdb</code> module: |
| |
| <dl> |
| <dt><code>COMMAND_NONE</code><a name="index-COMMAND_005fNONE-2617"></a><dd>The command does not belong to any particular class. A command in |
| this category will not be displayed in any of the help categories. |
| This is the default. |
| |
| <br><dt><code>COMMAND_RUNNING</code><a name="index-COMMAND_005fRUNNING-2618"></a><dd>The command is related to running the inferior. For example, |
| <code>start</code>, <code>step</code>, and <code>continue</code> are in this category. |
| Type <kbd>help running</kbd> at the <span class="sc">gdb</span> prompt to see a list of |
| commands in this category. |
| |
| <br><dt><code>COMMAND_DATA</code><a name="index-COMMAND_005fDATA-2619"></a><dd>The command is related to data or variables. For example, |
| <code>call</code>, <code>find</code>, and <code>print</code> are in this category. Type |
| <kbd>help data</kbd> at the <span class="sc">gdb</span> prompt to see a list of commands |
| in this category. |
| |
| <br><dt><code>COMMAND_STACK</code><a name="index-COMMAND_005fSTACK-2620"></a><dd>The command has to do with manipulation of the stack. For example, |
| <code>backtrace</code>, <code>frame</code>, and <code>return</code> are in this |
| category. Type <kbd>help stack</kbd> at the <span class="sc">gdb</span> prompt to see a |
| list of commands in this category. |
| |
| <br><dt><code>COMMAND_FILES</code><a name="index-COMMAND_005fFILES-2621"></a><dd>This class is used for file-related commands. For example, |
| <code>file</code>, <code>list</code> and <code>section</code> are in this category. |
| Type <kbd>help files</kbd> at the <span class="sc">gdb</span> prompt to see a list of |
| commands in this category. |
| |
| <br><dt><code>COMMAND_SUPPORT</code><a name="index-COMMAND_005fSUPPORT-2622"></a><dd>This should be used for “support facilities”, generally meaning |
| things that are useful to the user when interacting with <span class="sc">gdb</span>, |
| but not related to the state of the inferior. For example, |
| <code>help</code>, <code>make</code>, and <code>shell</code> are in this category. Type |
| <kbd>help support</kbd> at the <span class="sc">gdb</span> prompt to see a list of |
| commands in this category. |
| |
| <br><dt><code>COMMAND_STATUS</code><a name="index-COMMAND_005fSTATUS-2623"></a><dd>The command is an ‘<samp><span class="samp">info</span></samp>’-related command, that is, related to the |
| state of <span class="sc">gdb</span> itself. For example, <code>info</code>, <code>macro</code>, |
| and <code>show</code> are in this category. Type <kbd>help status</kbd> at the |
| <span class="sc">gdb</span> prompt to see a list of commands in this category. |
| |
| <br><dt><code>COMMAND_BREAKPOINTS</code><a name="index-COMMAND_005fBREAKPOINTS-2624"></a><dd>The command has to do with breakpoints. For example, <code>break</code>, |
| <code>clear</code>, and <code>delete</code> are in this category. Type <kbd>help |
| breakpoints</kbd> at the <span class="sc">gdb</span> prompt to see a list of commands in |
| this category. |
| |
| <br><dt><code>COMMAND_TRACEPOINTS</code><a name="index-COMMAND_005fTRACEPOINTS-2625"></a><dd>The command has to do with tracepoints. For example, <code>trace</code>, |
| <code>actions</code>, and <code>tfind</code> are in this category. Type |
| <kbd>help tracepoints</kbd> at the <span class="sc">gdb</span> prompt to see a list of |
| commands in this category. |
| |
| <br><dt><code>COMMAND_USER</code><a name="index-COMMAND_005fUSER-2626"></a><dd>The command is a general purpose command for the user, and typically |
| does not fit in one of the other categories. |
| Type <kbd>help user-defined</kbd> at the <span class="sc">gdb</span> prompt to see |
| a list of commands in this category, as well as the list of gdb macros |
| (see <a href="Sequences.html#Sequences">Sequences</a>). |
| |
| <br><dt><code>COMMAND_OBSCURE</code><a name="index-COMMAND_005fOBSCURE-2627"></a><dd>The command is only used in unusual circumstances, or is not of |
| general interest to users. For example, <code>checkpoint</code>, |
| <code>fork</code>, and <code>stop</code> are in this category. Type <kbd>help |
| obscure</kbd> at the <span class="sc">gdb</span> prompt to see a list of commands in this |
| category. |
| |
| <br><dt><code>COMMAND_MAINTENANCE</code><a name="index-COMMAND_005fMAINTENANCE-2628"></a><dd>The command is only useful to <span class="sc">gdb</span> maintainers. The |
| <code>maintenance</code> and <code>flushregs</code> commands are in this category. |
| Type <kbd>help internals</kbd> at the <span class="sc">gdb</span> prompt to see a list of |
| commands in this category. |
| </dl> |
| |
| <p>A new command can use a predefined completion function, either by |
| specifying it via an argument at initialization, or by returning it |
| from the <code>completer</code> procedure. These predefined completion |
| constants are all defined in the <code>gdb</code> module: |
| |
| <dl> |
| <dt><code>COMPLETE_NONE</code><a name="index-COMPLETE_005fNONE-2629"></a><dd>This constant means that no completion should be done. |
| |
| <br><dt><code>COMPLETE_FILENAME</code><a name="index-COMPLETE_005fFILENAME-2630"></a><dd>This constant means that filename completion should be performed. |
| |
| <br><dt><code>COMPLETE_LOCATION</code><a name="index-COMPLETE_005fLOCATION-2631"></a><dd>This constant means that location completion should be done. |
| See <a href="Specify-Location.html#Specify-Location">Specify Location</a>. |
| |
| <br><dt><code>COMPLETE_COMMAND</code><a name="index-COMPLETE_005fCOMMAND-2632"></a><dd>This constant means that completion should examine <span class="sc">gdb</span> |
| command names. |
| |
| <br><dt><code>COMPLETE_SYMBOL</code><a name="index-COMPLETE_005fSYMBOL-2633"></a><dd>This constant means that completion should be done using symbol names |
| as the source. |
| |
| <br><dt><code>COMPLETE_EXPRESSION</code><a name="index-COMPLETE_005fEXPRESSION-2634"></a><dd>This constant means that completion should be done on expressions. |
| Often this means completing on symbol names, but some language |
| parsers also have support for completing on field names. |
| </dl> |
| |
| <p>The following code snippet shows how a trivial CLI command can be |
| implemented in Guile: |
| |
| <pre class="smallexample"> (gdb) guile |
| (register-command! (make-command "hello-world" |
| #:command-class COMMAND_USER |
| #:doc "Greet the whole world." |
| #:invoke (lambda (self args from-tty) (display "Hello, World!\n")))) |
| end |
| (gdb) hello-world |
| Hello, World! |
| </pre> |
| </body></html> |
| |