diff --git a/docs b/docs index 03c5eb48..e366c5d3 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 03c5eb487fe7abd85745a6810bab06eaf29b5a81 +Subproject commit e366c5d3642137d1326635cebafa666f198131db diff --git a/platformio/commands/debug/client.py b/platformio/commands/debug/client.py index 610f598d..4e2298f9 100644 --- a/platformio/commands/debug/client.py +++ b/platformio/commands/debug/client.py @@ -27,8 +27,9 @@ from twisted.internet import stdio # pylint: disable=import-error from twisted.internet import task # pylint: disable=import-error from platformio import app, fs, proc, telemetry, util -from platformio.commands.debug import helpers, initcfgs +from platformio.commands.debug import helpers from platformio.commands.debug.exception import DebugInvalidOptionsError +from platformio.commands.debug.initcfgs import get_gdb_init_config from platformio.commands.debug.process import BaseProcess from platformio.commands.debug.server import DebugServer from platformio.compat import hashlib_encode_data, is_bytes @@ -113,22 +114,8 @@ class GDBClient(BaseProcess): # pylint: disable=too-many-instance-attributes return gdb_data_dir if isdir(gdb_data_dir) else None def generate_pioinit(self, dst_dir, patterns): - server_exe = ( - (self.debug_options.get("server") or {}).get("executable", "").lower() - ) - if "jlink" in server_exe: - cfg = initcfgs.GDB_JLINK_INIT_CONFIG - elif "st-util" in server_exe: - cfg = initcfgs.GDB_STUTIL_INIT_CONFIG - elif "mspdebug" in server_exe: - cfg = initcfgs.GDB_MSPDEBUG_INIT_CONFIG - elif "qemu" in server_exe: - cfg = initcfgs.GDB_QEMU_INIT_CONFIG - elif self.debug_options["require_debug_port"]: - cfg = initcfgs.GDB_BLACKMAGIC_INIT_CONFIG - else: - cfg = initcfgs.GDB_DEFAULT_INIT_CONFIG - commands = cfg.split("\n") + # default GDB init commands depending on debug tool + commands = get_gdb_init_config(self.debug_options).split("\n") if self.debug_options["init_cmds"]: commands = self.debug_options["init_cmds"] diff --git a/platformio/commands/debug/initcfgs.py b/platformio/commands/debug/initcfgs.py index 50da1779..d39629d5 100644 --- a/platformio/commands/debug/initcfgs.py +++ b/platformio/commands/debug/initcfgs.py @@ -123,3 +123,21 @@ $LOAD_CMDS pio_reset_halt_target $INIT_BREAK """ + + +TOOL_TO_CONFIG = { + "jlink": GDB_JLINK_INIT_CONFIG, + "mspdebug": GDB_MSPDEBUG_INIT_CONFIG, + "qemu": GDB_QEMU_INIT_CONFIG, + "blackmagic": GDB_BLACKMAGIC_INIT_CONFIG, +} + + +def get_gdb_init_config(debug_options): + tool = debug_options.get("tool") + if tool and tool in TOOL_TO_CONFIG: + return TOOL_TO_CONFIG[tool] + server_exe = (debug_options.get("server") or {}).get("executable", "").lower() + if "st-util" in server_exe: + return GDB_STUTIL_INIT_CONFIG + return GDB_DEFAULT_INIT_CONFIG