4

I am trying to enable pretty printing for C++ in Visual Studio Code using MinGW GDB python debugger.

I followed steps described here under the "This is for MinGW users with Eclipse CDT" heading, but when I try to start the debugger with "externalConsole": true I get the following logging output in the debug console:

1: (189) LaunchOptions{"name":"g++.exe - Build and debug active file","type":"cppdbg","request":"launch","program":"c:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges\\movie.exe","args":[],"stopAtEntry":false,"cwd":"C:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges","environment":[],"externalConsole":true,"MIMode":"gdb","miDebuggerPath":"C:\\MinGW\\bin\\gdb-python27.exe","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"C/C++: g++.exe build active file","logging":{"engineLogging":true},"__configurationTarget":5,"__sessionId":"c62bc9d3-8c55-4dfb-b413-c91d22f3232e"}
1: (315) Starting: "C:\MinGW\bin\gdb-python27.exe" --interpreter=mi -x "C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges\.gdbinit"
1: (328) DebuggerPid=11376
1: (391) "C:\MinGW\bin\gdb-python27.exe" exited with code -1073741515 (0xC0000135).
Starting: "C:\MinGW\bin\gdb-python27.exe" --interpreter=mi -x "C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges\.gdbinit"
"C:\MinGW\bin\gdb-python27.exe" exited with code -1073741515 (0xC0000135).

1: (407) Send Event AD7MessageEvent
1: (408) <-logout

I tried setting "externalConsole": false, and I get this output to the debug console:

1: (123) LaunchOptions{"name":"g++.exe - Build and debug active file","type":"cppdbg","request":"launch","program":"c:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges\\movie.exe","args":[],"stopAtEntry":false,"cwd":"C:\\Users\\Ben Wilson\\Documents\\Scripts\\CodingChallenges","environment":[],"externalConsole":false,"MIMode":"gdb","miDebuggerPath":"C:\\MinGW\\bin\\gdb-python27.exe","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true}],"preLaunchTask":"C/C++: g++.exe build active file","logging":{"engineLogging":true},"__configurationTarget":5,"__sessionId":"cfbd8955-0807-495d-8bfa-e06052797523"}
1: (225) Wait for connection completion.

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": "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-python27.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file",
            "logging": { "engineLogging": true }
        }
    ]
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

Also, running the gdb-python27 executable separately doesnt seem to do anything (unsure if this is expected behaviour)

C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges>C:\MinGW\bin\gdb-python27.exe

C:\Users\Ben Wilson\Documents\Scripts\CodingChallenges>

Has anyone experienced this before or know what to do here?

Soutcast
  • 91
  • 2
  • 7

2 Answers2

4

Solution

Fixed issue by:

  1. Uninstalling mingw and installing mingw64 from this link
  2. Modifying miDebuggerPath in launch.json and command and cwd in tasks.json to match new file locations
  3. Adding new mingw64 bin location to PATH
  4. Modifying includePath and compilerPath in c_cpp_properties.json to match new file locations
Soutcast
  • 91
  • 2
  • 7
4

I've encountered the same issue. My environments:

  • Local/Remote: Ubuntu 18.04 Desktop/Server
  • VSCode 1.60 + vscode_remote
  • g++ with gdb 8

The setting -enable-pretty-printing is not working at all:

Screenshot from 2021-09-04 20-04-51

The following solution works for me:

  1. check your gdb is supporting the 'pretty-print' which supplied by the python module of gdb: readelf -d $(which gdb) | grep python. if nothing is listed, unfortunately, you have to rebuild your gdb from the source.
  2. Some requirements must be installed before rebuilding of gdb: sudo apt install python libpython-dev # Python 2.7 and it's PythonLib will be installed in Ubuntu 18.04
  3. Download the latest gdb from here and unpack.
  4. Perform the building and installation with the following configurations:
    ./configure --with-python
    make all -j16
    sudo make install -j16
    
  5. Done! Screenshot from 2021-09-04 20-01-05

Ps. If you are using conda, your Python environment maybe not correct for the GDB. Deactive your conda before debug:

conda deactivate

to make sure the correct version of Python is loaded by gdb.

Devymex
  • 446
  • 3
  • 17