Skip to content

Commit be25c8a

Browse files
samuel-williams-shopifyioquatix
authored andcommitted
Consistency.
1 parent d3e2b06 commit be25c8a

File tree

9 files changed

+81
-54
lines changed

9 files changed

+81
-54
lines changed

context/index.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ files:
1212
programs and core dumps with GDB or LLDB.
1313
- path: object-inspection.md
1414
title: Object Inspection
15-
description: This guide explains how to use `rb-object-print` to inspect Ruby objects,
15+
description: This guide explains how to use `rb-print` to inspect Ruby objects,
1616
hashes, arrays, and structs in GDB.
1717
- path: stack-inspection.md
1818
title: Stack Inspection

data/toolbox/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def invoke(self, arguments, terminal):
284284

285285
print()
286286
print("Now you can use:")
287-
print(" rb-object-print $errinfo")
288-
print(" rb-object-print $ec->cfp->sp[-1]")
287+
print(" rb-print $errinfo")
288+
print(" rb-print $ec->cfp->sp[-1]")
289289
print(" rb-stack-trace")
290290

291291
except Exception as e:

data/toolbox/debugger/gdb_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def __init__(self, name, category=COMMAND_DATA):
312312
"""Initialize and register a command.
313313
314314
Args:
315-
name: Command name (e.g., "rb-object-print")
315+
name: Command name (e.g., "rb-print")
316316
category: Command category (COMMAND_DATA or COMMAND_USER)
317317
"""
318318
self.name = name
@@ -597,7 +597,7 @@ def register(name, handler_class, usage=None, category=COMMAND_USER):
597597
and delegates to the handler class for actual command logic.
598598
599599
Args:
600-
name: Command name (e.g., "rb-object-print")
600+
name: Command name (e.g., "rb-print")
601601
handler_class: Class to instantiate for handling the command
602602
usage: Optional command.Usage specification for validation/help
603603
category: Command category (COMMAND_USER, etc.)

data/toolbox/debugger/lldb_backend.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def __init__(self, name, category=COMMAND_DATA):
428428
"""Initialize and register a command.
429429
430430
Args:
431-
name: Command name (e.g., "rb-object-print")
431+
name: Command name (e.g., "rb-print")
432432
category: Command category (not used in LLDB)
433433
"""
434434
self.name = name
@@ -538,8 +538,8 @@ def set_convenience_variable(name, value):
538538
name: Variable name (without $ prefix)
539539
value: Value to set (can be Value wrapper or native value)
540540
541-
Note: LLDB doesn't have direct convenience variables like GDB.
542-
This implementation uses expression evaluation to set variables.
541+
Note: LLDB convenience variables are created using expression evaluation.
542+
The variable name will be prefixed with $ automatically.
543543
"""
544544
if isinstance(value, Value):
545545
native_value = value._value
@@ -549,16 +549,45 @@ def set_convenience_variable(name, value):
549549
# LLDB approach: use expression to create a persistent variable
550550
# Variables in LLDB are prefixed with $
551551
target = lldb.debugger.GetSelectedTarget()
552-
frame = target.GetProcess().GetSelectedThread().GetSelectedFrame()
552+
if not target:
553+
return
553554

554-
# Create a persistent variable by evaluating an expression
555+
process = target.GetProcess()
556+
if not process:
557+
return
558+
559+
thread = process.GetSelectedThread()
560+
if not thread:
561+
return
562+
563+
frame = thread.GetSelectedFrame()
564+
if not frame:
565+
return
566+
567+
# Create a persistent variable by evaluating an assignment expression
555568
if hasattr(native_value, 'GetValue'):
556569
# It's an SBValue
557570
addr = native_value.GetValueAsUnsigned()
558571
type_name = native_value.GetType().GetName()
559-
frame.EvaluateExpression(f"({type_name})0x{addr:x}", lldb.SBExpressionOptions())
560-
# For now, simplified implementation
561-
# Full implementation would require more complex value handling
572+
573+
# Use expr command to create persistent variable
574+
# Format: expr <type> $varname = (<type>)address
575+
expr = f"{type_name} ${name} = ({type_name})0x{addr:x}"
576+
577+
options = lldb.SBExpressionOptions()
578+
options.SetIgnoreBreakpoints(True)
579+
options.SetFetchDynamicValue(lldb.eNoDynamicValues)
580+
options.SetTimeoutInMicroSeconds(100000) # 0.1 second timeout
581+
options.SetTryAllThreads(False)
582+
583+
# Evaluate the expression to create the persistent variable
584+
result = frame.EvaluateExpression(expr, options)
585+
586+
# Check for errors
587+
if result.GetError().Fail():
588+
error_msg = result.GetError().GetCString()
589+
# Silently ignore errors for now - convenience variables are optional
590+
pass
562591

563592

564593
def execute(command, from_tty=False, to_string=False):
@@ -894,7 +923,7 @@ def register(name, handler_class, usage=None, category=COMMAND_USER):
894923
and delegates to the handler class for actual command logic.
895924
896925
Args:
897-
name: Command name (e.g., "rb-object-print")
926+
name: Command name (e.g., "rb-print")
898927
handler_class: Class to instantiate for handling the command
899928
usage: Optional command.Usage specification for validation/help
900929
category: Command category (COMMAND_USER, etc.)

data/toolbox/rbasic.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,39 @@ def is_type(value, ruby_type_constant):
2929

3030
# Map of type constants to their names for display
3131
TYPE_NAMES = {
32-
'RUBY_T_NONE': 'None',
33-
'RUBY_T_OBJECT': 'Object',
34-
'RUBY_T_CLASS': 'Class',
35-
'RUBY_T_MODULE': 'Module',
36-
'RUBY_T_FLOAT': 'Float',
37-
'RUBY_T_STRING': 'String',
38-
'RUBY_T_REGEXP': 'Regexp',
39-
'RUBY_T_ARRAY': 'Array',
40-
'RUBY_T_HASH': 'Hash',
41-
'RUBY_T_STRUCT': 'Struct',
42-
'RUBY_T_BIGNUM': 'Bignum',
43-
'RUBY_T_FILE': 'File',
44-
'RUBY_T_DATA': 'Data',
45-
'RUBY_T_MATCH': 'Match',
46-
'RUBY_T_COMPLEX': 'Complex',
47-
'RUBY_T_RATIONAL': 'Rational',
48-
'RUBY_T_NIL': 'Nil',
49-
'RUBY_T_TRUE': 'True',
50-
'RUBY_T_FALSE': 'False',
51-
'RUBY_T_SYMBOL': 'Symbol',
52-
'RUBY_T_FIXNUM': 'Fixnum',
53-
'RUBY_T_UNDEF': 'Undef',
54-
'RUBY_T_IMEMO': 'IMemo',
55-
'RUBY_T_NODE': 'Node',
56-
'RUBY_T_ICLASS': 'IClass',
57-
'RUBY_T_ZOMBIE': 'Zombie',
32+
'RUBY_T_NONE': 'T_NONE',
33+
'RUBY_T_OBJECT': 'T_OBJECT',
34+
'RUBY_T_CLASS': 'T_CLASS',
35+
'RUBY_T_MODULE': 'T_MODULE',
36+
'RUBY_T_FLOAT': 'T_FLOAT',
37+
'RUBY_T_STRING': 'T_STRING',
38+
'RUBY_T_REGEXP': 'T_REGEXP',
39+
'RUBY_T_ARRAY': 'T_ARRAY',
40+
'RUBY_T_HASH': 'T_HASH',
41+
'RUBY_T_STRUCT': 'T_STRUCT',
42+
'RUBY_T_BIGNUM': 'T_BIGNUM',
43+
'RUBY_T_FILE': 'T_FILE',
44+
'RUBY_T_DATA': 'T_DATA',
45+
'RUBY_T_MATCH': 'T_MATCH',
46+
'RUBY_T_COMPLEX': 'T_COMPLEX',
47+
'RUBY_T_RATIONAL': 'T_RATIONAL',
48+
'RUBY_T_NIL': 'T_NIL',
49+
'RUBY_T_TRUE': 'T_TRUE',
50+
'RUBY_T_FALSE': 'T_FALSE',
51+
'RUBY_T_SYMBOL': 'T_SYMBOL',
52+
'RUBY_T_FIXNUM': 'T_FIXNUM',
53+
'RUBY_T_UNDEF': 'T_UNDEF',
54+
'RUBY_T_IMEMO': 'T_IMEMO',
55+
'RUBY_T_NODE': 'T_NODE',
56+
'RUBY_T_ICLASS': 'T_ICLASS',
57+
'RUBY_T_ZOMBIE': 'T_ZOMBIE',
5858
}
5959

6060
def type_name(value):
6161
"""Get the human-readable type name for a VALUE.
6262
6363
Returns:
64-
String like 'String', 'Array', 'Hash', etc., or 'Unknown'
64+
String like 'T_STRING', 'T_ARRAY', 'T_HASH', etc., or 'Unknown(0x...)'
6565
"""
6666
type_flag = type_of(value)
6767

@@ -85,16 +85,14 @@ def __init__(self, value):
8585

8686
def __str__(self):
8787
type_str = type_name(self.value)
88-
return f"<{type_str}:0x{int(self.value):x}>"
88+
return f"<{type_str}@0x{int(self.value):x}>"
8989

9090
def print_to(self, terminal):
9191
"""Print formatted basic object representation."""
9292
type_str = type_name(self.value)
9393
addr = int(self.value)
94-
# Note: Using : instead of @ for basic objects
95-
import format as fmt
96-
terminal.print(fmt.metadata, '<', fmt.reset, fmt.type, type_str, fmt.reset, end='')
97-
terminal.print(fmt.metadata, f':0x{addr:x}>', fmt.reset, end='')
94+
# Use print_type_tag for consistency with other types
95+
terminal.print_type_tag(type_str, addr)
9896

9997
def print_recursive(self, printer, depth):
10098
"""Print this basic object (no recursion)."""

data/toolbox/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ command script import /path/to/gem/data/toolbox/init.py
125125
- `rb-heap-scan [--type TYPE] [--limit N]` - Scan Ruby heap for objects
126126

127127
### Stack Inspection
128-
- `rb-stack-print` - Print Ruby stack (coming soon)
128+
- `rb-stack-trace` - Print combined Ruby/C stack trace
129129

130130
## Migration Status
131131

fixtures/toolbox/gdb/context/can_get_context.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Convenience variables set:
1111
$cfp - Control frame pointer
1212

1313
Now you can use:
14-
rb-object-print $errinfo
15-
rb-object-print $ec->cfp->sp[-1]
14+
rb-print $errinfo
15+
rb-print $ec->cfp->sp[-1]
1616
rb-stack-trace

fixtures/toolbox/gdb/heap/can_find_with_numeric_type.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Scanning heap for type 0x..., limit=3...
22

33
Found 3 object(s):
44

5-
[0] $heap0 = <File:0x...>
6-
[1] $heap1 = <File:0x...>
7-
[2] $heap2 = <File:0x...>
5+
[0] $heap0 = <T_FILE@...>
6+
[1] $heap1 = <T_FILE@...>
7+
[2] $heap2 = <T_FILE@...>
88

99
Objects saved in $heap0 through $heap2
1010
Reached end of heap (no more objects to scan)

fixtures/toolbox/lldb/context/can_get_context.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Convenience variables set:
1111
$cfp - Control frame pointer
1212

1313
Now you can use:
14-
rb-object-print $errinfo
15-
rb-object-print $ec->cfp->sp[-1]
14+
rb-print $errinfo
15+
rb-print $ec->cfp->sp[-1]
1616
rb-stack-trace

0 commit comments

Comments
 (0)