Skip to content

Commit

Permalink
Loclists pair fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sevaa committed Nov 15, 2023
1 parent 1c79abe commit ba8f356
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dwex/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .locals import LocalsDlg

# Sync with version in setup.py
version = (3, 22)
version = (3, 23)

# TODO:
# On MacOS, start without a main window, instead show the Open dialog
Expand Down
21 changes: 21 additions & 0 deletions dwex/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import elftools.dwarf.dwarf_expr
import elftools.dwarf.locationlists
import elftools.elf.elffile
import elftools.dwarf.dwarfinfo
from elftools.common.utils import struct_parse
from elftools.common.exceptions import DWARFError
from elftools.dwarf.descriptions import _DESCR_DW_CC
from elftools.dwarf.dwarfinfo import DebugSectionDescriptor
from elftools.elf.relocation import RelocationHandler
from elftools.dwarf.locationlists import LocationLists, LocationListsPair
from types import MethodType
from io import BytesIO

Expand Down Expand Up @@ -86,6 +88,8 @@ def get_location_list_at_offset_ex(self, offset):
in struct_parse(self.structs.Dwarf_loclists_entries, self.stream)]

elftools.dwarf.locationlists.LocationLists.get_location_lists_at_offset_ex = get_location_list_at_offset_ex
# Same for the pair object
elftools.dwarf.locationlists.LocationListsPair.get_location_lists_at_offset_ex = lambda self, offset: self._loclists.get_location_lists_at_offset_ex(offset)

# Rangelist entry translate with mixed V4/V5
def translate_v5_entry(self, entry, cu):
Expand Down Expand Up @@ -127,3 +131,20 @@ def _read_dwarf_section(self, section, relocate_dwarf_sections):

elftools.elf.elffile.ELFFile._read_dwarf_section = _read_dwarf_section

# Fix for #1572, also for eliben/pyelftools#519
def location_lists(self):
""" Get a LocationLists object representing the .debug_loc/debug_loclists section of
the DWARF data, or None if this section doesn't exist.
If both sections exist, it returns a LocationListsPair.
"""
if self.debug_loclists_sec and self.debug_loc_sec is None:
return LocationLists(self.debug_loclists_sec.stream, self.structs, 5, self)
elif self.debug_loc_sec and self.debug_loclists_sec is None:
return LocationLists(self.debug_loc_sec.stream, self.structs, 4, self)
elif self.debug_loc_sec and self.debug_loclists_sec:
return LocationListsPair(self.debug_loc_sec.stream, self.debug_loclists_sec.stream, self.structs, self)
else:
return None

elftools.dwarf.dwarfinfo.DWARFInfo.location_lists = location_lists

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run(self):

setup(
name='dwex',
version='3.22', # Sync with version in __main__
version='3.23', # Sync with version in __main__
packages=['dwex'],
url="https://github.com/sevaa/dwex/",
entry_points={"gui_scripts": ["dwex = dwex.__main__:main"]},
Expand Down

0 comments on commit ba8f356

Please sign in to comment.