vuvova / gdb-tools

Various tools to improve the gdb experience
BSD 3-Clause "New" or "Revised" License
123 stars 17 forks source link

Member variables starting with "_" not working #17

Closed ssbssa closed 1 year ago

ssbssa commented 2 years ago

In this example:

struct S
{
  int _i;
  long _l;
};

struct S s[] = {{4, 5}, {94, 34}, {83, 95}};

int main()
{
  return s[0]._i + s[2]._l;
}

When trying to print only the _i member:

(gdb) dl s[..3]._i
Expected '#' or '.' or '->' or '-->' or '@' or '[' or '[[' or '(' or '/' or '*' or '%' or '-' or '+' or '<<' or '>>' or '..' or '<=?' or '>=?' or '<?' or '>?' o
r '<=' or '>=' or '<' or '>' or '==?' or '!=?' or '==' or '!=' or '&' or '^' or '|' or '&&' or '||' or '?' or ',' or '=>' or ';' or EOF at position (1, 9) => 's
[..3]._*i'.

With this possible fix ...:

--- a/duel/parser.py
+++ b/duel/parser.py
@@ -57,7 +57,7 @@ def char(): return RegExMatch(r"'([^'\\]|"+escapes+")'")
 def string(): return RegExMatch(r'"([^\\"]|'+escapes+')*"')
 def ident(): return RegExMatch(r'[A-Za-z_]\w*')
 def gdbvar(): return RegExMatch(r'\$\w+')
-def underscores(): return RegExMatch(r'_+')
+def underscores(): return RegExMatch(r'_+\b')
 def parens(): return [('(', expression, ')'), ('{', expression, '}')]
 def term21(): return [real, hexadecimal, decimal, octal, char, string,
                       underscores, ident, gdbvar]

... it looks better:

(gdb) dl s[..3]._i
s[0]._i = 4
s[1]._i = 94
s[2]._i = 83