OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[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-2001 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 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
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 with Ada.Text_IO;             use Ada.Text_IO;
40
41 package Memroot is
42
43    --  Work with instrumented allocation routines
44    Gmem_Mode  : Boolean := False;
45
46    --  Simple abstract type for names. A name is a sequence of letters.
47
48    type Name_Id is new Natural;
49    No_Name_Id : constant Name_Id := 0;
50
51    function Enter_Name (S : String) return Name_Id;
52    function Image      (N : Name_Id) return String;
53
54    --  Simple abstract type for a backtrace frame. A frame is composed by
55    --  a subprogram name, a file name and a line reference.
56
57    type Frame_Id is new Natural;
58    No_Frame_Id : constant Frame_Id := 0;
59
60    function Enter_Frame (Name, File, Line : Name_Id) return Frame_Id;
61
62    type Frame_Array is array (Natural range <>) of Frame_Id;
63
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.
68
69    type Root_Id is new Natural;
70    No_Root_Id : constant Root_Id := 0;
71
72    function Read_BT (BT_Depth : Integer; FT : File_Type) return Root_Id;
73    --  Read a backtrace from file FT whose maximum frame number is given by
74    --  BT_Depth and returns the corresponding Allocation root.
75
76    function Enter_Root  (Fr : Frame_Array) return Root_Id;
77    --  Create an allocation root from the frames that compose it
78
79    function Frames_Of   (B  : Root_Id) return Frame_Array;
80    --  Retreives the Frames of the root's backtrace
81
82    procedure Print_BT (B  : Root_Id);
83    --  Prints on standard out the backtrace associated with the root B
84
85    function Get_First return Root_Id;
86    function Get_Next  return Root_Id;
87    --  Iterator to iterate over roots
88
89    procedure Set_Nb_Alloc (B : Root_Id; V : Integer);
90    function      Nb_Alloc (B : Root_Id) return Integer;
91    --  Access and modify the number of allocation counter associated with
92    --  this allocation root. If the value is negative, it means that this is
93    --  not an allocation root but a deallocation root (this can only happen
94    --  in erroneous situations where there are more frees than allocations).
95
96    procedure Set_Alloc_Size (B : Root_Id; V : Storage_Count);
97    function      Alloc_Size (B : Root_Id) return Storage_Count;
98    --  Access and modify the total allocated memory counter associated with
99    --  this allocation root.
100
101    procedure Set_High_Water_Mark (B : Root_Id; V : Storage_Count);
102    function  High_Water_Mark     (B : Root_Id) return Storage_Count;
103    --  Access and modify the high water mark associated with this
104    --  allocation root. The high water mark is the maximum value, over
105    --  time, of the Alloc_Size.
106
107 end Memroot;