Author: mgorny
Date: Wed Feb 20 06:31:06 2019
New Revision: 354466

URL: http://llvm.org/viewvc/llvm-project?rev=354466&view=rev
Log:
[lldb] [ObjectFile/ELF] Fix recognizing NetBSD images

Split the recognition into NetBSD executables & shared libraries
and core(5) files.

Introduce new owner type: "NetBSD-CORE", as core(5) files are not tagged
in the same way as regular NetBSD executables.

Stop using incorrectly ABI_TAG and ABI_SIZE.  Introduce IDENT_TAG,
IDENT_DECSZ, IDENT_NAMESZ and PROCINFO.

The new values detect correctly the NetBSD images.

The patch has been originally written by Kamil Rytarowski.  I've added
tests and applied minor code changes per review.  The work has been
sponsored by the NetBSD Foundation.

Differential Revision: https://reviews.llvm.org/D42870

Added:
    lldb/trunk/lit/Modules/ELF/Inputs/netbsd-amd64.core   (with props)
    lldb/trunk/lit/Modules/ELF/netbsd-core-amd64.test
    lldb/trunk/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml
Modified:
    lldb/trunk/lit/Modules/lit.local.cfg
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Added: lldb/trunk/lit/Modules/ELF/Inputs/netbsd-amd64.core
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/Inputs/netbsd-amd64.core?rev=354466&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lldb/trunk/lit/Modules/ELF/Inputs/netbsd-amd64.core
------------------------------------------------------------------------------
    svn:mime-type = application/x-coredump

Added: lldb/trunk/lit/Modules/ELF/netbsd-core-amd64.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/netbsd-core-amd64.test?rev=354466&view=auto
==============================================================================
--- lldb/trunk/lit/Modules/ELF/netbsd-core-amd64.test (added)
+++ lldb/trunk/lit/Modules/ELF/netbsd-core-amd64.test Wed Feb 20 06:31:06 2019
@@ -0,0 +1,12 @@
+# Test whether NetBSD core dumps are recognized correctly.
+
+# Core dump generated by the following program:
+# int main() {
+#   void* v = 0;
+#   *v = 1;
+#   return 0;
+# }
+
+# RUN: lldb-test object-file %S/Inputs/netbsd-amd64.core | FileCheck %s
+# CHECK: Architecture: x86_64-unknown-netbsd
+# CHECK: Type: core file

Added: lldb/trunk/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml?rev=354466&view=auto
==============================================================================
--- lldb/trunk/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml (added)
+++ lldb/trunk/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml Wed Feb 20 
06:31:06 2019
@@ -0,0 +1,22 @@
+# Test whether NetBSD executables are recognized correctly.
+
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test object-file %t | FileCheck %s
+# CHECK: Architecture: x86_64--netbsd8.99.30
+# CHECK: Type: executable
+
+--- !ELF
+FileHeader:      
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+  Entry:           0x00000000002006F0
+Sections:        
+  - Name:            .note.netbsd.ident
+    Type:            SHT_NOTE
+    Flags:           [ SHF_ALLOC ]
+    Address:         0x00000000002005A8
+    AddressAlign:    0x0000000000000004
+    Content:         0700000004000000010000004E6574425344000078B29535
+...

Modified: lldb/trunk/lit/Modules/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/lit.local.cfg?rev=354466&r1=354465&r2=354466&view=diff
==============================================================================
--- lldb/trunk/lit/Modules/lit.local.cfg (original)
+++ lldb/trunk/lit/Modules/lit.local.cfg Wed Feb 20 06:31:06 2019
@@ -1 +1 @@
-config.suffixes = ['.s', '.yaml']
+config.suffixes = ['.s', '.test', '.yaml']

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=354466&r1=354465&r2=354466&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Wed Feb 20 
06:31:06 2019
@@ -55,6 +55,7 @@ namespace {
 const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD";
 const char *const LLDB_NT_OWNER_GNU = "GNU";
 const char *const LLDB_NT_OWNER_NETBSD = "NetBSD";
+const char *const LLDB_NT_OWNER_NETBSDCORE = "NetBSD-CORE";
 const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
 const char *const LLDB_NT_OWNER_CSR = "csr";
 const char *const LLDB_NT_OWNER_ANDROID = "Android";
@@ -70,8 +71,10 @@ const elf_word LLDB_NT_GNU_ABI_SIZE = 16
 
 const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03;
 
-const elf_word LLDB_NT_NETBSD_ABI_TAG = 0x01;
-const elf_word LLDB_NT_NETBSD_ABI_SIZE = 4;
+const elf_word LLDB_NT_NETBSD_IDENT_TAG = 1;
+const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ = 4;
+const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ = 7;
+const elf_word LLDB_NT_NETBSD_PROCINFO = 1;
 
 // GNU ABI note OS constants
 const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00;
@@ -1294,25 +1297,39 @@ ObjectFileELF::RefineModuleDetailsFromNo
         // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform
         arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
     }
-    // Process NetBSD ELF notes.
+    // Process NetBSD ELF executables and shared libraries
     else if ((note.n_name == LLDB_NT_OWNER_NETBSD) &&
-             (note.n_type == LLDB_NT_NETBSD_ABI_TAG) &&
-             (note.n_descsz == LLDB_NT_NETBSD_ABI_SIZE)) {
-      // Pull out the min version info.
+             (note.n_type == LLDB_NT_NETBSD_IDENT_TAG) &&
+             (note.n_descsz == LLDB_NT_NETBSD_IDENT_DESCSZ) &&
+             (note.n_namesz == LLDB_NT_NETBSD_IDENT_NAMESZ)) {
+      // Pull out the version info.
       uint32_t version_info;
       if (data.GetU32(&offset, &version_info, 1) == nullptr) {
         error.SetErrorString("failed to read NetBSD ABI note payload");
         return error;
       }
-
+      // Convert the version info into a major/minor/patch number.
+      //     #define __NetBSD_Version__ MMmmrrpp00
+      //
+      //     M = major version
+      //     m = minor version; a minor number of 99 indicates current.
+      //     r = 0 (since NetBSD 3.0 not used)
+      //     p = patchlevel
+      const uint32_t version_major = version_info / 100000000;
+      const uint32_t version_minor = (version_info % 100000000) / 1000000;
+      const uint32_t version_patch = (version_info % 10000) / 100;
+      // Set the elf OS version to NetBSD.  Also clear the vendor.
+      arch_spec.GetTriple().setOSName(
+          llvm::formatv("netbsd{0}.{1}.{2}", version_major, version_minor,
+                        version_patch).str());
+      arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
+    }
+    // Process NetBSD ELF core(5) notes
+    else if ((note.n_name == LLDB_NT_OWNER_NETBSDCORE) &&
+             (note.n_type == LLDB_NT_NETBSD_PROCINFO)) {
       // Set the elf OS version to NetBSD.  Also clear the vendor.
       arch_spec.GetTriple().setOS(llvm::Triple::OSType::NetBSD);
       arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
-
-      if (log)
-        log->Printf(
-            "ObjectFileELF::%s detected NetBSD, min version constant %" PRIu32,
-            __FUNCTION__, version_info);
     }
     // Process OpenBSD ELF notes.
     else if (note.n_name == LLDB_NT_OWNER_OPENBSD) {


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to