annotate gcc/ada/libgnat/s-dwalin.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2009-2017, Free Software Foundation, Inc. --
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);
kono
parents:
diff changeset
76 -- Return true iff Addr is within the module
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function Low (C : Dwarf_Context) return Address;
kono
parents:
diff changeset
79 pragma Inline (Low);
kono
parents:
diff changeset
80 -- Return the lowest address of C
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 procedure Dump (C : in out Dwarf_Context);
kono
parents:
diff changeset
83 -- Dump each row found in the object's .debug_lines section to standard out
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Dump_Cache (C : Dwarf_Context);
kono
parents:
diff changeset
86 -- Dump the cache (if present)
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 procedure Enable_Cache (C : in out Dwarf_Context);
kono
parents:
diff changeset
89 -- Read symbols information to speed up Symbolic_Traceback.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Symbolic_Traceback
kono
parents:
diff changeset
92 (Cin : Dwarf_Context;
kono
parents:
diff changeset
93 Traceback : AET.Tracebacks_Array;
kono
parents:
diff changeset
94 Suppress_Hex : Boolean;
kono
parents:
diff changeset
95 Symbol_Found : in out Boolean;
kono
parents:
diff changeset
96 Res : in out System.Bounded_Strings.Bounded_String);
kono
parents:
diff changeset
97 -- Generate a string for a traceback suitable for displaying to the user.
kono
parents:
diff changeset
98 -- If one or more symbols are found, Symbol_Found is set to True. This
kono
parents:
diff changeset
99 -- allows the caller to fall back to hexadecimal addresses.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 Dwarf_Error : exception;
kono
parents:
diff changeset
102 -- Raised if a problem is encountered parsing DWARF information. Can be a
kono
parents:
diff changeset
103 -- result of a logic error or malformed DWARF information.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 private
kono
parents:
diff changeset
106 -- The following section numbers reference
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- "DWARF Debugging Information Format, Version 3"
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 -- published by the Standards Group, http://freestandards.org.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 -- 6.2.2 State Machine Registers
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 type Line_Info_Registers is record
kono
parents:
diff changeset
115 Address : SOR.uint64;
kono
parents:
diff changeset
116 File : SOR.uint32;
kono
parents:
diff changeset
117 Line : SOR.uint32;
kono
parents:
diff changeset
118 Column : SOR.uint32;
kono
parents:
diff changeset
119 Is_Stmt : Boolean;
kono
parents:
diff changeset
120 Basic_Block : Boolean;
kono
parents:
diff changeset
121 End_Sequence : Boolean;
kono
parents:
diff changeset
122 Prologue_End : Boolean;
kono
parents:
diff changeset
123 Epilogue_Begin : Boolean;
kono
parents:
diff changeset
124 ISA : SOR.uint32;
kono
parents:
diff changeset
125 Is_Row : Boolean;
kono
parents:
diff changeset
126 end record;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 -- 6.2.4 The Line Number Program Prologue
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 MAX_OPCODE_LENGTHS : constant := 256;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 type Opcodes_Lengths_Array is
kono
parents:
diff changeset
133 array (SOR.uint32 range 1 .. MAX_OPCODE_LENGTHS) of SOR.uint8;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 type Line_Info_Prologue is record
kono
parents:
diff changeset
136 Unit_Length : SOR.uint32;
kono
parents:
diff changeset
137 Version : SOR.uint16;
kono
parents:
diff changeset
138 Prologue_Length : SOR.uint32;
kono
parents:
diff changeset
139 Min_Isn_Length : SOR.uint8;
kono
parents:
diff changeset
140 Default_Is_Stmt : SOR.uint8;
kono
parents:
diff changeset
141 Line_Base : SOR.int8;
kono
parents:
diff changeset
142 Line_Range : SOR.uint8;
kono
parents:
diff changeset
143 Opcode_Base : SOR.uint8;
kono
parents:
diff changeset
144 Opcode_Lengths : Opcodes_Lengths_Array;
kono
parents:
diff changeset
145 Includes_Offset : SOR.Offset;
kono
parents:
diff changeset
146 File_Names_Offset : SOR.Offset;
kono
parents:
diff changeset
147 end record;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 type Search_Entry is record
kono
parents:
diff changeset
150 First : SOR.uint32;
kono
parents:
diff changeset
151 Size : SOR.uint32;
kono
parents:
diff changeset
152 -- Function bounds as offset to the base address.
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Sym : SOR.uint32;
kono
parents:
diff changeset
155 -- Symbol offset to get the name.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 Line : SOR.uint32;
kono
parents:
diff changeset
158 -- Dwarf line offset.
kono
parents:
diff changeset
159 end record;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 type Search_Array is array (Natural range <>) of Search_Entry;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 type Search_Array_Access is access Search_Array;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 type Dwarf_Context (In_Exception : Boolean := False) is record
kono
parents:
diff changeset
166 Load_Slide : System.Storage_Elements.Integer_Address := 0;
kono
parents:
diff changeset
167 Low, High : Address;
kono
parents:
diff changeset
168 -- Bounds of the module
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
kono
parents:
diff changeset
173 Has_Debug : Boolean;
kono
parents:
diff changeset
174 -- True if all debug sections are available
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 Cache : Search_Array_Access;
kono
parents:
diff changeset
177 -- Quick access to symbol and debug info (when present).
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 Lines : SOR.Mapped_Stream;
kono
parents:
diff changeset
180 Aranges : SOR.Mapped_Stream;
kono
parents:
diff changeset
181 Info : SOR.Mapped_Stream;
kono
parents:
diff changeset
182 Abbrev : SOR.Mapped_Stream;
kono
parents:
diff changeset
183 -- Dwarf line, aranges, info and abbrev sections
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 Prologue : Line_Info_Prologue;
kono
parents:
diff changeset
186 Registers : Line_Info_Registers;
kono
parents:
diff changeset
187 Next_Prologue : SOR.Offset;
kono
parents:
diff changeset
188 -- State for lines
kono
parents:
diff changeset
189 end record;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 end System.Dwarf_Lines;