source: branches/libc-0.6/src/libctests/glibc/debug/backtrace-tst.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 868 bytes
Line 
1#include <execinfo.h>
2#include <inttypes.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6
7static int
8compare (const void *p1, const void *p2)
9{
10 void *ba[20];
11 int n = backtrace (ba, sizeof (ba) / sizeof (ba[0]));
12 if (n != 0)
13 {
14 char **names = backtrace_symbols (ba, n);
15 if (names != NULL)
16 {
17 int i;
18 printf ("called from %s\n", names[0]);
19 for (i = 1; i < n; ++i)
20 printf (" %s\n", names[i]);
21 free (names);
22 }
23 }
24
25 return *(const uint32_t *) p1 - *(const uint32_t *) p2;
26}
27
28
29int
30main (int argc, char *argv[])
31{
32 uint32_t arr[20];
33 size_t cnt;
34
35 for (cnt = 0; cnt < sizeof (arr) / sizeof (arr[0]); ++cnt)
36 arr[cnt] = random ();
37
38 qsort (arr, sizeof (arr) / sizeof (arr[0]), sizeof (arr[0]), compare);
39
40 for (cnt = 0; cnt < sizeof (arr) / sizeof (arr[0]); ++cnt)
41 printf ("%" PRIx32 "\n", arr[cnt]);
42
43 return 0;
44}
Note: See TracBrowser for help on using the repository browser.