diff options
author | Nathan Lanza <nathan@lanza.io> | 2018-11-07 19:27:36 +0000 |
---|---|---|
committer | Nathan Lanza <nathan@lanza.io> | 2018-11-07 19:27:36 +0000 |
commit | f09e910923c96e4d14f771c3c2e4cab3b832f99c (patch) | |
tree | 6b262977a85d156af1ffae4e57a89d9c5e8e1e91 /lldb/tools | |
parent | 24f1606f36d496dadb4abf52497d5e40c3b1dae8 (diff) |
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
Diffstat (limited to 'lldb/tools')
-rw-r--r-- | lldb/tools/lldb-vscode/JSONUtils.cpp | 3 | ||||
-rw-r--r-- | lldb/tools/lldb-vscode/LLDBUtils.cpp | 29 | ||||
-rw-r--r-- | lldb/tools/lldb-vscode/LLDBUtils.h | 76 | ||||
-rw-r--r-- | lldb/tools/lldb-vscode/VSCode.cpp | 5 |
4 files changed, 107 insertions, 6 deletions
diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp index 2c6a5d6d67a..019a9db624d 100644 --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/lldb-vscode/JSONUtils.cpp @@ -288,8 +288,7 @@ llvm::json::Value CreateBreakpoint(lldb::SBBreakpointLocation &bp_loc) { 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()) { diff --git a/lldb/tools/lldb-vscode/LLDBUtils.cpp b/lldb/tools/lldb-vscode/LLDBUtils.cpp index 797eda09ccd..9653522a2d3 100644 --- a/lldb/tools/lldb-vscode/LLDBUtils.cpp +++ b/lldb/tools/lldb-vscode/LLDBUtils.cpp @@ -65,9 +65,34 @@ bool ThreadHasStopReason(lldb::SBThread &thread) { 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 diff --git a/lldb/tools/lldb-vscode/LLDBUtils.h b/lldb/tools/lldb-vscode/LLDBUtils.h index f5ff2c97561..96ebb85f14b 100644 --- a/lldb/tools/lldb-vscode/LLDBUtils.h +++ b/lldb/tools/lldb-vscode/LLDBUtils.h @@ -89,6 +89,82 @@ bool ThreadHasStopReason(lldb::SBThread &thread); //---------------------------------------------------------------------- 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 diff --git a/lldb/tools/lldb-vscode/VSCode.cpp b/lldb/tools/lldb-vscode/VSCode.cpp index a8667769ab4..d268c45aca6 100644 --- a/lldb/tools/lldb-vscode/VSCode.cpp +++ b/lldb/tools/lldb-vscode/VSCode.cpp @@ -308,9 +308,10 @@ lldb::SBFrame VSCode::GetLLDBFrame(const llvm::json::Object &arguments) { 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() { |