mips: FIx clone3 implementation (BZ 31325)
[glibc.git] / sysdeps / unix / sysv / linux / tst-sigcontext-get_pc.c
blobea375f97d9f5ca619f990e5cd4ca2ba747a69d69
1 /* Test that the GET_PC macro is consistent with the unwinder.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, see <https://www.gnu.org/licenses/>. */
19 /* This test searches for the value of the GET_PC macro in the
20 addresses obtained from the backtrace function. */
22 #include <array_length.h>
23 #include <execinfo.h>
24 #include <inttypes.h>
25 #include <signal.h>
26 #include <stdbool.h>
27 #include <stdio.h>
28 #include <support/check.h>
29 #include <support/xsignal.h>
30 #include <sigcontextinfo.h>
32 static bool handler_called;
34 static void
35 handler (int signal, siginfo_t *info, void *ctx)
37 TEST_COMPARE (signal, SIGUSR1);
39 uintptr_t pc = sigcontext_get_pc (ctx);
40 printf ("info: address in signal handler: 0x%" PRIxPTR "\n", pc);
42 void *callstack[10];
43 int callstack_count = backtrace (callstack, array_length (callstack));
44 TEST_VERIFY_EXIT (callstack_count > 0);
45 TEST_VERIFY_EXIT (callstack_count <= array_length (callstack));
46 bool found = false;
47 for (int i = 0; i < callstack_count; ++i)
49 const char *marker;
50 if ((uintptr_t) callstack[i] == pc)
52 found = true;
53 marker = " *";
55 else
56 marker = "";
57 printf ("info: call stack entry %d: 0x%" PRIxPTR "%s\n",
58 i, (uintptr_t) callstack[i], marker);
60 TEST_VERIFY (found);
61 handler_called = true;
64 static int
65 do_test (void)
67 struct sigaction sa =
69 .sa_sigaction = &handler,
70 .sa_flags = SA_SIGINFO
72 xsigaction (SIGUSR1, &sa, NULL);
73 raise (SIGUSR1);
74 TEST_VERIFY (handler_called);
75 return 0;
78 #include <support/test-driver.c>