Include atomic.h in generic lowlevellock.c.
[glibc.git] / debug / tst-backtrace3.c
blob182f423925c0b1a55da6702bef0bfe25ec1b4e0f
1 /* Test backtrace and backtrace_symbols for recursive calls.
2 Copyright (C) 2010-2013 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
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <execinfo.h>
20 #include <search.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "tst-backtrace.h"
27 static int do_test (void);
28 #define TEST_FUNCTION do_test ()
29 #include "../test-skeleton.c"
31 /* The backtrace should include at least 3 * fn, and do_test. */
32 #define NUM_FUNCTIONS 4
34 NO_INLINE int
35 fn (int c)
37 void *addresses[NUM_FUNCTIONS];
38 char **symbols;
39 int n;
40 int i;
42 if (c > 0)
44 fn (c - 1);
45 return x;
47 /* Get the backtrace addresses. */
48 n = backtrace (addresses, sizeof (addresses) / sizeof (addresses[0]));
49 printf ("Obtained backtrace with %d functions\n", n);
50 /* Check that there are at least four functions. */
51 if (n < NUM_FUNCTIONS)
53 FAIL ();
54 return 1;
56 /* Convert them to symbols. */
57 symbols = backtrace_symbols (addresses, n);
58 /* Check that symbols were obtained. */
59 if (symbols == NULL)
61 FAIL ();
62 return 1;
64 for (i = 0; i < n; ++i)
65 printf ("Function %d: %s\n", i, symbols[i]);
66 /* Check that the function names obtained are accurate. */
67 for (i = 0; i < n - 1; ++i)
68 if (!match (symbols[i], "fn"))
70 FAIL ();
71 return 1;
73 /* Symbol names are not available for static functions, so we do not
74 check do_test. */
75 return x;
78 NO_INLINE static int
79 do_test (void)
81 fn (2);
82 return ret;