[Lldb-commits] [lldb] r320127 - [MachException] Avoid alignment UB, NFC

Vedant Kumar via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 7 17:09:40 PST 2017


Author: vedantk
Date: Thu Dec  7 17:09:40 2017
New Revision: 320127

URL: http://llvm.org/viewvc/llvm-project?rev=320127&view=rev
Log:
[MachException] Avoid alignment UB, NFC

Fix alignment UB in some Mach exception-handling logic.

This lets us build lldb and debugserver with UBSan in trapping mode, and
get further along in the testing process before a trap is encountered.

rdar://35923991

Modified:
    lldb/trunk/tools/debugserver/source/MacOSX/MachException.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachException.h

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachException.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachException.cpp?rev=320127&r1=320126&r2=320127&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachException.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachException.cpp Thu Dec  7 17:09:40 2017
@@ -113,8 +113,7 @@ catch_mach_exception_raise(mach_port_t e
     g_message->task_port = task_port;
     g_message->thread_port = thread_port;
     g_message->exc_type = exc_type;
-    for (mach_msg_type_number_t i=0; i<exc_data_count; ++i)
-      g_message->exc_data.push_back(exc_data[i]);
+    g_message->AppendExceptionData(exc_data, exc_data_count);
     return KERN_SUCCESS;
   } else if (!MachTask::IsValid(g_message->task_port)) {
     // Our original exception port isn't valid anymore check for a SIGTRAP
@@ -126,8 +125,7 @@ catch_mach_exception_raise(mach_port_t e
       g_message->task_port = task_port;
       g_message->thread_port = thread_port;
       g_message->exc_type = exc_type;
-      for (mach_msg_type_number_t i=0; i<exc_data_count; ++i)
-        g_message->exc_data.push_back(exc_data[i]);
+      g_message->AppendExceptionData(exc_data, exc_data_count);
       return KERN_SUCCESS;
     }
   }

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachException.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachException.h?rev=320127&r1=320126&r2=320127&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachException.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachException.h Thu Dec  7 17:09:40 2017
@@ -71,6 +71,15 @@ public:
       return (exc_type == EXC_BREAKPOINT ||
               ((exc_type == EXC_SOFTWARE) && exc_data[0] == 1));
     }
+    void AppendExceptionData(mach_exception_data_t Data,
+                             mach_msg_type_number_t Count) {
+      mach_exception_data_type_t Buf;
+      for (mach_msg_type_number_t i = 0; i < Count; ++i) {
+        // Perform an unaligned copy.
+        memcpy(&Buf, Data + i, sizeof(mach_exception_data_type_t));
+        exc_data.push_back(Buf);
+      }
+    }
     void Dump() const;
     void DumpStopReason() const;
     bool GetStopInfo(struct DNBThreadStopInfo *stop_info) const;




More information about the lldb-commits mailing list