wxString MemCheckPlugin::PrepareCommand(const wxString& projectName, wxString& wd) { wd.clear(); if(!clCxxWorkspaceST::Get()->IsOpen()) { return ""; } ProjectPtr proj = clCxxWorkspaceST::Get()->GetProject(projectName); if(!proj) { clWARNING() << "MemCheckPlugin::PrepareCommand(): could not find project:" << projectName; return wxEmptyString; } BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(projectName, wxEmptyString); if(!bldConf) { clWARNING() << "MemCheckPlugin::PrepareCommand(): failed to find project configuration for project:" << projectName; return wxEmptyString; } wxString projectPath = proj->GetFileName().GetPath(); // expand variables wxString cmd = bldConf->GetCommand(); cmd = MacroManager::Instance()->Expand(cmd, NULL, projectName); wxString cmdArgs = bldConf->GetCommandArguments(); cmdArgs = MacroManager::Instance()->Expand(cmdArgs, NULL, projectName); // Execute command & cmdArgs wd = bldConf->GetWorkingDirectory(); wd = MacroManager::Instance()->Expand(wd, NULL, projectName); wxFileName workingDir(wd, ""); if(workingDir.IsRelative()) { workingDir.MakeAbsolute(projectPath); } wxFileName fileExe(cmd); if(fileExe.IsRelative()) { fileExe.MakeAbsolute(workingDir.GetPath()); } fileExe.Normalize(); #ifdef __WXMSW__ if(!fileExe.Exists() && fileExe.GetExt().IsEmpty()) { // Try with .exe wxFileName withExe(fileExe); withExe.SetExt("exe"); if(withExe.Exists()) { fileExe = withExe; } } #endif wd = workingDir.GetPath(); cmd = fileExe.GetFullPath(); cmd = ::WrapWithQuotes(cmd); cmd << " " << cmdArgs; clDEBUG() << "Command to execute:" << cmd; clDEBUG() << "Working directory:" << wd; return cmd; }
void PSGeneralPage::Load(BuildConfigPtr buildConf) { Clear(); m_configName = buildConf->GetName(); m_checkBoxEnabled->SetValue( buildConf->IsProjectEnabled() ); m_pgPropArgs->SetValue( buildConf->GetCommandArguments() ); m_pgPropDebugArgs->SetValueFromString( buildConf->GetDebugArgs() ); m_pgPropIntermediateFolder->SetValueFromString( buildConf->GetIntermediateDirectory() ); m_pgPropGUIApp->SetValue( buildConf->IsGUIProgram() ); m_pgPropOutputFile->SetValueFromString( buildConf->GetOutputFileName() ); m_pgPropPause->SetValue( buildConf->GetPauseWhenExecEnds() ); m_pgPropProgram->SetValueFromString( buildConf->GetCommand() ); m_pgPropWorkingDirectory->SetValue( buildConf->GetWorkingDirectory() ); // Project type wxPGChoices choices; choices.Add(Project::STATIC_LIBRARY); choices.Add(Project::DYNAMIC_LIBRARY); choices.Add(Project::EXECUTABLE); m_pgPropProjectType->SetChoices( choices ); m_pgPropProjectType->SetChoiceSelection( choices.Index(buildConf->GetProjectType() ) ); // Compilers choices.Clear(); wxString cmpType = buildConf->GetCompilerType(); BuildSettingsConfigCookie cookie; CompilerPtr cmp = BuildSettingsConfigST::Get()->GetFirstCompiler(cookie); while (cmp) { choices.Add(cmp->GetName()); cmp = BuildSettingsConfigST::Get()->GetNextCompiler(cookie); } m_pgPropCompiler->SetChoices( choices ); m_pgPropCompiler->SetChoiceSelection( choices.Index( buildConf->GetCompiler()->GetName() ) ); // Debuggers choices.Clear(); wxString dbgType = buildConf->GetDebuggerType(); wxArrayString dbgs = DebuggerMgr::Get().GetAvailableDebuggers(); choices.Add(dbgs); m_pgPropDebugger->SetChoices( choices ); m_pgPropDebugger->SetChoiceSelection( choices.Index(buildConf->GetDebuggerType()) ); m_pgPropUseSeparateDebuggerArgs->SetValue( buildConf->GetUseSeparateDebugArgs() ); m_dlg->SetIsProjectEnabled( buildConf->IsProjectEnabled() ); }
void LLDBPlugin::OnDebugStart(clDebugEvent& event) { if(event.GetDebuggerName() != LLDB_DEBUGGER_NAME) { event.Skip(); return; } CL_DEBUG("LLDB: Initial working directory is restored to: " + ::wxGetCwd()); { // Get the executable to debug wxString errMsg; ProjectPtr pProject = clCxxWorkspaceST::Get()->FindProjectByName(event.GetProjectName(), errMsg); if(!pProject) { ::wxMessageBox(wxString() << _("Could not locate project: ") << event.GetProjectName(), "LLDB Debugger", wxICON_ERROR | wxOK | wxCENTER); return; } DirSaver ds; ::wxSetWorkingDirectory(pProject->GetFileName().GetPath()); // Load LLDB settings LLDBSettings settings; settings.Load(); BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(pProject->GetName(), wxEmptyString); if(!bldConf) { ::wxMessageBox(wxString() << _("Could not locate the requested buid configuration"), "LLDB Debugger", wxICON_ERROR | wxOK | wxCENTER); return; } // Launch codelite-lldb now. // Choose wether we need to debug a local or remote target // Honour the project settings if(bldConf->GetIsDbgRemoteTarget()) { long nPort(wxNOT_FOUND); bldConf->GetDbgHostPort().ToCLong(&nPort); settings.SetProxyIp(bldConf->GetDbgHostName()); settings.SetProxyPort(nPort); settings.EnableFlag(kLLDBOptionUseRemoteProxy, true); } if(!settings.IsUsingRemoteProxy()) { // Not using a remote proxy, launch the debug server if(!m_connector.LaunchLocalDebugServer(settings.GetDebugserver())) { return; } } // Determine the executable to debug, working directory and arguments EnvSetter env(NULL, NULL, pProject ? pProject->GetName() : wxString(), bldConf->GetName()); wxString exepath = bldConf->GetCommand(); wxString args; wxString workingDirectory; // Get the debugging arguments. if(bldConf->GetUseSeparateDebugArgs()) { args = bldConf->GetDebugArgs(); } else { args = bldConf->GetCommandArguments(); } workingDirectory = ::ExpandVariables(bldConf->GetWorkingDirectory(), pProject, m_mgr->GetActiveEditor()); exepath = ::ExpandVariables(exepath, pProject, m_mgr->GetActiveEditor()); { DirSaver ds; ::wxSetWorkingDirectory(workingDirectory); wxFileName execToDebug(exepath); if(execToDebug.IsRelative()) { execToDebug.MakeAbsolute(); } ////////////////////////////////////////////////////////////////////// // Launch terminal for IO redirection ////////////////////////////////////////////////////////////////////// TerminateTerminal(); bool isWindows = wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS; if(!bldConf->IsGUIProgram() && !isWindows) { m_debuggerTerminal.Launch(clDebuggerTerminalPOSIX::MakeExeTitle(execToDebug.GetFullPath(), args)); if(m_debuggerTerminal.IsValid()) { CL_DEBUG("Successfully launched terminal %s", m_debuggerTerminal.GetTty()); } else { // Failed to launch it... DoCleanup(); ::wxMessageBox(_("Failed to start terminal for debugger"), "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return; } } if(!isWindows) { workingDirectory = ::wxGetCwd(); } CL_DEBUG("LLDB: Using executable : " + execToDebug.GetFullPath()); CL_DEBUG("LLDB: Working directory: " + workingDirectory); ////////////////////////////////////////////////////////////////////// // Initiate the connection to codelite-lldb ////////////////////////////////////////////////////////////////////// LLDBConnectReturnObject retObj; if(m_connector.Connect(retObj, settings, 5)) { // Get list of breakpoints and add them ( we will apply them later on ) BreakpointInfo::Vec_t gdbBps; m_mgr->GetAllBreakpoints(gdbBps); // remove all breakpoints from previous session m_connector.DeleteAllBreakpoints(); // apply the serialized breakpoints m_connector.AddBreakpoints(gdbBps); // Setup pivot folder if needed SetupPivotFolder(retObj); LLDBCommand startCommand; startCommand.FillEnvFromMemory(); // If the current platform is Windows, use the executable as it appears in the project settings startCommand.SetExecutable(isWindows ? exepath : execToDebug.GetFullPath()); startCommand.SetCommandArguments(args); // Since we called 'wxSetWorkingDirectory' earlier, wxGetCwd() should give use the // correct working directory for the debugger startCommand.SetWorkingDirectory(workingDirectory); startCommand.SetRedirectTTY(m_debuggerTerminal.GetTty()); m_connector.Start(startCommand); clDebugEvent cl_event(wxEVT_DEBUG_STARTED); EventNotifier::Get()->AddPendingEvent(cl_event); } else { // Failed to connect, notify and perform cleanup DoCleanup(); wxString message; message << _("Could not connect to codelite-lldb at '") << (settings.IsUsingRemoteProxy() ? settings.GetTcpConnectString() : m_connector.GetConnectString()) << "'"; ::wxMessageBox(message, "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return; } } } CL_DEBUG("LLDB: Working directory is restored to: " + ::wxGetCwd()); }
void DebugCoreDumpDlg::Initialize() { DebugCoreDumpInfo info; EditorConfigST::Get()->ReadObject(wxT("DebugCoreDumpDlg"), &info); m_choiceDebuggers->Append(DebuggerMgr::Get().GetAvailableDebuggers()); if(m_choiceDebuggers->GetCount()) { m_choiceDebuggers->SetSelection(0); } if(m_choiceDebuggers->GetCount() > (unsigned int)info.GetSelectedDbg()) { m_choiceDebuggers->SetSelection(info.GetSelectedDbg()); } m_Core->Append(info.GetCoreFilepaths()); if(m_Core->GetCount() > 0) { m_Core->SetSelection(0); } m_WD->Append(info.GetWds()); if(m_WD->GetCount() > 0) { m_WD->SetSelection(0); } m_ExeFilepath->Append(info.GetExeFilepaths()); if(m_ExeFilepath->GetCount() > 0) { m_ExeFilepath->SetSelection(0); } else { // determine the executable to debug: // - If the 'Program' field is set - we use it // - Else we use the project's output name wxString activename, conf; ManagerST::Get()->GetActiveProjectAndConf(activename, conf); BuildConfigPtr buildConf = WorkspaceST::Get()->GetProjBuildConf(activename, conf); if(buildConf) { // expand all macros with their values wxString programToDebug = buildConf->GetCommand(); programToDebug.Trim().Trim(false); if(programToDebug.IsEmpty()) { programToDebug = buildConf->GetOutputFileName(); } wxString outputFile = MacroManager::Instance()->Expand(programToDebug, PluginManager::Get(), activename, conf); if(m_ExeFilepath->Append(outputFile) != wxNOT_FOUND) { m_ExeFilepath->SetSelection(0); } // determine the working directory // if we have a working directory set in the project settings, use it (if it is not an // absolute path, it will be appended to the project's path) wxString projWD = MacroManager::Instance()->Expand( buildConf->GetWorkingDirectory(), PluginManager::Get(), activename, conf); projWD.Trim().Trim(false); wxString wd; ProjectPtr proj = ManagerST::Get()->GetProject(activename); if(proj) { if(projWD.IsEmpty() || !wxFileName(projWD).IsAbsolute()) { wxString basePath = proj->GetFileName().GetPath(); wd << basePath << wxFileName::GetPathSeparator(); } } wd << projWD; if(m_WD->Insert(wd, 0) != wxNOT_FOUND) { m_WD->SetSelection(0); } } } }