3 Commits

Author SHA1 Message Date
Christopher Haster
29e1701964 scripts: gdb: Globbed all dbg scripts into dbg.gdb.py
This goes ahead and makes all dbg scripts available in dbg.gdb.py, via
the magic of globbing __file__ relative, and dynamic python class
generation.

Probably one of the more evil scripts I've written, but this means we
don't need to worry about dbg.gdb.py falling out-of-date when adding new
dbg scripts.

Not all of the dbg scripts are useful inside gdb, but most of them are.
After all, what's cooler than this!

  (gdb) dbgrbyd -b4096 "disk" -t \
          file->b.shrub.blocks[0] \
          --trunk lfs3_rbyd_trunk(&file->b.shrub)
  rbyd 0x46.23a w2048, rev 00000000, size 629, cksum 8f5169e1
  00000004:           .->     0-334 data w335 0
  00000009:         .-+->       335 data w1 1                  71
  0000000e:         | .->       336 data w1 1                  67
  00000013:       .-+-+->       337 data w1 1                  66
  ...
  00000144: | | | |   .->       350 data w1 1                  74
  0000019a: | | | | .-+->       351 data w1 1                  78
  000001f5: | | | | | .->   352-739 data w388 1                76
  00000258: +-+-+-+-+-+->  740-2047 data w1308 1               6c

Note some tricks to help interact with bash and gdb:

- Flags are passed as is (-b4096, -t, --trunk)
- All non-flags are parsed as expressions (file->b.shrub.blocks[0])
- String expressions may be useful for paths and stuff ("./disk")
2025-07-04 18:55:46 -05:00
Christopher Haster
19747f691e 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...
2025-07-04 18:08:11 -05:00
Christopher Haster
0b804c092b scripts: gdb: Added some useful GDB scripts to test.py --gdb
These just invoke the existing dbg*.py python scripts, but allow quick
references to variables in the debugginged process:

  (gdb) dbgflags o file->b.o.flags
  LFS3_O_RDWR    0x00000002  Open a file as read and write
  LFS3_o_REG     0x10000000  Type = regular-file
  LFS3_o_UNSYNC  0x01000000  File's metadata does not match disk

Quite neat and useful!

This works by injecting dbg.gdb.py via gdb -x, which includes the
necessary python hooks to add these commands to gdb. This can be
overridden/extended with test.py/bench.py's --gdb-script flag.

Currently limited to scripts that seem the most useful for process
internals:

- dbgerr - Decode littlefs error codes
- dbgflags - Decode littlefs flags
- dbgtag - Decode littlefs tags
2025-07-04 18:08:04 -05:00