From bb51c1bd1d465397ab0463b5f7b5976cc68670b5 Mon Sep 17 00:00:00 2001 From: Igor Kulaychuk Date: Fri, 12 Jan 2018 17:48:48 +0300 Subject: [PATCH] Encode thread id and frame level as frame id --- src/debug/netcoredbg/commands.cpp | 2 +- src/debug/netcoredbg/frames.cpp | 19 +++++++++++++------ src/debug/netcoredbg/frames.h | 2 +- src/debug/netcoredbg/main.cpp | 12 ++++++------ src/debug/netcoredbg/protocol.h | 13 +++++++++++-- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/debug/netcoredbg/commands.cpp b/src/debug/netcoredbg/commands.cpp index 83f2b09..4229b7f 100644 --- a/src/debug/netcoredbg/commands.cpp +++ b/src/debug/netcoredbg/commands.cpp @@ -277,7 +277,7 @@ HRESULT PrintFrameLocation(const StackFrame &stackFrame, std::string &output) ss << "func=\"" << stackFrame.name << "\""; if (stackFrame.id != 0) - ss << ",addr=\"" << AddrToString(stackFrame.id) << "\""; + ss << ",addr=\"" << AddrToString(stackFrame.addr) << "\""; output = ss.str(); diff --git a/src/debug/netcoredbg/frames.cpp b/src/debug/netcoredbg/frames.cpp index ac2b293..74ef27e 100644 --- a/src/debug/netcoredbg/frames.cpp +++ b/src/debug/netcoredbg/frames.cpp @@ -56,7 +56,7 @@ static uint64_t FrameAddr(ICorDebugFrame *pFrame) return startAddr; } -HRESULT GetFrameLocation(ICorDebugFrame *pFrame, StackFrame &stackFrame) +HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame) { HRESULT Status; @@ -393,6 +393,9 @@ HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std HRESULT Status; std::stringstream ss; + DWORD threadId = 0; + pThread->GetID(&threadId); + int currentFrame = -1; IfFailRet(WalkFrames(pThread, [&]( @@ -411,15 +414,18 @@ HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std switch(frameType) { case FrameUnknown: - stackFrames.emplace_back(FrameAddr(pFrame), "?"); + stackFrames.emplace_back(threadId, currentFrame, "?"); + stackFrames.back().addr = FrameAddr(pFrame); break; case FrameNative: - stackFrames.emplace_back(pNative->addr, pNative->symbol); + stackFrames.emplace_back(threadId, currentFrame, pNative->symbol); + stackFrames.back().addr = pNative->addr; stackFrames.back().source = Source(pNative->file); stackFrames.back().line = pNative->linenum; break; case FrameCLRNative: - stackFrames.emplace_back(FrameAddr(pFrame), "[Native Frame]"); + stackFrames.emplace_back(threadId, currentFrame, "[Native Frame]"); + stackFrames.back().addr = FrameAddr(pFrame); break; case FrameCLRInternal: { @@ -430,13 +436,14 @@ HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std std::string name = "["; name += GetInternalTypeName(frameType); name += "]"; - stackFrames.emplace_back(FrameAddr(pFrame), name); + stackFrames.emplace_back(threadId, currentFrame, name); + stackFrames.back().addr = FrameAddr(pFrame); } break; case FrameCLRManaged: { StackFrame stackFrame; - GetFrameLocation(pFrame, stackFrame); + GetFrameLocation(pFrame, threadId, currentFrame, stackFrame); stackFrames.push_back(stackFrame); } break; diff --git a/src/debug/netcoredbg/frames.h b/src/debug/netcoredbg/frames.h index 191b5e8..70f9a4b 100644 --- a/src/debug/netcoredbg/frames.h +++ b/src/debug/netcoredbg/frames.h @@ -2,7 +2,7 @@ // Distributed under the MIT License. // See the LICENSE file in the project root for more information. -HRESULT GetFrameLocation(ICorDebugFrame *pFrame, StackFrame &stackFrame); +HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame); HRESULT GetFrameAt(ICorDebugThread *pThread, int level, ICorDebugFrame **ppFrame); HRESULT GetThreadsState(ICorDebugController *controller, std::vector &threads); HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std::vector &stackFrames); diff --git a/src/debug/netcoredbg/main.cpp b/src/debug/netcoredbg/main.cpp index f0a33a6..28a3491 100644 --- a/src/debug/netcoredbg/main.cpp +++ b/src/debug/netcoredbg/main.cpp @@ -347,7 +347,7 @@ public: ToRelease pFrame; if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr) - GetFrameLocation(pFrame, event.frame); + GetFrameLocation(pFrame, threadId, 0, event.frame); SetLastStoppedThread(pThread); m_debugger->EmitStoppedEvent(event); @@ -361,11 +361,14 @@ public: /* [in] */ ICorDebugStepper *pStepper, /* [in] */ CorDebugStepReason reason) { + DWORD threadId = 0; + pThread->GetID(&threadId); + StackFrame stackFrame; ToRelease pFrame; HRESULT Status = S_FALSE; if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr) - Status = GetFrameLocation(pFrame, stackFrame); + Status = GetFrameLocation(pFrame, threadId, 0, stackFrame); const bool no_source = Status == S_FALSE; @@ -376,9 +379,6 @@ public: } else { - DWORD threadId = 0; - pThread->GetID(&threadId); - StoppedEvent event(StopStep, threadId); event.frame = stackFrame; @@ -409,7 +409,7 @@ public: StackFrame stackFrame; ToRelease pFrame; if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr) - GetFrameLocation(pFrame, stackFrame); + GetFrameLocation(pFrame, threadId, 0, stackFrame); SetLastStoppedThread(pThread); diff --git a/src/debug/netcoredbg/protocol.h b/src/debug/netcoredbg/protocol.h index c7a49cb..2c2a277 100644 --- a/src/debug/netcoredbg/protocol.h +++ b/src/debug/netcoredbg/protocol.h @@ -37,7 +37,7 @@ struct ClrAddr struct StackFrame { - uint64_t id; // frame start address + uint64_t id; // (threadId << 32) | level std::string name; Source source; int line; @@ -47,11 +47,20 @@ struct StackFrame std::string moduleId; ClrAddr clrAddr; // exposed for MI protocol + uint64_t addr; // exposed for MI protocol StackFrame() : id(0), line(0), column(0), endLine(0), endColumn(0) {} - StackFrame(uint64_t id, std::string name) : id(id), name(name) {} + StackFrame(int threadId, uint32_t level, std::string name) : name(name) + { + id = threadId; + id <<= 32; + id |= level; + } + + uint32_t GetLevel() const { return id & 0xFFFFFFFFul; } + int GetThreadId() const { return id >> 32; } }; struct Breakpoint -- 2.7.4