Skip to content

Commit 3019724

Browse files
committed
Experiment with custom_rr_abi.swift test.
1 parent 93653c7 commit 3019724

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

test/Runtime/Inputs/custom_rr_abi_utilities.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
#define NUM_REGS 30
1+
#include <execinfo.h>
2+
#include <signal.h>
3+
#include <unistd.h>
4+
#include <stdlib.h>
5+
#include <stdio.h>
26

3-
// Apply `macro` to "all" registers. Skip x18 since it's reserved, and x30 since
4-
// it's the link register.
7+
#define NUM_REGS 29
8+
9+
// Apply `macro` to "all" registers. Skip x18 since it's reserved, x29
10+
// since it's the frame pointer, and x30 since it's the link register.
511
#define ALL_REGS(macro) \
612
macro( 0) \
713
macro( 1) \
@@ -30,8 +36,7 @@
3036
macro(25) \
3137
macro(26) \
3238
macro(27) \
33-
macro(28) \
34-
macro(29)
39+
macro(28)
3540

3641
// Apply `macro` with the given parameters to all registers that have
3742
// specialized entrypoints. That's the same as ALL_REGS, minus x0 (the standard
@@ -109,3 +114,24 @@ static inline void foreachRRFunction(void (*call)(void (*)(void **regs),
109114

110115
ALL_FUNCTIONS(CALL_WITH_FUNCTIONS)
111116
}
117+
118+
static inline void signalHandler(int sig) {
119+
void* callstack[128];
120+
int frames = backtrace(callstack, 128);
121+
backtrace_symbols_fd(callstack, frames, 2);
122+
extern const char* dyld_image_path_containing_address(const void* addr);
123+
const char *progpath = dyld_image_path_containing_address(signalHandler);
124+
char *command;
125+
asprintf(&command, "/usr/bin/otool -tV '%s'", progpath);
126+
system(command);
127+
extern void *swift_retain_x10(void);
128+
const char *libpath = dyld_image_path_containing_address(swift_retain_x10);
129+
asprintf(&command, "/usr/bin/otool -tV -p _swift_retain_x10 '%s' | /usr/bin/head -n 100", libpath);
130+
system(command);
131+
_exit(1);
132+
}
133+
134+
static inline void installSignalHandlers(void) {
135+
signal(SIGSEGV, signalHandler);
136+
signal(SIGBUS, signalHandler);
137+
}

test/Runtime/custom_rr_abi.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// UNSUPPORTED: use_os_stdlib
77
// UNSUPPORTED: back_deployment_runtime
88

9-
// REQUIRES: rdar102912772
10-
119
import StdlibUnittest
1210

1311
// A class that can provider a retainable pointer and determine whether it's
@@ -54,9 +52,11 @@ class RetainReleaseChecker {
5452
var CustomRRABITestSuite = TestSuite("CustomRRABI")
5553

5654
CustomRRABITestSuite.test("retain") {
55+
installSignalHandlers()
5756
foreachRRFunction { function, cname, register, isRetain in
5857
let name = String(cString: cname!)
5958
let fullname = "\(name)_x\(register)"
59+
print("Testing \(fullname)")
6060

6161
// Create a set of RR checker objects.
6262
var checkers = (0..<NUM_REGS).map{ _ in RetainReleaseChecker() }
@@ -65,6 +65,7 @@ CustomRRABITestSuite.test("retain") {
6565
var regs: [UnsafeMutableRawPointer?] = checkers.map{ $0.pointerValue }
6666

6767
// Call the RR function.
68+
print(regs)
6869
function!(&regs)
6970

7071
// Make sure all the checkers report what they're supposed to. All registers

0 commit comments

Comments
 (0)