If you use a build path that contains spaces, setting the working directory of the executable will fail if you try to debug the program via the "Debug" button. This happens in both cases if the working directory is implicitly assumed to be the build directory or if you set it manually in Run -> Configure launches. Quote: the bug is that KDevelop uses single quotes instead of double quotes to escape the path. gdb needs double quotes Reproducible: Always Steps to Reproduce: 1. Create new project 2. Set build directory to a path with spaces e.g. "~/project x/build" 3. Configure Launch to start the executable, optionally set working directory to the build path 4. Build and run via "Debug" 5. Check cwd in /proc/$PID/cwd/ Actual Results: Working directory of the process is set to ~/ Expected Results: Working directory equals the build directory
Created attachment 88763 [details] probably related debug output of kdevelop "/home/nicolas/Dokumente/devel/C++/Lone Writer/build/" as build directory gdb expects double quotes, but path is given in single quotes, which only works when there are no spaces in the build path
I have now looked at it, and found where the problem occurs, but I'm not sure, which way it the right one to fix the problem. The quoting occurs in line 1040 debuggers/gdb/debugsession.cpp@master queueCmd(new GDBCommand(GDBMI::EnvironmentCd, KShell::quoteArg(dir.toLocalFile()))); (or line 1039 in the 4.7er branch, that uses QString instead of QUrl) KShell only does a single quote and doesn't escape spaces. That seems to be the right solution in some cases, so I should probably only do an in place quoting of dir.toLocalFile() with double quotes, right? Or should I check, if the path already contains double quotes and escape them? Or is the semantic of KShell::quoteArg() counter intuitive and should be changed? (Probably not, as it is used elsewhere) But basically the fix would be a one liner, what do you think about it?
I somehow doubt that the quoting is required here at all. This is a GDB console, and that is EOF delimited. So something like cd "foo" is not equivalent to cd foo (gdb) cd "/" "/": No such file or directory. (gdb) cd / Working directory /. Also one cannot inject commands by doing something like cd foo; someothercommand If at all that could happen when the file contains a newline, which can easily be checked. But maybe the above is different for the MI interface which we use in KDevelop. Needs to be checked, but I agree that KShell seems superfluous here.
Ah, I didn't notice, that kdevelop uses a different interface of gdb. Running some tests: (gdb) -environment-cd '/home/nicolas/Dokumente/devel/C++/Lone Writer/build/' ^error,msg="-environment-cd: Usage DIRECTORY" (gdb) -environment-cd /home/nicolas/Dokumente/devel/C++/Lone Writer/build/ ^error,msg="-environment-cd: Usage DIRECTORY" (gdb) -environment-cd "/home/nicolas/Dokumente/devel/C++/Lone Writer/build/" ^done (gdb) -environment-cd /home/nicolas/Dokumente/devel/C++/Lone\ Writer/build/ ^error,msg="-environment-cd: Usage DIRECTORY" So it only works, when putting the string in double quotes. I'll think of a patch, and I will send it in for review. Thank you for the fast response!
Sent in a review request (via review board). But I also have a patch for the 4.7 branch and I don't know, where to put it, so I'll post it here.
(In reply to Nicolas Werner from comment #5) > Sent in a review request (via review board). > > But I also have a patch for the 4.7 branch and I don't know, where to put > it, so I'll post it here. https://git.reviewboard.kde.org/r/121061/ (forgot the link...)
Created attachment 89497 [details] Proposed patch for 4.7.x
Git commit f455ae9f4305a3db66bd091318ee370d4a97a48f by Milian Wolff, on behalf of Nicolas Werner. Committed on 15/11/2014 at 20:10. Pushed by mwolff into branch '4.7'. Fix environment-cd for paths containing spaces. Problem: GDBMI only accepts paths containing spaces if they are in double quotes otherwise cd will fail. Solution: Add prepend and append double quotes to the dir string instead of using KShell::quoteArg. REVIEW: 121061 M +1 -1 debuggers/gdb/debugsession.cpp M +2 -0 debuggers/gdb/unittests/CMakeLists.txt M +21 -1 debuggers/gdb/unittests/gdbtest.cpp M +1 -0 debuggers/gdb/unittests/gdbtest.h A +2 -0 debuggers/gdb/unittests/path with space/CMakeLists.txt A +31 -0 debuggers/gdb/unittests/path with space/spacedebugee.cpp [License: LGPL (v2)] http://commits.kde.org/kdevelop/f455ae9f4305a3db66bd091318ee370d4a97a48f