1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1997-2001 Ada Core Technologies, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This package offers basic types that deal with gdb backtraces related
30 -- to memory allocation. A memory root (root_id) is a backtrace
31 -- referencing the actual point of allocation along with counters
32 -- recording various information concerning allocation at this root.
34 -- A back trace is composed of Frames (Frame_Id) which themselves are
35 -- nothing else than a subprogram call at a source location which can be
36 -- represented by three strings: subprogram name, file name and line
37 -- number. All the needed strings are entered in a table and referenced
38 -- through a Name_Id in order to avoid duplication.
40 with System.Storage_Elements; use System.Storage_Elements;
41 with Ada.Text_IO; use Ada.Text_IO;
45 -- Work with instrumented allocation routines
46 Gmem_Mode : Boolean := False;
48 -- Simple abstract type for names. A name is a sequence of letters.
50 type Name_Id is new Natural;
51 No_Name_Id : constant Name_Id := 0;
53 function Enter_Name (S : String) return Name_Id;
54 function Image (N : Name_Id) return String;
56 -- Simple abstract type for a backtrace frame. A frame is composed by
57 -- a subprogram name, a file name and a line reference.
59 type Frame_Id is new Natural;
60 No_Frame_Id : constant Frame_Id := 0;
62 function Enter_Frame (Name, File, Line : Name_Id) return Frame_Id;
64 type Frame_Array is array (Natural range <>) of Frame_Id;
66 -- Simple abstract type for an allocation root. It is composed by a set
67 -- of frames, the number of allocation, the total size of allocated
68 -- memory, and the high water mark. An iterator is also provided to
69 -- iterate over all the entered allocation roots.
71 type Root_Id is new Natural;
72 No_Root_Id : constant Root_Id := 0;
74 function Read_BT (BT_Depth : Integer; FT : File_Type) return Root_Id;
75 -- Read a backtrace from file FT whose maximum frame number is given by
76 -- BT_Depth and returns the corresponding Allocation root.
78 function Enter_Root (Fr : Frame_Array) return Root_Id;
79 -- Create an allocation root from the frames that compose it
81 function Frames_Of (B : Root_Id) return Frame_Array;
82 -- Retreives the Frames of the root's backtrace
84 procedure Print_BT (B : Root_Id);
85 -- Prints on standard out the backtrace associated with the root B
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.