File: CodeLiteLLDBApp.h

package info (click to toggle)
codelite 10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 71,364 kB
  • sloc: cpp: 415,397; ansic: 18,277; php: 9,547; lex: 4,181; yacc: 2,820; python: 2,294; sh: 383; makefile: 51; xml: 13
file content (159 lines) | stat: -rw-r--r-- 5,470 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : CodeLiteLLDBApp.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 CODELITE_LLDB_APP_H
#define CODELITE_LLDB_APP_H

#include <wx/app.h>
#include <wx/cmdline.h>
#include "LLDBProtocol/LLDBCommand.h"
#include "SocketAPI/clSocketClient.h"
#include "codelite-lldb/LLDBNetworkServerThread.h"
#include <lldb/API/SBDebugger.h>
#include <lldb/API/SBTarget.h>
#include "LLDBProtocol/LLDBEnums.h"
#include "LLDBProcessEventHandlerThread.h"
#include "LLDBProtocol/LLDBReply.h"
#include "SocketAPI/clSocketServer.h"
#include "LLDBProtocol/LLDBVariable.h"
#include <lldb/API/SBValue.h>
#include <wx/msgqueue.h>
#include "LLDBProtocol/LLDBSettings.h"

struct VariableWrapper
{
    lldb::SBValue value;
    bool isWatch;
    wxString expression;
    
    VariableWrapper() : isWatch(false) {}
};

class CodeLiteLLDBApp
{
public:
    typedef void (CodeLiteLLDBApp::*CommandFunc_t)(const LLDBCommand& command);
    typedef std::pair<CodeLiteLLDBApp::CommandFunc_t, LLDBCommand> QueueItem_t;

    typedef void (CodeLiteLLDBApp::*NotifyFunc_t)();

protected:
    clSocketServer m_acceptSocket;
    LLDBNetworkServerThread* m_networkThread;
    LLDBProcessEventHandlerThread* m_lldbProcessEventThread;
    lldb::SBDebugger m_debugger;
    lldb::SBTarget m_target;
    int m_debuggeePid;
    clSocketBase::Ptr_t m_replySocket;
    eInterruptReason m_interruptReason;
    std::map<int, VariableWrapper> m_variables;
    wxArrayString m_watches;
    wxMessageQueue<CodeLiteLLDBApp::QueueItem_t> m_commands_queue;
    wxMessageQueue<CodeLiteLLDBApp::NotifyFunc_t> m_notify_queue;
    wxString m_debuggerSocketPath;
    bool m_exitMainLoop;
    LLDBSettings m_settings;
    eLLDBDebugSessionType m_sessionType;
    wxString m_ip;
    int m_port;

private:
    void Cleanup();
    void AcceptNewConnection() throw(clSocketException);
    bool InitializeLLDB(const LLDBCommand& command);
    void DoInitializeApp();
    void DoExecutueShellCommand(const wxString& command, bool printOutput = true);

public:
    void NotifyStoppedOnFirstEntry();
    void NotifyStopped();
    void NotifyExited();
    void NotifyAborted();
    void NotifyStarted(eLLDBDebugSessionType sessionType);
    void NotifyRunning();
    void NotifyBreakpointsUpdated();
    void NotifyAllBreakpointsDeleted();

    void NotifyLocals(LLDBVariable::Vect_t locals);

    void SendReply(const LLDBReply& reply);
    bool CanInteract();
    bool IsDebugSessionInProgress();

    /**
     * @brief push new handler to the queue
     */
    void CallAfter(CodeLiteLLDBApp::CommandFunc_t func, const LLDBCommand& command);

    void CallAfter(CodeLiteLLDBApp::NotifyFunc_t func) { m_notify_queue.Post(func); }

    /**
     * @brief start codelite-lldb
     */
    void MainLoop();

public:
    CodeLiteLLDBApp(const wxString& socketPath);
    CodeLiteLLDBApp(const wxString& ip, int port);
    virtual ~CodeLiteLLDBApp();

    /**
     * @brief intialize the application
     */
    virtual bool OnInit();
    /**
     * @brief perform cleanup before exiting
     */
    virtual int OnExit();

    // callback from the network thread
    void StartDebugger(const LLDBCommand& command);
    void RunDebugger(const LLDBCommand& command);
    void Continue(const LLDBCommand& command);
    void ApplyBreakpoints(const LLDBCommand& command);
    void StopDebugger(const LLDBCommand& command);
    void DetachDebugger(const LLDBCommand& command);
    void DeleteBreakpoints(const LLDBCommand& command);
    void DeleteAllBreakpoints(const LLDBCommand& command);
    void Next(const LLDBCommand& command);
    void NextInstruction(const LLDBCommand& command);
    void AddWatch(const LLDBCommand& command);
    void ExecuteInterperterCommand(const LLDBCommand& command);
    void DeleteWatch(const LLDBCommand& command);
    void StepIn(const LLDBCommand& command);
    void StepOut(const LLDBCommand& command);
    void Interrupt(const LLDBCommand& command);
    void LocalVariables(const LLDBCommand& command);
    void ExpandVariable(const LLDBCommand& command);
    void SelectFrame(const LLDBCommand& command);
    void SelectThread(const LLDBCommand& command);
    void EvalExpression(const LLDBCommand& command);
    void OpenCoreFile(const LLDBCommand& command);
    void AttachProcess(const LLDBCommand& command);
    void ShowCurrentFileLine(const LLDBCommand& command);
};

DECLARE_APP(CodeLiteLLDBApp)
#endif // CODELITE_LLDB_APP_H