microsoft / microsoft/vscode-cpptools

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

Offen
#6,586 7 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug debugger
Vorherrschende Sprache
TypeScript
Sterne
6.2k
Forks
1.7k
Ø Merge
14 Std. 46 Min.
Gemergte PRs (30 T.)
61

Beschreibung

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).

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Keine Quelldatei oder kein Test ist angegeben. Beginnen Sie damit, das Problem mit dem bereitgestellten C++ unordered_map-Beispiel zu reproduzieren, und untersuchen Sie die Variablenanforderung für die Map-Kinder in GDB/MI, indem Sie sie mit der erfolgreichen Konsolenauswertung vergleichen. Als erledigt gilt die Aufgabe, wenn das Anzeigen der Map im Variables- oder Watch-Fenster die Debug-Sitzung nicht mehr zum Absturz bringt und ihre Einträge anzeigt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
cpp, vscode
Bereich
devtools, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.