Skip to content

Commit 9500e29

Browse files
Refactor.
1 parent d5a47c2 commit 9500e29

30 files changed

+97
-116
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-inspect $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-inspect"
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-inspect`) - 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-inspect $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-inspect $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-inspect $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-inspect`, `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-inspect` 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-inspect` 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-inspect` when you need:
1515

1616
## Basic Usage
1717

18-
The `rb-inspect` 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-inspect <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-inspect 0 # <T_FALSE>
37-
(gdb) rb-inspect 8 # <T_NIL>
38-
(gdb) rb-inspect 20 # <T_TRUE>
39-
(gdb) rb-inspect 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-inspect $ec->errinfo # Exception object
50-
(gdb) rb-inspect $ec->cfp->sp[-1] # Top of VM stack
51-
(gdb) rb-inspect $ec->storage # Fiber storage hash
52-
(gdb) rb-inspect (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-inspect $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-inspect $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-inspect $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-inspect $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-inspect $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-inspect $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-inspect $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-inspect $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-inspect $ec->cfp->sp[-1] # Last argument
171-
(gdb) rb-inspect $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-inspect $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-inspect` 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-inspect $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-inspect *(VALUE*)($sp - 1) # Top of stack
144-
(gdb) rb-inspect *(VALUE*)($sp - 2) # Second value
145-
(gdb) rb-inspect *(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

data/toolbox/init.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# Try to load each extension individually
2626
extensions_to_load = [
27-
('print', 'rb-inspect'),
27+
('print', 'rb-print'),
2828
('context', 'rb-context, rb-context-storage'),
2929
('fiber', 'rb-fiber-scan-heap, rb-fiber-switch'),
3030
('stack', 'rb-stack-trace'),
@@ -33,10 +33,8 @@
3333

3434
for module_name, commands in extensions_to_load:
3535
try:
36-
print(f"DEBUG: Loading module {module_name}", file=sys.stderr)
3736
if module_name == 'print':
3837
import print as print_module
39-
print(f"DEBUG: print module loaded successfully", file=sys.stderr)
4038
elif module_name == 'context':
4139
import context
4240
elif module_name == 'fiber':
@@ -47,7 +45,7 @@
4745
import heap
4846
loaded_extensions.append((module_name, commands))
4947
except Exception as e:
50-
# Catch all exceptions, not just ImportError
48+
# Catch all exceptions during module load
5149
failed_extensions.append((module_name, str(e)))
5250
import traceback
5351
print(f"Failed to load {module_name}: {e}", file=sys.stderr)
@@ -60,9 +58,6 @@
6058
if debugger.DEBUGGER_NAME == 'lldb':
6159
import lldb
6260

63-
# Debug: Show what commands are in the registry
64-
print(f"DEBUG: Commands in registry: {list(debugger.Command._commands.keys())}", file=sys.stderr)
65-
6661
# Get all registered commands
6762
for cmd_name, cmd_obj in debugger.Command._commands.items():
6863
# Create a wrapper function in this module's namespace

data/toolbox/print.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"""Object inspection command for Ruby values."""
1+
"""Print command for Ruby values."""
22

33
import debugger
44
import sys
55

6-
print("DEBUG: inspect.py is being loaded", file=sys.stderr)
7-
86
# Import utilities
97
import command
108
import constants
@@ -19,8 +17,6 @@
1917
import rbasic
2018
import format
2119

22-
print("DEBUG: All imports done in inspect.py", file=sys.stderr)
23-
2420

2521
class RubyObjectPrinter:
2622
"""Print Ruby objects with recursive descent into nested structures."""
@@ -79,16 +75,6 @@ def invoke(self, arguments, terminal, from_tty):
7975
traceback.print_exc(file=sys.stderr)
8076

8177

82-
print("DEBUG: RubyObjectPrinter class defined", file=sys.stderr)
83-
8478
# Register command using new interface
85-
print("DEBUG: About to register rb-inspect", file=sys.stderr)
86-
try:
87-
print(f"DEBUG: Registering rb-inspect, debugger.register = {debugger.register}", file=sys.stderr)
88-
result = debugger.register("rb-inspect", RubyObjectPrinter, usage=RubyObjectPrinter.USAGE)
89-
print(f"DEBUG: Registration result = {result}", file=sys.stderr)
90-
except Exception as e:
91-
print(f"ERROR: Failed to register rb-inspect: {e}", file=sys.stderr)
92-
import traceback
93-
traceback.print_exc(file=sys.stderr)
79+
debugger.register("rb-print", RubyObjectPrinter, usage=RubyObjectPrinter.USAGE)
9480

data/toolbox/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data/toolbox/
1414
│ └── *.md # Documentation
1515
1616
# Ruby debugging extensions (currently GDB-specific, migrating to abstraction)
17-
├── object.py # Object inspection (rb-inspect)
17+
├── object.py # Object inspection (rb-print)
1818
├── fiber.py # Fiber debugging (rb-fiber-scan-heap, rb-fiber-switch)
1919
├── heap.py # Heap scanning (rb-heap-scan)
2020
├── stack.py # Stack inspection
@@ -113,7 +113,7 @@ command script import /path/to/gem/data/toolbox/init.py
113113
## Available Commands
114114

115115
### Object Inspection
116-
- `rb-inspect <expression> [--depth N]` - Print Ruby objects with recursion
116+
- `rb-print <expression> [--depth N]` - Print Ruby objects with recursion
117117

118118
### Fiber Debugging
119119
- `rb-fiber-scan-heap [--limit N]` - Scan heap for fiber objects
@@ -151,14 +151,14 @@ command script import /path/to/gem/data/toolbox/init.py
151151
Test with GDB:
152152
```bash
153153
gdb -q ruby
154-
(gdb) help rb-inspect
154+
(gdb) help rb-print
155155
(gdb) help rb-fiber-scan-heap
156156
```
157157

158158
Test with LLDB (once migrated):
159159
```bash
160160
lldb ruby
161-
(lldb) help rb-inspect
161+
(lldb) help rb-print
162162
(lldb) help rb-fiber-scan-heap
163163
```
164164

fixtures/toolbox/gdb/object/can_handle_bignum.gdb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ break ruby_process_options
88
run
99
set $value = rb_eval_string("[123456789012345678901234567890, -999999999999999999999999999999]")
1010
echo ===TOOLBOX-OUTPUT-START===\n
11-
rb-inspect $value
11+
rb-print $value
1212
echo ===TOOLBOX-OUTPUT-END===\n
1313
quit

fixtures/toolbox/gdb/object/can_handle_debug_flag.gdb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source data/toolbox/init.py
44

5-
rb-inspect 85 --debug
5+
rb-print 85 --debug
66
quit
77

fixtures/toolbox/gdb/object/can_handle_depth_flag.gdb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source data/toolbox/init.py
44

5-
rb-inspect 85 --depth 3
5+
rb-print 85 --depth 3
66
quit
77

0 commit comments

Comments
 (0)