feat(debugging): move gdbinit generation to CMake

This feature is useful for 3rd-party software to run GDB with predefined
options that described in project_description.json file

allow to pass custom options to "idf.py gdb":

  --gdb-commands: command line arguments for gdb. (without changes)
  -ex: pass command to gdb.
  -x: pass gdbinit file to gdb. Alias for old --gdbinit command
This commit is contained in:
Alexey Lapshin
2024-11-06 17:01:33 +07:00
parent 16469297b4
commit 48a49c8154
19 changed files with 394 additions and 320 deletions

View File

@@ -1,21 +1,15 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import json
import logging
import os
import re
import subprocess
import sys
import pexpect
import pytest
from pytest_embedded_idf import IdfDut
try:
from idf_py_actions.debug_ext import get_openocd_arguments
except ModuleNotFoundError:
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
from idf_py_actions.debug_ext import get_openocd_arguments
@pytest.mark.supported_targets
@pytest.mark.jtag
@@ -27,8 +21,12 @@ def test_idf_gdb(dut: IdfDut) -> None:
# Don't need to have output from UART anymore
dut.serial.stop_redirect_thread()
desc_path = os.path.join(dut.app.binary_path, 'project_description.json')
with open(desc_path, 'r') as f:
project_desc = json.load(f)
with open(os.path.join(dut.logdir, 'ocd.txt'), 'w') as ocd_log:
cmd = ['openocd', *get_openocd_arguments(dut.target).split()]
cmd = ['openocd'] + project_desc['debug_arguments_openocd'].split()
openocd_scripts = os.getenv('OPENOCD_SCRIPTS')
if openocd_scripts:
cmd.extend(['-s', openocd_scripts])
@@ -37,18 +35,14 @@ def test_idf_gdb(dut: IdfDut) -> None:
ocd = subprocess.Popen(cmd, stdout=ocd_log, stderr=ocd_log)
try:
gdb_env = os.environ.copy()
gdb_env['ESP_IDF_GDB_TESTING'] = '1'
with open(os.path.join(dut.logdir, 'gdb.txt'), 'w') as gdb_log, \
pexpect.spawn(f'idf.py -B {dut.app.binary_path} gdb --batch',
env=gdb_env,
timeout=60,
logfile=gdb_log,
encoding='utf-8',
codec_errors='ignore') as p:
p.expect(re.compile(r'add symbol table from file.*bootloader.elf'))
p.expect(re.compile(r'add symbol table from file.*rom.elf'))
p.expect(re.compile(r'add symbol table from file.*rom.elf')) # if fail here: add target support here https://github.com/espressif/esp-rom-elfs
p.expect_exact('hit Temporary breakpoint 1, app_main ()')
finally:
ocd.terminate()