eclipse-cdt / cdt

Eclipse CDT™ C/C++ Development Tools
http://eclipse.org/cdt
Eclipse Public License 2.0
299 stars 198 forks source link

Debugging failed on Windows when using MSYS2 or Cygwin #228

Open wdtj opened 1 year ago

wdtj commented 1 year ago

Describe the bug I installed EclipseCDT 2022-12, created the HelloWorld example app, compiled, but when I debug I get an error. I have both current MSYS2 (MinGW64) and Cygwin64 installed, neither environment works and fails with the same error:

Error in final launch sequence:

Failed to execute MI command: -exec-run Error message from debugger back end: Error creating process /cygdrive/c/Windows/system32/C:/Projects/cc3135/hello/C:/Projects/cc3135/hello/Debug/hello.exe, (error 2). Failed to execute MI command: -exec-run Error message from debugger back end: Error creating process /cygdrive/c/Windows/system32/C:/Projects/cc3135/hello/C:/Projects/cc3135/hello/Debug/hello.exe, (error 2). Error creating process /cygdrive/c/Windows/system32/C:/Projects/cc3135/hello/C:/Projects/cc3135/hello/Debug/hello.exe, (error 2).

To Reproduce See above.

Expected behavior Should run Cygwin or MSYS GDB.

Screenshots Error message copied above

Desktop (please complete the following information):

Additional context More information here: https://stackoverflow.com/questions/74892494/eclipsecdt-will-not-debug-executable-error-creating-process and the bypass suggested here: https://www.eclipse.org/forums/index.php?t=msg&th=1105969&goto=1847401&#msg_1847401

wdtj commented 1 year ago

The program under test (hello world) works fine under command shells and when running (not debugging) with Eclipse.

jonahgraham commented 1 year ago

For starters, thank you for reporting the problem. From your links I can see there has been discussion on the user forums for a while, but this seems to be the first entry in the bug tracker. Of course it is holiday season now, so response times will be quite slow.

Seeing as you have reported GDB 9.x as working and GDB 10.x/11.x as failing it seems like something has changed on the GDB side that we need to take into account.

Can you provide the MI traces of the problem? If you don't want to reinstall the broken GDB, please just provide the GDB 9.x traces as the command we send to GDB will be the same in GDB 9 and 11 anyway.

chgenly commented 1 year ago

001,041 2-gdb-version 001,045 3-list-thread-groups 001,053 ~"GNU gdb (GDB) (Cygwin 11.2-1) 11.2\n" 001,053 ~"Copyright (C) 2022 Free Software Foundation, Inc.\n" 001,053 ~"License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html\nThis is fre\ e software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitt\ ed by law." 001,054 ~"\nType \"show copying\" and \"show warranty\" for details.\n" 001,054 ~"This GDB was configured as \"x86_64-pc-cygwin\".\n" 001,054 ~"Type \"show configuration\" for configuration details.\n" 001,054 ~"For bug reporting instructions, please see:\n" 001,054 ~"https://www.gnu.org/software/gdb/bugs/.\n" 001,054 ~"Find the GDB manual and other documentation resources online at:\n http://www.gnu.org/\ software/gdb/documentation/." 001,054 ~"\n\n" 001,054 ~"For help, type \"help\".\n" 001,054 ~"Type \"apropos word\" to search for commands related to \"word\".\n" 001,054 2^done 001,055 (gdb) 001,055 3^done,groups=[{id="i1",type="process"}] 001,059 (gdb) 001,062 4-environment-cd C:/coherent/tot_layout_editor/runtime-hxisde.feature.product/aaa 001,069 4^done 001,069 (gdb) 001,073 5-gdb-set breakpoint pending on 001,085 5^done 001,085 (gdb) 001,090 6-gdb-set detach-on-fork on 001,101 6^done 001,101 (gdb) 001,102 7-enable-pretty-printing 001,117 7^done 001,117 (gdb) 001,119 8-gdb-set python print-stack none 001,133 8^done 001,133 (gdb) 001,135 9-gdb-set print object on 001,149 9^done 001,149 (gdb) 001,152 10-gdb-set print sevenbit-strings on 001,165 10^done 001,165 (gdb) 001,166 11-gdb-set host-charset UTF-8 001,181 11^done 001,181 (gdb) 001,182 12-gdb-set target-charset UTF-8 001,197 12^done 001,197 (gdb) 001,198 13-gdb-set target-wide-charset UTF-16 001,212 13^done 001,212 (gdb) 001,214 14-gdb-set dprintf-style call 001,227 14^done 001,227 (gdb) 001,232 15source .gdbinit 001,243 &"source .gdbinit\n" 001,244 &".gdbinit: No such file or directory.\n" 001,244 15^error,msg=".gdbinit: No such file or directory." 001,244 (gdb) 001,249 16-gdb-set mi-async off 001,259 16^done 001,259 (gdb) 001,262 17-gdb-set record full stop-at-limit off 001,274 17^done 001,274 (gdb) 001,275 18-gdb-set auto-solib-add on 001,289 18^done 001,289 (gdb) 001,297 19-file-exec-and-symbols --thread-group i1 C:/coherent/tot_layout_editor/runtime-hxisde.feat\ ure.product/aaa/Debug/aaa.exe 001,315 19^done 001,315 (gdb) 001,318 20-gdb-show --thread-group i1 language 001,320 20^done,value="auto" 001,320 (gdb) 001,321 21-gdb-set --thread-group i1 language c 001,335 21^done 001,335 (gdb) 001,337 22-interpreter-exec --thread-group i1 console "p/x (char)-1" 001,351 ~"$1 = 0xff\n" 001,351 22^done 001,352 (gdb) 001,353 23-data-evaluate-expression --thread-group i1 "sizeof (void*)" 001,367 23^done,value="8" 001,368 (gdb) 001,371 24-gdb-set --thread-group i1 language auto 001,382 24^done 001,382 (gdb) 001,383 25-interpreter-exec --thread-group i1 console "show endian" 001,397 ~"The target endianness is set automatically (currently little endian).\n" 001,397 25^done 001,397 (gdb) 001,402 26-break-insert -t -f main 001,419 26^done,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0000000100401088",\ func="main",file="../src/aaa.c",fullname="/cygdrive/c/coherent/tot_layout_editor/runtime-hxisde.feat\ ure.product/aaa/src/aaa.c",line="14",thread-groups=["i1"],times="0",original-location="main"} 001,420 (gdb) 001,453 27-exec-run --thread-group i1 001,460 27^error,msg="Error creating process /cygdrive/c/coherent/tot_layout_editor/src/C:/coherent/\ tot_layout_editor/runtime-hxisde.feature.product/aaa/C:/coherent/tot_layout_editor/runtime-hxisde.fe\ ature.product/aaa/Debug/aaa.exe, (error 2)." 001,460 (gdb) 001,468 28-gdb-exit 001,475 28^exit

jonahgraham commented 1 year ago

All indications in this log is that the bug is on GDB side not CDT. Not even sure how we could workaround it in CDT.

This line passes the EXE to GDB

001,297 19-file-exec-and-symbols --thread-group i1 C:/coherent/tot_layout_editor/runtime-hxisde.feat
ure.product/aaa/Debug/aaa.exe

Which has worked fine because GDB is able to insert a breakpoint at main and report back where that breakpoint is:

001,402 26-break-insert -t -f main
001,419 26^done,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0000000100401088",
func="main",file="../src/aaa.c",fullname="/cygdrive/c/coherent/tot_layout_editor/runtime-hxisde.feat
ure.product/aaa/src/aaa.c",line="14",thread-groups=["i1"],times="0",original-location="main"}

But when CDT tells GDB to run, GDB falls over:

001,453 27-exec-run --thread-group i1
001,460 27^error,msg="Error creating process /cygdrive/c/coherent/tot_layout_editor/src/C:/coherent/
tot_layout_editor/runtime-hxisde.feature.product/aaa/C:/coherent/tot_layout_editor/runtime-hxisde.fe
ature.product/aaa/Debug/aaa.exe, (error 2)."

It looks like GDB has different code in different code paths for handling the path.

chgenly commented 1 year ago

Thanks, jonahgraham. I agree. wdtj, would you please file a bug with gdb?

jonahgraham commented 1 year ago

I don't have a cygwin setup. So I can't test/reproduce the bug. To file a bug with GDB someone needs to make a small reproducible test case that doesn't involve CDT. I may be able to find time at some point to do that, but to be upfront it isn't a high priority for me.

chgenly commented 1 year ago

I'll submit the bug.

chgenly commented 1 year ago

Bug 30017 - Cygwin gdb fails when given a windows absolute path https://sourceware.org/bugzilla/show_bug.cgi?id=30017

jonahgraham commented 1 year ago

Thank you for submitting the bug.

homacs commented 1 year ago

I was wondering if this is related to cygwin or msys2, rather than gdb, since they provide the windows builds, and posted the issue on the cygwin mailing list. This is the answer:

While in many cases, Cygwin executable may work with Windows paths OOTB, this kind of interoperability is not guaranteed or even promised. Cygwin is "a kind of POSIX" and expectation is that it works with POSIX paths.

And BTW: gdb-11.2 shipped with mingw-builds can handle windows' absolute paths.

jonahgraham commented 1 year ago

Thanks @homacs, can you post a link if possible?

Either Eclipse CDT or Cygwin/gdb are going to have to make a change here. I guess from the comments on the mailing list and the comment on the bugzilla, no one at Cygwin or gdb are going to fix this for us, so the change has to be in CDT to be careful when using absolute paths and Cygwin together.

I guess a whole bunch of code needs to be checked that may do absolute paths and then convert them to the equivalent cygwin path by calling cygpath in the same environment.

For the immediate case of the executable passed to gdb, modifying LaunchUtils.resolveProgramPath with reference to how cygpath is used elsewhere in CDT may be the best starting point (e.g. CygpathTranslator).

PRs welcome for CDT.

jonahgraham commented 1 year ago

And BTW: gdb-11.2 shipped with mingw-builds can handle windows' absolute paths.

This is an important note, most of the tool vendors that build on top of CDT ship mingw versions of GDB or recommend such versions.

jld01 commented 1 year ago

A couple of observations:

I wonder if Cygwin/MSYS2 gcc might also stop supporting Windows-style file paths in the future.