microsoft / microsoft/vscode-cpptools

GDB pretty-printing of unordered_map<std::type_index, T> crashes connection to debugger

Open
#6,586 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug debugger
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Issue Type: Bug

To reproduce:

  • Compile (with debug info) any code including a std::unordered_map containing std::type_index. For example:
#include <unordered_map>
#include <typeindex>

int main() {
    int x=5;
    std::unordered_map<std::type_index, int> m {
        { typeid(int), 1 },
        { typeid(double), 2}
    };
    return 0;
}
  • Put a breakpoint after the map has some data in it (the return line above)
  • Set up a launch.json similar to this:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "<path to exe>",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/opt/rh/devtoolset-7/root/usr/bin/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ]
        }
    ]
}
  • Launch the debugger. At the breakpoint, look at the variables (in the variables or watch window, or by hovering).

Actual behaviour: as soon as an attempt is made to visualise the map, the debug session crashes, giving Stopping due to fatal error: NullReferenceException: Object reference not set to an instance of an object in the Debug console.

Expected behaviour: we get a visualisation of the map.

Detailed log output:

<--   C (variables-16): {"command":"variables","arguments":{"variablesReference":1003},"type":"request","seq":16}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (48954) <-1029-var-list-children --simple-values \"var2\" 0 1000\n"},"seq":470}
1: (48954) <-1029-var-list-children --simple-values "var2" 0 1000
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (48955) ->1029^done,numchild=\"4\",displayhint=\"map\",children=[child={name=\"var2.[0]\",exp=\"[0]\",numchild=\"1\",type=\"const std::type_index\",thread-id=\"1\"},child={name=\"var2.[1]\",exp=\"[1]\",numchild=\"0\",value=\"2\",type=\"int\",thread-id=\"1\"},child={name=\"var2.[2]\",exp=\"[2]\",numchild=\"1\",type=\"const std::type_index\",thread-id=\"1\"},child={name=\"var2.[3]\",exp=\"[3]\",numchild=\"0\",value=\"1\",type=\"int\",thread-id=\"1\"}],has_more=\"0\"\n"},"seq":472}
1: (48955) ->1029^done,numchild="4",displayhint="map",children=[child={name="var2.[0]",exp="[0]",numchild="1",type="const std::type_index",thread-id="1"},child={name="var2.[1]",exp="[1]",numchild="0",value="2",type="int",thread-id="1"},child={name="var2.[2]",exp="[2]",numchild="1",type="const std::type_index",thread-id="1"},child={name="var2.[3]",exp="[3]",numchild="0",value="1",type="int",thread-id="1"}],has_more="0"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (48955) ->(gdb)\n"},"seq":474}
1: (48955) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (48955) 1029: elapsed time 1\n"},"seq":476}
1: (48955) 1029: elapsed time 1
Stopping due to fatal error: NullReferenceException: Object reference not set to an instance of an object

For comparison, if I run -exec p m, I get

-exec p m
<--   C (evaluate-13): {"command":"evaluate","arguments":{"expression":"-exec p m","frameId":1000,"context":"repl"},"type":"request","seq":13}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10589) <-1028-interpreter-exec console \"p m\"\n"},"seq":435}
1: (10589) <-1028-interpreter-exec console "p m"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10590) ->~\"$1 = std::unordered_map with 2 elements = {[{_M_target = 0x604dc0 <typeinfo for double@@CXXABI_1.3>\"\n"},"seq":437}
1: (10590) ->~"$1 = std::unordered_map with 2 elements = {[{_M_target = 0x604dc0 <typeinfo for double@@CXXABI_1.3>"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10590) ->~\"}\"\n"},"seq":439}
1: (10590) ->~"}"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->~\"] = 2\"\n"},"seq":441}
1: (10591) ->~"] = 2"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->~\", [{_M_target = 0x604de0 <typeinfo for int@@CXXABI_1.3>\"\n"},"seq":443}
1: (10591) ->~", [{_M_target = 0x604de0 <typeinfo for int@@CXXABI_1.3>"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->~\"}\"\n"},"seq":445}
1: (10591) ->~"}"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->~\"] = 1\"\n"},"seq":447}
1: (10591) ->~"] = 1"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->~\"}\\n\"\n"},"seq":449}
1: (10591) ->~"}\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->1028^done\n"},"seq":451}
1: (10591) ->1028^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) ->(gdb)\n"},"seq":453}
1: (10591) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (10591) 1028: elapsed time 1\n"},"seq":455}
1: (10591) 1028: elapsed time 1
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"$1 = std::unordered_map with 2 elements = {[{_M_target = 0x604dc0 <typeinfo for double@@CXXABI_1.3>}] = 2, [{_M_target = 0x604de0 <typeinfo for int@@CXXABI_1.3>}] = 1}\n\n"},"seq":457}
$1 = std::unordered_map with 2 elements = {[{_M_target = 0x604dc0 <typeinfo for double@@CXXABI_1.3>}] = 2, [{_M_target = 0x604de0 <typeinfo for int@@CXXABI_1.3>}] = 1}

--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Evaluate","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"16.5.11030.1","VS.Diagnostics.Debugger.HostVersion":"16.5.11030.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Evaluate.Duration":5.0,"VS.Diagnostics.Debugger.Evaluate.IsError":false,"VS.Diagnostics.Debugger.Evaluate.ExecuteInConsole":true}},"seq":459}
--> R (evaluate-13): {"type":"response","request_seq":13,"success":true,"command":"evaluate","body":{"result":"","variablesReference":0},"seq":461}
<--   C (scopes-14): {"command":"scopes","arguments":{"frameId":1000},"type":"request","seq":14}
--> R (scopes-14): {"type":"response","request_seq":14,"success":true,"command":"scopes","body":{"scopes":[{"name":"Locals","variablesReference":1002,"expensive":false}]},"seq":464}
<--   C (variables-15): {"command":"variables","arguments":{"variablesReference":1002},"type":"request","seq":15}
--> R (variables-15): {"type":"response","request_seq":15,"success":true,"command":"variables","body":{"variables":[{"name":"x","value":"5","type":"int","evaluateName":"x","variablesReference":0,"memoryReference":"0x0000000000000005"},{"name":"m","value":"{...}","type":"std::unordered_map<std::type_index, int, std::hash<std::type_index>, std::equal_to<std::type_index>, std::allocator<std::pair<std::type_index const, int> > >","evaluateName":"m","variablesReference":1003}]},"seq":467}

Extension version: 1.1.2
VS Code version: Code 1.51.1 (e5a624b788d92b8d34d1392e4c4d9789406efe8f, 2020-11-10T23:34:32.027Z)
OS version: Windows_NT x64 10.0.19041
Remote OS version: Linux x64 4.19.104-microsoft-standard
Remote OS version: Linux x64 4.19.104-microsoft-standard

Also reproduced on Linux in VSCode 1.49.3 (same extension version; in this case the only other extension was CMake Tools).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the issue with the provided C++ unordered_map sample and inspect the variables request for the GDB/MI map children, comparing it with the successful console evaluation. Done means viewing the map in the Variables or Watch window no longer crashes the debug session and displays its entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, vscode
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.