Allow to pass multiple load commands to PIO Unified Debugger

This commit is contained in:
Ivan Kravets
2019-05-31 14:45:48 +03:00
parent 5f9fd9260e
commit bae21f1cdd
5 changed files with 27 additions and 22 deletions

View File

@ -73,7 +73,7 @@ class GDBClient(BaseProcess): # pylint: disable=too-many-instance-attributes
"DEBUG_PORT": self.debug_options['port'], "DEBUG_PORT": self.debug_options['port'],
"UPLOAD_PROTOCOL": self.debug_options['upload_protocol'], "UPLOAD_PROTOCOL": self.debug_options['upload_protocol'],
"INIT_BREAK": self.debug_options['init_break'] or "", "INIT_BREAK": self.debug_options['init_break'] or "",
"LOAD_CMD": self.debug_options['load_cmd'] or "", "LOAD_CMDS": "\n".join(self.debug_options['load_cmds'] or []),
} }
self._debug_server.spawn(patterns) self._debug_server.spawn(patterns)

View File

@ -93,11 +93,11 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface,
raise exception.PlatformioException("\n".join( raise exception.PlatformioException("\n".join(
[result['out'], result['err']])) [result['out'], result['err']]))
debug_options['load_cmd'] = helpers.configure_esp32_load_cmd( debug_options['load_cmds'] = helpers.configure_esp32_load_cmds(
debug_options, configuration) debug_options, configuration)
rebuild_prog = False rebuild_prog = False
preload = debug_options['load_cmd'] == "preload" preload = debug_options['load_cmds'] == ["preload"]
load_mode = debug_options['load_mode'] load_mode = debug_options['load_mode']
if load_mode == "always": if load_mode == "always":
rebuild_prog = ( rebuild_prog = (
@ -112,7 +112,7 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface,
if preload or (not rebuild_prog and load_mode != "always"): if preload or (not rebuild_prog and load_mode != "always"):
# don't load firmware through debug server # don't load firmware through debug server
debug_options['load_cmd'] = None debug_options['load_cmds'] = []
if rebuild_prog: if rebuild_prog:
if helpers.is_mi_mode(__unprocessed): if helpers.is_mi_mode(__unprocessed):

View File

@ -26,6 +26,7 @@ from platformio.commands.platform import \
platform_install as cmd_platform_install platform_install as cmd_platform_install
from platformio.commands.run import cli as cmd_run from platformio.commands.run import cli as cmd_run
from platformio.managers.platform import PlatformFactory from platformio.managers.platform import PlatformFactory
from platformio.project.config import ProjectConfig
class GDBBytesIO(BytesIO): # pylint: disable=too-few-public-methods class GDBBytesIO(BytesIO): # pylint: disable=too-few-public-methods
@ -53,12 +54,11 @@ def get_default_debug_env(config):
def validate_debug_options(cmd_ctx, env_options): def validate_debug_options(cmd_ctx, env_options):
def _cleanup_cmds(cmds): def _cleanup_cmds(items):
if not cmds: items = ProjectConfig.parse_multi_values(items)
return [] return [
if not isinstance(cmds, list): "$LOAD_CMDS" if item == "$LOAD_CMD" else item for item in items
cmds = cmds.split("\n") ]
return [c.strip() for c in cmds if c.strip()]
try: try:
platform = PlatformFactory.newPlatform(env_options['platform']) platform = PlatformFactory.newPlatform(env_options['platform'])
@ -115,8 +115,11 @@ def validate_debug_options(cmd_ctx, env_options):
upload_protocol=env_options.get( upload_protocol=env_options.get(
"upload_protocol", "upload_protocol",
board_config.get("upload", {}).get("protocol")), board_config.get("upload", {}).get("protocol")),
load_cmd=env_options.get("debug_load_cmd", load_cmds=_cleanup_cmds(
tool_settings.get("load_cmd", "load")), env_options.get(
"debug_load_cmds",
tool_settings.get("load_cmds",
tool_settings.get("load_cmd", "load")))),
load_mode=env_options.get("debug_load_mode", load_mode=env_options.get("debug_load_mode",
tool_settings.get("load_mode", "always")), tool_settings.get("load_mode", "always")),
init_break=env_options.get( init_break=env_options.get(
@ -173,9 +176,9 @@ def load_configuration(ctx, project_dir, env_name):
return None return None
def configure_esp32_load_cmd(debug_options, configuration): def configure_esp32_load_cmds(debug_options, configuration):
ignore_conds = [ ignore_conds = [
debug_options['load_cmd'] != "load", debug_options['load_cmds'] != ["load"],
"xtensa-esp32" not in configuration.get("cc_path", ""), "xtensa-esp32" not in configuration.get("cc_path", ""),
not configuration.get("flash_extra_images"), not all([ not configuration.get("flash_extra_images"), not all([
isfile(item['path']) isfile(item['path'])
@ -183,7 +186,7 @@ def configure_esp32_load_cmd(debug_options, configuration):
]) ])
] ]
if any(ignore_conds): if any(ignore_conds):
return debug_options['load_cmd'] return debug_options['load_cmds']
mon_cmds = [ mon_cmds = [
'monitor program_esp32 "{{{path}}}" {offset} verify'.format( 'monitor program_esp32 "{{{path}}}" {offset} verify'.format(
@ -192,7 +195,7 @@ def configure_esp32_load_cmd(debug_options, configuration):
] ]
mon_cmds.append('monitor program_esp32 "{%s.bin}" 0x10000 verify' % mon_cmds.append('monitor program_esp32 "{%s.bin}" 0x10000 verify' %
escape_path(configuration['prog_path'][:-4])) escape_path(configuration['prog_path'][:-4]))
return "\n".join(mon_cmds) return mon_cmds
def has_debug_symbols(prog_path): def has_debug_symbols(prog_path):

View File

@ -24,7 +24,7 @@ end
target extended-remote $DEBUG_PORT target extended-remote $DEBUG_PORT
$INIT_BREAK $INIT_BREAK
pio_reset_halt_target pio_reset_halt_target
$LOAD_CMD $LOAD_CMDS
monitor init monitor init
pio_reset_halt_target pio_reset_halt_target
""" """
@ -42,7 +42,7 @@ end
target extended-remote $DEBUG_PORT target extended-remote $DEBUG_PORT
$INIT_BREAK $INIT_BREAK
pio_reset_halt_target pio_reset_halt_target
$LOAD_CMD $LOAD_CMDS
pio_reset_halt_target pio_reset_halt_target
""" """
@ -59,7 +59,7 @@ end
target extended-remote $DEBUG_PORT target extended-remote $DEBUG_PORT
$INIT_BREAK $INIT_BREAK
pio_reset_halt_target pio_reset_halt_target
$LOAD_CMD $LOAD_CMDS
pio_reset_halt_target pio_reset_halt_target
""" """
@ -83,7 +83,7 @@ monitor swdp_scan
attach 1 attach 1
set mem inaccessible-by-default off set mem inaccessible-by-default off
$INIT_BREAK $INIT_BREAK
$LOAD_CMD $LOAD_CMDS
set language c set language c
set *0xE000ED0C = 0x05FA0004 set *0xE000ED0C = 0x05FA0004
@ -104,6 +104,6 @@ end
target extended-remote $DEBUG_PORT target extended-remote $DEBUG_PORT
$INIT_BREAK $INIT_BREAK
monitor erase monitor erase
$LOAD_CMD $LOAD_CMDS
pio_reset_halt_target pio_reset_halt_target
""" """

View File

@ -176,7 +176,9 @@ ProjectOptions = OrderedDict([
ConfigEnvOption(name="debug_init_break"), ConfigEnvOption(name="debug_init_break"),
ConfigEnvOption(name="debug_init_cmds", multiple=True), ConfigEnvOption(name="debug_init_cmds", multiple=True),
ConfigEnvOption(name="debug_extra_cmds", multiple=True), ConfigEnvOption(name="debug_extra_cmds", multiple=True),
ConfigEnvOption(name="debug_load_cmd"), ConfigEnvOption(name="debug_load_cmds",
oldnames=["debug_load_cmd"],
multiple=True),
ConfigEnvOption(name="debug_load_mode", ConfigEnvOption(name="debug_load_mode",
type=click.Choice(["always", "modified", "manual"])), type=click.Choice(["always", "modified", "manual"])),
ConfigEnvOption(name="debug_server", multiple=True), ConfigEnvOption(name="debug_server", multiple=True),