[Lldb-commits] [lldb] d4c437c - [lldb] [Process/elf-core] Fix reading NetBSD/i386 core dumps
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Sun Jun 20 10:38:54 PDT 2021
Author: Michał Górny
Date: 2021-06-20T18:59:21+02:00
New Revision: d4c437c4289c0e0fd2684920b7e59b3f3c19b8e5
URL: https://github.com/llvm/llvm-project/commit/d4c437c4289c0e0fd2684920b7e59b3f3c19b8e5
DIFF: https://github.com/llvm/llvm-project/commit/d4c437c4289c0e0fd2684920b7e59b3f3c19b8e5.diff
LOG: [lldb] [Process/elf-core] Fix reading NetBSD/i386 core dumps
Add support for extracting basic data from NetBSD/i386 core dumps.
FPU registers are not supported at the moment.
Differential Revision: https://reviews.llvm.org/D101091
Added:
lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test
lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test
Modified:
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 21f1b93dc13a8..12bc7390c7294 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -664,6 +664,32 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
thread_data.notes.push_back(note);
}
} break;
+ case llvm::Triple::x86: {
+ // Assume order PT_GETREGS, PT_GETFPREGS
+ if (note.info.n_type == NETBSD::I386::NT_REGS) {
+ // If this is the next thread, push the previous one first.
+ if (had_nt_regs) {
+ m_thread_data.push_back(thread_data);
+ thread_data = ThreadData();
+ had_nt_regs = false;
+ }
+
+ thread_data.gpregset = note.data;
+ thread_data.tid = tid;
+ if (thread_data.gpregset.GetByteSize() == 0)
+ return llvm::make_error<llvm::StringError>(
+ "Could not find general purpose registers note in core file.",
+ llvm::inconvertibleErrorCode());
+ had_nt_regs = true;
+ } else if (note.info.n_type == NETBSD::I386::NT_FPREGS) {
+ if (!had_nt_regs || tid != thread_data.tid)
+ return llvm::make_error<llvm::StringError>(
+ "Error parsing NetBSD core(5) notes: Unexpected order "
+ "of NOTEs PT_GETFPREG before PT_GETREG",
+ llvm::inconvertibleErrorCode());
+ thread_data.notes.push_back(note);
+ }
+ } break;
case llvm::Triple::x86_64: {
// Assume order PT_GETREGS, PT_GETFPREGS
if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
diff --git a/lldb/source/Plugins/Process/elf-core/RegisterUtilities.h b/lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
index ce07dfc38f808..f6a2fbdcc9387 100644
--- a/lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
+++ b/lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
@@ -55,6 +55,10 @@ namespace AMD64 {
enum { NT_REGS = 33, NT_FPREGS = 35 };
}
+namespace I386 {
+enum { NT_REGS = 33, NT_FPREGS = 35 };
+}
+
} // namespace NETBSD
namespace OPENBSD {
@@ -106,6 +110,7 @@ constexpr RegsetDesc FPR_Desc[] = {
{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, NETBSD::I386::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/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 28483cf5f5a05..937d074869a25 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/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 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
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;
diff --git a/lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test b/lldb/test/Shell/Register/Core/x86-32-netbsd-addr.test
new file mode 100644
index 0000000000000..a074e91b8d54f
--- /dev/null
+++ b/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
diff --git a/lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test b/lldb/test/Shell/Register/Core/x86-32-netbsd-gp.test
new file mode 100644
index 0000000000000..0b5221f5a89f1
--- /dev/null
+++ b/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
More information about the lldb-commits
mailing list