Remote debugging C++ with VsCode - visual-studio-code

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

Related

How to load symbol while debugging with GDB in VSCODE

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>"
}
]

How to run two pwa-msedge debuggers in vscode at the same time?

I have two frontend applications in my applications that need to be run in debugger mode, at the same time.
{
// 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": "pwa-msedge",
"request": "launch",
"name": "Org Admin - Edge",
"url": "http://localhost:3001",
"webRoot": "${workspaceFolder}",
"runtimeExecutable": "/usr/bin/microsoft-edge-beta"
},
{
"name": "Super Admin - Edge",
"request": "launch",
"type": "pwa-msedge",
"url": "http://localhost:3002",
"webRoot": "${workspaceFolder}",
"runtimeExecutable": "/usr/bin/microsoft-edge-beta"
},
{
"command": "npm run dev",
"name": "Start Full Application",
"request": "launch",
"type": "node-terminal"
}
]
}
This is the configuration I have so far, But I am only able to run either the Super Admin - Edge or the Org Admin - Edge at the same time. What I want is to run all of them at the same time when I launch each of them individually.
Basically, the need is to run two "pwa-msedge" instances from VSCode Debugger simultaneously.
I'm afraid what you want is impossible. One config can launch one Edge instance and you can only use one config at a time. The only thing you can do is to launch Org Admin - Edge and Super Admin - Edge one by one. Then both are running and you can debug them.

Running a gdb command before attaching it to a process via Visual Studio Code

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.

unable to start debugging unexpected gdb output from command environment cd

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.

VS Code debug in Chrome - This site can’t be reached error

I know this question has been asked before, but after reading a lot of the threads, I still haven't found my answer...
I am trying to debug a very simple html app with Chrome, but when I get to my localhost I get an error that says "This site can’t be reached". My launch.json code looks like this:
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
},
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
}
]
}
Any help would really be appreciated as I have been struggling for quite a while with this now.
As #Rob-Lourens has mentioned you need to start your own local server to host your HTML/Javascript/CSS and images.
You can use a VS code plugin Live Server to create a local development server for you. Please make sure your URL("url": "http://localhost:3000") in your configuration file matches the URL of Live Server.
If you are on Windows and want to use IIS or IIS Express you can read up on IIS and IISExpress
Just change the value in launch.Json and remove unwanted and paste the html file location in the file attribute.
{
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Open index.html",
"file": "C:\\Users\\xyz\\projects\\PracticeProjects\\jsbasics\\index.html"
}
]
}