User forums > Using Code::Blocks

Problem with debugger

<< < (9/9)

Pecan:
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;
}


--- End code ---

Pecan:
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());

--- End code ---

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


--- End code ---

kramed:
It works!!!!!

kramed:
I love you Pecan. Wonder how many posts this thread is up to. I am going to bed... Thanks again!

Pecan:
Thanks for your hard work and persistence. It'll make the code better for all of us.

Navigation

[0] Message Index

[*] Previous page

Go to full version