diff --git a/sdb/target.py b/sdb/target.py index 162f6738..b20cc13e 100644 --- a/sdb/target.py +++ b/sdb/target.py @@ -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() diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 6050de16..e0a7d153 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -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(, [, ...], + create_struct_type(, , [, ...], [, , ...]) ``` returns a C structure: @@ -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: @@ -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