scripts: dbgflags.py: Reimplemented filters as flags

So instead of:

  $ ./scripts/dbgflags.py o 0x10000003

The filter is now specified as a normal(ish) argparse flag:

  $ ./scripts/dbgflags.py --o 0x10000003

This is a bit easier to interop with in dbg.gdb.py, and I think a bit
more readable.

Though -a and --a now do _very_ different things. I'm sure that won't
confuse anyone...
This commit is contained in:
Christopher Haster
2025-07-04 13:33:45 -05:00
parent 0c19a68536
commit 19747f691e
2 changed files with 42 additions and 69 deletions

View File

@@ -45,21 +45,17 @@ class DbgFlags(gdb.Command):
def invoke(self, args, *_):
args = args.split()
# hack, but don't eval if -l or --list specified
if '-l' not in args and '--list' not in args:
# find nonflags
nonflags = []
for i, a in enumerate(args):
if not a.startswith('-'):
nonflags.append(i)
# parse and eval
for i, n in enumerate(nonflags):
# dbgflags is special in that first arg may be prefix
if i > 0 or len(nonflags) <= 1:
try:
args[n] = '%d' % gdb.parse_and_eval(args[n])
except gdb.error as e:
raise gdb.GdbError(e)
# find nonflags
nonflags = []
for i, a in enumerate(args):
if not a.startswith('-'):
nonflags.append(i)
# parse and eval
for i, n in enumerate(nonflags):
try:
args[n] = '%d' % gdb.parse_and_eval(args[n])
except gdb.error as e:
raise gdb.GdbError(e)
# execute
gdb.execute(' '.join(['!./scripts/dbgflags.py'] + args))