I've been building a C++ dll which then gets loaded into another process that loads it. I've been trying to find a solution so that whenever I hit F5, it will automatically attach itself to that external process without me having to provide the processId from the list, but I haven't found any solutions specific to my language. Do anyone have a solution?
This is my current 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": "Attatch to process",
"type": "cppdbg",
"request": "attach",
"program": "D:\\myapp.exe",
"processId": "${command:pickProcess}",
"stopAtEntry": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
}
]
}
Related
I am trying to use pretty-printing for debugging C++ in VS code under a Debian configuration.
Right now vectors are displayed like that : Vector display
My launch.json file is :
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/examples/005_friction/mode_III_slip_weakening",
"args": ["dumps", "100", "100"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/examples/005_friction/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
],
}
I have also tried to add in configurations
"gdb": {
"prettyPrinting": true}
In that case, I have an error "Property gdb is not allowed". But I have gdb installed on my computer. I also have the "C/C++" extension installed in VS code.
At last, I tried to type -exec -enable-pretty-printing in the Debug console without further success.
What should I do ?
I'd like to run a configuration from launch.json when VSCode starts.
Is this possible ?
open vs Code >>> then >>> type your simple cpp program such >>> "Hello world >>> then >>> open run at the status bar at the top of VS Code >>> then >>> chose add configuration >>> then >>> your launch.json would be ready but it needs some configurations >>>> the following code has most of the configurations you need >>>
*** modify this path "miDebuggerPath": "C:\msys64\mingw64\bin\gdb.exe" with the gdb path in your computer .... good luck bro
{
// 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": []
// 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": "🔰Debug with g++🏹🧲🧲",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
//There I have got error Property keys must be doublequotedjsonc
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
In Linux, I would be able to type into the integrated terminal no problem. I'd be able to type in user input and it would output. On Windows, I cannot do that. The output shows in the Debug Console and I cannot type into that or the integrated terminal.
In the picture, I run without debugging in C++ and when I ask for an input, it hangs there and doesn't output. I've seen CodeRunner but I rather not use that.
The picture of the terminal when running.
EDIT
{
// 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": "C/C++: g++.exe build active file"
}
]
}
By default, the Debug Console which the C++ program is outputting to does not support user input. This means that typing your input in the Debug Console will not be read by the C++ program.
To solve this problem, change the line "externalConsole": false to "externalConsole": true in your launch.json file so that your C++ program can run in an external console. This way, you can enter your user input and get interpreted by the C++ program that is being debugged.
Your launch.json should now look something like:
{
// 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": true, // <-- Changed to "true" in here
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
Read more here:
How to read input when debugging in C++ in Visual Studio Code?
I am trying to create a launch.json file where I want to call gdb. Only, when I call it, it seems that I have to use 4 backslashes in filepaths in order to get it working. So I am now using hardcoded paths, but I would like to use paths coming from cmake-tools.
{
// 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": "gdb",
"args": [],
"externalConsole": true,
"stopAtEntry": true,
"windows": {
"MIMode": "gdb",
"cwd": "${workspaceRoot}",
"miDebuggerPath": "${env:QNX_HOST}\\usr\\bin\\ntox86_64-gdb.exe",
"miDebuggerServerAddress": "192.168.88.128:1234",
"launchCompleteCommand": "exec-run",
"customLaunchSetupCommands": [
{
"text": "-environment-cd ${workspaceRoot}"
},
{
"description": "Connecting to QNX pdebug",
"text": "target qnx 192.168.88.128:1234",
"ignoreFailures": false
},
{
"description": "Loading symbol table",
"text": "file ${command:cmake.launchTargetPath}", // this line is returning single backslashes and I want to replace them with four backslashes
"ignoreFailures": false
},
{
"description": "Uploading",
"text": "upload THIS\\\\FOLDER\\\\STRUCTURE\\\\IS\\\\WORKING /SOMEWHERE/ON/QNX",
"ignoreFailures": false
}
]
},
"logging": {
"engineLogging": true,
"trace": true,
"traceResponse": true
},
"targetArchitecture": "x86_64"
}
]
}
I have changed a couple of things to this script in order to get it working.
It seems that forward slashes are using as well. So you can just do "text": "upload THIS/FOLDER/STRUCTURE/IS/WORKING /SOMEWHERE/ON/QNX
${workspaceRoot} still wasn't working, but I used VS Code Power Tools to make some custom commands that can be added to your build script and you can simply call them via ${command:myCustomCommand}. Inside of those commands, you can also call other commands, like cmake.launchTargetPath and change it to forward slashes with simple javascript regex.
right now my launch.json file for debugging looks like this
{
// ${command:pickProcess}
"version": "0.2.0",
"configurations":
[{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceFolder}/devel/lib/beginner_tutorials/talker",
"processId": "619",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]}
but the things is that I need to manually update the processid every time, is that possible that for the "processId", I can invoke some kind of script and return a pid in programmatic manner?
ex.
"processId": ${shell_script: get_pid}
You can use "processId": "${command:pickRemoteProcess}", to open up a process picker so you can select it.