Commit fefbc172 authored by hjk's avatar hjk

Debugger: Use thread id, not model row to remember current thread

Task-number: QTCREATORBUG-9207
Change-Id: Ic98fb9a99c250dccf2735f28d0d3fefa7d1da52f
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 7f6c793f
......@@ -52,6 +52,7 @@ public:
bool isValid() const { return m_id != -1; }
qint64 raw() const { return m_id; }
bool operator==(const ThreadId other) const { return m_id == other.m_id; }
bool operator!=(const ThreadId other) const { return m_id != other.m_id; }
private:
qint64 m_id;
......
......@@ -130,7 +130,7 @@ static QString threadToolTip(const ThreadData &thread)
*/
ThreadsHandler::ThreadsHandler()
: m_currentIndex(-1),
: m_currentId(),
m_positionIcon(QLatin1String(":/debugger/images/location_16.png")),
m_emptyIcon(QLatin1String(":/debugger/images/debugger_empty_14.png"))
{
......@@ -140,6 +140,11 @@ ThreadsHandler::ThreadsHandler()
// m_proxyModel->setSourceModel(this);
}
int ThreadsHandler::currentThreadIndex() const
{
return indexOf(m_currentId);
}
int ThreadsHandler::rowCount(const QModelIndex &parent) const
{
// Since the stack is not a tree, row count is 0 for any valid parent.
......@@ -196,7 +201,7 @@ QVariant ThreadsHandler::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
// Return icon that indicates whether this is the active stack frame.
if (index.column() == 0)
return (index.row() == m_currentIndex) ? m_positionIcon : m_emptyIcon;
return (thread.id == m_currentId) ? m_positionIcon : m_emptyIcon;
break;
case ThreadData::IdRole:
return thread.id.raw();
......@@ -246,9 +251,7 @@ Qt::ItemFlags ThreadsHandler::flags(const QModelIndex &index) const
ThreadId ThreadsHandler::currentThread() const
{
if (m_currentIndex < 0 || m_currentIndex >= m_threads.size())
return ThreadId();
return m_threads[m_currentIndex].id;
return m_currentId;
}
ThreadId ThreadsHandler::threadAt(int index) const
......@@ -259,23 +262,22 @@ ThreadId ThreadsHandler::threadAt(int index) const
void ThreadsHandler::setCurrentThread(ThreadId id)
{
const int index = indexOf(id);
if (index == m_currentIndex)
if (id == m_currentId)
return;
const int index = indexOf(id);
if (index == -1) {
qWarning("ThreadsHandler::setCurrentThreadId: No such thread %d.", int(id.raw()));
return;
}
// Emit changed for previous frame.
if (m_currentIndex != -1)
dataChanged(m_currentIndex);
threadDataChanged(m_currentId);
m_currentIndex = index;
m_currentId = id;
// Emit changed for new frame.
dataChanged(m_currentIndex);
threadDataChanged(m_currentId);
updateThreadBox();
}
......@@ -297,7 +299,7 @@ void ThreadsHandler::updateThread(const ThreadData &thread)
endInsertRows();
} else {
mergeThreadData(m_threads[i], thread);
dataChanged(i);
threadDataChanged(thread.id);
}
}
......@@ -315,8 +317,14 @@ void ThreadsHandler::setThreads(const Threads &threads)
{
beginResetModel();
m_threads = threads;
if (m_currentIndex >= m_threads.size())
m_currentIndex = -1;
bool found = false;
for (int i = 0, n = m_threads.size(); i < n; ++i)
if (threads.at(i).id == m_currentId) {
found = true;
break;
}
if (!found)
m_currentId = ThreadId();
m_resetLocationScheduled = false;
endResetModel();
updateThreadBox();
......@@ -327,13 +335,17 @@ void ThreadsHandler::updateThreadBox()
QStringList list;
foreach (const ThreadData &thread, m_threads)
list.append(QString::fromLatin1("#%1 %2").arg(thread.id.raw()).arg(thread.name));
debuggerCore()->setThreads(list, m_currentIndex);
debuggerCore()->setThreads(list, indexOf(m_currentId));
}
void ThreadsHandler::dataChanged(int index)
void ThreadsHandler::threadDataChanged(ThreadId id)
{
Q_UNUSED(index);
layoutChanged();
int row = indexOf(id);
if (row < 0)
return;
QModelIndex l = index(row, 0);
QModelIndex r = index(row, ThreadData::ColumnCount - 1);
dataChanged(l, r);
}
Threads ThreadsHandler::threads() const
......@@ -351,7 +363,7 @@ void ThreadsHandler::removeAll()
{
beginResetModel();
m_threads.clear();
m_currentIndex = -1;
m_currentId = ThreadId();
endResetModel();
}
......@@ -381,7 +393,7 @@ void ThreadsHandler::notifyRunning(ThreadId id)
int i = indexOf(id);
if (i >= 0) {
m_threads[i].notifyRunning();
dataChanged(i);
threadDataChanged(id);
}
}
......@@ -411,7 +423,7 @@ void ThreadsHandler::notifyStopped(ThreadId id)
int i = indexOf(id);
if (i >= 0) {
m_threads[i].stopped = true;
dataChanged(i);
threadDataChanged(id);
}
}
......@@ -423,15 +435,10 @@ void ThreadsHandler::updateThreads(const GdbMi &data)
// state="stopped",core="0"}],current-thread-id="1"
// Emit changed for previous frame.
if (m_currentIndex != -1) {
dataChanged(m_currentIndex);
m_currentIndex = -1;
}
ThreadId currentId;
const GdbMi current = data["current-thread-id"];
if (current.isValid())
currentId = ThreadId(current.data().toLongLong());
// if (m_currentIndex != -1) {
// rowChanged(m_currentIndex);
// m_currentIndex = -1;
// }
const QList<GdbMi> items = data["threads"].children();
const int n = items.size();
......@@ -449,17 +456,20 @@ void ThreadsHandler::updateThreads(const GdbMi &data)
thread.fileName = frame["fullname"].toLatin1();
thread.lineNumber = frame["line"].toInt();
thread.module = QString::fromLocal8Bit(frame["from"].data());
thread.stopped = true;
thread.name = item["name"].toLatin1();
if (thread.state == QLatin1String("running"))
thread.stopped = false;
if (thread.id == currentId)
m_currentIndex = index;
thread.stopped = thread.state != QLatin1String("running");
updateThread(thread);
}
if (m_currentIndex != -1)
dataChanged(m_currentIndex);
const GdbMi current = data["current-thread-id"];
if (current.isValid()) {
ThreadId currentId = ThreadId(current.data().toLongLong());
if (currentId != m_currentId) {
threadDataChanged(m_currentId);
m_currentId = currentId;
threadDataChanged(m_currentId);
}
}
updateThreadBox();
}
......
......@@ -57,7 +57,7 @@ class ThreadsHandler : public QAbstractTableModel
public:
ThreadsHandler();
int currentThreadIndex() const { return m_currentIndex; }
int currentThreadIndex() const;
ThreadId currentThread() const;
ThreadId threadAt(int index) const;
void setCurrentThread(ThreadId id);
......@@ -93,10 +93,10 @@ private:
int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
void updateThreadBox();
void dataChanged(int index);
void threadDataChanged(ThreadId id);
Threads m_threads;
int m_currentIndex;
ThreadId m_currentId;
const QIcon m_positionIcon;
const QIcon m_emptyIcon;
......
......@@ -3964,7 +3964,7 @@ namespace qthread {
// Check j 3 int.
// CheckType this qthread::Thread.
// Check this.@1 QThread.
// Check this.@1.@1 "This is thread #3" QObject.
// Check this.@1.@1 "Thread #3" QObject.
// Continue.
dummyStatement(this);
}
......@@ -3982,7 +3982,7 @@ namespace qthread {
Thread thread[N];
for (int i = 0; i != N; ++i) {
thread[i].setId(i);
thread[i].setObjectName("This is thread #" + QString::number(i));
thread[i].setObjectName("Thread #" + QString::number(i));
thread[i].start();
}
BREAK_HERE;
......@@ -3993,9 +3993,9 @@ namespace qthread {
// Expand thread.13.@1.
// CheckType thread qthread::Thread [14].
// Check thread.0 qthread::Thread.
// Check thread.0.@1.@1 "This is thread #0" qthread::Thread.
// Check thread.0.@1.@1 "Thread #0" qthread::Thread.
// Check thread.13 qthread::Thread.
// Check thread.13.@1.@1 "This is thread #13" qthread::Thread.
// Check thread.13.@1.@1 "Thread #13" qthread::Thread.
// Continue.
for (int i = 0; i != N; ++i) {
thread[i].wait();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment