Patch #3117 2011-01-15 09:16

etheranger

Correctly set CDB's working directory
Download
3117-Correctly_set.patch (1.9 KB)
Category
Application::Bugfix
Status
Out of date
Close date
2011-02-03 20:02
Assigned to
mortenmacfly
Index: src/plugins/debuggergdb/cdb_driver.cpp
===================================================================
--- src/plugins/debuggergdb/cdb_driver.cpp    (revision 6920)
+++ src/plugins/debuggergdb/cdb_driver.cpp    (working copy)
@@ -24,7 +24,8 @@
 static wxRegEx reFile(_T("[ \t]([A-z]+.*)[ \t]+\\[([A-z]:)(.*) @ ([0-9]+)\\]"));
 
 CDB_driver::CDB_driver(DebuggerGDB* plugin)
-    : DebuggerDriver(plugin)
+    : DebuggerDriver(plugin),
+    m_Debuggee(wxEmptyString)
 {
     //ctor
 }
@@ -62,6 +63,10 @@
     // finally, add the program to debug
     cmd << _T(' ') << debuggee;
 
+    // Because of the lack of ChDir functionality for a process which has already been launched,
+    // do a dodgy workaround by starting with a dummy version of the process, then starting in the right folder later.
+    m_Debuggee.assign(debuggee);
+
     if (!m_WorkingDir.IsEmpty())
         wxSetWorkingDirectory(m_WorkingDir);
 
@@ -104,7 +109,19 @@
 
 void CDB_driver::Prepare(ProjectBuildTarget* /*target*/, bool /*isConsole*/)
 {
-    // default initialization
+    if (!m_Debuggee.IsEmpty())
+    {
+        // Workaround for setting the correct working dir:
+        wxString cmd = _T(".kill; .createdir ");
+        cmd << m_WorkingDir;
+        QueueCommand(new DebuggerCmd(this,cmd)); // Kill the process and CD to the right place
+
+        cmd = _T(".create ");
+        cmd << m_Debuggee << _T("; g");
+        QueueCommand(new DebuggerCmd(this,cmd)); // Restart the process in the correct directory
+
+        m_Debuggee.Clear();
+    }
 }
 
 void CDB_driver::Start(bool /*breakOnEntry*/)
Index: src/plugins/debuggergdb/cdb_driver.h
===================================================================
--- src/plugins/debuggergdb/cdb_driver.h    (revision 6920)
+++ src/plugins/debuggergdb/cdb_driver.h    (working copy)
@@ -49,6 +49,7 @@
         virtual void ParseOutput(const wxString& output);
     protected:
     private:
+        wxString m_Debuggee;
 };
 
 #endif // CDB_DRIVER_H
etheranger 2011-01-15 09:18

Technically a problem with the debugger plugin launching ANY debugger from the project dir, rather than specified working dir, however GDB's behaviour happens to workaround this by resetting it after launch in GDB_driver::Prepare().

etheranger 2011-01-15 14:38

REWRITTEN:

Disregard the previous comment, the debugger needs to run from the current directory or else relative source/symbol paths stop working.

This more comes down to the complete lack of either starting CDB without a child process or changing the first child's working directory.

This patch creates a workaround by killing the first child before execution begins, and respawning the process in the right place. Not ideal, but better than not being able to debug it at all.

etheranger 2011-01-21 13:04

Aaand hopefully superseded by #3118, which has a bunch of other fixes, and a more managable version of this one.

If you'd like your app to run in the right directory /and/ work with breakpoints, asserts and the like, please use that one instead.