scripts: tracebd.py/dbgbmap.py: Made off range a subparser of block range

So:

- before: ./scripts/dbgbmap.py disk -b4096 -@0 -n16,32
- after:  ./scripts/dbgbmap.py disk -b4096 -@'0 -n16,32'

This is mainly to avoid the naming conflict between -n/--size and
-n/--lines, while also separating out the namespaces a bit.

It's probably not the most intuitive CLI UI, but --off and -n/--size are
probably infrequent arguments at this level of script anyways.
This commit is contained in:
Christopher Haster
2025-03-14 17:52:02 -05:00
parent e18cecc3fb
commit 9b03933f2d
4 changed files with 56 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ import functools as ft
import itertools as it
import math as mt
import os
import shlex
import shutil
import struct
@@ -952,8 +953,6 @@ def main(disk, mroots=None, *,
block_size=None,
block_count=None,
block=None,
off=None,
size=None,
mdirs=False,
btrees=False,
datas=False,
@@ -1005,6 +1004,13 @@ def main(disk, mroots=None, *,
block_count = block_count_
# try to simplify the block/off/size arguments a bit
if not isinstance(block, dict):
block = {'block': block}
block, off, size = (
block.get('block'),
block.get('off'),
block.get('size'))
if not isinstance(block, tuple):
block = block,
if isinstance(off, tuple) and len(off) == 1:
@@ -1419,25 +1425,38 @@ if __name__ == "__main__":
'--block-count',
type=lambda x: int(x, 0),
help="Block count in blocks.")
parser.add_argument(
'-@', '--block',
# subparser for block arguments
blockparser = argparse.ArgumentParser(
prog="%s -@/--block" % parser.prog,
allow_abbrev=False)
blockparser.add_argument(
'block',
nargs='?',
type=lambda x: tuple(
rbydaddr(x) if x.strip() else None
for x in x.split(',')),
help="Optional block to show, may be a range.")
parser.add_argument(
help="Block address, may be a range.")
blockparser.add_argument(
'--off',
type=lambda x: tuple(
int(x, 0) if x.strip() else None
for x in x.split(',')),
help="Show a specific offset, may be a range.")
parser.add_argument(
'--size',
blockparser.add_argument(
'-n', '--size',
type=lambda x: tuple(
int(x, 0) if x.strip() else None
for x in x.split(',')),
help="Show this many bytes, may be a range.")
parser.add_argument(
'-@', '--block',
type=lambda x: {k: v
for k, v in vars(blockparser.parse_intermixed_args(
shlex.split(x))).items()
if v is not None},
help="Optional block to show, may be a range. Can also include "
"--off and -n/--size flags to indicate a range inside the "
"block, both which may also be ranges.")
parser.add_argument(
'--mdirs',
action='store_true',