[PATCH] D137156: [llvm-debuginfo-analyzer] Fix memory leak reported by sanitizers.

Carlos Alberto Enciso via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 06:16:33 PDT 2022


CarlosAlbertoEnciso created this revision.
CarlosAlbertoEnciso added reviewers: probinson, dblaikie, psamolysov, jryans, Orlando, vitalybuka.
CarlosAlbertoEnciso added projects: debug-info, LLVM.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware, hiraditya.
Herald added a project: All.
CarlosAlbertoEnciso requested review of this revision.
Herald added a subscriber: llvm-commits.

Afte landing the `08-elf-reader` patch the sanitizer reported
memory leak issues. The test causing the issue was disabled

https://reviews.llvm.org/rGd81725d2bc016b58cb9327910f7892a2d4ac53c1

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137156

Files:
  llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
  llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
  llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test
  llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp


Index: llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp
+++ llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp
@@ -330,9 +330,7 @@
 
   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 @@
   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);
Index: llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test
===================================================================
--- llvm/test/tools/llvm-debuginfo-analyzer/DWARF/pr-incorrect-logical-instructions.test
+++ 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'
Index: llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
===================================================================
--- llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
+++ llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
@@ -726,9 +726,8 @@
   // 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
Index: llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
===================================================================
--- llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
+++ llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
@@ -562,7 +562,7 @@
       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 @@
   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 @@
             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();
         }
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137156.472269.patch
Type: text/x-patch
Size: 4410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221101/7c2df27c/attachment.bin>


More information about the llvm-commits mailing list