Skip to content

Commit

Permalink
DLPX-84435 Support printing local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybee committed Feb 27, 2025
1 parent ce88ecd commit e442812
Show file tree
Hide file tree
Showing 9 changed files with 707 additions and 212 deletions.
147 changes: 93 additions & 54 deletions sdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,102 @@
# the modules are imported and attempt to have a cleaner
# separation of concerns between modules.
#
from sdb.error import (Error, CommandNotFoundError, CommandError,
CommandInvalidInputError, SymbolNotFoundError,
CommandArgumentsError, CommandEvalSyntaxError,
ParserError)
from sdb.target import (create_object, get_object, get_prog, get_type,
get_pointer_type, get_target_flags, get_symbol, is_null,
type_canonical_name, type_canonicalize,
type_canonicalize_name, type_canonicalize_size,
type_equals, Runtime, All, Kernel, Userland, Module,
Library)
from sdb.command import (Address, Cast, Command, InputHandler, Locator,
PrettyPrinter, Walk, Walker, SingleInputCommand,
get_registered_commands, register_commands)
from sdb.error import (
Error,
CommandNotFoundError,
CommandError,
CommandInvalidInputError,
SymbolNotFoundError,
CommandArgumentsError,
CommandEvalSyntaxError,
ParserError,
)
from sdb.target import (
create_object,
get_object,
get_prog,
get_type,
set_thread,
get_thread,
set_frame,
get_frame,
get_pointer_type,
get_target_flags,
get_symbol,
is_null,
type_canonical_name,
type_canonicalize,
type_canonicalize_name,
type_canonicalize_size,
type_equals,
Runtime,
All,
Kernel,
Userland,
Module,
Library,
)
from sdb.command import (
Address,
Cast,
Command,
InputHandler,
Locator,
PrettyPrinter,
Walk,
Walker,
SingleInputCommand,
get_registered_commands,
register_commands,
)
from sdb.pipeline import execute_pipeline, get_first_type, invoke

__all__ = [
'Address',
'All',
'Cast',
'Command',
'CommandArgumentsError',
'CommandError',
'CommandEvalSyntaxError',
'CommandInvalidInputError',
'CommandNotFoundError',
'Error',
'InputHandler',
'Kernel',
'Library',
'Locator',
'Module',
'ParserError',
'PrettyPrinter',
'Runtime',
'SingleInputCommand',
'SymbolNotFoundError',
'Userland',
'Walk',
'Walker',
'create_object',
'execute_pipeline',
'invoke',
'is_null',
'get_first_type',
'get_object',
'get_pointer_type',
'get_prog',
'get_registered_commands',
'get_symbol',
'get_target_flags',
'get_type',
'register_commands',
'type_canonical_name',
'type_canonicalize',
'type_canonicalize_name',
'type_canonicalize_size',
'type_equals',
"Address",
"All",
"Cast",
"Command",
"CommandArgumentsError",
"CommandError",
"CommandEvalSyntaxError",
"CommandInvalidInputError",
"CommandNotFoundError",
"Error",
"InputHandler",
"Kernel",
"Library",
"Locator",
"Module",
"ParserError",
"PrettyPrinter",
"Runtime",
"SingleInputCommand",
"SymbolNotFoundError",
"Userland",
"Walk",
"Walker",
"create_object",
"execute_pipeline",
"invoke",
"is_null",
"get_first_type",
"get_frame",
"get_object",
"get_pointer_type",
"get_prog",
"get_registered_commands",
"get_thread",
"get_symbol",
"get_target_flags",
"get_type",
"register_commands",
"set_frame",
"set_thread",
"type_canonical_name",
"type_canonicalize",
"type_canonicalize_name",
"type_canonicalize_size",
"type_equals",
]

#
Expand Down
19 changes: 18 additions & 1 deletion sdb/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ def __invalid_memory_objects_check(self, objs: Iterable[drgn.Object],
for obj in objs:
try:
obj.read_()
except AttributeError:
#
# This object does not support the read_() method.
#
yield obj
continue
except TypeError as err:
obj_type = type_canonicalize(obj.type_)
if obj_type.kind == drgn.TypeKind.ARRAY and not obj_type.is_complete(
Expand Down Expand Up @@ -389,6 +395,12 @@ def __invalid_memory_objects_check(self, objs: Iterable[drgn.Object],
raise err
print(err.text)
continue
except drgn.ObjectAbsentError as err:
# XXX - maybe just go ahead and yield the object?
if fatal:
raise CommandError(self.name, str(err)) from err
print(str(err))
continue
yield obj

def call(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
Expand Down Expand Up @@ -587,7 +599,12 @@ def caller(self, objs: Iterable[drgn.Object]) -> Iterable[drgn.Object]:
return

for i in objs:
obj_type_name = type_canonical_name(i.type_)
try:
obj_type_name = type_canonical_name(i.type_)
except AttributeError:
# This input is not a drgn.Object, so we can't check its type.
yield i
continue

# try subclass-specified input types first, so that they can
# override any other behavior
Expand Down
Loading

0 comments on commit e442812

Please sign in to comment.