Back to index

glibc  2.9
Classes | Defines | Functions | Variables
backtrace.c File Reference
#include <bits/libc-lock.h>
#include <dlfcn.h>
#include <execinfo.h>
#include <stddef.h>
#include <stdlib.h>
#include <unwind.h>

Go to the source code of this file.


struct  layout
struct  trace_arg


#define unwind_backtrace   _Unwind_Backtrace
#define unwind_getip   _Unwind_GetIP


static int __backchain_backtrace (void **array, int size)
static _Unwind_Reason_Code backtrace_helper (struct _Unwind_Context *ctx, void *a)
int __backtrace (void **array, int size)


void * __libc_stack_end

Class Documentation

struct layout

Definition at line 21 of file frame.h.

Collaboration diagram for layout:
Class Members
int back_chain
long back_chain
long condition_register
struct layout * ebp
long empty
int empty
long end_of_stack
int end_of_stack
int glue
unsigned long ins
unsigned long locals
void *__unbounded next
struct layout *__unbounded next
void * next
unsigned long next
void * ret
void *__unbounded return_address
void * return_address
long save_fp
int save_fp
long save_grps
int save_grps
long scratch
int scratch
void *__unbounded sp
struct trace_arg

Definition at line 27 of file backtrace.c.

Class Members
void ** array
int cnt
void * lastebp
void * lastesp
int size

Define Documentation

Definition at line 82 of file backtrace.c.

Definition at line 83 of file backtrace.c.

Function Documentation

static int __backchain_backtrace ( void **  array,
int  size 
) [static]

Definition at line 87 of file backtrace.c.

  /* We assume that all the code is generated with frame pointers set.  */
  struct layout *stack;
  int cnt = 0;

  asm ("LR  %0,%%r15" : "=d" (stack) );
  /* We skip the call to this function, it makes no sense to record it.  */
  stack = (struct layout *) stack->back_chain;
  while (cnt < size)
      if (stack == NULL || (void *) stack > __libc_stack_end)
       /* This means the address is out of range.  Note that for the
          toplevel we see a frame pointer with value NULL which clearly is
          out of range.  */

      array[cnt++] = (void *) (stack->save_grps[8] & 0x7fffffff);

      stack = (struct layout *) stack->back_chain;

  return cnt;

Here is the caller graph for this function:

int __backtrace ( void **  array,
int  size 

Definition at line 127 of file backtrace.c.

  struct trace_arg arg = { .array = array, .size = size, .cnt = -1 };
#ifdef SHARED
  __libc_once_define (static, once);

  __libc_once (once, init);
  if (unwind_backtrace == NULL)
    return __backchain_backtrace (array, size);

  if (size >= 1)
    unwind_backtrace (backtrace_helper, &arg);

  return arg.cnt != -1 ? arg.cnt : 0;

Here is the call graph for this function:

static _Unwind_Reason_Code backtrace_helper ( struct _Unwind_Context ctx,
void *  a 
) [static]

Definition at line 113 of file backtrace.c.

  struct trace_arg *arg = a;

  /* We are first called with address in the __backtrace function.
     Skip it.  */
  if (arg->cnt != -1)
    arg->array[arg->cnt] = (void *) unwind_getip (ctx);
  if (++arg->cnt == arg->size)
    return _URC_END_OF_STACK;
  return _URC_NO_REASON;

Here is the caller graph for this function:

Variable Documentation

Definition at line 38 of file libc-start.c.