mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 07:04:32 +02:00
tools: fix idf_monitor.py not working on macOS for Linux target
Since the introduction of PCAddressMatcher, the executable produced by the build system is passed to elftools.elf.elffile.ELFFile. However on macOS, native executables are not ELF files, so the ELFFile class raises a rather unhelpful AssertionError exception. Given that the rest of the idf_monitor.py doesn't have assumptions that the "elf_file" argument is an ELF file (rather than just an executable), check if the file is a real ELF file inside PCAddressMatcher.
This commit is contained in:
@@ -7,8 +7,8 @@ from elftools.elf.elffile import ELFFile
|
|||||||
|
|
||||||
class PcAddressMatcher(object):
|
class PcAddressMatcher(object):
|
||||||
"""
|
"""
|
||||||
Class for detecting potentional addresses which will consequently run through the external addr2line command to
|
Class for detecting potential addresses which will consequently run through the external addr2line command to
|
||||||
indentify and print information about it.
|
identify and print information about it.
|
||||||
|
|
||||||
The input to this class is the path to the ELF file. Addresses of sections with executable flag are stored and
|
The input to this class is the path to the ELF file. Addresses of sections with executable flag are stored and
|
||||||
used later for lookup.
|
used later for lookup.
|
||||||
@@ -18,6 +18,14 @@ class PcAddressMatcher(object):
|
|||||||
self.intervals = []
|
self.intervals = []
|
||||||
try:
|
try:
|
||||||
with open(elf_path, 'rb') as f:
|
with open(elf_path, 'rb') as f:
|
||||||
|
# Is this an ELF file?
|
||||||
|
elf_magic = f.read(4)
|
||||||
|
if elf_magic != b'\x7fELF':
|
||||||
|
# Probably not an ELF file
|
||||||
|
# (could be Mach-O format on macOS, for example)
|
||||||
|
raise NotImplementedError()
|
||||||
|
f.seek(0)
|
||||||
|
|
||||||
elf = ELFFile(f)
|
elf = ELFFile(f)
|
||||||
|
|
||||||
for section in elf.iter_sections():
|
for section in elf.iter_sections():
|
||||||
@@ -30,13 +38,15 @@ class PcAddressMatcher(object):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# ELF file is just an optional argument
|
# ELF file is just an optional argument
|
||||||
pass
|
pass
|
||||||
|
except NotImplementedError:
|
||||||
|
pass
|
||||||
|
|
||||||
# sort them in order to have faster lookup
|
# sort them in order to have faster lookup
|
||||||
self.intervals = sorted(self.intervals)
|
self.intervals = sorted(self.intervals)
|
||||||
|
|
||||||
def is_executable_address(self, addr): # type: (int) -> bool
|
def is_executable_address(self, addr): # type: (int) -> bool
|
||||||
"""
|
"""
|
||||||
Returns True/False depending on of "addr" is in one of the ELF sections with executable flag set.
|
Returns True/False if "addr" is in one of the ELF sections with executable flag set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for start, end in self.intervals:
|
for start, end in self.intervals:
|
||||||
|
Reference in New Issue
Block a user