Skip to content

Commit 6163c8a

Browse files
committed
Fix: type_canonicalize_name() returns whole structure
Introduce type_canonicalize_size() to target API
1 parent 9e55751 commit 6163c8a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

sdb/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from sdb.target import (create_object, get_object, get_prog, get_typed_null,
3535
get_type, get_pointer_type, get_target_flags,
3636
get_symbol, type_canonical_name, type_canonicalize,
37-
type_canonicalize_name, type_equals)
37+
type_canonicalize_name, type_canonicalize_size,
38+
type_equals)
3839
from sdb.command import (Address, Cast, Command, InputHandler, Locator,
3940
PrettyPrinter, Walk, Walker, SingleInputCommand,
4041
get_registered_commands)

sdb/target.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def type_canonical_name(t: drgn.Type) -> str:
117117
"""
118118
Return the "canonical name" of this type. See type_canonicalize().
119119
"""
120-
return str(type_canonicalize(t))
120+
return type_canonicalize(t).type_name()
121121

122122

123123
def type_canonicalize_name(type_name: str) -> str:
@@ -128,6 +128,18 @@ def type_canonicalize_name(type_name: str) -> str:
128128
return type_canonical_name(prog.type(type_name))
129129

130130

131+
def type_canonicalize_size(t: Union[drgn.Type, str]) -> int:
132+
"""
133+
Return the "canonical size" of this type. See type_canonicalize().
134+
"""
135+
if isinstance(t, str):
136+
type_ = get_type(t)
137+
else:
138+
assert isinstance(t, drgn.Type)
139+
type_ = t
140+
return type_canonicalize(type_).size
141+
142+
131143
def type_equals(a: drgn.Type, b: drgn.Type) -> bool:
132144
"""
133145
This function determines if two types have the same canonical name. See

0 commit comments

Comments
 (0)