bool DbgGdb::DoLocateGdbExecutable(const wxString& debuggerPath, wxString& dbgExeName) { if (m_gdbProcess) { //dont allow second instance of the debugger return false; } wxString cmd; dbgExeName = debuggerPath; if (dbgExeName.IsEmpty()) { dbgExeName = wxT("gdb"); } wxString actualPath; if (ExeLocator::Locate(dbgExeName, actualPath) == false) { wxMessageBox(wxString::Format(wxT("Failed to locate gdb! at '%s'"), dbgExeName.c_str()), wxT("EmbeddedLite")); return false; } // set the debugger specific startup commands wxString startupInfo ( m_info.startupCommands ); // We must replace TABS with spaces or else gdb will hang... startupInfo.Replace(wxT("\t"), wxT(" ")); // Write the content into a file wxString codelite_gdbinit_file; #ifdef __WXMSW__ codelite_gdbinit_file << wxFileName::GetTempDir() << wxFileName::GetPathSeparator() << wxT("codelite_gdbinit.txt"); #else wxString home_env; if( !wxGetEnv(wxT("HOME"), &home_env) ) { m_observer->UpdateAddLine(wxString::Format(wxT("Failed to read HOME environment variable"))); } else { codelite_gdbinit_file << home_env << wxT("/") << wxT(".gdbinit"); if( wxFileName::FileExists(codelite_gdbinit_file) && !wxFileName::FileExists(codelite_gdbinit_file + wxT(".backup"))) { wxCopyFile(codelite_gdbinit_file, codelite_gdbinit_file + wxT(".backup") ); m_observer->UpdateAddLine(wxString::Format(wxT(".gdbinit file was backup to %s"), wxString(codelite_gdbinit_file + wxT(".backup")).c_str())); } } #endif wxFFile file; if (!file.Open(codelite_gdbinit_file, wxT("w+b"))) { m_observer->UpdateAddLine(wxString::Format(wxT("Failed to generate gdbinit file at %s"), codelite_gdbinit_file.c_str())); } else { m_observer->UpdateAddLine(wxString::Format(wxT("Using gdbinit file: %s"), codelite_gdbinit_file.c_str())); file.Write(startupInfo); file.Close(); #ifdef __WXMSW__ dbgExeName << wxT(" --command=\"") << codelite_gdbinit_file << wxT("\""); #endif } return true; }
bool DbgGdb::DoLocateGdbExecutable( const wxString& debuggerPath, wxString& dbgExeName ) { if ( m_gdbProcess ) { //dont allow second instance of the debugger return false; } wxString cmd; dbgExeName = debuggerPath; if ( dbgExeName.IsEmpty() ) { dbgExeName = wxT( "gdb" ); } wxString actualPath; if ( ExeLocator::Locate( dbgExeName, actualPath ) == false ) { wxMessageBox( wxString::Format( wxT( "Failed to locate gdb! at '%s'" ), dbgExeName.c_str() ), wxT( "CodeLite" ) ); return false; } // set the debugger specific startup commands wxString startupInfo ( m_info.startupCommands ); // We must replace TABS with spaces or else gdb will hang... startupInfo.Replace( wxT( "\t" ), wxT( " " ) ); // Write the content into a file wxString codelite_gdbinit_file; codelite_gdbinit_file << wxFileName::GetTempDir() << wxFileName::GetPathSeparator() << wxT( "codelite_gdbinit.txt" ); wxFFile file; if ( !file.Open( codelite_gdbinit_file, wxT( "w+b" ) ) ) { m_observer->UpdateAddLine( wxString::Format( wxT( "Failed to generate gdbinit file at %s" ), codelite_gdbinit_file.c_str() ) ); } else { m_observer->UpdateAddLine( wxString::Format( wxT( "Using gdbinit file: %s" ), codelite_gdbinit_file.c_str() ) ); file.Write( startupInfo ); file.Close(); dbgExeName << wxT( " --command=\"" ) << codelite_gdbinit_file << wxT( "\"" ); } return true; }