forked from platformio/platformio-core
Debug native (desktop) application on a host machine // Resolve #980
This commit is contained in:
@ -14,6 +14,7 @@ PlatformIO Core 5
|
|||||||
* **PlatformIO Debugging**
|
* **PlatformIO Debugging**
|
||||||
|
|
||||||
- Boosted `PlatformIO Debugging <https://docs.platformio.org/page/plus/debugging.html>`__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack
|
- Boosted `PlatformIO Debugging <https://docs.platformio.org/page/plus/debugging.html>`__ performance thanks to migrating the codebase to the pure Python 3 Asynchronous I/O stack
|
||||||
|
- Debug native (desktop) application on a host machine (`issue #980 <https://github.com/platformio/platformio-core/issues/980>`_)
|
||||||
- Support debugging on Windows using Windows CMD/CLI (`pio debug <https://docs.platformio.org/page/core/userguide/cmd_debug.html>`__) (`issue #3793 <https://github.com/platformio/platformio-core/issues/3793>`_)
|
- Support debugging on Windows using Windows CMD/CLI (`pio debug <https://docs.platformio.org/page/core/userguide/cmd_debug.html>`__) (`issue #3793 <https://github.com/platformio/platformio-core/issues/3793>`_)
|
||||||
- Configure a custom pattern to determine when debugging server is started with a new `debug_server_ready_pattern <https://docs.platformio.org/page/projectconf/section_env_debug.html#debug-server-ready-pattern>`__ option
|
- Configure a custom pattern to determine when debugging server is started with a new `debug_server_ready_pattern <https://docs.platformio.org/page/projectconf/section_env_debug.html#debug-server-ready-pattern>`__ option
|
||||||
- Fixed an issue with silent hanging when a custom debug server is not found (`issue #3756 <https://github.com/platformio/platformio-core/issues/3756>`_)
|
- Fixed an issue with silent hanging when a custom debug server is not found (`issue #3756 <https://github.com/platformio/platformio-core/issues/3756>`_)
|
||||||
|
@ -79,7 +79,7 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, __unpro
|
|||||||
return helpers.predebug_project(ctx, project_dir, env_name, False, verbose)
|
return helpers.predebug_project(ctx, project_dir, env_name, False, verbose)
|
||||||
|
|
||||||
env_options = project_config.items(env=env_name, as_dict=True)
|
env_options = project_config.items(env=env_name, as_dict=True)
|
||||||
if not set(env_options.keys()) >= set(["platform", "board"]):
|
if "platform" not in env_options:
|
||||||
raise ProjectEnvsNotAvailableError()
|
raise ProjectEnvsNotAvailableError()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -29,14 +29,21 @@ class DebugConfigBase: # pylint: disable=too-many-instance-attributes
|
|||||||
self.project_config = project_config
|
self.project_config = project_config
|
||||||
self.env_name = env_name
|
self.env_name = env_name
|
||||||
self.env_options = project_config.items(env=env_name, as_dict=True)
|
self.env_options = project_config.items(env=env_name, as_dict=True)
|
||||||
self.board_config = platform.board_config(self.env_options["board"])
|
|
||||||
self.build_data = self._load_build_data()
|
self.build_data = self._load_build_data()
|
||||||
self.tool_name = self.board_config.get_debug_tool_name(
|
|
||||||
self.env_options.get("debug_tool")
|
self.tool_name = None
|
||||||
)
|
self.board_config = {}
|
||||||
self.tool_settings = (
|
self.tool_settings = {}
|
||||||
self.board_config.get("debug", {}).get("tools", {}).get(self.tool_name, {})
|
if "board" in self.env_options:
|
||||||
)
|
self.board_config = platform.board_config(self.env_options["board"])
|
||||||
|
self.tool_name = self.board_config.get_debug_tool_name(
|
||||||
|
self.env_options.get("debug_tool")
|
||||||
|
)
|
||||||
|
self.tool_settings = (
|
||||||
|
self.board_config.get("debug", {})
|
||||||
|
.get("tools", {})
|
||||||
|
.get(self.tool_name, {})
|
||||||
|
)
|
||||||
|
|
||||||
self._load_cmds = None
|
self._load_cmds = None
|
||||||
self._port = None
|
self._port = None
|
||||||
|
@ -16,6 +16,7 @@ import importlib
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from platformio.debug.config.generic import GenericDebugConfig
|
from platformio.debug.config.generic import GenericDebugConfig
|
||||||
|
from platformio.debug.config.native import NativeDebugConfig
|
||||||
|
|
||||||
|
|
||||||
class DebugConfigFactory(object):
|
class DebugConfigFactory(object):
|
||||||
@ -29,13 +30,19 @@ class DebugConfigFactory(object):
|
|||||||
board_config = platform.board_config(
|
board_config = platform.board_config(
|
||||||
project_config.get("env:" + env_name, "board")
|
project_config.get("env:" + env_name, "board")
|
||||||
)
|
)
|
||||||
tool_name = board_config.get_debug_tool_name(
|
tool_name = (
|
||||||
project_config.get("env:" + env_name, "debug_tool")
|
board_config.get_debug_tool_name(
|
||||||
|
project_config.get("env:" + env_name, "debug_tool")
|
||||||
|
)
|
||||||
|
if board_config
|
||||||
|
else None
|
||||||
)
|
)
|
||||||
config_cls = None
|
config_cls = None
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module("platformio.debug.config.%s" % tool_name)
|
mod = importlib.import_module("platformio.debug.config.%s" % tool_name)
|
||||||
config_cls = getattr(mod, cls.get_clsname(tool_name))
|
config_cls = getattr(mod, cls.get_clsname(tool_name))
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
config_cls = GenericDebugConfig
|
config_cls = (
|
||||||
|
GenericDebugConfig if platform.is_embedded() else NativeDebugConfig
|
||||||
|
)
|
||||||
return config_cls(platform, project_config, env_name)
|
return config_cls(platform, project_config, env_name)
|
||||||
|
32
platformio/debug/config/native.py
Normal file
32
platformio/debug/config/native.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
from platformio.debug.config.base import DebugConfigBase
|
||||||
|
|
||||||
|
|
||||||
|
class NativeDebugConfig(DebugConfigBase):
|
||||||
|
|
||||||
|
GDB_INIT_SCRIPT = """
|
||||||
|
define pio_reset_halt_target
|
||||||
|
end
|
||||||
|
|
||||||
|
define pio_reset_run_target
|
||||||
|
end
|
||||||
|
|
||||||
|
define pio_restart_target
|
||||||
|
end
|
||||||
|
|
||||||
|
$INIT_BREAK
|
||||||
|
set startup-with-shell off
|
||||||
|
"""
|
@ -37,7 +37,7 @@ class GDBClientProcess(DebugClientProcess):
|
|||||||
await super(GDBClientProcess, self).run()
|
await super(GDBClientProcess, self).run()
|
||||||
|
|
||||||
self.generate_init_script(os.path.join(self.working_dir, self.PIO_SRC_NAME))
|
self.generate_init_script(os.path.join(self.working_dir, self.PIO_SRC_NAME))
|
||||||
gdb_path = self.debug_config.client_executable_path
|
gdb_path = self.debug_config.client_executable_path or "gdb"
|
||||||
# start GDB client
|
# start GDB client
|
||||||
args = [
|
args = [
|
||||||
gdb_path,
|
gdb_path,
|
||||||
@ -115,7 +115,8 @@ class GDBClientProcess(DebugClientProcess):
|
|||||||
token, _ = data.split(b"-", 1)
|
token, _ = data.split(b"-", 1)
|
||||||
self.stdout_data_received(token + b"^running\n")
|
self.stdout_data_received(token + b"^running\n")
|
||||||
return
|
return
|
||||||
data = data.replace(b"-exec-run", b"-exec-continue")
|
if self.debug_config.platform.is_embedded():
|
||||||
|
data = data.replace(b"-exec-run", b"-exec-continue")
|
||||||
|
|
||||||
if b"-exec-continue" in data:
|
if b"-exec-continue" in data:
|
||||||
self._target_is_running = True
|
self._target_is_running = True
|
||||||
@ -158,9 +159,14 @@ class GDBClientProcess(DebugClientProcess):
|
|||||||
self.console_log(
|
self.console_log(
|
||||||
"PlatformIO: More configuration options -> http://bit.ly/pio-debug\n"
|
"PlatformIO: More configuration options -> http://bit.ly/pio-debug\n"
|
||||||
)
|
)
|
||||||
self.transport.get_pipe_transport(0).write(
|
if self.debug_config.platform.is_embedded():
|
||||||
b"0-exec-continue\n" if helpers.is_gdbmi_mode() else b"continue\n"
|
self.transport.get_pipe_transport(0).write(
|
||||||
)
|
b"0-exec-continue\n" if helpers.is_gdbmi_mode() else b"continue\n"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.transport.get_pipe_transport(0).write(
|
||||||
|
b"0-exec-run\n" if helpers.is_gdbmi_mode() else b"run\n"
|
||||||
|
)
|
||||||
self._target_is_running = True
|
self._target_is_running = True
|
||||||
|
|
||||||
def stderr_data_received(self, data):
|
def stderr_data_received(self, data):
|
||||||
|
Reference in New Issue
Block a user