microsoft / microsoft/vscode-cpptools

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

Abierto
#6,586 7 comentarios 6 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug debugger
Lenguaje dominante
TypeScript
Estrellas
6.2k
Forks
1.7k
Merge medio
14 h 46 min
PR fusionados (30 d)
61

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

No se nombra ningún archivo fuente ni ninguna prueba. Empieza reproduciendo el problema con el ejemplo proporcionado de C++ unordered_map e inspecciona la solicitud de variables para los elementos secundarios del mapa en GDB/MI, comparándola con la evaluación correcta en la consola. Se considerará terminado cuando ver la asignación en la ventana Variables o Watch ya no bloquee la sesión de depuración y muestre sus entradas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
cpp, vscode
Área
devtools, tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.