Patch #3118 2011-01-16 04:33

etheranger

Multiple bugfixes for CDB driver
Download
3118-Multiple_bugfi.patch (8.7 KB)
Category
Application::Bugfix
Status
Out of date
Close date
2011-02-03 20:02
Assigned to
mortenmacfly
Index: src/plugins/debuggergdb/cdb_commands.h
===================================================================
--- src/plugins/debuggergdb/cdb_commands.h    (revision 6930)
+++ src/plugins/debuggergdb/cdb_commands.h    (working copy)
@@ -16,6 +16,7 @@
 #include "debuggertree.h"
 #include "backtracedlg.h"
 
+static wxRegEx reProcessInf(_T("id:[ \t]+([A-Fa-f0-9]+)[ \t]+create"));
 static wxRegEx reWatch(_T("(\\+0x[A-Fa-f0-9]+ )"));
 static wxRegEx reBT1(_T("([0-9]+) ([A-Fa-f0-9]+) ([A-Fa-f0-9]+) ([^[]*)"));
 static wxRegEx reBT2(_T("\\[([A-z]:)(.*) @ ([0-9]+)\\]"));
@@ -174,6 +175,40 @@
 };
 
 /**
+  * Command to find the PID of the active child
+  */
+  class CdbCmd_GetPID : public DebuggerCmd
+{
+    public:
+        /** @param file The file to debug. */
+        CdbCmd_GetPID(DebuggerDriver* driver)
+            : DebuggerCmd(driver)
+        {
+            m_Cmd << _T("|.");
+        }
+        void ParseOutput(const wxString& output)
+        {
+            // Output:
+            // <decimal process num> id: <hex PID> create name: <process name>
+            wxArrayString lines = GetArrayFromString(output, _T('\n'));
+            for (unsigned int i = 0; i < lines.GetCount(); ++i)
+            {
+                if (reProcessInf.Matches(lines[i]))
+                {
+                    wxString hexID = reProcessInf.GetMatch(lines[i],1);
+
+                    long pid;
+                    if (hexID.ToLong(&pid,16))
+                    {
+                        m_pDriver->SetChildPID(pid);
+                    }
+                }
+            }
+        }
+};
+
+
+/**
   * Command to add a breakpoint.
   */
 class CdbCmd_AddBreakpoint : public DebuggerCmd
Index: src/plugins/debuggergdb/cdb_driver.cpp
===================================================================
--- src/plugins/debuggergdb/cdb_driver.cpp    (revision 6930)
+++ src/plugins/debuggergdb/cdb_driver.cpp    (working copy)
@@ -15,8 +15,11 @@
 #include <globals.h>
 #include <infowindow.h>
 
-#define CDB_PROMPT _T("0:000>")
+#define ENABLE_WORKINGDIR_WORKAROUND
+#define CDB_STACKTRACE _T("ChildEBP")
+#define CDB_FRAMESWITCH _T("CBFrameSwitch")
 
+static wxRegEx rePrompt(_T("([0-9]+:){1,2}[0-9]+>"));
 static wxRegEx reBP(_T("Breakpoint ([0-9]+) hit"));
 // one stack frame (to access current file; is there another way???)
 //  # ChildEBP RetAddr
@@ -24,7 +27,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
 }
@@ -63,8 +67,16 @@
     cmd << _T(' ') << debuggee;
 
     if (!m_WorkingDir.IsEmpty())
+    {
         wxSetWorkingDirectory(m_WorkingDir);
 
+#ifdef ENABLE_WORKINGDIR_WORKAROUND
+        // 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);
+#endif
+    }
+
     return cmd;
 }
 
@@ -104,7 +116,28 @@
 
 void CDB_driver::Prepare(ProjectBuildTarget* /*target*/, bool /*isConsole*/)
 {
-    // default initialization
+    // CDB outputs a lot of spam to begin with, which mucks up output parsing without a dummy command first
+    m_QueueBusy = true;
+    QueueCommand(new DebuggerCmd(this,_T(".echo Clear initial spam")));
+
+#ifdef ENABLE_WORKINGDIR_WORKAROUND
+    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();
+    }
+#endif
+
+    // Either way, get the PID of the child
+    QueueCommand(new CdbCmd_GetPID(this));
 }
 
 void CDB_driver::Start(bool /*breakOnEntry*/)
@@ -179,9 +212,11 @@
     QueueCommand(new CdbCmd_InfoRegisters(this, m_pCPURegisters));
 }
 
-void CDB_driver::SwitchToFrame(size_t /*number*/)
+void CDB_driver::SwitchToFrame(size_t number)
 {
-    NOT_IMPLEMENTED();
+    wxString cmd = _T(".echo "); // Echo in our trace token to tell ParseOutput to update the frame.
+    cmd << CDB_FRAMESWITCH << _T("; .frame ") << number;
+    QueueCommand(new DebuggerCmd(this, cmd));
 }
 
 void CDB_driver::SetVarValue(const wxString& /*var*/, const wxString& /*value*/)
@@ -268,26 +303,32 @@
 {
     m_Cursor.changed = false;
     static wxString buffer;
+
     buffer << output << _T('\n');
 
     m_pDBG->DebugLog(output);
 
-    int idx = buffer.First(CDB_PROMPT);
-    if (idx != wxNOT_FOUND)
-    {
+    if (rePrompt.Matches(buffer))
+    {
+        int idx = buffer.First(rePrompt.GetMatch(buffer));
+        cbAssert(idx != wxNOT_FOUN
download for full patch...
etheranger 2011-01-16 04:47

Internal changes:

+ Fix output parsing being one command out due to output spam at CDB's launch

+ Fix command prompt recognition

+ Find the debuggee's PID on launch so that the IDE can break / halt execution cleanly.

Resultant functionality fixes:

+ Recognise and update UI on code breakpoints (assert / asm int 3 / etc)

+ Enable setting / unsetting breakpoints on the fly

+ Support stack frame switching while broken (works a treat with Patch #3112!)

This includes Patch #3117, but that workaround functionality can be disabled by commenting out by #undefining ENABLE_WORKINGDIR_WORKAROUND.

tpetrov 2011-01-16 15:06

Is this against trunk or against debuggers branch?

If it is against trunk can you redo your patch for the branch?

There are many changes related to the debugger in this branch.

Also the CDB support is improved (I think).

etheranger 2011-01-17 02:17

It's against trunk, I just wanted to get a stable-ish build up and running for my use.

I'll take a look at the debugger branch next time I get a chance (in a week or so).