labath created this revision.
Herald added a subscriber: mgorny.

If we have symbol information in a separate file, we need to be very
careful about presenting a unified section view of module to the rest of
the debugger. ObjectFileELF had code to handle that, but it was being
overly cautious -- the section->GetFileSize()!=0 meant that the
unification would fail for sections which do not occupy any space in the
object file (e.g., .bss). In my case, that manifested itself as not
being able to display the values of .bss variables properly as the
section associated with the variable did not have it's load address set
(because it was not present in the unified section list).

I test this by making sure the unified section list and the variables
refer to the same section.


https://reviews.llvm.org/D32434

Files:
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  unittests/ObjectFile/ELF/CMakeLists.txt
  unittests/ObjectFile/ELF/Inputs/test.c
  unittests/ObjectFile/ELF/Inputs/test.dbg
  unittests/ObjectFile/ELF/Inputs/test.strip
  unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Index: unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===================================================================
--- /dev/null
+++ unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -0,0 +1,82 @@
+//===-- TestObjectFileELF.cpp -----------------------------------*- C++ -*-===//
+//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Path.h"
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Host/HostInfo.h"
+#include "gtest/gtest.h"
+
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+
+extern const char *TestMainArgv0;
+
+using namespace lldb_private;
+using namespace lldb;
+
+class ObjectFileELFTest : public testing::Test {
+public:
+  void SetUp() override {
+    HostInfo::Initialize();
+    ObjectFileELF::Initialize();
+    SymbolVendorELF::Initialize();
+
+    llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
+    llvm::SmallString<128> inputs_folder = exe_folder;
+    llvm::sys::path::append(inputs_folder, "Inputs");
+
+    m_exe_stripped = m_exe_debug = inputs_folder;
+    llvm::sys::path::append(m_exe_stripped, "test.strip");
+    llvm::sys::path::append(m_exe_debug, "test.dbg");
+  }
+
+  void TearDown() override {
+    SymbolVendorELF::Terminate();
+    ObjectFileELF::Terminate();
+    HostInfo::Terminate();
+  }
+
+protected:
+  llvm::SmallString<128> m_exe_stripped;
+  llvm::SmallString<128> m_exe_debug;
+};
+
+
+TEST_F(ObjectFileELFTest, SectionsResolveConsistently) {
+  ModuleSpec spec{FileSpec(m_exe_stripped, false)};
+  spec.GetSymbolFileSpec().SetFile(m_exe_debug, false);
+  auto module_sp = std::make_shared<Module>(spec);
+  SectionList *list = module_sp->GetSectionList();
+  ASSERT_NE(nullptr, list);
+
+  auto bss_sp = list->FindSectionByName(ConstString(".bss"));
+  ASSERT_NE(nullptr, bss_sp);
+  auto data_sp = list->FindSectionByName(ConstString(".data"));
+  ASSERT_NE(nullptr, data_sp);
+  auto text_sp = list->FindSectionByName(ConstString(".text"));
+  ASSERT_NE(nullptr, text_sp);
+
+  const Symbol *X = module_sp->FindFirstSymbolWithNameAndType(ConstString("X"),
+                                                              eSymbolTypeAny);
+  ASSERT_NE(nullptr, X);
+  EXPECT_EQ(bss_sp, X->GetAddress().GetSection());
+
+  const Symbol *Y = module_sp->FindFirstSymbolWithNameAndType(ConstString("Y"),
+                                                              eSymbolTypeAny);
+  ASSERT_NE(nullptr, Y);
+  EXPECT_EQ(data_sp, Y->GetAddress().GetSection());
+
+  const Symbol *start = module_sp->FindFirstSymbolWithNameAndType(
+      ConstString("_start"), eSymbolTypeAny);
+  ASSERT_NE(nullptr, start);
+  EXPECT_EQ(text_sp, start->GetAddress().GetSection());
+}
Index: unittests/ObjectFile/ELF/Inputs/test.c
===================================================================
--- /dev/null
+++ unittests/ObjectFile/ELF/Inputs/test.c
@@ -0,0 +1,5 @@
+// compile with: $CC test.c -nostdlib -g -o test.dbg
+// strip: objcopy --strip-debug test.dbg test.strip
+int X;
+int Y = 47;
+void _start() { X = Y; }
Index: unittests/ObjectFile/ELF/CMakeLists.txt
===================================================================
--- unittests/ObjectFile/ELF/CMakeLists.txt
+++ unittests/ObjectFile/ELF/CMakeLists.txt
@@ -1,7 +1,15 @@
 add_lldb_unittest(ObjectFileELFTests
   TestELFHeader.cpp
+  TestObjectFileELF.cpp
 
   LINK_LIBS
     lldbPluginObjectFileELF
+    lldbPluginSymbolVendorELF
     lldbCore
   )
+
+set(test_inputs
+  test.strip
+  test.dbg
+  )
+add_unittest_inputs(ObjectFileELFTests "${test_inputs}")
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2418,7 +2418,7 @@
                 .emplace(sect_name.GetCString(),
                          module_section_list->FindSectionByName(sect_name))
                 .first;
-      if (section_it->second && section_it->second->GetFileSize())
+      if (section_it->second)
         symbol_section_sp = section_it->second;
     }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to