Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add GDB trick

  • Loading branch information...
commit 2dbde57b3cb19cb1a58f266b3aef245d8e90ffaa 1 parent 548a941
@Watson1978 Watson1978 authored
Showing with 115 additions and 0 deletions.
  1. +106 −0 .gdbinit
  2. +9 −0 HACKING.rdoc
View
106 .gdbinit
@@ -0,0 +1,106 @@
+define rp
+ set $types = rb_type($arg0)
+
+ if $types == 0x01
+ # RUBY_T_OBJECT
+ p "T_OBJECT:"
+ p (struct RBasic *)($arg0)
+ else
+ if $types == 0x02
+ # RUBY_T_CLASS
+ p "T_CLASS:"
+ p (struct RBasic *)($arg0)
+ else
+ if $types == 0x03
+ # RUBY_T_MODULE
+ p "T_MODULE:"
+ p (struct RBasic *)($arg0)
+ else
+ if $types == 0x04
+ # RUBY_T_FLOAT
+ p "T_FLOAT:"
+ p coerce_ptr_to_double($arg0)
+ else
+ if $types == 0x05
+ # RUBY_T_STRING
+ p "T_STRING:"
+ p *(struct RString *)($arg0)
+ else
+ if $types == 0x06
+ # RUBY_T_REGEXP
+ p "T_REGEXP:"
+ p *(struct rb_regexp *)($arg0)
+ else
+ if $types == 0x07
+ # RUBY_T_ARRAY
+ p "T_ARRAY:"
+ p *(struct RArray *)($arg0)
+ else
+ if $types == 0x08
+ # RUBY_T_HASH
+ p "T_HASH:"
+ p *(struct RHash *)($arg0)
+ else
+ if $types == 0x09
+ # RUBY_T_STRUCT
+ p "T_STRUCT:"
+ p *(struct RStruct *)($arg0)
+ else
+ if $types == 0x0a
+ # RUBY_T_BIGNUM
+ p "T_BIGNUM:"
+ p *(struct RBignum *)($arg0)
+ else
+ if $types == 0x0b
+ # RUBY_T_FILE
+ p "T_FILE:"
+ p *(struct RFile *)($arg0)
+ p *((struct RFile *)($arg0))->fptr
+ else
+ if $types == 0x0c
+ # RUBY_T_DATA
+ p "T_DATA:"
+ p *(struct RData *)($arg0)
+ else
+ if $types == 0x0d
+ # RUBY_T_MATCH
+ p "T_MATCH:"
+ p *(struct rb_match *)($arg0)
+ else
+ if $types == 0x0e
+ # RUBY_T_COMPLEX
+ p "T_COMPLEX:"
+ p *(struct RComplex *)($arg0)
+ else
+ if $types == 0x0f
+ # RUBY_T_RATIONAL
+ p "T_RATIONAL:"
+ p *(struct RRational *)($arg0)
+ else
+ if $types == 0x11
+ # RUBY_T_NIL
+ p "T_NIL:"
+ p "nil"
+ else
+ if $types == 0x12
+ # RUBY_T_TRUE
+ p "T_TRUE:"
+ p "true"
+ else
+ if $types == 0x14
+ # RUBY_T_SYMBOL
+ p "T_SYMBOL:"
+ p *(struct rb_sym_t *)($arg0)
+ else
+ if $types == 0x15
+ # RUBY_T_FIXNUM
+ p "T_FIXNUM:"
+ p rb_num2int($arg0)
+ end
+ if $types == 0x1b
+ # RUBY_T_UNDEF
+ p "T_UNDEF:"
+ p "undef"
+ end
+
+end
View
9 HACKING.rdoc
@@ -173,3 +173,12 @@ The following environment variables might help you debug easy bugs.
* To print the GC references of a given memory object:
(gdb) info gc-references <address>
+
+* To print the content of Ruby object:
+ (gdb) rp <variable name of Ruby object>
+
+ ex)
+ (gdb) rp str
+ $1 = "T_STRING:"
+ $2 = {basic = {klass = 17183054944, flags = 0}, encoding = 0x40040a280, capacity_in_bytes = 6, length_in_bytes = 5, cached_length = 0,
+ bytes = 0x40049e640 "hello", flags = 0 '\0'}
Please sign in to comment.
Something went wrong with that request. Please try again.