]> sourceware.org Git - glibc.git/commitdiff
Example for backtrace() functions.
authorUlrich Drepper <drepper@redhat.com>
Wed, 17 Jan 2001 16:51:27 +0000 (16:51 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 17 Jan 2001 16:51:27 +0000 (16:51 +0000)
manual/examples/execinfo.c [new file with mode: 0644]

diff --git a/manual/examples/execinfo.c b/manual/examples/execinfo.c
new file mode 100644 (file)
index 0000000..5a04901
--- /dev/null
@@ -0,0 +1,37 @@
+#include <execinfo.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Obtain a backtrace and print it to @code{stdout}. */
+void
+print_trace (void)
+{
+  void *array[10];
+  size_t size;
+  char **strings;
+  size_t i;
+
+  size = backtrace (array, 10);
+  strings = backtrace_symbols (array, size);
+
+  printf ("Obtained %zd stack frames.\n", size);
+
+  for (i = 0; i < size; i++)
+     printf ("%s\n", strings[i]);
+
+  free (strings);
+}
+
+/* A dummy function to make the backtrace more interesting. */
+void
+dummy_function (void)
+{
+  print_trace ();
+}
+
+int
+main (void)
+{
+  dummy_function ();
+  return 0;
+}
This page took 0.043315 seconds and 5 git commands to generate.