From 9d56d9a95fcf065f9542e49300e0d6af66883e73 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Enciso Date: Tue, 1 Nov 2022 12:41:04 +0000 Subject: [PATCH] [llvm-debuginfo-analyzer] Fix memory leak reported by sanitizers. The sanitizer reported memory leak issues; the command line used in the test case is: llvm-debuginfo-analyzer --attribute=level --print=instructions pr-incorrect-instructions-dwarf-clang.o When dealing with logical instruction lines associated with an artificial logical scope, skip the process of finding their enclosing scope. Just add them to the scope. Create logical debug lines only if the command line specifies: --print=lines or --print=elements or --print=all Reviewed By: jryans, vitalybuka Differential Revision: https://reviews.llvm.org/D137156 --- llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp | 14 +++++++++----- llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp | 5 ++--- .../DWARF/pr-incorrect-logical-instructions.test | 3 --- llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp index 1a6e950..35e0eca 100644 --- a/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp +++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp @@ -562,7 +562,7 @@ void LVBinaryReader::processLines(LVLines *DebugLines, size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" - << format("Process instructions lines: %d\n", + << format("Process instruction lines: %d\n", InstructionLines.size()); for (const LVLine *Line : InstructionLines) dbgs() << format_decimal(++Index, 5) << ": " @@ -640,8 +640,6 @@ void LVBinaryReader::processLines(LVLines *DebugLines, if (DebugLines->empty()) { if (const LVScopes *Scopes = CompileUnit->getScopes()) for (LVScope *Scope : *Scopes) { - if (Scope->getIsArtificial()) - continue; LVLines *Lines = ScopeInstructions.find(Scope); if (Lines) { @@ -649,14 +647,20 @@ void LVBinaryReader::processLines(LVLines *DebugLines, size_t Index = 0; dbgs() << "\nSectionIndex: " << format_decimal(SectionIndex, 3) << " Scope DIE: " << hexValue(Scope->getOffset()) << "\n" - << format("Instructions lines: %d\n", Lines->size()); + << format("Instruction lines: %d\n", Lines->size()); for (const LVLine *Line : *Lines) dbgs() << format_decimal(++Index, 5) << ": " << hexValue(Line->getOffset()) << ", (" << Line->getName() << ")\n"; }); - DebugLines->append(*Lines); + if (Scope->getIsArtificial()) { + // Add the instruction lines to their artificial scope. + for (LVLine *Line : *Lines) + Scope->addElement(Line); + } else { + DebugLines->append(*Lines); + } Lines->clear(); } } diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp index 6a7e289..51ac39f 100644 --- a/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp +++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp @@ -726,9 +726,8 @@ void LVELFReader::createLineAndFileRecords( // In DWARF5 the file indexes start at 0; bool IncrementIndex = Lines->Prologue.getVersion() >= 5; - // Get the source lines. - if ((options().getAttributeRange() || options().getPrintLines()) && - Lines->Rows.size()) + // Get the source lines if requested by command line option. + if (options().getPrintLines() && Lines->Rows.size()) for (const DWARFDebugLine::Row &Row : Lines->Rows) { // Here we collect logical debug lines in CULines. Later on, // the 'processLines()' function will move each created logical line diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test index 72bc76a5..a99eae2 100644 --- a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test +++ b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test @@ -1,8 +1,5 @@ ; REQUIRES: x86-registered-target -; FIXME: Memory leak https://reviews.llvm.org/D125783 -; UNSUPPORTED: asan - ; * Added incorrect logical instructions for: --print=lines,instructions ; 'bar' and 'foo' showing extra instruction from compiler generated functions: ; '_cxx_global_var_init' and '_GLOBAL_sub_l_suite_lexical_01.cpp' diff --git a/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp b/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp index 1c97365..f0e1552 100644 --- a/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp +++ b/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp @@ -330,9 +330,7 @@ TEST(LogicalViewTest, ELFReader) { llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); - SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0); - - // This test requires a x86-registered-target + // This test requires a x86-registered-target. Triple TT; TT.setArch(Triple::x86_64); TT.setVendor(Triple::UnknownVendor); @@ -342,6 +340,8 @@ TEST(LogicalViewTest, ELFReader) { if (!TargetRegistry::lookupTarget(std::string(TT.str()), TargetLookupError)) return; + SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0); + // Logical elements general properties and selection. elementProperties(InputsDir); elementSelection(InputsDir); -- 2.7.4