Ejemplo n.º 1
0
bool DbgGdb::ExecuteCmd( const wxString &cmd )
{
    if( m_gdbProcess ) {
        if ( m_info.enableDebugLog ) {
#if DBG_LOG
            if(gfp.IsOpened()) {
                gfp.Write(wxString::Format( wxT( "DEBUG>>%s\n" ), cmd.c_str() ));
                gfp.Flush();
            }
#else
            m_observer->UpdateAddLine( wxString::Format( wxT( "DEBUG>>%s" ), cmd.c_str() ) );
#endif
        }
        return m_gdbProcess->Write( cmd );
    }
    return false;
}
Ejemplo n.º 2
0
void DbgGdb::Poke()
{
    static wxRegEx reCommand( wxT( "^([0-9]{8})" ) );



    //poll the debugger output
    wxString curline;
    if ( !m_gdbProcess || m_gdbOutputArr.IsEmpty() ) {
        return;
    }

    while ( DoGetNextLine( curline ) ) {

        GetDebugeePID(curline);

        // For string manipulations without damaging the original line read
        wxString tmpline ( curline );
        StripString( tmpline );
        tmpline.Trim().Trim( false );
        if ( m_info.enableDebugLog ) {
            //Is logging enabled?

            if ( curline.IsEmpty() == false && !tmpline.StartsWith( wxT( ">" ) ) ) {
                wxString strdebug( wxT( "DEBUG>>" ) );
                strdebug << curline;
#if DBG_LOG
                if(gfp.IsOpened()) {
                    gfp.Write(strdebug);
                    gfp.Flush();
                }
#else
                m_observer->UpdateAddLine( strdebug );
#endif
            }
        }

        if ( reConnectionRefused.Matches( curline ) ) {
            StripString( curline );
#ifdef __WXGTK__
            m_consoleFinder.FreeConsole();
#endif
            m_observer->UpdateAddLine( curline );
            m_observer->UpdateGotControl( DBG_EXITED_NORMALLY );
            return;
        }

        // Check for "Operation not permitted" usually means
        // that the process does not have enough permission to
        // attach to the process
        if( curline.Contains(wxT("Operation not permitted")) ) {
#ifdef __WXGTK__
            m_consoleFinder.FreeConsole();
#endif
            m_observer->UpdateAddLine( _("Failed to start debugger: permission denied") );
            m_observer->UpdateGotControl( DBG_EXITED_NORMALLY );
            return;

        }

        if( tmpline.StartsWith( wxT( ">" ) ) ) {
            // Shell line, probably user command line
            continue;
        }

        if ( curline.StartsWith( wxT( "~" ) ) || curline.StartsWith( wxT( "&" ) ) || curline.StartsWith("@") ) {

            // lines starting with ~ are considered "console stream" message
            // and are important to the CLI handler
            bool consoleStream( false );
            bool targetConsoleStream(false);

            if ( curline.StartsWith( wxT( "~" ) ) ) {
                consoleStream = true;
            }

            if ( curline.StartsWith( wxT( "@" ) ) ) {
                targetConsoleStream = true;
            }

            // Filter out some gdb error lines...
            if ( FilterMessage( curline ) ) {
                continue;
            }

            StripString( curline );

            // If we got a valid "CLI Handler" instead of writing the output to
            // the output view, concatenate it into the handler buffer
            if ( targetConsoleStream ) {
                m_observer->UpdateAddLine( curline );

            } else if ( consoleStream && GetCliHandler()) {
                GetCliHandler()->Append( curline );

            } else if ( consoleStream ) {
                // log message
                m_observer->UpdateAddLine( curline );

            }

        } else if ( reCommand.Matches( curline ) ) {

            //not a gdb message, get the command associated with the message
            wxString id = reCommand.GetMatch( curline, 1 );

            if ( GetCliHandler() && GetCliHandler()->GetCommandId() == id ) {
                // probably the "^done" message of the CLI command
                GetCliHandler()->ProcessOutput( curline );
                SetCliHandler( NULL ); // we are done processing the CLI

            } else {
                //strip the id from the line
                curline = curline.Mid( 8 );
                DoProcessAsyncCommand( curline, id );

            }
        } else if ( curline.StartsWith( wxT( "^done" ) ) || curline.StartsWith( wxT( "*stopped" ) ) ) {
            //Unregistered command, use the default AsyncCommand handler to process the line
            DbgCmdHandlerAsyncCmd cmd( m_observer, this );
            cmd.ProcessOutput( curline );
        } else {
            //Unknow format, just log it
            if( m_info.enableDebugLog && !FilterMessage( curline ) ) {
                m_observer->UpdateAddLine( curline );
            }
        }
    }
}