I'm developing applications on a Cortex-M3 microcontroller (STM32 family). I'm trying to use Visual Studio Code as the debugger interface, with a ST-Link v2 JTAG probe. I managed to configure OpenOCD to talk to my device, and VSCode to run a local GDB and connect to OpenOCD.
Now I'd like to have VSCode start OpenOCD at the same time as GDB when I start debugging. I have the following launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Pipe Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/path/to/program.elf",
"stopAtEntry": false,
"cwd": "${workspaceFolder}/gcc-arm-none-eabi",
"environment": [],
"externalConsole": true,
"pipeTransport": {
"pipeProgram": "X:\\path\\to\\openocd-0.10.0\\bin-x64\\openocd.exe",
"pipeArgs": ["-f", "vscode.ocd"],
"pipeCwd": "${workspaceFolder}"
},
"MIMode": "gdb"
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}/gcc-arm-none-eabi",
"program": "${workspaceFolder}/path/to/program.elf",
"MIMode": "gdb",
"targetArchitecture": "arm",
"miDebuggerPath": "X:\\path\\to\\gcc-arm-none-eabi-4_8-2014q2-20140609-win32\\bin\\arm-none-eabi-gdb.exe",
"miDebuggerServerAddress": "127.0.0.1:3333"
}
]
}
And my vscode.ocd file is as follow:
source [find interface/stlink-v2.cfg]
transport select "hla_swd"
source stm32l1.cfg
stm32l1.cpu configure -event gdb-attach halt
stm32l1.cpu configure -event gdb-detach resume
gdb_port pipe
log_output openocd.log
When I start OpenOCD manually (without "gdb_port pipe") and then run the configuration "(gdb) Attach", all is fine.
But when I run the "(gdb) Pipe Launch" configuration, VSCode starts openocd.exe, and then nothing happens. When I kill the openocd.exe process, I get a popup in VSCode which says "Unable to start debugging. Unable to establish a connection to GDB. The following message was written to stderr:" followed by some OpenOCD stderr.
I can also run GDB on its own in the command line with the following .gdbinit just fine:
target remote | openocd -f path/tovscode.ocd
sym path/to/program.elf
So my question is is there a way to have VSCode talk to OpenOCD's GDB server directly? Otherwise if I need to use some local arm-none-eabi-gdb.exe file, how can I configure VSCode to have it tell GDB to use a pipe ("target remote | something") remote?
Related
I would like to use the integrated terminal for debugging C++ files in VSCode on my Mac. I have the C/C++ extension added and enabled globally.
Here is the launch.json that I am using:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
I have tried adding "console": "integratedTerminal" to this with no change. When debugging a program, the terminal output says:
> Executing task: /usr/bin/clang++ -fdiagnostics-color=always -std=c++17 -g /Users/kris/learncpp/chapter_03/debugTest4.cpp -o /Users/kris/learncpp/chapter_03/debugTest4 <
Terminal will be reused by tasks, press any key to close it.
Hitting any key here closes the terminal and drops me into a bash shell. Is there another setting I am missing somewhere?
the C/C++ Extension of Microsoft for VSCode allows to set a launch.json file with which you can set how to debug and run your C++ code. By default it has lldb as debugger for MacOS.
I wonder how to set gdb as debugger instead of lldb.
I tried and it shows me:
Unable to start debugging. GDB exited unexpectedly with exit code 134 (0x86).
This is how my launch.json file looks like:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++-9 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"osx": {
"miDebuggerPath": "/usr/local/bin/gdb",
"MIMode": "gdb"
},
"preLaunchTask": "C/C++: g++-9 build active file"
}
]
}
Make sure you have gdb installed.
For that you can use:
brew install gdb
Then make the gdb binary is certified. Because:
... modern Darwin kernels restrict the capability to assume
control over another process (here, for the purpose of debugging it),
since that capability is a boon to malware. In order for said
taskgated to grant access to gdb, the latter must be fitted with
entitlements, which consist of digitally-signed metadata inside the
gdb binary.
From: https://sourceware.org/gdb/wiki/PermissionsDarwin
To create a certification follow these instructions:
https://sourceware.org/gdb/wiki/PermissionsDarwin
After doing so, certify the binary as instructed here.
Then try this for launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
I want to debug a C++ program with VSCode, but I run my program with a bash script.
I tried this:
{
"name": "Run",
"type": "cppdbg",
"request": "launch",
"program": "/bin/bash",
"stopAtEntry": false,
"args": ["-ic" , "run_script"],
},
But I receive
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
And the debugger doesn't connect (though the program is running).
I know there's tasks.json for scripts but I want to debug the C++ program invoked from the script.
Is it possible?
I have the following setup in my launch.json file to debug native code compiled from c++ using clang. I am able to use lldb on the command line and debug it, including setting breakpoints. But when I try setting a breakpoint using Visual Studio Code, I get the error message:
Unable to open 'foo.cc': no provider for .///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////tests/foo/foo.cc.
{
"name": "(lldb) test",
"type": "cppdbg",
"request": "launch",
"program": "./prog-test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": false,
"MIMode": "lldb"
}
On the lldb prompt, I simply run breakpoint set -f foo.cc -n 18 and it works.
I am guessing this is something about the path to the file in VS Code. But changing the working directory around did not help. It is currently set to the directory from which lldb on the commandline works.
Any ideas would be appreciated!
I am using:
Ubuntu 16.04 (I know it is not supported officially)
Latest VSCode version
Latest "C/C++ for VSCode" version
My project is a C++ project and the structure looks like this:
/home/lvier/mainProject/fooProject (source code)
/home/lvier/mainProject/build/fooProject (binaries)
I am working in the sub-project "/home/lvier/mainProject/fooProject" and in "/home/lvier/mainProject/build/fooProject" there are many sub programs (lets say "foo", "foo_sub1", "foo_sub2" ...).
My goal:
I want to start the program "foo" (which starts all other foo_sub-programs) and then, I want to debug a certain sub program (let's say "foo_sub1") by attaching to it. I am also fine with starting and debugging in the same time as long as I can debug the sub-program "foo_sub1". The main project itself does not contain any executables.
Some months ago, debugging was working with "attach". For me it is not working anymore (because of VSCode updates and/or C/C++ extension updates). Here are my problems:
Assume that "foo" is running.
When using the "C++ Attach"-config and setting "request": "attach" (which is getting highlighted as "not an accepted value"), it will ask for the property "processId" if it is not set. If I set "processId", the error "Attach not supported" pops up.
If I use the "C++ Attach"-config with "request": "launch" (in the beginning this was autogenerated by the C/C++-extension), then the program finds the process id, tries to attach but then aborts with the message "Unable to start debugging. Commands are only accepted when the process is stopped." - what a surprise.
Assume that "foo" is not running yet.
When using the "C++ Launch"-config, the program starts but no UI elements appear. Instead, it starts with a new terminal popping up which says "warning gdb failed to set controlling terminal operation not permitted" for a brief moment and in the internal console of VSCode, it states that it stops at a certain line of code (a breakpoint not defined by me) and prints
"Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1"."
From there I can't continue further and I have to manually terminate the program.
When I use GDB without VSCode, i.e. just by native terminal, my program is starting properly but with VSCode, there seem to be some issues currently.
This is my current, autogenerated config where I only edited the "cwd" and "program" paths (assume that the environment variable "${env.build_foo}" is set to "/home/lvier/mainProject/build/fooProject"):
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${env.build_foo}/foo",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
{
"name": "C++ Attach",
"type": "cppdbg",
"targetArchitecture": "x64",
"request": "launch", // <-- "attach" is not allowed (anymore)! :(
"program": "${env.build_foo}/foo_sub1",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"processId": "${command.pickProcess}",
"externalConsole": false,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
}
]
}
So far I am really frustrated and still don't want to give up on VSCode (I don't want to switch to another IDE yet). I have searched a lot for other issues and also tried to set some other config-properties but none of it helped.
Does anyone else also have such issues with the debugger or is this a general problem with the extension (... and Ubuntu 16.04)?
I am happy for any help or convenient workaround. Thanks in advance!
Note:
I have also created a thread on the related github page (see https://github.com/Microsoft/vscppsamples/issues/115)
Update 07/26/2016:
It seems like there is a bug with the C/C++ extension (see comments in the github link above). It is still being investigated though.
Here solution:
...Debugging works for me now after I removed the GCC -s flag (strip symbol table and relocation information) from the linker settings...
Got it from last answer of the next link (thanks HorstBaerbel):
https://github.com/Microsoft/vscode-cpptools/issues/115#issuecomment-299334301