How to load symbol while debugging with GDB in VSCODE - visual-studio-code

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

Related

Start GDB using command line via VSCode launch.json

I'm using GDB to debug a QEMU program using vscode. The GDB server is started by a make command, via a task in tasks.json:
"tasks": [
{
"label": "ARMCM33_GDBServer",
"type": "shell",
"command": "make gdbserver",
"isBackground": true
}
]
Where my makefile looks a bit like this:
gdbserver: $(BINARY)
#$(QEMU_PATH) \
-machine $(MACHINE_NAME) \
-kernel $(BUILD_DIR)/kernel.elf \
-S -gdb tcp::4321
gdb: $(BINARY)
$(GDB) $(BINARY) -ex "target remote:4321"
My launch.json looks a bit like this:
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "Debug",
"miDebuggerPath": "/bin/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-gdb",
"program": "build/ARMCM33/kernel.elf",
"args": ["ex"],
"miDebuggerServerAddress": "localhost:4321",
"preLaunchTask": "ARMCM33_GDBServer",
],
},
This all works well in vscode. However, the problem is I want vscode to use my Makefile gdb call, rather than having to duplicate parameters in the launch.json (e.g. like the TCP address, GDB path). Having browsed the launch.json docs, I can't immediately see a solution.
So, how do I use my gdb command line command to use GDB in vscode?

Vscode debug error for Deno application: Could not connect to debug target at

I am following deno course on Pluralsight (Deno: Getting Started). I am on debugging module. When I try to start the debugger, I am getting this error message on vscode:
This is my launch settings:
{
"name": "Launch Deno",
"request": "launch",
"type": "pwa-node",
"program": "affiliate_data_server.ts",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect",
"--allow-all"
],
"attachSimplePort": 8888
},
Debug console gives only this output:
C:\Users\kara\.deno\bin\deno.exe run --inspect --allow-all affiliate_data_server.ts
Sometimes, when I click to cancel, application still listens on the port, so i have to kill the process manually.
When i try this config instead;
{
"name": "Node Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": ["run", "--inspect", "-A", "affiliate_data_server.ts"],
"port": 9229
},
It starts the server but breakpoints are not working.
What would be the solution?
I have solved the issue by downgrading the Deno to version 1.6.1 with
deno upgrade --version 1.6.1
Source: Github
You can use --inspect-brk instead of --inspect so it will break on the first line of the program.

Remote debugging C++ with VsCode

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

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.

Visual Studio Code Task is Prepending the working directory to the command

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.