https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115468
Bug ID: 115468 Summary: Convenience functions defined in gdbinit.in does not handle spaces in expression correctly Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: user202729 at protonmail dot com Target Milestone: --- There's a file gcc/gdbinit.in in the source tree that defines a few convenience functions, for example: define pp eval "set $debug_arg = $%s", $argc ? "arg0" : "" call debug ($debug_arg) end to be used as "pp" to pretty-print the last-printed value, or "pp [expression]" to pretty-print the expression. However, this definition will mysteriously error out when the expression contains a space because the parts after the space will be put in arg1, etc. I can think of some ways to fix this. 1. Modify the definition of pp to the following: define pp if $argc == 0 set $debug_arg = $ else set $tmp = "set $debug_arg = " set $i = 0 while $i < $argc eval "set $tmp = \"%s $arg%d\"", $tmp, $i set $i = $i + 1 end eval "%s", $tmp end call debug ($debug_arg) end But the problem is that we need to repeat this to every other function, which is not elegant. (string concatenation technique was from https://stackoverflow.com/a/40918181/) 2. Throw an error when argc >= 2. Also not elegant. 3. Edit gdb to implement something like "$arg@" which is equivalent to "$arg0 $arg1 ... $arg[$argc-1]" 4. Use Python. What do you think?