forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebuginfo.cpp
77 lines (63 loc) · 2.48 KB
/
debuginfo.cpp
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
// --- storing and accessing source location metadata ---
struct FuncInfo{
const Function* func;
size_t lengthAdr;
std::vector<JITEvent_EmittedFunctionDetails::LineStart> lines;
};
class JuliaJITEventListener: public JITEventListener
{
std::map<size_t, FuncInfo> info;
public:
JuliaJITEventListener(){}
virtual ~JuliaJITEventListener() {}
virtual void NotifyFunctionEmitted(const Function &F, void *Code,
size_t Size, const EmittedFunctionDetails &Details)
{
FuncInfo tmp = {&F, Size, Details.LineStarts};
info[(size_t)(Code)] = tmp;
}
std::map<size_t, FuncInfo> getMap()
{
return info;
}
};
JuliaJITEventListener *jl_jit_events;
extern "C" void getFunctionInfo(const char **name, int *line, const char **filename,size_t pointer);
void getFunctionInfo(const char **name, int *line, const char **filename, size_t pointer)
{
std::map<size_t, FuncInfo> info = jl_jit_events->getMap();
*name = NULL;
*line = -1;
*filename = "no file";
for (std::map<size_t, FuncInfo>::iterator it= info.begin(); it!= info.end(); it++) {
if ((*it).first <= pointer) {
if ((size_t)(*it).first + (*it).second.lengthAdr >= pointer) {
*name = &(*(*it).second.func).getNameStr()[0];
if ((*it).second.lines.size() == 0) {
continue;
}
std::vector<JITEvent_EmittedFunctionDetails::LineStart>::iterator vit = (*it).second.lines.begin();
JITEvent_EmittedFunctionDetails::LineStart prev = *vit;
DISubprogram debugscope =
DISubprogram(prev.Loc.getScope((*it).second.func->getContext()));
*filename = debugscope.getFilename().data();
// the DISubprogram has the un-mangled name, so use that if
// available.
*name = debugscope.getName().data();
vit++;
while (vit != (*it).second.lines.end()) {
if (pointer <= (*vit).Address) {
*line = prev.Loc.getLine();
break;
}
prev = *vit;
vit++;
}
if (*line == -1) {
*line = prev.Loc.getLine();
}
break;
}
}
}
}