annotate gcc/ada/libgnat/s-stausa.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M - S T A C K _ U S A G E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL 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 -- GNARL was developed by the GNARL team at Florida State 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 with System.Parameters;
kono
parents:
diff changeset
33 with System.CRTL;
kono
parents:
diff changeset
34 with System.IO;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package body System.Stack_Usage is
kono
parents:
diff changeset
37 use System.Storage_Elements;
kono
parents:
diff changeset
38 use System.IO;
kono
parents:
diff changeset
39 use Interfaces;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 -----------------
kono
parents:
diff changeset
42 -- Stack_Slots --
kono
parents:
diff changeset
43 -----------------
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 -- Stackl_Slots is an internal data type to represent a sequence of real
kono
parents:
diff changeset
46 -- stack slots initialized with a provided pattern, with operations to
kono
parents:
diff changeset
47 -- abstract away the target call stack growth direction.
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 type Stack_Slots is array (Integer range <>) of Pattern_Type;
kono
parents:
diff changeset
50 for Stack_Slots'Component_Size use Pattern_Type'Object_Size;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- We will carefully handle the initializations ourselves and might want
kono
parents:
diff changeset
53 -- to remap an initialized overlay later on with an address clause.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 pragma Suppress_Initialization (Stack_Slots);
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- The abstract Stack_Slots operations all operate over the simple array
kono
parents:
diff changeset
58 -- memory model:
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 -- memory addresses increasing ---->
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- Slots('First) Slots('Last)
kono
parents:
diff changeset
63 -- | |
kono
parents:
diff changeset
64 -- V V
kono
parents:
diff changeset
65 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
66 -- |####| |####|
kono
parents:
diff changeset
67 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- What we call Top or Bottom always denotes call chain leaves or entry
kono
parents:
diff changeset
70 -- points respectively, and their relative positions in the stack array
kono
parents:
diff changeset
71 -- depends on the target stack growth direction:
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -- Stack_Grows_Down
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 -- <----- calls push frames towards decreasing addresses
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 -- Top(most) Slot Bottom(most) Slot
kono
parents:
diff changeset
78 -- | |
kono
parents:
diff changeset
79 -- V V
kono
parents:
diff changeset
80 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
81 -- |####| | leaf frame | ... | entry frame |
kono
parents:
diff changeset
82 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 -- Stack_Grows_Up
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -- calls push frames towards increasing addresses ----->
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- Bottom(most) Slot Top(most) Slot
kono
parents:
diff changeset
89 -- | |
kono
parents:
diff changeset
90 -- V V
kono
parents:
diff changeset
91 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
92 -- | entry frame | ... | leaf frame | |####|
kono
parents:
diff changeset
93 -- +------------------------------------------------------------------+
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -------------------
kono
parents:
diff changeset
96 -- Unit Services --
kono
parents:
diff changeset
97 -------------------
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -- Now the implementation of the services offered by this unit, on top of
kono
parents:
diff changeset
100 -- the Stack_Slots abstraction above.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 Index_Str : constant String := "Index";
kono
parents:
diff changeset
103 Task_Name_Str : constant String := "Task Name";
kono
parents:
diff changeset
104 Stack_Size_Str : constant String := "Stack Size";
kono
parents:
diff changeset
105 Actual_Size_Str : constant String := "Stack usage";
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Output_Result
kono
parents:
diff changeset
108 (Result_Id : Natural;
kono
parents:
diff changeset
109 Result : Task_Result;
kono
parents:
diff changeset
110 Max_Stack_Size_Len : Natural;
kono
parents:
diff changeset
111 Max_Actual_Use_Len : Natural);
kono
parents:
diff changeset
112 -- Prints the result on the standard output. Result Id is the number of
kono
parents:
diff changeset
113 -- the result in the array, and Result the contents of the actual result.
kono
parents:
diff changeset
114 -- Max_Stack_Size_Len and Max_Actual_Use_Len are used for displaying the
kono
parents:
diff changeset
115 -- proper layout. They hold the maximum length of the string representing
kono
parents:
diff changeset
116 -- the Stack_Size and Actual_Use values.
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 ----------------
kono
parents:
diff changeset
119 -- Initialize --
kono
parents:
diff changeset
120 ----------------
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 procedure Initialize (Buffer_Size : Natural) is
kono
parents:
diff changeset
123 Stack_Size_Chars : System.Address;
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 begin
kono
parents:
diff changeset
126 -- Initialize the buffered result array
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 Result_Array := new Result_Array_Type (1 .. Buffer_Size);
kono
parents:
diff changeset
129 Result_Array.all :=
kono
parents:
diff changeset
130 (others =>
kono
parents:
diff changeset
131 (Task_Name => (others => ASCII.NUL),
kono
parents:
diff changeset
132 Value => 0,
kono
parents:
diff changeset
133 Stack_Size => 0));
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -- Set the Is_Enabled flag to true, so that the task wrapper knows that
kono
parents:
diff changeset
136 -- it has to handle dynamic stack analysis
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 Is_Enabled := True;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 Stack_Size_Chars := System.CRTL.getenv ("GNAT_STACK_LIMIT" & ASCII.NUL);
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 -- If variable GNAT_STACK_LIMIT is set, then we will take care of the
kono
parents:
diff changeset
143 -- environment task, using GNAT_STASK_LIMIT as the size of the stack.
kono
parents:
diff changeset
144 -- It doesn't make sens to process the stack when no bound is set (e.g.
kono
parents:
diff changeset
145 -- limit is typically up to 4 GB).
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 if Stack_Size_Chars /= Null_Address then
kono
parents:
diff changeset
148 declare
kono
parents:
diff changeset
149 My_Stack_Size : Integer;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 begin
kono
parents:
diff changeset
152 My_Stack_Size := System.CRTL.atoi (Stack_Size_Chars) * 1024;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Initialize_Analyzer
kono
parents:
diff changeset
155 (Environment_Task_Analyzer,
kono
parents:
diff changeset
156 "ENVIRONMENT TASK",
kono
parents:
diff changeset
157 My_Stack_Size,
kono
parents:
diff changeset
158 0,
kono
parents:
diff changeset
159 My_Stack_Size);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 Fill_Stack (Environment_Task_Analyzer);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 Compute_Environment_Task := True;
kono
parents:
diff changeset
164 end;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 -- GNAT_STACK_LIMIT not set
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 else
kono
parents:
diff changeset
169 Compute_Environment_Task := False;
kono
parents:
diff changeset
170 end if;
kono
parents:
diff changeset
171 end Initialize;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 ----------------
kono
parents:
diff changeset
174 -- Fill_Stack --
kono
parents:
diff changeset
175 ----------------
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 procedure Fill_Stack (Analyzer : in out Stack_Analyzer) is
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -- Change the local variables and parameters of this function with
kono
parents:
diff changeset
180 -- super-extra care. The more the stack frame size of this function is
kono
parents:
diff changeset
181 -- big, the more an "instrumentation threshold at writing" error is
kono
parents:
diff changeset
182 -- likely to happen.
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 Current_Stack_Level : aliased Integer;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Guard : constant := 256;
kono
parents:
diff changeset
187 -- Guard space between the Current_Stack_Level'Address and the last
kono
parents:
diff changeset
188 -- allocated byte on the stack.
kono
parents:
diff changeset
189 begin
kono
parents:
diff changeset
190 if Parameters.Stack_Grows_Down then
kono
parents:
diff changeset
191 if Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size) >
kono
parents:
diff changeset
192 To_Stack_Address (Current_Stack_Level'Address) - Guard
kono
parents:
diff changeset
193 then
kono
parents:
diff changeset
194 -- No room for a pattern
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 Analyzer.Pattern_Size := 0;
kono
parents:
diff changeset
197 return;
kono
parents:
diff changeset
198 end if;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 Analyzer.Pattern_Limit :=
kono
parents:
diff changeset
201 Analyzer.Stack_Base - Stack_Address (Analyzer.Pattern_Size);
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 if Analyzer.Stack_Base >
kono
parents:
diff changeset
204 To_Stack_Address (Current_Stack_Level'Address) - Guard
kono
parents:
diff changeset
205 then
kono
parents:
diff changeset
206 -- Reduce pattern size to prevent local frame overwrite
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 Analyzer.Pattern_Size :=
kono
parents:
diff changeset
209 Integer (To_Stack_Address (Current_Stack_Level'Address) - Guard
kono
parents:
diff changeset
210 - Analyzer.Pattern_Limit);
kono
parents:
diff changeset
211 end if;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 Analyzer.Pattern_Overlay_Address :=
kono
parents:
diff changeset
214 To_Address (Analyzer.Pattern_Limit);
kono
parents:
diff changeset
215 else
kono
parents:
diff changeset
216 if Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size) <
kono
parents:
diff changeset
217 To_Stack_Address (Current_Stack_Level'Address) + Guard
kono
parents:
diff changeset
218 then
kono
parents:
diff changeset
219 -- No room for a pattern
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 Analyzer.Pattern_Size := 0;
kono
parents:
diff changeset
222 return;
kono
parents:
diff changeset
223 end if;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 Analyzer.Pattern_Limit :=
kono
parents:
diff changeset
226 Analyzer.Stack_Base + Stack_Address (Analyzer.Pattern_Size);
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 if Analyzer.Stack_Base <
kono
parents:
diff changeset
229 To_Stack_Address (Current_Stack_Level'Address) + Guard
kono
parents:
diff changeset
230 then
kono
parents:
diff changeset
231 -- Reduce pattern size to prevent local frame overwrite
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 Analyzer.Pattern_Size :=
kono
parents:
diff changeset
234 Integer
kono
parents:
diff changeset
235 (Analyzer.Pattern_Limit -
kono
parents:
diff changeset
236 (To_Stack_Address (Current_Stack_Level'Address) + Guard));
kono
parents:
diff changeset
237 end if;
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 Analyzer.Pattern_Overlay_Address :=
kono
parents:
diff changeset
240 To_Address (Analyzer.Pattern_Limit -
kono
parents:
diff changeset
241 Stack_Address (Analyzer.Pattern_Size));
kono
parents:
diff changeset
242 end if;
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 -- Declare and fill the pattern buffer
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 declare
kono
parents:
diff changeset
247 Pattern : aliased Stack_Slots
kono
parents:
diff changeset
248 (1 .. Analyzer.Pattern_Size / Bytes_Per_Pattern);
kono
parents:
diff changeset
249 for Pattern'Address use Analyzer.Pattern_Overlay_Address;
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 begin
kono
parents:
diff changeset
252 if System.Parameters.Stack_Grows_Down then
kono
parents:
diff changeset
253 for J in reverse Pattern'Range loop
kono
parents:
diff changeset
254 Pattern (J) := Analyzer.Pattern;
kono
parents:
diff changeset
255 end loop;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 else
kono
parents:
diff changeset
258 for J in Pattern'Range loop
kono
parents:
diff changeset
259 Pattern (J) := Analyzer.Pattern;
kono
parents:
diff changeset
260 end loop;
kono
parents:
diff changeset
261 end if;
kono
parents:
diff changeset
262 end;
kono
parents:
diff changeset
263 end Fill_Stack;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 -------------------------
kono
parents:
diff changeset
266 -- Initialize_Analyzer --
kono
parents:
diff changeset
267 -------------------------
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 procedure Initialize_Analyzer
kono
parents:
diff changeset
270 (Analyzer : in out Stack_Analyzer;
kono
parents:
diff changeset
271 Task_Name : String;
kono
parents:
diff changeset
272 Stack_Size : Natural;
kono
parents:
diff changeset
273 Stack_Base : Stack_Address;
kono
parents:
diff changeset
274 Pattern_Size : Natural;
kono
parents:
diff changeset
275 Pattern : Interfaces.Unsigned_32 := 16#DEAD_BEEF#)
kono
parents:
diff changeset
276 is
kono
parents:
diff changeset
277 begin
kono
parents:
diff changeset
278 -- Initialize the analyzer fields
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 Analyzer.Stack_Base := Stack_Base;
kono
parents:
diff changeset
281 Analyzer.Stack_Size := Stack_Size;
kono
parents:
diff changeset
282 Analyzer.Pattern_Size := Pattern_Size;
kono
parents:
diff changeset
283 Analyzer.Pattern := Pattern;
kono
parents:
diff changeset
284 Analyzer.Result_Id := Next_Id;
kono
parents:
diff changeset
285 Analyzer.Task_Name := (others => ' ');
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 -- Compute the task name, and truncate if bigger than Task_Name_Length
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 if Task_Name'Length <= Task_Name_Length then
kono
parents:
diff changeset
290 Analyzer.Task_Name (1 .. Task_Name'Length) := Task_Name;
kono
parents:
diff changeset
291 else
kono
parents:
diff changeset
292 Analyzer.Task_Name :=
kono
parents:
diff changeset
293 Task_Name (Task_Name'First ..
kono
parents:
diff changeset
294 Task_Name'First + Task_Name_Length - 1);
kono
parents:
diff changeset
295 end if;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 Next_Id := Next_Id + 1;
kono
parents:
diff changeset
298 end Initialize_Analyzer;
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 ----------------
kono
parents:
diff changeset
301 -- Stack_Size --
kono
parents:
diff changeset
302 ----------------
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 function Stack_Size
kono
parents:
diff changeset
305 (SP_Low : Stack_Address;
kono
parents:
diff changeset
306 SP_High : Stack_Address) return Natural
kono
parents:
diff changeset
307 is
kono
parents:
diff changeset
308 begin
kono
parents:
diff changeset
309 if SP_Low > SP_High then
kono
parents:
diff changeset
310 return Natural (SP_Low - SP_High);
kono
parents:
diff changeset
311 else
kono
parents:
diff changeset
312 return Natural (SP_High - SP_Low);
kono
parents:
diff changeset
313 end if;
kono
parents:
diff changeset
314 end Stack_Size;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 --------------------
kono
parents:
diff changeset
317 -- Compute_Result --
kono
parents:
diff changeset
318 --------------------
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 procedure Compute_Result (Analyzer : in out Stack_Analyzer) is
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 -- Change the local variables and parameters of this function with
kono
parents:
diff changeset
323 -- super-extra care. The larger the stack frame size of this function
kono
parents:
diff changeset
324 -- is, the more an "instrumentation threshold at reading" error is
kono
parents:
diff changeset
325 -- likely to happen.
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 Stack : Stack_Slots (1 .. Analyzer.Pattern_Size / Bytes_Per_Pattern);
kono
parents:
diff changeset
328 for Stack'Address use Analyzer.Pattern_Overlay_Address;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 begin
kono
parents:
diff changeset
331 -- Value if the pattern was not modified
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 if Parameters.Stack_Grows_Down then
kono
parents:
diff changeset
334 Analyzer.Topmost_Touched_Mark :=
kono
parents:
diff changeset
335 Analyzer.Pattern_Limit + Stack_Address (Analyzer.Pattern_Size);
kono
parents:
diff changeset
336 else
kono
parents:
diff changeset
337 Analyzer.Topmost_Touched_Mark :=
kono
parents:
diff changeset
338 Analyzer.Pattern_Limit - Stack_Address (Analyzer.Pattern_Size);
kono
parents:
diff changeset
339 end if;
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 if Analyzer.Pattern_Size = 0 then
kono
parents:
diff changeset
342 return;
kono
parents:
diff changeset
343 end if;
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 -- Look backward from the topmost possible end of the marked stack to
kono
parents:
diff changeset
346 -- the bottom of it. The first index not equals to the patterns marks
kono
parents:
diff changeset
347 -- the beginning of the used stack.
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 if System.Parameters.Stack_Grows_Down then
kono
parents:
diff changeset
350 for J in Stack'Range loop
kono
parents:
diff changeset
351 if Stack (J) /= Analyzer.Pattern then
kono
parents:
diff changeset
352 Analyzer.Topmost_Touched_Mark :=
kono
parents:
diff changeset
353 To_Stack_Address (Stack (J)'Address);
kono
parents:
diff changeset
354 exit;
kono
parents:
diff changeset
355 end if;
kono
parents:
diff changeset
356 end loop;
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 else
kono
parents:
diff changeset
359 for J in reverse Stack'Range loop
kono
parents:
diff changeset
360 if Stack (J) /= Analyzer.Pattern then
kono
parents:
diff changeset
361 Analyzer.Topmost_Touched_Mark :=
kono
parents:
diff changeset
362 To_Stack_Address (Stack (J)'Address);
kono
parents:
diff changeset
363 exit;
kono
parents:
diff changeset
364 end if;
kono
parents:
diff changeset
365 end loop;
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 end if;
kono
parents:
diff changeset
368 end Compute_Result;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 ---------------------
kono
parents:
diff changeset
371 -- Output_Result --
kono
parents:
diff changeset
372 ---------------------
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 procedure Output_Result
kono
parents:
diff changeset
375 (Result_Id : Natural;
kono
parents:
diff changeset
376 Result : Task_Result;
kono
parents:
diff changeset
377 Max_Stack_Size_Len : Natural;
kono
parents:
diff changeset
378 Max_Actual_Use_Len : Natural)
kono
parents:
diff changeset
379 is
kono
parents:
diff changeset
380 Result_Id_Str : constant String := Natural'Image (Result_Id);
kono
parents:
diff changeset
381 Stack_Size_Str : constant String := Natural'Image (Result.Stack_Size);
kono
parents:
diff changeset
382 Actual_Use_Str : constant String := Natural'Image (Result.Value);
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 Result_Id_Blanks : constant
kono
parents:
diff changeset
385 String (1 .. Index_Str'Length - Result_Id_Str'Length) :=
kono
parents:
diff changeset
386 (others => ' ');
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 Stack_Size_Blanks : constant
kono
parents:
diff changeset
389 String (1 .. Max_Stack_Size_Len - Stack_Size_Str'Length) :=
kono
parents:
diff changeset
390 (others => ' ');
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 Actual_Use_Blanks : constant
kono
parents:
diff changeset
393 String (1 .. Max_Actual_Use_Len - Actual_Use_Str'Length) :=
kono
parents:
diff changeset
394 (others => ' ');
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 begin
kono
parents:
diff changeset
397 Set_Output (Standard_Error);
kono
parents:
diff changeset
398 Put (Result_Id_Blanks & Natural'Image (Result_Id));
kono
parents:
diff changeset
399 Put (" | ");
kono
parents:
diff changeset
400 Put (Result.Task_Name);
kono
parents:
diff changeset
401 Put (" | ");
kono
parents:
diff changeset
402 Put (Stack_Size_Blanks & Stack_Size_Str);
kono
parents:
diff changeset
403 Put (" | ");
kono
parents:
diff changeset
404 Put (Actual_Use_Blanks & Actual_Use_Str);
kono
parents:
diff changeset
405 New_Line;
kono
parents:
diff changeset
406 end Output_Result;
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 ---------------------
kono
parents:
diff changeset
409 -- Output_Results --
kono
parents:
diff changeset
410 ---------------------
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 procedure Output_Results is
kono
parents:
diff changeset
413 Max_Stack_Size : Natural := 0;
kono
parents:
diff changeset
414 Max_Stack_Usage : Natural := 0;
kono
parents:
diff changeset
415 Max_Stack_Size_Len, Max_Actual_Use_Len : Natural := 0;
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 Task_Name_Blanks : constant
kono
parents:
diff changeset
418 String
kono
parents:
diff changeset
419 (1 .. Task_Name_Length - Task_Name_Str'Length) :=
kono
parents:
diff changeset
420 (others => ' ');
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 begin
kono
parents:
diff changeset
423 Set_Output (Standard_Error);
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 if Compute_Environment_Task then
kono
parents:
diff changeset
426 Compute_Result (Environment_Task_Analyzer);
kono
parents:
diff changeset
427 Report_Result (Environment_Task_Analyzer);
kono
parents:
diff changeset
428 end if;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 if Result_Array'Length > 0 then
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 -- Computes the size of the largest strings that will get displayed,
kono
parents:
diff changeset
433 -- in order to do correct column alignment.
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 for J in Result_Array'Range loop
kono
parents:
diff changeset
436 exit when J >= Next_Id;
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 if Result_Array (J).Value > Max_Stack_Usage then
kono
parents:
diff changeset
439 Max_Stack_Usage := Result_Array (J).Value;
kono
parents:
diff changeset
440 end if;
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 if Result_Array (J).Stack_Size > Max_Stack_Size then
kono
parents:
diff changeset
443 Max_Stack_Size := Result_Array (J).Stack_Size;
kono
parents:
diff changeset
444 end if;
kono
parents:
diff changeset
445 end loop;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 Max_Stack_Size_Len := Natural'Image (Max_Stack_Size)'Length;
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 Max_Actual_Use_Len := Natural'Image (Max_Stack_Usage)'Length;
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 -- Display the output header. Blanks will be added in front of the
kono
parents:
diff changeset
452 -- labels if needed.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 declare
kono
parents:
diff changeset
455 Stack_Size_Blanks : constant
kono
parents:
diff changeset
456 String (1 .. Max_Stack_Size_Len -
kono
parents:
diff changeset
457 Stack_Size_Str'Length) :=
kono
parents:
diff changeset
458 (others => ' ');
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 Stack_Usage_Blanks : constant
kono
parents:
diff changeset
461 String (1 .. Max_Actual_Use_Len -
kono
parents:
diff changeset
462 Actual_Size_Str'Length) :=
kono
parents:
diff changeset
463 (others => ' ');
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 begin
kono
parents:
diff changeset
466 if Stack_Size_Str'Length > Max_Stack_Size_Len then
kono
parents:
diff changeset
467 Max_Stack_Size_Len := Stack_Size_Str'Length;
kono
parents:
diff changeset
468 end if;
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 if Actual_Size_Str'Length > Max_Actual_Use_Len then
kono
parents:
diff changeset
471 Max_Actual_Use_Len := Actual_Size_Str'Length;
kono
parents:
diff changeset
472 end if;
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 Put
kono
parents:
diff changeset
475 (Index_Str & " | " & Task_Name_Str & Task_Name_Blanks & " | "
kono
parents:
diff changeset
476 & Stack_Size_Str & Stack_Size_Blanks & " | "
kono
parents:
diff changeset
477 & Stack_Usage_Blanks & Actual_Size_Str);
kono
parents:
diff changeset
478 end;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 New_Line;
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 -- Now display the individual results
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 for J in Result_Array'Range loop
kono
parents:
diff changeset
485 exit when J >= Next_Id;
kono
parents:
diff changeset
486 Output_Result
kono
parents:
diff changeset
487 (J, Result_Array (J), Max_Stack_Size_Len, Max_Actual_Use_Len);
kono
parents:
diff changeset
488 end loop;
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 -- Case of no result stored, still display the labels
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 else
kono
parents:
diff changeset
493 Put
kono
parents:
diff changeset
494 (Index_Str & " | " & Task_Name_Str & Task_Name_Blanks & " | "
kono
parents:
diff changeset
495 & Stack_Size_Str & " | " & Actual_Size_Str);
kono
parents:
diff changeset
496 New_Line;
kono
parents:
diff changeset
497 end if;
kono
parents:
diff changeset
498 end Output_Results;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 -------------------
kono
parents:
diff changeset
501 -- Report_Result --
kono
parents:
diff changeset
502 -------------------
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 procedure Report_Result (Analyzer : Stack_Analyzer) is
kono
parents:
diff changeset
505 Result : Task_Result := (Task_Name => Analyzer.Task_Name,
kono
parents:
diff changeset
506 Stack_Size => Analyzer.Stack_Size,
kono
parents:
diff changeset
507 Value => 0);
kono
parents:
diff changeset
508 begin
kono
parents:
diff changeset
509 if Analyzer.Pattern_Size = 0 then
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- If we have that result, it means that we didn't do any computation
kono
parents:
diff changeset
512 -- at all (i.e. we used at least everything (and possibly more).
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 Result.Value := Analyzer.Stack_Size;
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 else
kono
parents:
diff changeset
517 Result.Value := Stack_Size (Analyzer.Topmost_Touched_Mark,
kono
parents:
diff changeset
518 Analyzer.Stack_Base);
kono
parents:
diff changeset
519 end if;
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 if Analyzer.Result_Id in Result_Array'Range then
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 -- If the result can be stored, then store it in Result_Array
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 Result_Array (Analyzer.Result_Id) := Result;
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 else
kono
parents:
diff changeset
528 -- If the result cannot be stored, then we display it right away
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 declare
kono
parents:
diff changeset
531 Result_Str_Len : constant Natural :=
kono
parents:
diff changeset
532 Natural'Image (Result.Value)'Length;
kono
parents:
diff changeset
533 Size_Str_Len : constant Natural :=
kono
parents:
diff changeset
534 Natural'Image (Analyzer.Stack_Size)'Length;
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 Max_Stack_Size_Len : Natural;
kono
parents:
diff changeset
537 Max_Actual_Use_Len : Natural;
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 begin
kono
parents:
diff changeset
540 -- Take either the label size or the number image size for the
kono
parents:
diff changeset
541 -- size of the column "Stack Size".
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 Max_Stack_Size_Len :=
kono
parents:
diff changeset
544 (if Size_Str_Len > Stack_Size_Str'Length
kono
parents:
diff changeset
545 then Size_Str_Len
kono
parents:
diff changeset
546 else Stack_Size_Str'Length);
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 -- Take either the label size or the number image size for the
kono
parents:
diff changeset
549 -- size of the column "Stack Usage".
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 Max_Actual_Use_Len :=
kono
parents:
diff changeset
552 (if Result_Str_Len > Actual_Size_Str'Length
kono
parents:
diff changeset
553 then Result_Str_Len
kono
parents:
diff changeset
554 else Actual_Size_Str'Length);
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 Output_Result
kono
parents:
diff changeset
557 (Analyzer.Result_Id,
kono
parents:
diff changeset
558 Result,
kono
parents:
diff changeset
559 Max_Stack_Size_Len,
kono
parents:
diff changeset
560 Max_Actual_Use_Len);
kono
parents:
diff changeset
561 end;
kono
parents:
diff changeset
562 end if;
kono
parents:
diff changeset
563 end Report_Result;
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 end System.Stack_Usage;