GDB is no longer hitting breakpoints in VS Code within docker container - docker

Once I had set launch.json and I ran gdb and debugged in my code successfully until something happened and all breakpoint became "gray" with the such message:
"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."
However, debugger attaches to running program and I even can make steps from main, but still breakpoint are not hit... This is C++ project that is built with cmake with gcc with -DCMAKE_BUILD_TYPE=DEBUG flag.
launch.json is 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": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./MyProject/project",
"args": [],
"stopAtEntry": false,
"cwd": "/home/AA/workspace",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerServerAddress": "/*Cannot write here, but it's fine*/",
"sourceFileMap": {/*Cannot write here, but it*/}
},
]
}
How do I fix this problem?

I was looking for an answer in other resources and the most solutions say that you should -g option if you compiler a project with gcc. It wasn't my case because I use cmake but I had one detail that I debugged code that was run in docker.
When you work with files in VS code from your user and docker runs project from another user, you should add the option "sourceFileMap": {} in launch.json:
"sourceFileMap": {
"/home/user/project/file.hpp" : "/home/YourNameBeyondDocker/project/file.hpp",
...
I added wrong path in this option. When I took it out, my debugger finally started hitting breakpoints!

Related

VScode remote containter debug unable to find malloc.c

I have been trying to debug C++ code via VScode on a remote docker container. While this is working for 2 of my other college's it isn't for me. We both use the same docker image. So I suspect it's something in my VScode, but what I do not know.
I get the following error when debugging the source code.
Unable to open 'malloc.c': Unable to read file 'vscode-remote://attached-container+7b22636f6e7461696e65724e616d65223a222f637070616e74227d/build/glibc-S9d2JN/glibc-2.27/malloc/malloc.c' (Error: Unable to resolve non-existing file 'vscode-remote://attached-container+7b22636f6e7461696e65724e616d65223a222f637070616e74227d/build/glibc-S9d2JN/glibc-2.27/malloc/malloc.c').
I can "fix" this by extracting glibc in /build/, but I would rather have it fix forever and not have the same issue with another docker container (possible). Glibc is installed in the Docker container at /usr/src/glibc. I found it by running find / -iname glibc.
To run the application from VScode on the remote docker container, I use this launch.json file:
{
// 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 Program",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/src/application",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/src",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Not sure if this information is necessary but it cant do harm.
host: Windows 10
docker container: ubuntu 18:04
visual studio code version: 1.55.0
Hopefully, this is enough information to resolve the issue I'm facing.

using OpenCV in VS code

I'm writing a simple program using VS Code, Mingw and OpenCv Lib. I downloaded a prebuild OpenCV package from here and I followed the instruction in this page for building the code. I can build the program successfully with no error but there is a problem. when I call OpenCV function(like cv::imread) an segmentation fault occurs. It will be appreciated for any kind of help.
task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\mingw\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"${workspaceFolder}/utils.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-IC:\\OpenCV\\include",
"-LC:\\OpenCV\\x64\\mingw\\bin",
"-llibopencv_calib3d341",
"-llibopencv_core341",
"-llibopencv_dnn341",
"-llibopencv_features2d341",
"-llibopencv_flann341",
"-llibopencv_highgui341",
"-llibopencv_imgcodecs341",
"-llibopencv_imgproc341",
"-llibopencv_ml341",
"-llibopencv_objdetect341",
"-llibopencv_photo341",
"-llibopencv_shape341",
"-llibopencv_stitching341",
"-llibopencv_superres341",
"-llibopencv_video341",
"-llibopencv_videoio341",
"-llibopencv_videostab341"
],
"options": {
"cwd": "C:\\mingw\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\mingw\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\mingw\\mingw64\\bin"
}
}
]
}
c_cpp_properties.json
{
"configurations": [{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/OpenCV/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "C:\\mingw\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}],
"version": 4
}
Is this on Windows? If so I don't think the issue is with your VS Code files if you're only facing problems after build. You may want to check your opencv or mingw-w64 installation, did you build and install with cmake? For Mingw64, was your install configuration correct for your machine?
Assuming of course that everything has also been added to your Windows path environment variable, I tested your cpp_properties.json and tasks.json setup with my own opencv windows vs code environment. The only things I did differently were to get rid of include errors, such as:
"problemMatcher": {
"base": "$gcc",
"fileLocation": [
"absolute"
]
},
"group": {
"kind":"build",
"isDefault": true
}
To my tasks.json problemMatcher statement and group statement so that the system could properly find the opencv library. I also don't know what the "${workspaceFolder}/utils.cpp" line is doing in tasks.json, but regardless, if you're able to build fine it would seem to me there's more likely an underlying problem with either mingw or opencv.

How to make problems tab show build warnings when building via ssh

On my linux VM I have set up a docker container to build and debug my vs code C++ project via an ssh connection. Building works inside the container as well as running and debugging with breakpoints. I am stuck on how to redirect stdout to the Output and Problems tabs so i can see warnings generated from the build and then navigate to the affected files. Instead it just outputs the build to a terminal window.
The project is located in a docker volume in the location:
/var/snap/docker/common/var-lib-docker/volumes/vol-tom-2/_data/My-Project
And inside the container it is located in:
/home/buildmaster/workspace/My-Project
For debugging i have modified the launch.json file so that when setting breakpoints it matches up the files in the project to the ones in the container, by adding this line:
"sourceFileMap": {
"/home/user/workspace": "/var/snap/docker/common/var-lib-docker/volumes/vol-tom-2/_data/"
},
I would like to find something similar in tasks.json so that it can sync up my local vs code project with the warnings and errors generated from the build inside the container.
Below is my tasks.json file, thanks in advance if any one has any idea how to solve this!
{
"version": "2.0.0",
"command": "/bin/sh",
"args": ["-c"],
"reveal": "always",
"tasks": [
{
"args": [
"user#localhost",
"-p",
"32772",
"/home/build-scripts/build-script.sh"
],
"label": "build",
"command": "ssh",
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^\/host\/(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
}
]
}

How do I set up the visual studio code launch.json file to debug F#?

How do I set up the debugger in launch.json?
Currently, I have
{
"version": "0.1.0",
"configurations": [
{
// Name of configuration
// Appears in the launch configuration drop down menu.
"name": "Launch Lukecxu",
"request": "launch",
"cwd": "/Users/lukexu/lukecxu",
"type": "node",
// Automatically stop program after launch.
"stopOnEntry": true,
"program": "${workspaceRoot}"
}
]
}
I found some of this online but it's not working. It said I should have "type" as mono but when I set it has mono it said type not supported.
For my system settings I did brew install mono and I also have ionide installed.
Right now I can't click the gutter to set any break points and when I hit F5 it says "Cannot launch program '/Users/lukexu/lukecxu'; configuring source maps might help."
Is there a tutorial to set up F# debugger in VSCode?
I think that you need to install mono debug extension
After you've installed extension following configuration should work:
{
"version": "0.1.0",
"configurations": [
{
// optional "preLaunchTask": "Build" - some way of building your application.
"externalConsole": true,
"name": "Launch",
"type": "mono",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}/bin/myapp/myapp.exe",
"stopOnEntry": true
},
{
"name": "Attach",
"request": "attach",
"type": "mono",
"address": "localhost",
"port": 55555
}
]
}

How do I use ${workspaceRoot} for my Electron app in Visual Studio Code?

I have an Electron app that I was able to debug in Visual Studio Code. After I upgraded to version 0.10.8 it will no longer run.
I am getting the error message below in my launch.json file:
Relative paths will no longer be automatically converted to absolute ones. Consider using ${workspaceRoot} as a prefix.
Absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
Here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "My First Electron App",
"type": "node",
"request": "launch",
"program": "$(workspaceRoot}/app/main.js", //ERROR
"stopOnEntry": false,
"args": [],
"cwd": "$(workspaceRoot}",
"runtimeExecutable": "$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron", //ERROR
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858
}
]
}
I am getting the green squiggly line mentioned for the two lines with //ERROR at the end.
I saw this article, but honestly was familiar with VS Code enough to understand how this should be implemented: https://code.visualstudio.com/Docs/editor/tasks#_variable-substitution
UPDATE
I replaced the value for "cwd" with "${workspaceRoot}" as recommended by Isidor. The green squiggly line went away.
I updated the error message that I am still seeing on the other two lines.
When I hit F5 I get this error message:
request 'launch': runtime executable '/private/var/git/electron-vs-code/$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron' does not exist
There is a typo in your json. Change the parenthesis after the $ in $(workspaceRoot} to a curly brace. This should at least fix the warning.
Even though you are getting the relative path warning VSCode still automatically converts relative to absolute paths in 0.10.8. To get rid of the warnings for "cwd", instead of "." please put "${workspaceRoot}".
What happens when you run try to debug your electron app, do you see some other error, since the relative to absolute can not be the true cause of this. If you command palette / open developper tools -> do you see some error in the console?

Resources