-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcallgraph.cpp
More file actions
executable file
·107 lines (84 loc) · 2.09 KB
/
callgraph.cpp
File metadata and controls
executable file
·107 lines (84 loc) · 2.09 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <cstddef>
using namespace std;
#include "callgraph.h"
void CallGraph::addCall(Function *caller, Function *callee) {
CallGraphEdge *e;
if (!hasVertex(caller)) {
addVertex(caller);
}
if (!hasVertex(callee)) {
addVertex(callee);
}
e = new CallGraphEdge(caller, callee);
assert(e);
addEdge(caller, callee, e);
if (!main)
setMain(caller);
}
std::string CallGraph::dot() {
std::string r = "";
char tmp[1024];
r = "digraph G {\n";
for ( CallGraph::const_func_iterator fit = func_begin();
fit != func_end();
fit++
)
{
Function *f1 = *fit;
sprintf( tmp,
"func_%lx [label=\"%s@%lx\\n[%s]\", shape=rectangle%s"
",URL=\"%lx.svg\"];\n",
f1->getAddress(),
f1->getName(),
f1->getAddress(),
f1->getModule(), f1 != main ? "" : ", color=red",
f1->getAddress()
);
r += " " + std::string(tmp);
}
for ( CallGraph::const_edge_iterator eit = edge_begin();
eit != edge_end();
eit++
)
{
Function *f1 = (*eit)->getSource();
Function *f2 = (*eit)->getTarget();
sprintf( tmp,
"func_%lx -> func_%lx;\n",
f1->getAddress(),
f2->getAddress()
);
r += " " + std::string(tmp);
}
r += "}";
return r;
}
std::string CallGraph::vcg() {
std::string r = "";
char tmp[1024];
r = "graph: {\n";
for (CallGraph::const_func_iterator fit = func_begin();
fit != func_end(); fit++) {
Function *f1 = *fit;
sprintf(tmp, "node: { title: \"func_%lx\" "
"label: \"%s@%lx\\n[%s]\" }\n",
f1->getAddress(), f1->getName(), f1->getAddress(),
f1->getModule());
r += " " + std::string(tmp);
}
for (CallGraph::const_edge_iterator eit = edge_begin();
eit != edge_end(); eit++) {
Function *f1 = (*eit)->getSource();
Function *f2 = (*eit)->getTarget();
sprintf(tmp, "edge: { sourcename: \"func_%lx\" "
"targetname: \"func_%lx\"}\n", f1->getAddress(),
f2->getAddress());
r += " " + std::string(tmp);
}
r += "}";
return r;
}
// Local Variables:
// c-basic-offset: 4
// compile-command: "dchroot -c typeinfer -d make"
// End: