[Lldb-commits] [lldb] ca84935 - Fix lldb-vscode frame id integer overflow

Jeffrey Tan via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 26 16:12:50 PDT 2023


Author: Jeffrey Tan
Date: 2023-07-26T16:12:41-07:00
New Revision: ca849352936dadadd232cf9ec74ac006ce410f51

URL: https://github.com/llvm/llvm-project/commit/ca849352936dadadd232cf9ec74ac006ce410f51
DIFF: https://github.com/llvm/llvm-project/commit/ca849352936dadadd232cf9ec74ac006ce410f51.diff

LOG: Fix lldb-vscode frame id integer overflow

This patch fixes a 32bit integer overflow in lldb-vscode.
The current implementation of frame_id does `(thread_index << 19 | frame_index)`. Since thread_index is a 32 bit integer this leaves only 32 - 19 == 13 bits available for the thread_index. As a result, lldb-vscode can only handle 2^13 == 8192 threads. Normally, this would be sufficient, but we have seen crazy process having +12000 threads, causing the frame_id algorithm above to integer overflow during casting.

The patch fixes the overflow by up casting to 64 bit integer first before bit shifiting.

Differential Revision: https://reviews.llvm.org/D156375

Added: 
    

Modified: 
    lldb/tools/lldb-vscode/LLDBUtils.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/lldb-vscode/LLDBUtils.cpp b/lldb/tools/lldb-vscode/LLDBUtils.cpp
index 621f4ec37c83da..464195bdc6444c 100644
--- a/lldb/tools/lldb-vscode/LLDBUtils.cpp
+++ b/lldb/tools/lldb-vscode/LLDBUtils.cpp
@@ -79,8 +79,8 @@ uint32_t GetLLDBFrameID(uint64_t dap_frame_id) {
 }
 
 int64_t MakeVSCodeFrameID(lldb::SBFrame &frame) {
-  return (int64_t)(frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT |
-                   frame.GetFrameID());
+  return ((int64_t)frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT) |
+         frame.GetFrameID();
 }
 
 } // namespace lldb_vscode


        


More information about the lldb-commits mailing list