-
Notifications
You must be signed in to change notification settings - Fork 2
/
gdbmacros
140 lines (127 loc) · 3.21 KB
/
gdbmacros
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
132
133
134
135
136
137
138
139
140
# GC_UM_Chunk umheap.h
define listchunks
set $list = $arg0
set $e = $list
set $i = 0
while $e != 0x0
printf "rtml-debug: listchunks #%d: %p ", $i++, $e
set $e = (GC_UM_Chunk)$e->next_chunk
printf "\n"
end
end
def dumparraychunk
set $caddr = $arg0
print /x *((GC_UM_Array_Chunk) $caddr)
end
def dumpchunk
set $caddr = $arg0
print /x *((GC_UM_Chunk) $caddr)
end
def dumpprevchunk
set $caddr = $arg0
print *((GC_UM_Chunk) $caddr)->prev_chunk
end
def returnaddress
set $caddr = $arg0
set $raoffset = ((GC_UM_Chunk) $caddr)->ra
set $ra = *(unsigned int*)((GC_UM_Chunk) $caddr)->ml_object[$raoffset]
print $raoffset
print $ra
end
def dumpthread
set $tn = $arg0
if gcState.currentThread[$tn] == 1
print "not a valid thread"
else
print *((GC_thread) gcState.currentThread[$tn])
end
end
define dumpcurrentframe
set $tn = $arg0
if gcState.currentThread[$tn] == 1
print "not a valid thread"
else
x /32wx gcState->currentFrame[$arg0]
end
end
document dumpcurrentframe
dumpcurrentframe [tn]
dump the current frame (first 32 words) as hex
end
define dumpstrings
set $a = $arg0
x /32sb $arg0
end
document dumpstrings
dumpstrings [addr]
dump the first 32 strings at the given address
end
define dumpstack
set $tn = $arg0
if gcState.currentThread[$tn] == 1
print "not a valid thread"
else
set $e = ((GC_thread) gcState.currentThread[$tn])->firstFrame
set $i = 0
while $e != 0x0
printf "dumpstack: #%d: %p ", $i++, $e
set $e = ((GC_UM_Chunk)$e)->next_chunk
printf "\n"
end
end
end
define whichheap
set $a = $arg0
if gcState->heap.start <= $a && $a <= (gcState->heap.start + gcState->heap.size)
print "is on old heap"
end
if gcState->umheap.start <= $a && $a <= gcState->umheap.end
print "is on chunked heap"
end
end
document whichheap
whichheap(address)
determine which heap the address is on.
end
define isonstack
set $tn = $arg0
set $addr = $arg1
set $chunknum = 0
set $foundaddr = 0
if gcState.currentThread[$tn] == 1
print "not a valid thread"
else
set $framestartaddr = ((GC_thread) gcState.currentThread[$tn])->firstFrame
set $frameendaddr = $framestartaddr + sizeof(GC_UM_Chunk)
set $i = 0
set $found = 0
while $framestartaddr != 0x0 && $found == 0
set $chunknum = $chunknum + 1
if $framestartaddr <= $addr && $addr <= $frameendaddr
# print "is in stack"
set $found = 1
set $foundaddr = $framestartaddr
else
set $framestartaddr = ((GC_UM_Chunk)$framestartaddr)->next_chunk
set $frameendaddr = $framestartaddr + sizeof(GC_UM_Chunk)
end
end
end
if $found == 1
print "is on stack at chunk:"
print $chunknum
print $foundaddr
else
print "not on stack"
end
end
document isonstack
isonstack(thr_num, address)
if address is on the stack of thr_num
end
define tohex
print /x $arg0
end
define todec
print /d $arg0
end