-
Notifications
You must be signed in to change notification settings - Fork 18
/
.gdbinit
219 lines (180 loc) · 4.4 KB
/
.gdbinit
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
define berr
b Rf_errorcall
end
define pv
if $arg0==R_MissingArg
printf "R_MissingArg"
end
if $arg0!=R_MissingArg
call Rf_PrintValue($arg0)
end
end
define pe
set $x=R_lsInternal($arg0, 1)
pv $x
end
define pve
set $x=Rf_findVar(Rf_install($arg0), $arg1)
pv $x
end
define pp
if TYPEOF($arg0)!=PROMSXP
printf "Not a promise\n"
end
if TYPEOF($arg0)==PROMSXP
printf "Value: "
if PRVALUE($arg0)==R_UnboundValue
printf "R_UnboundValue\n"
end
if PRVALUE($arg0)!=R_UnboundValue
pv PRVALUE($arg0)
end
printf "Expr: "
if PRCODE($arg0)==R_MissingArg
printf "R_MissingArg\n"
end
if PRCODE($arg0)!=R_MissingArg
pv PRCODE($arg0)
end
end
end
set history save
set print pretty on
set print array off
set print array-indexes on
define dumpsxp
printf "\n\n>> SEXP %p\n", $arg0
if $arg0==0
printf "NULL\n"
return
end
if $arg1==1
set $insp=do_inspect(0, 0, Rf_cons($arg0, R_NilValue), 0)
printf "%s\n", $insp
end
set $sexptype=TYPEOF($arg0)
# typename
printf "Type: %s (%d)\n", Rf_type2char($sexptype), $sexptype
# SYMSXP
if $sexptype==1
# CHAR(PRINTNAME(x))
print_char PRINTNAME($arg0)
end
# LISTSXP
if $sexptype==2
printf "(%s,%s)\n", Rf_type2char(TYPEOF(CDR($arg0))), Rf_type2char(TYPEOF(CAR($arg0)))
# printf "( ,%s)\n", type2char(TYPEOF(CDR($arg0)))
end
# CLOSXP
if $sexptype==3
dumpsxp BODY($arg0) 0
end
# PROMSXP
# Promises contain pointers to value, expr and env
# tmp = eval(tmp, rho);
if $sexptype==5
printf "Promise under evaluation: %d\n", PRSEEN($arg0)
printf "Expression: "
dumpsxp ($arg0)->u.promsxp.expr 0
# Expression: (CAR(chain))->u.promsxp.expr
end
# LANGSXP
if $sexptype==6
printf "Function:"
dumpsxp CAR($arg0) 0
printf "Args:"
dumpsxp CDR($arg0) 0
end
# SPECIALSXP
if $sexptype==7
printf "Special function: %s\n", R_FunTab[($arg0)->u.primsxp.offset].name
end
# BUILTINSXP
if $sexptype==8
printf "Function: %s\n", R_FunTab[($arg0)->u.primsxp.offset].name
end
# CHARSXP
if $sexptype==9
printf "length=%d\n", ((VECTOR_SEXPREC)(*$arg0))->vecsxp.length
#print_veclen $arg0
print_char $arg0
end
# LGLSXP
if $sexptype==10
set $lgl=*LOGICAL($arg0)
if $lgl > 0
printf "TRUE\n"
end
if $lgl == 0
printf "FALSE\n"
end
end
# INTSXP
if $sexptype==13
printf "%d\n", *(INTEGER($arg0))
end
# REALSXP
if $sexptype==14
print_veclen $arg0
#print_double $arg0
end
# STRSXP || VECSXP
if $sexptype==16 || $sexptype==19
print_veclen $arg0
set $i=LENGTH($arg0)
set $count=0
while ($count < $i)
printf "Element #%d:\n", $count
dumpsxp STRING_ELT($arg0,$count) 0
set $count = $count + 1
end
end
# RAWSXP
if $sexptype==24
print_veclen $arg0
end
printf "\n"
end
define print_veclen
printf "Vector length=%d\n", LENGTH($arg0)
end
define print_char
# this may be a bit dodgy, as I am not using the aligned union
printf "\"%s\"\n", (const char*)((VECTOR_SEXPREC *) ($arg0)+1)
end
define print_double
printf "%g\n", (double*)((VECTOR_SEXPREC *) ($arg0)+1)
end
define ds
dumpsxp $arg0 1
end
define ninja
shell ninja
python gdb.execute("file " + gdb.current_progspace().filename)
directory
end
# source .pirpp.py
# multiple commands
python
from __future__ import print_function
import gdb
class Cmds(gdb.Command):
"""run multiple commands separated by ';'"""
def __init__(self):
gdb.Command.__init__(
self,
"cmds",
gdb.COMMAND_DATA,
gdb.COMPLETE_SYMBOL,
True,
)
def invoke(self, arg, from_tty):
for fragment in arg.split(';'):
# from_tty is passed in from invoke.
# These commands should be considered interactive if the command
# that invoked them is interactive.
# to_string is false. We just want to write the output of the commands, not capture it.
gdb.execute(fragment, from_tty=from_tty, to_string=False)
print()
Cmds()
end