Shuffle how lldb register contexts are built.
authormortimer <mortimer@openbsd.org>
Sun, 14 Feb 2021 16:16:02 +0000 (16:16 +0000)
committermortimer <mortimer@openbsd.org>
Sun, 14 Feb 2021 16:16:02 +0000 (16:16 +0000)
Instead of using #if defined(__arch__) to include / exclude the entire contents
of the NativeRegisterContext implementations, use a single NativeRegisterContextOpenBSD_arch
which includes the right arch specific register context, and provides a dummy implementation
for unsupported architectures.

This allows building lldb on architectures which do not have a register context implementation
so it can be used as a remote client.

ok patrick@

gnu/llvm/lldb/source/Plugins/Process/OpenBSD/CMakeLists.txt
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD.h
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_arch.cpp [new file with mode: 0644]
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_arm64.cpp
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_arm64.h
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_x86_64.cpp
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_x86_64.h
gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeThreadOpenBSD.cpp
gnu/usr.bin/clang/liblldbPluginProcess/Makefile

index 0c24116..424dc34 100644 (file)
@@ -1,8 +1,7 @@
 add_lldb_library(lldbPluginProcessOpenBSD PLUGIN
   NativeProcessOpenBSD.cpp
   NativeRegisterContextOpenBSD.cpp
-  NativeRegisterContextOpenBSD_x86_64.cpp
-  NativeRegisterContextOpenBSD_arm64.cpp
+  NativeRegisterContextOpenBSD_arch.cpp
   NativeThreadOpenBSD.cpp
 
   LINK_LIBS
index 013fe89..7d86a5b 100644 (file)
@@ -28,7 +28,7 @@ public:
   // NativeRegisterContextOpenBSD. The implementations can't collide as only one
   // NativeRegisterContextOpenBSD_* variant should be compiled into the final
   // executable.
-  static NativeRegisterContextOpenBSD *
+  static std::unique_ptr<NativeRegisterContextOpenBSD>
   CreateHostNativeRegisterContextOpenBSD(const ArchSpec &target_arch,
                                         NativeThreadProtocol &native_thread);
 
diff --git a/gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_arch.cpp b/gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD_arch.cpp
new file mode 100644 (file)
index 0000000..77c56e9
--- /dev/null
@@ -0,0 +1,35 @@
+//===-- NativeRegisterContextOpenBSD_arch.cpp ---------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// NativeRegisterContextOpenBSD_* contains the implementations for each
+// supported architecture, and includes the static initalizer
+// CreateHostNativeRegisterContextOpenBSD() implementation which returns a arch
+// specific register context. In order to facilitate compiling lldb
+// on architectures which do not have an RegisterContext implementation
+// this file will include the relevant backend, and otherwise will
+// include a stub implentation which just reports an error and exits.
+
+#if defined(__arm64__) || defined(__aarch64__)
+#include "NativeRegisterContextOpenBSD_arm64.cpp"
+#elif defined(__x86_64__)
+#include "NativeRegisterContextOpenBSD_x86_64.cpp"
+#else
+
+#include "Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD.h"
+
+using namespace lldb_private;
+using namespace lldb_private::process_openbsd;
+
+std::unique_ptr<NativeRegisterContextOpenBSD>
+NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(
+        const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
+  return std::unique_ptr<NativeRegisterContextOpenBSD>{};
+}
+
+#endif
index d00d67b..a385bcd 100644 (file)
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#if defined(__arm64__) || defined(__aarch64__)
-
 #include <elf.h>
 #include <err.h>
 #include <stdint.h>
@@ -108,10 +106,10 @@ static const RegisterSet g_reg_sets_arm64[k_num_register_sets] = {
     {"Floating Point Registers", "fpu", k_num_fpr_registers_arm64,
      g_fpu_regnums_arm64}};
 
-NativeRegisterContextOpenBSD *
+std::unique_ptr<NativeRegisterContextOpenBSD>
 NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(
     const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
-  return new NativeRegisterContextOpenBSD_arm64(target_arch, native_thread);
+  return std::make_unique<NativeRegisterContextOpenBSD_arm64>(target_arch, native_thread);
 }
 
 // ----------------------------------------------------------------------------
@@ -558,5 +556,3 @@ int NativeRegisterContextOpenBSD_arm64::WriteRegisterSet(uint32_t set) {
   }
   return -1;
 }
-
-#endif // defined(__arm64__) || defined(__aarch64__)
index 8dc482c..7cab092 100644 (file)
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#if defined(__arm64__) || defined(__aarch64__)
-
 #ifndef lldb_NativeRegisterContextOpenBSD_arm64_h
 #define lldb_NativeRegisterContextOpenBSD_arm64_h
 
@@ -83,5 +81,3 @@ private:
 } // namespace lldb_private
 
 #endif // #ifndef lldb_NativeRegisterContextOpenBSD_arm64_h
-
-#endif // defined(__arm64__) || defined(__aarch64__)
index 0b7e815..6044d52 100644 (file)
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#if defined(__x86_64__)
-
 #include <elf.h>
 #include <err.h>
 #include <stdint.h>
@@ -110,10 +108,10 @@ struct x86_fpu_addr {
 
 #define REG_CONTEXT_SIZE (GetGPRSize() + GetFPRSize())
 
-NativeRegisterContextOpenBSD *
+std::unique_ptr<NativeRegisterContextOpenBSD>
 NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(
     const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
-  return new NativeRegisterContextOpenBSD_x86_64(target_arch, native_thread);
+  return std::make_unique<NativeRegisterContextOpenBSD_x86_64>(target_arch, native_thread);
 }
 
 // ----------------------------------------------------------------------------
@@ -672,5 +670,3 @@ Status NativeRegisterContextOpenBSD_x86_64::WriteAllRegisterValues(
 
   return error;
 }
-
-#endif // defined(__x86_64__)
index 8f66c89..44497d7 100644 (file)
@@ -7,8 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#if defined(__x86_64__)
-
 #ifndef lldb_NativeRegisterContextOpenBSD_x86_64_h
 #define lldb_NativeRegisterContextOpenBSD_x86_64_h
 
@@ -70,5 +68,3 @@ private:
 } // namespace lldb_private
 
 #endif // #ifndef lldb_NativeRegisterContextOpenBSD_x86_64_h
-
-#endif // defined(__x86_64__)
index f16beee..90f1424 100644 (file)
@@ -27,9 +27,11 @@ using namespace lldb_private::process_openbsd;
 NativeThreadOpenBSD::NativeThreadOpenBSD(NativeProcessOpenBSD &process,
                                        lldb::tid_t tid)
     : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
-      m_stop_info(), m_reg_context_up(
-NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(process.GetArchitecture(), *this)
-), m_stop_description() {}
+      m_stop_info(), m_stop_description() {
+  m_reg_context_up = NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(process.GetArchitecture(), *this);
+  if (!m_reg_context_up)
+    llvm_unreachable("This architecture does not support debugging running processes.");
+}
 
 void NativeThreadOpenBSD::SetStoppedBySignal(uint32_t signo,
                                             const siginfo_t *info) {
index 687a51e..87ca6ab 100644 (file)
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2020/08/03 14:45:30 patrick Exp $
+# $OpenBSD: Makefile,v 1.8 2021/02/14 16:16:02 mortimer Exp $
 
 LIB=   lldbPluginProcess
 NOPIC=
@@ -30,8 +30,7 @@ SRCS= AuxVector.cpp \
        MipsLinuxSignals.cpp \
        NativeProcessOpenBSD.cpp \
        NativeRegisterContextOpenBSD.cpp \
-       NativeRegisterContextOpenBSD_x86_64.cpp \
-       NativeRegisterContextOpenBSD_arm64.cpp \
+       NativeRegisterContextOpenBSD_arch.cpp \
        NativeRegisterContextRegisterInfo.cpp \
        NativeThreadOpenBSD.cpp \
        NetBSDSignals.cpp \