OSDN Git Service

PR bootstrap/11932
[pf3gnuchains/gcc-fork.git] / gcc / ada / memroot.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              M E M R O O T                               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --            Copyright (C) 1997-2003 Ada Core Technologies, Inc.           --
10 --                                                                          --
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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This package offers basic types that deal with gdb backtraces related
28 --  to memory allocation. A memory root (root_id) is a backtrace
29 --  referencing the actual point of allocation along with counters
30 --  recording various information concerning allocation at this root.
31
32 --  A back trace is composed of Frames (Frame_Id) which themselves are
33 --  nothing else than a subprogram call at a source location which can be
34 --  represented by three strings: subprogram name, file name and line
35 --  number. All the needed strings are entered in a table and referenced
36 --  through a Name_Id in order to avoid duplication.
37
38 with System.Storage_Elements; use System.Storage_Elements;
39
40 package Memroot is
41
42    --  Simple abstract type for names. A name is a sequence of letters.
43
44    type Name_Id is new Natural;
45    No_Name_Id : constant Name_Id := 0;
46
47    function Enter_Name (S : String) return Name_Id;
48    function Image      (N : Name_Id) return String;
49
50    --  Simple abstract type for a backtrace frame. A frame is composed by
51    --  a subprogram name, a file name and a line reference.
52
53    type Frame_Id is new Natural;
54    No_Frame_Id : constant Frame_Id := 0;
55
56    function Enter_Frame
57      (Addr : System.Address;
58       Name : Name_Id;
59       File : Name_Id;
60       Line : Name_Id)
61       return Frame_Id;
62
63    type Frame_Array is array (Natural range <>) of Frame_Id;
64
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.
69
70    type Root_Id is new Natural;
71    No_Root_Id : constant Root_Id := 0;
72
73    function Read_BT (BT_Depth : Integer) return Root_Id;
74    --  Reads a backtrace whose maximum frame number is given by
75    --  BT_Depth and returns the corresponding Allocation root.
76
77    function Enter_Root  (Fr : Frame_Array) return Root_Id;
78    --  Create an allocation root from the frames that compose it
79
80    function Frames_Of   (B  : Root_Id) return Frame_Array;
81    --  Retreives the Frames of the root's backtrace
82
83    procedure Print_BT (B  : Root_Id; Short : Boolean := False);
84    --  Prints on standard out the backtrace associated with the root B
85    --  When Short is set to True, only the filename & line info is printed.
86    --  When it is set to false, the subprogram name is also printed.
87
88    function Get_First return Root_Id;
89    function Get_Next  return Root_Id;
90    --  Iterator to iterate over roots
91
92    procedure Set_Nb_Alloc (B : Root_Id; V : Integer);
93    function      Nb_Alloc (B : Root_Id) return Integer;
94    --  Access and modify the number of allocation counter associated with
95    --  this allocation root. If the value is negative, it means that this is
96    --  not an allocation root but a deallocation root (this can only happen
97    --  in erroneous situations where there are more frees than allocations).
98
99    procedure Set_Alloc_Size (B : Root_Id; V : Storage_Count);
100    function      Alloc_Size (B : Root_Id) return Storage_Count;
101    --  Access and modify the total allocated memory counter associated with
102    --  this allocation root.
103
104    procedure Set_High_Water_Mark (B : Root_Id; V : Storage_Count);
105    function  High_Water_Mark     (B : Root_Id) return Storage_Count;
106    --  Access and modify the high water mark associated with this
107    --  allocation root. The high water mark is the maximum value, over
108    --  time, of the Alloc_Size.
109
110 end Memroot;