]> git.ipfire.org Git - thirdparty/glibc.git/blame - debug/backtrace-tst.c
time/tst-strftime2.c: Make the file easier to maintain
[thirdparty/glibc.git] / debug / backtrace-tst.c
CommitLineData
2de7874e
UD
1#include <execinfo.h>
2#include <inttypes.h>
3#include <stdio.h>
4#include <stdlib.h>
e054f494 5#include <stdint.h>
2de7874e
UD
6
7
8static int
9compare (const void *p1, const void *p2)
10{
11 void *ba[20];
12 int n = backtrace (ba, sizeof (ba) / sizeof (ba[0]));
13 if (n != 0)
14 {
15 char **names = backtrace_symbols (ba, n);
16 if (names != NULL)
17 {
18 int i;
19 printf ("called from %s\n", names[0]);
20 for (i = 1; i < n; ++i)
21 printf (" %s\n", names[i]);
22 free (names);
23 }
24 }
25
2a068d20 26 return *(const uint32_t *) p1 - *(const uint32_t *) p2;
2de7874e
UD
27}
28
29
30int
31main (int argc, char *argv[])
32{
33 uint32_t arr[20];
34 size_t cnt;
35
36 for (cnt = 0; cnt < sizeof (arr) / sizeof (arr[0]); ++cnt)
37 arr[cnt] = random ();
38
39 qsort (arr, sizeof (arr) / sizeof (arr[0]), sizeof (arr[0]), compare);
40
41 for (cnt = 0; cnt < sizeof (arr) / sizeof (arr[0]); ++cnt)
42 printf ("%" PRIx32 "\n", arr[cnt]);
43
44 return 0;
45}