1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*-
* Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <sys/param.h>
#include <sys/wait.h>
#include <execinfo.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#define BT_FUNCTIONS 10
void handler(int);
__noinline void
handler(int signum __unused)
{
void *addresses[BT_FUNCTIONS];
char **symbols;
size_t n, i, match;
n = backtrace(addresses, nitems(addresses));
ATF_REQUIRE(n > 1);
symbols = backtrace_symbols(addresses, n);
ATF_REQUIRE(symbols != NULL);
match = -1;
for (i = 0; i < n; i++) {
printf("%zu: %p, %s\n", i, addresses[i], symbols[i]);
if (strstr(symbols[i], "<main+") != NULL)
match = i;
}
ATF_REQUIRE(match > 0);
printf("match at %zu, symbols %zu\n", match, n);
}
ATF_TC_WITHOUT_HEAD(test_backtrace_sigtramp);
ATF_TC_BODY(test_backtrace_sigtramp, tc)
{
struct sigaction act;
pid_t child;
int status;
memset(&act, 0, sizeof(act));
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
sigaction(SIGUSR1, &act, NULL);
child = fork();
ATF_REQUIRE(child != -1);
if (child == 0) {
kill(getppid(), SIGUSR1);
_exit(0);
} else
wait(&status);
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, test_backtrace_sigtramp);
return (atf_no_error());
}
|