Author Topic: Problem with debugger  (Read 25811 times)

kramed

  • Guest
Problem with debugger
« on: March 08, 2007, 05:38:22 pm »
Hi,

I just upgraded to SVN using wxGTK 2.6.3 patch2. I have compiled it in Linux. I have typically used C::B in Windows. The problem I seem to be having is during debugging. I am able to set break points but when I start the debugger my program does not start in a terminal. The debugger is active and I can step through the program if break points are set before any user input is required but as soon as it hits a cin >> I have to force the debugger to close. What am I overlooking during my transition from Windows to Linux.

PS, yes I have debugging symbols included and am compiling in Debug mode.

Thanks, Mark.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #1 on: March 08, 2007, 06:44:44 pm »
Here's a patch to add a Linux debugging console.

Code
Index: debuggergdb.cpp
===================================================================
--- debuggergdb.cpp (revision 3659)
+++ 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
         {
@@ -2196,3 +2224,101 @@
 {
     Configure();
 }
+// ----------------------------------------------------------------------------
+int DebuggerGDB::RunNixConsole()
+// ----------------------------------------------------------------------------
+{
+    // 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("'") + _T("*nixConsole") + _T("'"));
+    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
+    cmd << term << _T(" ");
+    cmd << wxT("sleep ");
+    cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command
+
+    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
+    //Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s"), cmd.c_str() );
+    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() )
+        return m_nConsolePid;
+    // failed to find the console tty
+    DebugLog( wxT("Console Execution error:failed to find console tty."));
+    ::wxKill(m_nConsolePid);
+    m_nConsolePid = 0;
+  #endif//ndef __WWXMSW__
+    return -1;
+}
+// ----------------------------------------------------------------------------
+wxString DebuggerGDB::GetConsoleTty(int ConsolePid)
+// ----------------------------------------------------------------------------
+{
+    // execute the ps -xo 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 ") << 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 or out "ps x" 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))
+        {   // found sleep 93343 string, extract tty field
+            ConsTtyStr = wxT("/dev/") + psCmd.BeforeFirst(' ');
+            DebugLog(wxString::Format( _("TTY is[%s]"), ConsTtyStr.c_str()) );
+            return ConsTtyStr;
+        }//if
+    }//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 3659)
+++ 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()
 };
 


kramed

  • Guest
Re: Problem with debugger
« Reply #2 on: March 08, 2007, 07:02:47 pm »
Thank you! I applied the patch. When I start the debugger the terminal opens for a brief second and closes before I can see if there is any output to the screen. Does this patch work with last nights revision? Im trying to think of why it may be closing before I even get to a breakpoint.

kramed

  • Guest
Re: Problem with debugger
« Reply #3 on: March 08, 2007, 07:36:31 pm »
I reverted to SVN 3659 but the problem with the console automatically closing remains. This is quite upsetting as I had been using CodeBlocks under the assumption it was full platform independent. Any other suggestions?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #4 on: March 08, 2007, 07:38:34 pm »
Hold on for a couple of hours. I'll update and see what's going on.

This patch has been working for me for some time now. Something must have changed.

What OS/distribution are you using.

Can you give me a short minimal pgm that causes the problem?
« Last Edit: March 08, 2007, 07:48:02 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #5 on: March 08, 2007, 07:53:58 pm »
Here is the debugger console working with cout/cin in SVN 3659



Now I'll update to the latest svn.

Could you please attach a minimal pgm that fails for you.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #6 on: March 08, 2007, 08:01:49 pm »
Try this source with the console and see if it runs for you.

Code
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int upstring(char *value);


int main()
{
    //asm("int3");
        char value[81]={'\0'};
        int upper_count;

        // perform i/o operation
        do
    {   cout << "Please type in a String (max. 80 characters): ";
        cin.getline(value, 80);
        //strcpy(value,"FakeReply");
        upper_count = upstring(value);
        cout << upper_count << " characters are converted" << endl;
        cout << "The new string is now: " << value << endl;
        if ( (strlen(value) >3) && (0==strncmp(value,"LOOP",4) ))
            break;
    }while(upper_count);

    // perform infinite loop if user entered text "loop"
    if ( (strlen(value) >3) && (0==strncmp(value,"LOOP",4)) )
    {
        int i = 0;
        while(true){
            cout<<".";cout.flush();
            ++i;
            sleep(1);
        }
    }
  return EXIT_SUCCESS;
}

int upstring(char *value)
{
  int i=0;
  while(*value)
  {
    if(islower(*value))
    {
      *value=toupper(*value);
      i++;
    }
  value++;
  }
  return(i);
}



kramed

  • Guest
Re: Problem with debugger
« Reply #7 on: March 08, 2007, 08:09:23 pm »
I am running Slackware 11 Kernel 2.6.20.

I am not sure if you mean a screen capture when you say PGM. It would be extremely difficult for me to catch the popup for you to see.

I tried executing your code. Works fine build/run but when I add a breakpoint and try to debug the console just pops up and dies again.

The patch was applied successfully in case you are wondering.

kramed

  • Guest
Re: Problem with debugger
« Reply #8 on: March 08, 2007, 08:13:04 pm »
I checked if X reported any problem.

Code
-------------- Build: Debug in test ---------------
Compiling: test.cpp
Linking console executable: bin/Debug/test
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings
X Error: BadWindow (invalid Window parameter) 3
  Major opcode:  2
  Minor opcode:  0
  Resource id:  0x1000009


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #9 on: March 08, 2007, 08:26:13 pm »
Uh oh,

This patch issues xterm -e sleep 80000+some pid number
in order to put the shell into a coma. Then it tells gdb to use the tty that it finds sleeping.

I guess the Slackware console starts running, but never sleeps on Slack.

So... how does Slack put a shell to sleep?

Can you issue an

xterm
sleep 60

Can you issue an xterm -e sleep 60

what happens?


« Last Edit: March 08, 2007, 08:28:15 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #10 on: March 08, 2007, 08:33:49 pm »
Would you turn on the Debuggers debugging log:

MainMenu=>Settings=>Compiler and Debugger=>Debugger Settings=>check Display Debuggers log

Now debug youf program again and paste the contents of the tab marked "Debugger (debug)" and also the contents of the tab marked "Debugger".

Let's see what gdb sees.

kramed

  • Guest
Re: Problem with debugger
« Reply #11 on: March 08, 2007, 08:35:20 pm »
The xterm -e sleep 60 is working when I type it into another console

kramed

  • Guest
Re: Problem with debugger
« Reply #12 on: March 08, 2007, 08:38:50 pm »
Code
Building to ensure sources are up-to-date
Build succeeded
Selecting target: Debug
Adding source dir: /home/mark/test/
Adding source dir: /home/mark/test/
Adding file: bin/Debug/test
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.5
At /home/mark/test/test.cpp:18
At /home/mark/test/test.cpp:19

I used the program you posted and set the break right before the cin. I stepped until it got to the cin and then I am forced to stop the debugger manually.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #13 on: March 08, 2007, 08:40:44 pm »
This is the Debugger log. I also need the "Debuggers (debug)" log as mentioned above. You may have to use the little black arrow at the right of the tabs to get to it.

kramed

  • Guest
Re: Problem with debugger
« Reply #14 on: March 08, 2007, 08:42:18 pm »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/test
Working dir : /home/mark/test/
> set prompt >>>>>>cb_gdb:
Executing: xterm -T 'Program Console' -e sleep
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/test/test.cpp:17"
Breakpoint 1 at 0x8048a5b: file /home/mark/test/test.cpp, line 17.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: ?        27347 gaim
PS result: ?        27119 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kdevelopKzOKsa.slave-socket
PS result: ?        25985 konqueror [kdeinit] --silent         
PS result: ?        20333 /usr/local/apps/firefox/firefox-bin
PS result: ?        20328 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?        20325 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?        15990 xchat
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: ?         3253 ps x -o tty,pid,command
PS result: ?         3240 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/test
PS result: ?         2537 codeblocks
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1644 superkaramba -session 108f363330000117290000100000036900010_1173329213_704426
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: pts/1      559 -bash
PS result: ?          558 konsole [kdeinit] --ls               
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 2 at 0x8048a44: file /home/mark/test/test.cpp, line 13.
main () at /home/mark/test/test.cpp:13
/home/mark/test/test.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 3254.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Breakpoint 1, main () at /home/mark/test/test.cpp:18
/home/mark/test/test.cpp:18:243:beg:0x8048a5b
>>>>>>cb_gdb:
> info locals
value = '\0' <repeats 80 times>
upper_count = -1208292500
>>>>>>cb_gdb:
> info args
No arguments.
>>>>>>cb_gdb:
> next
/home/mark/test/test.cpp:19:309:beg:0x8048a70
>>>>>>cb_gdb:
> info locals
value = '\0' <repeats 80 times>
upper_count = -1208292500
>>>>>>cb_gdb:
> info args
No arguments.
>>>>>>cb_gdb:
> next
Please type in a String (max. 80 characters):
Program received signal SIGINT, Interrupt.
0xb7e1846e in __read_nocancel () from /lib/tls/libc.so.6
>>>>>>cb_gdb:
> info locals
No symbol table info available.
>>>>>>cb_gdb:
> info args
No symbol table info available.
>>>>>>cb_gdb:
> quit

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #15 on: March 08, 2007, 08:42:55 pm »
What's in your shell & terminal entries?

Menu=>Setting->Enviornment.


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #16 on: March 08, 2007, 08:44:43 pm »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/test
Working dir : /home/mark/test/
> set prompt >>>>>>cb_gdb:
Executing: xterm -T 'Program Console' -e sleep
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/test/test.cpp:17"
Breakpoint 1 at 0x8048a5b: file /home/mark/test/test.cpp, line 17.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: ?        27347 gaim
PS result: ?        27119 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kdevelopKzOKsa.slave-socket
PS result: ?        25985 konqueror [kdeinit] --silent         
PS result: ?        20333 /usr/local/apps/firefox/firefox-bin
PS result: ?        20328 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?        20325 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?        15990 xchat
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: ?         3253 ps x -o tty,pid,command
PS result: ?         3240 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/test
PS result: ?         2537 codeblocks
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1644 superkaramba -session 108f363330000117290000100000036900010_1173329213_704426
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: pts/1      559 -bash
PS result: ?          558 konsole [kdeinit] --ls               
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 2 at 0x8048a44: file /home/mark/test/test.cpp, line 13.
main () at /home/mark/test/test.cpp:13
/home/mark/test/test.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 3254.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Breakpoint 1, main () at /home/mark/test/test.cpp:18
/home/mark/test/test.cpp:18:243:beg:0x8048a5b
>>>>>>cb_gdb:
> info locals
value = '\0' <repeats 80 times>
upper_count = -1208292500
>>>>>>cb_gdb:
> info args
No arguments.
>>>>>>cb_gdb:
> next
/home/mark/test/test.cpp:19:309:beg:0x8048a70
>>>>>>cb_gdb:
> info locals
value = '\0' <repeats 80 times>
upper_count = -1208292500
>>>>>>cb_gdb:
> info args
No arguments.
>>>>>>cb_gdb:
> next
Please type in a String (max. 80 characters):
Program received signal SIGINT, Interrupt.
0xb7e1846e in __read_nocancel () from /lib/tls/libc.so.6
>>>>>>cb_gdb:
> info locals
No symbol table info available.
>>>>>>cb_gdb:
> info args
No symbol table info available.
>>>>>>cb_gdb:
> quit

Ahhh, the sleep count is missing. Let me do some looking.

kramed

  • Guest
Re: Problem with debugger
« Reply #17 on: March 08, 2007, 08:44:59 pm »
Stock defaults:

/bin/sh -c

&

xterm -T $TITLE -e

kramed

  • Guest
Re: Problem with debugger
« Reply #18 on: March 08, 2007, 08:47:00 pm »
I have to leave for class right now. Ill be back this evening (EST) to check again. Thank you for all the help so far, I appreciate it. I am pretty familiar with C::B and I like it, I just need the console with the debugger.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #19 on: March 08, 2007, 08:49:43 pm »
would you do a "ps x -o tty,pid,command" for me and paste the results here. Thanks

kramed

  • Guest
Re: Problem with debugger
« Reply #20 on: March 08, 2007, 08:51:44 pm »
Code
TT         PID COMMAND
tty1      1514 -bash
tty1      1540 /bin/sh /usr/X11R6/bin/startx
tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -
tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
tty1      1569 /bin/sh /opt/kde/bin/startkde
?         1597 kdeinit Running...
?         1600 dcopserver [kdeinit] --nosid
?         1604 klauncher [kdeinit] --new-startup
?         1606 kded [kdeinit] --new-startup
tty1      1619 kwrapper ksmserver
?         1621 ksmserver [kdeinit]
?         1623 kwin [kdeinit] -session 108f363330000117208531500000062
?         1627 kdesktop [kdeinit]
?         1630 kicker [kdeinit]
?         1638 kaccess [kdeinit]
?         1642 superkaramba -session 108f36333000011728590840000002728
?         1644 superkaramba -session 108f36333000011729000010000003690
?         1645 superkaramba -session 108f36333000011729000030000003690
?         1694 konqueror [kdeinit] -session 108f3633300001173327676000
?         7962 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSO
?         8506 konsole [kdeinit] --ls
pts/1     8507 -bash
pts/1     8609 ps x -o tty,pid,command
?        12097 kio_uiserver [kdeinit]
?        15990 xchat
?        20325 /bin/sh /usr/local/apps/firefox/firefox
?        20328 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/loc
?        20333 /usr/local/apps/firefox/firefox-bin
?        25985 konqueror [kdeinit] --silent
?        27119 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSO
?        27347 gaim

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #21 on: March 08, 2007, 09:00:12 pm »
Are you sure the line:

 cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command

is in your patched code

Code
// ----------------------------------------------------------------------------
int DebuggerGDB::RunNixConsole()
// ----------------------------------------------------------------------------
{
    // 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("'") + _T("*nixConsole") + _T("'"));
    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
    cmd << term << _T(" ");
    cmd << wxT("sleep ");
    cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command

    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
    //Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s"), cmd.c_str() );
    DebugLog(wxString::Format( _("Executing: %s"), cmd.c_str()) );


« Last Edit: March 08, 2007, 09:55:41 pm by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #22 on: March 09, 2007, 12:55:51 am »
It is in there. I verified the patch and debuggergdb.cpp and debuggergdb.h

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #23 on: March 09, 2007, 01:13:09 am »
Something is wrong with that line. All you're getting in your log is:

"Executing: xterm -T 'Program Console' -e sleep"

It should be like this one:

"Executing: xterm -T 'Program Console' -e sleep 81234"

if the 80000+pidNumber isn't there, the console flashes as you described because no sleep seconds are specified.

Please zip up debuggerGDB.cpp and debuggerGDB.h and attach them to a message here.




kramed

  • Guest
Re: Problem with debugger
« Reply #24 on: March 09, 2007, 01:17:31 am »
Hope you find something I dont...

Thanks for all your help.

[attachment deleted by admin]

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #25 on: March 09, 2007, 01:35:46 am »
Would you run an xterm
then :

sleep 81234

then :

ps x -o tty,pid,command

then paste the output to me.

thanks

I'm wondering if the number even shows up.

« Last Edit: March 09, 2007, 01:37:19 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #26 on: March 09, 2007, 01:39:13 am »
The sleep command just sits there doing its thing....

Code
bash-3.1$ ps x -o tty,pid,command
TT         PID COMMAND
tty1      1514 -bash
tty1      1540 /bin/sh /usr/X11R6/bin/startx
tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /h
tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
tty1      1569 /bin/sh /opt/kde/bin/startkde
?         1597 kdeinit Running...                   
?         1600 dcopserver [kdeinit] --nosid         
?         1604 klauncher [kdeinit] --new-startup     
?         1606 kded [kdeinit] --new-startup         
tty1      1619 kwrapper ksmserver
?         1621 ksmserver [kdeinit]                   
?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_117
?         1627 kdesktop [kdeinit]                   
?         1630 kicker [kdeinit]                     
?         1638 kaccess [kdeinit]                     
?         1642 superkaramba -session 108f363330000117285908400000027280029_11733
?         1644 superkaramba -session 108f363330000117290000100000036900010_11733
?         1645 superkaramba -session 108f363330000117290000300000036900011_11733
?         1694 konqueror [kdeinit] -session 108f36333000011733276760000007048003
?         4536 kompare -caption Kompare -icon kompare -miniicon kompare -o /home
?         8506 konsole [kdeinit] --ls               
pts/1     8507 -bash
?        15990 xchat
?        20325 /bin/sh /usr/local/apps/firefox/firefox
?        20328 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/fi
?        20333 /usr/local/apps/firefox/firefox-bin
?        21972 konsole [kdeinit] --ls               
pts/3    21973 -bash
?        22093 konsole [kdeinit] --ls               
pts/4    22094 -bash
?        22316 xterm
pts/5    22318 bash
pts/5    22373 sleep 81234
?        22394 xterm
pts/6    22396 bash
pts/6    22459 ps x -o tty,pid,command
?        25985 konqueror [kdeinit] --silent         
?        27347 gaim
bash-3.1$

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #27 on: March 09, 2007, 01:46:08 am »
Ok, I'm gonna make some debugging output statements, then send debuggergdb.cpp back to ya. standby...

Maybe we got a wxWidgets error. What version of wxWidgets are you compiling with?

kramed

  • Guest
Re: Problem with debugger
« Reply #28 on: March 09, 2007, 01:49:26 am »
2.6.3 with Patch #2. I used the wiki as a guide. Im pretty sure wxGTK is installed fine, there were no errors.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #29 on: March 09, 2007, 02:19:17 am »
Here are the last two routines in debuggergdb.cpp

please cut and paste them into your CB, run the console program and then give the "Debugger(debug)" output to me.

I've put two debugging statements in to try and identify the problem with the missing sleep parameter.

Code
// ----------------------------------------------------------------------------
int DebuggerGDB::RunNixConsole()
// ----------------------------------------------------------------------------
{
    // 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("'") + _T("*nixConsole") + _T("'"));
    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
    cmd << term << _T(" ");
    cmd << wxT("sleep ");
    cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command

    wxString sleepPid; sleepPid << 80000 + ::wxGetProcessId();
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_1 is[%s]"),sleepPid.c_str() ));
    sleepPid = wxString::Format(wxT("%d"),80000+ ::wxGetProcessId());
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_2 is[%s]"),sleepPid.c_str() ));

    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
    //Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s"), cmd.c_str() );
    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)
// ----------------------------------------------------------------------------
{
    // 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 ") << 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;
}


« Last Edit: March 09, 2007, 02:23:42 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #30 on: March 09, 2007, 02:29:03 am »
Im sorry I dont understand clearly. The two routine code above, pasted into codeblocks does not compile on its own therefore no way for me to get debugging output.

I am in #codeblocks on irc.freenode.net if that would make things easier.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #31 on: March 09, 2007, 02:36:52 am »
Im sorry I dont understand clearly. The two routine code above, pasted into codeblocks does not compile on its own therefore no way for me to get debugging output.

I am in #codeblocks on irc.freenode.net if that would make things easier.

There are two routines at the bottom of debuggergdb.cpp just like the ones I pasted above named DebuggerGDB::RunNixConsole() and  DebuggerGDB::GetConsoleTty .

Please replace those routines with with the two I include above. Compile, quite CB, restart CB, and run the test program.

Paste the "Debugger(debug)" output here.
 

kramed

  • Guest
Re: Problem with debugger
« Reply #32 on: March 09, 2007, 02:53:48 am »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/cb_test
Working dir : /home/mark/cb_test/
> set prompt >>>>>>cb_gdb:
Executing: xterm -T 'Program Console' -e sleep
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/cb_test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/cb_test/pecans.cpp:25"
Breakpoint 1 at 0x8048b31: file /home/mark/cb_test/pecans.cpp, line 25.
>>>>>>cb_gdb:
> break "/home/mark/test/test.cpp:18"
No source file named /home/mark/test/test.cpp.
Breakpoint 2 ("/home/mark/test/test.cpp:18) pending.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: ?        27347 gaim
PS result: ?        27298 ps x -o tty,pid,command
PS result: ?        27282 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/cb_test
PS result: ?        24807 codeblocks
PS result: ?        15990 xchat
PS result: ?        13294 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/ark8vCrBa.slave-socket
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: pts/1     7619 -bash
PS result: ?         7606 konsole [kdeinit] --ls               
PS result: ?         3678 /usr/local/apps/firefox/firefox-bin
PS result: ?         3672 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?         3669 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: ?          987 java -Xms16m -Xmx128m -cp /usr/local/apps/azureus/Azureus2.jar:/usr/local/apps/azureus/swt.jar -Djava.library.path=/usr/local/apps/azureus -Dazureus.install.path=/usr/local/apps/azureus org.gudy.azureus2.ui.swt.Main /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: ?          961 /bin/bash /usr/local/apps/azureus/azureus /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 3 at 0x8048a44: file /home/mark/cb_test/pecans.cpp, line 13.
main () at /home/mark/cb_test/pecans.cpp:13
/home/mark/cb_test/pecans.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 27299.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Please type in a String (max. 80 characters):


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #33 on: March 09, 2007, 02:59:44 am »
Wasn't compiled, or the code was not pasted correctly.

These statements did not execute:

Code
wxString sleepPid; sleepPid << 80000 + ::wxGetProcessId();
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_1 is[%s]"),sleepPid.c_str() ));
    sleepPid = wxString::Format(wxT("%d"),80000+ ::wxGetProcessId());
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_2 is[%s]"),sleepPid.c_str() ));

There's no way around them. Please check that they're there and you restarted CB when you ran the test.

« Last Edit: March 09, 2007, 03:02:15 am by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #34 on: March 09, 2007, 03:08:54 am »
I need to know what's wrong with the sleep argument.
The results of the new debugging statements are missing in your posted output.

Output will look like the following:
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args ./conio
Working dir : /home/pecan/proj/conio/
> set prompt >>>>>>cb_gdb:
RunNixConsole.SleepPid_1 is[82576]
RunNixConsole.SleepPid_2 is[82576]
Executing: xterm -font -*-*-*-*-*-*-20-*-*-*-*-*-*-*  -T 'Program Console' -e sleep 82576
Using host libthread_db library "/lib/libthread_db.so.1".
« Last Edit: March 09, 2007, 03:17:43 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #35 on: March 09, 2007, 03:29:01 am »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/cb_test
Working dir : /home/mark/cb_test/
> set prompt >>>>>>cb_gdb:
Executing: xterm -T 'Program Console' -e sleep
Executing: ps x -o tty,pid,command
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/cb_test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/cb_test/pecans.cpp:25"
Breakpoint 1 at 0x8048b31: file /home/mark/cb_test/pecans.cpp, line 25.
>>>>>>cb_gdb:
PS result: ?        27347 gaim
PS result: ?        15990 xchat
PS result: ?        15942 ps x -o tty,pid,command
PS result: ?        15930 [xterm] <defunct>
PS result: ?        15929 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/cb_test
PS result: ?        15749 codeblocks
PS result: ?        13294 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/ark8vCrBa.slave-socket
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: pts/1     7619 -bash
PS result: ?         7606 konsole [kdeinit] --ls               
PS result: ?         3678 /usr/local/apps/firefox/firefox-bin
PS result: ?         3672 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?         3669 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: ?          987 java -Xms16m -Xmx128m -cp /usr/local/apps/azureus/Azureus2.jar:/usr/local/apps/azureus/swt.jar -Djava.library.path=/usr/local/apps/azureus -Dazureus.install.path=/usr/local/apps/azureus org.gudy.azureus2.ui.swt.Main /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: ?          961 /bin/bash /usr/local/apps/azureus/azureus /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 2 at 0x8048a44: file /home/mark/cb_test/pecans.cpp, line 13.
main () at /home/mark/cb_test/pecans.cpp:13
/home/mark/cb_test/pecans.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 15950.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Please type in a String (max. 80 characters):

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #36 on: March 09, 2007, 03:34:46 am »
Ok, here's the problem. You are not executing the code I sent you.
If you were, we'd see the following statements in your log:

Code
RunNixConsole.SleepPid_1 is[82576]
RunNixConsole.SleepPid_2 is[82576]
Executing: xterm  -T 'Program Console' -e sleep

We cannot go any further until we get that output.
I'll keep checking back to see if you solved this.

Are you compiling one CB, but executing another CB?
Are you sure the code is in debuggergdb.cpp?
Are you forgetting to restart CB after compiling it?
Are you compiling from the ../output dir and forgetting to move to the .../devel dir to execute?

I donno
« Last Edit: March 09, 2007, 03:46:32 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #37 on: March 09, 2007, 04:53:31 am »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/cb_test
Working dir : /home/mark/cb_test/
> set prompt >>>>>>cb_gdb:
RunNixConsole.SleepPid_1 is[]
RunNixConsole.SleepPid_2 is[111252]
Executing: xterm -T 'Program Console' -e sleep
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/cb_test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/cb_test/pecans.cpp:25"
Breakpoint 1 at 0x8048b31: file /home/mark/cb_test/pecans.cpp, line 25.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: ?        31414 ps x -o tty,pid,command
PS result: ?        31401 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/cb_test
PS result: ?        31252 codeblocks
PS result: ?        27347 gaim
PS result: ?        20407 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kateonNO0a.slave-socket
PS result: ?        20390 kate [kdeinit] /home/mark/codeblocks/trunk/src/plugins/debuggergdb/debuggergdb.cpp
PS result: ?        19946 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kwritepxMgnc.slave-socket
PS result: ?        19120 konqueror [kdeinit] --silent         
PS result: ?        15990 xchat
PS result: ?        13294 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/ark8vCrBa.slave-socket
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: pts/1     7619 -bash
PS result: ?         7606 konsole [kdeinit] --ls               
PS result: ?         3678 /usr/local/apps/firefox/firefox-bin
PS result: ?         3672 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?         3669 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: ?          987 java -Xms16m -Xmx128m -cp /usr/local/apps/azureus/Azureus2.jar:/usr/local/apps/azureus/swt.jar -Djava.library.path=/usr/local/apps/azureus -Dazureus.install.path=/usr/local/apps/azureus org.gudy.azureus2.ui.swt.Main /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: ?          961 /bin/bash /usr/local/apps/azureus/azureus /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 2 at 0x8048a44: file /home/mark/cb_test/pecans.cpp, line 13.
main () at /home/mark/cb_test/pecans.cpp:13
/home/mark/cb_test/pecans.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 31419.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Please type in a String (max. 80 characters):

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #38 on: March 09, 2007, 05:13:40 am »
Code
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/cb_test
Working dir : /home/mark/cb_test/
> set prompt >>>>>>cb_gdb:
RunNixConsole.SleepPid_1 is[]
RunNixConsole.SleepPid_2 is[111252]
Executing: xterm -T 'Program Console' -e sleep
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor att
>>>>>>cb_gdb:
> directory /home/mark/cb_test/
>>>>>>cb_gdb:
> delete breakpoints
>>>>>>cb_gdb:
> break "/home/mark/cb_test/pecans.cpp:25"
Breakpoint 1 at 0x8048b31: file /home/mark/cb_test/pecans.cpp, line 25.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: ?        31414 ps x -o tty,pid,command
PS result: ?        31401 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/cb_test
PS result: ?        31252 codeblocks
PS result: ?        27347 gaim
PS result: ?        20407 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kateonNO0a.slave-socket
PS result: ?        20390 kate [kdeinit] /home/mark/codeblocks/trunk/src/plugins/debuggergdb/debuggergdb.cpp
PS result: ?        19946 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/kwritepxMgnc.slave-socket
PS result: ?        19120 konqueror [kdeinit] --silent         
PS result: ?        15990 xchat
PS result: ?        13294 kio_file [kdeinit] file /tmp/ksocket-mark/klauncherMOSOQb.slave-socket /tmp/ksocket-mark/ark8vCrBa.slave-socket
PS result: ?        12097 kio_uiserver [kdeinit]               
PS result: pts/1     7619 -bash
PS result: ?         7606 konsole [kdeinit] --ls               
PS result: ?         3678 /usr/local/apps/firefox/firefox-bin
PS result: ?         3672 /bin/sh /usr/local/apps/firefox/run-mozilla.sh /usr/local/apps/firefox/firefox-bin
PS result: ?         3669 /bin/sh /usr/local/apps/firefox/firefox
PS result: ?         1694 konqueror [kdeinit] -session 108f363330000117332767600000070480034_1173327676_271749
PS result: ?         1645 superkaramba -session 108f363330000117290000300000036900011_1173329213_704079
PS result: ?         1642 superkaramba -session 108f363330000117285908400000027280029_1173329213_704201
PS result: ?         1638 kaccess [kdeinit]                     
PS result: ?         1630 kicker [kdeinit]                     
PS result: ?         1627 kdesktop [kdeinit]                   
PS result: ?         1623 kwin [kdeinit] -session 108f363330000117208531500000062480000_1173329221_738408
PS result: ?         1621 ksmserver [kdeinit]                   
PS result: tty1      1619 kwrapper ksmserver
PS result: ?         1606 kded [kdeinit] --new-startup         
PS result: ?         1604 klauncher [kdeinit] --new-startup     
PS result: ?         1600 dcopserver [kdeinit] --nosid         
PS result: ?         1597 kdeinit Running...                   
PS result: tty1      1569 /bin/sh /opt/kde/bin/startkde
PS result: tty1      1567 /bin/sh /usr/X11R6/lib/X11/xinit/xinitrc
PS result: tty1      1556 /usr/X11R6/bin/xinit /usr/X11R6/lib/X11/xinit/xinitrc -- -auth /home/mark/.serverauth.1540
PS result: tty1      1540 /bin/sh /usr/X11R6/bin/startx
PS result: tty1      1514 -bash
PS result: ?          987 java -Xms16m -Xmx128m -cp /usr/local/apps/azureus/Azureus2.jar:/usr/local/apps/azureus/swt.jar -Djava.library.path=/usr/local/apps/azureus -Dazureus.install.path=/usr/local/apps/azureus org.gudy.azureus2.ui.swt.Main /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: ?          961 /bin/bash /usr/local/apps/azureus/azureus /tmp/The.Departed.DVDRip.XviD-PUKKA.torrent
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
> start
Breakpoint 2 at 0x8048a44: file /home/mark/cb_test/pecans.cpp, line 13.
main () at /home/mark/cb_test/pecans.cpp:13
/home/mark/cb_test/pecans.cpp:13:142:beg:0x8048a44
>>>>>>cb_gdb:
> info program
Using the running image of child process 31419.
Program stopped at 0x8048a44.
It stopped at a breakpoint that has since been deleted.
Type "info stack" or "info registers" for more information.
>>>>>>cb_gdb:
> cont
Please type in a String (max. 80 characters):

Ok, that's it. I see the error. Looks like a wxWidgets problem on slackware.

Will now do a fix.
« Last Edit: March 09, 2007, 05:18:25 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #39 on: March 09, 2007, 05:20:40 am »
Thanks. Keep me posted.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #40 on: March 09, 2007, 05:30:31 am »
Ok, here we go again with the cut and paste.

Again paste the following routines over the last two routines in debuggergdb.cpp just like we did before.
Compile, quit CB, restart CB and do the test.

Notice I change two lines, commenting out

//cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command

and added:

    cmd << sleepPid;

because it appears SlackWare wxWidgets has a problem with addition in a "streamed" string.


Code
// ----------------------------------------------------------------------------
int DebuggerGDB::RunNixConsole()
// ----------------------------------------------------------------------------
{
    // 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("'") + _T("*nixConsole") + _T("'"));
    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
    cmd << term << _T(" ");
    cmd << wxT("sleep ");
    //cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command

    wxString sleepPid; sleepPid << 80000 + ::wxGetProcessId();
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_1 is[%s]"),sleepPid.c_str() ));
    sleepPid = wxString::Format(wxT("%d"),80000+ ::wxGetProcessId());
    DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_2 is[%s]"),sleepPid.c_str() ));

    cmd << sleepPid;

    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
    //Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s"), cmd.c_str() );
    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)
// ----------------------------------------------------------------------------
{
    // 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 ") << 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;
}


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #41 on: March 09, 2007, 06:15:54 am »
Sorry, I found another problem. Let's do it again...

I had to change two more lines:

Code
//uniqueSleepTimeStr << wxT("sleep ") << 80000 + ::wxGetProcessId();
    uniqueSleepTimeStr << wxT("sleep ") << wxString::Format(wxT("%d"),80000 + ::wxGetProcessId());

If you'll change your build target to "Debugger", you can compile and link this code faster. But be sure to change it back to "All" when you're through


Code
// ----------------------------------------------------------------------------
int DebuggerGDB::RunNixConsole()
// ----------------------------------------------------------------------------
{
    // 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("'") + _T("*nixConsole") + _T("'"));
    term.Replace(_T("$TITLE"), _T("'") + title + _T("'"));
    cmd << term << _T(" ");
    cmd << wxT("sleep ");
    cmd << wxString::Format(wxT("%d"),80000 + ::wxGetProcessId());
    // Bug:
    // Math in streamed strings on SlackWare does not work
    //cmd << 80000 + ::wxGetProcessId(); //make a unique sleep command
    //wxString sleepPid; sleepPid << 80000 + ::wxGetProcessId();
    //DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_1 is[%s]"),sleepPid.c_str() ));
    //sleepPid = wxString::Format(wxT("%d"),80000+ ::wxGetPro cessId());
    //DebugLog(wxString::Format(wxT("RunNixConsole.SleepPid_2 is[%s]"),sleepPid.c_str() ));

    Manager::Get()->GetMacrosManager()->ReplaceEnvVars(cmd);
    //Manager::Get()->GetMessageManager()->Log(m_PageIndex, _("Executing: %s"), cmd.c_str() );
    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)
// ----------------------------------------------------------------------------
{
    // 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 ") << 80000 + ::wxGetProcessId();
    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;
}

« Last Edit: March 09, 2007, 06:20:10 am by Pecan »

kramed

  • Guest
Re: Problem with debugger
« Reply #42 on: March 09, 2007, 06:29:38 am »
It works!!!!!

kramed

  • Guest
Re: Problem with debugger
« Reply #43 on: March 09, 2007, 06:33:39 am »
I love you Pecan. Wonder how many posts this thread is up to. I am going to bed... Thanks again!

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Problem with debugger
« Reply #44 on: March 09, 2007, 01:55:56 pm »
Thanks for your hard work and persistence. It'll make the code better for all of us.