Skip to content

Commit

Permalink
Added --gdb-pl to test.py for breaking on specific powerlosses
Browse files Browse the repository at this point in the history
This allows debugging strategies such as binary searching for the point
of "failure", which may be more complex than simply failing an assert.
  • Loading branch information
geky committed Dec 17, 2022
1 parent 801cf27 commit c2147c4
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,11 @@ def run(runner, test_ids=[], **args):

# drop into gdb?
if failures and (args.get('gdb')
or args.get('gdb_powerloss_before')
or args.get('gdb_powerloss_after')
or args.get('gdb_case')
or args.get('gdb_main')):
or args.get('gdb_main')
or args.get('gdb_pl') is not None
or args.get('gdb_pl_before')
or args.get('gdb_pl_after')):
failure = failures[0]
cmd = runner_ + [failure.id]

Expand All @@ -1161,7 +1162,14 @@ def run(runner, test_ids=[], **args):
'-ex', 'break %s:%d' % (path, lineno),
'-ex', 'run',
'--args']
elif args.get('gdb_powerloss_before'):
elif args.get('gdb_pl') is not None:
path, lineno = find_path(runner_, failure.id, **args)
cmd[:0] = args['gdb_path'] + [
'-ex', 'break %s:%d' % (path, lineno),
'-ex', 'ignore 1 %d' % args['gdb_pl'],
'-ex', 'run',
'--args']
elif args.get('gdb_pl_before'):
# figure out how many powerlosses there were
powerlosses = (
sum(1 for _ in re.finditer('[0-9a-f]',
Expand All @@ -1173,7 +1181,7 @@ def run(runner, test_ids=[], **args):
'-ex', 'ignore 1 %d' % max(powerlosses-1, 0),
'-ex', 'run',
'--args']
elif args.get('gdb_powerloss_after'):
elif args.get('gdb_pl_after'):
# figure out how many powerlosses there were
powerlosses = (
sum(1 for _ in re.finditer('[0-9a-f]',
Expand Down Expand Up @@ -1373,14 +1381,6 @@ def main(**args):
'--gdb',
action='store_true',
help="Drop into gdb on test failure.")
test_parser.add_argument(
'--gdb-powerloss-before',
action='store_true',
help="Drop into gdb before the powerloss that caused the failure.")
test_parser.add_argument(
'--gdb-powerloss-after',
action='store_true',
help="Drop into gdb after the powerloss that caused the failure.")
test_parser.add_argument(
'--gdb-case',
action='store_true',
Expand All @@ -1391,6 +1391,18 @@ def main(**args):
action='store_true',
help="Drop into gdb on test failure but stop at the beginning "
"of main.")
test_parser.add_argument(
'--gdb-pl',
type=lambda x: int(x, 0),
help="Drop into gdb on this specific powerloss.")
test_parser.add_argument(
'--gdb-pl-before',
action='store_true',
help="Drop into gdb before the powerloss that caused the failure.")
test_parser.add_argument(
'--gdb-pl-after',
action='store_true',
help="Drop into gdb after the powerloss that caused the failure.")
test_parser.add_argument(
'--gdb-path',
type=lambda x: x.split(),
Expand Down

0 comments on commit c2147c4

Please sign in to comment.