[Lldb-commits] [lldb] 484bc2b - Run cmdline address expressions through ABI's FixAddress
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Mon Jan 23 10:44:25 PST 2023
Author: Jason Molenda
Date: 2023-01-23T10:44:19-08:00
New Revision: 484bc2bcc7990f4ecaf40f3d806ed870cdbdfd95
URL: https://github.com/llvm/llvm-project/commit/484bc2bcc7990f4ecaf40f3d806ed870cdbdfd95
DIFF: https://github.com/llvm/llvm-project/commit/484bc2bcc7990f4ecaf40f3d806ed870cdbdfd95.diff
LOG: Run cmdline address expressions through ABI's FixAddress
On systems like ARM, where the non-addressable bits of a pointer
value may be used for metadata (ARMv8.3 pointer authentication, or
Type Byte Ignore), those bits need to be cleared before the address
points to a valid memory location. Add a call to the target's ABI
to clear those from address expression arguments to the lldb
commands (e.g. `disassemble -a`).
Differential Revision: https://reviews.llvm.org/D141629
Added:
lldb/test/API/macosx/ptrauth-address-expressions/Makefile
lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
lldb/test/API/macosx/ptrauth-address-expressions/main.c
Modified:
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/source/Interpreter/OptionArgParser.cpp
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index d0501ef6b9d10..97fe14e769cdd 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1243,6 +1243,8 @@ def isAArch64MTE(self):
return self.isAArch64() and "mte" in self.getCPUInfo()
def isAArch64PAuth(self):
+ if self.getArchitecture() == "arm64e":
+ return True
return self.isAArch64() and "paca" in self.getCPUInfo()
def getArchitecture(self):
diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp
index 93b01abde4bb9..63ca0f9d3d4d9 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -8,6 +8,7 @@
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/DataFormatters/FormatManager.h"
+#include "lldb/Target/ABI.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
@@ -157,6 +158,10 @@ lldb::addr_t OptionArgParser::ToAddress(const ExecutionContext *exe_ctx,
if (!s.getAsInteger(0, addr)) {
if (error_ptr)
error_ptr->Clear();
+ Process *process = exe_ctx->GetProcessPtr();
+ if (process)
+ if (ABISP abi_sp = process->GetABI())
+ addr = abi_sp->FixCodeAddress(addr);
return addr;
}
diff --git a/lldb/test/API/macosx/ptrauth-address-expressions/Makefile b/lldb/test/API/macosx/ptrauth-address-expressions/Makefile
new file mode 100644
index 0000000000000..10495940055b6
--- /dev/null
+++ b/lldb/test/API/macosx/ptrauth-address-expressions/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py b/lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
new file mode 100644
index 0000000000000..3d21c20601cef
--- /dev/null
+++ b/lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
@@ -0,0 +1,28 @@
+"""Test that AArch64 PAC bits are stripped from address expression arguments"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestPtrauthAddressExpressions(TestBase):
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ # On Darwin systems, arch arm64e means ARMv8.3 with ptrauth
+ # ABI used.
+ @skipIf(archs=no_match(['arm64e']))
+
+ def test(self):
+
+ # Skip this test if not running on AArch64 target that supports PAC
+ if not self.isAArch64PAuth():
+ self.skipTest('Target must support pointer authentication.')
+ self.source = 'main.c'
+ self.build()
+ (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+ "break here", lldb.SBFileSpec(self.source, False))
+
+ self.expect("p fptr", substrs=[self.source])
+ self.expect("ima loo -va fptr", substrs=[self.source])
+ self.expect("break set -a fptr", substrs=[self.source])
diff --git a/lldb/test/API/macosx/ptrauth-address-expressions/main.c b/lldb/test/API/macosx/ptrauth-address-expressions/main.c
new file mode 100644
index 0000000000000..388de7f4b16e8
--- /dev/null
+++ b/lldb/test/API/macosx/ptrauth-address-expressions/main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int foo () { return 10; }
+
+int main ()
+{
+ int (*fptr)() = foo;
+ printf ("%p\n", fptr); // break here
+ return fptr();
+}
More information about the lldb-commits
mailing list