Debian Codegraph @

src/lib/libdwarf/dwarf_loc.c

raw
1 /*
2 Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
3 Portions Copyright (C) 2007-2018 David Anderson. All Rights Reserved.
4 Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved.
5
6 This program is free software; you can redistribute it
7 and/or modify it under the terms of version 2.1 of the
8 GNU Lesser General Public License as published by the Free
9 Software Foundation.
10
11 This program is distributed in the hope that it would be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE.
15
16 Further, this software is distributed without any warranty
17 that it is free of the rightful claim of any third person
18 regarding infringement or the like. Any license provided
19 herein, whether implied or otherwise, applies only to this
20 software file. Patent licenses, if any, provided herein
21 do not apply to combinations of this program with other
22 software, or any other product whatsoever.
23
24 You should have received a copy of the GNU Lesser General
25 Public License along with this program; if not, write the
26 Free Software Foundation, Inc., 51 Franklin Street - Fifth
27 Floor, Boston MA 02110-1301, USA.
28
29 */
30
31 #include <config.h>
32
33 #include <string.h> /* memset() */
34 #include <stdio.h> /* for debugging printf */
35
36 #if defined(_WIN32) && defined(HAVE_STDAFX_H)
37 #include "stdafx.h"
38 #endif /* HAVE_STDAFX_H */
39
40 #include "dwarf.h"
41 #include "libdwarf.h"
42 #include "libdwarf_private.h"
43 #include "dwarf_base_types.h"
44 #include "dwarf_opaque.h"
45 #include "dwarf_alloc.h"
46 #include "dwarf_error.h"
47 #include "dwarf_util.h"
48 #include "dwarf_loc.h"
49 #include "dwarf_string.h"
50
51 #define DEBUG_LOCLIST 1
52 #undef DEBUG_LOCLIST
53
54 static int _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
55 Dwarf_Block_c * return_block,
56 Dwarf_Addr * lowpc,
57 Dwarf_Addr * highpc,
58 Dwarf_Bool * at_end,
59 Dwarf_Half * lle_op,
60 Dwarf_Off sec_offset,
61 Dwarf_Half address_size,
62 Dwarf_Half lkind,
63 Dwarf_Error *error);
64
65 /* Used to enable sanity checking of these data
66 items before we return to caller. */
67 int
68 _dwarf_locdesc_c_constructor(Dwarf_Debug dbg, void *locd)
69 {
70 Dwarf_Locdesc_c ldp = (Dwarf_Locdesc_c)locd;
71
72 if (IS_INVALID_DBG(dbg)) {
73 return DW_DLV_ERROR;
74 }
75 ldp->ld_lle_value = DW_LLE_VALUE_BOGUS;
76 ldp->ld_lkind = DW_LKIND_unknown;
77 return DW_DLV_OK;
78 }
79
80 static void
81 _dwarf_lkind_name(unsigned lkind, dwarfstring *m)
82 {
83 switch(lkind) {
84 case DW_LKIND_expression:
85 dwarfstring_append(m,"DW_LKIND_expression");
86 return;
87 case DW_LKIND_loclist:
88 dwarfstring_append(m,"DW_LKIND_loclist");
89 return;
90 case DW_LKIND_GNU_exp_list:
91 dwarfstring_append(m,"DW_LKIND_GNU_exp_list");
92 return;
93 case DW_LKIND_loclists:
94 dwarfstring_append(m,"DW_LKIND_loclists");
95 return;
96 case DW_LKIND_unknown:
97 dwarfstring_append(m,"DW_LKIND_unknown");
98 return;
99 default: break;
100 }
101 dwarfstring_append_printf_u(m,
102 "<DW_LKIND location kind is unknown and has value %u>.",
103 lkind);
104 }
105
106 static int
107 determine_location_lkind(unsigned int version,
108 unsigned int form,
109 Dwarf_Bool is_dwo)
110 {
111 switch(form) {
112 case DW_FORM_exprloc: /* only defined for
113 DW_CFA_def_cfa_expression */
114 case DW_FORM_block:
115 case DW_FORM_block1:
116 case DW_FORM_block2:
117 case DW_FORM_block4:
118 return DW_LKIND_expression;
119 break;
120 case DW_FORM_data4:
121 case DW_FORM_data8:
122 if (version > 1 && version < 4) {
123 return DW_LKIND_loclist;
124 }
125 break;
126 case DW_FORM_sec_offset:
127 if (version == 5 ) {
128 return DW_LKIND_loclists;
129 }
130 if (version == 4 && is_dwo ) {
131 return DW_LKIND_GNU_exp_list;
132 }
133 return DW_LKIND_loclist;
134 break;
135 case DW_FORM_loclistx:
136 if (version == 5 ) {
137 return DW_LKIND_loclists;
138 }
139 break;
140 default:
141 break;
142 }
143 return DW_LKIND_unknown;
144 }
145
146 static void
147 _dwarf_free_op_chain(Dwarf_Debug dbg,
148 Dwarf_Loc_Chain headloc)
149 {
150 Dwarf_Loc_Chain cur = headloc;
151
152 while (cur) {
153 Dwarf_Loc_Chain next = cur->lc_next;
154 dwarf_dealloc(dbg, cur, DW_DLA_LOC_CHAIN);
155 cur = next;
156 }
157 }
158
159 /* Using a loclist offset to get the in-memory
160 address of .debug_loc data to read, returns the loclist
161 'header' info in return_block.
162 */
163
164 #define MAX_ADDR \
165 ((address_size == 8)?0xffffffffffffffffULL:0xffffffff)
166
167 static int
168 _dwarf_read_loc_section(Dwarf_Debug dbg,
169 Dwarf_Block_c * return_block,
170 Dwarf_Addr * lowpc,
171 Dwarf_Addr * hipc,
172 Dwarf_Half * lle_val,
173 Dwarf_Off sec_offset,
174 Dwarf_Half address_size,
175 Dwarf_Error * error)
176 {
177 Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
178 Dwarf_Small *loc_section_end =
179 dbg->de_debug_loc.dss_data + dbg->de_debug_loc.dss_size;
180
181 /* start_addr and end_addr are actually offsets
182 of the applicable base address of the CU.
183 They are address-size. */
184 Dwarf_Addr start_addr = 0;
185 Dwarf_Addr end_addr = 0;
186 Dwarf_Half exprblock_size = 0;
187 Dwarf_Unsigned exprblock_off =
188 2 * address_size + DWARF_HALF_SIZE;
189
190 if (sec_offset >= dbg->de_debug_loc.dss_size) {
191 /* We're at the end. No more present. */
192 return DW_DLV_NO_ENTRY;
193 }
194
195 /* If it goes past end, error */
196 if (exprblock_off > dbg->de_debug_loc.dss_size) {
197 _dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
198 return DW_DLV_ERROR;
199 }
200
201 READ_UNALIGNED_CK(dbg, start_addr, Dwarf_Addr, beg, address_size,
202 error,loc_section_end);
203 READ_UNALIGNED_CK(dbg, end_addr, Dwarf_Addr,
204 beg + address_size, address_size,
205 error,loc_section_end);
206 if (start_addr == 0 && end_addr == 0) {
207 /* If start_addr and end_addr are 0, it's the end and no
208 exprblock_size field follows. */
209 exprblock_size = 0;
210 exprblock_off -= DWARF_HALF_SIZE;
211 *lle_val = DW_LLE_end_of_list;
212 } else if (start_addr == MAX_ADDR) {
213 /* End address is a base address,
214 no exprblock_size field here either */
215 exprblock_size = 0;
216 exprblock_off -= DWARF_HALF_SIZE;
217 *lle_val = DW_LLE_base_address;
218 } else {
219 /* Here we note the address and length of the
220 expression operators, DW_OP_reg0 etc */
221 READ_UNALIGNED_CK(dbg, exprblock_size, Dwarf_Half,
222 beg + 2 * address_size, DWARF_HALF_SIZE,
223 error,loc_section_end);
224 /* exprblock_size can be zero, means no expression */
225 if ( exprblock_size >= dbg->de_debug_loc.dss_size) {
226 _dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
227 return DW_DLV_ERROR;
228 }
229 if ((sec_offset +exprblock_off + exprblock_size) >
230 dbg->de_debug_loc.dss_size) {
231 _dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
232 return DW_DLV_ERROR;
233 }
234 *lle_val = DW_LLE_start_end;
235 }
236 *lowpc = start_addr;
237 *hipc = end_addr;
238
239 return_block->bl_len = exprblock_size;
240 return_block->bl_kind = DW_LKIND_loclist;
241 return_block->bl_data = beg + exprblock_off;
242 return_block->bl_section_offset =
243 ((Dwarf_Small *) return_block->bl_data) -
244 dbg->de_debug_loc.dss_data;
245 return DW_DLV_OK;
246 }
247
248 static int
249 _dwarf_get_loclist_lle_count_dwo(Dwarf_Debug dbg,
250 Dwarf_Off loclist_offset,
251 Dwarf_Half address_size,
252 Dwarf_Half lkind,
253 int *loclist_count,
254 Dwarf_Error * error)
255 {
256 int count = 0;
257 Dwarf_Off offset = loclist_offset;
258
259 for (;;) {
260 Dwarf_Block_c b;
261 Dwarf_Bool at_end = FALSE;
262 Dwarf_Addr lowpc = 0;
263 Dwarf_Addr highpc = 0;
264 Dwarf_Half lle_op = 0;
265 int res = _dwarf_read_loc_section_dwo(dbg, &b,
266 &lowpc,
267 &highpc,
268 &at_end,
269 &lle_op,
270 offset,
271 address_size,
272 lkind,
273 error);
274 if (res != DW_DLV_OK) {
275 return res;
276 }
277 if (at_end) {
278 count++;
279 break;
280 }
281 offset = b.bl_len + b.bl_section_offset;
282 count++;
283 }
284 *loclist_count = count;
285 return DW_DLV_OK;
286 }
287
288 static int
289 _dwarf_get_loclist_lle_count(Dwarf_Debug dbg,
290 Dwarf_Off loclist_offset,
291 Dwarf_Half address_size,
292 int *loclist_count,
293 Dwarf_Error * error)
294 {
295 int count = 0;
296 Dwarf_Off offset = loclist_offset;
297
298 for (;;) {
299 Dwarf_Block_c b;
300 Dwarf_Addr lowpc = 0;
301 Dwarf_Addr highpc = 0;
302 Dwarf_Half lle_val = DW_LLE_VALUE_BOGUS;
303
304 int res = _dwarf_read_loc_section(dbg, &b,
305 &lowpc, &highpc,
306 &lle_val,
307 offset, address_size,error);
308 if (res != DW_DLV_OK) {
309 return res;
310 }
311 offset = b.bl_len + b.bl_section_offset;
312 if (lowpc == 0 && highpc == 0) {
313 break;
314 }
315 count++;
316 }
317 *loclist_count = count;
318 return DW_DLV_OK;
319 }
320
321 /* Helper routine to avoid code duplication.
322 */
323 static int
324 _dwarf_setup_loc(Dwarf_Attribute attr,
325 Dwarf_Debug * dbg_ret,
326 Dwarf_CU_Context *cucontext_ret,
327 Dwarf_Half *form_ret,
328 Dwarf_Error *error)
329 {
330 Dwarf_Debug dbg = 0;
331 Dwarf_Half form = 0;
332 int blkres = DW_DLV_ERROR;
333
334 /* Creating an error with NULL dbg is not a good thing.
335 These won't be freed if we later call dealloc
336 with a non-NULL dbg.
337 */
338 if (!attr) {
339 _dwarf_error_string(NULL, error, DW_DLE_ATTR_NULL,
340 "DW_DLE_ATTR_NULL: the attribute passed to "
341 "dwarf_get_loclist_c() is a NULL pointer");
342 return DW_DLV_ERROR;
343 }
344 if (attr->ar_cu_context == NULL) {
345 _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
346 return DW_DLV_ERROR;
347 }
348 *cucontext_ret = attr->ar_cu_context;
349
350 dbg = attr->ar_cu_context->cc_dbg;
351 CHECK_DBG(dbg,error,"_dwarf_get_loclist_lle_count()");
352 *dbg_ret = dbg;
353 blkres = dwarf_whatform(attr, &form, error);
354 if (blkres != DW_DLV_OK) {
355 return blkres;
356 }
357 *form_ret = form;
358 return DW_DLV_OK;
359 }
360
361 /* Helper routine to avoid code duplication.
362 */
363 static int
364 _dwarf_get_loclist_header_start(Dwarf_Debug dbg,
365 Dwarf_Attribute attr,
366 Dwarf_Unsigned * loclist_offset_out,
367 Dwarf_Error * error)
368 {
369 Dwarf_Unsigned loc_sec_size = 0;
370 Dwarf_Unsigned loclist_offset = 0;
371
372 int blkres = dwarf_global_formref(attr, &loclist_offset, error);
373 if (blkres != DW_DLV_OK) {
374 return blkres;
375 }
376 if (!dbg->de_debug_loc.dss_data) {
377 int secload = _dwarf_load_section(dbg,
378 &dbg->de_debug_loc,error);
379 if (secload != DW_DLV_OK) {
380 return secload;
381 }
382 if (!dbg->de_debug_loc.dss_size) {
383 return DW_DLV_NO_ENTRY;
384 }
385 }
386 loc_sec_size = dbg->de_debug_loc.dss_size;
387 if (loclist_offset >= loc_sec_size) {
388 _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
389 return DW_DLV_ERROR;
390 }
391
392 {
393 int fisres = 0;
394 Dwarf_Unsigned fissoff = 0;
395 Dwarf_Unsigned size = 0;
396 fisres = _dwarf_get_fission_addition_die(attr->ar_die,
397 DW_SECT_LOCLISTS,
398 &fissoff, &size,error);
399 if (fisres != DW_DLV_OK) {
400 return fisres;
401 }
402 if (fissoff >= loc_sec_size) {
403 _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
404 return DW_DLV_ERROR;
405 }
406 loclist_offset += fissoff;
407 if (loclist_offset >= loc_sec_size) {
408 _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
409 return DW_DLV_ERROR;
410 }
411 }
412 *loclist_offset_out = loclist_offset;
413 return DW_DLV_OK;
414 }
415
416 static int
417 context_is_cu_not_tu(Dwarf_CU_Context context,
418 Dwarf_Bool *r)
419 {
420 int ut = context->cc_unit_type;
421
422 if (ut == DW_UT_type || ut == DW_UT_split_type ) {
423 *r =FALSE;
424 return DW_DLV_OK;
425 }
426 *r = TRUE;
427 return DW_DLV_OK;
428 }
429
430 /* Handles only a location expression.
431 It returns the location expression as a loclist with
432 a single entry.
433
434 Usable to access dwarf expressions from any source, but
435 specifically from
436 DW_CFA_def_cfa_expression
437 DW_CFA_expression
438 DW_CFA_val_expression
439 expression_in must point to a valid dwarf expression
440 */
441
442 /* ============== the October 2015 interfaces. */
443 int
444 _dwarf_loc_block_sanity_check(Dwarf_Debug dbg,
445 Dwarf_Block_c *loc_block,Dwarf_Error* error)
446 {
447 unsigned lkind = loc_block->bl_kind;
448 if (lkind == DW_LKIND_loclist) {
449 Dwarf_Small *loc_ptr = 0;
450 Dwarf_Unsigned loc_len = 0;
451 Dwarf_Small *end_ptr = 0;
452
453 loc_ptr = loc_block->bl_data;
454 loc_len = loc_block->bl_len;
455 end_ptr = dbg->de_debug_loc.dss_size +
456 dbg->de_debug_loc.dss_data;
457 if ((loc_ptr +loc_len) > end_ptr) {
458 dwarfstring m;
459
460 dwarfstring_constructor(&m);
461 dwarfstring_append(&m,
462 "DW_DLE_DEBUG_LOC_SECTION_SHORT kind: ");
463 _dwarf_lkind_name(lkind, &m);
464 _dwarf_error_string(dbg,error,
465 DW_DLE_DEBUG_LOC_SECTION_SHORT,
466 dwarfstring_string(&m));
467 dwarfstring_destructor(&m);
468 return DW_DLV_ERROR;
469 }
470 return DW_DLV_OK;
471 }
472 if (lkind == DW_LKIND_loclists) {
473 Dwarf_Small *loc_ptr = 0;
474 Dwarf_Unsigned loc_len = 0;
475 Dwarf_Small *end_ptr = 0;
476
477 loc_ptr = loc_block->bl_data;
478 loc_len = loc_block->bl_len;
479 end_ptr = dbg->de_debug_loclists.dss_size +
480 dbg->de_debug_loclists.dss_data;
481 if ((loc_ptr +loc_len) > end_ptr) {
482 dwarfstring m;
483
484 dwarfstring_constructor(&m);
485 dwarfstring_append(&m,
486 "DW_DLE_DEBUG_LOC_SECTION_SHORT "
487 "(the .debug_loclists section is short), kind: ");
488 _dwarf_lkind_name(lkind, &m);
489 _dwarf_error_string(dbg,error,
490 DW_DLE_DEBUG_LOC_SECTION_SHORT,
491 dwarfstring_string(&m));
492 dwarfstring_destructor(&m);
493 return DW_DLV_ERROR;
494 }
495 }
496 return DW_DLV_OK;
497 }
498
499 /* ld_lkind was checked before calling this, so we
500 know its value is an intended value. */
501 static const char *kindset[] = {
502 "DW_LKIND_expression",
503 "DW_LKIND_loclist",
504 "DW_LKIND_GNU_exp_list",
505 "DW_LKIND_unknown3",
506 "DW_LKIND_unknown4",
507 "DW_LKIND_loclists"
508 };
509 static const char *
510 get_loc_kind_str(Dwarf_Small lkind)
511 {
512 if (lkind <= DW_LKIND_loclists) {
513 return kindset[lkind];
514 }
515 if (lkind == DW_LKIND_unknown) {
516 return "DW_LKIND_unknown";
517 }
518 return "UNKNOWN DW_LKIND!";
519 }
520 static int
521 validate_lle_value(Dwarf_Debug dbg,
522 Dwarf_Locdesc_c locdesc,
523 Dwarf_Error *error)
524 {
525 dwarfstring m;
526
527 if (locdesc->ld_lkind != DW_LKIND_GNU_exp_list) {
528 switch(locdesc->ld_lle_value) {
529 case DW_LLE_end_of_list:
530 case DW_LLE_base_addressx:
531 case DW_LLE_startx_endx:
532 case DW_LLE_startx_length:
533 case DW_LLE_offset_pair:
534 case DW_LLE_default_location:
535 case DW_LLE_base_address:
536 case DW_LLE_start_end:
537 case DW_LLE_start_length:
538 return DW_DLV_OK;
539 default: break;
540 }
541 dwarfstring_constructor(&m);
542
543 dwarfstring_append_printf_s(&m,
544 "DW_DLE_LOCATION_ERROR: For location kind %s (",
545 (char *)get_loc_kind_str(
546 (Dwarf_Small)locdesc->ld_lkind));
547 dwarfstring_append_printf_u(&m,"%u) the DW_LLE value is "
548 "not properly set",
549 locdesc->ld_lkind);
550 dwarfstring_append_printf_u(&m," but is %u "
551 " which is a libdwarf bug",
552 locdesc->ld_lle_value);
553 _dwarf_error_string(dbg,error,DW_DLE_LOCATION_ERROR,
554 dwarfstring_string(&m));
555 dwarfstring_destructor(&m);
556 return DW_DLV_ERROR;
557 }
558 switch(locdesc->ld_lle_value) {
559 case DW_LLEX_end_of_list_entry:
560 case DW_LLEX_base_address_selection_entry:
561 case DW_LLEX_start_end_entry:
562 case DW_LLEX_start_length_entry:
563 case DW_LLEX_offset_pair_entry:
564 return DW_DLV_OK;
565 default: break; /* ERROR */
566 }
567 {
568 dwarfstring_constructor(&m);
569 dwarfstring_append_printf_s(&m,
570 "DW_DLE_LOCATION_ERROR: For location kind %s (",
571 (char *)get_loc_kind_str(
572 (Dwarf_Small)locdesc->ld_lkind));
573 dwarfstring_append_printf_u(&m,"%u) the DW_LLEX value is "
574 "not properly set",
575 locdesc->ld_lkind);
576 dwarfstring_append_printf_u(&m," but is %u "
577 " which is a libdwarf bug",
578 locdesc->ld_lle_value);
579 _dwarf_error_string(dbg,error,DW_DLE_LOCATION_ERROR,
580 dwarfstring_string(&m));
581 dwarfstring_destructor(&m);
582 }
583 return DW_DLV_ERROR;
584 }
585 /* Sets locdesc operator list information in locdesc.
586 Sets the locdesc values (rawlow, rawhigh etc).
587 This synthesizes the ld_lle_value of the locdesc
588 if it's not already provided.
589 Not passing in locdesc pointer, the locdesc_index suffices
590 to index to the relevant locdesc pointer.
591 See also dwarf_loclists.c: build_array_of_lle*/
592 int
593 _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
594 Dwarf_Unsigned locdesc_index,
595 Dwarf_Loc_Head_c loc_head,
596 Dwarf_Block_c * loc_block,
597 Dwarf_Half address_size,
598 Dwarf_Half offset_size,
599 Dwarf_Half version_stamp,
600 Dwarf_Addr lowpc,
601 Dwarf_Addr highpc,
602 Dwarf_Half lle_op,
603 Dwarf_Error * error)
604 {
605 /* Offset of current operator from start of block. */
606 Dwarf_Unsigned offset = 0;
607
608 /* Chain the DW_OPerator structs. */
609 Dwarf_Loc_Chain new_loc = NULL;
610 Dwarf_Loc_Chain prev_loc = NULL;
611 Dwarf_Loc_Chain head_loc = NULL;
612 Dwarf_Loc_Chain *plast = &head_loc;
613
614 Dwarf_Unsigned op_count = 0;
615
616 /* Contiguous block of Dwarf_Loc_Expr_Op_s
617 for Dwarf_Locdesc. */
618 Dwarf_Loc_Expr_Op block_loc = 0;
619
620 Dwarf_Locdesc_c locdesc = loc_head->ll_locdesc + locdesc_index;
621 Dwarf_Unsigned i = 0;
622 int res = 0;
623 Dwarf_Small *section_start = 0;
624 Dwarf_Unsigned section_size = 0;
625 Dwarf_Small *section_end = 0;
626 const char *section_name = 0;
627 Dwarf_Small *blockdataptr = 0;
628 unsigned lkind = loc_head->ll_lkind;
629
630 /* ***** BEGIN CODE ***** */
631 blockdataptr = loc_block->bl_data;
632 if (!blockdataptr || !loc_block->bl_len) {
633 /* an empty block has no operations so
634 no section or tests need be done.. */
635 } else {
636 res = _dwarf_what_section_are_we(dbg,
637 blockdataptr,&section_name,&section_start,
638 &section_size,&section_end);
639 if (res != DW_DLV_OK) {
640 _dwarf_error(dbg, error,DW_DLE_POINTER_SECTION_UNKNOWN);
641 return DW_DLV_ERROR;
642 }
643 res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
644 if (res != DW_DLV_OK) {
645 return res;
646 }
647 }
648 /* New loop getting Loc operators. Non DWO */
649 while (offset <= loc_block->bl_len) {
650 Dwarf_Unsigned nextoffset = 0;
651 struct Dwarf_Loc_Expr_Op_s temp_loc;
652
653 /* This call is ok even if bl_data NULL and bl_len 0 */
654 res = _dwarf_read_loc_expr_op(dbg,loc_block,
655 op_count,
656 version_stamp,
657 offset_size,
658 address_size,
659 offset,
660 section_end,
661 &nextoffset,
662 &temp_loc,
663 error);
664 if (res == DW_DLV_ERROR) {
665 _dwarf_free_op_chain(dbg,head_loc);
666 return res;
667 }
668 if (res == DW_DLV_NO_ENTRY) {
669 /* Normal end.
670 Also the end for an empty loc_block. */
671 break;
672 }
673 op_count++;
674 new_loc = (Dwarf_Loc_Chain) _dwarf_get_alloc(dbg,
675 DW_DLA_LOC_CHAIN, 1);
676 if (new_loc == NULL) {
677 _dwarf_free_op_chain(dbg,head_loc);
678 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
679 return DW_DLV_ERROR;
680 }
681
682 /* Copying all the fields. DWARF 2,3,4,5. */
683 new_loc->lc_atom = temp_loc.lr_atom;
684 new_loc->lc_opnumber= temp_loc.lr_opnumber;
685 new_loc->lc_number = temp_loc.lr_number;
686 new_loc->lc_number2 = temp_loc.lr_number2;
687 new_loc->lc_number3 = temp_loc.lr_number3;
688 new_loc->lc_offset = temp_loc.lr_offset;
689 *plast = new_loc;
690 plast= &(new_loc->lc_next);
691 offset = nextoffset;
692 }
693 block_loc =
694 (Dwarf_Loc_Expr_Op ) _dwarf_get_alloc(dbg,
695 DW_DLA_LOC_BLOCK_C, op_count);
696 new_loc = head_loc;
697 if (!block_loc) {
698 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
699 for (i = 0; i < op_count; i++) {
700 prev_loc = new_loc;
701 new_loc = prev_loc->lc_next;
702 dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
703 }
704 return DW_DLV_ERROR;
705 }
706
707 /* op_count could be zero. */
708 new_loc = head_loc;
709 for (i = 0; i < op_count; i++) {
710 /* Copying only the fields needed by DWARF 2,3,4 */
711 (block_loc + i)->lr_atom = new_loc->lc_atom;
712 (block_loc + i)->lr_number = new_loc->lc_number;
713 (block_loc + i)->lr_number2 = new_loc->lc_number2;
714 (block_loc + i)->lr_number3 = new_loc->lc_number3;
715 (block_loc + i)->lr_offset = new_loc->lc_offset;
716 (block_loc + i)->lr_opnumber = new_loc->lc_opnumber;
717 prev_loc = new_loc;
718 new_loc = prev_loc->lc_next;
719 dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
720 }
721 /* Synthesizing the DW_LLE values for the old loclist
722 versions. */
723 switch(loc_head->ll_lkind) {
724 case DW_LKIND_loclist: {
725 if (highpc == 0 && lowpc == 0) {
726 locdesc->ld_lle_value = DW_LLE_end_of_list;
727 } else if (lowpc == MAX_ADDR) {
728 locdesc->ld_lle_value = DW_LLE_base_address;
729 } else {
730 locdesc->ld_lle_value = DW_LLE_offset_pair;
731 }
732 }
733 break;
734 case DW_LKIND_GNU_exp_list:
735 /* DW_LKIND_GNU_exp_list */
736 locdesc->ld_lle_value = (Dwarf_Small)lle_op;
737 break;
738 case DW_LKIND_expression:
739 /* This is a kind of fake, but better than 0 */
740 locdesc->ld_lle_value = (Dwarf_Small)DW_LLE_start_end;
741 break;
742 case DW_LKIND_loclists:
743 /* ld_lle_value already set */
744 break;
745 default: {
746 dwarfstring m;
747
748 dwarfstring_constructor(&m);
749 dwarfstring_append_printf_u(&m,
750 "DW_DLE_LOCATION_ERROR: An impossible DW_LKIND"
751 " value of %u encountered, likely internal "
752 "libdwarf error or data corruption",
753 (unsigned)loc_head->ll_lkind);
754 _dwarf_error_string(dbg,error,
755 DW_DLE_LOCATION_ERROR,
756 dwarfstring_string(&m));
757 dwarfstring_destructor(&m);
758 dwarf_dealloc(dbg,block_loc,DW_DLA_LOC_BLOCK_C);
759 return DW_DLV_ERROR;
760 }
761 }
762 locdesc->ld_cents = (Dwarf_Half)op_count;
763 locdesc->ld_s = block_loc;
764
765 locdesc->ld_lkind = lkind;
766 locdesc->ld_section_offset = loc_block->bl_section_offset;
767 locdesc->ld_locdesc_offset = loc_block->bl_locdesc_offset;
768 locdesc->ld_rawlow = lowpc;
769 locdesc->ld_rawhigh = highpc;
770
771 res = validate_lle_value(dbg,locdesc,error);
772 if (res != DW_DLV_OK) {
773 dwarf_dealloc(dbg,block_loc,DW_DLA_LOC_BLOCK_C);
774 locdesc->ld_s = 0;
775 return res;
776 }
777 /* Leaving the cooked values zero. Filled in later. */
778 /* We have not yet looked for debug_addr, so we'll
779 set it as not-missing. */
780 locdesc->ld_index_failed = FALSE;
781 return DW_DLV_OK;
782 }
783
784 /* Non-standard DWARF4 dwo loclist */
785 static int
786 _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
787 Dwarf_Block_c * return_block,
788 Dwarf_Addr * lowpc,
789 Dwarf_Addr * highpc,
790 Dwarf_Bool *at_end,
791 Dwarf_Half * lle_op,
792 Dwarf_Off sec_offset,
793 Dwarf_Half address_size,
794 Dwarf_Half lkind,
795 Dwarf_Error * error)
796 {
797 Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
798 Dwarf_Small *locptr = 0;
799 Dwarf_Small llecode = 0;
800 Dwarf_Unsigned expr_offset = sec_offset;
801 Dwarf_Byte_Ptr section_end = dbg->de_debug_loc.dss_data
802 + dbg->de_debug_loc.dss_size;
803
804 if (sec_offset >= dbg->de_debug_loc.dss_size) {
805 /* We're at the end. No more present. */
806 return DW_DLV_NO_ENTRY;
807 }
808 memset(return_block,0,sizeof(*return_block));
809
810 /* not the same as non-split loclist, but still a list. */
811 return_block->bl_kind = lkind;
812
813 /* This is non-standard GNU Dwarf4 loclist */
814 return_block->bl_locdesc_offset = sec_offset;
815 llecode = *beg;
816 locptr = beg +1;
817 expr_offset++;
818 switch(llecode) {
819 case DW_LLEX_end_of_list_entry:
820 *at_end = TRUE;
821 return_block->bl_section_offset = expr_offset;
822 expr_offset++;
823 break;
824 case DW_LLEX_base_address_selection_entry: {
825 Dwarf_Unsigned addr_index = 0;
826
827 DECODE_LEB128_UWORD_CK(locptr,addr_index,
828 dbg,error,section_end);
829 return_block->bl_section_offset = expr_offset;
830 /* So this behaves much like non-dwo loclist */
831 *lowpc=MAX_ADDR;
832 *highpc=addr_index;
833 }
834 break;
835 case DW_LLEX_start_end_entry: {
836 Dwarf_Unsigned addr_indexs = 0;
837 Dwarf_Unsigned addr_indexe= 0;
838 Dwarf_Unsigned exprlen = 0;
839 Dwarf_Unsigned leb128_length = 0;
840
841 DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexs,
842 leb128_length,
843 dbg,error,section_end);
844 expr_offset += leb128_length;
845
846 DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexe,
847 leb128_length,
848 dbg,error,section_end);
849 expr_offset +=leb128_length;
850
851 *lowpc=addr_indexs;
852 *highpc=addr_indexe;
853
854 READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
855 DWARF_HALF_SIZE,
856 error,section_end);
857 locptr += DWARF_HALF_SIZE;
858 expr_offset += DWARF_HALF_SIZE;
859
860 return_block->bl_len = exprlen;
861 return_block->bl_data = locptr;
862 return_block->bl_section_offset = expr_offset;
863
864 expr_offset += exprlen;
865 if (expr_offset > dbg->de_debug_loc.dss_size) {
866 dwarfstring m;
867
868 dwarfstring_constructor(&m);
869 dwarfstring_append(&m,
870 "DW_DLE_DEBUG_LOC_SECTION_SHORT:");
871 dwarfstring_append_printf_u(&m,
872 " in DW_LLEX_start_end_entry "
873 "The expression offset is 0x%x",
874 expr_offset);
875 dwarfstring_append_printf_u(&m,
876 " which is greater than the section size"
877 " of 0x%x. Corrupt Dwarf.",
878 dbg->de_debug_loc.dss_size);
879 _dwarf_error_string(dbg,error,
880 DW_DLE_DEBUG_LOC_SECTION_SHORT,
881 dwarfstring_string(&m));
882 dwarfstring_destructor(&m);
883 return DW_DLV_ERROR;
884 }
885 }
886 break;
887 case DW_LLEX_start_length_entry: {
888 Dwarf_Unsigned addr_index = 0;
889 Dwarf_Unsigned range_length = 0;
890 Dwarf_Unsigned exprlen = 0;
891 Dwarf_Unsigned leb128_length = 0;
892
893 DECODE_LEB128_UWORD_LEN_CK(locptr,addr_index,
894 leb128_length,
895 dbg,error,section_end);
896 expr_offset +=leb128_length;
897
898 READ_UNALIGNED_CK(dbg, range_length, Dwarf_Unsigned, locptr,
899 DWARF_32BIT_SIZE,
900 error,section_end);
901 locptr += DWARF_32BIT_SIZE;
902 expr_offset += DWARF_32BIT_SIZE;
903
904 READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
905 DWARF_HALF_SIZE,
906 error,section_end);
907 locptr += DWARF_HALF_SIZE;
908 expr_offset += DWARF_HALF_SIZE;
909
910 *lowpc = addr_index;
911 *highpc = range_length;
912 return_block->bl_len = exprlen;
913 return_block->bl_data = locptr;
914 return_block->bl_section_offset = expr_offset;
915 /* exprblock_size can be zero, means no expression */
916
917 expr_offset += exprlen;
918 if (expr_offset > dbg->de_debug_loc.dss_size) {
919 dwarfstring m;
920
921 dwarfstring_constructor(&m);
922 dwarfstring_append(&m,
923 "DW_DLE_DEBUG_LOC_SECTION_SHORT:");
924 dwarfstring_append_printf_u(&m,
925 " in DW_LLEX_start_length_entry "
926 "The expression offset is 0x%x",
927 expr_offset);
928 dwarfstring_append_printf_u(&m,
929 " which is greater than the section size"
930 " of 0x%x. Corrupt Dwarf.",
931 dbg->de_debug_loc.dss_size);
932 _dwarf_error_string(dbg,error,
933 DW_DLE_DEBUG_LOC_SECTION_SHORT,
934 dwarfstring_string(&m));
935 dwarfstring_destructor(&m);
936 return DW_DLV_ERROR;
937 }
938 }
939 break;
940 case DW_LLEX_offset_pair_entry: {
941 Dwarf_Unsigned startoffset = 0;
942 Dwarf_Unsigned endoffset = 0;
943 Dwarf_Unsigned exprlen = 0;
944
945 READ_UNALIGNED_CK(dbg, startoffset,
946 Dwarf_Unsigned, locptr,
947 DWARF_32BIT_SIZE,
948 error,section_end);
949 locptr += DWARF_32BIT_SIZE;
950 expr_offset += DWARF_32BIT_SIZE;
951
952 READ_UNALIGNED_CK(dbg, endoffset,
953 Dwarf_Unsigned, locptr,
954 DWARF_32BIT_SIZE,
955 error,section_end);
956 locptr += DWARF_32BIT_SIZE;
957 expr_offset += DWARF_32BIT_SIZE;
958 *lowpc= startoffset;
959 *highpc = endoffset;
960
961 READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
962 DWARF_HALF_SIZE,
963 error,section_end);
964 locptr += DWARF_HALF_SIZE;
965 expr_offset += DWARF_HALF_SIZE;
966
967 return_block->bl_len = exprlen;
968 return_block->bl_data = locptr;
969 return_block->bl_section_offset = expr_offset;
970
971 expr_offset += exprlen;
972 if (expr_offset > dbg->de_debug_loc.dss_size) {
973 dwarfstring m;
974
975 dwarfstring_constructor(&m);
976 dwarfstring_append(&m,
977 "DW_DLE_DEBUG_LOC_SECTION_SHORT:");
978 dwarfstring_append_printf_u(&m,
979 " in DW_LLEX_offset_pair_entry "
980 "The expression offset is 0x%x",
981 expr_offset);
982 dwarfstring_append_printf_u(&m,
983 " which is greater than the section size"
984 " of 0x%x. Corrupt Dwarf.",
985 dbg->de_debug_loc.dss_size);
986 _dwarf_error_string(dbg,error,
987 DW_DLE_DEBUG_LOC_SECTION_SHORT,
988 dwarfstring_string(&m));
989 dwarfstring_destructor(&m);
990 return DW_DLV_ERROR;
991 }
992 }
993 break;
994 default: {
995 dwarfstring m;
996
997 dwarfstring_constructor(&m);
998 dwarfstring_append(&m,
999 "DW_DLE_LLE_CODE_UNKNOWN:");
1000 dwarfstring_append_printf_u(&m,
1001 " in DW_LLEX_ code value "
1002 " is 0x%x ,not an expected value.",
1003 llecode);
1004 _dwarf_error_string(dbg,error,
1005 DW_DLE_LLE_CODE_UNKNOWN,
1006 dwarfstring_string(&m));
1007 dwarfstring_destructor(&m);
1008 return DW_DLV_ERROR;
1009 }
1010 }
1011 *lle_op = llecode;
1012 return DW_DLV_OK;
1013 }
1014
1015 int
1016 dwarf_get_loclist_head_kind(Dwarf_Loc_Head_c ll_header,
1017 unsigned int * kind,
1018 Dwarf_Error * error)
1019 {
1020 if (!ll_header) {
1021 _dwarf_error_string(NULL, error,DW_DLE_DBG_NULL,
1022 "DW_DLE_DBG_NULL: "
1023 "NULL Dwarf_Loc_Head_c "
1024 "argument passed to "
1025 "dwarf_get_loclist_head_kind()");
1026 return DW_DLV_ERROR;
1027 }
1028 *kind = ll_header->ll_lkind;
1029 return DW_DLV_OK;
1030 }
1031
1032 static int
1033 _dwarf_original_loclist_build(Dwarf_Debug dbg,
1034 Dwarf_Loc_Head_c llhead,
1035 Dwarf_Attribute attr,
1036 Dwarf_Error *error)
1037 {
1038 Dwarf_Unsigned loclist_offset = 0;
1039 Dwarf_Unsigned starting_loclist_offset = 0;
1040 int off_res = DW_DLV_ERROR;
1041 int count_res = DW_DLV_ERROR;
1042 int loclist_count = 0;
1043 Dwarf_Unsigned lli = 0;
1044 unsigned lkind = llhead->ll_lkind;
1045 unsigned address_size = llhead->ll_address_size;
1046 Dwarf_Unsigned listlen = 0;
1047 Dwarf_Locdesc_c llbuf = 0;
1048 Dwarf_CU_Context cucontext;
1049
1050 off_res = _dwarf_get_loclist_header_start(dbg,
1051 attr, &loclist_offset, error);
1052 if (off_res != DW_DLV_OK) {
1053 return off_res;
1054 }
1055 starting_loclist_offset = loclist_offset;
1056
1057 if (lkind == DW_LKIND_GNU_exp_list) {
1058 count_res = _dwarf_get_loclist_lle_count_dwo(dbg,
1059 loclist_offset,
1060 (Dwarf_Half)address_size,
1061 (Dwarf_Half)lkind,
1062 &loclist_count,
1063 error);
1064 } else {
1065 count_res = _dwarf_get_loclist_lle_count(dbg,
1066 loclist_offset, (Dwarf_Half)address_size,
1067 &loclist_count,
1068 error);
1069 }
1070 if (count_res != DW_DLV_OK) {
1071 return count_res;
1072 }
1073 if (loclist_count == 0) {
1074 return DW_DLV_NO_ENTRY;
1075 }
1076
1077 listlen = loclist_count;
1078 llbuf = (Dwarf_Locdesc_c)
1079 _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
1080 if (!llbuf) {
1081 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1082 return DW_DLV_ERROR;
1083 }
1084 llbuf->ld_magic = LOCLISTS_MAGIC;
1085 llhead->ll_locdesc = llbuf;
1086 llhead->ll_locdesc_count = listlen;
1087 cucontext = llhead->ll_context;
1088 llhead->ll_llearea_offset = loclist_offset;
1089 /* Now get loc ops */
1090 for (lli = 0; lli < listlen; ++lli) {
1091 int lres = 0;
1092 Dwarf_Half lle_op = 0;
1093 Dwarf_Bool at_end = 0;
1094 Dwarf_Block_c loc_block;
1095 Dwarf_Unsigned rawlowpc = 0;
1096 Dwarf_Unsigned rawhighpc = 0;
1097 int blkres = 0;
1098
1099 memset(&loc_block,0,sizeof(loc_block));
1100 if (lkind == DW_LKIND_GNU_exp_list) {
1101 blkres = _dwarf_read_loc_section_dwo(dbg,
1102 &loc_block,
1103 &rawlowpc, &rawhighpc,
1104 &at_end, &lle_op,
1105 loclist_offset,
1106 address_size,
1107 lkind,
1108 error);
1109 } else {
1110 blkres = _dwarf_read_loc_section(dbg,
1111 &loc_block,
1112 &rawlowpc, &rawhighpc,
1113 &lle_op,
1114 loclist_offset,
1115 address_size,
1116 error);
1117 }
1118 if (blkres != DW_DLV_OK) {
1119 return blkres;
1120 }
1121 /* Fills in the locdesc and its operators list at index lli */
1122 lres = _dwarf_fill_in_locdesc_op_c(dbg,
1123 lli,
1124 llhead,
1125 &loc_block,
1126 address_size,
1127 cucontext->cc_length_size,
1128 cucontext->cc_version_stamp,
1129 rawlowpc,
1130 rawhighpc,
1131 lle_op,
1132 error);
1133 if (lres != DW_DLV_OK) {
1134 return lres;
1135 }
1136 /* Now get to next loclist entry offset. */
1137 loclist_offset = loc_block.bl_section_offset +
1138 loc_block.bl_len;
1139 }
1140 /* We need to calculate the cooked values for
1141 each locldesc entry, that will be done
1142 in dwarf_get_loclist_d(). */
1143
1144 llhead->ll_bytes_total = loclist_offset -
1145 starting_loclist_offset;
1146 return DW_DLV_OK;
1147 }
1148
1149 static int
1150 _dwarf_original_expression_build(Dwarf_Debug dbg,
1151 Dwarf_Loc_Head_c llhead,
1152 Dwarf_Attribute attr,
1153 Dwarf_Error *error)
1154 {
1155
1156 Dwarf_Block_c loc_blockc;
1157 Dwarf_Unsigned rawlowpc = 0;
1158 Dwarf_Unsigned rawhighpc = 0;
1159 unsigned form = llhead->ll_attrform;
1160 int blkres = 0;
1161 Dwarf_Locdesc_c llbuf = 0;
1162 unsigned listlen = 1;
1163 Dwarf_CU_Context cucontext = llhead->ll_context;
1164 unsigned address_size = llhead->ll_address_size;
1165
1166 memset(&loc_blockc,0,sizeof(loc_blockc));
1167 if (form == DW_FORM_exprloc) {
1168 /* A bit ugly. dwarf_formexprloc should use a
1169 Dwarf_Block argument. */
1170 blkres = dwarf_formexprloc(attr,&loc_blockc.bl_len,
1171 (Dwarf_Ptr)&loc_blockc.bl_data,error);
1172 if (blkres != DW_DLV_OK) {
1173 return blkres;
1174 }
1175 loc_blockc.bl_kind = llhead->ll_lkind;
1176 loc_blockc.bl_section_offset =
1177 (char *)loc_blockc.bl_data -
1178 (char *)dbg->de_debug_info.dss_data;
1179 loc_blockc.bl_locdesc_offset = 0; /* not relevant */
1180 } else {
1181 Dwarf_Block loc_block;
1182
1183 memset(&loc_block,0,sizeof(loc_block));
1184 blkres = _dwarf_formblock_internal(dbg,attr,
1185 llhead->ll_context,
1186 &loc_block,
1187 error);
1188 if (blkres != DW_DLV_OK) {
1189 return blkres;
1190 }
1191 loc_blockc.bl_len = loc_block.bl_len;
1192 loc_blockc.bl_data = loc_block.bl_data;
1193 loc_blockc.bl_kind = llhead->ll_lkind;
1194 loc_blockc.bl_section_offset =
1195 loc_block.bl_section_offset;
1196 loc_blockc.bl_locdesc_offset = 0; /* not relevant */
1197 }
1198 /* We will mark the Locdesc_c DW_LLE_start_end
1199 shortly. Here we fake the address range
1200 as 'all addresses'. */
1201 rawlowpc = 0;
1202 rawhighpc = MAX_ADDR;
1203
1204 llbuf = (Dwarf_Locdesc_c)
1205 _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
1206 if (!llbuf) {
1207 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1208 return DW_DLV_ERROR;
1209 }
1210 llbuf->ld_magic = LOCLISTS_MAGIC;
1211 llhead->ll_locdesc = llbuf;
1212 /* Count is one by definition of a location entry. */
1213 llhead->ll_locdesc_count = listlen;
1214 llbuf = 0;
1215
1216 /* An empty location description (block length 0)
1217 means the code generator emitted no variable,
1218 the variable was not generated, it was unused
1219 or perhaps never tested after being set. Dwarf2,
1220 section 2.4.1 In other words, it is not an error,
1221 and we don't test for block length 0 specially here. */
1222
1223 /* Fills in the locdesc and its operators list
1224 at index 0 */
1225 blkres = _dwarf_fill_in_locdesc_op_c(dbg,
1226 0, /* fake locdesc is index 0 */
1227 llhead,
1228 &loc_blockc,
1229 llhead->ll_address_size,
1230 cucontext->cc_length_size,
1231 cucontext->cc_version_stamp,
1232 rawlowpc, rawhighpc,
1233 0,
1234 error);
1235 llhead->ll_bytes_total += loc_blockc.bl_len;
1236 if (blkres != DW_DLV_OK) {
1237 /* low level error already set: let problem be passed back */
1238 dwarf_dealloc(dbg,llhead->ll_locdesc,DW_DLA_LOCDESC_C);
1239 llhead->ll_locdesc = 0;
1240 llhead->ll_locdesc_count = 0;
1241 return blkres;
1242 }
1243 return DW_DLV_OK;
1244 }
1245
1246 /* Following the original loclist definition the low
1247 value is all one bits, the high value is the base
1248 address. */
1249 static int
1250 cook_original_loclist_contents(Dwarf_Debug dbg,
1251 Dwarf_Loc_Head_c llhead,
1252 Dwarf_Error *error)
1253 {
1254 Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1255 Dwarf_Unsigned count = llhead->ll_locdesc_count;
1256 Dwarf_Unsigned i = 0;
1257
1258 for ( i = 0 ; i < count; ++i) {
1259 Dwarf_Locdesc_c llc = 0;
1260
1261 llc = llhead->ll_locdesc +i;
1262 switch(llc->ld_lle_value) {
1263 case DW_LLE_end_of_list: {
1264 /* nothing to do */
1265 break;
1266 }
1267 case DW_LLE_base_address: {
1268 llc->ld_lopc = llc->ld_rawhigh;
1269 llc->ld_highpc = llc->ld_rawhigh;
1270 baseaddress = llc->ld_rawhigh;
1271 break;
1272 }
1273 /* This is the only way baseaddress is used. */
1274 case DW_LLE_offset_pair: {
1275 llc->ld_lopc = llc->ld_rawlow + baseaddress;
1276 llc->ld_highpc = llc->ld_rawhigh + baseaddress;
1277 break;
1278 }
1279 default: {
1280 dwarfstring m;
1281
1282 dwarfstring_constructor(&m);
1283 dwarfstring_append_printf_u(&m,
1284 "DW_DLE_LOCLISTS_ERROR: "
1285 "improper synthesized LLE code "
1286 "of 0x%x is unknown. In standard DWARF3/4 loclist",
1287 llc->ld_lle_value);
1288 _dwarf_error_string(dbg,error,
1289 DW_DLE_LOCLISTS_ERROR,
1290 dwarfstring_string(&m));
1291 dwarfstring_destructor(&m);
1292 return DW_DLV_ERROR;
1293 }
1294 }
1295 }
1296 return DW_DLV_OK;
1297 }
1298
1299 static int
1300 cook_gnu_loclist_contents(Dwarf_Debug dbg,
1301 Dwarf_Loc_Head_c llhead,
1302 Dwarf_Error *error)
1303 {
1304 Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1305 Dwarf_Unsigned count = llhead->ll_locdesc_count;
1306 Dwarf_Unsigned i = 0;
1307 Dwarf_CU_Context cucontext = llhead->ll_context;
1308 int res = 0;
1309
1310 for (i = 0 ; i < count ; ++i) {
1311 Dwarf_Locdesc_c llc = 0;
1312
1313 llc = llhead->ll_locdesc +i;
1314 switch(llc->ld_lle_value) {
1315 case DW_LLEX_base_address_selection_entry:{
1316 Dwarf_Addr targaddr = 0;
1317
1318 res = _dwarf_look_in_local_and_tied_by_index(
1319 dbg,cucontext,llc->ld_rawhigh,&targaddr,
1320 error);
1321 if (res != DW_DLV_OK) {
1322 llc->ld_index_failed = TRUE;
1323 llc->ld_lopc = 0;
1324 llc->ld_highpc = 0;
1325 if (res == DW_DLV_ERROR && error) {
1326 dwarf_dealloc_error(dbg, *error);
1327 *error = 0;
1328 }
1329 } else {
1330 llc->ld_lopc = targaddr;
1331 llc->ld_highpc = targaddr;
1332 }
1333 break;
1334 }
1335 case DW_LLEX_end_of_list_entry:{
1336 /* Nothing to do. */
1337 break;
1338 }
1339 case DW_LLEX_start_length_entry:{
1340 Dwarf_Addr targaddr = 0;
1341 res = _dwarf_look_in_local_and_tied_by_index(
1342 dbg,cucontext,llc->ld_rawlow,&targaddr,
1343 error);
1344 if (res != DW_DLV_OK) {
1345 llc->ld_index_failed = TRUE;
1346 llc->ld_lopc = 0;
1347 if (res == DW_DLV_ERROR && error) {
1348 dwarf_dealloc_error(dbg, *error);
1349 *error = 0;
1350 }
1351 } else {
1352 llc->ld_lopc = targaddr;
1353 llc->ld_highpc = llc->ld_lopc +llc->ld_rawhigh;
1354 }
1355 break;
1356 }
1357 case DW_LLEX_offset_pair_entry:{
1358 llc->ld_lopc = llc->ld_rawlow + baseaddress;
1359 llc->ld_highpc = llc->ld_rawhigh + baseaddress;
1360 break;
1361 }
1362 case DW_LLEX_start_end_entry:{
1363 Dwarf_Addr targaddr = 0;
1364 res = _dwarf_look_in_local_and_tied_by_index(
1365 dbg,cucontext,llc->ld_rawlow,&targaddr,
1366 error);
1367 if (res != DW_DLV_OK) {
1368 llc->ld_index_failed = TRUE;
1369 llc->ld_lopc = 0;
1370 if (res == DW_DLV_ERROR && error) {
1371 dwarf_dealloc_error(dbg, *error);
1372 *error = 0;
1373 }
1374 } else {
1375 llc->ld_lopc = targaddr;
1376 }
1377 res = _dwarf_look_in_local_and_tied_by_index(
1378 dbg,cucontext,llc->ld_rawlow,&targaddr,
1379 error);
1380 if (res != DW_DLV_OK) {
1381 llc->ld_index_failed = TRUE;
1382 llc->ld_highpc = 0;
1383 if (res == DW_DLV_ERROR && error) {
1384 dwarf_dealloc_error(dbg, *error);
1385 *error = 0;
1386 }
1387 } else {
1388 llc->ld_highpc = targaddr;
1389 }
1390
1391 break;
1392 }
1393 default:{
1394 dwarfstring m;
1395
1396 dwarfstring_constructor(&m);
1397 dwarfstring_append_printf_u(&m,
1398 "DW_DLE_LOCLISTS_ERROR: improper LLEX code "
1399 "of 0x%x is unknown. GNU LLEX dwo loclists error",
1400 llc->ld_lle_value);
1401 _dwarf_error_string(dbg,error,
1402 DW_DLE_LOCLISTS_ERROR,
1403 dwarfstring_string(&m));
1404 dwarfstring_destructor(&m);
1405 return DW_DLV_ERROR;
1406
1407 break;
1408 }
1409 }
1410 }
1411 return DW_DLV_OK;
1412 }
1413
1414 /* DWARF5 */
1415 static int
1416 cook_loclists_contents(Dwarf_Debug dbg,
1417 Dwarf_Loc_Head_c llhead,
1418 Dwarf_Error *error)
1419 {
1420 Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1421 Dwarf_Unsigned count = llhead->ll_locdesc_count;
1422 Dwarf_Unsigned i = 0;
1423 Dwarf_CU_Context cucontext = llhead->ll_context;
1424 int res = 0;
1425 Dwarf_Bool base_address_fail = FALSE;
1426 Dwarf_Bool debug_addr_fail = FALSE;
1427
1428 if (!llhead->ll_cu_base_address_present) {
1429 base_address_fail = TRUE;
1430 }
1431 for (i = 0 ; i < count ; ++i) {
1432 Dwarf_Locdesc_c llc = 0;
1433
1434 llc = llhead->ll_locdesc +i;
1435 switch(llc->ld_lle_value) {
1436 case DW_LLE_base_addressx: {
1437 Dwarf_Addr targaddr = 0;
1438 if (debug_addr_fail) {
1439 res = DW_DLV_NO_ENTRY;
1440 } else {
1441 res = _dwarf_look_in_local_and_tied_by_index(
1442 dbg,cucontext,llc->ld_rawlow,&targaddr,
1443 error);
1444 }
1445 if (res != DW_DLV_OK) {
1446 debug_addr_fail = TRUE;
1447 base_address_fail = TRUE;
1448 llc->ld_index_failed = TRUE;
1449 llc->ld_lopc = 0;
1450 if (res == DW_DLV_ERROR && error) {
1451 dwarf_dealloc_error(dbg, *error);
1452 *error = 0;
1453 }
1454 } else {
1455 base_address_fail = FALSE;
1456 baseaddress = targaddr;
1457 llc->ld_lopc = targaddr;
1458 }
1459 break;
1460 }
1461 case DW_LLE_startx_endx:{
1462 /* two indexes into debug_addr */
1463 Dwarf_Addr targaddr = 0;
1464 if (debug_addr_fail) {
1465 res = DW_DLV_NO_ENTRY;
1466 } else {
1467 res = _dwarf_look_in_local_and_tied_by_index(
1468 dbg,cucontext,llc->ld_rawlow,&targaddr,
1469 error);
1470 }
1471 if (res != DW_DLV_OK) {
1472 debug_addr_fail = TRUE;
1473 llc->ld_index_failed = TRUE;
1474 llc->ld_lopc = 0;
1475 if (res == DW_DLV_ERROR && error) {
1476 dwarf_dealloc_error(dbg, *error);
1477 *error = 0;
1478 }
1479 } else {
1480 llc->ld_lopc = targaddr;
1481 }
1482 if (debug_addr_fail) {
1483 res = DW_DLV_NO_ENTRY;
1484 } else {
1485 res = _dwarf_look_in_local_and_tied_by_index(
1486 dbg,cucontext,llc->ld_rawhigh,&targaddr,
1487 error);
1488
1489 }
1490 if (res != DW_DLV_OK) {
1491 debug_addr_fail = TRUE;
1492 llc->ld_index_failed = TRUE;
1493 llc->ld_highpc = 0;
1494 if (res == DW_DLV_ERROR && error) {
1495 dwarf_dealloc_error(dbg, *error);
1496 *error = 0;
1497 }
1498 } else {
1499 llc->ld_highpc = targaddr;
1500 }
1501 break;
1502 }
1503 case DW_LLE_startx_length:{
1504 /* one index to debug_addr other a length */
1505 Dwarf_Addr targaddr = 0;
1506 if (debug_addr_fail) {
1507 res = DW_DLV_NO_ENTRY;
1508 } else {
1509 res = _dwarf_look_in_local_and_tied_by_index(
1510 dbg,cucontext,llc->ld_rawlow,&targaddr,
1511 error);
1512 }
1513 if (res != DW_DLV_OK) {
1514 debug_addr_fail = TRUE;
1515 llc->ld_index_failed = TRUE;
1516 llc->ld_lopc = 0;
1517 if (res == DW_DLV_ERROR && error) {
1518 dwarf_dealloc_error(dbg, *error);
1519 *error = 0;
1520 }
1521 } else {
1522 llc->ld_lopc = targaddr;
1523 llc->ld_highpc = targaddr + llc->ld_rawhigh;
1524 }
1525 break;
1526 }
1527 case DW_LLE_offset_pair:{
1528 if (base_address_fail) {
1529 llc->ld_index_failed = TRUE;
1530 llc->ld_lopc = 0;
1531 llc->ld_highpc = 0;
1532 } else {
1533 /*offsets of the current base address*/
1534 llc->ld_lopc = llc->ld_rawlow +baseaddress;
1535 llc->ld_highpc = llc->ld_rawhigh +baseaddress;
1536 }
1537 break;
1538 }
1539 case DW_LLE_default_location:{
1540 /* nothing to do here, just has a counted
1541 location description */
1542 break;
1543 }
1544 case DW_LLE_base_address:{
1545 llc->ld_lopc = llc->ld_rawlow;
1546 llc->ld_highpc = llc->ld_rawlow;
1547 baseaddress = llc->ld_rawlow;
1548 base_address_fail = FALSE;
1549 break;
1550 }
1551 case DW_LLE_start_end:{
1552 llc->ld_lopc = llc->ld_rawlow;
1553 llc->ld_highpc = llc->ld_rawhigh;
1554 break;
1555 }
1556 case DW_LLE_start_length:{
1557 llc->ld_lopc = llc->ld_rawlow;
1558 llc->ld_highpc = llc->ld_rawlow + llc->ld_rawhigh;
1559 break;
1560 }
1561 case DW_LLE_end_of_list:{
1562 /* do nothing */
1563 break;
1564 }
1565 default: {
1566 dwarfstring m;
1567
1568 dwarfstring_constructor(&m);
1569 dwarfstring_append_printf_u(&m,
1570 "DW_DLE_LOCLISTS_ERROR: improper DW_LLE code "
1571 "of 0x%x is unknown. DWARF5 loclists error",
1572 llc->ld_lle_value);
1573 _dwarf_error_string(dbg,error,
1574 DW_DLE_LOCLISTS_ERROR,
1575 dwarfstring_string(&m));
1576 dwarfstring_destructor(&m);
1577 return DW_DLV_ERROR;
1578 }
1579 }
1580 }
1581 return DW_DLV_OK;
1582 }
1583
1584 /* New October 2015
1585 This interface requires the use of interface functions
1586 to get data from Dwarf_Locdesc_c. The structures
1587 are not visible to callers. */
1588 int
1589 dwarf_get_loclist_c(Dwarf_Attribute attr,
1590 Dwarf_Loc_Head_c * ll_header_out,
1591 Dwarf_Unsigned * listlen_out,
1592 Dwarf_Error * error)
1593 {
1594 Dwarf_Debug dbg = 0;
1595 Dwarf_Half form = 0;
1596 Dwarf_Loc_Head_c llhead = 0;
1597 unsigned address_size = 0;
1598 Dwarf_Half cuversionstamp = 0;
1599 Dwarf_Bool is_cu = FALSE;
1600 Dwarf_Unsigned attrnum = 0;
1601 Dwarf_Bool is_dwo = 0;
1602 int lkind = 0;
1603 Dwarf_CU_Context ctx = 0;
1604 Dwarf_Bool is_loclistx = FALSE;
1605 Dwarf_Unsigned attr_val = 0;
1606 Dwarf_Bool offset_is_info = TRUE;
1607 int res = 0;
1608 int setup_res = 0;
1609
1610 if (!attr) {
1611 _dwarf_error_string(dbg, error,DW_DLE_ATTR_NULL,
1612 "DW_DLE_ATTR_NULL"
1613 "NULL Dwarf_Attribute "
1614 "argument passed to "
1615 "dwarf_get_loclist_c()");
1616 return DW_DLV_ERROR;
1617 }
1618 setup_res = _dwarf_setup_loc(attr, &dbg,&ctx, &form, error);
1619 if (setup_res != DW_DLV_OK) {
1620 return setup_res;
1621 }
1622
1623 CHECK_DBG(dbg,error,"dwarf_get_loclist_c()");
1624 if (form == DW_FORM_loclistx) {
1625 is_loclistx = TRUE;
1626 }
1627 attrnum = attr->ar_attribute;
1628 cuversionstamp = ctx->cc_version_stamp;
1629 address_size = ctx->cc_address_size;
1630 is_dwo = ctx->cc_is_dwo;
1631 lkind = determine_location_lkind(cuversionstamp,
1632 form, is_dwo);
1633
1634 if (form == DW_FORM_loclistx || form == DW_FORM_sec_offset) {
1635 /* Aimed at DWARF5 and later */
1636 res = dwarf_global_formref_b(attr,&attr_val,
1637 &offset_is_info,error);
1638 if (res != DW_DLV_OK) {
1639 return res;
1640 }
1641 }
1642 if (lkind == DW_LKIND_loclists) {
1643 if (is_loclistx) {
1644 if (ctx->cc_loclists_base_present ||
1645 dbg->de_loclists_context_count == 1) {
1646 /* leave on primary.
1647 WARNING: It is not clear whether
1648 looking for a context count of 1
1649 is actually correct, but it
1650 seems to work. */
1651 } else if (DBG_HAS_SECONDARY(dbg)){
1652 dbg = dbg->de_secondary_dbg;
1653 CHECK_DBG(dbg,error,
1654 "dwarf_loclists_get_lle_head() "
1655 "via attribute(sec)");
1656 }
1657 } else {
1658 /* attr_val is .debug_loclists[.dwo]
1659 section global offset
1660 of a location list*/
1661 if (!dbg->de_debug_loclists.dss_size ||
1662 attr_val >= dbg->de_debug_loclists.dss_size) {
1663 if (DBG_HAS_SECONDARY(dbg)) {
1664 dbg = dbg->de_secondary_dbg;
1665 CHECK_DBG(dbg,error,
1666 "dwarf_loclists_get_lle_head() "
1667 "via attribute(secb)");
1668 } else {
1669 /* There is an error to be
1670 generated later */
1671 }
1672 }
1673 }
1674 res = _dwarf_load_section(dbg,
1675 &dbg->de_debug_loclists,
1676 error);
1677 if (res == DW_DLV_ERROR) {
1678 return res;
1679 }
1680 }
1681
1682 attrnum = attr->ar_attribute;
1683 cuversionstamp = ctx->cc_version_stamp;
1684 address_size = ctx->cc_address_size;
1685 is_dwo = ctx->cc_is_dwo;
1686 lkind = determine_location_lkind(cuversionstamp,
1687 form, is_dwo);
1688 if (lkind == DW_LKIND_unknown) {
1689 dwarfstring m;
1690 const char * formname = "<unknownform>";
1691 const char * attrname = "<unknown attribute>";
1692
1693 dwarfstring_constructor(&m);
1694 dwarf_get_FORM_name((unsigned int)form,&formname);
1695 dwarf_get_AT_name((unsigned int)attrnum,&attrname);
1696 dwarfstring_append_printf_u(&m,
1697 "DW_DLE_LOC_EXPR_BAD: For Compilation Unit "
1698 "version %u",cuversionstamp);
1699 dwarfstring_append_printf_u(&m,
1700 ", attribute 0x%x (",attrnum);
1701 dwarfstring_append(&m,(char *)attrname);
1702 dwarfstring_append_printf_u(&m,
1703 ") form 0x%x (",form);
1704 dwarfstring_append(&m,(char *)formname);
1705 if (is_dwo) {
1706 dwarfstring_append(&m,") (the CU is a .dwo) ");
1707 } else {
1708 dwarfstring_append(&m,") (the CU is not a .dwo) ");
1709 }
1710 dwarfstring_append(&m," we don't understand the location");
1711 _dwarf_error_string(dbg,error,DW_DLE_LOC_EXPR_BAD,
1712 dwarfstring_string(&m));
1713 dwarfstring_destructor(&m);
1714 return DW_DLV_ERROR;
1715 }
1716 /* Doing this early (first) to avoid repeating the alloc code
1717 for each type */
1718 llhead = (Dwarf_Loc_Head_c)
1719 _dwarf_get_alloc(dbg, DW_DLA_LOC_HEAD_C, 1);
1720 if (!llhead) {
1721 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1722 return DW_DLV_ERROR;
1723 }
1724 llhead->ll_cuversion = cuversionstamp;
1725 llhead->ll_lkind = lkind;
1726 llhead->ll_attrnum = (Dwarf_Half)attrnum;
1727 llhead->ll_attrform = (Dwarf_Half)form;
1728 llhead->ll_dbg = dbg;
1729 llhead->ll_address_size = address_size;
1730 llhead->ll_offset_size = ctx->cc_length_size;
1731 llhead->ll_context = ctx;
1732 llhead->ll_magic = LOCLISTS_MAGIC;
1733
1734 llhead->ll_at_loclists_base_present =
1735 ctx->cc_loclists_base_present;
1736 llhead->ll_at_loclists_base = ctx->cc_loclists_base;
1737 llhead->ll_cu_base_address_present =
1738 ctx->cc_base_address_present;
1739 llhead->ll_cu_base_address = ctx->cc_base_address;
1740
1741 llhead->ll_cu_addr_base_offset = ctx->cc_addr_base_offset;
1742 llhead->ll_cu_addr_base_offset_present =
1743 ctx->cc_addr_base_offset_present;
1744
1745 if (lkind == DW_LKIND_loclist ||
1746 lkind == DW_LKIND_GNU_exp_list) {
1747 int ores = 0;
1748 /* Here we have a loclist to deal with. */
1749 ores = context_is_cu_not_tu(ctx,&is_cu);
1750 if (ores != DW_DLV_OK) {
1751 dwarf_dealloc_loc_head_c(llhead);
1752 return ores;
1753 }
1754 ores = _dwarf_original_loclist_build(dbg,
1755 llhead, attr, error);
1756 if (ores != DW_DLV_OK) {
1757 dwarf_dealloc_loc_head_c(llhead);
1758 return ores;
1759 }
1760 if (lkind == DW_LKIND_loclist) {
1761 ores = cook_original_loclist_contents(dbg,llhead,
1762 error);
1763 } else {
1764 ores = cook_gnu_loclist_contents(dbg,llhead,error);
1765 }
1766 if (ores != DW_DLV_OK) {
1767 dwarf_dealloc_loc_head_c(llhead);
1768 return ores;
1769 }
1770 } else if (lkind == DW_LKIND_expression) {
1771 /* DWARF2,3,4,5 */
1772 int eres = 0;
1773 eres = _dwarf_original_expression_build(dbg,
1774 llhead, attr, error);
1775 if (eres != DW_DLV_OK) {
1776 dwarf_dealloc_loc_head_c(llhead);
1777 return eres;
1778 }
1779 } else if (lkind == DW_LKIND_loclists) {
1780 /* DWARF5! */
1781 int leres = 0;
1782
1783 leres = _dwarf_loclists_fill_in_lle_head(dbg,
1784 attr,form,attr_val,llhead,error);
1785 if (leres != DW_DLV_OK) {
1786 dwarf_dealloc_loc_head_c(llhead);
1787 return leres;
1788 }
1789 leres = cook_loclists_contents(dbg,llhead,error);
1790 if (leres != DW_DLV_OK) {
1791 dwarf_dealloc_loc_head_c(llhead);
1792 return leres;
1793 }
1794 } /* ASSERT else impossible */
1795 *ll_header_out = llhead;
1796 *listlen_out = llhead->ll_locdesc_count;
1797 return DW_DLV_OK;
1798 }
1799
1800 /* An interface giving us no cu context!
1801 This is not going to be quite right. */
1802 int
1803 dwarf_loclist_from_expr_c(Dwarf_Debug dbg,
1804 Dwarf_Ptr expression_in,
1805 Dwarf_Unsigned expression_length,
1806 Dwarf_Half address_size,
1807 Dwarf_Half offset_size,
1808 Dwarf_Half dwarf_version,
1809 Dwarf_Loc_Head_c *loc_head,
1810 Dwarf_Unsigned * listlen,
1811 Dwarf_Error * error)
1812 {
1813 /* Dwarf_Block that describes a single location expression. */
1814 Dwarf_Block_c loc_block;
1815 Dwarf_Loc_Head_c llhead = 0;
1816 Dwarf_Locdesc_c llbuf = 0;
1817 int local_listlen = 1;
1818 Dwarf_Addr rawlowpc = 0;
1819 Dwarf_Addr rawhighpc = MAX_ADDR;
1820 Dwarf_Half version_stamp = dwarf_version;
1821 int res = 0;
1822
1823 CHECK_DBG(dbg,error,"dwarf_loclist_from_expr_c()");
1824 llhead = (Dwarf_Loc_Head_c)_dwarf_get_alloc(dbg,
1825 DW_DLA_LOC_HEAD_C, 1);
1826 if (!llhead) {
1827 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1828 return DW_DLV_ERROR;
1829 }
1830 llhead->ll_magic = LOCLISTS_MAGIC;
1831 memset(&loc_block,0,sizeof(loc_block));
1832 loc_block.bl_len = expression_length;
1833 loc_block.bl_data = expression_in;
1834 loc_block.bl_kind = DW_LKIND_expression; /* Not from loclist. */
1835 loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
1836 loc_block.bl_locdesc_offset = 0; /* Fake. Not meaningful. */
1837 llbuf = (Dwarf_Locdesc_c)
1838 _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, local_listlen);
1839 if (!llbuf) {
1840 dwarf_dealloc_loc_head_c(llhead);
1841 _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1842 return DW_DLV_ERROR;
1843 }
1844 llbuf->ld_magic = LOCLISTS_MAGIC;
1845 llhead->ll_locdesc = llbuf;
1846 llhead->ll_locdesc_count = local_listlen;
1847 llhead->ll_context = 0; /* Not available! */
1848 llhead->ll_dbg = dbg;
1849 llhead->ll_lkind = DW_LKIND_expression;
1850
1851 /* An empty location description (block length 0)
1852 means the code generator emitted no variable,
1853 the variable was not generated,
1854 it was unused or perhaps never tested
1855 after being set. Dwarf2,
1856 section 2.4.1 In other words, it is not
1857 an error, and we don't
1858 test for block length 0 specially here. */
1859
1860 /* Fills in the locdesc and its operators list at index 0 */
1861 res = _dwarf_fill_in_locdesc_op_c(dbg,
1862 0,
1863 llhead,
1864 &loc_block,
1865 address_size,
1866 offset_size,
1867 version_stamp,
1868 rawlowpc,
1869 rawhighpc,
1870 DW_LKIND_expression,
1871 error);
1872 if (res != DW_DLV_OK) {
1873 /* low level error already set: let it be passed back */
1874 dwarf_dealloc(dbg,llbuf,DW_DLA_LOCDESC_C);
1875 llhead->ll_locdesc = 0;
1876 llhead->ll_locdesc_count = 0;
1877 dwarf_dealloc_loc_head_c(llhead);
1878 return DW_DLV_ERROR;
1879 }
1880 *loc_head = llhead;
1881 *listlen = local_listlen;
1882 return DW_DLV_OK;
1883 }
1884
1885 /* New June 2020 Supports all versions of DWARF.
1886 Distinguishes location entry values as in the
1887 file directly (raw) from the computed
1888 value (lowpc_out,hipc_out) after
1889 applying base values (if any). */
1890 int
1891 dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c loclist_head,
1892 Dwarf_Unsigned index,
1893 /* Dwarf_Unsigned lle_entry_index, */
1894 Dwarf_Small * lle_value_out,
1895 Dwarf_Unsigned * rawval1,
1896 Dwarf_Unsigned * rawval2,
1897 Dwarf_Bool * debug_addr_unavailable,
1898 Dwarf_Addr * lowpc_out, /* 'cooked' value */
1899 Dwarf_Addr * hipc_out, /* 'cooked' value */
1900 Dwarf_Unsigned * loclist_expr_op_count_out,
1901 /* Returns pointer to the specific locdesc of the index; */
1902 Dwarf_Locdesc_c* locdesc_entry_out,
1903 Dwarf_Small * loclist_source_out, /* 0,1, or 2 */
1904 Dwarf_Unsigned * expression_offset_out,
1905 Dwarf_Unsigned * locdesc_offset_out,
1906 Dwarf_Error * error)
1907 {
1908 return dwarf_get_locdesc_entry_e(
1909 loclist_head, index,
1910 /*0 base local index,*/
1911 lle_value_out,
1912 rawval1,
1913 rawval2,
1914 debug_addr_unavailable,
1915 lowpc_out, /* 'cooked' value */
1916 hipc_out, /* 'cooked' value */
1917 loclist_expr_op_count_out,
1918 0 /* not returning lle_bytecount*/ ,
1919 /* Returns pointer to the specific locdesc of the index; */
1920 locdesc_entry_out,
1921 loclist_source_out, /* 0,1, or 2 */
1922 expression_offset_out,
1923 locdesc_offset_out,
1924 error);
1925 }
1926 int
1927 dwarf_get_locdesc_entry_e(Dwarf_Loc_Head_c loclist_head,
1928 /* The context-local offset of an lle set as reverenced
1929 by an offset_entry_table. */
1930 Dwarf_Unsigned index,
1931 /*Dwarf_Unsigned base_local_index, */
1932 Dwarf_Small * lle_value_out,
1933 Dwarf_Unsigned * rawval1,
1934 Dwarf_Unsigned * rawval2,
1935 Dwarf_Bool * debug_addr_unavailable,
1936 Dwarf_Addr * lowpc_out, /* 'cooked' value */
1937 Dwarf_Addr * hipc_out, /* 'cooked' value */
1938 Dwarf_Unsigned * loclist_expr_op_count_out,
1939 /* Returns pointer to the specific locdesc of the index; */
1940 Dwarf_Unsigned * lle_bytecount,
1941 Dwarf_Locdesc_c* locdesc_entry_out,
1942 Dwarf_Small * loclist_source_out, /* 0,1, or 2 */
1943 Dwarf_Unsigned * expression_offset_out,
1944 Dwarf_Unsigned * locdesc_offset_out,
1945 Dwarf_Error * error)
1946 {
1947 Dwarf_Locdesc_c descs_base = 0;
1948 Dwarf_Locdesc_c desc = 0;
1949 Dwarf_Unsigned desc_count = 0;
1950 Dwarf_Debug dbg = 0;
1951
1952 if (!loclist_head || loclist_head->ll_magic != LOCLISTS_MAGIC) {
1953 _dwarf_error_string(dbg, error,DW_DLE_DBG_NULL,
1954 "DW_DLE_DBG_NULL: "
1955 "Dwarf_Loc_Head_c NULL or not "
1956 "marked LOCLISTS_MAGIC "
1957 "in calling "
1958 "dwarf_get_locdesc_entry_d()");
1959 return DW_DLV_ERROR;
1960 }
1961 desc_count = loclist_head->ll_locdesc_count;
1962 descs_base = loclist_head->ll_locdesc;
1963 dbg = loclist_head->ll_dbg;
1964 if (index >= desc_count) {
1965 _dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
1966 return DW_DLV_ERROR;
1967 }
1968 desc = descs_base + index;
1969 *lle_value_out = desc->ld_lle_value;
1970 *rawval1 = desc->ld_rawlow;
1971 *rawval2 = desc->ld_rawhigh;
1972 *lowpc_out = desc->ld_lopc;
1973 *hipc_out = desc->ld_highpc;
1974 *debug_addr_unavailable = desc->ld_index_failed;
1975 *loclist_expr_op_count_out = desc->ld_cents;
1976 *locdesc_entry_out = desc;
1977 *loclist_source_out = (Dwarf_Small)desc->ld_lkind;
1978 *expression_offset_out = desc->ld_section_offset;
1979 *locdesc_offset_out = desc->ld_locdesc_offset;
1980 if (lle_bytecount) {
1981 *lle_bytecount = desc->ld_lle_bytecount;
1982 }
1983 return DW_DLV_OK;
1984 }
1985
1986 int
1987 dwarf_get_location_op_value_c(Dwarf_Locdesc_c locdesc,
1988 Dwarf_Unsigned index,
1989 Dwarf_Small * atom_out,
1990 Dwarf_Unsigned * operand1,
1991 Dwarf_Unsigned * operand2,
1992 Dwarf_Unsigned * operand3,
1993 Dwarf_Unsigned * offset_for_branch,
1994 Dwarf_Error* error)
1995 {
1996 Dwarf_Loc_Expr_Op op = 0;
1997 Dwarf_Unsigned max = 0;
1998
1999 if (!locdesc) {
2000 _dwarf_error_string(NULL, error,DW_DLE_DBG_NULL,
2001 "DW_DLE_DBG_NULL"
2002 "Dwarf_Locdesc_c_Head_c NULL "
2003 "in calling "
2004 "dwarf_get_location_op_value_c()");
2005 return DW_DLV_ERROR;
2006 }
2007 max = locdesc->ld_cents;
2008 if (index >= max) {
2009 Dwarf_Debug dbg = locdesc->ld_loclist_head->ll_dbg;
2010 _dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
2011 return DW_DLV_ERROR;
2012 }
2013 op = locdesc->ld_s + index;
2014 *atom_out = op->lr_atom;
2015 *operand1 = op->lr_number;
2016 *operand2 = op->lr_number2;
2017 *operand3 = op->lr_number3;
2018 *offset_for_branch = op->lr_offset;
2019 return DW_DLV_OK;
2020 }
2021 /* ============== End of the October 2015 interfaces. */