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
34
35public:
36 // Constructors and Destructors
37 StopInfoMachException(Thread &thread, uint32_t exc_type,
38 uint32_t exc_data_count, uint64_t exc_code,
39 uint64_t exc_subcode,
40 bool not_stepping_but_got_singlestep_exception)
41 : StopInfo(thread, exc_type), m_exc_data_count(exc_data_count),
42 m_exc_code(exc_code), m_exc_subcode(exc_subcode),
44 not_stepping_but_got_singlestep_exception) {}
45
46 ~StopInfoMachException() override = default;
47
50 }
51
52 const char *GetDescription() override;
53
54 uint32_t GetStopReasonDataCount() const override {
55 // We return the Exception Type as the first element, then the code and
56 // subcode. But we don't store any further exception data, so we can't
57 // return more than these three elements regardless of the data count.
58 // Not many exceptions we deal with have more than code & subcode, however
59 // so fixing that isn't urgent.
60 return std::min((uint32_t)3, m_exc_data_count + 1);
61 }
62
63 uint64_t GetStopReasonDataAtIndex(uint32_t idx) override {
64 // FIXME: We really should return all the exception data, but for now we
65 // just cheese out and return only the exception type.
66 if (idx >= GetStopReasonDataCount())
67 return 0;
68
69 switch (idx) {
70 case 0:
71 return GetValue();
72 case 1:
73 return m_exc_code;
74 case 2:
75 return m_exc_subcode;
76 default:
77 return 0;
78 }
79 }
80
81 // Returns the fault address, iff this is a EXC_ARM_MTE_TAG_FAULT.
82 std::optional<lldb::addr_t> GetTagFaultAddress() const;
83
84#if defined(__APPLE__)
85 struct MachException {
86 static const char *Name(exception_type_t exc_type);
87 static std::optional<exception_type_t> ExceptionCode(const char *name);
88 };
89#endif
90
91 /// Allow this plugin to respond to stop events to enable skip-over-trap
92 /// behaviour on AArch64.
93 void PerformAction(Event *event_ptr) override;
94
95 // Since some mach exceptions will be reported as breakpoints, signals,
96 // or trace, we use this static accessor which will translate the mach
97 // exception into the correct StopInfo.
99 Thread &thread, uint32_t exc_type, uint32_t exc_data_count,
100 uint64_t exc_code, uint64_t exc_sub_code, uint64_t exc_sub_sub_code,
101 bool pc_already_adjusted = true, bool adjust_pc_if_needed = false);
102
103 bool WasContinueInterrupted(Thread &thread) override;
104
105protected:
107 uint64_t m_exc_code;
109
111};
112
113} // namespace lldb_private
114
115#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_STOPINFOMACHEXCEPTION_H
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
uint32_t GetStopReasonDataCount() const override
void PerformAction(Event *event_ptr) override
Allow this plugin to respond to stop events to enable skip-over-trap behaviour on AArch64.
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:251
StopInfo(Thread &thread, uint64_t value)
Definition StopInfo.cpp:37
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
StopReason
Thread stop reasons.
@ eStopReasonException