Skip to content

Commit 88175e6

Browse files
committed
[lldb][NFC] Extract StopInfoMachException::GetTagFaultAddress() helper function
1 parent 36655fc commit 88175e6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,26 @@ static void DescribeAddressBriefly(Stream &strm, const Address &addr,
7777
strm.Printf(".\n");
7878
}
7979

80+
std::optional<addr_t> StopInfoMachException::GetTagFaultAddress() const {
81+
bool bad_access = (m_value == 1); // EXC_BAD_ACCESS
82+
bool tag_fault = (m_exc_code == 0x106); // EXC_ARM_MTE_TAG_FAULT
83+
bool has_fault_addr = (m_exc_data_count >= 2); // m_exc_subcode -> fault addr
84+
85+
if (bad_access && tag_fault && has_fault_addr)
86+
return m_exc_subcode; // Fault address
87+
88+
return std::nullopt;
89+
}
90+
8091
static constexpr uint8_t g_mte_tag_shift = 64 - 8;
8192
static constexpr addr_t g_mte_tag_mask = (addr_t)0x0f << g_mte_tag_shift;
8293

83-
bool StopInfoMachException::DetermineTagMismatch(ExecutionContext &exe_ctx) {
84-
const bool IsBadAccess = m_value == 1; // EXC_BAD_ACCESS
85-
const bool IsMTETagFault = (m_exc_code == 0x106); // EXC_ARM_MTE_TAG_FAULT
86-
if (!IsBadAccess || !IsMTETagFault)
87-
return false;
88-
89-
if (m_exc_data_count < 2)
94+
bool StopInfoMachException::DetermineTagMismatch() {
95+
auto fault_address = GetTagFaultAddress();
96+
if (!fault_address)
9097
return false;
9198

92-
const uint64_t bad_address = m_exc_subcode;
99+
const uint64_t bad_address = *fault_address;
93100

94101
StreamString strm;
95102
strm.Printf("EXC_ARM_MTE_TAG_FAULT (code=%" PRIu64 ", address=0x%" PRIx64
@@ -295,7 +302,7 @@ const char *StopInfoMachException::GetDescription() {
295302
case llvm::Triple::aarch64:
296303
if (DeterminePtrauthFailure(exe_ctx))
297304
return m_description.c_str();
298-
if (DetermineTagMismatch(exe_ctx))
305+
if (DetermineTagMismatch())
299306
return m_description.c_str();
300307
break;
301308

lldb/source/Plugins/Process/Utility/StopInfoMachException.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StopInfoMachException : public StopInfo {
2727
/// is auth-related failure, and returns false otherwise.
2828
bool DeterminePtrauthFailure(ExecutionContext &exe_ctx);
2929

30-
bool DetermineTagMismatch(ExecutionContext &exe_ctx);
30+
bool DetermineTagMismatch();
3131

3232
public:
3333
// Constructors and Destructors
@@ -48,6 +48,9 @@ class StopInfoMachException : public StopInfo {
4848

4949
const char *GetDescription() override;
5050

51+
// Returns the fault address, iff this is a EXC_ARM_MTE_TAG_FAULT.
52+
std::optional<lldb::addr_t> GetTagFaultAddress() const;
53+
5154
#if defined(__APPLE__)
5255
struct MachException {
5356
static const char *Name(exception_type_t exc_type);

0 commit comments

Comments
 (0)