annotate gcc/ada/libgnat/s-traceb__hpux.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
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 COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . T R A C E B A C K --
kono
parents:
diff changeset
6 -- (HP/UX Version) --
kono
parents:
diff changeset
7 -- --
kono
parents:
diff changeset
8 -- B o d y --
kono
parents:
diff changeset
9 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
10 -- Copyright (C) 2009-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
11 -- --
kono
parents:
diff changeset
12 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
13 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
18 -- --
kono
parents:
diff changeset
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
20 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
21 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
22 -- --
kono
parents:
diff changeset
23 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
24 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
26 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
27 -- --
kono
parents:
diff changeset
28 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 ------------------------------------------------------------------------------
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 with Ada.Unchecked_Conversion;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package body System.Traceback is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 -- This package implements the backtracing facility by way of a dedicated
kono
parents:
diff changeset
38 -- HP library for stack unwinding described in the "Runtime Architecture
kono
parents:
diff changeset
39 -- Document".
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 pragma Linker_Options ("/usr/lib/libcl.a");
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 -- The library basically offers services to fetch information about a
kono
parents:
diff changeset
44 -- "previous" frame based on information about a "current" one.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 type Current_Frame_Descriptor is record
kono
parents:
diff changeset
47 cur_fsz : Address; -- Frame size of current routine.
kono
parents:
diff changeset
48 cur_sp : Address; -- The current value of stack pointer.
kono
parents:
diff changeset
49 cur_rls : Address; -- PC-space of the caller.
kono
parents:
diff changeset
50 cur_rlo : Address; -- PC-offset of the caller.
kono
parents:
diff changeset
51 cur_dp : Address; -- Data Pointer of the current routine.
kono
parents:
diff changeset
52 top_rp : Address; -- Initial value of RP.
kono
parents:
diff changeset
53 top_mrp : Address; -- Initial value of MRP.
kono
parents:
diff changeset
54 top_sr0 : Address; -- Initial value of sr0.
kono
parents:
diff changeset
55 top_sr4 : Address; -- Initial value of sr4.
kono
parents:
diff changeset
56 top_r3 : Address; -- Initial value of gr3.
kono
parents:
diff changeset
57 cur_r19 : Address; -- GR19 value of the calling routine.
kono
parents:
diff changeset
58 top_r4 : Address; -- Initial value of gr4.
kono
parents:
diff changeset
59 dummy : Address; -- Reserved.
kono
parents:
diff changeset
60 out_rlo : Address; -- PC-offset of the caller after get_previous.
kono
parents:
diff changeset
61 end record;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 type Previous_Frame_Descriptor is record
kono
parents:
diff changeset
64 prev_fsz : Address; -- frame size of calling routine.
kono
parents:
diff changeset
65 prev_sp : Address; -- SP of calling routine.
kono
parents:
diff changeset
66 prev_rls : Address; -- PC_space of calling routine's caller.
kono
parents:
diff changeset
67 prev_rlo : Address; -- PC_offset of calling routine's caller.
kono
parents:
diff changeset
68 prev_dp : Address; -- DP of calling routine.
kono
parents:
diff changeset
69 udescr0 : Address; -- low word of calling routine's unwind desc.
kono
parents:
diff changeset
70 udescr1 : Address; -- high word of calling routine's unwind desc.
kono
parents:
diff changeset
71 ustart : Address; -- start of the unwind region.
kono
parents:
diff changeset
72 uend : Address; -- end of the unwind region.
kono
parents:
diff changeset
73 uw_index : Address; -- index into the unwind table.
kono
parents:
diff changeset
74 prev_r19 : Address; -- GR19 value of the caller's caller.
kono
parents:
diff changeset
75 top_r3 : Address; -- Caller's initial gr3.
kono
parents:
diff changeset
76 top_r4 : Address; -- Caller's initial gr4.
kono
parents:
diff changeset
77 end record;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- Provide useful shortcuts for the names
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 subtype CFD is Current_Frame_Descriptor;
kono
parents:
diff changeset
82 subtype PFD is Previous_Frame_Descriptor;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 -- Frames with dynamic stack allocation are handled using the associated
kono
parents:
diff changeset
85 -- frame pointer, but HP compilers and GCC setup this pointer differently.
kono
parents:
diff changeset
86 -- HP compilers set it to point at the top (highest address) of the static
kono
parents:
diff changeset
87 -- part of the frame, whereas GCC sets it to point at the bottom of this
kono
parents:
diff changeset
88 -- region. We have to fake the unwinder to compensate for this difference,
kono
parents:
diff changeset
89 -- for which we'll need to access some subprograms unwind descriptors.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 type Bits_2_Value is mod 2 ** 2;
kono
parents:
diff changeset
92 for Bits_2_Value'Size use 2;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 type Bits_4_Value is mod 2 ** 4;
kono
parents:
diff changeset
95 for Bits_4_Value'Size use 4;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 type Bits_5_Value is mod 2 ** 5;
kono
parents:
diff changeset
98 for Bits_5_Value'Size use 5;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 type Bits_27_Value is mod 2 ** 27;
kono
parents:
diff changeset
101 for Bits_27_Value'Size use 27;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 type Unwind_Descriptor is record
kono
parents:
diff changeset
104 cannot_unwind : Boolean;
kono
parents:
diff changeset
105 mcode : Boolean;
kono
parents:
diff changeset
106 mcode_save_restore : Boolean;
kono
parents:
diff changeset
107 region_desc : Bits_2_Value;
kono
parents:
diff changeset
108 reserved0 : Boolean;
kono
parents:
diff changeset
109 entry_sr : Boolean;
kono
parents:
diff changeset
110 entry_fr : Bits_4_Value;
kono
parents:
diff changeset
111 entry_gr : Bits_5_Value;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 args_stored : Boolean;
kono
parents:
diff changeset
114 variable_frame : Boolean;
kono
parents:
diff changeset
115 separate_package_body : Boolean;
kono
parents:
diff changeset
116 frame_extension_mcode : Boolean;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 stack_overflow_check : Boolean;
kono
parents:
diff changeset
119 two_steps_sp_adjust : Boolean;
kono
parents:
diff changeset
120 sr4_export : Boolean;
kono
parents:
diff changeset
121 cxx_info : Boolean;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 cxx_try_catch : Boolean;
kono
parents:
diff changeset
124 sched_entry_seq : Boolean;
kono
parents:
diff changeset
125 reserved1 : Boolean;
kono
parents:
diff changeset
126 save_sp : Boolean;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 save_rp : Boolean;
kono
parents:
diff changeset
129 save_mrp : Boolean;
kono
parents:
diff changeset
130 save_r19 : Boolean;
kono
parents:
diff changeset
131 cleanups : Boolean;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 hpe_interrupt_marker : Boolean;
kono
parents:
diff changeset
134 hpux_interrupt_marker : Boolean;
kono
parents:
diff changeset
135 large_frame : Boolean;
kono
parents:
diff changeset
136 alloca_frame : Boolean;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 reserved2 : Boolean;
kono
parents:
diff changeset
139 frame_size : Bits_27_Value;
kono
parents:
diff changeset
140 end record;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 for Unwind_Descriptor'Size use 64;
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 for Unwind_Descriptor use record
kono
parents:
diff changeset
145 cannot_unwind at 0 range 0 .. 0;
kono
parents:
diff changeset
146 mcode at 0 range 1 .. 1;
kono
parents:
diff changeset
147 mcode_save_restore at 0 range 2 .. 2;
kono
parents:
diff changeset
148 region_desc at 0 range 3 .. 4;
kono
parents:
diff changeset
149 reserved0 at 0 range 5 .. 5;
kono
parents:
diff changeset
150 entry_sr at 0 range 6 .. 6;
kono
parents:
diff changeset
151 entry_fr at 0 range 7 .. 10;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 entry_gr at 1 range 3 .. 7;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 args_stored at 2 range 0 .. 0;
kono
parents:
diff changeset
156 variable_frame at 2 range 1 .. 1;
kono
parents:
diff changeset
157 separate_package_body at 2 range 2 .. 2;
kono
parents:
diff changeset
158 frame_extension_mcode at 2 range 3 .. 3;
kono
parents:
diff changeset
159 stack_overflow_check at 2 range 4 .. 4;
kono
parents:
diff changeset
160 two_steps_sp_adjust at 2 range 5 .. 5;
kono
parents:
diff changeset
161 sr4_export at 2 range 6 .. 6;
kono
parents:
diff changeset
162 cxx_info at 2 range 7 .. 7;
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 cxx_try_catch at 3 range 0 .. 0;
kono
parents:
diff changeset
165 sched_entry_seq at 3 range 1 .. 1;
kono
parents:
diff changeset
166 reserved1 at 3 range 2 .. 2;
kono
parents:
diff changeset
167 save_sp at 3 range 3 .. 3;
kono
parents:
diff changeset
168 save_rp at 3 range 4 .. 4;
kono
parents:
diff changeset
169 save_mrp at 3 range 5 .. 5;
kono
parents:
diff changeset
170 save_r19 at 3 range 6 .. 6;
kono
parents:
diff changeset
171 cleanups at 3 range 7 .. 7;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 hpe_interrupt_marker at 4 range 0 .. 0;
kono
parents:
diff changeset
174 hpux_interrupt_marker at 4 range 1 .. 1;
kono
parents:
diff changeset
175 large_frame at 4 range 2 .. 2;
kono
parents:
diff changeset
176 alloca_frame at 4 range 3 .. 3;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 reserved2 at 4 range 4 .. 4;
kono
parents:
diff changeset
179 frame_size at 4 range 5 .. 31;
kono
parents:
diff changeset
180 end record;
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 subtype UWD is Unwind_Descriptor;
kono
parents:
diff changeset
183 type UWD_Ptr is access all UWD;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 function To_UWD_Access is new Ada.Unchecked_Conversion (Address, UWD_Ptr);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 -- The descriptor associated with a given code location is retrieved
kono
parents:
diff changeset
188 -- using functions imported from the HP library, requiring the definition
kono
parents:
diff changeset
189 -- of additional structures.
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 type Unwind_Table_Region is record
kono
parents:
diff changeset
192 Table_Start : Address;
kono
parents:
diff changeset
193 Table_End : Address;
kono
parents:
diff changeset
194 end record;
kono
parents:
diff changeset
195 -- An Unwind Table region, which is a memory area containing Unwind
kono
parents:
diff changeset
196 -- Descriptors.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 subtype UWT is Unwind_Table_Region;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 -- The subprograms imported below are provided by the HP library
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 function U_get_unwind_table return UWT;
kono
parents:
diff changeset
203 pragma Import (C, U_get_unwind_table, "U_get_unwind_table");
kono
parents:
diff changeset
204 -- Get the unwind table region associated with the current executable.
kono
parents:
diff changeset
205 -- This function is actually documented as having an argument, but which
kono
parents:
diff changeset
206 -- is only used for the MPE/iX targets.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 function U_get_shLib_unwind_table (r19 : Address) return UWT;
kono
parents:
diff changeset
209 pragma Import (C, U_get_shLib_unwind_table, "U_get_shLib_unw_tbl");
kono
parents:
diff changeset
210 -- Return the unwind table region associated with a possible shared
kono
parents:
diff changeset
211 -- library, as determined by the provided r19 value.
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 function U_get_shLib_text_addr (r19 : Address) return Address;
kono
parents:
diff changeset
214 pragma Import (C, U_get_shLib_text_addr, "U_get_shLib_text_addr");
kono
parents:
diff changeset
215 -- Return the address at which the code for a shared library begins, or
kono
parents:
diff changeset
216 -- -1 if the value provided for r19 does not identify shared library code.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 function U_get_unwind_entry
kono
parents:
diff changeset
219 (Pc : Address;
kono
parents:
diff changeset
220 Space : Address;
kono
parents:
diff changeset
221 Table_Start : Address;
kono
parents:
diff changeset
222 Table_End : Address) return Address;
kono
parents:
diff changeset
223 pragma Import (C, U_get_unwind_entry, "U_get_unwind_entry");
kono
parents:
diff changeset
224 -- Given the bounds of an unwind table, return the address of the
kono
parents:
diff changeset
225 -- unwind descriptor associated with a code location/space. In the case
kono
parents:
diff changeset
226 -- of shared library code, the offset from the beginning of the library
kono
parents:
diff changeset
227 -- is expected as Pc.
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 procedure U_init_frame_record (Frame : not null access CFD);
kono
parents:
diff changeset
230 pragma Import (C, U_init_frame_record, "U_init_frame_record");
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 procedure U_prep_frame_rec_for_unwind (Frame : not null access CFD);
kono
parents:
diff changeset
233 pragma Import (C, U_prep_frame_rec_for_unwind,
kono
parents:
diff changeset
234 "U_prep_frame_rec_for_unwind");
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 -- Fetch the description data of the frame in which these two procedures
kono
parents:
diff changeset
237 -- are called.
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 function U_get_u_rlo
kono
parents:
diff changeset
240 (Cur : not null access CFD; Prev : not null access PFD) return Integer;
kono
parents:
diff changeset
241 pragma Import (C, U_get_u_rlo, "U_IS_STUB_OR_CALLX");
kono
parents:
diff changeset
242 -- From a complete current frame with a return location possibly located
kono
parents:
diff changeset
243 -- into a linker generated stub, and basic information about the previous
kono
parents:
diff changeset
244 -- frame, place the first non stub return location into the current frame.
kono
parents:
diff changeset
245 -- Return -1 if something went wrong during the computation.
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 function U_is_shared_pc (rlo : Address; r19 : Address) return Address;
kono
parents:
diff changeset
248 pragma Import (C, U_is_shared_pc, "U_is_shared_pc");
kono
parents:
diff changeset
249 -- Return 0 if the provided return location does not correspond to code
kono
parents:
diff changeset
250 -- in a shared library, or something non null otherwise.
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 function U_get_previous_frame_x
kono
parents:
diff changeset
253 (current_frame : not null access CFD;
kono
parents:
diff changeset
254 previous_frame : not null access PFD;
kono
parents:
diff changeset
255 previous_size : Integer) return Integer;
kono
parents:
diff changeset
256 pragma Import (C, U_get_previous_frame_x, "U_get_previous_frame_x");
kono
parents:
diff changeset
257 -- Fetch the data describing the "previous" frame relatively to the
kono
parents:
diff changeset
258 -- "current" one. "previous_size" should be the size of the "previous"
kono
parents:
diff changeset
259 -- frame descriptor provided.
kono
parents:
diff changeset
260 --
kono
parents:
diff changeset
261 -- The library provides a simpler interface without the size parameter
kono
parents:
diff changeset
262 -- but it is not usable when frames with dynamically allocated space are
kono
parents:
diff changeset
263 -- on the way.
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 procedure Call_Chain
kono
parents:
diff changeset
266 (Traceback : System.Address;
kono
parents:
diff changeset
267 Max_Len : Natural;
kono
parents:
diff changeset
268 Len : out Natural;
kono
parents:
diff changeset
269 Exclude_Min : System.Address := System.Null_Address;
kono
parents:
diff changeset
270 Exclude_Max : System.Address := System.Null_Address;
kono
parents:
diff changeset
271 Skip_Frames : Natural := 1);
kono
parents:
diff changeset
272 -- Same as the exported version, but takes Traceback as an Address
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 ------------------
kono
parents:
diff changeset
275 -- C_Call_Chain --
kono
parents:
diff changeset
276 ------------------
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 function C_Call_Chain
kono
parents:
diff changeset
279 (Traceback : System.Address;
kono
parents:
diff changeset
280 Max_Len : Natural) return Natural
kono
parents:
diff changeset
281 is
kono
parents:
diff changeset
282 Val : Natural;
kono
parents:
diff changeset
283 begin
kono
parents:
diff changeset
284 Call_Chain (Traceback, Max_Len, Val);
kono
parents:
diff changeset
285 return Val;
kono
parents:
diff changeset
286 end C_Call_Chain;
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 ----------------
kono
parents:
diff changeset
289 -- Call_Chain --
kono
parents:
diff changeset
290 ----------------
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 procedure Call_Chain
kono
parents:
diff changeset
293 (Traceback : System.Address;
kono
parents:
diff changeset
294 Max_Len : Natural;
kono
parents:
diff changeset
295 Len : out Natural;
kono
parents:
diff changeset
296 Exclude_Min : System.Address := System.Null_Address;
kono
parents:
diff changeset
297 Exclude_Max : System.Address := System.Null_Address;
kono
parents:
diff changeset
298 Skip_Frames : Natural := 1)
kono
parents:
diff changeset
299 is
kono
parents:
diff changeset
300 type Tracebacks_Array is array (1 .. Max_Len) of System.Address;
kono
parents:
diff changeset
301 pragma Suppress_Initialization (Tracebacks_Array);
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 -- The code location returned by the unwinder is a return location but
kono
parents:
diff changeset
304 -- what we need is a call point. Under HP-UX call instructions are 4
kono
parents:
diff changeset
305 -- bytes long and the return point they specify is 4 bytes beyond the
kono
parents:
diff changeset
306 -- next instruction because of the delay slot.
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 Call_Size : constant := 4;
kono
parents:
diff changeset
309 DSlot_Size : constant := 4;
kono
parents:
diff changeset
310 Rlo_Offset : constant := Call_Size + DSlot_Size;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 -- Moreover, the return point is passed via a register which two least
kono
parents:
diff changeset
313 -- significant bits specify a privilege level that we will have to mask.
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 Priv_Mask : constant := 16#00000003#;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 Frame : aliased CFD;
kono
parents:
diff changeset
318 Code : System.Address;
kono
parents:
diff changeset
319 J : Natural := 1;
kono
parents:
diff changeset
320 Pop_Success : Boolean;
kono
parents:
diff changeset
321 Trace : Tracebacks_Array;
kono
parents:
diff changeset
322 for Trace'Address use Traceback;
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 -- The backtracing process needs a set of subprograms :
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 function UWD_For_RLO_Of (Frame : not null access CFD) return UWD_Ptr;
kono
parents:
diff changeset
327 -- Return an access to the unwind descriptor for the caller of
kono
parents:
diff changeset
328 -- a given frame, using only the provided return location.
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 function UWD_For_Caller_Of (Frame : not null access CFD) return UWD_Ptr;
kono
parents:
diff changeset
331 -- Return an access to the unwind descriptor for the user code caller
kono
parents:
diff changeset
332 -- of a given frame, or null if the information is not available.
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 function Pop_Frame (Frame : not null access CFD) return Boolean;
kono
parents:
diff changeset
335 -- Update the provided machine state structure so that it reflects
kono
parents:
diff changeset
336 -- the state one call frame "above" the initial one.
kono
parents:
diff changeset
337 --
kono
parents:
diff changeset
338 -- Return True if the operation has been successful, False otherwise.
kono
parents:
diff changeset
339 -- Failure typically occurs when the top of the call stack has been
kono
parents:
diff changeset
340 -- reached.
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 function Prepare_For_Unwind_Of
kono
parents:
diff changeset
343 (Frame : not null access CFD) return Boolean;
kono
parents:
diff changeset
344 -- Perform the necessary adaptations to the machine state before
kono
parents:
diff changeset
345 -- calling the unwinder. Currently used for the specific case of
kono
parents:
diff changeset
346 -- dynamically sized previous frames.
kono
parents:
diff changeset
347 --
kono
parents:
diff changeset
348 -- Return True if everything went fine, or False otherwise.
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 Program_UWT : constant UWT := U_get_unwind_table;
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 ---------------
kono
parents:
diff changeset
353 -- Pop_Frame --
kono
parents:
diff changeset
354 ---------------
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 function Pop_Frame (Frame : not null access CFD) return Boolean is
kono
parents:
diff changeset
357 Up_Frame : aliased PFD;
kono
parents:
diff changeset
358 State_Ready : Boolean;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 begin
kono
parents:
diff changeset
361 -- Check/adapt the state before calling the unwinder and return
kono
parents:
diff changeset
362 -- if anything went wrong.
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 State_Ready := Prepare_For_Unwind_Of (Frame);
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 if not State_Ready then
kono
parents:
diff changeset
367 return False;
kono
parents:
diff changeset
368 end if;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 -- Now, safely call the unwinder and use the results
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 if U_get_previous_frame_x (Frame,
kono
parents:
diff changeset
373 Up_Frame'Access,
kono
parents:
diff changeset
374 Up_Frame'Size) /= 0
kono
parents:
diff changeset
375 then
kono
parents:
diff changeset
376 return False;
kono
parents:
diff changeset
377 end if;
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 -- In case a stub is on the way, the usual previous return location
kono
parents:
diff changeset
380 -- (the one in prev_rlo) is the one in the stub and the "real" one
kono
parents:
diff changeset
381 -- is placed in the "current" record, so let's take this one into
kono
parents:
diff changeset
382 -- account.
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 Frame.out_rlo := Frame.cur_rlo;
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 Frame.cur_fsz := Up_Frame.prev_fsz;
kono
parents:
diff changeset
387 Frame.cur_sp := Up_Frame.prev_sp;
kono
parents:
diff changeset
388 Frame.cur_rls := Up_Frame.prev_rls;
kono
parents:
diff changeset
389 Frame.cur_rlo := Up_Frame.prev_rlo;
kono
parents:
diff changeset
390 Frame.cur_dp := Up_Frame.prev_dp;
kono
parents:
diff changeset
391 Frame.cur_r19 := Up_Frame.prev_r19;
kono
parents:
diff changeset
392 Frame.top_r3 := Up_Frame.top_r3;
kono
parents:
diff changeset
393 Frame.top_r4 := Up_Frame.top_r4;
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 return True;
kono
parents:
diff changeset
396 end Pop_Frame;
kono
parents:
diff changeset
397
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
398 ---------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
399 -- Prepare_For_Unwind_Of --
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
400 ---------------------------
111
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 function Prepare_For_Unwind_Of
kono
parents:
diff changeset
403 (Frame : not null access CFD) return Boolean
kono
parents:
diff changeset
404 is
kono
parents:
diff changeset
405 Caller_UWD : UWD_Ptr;
kono
parents:
diff changeset
406 FP_Adjustment : Integer;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 begin
kono
parents:
diff changeset
409 -- No need to bother doing anything if the stack is already fully
kono
parents:
diff changeset
410 -- unwound.
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 if Frame.cur_rlo = 0 then
kono
parents:
diff changeset
413 return False;
kono
parents:
diff changeset
414 end if;
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 -- When ALLOCA_FRAME is set in an unwind descriptor, the unwinder
kono
parents:
diff changeset
417 -- uses the value provided in current.top_r3 or current.top_r4 as
kono
parents:
diff changeset
418 -- a frame pointer to compute the size of the frame. What decides
kono
parents:
diff changeset
419 -- between r3 or r4 is the unwind descriptor LARGE_FRAME bit, with
kono
parents:
diff changeset
420 -- r4 chosen if the bit is set.
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 -- The size computed by the unwinder is STATIC_PART + (SP - FP),
kono
parents:
diff changeset
423 -- which is correct with HP's frame pointer convention, but not
kono
parents:
diff changeset
424 -- with GCC's one since we end up with the static part accounted
kono
parents:
diff changeset
425 -- for twice.
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 -- We have to compute r4 when it is required because the unwinder
kono
parents:
diff changeset
428 -- has looked for it at a place where it was not if we went through
kono
parents:
diff changeset
429 -- GCC frames.
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 -- The size of the static part of a frame can be found in the
kono
parents:
diff changeset
432 -- associated unwind descriptor.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 Caller_UWD := UWD_For_Caller_Of (Frame);
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 -- If we cannot get it, we are unable to compute the potentially
kono
parents:
diff changeset
437 -- necessary adjustments. We'd better not try to go on then.
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 if Caller_UWD = null then
kono
parents:
diff changeset
440 return False;
kono
parents:
diff changeset
441 end if;
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- If the caller frame is a GCC one, r3 is its frame pointer and
kono
parents:
diff changeset
444 -- points to the bottom of the frame. The value to provide for r4
kono
parents:
diff changeset
445 -- can then be computed directly from the one of r3, compensating
kono
parents:
diff changeset
446 -- for the static part of the frame.
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 -- If the caller frame is an HP one, r3 is used to locate the
kono
parents:
diff changeset
449 -- previous frame marker, that is it also points to the bottom of
kono
parents:
diff changeset
450 -- the frame (this is why r3 cannot be used as the frame pointer in
kono
parents:
diff changeset
451 -- the HP sense for large frames). The value to provide for r4 can
kono
parents:
diff changeset
452 -- then also be computed from the one of r3 with the compensation
kono
parents:
diff changeset
453 -- for the static part of the frame.
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 FP_Adjustment := Integer (Caller_UWD.frame_size * 8);
kono
parents:
diff changeset
456 Frame.top_r4 := Address (Integer (Frame.top_r3) + FP_Adjustment);
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 return True;
kono
parents:
diff changeset
459 end Prepare_For_Unwind_Of;
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 -----------------------
kono
parents:
diff changeset
462 -- UWD_For_Caller_Of --
kono
parents:
diff changeset
463 -----------------------
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 function UWD_For_Caller_Of (Frame : not null access CFD) return UWD_Ptr
kono
parents:
diff changeset
466 is
kono
parents:
diff changeset
467 UWD_Access : UWD_Ptr;
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 begin
kono
parents:
diff changeset
470 -- First try the most direct path, using the return location data
kono
parents:
diff changeset
471 -- associated with the frame.
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 UWD_Access := UWD_For_RLO_Of (Frame);
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 if UWD_Access /= null then
kono
parents:
diff changeset
476 return UWD_Access;
kono
parents:
diff changeset
477 end if;
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 -- If we did not get a result, we might face an in-stub return
kono
parents:
diff changeset
480 -- address. In this case U_get_previous_frame can tell us what the
kono
parents:
diff changeset
481 -- first not-in-stub return point is. We cannot call it directly,
kono
parents:
diff changeset
482 -- though, because we haven't computed the potentially necessary
kono
parents:
diff changeset
483 -- frame pointer adjustments, which might lead to SEGV in some
kono
parents:
diff changeset
484 -- circumstances. Instead, we directly call the libcl routine which
kono
parents:
diff changeset
485 -- is called by U_get_previous_frame and which only requires few
kono
parents:
diff changeset
486 -- information. Take care, however, that the information is provided
kono
parents:
diff changeset
487 -- in the "current" argument, so we need to work on a copy to avoid
kono
parents:
diff changeset
488 -- disturbing our caller.
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 declare
kono
parents:
diff changeset
491 U_Current : aliased CFD := Frame.all;
kono
parents:
diff changeset
492 U_Previous : aliased PFD;
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 begin
kono
parents:
diff changeset
495 U_Previous.prev_dp := U_Current.cur_dp;
kono
parents:
diff changeset
496 U_Previous.prev_rls := U_Current.cur_rls;
kono
parents:
diff changeset
497 U_Previous.prev_sp := U_Current.cur_sp - U_Current.cur_fsz;
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 if U_get_u_rlo (U_Current'Access, U_Previous'Access) /= -1 then
kono
parents:
diff changeset
500 UWD_Access := UWD_For_RLO_Of (U_Current'Access);
kono
parents:
diff changeset
501 end if;
kono
parents:
diff changeset
502 end;
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 return UWD_Access;
kono
parents:
diff changeset
505 end UWD_For_Caller_Of;
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 --------------------
kono
parents:
diff changeset
508 -- UWD_For_RLO_Of --
kono
parents:
diff changeset
509 --------------------
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 function UWD_For_RLO_Of (Frame : not null access CFD) return UWD_Ptr
kono
parents:
diff changeset
512 is
kono
parents:
diff changeset
513 UWD_Address : Address;
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- The addresses returned by the library point to full descriptors
kono
parents:
diff changeset
516 -- including the frame information bits but also the applicable PC
kono
parents:
diff changeset
517 -- range. We need to account for this.
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 Frame_Info_Offset : constant := 8;
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 begin
kono
parents:
diff changeset
522 -- First try to locate the descriptor in the program's unwind table
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 UWD_Address := U_get_unwind_entry (Frame.cur_rlo,
kono
parents:
diff changeset
525 Frame.cur_rls,
kono
parents:
diff changeset
526 Program_UWT.Table_Start,
kono
parents:
diff changeset
527 Program_UWT.Table_End);
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- If we did not get it, we might have a frame from code in a
kono
parents:
diff changeset
530 -- stub or shared library. For code in stub we would have to
kono
parents:
diff changeset
531 -- compute the first non-stub return location but this is not
kono
parents:
diff changeset
532 -- the role of this subprogram, so let's just try to see if we
kono
parents:
diff changeset
533 -- can get a result from the tables in shared libraries.
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 if UWD_Address = -1
kono
parents:
diff changeset
536 and then U_is_shared_pc (Frame.cur_rlo, Frame.cur_r19) /= 0
kono
parents:
diff changeset
537 then
kono
parents:
diff changeset
538 declare
kono
parents:
diff changeset
539 Shlib_UWT : constant UWT :=
kono
parents:
diff changeset
540 U_get_shLib_unwind_table (Frame.cur_r19);
kono
parents:
diff changeset
541 Shlib_Start : constant Address :=
kono
parents:
diff changeset
542 U_get_shLib_text_addr (Frame.cur_r19);
kono
parents:
diff changeset
543 Rlo_Offset : constant Address :=
kono
parents:
diff changeset
544 Frame.cur_rlo - Shlib_Start;
kono
parents:
diff changeset
545 begin
kono
parents:
diff changeset
546 UWD_Address := U_get_unwind_entry (Rlo_Offset,
kono
parents:
diff changeset
547 Frame.cur_rls,
kono
parents:
diff changeset
548 Shlib_UWT.Table_Start,
kono
parents:
diff changeset
549 Shlib_UWT.Table_End);
kono
parents:
diff changeset
550 end;
kono
parents:
diff changeset
551 end if;
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 if UWD_Address /= -1 then
kono
parents:
diff changeset
554 return To_UWD_Access (UWD_Address + Frame_Info_Offset);
kono
parents:
diff changeset
555 else
kono
parents:
diff changeset
556 return null;
kono
parents:
diff changeset
557 end if;
kono
parents:
diff changeset
558 end UWD_For_RLO_Of;
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 -- Start of processing for Call_Chain
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 begin
kono
parents:
diff changeset
563 -- Fetch the state for this subprogram's frame and pop it so that we
kono
parents:
diff changeset
564 -- start with an initial out_rlo "here".
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 U_init_frame_record (Frame'Access);
kono
parents:
diff changeset
567 Frame.top_sr0 := 0;
kono
parents:
diff changeset
568 Frame.top_sr4 := 0;
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 U_prep_frame_rec_for_unwind (Frame'Access);
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 Pop_Success := Pop_Frame (Frame'Access);
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 -- Skip the requested number of frames
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 for I in 1 .. Skip_Frames loop
kono
parents:
diff changeset
577 Pop_Success := Pop_Frame (Frame'Access);
kono
parents:
diff changeset
578 end loop;
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 -- Loop popping frames and storing locations until either a problem
kono
parents:
diff changeset
581 -- occurs, or the top of the call chain is reached, or the provided
kono
parents:
diff changeset
582 -- array is full.
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 loop
kono
parents:
diff changeset
585 -- We have to test some conditions against the return location
kono
parents:
diff changeset
586 -- as it is returned, so get it as is first.
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 Code := Frame.out_rlo;
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 exit when not Pop_Success or else Code = 0 or else J = Max_Len + 1;
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 -- Compute the call point from the retrieved return location :
kono
parents:
diff changeset
593 -- Mask the privilege bits and account for the delta between the
kono
parents:
diff changeset
594 -- call site and the return point.
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 Code := (Code and not Priv_Mask) - Rlo_Offset;
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 if Code < Exclude_Min or else Code > Exclude_Max then
kono
parents:
diff changeset
599 Trace (J) := Code;
kono
parents:
diff changeset
600 J := J + 1;
kono
parents:
diff changeset
601 end if;
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 Pop_Success := Pop_Frame (Frame'Access);
kono
parents:
diff changeset
604 end loop;
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 Len := J - 1;
kono
parents:
diff changeset
607 end Call_Chain;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 procedure Call_Chain
kono
parents:
diff changeset
610 (Traceback : in out System.Traceback_Entries.Tracebacks_Array;
kono
parents:
diff changeset
611 Max_Len : Natural;
kono
parents:
diff changeset
612 Len : out Natural;
kono
parents:
diff changeset
613 Exclude_Min : System.Address := System.Null_Address;
kono
parents:
diff changeset
614 Exclude_Max : System.Address := System.Null_Address;
kono
parents:
diff changeset
615 Skip_Frames : Natural := 1)
kono
parents:
diff changeset
616 is
kono
parents:
diff changeset
617 begin
kono
parents:
diff changeset
618 Call_Chain
kono
parents:
diff changeset
619 (Traceback'Address, Max_Len, Len,
kono
parents:
diff changeset
620 Exclude_Min, Exclude_Max,
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 -- Skip one extra frame to skip the other Call_Chain entry as well
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 Skip_Frames => Skip_Frames + 1);
kono
parents:
diff changeset
625 end Call_Chain;
kono
parents:
diff changeset
626
kono
parents:
diff changeset
627 end System.Traceback;