FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / memroot.ads
blob5df16ad55eb73f4a40251e889419325f5dcbb38d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M E M R O O T --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1997-2001 Ada Core Technologies, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 -- This package offers basic types that deal with gdb backtraces related
29 -- to memory allocation. A memory root (root_id) is a backtrace
30 -- referencing the actual point of allocation along with counters
31 -- recording various information concerning allocation at this root.
33 -- A back trace is composed of Frames (Frame_Id) which themselves are
34 -- nothing else than a subprogram call at a source location which can be
35 -- represented by three strings: subprogram name, file name and line
36 -- number. All the needed strings are entered in a table and referenced
37 -- through a Name_Id in order to avoid duplication.
39 with System.Storage_Elements; use System.Storage_Elements;
40 with Ada.Text_IO; use Ada.Text_IO;
42 package Memroot is
44 -- Work with instrumented allocation routines
45 Gmem_Mode : Boolean := False;
47 -- Simple abstract type for names. A name is a sequence of letters.
49 type Name_Id is new Natural;
50 No_Name_Id : constant Name_Id := 0;
52 function Enter_Name (S : String) return Name_Id;
53 function Image (N : Name_Id) return String;
55 -- Simple abstract type for a backtrace frame. A frame is composed by
56 -- a subprogram name, a file name and a line reference.
58 type Frame_Id is new Natural;
59 No_Frame_Id : constant Frame_Id := 0;
61 function Enter_Frame (Name, File, Line : Name_Id) return Frame_Id;
63 type Frame_Array is array (Natural range <>) of Frame_Id;
65 -- Simple abstract type for an allocation root. It is composed by a set
66 -- of frames, the number of allocation, the total size of allocated
67 -- memory, and the high water mark. An iterator is also provided to
68 -- iterate over all the entered allocation roots.
70 type Root_Id is new Natural;
71 No_Root_Id : constant Root_Id := 0;
73 function Read_BT (BT_Depth : Integer; FT : File_Type) return Root_Id;
74 -- Read a backtrace from file FT whose maximum frame number is given by
75 -- BT_Depth and returns the corresponding Allocation root.
77 function Enter_Root (Fr : Frame_Array) return Root_Id;
78 -- Create an allocation root from the frames that compose it
80 function Frames_Of (B : Root_Id) return Frame_Array;
81 -- Retreives the Frames of the root's backtrace
83 procedure Print_BT (B : Root_Id);
84 -- Prints on standard out the backtrace associated with the root B
86 function Get_First return Root_Id;
87 function Get_Next return Root_Id;
88 -- Iterator to iterate over roots
90 procedure Set_Nb_Alloc (B : Root_Id; V : Integer);
91 function Nb_Alloc (B : Root_Id) return Integer;
92 -- Access and modify the number of allocation counter associated with
93 -- this allocation root. If the value is negative, it means that this is
94 -- not an allocation root but a deallocation root (this can only happen
95 -- in erroneous situations where there are more frees than allocations).
97 procedure Set_Alloc_Size (B : Root_Id; V : Storage_Count);
98 function Alloc_Size (B : Root_Id) return Storage_Count;
99 -- Access and modify the total allocated memory counter associated with
100 -- this allocation root.
102 procedure Set_High_Water_Mark (B : Root_Id; V : Storage_Count);
103 function High_Water_Mark (B : Root_Id) return Storage_Count;
104 -- Access and modify the high water mark associated with this
105 -- allocation root. The high water mark is the maximum value, over
106 -- time, of the Alloc_Size.
108 end Memroot;