]>
Witch of Git - ivy/blob - tools/format_trace.py
7 result
= subprocess
.run(
8 ["nm", "-defined-only", "-demangle", program
],
14 for line
in result
.stdout
.split("\n"):
17 addr
, _
, name
= line
.split(' ', 2)
18 if name
.startswith("ivy_builtin$"):
19 name
= name
.split("$", 2)[1]
24 def handle_trace(lines
, syms
={}, only_debug
=False):
27 if int(x
, 16) % 2 == 1:
28 return int(x
, 16) >> 1
36 kind
, *args
= line
.split()
38 objs
[args
[0]] = syms
.get(args
[1], f
"fn@{args[1]}")
40 print("MAKE", objs
[args
[0]])
42 objs
[args
[1]] = obj(args
[0])
44 if int(args
[1], 16) == 0:
45 objs
[args
[0]] = f
"({obj(args[0])})"
47 objs
[args
[0]] = f
"({obj(args[0])} {obj(args[1])})"
49 print("APP", objs
[args
[0]])
54 print("DEBUG", obj(args
[0]))
59 print(kind
, *(obj(x
) for x
in args
))
62 if __name__
== "__main__":
63 parser
= argparse
.ArgumentParser(
64 description
="Make an Ivy runtime trace more readable",
66 parser
.add_argument("program", help="The program that produced the trace")
67 parser
.add_argument("trace", help="A file containing the trace")
69 "-d", "--only-debug", action
="store_true",
70 help="If set, only print the DEBUG outputs",
72 if len(sys
.argv
) == 1:
75 args
= parser
.parse_args()
77 syms
= get_syms(args
.program
)
78 with
open(args
.trace
, "r") as f
:
79 lines
= [line
.strip() for line
in f
if line
.strip()]
80 handle_trace(lines
, syms
, ags
.only_debug
)