alur updated this revision to Diff 142962.

https://reviews.llvm.org/D45628

Files:
  packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
  
packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
  packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1775,13 +1775,22 @@
     return eSectionTypeOther;
   }
 
+  llvm::StringRef mapped_name;
+  if (section_name.startswith(".zdebug")) {
+    // .zdebug* are compressed equivalents of .debug* sections, and should map
+    // to the same corresponding type.
+    mapped_name = section_name.drop_front(2);
+  } else {
+    mapped_name = section_name.drop_front(1);
+  }
+
   // MISSING? .gnu_debugdata - "mini debuginfo / MiniDebugInfo" section,
   // http://sourceware.org/gdb/onlinedocs/gdb/MiniDebugInfo.html
   // MISSING? .debug-index -
   // http://src.chromium.org/viewvc/chrome/trunk/src/build/gdb-add-index?pathrev=144644
   // MISSING? .debug_types - Type descriptions from DWARF 4? See
   // http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo
-  return llvm::StringSwitch<SectionType>(section_name.drop_front(1))
+  return llvm::StringSwitch<SectionType>(mapped_name)
       .Case("text", eSectionTypeCode)
       .Case("data", eSectionTypeData)
       .Case("bss", eSectionTypeZeroFill)
@@ -2823,6 +2832,7 @@
 void ObjectFileELF::RelocateSection(lldb_private::Section *section)
 {
   static const llvm::StringRef debug_prefix(".debug");
+  static const llvm::StringRef zdebug_prefix(".zdebug");
 
   // Set relocated bit so we stop getting called, regardless of
   // whether we actually relocate.
@@ -2838,7 +2848,8 @@
     return;
 
   // We don't relocate non-debug sections at the moment
-  if (section_name.startswith(debug_prefix))
+  if (section_name.startswith(debug_prefix) ||
+      section_name.startswith(zdebug_prefix))
     return;
 
   // Relocation section names to look for
@@ -3333,7 +3344,8 @@
     return section->GetObjectFile()->ReadSectionData(section, section_offset,
                                                      dst, dst_len);
 
-  if (!section->Test(SHF_COMPRESSED))
+  if (!llvm::object::Decompressor::isCompressedELFSection(
+          section->Get(), section->GetName().GetStringRef()))
     return ObjectFile::ReadSectionData(section, section_offset, dst, dst_len);
 
   // For compressed sections we need to read to full data to be able to
@@ -3352,7 +3364,8 @@
   Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES);
 
   size_t result = ObjectFile::ReadSectionData(section, section_data);
-  if (result == 0 || !section->Test(SHF_COMPRESSED))
+  if (result == 0 || !llvm::object::Decompressor::isCompressedELFSection(
+                         section->Get(), section->GetName().GetStringRef()))
     return result;
 
   auto Decompressor = llvm::object::Decompressor::create(
Index: packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/linux/compressed-debug-info/a.c
@@ -0,0 +1,4 @@
+int main() {
+  int z = 2;
+  return z;
+}
Index: packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/linux/compressed-debug-info/TestCompressedDebugInfo.py
@@ -0,0 +1,47 @@
+""" Tests that compressed debug info sections are used. """
+import os
+import lldb
+import sys
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCompressedDebugInfo(TestBase):
+  mydir = TestBase.compute_mydir(__file__)
+
+  def setUp(self):
+    TestBase.setUp(self)
+
+  @no_debug_info_test  # Prevent the genaration of the dwarf version of this test
+  @skipUnlessPlatform(["linux"])
+  def test_compressed_debug_info(self):
+    """Tests that the 'frame variable' works with compressed debug info."""
+
+    self.build()
+    process = lldbutil.run_to_source_breakpoint(
+        self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.out")[1]
+
+    # The process should be stopped at a breakpoint, and the z variable should
+    # be in the top frame.
+    self.assertTrue(process.GetState() == lldb.eStateStopped,
+                    STOPPED_DUE_TO_BREAKPOINT)
+    frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+    self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")
+
+  @no_debug_info_test  # Prevent the genaration of the dwarf version of this test
+  @skipUnlessPlatform(["linux"])
+  def test_compressed_debug_info_gnu(self):
+    """Tests that the 'frame variable' works with gnu-style compressed debug info."""
+
+    self.build()
+    process = lldbutil.run_to_source_breakpoint(
+        self, "main", lldb.SBFileSpec("a.c"), exe_name="compressed.gnu.out")[1]
+
+    # The process should be stopped at a breakpoint, and the z variable should
+    # be in the top frame.
+    self.assertTrue(process.GetState() == lldb.eStateStopped,
+                    STOPPED_DUE_TO_BREAKPOINT)
+    frame = process.GetThreadAtIndex(0).GetFrameAtIndex(0)
+    self.assertTrue(frame.FindVariable("z").IsValid(), "z is not valid")
+
Index: packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/linux/compressed-debug-info/Makefile
@@ -0,0 +1,16 @@
+LEVEL := ../../make
+
+C_SOURCES := a.c
+
+all: compressed.out compressed.gnu.out
+
+compressed.out: a.out
+	$(OBJCOPY) --compress-debug-sections=zlib $< $@
+
+compressed.gnu.out: a.out
+	$(OBJCOPY) --compress-debug-sections=zlib-gnu $< $@
+
+include $(LEVEL)/Makefile.rules
+
+clean::
+	$(RM) -f a.o main compressed.out compressed.gnu.out
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to