microsoft / vscode-cpptools

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

[MSYS2 GDB 10.2] gdb: ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Error creating process #7706

Closed dcm684w closed 2 years ago

dcm684w commented 3 years ago

Bug Type: Debugger

The Problem

When I try to debug an executable, the debug console has the following error ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Error creating process /usr/bin/C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave/C:\Checked_Out\PIC_Drivers\LIN_Master_Slave/test_ceedling/build/test/out/foo.out, (error 2).

Note that the path listed is a concatenation of paths (Msys2 GDB path, workspaceFolder, and the actual path to the executable).

The break point (set on print line in foo.c) is ignored.

To Reproduce

launch.json

    "configurations": [
        {
            "name": "Debug Test",
            "type": "cppdbg",
            "request": "launch",
            //"preLaunchTask": "Ceedling test",
            "program": "${workspaceFolder}/test_ceedling/build/test/out/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "logging": {
                "engineLogging": true
            },
            "MIMode": "gdb",
            "miDebuggerPath": "C:/msys64/usr/bin/gdb.exe",
            // "sourceFileMap": {
            //     "\\c":"C:\\"
            // },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

C:\Checked_Out\PIC_Drivers\LIN_Master_Slave\test_ceedling\test\drivers_lin\foo.c Compiled via gcc -g -o .\test_ceedling\build\test\out\foo.out .\test_ceedling\test\drivers_lin\foo.c

int main(){
    printf("Howdy\n");
    return 1;
}

Command Printed on Terminal window when starting debug & 'c:\Users\XXXXX\.vscode\extensions\ms-vscode.cpptools-1.5.0-insiders\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-mjmxer35.qfv' '--stdout=Microsoft-MIEngine-Out-rwzy3jm4.ibe' '--stderr=Microsoft-MIEngine-Error-5sf3fcqh.013' '--pid=Microsoft-MIEngine-Pid-psyrrdnu.5fu' '--dbgExe=C:/msys64/usr/bin/gdb.exe' '--interpreter=mi'

Debug Console Output

1: (255) Wait for connection completion.
1: (694) ->=thread-group-added,id="i1"
1: (696) ->~"GNU gdb (GDB) 10.2\n"
1: (696) ->~"Copyright (C) 2021 Free Software Foundation, Inc.\n"
1: (696) ->~"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."
1: (696) ->~"\nType \"show copying\" and \"show warranty\" for details.\n"
1: (696) ->~"This GDB was configured as \"x86_64-pc-msys\".\n"
1: (697) ->~"Type \"show configuration\" for configuration details.\n"
1: (697) ->~"For bug reporting instructions, please see:\n"
1: (697) ->~"<https://www.gnu.org/software/gdb/bugs/>.\n"
1: (698) ->~"Find the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>."
1: (698) ->~"\n\n"
1: (698) ->~"For help, type \"help\".\n"
1: (698) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (710) ->(gdb)
1: (714) <-1001-gdb-set target-async on
1: (716) ->1001^done
1: (716) ->(gdb)
1: (716) ->&"\n"
1: (716) ->^done
1: (716) ->(gdb)
1: (718) 1001: elapsed time 4
1: (731) <-1002-enable-pretty-printing
1: (734) ->1002^done
1: (734) ->(gdb)
1: (734) 1002: elapsed time 3
1: (735) ->&"\n"
1: (735) ->^done
1: (735) ->(gdb)
1: (735) <-1003-interpreter-exec console "set pagination off"
1: (736) ->=cmd-param-changed,param="pagination",value="off"
1: (736) ->1003^done
1: (736) 1003: elapsed time 0
1: (736) <-1004-gdb-set auto-solib-add on
1: (736) ->(gdb)
1: (736) ->&"\n"
1: (736) ->^done
1: (737) ->(gdb)
1: (738) ->1004^done
1: (738) 1004: elapsed time 1
1: (738) ->(gdb)
1: (738) ->&"\n"
1: (738) ->^done
1: (738) ->(gdb)
1: (738) <-1005-gdb-set solib-search-path C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave/test_ceedling/build/test/out;
1: (740) ->1005^done
1: (740) 1005: elapsed time 2
1: (740) ->(gdb)
1: (740) <-1006-environment-cd C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave
1: (740) ->&"\n"
1: (740) ->^done
1: (741) ->(gdb)
1: (742) ->1006^done
1: (742) 1006: elapsed time 1
1: (742) ->(gdb)
1: (743) ->&"\n"
1: (743) ->^done
1: (743) ->(gdb)
1: (747) <-1007-interpreter-exec console "show configuration"
1: (748) ->~"This GDB was configured as follows:\n   configure --host="
1: (748) ->~"x86_64-pc-msys --target=x86_64-pc-msys\n"
1: (748) ->~"             --with-auto-load-dir=$debugdir:$datadir/auto-load\n             --with-auto-load-safe-path="
1: (748) ->~"$debugdir:$datadir/auto-load\n"
1: (748) ->~"             --with-expat\n"
1: (749) ->~"             --with-gdb-datadir=/usr/share/gdb (relocatable)\n"
1: (749) ->~"             --with-jit-reader-dir=/usr/lib/gdb (relocatable)\n"
1: (749) ->~"             --without-libunwind-ia64\n"
1: (749) ->~"             --with-lzma\n"
1: (749) ->~"             --without-babeltrace\n"
1: (749) ->~"             --without-intel-pt\n"
1: (749) ->~"             --with-mpfr\n"
1: (749) ->~"             --without-xxhash\n"
1: (749) ->~"             --with-python=/usr (relocatable)\n"
1: (749) ->~"             --with-python-libdir=/usr/lib (relocatable)\n"
1: (750) ->~"             --without-debuginfod\n"
1: (750) ->~"             --without-guile\n"
1: (750) ->~"             --disable-source-highlight\n"
1: (750) ->~"             --with-separate-debug-dir=/usr/lib/debug (relocatable)\n"
1: (750) ->~"             --with-system-gdbinit=/etc/gdbinit\n"
1: (750) ->~"\n(\"Relocatable\" means the directory can be moved with the GDB installation\ntree, and GDB will still find it.)\n"
1: (750) ->1007^done
1: (750) ->(gdb)
1: (750) 1007: elapsed time 3
1: (751) ->&"\n"
1: (751) ->^done
1: (751) ->(gdb)
1: (752) <-1008-file-exec-and-symbols C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave/test_ceedling/build/test/out/foo.out
1: (770) ->1008^done
1: (770) ->(gdb)
1: (770) 1008: elapsed time 17
1: (770) ->&"\n"
1: (770) <-1009-interpreter-exec console "show architecture"
1: (770) ->^done
1: (770) ->(gdb)
1: (773) ->~"The target architecture is set to \"auto\" (currently \"i386:x86-64\").\n"
1: (773) ->1009^done
1: (773) 1009: elapsed time 2
1: (773) ->(gdb)
1: (773) ->&"\n"
1: (773) ->^done
1: (773) ->(gdb)
1: (774) <-1010-exec-arguments 2>CON 1>CON <CON
1: (777) ->1010^done
1: (777) 1010: elapsed time 2
1: (777) <-1011-break-insert -f main
1: (777) ->(gdb)
1: (777) ->&"\n"
1: (777) ->^done
1: (777) ->(gdb)
1: (783) ->1011^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000100401088",func="main",file=".\\test_ceedling\\test\\drivers_lin\\foo.c",fullname="/c/Checked_Out/PIC_Drivers/LIN_Master_Slave/test_ceedling/test/drivers_lin/foo.c",line="2",thread-groups=["i1"],times="0",original-location="main"}
1: (783) ->(gdb)
1: (783) ->&"\n"
1: (783) ->^done
1: (784) ->(gdb)
1: (791) 1011: elapsed time 14
1: (801) Send Event AD7EngineCreateEvent
1: (805) Send Event AD7ProgramCreateEvent
1: (838) ShellPid=3104
1: (870) DebuggerPid=67832
1: (913) <-1012-break-insert -f foo.c:3
1: (921) ->&"No source file named foo.c.\n"
1: (921) ->1012^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="foo.c:3",times="0",original-location="foo.c:3"}
1: (921) 1012: elapsed time 7
1: (921) ->(gdb)
1: (921) ->&"\n"
1: (921) ->^done
1: (921) ->(gdb)
1: (931) Send Event AD7BreakpointErrorEvent
1: (978) Send Event AD7LoadCompleteEvent
=thread-group-added,id="i1"
GNU gdb (GDB) 10.2
Copyright (C) 2021 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-pc-msys".
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"
1: (985) <-1013-exec-run
1: (990) ->1013^error,msg="Error creating process /usr/bin/C:\\\\Checked_Out\\\\PIC_Drivers\\\\LIN_Master_Slave/C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave/test_ceedling/build/test/out/foo.out, (error 2)."
1: (990) 1013: elapsed time 5
1: (990) ->(gdb)
1: (990) ->&"\n"
1: (990) ->^done
1: (990) ->(gdb)
1: (993) Send Event AD7MessageEvent
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Error creating process /usr/bin/C:\\Checked_Out\\PIC_Drivers\\LIN_Master_Slave/C:\Checked_Out\PIC_Drivers\LIN_Master_Slave/test_ceedling/build/test/out/foo.out, (error 2).
1: (1005) <--gdb-exit
1: (1006) ->^exit
1: (1015) Send Event AD7ProgramDestroyEvent
The program 'C:\Checked_Out\PIC_Drivers\LIN_Master_Slave\test_ceedling\build\test\out\foo.out' has exited with code 42 (0x0000002a).
1: (1021) Shell exited, stop debugging
WardenGnaw commented 3 years ago

Can confirm this reproduces on GDB 10.2 in MSYS2,

GDB 9.2 did not experience this problem.

Passing -file-exec-and-symbols /home/project/cpp/main.exe instead of -file-exec-and-symbols C:\msys2\home\project\cpp\main.exe resolved the issue.

Investigating.

WardenGnaw commented 3 years ago

Working on a fix at: https://github.com/microsoft/MIEngine/pull/1155

AcientYan commented 3 years ago

Working on a fix at: microsoft/MIEngine#1155

Hello, Sorry,I am new here. But my problem is very similar to this post. I am not sure it is polite to ask here. But I will appreciate it if you have time to help me.

I just begin to use visual studio code to program with C++. And my environment:

OS: Windows 10 VS Code Version: 1.60.1 C/C++ Extension Version: 1.6.0 GDB Version: (Cygwin 10.2-1) 10.2 G++ Version:11.2.0

And I got the following error message when debugging a hello world C++ program.

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Error creating process /usr/bin/d:\Programs\Projects\test/d:\Programs\Projects\test\test.exe, (error 2). The program 'd:\Programs\Projects\test\test.exe' has exited with code 42 (0x0000002a).

I did not post the full message. If I choose the option C++(windows) to create my launch.json file to debug, the program runs correctly but won't stop at breakpoints I set. And I know I should choose C++(GDB/GLLB) according to the official help websites. Then I got the above error message when I tried to debug.

I spent a lot of time on related websites and can not solve the problem on my own. I also updated my GDB to the latest version. The GDB was good because I verified it on the command line. (with "gdb --version")

leonardpin-br commented 2 years ago

Working on a fix at: microsoft/MIEngine#1155

Hello, Sorry,I am new here. But my problem is very similar to this post. I am not sure it is polite to ask here. But I will appreciate it if you have time to help me.

I just begin to use visual studio code to program with C++. And my environment:

OS: Windows 10 VS Code Version: 1.60.1 C/C++ Extension Version: 1.6.0 GDB Version: (Cygwin 10.2-1) 10.2 G++ Version:11.2.0

And I got the following error message when debugging a hello world C++ program.

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Error creating process /usr/bin/d:\Programs\Projects\test/d:\Programs\Projects\test\test.exe, (error 2). The program 'd:\Programs\Projects\test\test.exe' has exited with code 42 (0x0000002a).

I did not post the full message. If I choose the option C++(windows) to create my launch.json file to debug, the program runs correctly but won't stop at breakpoints I set. And I know I should choose C++(GDB/GLLB) according to the official help websites. Then I got the above error message when I tried to debug.

I spent a lot of time on related websites and can not solve the problem on my own. I also updated my GDB to the latest version. The GDB was good because I verified it on the command line. (with "gdb --version")

I am having the same issue with cygwin64 on Windows 10 and VSCode 1.61.2, trying to compile a test c program.

leonardpin-br commented 2 years ago

Based partially on @WardenGnaw answer in other thread, I got mine working. This is my own answer in another site: Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows (ERROR: Unable to start debugging) I hope it can help someone.

cppkeyboardman commented 2 years ago

Based partially on @WardenGnaw answer in other thread, I got mine working. This is my own answer in another site: Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows (ERROR: Unable to start debugging) I hope it can help someone.

Thank you, it works.

zergnick commented 2 years ago

Based partially on @WardenGnaw answer in other thread, I got mine working. This is my own answer in another site: Setting up VS Code for C using Cygwin64 Compiler and Debugger on Windows (ERROR: Unable to start debugging) I hope it can help someone.

It helps, thanks. I run into the same issue when I was trying to use a class from a hpp file on windows. After I checked the recommended launch file from the link, I found that I have missed contents in the "environment" part.

sean-mcmanus commented 2 years ago

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.8.0-insiders3 or 1.8.0 (via using VS Code's "Pre-Release Version" UI or https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools&ssr=false#version-history ).

sean-mcmanus commented 2 years ago

Looks like it's fixed in https://github.com/microsoft/vscode-cpptools/releases/tag/1.8.2 (not 1.8.0).

enigma1 commented 2 years ago

@sean-mcmanus I am not sure how you managed to make it work, but I still get the same problem both with the 1.8.2 and the pre-release 1.8.3. And I did restart vscode using 1.64.0

_ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000139.

Now that error seems to be program related and happens with the helloworld tutorial I checked. Removing the works fine. It could relate to MinGW and could be a separate issue, I am not sure let me know if you can see it. Just follow the steps shown in https://code.visualstudio.com/docs/cpp/config-mingw installing mingw with win10 and then try the tutorial. There was an older thread describing this problem

https://github.com/microsoft/vscode-cpptools/issues/1372

The last entry in that thread, points to that tutorial as a solution which actually if followed manifests this problem for me. Quite ironic.

sean-mcmanus commented 2 years ago

@WardenGnaw ?

WardenGnaw commented 2 years ago

Please open a new issue with additional information like engineLogging and traceRepsonse enabled in your launch.json.

enigma1 commented 2 years ago

Right, thanks. Before opening a new issue, I double checked if this problem happens outside vscode. So I ran gdb from the command line and I got the same error. Therefore I won't be opening a new here because it is not relevant.

AbleBacon commented 2 years ago

I can confirm that this issue persists with version v1.10.0 Pre-Release , using mingw-w64-x86_64-gdb version 11.2, but it is not due to Windows vs Unix paths as @WardenGnaw suggested. (In fact, if this fix was applied as @sean-mcmanus suggested, it has since been reverted because the current debugger engine still sends Windows paths to GDB/MI).

However, if you run a GDB/MI session and try sending the same commands that the C++ Extensions debugging engine sends (Windows paths and all)), debugging succeeds (you can try this with the MinGW setup tutorial: https://code.visualstudio.com/docs/cpp/config-mingw). The issue must be with the debugging engine not recognizing whatever output it's expecting from GDB/MI. Perhaps the debugging engine should consider other criteria besides this before prematurely terminating the debugging session?

I'd suggest re-opening this issue, or I can create a new one if that would be more appropriate.

soumesh2002 commented 2 years ago

same with GDB 11.2, in vscode gdb ignores my breakpoint

vittorioromeo commented 2 years ago

Having the same issue with the latest version of MSYS2/MinGW x64.

felix021 commented 2 years ago

Having the same issue on Windows 10 with:

WardenGnaw commented 2 years ago

For those still experiencing these issues, Please open a new issue with additional information like engineLogging and traceRepsonse enabled in your launch.json.