Author Topic: Code::Blocks debugger plugin and Cygwin  (Read 13604 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12122
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #15 on: January 17, 2012, 08:37:41 pm »
The last patch doesn't look good at all.
There is no guarantee, that the executable path will contain mingw.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline bugshunter69

  • Single posting newcomer
  • *
  • Posts: 6
Re: Code::Blocks debugger plugin and Cygwin
« Reply #16 on: January 18, 2012, 12:19:42 am »
oBFusCATed,
it's true, then I propose this one that parse "gdb --version" ouput to set "m_GDBTargetIsCygwin" or "m_GDBTargetIsMingw32" variable.

Bye
B.

Code: [Select]
Index: src/plugins/debuggergdb/gdb_driver.cpp
===================================================================
--- src/plugins/debuggergdb/gdb_driver.cpp (revision 7698)
+++ src/plugins/debuggergdb/gdb_driver.cpp (working copy)
@@ -87,6 +87,8 @@
 GDB_driver::GDB_driver(DebuggerGDB* plugin)
     : DebuggerDriver(plugin),
     m_CygwinPresent(false),
+    m_GDBTargetIsCygwin(false),
+    m_GDBTargetIsMingw32(false),
     m_BreakOnEntry(false),
     m_ManualBreakOnEntry(false),
     m_IsStarted(false),
@@ -670,6 +672,27 @@
 
 void GDB_driver::AddBreakpoint(DebuggerBreakpoint::Pointer bp)
 {
+    wxString SaveFileName(bp->filename);
+    if(platform::windows && m_GDBTargetIsMingw32==false && m_GDBTargetIsCygwin==true)
+    {
+        wxString FileName(bp->filename);
+
+        if (FileName.GetChar(1) == _T(':'))
+        {
+            wxString m_CygdrivePrefixNormalized;
+            if (m_CygdrivePrefix.EndsWith(_T("/"))) // for the case   "/cygdrive/"
+              m_CygdrivePrefixNormalized = m_CygdrivePrefix;
+            else                                    // for cases e.g. "/cygdrive"
+              m_CygdrivePrefixNormalized = m_CygdrivePrefix + _T("/");
+            // replace drive letter with cygwin prefix and adding the drive label back
+            if (FileName.GetChar(2) == _T('/'))
+                FileName.Replace(FileName.Left(1) + _T(":") + _T("/"), m_CygdrivePrefixNormalized + FileName.Left(1).Lower() + _T("/"), false);
+            else
+                FileName.Replace(FileName.Left(1) + _T(":"), m_CygdrivePrefixNormalized + FileName.Left(1).Lower() + _T("/"), false);
+
+        }
+        bp->filename = FileName;
+    }
     if (bp->type == DebuggerBreakpoint::bptData)
     {
         QueueCommand(new GdbCmd_AddDataBreakpoint(this, bp));
@@ -701,6 +724,7 @@
 
         QueueCommand(new GdbCmd_AddBreakpoint(this, bp));
     }
+    bp->filename = SaveFileName;
 }
 
 void GDB_driver::RemoveBreakpoint(DebuggerBreakpoint::Pointer bp)
@@ -874,6 +898,25 @@
             CorrectCygwinPath(lines.Item(i));
         }
 
+        // log GDB's target
+        if (lines[i].StartsWith(_T("This GDB was configured as ")))
+        {
+            if (lines[i].Lower().Contains(_T("mingw")))
+            {
+                m_GDBTargetIsMingw32 = true;
+                m_pDBG->GetState().ApplyBreakpoints();
+
+            }
+            else
+            if (lines[i].Lower().Contains(_T("cygwin")))
+            {
+                m_GDBTargetIsCygwin = true;
+                if (m_CygwinPresent == false)
+                    m_CygdrivePrefix = _T("/cygdrive/");
+                m_pDBG->GetState().ApplyBreakpoints();
+            }
+        }
+        else
         // log GDB's version
         if (lines[i].StartsWith(_T("GNU gdb")))
         {
@@ -901,7 +944,7 @@
 //                        minor.c_str(),
 //                        m_GDBVersionMinor);
 //            m_pDBG->Log(log);
-            break;
+            //break;
         }
 
         // Is the program exited?
Index: src/plugins/debuggergdb/gdb_driver.h
===================================================================
--- src/plugins/debuggergdb/gdb_driver.h (revision 7698)
+++ src/plugins/debuggergdb/gdb_driver.h (working copy)
@@ -105,6 +105,9 @@
         bool m_CygwinPresent;
         wxString m_CygdrivePrefix;
 
+        bool m_GDBTargetIsCygwin;
+        bool m_GDBTargetIsMingw32;
+
         TypesArray m_Types;
 
         // Seems to be intended to allow step before program has started.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12122
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #17 on: January 18, 2012, 01:03:27 am »
This is another wrong version of the patch. You just have to add an option in the settings :)
But don't worry, too much for it, I'll do it for you:)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline bugshunter69

  • Single posting newcomer
  • *
  • Posts: 6
Re: Code::Blocks debugger plugin and Cygwin
« Reply #18 on: January 18, 2012, 01:11:44 am »
Ok, ;)
thank you, I don't know how to make it.

B.