Author: lanza Date: Wed Nov 7 11:27:36 2018 New Revision: 346346 URL: http://llvm.org/viewvc/llvm-project?rev=346346&view=rev Log: Adjust some id bit shifts to fit inside 32 bit integers
Summary: The DAP on vscode uses a JavaScript `number` for identifiers while the Visual Studio version uses a C# `Int` for identifiers. lldb-vscode is bit shifting identifiers 32 bits and then bitwise ORing another 32 bit identifier into a 64 bit id to form a unique ID. Change this to a a partitioning of the 32 bits that makes sense for the data types. Reviewers: clayborg Differential Revision: https://reviews.llvm.org/D53599 Modified: lldb/trunk/tools/lldb-vscode/JSONUtils.cpp lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp lldb/trunk/tools/lldb-vscode/LLDBUtils.h lldb/trunk/tools/lldb-vscode/VSCode.cpp Modified: lldb/trunk/tools/lldb-vscode/JSONUtils.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/JSONUtils.cpp?rev=346346&r1=346345&r2=346346&view=diff ============================================================================== --- lldb/trunk/tools/lldb-vscode/JSONUtils.cpp (original) +++ lldb/trunk/tools/lldb-vscode/JSONUtils.cpp Wed Nov 7 11:27:36 2018 @@ -288,8 +288,7 @@ llvm::json::Value CreateBreakpoint(lldb: 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()) { Modified: lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp?rev=346346&r1=346345&r2=346346&view=diff ============================================================================== --- lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp (original) +++ lldb/trunk/tools/lldb-vscode/LLDBUtils.cpp Wed Nov 7 11:27:36 2018 @@ -65,9 +65,34 @@ bool ThreadHasStopReason(lldb::SBThread 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 Modified: lldb/trunk/tools/lldb-vscode/LLDBUtils.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/LLDBUtils.h?rev=346346&r1=346345&r2=346346&view=diff ============================================================================== --- lldb/trunk/tools/lldb-vscode/LLDBUtils.h (original) +++ lldb/trunk/tools/lldb-vscode/LLDBUtils.h Wed Nov 7 11:27:36 2018 @@ -89,6 +89,82 @@ bool ThreadHasStopReason(lldb::SBThread //---------------------------------------------------------------------- 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 Modified: lldb/trunk/tools/lldb-vscode/VSCode.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/VSCode.cpp?rev=346346&r1=346345&r2=346346&view=diff ============================================================================== --- lldb/trunk/tools/lldb-vscode/VSCode.cpp (original) +++ lldb/trunk/tools/lldb-vscode/VSCode.cpp Wed Nov 7 11:27:36 2018 @@ -308,9 +308,10 @@ lldb::SBFrame VSCode::GetLLDBFrame(const 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() { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits