Display thread names

extract thread names from QThread object name

Task-Number: QTCREATORBUG-382
Reviewed-by: hjk
This commit is contained in:
Arvid Ephraim Picciani
2010-09-13 12:37:30 +02:00
parent f7b19f8114
commit 98736d256b
7 changed files with 86 additions and 2 deletions

View File

@@ -2042,6 +2042,7 @@ void DebuggerPluginPrivate::connectEngine(DebuggerEngine *engine, bool notify)
m_stackWindow->setModel(engine->stackModel());
m_threadsWindow->setModel(engine->threadsModel());
m_threadBox->setModel(engine->threadsModel());
m_threadBox->setModelColumn(ThreadData::NameColumn);
m_watchersWindow->setModel(engine->watchersModel());
m_capabilities = engine->debuggerCapabilities();
if (notify)

View File

@@ -2963,6 +2963,7 @@ void GdbEngine::handleThreadInfo(const GdbResponse &response)
response.data.findChild("current-thread-id").data().toInt();
threadsHandler()->setCurrentThreadId(currentThreadId);
plugin()->updateState(this); // Adjust Threads combobox.
postCommand("threadnames " + theDebuggerAction(MaximalStackDepth)->value().toByteArray(), CB(handleThreadNames), id);
} else {
// Fall back for older versions: Try to get at least a list
// of running threads.
@@ -2986,6 +2987,31 @@ void GdbEngine::handleThreadListIds(const GdbResponse &response)
threadsHandler()->setCurrentThreadId(id);
}
void GdbEngine::handleThreadNames(const GdbResponse &response)
{
if (response.resultClass == GdbResultDone) {
GdbMi contents = response.data.findChild("consolestreamoutput");
GdbMi names;
names.fromString(contents.data());
Threads threads = threadsHandler()->threads();
foreach (const GdbMi &name, names.children()) {
int id = name.findChild("id").data().toInt();
for (int index = 0, n = threads.size(); index != n; ++index) {
ThreadData & thread = threads[index];
if (thread.id == id) {
thread.name = decodeData(name.findChild("value").data(), name.findChild("valueencoded").data().toInt());
break;
}
}
}
threadsHandler()->setThreads(threads);
plugin()->updateState(this);
}
}
//////////////////////////////////////////////////////////////////////
//

View File

@@ -435,6 +435,7 @@ private: ////////// View & Data Stuff //////////
void handleStackSelectFrame(const GdbResponse &response);
void handleThreadListIds(const GdbResponse &response);
void handleThreadInfo(const GdbResponse &response);
void handleThreadNames(const GdbResponse &response);
Q_SLOT void reloadStack(bool forceGotoLocation);
Q_SLOT virtual void reloadFullStack();
int currentFrame() const;

View File

@@ -149,6 +149,10 @@ QVariant ThreadsHandler::data(const QModelIndex &index, int role) const
return thread.core;
case ThreadData::StateColumn:
return thread.state;
case ThreadData::NameColumn:
if (thread.name.isEmpty())
return thread.id;
return thread.name;
}
case Qt::ToolTipRole:
return threadToolTip(thread);
@@ -183,6 +187,8 @@ QVariant ThreadsHandler::headerData
return tr("Core");
case ThreadData::StateColumn:
return tr("State");
case ThreadData::NameColumn:
return tr("Name");
}
return QVariant();
}

View File

@@ -59,6 +59,7 @@ struct ThreadData
FileColumn,
LineColumn,
StateColumn,
NameColumn,
CoreColumn,
ColumnCount = CoreColumn
};
@@ -77,6 +78,7 @@ struct ThreadData
QString fileName;
QString state;
int lineNumber;
QString name;
};
typedef QVector<ThreadData> Threads;

View File

@@ -716,6 +716,12 @@ QString decodeData(const QByteArray &ba, int encoding)
return doubleQuote + QString::fromUtf16(reinterpret_cast<const ushort *>
(decodedBa.data()), decodedBa.size() / 2) + doubleQuote;
}
case 12: { // %04x encoded 16 bit data, Little Endian, without quotes (see 7)
const QByteArray decodedBa = QByteArray::fromHex(ba);
//qDebug() << quoteUnprintableLatin1(decodedBa) << "\n\n";
return QString::fromUtf16(reinterpret_cast<const ushort *>
(decodedBa.data()), decodedBa.size() / 2);
}
}
qDebug() << "ENCODING ERROR: " << encoding;
return QCoreApplication::translate("Debugger", "<Encoding error>");