-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy paththreadframes.h
More file actions
223 lines (181 loc) · 6.2 KB
/
threadframes.h
File metadata and controls
223 lines (181 loc) · 6.2 KB
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
/*
Copyright 2020-2026 Vector 35 Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <QtWidgets/QTreeView>
#include <QStyledItemDelegate>
#include <QAbstractItemModel>
#include <QHeaderView>
#include <QGuiApplication>
#include <QMimeData>
#include <QClipboard>
#include "binaryninjaapi.h"
#include "globalarea.h"
#include "viewframe.h"
#include "fontsettings.h"
#include "debuggerapi.h"
#include "inttypes.h"
#include "ui.h"
#include "fmt/format.h"
using namespace BinaryNinjaDebuggerAPI;
using namespace BinaryNinja;
using namespace std;
class FrameItem
{
public:
FrameItem() = default;
FrameItem(const DebugThread& thread, FrameItem* parentItem = nullptr) :
m_isFrozen(thread.m_isFrozen), m_tid(thread.m_tid), m_threadPc(thread.m_rip), m_parentItem(parentItem)
{}
FrameItem(const DebugThread& thread, const DebugFrame& frame, FrameItem* parentItem = nullptr) :
m_isFrame(true), m_tid(thread.m_tid), m_threadPc(thread.m_rip), m_frameIndex(frame.m_index),
m_module(frame.m_module), m_framePc(frame.m_pc), m_sp(frame.m_sp), m_fp(frame.m_fp), m_parentItem(parentItem)
{
// WinDbg always reports the function name with the module prefix, we remove it for conciseness
auto trimmedFunctionName = frame.m_functionName;
auto prefix = m_module + '!';
if (trimmedFunctionName.compare(0, prefix.size(), prefix) == 0)
trimmedFunctionName.erase(0, prefix.size());
// Only show the offset if it is not 0x0
uint64_t offset = frame.m_pc - frame.m_functionStart;
if (offset != 0 && !trimmedFunctionName.empty())
m_function = fmt::format("{} + {:#x}", trimmedFunctionName, offset);
else if (offset == 0)
m_function = trimmedFunctionName;
else
m_function = fmt::format("{:#x}", offset);
}
~FrameItem();
void appendChild(FrameItem* child);
FrameItem* child(int row);
int childCount() const;
int row() const;
FrameItem* parentItem();
bool isFrame() const { return m_isFrame; }
bool isFrozen() const { return m_isFrozen; }
uint32_t tid() const { return m_tid; }
uint64_t threadPc() const { return m_threadPc; }
uint64_t framePc() const { return m_framePc; }
uint64_t sp() const { return m_sp; }
uint64_t fp() const { return m_fp; }
size_t frameIndex() const { return m_frameIndex; }
std::string module() const { return m_module; }
std::string function() const { return m_function; }
private:
bool m_isFrame {false};
bool m_isFrozen {false};
uint32_t m_tid {};
uint64_t m_threadPc {};
size_t m_frameIndex {};
std::string m_module {};
std::string m_function {};
uint64_t m_framePc {};
uint64_t m_sp {};
uint64_t m_fp {};
QList<FrameItem*> m_childItems;
FrameItem* m_parentItem {nullptr};
};
Q_DECLARE_METATYPE(FrameItem);
class ThreadFrameModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum ColumnHeaders
{
StateColumn,
ThreadColumn,
FrameIndexColumn,
ModuleColumn,
FunctionColumn,
PcColumn,
SpColumn,
FpColumn,
};
explicit ThreadFrameModel(QObject* parent = nullptr, DebuggerControllerRef controller = nullptr);
~ThreadFrameModel();
QVariant data(const QModelIndex& index, int role) const override;
QVariant headerData(int column, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& index) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override
{
(void)parent;
return 8;
}
void updateRows(DebuggerController* controller);
private:
FrameItem* rootItem;
DebuggerControllerRef m_controller = nullptr;
};
class ThreadFramesItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
QFont m_font;
int m_baseline, m_charWidth, m_charHeight, m_charOffset;
DbgRef<DebuggerController> m_debugger;
public:
ThreadFramesItemDelegate(QWidget* parent, DebuggerController* controller);
void updateFonts();
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& idx) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& idx) const;
};
class ThreadFramesWidget : public QTreeView
{
Q_OBJECT
ViewFrame* m_view;
DbgRef<DebuggerController> m_debugger;
ThreadFrameModel* m_model;
ThreadFramesItemDelegate* m_delegate;
UIActionHandler m_actionHandler;
ContextMenuManager* m_contextMenuManager;
Menu* m_menu;
size_t m_debuggerEventCallback;
virtual void contextMenuEvent(QContextMenuEvent* event) override;
bool selectionNotEmpty();
bool canSuspendOrResume();
void expandCurrentThread();
void updateContent();
signals:
void debuggerEvent(const DebuggerEvent& event);
public slots:
void onDebuggerEvent(const DebuggerEvent& event);
public:
ThreadFramesWidget(QWidget* parent, ViewFrame* view, BinaryViewRef debugger);
~ThreadFramesWidget();
void updateFonts();
private slots:
void onDoubleClicked();
void suspendThread();
void resumeThread();
void makeItSoloThread();
void copy();
void copyCurrentFrame();
void copyAllFrames();
};
class ThreadFramesContainer : public SidebarWidget
{
ThreadFramesWidget* m_widget;
public:
ThreadFramesContainer(ViewFrame* frame, BinaryViewRef data);
void notifyFontChanged() override;
};
class ThreadFramesSidebarWidgetType : public SidebarWidgetType
{
public:
ThreadFramesSidebarWidgetType();
SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override;
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::RightBottom; }
SidebarContextSensitivity contextSensitivity() const override { return PerViewTypeSidebarContext; }
SidebarIconVisibility defaultIconVisibility() const override { return HideSidebarIconIfNoContent; }
SidebarContentClassifier* contentClassifier(ViewFrame*, BinaryViewRef) override;
};