Back to index

glibc  2.9
Defines | Functions
backtracesyms.c File Reference
#include <execinfo.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define WORD_WIDTH   16

Functions

char ** __backtrace_symbols (void *const *array, int size)

Define Documentation

#define WORD_WIDTH   16

Definition at line 27 of file backtracesyms.c.


Function Documentation

char** __backtrace_symbols ( void *const array,
int  size 
)

Definition at line 31 of file backtracesyms.c.

{
  int cnt;
  size_t total = 0;
  char **result;

  /* We can compute the text size needed for the symbols since we print
     them all as "[+0x<addr>]".  */
  total = size * (WORD_WIDTH + 6);

  /* Allocate memory for the result.  */
  result = malloc (size * sizeof (char *) + total);
  if (result != NULL)
    {
      char *last = (char *) (result + size);

      for (cnt = 0; cnt < size; ++cnt)
       {
         result[cnt] = last;
         last += 1 + sprintf (last, "[+%p]", array[cnt]);
       }
    }

  return result;
}