Skip to content

Commit

Permalink
update drgn type instantiation routines
Browse files Browse the repository at this point in the history
drgn changed the way what you instantiate a type object, so we need to
update type_canonicalize().
  • Loading branch information
ahrens authored and sdimitro committed Sep 2, 2020
1 parent 31c4375 commit fb7d435
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sdb/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ def type_canonicalize(t: drgn.Type) -> drgn.Type:
Note: function type's arguments and return types are not canonicalized.
"""
global prog
if t.kind == drgn.TypeKind.TYPEDEF:
return type_canonicalize(t.type)
if t.kind == drgn.TypeKind.POINTER:
return drgn.pointer_type(t.size, type_canonicalize(t.type))
return prog.pointer_type(type_canonicalize(t.type), t.size)
if t.kind == drgn.TypeKind.ARRAY:
return drgn.array_type(t.length, type_canonicalize(t.type))
return prog.array_type(type_canonicalize(t.type), t.length)
return t.unqualified()


Expand Down
10 changes: 5 additions & 5 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import sdb


def create_struct_type(name: str, member_names: List[str],
def create_struct_type(prog: drgn.Program, name: str, member_names: List[str],
member_types: List[drgn.Type]) -> drgn.Type:
"""
Creates a structure type given a list of member names and
a list of types like this:
```
create_struct_type(<name>, [<name_a>, <name_b> ...],
create_struct_type(<prog>, <name>, [<name_a>, <name_b> ...],
[<type_a>, <type_b>, ...])
```
returns a C structure:
Expand All @@ -52,7 +52,7 @@ def create_struct_type(name: str, member_names: List[str],
else:
bit_offset += 8 * type_.size
struct_size += type_.size
return drgn.struct_type(name, struct_size, member_list)
return prog.struct_type(name, struct_size, member_list)


def setup_basic_mock_program() -> drgn.Program:
Expand Down Expand Up @@ -97,13 +97,13 @@ def mock_type_find(kind: drgn.TypeKind, name: str,
# More complex types are added to the mocked_types table in
# an ad-hoc way here.
#
struct_type = create_struct_type('test_struct',
struct_type = create_struct_type(prog, 'test_struct',
['ts_int', 'ts_voidp', 'ts_array'],
[int_type, voidp_type, int_array_type])
mocked_types['test_struct'] = struct_type
structp_type = prog.type('struct test_struct *')
complex_struct_type = create_struct_type(
'complex_struct', ['cs_structp', 'cs_struct', 'cs_structp_null'],
prog, 'complex_struct', ['cs_structp', 'cs_struct', 'cs_structp_null'],
[structp_type, struct_type, structp_type])
mocked_types['complex_struct'] = complex_struct_type

Expand Down

0 comments on commit fb7d435

Please sign in to comment.