pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lldb-netbsd: Add support for reading aarch64 core files



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Thu Apr 12 03:03:24 2018 +0200
Changeset:	ac61774e0ac7204094ef643a3a106218049d399d

Modified Files:
	lldb-netbsd/distinfo
	lldb-netbsd/patches/patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp
Added Files:
	lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp
	lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_RegisterUtilities.h
	lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ThreadElfCore.cpp

Log Message:
lldb-netbsd: Add support for reading aarch64 core files

For now, there is disabled an option to read FP registers.

Tested with a core(5) file shipped by jmcneill:

$ LD_LIBRARY_PATH=/usr/pkg/lib  /public/llvm-build/bin/lldb -c ./a.out.core ./a.out
(lldb) target create "./a.out" --core "./a.out.core"
Core file '/public/core-arm64/./a.out.core' (aarch64) was loaded.
(lldb) thread list
Process 0 stopped
* thread #1: tid = 1, 0x0000000200100990 a.out`main(argc=1, argv=0x0000ffffffb97a88) at test.c:27, stop reason = signal SIGSEGV
(lldb) bt
* thread #1, stop reason = signal SIGSEGV
  * frame #0: 0x0000000200100990 a.out`main(argc=1, argv=0x0000ffffffb97a88) at test.c:27
    frame #1: 0x0000000200100834 a.out`___start + 320
(lldb) list
(lldb) list main
File: /home/jmcneill/test.c
(lldb) target
Available completions:
        create
        delete
        list
        modules
        select
        stop-hook
        symbols
        variable
(lldb) target list
Current targets:
* target #0: ./a.out ( arch=aarch64-*-netbsd8.99.14, platform=host, state=stopped )
(lldb) platform
Available completions:
        connect
        disconnect
        file
        get-file
        get-size
        list
        mkdir
        process
        put-file
        select
        settings
        shell
        status
        target-install
(lldb) platform status
  Platform: host
    Triple: x86_64-unknown-netbsd8.99.12
OS Version: 8.99.14 (0899001400)
    Kernel: NetBSD 8.99.14 (GENERIC) #4: Sun Apr  8 18:53:59 CEST 2018  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC
  Hostname: 127.0.0.1
WorkingDir: /public/core-arm64
    Kernel: NetBSD
   Release: 8.99.14
   Version: NetBSD 8.99.14 (GENERIC) #4: Sun Apr  8 18:53:59 CEST 2018  root@chieftec:/public/netbsd-root/sys/arch/amd64/compile/GENERIC

Sponsored by <The NetBSD Foundation>

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=ac61774e0ac7204094ef643a3a106218049d399d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 lldb-netbsd/distinfo                               |   5 +-
 ...source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp |   8 +-
 ...rce_Plugins_Process_elf-core_ProcessElfCore.cpp | 192 +++++++++++++++++++++
 ...ce_Plugins_Process_elf-core_RegisterUtilities.h |  62 +++++++
 ...urce_Plugins_Process_elf-core_ThreadElfCore.cpp |  14 ++
 5 files changed, 276 insertions(+), 5 deletions(-)

diffs:
diff --git a/lldb-netbsd/distinfo b/lldb-netbsd/distinfo
index 462571b386..faad2ccba9 100644
--- a/lldb-netbsd/distinfo
+++ b/lldb-netbsd/distinfo
@@ -12,4 +12,7 @@ Size (libcxx-3.6.2.src.tar.xz) = 944020 bytes
 SHA1 (llvm-3.6.2.src.tar.xz) = 7a00257eb2bc9431e4c77c3a36b033072c54bc7e
 RMD160 (llvm-3.6.2.src.tar.xz) = 521cbc5fe2925ea3c6e90c7a31f752a04045c972
 Size (llvm-3.6.2.src.tar.xz) = 12802380 bytes
-SHA1 (patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp) = b01ecef7dfe109d047663997452065cdc4242292
+SHA1 (patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp) = 6da890620fb393f202d2acc6402b96dbb0b82928
+SHA1 (patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp) = 90f9ce4bdbdfbfab2090b7296a00c66dacd126d6
+SHA1 (patch-source_Plugins_Process_elf-core_RegisterUtilities.h) = e1f3d5eb7b050e92f6d1d57ea31266eb3a8720ad
+SHA1 (patch-source_Plugins_Process_elf-core_ThreadElfCore.cpp) = 9ef247cde8681d060263ccd25d7128f7c7d38e30
diff --git a/lldb-netbsd/patches/patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp b/lldb-netbsd/patches/patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp
index 72745ca38d..8b74011ba3 100644
--- a/lldb-netbsd/patches/patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp
+++ b/lldb-netbsd/patches/patch-source_Plugins_ObjectFile_ELF_ObjectFileELF.cpp
@@ -1,8 +1,8 @@
 $NetBSD$
 
---- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp.orig	2018-02-02 18:39:18.800930947 +0000
+--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp.orig	2018-02-23 22:54:35.000000000 +0000
 +++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
-@@ -52,6 +52,7 @@ namespace {
+@@ -53,6 +53,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";
@@ -10,7 +10,7 @@ $NetBSD$
  const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
  const char *const LLDB_NT_OWNER_CSR = "csr";
  const char *const LLDB_NT_OWNER_ANDROID = "Android";
-@@ -67,8 +68,10 @@ const elf_word LLDB_NT_GNU_ABI_SIZE = 16
+@@ -68,8 +69,10 @@ const elf_word LLDB_NT_GNU_ABI_SIZE = 16
  
  const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03;
  
@@ -23,7 +23,7 @@ $NetBSD$
  
  // GNU ABI note OS constants
  const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00;
-@@ -1341,25 +1344,41 @@ ObjectFileELF::RefineModuleDetailsFromNo
+@@ -1297,25 +1300,41 @@ ObjectFileELF::RefineModuleDetailsFromNo
          // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform
          arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
      }
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp
new file mode 100644
index 0000000000..28e9921a54
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ProcessElfCore.cpp
@@ -0,0 +1,192 @@
+$NetBSD$
+
+--- source/Plugins/Process/elf-core/ProcessElfCore.cpp.orig	2018-02-19 18:10:15.000000000 +0000
++++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
+@@ -453,16 +453,43 @@ static void ParseFreeBSDPrStatus(ThreadD
+   thread_data.gpregset = DataExtractor(data, offset, len);
+ }
+ 
+-static void ParseNetBSDProcInfo(ThreadData &thread_data,
+-                                const DataExtractor &data) {
++static Status ParseNetBSDProcInfo(const DataExtractor &data, uint32_t &cpi_nlwps,
++                                  uint32_t &cpi_signo, uint32_t &cpi_siglwp) {
+   lldb::offset_t offset = 0;
+ 
+-  int version = data.GetU32(&offset);
++  uint32_t version = data.GetU32(&offset);
+   if (version != 1)
+-    return;
++    return Status(
++        "Error parsing NetBSD core(5) notes: Unsupported procinfo version");
+ 
+-  offset += 4;
+-  thread_data.signo = data.GetU32(&offset);
++  uint32_t cpisize = data.GetU32(&offset);
++  if (cpisize != NETBSD::NT_PROCINFO_SIZE)
++    return Status(
++        "Error parsing NetBSD core(5) notes: Unsupported procinfo size");
++
++  cpi_signo = data.GetU32(&offset); /* killing signal */
++
++  offset += NETBSD::NT_PROCINFO_CPI_SIGCODE_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SIGPEND_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SIGMASK_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SIGIGNORE_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SIGCATCH_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_PID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_PPID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_PGRP_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_RUID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_EUID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SVUID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_RGID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_EGID_SIZE;
++  offset += NETBSD::NT_PROCINFO_CPI_SVGID_SIZE;
++  cpi_nlwps = data.GetU32(&offset); /* number of LWPs */
++
++  offset += NETBSD::NT_PROCINFO_CPI_NAME_SIZE;
++  cpi_siglwp = data.GetU32(&offset); /* LWP target of killing signal */
++
++  return Status();
+ }
+ 
+ static void ParseOpenBSDProcInfo(ThreadData &thread_data,
+@@ -550,35 +577,113 @@ llvm::Error ProcessElfCore::parseFreeBSD
+ 
+ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
+   ThreadData thread_data;
+-  for (const auto &note : notes) {
+-    // NetBSD per-thread information is stored in notes named
+-    // "NetBSD-CORE@nnn" so match on the initial part of the string.
+-    if (!llvm::StringRef(note.info.n_name).startswith("NetBSD-CORE"))
+-      continue;
+ 
+-    switch (note.info.n_type) {
+-    case NETBSD::NT_PROCINFO:
+-      ParseNetBSDProcInfo(thread_data, note.data);
+-      break;
+-    case NETBSD::NT_AUXV:
+-      m_auxv = note.data;
+-      break;
++  ArchSpec arch = GetArchitecture();
+ 
+-    case NETBSD::NT_AMD64_REGS:
+-      if (GetArchitecture().GetMachine() == llvm::Triple::x86_64)
+-        thread_data.gpregset = note.data;
+-      break;
+-    default:
+-      thread_data.notes.push_back(note);
+-      break;
++  /*
++   * To be extracted from struct netbsd_elfcore_procinfo
++   * Used to sanity check of the LWPs of the process
++   */
++  uint32_t nlwps = 0;
++  uint32_t signo;  /* killing signal */
++  uint32_t siglwp; /* LWP target of killing signal */
++
++  for (const auto &note : notes) {
++    llvm::StringRef name = note.info.n_name;
++
++    if (name == "NetBSD-CORE") {
++      if (note.info.n_type == NETBSD::NT_PROCINFO) {
++        Status error = ParseNetBSDProcInfo(note.data, nlwps, signo, siglwp);
++        if (error.Fail()) {
++          return error.ToError(); // return Status(std::move(error));
++        }
++      } else if (note.info.n_type == NETBSD::NT_AUXV) {
++        m_auxv = note.data;
++      }
++    } else if (name.consume_front("NetBSD-CORE@")) {
++      lldb::tid_t tid;
++      if (name.getAsInteger(10, tid))
++        return Status("Error parsing NetBSD core(5) notes: Cannot convert "
++                     "LWP ID to integer").ToError();
++
++      switch (arch.GetMachine()) {
++      case llvm::Triple::x86_64: {
++        /* Assume order PT_GETREGS, PT_GETFPREGS */
++        if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
++          m_thread_data.push_back(ThreadData());
++          m_thread_data.back().gpregset = note.data;
++          m_thread_data.back().tid = tid;
++        } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
++#if notyet
++          if (m_thread_data.empty() || tid != m_thread_data.back().tid)
++            return Status("Error parsing NetBSD core(5) notes: Unexpected order "
++                         "of NOTEs PT_GETFPREG before PT_GETREG").ToError();
++          m_thread_data.back().fpregset = note.data;
++#endif
++        } else {
++          return Status(
++              "Error parsing NetBSD core(5) notes: Unsupported AMD64 NOTE").ToError();
++        }
++      } break;
++      case llvm::Triple::aarch64: {
++        /* Assume order PT_GETREGS, PT_GETFPREGS */
++	{FILE *fp = fopen("/tmp/log.txt", "a");fprintf(fp, "%s() %s:%d note.info.n_type=%d\n", __func__, __FILE__, __LINE__, note.info.n_type);fflush(fp);fclose(fp);}
++        if (note.info.n_type == NETBSD::AARCH64::NT_REGS) {
++          m_thread_data.push_back(ThreadData());
++          m_thread_data.back().gpregset = note.data;
++          m_thread_data.back().tid = tid;
++        } else if (note.info.n_type == NETBSD::AARCH64::NT_FPREGS) {
++#if notyet
++          if (m_thread_data.empty() || tid != m_thread_data.back().tid)
++            return Status("Error parsing NetBSD core(5) notes: Unexpected order "
++                         "of NOTEs PT_GETFPREG before PT_GETREG").ToError();
++          m_thread_data.back().fpregset = note.data;
++#endif
++        } else {
++          return Status(
++              "Error parsing NetBSD core(5) notes: Unsupported EVBARM NOTE").ToError();
++        }
++      } break;
++      default:
++        return Status(
++            "Error parsing NetBSD core(5) notes: Unsupported architecture").ToError();
++      }
++    } else {
++      return Status("Error parsing NetBSD core(5) notes: Unrecognized note").ToError();
+     }
+   }
+-  if (thread_data.gpregset.GetByteSize() == 0) {
+-    return llvm::make_error<llvm::StringError>(
+-        "Could not find general purpose registers note in core file.",
+-        llvm::inconvertibleErrorCode());
++
++  if (m_thread_data.empty())
++    return Status("Error parsing NetBSD core(5) notes: No threads information "
++                 "specified in notes").ToError();
++
++  if (m_thread_data.size() != nlwps)
++    return Status("Error parsing NetBSD core(5) notes: Mismatch between the "
++                 "number of LWPs in netbsd_elfcore_procinfo and the number of "
++                 "LWPs specified by MD notes").ToError();
++
++  /* The whole process signal */
++  if (siglwp == 0) {
++    for (auto &data : m_thread_data)
++      data.signo = signo;
++  }
++  /* Signal destinated for a particular LWP */
++  else {
++    bool passed = false;
++
++    for (auto &data : m_thread_data) {
++      if (data.tid == siglwp) {
++        data.signo = signo;
++        passed = true;
++        break;
++      }
++    }
++
++    if (!passed)
++      return Status(
++          "Error parsing NetBSD core(5) notes: Signal passed to unknown LWP").ToError();
+   }
+-  m_thread_data.push_back(thread_data);
++
+   return llvm::Error::success();
+ }
+ 
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_RegisterUtilities.h b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_RegisterUtilities.h
new file mode 100644
index 0000000000..2d42380034
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_RegisterUtilities.h
@@ -0,0 +1,62 @@
+$NetBSD$
+
+--- source/Plugins/Process/elf-core/RegisterUtilities.h.orig	2018-02-02 18:39:12.000000000 +0000
++++ source/Plugins/Process/elf-core/RegisterUtilities.h
+@@ -28,9 +28,46 @@ enum {
+ }
+ 
+ namespace NETBSD {
+-enum { NT_PROCINFO = 1, NT_AUXV, NT_AMD64_REGS = 33, NT_AMD64_FPREGS = 35 };
++enum { NT_PROCINFO = 1, NT_AUXV = 2};
++
++/* Size in bytes */
++enum { NT_PROCINFO_SIZE = 160 };
++
++/* Size in bytes */
++enum {
++  NT_PROCINFO_CPI_VERSION_SIZE = 4,
++  NT_PROCINFO_CPI_CPISIZE_SIZE = 4,
++  NT_PROCINFO_CPI_SIGNO_SIZE = 4,
++  NT_PROCINFO_CPI_SIGCODE_SIZE = 4,
++  NT_PROCINFO_CPI_SIGPEND_SIZE = 16,
++  NT_PROCINFO_CPI_SIGMASK_SIZE = 16,
++  NT_PROCINFO_CPI_SIGIGNORE_SIZE = 16,
++  NT_PROCINFO_CPI_SIGCATCH_SIZE = 16,
++  NT_PROCINFO_CPI_PID_SIZE = 4,
++  NT_PROCINFO_CPI_PPID_SIZE = 4,
++  NT_PROCINFO_CPI_PGRP_SIZE = 4,
++  NT_PROCINFO_CPI_SID_SIZE = 4,
++  NT_PROCINFO_CPI_RUID_SIZE = 4,
++  NT_PROCINFO_CPI_EUID_SIZE = 4,
++  NT_PROCINFO_CPI_SVUID_SIZE = 4,
++  NT_PROCINFO_CPI_RGID_SIZE = 4,
++  NT_PROCINFO_CPI_EGID_SIZE = 4,
++  NT_PROCINFO_CPI_SVGID_SIZE = 4,
++  NT_PROCINFO_CPI_NLWPS_SIZE = 4,
++  NT_PROCINFO_CPI_NAME_SIZE = 32,
++  NT_PROCINFO_CPI_SIGLWP_SIZE = 4,
++};
++
++namespace AMD64 {
++enum { NT_REGS = 33, NT_FPREGS = 35 };
++}
++
++namespace AARCH64 {
++enum { NT_REGS = 32, NT_FPREGS = 34 };
+ }
+ 
++} // namespace NETBSD
++
+ namespace OPENBSD {
+ enum {
+   NT_PROCINFO = 10,
+@@ -92,7 +129,8 @@ constexpr RegsetDesc FPR_Desc[] = {
+     // The result from FXSAVE is in NT_PRXFPREG for i386 core files
+     {llvm::Triple::Linux, llvm::Triple::x86, LINUX::NT_PRXFPREG},
+     {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_FPREGSET},
+-    {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::NT_AMD64_FPREGS},
++    {llvm::Triple::NetBSD, llvm::Triple::aarch64, NETBSD::AARCH64::NT_FPREGS},
++    {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::AMD64::NT_FPREGS},
+     {llvm::Triple::OpenBSD, llvm::Triple::UnknownArch, OPENBSD::NT_FPREGS},
+ };
+ 
diff --git a/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ThreadElfCore.cpp b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ThreadElfCore.cpp
new file mode 100644
index 0000000000..bb6108e043
--- /dev/null
+++ b/lldb-netbsd/patches/patch-source_Plugins_Process_elf-core_ThreadElfCore.cpp
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- source/Plugins/Process/elf-core/ThreadElfCore.cpp.orig	2018-02-02 18:39:12.000000000 +0000
++++ source/Plugins/Process/elf-core/ThreadElfCore.cpp
+@@ -118,6 +118,9 @@ ThreadElfCore::CreateRegisterContextForF
+ 
+     case llvm::Triple::NetBSD: {
+       switch (arch.GetMachine()) {
++      case llvm::Triple::aarch64:
++        reg_interface = new RegisterInfoPOSIX_arm64(arch);
++        break;
+       case llvm::Triple::x86_64:
+         reg_interface = new RegisterContextNetBSD_x86_64(arch);
+         break;


Home | Main Index | Thread Index | Old Index