1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 The CodeLite Team
// file name : LLDBConnector.h
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#ifndef LLDBCONNECTOR_H
#define LLDBCONNECTOR_H
#include <wx/event.h>
#include "LLDBCommand.h"
#include "SocketAPI/clSocketClient.h"
#include "SocketAPI/clSocketServer.h"
#include "LLDBEnums.h"
#include "LLDBBreakpoint.h"
#include "asyncprocess.h"
#include "LLDBEvent.h"
#include "LLDBRemoteConnectReturnObject.h"
#include "LLDBPivot.h"
class LLDBConnector;
class LLDBNetworkListenerThread;
class LLDBTerminalCallback : public IProcessCallback
{
LLDBConnector* m_connector;
IProcess* m_process;
public:
LLDBTerminalCallback(LLDBConnector* connector) : m_connector(connector), m_process(NULL) {}
virtual void OnProcessOutput(const wxString &str);
virtual void OnProcessTerminated();
void SetProcess(IProcess* process) {
this->m_process = process;
}
};
class LLDBConnector : public wxEvtHandler
{
public:
struct TerminalInfo {
int terminalProcessID;
wxString tty;
TerminalInfo() : terminalProcessID(wxNOT_FOUND) {}
};
protected:
clSocketClient::Ptr_t m_socket;
LLDBNetworkListenerThread * m_thread;
LLDBBreakpoint::Vec_t m_breakpoints;
LLDBBreakpoint::Vec_t m_pendingDeletionBreakpoints;
IProcess* m_process;
bool m_isRunning;
bool m_canInteract;
LLDBCommand m_runCommand;
TerminalInfo m_terminalInfo;
bool m_attachedToProcess;
bool m_goingDown;
LLDBPivot m_pivot;
wxDECLARE_EVENT_TABLE();
void OnProcessOutput(wxCommandEvent &event);
void OnProcessTerminated(wxCommandEvent &event);
protected:
bool IsBreakpointExists(LLDBBreakpoint::Ptr_t bp) const;
LLDBBreakpoint::Vec_t::const_iterator FindBreakpoint(LLDBBreakpoint::Ptr_t bp) const;
LLDBBreakpoint::Vec_t::iterator FindBreakpoint(LLDBBreakpoint::Ptr_t bp);
LLDBBreakpoint::Vec_t GetUnappliedBreakpoints();
void OnLLDBStarted(LLDBEvent &event);
void OnLLDBExited(LLDBEvent &event);
wxString GetDebugServerPath() const;
public:
LLDBConnector();
virtual ~LLDBConnector();
void StartNetworkThread();
void SetPivot(const LLDBPivot& pivot) {
this->m_pivot = pivot;
}
/**
* @brief return the connect string that is used to connect to codelite-lldb
* @return
*/
wxString GetConnectString() const;
void SetGoingDown(bool goingDown) {
this->m_goingDown = goingDown;
}
bool IsGoingDown() const {
return m_goingDown;
}
void SetAttachedToProcess(bool attachedToProcess) {
this->m_attachedToProcess = attachedToProcess;
}
bool IsAttachedToProcess() const {
return m_attachedToProcess;
}
TerminalInfo& GetTerminalInfo() {
return m_terminalInfo;
}
bool IsCanInteract() const {
return m_canInteract;
}
void SetCanInteract(bool canInteract) {
this->m_canInteract = canInteract;
}
void SetIsRunning(bool isRunning) {
this->m_isRunning = isRunning;
}
bool IsRunning() const {
return m_isRunning;
}
const LLDBBreakpoint::Vec_t& GetAllBreakpoints() const;
/**
* @brief invalidate all breakpoints (remove their internal id)
*/
void InvalidateBreakpoints();
/**
* @brief connect to the debugger (automatically decides if it is a local debugger or remote)
*/
bool Connect(LLDBConnectReturnObject& ret, const LLDBSettings& settings, int timeout);
/**
* @brief start codelite-lldb if not running
*/
bool LaunchLocalDebugServer();
/**
* @brief terminate the debug server
*/
void StopDebugServer();
/**
* @brief apply the breakpoints
* Note this does not assure that the breakpoints will actually be added
* codelite-lldb will might need to interrupt the process in order to apply them
* so a LLDB_STOPPED event will be sent with interrupt-reason set to
*/
void ApplyBreakpoints();
/**
* @brief add list of breakpoints ( do not add apply them just yet)
* @param breakpoints
*/
void AddBreakpoints(const LLDBBreakpoint::Vec_t& breakpoints);
/**
* @brief add list of breakpoints ( do not add apply them just yet)
* @param breakpoints
*/
void AddBreakpoints(const BreakpointInfo::Vec_t& breakpoints);
/**
* @brief add a breakpoint to the list (do not apply them yet)
*/
void AddBreakpoint(LLDBBreakpoint::Ptr_t breakpoint, bool notify = true);
/**
* @brief replace all the breakpoints with new list. This also clear the 'pending deletion' breakpoints
*/
void UpdateAppliedBreakpoints(const LLDBBreakpoint::Vec_t& breakpoints);
// aliases
void AddBreakpoint(const wxString &location) {
LLDBBreakpoint::Ptr_t bp( new LLDBBreakpoint(location) );
AddBreakpoint( bp );
}
void AddBreakpoint(const wxFileName& filename, int line) {
LLDBBreakpoint::Ptr_t bp( new LLDBBreakpoint(filename, line) );
AddBreakpoint( bp );
}
/**
* @brief delete a single breakpoint
*/
void MarkBreakpointForDeletion(LLDBBreakpoint::Ptr_t bp);
/**
* @brief delete all breakpoints which are marked for deletion
*/
void DeleteBreakpoints();
/**
* @brief delete all breakpoints
*/
void DeleteAllBreakpoints();
/**
* @brief clear the breakpoint pending deletion queue
*/
void ClearBreakpointDeletionQueue();
/**
* @brief send command to codelite-lldb
*/
void SendCommand(const LLDBCommand& command);
/**
* @brief issue a 'Continue' command
*/
void Continue();
/**
* @brief send request to the debugger to request the local varibles
*/
void RequestLocals();
/**
* @brief add watch. To get the list of values, you should invoke
* a call to 'RequestLocals'
*/
void AddWatch(const wxString& watch);
/**
* @brief delete a watch. To get the list of values, you should invoke
* a call to 'RequestLocals'
*/
void DeleteWatch(int lldbId);
/**
* @brief request lldb to expand a variable and return its children
* @param lldbId the unique identifier that identifies this variable
* at the debug server side
*/
void RequestVariableChildren(int lldbId);
/**
* @brief stop the debugger
*/
void Stop();
/**
* @brief detach from the process
*/
void Detach();
/**
* @brief send a next command
*/
void Next();
/**
* @brief send a step-out command (gdb's "finish")
*/
void StepOut();
/**
* @brief send a step-into-function command (gdb's "step")
*/
void StepIn();
/**
* @brief cleanup this object and make re-usable for next debug session
*/
void Cleanup();
/**
* @brief Start the debugger
* The debugger starts in 2 phases:
* 1. A "Start" command is sent over to the debugger
* 2. When the "Start" command is successfully executed on the codelite-lldb side, the caller should call 'Run()'. Run() will use the arguments passed to this command
* @param runCommand
*/
void Start(const LLDBCommand& runCommand);
/**
* @brief debug a core file
*/
void OpenCoreFile(const LLDBCommand& runCommand);
/**
* @brief attach to process with PID
*/
void AttachProcessWithPID(const LLDBCommand& runCommand);
/**
* @brief instruct the debugger to 'run'
*/
void Run();
/**
* @brief
* @param reason
*/
void Interrupt(eInterruptReason reason);
/**
* @brief select a given frame
*/
void SelectFrame(int frameID);
/**
* @brief select a given thread by its ID
*/
void SelectThread(int threadID);
/**
* @brief evaluate an expression
*/
void EvaluateExpression(const wxString &expression);
/**
* @brief step over to next instruction
*/
void NextInstruction();
/**
* @brief step over to next instruction
*/
void ShowCurrentFileLine();
protected:
/**
* @brief establish connection to codelite-lldb server
* @param timeout number of seconds to wait until successfull connect
* @return true on success, false otherwise
*/
bool ConnectToLocalDebugger(LLDBConnectReturnObject& ret, int timeout = 10);
/**
* @brief established connection to codelite-lldb over TCP/IP
* @param ip codelite-lldb listen IP
* @param port codelite-lldb listen port
* @param timeout number of seconds to wait until successfull connect
* @return true on success, false otherwise
*/
bool ConnectToRemoteDebugger(const wxString &ip, int port, LLDBConnectReturnObject& ret, int timeout = 10);
};
#endif // LLDBCONNECTOR_H
|