1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1997-2008, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package offers basic types that deal with gdb backtraces related
27 -- to memory allocation. A memory root (root_id) is a backtrace
28 -- referencing the actual point of allocation along with counters
29 -- recording various information concerning allocation at this root.
31 -- A back trace is composed of Frames (Frame_Id) which themselves are
32 -- nothing else than a subprogram call at a source location which can be
33 -- represented by three strings: subprogram name, file name and line
34 -- number. All the needed strings are entered in a table and referenced
35 -- through a Name_Id in order to avoid duplication.
37 with System
.Storage_Elements
; use System
.Storage_Elements
;
41 -- Simple abstract type for names. A name is a sequence of letters
43 type Name_Id
is new Natural;
44 No_Name_Id
: constant Name_Id
:= 0;
46 function Enter_Name
(S
: String) return Name_Id
;
47 function Image
(N
: Name_Id
) return String;
49 -- Simple abstract type for a backtrace frame. A frame is composed by
50 -- a subprogram name, a file name and a line reference.
52 type Frame_Id
is new Natural;
53 No_Frame_Id
: constant Frame_Id
:= 0;
56 (Addr
: System
.Address
;
62 type Frame_Array
is array (Natural range <>) of Frame_Id
;
64 -- Simple abstract type for an allocation root. It is composed by a set
65 -- of frames, the number of allocation, the total size of allocated
66 -- memory, and the high water mark. An iterator is also provided to
67 -- iterate over all the entered allocation roots.
69 type Root_Id
is new Natural;
70 No_Root_Id
: constant Root_Id
:= 0;
72 function Read_BT
(BT_Depth
: Integer) return Root_Id
;
73 -- Reads a backtrace whose maximum frame number is given by
74 -- BT_Depth and returns the corresponding Allocation root.
76 function Enter_Root
(Fr
: Frame_Array
) return Root_Id
;
77 -- Create an allocation root from the frames that compose it
79 function Frames_Of
(B
: Root_Id
) return Frame_Array
;
80 -- Retrieves the Frames of the root's backtrace
82 procedure Print_BT
(B
: Root_Id
; Short
: Boolean := False);
83 -- Prints on standard out the backtrace associated with the root B
84 -- When Short is set to True, only the filename & line info is printed.
85 -- When it is set to false, the subprogram name is also printed.
87 function Get_First
return Root_Id
;
88 function Get_Next
return Root_Id
;
89 -- Iterator to iterate over roots
91 procedure Set_Nb_Alloc
(B
: Root_Id
; V
: Integer);
92 function Nb_Alloc
(B
: Root_Id
) return Integer;
93 -- Access and modify the number of allocation counter associated with
94 -- this allocation root. If the value is negative, it means that this is
95 -- not an allocation root but a deallocation root (this can only happen
96 -- in erroneous situations where there are more frees than allocations).
98 procedure Set_Alloc_Size
(B
: Root_Id
; V
: Storage_Count
);
99 function Alloc_Size
(B
: Root_Id
) return Storage_Count
;
100 -- Access and modify the total allocated memory counter associated with
101 -- this allocation root.
103 procedure Set_High_Water_Mark
(B
: Root_Id
; V
: Storage_Count
);
104 function High_Water_Mark
(B
: Root_Id
) return Storage_Count
;
105 -- Access and modify the high water mark associated with this
106 -- allocation root. The high water mark is the maximum value, over
107 -- time, of the Alloc_Size.