my current setup involves a boost-python module, that I wrote. To debug this module, I wrote a standalone C++ program that calls the python-script from within the C++ program.
int main()
{
try
{
PyImport_AppendInittab("oum_export", INIT_MODULE);
Py_Initialize();
PyObject *obj = Py_BuildValue("s", "/media/thomas/Data/seafile/Seafile/TUG/ILearnHeart/Anisotropic\\ Diffusion/python/oum_cpp_opt.py");
FILE *file = _Py_fopen_obj(obj, "r+");
if (file != NULL)
PyRun_SimpleFile(file, "D:/seafile/Seafile/TUG/ILearnHeart/Anisotropic Diffusion/python/oum_cpp_opt.py");
else
cout << "Script file to execute not found" << endl;
}
catch( p::error_already_set )
{
PyErr_Print();
}
Py_Finalize();
}
This should allow me to easily debug the callbacks made to the Python-modules, written in in C++. On invoking the vscode-debugger, the program crashes with the error
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
which is due to the fact that I'm not in the correct anaconda environment. How can I tell visual-studio code to enter the correct environment, before launching the gdb (i.e.: "source activate aniso_diff && gdb oum_export_test")?
Here's my current launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "oum_export_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build_linux",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build oum standalone"
}
]
}
I tried incorporating the activate command into the build preLaunchTask, but it seems vscode invokes a fresh shell for gdb.
This is probably a no-brainer for most of you, but I just figured out that the simplest solution is to simply activate your desired environment before invoking vscode on the same shell.
Related
While debugging like normally (before I didn't have this kind of problem) GDB returned message :
Internal error while converting character sets: No error.
Only for viewing string or char kind of variables.
I have tried to disable Windows beta UTF-8 engine, tried additional commands from here StackOverflow
Unfortunately nothing works.
Adding additional command for GDB logging I receive the same message.
1: (394137) ->1059^error,msg="Internal error while converting character sets: No error."
EDIT
As #rainbow.gekota requested, I added some more informations.
Current OS : Windows 10 21H2 (Compilation: 19044:2006)
VSCode ver. : 1.72.0 x64 -> 64bbfbf67ada9953918d72e1df2f4d8e537d340e
GDB ver. : 12.1 for MinGW-W64 x86_64, built by Brecht Sanders
GDB installed from MSYS2 repos.
Here's my launch.json with which I was trying to fix this error with set charset UTF-8
{
"version": "0.2.0",
"configurations": [
{
"name": "Start debugging",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\main.exe",
"args": ["arg1", "arg2", "arg3"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"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
},
{
"description": "Fix pretty-printing for gdb",
"text": "set charset UTF-8"
}
],
"preLaunchTask": "Build program",
"logging": { "engineLogging": true }
}
]
}
I don't have any more idea how to reproduce this error. It was working fine until one day.
Unfortunately I couldn't find any logical answer to my question. The only thing that helped was deleting MSYS2 with gdb and gcc installed and installing it once again.
Now I can't reproduce this issues so maybe in the future I'll comeback with the same error. Will see.
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've installed WSL2 and build tool and everything is working well on linux console (including a test c++ program I was able to debug with dbg).
I'm now trying to have a working development environment on my windows10 machine, by installing VSCode and a couple of extensions (c/c++ and Remote WSL).
Build works just fine, but when I try to debug, after executing (F10) a couple of lines I get the error:
Unable to open 'libc-start.c': Unable to read file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c').
From that point on debugger basically doesn't work anymore, every time I press F10 (or F11) I get a new popup with the same error
screenshot of error and dev environment
Pressing the "Create File" button results in an "Unable to write file 'vscode-remote://wsl+ubuntu-20.04...." (same file as above).
here following my 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",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
and my tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C++ Compile",
"command": "/usr/bin/g++",
"args": ["-g","*.cpp","-o","${fileDirname}/${fileBasenameNoExtension}"],
"options": {"cwd": "${workspaceFolder}"},
"problemMatcher": ["$gcc"],
"group": {"kind": "build","isDefault": true}
}
]
}
I've searched quite a bit before posting. Other have had similar problems in older posts but most of them claimed that being an old bug and they say the problem was solved with the upgrade. I'm running latest version of everything I'm using (including VSCode and the plugins).
thank you in advance to anyone helping out.
Adding
"sourceFileMap": { "//wsl$/Ubuntu-20.04" : "/" }
to the launch.json resolved the problem for me.
I'm at a bit of a loss here, I hadn't really expected this to be difficult. I usually work on Linux, but today I had some work that I needed to do and only had a Windows machine. I thought this would be no problem, I can install git for windows, clone my project, and get right to work. Its just been a huge mess. I'm really hoping someone can help me understand where I went wrong in setting all this up on Windows. It isn't something I plan to do frequently, but definitely something I want to be able to do on a Windows machine in a reasonable amount of time.
I'm using WSL and have set my default VSCode Windows integrated terminal to C:\WINDOWS\System32\bash.exe
I installed Windows 10 SDK to fix crtdbg.h include errors as a dependency against <iostream>
I installed gdb with MinGW -
I set the path environment variable
I created a 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": "(gdb) CDLL Driver",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/driver",
"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
}
]
}
]
}
My MinGW bin contains the following
I launch my debug task in VSCode and I get the following error
cmd /C "c:\Users\shaun\.vscode\extensions\ms-vscode.cpptools-0.28.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-4n4ohh2f.ibt --stdout=Microsoft-MIEngine-Out-1irudlfy.q5x --stderr=Microsoft-MIEngine-Error-fg20cagk.ynl --pid=Microsoft-MIEngine-Pid-kzdzn4p4.lro --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
Command 'cmd' not found, but there are 16 similar ones.
I can provide more information if needed. I'm really hoping I missed something simple here that would be obvious to someone who works on Windows.. Thank you in advance, I really appreciate the help!
If you are using WSL to compile the project you should not use MinGW gdb.
You need to install gdb on you Linux subsystem (using native tools like apt if you are using Ubuntu WSL), reopen your project in WSL and configure the WSL path to gdb.
I was able to successfully debug using this setup on WSL.
Replace your launch.json file with this file
{
"version": "0.2.0",
"configurations": [
{
"args": ["1"],
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
Make Sure you have installed MinGw Compiler and gdb debugger
I am trying to follow the direction from this post
Visual Studio Code redirect input on debug
but when I add the console config to the launch.json file
"console": "integratedTerminal"
it throws a "Property console is not allowed". and when I debug the program it still waits on input and never reach break point like I would if I start in shell like
"./a.out 1 test1.txt"
"./a.out 1 <test1.txt"
Full config
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${workspaceRoot}/a.out.dSYM/Contents/Resources/DWARF/a.out",
"program": "${workspaceRoot}/a.out",
"args": ["1", "<","test1.txt"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
//"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"console": "integratedTerminal"
//"preLaunchTask": //"build test1"
}
]
}
I use GDB instead of lldb but still encountered the same issue. It waited for an input when I typed arguments in the "launch.json" file this way:
"args": ["<", "test1.txt"],
But it started working properly when I had rewritten it in the following manner:
"args": ["<", "${workspaceFolder}/test1.txt"],
I think that one should add a parent folder even though the input file is in the workspace folder or simply use the full path.
If you use the integrated console, the < doesn't get interpreted by a shell. Usually, using externalConsole: true fixes the problem since this uses a shell. But if the external console doesn't work on your system for whatever reason and you're forced to use externalConsole: false, the workaround is to let GDB create the shell: miDebuggerArgs: "'-ex' 'run < /path/to/test1.txt'"