I want to lauch gdb in vscode. I want to debug my c code using gdb in vscode , but i m getting following error :
unable to start debugging unexpected gdb output from command environment cd
I have my gdb installed on wsl.
here is my lauch.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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\bin\\main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"pipeTransport": {
"pipeCwd": "",
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
"pipeArgs": ["-c"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/mnt/z": "z:\\"
}
}
]
}
I am unable to debug my program
Well, two years too late, but here we go.
From what I saw, you are using windows. I had the same problem and quickly resolved it. Apparently it's some system bug. To resolve, follow these steps:
(Tested on Windows 10)
Go to Windows Control Panel (You can do this by opening File Explorer and in the path type 'Control Panel' (without quotes) and hit Enter);
From the Control Panel, click on 'Clock and Region'.
Click Region. A new screen will open.
In the screen that opened, click on Administrative and search for the button "Change system location".
Check the option: "Beta: Use Unicode UTF-8 for world language support"
Restart the computer.
By doing this procedure, the problem will be solved.
I hope it has helped you and others who are experiencing this problem.
Related
Environment: WSL Ubuntu20.04 on Windows 10
GDB: gdb-multiarch (GNU gdb 9.2)
VSCODE version: 1.67.0
I'm trying to debug with GDB on VSCODE.
If I use command-line in Ubuntu to connect with GDB server and load symboal to my target device. It works normally.
$gdb-multiarch main
$(gdb)target remote:2331
$(gdb)load
$(gdb)c
Screenshot on Ubuntu command-line (Works normally)
However, I wanna do the same thing on VSCODE.
After modifying my launch.json file, the GDB debugger in VSCODE can only "attach" to my target device. There is no any symbol loaded. Here is my launch.json.
"configurations": [
{
"name": "GDB Launch",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/main",
"stopAtEntry": true,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"miDebuggerServerAddress": "localhost:2331"
},
}
]
Did I miss any propertey which needs to be filled in the configurations?
Thanks for any comments and helping:)
You can open logs to see what happened:
"logging": {
"moduleLoad": true,
"engineLogging": true,
"trace": true
},
There may be some configurations that affect the symbol load, such as solib-search-path, sysroot, you can check and add the configs in setupCommands
"setupCommands": [
{
"description": "Set sysroot ",
"text": "set sysroot <path_to_sysroot>"
},
{
"description": "Set solib",
"text": "set solib-search-path <path_to_solib_search_path>"
}
]
Vscode debugger didn't skip node_internals. I don't know what i'm missing here. Below is my 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": [
{
"type": "node",
"request": "launch",
"name": "Build and run Project",
"program": "${workspaceFolder}/out/code/main.js",
"preLaunchTask": "npm: build",
"sourceMaps": true,
"smartStep": true,
"env": {"NODE_PATH": "${workspaceFolder}/out"},
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js",
"/<node_internals>/**",
"**/<node_internals>/**",
"<node_internals>/internal/**",
],
"cwd": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
I tried all the possible glob patterns but debugger didn't skip the specified paths.
node and npm version
v14.16.0 and 6.14.11
code version(linux)
1.55.0
c185983a683d14c396952dd432459097bc7f757f
x64
Any help is appreciated. :-)
Windows or Linux? I've found that the skip files syntax is dependent on the platform and the / (Linux) or \ (Windows) that each requires. Also I don't believe you need the root locations for the folders e.g. /<node_internals>/
I've had success by providing both forms as I move between Windows and Linux frequently:
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"${workspaceFolder}\\node_modules\\**\\*.js",
"<node_internals>/**/*.js",
"<node_internals>\\**\\*.js",
]
I do hope there's a simpler answer out there but I have yet to find it.
I am trying to step through Postgresql code using Visual Studio Code as my IDE on Linux. I am using attach to a process config in launch.json to achieve the same. Following is the launch.json config:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "attach",
"program": "/usr/local/pgsql/bin/postgres",
"processId": 4165,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
}
]
}
When I start Debugging via the GUI, it attaches to the process. But whenever I add a breakpoint, I get the following message printed on the debug console:
Program received signal SIGINT, Interrupt.
0x00007ff5d084e31b in epoll_wait () from /lib64/libc.so.6
And fails to add the breakpoint. From the Postgres developer documentation (link) it is clear that we need to bypass the interrupts arriving at gdb by issuing the following command to gdb:
handle SIGUSR1 noprint pass
I think this command in gdb can be executed only before attaching the process for debugging. Hence when I run this command via the debug console on Visual Studio Code, I get the following error:
Unable to perform this action because the process is running.
Is there a way to instruct the Visual Studio Code debugging, to issue the "handle SIGUSR1 noprint pass" into gdb before it attaches the target process via gdb?
After more research, I found a way to achieve this using ~/.gdbinit file. This file can have commands that will be run each time gdb is run. I have the following content in it:
handle SIGUSR1 nostop noprint pass
handle SIGINT nostop noprint pass
Now what happens is since SIGINT is being overriden, every time the IDE is disconnected from the process, it has be restarted because it cannot disconnect gracefully anymore.
Consider to define these commands in section setupCommands of launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "debugging of local server",
"type": "cppdbg",
"request": "attach",
"program": "/usr/local/pgsql/bin/postgres",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "ignore SIGUSR1 signal",
"text": "handle SIGUSR1 nostop noprint pass"
}
]
}
]
}
In addition to Keshav's answer.
You may also add another command to the ~/.gdbinit file :
set auto-load safe-path /
This will tell the compiler that it can use the local .gdbinit file in your working directory.
Now you can make a separate .gdbinit for each project / directory and have them configured independently and not clutter up the global .gdbinit.
I have gdbserver attached to a process and working fine on a remote machine, port 9999. On my local machine, from command line:
$ gdb
(gdb) target remote localhost:9999
works just fine. I am trying to configure Vs Code debugger so that I can have a GDB frontend for this case. Here is my launch JSON.
"version": "0.2.0",
"configurations": [
{
"name": "GDB",
"type": "cppdbg",
"request": "attach",
"miDebuggerServerAddress": "localhost:9999",
"program": "path-to-cross-compiled-binary-with-same-debug-symbols",
"linux": {
"MIMode": "gdb",
},
}
]
There are couple of issues here. First of all, why "program"? In this case, gdb doesn't need any program name to start. Program is already running on remote, gdbserver is already attached to it. I just want gdb client to connect to port 9999. But anyways, moving on.
It wants me to give a processId. This also does not make sense, I am already attached on remote. The fun part is:
If you leave out processId, Vs Code says "unable to parse the process id"
If you specify a processId, Vs Code says "processId cannot be used with miDebuggerServerAddress"
Of course, if I am using a debugger server address, server is already attached to PID and it makes sense that processId can't be used in this case. But if I leave it out, VS Code gives the 1. error. This is cyclic in a way.
Anyone is able to attach to a remote process in VS Code C++ debugger with gdbserver address, that is my question. What is wrong with my launch file?
You need to use the "launch" request instead of "attach". I also needed to add the default "cwd" option.
"request": "launch",
"cwd": "${workspaceFolder}",
You may also need to define "additionalSOLibSearchPath".
My launch config now looks like this:
{
// 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": [
{
// "processId": "${command:pickProcess}",
"name": "(gdb) Remote Attach",
"type": "cppdbg",
"request": "launch",
"program": ".\\src\\binaryfolder\\app.nostrip",
"additionalSOLibSearchPath": "arm-none-linux-gnueabi/libc/lib;./lib;C:\\DeviceSDK\\win-2.8.15\\sdk\\toolchains\\arm-4.4.1\\arm-none-linux-gnueabi\\libc\\lib;C:\\DeviceSDK\\win-2.8.15\\sdk\\platforms\\201205\\lib",
// "processId": "${command:pickProcess}",
"MIMode": "gdb",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "C:\\DeviceSDK\\win-2.8.15\\sdk\\toolchains\\arm-4.4.1\\bin\\arm-none-linux-gnueabi-gdb.exe",
"miDebuggerServerAddress": "192.168.205.88:51000",
"miDebuggerArgs": " -ex 'handle all print nostop noignore'",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
]
},
]
}
See CppTools issue 321
I'm trying to setup visual studio code for rust to do debugging. In my launch.json file I have
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/vscode-rust-debug-example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "localcargobuildtask"
}
]
}
and in my tasks.json I have
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "localcargobuildtask",
"command": "echo hi",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Where "echo hi" is in my tasks I eventually want to have something like "cargo build" or "cargo test" or whatever. But this is just a starting step.
But when I press F5 the output I get is
> Executing task: C:\programs\VSCodeWorkspaces\RustProjects\vscode-rust-debug-example-debug-config-included\echo hi <
The terminal process terminated with exit code: 2
Terminal will be reused by tasks, press any key to close it.
Rather than running "echo" from where ever the terminal finds it (working directory first, then check global path variable like you would expect) it is actually looking for a program named "echo" in my root folder of the workspace.
How do I tell visual studio code "No I don't want you to run workspace/echo, I want you to run echo in workspace" ? Or is there another more direct way to tell visual studio code "compile this before you debug it" ?
The answer to this question How to debug Rust unit tests on Windows?
suggests that changing
"command": "cargo build",
into
"command": "cargo",
"args": [
"build"
],
in the tasks.json file works and somehow it does. Maybe the editor is configured to search the %path% for single word commands, or maybe some plugin I installed overwrote the "cargo" command. Maybe the reason echo wasn't found is because it is a terminal command, not a program. Maybe the error message was a lie and it was only reporting that it couldn't find workspacefolder\command despite checking %path%? Or maybe none of that. I have no idea. It is some pretty idiosyncratic behavior.