tools: fixed elf symbols load if gdbinit specified

ROM and bootloader symbols add to use in GDB (via 'idf.py gdb')
This commit is contained in:
Alexey Lapshin
2022-08-20 13:36:14 +04:00
parent fd2846c95e
commit 29655fe22a
6 changed files with 276 additions and 31 deletions

View File

@@ -9,7 +9,9 @@ import subprocess
import sys
from unittest import TestCase, main, mock
import elftools.common.utils as ecu
import jsonschema
from elftools.elf.elffile import ELFFile
try:
from StringIO import StringIO
@@ -25,7 +27,8 @@ except ImportError:
current_dir = os.path.dirname(os.path.realpath(__file__))
idf_py_path = os.path.join(current_dir, '..', 'idf.py')
extension_path = os.path.join(current_dir, 'test_idf_extensions', 'test_ext')
link_path = os.path.join(current_dir, '..', 'idf_py_actions', 'test_ext')
py_actions_path = os.path.join(current_dir, '..', 'idf_py_actions')
link_path = os.path.join(py_actions_path, 'test_ext')
class TestWithoutExtensions(TestCase):
@@ -246,5 +249,47 @@ class TestHelpOutput(TestWithoutExtensions):
action_test(['idf.py', 'help', '--json', '--add-options'], schema_json)
class TestROMs(TestWithoutExtensions):
def get_string_from_elf_by_addr(self, filename: str, address: int) -> str:
result = ''
with open(filename, 'rb') as stream:
elf_file = ELFFile(stream)
ro = elf_file.get_section_by_name('.rodata')
ro_addr_delta = ro['sh_addr'] - ro['sh_offset']
cstring = ecu.parse_cstring_from_stream(ro.stream, address - ro_addr_delta)
if cstring:
result = str(cstring.decode('utf-8'))
return result
def test_roms_validate_json(self):
with open(os.path.join(py_actions_path, 'roms.json'), 'r') as f:
roms_json = json.load(f)
with open(os.path.join(py_actions_path, 'roms_schema.json'), 'r') as f:
schema_json = json.load(f)
jsonschema.validate(roms_json, schema_json)
def test_roms_check_supported_chips(self):
from idf_py_actions.constants import SUPPORTED_TARGETS
with open(os.path.join(py_actions_path, 'roms.json'), 'r') as f:
roms_json = json.load(f)
for chip in SUPPORTED_TARGETS:
self.assertTrue(chip in roms_json, msg=f'Have no ROM data for chip {chip}')
def test_roms_validate_build_date(self):
sys.path.append(py_actions_path)
rom_elfs_dir = os.getenv('ESP_ROM_ELF_DIR')
with open(os.path.join(py_actions_path, 'roms.json'), 'r') as f:
roms_json = json.load(f)
for chip in roms_json:
for k in roms_json[chip]:
rom_file = os.path.join(rom_elfs_dir, f'{chip}_rev{k["rev"]}_rom.elf')
build_date_str = self.get_string_from_elf_by_addr(rom_file, int(k['build_date_str_addr'], base=16))
self.assertTrue(len(build_date_str) == 11)
self.assertTrue(build_date_str == k['build_date_str'])
if __name__ == '__main__':
main()