From c8b576661eac216527bdf086368694f3fb76c412 Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Wed, 3 Jun 2026 08:13:25 +0200 Subject: [PATCH 1/3] dwarf/struct: Add missing type information Fixes: 12e96365cb75 ("Fix a bunch of other ruff check issues") Signed-off-by: Philipp Hahn --- elftools/dwarf/structs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elftools/dwarf/structs.py b/elftools/dwarf/structs.py index 223488be..c14f89ae 100644 --- a/elftools/dwarf/structs.py +++ b/elftools/dwarf/structs.py @@ -429,7 +429,7 @@ def _parse(self, stream: IO[bytes], context: Container) -> Any: context[self.format_field + "_parser"] = parser return parser._parse(stream, context) - def ver5(ctx): + def ver5(ctx: Container) -> bool: return ctx.version >= 5 self.Dwarf_lineprog_header = Struct('Dwarf_lineprog_header', From b53fb7cb65626a1e34c759b6fb29ecd2ce5b070d Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Wed, 3 Jun 2026 08:19:40 +0200 Subject: [PATCH 2/3] dwarf/callframe: Type augmentation_bytes as bytes Harmonize both CFIEntry and FDE to expect bytes for augmentation_bytes; drop None alternative. Signed-off-by: Philipp Hahn --- elftools/dwarf/callframe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elftools/dwarf/callframe.py b/elftools/dwarf/callframe.py index 0a5a4171..ec31839c 100644 --- a/elftools/dwarf/callframe.py +++ b/elftools/dwarf/callframe.py @@ -526,7 +526,7 @@ def __init__( instructions: list[CallFrameInstruction], offset: int, augmentation_dict: Augmentation | None = None, - augmentation_bytes: bytes | None = b'', + augmentation_bytes: bytes = b"", cie: CIE | None = None, ) -> None: self.header = header @@ -696,7 +696,7 @@ def __init__( structs: DWARFStructs, instructions: list[CallFrameInstruction], offset: int, - augmentation_bytes: bytes | None = None, + augmentation_bytes: bytes = b"", cie: CIE | None = None, lsda_pointer: int | None = None, ) -> None: From b598da5315dd542a87d9d65817f69e6f84bc0fee Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Wed, 3 Jun 2026 07:52:08 +0200 Subject: [PATCH 3/3] dwarf: Replace assert(False) with raise DWARFError Instead of using dwarf_assert(False, mgs) directly raise DWARFError(msg). Signed-off-by: Philipp Hahn --- elftools/dwarf/callframe.py | 5 +++-- elftools/dwarf/lineprogram.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/elftools/dwarf/callframe.py b/elftools/dwarf/callframe.py index ec31839c..27d67c83 100644 --- a/elftools/dwarf/callframe.py +++ b/elftools/dwarf/callframe.py @@ -14,6 +14,7 @@ from typing import IO, TYPE_CHECKING, Any, Literal, NamedTuple, cast from warnings import warn +from ..common.exceptions import DWARFError from ..common.utils import ( struct_parse, dwarf_assert, preserve_stream_pos) from ..construct import Struct, Switch @@ -267,7 +268,7 @@ def _parse_instructions( case DW_CFA.GNU_args_size: args = [struct_parse(structs.the_Dwarf_uleb128, self.stream)] case _: - dwarf_assert(False, f'Unknown CFI opcode: {raw_opcode:#04x}') + raise DWARFError(f"Unknown CFI opcode: {raw_opcode:#04x}") instructions.append(CallFrameInstruction(opcode=opcode, args=args)) offset = self.stream.tell() @@ -670,7 +671,7 @@ def _add_to_order(regnum: int) -> None: case DW_CFA.nop | DW_CFA.AARCH64_negate_ra_state: pass case _: - dwarf_assert(False, f"Unknown CFI opcode: {instr.opcode:#02x}") + raise DWARFError(f"Unknown CFI opcode: {instr.opcode:#02x}") # The current line is appended to the table after all instructions # have ended, if there were instructions. diff --git a/elftools/dwarf/lineprogram.py b/elftools/dwarf/lineprogram.py index d666e2d1..82a4ec6c 100644 --- a/elftools/dwarf/lineprogram.py +++ b/elftools/dwarf/lineprogram.py @@ -13,7 +13,8 @@ from functools import cached_property from typing import IO, TYPE_CHECKING, Any, NamedTuple -from ..common.utils import struct_parse, dwarf_assert +from ..common.exceptions import DWARFError +from ..common.utils import struct_parse from .constants import DW_LNE, DW_LNS if TYPE_CHECKING: @@ -274,7 +275,6 @@ def add_entry_old_state(cmd: int, args: list[int], is_extended: bool = False) -> state.isa = operand add_entry_old_state(opcode, [operand]) else: - dwarf_assert(False, 'Invalid standard line program opcode: %s' % ( - opcode,)) + raise DWARFError(f"Invalid standard line program opcode: {opcode}") offset = self.stream.tell() return entries