@@ -22,22 +22,18 @@ The first step in fiber debugging is finding all fibers in the heap.
2222Scan the entire Ruby heap for fiber objects:
2323
2424~~~
25- (gdb) rb-scan-fibers
26- Scanning 1250 heap pages ...
25+ (gdb) rb-fiber- scan-heap
26+ Scanning heap for Fiber objects ...
2727 Checked 45000 objects, found 12 fiber(s)...
28- Scan complete: checked 67890 objects
2928
3029Found 12 fiber(s):
3130
32- Fiber #0: 0x7f8a1c800000
31+ Fiber #0: <VALUE: 0x7f8a1c800000>
3332 Status: RESUMED
34- Stack: base=0x7f8a1d000000, size=1048576
35- VM Stack: 0x7f8a1c900000, size=4096
36- CFP: 0x7f8a1c901000
37-
38- Fiber #1: 0x7f8a1c800100
33+ Stack: 0x7f8a1d000000
34+
35+ Fiber #1: <VALUE:0x7f8a1c800100>
3936 Status: SUSPENDED
40- Exception: RuntimeError: Connection failed
4137 ...
4238~~~
4339
@@ -46,71 +42,58 @@ Fiber #1: 0x7f8a1c800100
4642For large applications, limit the scan:
4743
4844~~~
49- (gdb) rb-scan-fibers 10 # Find first 10 fibers only
45+ (gdb) rb-fiber- scan-heap 10 # Find first 10 fibers only
5046~~~
5147
5248### Caching Results
5349
5450Cache fiber addresses for faster subsequent access:
5551
5652~~~
57- (gdb) rb-scan-fibers --cache # Save to fibers.json
58- (gdb) rb-scan-fibers --cache my.json # Custom cache file
53+ (gdb) rb-fiber- scan-heap --cache # Save to fibers.json
54+ (gdb) rb-fiber- scan-heap --cache my.json # Custom cache file
5955~~~
6056
6157Later, load from cache instantly:
6258
6359~~~
64- (gdb) rb-scan-fibers --cache
65- Loaded 12 fiber address(es ) from fibers.json
60+ (gdb) rb-fiber- scan-heap --cache
61+ Loaded 12 fiber(s ) from fibers.json
6662~~~
6763
6864This is especially useful with core dumps where heap scanning is slow.
6965
7066## Inspecting Specific Fibers
7167
72- After scanning, inspect fibers by index:
68+ After scanning, you can switch to a specific fiber's context or view all backtraces.
7369
74- ### Fiber Overview
70+ ### View All Fiber Backtraces
7571
76- ~~~
77- (gdb) rb-fiber 5
78- Fiber #5: 0x7f8a1c800500
79- Status: SUSPENDED
80- Exception: IOError: Connection reset
81- Stack: base=0x7f8a1e000000, size=1048576
82- VM Stack: 0x7f8a1c950000, size=4096
83- CFP: 0x7f8a1c951000
84- EC: 0x7f8a1c800600
72+ See Ruby-level call stacks for all fibers at once:
8573
86- Available commands:
87- rb-fiber-bt 5 - Show backtrace
88- rb-fiber-vm-stack 5 - Show VM stack
89- rb-fiber-c-stack 5 - Show C/machine stack info
9074~~~
75+ (gdb) rb-fiber-scan-stack-trace-all
76+ Found 12 fiber(s)
9177
92- This shows at a glance whether the fiber has an exception and what its state is.
93-
94- ### Fiber Backtraces
78+ Fiber #0: <VALUE:0x7f8a1c800000>
79+ Status: RESUMED
80+ [No backtrace - fiber is running]
9581
96- See the Ruby-level call stack:
82+ Fiber #1: <VALUE:0x7f8a1c800100>
83+ Status: SUSPENDED
84+ /app/lib/connection.rb:123:in `read'
85+ /app/lib/connection.rb:89:in `receive'
86+ /app/lib/server.rb:56:in `handle_client'
87+ ...
9788
98- ~~~
99- (gdb) rb-fiber-bt 5
100- Backtrace for fiber 0x7f8a1c800500:
101- 45: /app/lib/connection.rb:123:in `read'
102- 44: /app/lib/connection.rb:89:in `receive'
103- 43: /app/lib/server.rb:56:in `handle_client'
104- 42: /app/lib/server.rb:34:in `block in run'
105- 41: /gems/async-2.0/lib/async/task.rb:45:in `run'
89+ Fiber #5: <VALUE:0x7f8a1c800500>
90+ Status: SUSPENDED
91+ Exception: IOError: Connection reset
92+ /app/lib/connection.rb:45:in `write'
10693 ...
10794~~~
10895
109- Show backtraces for all non-terminated fibers:
110-
111- ~~~
112- (gdb) rb-all-fiber-bt
113- ~~~
96+ This gives you a complete overview of what every fiber is doing.
11497
11598## Switching Fiber Context
11699
@@ -119,27 +102,21 @@ The most powerful feature: switch GDB's view to a fiber's stack (even in core du
119102### Basic Usage
120103
121104~~~
122- (gdb) rb-scan-fibers
123- (gdb) rb-fiber-switch 5
124- Switched to Fiber #5: 0x7f8a1c800500
105+ (gdb) rb-fiber- scan-heap
106+ (gdb) rb-fiber-scan- switch 5
107+ Switched to Fiber #5
125108 Status: SUSPENDED
126- Exception: IOError: Connection reset
127-
128- Convenience variables set:
129- $fiber = Current fiber (struct rb_fiber_struct *)
130- $ec = Execution context (rb_execution_context_t *)
131- $errinfo = Exception being handled (VALUE)
132-
133- Now try:
134- bt # Show C backtrace of fiber
135- frame <n> # Switch to frame N
136- info locals # Show local variables
137- rp $errinfo # Pretty print exception
109+
110+ Now you can use standard GDB commands with this fiber's context:
111+ rb-stack-trace # Show combined backtrace
112+ bt # Show C backtrace
113+ info locals # Show C local variables
138114~~~
139115
140116After switching, all standard GDB commands work with the fiber's context:
141117
142118~~~
119+ (gdb) rb-stack-trace # Combined Ruby/C backtrace
143120(gdb) bt # C backtrace of fiber
144121#0 0x00007f8a1c567890 in fiber_setcontext
145122#1 0x00007f8a1c567900 in rb_fiber_yield
@@ -148,16 +125,22 @@ After switching, all standard GDB commands work with the fiber's context:
148125
149126(gdb) frame 2
150127(gdb) info locals # Local C variables in that frame
151- (gdb) rb-object-print $ec->cfp->sp[-1] # Ruby values on VM stack
128+ ~~~
129+
130+ ### Switching by VALUE
131+
132+ You can also switch to a specific fiber by its VALUE or address:
133+
134+ ~~~
135+ (gdb) rb-fiber-switch 0x7f8a1c800500
152136~~~
153137
154138### Switching Back
155139
156140Return to normal stack view:
157141
158142~~~
159- (gdb) rb-fiber-switch off
160- Fiber unwinder deactivated. Switched back to normal stack view.
143+ (gdb) rb-fiber-scan-switch off
161144~~~
162145
163146## Analyzing Fiber State
@@ -311,27 +294,26 @@ Validation:
311294After scanning fibers, use indices for all operations:
312295
313296~~~
314- (gdb) rb-scan-fibers # Scan once
315- (gdb) rb-fiber 5 # Use index thereafter
316- (gdb) rb-fiber-bt 5
317- (gdb) rb-fiber-switch 5
297+ (gdb) rb-fiber-scan-heap # Scan once
298+ (gdb) rb-fiber-scan-switch 5 # Switch to fiber #5
299+ (gdb) rb-stack-trace # View backtrace
318300~~~
319301
320302The cache persists throughout your GDB session.
321303
322- ### Check Fiber Status First
304+ ### Check Fiber Status
323305
324- Before inspecting, check the fiber's status:
306+ CREATED and TERMINATED fibers may not have valid saved contexts. The scan output shows status:
325307
326308~~~
327- (gdb) rb-fiber 5
309+ Fiber #5: <VALUE:0x7f8a1c800500>
328310 Status: TERMINATED # Won't have useful context
329311
330- (gdb) rb-fiber 3
312+ Fiber #3: <VALUE:0x7f8a1c800300>
331313 Status: SUSPENDED # Good candidate for inspection
332314~~~
333315
334- CREATED and TERMINATED fibers may not have valid saved contexts .
316+ Focus on SUSPENDED and RESUMED fibers for debugging .
335317
336318### Use Convenience Variables
337319
0 commit comments