-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebuginfo.js
131 lines (119 loc) · 4.23 KB
/
debuginfo.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
let debug_info = {
start: 0,
structures: {},
files: {},
address: {}, // map memory addresses to fileID/lineNumber
}
function debuginfo_load(file)
{
// reinit all data
debug_info = {
start: 0,
structures: {},
files: {},
address: {}
}
let remote = "/code/" + file;
let f = fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.text())
.then ( text => {
let dbg_spans = {}
let dbg_lines = {};
let dbg_lineID = {};
text = text.replaceAll("\r","");
let lines = text.split("\n");
for (let i in lines) {
let cols = lines[i].split("\t");
if (cols.length < 2) {
continue;
}
let type = cols[0];
let kattrs = cols[1].split(",");
let attrs = {}
for (let j in kattrs) {
let kv = kattrs[j].split("=");
attrs[kv[0]]=kv[1];
}
switch (type) {
case "line":
if (attrs.span != undefined) {
attrs['id']=parseInt(attrs.id);
attrs['span']=parseInt(attrs.span);
attrs["line"]=parseInt(attrs.line);
attrs["file"]=parseInt(attrs.file);
if (dbg_lines[attrs.span] == undefined) {
dbg_lines[attrs.span] = attrs;
}
}
dbg_lineID[parseInt(attrs.id)] = {
file: parseInt(attrs.file),
line: parseInt(attrs.line)
}
break;
case "span":
attrs['id']=parseInt(attrs.id);
attrs['seg']=parseInt(attrs.seg);
attrs['size']=parseInt(attrs.size);
attrs.start = parseInt(attrs.start);
dbg_spans[attrs.id] = attrs;
break;
case "file":
attrs['id']=parseInt(attrs.id);
attrs.name = attrs.name.replaceAll("\"","")
debug_info.files[attrs.id] = { "name":attrs.name, "lines":{}, symbols:[]};
break;
case "seg":
if (attrs.name=="\"CODE\"") {
// entry point of the code
let hex = attrs.start.substring(2);
debug_info.start = parseInt(hex, 16);
}
break;
case 'sym':
let addr = attrs.val
if (addr.substring(1,2) == '0x') {
addr = parseInt(addr.substring(3), 16)
}
else {
addr = parseInt(addr)
}
let name = attrs.name.replaceAll("\"","")
hSymbols[addr] = name
// record the symbol location in the source code
let def = parseInt(attrs.def)
let line = dbg_lineID[def]
debug_info.files[line.file].symbols[name] = line.line
break
case "scope":
if (attrs.type == 'struct') {
debug_info.structures[attrs.name.replaceAll("\"","").toLowerCase()] = {
'size': parseInt(attrs.size),
"attributes": []
}
}
break;
}
}
// bind memory addresses to source file/line number
for (let id in dbg_spans) {
let span = dbg_spans[id];
span.start += debug_info.start
let line = dbg_lines[span.id];
if (line != undefined && debug_info.address[span.start] == undefined) {
debug_info.address[span.start] = line;
debug_info.files[line.file].lines[line.line] = span;
}
}
// display file names
files_update()
return "ok"
})
.catch (error => {
console.log(error);
})
return f
}