annotate gcc/ada/libgnat/s-dwalin.ads @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . D W A R F _ L I N E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2009-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package provides routines to read DWARF line number information from
kono
parents:
diff changeset
33 -- a generic object file with as little overhead as possible. This allows
kono
parents:
diff changeset
34 -- conversions from PC addresses to human readable source locations.
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 -- Objects must be built with debugging information, however only the
kono
parents:
diff changeset
37 -- .debug_line section of the object file is referenced. In cases where object
kono
parents:
diff changeset
38 -- size is a consideration it's possible to strip all other .debug sections,
kono
parents:
diff changeset
39 -- which will decrease the size of the object significantly.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 pragma Polling (Off);
kono
parents:
diff changeset
42 -- We must turn polling off for this unit, because otherwise we can get
kono
parents:
diff changeset
43 -- elaboration circularities when polling is turned on
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 with Ada.Exceptions.Traceback;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 with System.Object_Reader;
kono
parents:
diff changeset
48 with System.Storage_Elements;
kono
parents:
diff changeset
49 with System.Bounded_Strings;
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 package System.Dwarf_Lines is
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 package AET renames Ada.Exceptions.Traceback;
kono
parents:
diff changeset
54 package SOR renames System.Object_Reader;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 type Dwarf_Context (In_Exception : Boolean := False) is private;
kono
parents:
diff changeset
57 -- Type encapsulation the state of the Dwarf reader. When In_Exception
kono
parents:
diff changeset
58 -- is True we are parsing as part of a exception handler decorator, we do
kono
parents:
diff changeset
59 -- not want an exception to be raised, the parsing is done safely skipping
kono
parents:
diff changeset
60 -- DWARF file that cannot be read or with stripped debug section for
kono
parents:
diff changeset
61 -- example.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 procedure Open
kono
parents:
diff changeset
64 (File_Name : String;
kono
parents:
diff changeset
65 C : out Dwarf_Context;
kono
parents:
diff changeset
66 Success : out Boolean);
kono
parents:
diff changeset
67 procedure Close (C : in out Dwarf_Context);
kono
parents:
diff changeset
68 -- Open and close files
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 procedure Set_Load_Address (C : in out Dwarf_Context; Addr : Address);
kono
parents:
diff changeset
71 -- Set the load address of a file. This is used to rebase PIE (Position
kono
parents:
diff changeset
72 -- Independant Executable) binaries.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 function Is_Inside (C : Dwarf_Context; Addr : Address) return Boolean;
kono
parents:
diff changeset
75 pragma Inline (Is_Inside);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
76 -- Return true iff a run-time address Addr is within the module
111
kono
parents:
diff changeset
77
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
78 function Low_Address (C : Dwarf_Context)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
79 return System.Address;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 pragma Inline (Low_Address);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
81 -- Return the lowest address of C, accounting for the module load address
111
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 procedure Dump (C : in out Dwarf_Context);
kono
parents:
diff changeset
84 -- Dump each row found in the object's .debug_lines section to standard out
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 procedure Dump_Cache (C : Dwarf_Context);
kono
parents:
diff changeset
87 -- Dump the cache (if present)
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 procedure Enable_Cache (C : in out Dwarf_Context);
kono
parents:
diff changeset
90 -- Read symbols information to speed up Symbolic_Traceback.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 procedure Symbolic_Traceback
kono
parents:
diff changeset
93 (Cin : Dwarf_Context;
kono
parents:
diff changeset
94 Traceback : AET.Tracebacks_Array;
kono
parents:
diff changeset
95 Suppress_Hex : Boolean;
kono
parents:
diff changeset
96 Symbol_Found : in out Boolean;
kono
parents:
diff changeset
97 Res : in out System.Bounded_Strings.Bounded_String);
kono
parents:
diff changeset
98 -- Generate a string for a traceback suitable for displaying to the user.
kono
parents:
diff changeset
99 -- If one or more symbols are found, Symbol_Found is set to True. This
kono
parents:
diff changeset
100 -- allows the caller to fall back to hexadecimal addresses.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 Dwarf_Error : exception;
kono
parents:
diff changeset
103 -- Raised if a problem is encountered parsing DWARF information. Can be a
kono
parents:
diff changeset
104 -- result of a logic error or malformed DWARF information.
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 private
kono
parents:
diff changeset
107 -- The following section numbers reference
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 -- "DWARF Debugging Information Format, Version 3"
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 -- published by the Standards Group, http://freestandards.org.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- 6.2.2 State Machine Registers
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 type Line_Info_Registers is record
kono
parents:
diff changeset
116 Address : SOR.uint64;
kono
parents:
diff changeset
117 File : SOR.uint32;
kono
parents:
diff changeset
118 Line : SOR.uint32;
kono
parents:
diff changeset
119 Column : SOR.uint32;
kono
parents:
diff changeset
120 Is_Stmt : Boolean;
kono
parents:
diff changeset
121 Basic_Block : Boolean;
kono
parents:
diff changeset
122 End_Sequence : Boolean;
kono
parents:
diff changeset
123 Prologue_End : Boolean;
kono
parents:
diff changeset
124 Epilogue_Begin : Boolean;
kono
parents:
diff changeset
125 ISA : SOR.uint32;
kono
parents:
diff changeset
126 Is_Row : Boolean;
kono
parents:
diff changeset
127 end record;
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -- 6.2.4 The Line Number Program Prologue
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 MAX_OPCODE_LENGTHS : constant := 256;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 type Opcodes_Lengths_Array is
kono
parents:
diff changeset
134 array (SOR.uint32 range 1 .. MAX_OPCODE_LENGTHS) of SOR.uint8;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 type Line_Info_Prologue is record
kono
parents:
diff changeset
137 Unit_Length : SOR.uint32;
kono
parents:
diff changeset
138 Version : SOR.uint16;
kono
parents:
diff changeset
139 Prologue_Length : SOR.uint32;
kono
parents:
diff changeset
140 Min_Isn_Length : SOR.uint8;
kono
parents:
diff changeset
141 Default_Is_Stmt : SOR.uint8;
kono
parents:
diff changeset
142 Line_Base : SOR.int8;
kono
parents:
diff changeset
143 Line_Range : SOR.uint8;
kono
parents:
diff changeset
144 Opcode_Base : SOR.uint8;
kono
parents:
diff changeset
145 Opcode_Lengths : Opcodes_Lengths_Array;
kono
parents:
diff changeset
146 Includes_Offset : SOR.Offset;
kono
parents:
diff changeset
147 File_Names_Offset : SOR.Offset;
kono
parents:
diff changeset
148 end record;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 type Search_Entry is record
kono
parents:
diff changeset
151 First : SOR.uint32;
kono
parents:
diff changeset
152 Size : SOR.uint32;
kono
parents:
diff changeset
153 -- Function bounds as offset to the base address.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 Sym : SOR.uint32;
kono
parents:
diff changeset
156 -- Symbol offset to get the name.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 Line : SOR.uint32;
kono
parents:
diff changeset
159 -- Dwarf line offset.
kono
parents:
diff changeset
160 end record;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 type Search_Array is array (Natural range <>) of Search_Entry;
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 type Search_Array_Access is access Search_Array;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 type Dwarf_Context (In_Exception : Boolean := False) is record
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 Low, High : System.Storage_Elements.Storage_Offset;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 -- Bounds of the module, per the module object file
111
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Obj : SOR.Object_File_Access;
kono
parents:
diff changeset
171 -- The object file containing dwarf sections
kono
parents:
diff changeset
172
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
173 Load_Address : System.Address := System.Null_Address;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
174 -- The address at which the object file was loaded at run time
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175
111
kono
parents:
diff changeset
176 Has_Debug : Boolean;
kono
parents:
diff changeset
177 -- True if all debug sections are available
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 Cache : Search_Array_Access;
kono
parents:
diff changeset
180 -- Quick access to symbol and debug info (when present).
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 Lines : SOR.Mapped_Stream;
kono
parents:
diff changeset
183 Aranges : SOR.Mapped_Stream;
kono
parents:
diff changeset
184 Info : SOR.Mapped_Stream;
kono
parents:
diff changeset
185 Abbrev : SOR.Mapped_Stream;
kono
parents:
diff changeset
186 -- Dwarf line, aranges, info and abbrev sections
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 Prologue : Line_Info_Prologue;
kono
parents:
diff changeset
189 Registers : Line_Info_Registers;
kono
parents:
diff changeset
190 Next_Prologue : SOR.Offset;
kono
parents:
diff changeset
191 -- State for lines
kono
parents:
diff changeset
192 end record;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 end System.Dwarf_Lines;