Summary: | JJ: kdevelop fails to set the working directory when debugging if the path contains spaces | ||
---|---|---|---|
Product: | [Applications] kdevelop | Reporter: | Nicolas Werner <nicolas.werner> |
Component: | CPP Debugger | Assignee: | kdevelop-bugs-null |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | nicolas.werner, niko.sams |
Priority: | NOR | ||
Version: | 4.7.0 | ||
Target Milestone: | --- | ||
Platform: | openSUSE | ||
OS: | Linux | ||
URL: | https://forum.kde.org/viewtopic.php?f=218&t=122931 | ||
Latest Commit: | http://commits.kde.org/kdevelop/f455ae9f4305a3db66bd091318ee370d4a97a48f | Version Fixed In: | |
Sentry Crash Report: | |||
Attachments: |
probably related debug output of kdevelop
Proposed patch for 4.7.x |
Description
Nicolas Werner
2014-09-20 12:54:51 UTC
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 |