-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathsyms.py
74 lines (58 loc) · 2.08 KB
/
syms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
from pathlib import Path
import argparse
import graphviz
parser = argparse.ArgumentParser()
parser.add_argument(
"-m", "--mapfile", type=Path, required=True, help="path to ld's map file"
)
parser.add_argument("-f", "--fullgv", type=Path, help="file to write the full graph to")
parser.add_argument(
"-s", "--summarygv", type=Path, help="file to write the summarized graph to"
)
shargs = parser.parse_args()
def parse_file(mapf):
fullgraph = graphviz.Digraph(graph_attr=dict(overlap="False"))
summary = graphviz.Digraph(strict=True, graph_attr=dict(overlap="False"))
start = "Archive member included to satisfy reference by file (symbol)"
stop = "Discarded input sections"
for line in mapf:
if line.startswith(start):
break
provider = None
demander = None
sym = None
for line in mapf:
if line.isspace():
continue
if line.startswith(stop):
break
if line.startswith((" ", "\t")):
try:
demander, sym = line.strip().rsplit(") (", 1)
demander = demander + ")"
sym = "(" + sym
except Exception:
continue
else:
provider = line.strip()
if provider and demander and sym:
# .split("(")[0] gets the lib ; without this you get the obj
objdemander = demander.rsplit("/", 1)[1]
objprovider = provider.rsplit("/", 1)[1]
libdemander = objdemander.split("(")[0]
libprovider = objprovider.split("(")[0]
fullgraph.edge(objdemander, objprovider, tooltip=sym)
summary.edge(libdemander, libprovider)
provider = None
demander = None
sym = None
return (fullgraph, summary)
with open(shargs.mapfile, "rt") as file:
fullgraph, summary = parse_file(file)
if shargs.fullgv:
with open(shargs.fullgv, "w") as file:
print(fullgraph.source, file=file)
if shargs.summarygv:
with open(shargs.summarygv, "w") as file:
print(summary.source, file=file)