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
+27 -8
View File
@@ -20,6 +20,7 @@ import itertools as it
import math as mt
import os
import re
import shlex
import shutil
import sys
import threading as th
@@ -659,8 +660,6 @@ def main(path='-', *,
block_count=None,
block_cycles=None,
block=None,
off=None,
size=None,
reads=False,
progs=False,
erases=False,
@@ -719,6 +718,13 @@ def main(path='-', *,
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:
@@ -1085,25 +1091,38 @@ if __name__ == "__main__":
type=lambda x: int(x, 0),
help="Assumed maximum number of erase cycles when measuring "
"wear.")
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(
'--reads',
action='store_true',