Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native debug session fails if custom boards are defined #4745

Closed
mmmspatz opened this issue Sep 9, 2023 · 1 comment
Closed

Native debug session fails if custom boards are defined #4745

mmmspatz opened this issue Sep 9, 2023 · 1 comment

Comments

@mmmspatz
Copy link

mmmspatz commented Sep 9, 2023

Configuration

PlatformIO Version (platformio --version): PlatformIO Core, version 6.1.11

Description of problem

Steps to Reproduce

  1. Create a project
  2. Add a custom board to the project that does not specify "platform" or "platforms"
  3. Add a configuration environment that specifies platform = native and debug_test = *
  4. Attempt to launch a native debug session pio debug -e native --interface=gdb

Actual Results

AttributeError: Traceback (most recent call last):
  File "/home/mspatz/code/platformio-core/platformio/__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/mspatz/code/platformio-core/platformio/cli.py", line 85, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/.local/pipx/venvs/platformio/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/code/platformio-core/platformio/debug/cli.py", line 104, in cli
    debug_config = _configure(*configure_args)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/code/platformio-core/platformio/debug/cli.py", line 113, in _configure
    debug_config = DebugConfigFactory.new(
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mspatz/code/platformio-core/platformio/debug/config/factory.py", line 34, in new
    board_config.get_debug_tool_name(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'get_debug_tool_name'

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `python -m pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

Expected Results

GDB launches and attaches to my test

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:custom_disco_h747xi]
platform = ststm32
board = custom_disco_h747xi
framework = cmsis

[env:native]
platform = native
debug_test = *

Source file to reproduce issue:

boards/custom_disco_h747xi.json (unmodified form platform ststm32, but copied into project board dir):

{
  "build": {
    "cpu": "cortex-m7",
    "extra_flags": "-DSTM32H7xx -DSTM32H747xx",
    "f_cpu": "400000000L",
    "mcu": "stm32h747xih6",
    "product_line": "STM32H747xx",
    "zephyr": {
       "variant": "stm32h747i_disco_m7"
    }
  },
  "connectivity": [
    "can",
    "ethernet"
  ],
  "debug": {
    "default_tools": [
      "stlink"
    ],
    "jlink_device": "STM32H747XI",
    "onboard_tools": [
      "stlink"
    ],
    "openocd_board": "st_nucleo_h743zi",
    "openocd_target": "stm32h7x",
    "svd_path": "STM32H747_CM7.svd"
  },
  "frameworks": [
    "cmsis",
    "stm32cube",
    "libopencm3",
    "mbed",
    "zephyr"
  ],
  "name": "STM32H747I-DISCO",
  "upload": {
    "maximum_ram_size": 524288,
    "maximum_size": 2097152,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "cmsis-dap",
      "stlink",
      "blackmagic",
      "mbed"
    ]
  },
  "url": "https://www.st.com/en/evaluation-tools/stm32h747i-disco.html",
  "vendor": "ST"
}

** Other Info **
This was reported here: #4685

The root of the problem is in PlatformBase.get_boards(), which returns EITHER a PlatformBoardConfig or a dict of them if id_ == None.

def get_boards(self, id_=None):

If [env:native] doesn't specify a board (which it shouldn't), DebugConfigFactory.new() ends up calling PlatformBase.get_boards(None), which as I said returns a dict instead of a PlatformBoardConfig, resulting in the exception.
The exception is avoided if the dict happens to be empty, which it is if there are no custom boards in the project or core_dir, thus the difficulty in reproducing this bug.
https://github.com/platformio/platformio-core/blob/091c96eb078964dd18eaa1cb9d84ee0079584e53/platformio/debug/config/factory.py#L30C1-L30C46

@ivankravets
Copy link
Member

Thanks for the report. Please re-test with pio upgrade --dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants