summaryrefslogtreecommitdiff
path: root/src/plugins/debugger/cdb/cdbstacktracecontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/debugger/cdb/cdbstacktracecontext.cpp')
-rw-r--r--src/plugins/debugger/cdb/cdbstacktracecontext.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/plugins/debugger/cdb/cdbstacktracecontext.cpp b/src/plugins/debugger/cdb/cdbstacktracecontext.cpp
index 40cd9776bc..3e5f1c65fc 100644
--- a/src/plugins/debugger/cdb/cdbstacktracecontext.cpp
+++ b/src/plugins/debugger/cdb/cdbstacktracecontext.cpp
@@ -219,5 +219,105 @@ void CdbStackTraceContext::format(QTextStream &str) const
}
}
+// Thread state helper
+
+static inline QString msgGetThreadStateFailed(unsigned long threadId, const QString &why)
+{
+ return QString::fromLatin1("Unable to determine the state of thread %1: %2").arg(threadId).arg(why);
+}
+
+static inline bool getStoppedThreadState(const CdbComInterfaces &cif,
+ ThreadData *t,
+ QString *errorMessage)
+{
+ ULONG currentThread;
+ HRESULT hr = cif.debugSystemObjects->GetCurrentThreadId(&currentThread);
+ if (FAILED(hr)) {
+ *errorMessage = msgGetThreadStateFailed(t->id, msgComFailed("GetCurrentThreadId", hr));
+ return false;
+ }
+ if (currentThread != t->id) {
+ hr = cif.debugSystemObjects->SetCurrentThreadId(t->id);
+ if (FAILED(hr)) {
+ *errorMessage = msgGetThreadStateFailed(t->id, msgComFailed("SetCurrentThreadId", hr));
+ return false;
+ }
+ }
+ ULONG frameCount;
+ DEBUG_STACK_FRAME topFrame[1];
+ hr = cif.debugControl->GetStackTrace(0, 0, 0, topFrame, 1, &frameCount);
+ if (FAILED(hr)) {
+ *errorMessage = msgGetThreadStateFailed(t->id, msgComFailed("GetStackTrace", hr));
+ return false;
+ }
+
+ t->address = topFrame[0].InstructionOffset;
+ WCHAR wszBuf[MAX_PATH];
+
+ cif.debugSymbols->GetNameByOffsetWide(topFrame[0].InstructionOffset, wszBuf, MAX_PATH, 0, 0);
+ t->function = QString::fromUtf16(reinterpret_cast<const ushort *>(wszBuf));
+ ULONG ulLine;
+ hr = cif.debugSymbols->GetLineByOffsetWide(topFrame[0].InstructionOffset, &ulLine, wszBuf, MAX_PATH, 0, 0);
+ if (SUCCEEDED(hr)) {
+ t->line = ulLine;
+ // Just display base name
+ t->file = QString::fromUtf16(reinterpret_cast<const ushort *>(wszBuf));
+ if (!t->file.isEmpty()) {
+ const int slashPos = t->file.lastIndexOf(QLatin1Char('\\'));
+ if (slashPos != -1)
+ t->file.remove(0, slashPos + 1);
+ }
+ }
+ return true;
+}
+
+static inline QString msgGetThreadsFailed(const QString &why)
+{
+ return QString::fromLatin1("Unable to determine the thread information: %1").arg(why);
+}
+
+bool CdbStackTraceContext::getThreads(const CdbComInterfaces &cif,
+ bool isStopped,
+ QList<ThreadData> *threads,
+ ULONG *currentThreadId,
+ QString *errorMessage)
+{
+ threads->clear();
+ ULONG threadCount;
+ *currentThreadId = 0;
+ HRESULT hr= cif.debugSystemObjects->GetNumberThreads(&threadCount);
+ if (FAILED(hr)) {
+ *errorMessage= msgGetThreadsFailed(msgComFailed("GetNumberThreads", hr));
+ return false;
+ }
+ // Get ids and index of current
+ if (!threadCount)
+ return true;
+ hr = cif.debugSystemObjects->GetCurrentThreadId(currentThreadId);
+ if (FAILED(hr)) {
+ *errorMessage= msgGetThreadsFailed(msgComFailed("GetCurrentThreadId", hr));
+ return false;
+ }
+
+ QVector<ULONG> threadIds(threadCount);
+ hr = cif.debugSystemObjects->GetThreadIdsByIndex(0, threadCount, &(*threadIds.begin()), 0);
+ if (FAILED(hr)) {
+ *errorMessage= msgGetThreadsFailed(msgComFailed("GetThreadIdsByIndex", hr));
+ return false;
+ }
+ for (ULONG i = 0; i < threadCount; i++) {
+ ThreadData threadData(threadIds.at(i));
+ if (isStopped) {
+ if (!getStoppedThreadState(cif, &threadData, errorMessage)) {
+ qWarning("%s\n", qPrintable(*errorMessage));
+ errorMessage->clear();
+ }
+ }
+ threads->push_back(threadData);
+ }
+ return true;
+}
+
+
} // namespace Internal
} // namespace Debugger