[Lldb-commits] [lldb] r368289 - ObjectFileELF: Convert a unit test to a lit test

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 05:57:47 PDT 2019


Author: labath
Date: Thu Aug  8 05:57:46 2019
New Revision: 368289

URL: http://llvm.org/viewvc/llvm-project?rev=368289&view=rev
Log:
ObjectFileELF: Convert a unit test to a lit test

It is much easier to test this functionality via lldb-test.

Added:
    lldb/trunk/lit/Modules/ELF/aarch64-relocations.yaml
Removed:
    lldb/trunk/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml
Modified:
    lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
    lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp

Added: lldb/trunk/lit/Modules/ELF/aarch64-relocations.yaml
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/aarch64-relocations.yaml?rev=368289&view=auto
==============================================================================
--- lldb/trunk/lit/Modules/ELF/aarch64-relocations.yaml (added)
+++ lldb/trunk/lit/Modules/ELF/aarch64-relocations.yaml Thu Aug  8 05:57:46 2019
@@ -0,0 +1,93 @@
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test object-file -contents %t | FileCheck %s
+
+# CHECK:      Name: .debug_info
+# CHECK:      Data:  (
+# CHECK-NEXT:     0000: 47000000 04000000 00000801 00000000 0C002D00 00000000 00003700 00000000
+# CHECK-NEXT:     0020: 00000000 00000800 00000200 00000000 00000008 00000001 6F490000 00010243
+# CHECK-NEXT:     0040: 00000003 4B000000 050400
+# CHECK-NEXT: )
+
+--- !ELF
+FileHeader:      
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_AARCH64
+Sections:        
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         E0031B32C0035FD6
+  - Name:            .debug_str
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x0000000000000001
+    Size:            0x50
+  - Name:            .debug_abbrev
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Size:            0x10
+  - Name:            .debug_info
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         470000000400000000000801000000000C0000000000000000000000000000000000000000000800000002000000000000000008000000016F000000000102430000000300000000050400
+  - Name:            .rela.debug_info
+    Type:            SHT_RELA
+    Link:            .symtab
+    AddressAlign:    0x0000000000000008
+    Info:            .debug_info
+    Relocations:     
+      - Offset:          0x0000000000000006
+        Symbol:          .debug_abbrev
+        Type:            R_AARCH64_ABS32
+      - Offset:          0x000000000000000C
+        Symbol:          .debug_str
+        Type:            R_AARCH64_ABS32
+      - Offset:          0x0000000000000012
+        Symbol:          .debug_str
+        Type:            R_AARCH64_ABS32
+        Addend:          45
+      - Offset:          0x0000000000000016
+        Symbol:          .debug_line
+        Type:            R_AARCH64_ABS32
+      - Offset:          0x000000000000001A
+        Symbol:          .debug_str
+        Type:            R_AARCH64_ABS32
+        Addend:          55
+      - Offset:          0x000000000000001E
+        Symbol:          .text
+        Type:            R_AARCH64_ABS64
+      - Offset:          0x000000000000002B
+        Symbol:          .text
+        Type:            R_AARCH64_ABS64
+      - Offset:          0x0000000000000039
+        Symbol:          .debug_str
+        Type:            R_AARCH64_ABS32
+        Addend:          73
+      - Offset:          0x0000000000000044
+        Symbol:          .debug_str
+        Type:            R_AARCH64_ABS32
+        Addend:          75
+  - Name:            .debug_line
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Size:            0x20
+Symbols:         
+  - Name:            .text
+    Type:            STT_SECTION
+    Section:         .text
+  - Name:            .debug_str
+    Type:            STT_SECTION
+    Section:         .debug_str
+  - Name:            .debug_abbrev
+    Type:            STT_SECTION
+    Section:         .debug_abbrev
+  - Name:            .debug_info
+    Type:            STT_SECTION
+    Section:         .debug_info
+  - Name:            .debug_line
+    Type:            STT_SECTION
+    Section:         .debug_line
+...

Modified: lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt?rev=368289&r1=368288&r2=368289&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt Thu Aug  8 05:57:46 2019
@@ -11,7 +11,6 @@ add_lldb_unittest(ObjectFileELFTests
 
 set(test_inputs
   early-section-headers.so
-  debug-info-relocations.pcm.yaml
   sections-resolve-consistently.yaml
   )
 add_unittest_inputs(ObjectFileELFTests "${test_inputs}")

Removed: lldb/trunk/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml?rev=368288&view=auto
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml (removed)
@@ -1,182 +0,0 @@
---- !ELF
-FileHeader:      
-  Class:           ELFCLASS64
-  Data:            ELFDATA2LSB
-  Type:            ET_REL
-  Machine:         EM_AARCH64
-Sections:        
-  - Name:            .text
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
-    AddressAlign:    0x0000000000000004
-    Content:         E0031B32C0035FD6
-  - Name:            .debug_str
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_MERGE, SHF_STRINGS ]
-    AddressAlign:    0x0000000000000001
-    Content:         636C616E672076657273696F6E20362E302E312028746167732F52454C454153455F3630312F66696E616C2900726564756365642E68002F746D702F617364666173646673646661006600696E7400
-  - Name:            .debug_abbrev
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         011101250E1305030E10171B0EB44219110112060000022E00110112064018030E3A0B3B0B271949133F190000032400030E3E0B0B0B000000
-  - Name:            .debug_info
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         470000000400000000000801000000000C0000000000000000000000000000000000000000000800000002000000000000000008000000016F000000000102430000000300000000050400
-  - Name:            .rela.debug_info
-    Type:            SHT_RELA
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    Info:            .debug_info
-    Relocations:     
-      - Offset:          0x0000000000000006
-        Symbol:          .debug_abbrev
-        Type:            R_AARCH64_ABS32
-      - Offset:          0x000000000000000C
-        Symbol:          .debug_str
-        Type:            R_AARCH64_ABS32
-      - Offset:          0x0000000000000012
-        Symbol:          .debug_str
-        Type:            R_AARCH64_ABS32
-        Addend:          45
-      - Offset:          0x0000000000000016
-        Symbol:          .debug_line
-        Type:            R_AARCH64_ABS32
-      - Offset:          0x000000000000001A
-        Symbol:          .debug_str
-        Type:            R_AARCH64_ABS32
-        Addend:          55
-      - Offset:          0x000000000000001E
-        Symbol:          .text
-        Type:            R_AARCH64_ABS64
-      - Offset:          0x000000000000002B
-        Symbol:          .text
-        Type:            R_AARCH64_ABS64
-      - Offset:          0x0000000000000039
-        Symbol:          .debug_str
-        Type:            R_AARCH64_ABS32
-        Addend:          73
-      - Offset:          0x0000000000000044
-        Symbol:          .debug_str
-        Type:            R_AARCH64_ABS32
-        Addend:          75
-  - Name:            .debug_ranges
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         ''
-  - Name:            .debug_macinfo
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         '00'
-  - Name:            .debug_pubnames
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         140000000200000000004B0000002A000000660000000000
-  - Name:            .rela.debug_pubnames
-    Type:            SHT_RELA
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    Info:            .debug_pubnames
-    Relocations:     
-      - Offset:          0x0000000000000006
-        Symbol:          .debug_info
-        Type:            R_AARCH64_ABS32
-  - Name:            .debug_pubtypes
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         160000000200000000004B00000043000000696E740000000000
-  - Name:            .rela.debug_pubtypes
-    Type:            SHT_RELA
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    Info:            .debug_pubtypes
-    Relocations:     
-      - Offset:          0x0000000000000006
-        Symbol:          .debug_info
-        Type:            R_AARCH64_ABS32
-  - Name:            .comment
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_MERGE, SHF_STRINGS ]
-    AddressAlign:    0x0000000000000001
-    Content:         00636C616E672076657273696F6E20362E302E312028746167732F52454C454153455F3630312F66696E616C2900
-  - Name:            .note.GNU-stack
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         ''
-  - Name:            .debug_frame
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000008
-    Content:         14000000FFFFFFFF04000800017C1E0C1F00000000000000140000000000000000000000000000000800000000000000
-  - Name:            .rela.debug_frame
-    Type:            SHT_RELA
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    Info:            .debug_frame
-    Relocations:     
-      - Offset:          0x000000000000001C
-        Symbol:          .debug_frame
-        Type:            R_AARCH64_ABS32
-      - Offset:          0x0000000000000020
-        Symbol:          .text
-        Type:            R_AARCH64_ABS64
-  - Name:            .debug_line
-    Type:            SHT_PROGBITS
-    AddressAlign:    0x0000000000000001
-    Content:         3C000000040021000000010101FB0E0D00010101010000000100000100726564756365642E68000000000000090200000000000000001305030A4B0204000101
-  - Name:            .rela.debug_line
-    Type:            SHT_RELA
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    Info:            .debug_line
-    Relocations:     
-      - Offset:          0x000000000000002E
-        Symbol:          .text
-        Type:            R_AARCH64_ABS64
-Symbols:         
-  - Name:            reduced.h
-    Type:            STT_FILE
-  - Name:            '$d.1'
-    Section:         .debug_str
-  - Name:            '$d.2'
-    Section:         .debug_abbrev
-  - Name:            '$d.3'
-    Section:         .debug_info
-  - Name:            '$d.4'
-    Section:         .debug_macinfo
-  - Name:            '$d.5'
-    Section:         .debug_pubnames
-  - Name:            '$d.6'
-    Section:         .debug_pubtypes
-  - Name:            '$d.7'
-    Section:         .comment
-  - Name:            '$d.8'
-    Section:         .debug_frame
-  - Name:            '$d.9'
-    Section:         .debug_line
-  - Name:            '$x.0'
-    Section:         .text
-  - Name:            .text
-    Type:            STT_SECTION
-    Section:         .text
-  - Name:            .debug_str
-    Type:            STT_SECTION
-    Section:         .debug_str
-  - Name:            .debug_abbrev
-    Type:            STT_SECTION
-    Section:         .debug_abbrev
-  - Name:            .debug_info
-    Type:            STT_SECTION
-    Section:         .debug_info
-  - Name:            .debug_frame
-    Type:            STT_SECTION
-    Section:         .debug_frame
-  - Name:            .debug_line
-    Type:            STT_SECTION
-    Section:         .debug_line
-  - Name:            f
-    Type:            STT_FUNC
-    Section:         .text
-    Size:            0x0000000000000008
-    Binding:         STB_GLOBAL
-DynamicSymbols:  
-...

Modified: lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp?rev=368289&r1=368288&r2=368289&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp Thu Aug  8 05:57:46 2019
@@ -123,62 +123,3 @@ TEST_F(ObjectFileELFTest, GetModuleSpeci
   Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
-
-static void CHECK_ABS32(uint8_t *bytes, uint32_t offset, uint32_t addend) {
-  uint32_t res;
-  memcpy(&res, reinterpret_cast<uint32_t *>(bytes + offset), sizeof(uint32_t));
-  ASSERT_EQ(addend, res);
-}
-
-static void CHECK_ABS64(uint8_t *bytes, uint64_t offset, uint64_t addend) {
-  uint64_t res;
-  memcpy(&res, reinterpret_cast<uint64_t *>(bytes + offset), sizeof(uint64_t));
-  ASSERT_EQ(addend, res);
-}
-
-TEST_F(ObjectFileELFTest, TestAARCH64Relocations) {
-  llvm::SmallString<128> obj;
-  ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
-      "debug-info-relocations-%%%%%%", "obj", obj));
-  llvm::FileRemover remover(obj);
-  ASSERT_THAT_ERROR(ReadYAMLObjectFile("debug-info-relocations.pcm.yaml", obj),
-                    llvm::Succeeded());
-
-  ModuleSpec spec{FileSpec(obj)};
-  spec.GetSymbolFileSpec().SetFile(obj, FileSpec::Style::native);
-  auto module_sp = std::make_shared<Module>(spec);
-
-  auto objfile = static_cast<ObjectFileELF *>(module_sp->GetObjectFile());
-  SectionList *section_list = objfile->GetSectionList();
-  ASSERT_NE(nullptr, section_list);
-
-  auto debug_info_sp =
-      section_list->FindSectionByName(ConstString(".debug_info"));
-  ASSERT_NE(nullptr, debug_info_sp);
-  objfile->RelocateSection(debug_info_sp.get());
-
-  DataExtractor data;
-  // length of 0x10 is not needed but length 0x0 crashes
-  objfile->GetData(0x00, 0x10, data);
-  DataBufferSP &data_buffer_sp = data.GetSharedDataBuffer();
-  uint8_t *bytes = data_buffer_sp->GetBytes();
-
-  addr_t debug_info_offset = debug_info_sp->GetFileOffset();
-  bytes += debug_info_offset;
-
-  // Sanity check - The first byte from the yaml file is 0x47
-  ASSERT_EQ(0x47, *bytes);
-
-  // .rela.debug_info contains 9 relocations:
-  // 7 R_AARCH64_ABS32 - 2 R_AARCH64_ABS64
-  // None have a value. Four have addends.
-  CHECK_ABS32(bytes, 0x6, 0);
-  CHECK_ABS32(bytes, 0xC, 0);
-  CHECK_ABS32(bytes, 0x12, 45);
-  CHECK_ABS32(bytes, 0x16, 0);
-  CHECK_ABS32(bytes, 0x1A, 55);
-  CHECK_ABS64(bytes, 0x1E, 0);
-  CHECK_ABS64(bytes, 0x2B, 0);
-  CHECK_ABS32(bytes, 0x39, 73);
-  CHECK_ABS32(bytes, 0x44, 75);
-}




More information about the lldb-commits mailing list