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 15c32509dd
commit 080f1a0b0d
17 changed files with 394 additions and 316 deletions

View File

@@ -9,6 +9,7 @@
import argparse
import os
import shutil
from typing import List
@@ -20,12 +21,18 @@ GDB_SUBSTITUTE_PATH_FMT = 'set substitute-path {} {}\n'
def write_gdbinit(build_dir: str, folders: List[str]) -> None:
gdb_init_filepath = os.path.join(build_dir, 'prefix_map_gdbinit')
gdbinit_dir = os.path.join(build_dir, 'gdbinit')
gdbinit_filepath = os.path.join(gdbinit_dir, 'prefix_map')
with open(gdb_init_filepath, 'w') as fw:
if not os.path.exists(gdbinit_dir):
os.mkdir(gdbinit_dir)
with open(gdbinit_filepath, 'w') as fw:
for folder in folders:
fw.write(f'{GDB_SUBSTITUTE_PATH_FMT.format(component_name(folder), folder)}')
shutil.copy(gdbinit_filepath, os.path.join(build_dir, 'prefix_map_gdbinit'))
def main(build_dir: str, folders: List[str]) -> None:
write_gdbinit(build_dir, folders)
@@ -34,7 +41,7 @@ def main(build_dir: str, folders: List[str]) -> None:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='print the debug-prefix-map and write to '
'$BUILD_DIR/prefix_map_gdbinit file')
'$BUILD_DIR/gdbinit/prefix_map file')
parser.add_argument('build_dir',
help='build dir')