microsoft / microsoft/vscode-cpptools
Unable to view values for custom class object in mixed mode (Python & C++) debugging
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 6.2k
- Forks
- 1.7k
- Ø Merge
- 14 Std. 46 Min.
- Gemergte PRs (30 T.)
- 61
Beschreibung
Bug type: Debugger
Describe the bug
- OS and Version: Ubuntu 18.04.5 LTS (on Remote)
- VS Code Version: 1.65.2 (Running on Windows 10, but, connected to remote server via MS Remote - SSH extension)
- C/C++ Extension Version: v1.8.4
- Other extensions you installed: MS Python v2022.2.1924087327; BeniBenj Python C++ Debugger v0.2.15
- A clear and concise description of what the bug is:
When debugging a mixed language application I am using the launch.json file as shown below to debug both Python and C++. The problem is, when the control reaches the C++ code (via gdb attach), the debugger is not able to "look inside" the object received from the Python code. All relevant libraries and header files have been included.
To Reproduce
Create the following directory structure:
|-- home
| |-- .vscode
| | `-- launch.json
| |-- MyProj
| | |-- cpp
| | | |-- build
| | | |-- include
| | | | `-- srcfile.h
| | | |-- libs
| | | | `-- libtorch
| | | |-- source
| | | | `-- srcfile.cpp
| | | |-- setup.py
| | | `-- setup.cfg
| | `-- __init__.py
| `-- test.py
launch.json
{
"logging": {
"engineLogging": true
},
"configurations": [
{
"name": "Python C++ Debug",
"type": "pythoncpp",
"request": "launch",
"pythonLaunchName": "Python: Current File",
"cppAttachName": "(gdb) Attach",
"stopAtEntry": false,
"externalConsole": false,
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"args": [],
"program": "/root/anaconda3/envs/py39env/bin/python",
"processId": "${command:pickProcess}",
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set print elements 0"
}
],
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"python": "/root/anaconda3/envs/py39env/bin/python",
"program": "${workspaceFolder}/test.py",
"console": "integratedTerminal",
"stopOnEntry": false,
"cwd": "${workspaceFolder}"
}
]
}
srcfile.h
#ifndef _SRCFILE_H
#define _SRCFILE_H
#include <torch/script.h>
#include <torch/torch.h>
#include <torch/extension.h>
#include <pybind11/pybind11.h>
#include <iostream>
#include <memory>
int test(torch::jit::script::Module);
#endif
srcfile.cpp
#include <srcfile.h>
int test(torch::jit::script::Module mod) {
std::cout<<"Received data"<<std::endl;
int blah = 1;
return blah;
}
PYBIND11_MODULE(srcfile, m) {
m.doc() = "dummy function"; // optional module docstring
m.def("test", &test, "dummy function");
}
setup.cfg
[build_ext]
debug = 1
[aliases]
release_install = build_ext install
debug_install = build_ext --debug install
debug_dev = build_ext --debug develop
setup.py
from setuptools import setup, Extension
from torch.utils import cpp_extension
import os
os.environ["MAX_JOBS"] = "6"
cpp_module = cpp_extension.CppExtension('srcfile',
sources = ['src/srcfile.cpp'],
library_dirs = ['/home/MyProj/cpp/libs/libtorch'],
include_dirs = [
'/home/MyProj/cpp/include',
'/home/MyProj/cpp/libs/libtorch/include',
'/home/MyProj/cpp/libs/libtorch/include/torch/csrc/api/include',
],
extra_compile_args=['-ggdb']
)
setup(
name = 'srcfile',
author = 'Anurag',
ext_modules = [cpp_module],
cmdclass = {'build_ext':cpp_extension.BuildExtension}
)
test.py
import torch
import torch.nn as nn
from MyProj.cpp import srcfile as j
device = torch.device('cpu')
class Dummy(nn.Module):
def __init__(self):
super(Dummy, self).__init__()
self.conv = nn.Conv2d(in_channels=3, out_channels=1, kernel_size=2, stride=1, padding=0, bias=False)
self.flat = nn.Flatten(start_dim=1, end_dim=-1)
self.lin = nn.Linear(in_features=81, out_features=5, bias=False)
def forward(self, x):
x = self.conv(x)
x = self.flat(x)
x = self.lin(x)
return x
def main():
net = Dummy()
#x = torch.randn(10,10,3, dtype=torch.float16)
scr = torch.jit.script(net)
print(j.test(scr._c))
blah = 1
if __name__ == '__main__':
main()
Now goto the directory: /home/MyProj/cpp and run the command: python setup.py debug_dev
After this, go to the debug panel and launch the debug configuration. Set breakpoints at the blah = 1 statement of both the languages.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere die gemischte Python/C++-Sitzung mit .vscode/launch.json, srcfile.cpp und test.py und führe anschließend python setup.py debug_dev aus /home/MyProj/cpp aus. Beginne mit den Konfigurationen (gdb) Attach und Python C++ Debug und untersuche das benutzerdefinierte torch::jit::script::Module am C++-Breakpoint. Als erledigt gilt die Aufgabe, wenn der Debugger die Werte des empfangenen Objekts der benutzerdefinierten Klasse anzeigen kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp, python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100