Skip to content

Debugger does not honor selected environment #4098

Closed

Description

@manuelbl

The new environment switch in the status bar is a welcome enhancement. Unfortunately, it is not honored by the debugger. Instead, the debugger uses the first environment or the one selected by default_envs.

As the environment switch applies to IntelliSense and the Build and Upload actions in the status bar, users expect that the debugger behaves the same. I did so too.

In my case it even lead to a very confusing situation:

  • Clicking the green arrow the debugger pane started a rebuild of the project (debug configuration) – as expected.
  • After that, nothing happened anymore.
  • It took me quite some time until I remembered to switch to the DEBUG CONSOLE. I found an error basically saying unexpected idcode: 0x0bb11477, expected 1 of 1: 0x2ba01477.
  • It took me even more time to figure out that this error message was not due to a Chinese clone of the STM32 chip, but rather due to a mismatch between the environment use by the debugger and the board connected to my computer.

I see two options to fix it:

  • Honor the currently select environment when starting the debugger (preferred)
  • Label the debug configuration (launch.json) such that it is obvious which one is used

Activity

  1. ivankravets commented on Oct 4, 2020

    @ivankravets
    Member

    I don’t remember, do we provide different debug profiles when you switch to Debugging activity?

  2. manuelbl commented on Oct 4, 2020

    @manuelbl
    Author

    I'm not sure I fully understand your question. But the below information might answer it.

    If you change platformio.ini and either rearrange the order of environments or changed default_envs, then launch.json is updated.

    A configuration in launch.json looks like so:

            {
                "type": "platformio-debug",
                "request": "launch",
                "name": "PIO Debug",
                "executable": "/Users/me/Documents/my-project/.pio/build/nucleo_f042k6/firmware.elf",
                "toolchainBinDir": "/Users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin",
                "svdPath": "/Users/me/.platformio/platforms/ststm32/misc/svd/STM32F042x.svd",
                "preLaunchTask": {
                    "type": "PlatformIO",
                    "task": "Pre-Debug"
                },
                "internalConsoleOptions": "openOnSessionStart"
            },
    

    Note that the selected environment is part of the executable path and the board type also affects svdPath. So the selected environment is very relevant.

  3. ivankravets commented on Oct 31, 2020

    @ivankravets
    Member

    platformio/platformio-vscode-ide#2018 (comment)

    You will also need the latest PlatformIO Core 5.0.3 Dev.

    Does it work now? Thanks!

    P.S: Also would be thankful for the feedback with upcoming chnages in 2.2.0.

  4. manuelbl commented on Nov 1, 2020

    @manuelbl
    Author

    I've jus tried it and it didn't work. The correct environment was used to build a debug version. But the debugger is then started with a different (incorrect) environment.

    launch.json looks ok. But the first line in the DEBUG CONSOLE already points at the incorrect environment (the selected environment is nucleo-f303re, the debugger however used nucleo_f042k6, which is the top most in platformio.ini):

    Processing nucleo-f042k6 (board: nucleo_f042k6; platform: ststm32; framework: libopencm3)
    

    Strangely enough, it looks as if the target was build twice: the output of the correct one appears in the TERMINAL view, the output of the incorrect one appears in DEBUG CONSOLE.

  5. ivankravets commented on Nov 1, 2020

    @ivankravets
    Member

    Do you use the latest PlatformIO Core 5.0.3 Dev?

  6. manuelbl commented on Nov 1, 2020

    @manuelbl
    Author

    Yes, I do.

    And I'm having more troubles. On a project with a single environment, I can't start the debugger anymore. I always get the error message "Could not find the specified task." This is new. It has worked before I upgraded to the development version.

    And I don't know if it is related... Quite often Build and Upload in the status bar don't work. Instead of executing something, they just display a pop up (the kind VSC displays to let you select something):

    image

    This isn't new. It has occurred from time to time since the environment selector in the status bar was introduced. The workaround is to again select the already selected environment from the status bar.

  7. ivankravets commented on Nov 1, 2020

    @ivankravets
    Member

    Keep PlatformIO IDe extension at 2.2.0-beta and downgrade PlatformIO Core to the latest stable 5.0.2. I'll try to investigate this issue.

    Another workaround is to use "PIO Debug (skip Pre-Debug)" instead of "PIO Debug".

  8. manuelbl commented on Nov 1, 2020

    @manuelbl
    Author

    I have been using the new core 5.0.3a1 but the old extension (2.1.3). How do I upgrade to the beta version?

  9. ivankravets commented on Nov 1, 2020

    @ivankravets
    Member

    See instruction by a link above. Thanks.

  10. ivankravets commented on Nov 3, 2020

    @ivankravets
    Member

    2.2.0 has been released! You will just need the latest PIO Core 5.0.3-dev.

  11. 3 remaining items

  12. maxgerhardt commented on Feb 2, 2021

    @maxgerhardt
    Contributor

    Also noted as a bug in community thread

  13. GadgetAngel commented on Feb 6, 2021

    @GadgetAngel

    THANK YOU

    I moved to "platformIO dev" branch and I also checked that I had the latest "PlafformIO IDE" extension installed. Moving to the dev branch, solved my "Error could not find specified task"

    Thankyou!

  14. added this to the 5.2.3 milestone on Nov 3, 2021
  15. self-assigned this
    on Nov 3, 2021
  16. dzid26 commented on Apr 6, 2023

    @dzid26

    I've jus tried it and it didn't work. The correct environment was used to build a debug version. But the debugger is then started with a different (incorrect) environment.

    launch.json looks ok. But the first line in the DEBUG CONSOLE already points at the incorrect environment (the selected environment is nucleo-f303re, the debugger however used nucleo_f042k6, which is the top most in platformio.ini):

    Strangely enough, it looks as if the target was build twice: the output of the correct one appears in the TERMINAL view, the output of the incorrect one appears in DEBUG CONSOLE.

    I still have this problem.
    Debug console uses an environment from default_envs rather than one containing build_type = debug and the whole thing builds twice (reason or a symptom? Maybe unrelated).

    I am poking around because I get the annoying full double rebuild when debugging.
    I am on Windows - VSCode.

  17. ivankravets commented on Apr 11, 2023

    @ivankravets
    Member

    @dzid26, could you share your platformio.ini content?

  18. dzid26 commented on Apr 11, 2023

    @dzid26

    I am using this normally.
    But I was also testing separate debug environment in relation to this issue with the following:

    ;PlatformIO Project Configuration File
    ;
    ;   Build options: build flags, source filter
    ;   Upload options: custom upload port, speed and extra flags
    ;   Library options: dependencies, extra library storages
    ;   Advanced options: extra scripting
    ;
    ; Please visit documentation for the other options and examples
    ; https://docs.platformio.org/page/projectconf.html
    
    [platformio]
    src_dir      = src
    include_dir  = src/BSP
    default_envs = ServoCAN
    
    [env]
    platform = ststm32
    
    board = genericSTM32F103C8
    upload_protocol = stlink
    
    build_flags =
      -D STM32F10X_MD
      -D SYSCLK_FREQ_64MHz
      -D USE_STDPERIPH_DRIVER
      -O3 -flto
      -W -Wall -pedantic -std=c99
      -fsingle-precision-constant
      -Wdouble-promotion
      -Wfloat-conversion
      -I src/OP
      -I src/CMSIS
      -I src/LIB/inc
      -I src/APP
      -Wl,-Map,${BUILD_DIR}/firmware.map
      -D HSE_VALUE=16000000
    
    board_build.ldscript = ./src/APP/STM32F103C8_DEFAULT.ld
    board_upload.maximum_size = 63488
    extra_scripts = linker_options_pio.py  ;skips definitions for system functions
    
    check_tool = cppcheck, clangtidy
    check_skip_packages = yes ;don't inlcude compiler package inludes 
    check_patterns = 
      src/BSP/*.c
      src/BSP/*.h
    check_flags =
      cppcheck:--addon=misra.json --std=c99 --language=c  --suppress=*:*/src/CMSIS/* --suppress=*:*/src/LIB/*
      clangtidy: --checks=-*,clang-analyzer-*,cert-*,bugprone-*,performance-*,hicpp-*,cppcoreguidelines-*,readability-*
    
    [env:ServoCAN]
    
    build_flags = ${env.build_flags}
      -g  #include variable symbols in elf file
    
      
    [env:ServoCAN_debug]
    build_type = debug
    debug_tool = stlink
    debug_build_flags = -Og -g3 -ggdb3 #disable most optimizations
      -D IGNORE_CAN_CHECKSUM
      -D DEBUG
    debug_extra_cmds =
      monitor arm semihosting enable
      monitor arm semihosting_fileio enable
    

    I think the problem is related to how launch.json is interpreted by the terminal and debug console, because when I change the default env on the toolbar or modify "projectEnvName": to "ServoCAN_debug" manually then both terminal and debug_console build the same thing. ...Albeit still the whole thing is rebuild twice which is my main trouble.

  19. ivankravets commented on Apr 12, 2023

    @ivankravets
    Member
  20. dzid26 commented on Apr 12, 2023

    @dzid26

    See https://github.com/platformio/platformio-core/blob/develop/platformio/debug/helpers.py#L65

    Does it makes sense to set "Environment Switcher" to "Auto"?

    This function seems to be ignored by the debug console.

    I am not sure but I think only CLI uses get_default_debug_env, but the debug console build uses whatever is in launch.json. When Environment Switcher is set to Default, then launch.json; happens to have non-debug env specified (i.e. "projectEnvName": "ServoCAN",). Then CLI will build ServoCAN_debug and debug console will build ServoCAN (even though it will say "building in debug mode". If I change I type "projectEnvName": "ServoCAN)debug", in launch.json, only then debug console builds the debug env.

    Terminal uses https://github.com/platformio/platformio-core/blob/develop/platformio/debug/helpers.py#L65.
    Debug console uses https://github.com/platformio/platformio-core/blob/develop/platformio/run/cli.py#L135 logic for some reason.

  21. ivankravets commented on Apr 12, 2023

    @ivankravets
    Member

    @dzid26, thanks, I reproduced this issue. This is a bug and is different from this issue. Could I ask you to open a new issue at https://github.com/platformio/platformio-core/issues to track this problem?

  22. added a commit that references this issue on Apr 18, 2026
    973f770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions