Author Topic: Problem with debug  (Read 6556 times)

Offline InddZen

  • Multiple posting newcomer
  • *
  • Posts: 16
Problem with debug
« on: March 13, 2007, 10:00:18 pm »
Hi all,

I'm working under windows using the 11th march build.
I've some problems while trying to debug my project (console application in c++) using "run to cursor" or a breakpoint.
First, it seems that the debugger don't stop where I want.
Second it gives me the following message, knowing that my program run usually without problem, specially with the function cited in the message "operator *()()":

Code
Building to ensure sources are up-to-date
Build succeeded
Selecting target: default
Adding source dir: D:\cfdproject\
Adding source dir: D:\cfdproject\
Adding file: cfdproject.exe
Starting debugger: done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
(no debugging symbols found)
Debugger name and version: GNU gdb 6.3

Child process PID: 2964
Program received signal SIGSEGV, Segmentation fault.
In operator* () ()
Debugger finished with status 0

So does anyone have an idea about this problem????
And thanx in advance...

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2775
Re: Problem with debug
« Reply #1 on: March 13, 2007, 10:53:54 pm »
Hi all,

I'm working under windows using the 11th march build.
I've some problems while trying to debug my project (console application in c++) using "run to cursor" or a breakpoint.
First, it seems that the debugger don't stop where I want.
Second it gives me the following message, knowing that my program run usually without problem, specially with the function cited in the message "operator *()()":

Code
Building to ensure sources are up-to-date
Build succeeded
Selecting target: default
Adding source dir: D:\cfdproject\
Adding source dir: D:\cfdproject\
Adding file: cfdproject.exe
Starting debugger: done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
(no debugging symbols found)
Debugger name and version: GNU gdb 6.3

Child process PID: 2964
Program received signal SIGSEGV, Segmentation fault.
In operator* () ()
Debugger finished with status 0

So does anyone have an idea about this problem????
And thanx in advance...

The message "(no debugging symbols found) " means that you compiled your project without turning on the -g flag to create debugging data.

Go to project settings and check the "produce debugging symbols" option.

Offline InddZen

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debug
« Reply #2 on: March 14, 2007, 12:22:45 am »
Thanx, I didn't get any message or error after setting the option as u told me...
But the debugger still don't want to stop in the cursor or in the breakpoint level  :?
It's like a normal execution.
« Last Edit: March 14, 2007, 12:25:24 am by InddZen »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2775
Re: Problem with debug
« Reply #3 on: March 14, 2007, 01:02:07 am »
Create a minimal source that causes the problem
Set:

   //-- Full Compile Logging --
   "Settings" -> "Compiler and Debugger"
   "Global Compiler Setting"
   "Other Settings"
   "compiler logging:" set to "Full Command Line"

Paste the compiler output here, and paste the minimal program source with step by step instructions on how to re-create the problem.

Offline InddZen

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debug
« Reply #4 on: March 14, 2007, 02:17:05 am »
Thanks for fast replies.

But maybe mine wasn't enough clear...

My program is working, neither bugs nor problems, but instead of printing in the screen all the datas I would like to control I prefer to run debug with a run to cursor and watch step by step the evolution.
That's what I was used to do using VC++ few years ago.

But it seems that it doesn't work. Maybe I need to select other settings but I don't know where or how.

dr snuggles

  • Guest
Re: Problem with debug
« Reply #5 on: March 14, 2007, 10:57:41 am »

My program is working, neither bugs nor problems, but instead of printing in the screen all the datas I would like to control I prefer to run debug with a run to cursor and watch step by step the evolution.
That's what I was used to do using VC++ few years ago.

But it seems that it doesn't work. Maybe I need to select other settings but I don't know where or how.
I think what Pecan ment was: If you change the settings according to Pecan's post, you will get a better log file. If you post this log file, Pecan can assist you better :).

Offline InddZen

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debug
« Reply #6 on: March 15, 2007, 11:11:39 am »
Create a minimal source that causes the problem
Set:

   //-- Full Compile Logging --
   "Settings" -> "Compiler and Debugger"
   "Global Compiler Setting"
   "Other Settings"
   "compiler logging:" set to "Full Command Line"

Paste the compiler output here, and paste the minimal program source with step by step instructions on how to re-create the problem.

Well, I did exactly what you told me.
A simple console project "hello world", and the run to cursor works. But I noticed that the output screen didn't appear.

So in my other project, because I have to enter many data, code blocks crash because with no output screen of course I can't enter them and it stays pending waiting for them, and even while trying the stop debugger it doesn't work, I have to force quit codeblocks...

PS : What do you mean by complier output? i.e. which one of the tabs?

Offline gd_on

  • Lives here!
  • ****
  • Posts: 797
Re: Problem with debug
« Reply #7 on: March 15, 2007, 12:11:06 pm »
Do you use Win2000 (or a previous one) ?
if yes, it's normal, because since 11th march version, debugger.dll has been changed (see http://forums.codeblocks.org/index.php/topic,5391.msg41849.html#msg41849 and the following posts) and debug does not work properly. So try the previous nightly (9 march).
if not, try also the previous nightly.
In any case, it's nice to indicate also your OS version, gcc version, ....

gd_on
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2775
Re: Problem with debug
« Reply #8 on: March 15, 2007, 01:07:06 pm »
If it's a Linux console you need, here is a patch to provide one:
https://developer.berlios.de/patch/?func=detailpatch&patch_id=1882&group_id=5358
See the raw patch, or the code below.

Code
Index: debuggergdb.cpp
===================================================================
--- debuggergdb.cpp (revision 3676)
+++ debuggergdb.cpp (working copy)
@@ -233,6 +233,10 @@
     {
         NotifyMissingFile(_T("debugger.zip"));
     }
+    // vars for Linux console //(pecan 2007/2/06)
+    m_bIsConsole = false;
+    m_nConsolePid = 0;
+    m_ConsoleTty = wxEmptyString;
 }
 
 DebuggerGDB::~DebuggerGDB()
@@ -1021,6 +1025,21 @@
     m_State.GetDriver()->Prepare(target && target->GetTargetType() == ttConsoleOnly);
     m_State.ApplyBreakpoints();
 
+   #ifdef __WXGTK__    //(pecan 2007/2/05)
+    // create xterm and issue tty "/dev/pts/#" to GDB where
+    // # is the tty for the newly created xterm
+    m_bIsConsole = (target && target->GetTargetType() == ttConsoleOnly);
+    if (m_bIsConsole)
+    {
+        if (RunNixConsole() > 0 )
+        {   wxString gdbTtyCmd;
+            gdbTtyCmd << wxT("tty ") << m_ConsoleTty;
+            m_State.GetDriver()->QueueCommand(new DebuggerCmd(m_State.GetDriver(), gdbTtyCmd, true));
+            DebugLog(wxString::Format( _("Queued:[%s]"), gdbTtyCmd.c_str()) );
+        }
+    }//if
+   #endif//def __WXGTK__
+
     // Don't issue 'run' if attaching to a process (Bug #1391904)
     if (m_PidToAttach == 0)
         m_State.GetDriver()->Start(m_BreakOnEntry);
@@ -1503,12 +1522,21 @@
 
 void DebuggerGDB::Stop()
 {
+    // m_Process is PipedProcess I/O; m_Pid is debugger pid
     if (m_pProcess && m_Pid)
     {
         if (IsStopped())
         {
             RunCommand(CMD_STOP);
             m_pProcess->CloseOutput();
+           #ifdef __WXGTK__
+            // kill any linux console //(pecan 2007/2/06)
+            if ( m_bIsConsole && (m_nConsolePid > 0) )
+            {
+                ::wxKill(m_nConsolePid);
+                m_nConsolePid = 0;
+            }
+           #endif
         }
         else
         {
@@ -2214,3 +2242,108 @@
 {
     Configure();
 }
+// ----------------------------------------------------------------------------
+int DebuggerGDB::RunNixConsole()
+// ----------------------------------------------------------------------------
+{//(pecan 2007/3/09)
+
+    // start the xterm and put the shell to sleep with -e sleep 80000
+    // fetch the xterm tty so we can issue to gdb a "tty /dev/pts/#"
+    // redirecting program stdin/stdout/stderr to the xterm console.
+
+  #ifndef __WXMSW__
+    wxString cmd;
+    wxString title = wxT("Program Console");
+    m_nConsolePid = 0;
+    // for non-win platforms, use m_ConsoleTerm to run the console app
+    wxString term = Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/console_terminal"), DEFAULT_CONSOLE_TERM);
+    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
+    cmd << term << _T(" ");
+    cmd << wxT("sleep ");
+    cmd << wxString::Format(wxT("%d"),80000 + ::wxGetProcessId());
+
+    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
+    DebugLog(wxString::Format( _("Executing: %s"), cmd.c_str()) );
+    //start xterm -e sleep {some unique # of seconds}
+    m_nConsolePid = wxExecute(cmd, wxEXEC_ASYNC);
+    if (m_nConsolePid <= 0) return -1;
+
+    // Issue the PS command to get the /dev/tty device name
+    // First, wait for the xterm to settle down, else PS won't see the sleep task
+    Manager::Yield();
+    ::wxSleep(1);
+    m_ConsoleTty = GetConsoleTty(m_nConsolePid);
+    if (not m_ConsoleTty.IsEmpty() )
+    {   // show what we found as tty
+        DebugLog(wxString::Format(wxT("GetConsoleTTY[%s]ConsolePid[%d]"),m_ConsoleTty.c_str(),m_nConsolePid));
+        return m_nConsolePid;
+    }
+    // failed to find the console tty
+    DebugLog( wxT("Console Execution error:failed to find console tty."));
+    if (m_nConsolePid != 0)::wxKill(m_nConsolePid);
+    m_nConsolePid = 0;
+  #endif//ndef __WWXMSW__
+    return -1;
+}
+// ----------------------------------------------------------------------------
+wxString DebuggerGDB::GetConsoleTty(int ConsolePid)
+// ----------------------------------------------------------------------------
+{//(pecan 2007/3/09)
+
+    // execute the ps x -o command  and read PS output to get the /dev/tty field
+
+ unsigned long ConsPid = ConsolePid;
+ wxString psCmd;
+ wxArrayString psOutput;
+ wxArrayString psErrors;
+
+ psCmd << wxT("ps x -o tty,pid,command");
+    DebugLog(wxString::Format( _("Executing: %s"), psCmd.c_str()) );
+ int result = wxExecute(psCmd, psOutput, psErrors, wxEXEC_SYNC);
+ psCmd.Clear();
+ if (result != 0)
+ {   psCmd << wxT("Result of ps x:") << result;
+        DebugLog(wxString::Format( _("Execution Error:"), psCmd.c_str()) );
+        return wxEmptyString;
+ }
+
+    wxString ConsTtyStr;
+    wxString ConsPidStr;
+    ConsPidStr << ConsPid;
+    //find task with our unique sleep time
+    wxString uniqueSleepTimeStr;
+    uniqueSleepTimeStr << wxT("sleep ") << wxString::Format(wxT("%d"),80000 + ::wxGetProcessId());
+    // search the output of "ps pid" command
+    int knt = psOutput.GetCount();
+    for (int i=knt-1; i>-1; --i)
+    {   psCmd = psOutput.Item(i);
+        DebugLog(wxString::Format( _("PS result: %s"), psCmd.c_str()) );
+        // find the pts/# or tty/# or whatever it's called
+        // by seaching the output of "ps x -o tty,pid,command" command.
+        // The output of ps looks like:
+        // TT       PID   COMMAND
+        // pts/0    13342 /bin/sh ./run.sh
+        // pts/0    13343 /home/pecan/devel/trunk/src/devel/codeblocks
+        // pts/0    13361 /usr/bin/gdb -nx -fullname -quiet -args ./conio
+        // pts/0    13362 xterm -font -*-*-*-*-*-*-20-*-*-*-*-*-*-* -T Program Console -e sleep 93343
+        // pts/2    13363 sleep 93343
+        // ?        13365 /home/pecan/proj/conio/conio
+        // pts/1    13370 ps x -o tty,pid,command
+
+        if (psCmd.Contains(uniqueSleepTimeStr))
+        do
+        {   // check for correct "sleep" line
+            if (psCmd.Contains(wxT("-T"))) break; //error;wrong sleep line.
+            // found "sleep 93343" string, extract tty field
+            ConsTtyStr = wxT("/dev/") + psCmd.BeforeFirst(' ');
+            DebugLog(wxString::Format( _("TTY is[%s]"), ConsTtyStr.c_str()) );
+            return ConsTtyStr;
+        }while(0);//if do
+    }//for
+
+    knt = psErrors.GetCount();
+    for (int i=0; i<knt; ++i)
+        DebugLog(wxString::Format( _("PS Error:%s"), psErrors.Item(i).c_str()) );
+    return wxEmptyString;
+}
+// ----------------------------------------------------------------------------
Index: debuggergdb.h
===================================================================
--- debuggergdb.h (revision 3676)
+++ debuggergdb.h (working copy)
@@ -205,6 +205,13 @@
 
         int m_HookId; // project loader hook ID
 
+        // Linux console support
+        int      RunNixConsole();
+        wxString GetConsoleTty(int ConsolePid);
+        bool     m_bIsConsole;
+        int      m_nConsolePid;
+        wxString m_ConsoleTty;
+
  DECLARE_EVENT_TABLE()
 };
 


Offline InddZen

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debug
« Reply #9 on: March 15, 2007, 01:23:24 pm »
Yes I'm currently working on Linux.
I still didn't try on Window (XP SP2 version) because I don't have my laptop now.
Now the question is how to apply this patch  :? Never did it before...

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2775
Re: Problem with debug
« Reply #10 on: March 15, 2007, 06:17:00 pm »
Yes I'm currently working on Linux.
I still didn't try on Window (XP SP2 version) because I don't have my laptop now.
Now the question is how to apply this patch  :? Never did it before...

copy the patch to debuggergdb.patch.
issue the following commands.

cd .../trunk/src/plugins/debuggergdb
patch </your download dir/debuggergdb.patch

recompile CB
test