generate_debug_prefix_map.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. # General Workflow:
  4. # 1. read all components dirs, a semicolon-separated string (cmake list)
  5. # 2. map the component dir with a unique prefix /COMPONENT_<NAME>_DIR
  6. # 2. write the prefix mapping file to $BUILD_DIR/prefix_map_gdbinit
  7. # 3. print the unique prefix out, a space-separated string, will be used by the build system to add compile options.
  8. import argparse
  9. import os
  10. from typing import List
  11. def component_name(component_dir: str) -> str:
  12. return '/COMPONENT_{}_DIR'.format(os.path.basename(component_dir).upper())
  13. GDB_SUBSTITUTE_PATH_FMT = 'set substitute-path {} {}\n'
  14. def write_gdbinit(build_dir: str, folders: List[str]) -> None:
  15. gdb_init_filepath = os.path.join(build_dir, 'prefix_map_gdbinit')
  16. with open(gdb_init_filepath, 'w') as fw:
  17. for folder in folders:
  18. fw.write(f'{GDB_SUBSTITUTE_PATH_FMT.format(component_name(folder), folder)}')
  19. def main(build_dir: str, folders: List[str]) -> None:
  20. write_gdbinit(build_dir, folders)
  21. print(' '.join([component_name(folder) for folder in folders]), end='')
  22. if __name__ == '__main__':
  23. parser = argparse.ArgumentParser(description='print the debug-prefix-map and write to '
  24. '$BUILD_DIR/prefix_map_gdbinit file')
  25. parser.add_argument('build_dir',
  26. help='build dir')
  27. parser.add_argument('folders',
  28. help='component folders, semicolon separated string')
  29. args = parser.parse_args()
  30. main(args.build_dir, args.folders.split(';'))