I am trying to debug a C++ application running inside a docker container with VSCode. I followed the below-mentioned steps to do that
Installed C/C++ and Remote-Containers extension in VSCode
Connected VSCode to the docker container
Added the below C/C++: (gdb) Attach configuration in launch.json
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/usr/local/bin/myfeature",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"additionalSOLibSearchPath": "/usr/local/bin/myfeature.dbg",
"sourceFileMap":{
"<source-path>": "/usr/local/src/test/av/"
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
When I start debugging the breakpoints in the file myclass.cc are disabled and show status as "Module containing this breakpoint has not been loaded yet...."
I am not very familiar with gdb but when I run this command from the command line
gdb /usr/local/bin/myfeature
I get this
Reading symbols from /usr/local/bin/myfeature...
Reading symbols from /usr/local/bin/myfeature.dbg...
Then I am able to add breakpoint using
break myclass.cc:15
If gdb is able to read symbols and add breakpoint then why is VSCode not able to do that? What am I doing wrong here?
Thank you
Related
Environment
Ubuntu 20.04.
VS Code 1.69.0 with extensions
VS Code launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Test debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/bazel-bin/app/mp_test",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
Note: I use bazel to build mediapipe and my app. Do not know if it matters or not.
bazel build --copt="-g" --strip="never" --define MEDIAPIPE_DISABLE_GPU=1 //app:mp_test
Problem description
I have a code:
mediapipe::CalculatorGraph graph;
graph.Initialize(config);
I set breakpoints on the second line. Start debugging. After F11 (step into) execution cursor stands on the line. I repeated several time F11 and at the end it goes into some standard library code (unique_ptr exactly). I tried to use Stack Trace and double click on one of its entries. Look at the screenshot. So, debugger cann't open the source file, because it looks into /proc/self/cwd/external folder which doesn't exists. Meanwhile IntelliSence can find the definition of the mediapipe::CalculatorGraph::Initialize in mediapipe project directory and my app was built successfully, means that compiler (linker) found everything. Why? How can I fix it?
Note: Folder /proc/self/cwd/ contains files from my app folder (BUILD, main.cpp, ...).
I'm currently developing a (simple) kernel using Qemu for i368.
I was using a normal makefile and had debugging via GDB into Qemu working perfeclty
The I moved to CMake and for some reason I can only hit breakpoints when my code is already in a breakpoint.
I also can't pause, the feedback I get from the debug window is the pause was succesful
When setting a breakpoint it tells me Attempting to bind the breakpoint
A hint may be that when I stop the debug session, I get a popup from vscode saying timeout
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": [
{
"name": "Launch with GDB",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"cwd": "${workspaceRoot}",
"args": [],
"targetArchitecture": "x86",
"MIMode": "gdb",
"miDebuggerPath": "/bin/gdb",
"miDebuggerArgs": "",
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
},
"customLaunchSetupCommands": [
{
"text": "target remote localhost:1234",
"description": "Connect to QEMU remote debugger"
}
],
"setupCommands": [
{
"text": "file ${command:cmake.launchTargetPath}",
"description": "Load binary."
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
}
]
}
Pause response
<-- C (pause-67): {"command":"pause","arguments":{"threadId":1},"type":"request","seq":67}
--> R (pause-67): {"type":"response","request_seq":67,"success":true,"command":"pause","body":{},"seq":1321}
Response when setting a breakpoint:
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (340258) Send Event AD7BreakpointErrorEvent\n"},"seq":1327}
1: (340258) Send Event AD7BreakpointErrorEvent
--> R (setBreakpoints-69): {"type":"response","request_seq":69,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":4,"verified":true,"line":73}]},"seq":1329}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":4,"verified":false,"message":"Attempting to bind the breakpoint....","line":73}},"seq":1331}
If I type stop in Qemu terminal then vscode stops and I can set breakpoints again.
I have the same issue and still haven't solved yet.
But I found something maybe useful for you.
according to their discussion under this issue: https://github.com/Microsoft/vscode-cpptools/issues/833
you can try
set target-async to off for your debugger:
"setupCommands": [
{
"text": "set target-async off"
}
send SIGINT to your local debugger process
-exec -interpreter-exec console "signal 2"
to see if it can pause or not.
I meet the similar issue, try to connect remote target with option ""MIDebuggerServerAddress": "targetIp:port", not command in customLaunchSetupCommands.
I was following the documentation on https://code.visualstudio.com/docs/cpp/config-mingw to set up my C++ development environment on VS code.
I succesfully created my build task and ran my build task, but when i tried to set up my debugger (GDB debugger), i got the following output on the terminal.
C:\Users\Ayon\c++\helloworld> cmd /C "c:\Users\Ayon\.vscode\extensions\ms-vscode.cpptools-0.28.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-shlwrnf5.x12 --stdout=Microsoft-MIEngine-Out-vg12hskh.c52 --stderr=Microsoft-MIEngine-Error-nrcvh0zz.0u0 --pid=Microsoft-MIEngine-Pid-m1nmxyvs.qk2 --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Im curious as to how the "cmd /" came about in the output. Please help me fix this error.
Thanks in advance.
For reference, here 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": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
Did you add mingw64/bin to your system path? Here's how to do so:
Control panel -> Edit path -> Environment variables -> Path -> New
You can also find more guidance on
vscode official website.
I believe the problem is with the MinGW installation. I also faced this problem for a long time, solved it by doing the following:
Completely removing the current MinGW Video tutorial
Installing MinGW-w64 from the site mentioned in vscode documentation. installation video tutorial
After this, I followed the configuration mentioned in this video. The video is for c code, but you can make the required changes to c++ code. Now I'm able to debug in vscode.
By this way, you will also be able to use the latest versions of gdb and g++ available.
We are developing a Win64 DLL using the GCC toolchain (MinGW-w64) in version 9.2.0. As IDE we use VisualStudio Code (version 1.47.3) with the C/C++ IntelliSense, debugging, and code browsing plugin from Microsoft (version 0.30.0).
Unfortunately, we cannot set any breakpoints inside our DLL.
The situation is the same if we attach the DLL within our TestApplication statical or dynamical by using LoadLibrary.
Starting the GDB as a console process allows us to set a breakpoint in the DLL and stop at that line, but we miss the convenience of the IDE. I assume there is an issue in the configuration of the VSCode project or within the C/C++ plugin.
We use the following launch.json file:
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/Win64/TestApplication.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "${workspaceFolder}/minGW-w64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build-all",
"avoidWindowsConsoleRedirection": true,
"logging": {
"trace": false,
"traceResponse": false,
"engineLogging": true
}
}
]
}
Update: 17-Aug-2020:
The reason is the missing symbols from the DLL, which cannot be loaded.
Even if I try to load the symbol file for the DLL while the debugger is starting, it always removes these symbols when loading the host application. The only workaround that I have found is to manually reload the symbol file within a first breakpoint that I can only enter by its address.
Is anybody able to debug a Win64 DLL with the same toolchain?
I'm trying to remote debug a c++ app from a VM ubuntu 16.04 amd64 host to a debian armbian target of cubietruck board (ARM® Cortex™-A7 Dual-Core) via vs code.
I have follwed this guide https://medium.com/#spe_/debugging-c-c-programs-remotely-using-visual-studio-code-and-gdbserver-559d3434fb78 with the only addition of the field
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
so the whole launch.json has become
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "/home/user/ARM/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"program": "/home/user/myproject/bin/app",
"miDebuggerServerAddress": "localhost:9091",
"args": [],
"stopAtEntry": false,
"cwd": "/home/user/myproject",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "gdb"
},
"windows": {
"MIMode": "gdb"
}
}
]
}
in launch.json file so as to support pretty printer.
In the host I'm using the linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf gdb while the gdb in arm board has the native 8.0.1 gdb.
Everything works fine except from the pretty printer since the strings are not shown correctly. Whenever I hover over a string the fields npos and _M_dataplus pop up and one should open the _M_dataplus filed to see the actual string.
In host the linaro gdb supports pretty-printer since the command info pretty-printer gives the output :
builtin
mpx_bound128
However when I give the same command in target gdb 8.0.1, I get:
Undefined info command: "pretty-printer". Try "help info".
I also created a .gdbinit file in my host home folder that contains the enable pretty-printer command. I saw in the debug console that it was executed successfully but the result was erroneous as well.
Since I am pretty novice in remote debugging, what should I do to get the pretty-printer working. Should I install pretty-printer in the remote board as well or am I doing something else wrong?
1.make sure your bin is NOT built with -static-libstdc++
2.if you have to use -static-libstdc++, please add the following in your ~/.gdbinit:
python sys.path.append('/usr/share/gdb/python') <--provided by gdb `show configuration: --with-gdb-datadir=`
python sys.path.append("/usr/share/gcc-8/python/") <--corresponding to your gcc version
source /usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25-gdb.py <--this script is for std::string/list/map/etc pretty-printing.
3.edit your launch.json:
"setupCommands": [
{ "text": "-interpreter-exec console \"set sysroot /\"", "ignoreFailures": true },
{ "text": "-enable-pretty-printing", "ignoreFailures": true },
],
This is what I did to resolve the same issue occured to me. Hope this would resolve your issue.
ref1: http://tomszilagyi.github.io/2018/03/Remote-gdb-with-stl-pp
ref2: http://transit.iut2.upmf-grenoble.fr/doc/gdb-doc/html/gdb/Writing-a-Pretty_002dPrinter.html
ref3: Import Error: No module name libstdcxx