Skip to content

Commit b110b2c

Browse files
author
Reini Urban
committed
add the missing debug lib files
loaded, but not yet enabled. remote is missing the socket interface z is also missing the serializer and z communication
1 parent 0a77056 commit b110b2c

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

lib/potion/debug.pn

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# debugger API used if #undef DEBUG_IN_C (not yet enabled)
2+
3+
#TODO: parse comma delim args. avoid readline (whois loading or calling)
4+
Debug = class (args):
5+
/state = 0
6+
/break = ()
7+
/init = (): load "readline".
8+
/read = (): readline("> ").
9+
/write = (o): o print.
10+
11+
/init()
12+
.
13+
14+
# API (from lua)
15+
Debug getinfo = (level, name): .
16+
Debug getlocal = (f, i): .
17+
Debug setlocal = (f, i, name): .
18+
Debug setupvalue = (f, i, name): .
19+
Debug traceback = (f| level): .
20+
Debug sethook = (hook, name): .
21+
22+
# state 0 for next/step
23+
# 1 :c continue until break
24+
# 5 :q exit debugger
25+
# 6 :exit exit program
26+
Debug loop = (src, proto):
27+
if (self/state == 1):
28+
if (self/break bsearch(src line)): return 1.
29+
.
30+
write = self/write
31+
("\ndebug line ", src file,":", src line string,
32+
" (:h for help, :q,:c,:n)\n") join write
33+
loop:
34+
code = self/read()
35+
if (code == ":c"):
36+
"continue\n" write
37+
self/state = 1
38+
return 1.
39+
if (code == ":q"):
40+
"quit\n" write
41+
return 5.
42+
if (code == ":exit"):
43+
"exit\n" write
44+
return 6.
45+
if (code == ":h"):
46+
(":q quit debugger and continue",
47+
":exit quit debugger and exit",
48+
":c continue",
49+
":b line set breakpoint",
50+
":B line unset breakpoint",
51+
":n step to next line",
52+
":s step into function",
53+
":r regs",
54+
":l locals",
55+
":u upvals",
56+
":v values (paths)",
57+
"expr eval expr",
58+
"src current ast",
59+
"proto current function\n") join("\n") write
60+
continue.
61+
if (code slice(0,2) == ":b"):
62+
b = code slice(4, code length) number
63+
if (self/break bsearch(b)): ("breakpoint ",b string," already defined\n") join write.
64+
else: self/break = self/break push (b) sort.
65+
continue.
66+
if (code slice(0,2) == ":B"):
67+
b = code slice(4, code length) number
68+
i = self/break bsearch(b)
69+
if (i):
70+
self/break delete(i)
71+
("breakpoint ", b string, " deleted") join write.
72+
continue.
73+
if (code != ""):
74+
code = code eval string write.
75+
.
76+
2
77+
.
78+
79+
debug = Debug

lib/potion/debug/remote.pn

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# via tcp socket
2+
# TODO: sock callbacks
3+
4+
load "debug"
5+
6+
# TODO: parse comma delim args
7+
remote.debug = Debug class (args):
8+
/init = (): load "aio".
9+
10+
/init()
11+
/port = 8172
12+
/sock = Aio_tcp
13+
/read = (): self/sock read.
14+
/write = (o): self/sock write(o).
15+
16+
/sock bind("127.0.0.1", self/port)
17+
/sock listen(1, self connect_cb)
18+
/sock run
19+
.
20+
21+
remote.debug connect_cb = (req, st): .
22+
remote.debug read_cb = (req, st): .
23+
24+
debug = remote.debug

lib/potion/debug/z.pn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# socket to ZeroBrane Studio
2+
# TODO: lua mobdebug protocol, serpent serializer
3+
4+
load "debug/remote"
5+
# debug

0 commit comments

Comments
 (0)