Skip to content

Commit ecc01d7

Browse files
Rename object -> print and introduce better command pattern. (#4)
1 parent 2f5d4d0 commit ecc01d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2497
-2166
lines changed

context/fiber-debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ After switching to a fiber with `rb-fiber-scan-switch`, you can use standard GDB
161161
(gdb) bt # Show C backtrace
162162
(gdb) frame <n> # Switch to specific frame
163163
(gdb) info locals # Show local variables
164-
(gdb) rb-object-print $errinfo # Print exception if present
164+
(gdb) rb-print $errinfo # Print exception if present
165165
~~~
166166

167167
The fiber switch command sets up several convenience variables:

context/getting-started.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Status: ✓ Installed
6363
Test that extensions load automatically:
6464

6565
~~~ bash
66-
$ gdb --batch -ex "help rb-object-print"
66+
$ gdb --batch -ex "help rb-print"
6767
Recursively print Ruby hash and array structures...
6868
~~~
6969

@@ -88,7 +88,7 @@ This removes the source line from your `~/.gdbinit` or `~/.lldbinit`.
8888
Ruby GDB provides specialized commands for debugging Ruby at multiple levels:
8989

9090
- **Context Setup** (`rb-context`) - Get current execution context and set up convenience variables
91-
- **Object Inspection** (`rb-object-print`) - View Ruby objects, hashes, arrays, and structs with proper formatting
91+
- **Object Inspection** (`rb-print`) - View Ruby objects, hashes, arrays, and structs with proper formatting
9292
- **Fiber Debugging** (`rb-fiber-*`) - Scan heap for fibers, inspect state, and switch contexts
9393
- **Stack Analysis** (`rb-stack-trace`) - Examine combined VM (Ruby) and C (native) stack frames
9494
- **Heap Navigation** (`rb-heap-scan`) - Scan the Ruby heap to find objects by type
@@ -132,7 +132,7 @@ Diagnose the issue (extensions load automatically if installed):
132132
(gdb) rb-fiber-scan-heap # Scan heap for all fibers
133133
(gdb) rb-fiber-scan-stack-trace-all # Show backtraces for all fibers
134134
(gdb) rb-fiber-scan-switch 0 # Switch to main fiber
135-
(gdb) rb-object-print $errinfo --depth 2 # Print exception (now $errinfo is set)
135+
(gdb) rb-print $errinfo --depth 2 # Print exception (now $errinfo is set)
136136
(gdb) rb-heap-scan --type RUBY_T_HASH --limit 10 # Find hashes
137137
~~~
138138

@@ -146,7 +146,7 @@ When a Ruby exception occurs, you can inspect it in detail:
146146
(gdb) break rb_exc_raise
147147
(gdb) run
148148
(gdb) rb-context
149-
(gdb) rb-object-print $errinfo --depth 2
149+
(gdb) rb-print $errinfo --depth 2
150150
~~~
151151

152152
This shows the exception class, message, and any nested structures. The `rb-context` command displays the current execution context and sets up `$ec`, `$cfp`, and `$errinfo` convenience variables.
@@ -167,7 +167,7 @@ When working with fibers, you often need to see what each fiber is doing:
167167
Ruby hashes and arrays can contain nested structures:
168168

169169
~~~
170-
(gdb) rb-object-print $some_hash --depth 2
170+
(gdb) rb-print $some_hash --depth 2
171171
<T_HASH@...>
172172
[ 0] K: <T_SYMBOL> :name
173173
V: <T_STRING@...> "Alice"
@@ -197,4 +197,4 @@ On macOS with LLDB and Ruby <= 3.4.x, some commands including `rb-fiber-scan-hea
197197
**Workarounds:**
198198
- Use Ruby head: `ruby-install ruby-head -- CFLAGS="-g -O0"`
199199
- Use GDB instead of LLDB (works with Ruby 3.4.x)
200-
- Other commands like `rb-object-print`, `rb-stack-trace`, `rb-context` work fine
200+
- Other commands like `rb-print`, `rb-stack-trace`, `rb-context` work fine

context/object-inspection.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Object Inspection
22

3-
This guide explains how to use `rb-object-print` to inspect Ruby objects, hashes, arrays, and structs in GDB.
3+
This guide explains how to use `rb-print` to inspect Ruby objects, hashes, arrays, and structs in GDB.
44

55
## Why Object Inspection Matters
66

77
When debugging Ruby programs or analyzing core dumps, you often need to inspect complex data structures that are difficult to read in their raw memory representation. Standard GDB commands show pointer addresses and raw memory, but not the logical structure of Ruby objects.
88

9-
Use `rb-object-print` when you need:
9+
Use `rb-print` when you need:
1010

1111
- **Understand exception objects**: See the full exception hierarchy, message, and backtrace data
1212
- **Inspect fiber storage**: View thread-local data and fiber-specific variables
@@ -15,12 +15,12 @@ Use `rb-object-print` when you need:
1515

1616
## Basic Usage
1717

18-
The `rb-object-print` command recursively prints Ruby objects in a human-readable format.
18+
The `rb-print` command recursively prints Ruby objects in a human-readable format.
1919

2020
### Syntax
2121

2222
~~~
23-
rb-object-print <expression> [--depth N] [--debug]
23+
rb-print <expression> [--depth N] [--debug]
2424
~~~
2525

2626
Where:
@@ -33,10 +33,10 @@ Where:
3333
Print immediate values and special constants:
3434

3535
~~~
36-
(gdb) rb-object-print 0 # <T_FALSE>
37-
(gdb) rb-object-print 8 # <T_NIL>
38-
(gdb) rb-object-print 20 # <T_TRUE>
39-
(gdb) rb-object-print 85 # <T_FIXNUM> 42
36+
(gdb) rb-print 0 # <T_FALSE>
37+
(gdb) rb-print 8 # <T_NIL>
38+
(gdb) rb-print 20 # <T_TRUE>
39+
(gdb) rb-print 85 # <T_FIXNUM> 42
4040
~~~
4141

4242
These work without any Ruby process running, making them useful for learning and testing.
@@ -46,10 +46,10 @@ These work without any Ruby process running, making them useful for learning and
4646
Use any valid GDB expression:
4747

4848
~~~
49-
(gdb) rb-object-print $ec->errinfo # Exception object
50-
(gdb) rb-object-print $ec->cfp->sp[-1] # Top of VM stack
51-
(gdb) rb-object-print $ec->storage # Fiber storage hash
52-
(gdb) rb-object-print (VALUE)0x00007f8a12345678 # Object at specific address
49+
(gdb) rb-print $ec->errinfo # Exception object
50+
(gdb) rb-print $ec->cfp->sp[-1] # Top of VM stack
51+
(gdb) rb-print $ec->storage # Fiber storage hash
52+
(gdb) rb-print (VALUE)0x00007f8a12345678 # Object at specific address
5353
~~~
5454

5555
## Inspecting Hashes
@@ -61,7 +61,7 @@ Ruby hashes have two internal representations (ST table and AR table). The comma
6161
For hashes with fewer than 8 entries, Ruby uses an array-based implementation:
6262

6363
~~~
64-
(gdb) rb-object-print $some_hash
64+
(gdb) rb-print $some_hash
6565
<T_HASH@...>
6666
[ 0] K: <T_SYMBOL> :name
6767
V: <T_STRING@...> "Alice"
@@ -76,7 +76,7 @@ For hashes with fewer than 8 entries, Ruby uses an array-based implementation:
7676
For larger hashes, Ruby uses a hash table (output format is similar):
7777

7878
~~~
79-
(gdb) rb-object-print $large_hash
79+
(gdb) rb-print $large_hash
8080
<T_HASH@...>
8181
[ 0] K: <T_SYMBOL> :user_id
8282
V: <T_FIXNUM> 12345
@@ -90,12 +90,12 @@ For larger hashes, Ruby uses a hash table (output format is similar):
9090
Prevent overwhelming output from deeply nested structures:
9191

9292
~~~
93-
(gdb) rb-object-print $nested_hash --depth 1 # Only top level
93+
(gdb) rb-print $nested_hash --depth 1 # Only top level
9494
<T_HASH@...>
9595
[ 0] K: <T_SYMBOL> :data
9696
V: <T_HASH@...> # Nested hash not expanded
9797
98-
(gdb) rb-object-print $nested_hash --depth 2 # Expand one level
98+
(gdb) rb-print $nested_hash --depth 2 # Expand one level
9999
<T_HASH@...>
100100
[ 0] K: <T_SYMBOL> :data
101101
V: <T_HASH@...>
@@ -114,7 +114,7 @@ Arrays also have two representations based on size:
114114
Arrays display their elements with type information:
115115

116116
~~~
117-
(gdb) rb-object-print $array
117+
(gdb) rb-print $array
118118
<T_ARRAY@...>
119119
[ 0] <T_FIXNUM> 1
120120
[ 1] <T_FIXNUM> 2
@@ -124,7 +124,7 @@ Arrays display their elements with type information:
124124
For arrays with nested objects:
125125

126126
~~~
127-
(gdb) rb-object-print $array --depth 2
127+
(gdb) rb-print $array --depth 2
128128
<T_ARRAY@...>
129129
[ 0] <T_STRING@...> "first item"
130130
[ 1] <T_HASH@...>
@@ -138,7 +138,7 @@ For arrays with nested objects:
138138
Ruby Struct objects work similarly to arrays:
139139

140140
~~~
141-
(gdb) rb-object-print $struct_instance
141+
(gdb) rb-print $struct_instance
142142
<T_STRUCT@...>
143143
[ 0] <T_STRING@...> "John"
144144
[ 1] <T_FIXNUM> 25
@@ -155,7 +155,7 @@ When a fiber has an exception, inspect it:
155155
~~~
156156
(gdb) rb-fiber-scan-heap
157157
(gdb) rb-fiber-scan-switch 5 # Switch to fiber #5
158-
(gdb) rb-object-print $errinfo --depth 3
158+
(gdb) rb-print $errinfo --depth 3
159159
~~~
160160

161161
This reveals the full exception structure including any nested causes. After switching to a fiber, `$errinfo` and `$ec` convenience variables are automatically set.
@@ -167,8 +167,8 @@ Break at a method and examine arguments on the stack:
167167
~~~
168168
(gdb) break some_method
169169
(gdb) run
170-
(gdb) rb-object-print $ec->cfp->sp[-1] # Last argument
171-
(gdb) rb-object-print $ec->cfp->sp[-2] # Second-to-last argument
170+
(gdb) rb-print $ec->cfp->sp[-1] # Last argument
171+
(gdb) rb-print $ec->cfp->sp[-2] # Second-to-last argument
172172
~~~
173173

174174
### Examining Fiber Storage
@@ -178,17 +178,17 @@ Thread-local variables are stored in fiber storage:
178178
~~~
179179
(gdb) rb-fiber-scan-heap
180180
(gdb) rb-fiber-scan-switch 0
181-
(gdb) rb-object-print $ec->storage --depth 2
181+
(gdb) rb-print $ec->storage --depth 2
182182
~~~
183183

184184
This shows all thread-local variables and their values.
185185

186186
## Debugging with --debug Flag
187187

188-
When `rb-object-print` doesn't show what you expect, use `--debug`:
188+
When `rb-print` doesn't show what you expect, use `--debug`:
189189

190190
~~~
191-
(gdb) rb-object-print $suspicious_value --debug
191+
(gdb) rb-print $suspicious_value --debug
192192
DEBUG: Evaluated '$suspicious_value' to 0x7f8a1c567890
193193
DEBUG: Loaded constant RUBY_T_MASK = 31
194194
DEBUG: Object at 0x7f8a1c567890 with flags=0x20040005, type=0x5

context/stack-inspection.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ See what values are on the current frame's stack:
140140
(gdb) set $sp = $ec->cfp->sp
141141
142142
# Print values on stack
143-
(gdb) rb-object-print *(VALUE*)($sp - 1) # Top of stack
144-
(gdb) rb-object-print *(VALUE*)($sp - 2) # Second value
145-
(gdb) rb-object-print *(VALUE*)($sp - 3) # Third value
143+
(gdb) rb-print *(VALUE*)($sp - 1) # Top of stack
144+
(gdb) rb-print *(VALUE*)($sp - 2) # Second value
145+
(gdb) rb-print *(VALUE*)($sp - 3) # Third value
146146
~~~
147147

148148
### Tracking Fiber Switches

0 commit comments

Comments
 (0)