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 <stdlib.h>
#include <unwind.h>

Go to the source code of this file.

Classes

struct  trace_arg
struct  layout

Defines

#define unwind_backtrace   _Unwind_Backtrace
#define unwind_getip   _Unwind_GetIP
#define unwind_getcfa   _Unwind_GetCFA
#define unwind_getgr   _Unwind_GetGR

Functions

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

Variables

void * __libc_stack_end

Class Documentation

struct trace_arg

Definition at line 27 of file backtrace.c.

Class Members
void ** array
int cnt
void * lastebp
void * lastesp
int size
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

Define Documentation

Definition at line 61 of file backtrace.c.

Definition at line 63 of file backtrace.c.

Definition at line 64 of file backtrace.c.

Definition at line 62 of file backtrace.c.


Function Documentation

int __backtrace ( void **  array,
int  size 
)

Definition at line 113 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 0;
#endif

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

  if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL)
    --arg.cnt;
  else if (arg.cnt < size)
    {
      struct layout *ebp = (struct layout *) arg.lastebp;

      while (arg.cnt < size)
       {
         /* Check for out of range.  */
         if ((void *) ebp < arg.lastesp || (void *) ebp > __libc_stack_end
             || ((long) ebp & 3))
           break;

         array[arg.cnt++] = ebp->ret;
         ebp = ebp->ebp;
       }
    }
  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 68 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;

  /* %ebp is DWARF2 register 5 on IA-32.  */
  arg->lastebp = (void *) unwind_getgr (ctx, 5);
  arg->lastesp = (void *) unwind_getcfa (ctx);
  return _URC_NO_REASON;
}

Here is the caller graph for this function:


Variable Documentation

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