| 1 |
#ifndef DAPMAINVIEW_H |
| 2 |
#define DAPMAINVIEW_H |
| 3 |
|
| 4 |
#include "UI.h" |
| 5 |
#include "clModuleLogger.hpp" |
| 6 |
#include "dap/Client.hpp" |
| 7 |
#include "dap/DAPEvent.hpp" |
| 8 |
#include "dap/dap.hpp" |
| 9 |
|
| 10 |
#include <unordered_set> |
| 11 |
#include <wx/timer.h> |
| 12 |
|
| 13 |
class wxTimer; |
| 14 |
class DebugAdapterClient; |
| 15 |
|
| 16 |
// variable items client data |
| 17 |
struct VariableClientData : public wxTreeItemData { |
| 18 |
int reference = wxNOT_FOUND; |
| 19 |
wxString value; // untrucated value |
| 20 |
VariableClientData(int ref, const wxString& v) |
| 21 |
: reference(ref) |
| 22 |
, value(v) |
| 23 |
{ |
| 24 |
} |
| 25 |
virtual ~VariableClientData() {} |
| 26 |
}; |
| 27 |
|
| 28 |
enum class FrameOrThread { |
| 29 |
THREAD, |
| 30 |
FRAME, |
| 31 |
}; |
| 32 |
|
| 33 |
// every entry in the threads tree has this item data |
| 34 |
struct FrameOrThreadClientData : public wxTreeItemData { |
| 35 |
FrameOrThread type; |
| 36 |
dap::StackFrame frame_info; |
| 37 |
dap::Thread thread_info; |
| 38 |
bool loaded = false; |
| 39 |
|
| 40 |
FrameOrThreadClientData(const dap::StackFrame& frameInfo) |
| 41 |
: type(FrameOrThread::FRAME) |
| 42 |
, frame_info(frameInfo) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
FrameOrThreadClientData(const dap::Thread& threadInfo) |
| 47 |
: type(FrameOrThread::THREAD) |
| 48 |
, thread_info(threadInfo) |
| 49 |
{ |
| 50 |
} |
| 51 |
|
| 52 |
virtual ~FrameOrThreadClientData() {} |
| 53 |
|
| 54 |
bool IsFrame() const { return type == FrameOrThread::FRAME; } |
| 55 |
bool IsThread() const { return type == FrameOrThread::THREAD; } |
| 56 |
|
| 57 |
int GetId() const |
| 58 |
{ |
| 59 |
if(IsFrame()) { |
| 60 |
return frame_info.id; |
| 61 |
} else { |
| 62 |
return thread_info.id; |
| 63 |
} |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
/// -------------------------------------------------------------------- |
| 68 |
|
| 69 |
class DAPMainView : public DAPMainViewBase |
| 70 |
{ |
| 71 |
DebugAdapterClient* m_plugin = nullptr; |
| 72 |
wxTimer* m_timer = nullptr; |
| 73 |
// the variables displayed in the view are owned by this frame Id |
| 74 |
int m_scopesFrameId = wxNOT_FOUND; |
| 75 |
|
| 76 |
clModuleLogger& LOG; |
| 77 |
|
| 78 |
protected: |
| 79 |
wxTreeItemId FindThreadNode(int threadId); |
| 80 |
wxTreeItemId FindVariableNode(int refId); |
| 81 |
|
| 82 |
FrameOrThreadClientData* GetFrameClientData(const wxTreeItemId& item); |
| 83 |
VariableClientData* GetVariableClientData(const wxTreeItemId& item); |
| 84 |
|
| 85 |
void OnTimerCheckCanInteract(wxTimerEvent& event); |
| 86 |
int GetThreadId(const wxTreeItemId& item); |
| 87 |
int GetVariableId(const wxTreeItemId& item); |
| 88 |
int GetFrameId(const wxTreeItemId& item); |
| 89 |
|
| 90 |
void DoThreadExpanding(const wxTreeItemId& item); |
| 91 |
bool DoCopyBacktrace(const wxTreeItemId& item, wxString* content); |
| 92 |
void OnThreadItemExpanding(wxTreeEvent& event); |
| 93 |
void OnFrameItemSelected(wxTreeEvent& event); |
| 94 |
void OnThreadsListMenu(wxTreeEvent& event); |
| 95 |
void OnVariablesMenu(wxTreeEvent& event); |
| 96 |
void OnScopeItemExpanding(wxTreeEvent& event); |
| 97 |
void Clear(); |
| 98 |
|
| 99 |
public: |
| 100 |
DAPMainView(wxWindow* parent, DebugAdapterClient* plugin, clModuleLogger& log); |
| 101 |
virtual ~DAPMainView(); |
| 102 |
|
| 103 |
void UpdateThreads(int activeThreadId, dap::ThreadsResponse* response); |
| 104 |
void UpdateFrames(int threadId, dap::StackTraceResponse* response); |
| 105 |
void UpdateScopes(int frameId, dap::ScopesResponse* response); |
| 106 |
void UpdateVariables(int parentRef, dap::VariablesResponse* response); |
| 107 |
/** |
| 108 |
* @brief return list of thread-id that are expanded in the UI |
| 109 |
*/ |
| 110 |
std::unordered_set<int> GetExpandedThreads(); |
| 111 |
|
| 112 |
void SetDisabled(bool b); |
| 113 |
bool IsDisabled() const; |
| 114 |
|
| 115 |
int GetCurrentFrameId() const { return m_scopesFrameId; } |
| 116 |
}; |
| 117 |
#endif // DAPMAINVIEW_H |