Debian Codegraph @

src/lib/libdwarf/dwarf_loc.h

raw
1 /*
2 Copyright (C) 2000, 2004 Silicon Graphics, Inc. All Rights Reserved.
3 Portions Copyright (C) 2015-2023 David Anderson. All Rights Reserved.
4
5 This program is free software; you can redistribute it
6 and/or modify it under the terms of version 2.1 of the
7 GNU Lesser General Public License as published by the Free
8 Software Foundation.
9
10 This program is distributed in the hope that it would be
11 useful, but WITHOUT ANY WARRANTY; without even the implied
12 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE.
14
15 Further, this software is distributed without any warranty
16 that it is free of the rightful claim of any third person
17 regarding infringement or the like. Any license provided
18 herein, whether implied or otherwise, applies only to this
19 software file. Patent licenses, if any, provided herein
20 do not apply to combinations of this program with other
21 software, or any other product whatsoever.
22
23 You should have received a copy of the GNU Lesser General
24 Public License along with this program; if not, write the
25 Free Software Foundation, Inc., 51 Franklin Street - Fifth
26 Floor, Boston MA 02110-1301, USA.
27 */
28 #ifndef DWARF_LOC_H
29 #define DWARF_LOC_H
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 #define LOCLISTS_MAGIC 0xadab4
35
36 typedef struct Dwarf_Loc_Chain_s *Dwarf_Loc_Chain;
37 struct Dwarf_Loc_Chain_s {
38 Dwarf_Small lc_atom;
39 Dwarf_Unsigned lc_number;
40 Dwarf_Unsigned lc_number2;
41 Dwarf_Unsigned lc_number3;
42 Dwarf_Unsigned lc_offset;
43 Dwarf_Unsigned lc_opnumber;
44 Dwarf_Loc_Chain lc_next;
45 };
46
47 /* Contains info on an uninterpreted block of data,
48 the data is DWARF location expression operators. */
49 struct Dwarf_Block_c_s {
50 /* length of block bl_data points at */
51 Dwarf_Unsigned bl_len;
52
53 /* Uninterpreted data, location expressions,
54 DW_OP_reg31 etc */
55 Dwarf_Byte_Ptr bl_data;
56
57 /* DW_LKIND, see libdwarf.h.in */
58 Dwarf_Half bl_kind;
59
60 /* Section (not CU) offset which 'data' comes from. */
61 Dwarf_Unsigned bl_section_offset;
62
63 /* Section offset where the location description
64 itself starts. So a few bytes lower than
65 bl_section_offset */
66 Dwarf_Unsigned bl_locdesc_offset;
67 };
68 typedef struct Dwarf_Block_c_s Dwarf_Block_c;
69
70 /* Location record. Records up to 3 operand values.
71 For DWARF5 ops with a 1 byte size and then a block
72 of data of that size we the size in an operand
73 and follow that with the next operand as a
74 pointer to the block. The pointer is inserted
75 via cast, so an ugly hack.
76 This struct is opaque. Not visible to callers.
77 */
78 typedef struct Dwarf_Loc_Expr_Op_s *Dwarf_Loc_Expr_Op;
79 struct Dwarf_Loc_Expr_Op_s {
80 Dwarf_Small lr_atom; /* Location operation */
81
82 Dwarf_Unsigned lr_raw1;
83 Dwarf_Unsigned lr_raw2;
84 Dwarf_Unsigned lr_raw3;
85
86 Dwarf_Unsigned lr_number; /* First operand */
87
88 /* Second operand.
89 For OP_bregx, OP_bit_piece, OP_[GNU_]const_type,
90 OP_[GNU_]deref_type, OP_[GNU_]entry_value,
91 OP_implicit_value,
92 OP_[GNU_]implicit_pointer, OP_[GNU_]regval_type,
93 OP_xderef_type, */
94 Dwarf_Unsigned lr_number2;
95
96 /* Third Operand.
97 For OP_[GNU_]const type, pointer to
98 block of length 'lr_number2'
99 FIXME: retrieve the value at the pointer,
100 store the value here instead*/
101 Dwarf_Unsigned lr_number3;
102
103 /* The number assigned. 0 to the number-of-ops-1 in
104 the expression we are expanding. */
105 Dwarf_Unsigned lr_opnumber;
106 Dwarf_Unsigned lr_offset; /* offset for OP_BRA etc */
107 Dwarf_Loc_Expr_Op lr_next; /* When a list is useful.*/
108 };
109
110 /* Used at construction to enable verifying we set
111 sensibly before returning to callers. */
112
113 #define DW_LLE_VALUE_BOGUS 254
114
115 /* Location description DWARF 2,3,4,5
116 Adds the DW_LLE value (new in DWARF5).
117 This struct is opaque. Not visible to callers. */
118 struct Dwarf_Locdesc_c_s {
119 Dwarf_Half ld_lkind; /* DW_LKIND */
120
121 /* A DW_LLEX or DW_LLE value, real or synthesized */
122 Dwarf_Small ld_lle_value;
123 /* Failed means .debug_addr section needed but missing.
124 (possibly tied file needed) */
125 Dwarf_Bool ld_index_failed;
126 /* the length of data in this lle entry */
127 Dwarf_Unsigned ld_lle_bytecount;
128 unsigned long ld_magic;
129
130 /* Beginning of active range. This is actually an offset
131 of an applicable base address, not a pc value. */
132 Dwarf_Addr ld_rawlow;
133 /* Translated to address */
134 Dwarf_Addr ld_lopc;
135
136 /* End of active range. This is actually an offset
137 of an applicable base address,
138 or a length, never a pc value. */
139 Dwarf_Addr ld_rawhigh;
140 /* Translated to address */
141 Dwarf_Addr ld_highpc;
142
143 /* Byte length of the entire record for this entry,
144 including any DW_OP entries */
145 Dwarf_Unsigned ld_entrylen;
146
147 /* For .debug_loclists, eases building record. */
148 Dwarf_Block_c ld_opsblock;
149
150 /* count of struct Dwarf_Loc_Expr_Op_s (expression operators)
151 in array. */
152 Dwarf_Half ld_cents;
153 /* pointer to array of expression operator structs */
154 Dwarf_Loc_Expr_Op ld_s;
155
156 /* Section (not CU) offset where loc-expr begins*/
157 Dwarf_Unsigned ld_section_offset;
158
159 /* Section (not CU) offset where location descr begins*/
160 Dwarf_Unsigned ld_locdesc_offset;
161
162 /* Pointer to our header (in which we are located). */
163 Dwarf_Loc_Head_c ld_loclist_head;
164 Dwarf_Locdesc_c ld_next; /*helps building the locdescs*/
165 };
166
167 int _dwarf_locdesc_c_constructor(Dwarf_Debug dbg, void *locd);
168
169 /* A 'header' to the loclist and the
170 location description(s) attached to an attribute.
171 This struct is opaque. The contents not visible to
172 callers. */
173 struct Dwarf_Loc_Head_c_s {
174 /* The array (1 or more entries) of
175 struct Loc_Desc_c_s
176 If 1 it may really be a locexpr */
177 Dwarf_Locdesc_c ll_locdesc;
178
179 /* Entry count of the ll_locdesc array. */
180 Dwarf_Unsigned ll_locdesc_count;
181
182 Dwarf_Half ll_attrnum;
183 Dwarf_Half ll_attrform;
184 Dwarf_Half ll_cuversion;
185 unsigned ll_address_size;
186 unsigned ll_offset_size;
187 /* The CU Context of this loclist or locexpr. */
188 Dwarf_CU_Context ll_context;
189 /* DW_LKIND* */
190 Dwarf_Half ll_lkind; /* DW_LKIND */
191 Dwarf_Debug ll_dbg;
192 unsigned long ll_magic;
193
194 /* If ll_lkind == DW_LKIND_loclists the following
195 pointer is non-null and index is the index
196 of the localcontext */
197 Dwarf_Unsigned ll_index;
198 Dwarf_Loclists_Context ll_localcontext;
199
200 /* rh_last and rh_first used during build-up.
201 Zero when array rh_loclists built. */
202 Dwarf_Locdesc_c ll_first;
203 Dwarf_Locdesc_c ll_last;
204 Dwarf_Unsigned ll_bytes_total;
205 unsigned ll_segment_selector_size;
206
207 /* DW_AT_loclists_base */
208 Dwarf_Bool ll_at_loclists_base_present;
209 Dwarf_Unsigned ll_at_loclists_base;
210
211 /* DW_AT_low_pc originally, , perhaps interited
212 into dwp from skeleton. */
213 Dwarf_Bool ll_cu_base_address_present;
214 Dwarf_Unsigned ll_cu_base_address;
215
216 /* DW_AT_addr_base, so we can use .debug_addr
217 if such is needed. */
218 Dwarf_Bool ll_cu_addr_base_offset_present;
219 Dwarf_Unsigned ll_cu_addr_base_offset;
220
221 Dwarf_Small * ll_llepointer;
222 Dwarf_Unsigned ll_llearea_offset;
223 Dwarf_Small * ll_end_data_area;
224 };
225
226 int _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
227 Dwarf_Unsigned locdesc_index,
228 Dwarf_Loc_Head_c loc_head,
229 Dwarf_Block_c * loc_block,
230 Dwarf_Half address_size,
231 Dwarf_Half offset_size,
232 Dwarf_Half version_stamp,
233 Dwarf_Addr lowpc,
234 Dwarf_Addr highpc,
235 Dwarf_Half lle_op,
236 Dwarf_Error * error);
237
238 int _dwarf_loc_block_sanity_check(Dwarf_Debug dbg,
239 Dwarf_Block_c *loc_block,Dwarf_Error*error);
240
241 int _dwarf_internal_read_loclists_header(Dwarf_Debug dbg,
242 Dwarf_Bool temporary,
243 Dwarf_Unsigned contextnum,
244 Dwarf_Unsigned sectionlength,
245 Dwarf_Small *data,
246 Dwarf_Small *end_data,
247 Dwarf_Unsigned offset,
248 Dwarf_Loclists_Context buildhere,
249 Dwarf_Unsigned *next_offset,
250 Dwarf_Error *error);
251
252 void _dwarf_loclists_head_destructor(void *l);
253
254 int _dwarf_loclists_fill_in_lle_head(Dwarf_Debug dbg,
255 Dwarf_Attribute attr,
256 Dwarf_Half theform,
257 Dwarf_Unsigned attr_val,
258 Dwarf_Loc_Head_c llhead,
259 Dwarf_Error *error);
260
261 int _dwarf_loclists_expression_build(Dwarf_Debug dbg,
262 Dwarf_Attribute attr,
263 Dwarf_Loc_Head_c* llhead,
264 Dwarf_Error *error);
265
266 int _dwarf_read_loc_expr_op(Dwarf_Debug dbg,
267 Dwarf_Block_c * loc_block,
268 /* Caller: Start numbering at 0. */
269 Dwarf_Signed opnumber,
270
271 /* 2 for DWARF 2 etc. */
272 Dwarf_Half version_stamp,
273 Dwarf_Half offset_size, /* 4 or 8 */
274 Dwarf_Half address_size, /* 2,4, 8 */
275 Dwarf_Signed startoffset_in, /* offset in block,
276 not section offset */
277 Dwarf_Small *section_end,
278
279 /* nextoffset_out so caller knows next entry startoffset */
280 Dwarf_Unsigned *nextoffset_out,
281
282 /* The values picked up. */
283 Dwarf_Loc_Expr_Op curr_loc,
284 Dwarf_Error * error);
285 void _dwarf_free_loclists_head_content(Dwarf_Loc_Head_c head);
286
287 #ifdef __cplusplus
288 }
289 #endif /* __cplusplus */
290 #endif /* DWARF_LOC_H */