gdbdump 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 589c4ae8d652fe1c24deb76f73deea5ba82ec242
4
- data.tar.gz: 2689d144842a157d13168a70c28adcce61a5e78d
3
+ metadata.gz: 4404278dd2a252a8c175717c167a796adee717c6
4
+ data.tar.gz: 5b6e430c94796dab5eab7db5933c83757455c295
5
5
  SHA512:
6
- metadata.gz: 5923cc6b4353b49039095e8440401b92645e6080dd95bc5c45a46804ed649f2cdc3e280a3fbef2f9f3b1759ce32a4dd7c0fc9e6061fbfe7c37ad6dcb4aaabc55
7
- data.tar.gz: 12dd18e4ca417c9d108767aa13f43d39aea3d69d477017ea19c1e91140b1a3af00fcdc2ff88b338ca6854b0256f6fd996dfecdafbae1d66859460a59a4b1c153
6
+ metadata.gz: eb73707296f26c46c4c8e8def9a9cab0584e27c6f5c14d62b8b549cb90ca047ccaa8bd17c1dffcefa0063c5e46484f4ab0fc0f3f8d241093e5f38d5eb3136a25
7
+ data.tar.gz: 6c6ead8c0f79e04ace82dc5dc68fca17fdce94ece83a346110bab569505415b79308b6dd8c3bd281cb97ef4c7bbdcd3184a3f4a6df8d01942650d73f7f50237f
@@ -1,3 +1,9 @@
1
+ # 0.9.2
2
+
3
+ Enhancements:
4
+
5
+ * Add gdbinit of ruby 2.1 and 2.2
6
+
1
7
  # 0.9.1
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -28,12 +28,12 @@ Usage: gdbdump [options] pid
28
28
 
29
29
  ### .gdbinit
30
30
 
31
- Default supported ruby versions: 2.3.0 - 2.4.1
31
+ Default supported ruby versions: 2.1.x - 2.4.x
32
32
 
33
33
  Ruby trunk's [.gdbinit](https://github.com/ruby/ruby/blob/trunk/.gdbinit) file defines useful helper functions and it is maintained by ruby core team. `gdbdump` uses it.
34
- Some versions of .gdbinit are bundled in this gem, but if you want to use `gdbdump` for older or newer ruby versions:
34
+ Some versions written as above of .gdbinit are bundled in this gem, but if you want to use `gdbdump` for older or newer ruby versions:
35
35
 
36
- 1. Download .gdbinit from ruby repo like https://github.com/ruby/ruby/blob/v2_4_1/.gdbinit, and specify with `-x` option
36
+ 1. Download .gdbinit from ruby repo like [ruby/2.4.1/.gdbinit](https://github.com/ruby/ruby/blob/v2_4_1/.gdbinit), and specify with `-x` option
37
37
  2. Or, send PR to bundle the .gdbinit in `gdbdump` gem.
38
38
 
39
39
  ## Example
@@ -14,11 +14,18 @@ class Gdbdump
14
14
  @debug = debug
15
15
  @gdb = gdb || 'gdb'
16
16
  @ruby = ruby || Procfs.new(@pid).exe
17
- @ruby_version = `#{@ruby} -e 'puts RUBY_VERSION'`.chomp
18
- @gdbinit = gdbinit || File.join(ROOT, 'vendor', 'ruby', @ruby_version, 'gdbinit')
17
+ @gdbinit = gdbinit || File.join(ROOT, 'vendor', 'ruby', ruby_minor_version, 'gdbinit')
19
18
  @exec_options = [SUDO_CMD, @gdb, '-silent', '-nw', '-x', @gdbinit, @ruby, @pid]
20
19
  end
21
20
 
21
+ private def ruby_version
22
+ `#{@ruby} -e 'puts RUBY_VERSION'`.chomp
23
+ end
24
+
25
+ private def ruby_minor_version
26
+ ruby_version.split('.')[0,2].join('.')
27
+ end
28
+
22
29
  def print_backtrace
23
30
  run do |gdb|
24
31
  out, err = gdb.cmd_exec('rb_ps')
@@ -1,3 +1,3 @@
1
1
  class Gdbdump
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -0,0 +1,882 @@
1
+ define hook-run
2
+ set $color_type = 0
3
+ set $color_highlite = 0
4
+ set $color_end = 0
5
+ end
6
+
7
+ define ruby_gdb_init
8
+ if !$color_type
9
+ set $color_type = "\033[31m"
10
+ end
11
+ if !$color_highlite
12
+ set $color_highlite = "\033[36m"
13
+ end
14
+ if !$color_end
15
+ set $color_end = "\033[m"
16
+ end
17
+ if ruby_dummy_gdb_enums.special_consts
18
+ end
19
+ end
20
+
21
+ # set prompt \033[36m(gdb)\033[m\040
22
+
23
+ define rp
24
+ ruby_gdb_init
25
+ if (VALUE)($arg0) & RUBY_FIXNUM_FLAG
26
+ printf "FIXNUM: %ld\n", (long)($arg0) >> 1
27
+ else
28
+ if ((VALUE)($arg0) & ~(~(VALUE)0<<RUBY_SPECIAL_SHIFT)) == RUBY_SYMBOL_FLAG
29
+ set $id = (($arg0) >> RUBY_SPECIAL_SHIFT)
30
+ printf "%sSYMBOL%s: ", $color_type, $color_end
31
+ rp_id $id
32
+ else
33
+ if ($arg0) == RUBY_Qfalse
34
+ echo false\n
35
+ else
36
+ if ($arg0) == RUBY_Qtrue
37
+ echo true\n
38
+ else
39
+ if ($arg0) == RUBY_Qnil
40
+ echo nil\n
41
+ else
42
+ if ($arg0) == RUBY_Qundef
43
+ echo undef\n
44
+ else
45
+ if (VALUE)($arg0) & RUBY_IMMEDIATE_MASK
46
+ if ((VALUE)($arg0) & RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG
47
+ printf "%sFLONUM%s: %g\n", $color_type, $color_end, (double)rb_float_value($arg0)
48
+ else
49
+ echo immediate\n
50
+ end
51
+ else
52
+ set $flags = ((struct RBasic*)($arg0))->flags
53
+ if ($flags & RUBY_FL_PROMOTED)
54
+ printf "[PROMOTED] "
55
+ end
56
+ if ($flags & RUBY_T_MASK) == RUBY_T_NONE
57
+ printf "%sT_NONE%s: ", $color_type, $color_end
58
+ print (struct RBasic *)($arg0)
59
+ else
60
+ if ($flags & RUBY_T_MASK) == RUBY_T_NIL
61
+ printf "%sT_NIL%s: ", $color_type, $color_end
62
+ print (struct RBasic *)($arg0)
63
+ else
64
+ if ($flags & RUBY_T_MASK) == RUBY_T_OBJECT
65
+ printf "%sT_OBJECT%s: ", $color_type, $color_end
66
+ print (struct RObject *)($arg0)
67
+ else
68
+ if ($flags & RUBY_T_MASK) == RUBY_T_CLASS
69
+ printf "%sT_CLASS%s%s: ", $color_type, ($flags & RUBY_FL_SINGLETON) ? "*" : "", $color_end
70
+ rp_class $arg0
71
+ else
72
+ if ($flags & RUBY_T_MASK) == RUBY_T_ICLASS
73
+ printf "%sT_ICLASS%s: ", $color_type, $color_end
74
+ rp_class $arg0
75
+ else
76
+ if ($flags & RUBY_T_MASK) == RUBY_T_MODULE
77
+ printf "%sT_MODULE%s: ", $color_type, $color_end
78
+ rp_class $arg0
79
+ else
80
+ if ($flags & RUBY_T_MASK) == RUBY_T_FLOAT
81
+ printf "%sT_FLOAT%s: %.16g ", $color_type, $color_end, (((struct RFloat*)($arg0))->float_value)
82
+ print (struct RFloat *)($arg0)
83
+ else
84
+ if ($flags & RUBY_T_MASK) == RUBY_T_STRING
85
+ printf "%sT_STRING%s: ", $color_type, $color_end
86
+ rp_string $arg0 $flags
87
+ else
88
+ if ($flags & RUBY_T_MASK) == RUBY_T_REGEXP
89
+ set $regsrc = ((struct RRegexp*)($arg0))->src
90
+ set $rsflags = ((struct RBasic*)$regsrc)->flags
91
+ printf "%sT_REGEXP%s: ", $color_type, $color_end
92
+ set print address off
93
+ output (char *)(($rsflags & RUBY_FL_USER1) ? \
94
+ ((struct RString*)$regsrc)->as.heap.ptr : \
95
+ ((struct RString*)$regsrc)->as.ary)
96
+ set print address on
97
+ printf " len:%ld ", ($rsflags & RUBY_FL_USER1) ? \
98
+ ((struct RString*)$regsrc)->as.heap.len : \
99
+ (($rsflags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2)
100
+ if $flags & RUBY_FL_USER6
101
+ printf "(none) "
102
+ end
103
+ if $flags & RUBY_FL_USER5
104
+ printf "(literal) "
105
+ end
106
+ if $flags & RUBY_FL_USER4
107
+ printf "(fixed) "
108
+ end
109
+ printf "encoding:%d ", ($flags & RUBY_ENCODING_MASK) >> RUBY_ENCODING_SHIFT
110
+ print (struct RRegexp *)($arg0)
111
+ else
112
+ if ($flags & RUBY_T_MASK) == RUBY_T_ARRAY
113
+ if ($flags & RUBY_FL_USER1)
114
+ set $len = (($flags & (RUBY_FL_USER3|RUBY_FL_USER4)) >> (RUBY_FL_USHIFT+3))
115
+ printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len
116
+ printf "(embed) "
117
+ if ($len == 0)
118
+ printf "{(empty)} "
119
+ else
120
+ output/x *((VALUE*)((struct RArray*)($arg0))->as.ary) @ $len
121
+ printf " "
122
+ end
123
+ else
124
+ set $len = ((struct RArray*)($arg0))->as.heap.len
125
+ printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len
126
+ if ($flags & RUBY_FL_USER2)
127
+ printf "(shared) shared="
128
+ output/x ((struct RArray*)($arg0))->as.heap.aux.shared
129
+ printf " "
130
+ else
131
+ printf "(ownership) capa=%ld ", ((struct RArray*)($arg0))->as.heap.aux.capa
132
+ end
133
+ if ($len == 0)
134
+ printf "{(empty)} "
135
+ else
136
+ output/x *((VALUE*)((struct RArray*)($arg0))->as.heap.ptr) @ $len
137
+ printf " "
138
+ end
139
+ end
140
+ print (struct RArray *)($arg0)
141
+ else
142
+ if ($flags & RUBY_T_MASK) == RUBY_T_FIXNUM
143
+ printf "%sT_FIXNUM%s: ", $color_type, $color_end
144
+ print (struct RBasic *)($arg0)
145
+ else
146
+ if ($flags & RUBY_T_MASK) == RUBY_T_HASH
147
+ printf "%sT_HASH%s: ", $color_type, $color_end,
148
+ if ((struct RHash *)($arg0))->ntbl
149
+ printf "len=%ld ", ((struct RHash *)($arg0))->ntbl->num_entries
150
+ end
151
+ print (struct RHash *)($arg0)
152
+ else
153
+ if ($flags & RUBY_T_MASK) == RUBY_T_STRUCT
154
+ printf "%sT_STRUCT%s: len=%ld ", $color_type, $color_end, \
155
+ (($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \
156
+ ($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) >> (RUBY_FL_USHIFT+1) : \
157
+ ((struct RStruct *)($arg0))->as.heap.len)
158
+ print (struct RStruct *)($arg0)
159
+ x/xw (($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \
160
+ ((struct RStruct *)($arg0))->as.ary : \
161
+ ((struct RStruct *)($arg0))->as.heap.ptr)
162
+ else
163
+ if ($flags & RUBY_T_MASK) == RUBY_T_BIGNUM
164
+ printf "%sT_BIGNUM%s: sign=%d len=%ld ", $color_type, $color_end, \
165
+ (($flags & RUBY_FL_USER1) != 0), \
166
+ (($flags & RUBY_FL_USER2) ? \
167
+ ($flags & (RUBY_FL_USER5|RUBY_FL_USER4|RUBY_FL_USER3)) >> (RUBY_FL_USHIFT+3) : \
168
+ ((struct RBignum*)($arg0))->as.heap.len)
169
+ if $flags & RUBY_FL_USER2
170
+ printf "(embed) "
171
+ end
172
+ print (struct RBignum *)($arg0)
173
+ x/xw (($flags & RUBY_FL_USER2) ? \
174
+ ((struct RBignum*)($arg0))->as.ary : \
175
+ ((struct RBignum*)($arg0))->as.heap.digits)
176
+ else
177
+ if ($flags & RUBY_T_MASK) == RUBY_T_RATIONAL
178
+ printf "%sT_RATIONAL%s: ", $color_type, $color_end
179
+ print (struct RRational *)($arg0)
180
+ else
181
+ if ($flags & RUBY_T_MASK) == RUBY_T_COMPLEX
182
+ printf "%sT_COMPLEX%s: ", $color_type, $color_end
183
+ print (struct RComplex *)($arg0)
184
+ else
185
+ if ($flags & RUBY_T_MASK) == RUBY_T_FILE
186
+ printf "%sT_FILE%s: ", $color_type, $color_end
187
+ print (struct RFile *)($arg0)
188
+ output *((struct RFile *)($arg0))->fptr
189
+ printf "\n"
190
+ else
191
+ if ($flags & RUBY_T_MASK) == RUBY_T_TRUE
192
+ printf "%sT_TRUE%s: ", $color_type, $color_end
193
+ print (struct RBasic *)($arg0)
194
+ else
195
+ if ($flags & RUBY_T_MASK) == RUBY_T_FALSE
196
+ printf "%sT_FALSE%s: ", $color_type, $color_end
197
+ print (struct RBasic *)($arg0)
198
+ else
199
+ if ($flags & RUBY_T_MASK) == RUBY_T_DATA
200
+ if ((struct RTypedData *)($arg0))->typed_flag == 1
201
+ printf "%sT_DATA%s(%s): ", $color_type, $color_end, ((struct RTypedData *)($arg0))->type->wrap_struct_name
202
+ print (struct RTypedData *)($arg0)
203
+ else
204
+ printf "%sT_DATA%s: ", $color_type, $color_end
205
+ print (struct RData *)($arg0)
206
+ end
207
+ else
208
+ if ($flags & RUBY_T_MASK) == RUBY_T_MATCH
209
+ printf "%sT_MATCH%s: ", $color_type, $color_end
210
+ print (struct RMatch *)($arg0)
211
+ else
212
+ if ($flags & RUBY_T_MASK) == RUBY_T_SYMBOL
213
+ printf "%sT_SYMBOL%s: ", $color_type, $color_end
214
+ print (struct RBasic *)($arg0)
215
+ else
216
+ if ($flags & RUBY_T_MASK) == RUBY_T_UNDEF
217
+ printf "%sT_UNDEF%s: ", $color_type, $color_end
218
+ print (struct RBasic *)($arg0)
219
+ else
220
+ if ($flags & RUBY_T_MASK) == RUBY_T_NODE
221
+ printf "%sT_NODE%s(", $color_type, $color_end
222
+ output (enum node_type)(($flags&RUBY_NODE_TYPEMASK)>>RUBY_NODE_TYPESHIFT)
223
+ printf "): "
224
+ print *(NODE *)($arg0)
225
+ else
226
+ if ($flags & RUBY_T_MASK) == RUBY_T_ZOMBIE
227
+ printf "%sT_ZOMBIE%s: ", $color_type, $color_end
228
+ print (struct RData *)($arg0)
229
+ else
230
+ printf "%sunknown%s: ", $color_type, $color_end
231
+ print (struct RBasic *)($arg0)
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+ document rp
266
+ Print a Ruby's VALUE.
267
+ end
268
+
269
+ define rp_id
270
+ set $id = (ID)$arg0
271
+ if $id == '!' || $id == '+' || $id == '-' || $id == '*' || $id == '/' || $id == '%' || $id == '<' || $id == '>' || $id == '`'
272
+ printf "(:%c)\n", $id
273
+ else
274
+ if $id == idDot2
275
+ printf "(:..)\n"
276
+ else
277
+ if $id == idDot3
278
+ printf "(:...)\n"
279
+ else
280
+ if $id == idUPlus
281
+ printf "(:+@)\n"
282
+ else
283
+ if $id == idUMinus
284
+ printf "(:-@)\n"
285
+ else
286
+ if $id == idPow
287
+ printf "(:**)\n"
288
+ else
289
+ if $id == idCmp
290
+ printf "(:<=>)\n"
291
+ else
292
+ if $id == idLTLT
293
+ printf "(:<<)\n"
294
+ else
295
+ if $id == idLE
296
+ printf "(:<=)\n"
297
+ else
298
+ if $id == idGE
299
+ printf "(:>=)\n"
300
+ else
301
+ if $id == idEq
302
+ printf "(:==)\n"
303
+ else
304
+ if $id == idEqq
305
+ printf "(:===)\n"
306
+ else
307
+ if $id == idNeq
308
+ printf "(:!=)\n"
309
+ else
310
+ if $id == idEqTilde
311
+ printf "(:=~)\n"
312
+ else
313
+ if $id == idNeqTilde
314
+ printf "(:!~)\n"
315
+ else
316
+ if $id == idAREF
317
+ printf "(:[])\n"
318
+ else
319
+ if $id == idASET
320
+ printf "(:[]=)\n"
321
+ else
322
+ if $id <= tLAST_OP_ID
323
+ printf "O"
324
+ else
325
+ set $id_type = $id & RUBY_ID_SCOPE_MASK
326
+ if $id_type == RUBY_ID_LOCAL
327
+ printf "l"
328
+ else
329
+ if $id_type == RUBY_ID_INSTANCE
330
+ printf "i"
331
+ else
332
+ if $id_type == RUBY_ID_GLOBAL
333
+ printf "G"
334
+ else
335
+ if $id_type == RUBY_ID_ATTRSET
336
+ printf "a"
337
+ else
338
+ if $id_type == RUBY_ID_CONST
339
+ printf "C"
340
+ else
341
+ if $id_type == RUBY_ID_CLASS
342
+ printf "c"
343
+ else
344
+ printf "j"
345
+ end
346
+ end
347
+ end
348
+ end
349
+ end
350
+ end
351
+ end
352
+ printf "(%ld): ", $id
353
+ rb_numtable_entry global_symbols.id_str $id
354
+ if $rb_numtable_rec
355
+ rp_string $rb_numtable_rec
356
+ else
357
+ echo undef\n
358
+ end
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end
374
+ end
375
+ end
376
+ end
377
+ document rp_id
378
+ Print an ID.
379
+ end
380
+
381
+ define rp_string
382
+ set $flags = ((struct RBasic*)($arg0))->flags
383
+ set print address off
384
+ output (char *)(($flags & RUBY_FL_USER1) ? \
385
+ ((struct RString*)($arg0))->as.heap.ptr : \
386
+ ((struct RString*)($arg0))->as.ary)
387
+ set print address on
388
+ printf " bytesize:%ld ", ($flags & RUBY_FL_USER1) ? \
389
+ ((struct RString*)($arg0))->as.heap.len : \
390
+ (($flags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2)
391
+ if !($flags & RUBY_FL_USER1)
392
+ printf "(embed) "
393
+ else
394
+ if ($flags & RUBY_FL_USER2)
395
+ printf "(shared) "
396
+ end
397
+ if ($flags & RUBY_FL_USER3)
398
+ printf "(assoc) "
399
+ end
400
+ end
401
+ printf "encoding:%d ", ($flags & RUBY_ENCODING_MASK) >> RUBY_ENCODING_SHIFT
402
+ if ($flags & RUBY_ENC_CODERANGE_MASK) == 0
403
+ printf "coderange:unknown "
404
+ else
405
+ if ($flags & RUBY_ENC_CODERANGE_MASK) == RUBY_ENC_CODERANGE_7BIT
406
+ printf "coderange:7bit "
407
+ else
408
+ if ($flags & RUBY_ENC_CODERANGE_MASK) == RUBY_ENC_CODERANGE_VALID
409
+ printf "coderange:valid "
410
+ else
411
+ printf "coderange:broken "
412
+ end
413
+ end
414
+ end
415
+ print (struct RString *)($arg0)
416
+ end
417
+ document rp_string
418
+ Print the content of a String.
419
+ end
420
+
421
+ define rp_class
422
+ printf "(struct RClass *) %p", (void*)$arg0
423
+ if ((struct RClass *)($arg0))->ptr.origin != $arg0
424
+ printf " -> %p", ((struct RClass *)($arg0))->ptr.origin
425
+ end
426
+ printf "\n"
427
+ rb_classname $arg0
428
+ print *(struct RClass *)($arg0)
429
+ print *((struct RClass *)($arg0))->ptr
430
+ end
431
+ document rp_class
432
+ Print the content of a Class/Module.
433
+ end
434
+
435
+ define nd_type
436
+ print (enum node_type)((((NODE*)($arg0))->flags&RUBY_NODE_TYPEMASK)>>RUBY_NODE_TYPESHIFT)
437
+ end
438
+ document nd_type
439
+ Print a Ruby' node type.
440
+ end
441
+
442
+ define nd_file
443
+ print ((NODE*)($arg0))->nd_file
444
+ end
445
+ document nd_file
446
+ Print the source file name of a node.
447
+ end
448
+
449
+ define nd_line
450
+ print ((unsigned int)((((NODE*)($arg0))->flags>>RUBY_NODE_LSHIFT)&RUBY_NODE_LMASK))
451
+ end
452
+ document nd_line
453
+ Print the source line number of a node.
454
+ end
455
+
456
+ # Print members of ruby node.
457
+
458
+ define nd_head
459
+ printf "%su1.node%s: ", $color_highlite, $color_end
460
+ rp ($arg0).u1.node
461
+ end
462
+
463
+ define nd_alen
464
+ printf "%su2.argc%s: ", $color_highlite, $color_end
465
+ p ($arg0).u2.argc
466
+ end
467
+
468
+ define nd_next
469
+ printf "%su3.node%s: ", $color_highlite, $color_end
470
+ rp ($arg0).u3.node
471
+ end
472
+
473
+
474
+ define nd_cond
475
+ printf "%su1.node%s: ", $color_highlite, $color_end
476
+ rp ($arg0).u1.node
477
+ end
478
+
479
+ define nd_body
480
+ printf "%su2.node%s: ", $color_highlite, $color_end
481
+ rp ($arg0).u2.node
482
+ end
483
+
484
+ define nd_else
485
+ printf "%su3.node%s: ", $color_highlite, $color_end
486
+ rp ($arg0).u3.node
487
+ end
488
+
489
+
490
+ define nd_orig
491
+ printf "%su3.value%s: ", $color_highlite, $color_end
492
+ rp ($arg0).u3.value
493
+ end
494
+
495
+
496
+ define nd_resq
497
+ printf "%su2.node%s: ", $color_highlite, $color_end
498
+ rp ($arg0).u2.node
499
+ end
500
+
501
+ define nd_ensr
502
+ printf "%su3.node%s: ", $color_highlite, $color_end
503
+ rp ($arg0).u3.node
504
+ end
505
+
506
+
507
+ define nd_1st
508
+ printf "%su1.node%s: ", $color_highlite, $color_end
509
+ rp ($arg0).u1.node
510
+ end
511
+
512
+ define nd_2nd
513
+ printf "%su2.node%s: ", $color_highlite, $color_end
514
+ rp ($arg0).u2.node
515
+ end
516
+
517
+
518
+ define nd_stts
519
+ printf "%su1.node%s: ", $color_highlite, $color_end
520
+ rp ($arg0).u1.node
521
+ end
522
+
523
+
524
+ define nd_entry
525
+ printf "%su3.entry%s: ", $color_highlite, $color_end
526
+ p ($arg0).u3.entry
527
+ end
528
+
529
+ define nd_vid
530
+ printf "%su1.id%s: ", $color_highlite, $color_end
531
+ p ($arg0).u1.id
532
+ end
533
+
534
+ define nd_cflag
535
+ printf "%su2.id%s: ", $color_highlite, $color_end
536
+ p ($arg0).u2.id
537
+ end
538
+
539
+ define nd_cval
540
+ printf "%su3.value%s: ", $color_highlite, $color_end
541
+ rp ($arg0).u3.value
542
+ end
543
+
544
+
545
+ define nd_cnt
546
+ printf "%su3.cnt%s: ", $color_highlite, $color_end
547
+ p ($arg0).u3.cnt
548
+ end
549
+
550
+ define nd_tbl
551
+ printf "%su1.tbl%s: ", $color_highlite, $color_end
552
+ p ($arg0).u1.tbl
553
+ end
554
+
555
+
556
+ define nd_var
557
+ printf "%su1.node%s: ", $color_highlite, $color_end
558
+ rp ($arg0).u1.node
559
+ end
560
+
561
+ define nd_ibdy
562
+ printf "%su2.node%s: ", $color_highlite, $color_end
563
+ rp ($arg0).u2.node
564
+ end
565
+
566
+ define nd_iter
567
+ printf "%su3.node%s: ", $color_highlite, $color_end
568
+ rp ($arg0).u3.node
569
+ end
570
+
571
+
572
+ define nd_value
573
+ printf "%su2.node%s: ", $color_highlite, $color_end
574
+ rp ($arg0).u2.node
575
+ end
576
+
577
+ define nd_aid
578
+ printf "%su3.id%s: ", $color_highlite, $color_end
579
+ p ($arg0).u3.id
580
+ end
581
+
582
+
583
+ define nd_lit
584
+ printf "%su1.value%s: ", $color_highlite, $color_end
585
+ rp ($arg0).u1.value
586
+ end
587
+
588
+
589
+ define nd_frml
590
+ printf "%su1.node%s: ", $color_highlite, $color_end
591
+ rp ($arg0).u1.node
592
+ end
593
+
594
+ define nd_rest
595
+ printf "%su2.argc%s: ", $color_highlite, $color_end
596
+ p ($arg0).u2.argc
597
+ end
598
+
599
+ define nd_opt
600
+ printf "%su1.node%s: ", $color_highlite, $color_end
601
+ rp ($arg0).u1.node
602
+ end
603
+
604
+
605
+ define nd_recv
606
+ printf "%su1.node%s: ", $color_highlite, $color_end
607
+ rp ($arg0).u1.node
608
+ end
609
+
610
+ define nd_mid
611
+ printf "%su2.id%s: ", $color_highlite, $color_end
612
+ p ($arg0).u2.id
613
+ end
614
+
615
+ define nd_args
616
+ printf "%su3.node%s: ", $color_highlite, $color_end
617
+ rp ($arg0).u3.node
618
+ end
619
+
620
+
621
+ define nd_noex
622
+ printf "%su1.id%s: ", $color_highlite, $color_end
623
+ p ($arg0).u1.id
624
+ end
625
+
626
+ define nd_defn
627
+ printf "%su3.node%s: ", $color_highlite, $color_end
628
+ rp ($arg0).u3.node
629
+ end
630
+
631
+
632
+ define nd_old
633
+ printf "%su1.id%s: ", $color_highlite, $color_end
634
+ p ($arg0).u1.id
635
+ end
636
+
637
+ define nd_new
638
+ printf "%su2.id%s: ", $color_highlite, $color_end
639
+ p ($arg0).u2.id
640
+ end
641
+
642
+
643
+ define nd_cfnc
644
+ printf "%su1.cfunc%s: ", $color_highlite, $color_end
645
+ p ($arg0).u1.cfunc
646
+ end
647
+
648
+ define nd_argc
649
+ printf "%su2.argc%s: ", $color_highlite, $color_end
650
+ p ($arg0).u2.argc
651
+ end
652
+
653
+
654
+ define nd_cname
655
+ printf "%su1.id%s: ", $color_highlite, $color_end
656
+ p ($arg0).u1.id
657
+ end
658
+
659
+ define nd_super
660
+ printf "%su3.node%s: ", $color_highlite, $color_end
661
+ rp ($arg0).u3.node
662
+ end
663
+
664
+
665
+ define nd_modl
666
+ printf "%su1.id%s: ", $color_highlite, $color_end
667
+ p ($arg0).u1.id
668
+ end
669
+
670
+ define nd_clss
671
+ printf "%su1.value%s: ", $color_highlite, $color_end
672
+ rp ($arg0).u1.value
673
+ end
674
+
675
+
676
+ define nd_beg
677
+ printf "%su1.node%s: ", $color_highlite, $color_end
678
+ rp ($arg0).u1.node
679
+ end
680
+
681
+ define nd_end
682
+ printf "%su2.node%s: ", $color_highlite, $color_end
683
+ rp ($arg0).u2.node
684
+ end
685
+
686
+ define nd_state
687
+ printf "%su3.state%s: ", $color_highlite, $color_end
688
+ p ($arg0).u3.state
689
+ end
690
+
691
+ define nd_rval
692
+ printf "%su2.value%s: ", $color_highlite, $color_end
693
+ rp ($arg0).u2.value
694
+ end
695
+
696
+
697
+ define nd_nth
698
+ printf "%su2.argc%s: ", $color_highlite, $color_end
699
+ p ($arg0).u2.argc
700
+ end
701
+
702
+
703
+ define nd_tag
704
+ printf "%su1.id%s: ", $color_highlite, $color_end
705
+ p ($arg0).u1.id
706
+ end
707
+
708
+ define nd_tval
709
+ printf "%su2.value%s: ", $color_highlite, $color_end
710
+ rp ($arg0).u2.value
711
+ end
712
+
713
+ define rb_p
714
+ call rb_p($arg0)
715
+ end
716
+
717
+ define rb_numtable_entry
718
+ set $rb_numtable_tbl = $arg0
719
+ set $rb_numtable_id = (st_data_t)$arg1
720
+ set $rb_numtable_key = 0
721
+ set $rb_numtable_rec = 0
722
+ if $rb_numtable_tbl->entries_packed
723
+ set $rb_numtable_p = $rb_numtable_tbl->as.packed.bins
724
+ while $rb_numtable_p && $rb_numtable_p < $rb_numtable_tbl->as.packed.bins+$rb_numtable_tbl->num_entries
725
+ if $rb_numtable_p.k == $rb_numtable_id
726
+ set $rb_numtable_key = $rb_numtable_p.k
727
+ set $rb_numtable_rec = $rb_numtable_p.v
728
+ set $rb_numtable_p = 0
729
+ else
730
+ set $rb_numtable_p = $rb_numtable_p + 1
731
+ end
732
+ end
733
+ else
734
+ set $rb_numtable_p = $rb_numtable_tbl->as.big.bins[$rb_numtable_id % $rb_numtable_tbl->num_bins]
735
+ while $rb_numtable_p
736
+ if $rb_numtable_p->key == $rb_numtable_id
737
+ set $rb_numtable_key = $rb_numtable_p->key
738
+ set $rb_numtable_rec = $rb_numtable_p->record
739
+ set $rb_numtable_p = 0
740
+ else
741
+ set $rb_numtable_p = $rb_numtable_p->next
742
+ end
743
+ end
744
+ end
745
+ end
746
+
747
+ define rb_id2name
748
+ ruby_gdb_init
749
+ printf "%sID%s: ", $color_type, $color_end
750
+ rp_id $arg0
751
+ end
752
+ document rb_id2name
753
+ Print the name of id
754
+ end
755
+
756
+ define rb_method_entry
757
+ set $rb_method_entry_klass = (struct RClass *)$arg0
758
+ set $rb_method_entry_id = (ID)$arg1
759
+ set $rb_method_entry_me = (rb_method_entry_t *)0
760
+ while !$rb_method_entry_me && $rb_method_entry_klass
761
+ rb_numtable_entry $rb_method_entry_klass->m_tbl_wrapper->tbl $rb_method_entry_id
762
+ set $rb_method_entry_me = (rb_method_entry_t *)$rb_numtable_rec
763
+ if !$rb_method_entry_me
764
+ set $rb_method_entry_klass = (struct RClass *)$rb_method_entry_klass->ptr->super
765
+ end
766
+ end
767
+ if $rb_method_entry_me
768
+ print *$rb_method_entry_klass
769
+ print *$rb_method_entry_me
770
+ else
771
+ echo method not found\n
772
+ end
773
+ end
774
+ document rb_method_entry
775
+ Search method entry by class and id
776
+ end
777
+
778
+ define rb_classname
779
+ # up to 128bit int
780
+ set $rb_classname_permanent = "0123456789ABCDEF"
781
+ set $rb_classname = classname($arg0, $rb_classname_permanent)
782
+ if $rb_classname != RUBY_Qnil
783
+ rp $rb_classname
784
+ else
785
+ echo anonymous class/module\n
786
+ end
787
+ end
788
+
789
+ define rb_ancestors
790
+ set $rb_ancestors_module = $arg0
791
+ while $rb_ancestors_module
792
+ rp_class $rb_ancestors_module
793
+ set $rb_ancestors_module = ((struct RClass *)($rb_ancestors_module))->ptr.super
794
+ end
795
+ end
796
+ document rb_ancestors
797
+ Print ancestors.
798
+ end
799
+
800
+ define rb_backtrace
801
+ call rb_backtrace()
802
+ end
803
+
804
+ define iseq
805
+ if ruby_dummy_gdb_enums.special_consts
806
+ end
807
+ if ($arg0)->type == ISEQ_ELEMENT_NONE
808
+ echo [none]\n
809
+ end
810
+ if ($arg0)->type == ISEQ_ELEMENT_LABEL
811
+ print *(LABEL*)($arg0)
812
+ end
813
+ if ($arg0)->type == ISEQ_ELEMENT_INSN
814
+ print *(INSN*)($arg0)
815
+ if ((INSN*)($arg0))->insn_id != YARVINSN_jump
816
+ set $i = 0
817
+ set $operand_size = ((INSN*)($arg0))->operand_size
818
+ set $operands = ((INSN*)($arg0))->operands
819
+ while $i < $operand_size
820
+ rp $operands[$i++]
821
+ end
822
+ end
823
+ end
824
+ if ($arg0)->type == ISEQ_ELEMENT_ADJUST
825
+ print *(ADJUST*)($arg0)
826
+ end
827
+ end
828
+
829
+ define rb_ps
830
+ rb_ps_vm ruby_current_vm
831
+ end
832
+ document rb_ps
833
+ Dump all threads and their callstacks
834
+ end
835
+
836
+ define rb_ps_vm
837
+ print $ps_vm = (rb_vm_t*)$arg0
838
+ set $ps_threads = (st_table*)$ps_vm->living_threads
839
+ if $ps_threads->entries_packed
840
+ set $ps_threads_i = 0
841
+ while $ps_threads_i < $ps_threads->num_entries
842
+ set $ps_threads_key = (st_data_t)$ps_threads->as.packed.entries[$ps_threads_i].key
843
+ set $ps_threads_val = (st_data_t)$ps_threads->as.packed.entries[$ps_threads_i].val
844
+ rb_ps_thread $ps_threads_key $ps_threads_val
845
+ set $ps_threads_i = $ps_threads_i + 1
846
+ end
847
+ else
848
+ set $ps_threads_ptr = (st_table_entry*)$ps_threads->head
849
+ while $ps_threads_ptr
850
+ set $ps_threads_key = (st_data_t)$ps_threads_ptr->key
851
+ set $ps_threads_val = (st_data_t)$ps_threads_ptr->record
852
+ rb_ps_thread $ps_threads_key $ps_threads_val
853
+ set $ps_threads_ptr = (st_table_entry*)$ps_threads_ptr->fore
854
+ end
855
+ end
856
+ end
857
+ document rb_ps_vm
858
+ Dump all threads in a (rb_vm_t*) and their callstacks
859
+ end
860
+
861
+ define rb_ps_thread
862
+ set $ps_thread = (struct RTypedData*)$arg0
863
+ set $ps_thread_id = $arg1
864
+ print $ps_thread_th = (rb_thread_t*)$ps_thread->data
865
+ end
866
+
867
+ # Details: https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/MachineInstructionsTraceWithGDB
868
+ define trace_machine_instructions
869
+ set logging on
870
+ set height 0
871
+ set width 0
872
+ display/i $pc
873
+ while !$exit_code
874
+ info line *$pc
875
+ si
876
+ end
877
+ end
878
+
879
+ define SDR
880
+ call rb_vmdebug_stack_dump_raw_current()
881
+ end
882
+