News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Code::Blocks debugger plugin and Cygwin

Started by cellulose, August 14, 2011, 10:15:55 PM

Previous topic - Next topic

cellulose

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.

QuoteBuilding 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.next.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.

oBFusCATed

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!]

cellulose

As per the fix mentioned you can probably just assume "/cygdrive" for that registry value.  I don't think very many people change that.

oBFusCATed

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!]

cellulose

#4
Actually that fix didn't seem to solve anything.  Reverting...

MortenMacFly

Quote from: cellulose 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.
Well, I changed it. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

gamert

when will this be fixed? I'm crazed by cygwin dbg... So I can only debug as this (http://forums.next.codeblocks.org/index.php/topic,15285.new.html#new)
Thank u.

oBFusCATed

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!]

bugshunter69

#8
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;
}

oBFusCATed

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!]

bugshunter69

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.

MortenMacFly

Quote from: bugshunter69 on January 14, 2012, 11:02:02 PM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

bugshunter69

#12
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.


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)

oBFusCATed

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!]

bugshunter69

Hi,
I realized that the previous patch doesn't work with MINGW's GDB (debuggger branch).

So I wrote a new one.

Bye
B.

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.