[Lldb-commits] [PATCH] D101091: [lldb] [Process/elf-core] Fix reading NetBSD/i386 core dumps

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 22 10:44:39 PDT 2021


mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski.
mgorny requested review of this revision.

Add support for extracting basic data from NetBSD/i386 core dumps.
FPU registers are not supported at the moment.


https://reviews.llvm.org/D101091

Files:
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
  lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
  lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
  lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test
  lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test


Index: lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test
@@ -0,0 +1,3 @@
+# RUN: %lldb -b -s %s -c %p/Inputs/x86-32-netbsd.core | FileCheck %p/Inputs/x86-32-gp.check
+
+register read --all
Index: lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test
@@ -0,0 +1,13 @@
+# RUN: %lldb -b -s %s -c %p/Inputs/x86-32-netbsd.core | FileCheck %s
+
+register read --all
+# CHECK-DAG: eip = 0x08048955
+# CHECK-DAG: eflags = 0x00010282
+# CHECK-DAG: cs = 0x00000037
+# CHECK-DAG: fs = 0x0000004f
+# CHECK-DAG: gs = 0x0000008b
+# CHECK-DAG: ss = 0x0000004f
+# CHECK-DAG: ds = 0x0000004f
+# CHECK-DAG: es = 0x0000004f
+
+# TODO: fix reading fp registers
Index: lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
===================================================================
--- lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -20,6 +20,7 @@
 #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextNetBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextNetBSD_x86_64.h"
 #include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
 #include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
@@ -107,6 +108,9 @@
       switch (arch.GetMachine()) {
       case llvm::Triple::aarch64:
         break;
+      case llvm::Triple::x86:
+        reg_interface = new RegisterContextNetBSD_i386(arch);
+        break;
       case llvm::Triple::x86_64:
         reg_interface = new RegisterContextNetBSD_x86_64(arch);
         break;
Index: lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
===================================================================
--- lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
+++ lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
@@ -51,7 +51,7 @@
 enum { NT_REGS = 32, NT_FPREGS = 34 };
 }
 
-namespace AMD64 {
+namespace X86 {
 enum { NT_REGS = 33, NT_FPREGS = 35 };
 }
 
@@ -106,7 +106,8 @@
     {llvm::Triple::Linux, llvm::Triple::x86, llvm::ELF::NT_PRXFPREG},
     {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_FPREGSET},
     {llvm::Triple::NetBSD, llvm::Triple::aarch64, NETBSD::AARCH64::NT_FPREGS},
-    {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::AMD64::NT_FPREGS},
+    {llvm::Triple::NetBSD, llvm::Triple::x86, NETBSD::X86::NT_FPREGS},
+    {llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::X86::NT_FPREGS},
     {llvm::Triple::OpenBSD, llvm::Triple::UnknownArch, OPENBSD::NT_FPREGS},
 };
 
Index: lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
===================================================================
--- lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -641,9 +641,10 @@
           thread_data.notes.push_back(note);
         }
       } break;
+      case llvm::Triple::x86:
       case llvm::Triple::x86_64: {
         // Assume order PT_GETREGS, PT_GETFPREGS
-        if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
+        if (note.info.n_type == NETBSD::X86::NT_REGS) {
           // If this is the next thread, push the previous one first.
           if (had_nt_regs) {
             m_thread_data.push_back(thread_data);
@@ -658,7 +659,7 @@
                 "Could not find general purpose registers note in core file.",
                 llvm::inconvertibleErrorCode());
           had_nt_regs = true;
-        } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
+        } else if (note.info.n_type == NETBSD::X86::NT_FPREGS) {
           if (!had_nt_regs || tid != thread_data.tid)
             return llvm::make_error<llvm::StringError>(
                 "Error parsing NetBSD core(5) notes: Unexpected order "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101091.339718.patch
Type: text/x-patch
Size: 4165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210422/76b5ffd0/attachment.bin>


More information about the lldb-commits mailing list