Index: lldb/trunk/tools/lldb-vscode/JSONUtils.cpp =================================================================== --- lldb/trunk/tools/lldb-vscode/JSONUtils.cpp +++ lldb/trunk/tools/lldb-vscode/JSONUtils.cpp @@ -288,8 +288,7 @@ return llvm::json::Value(std::move(object)); object.try_emplace("verified", true); - const auto bp_id = bp_loc.GetBreakpoint().GetID(); - const auto vs_id = (int64_t)(((int64_t)bp_id << 32) | bp_loc.GetID()); + const auto vs_id = MakeVSCodeBreakpointID(bp_loc); object.try_emplace("id", vs_id); auto bp_addr = bp_loc.GetAddress(); if (bp_addr.IsValid()) { Index: lldb/trunk/tools/lldb-vscode/LLDBUtils.h =================================================================== --- lldb/trunk/tools/lldb-vscode/LLDBUtils.h +++ lldb/trunk/tools/lldb-vscode/LLDBUtils.h @@ -89,6 +89,82 @@ //---------------------------------------------------------------------- int64_t MakeVSCodeFrameID(lldb::SBFrame &frame); +///---------------------------------------------------------------------- +/// Given a VSCode frame ID, convert to a LLDB thread index id. +/// +/// VSCode requires a Stackframe "id" to be unique, so we use the frame +/// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in +/// the upper 32 - THREAD_INDEX_SHIFT bits. +/// +/// @param[in] dap_frame_id +/// The VSCode frame ID to convert to a thread index ID. +/// +/// @return +/// The LLDB thread index ID. +//---------------------------------------------------------------------- +uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id); + +///---------------------------------------------------------------------- +/// Given a VSCode frame ID, convert to a LLDB frame ID. +/// +/// VSCode requires a Stackframe "id" to be unique, so we use the frame +/// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in +/// the upper 32 - THREAD_INDEX_SHIFT bits. +/// +/// @param[in] dap_frame_id +/// The VSCode frame ID to convert to a frame ID. +/// +/// @return +/// The LLDB frame index ID. +//---------------------------------------------------------------------- +uint32_t GetLLDBFrameID(uint64_t dap_frame_id); + +///---------------------------------------------------------------------- +/// Given a LLDB breakpoint, make a breakpoint ID that is unique to a +/// specific breakpoint and breakpoint location. +/// +/// VSCode requires a Breakpoint "id" to be unique, so we use the +/// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the +/// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. +/// +/// @param[in] frame +/// The LLDB stack frame object generate the ID for +/// +/// @return +/// A unique integer that allows us to easily find the right +/// stack frame within a thread on subsequent VS code requests. +//---------------------------------------------------------------------- +int64_t MakeVSCodeBreakpointID(lldb::SBBreakpointLocation &bp_loc); + +///---------------------------------------------------------------------- +/// Given a VSCode breakpoint ID, convert to a LLDB breakpoint ID. +/// +/// VSCode requires a Breakpoint "id" to be unique, so we use the +/// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the +/// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. +/// +/// @param[in] dap_breakpoint_id +/// The VSCode breakpoint ID to convert to an LLDB breakpoint ID. +/// +/// @return +/// The LLDB breakpoint ID. +//---------------------------------------------------------------------- +uint32_t GetLLDBBreakpointID(uint64_t dap_breakpoint_id); + +///---------------------------------------------------------------------- +/// Given a VSCode breakpoint ID, convert to a LLDB breakpoint location ID. +/// +/// VSCode requires a Breakpoint "id" to be unique, so we use the +/// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the +/// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. +/// +/// @param[in] dap_breakpoint_id +/// The VSCode frame ID to convert to a breakpoint location ID. +/// +/// @return +/// The LLDB breakpoint location ID. +//---------------------------------------------------------------------- +uint32_t GetLLDBBreakpointLocationID(uint64_t dap_breakpoint_id); } // namespace lldb_vscode #endif Index: lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp =================================================================== --- lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp +++ lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp @@ -65,9 +65,34 @@ return false; } +static uint32_t constexpr THREAD_INDEX_SHIFT = 19; + +uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id) { + return dap_frame_id >> THREAD_INDEX_SHIFT; +} + +uint32_t GetLLDBFrameID(uint64_t dap_frame_id) { + return dap_frame_id & ((1u << THREAD_INDEX_SHIFT) - 1); +} + int64_t MakeVSCodeFrameID(lldb::SBFrame &frame) { - return (int64_t)frame.GetThread().GetIndexID() << 32 | - (int64_t)frame.GetFrameID(); + return (int64_t)(frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT | + frame.GetFrameID()); +} + +static uint32_t constexpr BREAKPOINT_ID_SHIFT = 22; + +uint32_t GetLLDBBreakpointID(uint64_t dap_breakpoint_id) { + return dap_breakpoint_id >> BREAKPOINT_ID_SHIFT; +} + +uint32_t GetLLDBBreakpointLocationID(uint64_t dap_breakpoint_id) { + return dap_breakpoint_id & ((1u << BREAKPOINT_ID_SHIFT) - 1); +} + +int64_t MakeVSCodeBreakpointID(lldb::SBBreakpointLocation &bp_loc) { + return (int64_t)(bp_loc.GetBreakpoint().GetID() << BREAKPOINT_ID_SHIFT | + bp_loc.GetID()); } } // namespace lldb_vscode Index: lldb/trunk/tools/lldb-vscode/VSCode.cpp =================================================================== --- lldb/trunk/tools/lldb-vscode/VSCode.cpp +++ lldb/trunk/tools/lldb-vscode/VSCode.cpp @@ -308,9 +308,10 @@ const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX); lldb::SBProcess process = target.GetProcess(); // Upper 32 bits is the thread index ID - lldb::SBThread thread = process.GetThreadByIndexID(frame_id >> 32); + lldb::SBThread thread = + process.GetThreadByIndexID(GetLLDBThreadIndexID(frame_id)); // Lower 32 bits is the frame index - return thread.GetFrameAtIndex(frame_id & 0xffffffffu); + return thread.GetFrameAtIndex(GetLLDBFrameID(frame_id)); } llvm::json::Value VSCode::CreateTopLevelScopes() {