[Lldb-commits] [lldb] 71c4d18 - Revert "[lldb] Refactor CrashReason"

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 15 02:55:14 PDT 2023


Author: David Spickett
Date: 2023-03-15T09:54:47Z
New Revision: 71c4d186f1cf247f1aa45f4fd1b38f350b68d123

URL: https://github.com/llvm/llvm-project/commit/71c4d186f1cf247f1aa45f4fd1b38f350b68d123
DIFF: https://github.com/llvm/llvm-project/commit/71c4d186f1cf247f1aa45f4fd1b38f350b68d123.diff

LOG: Revert "[lldb] Refactor CrashReason"

This reverts commit af38530ee29c285f3827e33a41edf27c9c3a6767 due
to a build failure on 32 bit.

Added: 
    

Modified: 
    lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
    lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
    lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
    lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
    lldb/source/Plugins/Process/POSIX/CrashReason.cpp
    lldb/source/Plugins/Process/POSIX/CrashReason.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
index 449ec27e0da8f..8e6399bcf9c79 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp
@@ -90,7 +90,8 @@ void NativeThreadFreeBSD::SetStoppedBySignal(uint32_t signo,
     case SIGBUS:
     case SIGFPE:
     case SIGILL:
-      m_stop_description = GetCrashReasonString(*info);
+      const auto reason = GetCrashReason(*info);
+      m_stop_description = GetCrashReasonString(reason, *info);
       break;
     }
   }

diff  --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index b62e9f643fa79..9b9dfe5214601 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -294,19 +294,19 @@ void NativeThreadLinux::SetStoppedBySignal(uint32_t signo,
     case SIGBUS:
     case SIGFPE:
     case SIGILL:
-      m_stop_description = GetCrashReasonString(*info);
-#ifndef SEGV_MTESERR
-#define SEGV_MTESERR 9
-#endif
-      if (info->si_signo == SIGSEGV && info->si_code == SEGV_MTESERR)
-        AnnotateSyncTagCheckFault(
-            reinterpret_cast<lldb::addr_t>(info->si_addr));
+      const auto reason = GetCrashReason(*info);
+      m_stop_description = GetCrashReasonString(reason, *info);
+
+      if (reason == CrashReason::eSyncTagCheckFault) {
+        AnnotateSyncTagCheckFault(info);
+      }
+
       break;
     }
   }
 }
 
-void NativeThreadLinux::AnnotateSyncTagCheckFault(lldb::addr_t fault_addr) {
+void NativeThreadLinux::AnnotateSyncTagCheckFault(const siginfo_t *info) {
   int32_t allocation_tag_type = 0;
   switch (GetProcess().GetArchitecture().GetMachine()) {
   // aarch64_32 deliberately not here because there's no 32 bit MTE
@@ -331,6 +331,7 @@ void NativeThreadLinux::AnnotateSyncTagCheckFault(lldb::addr_t fault_addr) {
   m_stop_description.pop_back();
 
   std::stringstream ss;
+  lldb::addr_t fault_addr = reinterpret_cast<uintptr_t>(info->si_addr);
   std::unique_ptr<MemoryTagManager> manager(std::move(details->manager));
 
   ss << " logical tag: 0x" << std::hex << manager->GetLogicalTag(fault_addr);

diff  --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
index 1051c3ab68bf1..030a4012f46a7 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -110,7 +110,7 @@ class NativeThreadLinux : public NativeThreadProtocol {
   /// Extend m_stop_description with logical and allocation tag values.
   /// If there is an error along the way just add the information we were able
   /// to get.
-  void AnnotateSyncTagCheckFault(lldb::addr_t fault_addr);
+  void AnnotateSyncTagCheckFault(const siginfo_t *info);
 
   // Member Variables
   lldb::StateType m_state;

diff  --git a/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp b/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
index f561c21b9d91c..995fe3fa78e8b 100644
--- a/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
+++ b/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -90,7 +90,8 @@ void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
     case SIGBUS:
     case SIGFPE:
     case SIGILL:
-      m_stop_description = GetCrashReasonString(*info);
+      const auto reason = GetCrashReason(*info);
+      m_stop_description = GetCrashReasonString(reason, *info);
       break;
     }
   }

diff  --git a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
index 87411104b3fe8..31ec03c64bdeb 100644
--- a/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
+++ b/lldb/source/Plugins/Process/POSIX/CrashReason.cpp
@@ -12,42 +12,6 @@
 
 #include <sstream>
 
-enum class CrashReason {
-  eInvalidCrashReason,
-
-  // SIGSEGV crash reasons.
-  eInvalidAddress,
-  ePrivilegedAddress,
-  eBoundViolation,
-  eAsyncTagCheckFault,
-  eSyncTagCheckFault,
-
-  // SIGILL crash reasons.
-  eIllegalOpcode,
-  eIllegalOperand,
-  eIllegalAddressingMode,
-  eIllegalTrap,
-  ePrivilegedOpcode,
-  ePrivilegedRegister,
-  eCoprocessorError,
-  eInternalStackError,
-
-  // SIGBUS crash reasons,
-  eIllegalAlignment,
-  eIllegalAddress,
-  eHardwareError,
-
-  // SIGFPE crash reasons,
-  eIntegerDivideByZero,
-  eIntegerOverflow,
-  eFloatDivideByZero,
-  eFloatOverflow,
-  eFloatUnderflow,
-  eFloatInexactResult,
-  eFloatInvalidOperation,
-  eFloatSubscriptRange
-};
-
 static void AppendFaultAddr(std::string &str, lldb::addr_t addr) {
   std::stringstream ss;
   ss << " (fault address: 0x" << std::hex << addr << ")";
@@ -73,8 +37,10 @@ static void AppendBounds(std::string &str, lldb::addr_t lower_bound,
 }
 #endif
 
-static CrashReason GetCrashReasonForSIGSEGV(int code) {
-  switch (code) {
+static CrashReason GetCrashReasonForSIGSEGV(const siginfo_t &info) {
+  assert(info.si_signo == SIGSEGV);
+
+  switch (info.si_code) {
 #ifdef SI_KERNEL
   case SI_KERNEL:
     // Some platforms will occasionally send nonstandard spurious SI_KERNEL
@@ -107,8 +73,10 @@ static CrashReason GetCrashReasonForSIGSEGV(int code) {
   return CrashReason::eInvalidCrashReason;
 }
 
-static CrashReason GetCrashReasonForSIGILL(int code) {
-  switch (code) {
+static CrashReason GetCrashReasonForSIGILL(const siginfo_t &info) {
+  assert(info.si_signo == SIGILL);
+
+  switch (info.si_code) {
   case ILL_ILLOPC:
     return CrashReason::eIllegalOpcode;
   case ILL_ILLOPN:
@@ -130,8 +98,10 @@ static CrashReason GetCrashReasonForSIGILL(int code) {
   return CrashReason::eInvalidCrashReason;
 }
 
-static CrashReason GetCrashReasonForSIGFPE(int code) {
-  switch (code) {
+static CrashReason GetCrashReasonForSIGFPE(const siginfo_t &info) {
+  assert(info.si_signo == SIGFPE);
+
+  switch (info.si_code) {
   case FPE_INTDIV:
     return CrashReason::eIntegerDivideByZero;
   case FPE_INTOVF:
@@ -153,8 +123,10 @@ static CrashReason GetCrashReasonForSIGFPE(int code) {
   return CrashReason::eInvalidCrashReason;
 }
 
-static CrashReason GetCrashReasonForSIGBUS(int code) {
-  switch (code) {
+static CrashReason GetCrashReasonForSIGBUS(const siginfo_t &info) {
+  assert(info.si_signo == SIGBUS);
+
+  switch (info.si_code) {
   case BUS_ADRALN:
     return CrashReason::eIllegalAlignment;
   case BUS_ADRERR:
@@ -166,8 +138,25 @@ static CrashReason GetCrashReasonForSIGBUS(int code) {
   return CrashReason::eInvalidCrashReason;
 }
 
-static std::string GetCrashReasonString(CrashReason reason,
-                                        lldb::addr_t fault_addr) {
+std::string GetCrashReasonString(CrashReason reason, const siginfo_t &info) {
+  std::string str;
+
+// make sure that siginfo_t has the bound fields available.
+#if defined(si_lower) && defined(si_upper)
+  if (reason == CrashReason::eBoundViolation) {
+    str = "signal SIGSEGV";
+    AppendBounds(str, reinterpret_cast<uintptr_t>(info.si_lower),
+                 reinterpret_cast<uintptr_t>(info.si_upper),
+                 reinterpret_cast<uintptr_t>(info.si_addr));
+    return str;
+  }
+#endif
+
+  return GetCrashReasonString(reason,
+                              reinterpret_cast<uintptr_t>(info.si_addr));
+}
+
+std::string GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr) {
   std::string str;
 
   switch (reason) {
@@ -255,52 +244,18 @@ static std::string GetCrashReasonString(CrashReason reason,
   return str;
 }
 
-static CrashReason GetCrashReason(int signo, int code) {
-  switch (signo) {
+CrashReason GetCrashReason(const siginfo_t &info) {
+  switch (info.si_signo) {
   case SIGSEGV:
-    return GetCrashReasonForSIGSEGV(code);
+    return GetCrashReasonForSIGSEGV(info);
   case SIGBUS:
-    return GetCrashReasonForSIGBUS(code);
+    return GetCrashReasonForSIGBUS(info);
   case SIGFPE:
-    return GetCrashReasonForSIGFPE(code);
+    return GetCrashReasonForSIGFPE(info);
   case SIGILL:
-    return GetCrashReasonForSIGILL(code);
+    return GetCrashReasonForSIGILL(info);
   }
 
   assert(false && "unexpected signal");
   return CrashReason::eInvalidCrashReason;
 }
-
-static std::string GetCrashReasonString(int signo, int code, lldb::addr_t addr,
-                                        std::optional<lldb::addr_t> lower,
-                                        std::optional<lldb::addr_t> upper) {
-  CrashReason reason = GetCrashReason(signo, code);
-
-  if (lower && upper) {
-    std::string str;
-    if (reason == CrashReason::eBoundViolation) {
-      str = "signal SIGSEGV";
-      AppendBounds(str, reinterpret_cast<uintptr_t>(*lower),
-                   reinterpret_cast<uintptr_t>(*upper),
-                   reinterpret_cast<uintptr_t>(addr));
-      return str;
-    }
-  }
-
-  return GetCrashReasonString(reason, addr);
-}
-
-std::string GetCrashReasonString(const siginfo_t &info) {
-#if defined(si_lower) && defined(si_upper)
-  std::optional<lldb::addr_t> lower =
-      reinterpret_cast<lldb::addr_t>(info.si_lower);
-  std::optional<lldb::addr_t> upper =
-      reinterpret_cast<lldb::addr_t>(info.si_upper);
-#else
-  std::optional<lldb::addr_t> lower;
-  std::optional<lldb::addr_t> upper;
-#endif
-  return GetCrashReasonString(info.si_signo, info.si_code,
-                              reinterpret_cast<uintptr_t>(info.si_addr), lower,
-                              upper);
-}

diff  --git a/lldb/source/Plugins/Process/POSIX/CrashReason.h b/lldb/source/Plugins/Process/POSIX/CrashReason.h
index 2177726b76f0e..466cd14e69842 100644
--- a/lldb/source/Plugins/Process/POSIX/CrashReason.h
+++ b/lldb/source/Plugins/Process/POSIX/CrashReason.h
@@ -15,6 +15,45 @@
 
 #include <string>
 
-std::string GetCrashReasonString(const siginfo_t &info);
+enum class CrashReason {
+  eInvalidCrashReason,
+
+  // SIGSEGV crash reasons.
+  eInvalidAddress,
+  ePrivilegedAddress,
+  eBoundViolation,
+  eAsyncTagCheckFault,
+  eSyncTagCheckFault,
+
+  // SIGILL crash reasons.
+  eIllegalOpcode,
+  eIllegalOperand,
+  eIllegalAddressingMode,
+  eIllegalTrap,
+  ePrivilegedOpcode,
+  ePrivilegedRegister,
+  eCoprocessorError,
+  eInternalStackError,
+
+  // SIGBUS crash reasons,
+  eIllegalAlignment,
+  eIllegalAddress,
+  eHardwareError,
+
+  // SIGFPE crash reasons,
+  eIntegerDivideByZero,
+  eIntegerOverflow,
+  eFloatDivideByZero,
+  eFloatOverflow,
+  eFloatUnderflow,
+  eFloatInexactResult,
+  eFloatInvalidOperation,
+  eFloatSubscriptRange
+};
+
+std::string GetCrashReasonString(CrashReason reason, lldb::addr_t fault_addr);
+std::string GetCrashReasonString(CrashReason reason, const siginfo_t &info);
+
+CrashReason GetCrashReason(const siginfo_t &info);
 
 #endif // #ifndef liblldb_CrashReason_H_


        


More information about the lldb-commits mailing list