[Lldb-commits] [lldb] 32530e0 - [LLDB][NativePDB] Set block address range.

Zequan Wu via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 8 14:52:01 PDT 2022


Author: Zequan Wu
Date: 2022-09-08T14:51:47-07:00
New Revision: 32530e0493c130229b8fe5e4e65abd7fe76a2dc4

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

LOG: [LLDB][NativePDB] Set block address range.

The block address range was missing before.

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

Added: 
    lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp

Modified: 
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 4109f6b7d4fa0..75bff62404cc3 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -363,6 +363,24 @@ Block &SymbolFileNativePDB::CreateBlock(PdbCompilandSymId block_id) {
     lldbassert(block.Parent != 0);
     PdbCompilandSymId parent_id(block_id.modi, block.Parent);
     Block &parent_block = GetOrCreateBlock(parent_id);
+    Function *func = parent_block.CalculateSymbolContextFunction();
+    lldbassert(func);
+    lldb::addr_t block_base =
+        m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
+    lldb::addr_t func_base =
+        func->GetAddressRange().GetBaseAddress().GetFileAddress();
+    Block::Range range = Block::Range(block_base - func_base, block.CodeSize);
+    if (block_base >= func_base)
+      child_block->AddRange(range);
+    else {
+      GetObjectFile()->GetModule()->ReportError(
+          "S_BLOCK32 at modi: %d offset: %d: adding range [0x%" PRIx64
+          "-0x%" PRIx64 ") which has a base that is less than the function's "
+          "low PC 0x%" PRIx64 ". Please file a bug and attach the file at the "
+          "start of this error message",
+          block_id.modi, block_id.offset, block_base,
+          block_base + block.CodeSize, func_base);
+    }
     parent_block.AddChild(child_block);
     m_ast->GetOrCreateBlockDecl(block_id);
     m_blocks.insert({opaque_block_uid, child_block});

diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp b/lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp
new file mode 100644
index 0000000000000..1d7431847921d
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp
@@ -0,0 +1,20 @@
+// clang-format off
+// REQUIRES: lld, x86
+
+// Test block range is set.
+// RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -GS- -c /Fo%t.obj -- %s
+// RUN: lld-link -debug:full -nodefaultlib -entry:main -base:0x140000000 %t.obj -out:%t.exe -pdb:%t.pdb
+// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o "image lookup -a 0x140001014 -v" | FileCheck %s
+
+int main() {
+  int count = 0;
+  for (int i = 0; i < 3; ++i) {
+    ++count;
+  }
+  return count;
+}
+
+// CHECK:      Function: id = {{.*}}, name = "main", range = [0x0000000140001000-0x000000014000104b)
+// CHECK-NEXT: FuncType: id = {{.*}}, byte-size = 0, compiler_type = "int (void)"
+// CHECK-NEXT:   Blocks: id = {{.*}}, range = [0x140001000-0x14000104b)
+// CHECK-NEXT:           id = {{.*}}, range = [0x140001014-0x140001042)


        


More information about the lldb-commits mailing list