This source file includes following definitions.
- opal_backtrace_print
- opal_backtrace_buffer
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 #include "opal_config.h"
  22 
  23 #include <stdio.h>
  24 #include <string.h>
  25 #ifdef HAVE_UNISTD_H
  26 #include <unistd.h>
  27 #endif
  28 #ifdef HAVE_EXECINFO_H
  29 #include <execinfo.h>
  30 #endif
  31 
  32 #include "opal/constants.h"
  33 #include "opal/mca/backtrace/backtrace.h"
  34 
  35 int
  36 opal_backtrace_print(FILE *file, char *prefix, int strip)
  37 {
  38     int i, len;
  39     int trace_size;
  40     void * trace[32];
  41     char buf[6];
  42     int fd = opal_stacktrace_output_fileno;
  43 
  44     if( NULL != file ) {
  45         fd = fileno(file);
  46     }
  47 
  48     if (-1 == fd) {
  49         return OPAL_ERR_BAD_PARAM;
  50     }
  51 
  52     trace_size = backtrace (trace, 32);
  53 
  54     for (i = strip; i < trace_size; i++) {
  55         if (NULL != prefix) {
  56             write (fd, prefix, strlen (prefix));
  57         }
  58         len = snprintf (buf, sizeof(buf), "[%2d] ", i - strip);
  59         write (fd, buf, len);
  60         backtrace_symbols_fd (&trace[i], 1, fd);
  61     }
  62 
  63     return OPAL_SUCCESS;
  64 }
  65 
  66 
  67 int
  68 opal_backtrace_buffer(char ***message_out, int *len_out)
  69 {
  70     int trace_size;
  71     void * trace[32];
  72     char ** funcs = (char **)NULL;
  73 
  74     trace_size = backtrace (trace, 32);
  75     funcs = backtrace_symbols (trace, trace_size);
  76 
  77     *message_out = funcs;
  78     *len_out = trace_size;
  79 
  80     return OPAL_SUCCESS;
  81 }