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

Offline cellulose

  • Multiple posting newcomer
  • *
  • Posts: 20
Code::Blocks debugger plugin and Cygwin
« on: August 14, 2011, 10:15:55 pm »
Hello again.  I'm having some weird issues with my debugger; I learned they've been documented before, if not necessarily fixed.  Again, I'm still using the "official" 10.05 release.

Quote
Building to ensure sources are up-to-date
Build succeeded
Selecting target:
Debug
Adding source dir: C:\projects\cpp\contracts\CaveStory\
Adding source dir: C:\projects\cpp\contracts\CaveStory\
Adding file: bin\Debug\CaveStory+.exe
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.8.0.20080328-cvs (cygwin-special)
Warning: /cygdrive/c/projects/cpp/contracts/CaveStory/C: No such file or directory.
Child process PID: 9648
Program exited with code 030000000471.
Debugger finished with status 0

This doesn't render the debugger nonfunctional but seems to make it situationally less helpful.  On one occasion there was an apparent failure to start the application, though it may have been something else.  Anyway, it's well documented in this thread from last year:

http://forums.codeblocks.org/index.php/topic,12212.0.html

If a fix isn't in yet, one would be appreciated.  I'll probably use the workaround they mention for the time being.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #1 on: August 14, 2011, 10:19:37 pm »
It is on the todo, but I guess it won't happen soon, I've never used cygwin and I'm mostly using linux...
(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 cellulose

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Code::Blocks debugger plugin and Cygwin
« Reply #2 on: August 14, 2011, 10:23:34 pm »
As per the fix mentioned you can probably just assume "/cygdrive" for that registry value.  I don't think very many people change that.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #3 on: August 14, 2011, 10:31:17 pm »
Patches welcome. Keep in mind that all development related to the debugger happens in the wxpropgrid_debugger branch.
(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 cellulose

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Code::Blocks debugger plugin and Cygwin
« Reply #4 on: August 14, 2011, 10:53:45 pm »
Actually that fix didn't seem to solve anything.  Reverting...
« Last Edit: August 14, 2011, 10:56:54 pm by cellulose »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code::Blocks debugger plugin and Cygwin
« Reply #5 on: August 15, 2011, 07:22:52 am »
As per the fix mentioned you can probably just assume "/cygdrive" for that registry value.  I don't think very many people change that.
Well, I changed it. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline gamert

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code::Blocks debugger plugin and Cygwin
« Reply #6 on: September 24, 2011, 08:02:40 am »
when will this be fixed? I'm crazed by cygwin dbg... So I can only debug as this (http://forums.codeblocks.org/index.php/topic,15285.new.html#new)
Thank u.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #7 on: September 25, 2011, 12:15:43 am »
No cygwin env and I have no plans to install one.
So patches welcome if you're interested in this feature.
Keep in mind that the patch should be against the wxpropgrid_debugger branch (aka debugger_branch)!
(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 #8 on: January 04, 2012, 02:03:18 pm »
Hello all,
I have a fix for "unable to make breapoints usable in CYGWIN",  ;) just modify this method in GDB_driver class :
void GDB_driver::AddBreakpoint(DebuggerBreakpoint* bp)
{
   wxString SaveFileName(bp->filename);
    if(platform::windows && m_CygwinPresent==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));
    }
    //Workaround for GDB to break on C++ constructor/destructor
    else
    {
        if (bp->func.IsEmpty() && !bp->lineText.IsEmpty())
        {
            wxRegEx reCtorDtor(_T("([0-9A-z_]+)::([~]?)([0-9A-z_]+)[ \t\(]*"));
            if (reCtorDtor.Matches(bp->lineText))
            {
                wxString strBase = reCtorDtor.GetMatch(bp->lineText, 1);
                wxString strDtor = reCtorDtor.GetMatch(bp->lineText, 2);
                wxString strMethod = reCtorDtor.GetMatch(bp->lineText, 3);
                if (strBase.IsSameAs(strMethod))
                {
                    bp->func = strBase;
                    bp->func << _T("::");
                    bp->func << strDtor;
                    bp->func << strMethod;
    //                if (bp->temporary)
    //                    bp->temporary = false;
                    NotifyCursorChanged(); // to force breakpoints window update
                }
            }
        }
        //end GDB workaround

        QueueCommand(new GdbCmd_AddBreakpoint(this, bp));
    }
   bp->filename = SaveFileName;
}
« Last Edit: January 04, 2012, 02:08:05 pm by bugshunter69 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #9 on: January 04, 2012, 02:29:08 pm »
Your post is totally unreadable.
Please use svn diff to generate a patch file and make sure you've used the debugger branch otherwise you're just wasting your time...

See this http://wiki.codeblocks.org/index.php?title=Creating_a_patch_to_submit_to_BerliOS_%28Patch_Tracker%29 for details how to make a patch file.

And please use code tags
(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 #10 on: January 14, 2012, 11:02:02 pm »
Ok, :o
thank you, but I don't want to contribute to Code::Blocks.

I'm sorry, it was only a simple modification to make debugger usable under cygwin.

If someone will needs the patch file 'gdb_driver.cpp.patch' (unified diff format) I send to him.

I checked out the sources from 'svn://svn.berlios.de/codeblocks/trunk' the revision 7663 and I think that no one modified (patched) for our problem!

Bye
B.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code::Blocks debugger plugin and Cygwin
« Reply #11 on: January 15, 2012, 09:56:29 am »
If someone will needs the patch file 'gdb_driver.cpp.patch' (unified diff format) I send to him.
Please post it as "svn diff" here, using code tags and (at best) applied against debugger branch. That would be nice.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline bugshunter69

  • Single posting newcomer
  • *
  • Posts: 6
Re: Code::Blocks debugger plugin and Cygwin
« Reply #12 on: January 17, 2012, 01:17:38 pm »
MortenMacFly,
this is "svn diff" against "debugger branch" (svn://svn.berlios.de/codeblocks/branches/wxpropgrid_debugger).

In "debugger branch" I saw that breakpoints works (without this patch) fine also in cygwin.

But, I hope will be useful.

Bye
B.

Code
Index: gdb_driver.cpp
===================================================================
--- gdb_driver.cpp (revision 7698)
+++ gdb_driver.cpp (working copy)
@@ -670,6 +670,27 @@
 
 void GDB_driver::AddBreakpoint(DebuggerBreakpoint::Pointer bp)
 {
+    wxString SaveFileName(bp->filename);
+    if(platform::windows && m_CygwinPresent==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 +722,7 @@
 
         QueueCommand(new GdbCmd_AddBreakpoint(this, bp));
     }
+    bp->filename = SaveFileName;
 }
 
 void GDB_driver::RemoveBreakpoint(DebuggerBreakpoint::Pointer bp)
« Last Edit: January 17, 2012, 04:49:24 pm by bugshunter69 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Code::Blocks debugger plugin and Cygwin
« Reply #13 on: January 17, 2012, 01:42:10 pm »
Anyone with cygwin and problems with breakpoints willing to test this patch?
(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 #14 on: January 17, 2012, 08:03:18 pm »
Hi,
I realized that the previous patch doesn't work with MINGW's GDB (debuggger branch).

So I wrote a new one.

Bye
B.

Code
Index: gdb_driver.cpp
===================================================================
--- gdb_driver.cpp (revision 7698)
+++ 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),
@@ -223,6 +225,19 @@
     if(platform::windows)
         DetectCygwinMount();
 
+    // log GDB's target
+    wxString cmdexe;
+    cmdexe = m_pDBG->GetActiveConfigEx().GetDebuggerExecutable();
+    if (cmdexe.Lower().Contains(_T("mingw")))
+        m_GDBTargetIsMingw32 = true;
+    if (cmdexe.Lower().Contains(_T("cygwin")))
+    {
+        m_GDBTargetIsCygwin = true;
+        if (m_CygwinPresent == false)
+            m_CygdrivePrefix = _T("/cygdrive/");
+
+    }
+
     // make sure we 're using the prompt that we know and trust ;)
     QueueCommand(new DebuggerCmd(this, wxString(_T("set prompt ")) + FULL_GDB_PROMPT));
 
@@ -670,6 +685,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 +737,7 @@
 
         QueueCommand(new GdbCmd_AddBreakpoint(this, bp));
     }
+    bp->filename = SaveFileName;
 }
 
 void GDB_driver::RemoveBreakpoint(DebuggerBreakpoint::Pointer bp)
Index: gdb_driver.h
===================================================================
--- gdb_driver.h (revision 7698)
+++ 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: 13413
    • 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
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: 13413
    • 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.