Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.11.0
rev: 25.12.0
hooks:
- id: black
language_version: python3.13

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.7
rev: v0.14.8
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
Expand Down
1 change: 0 additions & 1 deletion objutils/dwarf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,4 +1004,3 @@ class Languages(EnumBase):
Mips_Assembler = 0x8001
GOOGLE_RenderScript = 0x8E57
BORLAND_Delphi = 0xB000

66 changes: 30 additions & 36 deletions objutils/dwarf/traverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
AttributeForm,
BaseTypeEncoding,
CallingConvention,
Defaulted,
DecimalSign,
Defaulted,
DiscriminantDescriptor,
Endianity,
IdentifierCase,
Expand All @@ -27,6 +27,7 @@
from objutils.elf import defs, model
from objutils.elf.model import DIEAttribute


DWARF_TYPE_ENCODINGS = frozenset(
{
Tag.base_type,
Expand Down Expand Up @@ -85,7 +86,6 @@ class DIE:
"ordering": Ordering,
"discr_list": DiscriminantDescriptor,
"defaulted": Defaulted,

}


Expand All @@ -100,8 +100,7 @@ def get_attribute(attrs: dict[str, DIEAttribute], key: str, default: Union[int,
class CompiledUnitsSummary:

def __init__(self, session) -> None:
cus = session.query(model.DebugInformationEntry).filter(
model.DebugInformationEntry.tag == Tag.compile_unit).all()
cus = session.query(model.DebugInformationEntry).filter(model.DebugInformationEntry.tag == Tag.compile_unit).all()
units = []
tps = set()
for cu in cus:
Expand All @@ -117,8 +116,7 @@ def __init__(self, session) -> None:
print(f"\t\tVariable without type: {ch.attributes_map}")
else:
tpx = int(ch.attributes_map["type"].raw_value)
tp = session.query(model.DebugInformationEntry).filter(
model.DebugInformationEntry.offset == tpx).first()
tp = session.query(model.DebugInformationEntry).filter(model.DebugInformationEntry.offset == tpx).first()
print(tp.attributes_map)

groups = groupby(sorted(units, key=lambda x: x.comp_dir), key=lambda x: x.comp_dir)
Expand Down Expand Up @@ -170,8 +168,7 @@ class AttributeParser:
# Little = 0
# Big = 1

def __init__(self, session_or_path, *, import_if_needed: bool = True, force_import: bool = False,
quiet: bool = True):
def __init__(self, session_or_path, *, import_if_needed: bool = True, force_import: bool = False, quiet: bool = True):
"""
Create an AttributeParser.

Expand Down Expand Up @@ -233,8 +230,7 @@ def __init__(self, session_or_path, *, import_if_needed: bool = True, force_impo
self.dwarf_expression = factory.dwarf_expression

@lru_cache(maxsize=64 * 1024)
def type_tree(self, obj: Union[int, model.DebugInformationEntry, DIEAttribute]) -> dict[
str, Any] | CircularReference:
def type_tree(self, obj: Union[int, model.DebugInformationEntry, DIEAttribute]) -> dict[str, Any] | CircularReference:
"""Return a fully traversed type tree as a dict.

Accepts one of:
Expand Down Expand Up @@ -278,9 +274,9 @@ def type_tree(self, obj: Union[int, model.DebugInformationEntry, DIEAttribute])
return {"tag": "<unsupported>", "attrs": {}}

def _resolve_type_offset(
self,
type_attr: DIEAttribute,
context_die: Optional[model.DebugInformationEntry],
self,
type_attr: DIEAttribute,
context_die: Optional[model.DebugInformationEntry],
) -> Optional[int]:
"""Resolve a DW_AT_type attribute's value to an absolute DIE offset.

Expand All @@ -297,11 +293,11 @@ def _resolve_type_offset(
try:
frm = getattr(type_attr, "form", None)
if frm in (
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
):
base = getattr(context_die, "cu_start", 0) if context_die is not None else 0
off += int(base or 0)
Expand Down Expand Up @@ -330,11 +326,11 @@ def traverse_tree(self, entry: model.DebugInformationEntry, level: int = 0) -> N
try:
frm = getattr(attr, "form", None)
if frm in (
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
):
base = getattr(entry, "cu_start", 0) or 0
off += int(base)
Expand All @@ -347,24 +343,22 @@ def traverse_tree(self, entry: model.DebugInformationEntry, level: int = 0) -> N
else:
if tag == "enumerator" and "const_value" in entry.attributes_map:
enumerator_value = int(entry.attributes_map["const_value"].raw_value)
print(
f"{' ' * level}{tag} '{name}'{type_info} [value=0x{enumerator_value:04x}] [off=0x{entry.offset:08x}]")
elif tag == 'subrange_type':
print(f"{' ' * level}{tag} '{name}'{type_info} [value=0x{enumerator_value:04x}] [off=0x{entry.offset:08x}]")
elif tag == "subrange_type":
lower_bound = 0
upper_bound = 0
if "lower_bound" in entry.attributes_map:
lower_bound = int(entry.attributes_map["lower_bound"].raw_value)
if "upper_bound" in entry.attributes_map:
upper_bound = int(entry.attributes_map["upper_bound"].raw_value)
print(
f"{' ' * level}{tag} '{name}'{type_info} [lower_bound={lower_bound}: upper_bound={upper_bound}] [off=0x{entry.offset:08x}]")
f"{' ' * level}{tag} '{name}'{type_info} [lower_bound={lower_bound}: upper_bound={upper_bound}] [off=0x{entry.offset:08x}]"
)
elif tag == "member" and "data_member_location" in entry.attributes_map:
data_member_location = self.dwarf_expression(
entry.attributes_map["data_member_location"].form,
entry.attributes_map["data_member_location"].raw_value
entry.attributes_map["data_member_location"].form, entry.attributes_map["data_member_location"].raw_value
)
print(
f"{' ' * level}{tag} '{name}'{type_info} [location={data_member_location}] [off=0x{entry.offset:08x}]")
print(f"{' ' * level}{tag} '{name}'{type_info} [location={data_member_location}] [off=0x{entry.offset:08x}]")
elif tag == "base_type":
descr = ""
if "byte_size" in entry.attributes_map:
Expand Down Expand Up @@ -410,11 +404,11 @@ def parse_attributes(self, die: model.DebugInformationEntry, level: int) -> dict
try:
frm = getattr(attr, "form", None)
if frm in (
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
getattr(AttributeForm, "DW_FORM_ref1", None),
getattr(AttributeForm, "DW_FORM_ref2", None),
getattr(AttributeForm, "DW_FORM_ref4", None),
getattr(AttributeForm, "DW_FORM_ref8", None),
getattr(AttributeForm, "DW_FORM_ref_udata", None),
):
base = getattr(die, "cu_start", 0) or 0
referenced_offset += int(base)
Expand Down
Loading