labath updated this revision to Diff 213342. labath added a comment. Herald added a reviewer: jdoerfert.
- redo the patch to keep the logic inside the line table code. I've been considering whether to do that my self. On one hand, this functionality seems like it could be useful in other places, but OTOH, the bool argument api is not really nice. I guess we can keep it this way until we come up with a better way to do that. I've kept the module unit test as it seems useful regardless of the fact that I'm not changing that code. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D65647/new/ https://reviews.llvm.org/D65647 Files: lit/SymbolFile/DWARF/debug-line-basic.s lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s lit/SymbolFile/DWARF/dir-separator-posix.s lit/SymbolFile/DWARF/dir-separator-windows.s source/Symbol/LineTable.cpp unittests/Core/CMakeLists.txt unittests/Core/Inputs/resolve-file-address.yaml unittests/Core/ModuleTest.cpp
Index: unittests/Core/ModuleTest.cpp =================================================================== --- /dev/null +++ unittests/Core/ModuleTest.cpp @@ -0,0 +1,67 @@ +//===-- ModuleTest.cpp ------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/Module.h" +#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" +#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" +#include "TestingSupport/TestUtilities.h" +#include "lldb/Core/Section.h" +#include "lldb/Host/HostInfo.h" +#include "llvm/Support/FileUtilities.h" +#include "llvm/Testing/Support/Error.h" +#include "gtest/gtest.h" + +using namespace lldb_private; +using namespace lldb; + +namespace { +class ModuleTest : public testing::Test { +public: + static void SetUpTestCase() { + FileSystem::Initialize(); + HostInfo::Initialize(); + ObjectFileELF::Initialize(); + SymbolFileSymtab::Initialize(); + } + + static void TearDownTestCase() { + SymbolFileSymtab::Terminate(); + ObjectFileELF::Terminate(); + HostInfo::Terminate(); + FileSystem::Terminate(); + } +}; +} // namespace + +llvm::Optional<Address> resolveFileAddress(Module &M, addr_t FileAddr) { + Address A; + if (M.ResolveFileAddress(FileAddr, A)) + return A; + return llvm::None; +} + +TEST_F(ModuleTest, ResolveFileAddress) { + llvm::SmallString<128> Obj; + ASSERT_EQ(llvm::sys::fs::createTemporaryFile("resolve-file-address-%%%%%%", + "obj", Obj), + std::error_code()); + llvm::FileRemover Deleter(Obj); + ASSERT_THAT_ERROR(ReadYAMLObjectFile("resolve-file-address.yaml", Obj), + llvm::Succeeded()); + + ModuleSpec Spec{FileSpec(Obj)}; + Spec.GetSymbolFileSpec().SetFile(Obj, FileSpec::Style::native); + auto M = std::make_shared<Module>(Spec); + + ASSERT_TRUE(M->GetSectionList()); + SectionSP S = M->GetSectionList()->FindSectionByName(ConstString(".text")); + ASSERT_TRUE(S); + + EXPECT_EQ(resolveFileAddress(*M, 0x1000), Address(S, 0)); + EXPECT_EQ(resolveFileAddress(*M, 0x1100), llvm::None); +} Index: unittests/Core/Inputs/resolve-file-address.yaml =================================================================== --- /dev/null +++ unittests/Core/Inputs/resolve-file-address.yaml @@ -0,0 +1,12 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + Size: 0x100 Index: unittests/Core/CMakeLists.txt =================================================================== --- unittests/Core/CMakeLists.txt +++ unittests/Core/CMakeLists.txt @@ -1,5 +1,6 @@ add_lldb_unittest(LLDBCoreTests MangledTest.cpp + ModuleTest.cpp RichManglingContextTest.cpp StreamCallbackTest.cpp UniqueCStringMapTest.cpp @@ -18,5 +19,6 @@ set(test_inputs mangled-function-names.yaml + resolve-file-address.yaml ) add_unittest_inputs(LLDBCoreTests "${test_inputs}") Index: source/Symbol/LineTable.cpp =================================================================== --- source/Symbol/LineTable.cpp +++ source/Symbol/LineTable.cpp @@ -241,33 +241,47 @@ bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx, LineEntry &line_entry) { - if (idx < m_entries.size()) { - const Entry &entry = m_entries[idx]; - ModuleSP module_sp(m_comp_unit->GetModule()); - if (module_sp && - module_sp->ResolveFileAddress(entry.file_addr, - line_entry.range.GetBaseAddress())) { - if (!entry.is_terminal_entry && idx + 1 < m_entries.size()) - line_entry.range.SetByteSize(m_entries[idx + 1].file_addr - - entry.file_addr); - else - line_entry.range.SetByteSize(0); - - line_entry.file = - m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); - line_entry.original_file = - m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); - line_entry.line = entry.line; - line_entry.column = entry.column; - line_entry.is_start_of_statement = entry.is_start_of_statement; - line_entry.is_start_of_basic_block = entry.is_start_of_basic_block; - line_entry.is_prologue_end = entry.is_prologue_end; - line_entry.is_epilogue_begin = entry.is_epilogue_begin; - line_entry.is_terminal_entry = entry.is_terminal_entry; - return true; - } - } - return false; + if (idx >= m_entries.size()) + return false; + + const Entry &entry = m_entries[idx]; + ModuleSP module_sp(m_comp_unit->GetModule()); + if (!module_sp) + return false; + + addr_t file_addr = entry.file_addr; + + // A terminal entry can point outside of a module or a section. Decrement the + // address to ensure it resolves correctly. + if (entry.is_terminal_entry) + --file_addr; + + if (!module_sp->ResolveFileAddress(file_addr, + line_entry.range.GetBaseAddress())) + return false; + + // Now undo the decrement above. + if (entry.is_terminal_entry) + line_entry.range.GetBaseAddress().Slide(1); + + if (!entry.is_terminal_entry && idx + 1 < m_entries.size()) + line_entry.range.SetByteSize(m_entries[idx + 1].file_addr - + entry.file_addr); + else + line_entry.range.SetByteSize(0); + + line_entry.file = + m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); + line_entry.original_file = + m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx); + line_entry.line = entry.line; + line_entry.column = entry.column; + line_entry.is_start_of_statement = entry.is_start_of_statement; + line_entry.is_start_of_basic_block = entry.is_start_of_basic_block; + line_entry.is_prologue_end = entry.is_prologue_end; + line_entry.is_epilogue_begin = entry.is_epilogue_begin; + line_entry.is_terminal_entry = entry.is_terminal_entry; + return true; } uint32_t LineTable::FindLineEntryIndexByFileIndex( Index: lit/SymbolFile/DWARF/dir-separator-windows.s =================================================================== --- lit/SymbolFile/DWARF/dir-separator-windows.s +++ lit/SymbolFile/DWARF/dir-separator-windows.s @@ -4,7 +4,7 @@ # REQUIRES: lld, x86 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o -# RUN: ld.lld -z separate-code %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: %lldb %t -s %S/Inputs/dir-separator-windows.lldbinit -o exit | FileCheck %s # CHECK-LABEL: image dump line-table a.c Index: lit/SymbolFile/DWARF/dir-separator-posix.s =================================================================== --- lit/SymbolFile/DWARF/dir-separator-posix.s +++ lit/SymbolFile/DWARF/dir-separator-posix.s @@ -4,7 +4,7 @@ # REQUIRES: lld, x86 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o -# RUN: ld.lld -z separate-code %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: %lldb %t -s %S/Inputs/dir-separator-posix.lldbinit -o exit | FileCheck %s # CHECK-LABEL: image dump line-table a.c Index: lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s =================================================================== --- lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s +++ lit/SymbolFile/DWARF/dir-separator-no-comp-dir.s @@ -4,7 +4,7 @@ # REQUIRES: lld, x86 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o -# RUN: ld.lld -z separate-code %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: %lldb %t -s %S/Inputs/dir-separator-windows.lldbinit -o exit | FileCheck %s # CHECK-LABEL: image dump line-table a.c Index: lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s =================================================================== --- lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s +++ lit/SymbolFile/DWARF/dir-separator-no-comp-dir-relative-name.s @@ -5,7 +5,7 @@ # REQUIRES: lld, x86 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o -# RUN: ld.lld -z separate-code %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: %lldb %t -s %S/Inputs/dir-separator-no-comp-dir-relative-name.lldbinit -o exit | FileCheck %s # CHECK-LABEL: image dump line-table a.c Index: lit/SymbolFile/DWARF/debug-line-basic.s =================================================================== --- lit/SymbolFile/DWARF/debug-line-basic.s +++ lit/SymbolFile/DWARF/debug-line-basic.s @@ -1,7 +1,7 @@ # REQUIRES: lld, x86 # RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj > %t.o -# RUN: ld.lld -z separate-code %t.o -o %t +# RUN: ld.lld %t.o -o %t # RUN: %lldb %t -o "image dump line-table -v a.c" -o exit | FileCheck %s
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits