diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-01-17 16:51:27 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-01-17 16:51:27 +0000 |
commit | 17abb551cedc46690e13e73d43100e68b631c02f (patch) | |
tree | c466b52d9404bb8add3e350bd4bc266d8b9d3bc8 | |
parent | ee4905312f537da28f21aaecb69eda9309125e92 (diff) | |
download | glibc-17abb551cedc46690e13e73d43100e68b631c02f.tar.gz glibc-17abb551cedc46690e13e73d43100e68b631c02f.tar.xz glibc-17abb551cedc46690e13e73d43100e68b631c02f.zip |
Example for backtrace() functions.
-rw-r--r-- | manual/examples/execinfo.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/manual/examples/execinfo.c b/manual/examples/execinfo.c new file mode 100644 index 0000000000..5a04901957 --- /dev/null +++ b/manual/examples/execinfo.c @@ -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; +} |