microsoft / microsoft/vscode-cpptools

Unable to view values for custom class object in mixed mode (Python & C++) debugging

オープン
#9,033 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

debugger help wanted
主要言語
TypeScript
スター
6.2k
フォーク
1.7k
平均マージ
14時間 46分
マージ済み PR(30日)
61

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

.vscode/launch.json、srcfile.cpp、test.pyを使用して混在するPython/C++セッションを再現し、その後 /home/MyProj/cpp から python setup.py debug_dev を実行します。(gdb) AttachPython C++ Debug の構成から開始し、C++ブレークポイントでcustom torch::jit::script::Moduleを調べます。デバッガーで受け取ったcustom-classオブジェクトの値を表示できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。