Search code examples
gdb

Does gdb support comments in the command line (gdb prompt)?


I want to comment gdb commands in the command prompt at the end of the line for two use cases:

  1. Writing a tutorial
  2. Documenting a gdb command file for automatic execution

While gdb command files seem to support comments via the hash (#) symbol I cannot find any command marker for the gdb command line:

(gdb) print 1
$2 = 1
(gdb) print 1   // comment
A syntax error in expression, near `/ comment'.
(gdb) print 1   -- comment
A syntax error in expression, near `comment'.
(gdb) print 1   # comment
Invalid character '#' in expression.
(gdb) print 1   ; comment
Invalid character ';' in expression.
(gdb) print 1   /* comment */
No symbol "comment" in current context.

How can I append comments?

Edit: According to the gdb documentation

Any text from a # to the end of the line is a comment; it does nothing. This is useful mainly in command files

I am not sure why it doesn't work as documented...


Solution

  • You can use it on its own line, but not at the end of a line. E.g.:

    (gdb) # foo
    (gdb) print "foo"
    $1 = "foo"