void DebuggerManager::FindTargetsDebugger() { if (Manager::Get()->GetProjectManager()->IsLoadingOrClosing()) return; m_activeDebugger = nullptr; m_menuHandler->SetActiveDebugger(nullptr); if (m_registered.empty()) { m_menuHandler->MarkActiveTargetAsValid(false); return; } ProjectManager* projectMgr = Manager::Get()->GetProjectManager(); LogManager* log = Manager::Get()->GetLogManager(); cbProject* project = projectMgr->GetActiveProject(); ProjectBuildTarget *target = nullptr; if (project) { const wxString &targetName = project->GetActiveBuildTarget(); if (project->BuildTargetValid(targetName)) target = project->GetBuildTarget(targetName); } Compiler *compiler = nullptr; if (!target) { if (project) compiler = CompilerFactory::GetCompiler(project->GetCompilerID()); if (!compiler) compiler = CompilerFactory::GetDefaultCompiler(); if (!compiler) { log->LogError(_("Can't get the compiler for the active target, nor the project, nor the default one!")); m_menuHandler->MarkActiveTargetAsValid(false); return; } } else { compiler = CompilerFactory::GetCompiler(target->GetCompilerID()); if (!compiler) { log->LogError(wxString::Format(_("Current target '%s' doesn't have valid compiler!"), target->GetTitle().c_str())); m_menuHandler->MarkActiveTargetAsValid(false); return; } } wxString dbgString = compiler->GetPrograms().DBGconfig; wxString::size_type pos = dbgString.find(wxT(':')); wxString name, config; if (pos != wxString::npos) { name = dbgString.substr(0, pos); config = dbgString.substr(pos + 1, dbgString.length() - pos - 1); } if (name.empty() || config.empty()) { log->LogError(wxString::Format(_("Current compiler '%s' doesn't have correctly defined debugger!"), compiler->GetName().c_str())); m_menuHandler->MarkActiveTargetAsValid(false); return; } for (RegisteredPlugins::iterator it = m_registered.begin(); it != m_registered.end(); ++it) { PluginData &data = it->second; if (it->first->GetSettingsName() == name) { ConfigurationVector &configs = data.GetConfigurations(); int index = 0; for (ConfigurationVector::iterator itConf = configs.begin(); itConf != configs.end(); ++itConf, ++index) { if ((*itConf)->GetName() == config) { m_activeDebugger = it->first; m_activeDebugger->SetActiveConfig(index); m_useTargetsDefault = true; WriteActiveDebuggerConfig(wxEmptyString, -1); RefreshUI(); m_menuHandler->MarkActiveTargetAsValid(true); return; } } } } wxString targetTitle(target ? target->GetTitle() : wxT("<nullptr>")); log->LogError(wxString::Format(_("Can't find the debugger config: '%s:%s' for the current target '%s'!"), name.c_str(), config.c_str(), targetTitle.c_str())); m_menuHandler->MarkActiveTargetAsValid(false); }
void CodeBlocksApp::AttachDebugger() { const wxString localAttach = m_DebuggerAttach; const wxString localConfig = m_DebuggerConfig; // Reset the values to prevent old values to be used when the user forgets to pass all required // command line parameters. m_DebuggerAttach = m_DebuggerConfig = wxString(); LogManager *logManager = Manager::Get()->GetLogManager(); if (localAttach.empty() || localConfig.empty()) { if (localAttach.empty() != localConfig.empty()) { logManager->LogError( _("For attaching to work you need to provide both '--dbg-attach' and '--dbg-config'")); logManager->Log(wxT(" --dbg-attach='") + localAttach + wxT("'")); logManager->Log(wxT(" --dbg-config='") + localConfig + wxT("'")); } return; } logManager->Log(wxString::Format(_("Attach debugger '%s' to '%s'"), localConfig.wx_str(), localAttach.wx_str())); // Split the dbg-config to plugin name and config name wxString::size_type pos = localConfig.find(wxT(':')); if (pos == wxString::npos || pos == 0) { logManager->LogError( _("No delimiter found. The --dbg-config format is 'plugin-name:config-name'")); return; } const wxString pluginName = localConfig.substr(0, pos); const wxString configName = localConfig.substr(pos + 1); // Find the plugin and the config. DebuggerManager *debuggerManager = Manager::Get()->GetDebuggerManager(); const DebuggerManager::RegisteredPlugins &debuggers = debuggerManager->GetAllDebuggers(); if (debuggers.empty()) { logManager->LogError(_("No debugger plugins loaded!")); return; } cbDebuggerPlugin *plugin = nullptr; int configIndex = -1; const DebuggerManager::PluginData *pluginData = nullptr; for (const auto &info : debuggers) { if (info.first->GetSettingsName() == pluginName) { plugin = info.first; pluginData = &info.second; break; } } if (!plugin) { logManager->LogError(wxString::Format(_("Debugger plugin '%s' not found!"), pluginName.wx_str())); logManager->Log(_("Available plugins:")); for (const auto &info : debuggers) { cbDebuggerPlugin *p = info.first; logManager->Log(wxString::Format(_(" '%s' (%s)"), p->GetSettingsName().wx_str(), p->GetGUIName().wx_str())); } return; } const DebuggerManager::ConfigurationVector &configs = pluginData->GetConfigurations(); for (auto it = configs.begin(); it != configs.end(); ++it) { if ((*it)->GetName() == configName) { configIndex = std::distance(configs.begin(), it); break; } } if (configIndex == -1) { logManager->LogError(wxString::Format(_("Debugger configuration '%s' not found!"), configName.wx_str())); logManager->Log(_("Available configurations:")); for (const cbDebuggerConfiguration *config : configs) logManager->Log(wxString::Format(_(" '%s'"), config->GetName().wx_str())); return; } // We have a debugger plugin and config, so lets try to attach... logManager->Log(_("Debugger plugin and configuration found. Attaching!!!")); plugin->SetActiveConfig(configIndex); plugin->AttachToProcess(localAttach); }