-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathclidbg.ts
39 lines (31 loc) · 1.23 KB
/
clidbg.ts
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
import * as hid from './hid';
import * as fs from "fs";
import Cloud = pxt.Cloud;
import U = pxt.Util;
import D = pxt.HWDBG;
export function startAsync(compileRes: pxtc.CompileResult) {
return hid.initAsync()
.then(d => {
hid.connectSerial(d)
D.postMessage = msg => {
if (msg.subtype != "breakpoint") {
console.log(msg)
return
}
let bmsg = msg as pxsim.DebuggerBreakpointMessage
console.log("GLOBALS", bmsg.globals)
for (let s of bmsg.stackframes)
console.log(s.funcInfo.functionName, s.locals)
let brkMatch = compileRes.breakpoints.filter(b => b.id == bmsg.breakpointId)[0]
if (!brkMatch) {
console.log("Invalid breakpoint ID", msg)
return
}
let lines = fs.readFileSync(brkMatch.fileName, "utf8").split(/\n/)
console.log(">>>", lines.slice(brkMatch.line, brkMatch.endLine + 1).join(" ;; "))
U.delay(500)
.then(() => D.resumeAsync(false))
}
return D.startDebugAsync(compileRes, d)
})
}