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
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : LLDBNetworkServerThread.cpp
//
// -------------------------------------------------------------------------
// 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.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "LLDBNetworkServerThread.h"
#include "SocketAPI/clSocketServer.h"
#include "LLDBProtocol/LLDBCommand.h"
#include "codelite-lldb/CodeLiteLLDBApp.h"
#include <wx/wxcrtvararg.h>
LLDBNetworkServerThread::LLDBNetworkServerThread(CodeLiteLLDBApp* app, socket_t fd)
: wxThread(wxTHREAD_JOINABLE)
, m_app(app)
{
m_socket.reset(new clSocketBase(fd));
// we don't own the socket, so don't close it when we are going down
m_socket->SetCloseOnExit(false);
}
LLDBNetworkServerThread::~LLDBNetworkServerThread()
{
if(IsAlive()) {
Delete(NULL, wxTHREAD_WAIT_BLOCK);
} else {
Wait(wxTHREAD_WAIT_BLOCK);
}
}
void* LLDBNetworkServerThread::Entry()
{
clSocketServer server;
wxPrintf("codelite-lldb: successfully started network thread. Reading input on fd=%d\n",
(int)m_socket->GetSocket());
try {
// we got connection, enter the main loop
while(!TestDestroy()) {
wxString str;
if(m_socket->ReadMessage(str, 1) == clSocketBase::kSuccess) {
// wxPrintf("codelite-lldb: received command\n%s\n", str);
// Process command
LLDBCommand command(str);
switch(command.GetCommandType()) {
case kCommandInterperterCommand:
m_app->CallAfter(&CodeLiteLLDBApp::ExecuteInterperterCommand, command);
break;
case kCommandAddWatch:
m_app->CallAfter(&CodeLiteLLDBApp::AddWatch, command);
break;
case kCommandDeleteWatch:
m_app->CallAfter(&CodeLiteLLDBApp::DeleteWatch, command);
break;
case kCommandNextInstruction:
m_app->CallAfter(&CodeLiteLLDBApp::NextInstruction, command);
break;
case kCommandCurrentFileLine:
m_app->CallAfter(&CodeLiteLLDBApp::ShowCurrentFileLine, command);
break;
case kCommandStart:
m_app->CallAfter(&CodeLiteLLDBApp::StartDebugger, command);
break;
case kCommandDebugCoreFile:
m_app->CallAfter(&CodeLiteLLDBApp::OpenCoreFile, command);
break;
case kCommandAttachProcess:
m_app->CallAfter(&CodeLiteLLDBApp::AttachProcess, command);
break;
case kCommandRun:
m_app->CallAfter(&CodeLiteLLDBApp::RunDebugger, command);
break;
case kCommandApplyBreakpoints:
m_app->CallAfter(&CodeLiteLLDBApp::ApplyBreakpoints, command);
break;
case kCommandContinue:
m_app->CallAfter(&CodeLiteLLDBApp::Continue, command);
break;
case kCommandStop:
m_app->CallAfter(&CodeLiteLLDBApp::StopDebugger, command);
break;
case kCommandDetach:
m_app->CallAfter(&CodeLiteLLDBApp::DetachDebugger, command);
break;
case kCommandDeleteBreakpoint:
m_app->CallAfter(&CodeLiteLLDBApp::DeleteBreakpoints, command);
break;
case kCommandDeleteAllBreakpoints:
m_app->CallAfter(&CodeLiteLLDBApp::DeleteAllBreakpoints, command);
break;
case kCommandNext:
m_app->CallAfter(&CodeLiteLLDBApp::Next, command);
break;
case kCommandStepIn:
m_app->CallAfter(&CodeLiteLLDBApp::StepIn, command);
break;
case kCommandStepOut:
m_app->CallAfter(&CodeLiteLLDBApp::StepOut, command);
break;
case kCommandInterrupt:
m_app->CallAfter(&CodeLiteLLDBApp::Interrupt, command);
break;
case kCommandGetLocals:
m_app->CallAfter(&CodeLiteLLDBApp::LocalVariables, command);
break;
case kCommandExpandVariable:
m_app->CallAfter(&CodeLiteLLDBApp::ExpandVariable, command);
break;
case kCommandSelectFrame:
m_app->CallAfter(&CodeLiteLLDBApp::SelectFrame, command);
break;
case kCommandSelectThread:
m_app->CallAfter(&CodeLiteLLDBApp::SelectThread, command);
break;
case kCommandEvalExpression:
m_app->CallAfter(&CodeLiteLLDBApp::EvalExpression, command);
break;
default:
break;
}
}
}
} catch(clSocketException& e) {
wxPrintf("codelite-lldb: error while reading message. %s\n", e.what().c_str());
m_app->CallAfter(&CodeLiteLLDBApp::NotifyAborted);
return NULL;
}
wxPrintf("codelite-lldb: network thread: leaving main loop\n");
return NULL;
}
|