gdb command argument lexing is broken, implement our own lexer
Author: k4lizenCreated Sep 29, 2026Updated Sep 29, 2026
See detailed explanation: https://sourceware.org/bugzilla/show_bug.cgi?id=34690 .
Here is how print and similar commands work:
Here is how it is for us:
This is due to how gdb.string_to_argv() works, and I personally can't think of any easy workarounds to fix it.
The first example I will fix since it's really pathological. But I don't think we have another way forward than to
just hand roll our own lexer.
It should be able to properly handle these:
cool 1 2cool 1+1 2+2cool 'weird symbol' func()cool 'weird symbol'+3 ((int*)func())+4cool -cool-flag cool-subcommand 'weird symbol'+3I will not invoke gdb.parse_and_eval() on "-cool-flag" and "cool-subcommand" as I will just directly pass them through to argparse, I just need the lexing to work in a way that doesn't mess up the 'weird symbol'+3 expression.
Source: pwndbg/pwndbg