Skip to content

VSCode env var ${cwd} does not work when use mingw cross gdb  #9727

@WittonBell

Description

@WittonBell

Environment

  • OS and version:
    Win10 MinGW
  • VS Code:
    1.70.1
  • C/C++ extension:
    cpptools 1.11.5
    cmake tools 1.11.26
    CMake language support 0.0.4
    CMake 0.0.17
  • OS and version of remote machine (if applicable):
  • GDB / LLDB version:
    x86_64-elf-gdb.exe 12.1

Bug Summary and Steps to Reproduce

Bug Summary:

Start GDB and load the target file. The absolute path must be used, otherwise the target file cannot be found.

I add arg -ex \"pwd\" to miDebuggerArgs, gdb show Working directory H:\msys64\opt\cross64\bin., not my ${workspaceFolder}.

I add arg -cd=${workspaceFolder} to miDebuggerArgs, but occur error:

/usr/bin/env c:\\Users\\admin\\.vscode\\extensions\\ms-vscode.cpptools-1.11.5-win32-x64\\debugAdapters\\bin\\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-yz2ffplh.lvl --stdout=Microsoft-MIEngine-Out-ic2rorfj.djg --stderr=Microsoft-MIEngine-Error-x2najehp.kci --pid=Microsoft-MIEngine-Pid-4mm211gi.1nh --dbgExe=H:\\msys64\\opt\\cross64\\bin\\x86_64-elf-gdb.exe --interpreter=mi\ -cd=G:\\test\\test\ -ex\ \"file\ build/Kernel/Kernel\"\ -ex\ \"set\ arch\ i386\"\ -ex\ \"b\ kmain\"\ -ex\ \"target\ remote\ :1234\"


   由于 Exception.ToString() 失败,因此无法打印异常字符串。

I think it may be caused by the path separator.

I Test in VS 2022, add arg -cd=${workspaceRoot} to miDebuggerArgs, it work fine.

在Win10 MinGW环境下,VSCode使用交叉调试器gdb来调试程序时,工作目录不是VSCode中设定的${cwd},而是调试器所在目录,导致无法找到调试目标。它必须使用绝对路径才能正常工作。尝试给gdb传入参数-cd=${workspaceFolder},但是有报错,可能路径分隔符的问题。我尝试在VS 2022中向交叉调试器gdb传入参数-cd=${workspaceRoot},可以正常工作。

Debugger Configurations

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/Kernel/Kernel",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "x86_64-elf-gdb",
            "miDebuggerArgs": "-cd=${workspaceRoot} -ex \"file build/Kernel/Kernel\" -ex \"set arch i386\" -ex \"b kmain\" -ex \"target remote :1234\"",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}


### Debugger Logs

```shell
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (66) LaunchOptions{\"name\":\"(gdb) 启动\",\"type\":\"cppdbg\",\"request\":\"launch\",\"program\":\"G:\\\\test\\\\test/build/Kernel/Kernel\",\"args\":[],\"stopAtEntry\":false,\"cwd\":\"G:\\\\test\\\\test\",\"environment\":[],\"externalConsole\":false,\"MIMode\":\"gdb\",\"miDebuggerPath\":\"x86_64-elf-gdb\",\"miDebuggerArgs\":\"-cd=G:\\\\test\\\\test -ex \\\"pwd\\\" -ex \\\"file build/Kernel/Kernel\\\" -ex \\\"set arch i386\\\" -ex \\\"b kmain\\\" -ex \\\"target remote :1234\\\"\",\"setupCommands\":[{\"description\":\"为 gdb 启用整齐打印\",\"text\":\"-enable-pretty-printing\",\"ignoreFailures\":true},{\"description\":\"将反汇编风格设置为 Intel\",\"text\":\"-gdb-set disassembly-flavor intel\",\"ignoreFailures\":true}],\"logging\":{\"engineLogging\":true,\"trace\":true,\"traceResponse\":true},\"__configurationTarget\":6,\"__sessionId\":\"d4f30e69-86f4-41d1-b104-94afd3dc3df7\"}\r\n"},"seq":2}
1: (66) LaunchOptions{"name":"(gdb) 启动","type":"cppdbg","request":"launch","program":"G:\\test\\test/build/Kernel/Kernel","args":[],"stopAtEntry":false,"cwd":"G:\\test\\test","environment":[],"externalConsole":false,"MIMode":"gdb","miDebuggerPath":"x86_64-elf-gdb","miDebuggerArgs":"-cd=G:\\test\\test -ex \"pwd\" -ex \"file build/Kernel/Kernel\" -ex \"set arch i386\" -ex \"b kmain\" -ex \"target remote :1234\"","setupCommands":[{"description":"为 gdb 启用整齐打印","text":"-enable-pretty-printing","ignoreFailures":true},{"description":"将反汇编风格设置为 Intel","text":"-gdb-set disassembly-flavor intel","ignoreFailures":true}],"logging":{"engineLogging":true,"trace":true,"traceResponse":true},"__configurationTarget":6,"__sessionId":"d4f30e69-86f4-41d1-b104-94afd3dc3df7"}
--> C (runInTerminal-4): {"type":"request","command":"runInTerminal","arguments":{"kind":"integrated","title":"cppdbg: Kernel","cwd":"","args":["c:\\Users\\admin\\.vscode\\extensions\\ms-vscode.cpptools-1.11.5-win32-x64\\debugAdapters\\bin\\WindowsDebugLauncher.exe","--stdin=Microsoft-MIEngine-In-5wm0th3j.pq3","--stdout=Microsoft-MIEngine-Out-4zz10whl.qnc","--stderr=Microsoft-MIEngine-Error-bvaqxtxa.znk","--pid=Microsoft-MIEngine-Pid-g5wj0bak.ibr","--dbgExe=H:\\msys64\\opt\\cross64\\bin\\x86_64-elf-gdb.exe","--interpreter=mi -cd=G:\\test\\test -ex \"pwd\" -ex \"file build/Kernel/Kernel\" -ex \"set arch i386\" -ex \"b kmain\" -ex \"target remote :1234\""],"env":{}},"seq":4}
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (117) Wait for connection completion.\r\n"},"seq":6}
1: (117) Wait for connection completion.
--> E (output): {"type":"event","event":"output","body":{"category":"stderr","output":"\r\n\r\n"},"seq":8}


--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (20135) Send Event AD7MessageEvent\r\n"},"seq":10}
1: (20135) Send Event AD7MessageEvent
--> 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.1.20608.1","VS.Diagnostics.Debugger.HostVersion":"17.1.20608.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.Launch.ErrorCode":1005,"VS.Diagnostics.Debugger.Launch.IsError":true}},"seq":12}
--> R (launch-2): {"type":"response","request_seq":2,"success":false,"command":"launch","message":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information.","body":{"error":{"id":1005,"format":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information."}},"seq":14}

Other Extensions

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    debuggerinvestigate: reproThis issue's repro steps needs to be investigated/confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions