1061da546Spatrick //===-- StopInfoMachException.h ---------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H 10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H 11061da546Spatrick 12*f6aab3d8Srobert #include <optional> 13061da546Spatrick #include <string> 14061da546Spatrick 15061da546Spatrick #include "lldb/Target/StopInfo.h" 16061da546Spatrick 17*f6aab3d8Srobert #if defined(__APPLE__) 18*f6aab3d8Srobert // Needed for the EXC_* defines 19*f6aab3d8Srobert #include <mach/exception.h> 20*f6aab3d8Srobert #endif 21*f6aab3d8Srobert 22061da546Spatrick namespace lldb_private { 23061da546Spatrick 24061da546Spatrick class StopInfoMachException : public StopInfo { 25*f6aab3d8Srobert /// Determine the pointer-authentication related failure that caused this 26*f6aab3d8Srobert /// exception. Returns true and fills out the failure description if there 27*f6aab3d8Srobert /// is auth-related failure, and returns false otherwise. 28*f6aab3d8Srobert bool DeterminePtrauthFailure(ExecutionContext &exe_ctx); 29*f6aab3d8Srobert 30061da546Spatrick public: 31061da546Spatrick // Constructors and Destructors StopInfoMachException(Thread & thread,uint32_t exc_type,uint32_t exc_data_count,uint64_t exc_code,uint64_t exc_subcode)32061da546Spatrick StopInfoMachException(Thread &thread, uint32_t exc_type, 33061da546Spatrick uint32_t exc_data_count, uint64_t exc_code, 34061da546Spatrick uint64_t exc_subcode) 35061da546Spatrick : StopInfo(thread, exc_type), m_exc_data_count(exc_data_count), 36061da546Spatrick m_exc_code(exc_code), m_exc_subcode(exc_subcode) {} 37061da546Spatrick 38061da546Spatrick ~StopInfoMachException() override = default; 39061da546Spatrick GetStopReason()40061da546Spatrick lldb::StopReason GetStopReason() const override { 41061da546Spatrick return lldb::eStopReasonException; 42061da546Spatrick } 43061da546Spatrick 44061da546Spatrick const char *GetDescription() override; 45061da546Spatrick 46*f6aab3d8Srobert #if defined(__APPLE__) 47*f6aab3d8Srobert struct MachException { 48*f6aab3d8Srobert static const char *Name(exception_type_t exc_type); 49*f6aab3d8Srobert static std::optional<exception_type_t> ExceptionCode(const char *name); 50*f6aab3d8Srobert }; 51*f6aab3d8Srobert #endif 52*f6aab3d8Srobert 53061da546Spatrick // Since some mach exceptions will be reported as breakpoints, signals, 54061da546Spatrick // or trace, we use this static accessor which will translate the mach 55061da546Spatrick // exception into the correct StopInfo. 56061da546Spatrick static lldb::StopInfoSP CreateStopReasonWithMachException( 57061da546Spatrick Thread &thread, uint32_t exc_type, uint32_t exc_data_count, 58061da546Spatrick uint64_t exc_code, uint64_t exc_sub_code, uint64_t exc_sub_sub_code, 59061da546Spatrick bool pc_already_adjusted = true, bool adjust_pc_if_needed = false); 60061da546Spatrick 61061da546Spatrick protected: 62061da546Spatrick uint32_t m_exc_data_count; 63061da546Spatrick uint64_t m_exc_code; 64061da546Spatrick uint64_t m_exc_subcode; 65061da546Spatrick }; 66061da546Spatrick 67061da546Spatrick } // namespace lldb_private 68061da546Spatrick 69dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H 70