forked from xjdrew/lua-gdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lua54_debug.sh
64 lines (59 loc) · 1.68 KB
/
lua54_debug.sh
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
#for lua5.4
#gdb中加载: source ./lua54_debug.sh
#命令
#1、luabt L 显示调用栈(参数为L)
# luabt 显示调用栈
define luabt
set $L = $0
print $L
set $ci = $L->ci
while($ci)
set $func = (StackValue*)$ci->func
set $tt = ((TValue)($func->val)->value_)->tt_ & 0x3f
if ($tt==6)
set $p = ((LClosure *)$func->val->value_.gc)->p
set $filename = (char*)($p->source->contents)
set $lineinfo = $p->lineinfo
set $pc1 = (int)(((int)$ci->u->l->savedpc)-(int)$p->code)/4 -1
set $lineno = 0
set $basepc = 0
set $baseline = 0
set $MAXIWTHABS = 128
set $ABSLINEINFO = -0x80
if ($lineinfo == 0)
set $lineno = -1
else
set $sizeabslineinfo = $p->sizeabslineinfo
if ($sizeabslineinfo == 0 || (long)$pc1 < (long)$p->abslineinfo[0].pc)
set $basepc = (long)(-1)
set $baseline = $p->linedefined
else
set $pcc = ((unsigned int)$pc1)
set $i = $pcc / $MAXIWTHABS - 1
while ((long)($i + 1) < (long)$p->sizeabslineinfo && (long)$pc1 >= (long)$p->abslineinfo[$i + 1].pc)
set $i=$i+1
end
set $basepc = (long)($p->abslineinfo[$i].pc)
set $baseline = $p->abslineinfo[$i].line
end
while((long)$basepc < (long)$pc1)
set $basepc = $basepc + 1
set $baseline = $baseline + $p->lineinfo[$basepc]
end
set $lineno = $baseline
end
printf "LUA FUNCTION : %s:%d\n", $filename, $lineno
end
if($tt==0x16)
set $f = $func->val->value_->f
printf "LC FUNCTION :"
info line *$f
end
if($tt==0x26)
set $f = ((CClosure *)$func->val->value_.gc)->f
printf "C FUNCTION :"
info line *$f
end
set $ci = $ci->previous
end
end