Skip to content

Commit 9932589

Browse files
Migrate all commands.
1 parent 53799b6 commit 9932589

File tree

4 files changed

+68
-96
lines changed

4 files changed

+68
-96
lines changed

data/toolbox/context.py

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -230,47 +230,23 @@ def print_info(self, terminal):
230230
pass
231231

232232

233-
class RubyContextCommand(debugger.Command):
234-
"""Show current execution context and set convenience variables.
233+
class RubyContextHandler:
234+
"""Show current execution context and set convenience variables."""
235235

236-
This command automatically discovers the current thread's execution context
237-
and displays detailed information about it, while also setting up convenience
238-
variables for easy inspection.
236+
USAGE = command.Usage(
237+
summary="Show current execution context and set convenience variables",
238+
parameters=[],
239+
options={},
240+
flags=[],
241+
examples=[
242+
("rb-context", "Display execution context info"),
243+
("rb-context; rb-print $errinfo", "Show context then print exception")
244+
]
245+
)
239246

240-
Usage:
241-
rb-context
242-
243-
Displays:
244-
- Execution context pointer and details
245-
- VM stack information
246-
- Control frame pointer
247-
- Exception information (if any)
248-
249-
Sets these convenience variables:
250-
$ec - Current execution context (rb_execution_context_t *)
251-
$cfp - Current control frame pointer
252-
$errinfo - Current exception (if any)
253-
254-
Example:
255-
(gdb) rb-context
256-
Execution Context:
257-
$ec = <rb_execution_context_t *@0x...>
258-
VM Stack: <VALUE *@0x...> size=1024
259-
$cfp = <rb_control_frame_t *@0x...>
260-
Exception: None
261-
262-
(gdb) rb-object-print $errinfo
263-
(gdb) rb-object-print $ec->cfp->sp[-1]
264-
"""
265-
266-
def __init__(self):
267-
super(RubyContextCommand, self).__init__("rb-context", debugger.COMMAND_USER)
268-
269-
def invoke(self, arg, from_tty):
247+
def invoke(self, arguments, terminal):
270248
"""Execute the rb-context command."""
271249
try:
272-
terminal = format.create_terminal(from_tty)
273-
274250
# Get current execution context
275251
ctx = RubyContext.current()
276252

@@ -314,30 +290,21 @@ def invoke(self, arg, from_tty):
314290
traceback.print_exc()
315291

316292

317-
class RubyContextStorageCommand(debugger.Command):
318-
"""Print the fiber storage from the current execution context.
319-
320-
This command is a convenience wrapper around rb-object-print that
321-
specifically prints $ec->storage (the inheritable fiber storage).
322-
323-
Usage:
324-
rb-context-storage [--depth N] [--debug]
325-
326-
All flags are passed through to rb-object-print.
327-
328-
Example:
329-
(gdb) rb-context
330-
(gdb) rb-context-storage --depth 3
331-
332-
This is equivalent to:
333-
(gdb) rb-context
334-
(gdb) rb-object-print $ec->storage --depth 3
335-
"""
293+
class RubyContextStorageHandler:
294+
"""Print the fiber storage from the current execution context."""
336295

337-
def __init__(self):
338-
super(RubyContextStorageCommand, self).__init__("rb-context-storage", debugger.COMMAND_USER)
296+
USAGE = command.Usage(
297+
summary="Print fiber storage from current execution context",
298+
parameters=[],
299+
options={'depth': (int, 1, 'Recursion depth for nested objects')},
300+
flags=[('debug', 'Show debug information')],
301+
examples=[
302+
("rb-context-storage", "Print storage with default depth"),
303+
("rb-context-storage --depth 3", "Print storage with depth 3")
304+
]
305+
)
339306

340-
def invoke(self, arg, from_tty):
307+
def invoke(self, arguments, terminal):
341308
"""Execute the rb-context-storage command."""
342309
try:
343310
# Get current execution context
@@ -396,6 +363,6 @@ def invoke(self, arg, from_tty):
396363

397364

398365
# Register commands
399-
RubyContextCommand()
400-
RubyContextStorageCommand()
366+
debugger.register("rb-context", RubyContextHandler, usage=RubyContextHandler.USAGE)
367+
debugger.register("rb-context-storage", RubyContextStorageHandler, usage=RubyContextStorageHandler.USAGE)
401368

data/toolbox/fiber.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,29 @@ def print_info(self, terminal):
220220
print(terminal.print_type_tag('rb_control_frame_t', int(self.cfp), None))
221221

222222

223-
class RubyFiberScanHeapCommand(debugger.Command):
223+
class RubyFiberScanHeapHandler:
224224
"""Scan heap and list all Ruby fibers."""
225225

226+
USAGE = command.Usage(
227+
summary="Scan heap and list all Ruby fibers",
228+
parameters=[],
229+
options={
230+
'limit': (int, None, 'Maximum fibers to find'),
231+
'cache': (str, None, 'Cache file to use (default: fibers.json)')
232+
},
233+
flags=[
234+
('terminated', 'Include terminated fibers in results')
235+
],
236+
examples=[
237+
("rb-fiber-scan-heap", "Find all non-terminated fibers"),
238+
("rb-fiber-scan-heap --limit 10", "Find first 10 fibers"),
239+
("rb-fiber-scan-heap --terminated", "Include terminated fibers"),
240+
("rb-fiber-scan-heap --cache my.json", "Use custom cache file")
241+
]
242+
)
243+
226244
def __init__(self):
227-
super(RubyFiberScanHeapCommand, self).__init__("rb-fiber-scan-heap", debugger.COMMAND_USER)
228245
self.heap = heap.RubyHeap()
229-
230-
def usage(self):
231-
"""Print usage information."""
232-
print("Usage: rb-fiber-scan-heap [--limit N] [--cache [filename]] [--terminated]")
233-
print("Examples:")
234-
print(" rb-fiber-scan-heap # Find all non-terminated fibers")
235-
print(" rb-fiber-scan-heap --limit 10 # Find first 10 non-terminated fibers")
236-
print(" rb-fiber-scan-heap --terminated # Include terminated fibers")
237-
print(" rb-fiber-scan-heap --cache # Use fibers.json cache")
238-
print(" rb-fiber-scan-heap --cache my.json # Use custom cache file")
239246

240247
def save_cache(self, fiber_values, filename):
241248
"""Save fiber VALUE addresses to cache file.
@@ -895,7 +902,7 @@ def invoke(self, arg, from_tty):
895902

896903

897904
# Register commands
898-
RubyFiberScanHeapCommand()
899-
RubyFiberScanSwitchCommand()
900-
RubyFiberSwitchCommand()
901-
RubyFiberScanStackTraceAllCommand()
905+
debugger.register("rb-fiber-scan-heap", RubyFiberScanHeapHandler, usage=RubyFiberScanHeapHandler.USAGE)
906+
debugger.register("rb-fiber-scan-switch", RubyFiberScanSwitchHandler, usage=RubyFiberScanSwitchHandler.USAGE)
907+
debugger.register("rb-fiber-switch", RubyFiberSwitchHandler, usage=RubyFiberSwitchHandler.USAGE)
908+
debugger.register("rb-fiber-scan-stack-trace-all", RubyFiberScanStackTraceAllHandler, usage=RubyFiberScanStackTraceAllHandler.USAGE)

data/toolbox/heap.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def find_typed_data(self, data_type, limit=None, progress=False):
471471
return objects
472472

473473

474-
class RubyHeapScanCommand(debugger.Command):
474+
class RubyHeapScanHandler:
475475
"""Scan the Ruby heap for objects, optionally filtered by type.
476476
477477
Usage: rb-heap-scan [--type TYPE] [--limit N] [--from $heap]
@@ -501,23 +501,21 @@ class RubyHeapScanCommand(debugger.Command):
501501
rb-heap-scan --from $heap # Continue from last scan
502502
"""
503503

504-
def __init__(self):
505-
super(RubyHeapScanCommand, self).__init__("rb-heap-scan", debugger.COMMAND_USER)
506-
507-
def usage(self):
508-
"""Print usage information."""
509-
print("Usage: rb-heap-scan [--type TYPE] [--limit N] [--from $heap]")
510-
print("Examples:")
511-
print(" rb-heap-scan --type RUBY_T_STRING # Find up to 10 strings")
512-
print(" rb-heap-scan --type RUBY_T_ARRAY --limit 5 # Find up to 5 arrays")
513-
print(" rb-heap-scan --type 0x05 --limit 100 # Find up to 100 T_STRING objects")
514-
print(" rb-heap-scan --limit 20 # Scan 20 objects (any type)")
515-
print(" rb-heap-scan --type RUBY_T_STRING --from $heap # Continue from last scan")
516-
print()
517-
print("Pagination:")
518-
print(" The address of the last object is saved to $heap for pagination:")
519-
print(" rb-heap-scan --type RUBY_T_STRING --limit 10 # First page")
520-
print(" rb-heap-scan --type RUBY_T_STRING --from $heap # Next page")
504+
USAGE = command.Usage(
505+
summary="Scan the Ruby heap for objects, optionally filtered by type",
506+
parameters=[],
507+
options={
508+
'type': (str, None, 'Filter by Ruby type (e.g., RUBY_T_STRING, RUBY_T_ARRAY, or 0x05)'),
509+
'limit': (int, 10, 'Maximum objects to find'),
510+
'from': (str, None, 'Start address for pagination (use $heap)')
511+
},
512+
flags=[],
513+
examples=[
514+
("rb-heap-scan --type RUBY_T_STRING", "Find up to 10 strings"),
515+
("rb-heap-scan --type RUBY_T_ARRAY --limit 20", "Find first 20 arrays"),
516+
("rb-heap-scan --from $heap", "Continue from last scan (pagination)")
517+
]
518+
)
521519

522520
def _parse_type(self, type_arg):
523521
"""Parse a type argument and return the type value.

data/toolbox/stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,4 @@ def invoke(self, arg, from_tty):
628628

629629

630630
# Register commands
631-
RubyStackTraceCommand()
631+
debugger.register("rb-stack-trace", RubyStackTraceHandler, usage=RubyStackTraceHandler.USAGE)

0 commit comments

Comments
 (0)