diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -363,6 +363,24 @@ 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 --- /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)