forked from eteran/edb-debugger
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadsModel.cpp
More file actions
131 lines (107 loc) · 3.22 KB
/
Copy pathThreadsModel.cpp
File metadata and controls
131 lines (107 loc) · 3.22 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
/*
Copyright (C) 2014 - 2015 Evan Teran
evan.teran@gmail.com
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ThreadsModel.h"
#include "IThread.h"
#include "edb.h"
#include <QtAlgorithms>
ThreadsModel::ThreadsModel(QObject *parent) : QAbstractItemModel(parent) {
}
QModelIndex ThreadsModel::index(int row, int column, const QModelIndex &parent) const {
Q_UNUSED(parent)
if(row >= rowCount(parent) || column >= columnCount(parent)) {
return QModelIndex();
}
if(row >= 0) {
return createIndex(row, column, const_cast<Item *>(&items_[row]));
} else {
return createIndex(row, column);
}
}
QModelIndex ThreadsModel::parent(const QModelIndex &index) const {
Q_UNUSED(index)
return QModelIndex();
}
QVariant ThreadsModel::data(const QModelIndex &index, int role) const {
if(index.isValid()) {
const Item &item = items_[index.row()];
if(role == Qt::DisplayRole) {
switch(index.column()) {
case 0:
if(item.current) {
return tr("*%1").arg(item.thread->tid());
} else {
return QVariant::fromValue(item.thread->tid());
}
case 1:
return item.thread->priority();
case 2:
{
const QString default_region_name;
const QString symname = edb::v1::find_function_symbol(item.thread->instruction_pointer(), default_region_name);
if(!symname.isEmpty()) {
return QString("%1 <%2>").arg(edb::v1::format_pointer(item.thread->instruction_pointer()), symname);
} else {
return QString("%1").arg(edb::v1::format_pointer(item.thread->instruction_pointer()));
}
}
case 3:
return item.thread->runState();
case 4:
return item.thread->name();
}
} else if(role == Qt::UserRole) {
return QVariant::fromValue(item.thread->tid());
}
}
return QVariant();
}
QVariant ThreadsModel::headerData(int section, Qt::Orientation orientation, int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) {
case 0:
return tr("ID");
case 1:
return tr("Priority");
case 2:
return tr("Instruction Pointer");
case 3:
return tr("State");
case 4:
return tr("Name");
}
}
return QVariant();
}
int ThreadsModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent)
return 5;
}
int ThreadsModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent)
return items_.size();
}
void ThreadsModel::addThread(const std::shared_ptr<IThread> &thread, bool current) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
const Item item = {
thread, current
};
items_.push_back(item);
endInsertRows();
}
void ThreadsModel::clear() {
beginRemoveRows(QModelIndex(), 0, rowCount());
items_.clear();
endRemoveRows();
}