bool DbgGdb::Attach(const DebugSessionInfo& si)
{
    // set the environment variables
    EnvSetter env(m_env, NULL, m_debuggeeProjectName, wxEmptyString);

    wxString dbgExeName;
    if(!DoLocateGdbExecutable(si.debuggerPath, dbgExeName)) {
        return false;
    }

    wxString cmd;
#if defined(__WXGTK__) || defined(__WXMAC__)
    cmd << dbgExeName;
    if(!si.ttyName.IsEmpty()) {
        cmd << wxT(" --tty=") << si.ttyName;
    }
    cmd << wxT(" --interpreter=mi ");
#else
    cmd << dbgExeName << wxT(" --interpreter=mi ");
    cmd << ProcUtils::GetProcessNameByPid(si.PID) << wxT(" ");
#endif

    // if(sudoCmd.IsEmpty() == false) {
    //    cmd.Prepend(sudoCmd + wxT(" "));
    //}

    m_attachedMode = true;
    m_debuggeePid = si.PID;
    cmd << wxT(" --pid=") << m_debuggeePid;
    wxLogMessage(cmd);

    m_observer->UpdateAddLine(wxString::Format(wxT("Current working dir: %s"), wxGetCwd().c_str()));
    m_observer->UpdateAddLine(wxString::Format(wxT("Launching gdb from : %s"), wxGetCwd().c_str()));
    m_observer->UpdateAddLine(wxString::Format(wxT("Starting debugger  : %s"), cmd.c_str()));
    
    // Build the process creation flags
    size_t createFlags = IProcessCreateDefault;
    if(m_info.flags & DebuggerInformation::kRunAsSuperuser) {
        createFlags |= IProcessCreateAsSuperuser;
    }
    m_gdbProcess = CreateAsyncProcess(this, cmd, createFlags);
    if(!m_gdbProcess) {
        return false;
    }
    m_gdbProcess->SetHardKill(true);

    DoInitializeGdb(si);
    m_observer->UpdateGotControl(DBG_END_STEPPING);
    return true;
}
Exemplo n.º 2
0
bool DbgGdb::Start(const wxString &debuggerPath, const wxString & exeName, int pid, const std::vector<BreakpointInfo> &bpList, const wxArrayString &cmds)
{
	wxString dbgExeName;
	if ( ! DoLocateGdbExecutable(debuggerPath, dbgExeName) ) {
		return false;
	}

	wxString cmd;

#if defined (__WXGTK__) || defined (__WXMAC__)
	//On GTK and other platforms, open a new terminal and direct all
	//debugee process into it
	wxString ptyName;
	if (!m_consoleFinder.FindConsole(wxT("EmbeddedLite: gdb"), ptyName)) {
		wxLogMessage(wxT("Failed to allocate console for debugger"));
		return false;
	}
	cmd << dbgExeName << wxT(" --tty=") << ptyName << wxT(" --interpreter=mi ");
#else
	cmd << dbgExeName << wxT(" --interpreter=mi ");
	cmd << ProcUtils::GetProcessNameByPid(pid) << wxT(" ");
#endif

	m_debuggeePid = pid;
	cmd << wxT(" --pid=") << m_debuggeePid;
	wxLogMessage(cmd);

	//set the environment variables
	EnvSetter env(m_env);

	m_observer->UpdateAddLine(wxString::Format(wxT("Current working dir: %s"), wxGetCwd().c_str()));
	m_observer->UpdateAddLine(wxString::Format(wxT("Launching gdb from : %s"), wxGetCwd().c_str()));
	m_observer->UpdateAddLine(wxString::Format(wxT("Starting debugger  : %s"), cmd.c_str()));

	m_gdbProcess = CreateAsyncProcess(this, cmd);
	if (!m_gdbProcess) {
		return false;
	}
	m_gdbProcess->SetHardKill(true);
	
	DoInitializeGdb(bpList, cmds);
	m_observer->UpdateGotControl(DBG_END_STEPPING);
	return true;
}
Exemplo n.º 3
0
bool DbgGdb::Start( const DebugSessionInfo& si)
{
    //set the environment variables
    EnvSetter env( m_env, NULL, m_debuggeeProjectName );

    wxString dbgExeName;
    if ( ! DoLocateGdbExecutable( si.debuggerPath, dbgExeName ) ) {
        return false;
    }

    wxString cmd;
#if defined (__WXGTK__) || defined (__WXMAC__)
    cmd << dbgExeName;
    if ( !si.ttyName.IsEmpty() ) {
        cmd << wxT( " --tty=" ) << si.ttyName;
    }
    cmd << wxT( " --interpreter=mi " ) << si.exeName;
#else
    cmd << dbgExeName << wxT( " --interpreter=mi " ) << si.exeName;
#endif

    m_debuggeePid = wxNOT_FOUND;
    m_attachedMode = false;

    m_observer->UpdateAddLine( wxString::Format( wxT( "Current working dir: %s" ), wxGetCwd().c_str() ) );
    m_observer->UpdateAddLine( wxString::Format( wxT( "Launching gdb from : %s" ), si.cwd.c_str() ) );
    m_observer->UpdateAddLine( wxString::Format( wxT( "Starting debugger  : %s" ), cmd.c_str() ) );
#ifdef __WXMSW__
    // When using remote debugging on Windows we need a console window, as this is the only
    // mechanism to send a Ctrl-C event and signal a SIGINT to interrupt the target.
    bool needs_console = GetIsRemoteDebugging() | m_info.showTerminal;
#else
    bool needs_console = m_info.showTerminal;
#endif
    m_gdbProcess = CreateAsyncProcess( this,
                                       cmd,
                                       // show console?
                                       needs_console ? IProcessCreateConsole : IProcessCreateDefault,
                                       si.cwd );
    if ( !m_gdbProcess ) {
        return false;
    }
#ifdef __WXMSW__
    if ( GetIsRemoteDebugging() ) {
        // This doesn't really make sense, but AttachConsole fails without it...
        AllocConsole();
        FreeConsole(); // Disconnect any existing console window.

        if ( !AttachConsole( m_gdbProcess->GetPid() ) )
            m_observer->UpdateAddLine( wxString::Format(wxT("AttachConsole returned error %d"), GetLastError()));

        // We can at least make the window invisible if the user doesn't want to see it.
        if ( !m_info.showTerminal )
            SetWindowPos(GetConsoleWindow(), HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);

        // Finally we ignore SIGINT so we don't get killed by our own signal
        signal(SIGINT, SIG_IGN);
    }
#endif
    m_gdbProcess->SetHardKill( true );
    DoInitializeGdb( si );
    return true;
}