microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

Unable to Debug on Apple M1/M2 when using linux/amd64 devcontainer #10788

Open jimklo opened 1 year ago

jimklo commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Attaching sample workspace: sample-cpp.zip

Steps:

  1. Build the devcontainer and install the plugins. (Note due to another issue, plugin verification must be disabled, see https://github.com/microsoft/vscode-remote-release/issues/8169)
  2. Open the test_app.cpp and press the debug/play button
  3. Error is displayed and debug session is not started.

Debugger Configurations

**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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/src/test_app",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "logging": { "engineLogging": true, "trace": true, "traceResponse": true }
        }

    ]
}

tasks.json

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

### Debugger Logs

```shell
**Debug Console**

--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (141) LaunchOptions{\"name\":\"(gdb) Launch\",\"type\":\"cppdbg\",\"request\":\"launch\",\"program\":\"/workspaces/sample-cpp/src/test_app\",\"args\":[],\"stopAtEntry\":false,\"cwd\":\"/workspaces/sample-cpp/.vscode\",\"environment\":[],\"externalConsole\":false,\"MIMode\":\"gdb\",\"setupCommands\":[{\"description\":\"Enable pretty-printing for gdb\",\"text\":\"-enable-pretty-printing\",\"ignoreFailures\":true},{\"description\":\"Set Disassembly Flavor to Intel\",\"text\":\"-gdb-set disassembly-flavor intel\",\"ignoreFailures\":true}],\"logging\":{\"engineLogging\":true,\"trace\":true,\"traceResponse\":true},\"__configurationTarget\":6,\"__sessionId\":\"25c2260b-663f-4095-b2bf-18837e8d7bff\"}\n"},"seq":2}
1: (141) LaunchOptions{"name":"(gdb) Launch","type":"cppdbg","request":"launch","program":"/workspaces/sample-cpp/src/test_app","args":[],"stopAtEntry":false,"cwd":"/workspaces/sample-cpp/.vscode","environment":[],"externalConsole":false,"MIMode":"gdb","setupCommands":[{"description":"Enable pretty-printing for gdb","text":"-enable-pretty-printing","ignoreFailures":true},{"description":"Set Disassembly Flavor to Intel","text":"-gdb-set disassembly-flavor intel","ignoreFailures":true}],"logging":{"engineLogging":true,"trace":true,"traceResponse":true},"__configurationTarget":6,"__sessionId":"25c2260b-663f-4095-b2bf-18837e8d7bff"}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (214) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-cex1gop1.45d ; cd \"/workspaces/sample-cpp/src\" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm \"/tmp/Microsoft-MIEngine-In-dmtmkzua.oyp\" \"/tmp/Microsoft-MIEngine-Out-gykjzcer.0gd\" \"/tmp/Microsoft-MIEngine-Pid-cex1gop1.45d\" \"/tmp/Microsoft-MIEngine-Cmd-x0bhpqfe.ngr\"' EXIT ; \"/usr/bin/gdb\" --interpreter=mi --tty=$DbgTerm < \"/tmp/Microsoft-MIEngine-In-dmtmkzua.oyp\" > \"/tmp/Microsoft-MIEngine-Out-gykjzcer.0gd\" & clear; pid=$! ; echo $pid > \"/tmp/Microsoft-MIEngine-Pid-cex1gop1.45d\" ; wait $pid; \n"},"seq":4}
1: (214) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-cex1gop1.45d ; cd "/workspaces/sample-cpp/src" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm "/tmp/Microsoft-MIEngine-In-dmtmkzua.oyp" "/tmp/Microsoft-MIEngine-Out-gykjzcer.0gd" "/tmp/Microsoft-MIEngine-Pid-cex1gop1.45d" "/tmp/Microsoft-MIEngine-Cmd-x0bhpqfe.ngr"' EXIT ; "/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-dmtmkzua.oyp" > "/tmp/Microsoft-MIEngine-Out-gykjzcer.0gd" & clear; pid=$! ; echo $pid > "/tmp/Microsoft-MIEngine-Pid-cex1gop1.45d" ; wait $pid;
--> C (runInTerminal-6): {"type":"request","command":"runInTerminal","arguments":{"kind":"integrated","title":"cppdbg: test_app","cwd":"","args":["/bin/sh","/tmp/Microsoft-MIEngine-Cmd-x0bhpqfe.ngr"],"env":{}},"seq":6}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (237) Wait for connection completion.\n"},"seq":8}
1: (237) Wait for connection completion.
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (492) ->=thread-group-added,id=\"i1\"\n"},"seq":10}
1: (492) ->=thread-group-added,id="i1"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (502) ->~\"GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1\\n\"\n"},"seq":12}
1: (502) ->~"GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (503) ->~\"Copyright (C) 2022 Free Software Foundation, Inc.\\n\"\n"},"seq":14}
1: (503) ->~"Copyright (C) 2022 Free Software Foundation, Inc.\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (505) ->~\"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\\nThis is free software: you are free to change and redistribute it.\\nThere is NO WARRANTY, to the extent permitted by law.\"\n"},"seq":16}
1: (505) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (505) ->~\"\\nType \\\"show copying\\\" and \\\"show warranty\\\" for details.\\n\"\n"},"seq":18}
1: (505) ->~"\nType \"show copying\" and \"show warranty\" for details.\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (505) ->~\"This GDB was configured as \\\"x86_64-linux-gnu\\\".\\n\"\n"},"seq":20}
1: (505) ->~"This GDB was configured as \"x86_64-linux-gnu\".\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (505) ->~\"Type \\\"show configuration\\\" for configuration details.\\n\"\n"},"seq":22}
1: (505) ->~"Type \"show configuration\" for configuration details.\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (506) ->~\"For bug reporting instructions, please see:\\n\"\n"},"seq":24}
1: (506) ->~"For bug reporting instructions, please see:\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (506) ->~\"<https://www.gnu.org/software/gdb/bugs/>.\\n\"\n"},"seq":26}
1: (506) ->~"<https://www.gnu.org/software/gdb/bugs/>.\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (506) ->~\"Find the GDB manual and other documentation resources online at:\\n    <http://www.gnu.org/software/gdb/documentation/>.\"\n"},"seq":28}
1: (506) ->~"Find the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>."
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (507) ->~\"\\n\\n\"\n"},"seq":30}
1: (507) ->~"\n\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (507) ->~\"For help, type \\\"help\\\".\\n\"\n"},"seq":32}
1: (507) ->~"For help, type \"help\".\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (507) ->~\"Type \\\"apropos word\\\" to search for commands related to \\\"word\\\".\\n\"\n"},"seq":34}
1: (507) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (507) ->(gdb)\n"},"seq":36}
1: (507) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (516) <-1001-gdb-set mi-async on\n"},"seq":38}
1: (516) <-1001-gdb-set mi-async on
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (519) ->1001^done\n"},"seq":40}
1: (519) ->1001^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (519) ->(gdb)\n"},"seq":42}
1: (519) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (525) 1001: elapsed time 11\n"},"seq":44}
1: (525) 1001: elapsed time 11
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (543) <-1002-enable-pretty-printing\n"},"seq":46}
1: (543) <-1002-enable-pretty-printing
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (545) ->1002^done\n"},"seq":48}
1: (545) ->1002^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (545) ->(gdb)\n"},"seq":50}
1: (545) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (546) 1002: elapsed time 3\n"},"seq":52}
1: (546) 1002: elapsed time 3
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (547) <-1003-gdb-set disassembly-flavor intel\n"},"seq":54}
1: (547) <-1003-gdb-set disassembly-flavor intel
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (547) ->1003^done\n"},"seq":56}
1: (547) ->1003^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (548) ->(gdb)\n"},"seq":58}
1: (548) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (548) 1003: elapsed time 0\n"},"seq":60}
1: (548) 1003: elapsed time 0
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (548) <-1004-interpreter-exec console \"set pagination off\"\n"},"seq":62}
1: (548) <-1004-interpreter-exec console "set pagination off"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (548) ->=cmd-param-changed,param=\"pagination\",value=\"off\"\n"},"seq":64}
1: (548) ->=cmd-param-changed,param="pagination",value="off"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (549) ->1004^done\n"},"seq":66}
1: (549) ->1004^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (549) ->(gdb)\n"},"seq":68}
1: (549) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (549) 1004: elapsed time 1\n"},"seq":70}
1: (549) 1004: elapsed time 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (549) <-1005-gdb-set auto-solib-add on\n"},"seq":72}
1: (549) <-1005-gdb-set auto-solib-add on
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (549) ->1005^done\n"},"seq":74}
1: (549) ->1005^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (550) ->(gdb)\n"},"seq":76}
1: (550) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (550) 1005: elapsed time 0\n"},"seq":78}
1: (550) 1005: elapsed time 0
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (550) <-1006-gdb-set solib-search-path /workspaces/sample-cpp/src:\n"},"seq":80}
1: (550) <-1006-gdb-set solib-search-path /workspaces/sample-cpp/src:
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (553) ->1006^done\n"},"seq":82}
1: (553) ->1006^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (553) ->(gdb)\n"},"seq":84}
1: (553) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (553) 1006: elapsed time 2\n"},"seq":86}
1: (553) 1006: elapsed time 2
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (553) <-1007-gdb-set stop-on-solib-events 1\n"},"seq":88}
1: (553) <-1007-gdb-set stop-on-solib-events 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) ->1007^done\n"},"seq":90}
1: (556) ->1007^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) ->(gdb)\n"},"seq":92}
1: (556) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) 1007: elapsed time 2\n"},"seq":94}
1: (556) 1007: elapsed time 2
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) <-1008-environment-cd /workspaces/sample-cpp/.vscode\n"},"seq":96}
1: (556) <-1008-environment-cd /workspaces/sample-cpp/.vscode
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) ->1008^done\n"},"seq":98}
1: (556) ->1008^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (556) ->(gdb)\n"},"seq":100}
1: (556) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (557) 1008: elapsed time 0\n"},"seq":102}
1: (557) 1008: elapsed time 0
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (557) <-1009-file-exec-and-symbols /workspaces/sample-cpp/src/test_app\n"},"seq":104}
1: (557) <-1009-file-exec-and-symbols /workspaces/sample-cpp/src/test_app
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (588) ->1009^done\n"},"seq":106}
1: (588) ->1009^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (589) ->(gdb)\n"},"seq":108}
1: (589) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (589) 1009: elapsed time 31\n"},"seq":110}
1: (589) 1009: elapsed time 31
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (591) <-1010-interpreter-exec console \"show architecture\"\n"},"seq":112}
1: (591) <-1010-interpreter-exec console "show architecture"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (592) ->~\"The target architecture is set to \\\"auto\\\" (currently \\\"i386:x86-64\\\").\\n\"\n"},"seq":114}
1: (592) ->~"The target architecture is set to \"auto\" (currently \"i386:x86-64\").\n"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (592) ->1010^done\n"},"seq":116}
1: (592) ->1010^done
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (592) ->(gdb)\n"},"seq":118}
1: (592) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (593) 1010: elapsed time 1\n"},"seq":120}
1: (593) 1010: elapsed time 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (595) <-1011-break-insert -f main\n"},"seq":122}
1: (595) <-1011-break-insert -f main
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (619) ->1011^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x0000000000001191\",func=\"main()\",file=\"/workspaces/sample-cpp/src/test_app.cpp\",fullname=\"/workspaces/sample-cpp/src/test_app.cpp\",line=\"5\",thread-groups=[\"i1\"],times=\"0\",original-location=\"main\"}\n"},"seq":124}
1: (619) ->1011^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000001191",func="main()",file="/workspaces/sample-cpp/src/test_app.cpp",fullname="/workspaces/sample-cpp/src/test_app.cpp",line="5",thread-groups=["i1"],times="0",original-location="main"}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (619) ->(gdb)\n"},"seq":126}
1: (619) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (627) 1011: elapsed time 32\n"},"seq":128}
1: (627) 1011: elapsed time 32
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (637) Send Event AD7EngineCreateEvent\n"},"seq":130}
1: (637) Send Event AD7EngineCreateEvent
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (640) Send Event AD7ProgramCreateEvent\n"},"seq":132}
1: (640) Send Event AD7ProgramCreateEvent
--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/Launch","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"17.4.21117.1","VS.Diagnostics.Debugger.HostVersion":"17.4.21117.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.Duration":522,"VS.Diagnostics.Debugger.MIMode":"gdb","VS.Diagnostics.Debugger.FrameworkVersion":"6.0.1122.52304"}},"seq":134}
--> R (launch-2): {"type":"response","request_seq":2,"success":true,"command":"launch","body":{},"seq":136}
--> E (initialized): {"type":"event","event":"initialized","body":{},"seq":138}
<--   R (runInTerminal-6) [444 ms]: {"type":"response","seq":3,"command":"runInTerminal","request_seq":6,"success":true,"body":{"shellProcessId":616}}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (699) ShellPid=4976\n"},"seq":141}
1: (699) ShellPid=4976
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (701) DebuggerPid=4978\n"},"seq":143}
1: (701) DebuggerPid=4978
<--   C (setBreakpoints-4): {"command":"setBreakpoints","arguments":{"source":{"name":"test_app.cpp","path":"/workspaces/sample-cpp/src/test_app.cpp"},"lines":[5],"breakpoints":[{"line":5}],"sourceModified":false},"type":"request","seq":4}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (732) <-1012-break-insert -f test_app.cpp:5\n"},"seq":146}
1: (732) <-1012-break-insert -f test_app.cpp:5
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (734) ->1012^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x0000000000001191\",func=\"main()\",file=\"/workspaces/sample-cpp/src/test_app.cpp\",fullname=\"/workspaces/sample-cpp/src/test_app.cpp\",line=\"5\",thread-groups=[\"i1\"],times=\"0\",original-location=\"test_app.cpp:5\"}\n"},"seq":148}
1: (734) ->1012^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000001191",func="main()",file="/workspaces/sample-cpp/src/test_app.cpp",fullname="/workspaces/sample-cpp/src/test_app.cpp",line="5",thread-groups=["i1"],times="0",original-location="test_app.cpp:5"}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (734) ->(gdb)\n"},"seq":150}
1: (734) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (735) 1012: elapsed time 3\n"},"seq":152}
1: (735) 1012: elapsed time 3
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (752) <-1013-symbol-list-lines /workspaces/sample-cpp/src/test_app.cpp\n"},"seq":154}
1: (752) <-1013-symbol-list-lines /workspaces/sample-cpp/src/test_app.cpp
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (753) ->1013^done,lines=[{pc=\"0x0000000000001189\",line=\"4\"},{pc=\"0x0000000000001191\",line=\"5\"},{pc=\"0x00000000000011aa\",line=\"7\"},{pc=\"0x00000000000011af\",line=\"8\"},{pc=\"0x00000000000011b1\",line=\"8\"},{pc=\"0x00000000000011c3\",line=\"8\"},{pc=\"0x00000000000011d2\",line=\"0\"},{pc=\"0x0000000000001204\",line=\"8\"},{pc=\"0x0000000000001207\",line=\"8\"},{pc=\"0x000000000000120f\",line=\"8\"},{pc=\"0x0000000000001220\",line=\"0\"}]\n"},"seq":156}
1: (753) ->1013^done,lines=[{pc="0x0000000000001189",line="4"},{pc="0x0000000000001191",line="5"},{pc="0x00000000000011aa",line="7"},{pc="0x00000000000011af",line="8"},{pc="0x00000000000011b1",line="8"},{pc="0x00000000000011c3",line="8"},{pc="0x00000000000011d2",line="0"},{pc="0x0000000000001204",line="8"},{pc="0x0000000000001207",line="8"},{pc="0x000000000000120f",line="8"},{pc="0x0000000000001220",line="0"}]
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (753) ->(gdb)\n"},"seq":158}
1: (753) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (758) 1013: elapsed time 5\n"},"seq":160}
1: (758) 1013: elapsed time 5
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (767) Send Event AD7BreakpointBoundEvent\n"},"seq":162}
1: (767) Send Event AD7BreakpointBoundEvent
--> R (setBreakpoints-4): {"type":"response","request_seq":4,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"line":5,"BoundBreakpoints":[]}]},"seq":164}
--> E (breakpoint): {"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":true,"line":5,"BoundBreakpoints":[]}},"seq":166}
<--   C (setFunctionBreakpoints-5): {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
--> R (setFunctionBreakpoints-5): {"type":"response","request_seq":5,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]},"seq":169}
<--   C (setDataBreakpoints-6): {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
--> R (setDataBreakpoints-6): {"type":"response","request_seq":6,"success":true,"command":"setDataBreakpoints","body":{"breakpoints":[]},"seq":172}
<--   C (setInstructionBreakpoints-7): {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":7}
--> R (setInstructionBreakpoints-7): {"type":"response","request_seq":7,"success":true,"command":"setInstructionBreakpoints","body":{"breakpoints":[]},"seq":175}
<--   C (setExceptionBreakpoints-8): {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[]},"type":"request","seq":8}
--> R (setExceptionBreakpoints-8): {"type":"response","request_seq":8,"success":true,"command":"setExceptionBreakpoints","body":{"breakpoints":[]},"seq":178}
<--   C (configurationDone-9): {"command":"configurationDone","type":"request","seq":9}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (893) Send Event AD7LoadCompleteEvent\n"},"seq":182}
1: (893) Send Event AD7LoadCompleteEvent
--> R (configurationDone-9): {"type":"response","request_seq":9,"success":true,"command":"configurationDone","body":{},"seq":181}
--> E (output): {"type":"event","event":"output","body":{"category":"stdout","output":"=thread-group-added,id=\"i1\"\nGNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1\nCopyright (C) 2022 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\nType \"show copying\" and \"show warranty\" for details.\nThis GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details.\nFor bug reporting instructions, please see:\n<https://www.gnu.org/software/gdb/bugs/>.\nFind the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>.\n\nFor help, type \"help\".\nType \"apropos word\" to search for commands related to \"word\".\nWarning: Debuggee TargetArchitecture not detected, assuming x86_64.\n=cmd-param-changed,param=\"pagination\",value=\"off\"\n"},"seq":185}
=thread-group-added,id="i1"
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (911) <-1014-exec-run\n"},"seq":187}
1: (911) <-1014-exec-run
<--   C (threads-10): {"command":"threads","type":"request","seq":10}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (918) ->=thread-group-started,id=\"i1\",pid=\"4990\"\n"},"seq":191}
1: (918) ->=thread-group-started,id="i1",pid="4990"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (918) ->=thread-created,id=\"1\",group-id=\"i1\"\n"},"seq":193}
1: (918) ->=thread-created,id="1",group-id="i1"
--> R (threads-10): {"type":"response","request_seq":10,"success":true,"command":"threads","body":{"threads":[]},"seq":190}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (923) <-1015-thread-info 1\n"},"seq":196}
1: (923) <-1015-thread-info 1
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (923) ->1014^error,msg=\"Couldn't get registers: Input/output error.\"\n"},"seq":198}
1: (923) ->1014^error,msg="Couldn't get registers: Input/output error."
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (924) ->(gdb)\n"},"seq":200}
1: (924) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (925) ->1015^error,msg=\"Couldn't get registers: Input/output error.\"\n"},"seq":202}
1: (925) ->1015^error,msg="Couldn't get registers: Input/output error."
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (925) ->(gdb)\n"},"seq":204}
1: (925) ->(gdb)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (926) 1014: elapsed time 15\n"},"seq":206}
1: (926) 1014: elapsed time 15
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (938) 1015: elapsed time 14\n"},"seq":208}
1: (938) 1015: elapsed time 14
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (940) Send Event AD7MessageEvent\n"},"seq":210}
1: (940) Send Event AD7MessageEvent
--> E (output): {"type":"event","event":"output","body":{"category":"stderr","output":"ERROR: Unable to start debugging. Unexpected GDB output from command \"-exec-run\". Couldn't get registers: Input/output error.\n"},"seq":212}
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Couldn't get registers: Input/output error.
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (946) <--gdb-exit\n"},"seq":214}
1: (946) <--gdb-exit
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (947) ->^exit\n"},"seq":216}
1: (947) ->^exit
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (948) ->=thread-exited,id=\"1\",group-id=\"i1\"\n"},"seq":218}
1: (948) ->=thread-exited,id="1",group-id="i1"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (949) ->=thread-group-exited,id=\"i1\"\n"},"seq":220}
1: (949) ->=thread-group-exited,id="i1"
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (960) Send Event AD7ProgramDestroyEvent\n"},"seq":222}
1: (960) Send Event AD7ProgramDestroyEvent
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"The program '/workspaces/sample-cpp/src/test_app' has exited with code 42 (0x0000002a).\r\n\n"},"seq":224}
The program '/workspaces/sample-cpp/src/test_app' has exited with code 42 (0x0000002a).
--> E (exited): {"type":"event","event":"exited","body":{"exitCode":42},"seq":226}
--> E (terminated): {"type":"event","event":"terminated","body":{},"seq":228}
--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/DebugCompleted","data":{"VS.Diagnostics.Debugger.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.EngineVersion":"17.4.21117.1","VS.Diagnostics.Debugger.HostVersion":"17.4.21117.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.DebugCompleted.BreakCounter":0}},"seq":230}
--> E (output): {"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/NonFatalError","data":{"VS.Diagnostics.Debugger.NonFatalError.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.NonFatalError.ExceptionType":"System.ObjectDisposedException","VS.Diagnostics.Debugger.NonFatalError.ExceptionStack":"   at Microsoft.MIDebugEngine.WorkerThread.PostOperation(Operation op)\n   at Microsoft.MIDebugEngine.DebuggedProcess.ScheduleStdOutProcessing(String line)\n   at MICore.Debugger.HandleThreadGroupExited(Results results)\n   at MICore.Debugger.OnNotificationOutput(String cmd)\n   at MICore.Debugger.ProcessStdOutLine(String line)\n   at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass94_0.<ScheduleStdOutProcessing>b__0()\n   at Microsoft.MIDebugEngine.WorkerThread.ThreadFunc()","VS.Diagnostics.Debugger.NonFatalError.HResult":-2146232798,"VS.Diagnostics.Debugger.EngineVersion":"17.4.21117.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.HostVersion":"17.4.21117.1"}},"seq":232}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1003) EXCEPTION: \n"},"seq":234}
[Error] 1: (1003) EXCEPTION:
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1004) EXCEPTION:    at Microsoft.MIDebugEngine.WorkerThread.PostOperation(Operation op)\n"},"seq":236}
[Error] 1: (1004) EXCEPTION:    at Microsoft.MIDebugEngine.WorkerThread.PostOperation(Operation op)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1004) EXCEPTION:    at Microsoft.MIDebugEngine.DebuggedProcess.ScheduleStdOutProcessing(String line)\n"},"seq":238}
[Error] 1: (1004) EXCEPTION:    at Microsoft.MIDebugEngine.DebuggedProcess.ScheduleStdOutProcessing(String line)
<--   C (disconnect-11): {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":11}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1004) EXCEPTION:    at MICore.Debugger.HandleThreadGroupExited(Results results)\n"},"seq":241}
[Error] 1: (1004) EXCEPTION:    at MICore.Debugger.HandleThreadGroupExited(Results results)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1005) EXCEPTION:    at MICore.Debugger.OnNotificationOutput(String cmd)\n"},"seq":243}
[Error] 1: (1005) EXCEPTION:    at MICore.Debugger.OnNotificationOutput(String cmd)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1005) EXCEPTION:    at MICore.Debugger.ProcessStdOutLine(String line)\n"},"seq":245}
[Error] 1: (1005) EXCEPTION:    at MICore.Debugger.ProcessStdOutLine(String line)
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1005) EXCEPTION:    at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass94_0.<ScheduleStdOutProcessing>b__0()\n"},"seq":247}
[Error] 1: (1005) EXCEPTION:    at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass94_0.<ScheduleStdOutProcessing>b__0()
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"[Error] 1: (1005) EXCEPTION:    at Microsoft.MIDebugEngine.WorkerThread.ThreadFunc()\n"},"seq":249}
[Error] 1: (1005) EXCEPTION:    at Microsoft.MIDebugEngine.WorkerThread.ThreadFunc()
--> R (disconnect-11): {"type":"response","request_seq":11,"success":true,"command":"disconnect","body":{},"seq":251}

Terminal

&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-dmtmkzua.oyp" 1>"/tmp/Microsoft-MIEngine-Out-gykjzcer.0gd"


### Other Extensions

_No response_

### Additional Information

My guess is this has to do with permissions with Rosetta 2, but unsure. I would think it should debug like a remote debugger.  Not sure how to proceed.  Also this works fine if run using linux/arm64 as the container platform.
WardenGnaw commented 1 year ago

The error is comming from GDB.

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Couldn't get registers: Input/output error.

This may be an issue with devcontainers or how GDB works within them. You can file a bug on GDB at https://sourceware.org/bugzilla/

mogongzi commented 1 year ago

When I tried to run gdb inside of the container (which is built on x86_64), I got the same error Couldn't write debug register: Input/output error.

KOConchobhair commented 1 year ago

Not a GDB bug...but GDB does get a little confused in this case since rosetta is involved.

I was able to get it working inside a container by following this excellent blog post: https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

ROSETTA_DEBUGSERVER_PORT=1234 node app.js &
gdb
(gdb) set architecture i386:x86-64
(gdb) file /usr/bin/node
(gdb) target remote localhost:1234
(gdb) continue

I am sure there's a way to convert the above to a VSCode launch configuration (exercise left to the reader). I am using macOS M2, Ventura 13.4, stock ubuntu:20.04 container --platform=linux/amd64 via colima v0.5.5 w/ Virtualization.Framework & rosetta enabled. Hope this helps!

jacogasp commented 1 year ago

Not a GDB bug...but GDB does get a little confused in this case since rosetta is involved.

I was able to get it working inside a container by following this excellent blog post: https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

ROSETTA_DEBUGSERVER_PORT=1234 node app.js &
gdb
(gdb) set architecture i386:x86-64
(gdb) file /usr/bin/node
(gdb) target remote localhost:1234
(gdb) continue

I am sure there's a way to convert the above to a VSCode launch configuration (exercise left to the reader). I am using macOS M2, Ventura 13.4, stock ubuntu:20.04 container --platform=linux/amd64 via colima v0.5.5 w/ Virtualization.Framework & rosetta enabled. Hope this helps!

Nice workaround. But I'm still struggling debbugging my cpp. I replaced your command with my-binary instead of /usr/bin/node. Apparently GDB loads all the symbols correctly but then I receive a segmentation fault when running continue. Still not sure where the problem is, since running my executable without gdb I don't have seg faults.

Same configuration: M2, macOS 13.4, colima 0.5.5

KOConchobhair commented 1 year ago

A segfault under gdb doesn't sound like OP's issue. We were simply seeing the error Couldn't write debug register: Input/output error. from gdb and the workaround above gets past that error.

If it's crashing for you it could be a different issue. I'd say make sure you are starting Colima with colima start --arch aarch64 --vm-type=vz --vz-rosetta (otherwise it uses qemu by default).

jacogasp commented 1 year ago

Hi @KOConchobhair,

yes, I'm investigating and apparently the segfault comes from some multithreaded libraries messing around in our code. Still don't now if this issue comes for rosetta emulation or not, but definitely not a gdb issue. Actually your workaround works: I'm able to perform gdb commands such as printing frames and break the code where I want.

Thank you very much!

P.s.: for reference your link doesn't not work anymore, here the archived version https://web.archive.org/web/20230419045554/https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

tang-hi commented 8 months ago

Not a GDB bug...but GDB does get a little confused in this case since rosetta is involved.

I was able to get it working inside a container by following this excellent blog post: https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

ROSETTA_DEBUGSERVER_PORT=1234 node app.js &
gdb
(gdb) set architecture i386:x86-64
(gdb) file /usr/bin/node
(gdb) target remote localhost:1234
(gdb) continue

I am sure there's a way to convert the above to a VSCode launch configuration (exercise left to the reader). I am using macOS M2, Ventura 13.4, stock ubuntu:20.04 container --platform=linux/amd64 via colima v0.5.5 w/ Virtualization.Framework & rosetta enabled. Hope this helps!

I tried this in Visual Studio Code, but I couldn't find a suitable way to convert these instructions to Microsoft's C++ extension. After some effort, I discovered an extension that could address this issue.

  1. Start by installing the "Native Debug" extension. image

  2. Next, add a configuration in your launch.json file:

    {
    "version": "0.2.0",
    "configurations": [
        {
            "type": "gdb",
            "request": "attach",
            "name": "Attach to gdbserver",
            "executable": "./your/executable/path",   //relative to your workspace
            "target": "localhost:1234", 
            "remote": true,
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        }
    ]
    }

    image

  3. Now, execute your program in the terminal:

    ROSETTA_DEBUGSERVER_PORT=1234 ./your/executable/path
  4. Finally, attach to the program through Visual Studio Code:

image

Now, you're all set to debug your program.

gittyabhay commented 4 months ago

Not a GDB bug...but GDB does get a little confused in this case since rosetta is involved. I was able to get it working inside a container by following this excellent blog post: https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

ROSETTA_DEBUGSERVER_PORT=1234 node app.js &
gdb
(gdb) set architecture i386:x86-64
(gdb) file /usr/bin/node
(gdb) target remote localhost:1234
(gdb) continue

I am sure there's a way to convert the above to a VSCode launch configuration (exercise left to the reader). I am using macOS M2, Ventura 13.4, stock ubuntu:20.04 container --platform=linux/amd64 via colima v0.5.5 w/ Virtualization.Framework & rosetta enabled. Hope this helps!

Nice workaround. But I'm still struggling debbugging my cpp. I replaced your command with my-binary instead of /usr/bin/node. Apparently GDB loads all the symbols correctly but then I receive a segmentation fault when running continue. Still not sure where the problem is, since running my executable without gdb I don't have seg faults.

Same configuration: M2, macOS 13.4, colima 0.5.5

idk what is wrong with my setup, this does not work for me, I am running a centos(x86) docker image with docker desktop on M3 pro, it still gives me

Couldn't get registers: Input/output error. Couldn't get registers: Input/output error.

Can u pls help?

tang-hi commented 4 months ago

Not a GDB bug...but GDB does get a little confused in this case since rosetta is involved. I was able to get it working inside a container by following this excellent blog post: https://sporks.space/2023/04/12/debugging-an-x86-application-in-rosetta-for-linux/

ROSETTA_DEBUGSERVER_PORT=1234 node app.js &
gdb
(gdb) set architecture i386:x86-64
(gdb) file /usr/bin/node
(gdb) target remote localhost:1234
(gdb) continue

I am sure there's a way to convert the above to a VSCode launch configuration (exercise left to the reader). I am using macOS M2, Ventura 13.4, stock ubuntu:20.04 container --platform=linux/amd64 via colima v0.5.5 w/ Virtualization.Framework & rosetta enabled. Hope this helps!

Nice workaround. But I'm still struggling debbugging my cpp. I replaced your command with my-binary instead of /usr/bin/node. Apparently GDB loads all the symbols correctly but then I receive a segmentation fault when running continue. Still not sure where the problem is, since running my executable without gdb I don't have seg faults. Same configuration: M2, macOS 13.4, colima 0.5.5

idk what is wrong with my setup, this does not work for me, I am running a centos(x86) docker image with docker desktop on M3 pro, it still gives me

Couldn't get registers: Input/output error. Couldn't get registers: Input/output error.

Can u pls help?

Hi, have you tried the setup I posted? I think it might be helpful.