|
|
@@ -12,7 +12,7 @@ import time
|
|
|
from base64 import b64decode
|
|
|
from textwrap import indent
|
|
|
from threading import Thread
|
|
|
-from typing import Any, Dict, List, Optional
|
|
|
+from typing import Any, Dict, List, Optional, Union
|
|
|
|
|
|
from click import INT
|
|
|
from click.core import Context
|
|
|
@@ -70,6 +70,18 @@ def get_openocd_arguments(target: str) -> str:
|
|
|
return str(OPENOCD_TAGET_CONFIG.get(target, default_args))
|
|
|
|
|
|
|
|
|
+def chip_rev_to_int(chip_rev: Optional[str]) -> Union[int, None]:
|
|
|
+ # The chip rev will be derived from the elf file if none are returned.
|
|
|
+ # The chip rev must be supplied for coredump files generated with idf versions less than 5.1 in order to load
|
|
|
+ # rom elf file.
|
|
|
+ if not chip_rev or not all(c.isdigit() or c == '.' for c in chip_rev):
|
|
|
+ return None
|
|
|
+ if '.' not in chip_rev:
|
|
|
+ chip_rev += '.0'
|
|
|
+ major, minor = map(int, chip_rev.split('.'))
|
|
|
+ return major * 100 + minor
|
|
|
+
|
|
|
+
|
|
|
def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
OPENOCD_OUT_FILE = 'openocd_out.txt'
|
|
|
GDBGUI_OUT_FILE = 'gdbgui_out.txt'
|
|
|
@@ -137,6 +149,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
args: PropertyDict,
|
|
|
gdb_timeout_sec: int = None,
|
|
|
core: str = None,
|
|
|
+ chip_rev: str = None,
|
|
|
save_core: str = None) -> CoreDump:
|
|
|
|
|
|
ensure_build_directory(args, ctx.info_name)
|
|
|
@@ -146,8 +159,20 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
coredump_to_flash = coredump_to_flash_config.rstrip().endswith('y') if coredump_to_flash_config else False
|
|
|
|
|
|
prog = os.path.join(project_desc['build_dir'], project_desc['app_elf'])
|
|
|
+ args.port = args.port or get_default_serial_port()
|
|
|
+
|
|
|
+ espcoredump_kwargs = dict()
|
|
|
+
|
|
|
+ espcoredump_kwargs['baud'] = args.baud
|
|
|
+ espcoredump_kwargs['gdb_timeout_sec'] = gdb_timeout_sec
|
|
|
+ espcoredump_kwargs['chip_rev'] = chip_rev_to_int(chip_rev)
|
|
|
+
|
|
|
+ # for reproducible builds
|
|
|
+ extra_gdbinit_file = project_desc.get('debug_prefix_map_gdbinit', None)
|
|
|
+
|
|
|
+ if extra_gdbinit_file:
|
|
|
+ espcoredump_kwargs['extra_gdbinit_file'] = extra_gdbinit_file
|
|
|
|
|
|
- espcoredump_kwargs: Dict[str, Any] = dict()
|
|
|
core_format = None
|
|
|
|
|
|
if core:
|
|
|
@@ -164,16 +189,8 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
sys.exit(1)
|
|
|
|
|
|
espcoredump_kwargs['port'] = args.port
|
|
|
- espcoredump_kwargs['baud'] = args.baud
|
|
|
- espcoredump_kwargs['gdb_timeout_sec'] = gdb_timeout_sec
|
|
|
-
|
|
|
- # for reproducible builds
|
|
|
- extra_gdbinit_file = project_desc.get('debug_prefix_map_gdbinit', None)
|
|
|
-
|
|
|
- if extra_gdbinit_file:
|
|
|
- espcoredump_kwargs['extra_gdbinit_file'] = extra_gdbinit_file
|
|
|
-
|
|
|
- espcoredump_kwargs['parttable_off'] = get_sdkconfig_value(project_desc['config_file'], 'CONFIG_PARTITION_TABLE_OFFSET')
|
|
|
+ espcoredump_kwargs['parttable_off'] = get_sdkconfig_value(project_desc['config_file'],
|
|
|
+ 'CONFIG_PARTITION_TABLE_OFFSET')
|
|
|
|
|
|
if core_format:
|
|
|
espcoredump_kwargs['core_format'] = core_format
|
|
|
@@ -245,7 +262,8 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
base_ident = ' '
|
|
|
rom_elfs_dir = os.getenv('ESP_ROM_ELF_DIR')
|
|
|
if not rom_elfs_dir:
|
|
|
- raise FatalError('ESP_ROM_ELF_DIR environment variable is not defined. Please try to run IDF "install" and "export" scripts.')
|
|
|
+ raise FatalError(
|
|
|
+ 'ESP_ROM_ELF_DIR environment variable is not defined. Please try to run IDF "install" and "export" scripts.')
|
|
|
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), ESP_ROM_INFO_FILE), 'r') as f:
|
|
|
roms = json.load(f)
|
|
|
if target not in roms:
|
|
|
@@ -382,8 +400,9 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
# use default value if commands not defined in the environment nor command line
|
|
|
target = project_desc['target']
|
|
|
openocd_arguments = get_openocd_arguments(target)
|
|
|
- print('Note: OpenOCD cfg not found (via env variable OPENOCD_COMMANDS nor as a --openocd-commands argument)\n'
|
|
|
- 'OpenOCD arguments default to: "{}"'.format(openocd_arguments))
|
|
|
+ print(
|
|
|
+ 'Note: OpenOCD cfg not found (via env variable OPENOCD_COMMANDS nor as a --openocd-commands argument)\n'
|
|
|
+ 'OpenOCD arguments default to: "{}"'.format(openocd_arguments))
|
|
|
# script directory is taken from the environment by OpenOCD, update only if command line arguments to override
|
|
|
if openocd_scripts is not None:
|
|
|
openocd_arguments += ' -s {}'.format(openocd_scripts)
|
|
|
@@ -469,8 +488,8 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
if debug_targets:
|
|
|
# Register the meta cleanup callback -> called on FatalError
|
|
|
ctx.meta['cleanup'] = debug_cleanup
|
|
|
- move_to_front('gdbgui') # possibly 2nd
|
|
|
- move_to_front('openocd') # always 1st
|
|
|
+ move_to_front('gdbgui') # possibly 2nd
|
|
|
+ move_to_front('openocd') # always 1st
|
|
|
# followed by "monitor", "gdb" or "gdbtui" in any order
|
|
|
|
|
|
post_action = ctx.invoke(ctx.command.get_command(ctx, 'post_debug'))
|
|
|
@@ -478,7 +497,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
post_action.action_args['block'] = 0
|
|
|
else:
|
|
|
post_action.action_args['block'] = 1
|
|
|
- tasks.append(post_action) # always last
|
|
|
+ tasks.append(post_action) # always last
|
|
|
if any([task.name == 'openocd' for task in tasks]):
|
|
|
for task in tasks:
|
|
|
if task.name in ('gdb', 'gdbgui', 'gdbtui'):
|
|
|
@@ -490,11 +509,12 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
"""
|
|
|
gdb(action, ctx, args, False, 1, gdbinit, require_openocd)
|
|
|
|
|
|
- def gdb(action: str, ctx: Context, args: PropertyDict, batch: bool, gdb_tui: Optional[int], gdbinit: Optional[str], require_openocd: bool) -> None:
|
|
|
+ def gdb(action: str, ctx: Context, args: PropertyDict, batch: bool, gdb_tui: Optional[int], gdbinit: Optional[str],
|
|
|
+ require_openocd: bool) -> None:
|
|
|
"""
|
|
|
Synchronous GDB target
|
|
|
"""
|
|
|
- watch_openocd = Thread(target=_check_openocd_errors, args=(fail_if_openocd_failed, action, ctx, ))
|
|
|
+ watch_openocd = Thread(target=_check_openocd_errors, args=(fail_if_openocd_failed, action, ctx,))
|
|
|
watch_openocd.start()
|
|
|
processes['threads_to_join'].append(watch_openocd)
|
|
|
project_desc = get_project_desc(args, ctx)
|
|
|
@@ -527,8 +547,10 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
args: PropertyDict,
|
|
|
gdb_timeout_sec: int,
|
|
|
core: str = None,
|
|
|
+ chip_rev: str = None,
|
|
|
save_core: str = None) -> None:
|
|
|
espcoredump = _get_espcoredump_instance(ctx=ctx, args=args, gdb_timeout_sec=gdb_timeout_sec, core=core,
|
|
|
+ chip_rev=chip_rev,
|
|
|
save_core=save_core)
|
|
|
|
|
|
espcoredump.info_corefile()
|
|
|
@@ -537,8 +559,9 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
ctx: Context,
|
|
|
args: PropertyDict,
|
|
|
core: str = None,
|
|
|
+ chip_rev: str = None,
|
|
|
save_core: str = None) -> None:
|
|
|
- espcoredump = _get_espcoredump_instance(ctx=ctx, args=args, core=core, save_core=save_core)
|
|
|
+ espcoredump = _get_espcoredump_instance(ctx=ctx, args=args, core=core, chip_rev=chip_rev, save_core=save_core)
|
|
|
|
|
|
espcoredump.dbg_corefile()
|
|
|
|
|
|
@@ -547,6 +570,12 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
'names': ['--core', '-c'],
|
|
|
'help': 'Path to core dump file (if skipped core dump will be read from flash)',
|
|
|
},
|
|
|
+ {
|
|
|
+ 'names': ['--chip-rev'],
|
|
|
+ 'help': 'Specify the chip revision (e.g., 0.1). If provided, the corresponding ROM ELF file will be used '
|
|
|
+ 'for decoding the core dump, improving stack traces. This is only needed for core dumps from IDF '
|
|
|
+ '<v5.1. Newer versions already contain chip revision information.',
|
|
|
+ },
|
|
|
{
|
|
|
'names': ['--save-core', '-s'],
|
|
|
'help': 'Save core to file. Otherwise temporary core file will be deleted.',
|
|
|
@@ -579,14 +608,14 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
{
|
|
|
'names': ['--openocd-scripts', '--openocd_scripts'],
|
|
|
'help':
|
|
|
- ('Script directory for openocd cfg files.\n'),
|
|
|
+ ('Script directory for openocd cfg files.\n'),
|
|
|
'default':
|
|
|
- None,
|
|
|
+ None,
|
|
|
},
|
|
|
{
|
|
|
'names': ['--openocd-commands', '--openocd_commands'],
|
|
|
'help':
|
|
|
- ('Command line arguments for openocd.\n'),
|
|
|
+ ('Command line arguments for openocd.\n'),
|
|
|
'default': None,
|
|
|
}
|
|
|
],
|
|
|
@@ -618,9 +647,9 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
{
|
|
|
'names': ['--gdbgui-port', '--gdbgui_port'],
|
|
|
'help':
|
|
|
- ('The port on which gdbgui will be hosted. Default: 5000\n'),
|
|
|
+ ('The port on which gdbgui will be hosted. Default: 5000\n'),
|
|
|
'default':
|
|
|
- None,
|
|
|
+ None,
|
|
|
}, gdbinit, fail_if_openocd_failed
|
|
|
],
|
|
|
'order_dependencies': ['all', 'flash'],
|
|
|
@@ -651,7 +680,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
{
|
|
|
'names': ['--block', '--block'],
|
|
|
'help':
|
|
|
- ('Set to 1 for blocking the console on the outputs of async debug actions\n'),
|
|
|
+ ('Set to 1 for blocking the console on the outputs of async debug actions\n'),
|
|
|
'default': 0,
|
|
|
},
|
|
|
],
|
|
|
@@ -671,7 +700,7 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
|
|
{
|
|
|
'names': ['--block', '--block'],
|
|
|
'help':
|
|
|
- ('Set to 1 for blocking the console on the outputs of async debug actions\n'),
|
|
|
+ ('Set to 1 for blocking the console on the outputs of async debug actions\n'),
|
|
|
'default': 0,
|
|
|
},
|
|
|
],
|