'Debugging C++ in VSCode - gdb attach fails to read the values inside custom class objects

I am working on a project that uses both Python and C++.

Here is the launch.json file:

{
    "logging": {
        "engineLogging": true
    },
    "configurations": [
        {
            "name": "Python C++ Debug",
            "type": "pythoncpp",
            "request": "launch",
            "pythonLaunchName": "Python: Current File",
            "cppAttachName": "(gdb) Attach",
            "stopAtEntry": false,
            "externalConsole": false,            
        },
        {
            "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",
            "program": "${workspaceFolder}/main_python.py",
            "console": "integratedTerminal",
            "stopOnEntry": false,
            "cwd": "${workspaceFolder}"
        }
    ]
}

When I run my project (Python file being the starting point) from main_python.py, the VSCode is able to debug and capture values in the Python memory space normally, but, the moment the control moves to the C++ part, the object somehow becomes alien to the gdb debugger. The program runs fine (does its job), however I am unable to look inside the object. The following screenshot will explain this scenario:

enter image description here

As can be seen on the Variables tab, the object is seen by GDB as some memory allocation and not the object of a class that is available (libtorch source code is available as a library while building the project)!

Kindly help me out!


UPDATE

For s̲t̲e̲p̲s̲ ̲t̲o̲ ̲r̲e̲p̲r̲o̲d̲u̲c̲e̲, kindly refer to this issue on the vscode-cpptools github repo.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source