Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "libts.h"
00025 #include "ink_stack_trace.h"
00026
00027 #include <strings.h>
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <unistd.h>
00031
00032 #ifndef STDERR_FILENO
00033 #define STDERR_FILENO 2
00034 #endif
00035
00036 #if TS_HAS_BACKTRACE
00037
00038 #include <execinfo.h>
00039 #include <signal.h>
00040
00041 void
00042 ink_stack_trace_dump()
00043 {
00044 int btl;
00045
00046
00047 const char *msg = " - STACK TRACE: \n";
00048 if (write(STDERR_FILENO, program_name, strlen(program_name)) == -1)
00049 return;
00050 if (write(STDERR_FILENO, msg, strlen(msg)) == -1)
00051 return;
00052
00053
00054
00055
00056 alarm(10);
00057
00058 void *stack[INK_STACK_TRACE_MAX_LEVELS + 1];
00059 memset(stack, 0, sizeof(stack));
00060 if ((btl = backtrace(stack, INK_STACK_TRACE_MAX_LEVELS)) > 2) {
00061
00062 backtrace_symbols_fd(stack + 2, btl - 2, STDERR_FILENO);
00063 }
00064 }
00065
00066 #else
00067
00068 void
00069 ink_stack_trace_dump()
00070 {
00071 const char msg[] = "ink_stack_trace_dump not implemented on this operating system\n";
00072 if (write(STDERR_FILENO, msg, sizeof(msg) - 1) == -1)
00073 return;
00074 }
00075
00076 #endif