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

Debugger does not honor selected environment #4098

Closed
manuelbl opened this issue Oct 4, 2020 · 20 comments
Closed

Debugger does not honor selected environment #4098

manuelbl opened this issue Oct 4, 2020 · 20 comments
Assignees
Milestone

Comments

@manuelbl
Copy link

manuelbl commented Oct 4, 2020

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
@ivankravets
Copy link
Member

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

@manuelbl
Copy link
Author

manuelbl commented Oct 4, 2020

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.

@ivankravets ivankravets transferred this issue from platformio/platformio-vscode-ide Oct 6, 2020
@ivankravets ivankravets transferred this issue from platformio/platformio-core Oct 28, 2020
@ivankravets
Copy link
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.

@manuelbl
Copy link
Author

manuelbl commented Nov 1, 2020

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.

@ivankravets
Copy link
Member

Do you use the latest PlatformIO Core 5.0.3 Dev?

@manuelbl
Copy link
Author

manuelbl commented Nov 1, 2020

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.

@ivankravets
Copy link
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".

@ivankravets ivankravets reopened this Nov 1, 2020
@manuelbl
Copy link
Author

manuelbl commented Nov 1, 2020

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?

@ivankravets
Copy link
Member

See instruction by a link above. Thanks.

@ivankravets
Copy link
Member

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

@manuelbl
Copy link
Author

manuelbl commented Nov 3, 2020

It looks good. For the first time, debugging the selected environment works. Thanks.

The "No configured task..." pop-up didn't appear anymore. I hope it has been fixed for good.

I can still generate the "Could not find the specified task." error. It seems to be related to currently open file in the editor. The error occurs if a file from another project is open. The solution is to open a file from the project to be debugged (or bring the file to the front).

@ivankravets
Copy link
Member

VSCode consumes tasks depending on the active project. We don’t rebuild index every time. It seems that we should provide debugging configuration using VSCode API and not use launch.json.

Other solution is to revert back PlatformIO Core and use a base pre-debug task.

@ivankravets ivankravets reopened this Nov 4, 2020
@maxgerhardt
Copy link
Contributor

Also noted as a bug in community thread

@GadgetAngel
Copy link

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!

@ivankravets ivankravets transferred this issue from platformio/platformio-vscode-ide Nov 3, 2021
@ivankravets ivankravets added this to the 5.2.3 milestone Nov 3, 2021
@ivankravets ivankravets self-assigned this Nov 3, 2021
@dzid26
Copy link

dzid26 commented Apr 6, 2023

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.

@ivankravets
Copy link
Member

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

@dzid26
Copy link

dzid26 commented Apr 11, 2023

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.

@ivankravets
Copy link
Member

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

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

@dzid26
Copy link

dzid26 commented Apr 12, 2023

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.

@ivankravets
Copy link
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?

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

5 participants