Index: lldb/lit/Modules/ELF/netbsd-core-amd64.test =================================================================== --- /dev/null +++ lldb/lit/Modules/ELF/netbsd-core-amd64.test @@ -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 Index: lldb/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml =================================================================== --- /dev/null +++ lldb/lit/Modules/ELF/netbsd-exec-8.99.30-amd64.yaml @@ -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 +... Index: lldb/lit/Modules/lit.local.cfg =================================================================== --- lldb/lit/Modules/lit.local.cfg +++ lldb/lit/Modules/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.s', '.yaml'] +config.suffixes = ['.s', '.test', '.yaml'] Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -55,6 +55,7 @@ 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_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 @@ // 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) {