From 906f16832f84de8edfbb13d31a4db8e6172c6e77 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Sat, 26 May 2018 17:48:52 -0700 Subject: [PATCH] program: make ProgramObject() address optional This way, rvalues can be more conveniently created with prog.object(type, value=x). --- drgn/__init__.py | 1 - drgn/program.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drgn/__init__.py b/drgn/__init__.py index f897aa4e..fcbbb8bb 100644 --- a/drgn/__init__.py +++ b/drgn/__init__.py @@ -27,7 +27,6 @@ Variables are represented by drgn.program.ProgramObject objects. Try >>> import drgn.program >>> help(drgn.program.ProgramObject) - Types are represented by drgn.type.Type objects. Try >>> import drgn.type diff --git a/drgn/program.py b/drgn/program.py index 8ca4fff4..091dddff 100644 --- a/drgn/program.py +++ b/drgn/program.py @@ -82,7 +82,8 @@ class ProgramObject: conflict. """ - def __init__(self, program: 'Program', type: Type, address: Optional[int], + def __init__(self, program: 'Program', type: Type, + address: Optional[int] = None, value: Any = None) -> None: if address is not None and value is not None: raise ValueError('object cannot have address and value') @@ -155,9 +156,11 @@ class ProgramObject: def __repr__(self) -> str: parts = [ - 'ProgramObject(type=<', str(self.type_.type_name()), '>, address=', - 'None' if self.address_ is None else hex(self.address_), + 'ProgramObject(type=<', str(self.type_.type_name()), '>' ] + if self.address_ is not None: + parts.append(', address=') + parts.append(hex(self.address_)) if self._value is not None: parts.append(', value=') if isinstance(self._real_type, PointerType): @@ -598,7 +601,8 @@ class Program: """ return self.variable(name) - def object(self, type: Union[str, Type, TypeName], address: Optional[int], + def object(self, type: Union[str, Type, TypeName], + address: Optional[int] = None, value: Any = None) -> ProgramObject: """ Return a ProgramObject with the given address of the given type. The