LLDB mainline
StopInfoMachException.h
Go to the documentation of this file.
1//===-- StopInfoMachException.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H
11
12#include <algorithm>
13#include <optional>
14#include <string>
15
17
18#if defined(__APPLE__)
19// Needed for the EXC_* defines
20#include <mach/exception.h>
21#endif
22
23namespace lldb_private {
24
26 /// Determine the pointer-authentication related failure that caused this
27 /// exception. Returns true and fills out the failure description if there
28 /// is auth-related failure, and returns false otherwise.
30
32
33public:
34 // Constructors and Destructors
35 StopInfoMachException(Thread &thread, uint32_t exc_type,
36 uint32_t exc_data_count, uint64_t exc_code,
37 uint64_t exc_subcode,
38 bool not_stepping_but_got_singlestep_exception)
39 : StopInfo(thread, exc_type), m_exc_data_count(exc_data_count),
40 m_exc_code(exc_code), m_exc_subcode(exc_subcode),
42 not_stepping_but_got_singlestep_exception) {}
43
44 ~StopInfoMachException() override = default;
45
48 }
49
50 const char *GetDescription() override;
51
52 uint32_t GetStopReasonDataCount() const override {
53 // We return the Exception Type as the first element, then the code and
54 // subcode. But we don't store any further exception data, so we can't
55 // return more than these three elements regardless of the data count.
56 // Not many exceptions we deal with have more than code & subcode, however
57 // so fixing that isn't urgent.
58 return std::min((uint32_t)3, m_exc_data_count + 1);
59 }
60
61 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
62 // FIXME: We really should return all the exception data, but for now we
63 // just cheese out and return only the exception type.
64 if (idx >= GetStopReasonDataCount())
65 return 0;
66
67 switch (idx) {
68 case 0:
69 return GetValue();
70 case 1:
71 return m_exc_code;
72 case 2:
73 return m_exc_subcode;
74 default:
75 return 0;
76 }
77 }
78
79 // Returns the fault address, iff this is a EXC_ARM_MTE_TAG_FAULT.
80 std::optional<lldb::addr_t> GetTagFaultAddress() const;
81
82#if defined(__APPLE__)
83 struct MachException {
84 static const char *Name(exception_type_t exc_type);
85 static std::optional<exception_type_t> ExceptionCode(const char *name);
86 };
87#endif
88
89 // Since some mach exceptions will be reported as breakpoints, signals,
90 // or trace, we use this static accessor which will translate the mach
91 // exception into the correct StopInfo.
93 Thread &thread, uint32_t exc_type, uint32_t exc_data_count,
94 uint64_t exc_code, uint64_t exc_sub_code, uint64_t exc_sub_sub_code,
95 bool pc_already_adjusted = true, bool adjust_pc_if_needed = false);
96
97 bool WasContinueInterrupted(Thread &thread) override;
98
99protected:
101 uint64_t m_exc_code;
103
105};
106
107} // namespace lldb_private
108
109#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
uint32_t GetStopReasonDataCount() const override
bool DeterminePtrauthFailure(ExecutionContext &exe_ctx)
Determine the pointer-authentication related failure that caused this exception.
bool WasContinueInterrupted(Thread &thread) override
A Continue operation can result in a false stop event before any execution has happened.
std::optional< lldb::addr_t > GetTagFaultAddress() const
lldb::StopReason GetStopReason() const override
uint64_t GetStopReasonDataAtIndex(uint32_t idx) override
static lldb::StopInfoSP CreateStopReasonWithMachException(Thread &thread, uint32_t exc_type, uint32_t exc_data_count, uint64_t exc_code, uint64_t exc_sub_code, uint64_t exc_sub_sub_code, bool pc_already_adjusted=true, bool adjust_pc_if_needed=false)
~StopInfoMachException() override=default
StopInfoMachException(Thread &thread, uint32_t exc_type, uint32_t exc_data_count, uint64_t exc_code, uint64_t exc_subcode, bool not_stepping_but_got_singlestep_exception)
uint64_t GetValue() const
Definition StopInfo.h:46
friend class Thread
Definition StopInfo.h:245
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:34
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
StopReason
Thread stop reasons.
@ eStopReasonException