idf.py gdb: autoload prefix_map_gdbinit when exists in project_description.json

pull/7855/head
Fu Hanxi 2021-10-26 10:41:13 +08:00
rodzic ea1005b740
commit 42405604af
4 zmienionych plików z 25 dodań i 17 usunięć

Wyświetl plik

@ -151,6 +151,8 @@ if(NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 8.0.0)
endif()
if(CONFIG_APP_REPRODUCIBLE_BUILD)
idf_build_set_property(DEBUG_PREFIX_MAP_GDBINIT "${BUILD_DIR}/prefix_map_gdbinit")
list(APPEND compile_options "-fdebug-prefix-map=${IDF_PATH}=/IDF")
list(APPEND compile_options "-fdebug-prefix-map=${PROJECT_DIR}=/IDF_PROJECT")
list(APPEND compile_options "-fdebug-prefix-map=${BUILD_DIR}=/IDF_BUILD")

Wyświetl plik

@ -111,6 +111,7 @@ function(__project_info test_components)
include(${sdkconfig_cmake})
idf_build_get_property(COMPONENT_KCONFIGS KCONFIGS)
idf_build_get_property(COMPONENT_KCONFIGS_PROJBUILD KCONFIG_PROJBUILDS)
idf_build_get_property(debug_prefix_map_gdbinit DEBUG_PREFIX_MAP_GDBINIT)
# Write project description JSON file
idf_build_get_property(build_dir BUILD_DIR)

Wyświetl plik

@ -18,5 +18,5 @@
},
"build_components" : ${build_components_json},
"build_component_paths" : ${build_component_paths_json},
"debug_prefix_map_gdbinit": "${BUILD_DIR}/prefix_map_gdbinit"
"debug_prefix_map_gdbinit": "${debug_prefix_map_gdbinit}"
}

Wyświetl plik

@ -7,6 +7,7 @@ import sys
import threading
import time
from threading import Thread
from typing import Any, Dict, List
from idf_py_actions.errors import FatalError
from idf_py_actions.tools import ensure_build_directory
@ -83,19 +84,6 @@ def action_extensions(base_actions, project_path):
print('Failed to close/kill {}'.format(target))
processes[target] = None # to indicate this has ended
def _get_commandline_options(ctx):
""" Return all the command line options up to first action """
# This approach ignores argument parsing done Click
result = []
for arg in sys.argv:
if arg in ctx.command.commands_with_aliases:
break
result.append(arg)
return result
def create_local_gdbinit(gdbinit, elf_file):
with open(gdbinit, 'w') as f:
if os.name == 'nt':
@ -188,6 +176,13 @@ def action_extensions(base_actions, project_path):
processes['openocd_outfile_name'] = openocd_out_name
print('OpenOCD started as a background task {}'.format(process.pid))
def get_gdb_args(gdbinit, project_desc: Dict[str, Any]) -> List[str]:
args = ['-x={}'.format(gdbinit)]
debug_prefix_gdbinit = project_desc.get('debug_prefix_map_gdbinit')
if debug_prefix_gdbinit:
args.append('-ix={}'.format(debug_prefix_gdbinit))
return args
def gdbui(action, ctx, args, gdbgui_port, gdbinit, require_openocd):
"""
Asynchronous GDB-UI target
@ -198,7 +193,17 @@ def action_extensions(base_actions, project_path):
if gdbinit is None:
gdbinit = os.path.join(local_dir, 'gdbinit')
create_local_gdbinit(gdbinit, os.path.join(args.build_dir, project_desc['app_elf']))
args = ['gdbgui', '-g', gdb, '--gdb-args="-x={}"'.format(gdbinit)]
# this is a workaround for gdbgui
# gdbgui is using shlex.split for the --gdb-args option. When the input is:
# - '"-x=foo -x=bar"', would return ['foo bar']
# - '-x=foo', would return ['-x', 'foo'] and mess up the former option '--gdb-args'
# so for one item, use extra double quotes. for more items, use no extra double quotes.
gdb_args = get_gdb_args(gdbinit, project_desc)
gdb_args = '"{}"'.format(' '.join(gdb_args)) if len(gdb_args) == 1 else ' '.join(gdb_args)
args = ['gdbgui', '-g', gdb, '--gdb-args', gdb_args]
print(args)
if gdbgui_port is not None:
args += ['--port', gdbgui_port]
gdbgui_out_name = os.path.join(local_dir, GDBGUI_OUT_FILE)
@ -278,10 +283,10 @@ def action_extensions(base_actions, project_path):
if gdbinit is None:
gdbinit = os.path.join(local_dir, 'gdbinit')
create_local_gdbinit(gdbinit, elf_file)
args = [gdb, '-x={}'.format(gdbinit)]
args = [gdb, *get_gdb_args(gdbinit, project_desc)]
if gdb_tui is not None:
args += ['-tui']
t = Thread(target=run_gdb, args=(args, ))
t = Thread(target=run_gdb, args=(args,))
t.start()
while True:
try: