OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [sysdep/] [dwarf2-backtrace.cc] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* dwarf2-backtrac.cc - backtrace implementation driven by the dwarf2
2
 exception unwinder.  */
3
 
4
/* Copyright (C) 2003  Free Software Foundation
5
 
6
   This file is part of libgcj.
7
 
8
This software is copyrighted work licensed under the terms of the
9
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
10
details.  */
11
 
12
/* Written by David Daney <ddaney@avtrex.com> */
13
 
14
/*
15
  Although this in theory could be 'C' instead of C++, saying that it
16
  is C++ and including jvm.h makes it easier to insure that the proper
17
  compiler options are used.  There must be unwind tables for
18
  backtrace because it is on the stack when _Unwind_Backtrace is
19
  called.  Compiling as C++ insures this.
20
 
21
*/
22
 
23
#include <config.h>
24
 
25
#include <unwind.h>
26
 
27
#include <jvm.h>
28
 
29
 
30
extern "C"
31
{
32
  int backtrace (void **, int);
33
}
34
 
35
struct backtrace_state
36
{
37
  int skip_count;
38
  int current_level;
39
  int max_level;
40
  void **locations;
41
};
42
 
43
static _Unwind_Reason_Code
44
my_trace_fn (struct _Unwind_Context *uc, void *arg)
45
{
46
 
47
  struct backtrace_state *bs = (struct backtrace_state *) arg;
48
 
49
  if (bs->skip_count)
50
    {
51
      bs->skip_count--;
52
      return _URC_NO_REASON;
53
    }
54
 
55
  _Unwind_Ptr loc = _Unwind_GetIP (uc);
56
 
57
  if (bs->current_level < bs->max_level)
58
    bs->locations[bs->current_level++] = (void *) loc;
59
 
60
  if (bs->current_level >= bs->max_level)
61
    return _URC_END_OF_STACK;
62
  else
63
    return _URC_NO_REASON;
64
}
65
 
66
/*
67
 * backtrace is defined in (some versions of) libc.  This definition
68
 * must match so that it can replace the libc version at link time.
69
 *
70
 * Fill the locations array with at most len back trace locations.
71
 *
72
 * Returns the number of locations actually filled in.
73
 *
74
 */
75
int
76
backtrace (void **locations, int len)
77
{
78
  struct backtrace_state bs;
79
  bs.skip_count = 1;            /* Don't log the call to backtrace itself. */
80
  bs.current_level = 0;
81
  bs.max_level = len;
82
  bs.locations = locations;
83
 
84
  _Unwind_Backtrace (my_trace_fn, &bs);
85
  return bs.current_level;
86
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.