annotate gcc/ada/libgnat/g-debpoo.ads @ 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 -- G N A T . D E B U G _ P O O L S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
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 packages provides a special implementation of the Ada 95 storage pools
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- The goal of this debug pool is to detect incorrect uses of memory
kono
parents:
diff changeset
35 -- (multiple deallocations, access to invalid memory,...). Errors are reported
kono
parents:
diff changeset
36 -- in one of two ways: either by immediately raising an exception, or by
kono
parents:
diff changeset
37 -- printing a message on standard output or standard error.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- You need to instrument your code to use this package: for each access type
kono
parents:
diff changeset
40 -- you want to monitor, you need to add a clause similar to:
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- type Integer_Access is access Integer;
kono
parents:
diff changeset
43 -- for Integer_Access'Storage_Pool use Pool;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 -- where Pool is a tagged object declared with
kono
parents:
diff changeset
46 --
kono
parents:
diff changeset
47 -- Pool : GNAT.Debug_Pools.Debug_Pool;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- This package was designed to be as efficient as possible, but still has an
kono
parents:
diff changeset
50 -- impact on the performance of your code, which depends on the number of
kono
parents:
diff changeset
51 -- allocations, deallocations and, somewhat less, dereferences that your
kono
parents:
diff changeset
52 -- application performs.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 -- For each faulty memory use, this debug pool will print several lines
kono
parents:
diff changeset
55 -- of information, including things like the location where the memory
kono
parents:
diff changeset
56 -- was initially allocated, the location where it was freed etc.
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- Physical allocations and deallocations are done through the usual system
kono
parents:
diff changeset
59 -- calls. However, in order to provide proper checks, the debug pool will not
kono
parents:
diff changeset
60 -- release the memory immediately. It keeps released memory around (the amount
kono
parents:
diff changeset
61 -- kept around is configurable) so that it can distinguish between memory that
kono
parents:
diff changeset
62 -- has not been allocated and memory that has been allocated but freed. This
kono
parents:
diff changeset
63 -- also means that this memory cannot be reallocated, preventing what would
kono
parents:
diff changeset
64 -- otherwise be a false indication that freed memory is now allocated.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -- In addition, this package presents several subprograms that help analyze
kono
parents:
diff changeset
67 -- the behavior of your program, by reporting memory leaks, the total amount
kono
parents:
diff changeset
68 -- of memory that was allocated. The pool is also designed to work correctly
kono
parents:
diff changeset
69 -- in conjunction with gnatmem.
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 -- Finally, a subprogram Print_Pool is provided for use from the debugger
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 -- Limitations
kono
parents:
diff changeset
74 -- ===========
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- Current limitation of this debug pool: if you use this debug pool for a
kono
parents:
diff changeset
77 -- general access type ("access all"), the pool might report invalid
kono
parents:
diff changeset
78 -- dereferences if the access object is pointing to another object on the
kono
parents:
diff changeset
79 -- stack which was not allocated through a call to "new".
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- This debug pool will respect all alignments specified in your code, but
kono
parents:
diff changeset
82 -- it does that by aligning all objects using Standard'Maximum_Alignment.
kono
parents:
diff changeset
83 -- This allows faster checks, and limits the performance impact of using
kono
parents:
diff changeset
84 -- this pool.
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 with System; use System;
kono
parents:
diff changeset
87 with System.Storage_Elements; use System.Storage_Elements;
kono
parents:
diff changeset
88 with System.Checked_Pools;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 package GNAT.Debug_Pools is
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 type Debug_Pool is new System.Checked_Pools.Checked_Pool with private;
kono
parents:
diff changeset
93 -- The new debug pool
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 subtype SSC is System.Storage_Elements.Storage_Count;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Default_Max_Freed : constant SSC := 50_000_000;
kono
parents:
diff changeset
98 Default_Stack_Trace_Depth : constant Natural := 20;
kono
parents:
diff changeset
99 Default_Reset_Content : constant Boolean := False;
kono
parents:
diff changeset
100 Default_Raise_Exceptions : constant Boolean := True;
kono
parents:
diff changeset
101 Default_Advanced_Scanning : constant Boolean := False;
kono
parents:
diff changeset
102 Default_Min_Freed : constant SSC := 0;
kono
parents:
diff changeset
103 Default_Errors_To_Stdout : constant Boolean := True;
kono
parents:
diff changeset
104 Default_Low_Level_Traces : constant Boolean := False;
kono
parents:
diff changeset
105 -- The above values are constants used for the parameters to Configure
kono
parents:
diff changeset
106 -- if not overridden in the call. See description of Configure for full
kono
parents:
diff changeset
107 -- details on these parameters. If these defaults are not satisfactory,
kono
parents:
diff changeset
108 -- then you need to call Configure to change the default values.
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 procedure Configure
kono
parents:
diff changeset
111 (Pool : in out Debug_Pool;
kono
parents:
diff changeset
112 Stack_Trace_Depth : Natural := Default_Stack_Trace_Depth;
kono
parents:
diff changeset
113 Maximum_Logically_Freed_Memory : SSC := Default_Max_Freed;
kono
parents:
diff changeset
114 Minimum_To_Free : SSC := Default_Min_Freed;
kono
parents:
diff changeset
115 Reset_Content_On_Free : Boolean := Default_Reset_Content;
kono
parents:
diff changeset
116 Raise_Exceptions : Boolean := Default_Raise_Exceptions;
kono
parents:
diff changeset
117 Advanced_Scanning : Boolean := Default_Advanced_Scanning;
kono
parents:
diff changeset
118 Errors_To_Stdout : Boolean := Default_Errors_To_Stdout;
kono
parents:
diff changeset
119 Low_Level_Traces : Boolean := Default_Low_Level_Traces);
kono
parents:
diff changeset
120 -- Subprogram used to configure the debug pool.
kono
parents:
diff changeset
121 --
kono
parents:
diff changeset
122 -- Stack_Trace_Depth. This parameter controls the maximum depth of stack
kono
parents:
diff changeset
123 -- traces that are output to indicate locations of actions for error
kono
parents:
diff changeset
124 -- conditions such as bad allocations. If set to zero, the debug pool
kono
parents:
diff changeset
125 -- will not try to compute backtraces. This is more efficient but gives
kono
parents:
diff changeset
126 -- less information on problem locations
kono
parents:
diff changeset
127 --
kono
parents:
diff changeset
128 -- Maximum_Logically_Freed_Memory: maximum amount of memory (bytes)
kono
parents:
diff changeset
129 -- that should be kept before starting to physically deallocate some.
kono
parents:
diff changeset
130 -- This value should be non-zero, since having memory that is logically
kono
parents:
diff changeset
131 -- but not physically freed helps to detect invalid memory accesses.
kono
parents:
diff changeset
132 --
kono
parents:
diff changeset
133 -- Minimum_To_Free is the minimum amount of memory that should be freed
kono
parents:
diff changeset
134 -- every time the pool starts physically releasing memory. The algorithm
kono
parents:
diff changeset
135 -- to compute which block should be physically released needs some
kono
parents:
diff changeset
136 -- expensive initialization (see Advanced_Scanning below), and this
kono
parents:
diff changeset
137 -- parameter can be used to limit the performance impact by ensuring
kono
parents:
diff changeset
138 -- that a reasonable amount of memory is freed each time. Even in the
kono
parents:
diff changeset
139 -- advanced scanning mode, marked blocks may be released to match this
kono
parents:
diff changeset
140 -- Minimum_To_Free parameter.
kono
parents:
diff changeset
141 --
kono
parents:
diff changeset
142 -- Reset_Content_On_Free: If true, then the contents of the freed memory
kono
parents:
diff changeset
143 -- is reset to the pattern 16#DEADBEEF#, following an old IBM convention.
kono
parents:
diff changeset
144 -- This helps in detecting invalid memory references from the debugger.
kono
parents:
diff changeset
145 --
kono
parents:
diff changeset
146 -- Raise_Exceptions: If true, the exceptions below will be raised every
kono
parents:
diff changeset
147 -- time an error is detected. If you set this to False, then the action
kono
parents:
diff changeset
148 -- is to generate output on standard error or standard output, depending
kono
parents:
diff changeset
149 -- on Errors_To_Stdout, noting the errors, but to
kono
parents:
diff changeset
150 -- keep running if possible (of course if storage is badly damaged, this
kono
parents:
diff changeset
151 -- attempt may fail. This helps to detect more than one error in a run.
kono
parents:
diff changeset
152 --
kono
parents:
diff changeset
153 -- Advanced_Scanning: If true, the pool will check the contents of all
kono
parents:
diff changeset
154 -- allocated blocks before physically releasing memory. Any possible
kono
parents:
diff changeset
155 -- reference to a logically free block will prevent its deallocation.
kono
parents:
diff changeset
156 -- Note that this algorithm is approximate, and it is recommended
kono
parents:
diff changeset
157 -- that you set Minimum_To_Free to a non-zero value to save time.
kono
parents:
diff changeset
158 --
kono
parents:
diff changeset
159 -- Errors_To_Stdout: Errors messages will be displayed on stdout if
kono
parents:
diff changeset
160 -- this parameter is True, or to stderr otherwise.
kono
parents:
diff changeset
161 --
kono
parents:
diff changeset
162 -- Low_Level_Traces: Traces all allocation and deallocations on the
kono
parents:
diff changeset
163 -- stream specified by Errors_To_Stdout. This can be used for
kono
parents:
diff changeset
164 -- post-processing by your own application, or to debug the
kono
parents:
diff changeset
165 -- debug_pool itself. The output indicates the size of the allocated
kono
parents:
diff changeset
166 -- block both as requested by the application and as physically
kono
parents:
diff changeset
167 -- allocated to fit the additional information needed by the debug
kono
parents:
diff changeset
168 -- pool.
kono
parents:
diff changeset
169 --
kono
parents:
diff changeset
170 -- All instantiations of this pool use the same internal tables. However,
kono
parents:
diff changeset
171 -- they do not store the same amount of information for the tracebacks,
kono
parents:
diff changeset
172 -- and they have different counters for maximum logically freed memory.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Accessing_Not_Allocated_Storage : exception;
kono
parents:
diff changeset
175 -- Exception raised if Raise_Exception is True, and an attempt is made
kono
parents:
diff changeset
176 -- to access storage that was never allocated.
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 Accessing_Deallocated_Storage : exception;
kono
parents:
diff changeset
179 -- Exception raised if Raise_Exception is True, and an attempt is made
kono
parents:
diff changeset
180 -- to access storage that was allocated but has been deallocated.
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 Freeing_Not_Allocated_Storage : exception;
kono
parents:
diff changeset
183 -- Exception raised if Raise_Exception is True, and an attempt is made
kono
parents:
diff changeset
184 -- to free storage that had not been previously allocated.
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Freeing_Deallocated_Storage : exception;
kono
parents:
diff changeset
187 -- Exception raised if Raise_Exception is True, and an attempt is made
kono
parents:
diff changeset
188 -- to free storage that had already been freed.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 -- Note on the above exceptions. The distinction between not allocated
kono
parents:
diff changeset
191 -- and deallocated storage is not guaranteed to be accurate in the case
kono
parents:
diff changeset
192 -- where storage is allocated, and then physically freed. Larger values
kono
parents:
diff changeset
193 -- of the parameter Maximum_Logically_Freed_Memory will help to guarantee
kono
parents:
diff changeset
194 -- that this distinction is made more accurately.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 generic
kono
parents:
diff changeset
197 with procedure Put_Line (S : String) is <>;
kono
parents:
diff changeset
198 with procedure Put (S : String) is <>;
kono
parents:
diff changeset
199 procedure Print_Info
kono
parents:
diff changeset
200 (Pool : Debug_Pool;
kono
parents:
diff changeset
201 Cumulate : Boolean := False;
kono
parents:
diff changeset
202 Display_Slots : Boolean := False;
kono
parents:
diff changeset
203 Display_Leaks : Boolean := False);
kono
parents:
diff changeset
204 -- Print out information about the High Water Mark, the current and
kono
parents:
diff changeset
205 -- total number of bytes allocated and the total number of bytes
kono
parents:
diff changeset
206 -- deallocated.
kono
parents:
diff changeset
207 --
kono
parents:
diff changeset
208 -- If Display_Slots is true, this subprogram prints a list of all the
kono
parents:
diff changeset
209 -- locations in the application that have done at least one allocation or
kono
parents:
diff changeset
210 -- deallocation. The result might be used to detect places in the program
kono
parents:
diff changeset
211 -- where lots of allocations are taking place. This output is not in any
kono
parents:
diff changeset
212 -- defined order.
kono
parents:
diff changeset
213 --
kono
parents:
diff changeset
214 -- If Cumulate if True, then each stack trace will display the number of
kono
parents:
diff changeset
215 -- allocations that were done either directly, or by the subprograms called
kono
parents:
diff changeset
216 -- at that location (e.g: if there were two physical allocations at a->b->c
kono
parents:
diff changeset
217 -- and a->b->d, then a->b would be reported as performing two allocations).
kono
parents:
diff changeset
218 --
kono
parents:
diff changeset
219 -- If Display_Leaks is true, then each block that has not been deallocated
kono
parents:
diff changeset
220 -- (often called a "memory leak") will be listed, along with the traceback
kono
parents:
diff changeset
221 -- showing where it was allocated. Not that no grouping of the blocks is
kono
parents:
diff changeset
222 -- done, you should use the Dump_Gnatmem procedure below in conjunction
kono
parents:
diff changeset
223 -- with the gnatmem utility.
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 procedure Print_Info_Stdout
kono
parents:
diff changeset
226 (Pool : Debug_Pool;
kono
parents:
diff changeset
227 Cumulate : Boolean := False;
kono
parents:
diff changeset
228 Display_Slots : Boolean := False;
kono
parents:
diff changeset
229 Display_Leaks : Boolean := False);
kono
parents:
diff changeset
230 -- Standard instantiation of Print_Info to print on standard_output. More
kono
parents:
diff changeset
231 -- convenient to use where this is the intended location, and in particular
kono
parents:
diff changeset
232 -- easier to use from the debugger.
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 procedure Dump_Gnatmem (Pool : Debug_Pool; File_Name : String);
kono
parents:
diff changeset
235 -- Create an external file on the disk, which can be processed by gnatmem
kono
parents:
diff changeset
236 -- to display the location of memory leaks.
kono
parents:
diff changeset
237 --
kono
parents:
diff changeset
238 -- This provides a nicer output that Print_Info above, and groups similar
kono
parents:
diff changeset
239 -- stack traces together. This also provides an easy way to save the memory
kono
parents:
diff changeset
240 -- status of your program for post-mortem analysis.
kono
parents:
diff changeset
241 --
kono
parents:
diff changeset
242 -- To use this file, use the following command line:
kono
parents:
diff changeset
243 -- gnatmem 5 -i <File_Name> <Executable_Name>
kono
parents:
diff changeset
244 -- If you want all the stack traces to be displayed with 5 levels.
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 procedure Print_Pool (A : System.Address);
kono
parents:
diff changeset
247 pragma Export (C, Print_Pool, "print_pool");
kono
parents:
diff changeset
248 -- This subprogram is meant to be used from a debugger. Given an address in
kono
parents:
diff changeset
249 -- memory, it will print on standard output the known information about
kono
parents:
diff changeset
250 -- this address (provided, of course, the matching pointer is handled by
kono
parents:
diff changeset
251 -- the Debug_Pool).
kono
parents:
diff changeset
252 --
kono
parents:
diff changeset
253 -- The information includes the stacktrace for the allocation or
kono
parents:
diff changeset
254 -- deallocation of that memory chunk, its current status (allocated or
kono
parents:
diff changeset
255 -- logically freed), etc.
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 type Report_Type is
kono
parents:
diff changeset
258 (All_Reports,
kono
parents:
diff changeset
259 Memory_Usage,
kono
parents:
diff changeset
260 Allocations_Count,
kono
parents:
diff changeset
261 Sort_Total_Allocs,
kono
parents:
diff changeset
262 Marked_Blocks);
kono
parents:
diff changeset
263 for Report_Type use
kono
parents:
diff changeset
264 (All_Reports => 0,
kono
parents:
diff changeset
265 Memory_Usage => 1,
kono
parents:
diff changeset
266 Allocations_Count => 2,
kono
parents:
diff changeset
267 Sort_Total_Allocs => 3,
kono
parents:
diff changeset
268 Marked_Blocks => 4);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 generic
kono
parents:
diff changeset
271 with procedure Put_Line (S : String) is <>;
kono
parents:
diff changeset
272 with procedure Put (S : String) is <>;
kono
parents:
diff changeset
273 procedure Dump
kono
parents:
diff changeset
274 (Pool : Debug_Pool;
kono
parents:
diff changeset
275 Size : Positive;
kono
parents:
diff changeset
276 Report : Report_Type := All_Reports);
kono
parents:
diff changeset
277 -- Dump information about memory usage.
kono
parents:
diff changeset
278 -- Size is the number of the biggest memory users we want to show. Report
kono
parents:
diff changeset
279 -- indicates which sorting order is used in the report.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 procedure Dump_Stdout
kono
parents:
diff changeset
282 (Pool : Debug_Pool;
kono
parents:
diff changeset
283 Size : Positive;
kono
parents:
diff changeset
284 Report : Report_Type := All_Reports);
kono
parents:
diff changeset
285 -- Standard instantiation of Dump to print on standard_output. More
kono
parents:
diff changeset
286 -- convenient to use where this is the intended location, and in particular
kono
parents:
diff changeset
287 -- easier to use from the debugger.
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 procedure Reset;
kono
parents:
diff changeset
290 -- Reset all internal data. This is in general not needed, unless you want
kono
parents:
diff changeset
291 -- to know what memory is used by specific parts of your application
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 procedure Get_Size
kono
parents:
diff changeset
294 (Storage_Address : Address;
kono
parents:
diff changeset
295 Size_In_Storage_Elements : out Storage_Count;
kono
parents:
diff changeset
296 Valid : out Boolean);
kono
parents:
diff changeset
297 -- Set Valid if Storage_Address is the address of a chunk of memory
kono
parents:
diff changeset
298 -- currently allocated by any pool.
kono
parents:
diff changeset
299 -- If Valid is True, Size_In_Storage_Elements is set to the size of this
kono
parents:
diff changeset
300 -- chunk of memory.
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 type Byte_Count is mod System.Max_Binary_Modulus;
kono
parents:
diff changeset
303 -- Type used for maintaining byte counts, needs to be large enough to
kono
parents:
diff changeset
304 -- to accommodate counts allowing for repeated use of the same memory.
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 function High_Water_Mark
kono
parents:
diff changeset
307 (Pool : Debug_Pool) return Byte_Count;
kono
parents:
diff changeset
308 -- Return the highest size of the memory allocated by the pool.
kono
parents:
diff changeset
309 -- Memory used internally by the pool is not taken into account.
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 function Current_Water_Mark
kono
parents:
diff changeset
312 (Pool : Debug_Pool) return Byte_Count;
kono
parents:
diff changeset
313 -- Return the size of the memory currently allocated by the pool.
kono
parents:
diff changeset
314 -- Memory used internally by the pool is not taken into account.
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 procedure System_Memory_Debug_Pool
kono
parents:
diff changeset
317 (Has_Unhandled_Memory : Boolean := True);
kono
parents:
diff changeset
318 -- Let the package know the System.Memory is using it.
kono
parents:
diff changeset
319 -- If Has_Unhandled_Memory is true, some deallocation can be done for
kono
parents:
diff changeset
320 -- memory not allocated with Allocate.
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 private
kono
parents:
diff changeset
323 -- The following are the standard primitive subprograms for a pool
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 procedure Allocate
kono
parents:
diff changeset
326 (Pool : in out Debug_Pool;
kono
parents:
diff changeset
327 Storage_Address : out Address;
kono
parents:
diff changeset
328 Size_In_Storage_Elements : Storage_Count;
kono
parents:
diff changeset
329 Alignment : Storage_Count);
kono
parents:
diff changeset
330 -- Allocate a new chunk of memory, and set it up so that the debug pool
kono
parents:
diff changeset
331 -- can check accesses to its data, and report incorrect access later on.
kono
parents:
diff changeset
332 -- The parameters have the same semantics as defined in the ARM95.
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 procedure Deallocate
kono
parents:
diff changeset
335 (Pool : in out Debug_Pool;
kono
parents:
diff changeset
336 Storage_Address : Address;
kono
parents:
diff changeset
337 Size_In_Storage_Elements : Storage_Count;
kono
parents:
diff changeset
338 Alignment : Storage_Count);
kono
parents:
diff changeset
339 -- Mark a block of memory as invalid. It might not be physically removed
kono
parents:
diff changeset
340 -- immediately, depending on the setup of the debug pool, so that checks
kono
parents:
diff changeset
341 -- are still possible. The parameters have the same semantics as defined
kono
parents:
diff changeset
342 -- in the RM.
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 function Storage_Size (Pool : Debug_Pool) return SSC;
kono
parents:
diff changeset
345 -- Return the maximal size of data that can be allocated through Pool.
kono
parents:
diff changeset
346 -- Since Pool uses the malloc() system call, all the memory is accessible
kono
parents:
diff changeset
347 -- through the pool
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 procedure Dereference
kono
parents:
diff changeset
350 (Pool : in out Debug_Pool;
kono
parents:
diff changeset
351 Storage_Address : System.Address;
kono
parents:
diff changeset
352 Size_In_Storage_Elements : Storage_Count;
kono
parents:
diff changeset
353 Alignment : Storage_Count);
kono
parents:
diff changeset
354 -- Check whether a dereference statement is valid, i.e. whether the pointer
kono
parents:
diff changeset
355 -- was allocated through Pool. As documented above, errors will be
kono
parents:
diff changeset
356 -- reported either by a special error message or an exception, depending
kono
parents:
diff changeset
357 -- on the setup of the storage pool.
kono
parents:
diff changeset
358 -- The parameters have the same semantics as defined in the ARM95.
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 type Debug_Pool is new System.Checked_Pools.Checked_Pool with record
kono
parents:
diff changeset
361 Stack_Trace_Depth : Natural := Default_Stack_Trace_Depth;
kono
parents:
diff changeset
362 Maximum_Logically_Freed_Memory : SSC := Default_Max_Freed;
kono
parents:
diff changeset
363 Reset_Content_On_Free : Boolean := Default_Reset_Content;
kono
parents:
diff changeset
364 Raise_Exceptions : Boolean := Default_Raise_Exceptions;
kono
parents:
diff changeset
365 Minimum_To_Free : SSC := Default_Min_Freed;
kono
parents:
diff changeset
366 Advanced_Scanning : Boolean := Default_Advanced_Scanning;
kono
parents:
diff changeset
367 Errors_To_Stdout : Boolean := Default_Errors_To_Stdout;
kono
parents:
diff changeset
368 Low_Level_Traces : Boolean := Default_Low_Level_Traces;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 Alloc_Count : Byte_Count := 0;
kono
parents:
diff changeset
371 -- Total number of allocation
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 Free_Count : Byte_Count := 0;
kono
parents:
diff changeset
374 -- Total number of deallocation
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 Allocated : Byte_Count := 0;
kono
parents:
diff changeset
377 -- Total number of bytes allocated in this pool
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 Logically_Deallocated : Byte_Count := 0;
kono
parents:
diff changeset
380 -- Total number of bytes logically deallocated in this pool. This is the
kono
parents:
diff changeset
381 -- memory that the application has released, but that the pool has not
kono
parents:
diff changeset
382 -- yet physically released through a call to free(), to detect later
kono
parents:
diff changeset
383 -- accessed to deallocated memory.
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 Physically_Deallocated : Byte_Count := 0;
kono
parents:
diff changeset
386 -- Total number of bytes that were free()-ed
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 Marked_Blocks_Deallocated : Boolean := False;
kono
parents:
diff changeset
389 -- Set to true if some mark blocks had to be deallocated in the advanced
kono
parents:
diff changeset
390 -- scanning scheme. Since this is potentially dangerous, this is
kono
parents:
diff changeset
391 -- reported to the user, who might want to rerun his program with a
kono
parents:
diff changeset
392 -- lower Minimum_To_Free value.
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 High_Water : Byte_Count := 0;
kono
parents:
diff changeset
395 -- Maximum of Allocated - Logically_Deallocated - Physically_Deallocated
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 First_Free_Block : System.Address := System.Null_Address;
kono
parents:
diff changeset
398 Last_Free_Block : System.Address := System.Null_Address;
kono
parents:
diff changeset
399 -- Pointers to the first and last logically freed blocks
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 First_Used_Block : System.Address := System.Null_Address;
kono
parents:
diff changeset
402 -- Pointer to the list of currently allocated blocks. This list is
kono
parents:
diff changeset
403 -- used to list the memory leaks in the application on exit, as well as
kono
parents:
diff changeset
404 -- for the advanced freeing algorithms that needs to traverse all these
kono
parents:
diff changeset
405 -- blocks to find possible references to the block being physically
kono
parents:
diff changeset
406 -- freed.
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 end record;
kono
parents:
diff changeset
409 end GNAT.Debug_Pools;