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-12-06 19:36:41 +07:00
parent daf465c038
commit 0e57dc044e
19 changed files with 401 additions and 320 deletions
+9 -3
View File
@@ -7,6 +7,8 @@
# remap the substituted paths back to the real paths in the filesystem.
function(__generate_prefix_map compile_options_var)
set(compile_options)
set(gdbinit_dir ${BUILD_DIR}/gdbinit)
set(gdbinit_path "${gdbinit_dir}/prefix_map")
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(build_components BUILD_COMPONENTS)
@@ -44,11 +46,15 @@ function(__generate_prefix_map compile_options_var)
list(APPEND compile_options "-fdebug-prefix-map=${compiler_sysroot}=/TOOLCHAIN")
string(APPEND gdbinit_file_lines "set substitute-path /TOOLCHAIN ${compiler_sysroot}\n")
# Write the final gdbinit file
set(gdbinit_path "${BUILD_DIR}/prefix_map_gdbinit")
file(WRITE "${gdbinit_path}" "${gdbinit_file_lines}")
file(WRITE "${BUILD_DIR}/prefix_map_gdbinit" "${gdbinit_file_lines}") # TODO IDF-11667
idf_build_set_property(DEBUG_PREFIX_MAP_GDBINIT "${gdbinit_path}")
else()
set(gdbinit_file_lines "# There is no prefix map defined for the project.\n")
endif()
# Write prefix_map_gdbinit file even it is empty.
file(MAKE_DIRECTORY ${gdbinit_dir})
file(WRITE "${gdbinit_path}" "${gdbinit_file_lines}")
idf_build_set_property(GDBINIT_FILES_PREFIX_MAP "${gdbinit_path}")
set(${compile_options_var} ${compile_options} PARENT_SCOPE)
endfunction()