annotate gcc/ada/tb-gcc.c @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /****************************************************************************
kono
parents:
diff changeset
2 * *
kono
parents:
diff changeset
3 * GNAT RUN-TIME COMPONENTS *
kono
parents:
diff changeset
4 * *
kono
parents:
diff changeset
5 * T R A C E B A C K - G C C t a b l e s *
kono
parents:
diff changeset
6 * *
kono
parents:
diff changeset
7 * C Implementation File *
kono
parents:
diff changeset
8 * *
kono
parents:
diff changeset
9 * Copyright (C) 2004-2012, Free Software Foundation, Inc. *
kono
parents:
diff changeset
10 * *
kono
parents:
diff changeset
11 * GNAT is free software; you can redistribute it and/or modify it under *
kono
parents:
diff changeset
12 * terms of the GNU General Public License as published by the Free Soft- *
kono
parents:
diff changeset
13 * ware Foundation; either version 3, or (at your option) any later ver- *
kono
parents:
diff changeset
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
kono
parents:
diff changeset
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
kono
parents:
diff changeset
16 * or FITNESS FOR A PARTICULAR PURPOSE. *
kono
parents:
diff changeset
17 * *
kono
parents:
diff changeset
18 * As a special exception under Section 7 of GPL version 3, you are granted *
kono
parents:
diff changeset
19 * additional permissions described in the GCC Runtime Library Exception, *
kono
parents:
diff changeset
20 * version 3.1, as published by the Free Software Foundation. *
kono
parents:
diff changeset
21 * *
kono
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License and *
kono
parents:
diff changeset
23 * a copy of the GCC Runtime Library Exception along with this program; *
kono
parents:
diff changeset
24 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
kono
parents:
diff changeset
25 * <http://www.gnu.org/licenses/>. *
kono
parents:
diff changeset
26 * *
kono
parents:
diff changeset
27 * GNAT was originally developed by the GNAT team at New York University. *
kono
parents:
diff changeset
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
kono
parents:
diff changeset
29 * *
kono
parents:
diff changeset
30 ****************************************************************************/
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 /* This is an implementation of the __gnat_backtrace routine using the
kono
parents:
diff changeset
33 underlying GCC unwinding support associated with the exception handling
kono
parents:
diff changeset
34 infrastructure. This will only work for ZCX based applications. */
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #include <unwind.h>
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* The implementation boils down to a call to _Unwind_Backtrace with a
kono
parents:
diff changeset
39 tailored callback and carried-on data structure to keep track of the
kono
parents:
diff changeset
40 input parameters we got as well as of the basic processing state. */
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 /******************
kono
parents:
diff changeset
43 * trace_callback *
kono
parents:
diff changeset
44 ******************/
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 #if !defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 typedef struct {
kono
parents:
diff changeset
49 void ** traceback;
kono
parents:
diff changeset
50 int max_len;
kono
parents:
diff changeset
51 void * exclude_min;
kono
parents:
diff changeset
52 void * exclude_max;
kono
parents:
diff changeset
53 int n_frames_to_skip;
kono
parents:
diff changeset
54 int n_frames_skipped;
kono
parents:
diff changeset
55 int n_entries_filled;
kono
parents:
diff changeset
56 } uw_data_t;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 #if defined (__ia64__) && defined (__hpux__)
kono
parents:
diff changeset
59 #include <uwx.h>
kono
parents:
diff changeset
60 #endif
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 static _Unwind_Reason_Code
kono
parents:
diff changeset
63 trace_callback (struct _Unwind_Context * uw_context, uw_data_t * uw_data)
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 char * pc;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 #if defined (__ia64__) && defined (__hpux__) && defined (USE_LIBUNWIND_EXCEPTIONS)
kono
parents:
diff changeset
68 /* Work around problem with _Unwind_GetIP on ia64 HP-UX. */
kono
parents:
diff changeset
69 uwx_get_reg ((struct uwx_env *) uw_context, UWX_REG_IP, (uint64_t *) &pc);
kono
parents:
diff changeset
70 #else
kono
parents:
diff changeset
71 pc = (char *) _Unwind_GetIP (uw_context);
kono
parents:
diff changeset
72 #endif
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 if (uw_data->n_frames_skipped < uw_data->n_frames_to_skip)
kono
parents:
diff changeset
75 {
kono
parents:
diff changeset
76 uw_data->n_frames_skipped ++;
kono
parents:
diff changeset
77 return _URC_NO_REASON;
kono
parents:
diff changeset
78 }
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 if (uw_data->n_entries_filled >= uw_data->max_len)
kono
parents:
diff changeset
81 return _URC_NORMAL_STOP;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 if (pc < (char *)uw_data->exclude_min || pc > (char *)uw_data->exclude_max)
kono
parents:
diff changeset
84 uw_data->traceback [uw_data->n_entries_filled ++] = pc + PC_ADJUST;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 return _URC_NO_REASON;
kono
parents:
diff changeset
87 }
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 #endif
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /********************
kono
parents:
diff changeset
92 * __gnat_backtrace *
kono
parents:
diff changeset
93 ********************/
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 int
kono
parents:
diff changeset
96 __gnat_backtrace (void ** traceback __attribute__((unused)),
kono
parents:
diff changeset
97 int max_len __attribute__((unused)),
kono
parents:
diff changeset
98 void * exclude_min __attribute__((unused)),
kono
parents:
diff changeset
99 void * exclude_max __attribute__((unused)),
kono
parents:
diff changeset
100 int skip_frames __attribute__((unused)))
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 #if defined (__USING_SJLJ_EXCEPTIONS__)
kono
parents:
diff changeset
103 /* We have no unwind material (tables) at hand with sjlj eh, and no
kono
parents:
diff changeset
104 way to retrieve complete and accurate call chain information from
kono
parents:
diff changeset
105 the context stack we maintain. */
kono
parents:
diff changeset
106 return 0;
kono
parents:
diff changeset
107 #else
kono
parents:
diff changeset
108 uw_data_t uw_data;
kono
parents:
diff changeset
109 /* State carried over during the whole unwinding process. */
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 uw_data.traceback = traceback;
kono
parents:
diff changeset
112 uw_data.max_len = max_len;
kono
parents:
diff changeset
113 uw_data.exclude_min = exclude_min;
kono
parents:
diff changeset
114 uw_data.exclude_max = exclude_max;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 uw_data.n_frames_to_skip = skip_frames;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 uw_data.n_frames_skipped = 0;
kono
parents:
diff changeset
119 uw_data.n_entries_filled = 0;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 _Unwind_Backtrace ((_Unwind_Trace_Fn)trace_callback, &uw_data);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 return uw_data.n_entries_filled;
kono
parents:
diff changeset
124 #endif
kono
parents:
diff changeset
125 }