Skip to content

Commit 9dc5083

Browse files
committed
ASTCMD: add call clobber to rdefs graph
1 parent 9b325be commit 9dc5083

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

chb/cmdline/astcmds.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def buildast(args: argparse.Namespace) -> NoReturn:
405405
functions_failed += 1
406406
continue
407407

408-
if show_reachingdefs is not None:
408+
if show_reachingdefs:
409409
if output_reachingdefs is None:
410410
UC.print_error("\nSpecify a file to save the reaching defs")
411411
continue
@@ -421,7 +421,12 @@ def buildast(args: argparse.Namespace) -> NoReturn:
421421

422422
for reg in reachingdefs_registers:
423423
print_reachingdefs(
424-
app, astinterface, output_reachingdefs + "__" + reg, fileformat, f, reg)
424+
app,
425+
astinterface,
426+
output_reachingdefs + "__" + reg,
427+
fileformat,
428+
f,
429+
reg)
425430

426431
else:
427432
UC.print_error("Unable to find function " + faddr)
@@ -488,6 +493,24 @@ def print_reachingdefs(
488493
rdefinstrs = rdefs,
489494
useinstrs=[iaddr])
490495
dotpaths.append((cfgpath, rdef, iaddr))
496+
elif rdef.endswith("_clobber"):
497+
rdefaddr = rdef[:-8]
498+
rdblock = f.containing_block(rdefaddr)
499+
graph = UG.DirectedGraph(list(f.cfg.blocks.keys()), f.cfg.edges)
500+
graph.find_paths(rdblock, cblock)
501+
for (i, p) in enumerate(
502+
sorted(graph.get_paths(), key=lambda p: len(p))):
503+
cfgpath = DotRdefPath(
504+
"path_" + str(rdef) + "_" + str(iaddr) + "_" + str(i),
505+
f,
506+
astinterface,
507+
p,
508+
subgraph=True,
509+
nodeprefix = str(iaddr) + str(rdef) + str(i) + ":",
510+
rdefinstrs = rdefs,
511+
useinstrs=[iaddr])
512+
dotpaths.append((cfgpath, rdef, iaddr))
513+
491514
else:
492515
rdblock = f.containing_block(rdef)
493516
graph = UG.DirectedGraph(list(f.cfg.blocks.keys()), f.cfg.edges)

chb/cmdline/chkx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def parse() -> argparse.Namespace:
745745
buildast.add_argument(
746746
"--show_reachingdefs",
747747
action="store_true",
748-
help="create a dot file for the reaching defs of <reg>")
748+
help="create dot files for the reaching defs of untyped registers")
749749
buildast.add_argument(
750750
"--output_reachingdefs",
751751
help="name of output file (without extension) to store dot/pdf file of reachingdefs")

chb/cmdline/runcmds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def run_commands(args: argparse.Namespace) -> NoReturn:
177177
opcode_output["opcode-distribution"] = opcode_distribution
178178
opcode_output["unknowns"] = unknowns
179179
with open(outputfilename, "w") as fp:
180-
json.dump(opcode_output, fp, indent=2)
180+
json.dump(opcode_output, fp, indent=2, sort_keys=True)
181181
else:
182182
print("\nOpcode distribution")
183183
for (opc, c) in sorted(opcode_distribution.items()):

0 commit comments

Comments
 (0)