-
Notifications
You must be signed in to change notification settings - Fork 243
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
[RFC] Support west debug #969
Comments
We don't hard code it. You did, by your choice. You can also use VSCode project settings.json (the preferred way), you can use env. vars, other extensions - including CMake. I will welcome your contribution but first I want to understand the issue and gaps. If you are saying that we should pick up all of our settings from another file rather than what VSCode tells us (via settings and/or launch.json) then I am not sure we are headed in the right direction. Not ruling it out but there is a trend that says please look at this file or that file for my settings. I would ask them to modify their build process to update the right settings for VSCode so it cuts across all extensions. |
@nguyenmthien, this is a pretty active space for Zephyr, with different proposals and ongoing discussions. Fundamentally, the data that a Zephyr project uses for builds/debugs/etc. should be generated by Zephyr in a Visual Studio Code extension-agnostic way. This is because you want your intellisense, linters, CoPilots, debuggers and others all to have a set of common info about the Zephyr project, rather than each extension trying to draw that context from the Zephyr project in their own unique way. I haven't seen any activity to actually introduce such an extension to the west tools for Zephyr, but their is an enhancement issue in that project that's been around for a while. See zephyrproject-rtos/zephyr#21119 To get started on a Zephyr in VS Code solution now, you can follow @beriberikix 's work in this presentation from the 2023 Embedded Open Source Summit: https://blog.golioth.io/how-to-configure-vs-code-for-zephyr-development/. |
Thanks @ifyall for the pointers I still maintain that your build process should do the right thing(s). I cannot realistically support every possible build system. And, not even have means of testing it. Way out of scope. |
I've been thinking about this problem for some time and agree that Zephyr should be handling (not cortex-debug) and it should ideally be in an extension-agnostic way. I think the right approach is to create a West extension that generates the right files, like a settings or workspace. Someone wrote a POC Python script called zephyr2vsc that's got the basic idea but it needs further development and would need to be converted into a West extension. |
thank you all for your pointers and inputs :) Since this issue is out-of-scope for cortex-debug, I will henceforth close this. |
Would love to test/help in any way I can! |
Thanks @beriberikix |
I've also played with this, and experimented with zephyr2vsc. We commit the launch.json (don't really use tasks.json), and it might look like this: {
"version": "0.2.0",
"configurations": [
{
"name": "dev",
"type": "cortex-debug",
"request": "attach",
"servertype":"jlink",
"executable": "${workspaceRoot}/build/zephyr/zephyr.elf",
"device": "nRF52840_xxAA",
"svdFile": "${workspaceFolder}/.vscode/nrf52840.svd",
"toolchainPrefix": "arm-zephyr-eabi",
"armToolchainPath": "${env:ARM_TOOLCHAIN_PATH}",
"serverpath": "${env:JLINK_GDB_SERVER}",
"rtos": "${env:JLINK_ZEPHYR_PLUGIN}",
},
{
"name": "mcuboot",
"type": "cortex-debug",
"request": "launch",
"servertype":"jlink",
"executable": "${workspaceRoot}/build/mcuboot/zephyr/zephyr.elf",
"device": "nRF52840_xxAA",
"svdFile": "${workspaceFolder}/.vscode/nrf52840.svd",
"toolchainPrefix": "arm-zephyr-eabi",
"runToEntryPoint": "main",
"armToolchainPath": "${env:ARM_TOOLCHAIN_PATH}",
"serverpath": "${env:JLINK_GDB_SERVER}",
"rtos": "${env:JLINK_ZEPHYR_PLUGIN}",
},
{
"name": "ztest",
"type": "cortex-debug",
"request": "launch",
"servertype":"jlink",
"executable": "${workspaceRoot}/tests/build/zephyr.elf",
"device": "nRF52840_xxAA",
"svdFile": "${workspaceFolder}/.vscode/nrf52840.svd",
"toolchainPrefix": "arm-zephyr-eabi",
"armToolchainPath": "${env:ARM_TOOLCHAIN_PATH}",
"serverpath": "${env:JLINK_GDB_SERVER}",
"rtos": "${env:JLINK_ZEPHYR_PLUGIN}",
},
],
} Bonus content: we can debug on-target tests from VSCode 😮 As you can see, environment variables are used so that this file can be shared and tracked by git. There's a huge catch, which is that you must set the environment variables before opening VSCode, otherwise launch.json cannot access them. I've been involved in discussions with MS, and they're sympathetic, but the tldr seems to be that once VCPKG found a nice workaround, any institutional pressure to improve things evaporated. FWIW, I maintain a MacOS/Windows/Linux 0-dependency script that manages environment variables, aliases, etc - simplifies things quite a bit in complex Zephyr environments. Handles setting ZEPHYR_BASE, using venv, and of course the interface is the same for all OS, cause that's the whole point of envr. https://github.com/JPhutchins/envr A typical Zephyr project config might look like:
It's critical to us that VSCode is a TOOL and never a DEPENDENCY - |
@nguyenmthien As to your initial ask; what I've taken to doing in Zephyr and non-Zephyr CMake systems that have multiple targets is add a target that always copies the "most recent ELF" to the same place, typically Truly, it reminds me that MS needs to be pressured to allow use of environment variables - here's the issue thread microsoft/vscode#152806 |
@JPHutchins thanks a lot for your information, I am now working on a west extension command to create a Because this issue is out-of-scope for cortex-debug, I have moved this discussion to the official Zephyr discord server, please chime in if you have any additional inputs 😃 |
If I may, I have a suggestion. I am not sure generating Then in launch.json, you can do See: https://code.visualstudio.com/docs/editor/variables-reference#_command-variables Now, in your extension CMake makes extensive use of this mechanism My two cents. |
Is your feature request related to a problem? Please describe.
One of the best features of Zephyr RTOS is the possibility to switch between targets in development. An application can be written for many hardware architectures, and the toolchain (
gcc
,gdb
,openocd
, etc) can be switched on the fly usingwest
and its subcommands (build
,flash
,debug
,debugserver
).Natively supporting
west
would be nice for those who use Cortex-Debug in their Zephyr workflow.At the moment, Cortex-Debug is hard-coding the path to GNU toolchain to each profiles, which make it impossible to change build targets without changing
launch.json
Describe the solution you'd like
Each Zephyr build directory contains enough information to reconstruct the content of a Cortex-Debug
launch.json
profile. I suggest creating a new type of server. Such profile can look like:Upon launching this profile, Cortex-Debug will look into the build directory, get the needed information, and lauch the correct toolchain.
Additional context
west
stores in each build directory:{build_dir}/zephyr/runners.yaml
{build_dir}/zephyr/zephyr.elf
Side note
I would like to help on this issue. Any help on how to get started with this is apprecitated 😄.
The text was updated successfully, but these errors were encountered: