From 32530e0493c130229b8fe5e4e65abd7fe76a2dc4 Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 7 Sep 2022 16:24:45 -0700 Subject: [PATCH] [LLDB][NativePDB] Set block address range. The block address range was missing before. Differential Revision: https://reviews.llvm.org/D133461 --- .../SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 18 ++++++++++++++++++ lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/blocks.cpp diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index 4109f6b..75bff62 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 0000000..1d74318 --- /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) -- 2.7.4