void NodeJSDebugger::OnAttach(clDebugEvent& event) { #ifdef __WXMSW__ if(event.GetDebuggerName() != "NodeJS Debugger") { event.Skip(); return; } event.Skip(false); ::wxMessageBox(_("Debugging a running Node.js process is only available on Linux / OSX"), "CodeLite", wxICON_WARNING | wxCENTER | wxOK); #else if(event.GetDebuggerName() != "NodeJS Debugger") { event.Skip(); return; } event.Skip(false); // ours to handle, stop the event chain if(m_socket && m_socket->IsConnected()) { ::wxMessageBox(_("An active debug session is already running"), "CodeLite", wxICON_WARNING | wxCENTER | wxOK); return; }; ::kill(event.GetInt(), SIGUSR1); // already connected? m_socket.Reset(new NodeJSSocket(this)); m_socket->Connect("127.0.0.1", 5858); #endif }
void LLDBPlugin::OnDebugAttachToProcess(clDebugEvent& event) { if(event.GetDebuggerName() != LLDB_DEBUGGER_NAME) { event.Skip(); return; } #ifdef __WXMSW__ ::wxMessageBox( _("Attach to process with LLDB is not supported under Windows"), "CodeLite", wxOK | wxCENTER | wxICON_WARNING); return; #endif wxString terminalTitle; terminalTitle << "Console PID " << event.GetInt(); if(!DoInitializeDebugger(event, true, terminalTitle)) return; LLDBConnectReturnObject retObj; LLDBSettings settings; settings.Load(); if(m_connector.Connect(retObj, settings, 5)) { // Apply the environment EnvSetter env; // remove all breakpoints from previous session m_connector.DeleteAllBreakpoints(); LLDBSettings settings; settings.Load(); // Attach to the process LLDBCommand command; command.SetCommandType(kCommandAttachProcess); command.SetProcessID(event.GetInt()); command.SetSettings(settings); m_connector.AttachProcessWithPID(command); } else { // Failed to connect, notify and perform cleanup DoCleanup(); wxString message; message << _("Could not connect to codelite-lldb at '") << m_connector.GetConnectString() << "'"; ::wxMessageBox(message, "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return; } }
void LLDBPlugin::OnDebugCoreFile(clDebugEvent& event) { if(event.GetDebuggerName() != LLDB_DEBUGGER_NAME) { event.Skip(); return; } #ifdef __WXMSW__ ::wxMessageBox( _("Debug core file with LLDB is not supported under Windows"), "CodeLite", wxOK | wxCENTER | wxICON_WARNING); return; #endif if(!DoInitializeDebugger(event, false)) { return; } LLDBConnectReturnObject retObj; LLDBSettings settings; settings.Load(); if(m_connector.Connect(retObj, settings, 5)) { // Apply the environment EnvSetter env; // remove all breakpoints from previous session m_connector.DeleteAllBreakpoints(); LLDBCommand startCommand; startCommand.FillEnvFromMemory(); startCommand.SetCommandType(kCommandDebugCoreFile); startCommand.SetExecutable(event.GetExecutableName()); startCommand.SetCorefile(event.GetCoreFile()); startCommand.SetWorkingDirectory(event.GetWorkingDirectory()); startCommand.SetRedirectTTY(m_terminalTTY); m_connector.OpenCoreFile(startCommand); } else { // Failed to connect, notify and perform cleanup DoCleanup(); wxString message; message << _("Could not connect to codelite-lldb at '") << m_connector.GetConnectString() << "'"; ::wxMessageBox(message, "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return; } }
bool LLDBPlugin::DoInitializeDebugger(clDebugEvent& event, bool redirectOutput, const wxString& terminalTitle) { if(event.GetDebuggerName() != LLDB_DEBUGGER_NAME) { event.Skip(); return false; } if(m_connector.IsRunning()) { // Another debug session is already in progress ::wxMessageBox(_("Another debug session is already in progress. Please stop it first"), "CodeLite", wxOK | wxCENTER | wxICON_WARNING); return false; } TerminateTerminal(); // If terminal is required, launch it now bool isWindows = wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS; if(redirectOutput && !isWindows) { wxString realPts; ::LaunchTerminalForDebugger( terminalTitle.IsEmpty() ? event.GetExecutableName() : terminalTitle, m_terminalTTY, realPts, m_terminalPID); if(m_terminalPID != wxNOT_FOUND) { CL_DEBUG("Successfully launched terminal"); } else { // Failed to launch it... DoCleanup(); ::wxMessageBox(_("Failed to start terminal for debugger"), "CodeLite", wxICON_ERROR | wxOK | wxCENTER); return false; } } // Launch local server if needed LLDBSettings settings; settings.Load(); if(!settings.IsUsingRemoteProxy() && !m_connector.LaunchLocalDebugServer()) { DoCleanup(); return false; } return true; }
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()); }