1bc1f688bSRobert Mustacchi /*
2bc1f688bSRobert Mustacchi   Copyright (C) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
3*4d9fdb46SRobert Mustacchi   Portions Copyright (C) 2007-2018 David Anderson. All Rights Reserved.
4*4d9fdb46SRobert Mustacchi   Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved.
5bc1f688bSRobert Mustacchi 
6*4d9fdb46SRobert Mustacchi   This program is free software; you can redistribute it
7*4d9fdb46SRobert Mustacchi   and/or modify it under the terms of version 2.1 of the
8*4d9fdb46SRobert Mustacchi   GNU Lesser General Public License as published by the Free
9*4d9fdb46SRobert Mustacchi   Software Foundation.
10bc1f688bSRobert Mustacchi 
11*4d9fdb46SRobert Mustacchi   This program is distributed in the hope that it would be
12*4d9fdb46SRobert Mustacchi   useful, but WITHOUT ANY WARRANTY; without even the implied
13*4d9fdb46SRobert Mustacchi   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14*4d9fdb46SRobert Mustacchi   PURPOSE.
15bc1f688bSRobert Mustacchi 
16*4d9fdb46SRobert Mustacchi   Further, this software is distributed without any warranty
17*4d9fdb46SRobert Mustacchi   that it is free of the rightful claim of any third person
18*4d9fdb46SRobert Mustacchi   regarding infringement or the like.  Any license provided
19*4d9fdb46SRobert Mustacchi   herein, whether implied or otherwise, applies only to this
20*4d9fdb46SRobert Mustacchi   software file.  Patent licenses, if any, provided herein
21*4d9fdb46SRobert Mustacchi   do not apply to combinations of this program with other
22*4d9fdb46SRobert Mustacchi   software, or any other product whatsoever.
23bc1f688bSRobert Mustacchi 
24*4d9fdb46SRobert Mustacchi   You should have received a copy of the GNU Lesser General
25*4d9fdb46SRobert Mustacchi   Public License along with this program; if not, write the
26*4d9fdb46SRobert Mustacchi   Free Software Foundation, Inc., 51 Franklin Street - Fifth
27*4d9fdb46SRobert Mustacchi   Floor, Boston MA 02110-1301, USA.
28bc1f688bSRobert Mustacchi 
29bc1f688bSRobert Mustacchi */
30bc1f688bSRobert Mustacchi 
31bc1f688bSRobert Mustacchi #include "config.h"
32bc1f688bSRobert Mustacchi #include <stdio.h> /* for debugging only. */
33*4d9fdb46SRobert Mustacchi #ifdef HAVE_STDINT_H
34*4d9fdb46SRobert Mustacchi #include <stdint.h> /* For uintptr_t */
35*4d9fdb46SRobert Mustacchi #endif /* HAVE_STDINT_H */
36*4d9fdb46SRobert Mustacchi #ifdef HAVE_STDLIB_H
37*4d9fdb46SRobert Mustacchi #include <stdlib.h> /* For uintptr_t */
38*4d9fdb46SRobert Mustacchi #endif /* HAVE_STDLIB_H */
39*4d9fdb46SRobert Mustacchi #include "dwarf_incl.h"
40*4d9fdb46SRobert Mustacchi #include "dwarf_alloc.h"
41*4d9fdb46SRobert Mustacchi #include "dwarf_error.h"
42*4d9fdb46SRobert Mustacchi #include "dwarf_util.h"
43*4d9fdb46SRobert Mustacchi #include "dwarf_loc.h"
44*4d9fdb46SRobert Mustacchi #include "dwarfstring.h"
45bc1f688bSRobert Mustacchi 
46*4d9fdb46SRobert Mustacchi #define TRUE 1
47*4d9fdb46SRobert Mustacchi #define FALSE 0
48*4d9fdb46SRobert Mustacchi 
49*4d9fdb46SRobert Mustacchi static int _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
50*4d9fdb46SRobert Mustacchi    Dwarf_Block_c * return_block,
51*4d9fdb46SRobert Mustacchi    Dwarf_Addr * lowpc,
52*4d9fdb46SRobert Mustacchi    Dwarf_Addr * highpc,
53*4d9fdb46SRobert Mustacchi    Dwarf_Bool * at_end,
54*4d9fdb46SRobert Mustacchi    Dwarf_Half * lle_op,
55*4d9fdb46SRobert Mustacchi    Dwarf_Off    sec_offset,
56*4d9fdb46SRobert Mustacchi    Dwarf_Half   address_size,
57*4d9fdb46SRobert Mustacchi    Dwarf_Half   lkind,
58*4d9fdb46SRobert Mustacchi    Dwarf_Error *error);
59*4d9fdb46SRobert Mustacchi 
60*4d9fdb46SRobert Mustacchi 
61*4d9fdb46SRobert Mustacchi static void
_dwarf_lkind_name(unsigned lkind,dwarfstring * m)62*4d9fdb46SRobert Mustacchi _dwarf_lkind_name(unsigned lkind, dwarfstring *m)
63*4d9fdb46SRobert Mustacchi {
64*4d9fdb46SRobert Mustacchi     switch(lkind) {
65*4d9fdb46SRobert Mustacchi     case DW_LKIND_expression:
66*4d9fdb46SRobert Mustacchi         dwarfstring_append(m,"DW_LKIND_expression");
67*4d9fdb46SRobert Mustacchi         return;
68*4d9fdb46SRobert Mustacchi     case DW_LKIND_loclist:
69*4d9fdb46SRobert Mustacchi         dwarfstring_append(m,"DW_LKIND_loclist");
70*4d9fdb46SRobert Mustacchi         return;
71*4d9fdb46SRobert Mustacchi     case DW_LKIND_GNU_exp_list:
72*4d9fdb46SRobert Mustacchi         dwarfstring_append(m,"DW_LKIND_GNU_exp_list");
73*4d9fdb46SRobert Mustacchi         return;
74*4d9fdb46SRobert Mustacchi     case DW_LKIND_loclists:
75*4d9fdb46SRobert Mustacchi         dwarfstring_append(m,"DW_LKIND_loclists");
76*4d9fdb46SRobert Mustacchi         return;
77*4d9fdb46SRobert Mustacchi     case DW_LKIND_unknown:
78*4d9fdb46SRobert Mustacchi         dwarfstring_append(m,"DW_LKIND_unknown");
79*4d9fdb46SRobert Mustacchi         return;
80*4d9fdb46SRobert Mustacchi     }
81*4d9fdb46SRobert Mustacchi     dwarfstring_append_printf_u(m,
82*4d9fdb46SRobert Mustacchi         "<DW_LKIND location kind is unknown and has value %u>.",
83*4d9fdb46SRobert Mustacchi         lkind);
84*4d9fdb46SRobert Mustacchi }
85*4d9fdb46SRobert Mustacchi 
86*4d9fdb46SRobert Mustacchi 
87*4d9fdb46SRobert Mustacchi static int
determine_location_lkind(unsigned int version,unsigned int form,UNUSEDARG unsigned int attribute,Dwarf_Bool is_dwo)88*4d9fdb46SRobert Mustacchi determine_location_lkind(unsigned int version,
89*4d9fdb46SRobert Mustacchi     unsigned int form,
90*4d9fdb46SRobert Mustacchi     UNUSEDARG unsigned int attribute,
91*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_dwo)
92*4d9fdb46SRobert Mustacchi {
93*4d9fdb46SRobert Mustacchi     switch(form) {
94*4d9fdb46SRobert Mustacchi     case DW_FORM_exprloc: /* only defined for
95*4d9fdb46SRobert Mustacchi         DW_CFA_def_cfa_expression */
96*4d9fdb46SRobert Mustacchi     case DW_FORM_block:
97*4d9fdb46SRobert Mustacchi     case DW_FORM_block1:
98*4d9fdb46SRobert Mustacchi     case DW_FORM_block2:
99*4d9fdb46SRobert Mustacchi     case DW_FORM_block4:
100*4d9fdb46SRobert Mustacchi         return DW_LKIND_expression;
101*4d9fdb46SRobert Mustacchi         break;
102*4d9fdb46SRobert Mustacchi     case DW_FORM_data4:
103*4d9fdb46SRobert Mustacchi     case DW_FORM_data8:
104*4d9fdb46SRobert Mustacchi         if (version > 1 && version < 4) {
105*4d9fdb46SRobert Mustacchi             return DW_LKIND_loclist;
106*4d9fdb46SRobert Mustacchi         }
107*4d9fdb46SRobert Mustacchi         break;
108*4d9fdb46SRobert Mustacchi     case DW_FORM_sec_offset:
109*4d9fdb46SRobert Mustacchi         if (version == 5 ) {
110*4d9fdb46SRobert Mustacchi             return DW_LKIND_loclists;
111*4d9fdb46SRobert Mustacchi         }
112*4d9fdb46SRobert Mustacchi         if (version == 4 &&  is_dwo  ) {
113*4d9fdb46SRobert Mustacchi             return DW_LKIND_GNU_exp_list;
114*4d9fdb46SRobert Mustacchi         }
115*4d9fdb46SRobert Mustacchi         return DW_LKIND_loclist;
116*4d9fdb46SRobert Mustacchi         break;
117*4d9fdb46SRobert Mustacchi     case DW_FORM_loclistx:
118*4d9fdb46SRobert Mustacchi         if (version == 5 ) {
119*4d9fdb46SRobert Mustacchi             return DW_LKIND_loclists;
120*4d9fdb46SRobert Mustacchi         }
121*4d9fdb46SRobert Mustacchi         break;
122*4d9fdb46SRobert Mustacchi     default:
123*4d9fdb46SRobert Mustacchi         break;
124*4d9fdb46SRobert Mustacchi     }
125*4d9fdb46SRobert Mustacchi     return DW_LKIND_unknown;
126*4d9fdb46SRobert Mustacchi }
127*4d9fdb46SRobert Mustacchi 
128*4d9fdb46SRobert Mustacchi static void
_dwarf_free_op_chain(Dwarf_Debug dbg,Dwarf_Loc_Chain headloc)129*4d9fdb46SRobert Mustacchi _dwarf_free_op_chain(Dwarf_Debug dbg,
130*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain headloc)
131*4d9fdb46SRobert Mustacchi {
132*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain cur = headloc;
133*4d9fdb46SRobert Mustacchi 
134*4d9fdb46SRobert Mustacchi     while (cur) {
135*4d9fdb46SRobert Mustacchi         Dwarf_Loc_Chain next = cur->lc_next;
136*4d9fdb46SRobert Mustacchi         dwarf_dealloc(dbg, cur, DW_DLA_LOC_CHAIN);
137*4d9fdb46SRobert Mustacchi         cur = next;
138*4d9fdb46SRobert Mustacchi     }
139*4d9fdb46SRobert Mustacchi }
140*4d9fdb46SRobert Mustacchi /*  Given a Dwarf_Block that represents a location expression,
141bc1f688bSRobert Mustacchi     this function returns a pointer to a Dwarf_Locdesc struct
142bc1f688bSRobert Mustacchi     that has its ld_cents field set to the number of location
143bc1f688bSRobert Mustacchi     operators in the block, and its ld_s field pointing to a
144bc1f688bSRobert Mustacchi     contiguous block of Dwarf_Loc structs.  However, the
145bc1f688bSRobert Mustacchi     ld_lopc and ld_hipc values are uninitialized.  Returns
146*4d9fdb46SRobert Mustacchi     DW_DLV_ERROR on error.
147*4d9fdb46SRobert Mustacchi 
148*4d9fdb46SRobert Mustacchi     Created for DWARF2 this really does not work well
149*4d9fdb46SRobert Mustacchi     as later DWARF needs the newer interface.
150*4d9fdb46SRobert Mustacchi     You want Dwarf_Locdesc_c opaque struct, not what this
151*4d9fdb46SRobert Mustacchi     function provides.
152*4d9fdb46SRobert Mustacchi 
153*4d9fdb46SRobert Mustacchi     This function assumes that the length of
154bc1f688bSRobert Mustacchi     the block is greater than 0.  Zero length location expressions
155bc1f688bSRobert Mustacchi     to represent variables that have been optimized away are
156bc1f688bSRobert Mustacchi     handled in the calling function.
157*4d9fdb46SRobert Mustacchi 
158*4d9fdb46SRobert Mustacchi     address_size, offset_size, and version_stamp are
159*4d9fdb46SRobert Mustacchi     per-CU, not per-object or per dbg.
160*4d9fdb46SRobert Mustacchi     We cannot use dbg directly to get those values.
161*4d9fdb46SRobert Mustacchi 
162*4d9fdb46SRobert Mustacchi     Use for DWARF 2,3,4 only to avoid updating to
163*4d9fdb46SRobert Mustacchi     later interfaces. Not for experimental
164*4d9fdb46SRobert Mustacchi     dwarf4 dwo either.
165*4d9fdb46SRobert Mustacchi     Better to switch to a newer interface.
166bc1f688bSRobert Mustacchi */
167*4d9fdb46SRobert Mustacchi static int
_dwarf_get_locdesc(Dwarf_Debug dbg,Dwarf_Block_c * loc_block,Dwarf_Half address_size,Dwarf_Half offset_size,Dwarf_Small version_stamp,Dwarf_Addr lowpc,Dwarf_Addr highpc,Dwarf_Small * section_end,Dwarf_Locdesc ** locdesc_out,Dwarf_Error * error)168bc1f688bSRobert Mustacchi _dwarf_get_locdesc(Dwarf_Debug dbg,
169*4d9fdb46SRobert Mustacchi     Dwarf_Block_c * loc_block,
170bc1f688bSRobert Mustacchi     Dwarf_Half address_size,
171*4d9fdb46SRobert Mustacchi     Dwarf_Half offset_size,
172*4d9fdb46SRobert Mustacchi     Dwarf_Small version_stamp,
173bc1f688bSRobert Mustacchi     Dwarf_Addr lowpc,
174bc1f688bSRobert Mustacchi     Dwarf_Addr highpc,
175*4d9fdb46SRobert Mustacchi     Dwarf_Small * section_end,
176*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc ** locdesc_out,
177bc1f688bSRobert Mustacchi     Dwarf_Error * error)
178bc1f688bSRobert Mustacchi {
179bc1f688bSRobert Mustacchi     /* Offset of current operator from start of block. */
180bc1f688bSRobert Mustacchi     Dwarf_Unsigned offset = 0;
181bc1f688bSRobert Mustacchi 
182bc1f688bSRobert Mustacchi     /* Used to chain the Dwarf_Loc_Chain_s structs. */
183*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain new_loc = NULL;
184bc1f688bSRobert Mustacchi     Dwarf_Loc_Chain prev_loc = NULL;
185bc1f688bSRobert Mustacchi     Dwarf_Loc_Chain head_loc = NULL;
186bc1f688bSRobert Mustacchi     /* Count of the number of location operators. */
187bc1f688bSRobert Mustacchi     Dwarf_Unsigned op_count = 0;
188bc1f688bSRobert Mustacchi 
189bc1f688bSRobert Mustacchi     /* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
190bc1f688bSRobert Mustacchi     Dwarf_Loc *block_loc = 0;
191bc1f688bSRobert Mustacchi 
192bc1f688bSRobert Mustacchi     /* Dwarf_Locdesc pointer to be returned. */
193bc1f688bSRobert Mustacchi     Dwarf_Locdesc *locdesc = 0;
194bc1f688bSRobert Mustacchi 
195bc1f688bSRobert Mustacchi     Dwarf_Unsigned i = 0;
196*4d9fdb46SRobert Mustacchi     int res = 0;
197bc1f688bSRobert Mustacchi 
198bc1f688bSRobert Mustacchi     /* ***** BEGIN CODE ***** */
199bc1f688bSRobert Mustacchi 
200bc1f688bSRobert Mustacchi     offset = 0;
201bc1f688bSRobert Mustacchi     op_count = 0;
202bc1f688bSRobert Mustacchi 
203*4d9fdb46SRobert Mustacchi 
204*4d9fdb46SRobert Mustacchi     res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
205*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
206*4d9fdb46SRobert Mustacchi         return res;
207*4d9fdb46SRobert Mustacchi     }
208*4d9fdb46SRobert Mustacchi 
209*4d9fdb46SRobert Mustacchi     /* OLD loop getting Loc operators. No DWARF5 */
210*4d9fdb46SRobert Mustacchi     while (offset <= loc_block->bl_len) {
211*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned nextoffset = 0;
212*4d9fdb46SRobert Mustacchi         struct Dwarf_Loc_Expr_Op_s temp_loc;
213*4d9fdb46SRobert Mustacchi 
214*4d9fdb46SRobert Mustacchi         res = _dwarf_read_loc_expr_op(dbg,loc_block,
215*4d9fdb46SRobert Mustacchi             op_count,
216*4d9fdb46SRobert Mustacchi             version_stamp,
217*4d9fdb46SRobert Mustacchi             offset_size,
218*4d9fdb46SRobert Mustacchi             address_size,
219*4d9fdb46SRobert Mustacchi             offset,
220*4d9fdb46SRobert Mustacchi             section_end,
221*4d9fdb46SRobert Mustacchi             &nextoffset,
222*4d9fdb46SRobert Mustacchi             &temp_loc,
223*4d9fdb46SRobert Mustacchi             error);
224*4d9fdb46SRobert Mustacchi         if (res == DW_DLV_ERROR) {
225*4d9fdb46SRobert Mustacchi             _dwarf_free_op_chain(dbg, head_loc);
226*4d9fdb46SRobert Mustacchi             return res;
227*4d9fdb46SRobert Mustacchi         }
228*4d9fdb46SRobert Mustacchi         if (res == DW_DLV_NO_ENTRY) {
229*4d9fdb46SRobert Mustacchi             /* Normal end. */
230*4d9fdb46SRobert Mustacchi             break;
231*4d9fdb46SRobert Mustacchi         }
232bc1f688bSRobert Mustacchi         op_count++;
233*4d9fdb46SRobert Mustacchi         new_loc =
234*4d9fdb46SRobert Mustacchi             (Dwarf_Loc_Chain) _dwarf_get_alloc(dbg,
235*4d9fdb46SRobert Mustacchi             DW_DLA_LOC_CHAIN, 1);
236*4d9fdb46SRobert Mustacchi         if (new_loc == NULL) {
237*4d9fdb46SRobert Mustacchi             dwarfstring m;
238bc1f688bSRobert Mustacchi 
239*4d9fdb46SRobert Mustacchi             _dwarf_free_op_chain(dbg, head_loc);
240*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
241*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m,
242*4d9fdb46SRobert Mustacchi                 " DW_DLE_ALLOC_FAIL: out of memory"
243*4d9fdb46SRobert Mustacchi                 "  allocating location"
244*4d9fdb46SRobert Mustacchi                 " expression operator chain entry %u.",
245*4d9fdb46SRobert Mustacchi                 op_count);
246*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg, error, DW_DLE_ALLOC_FAIL,
247*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
248*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
249*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
250bc1f688bSRobert Mustacchi         }
251bc1f688bSRobert Mustacchi 
252*4d9fdb46SRobert Mustacchi         /* Copying only the fields needed by DWARF 2,3,4 */
253*4d9fdb46SRobert Mustacchi         new_loc->lc_atom    = temp_loc.lr_atom;
254*4d9fdb46SRobert Mustacchi         new_loc->lc_opnumber= temp_loc.lr_opnumber;
255*4d9fdb46SRobert Mustacchi         new_loc->lc_number  = temp_loc.lr_number;
256*4d9fdb46SRobert Mustacchi         new_loc->lc_number2 = temp_loc.lr_number2;
257*4d9fdb46SRobert Mustacchi         new_loc->lc_number3 = temp_loc.lr_number3;
258*4d9fdb46SRobert Mustacchi         new_loc->lc_raw1  = temp_loc.lr_raw1;
259*4d9fdb46SRobert Mustacchi         new_loc->lc_raw2  = temp_loc.lr_raw2;
260*4d9fdb46SRobert Mustacchi         new_loc->lc_raw3  = temp_loc.lr_raw3;
261*4d9fdb46SRobert Mustacchi         new_loc->lc_offset  = temp_loc.lr_offset;
262*4d9fdb46SRobert Mustacchi         offset = nextoffset;
263bc1f688bSRobert Mustacchi 
264bc1f688bSRobert Mustacchi         if (head_loc == NULL)
265*4d9fdb46SRobert Mustacchi             head_loc = prev_loc = new_loc;
266bc1f688bSRobert Mustacchi         else {
267*4d9fdb46SRobert Mustacchi             prev_loc->lc_next = new_loc;
268*4d9fdb46SRobert Mustacchi             prev_loc = new_loc;
269bc1f688bSRobert Mustacchi         }
270bc1f688bSRobert Mustacchi     }
271bc1f688bSRobert Mustacchi 
272bc1f688bSRobert Mustacchi     block_loc =
273*4d9fdb46SRobert Mustacchi         (Dwarf_Loc *) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK,
274*4d9fdb46SRobert Mustacchi         op_count);
275bc1f688bSRobert Mustacchi     if (block_loc == NULL) {
276*4d9fdb46SRobert Mustacchi         _dwarf_free_op_chain(dbg, head_loc);
277bc1f688bSRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
278*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
279bc1f688bSRobert Mustacchi     }
280bc1f688bSRobert Mustacchi 
281*4d9fdb46SRobert Mustacchi     new_loc = head_loc;
282bc1f688bSRobert Mustacchi     for (i = 0; i < op_count; i++) {
283*4d9fdb46SRobert Mustacchi         /*  Copying only the fields needed by DWARF 2,3,4
284*4d9fdb46SRobert Mustacchi             the struct is public and must never be changed. */
285*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_atom = new_loc->lc_atom;
286*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_number = new_loc->lc_number;
287*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_number2 = new_loc->lc_number2;
288*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_offset = new_loc->lc_offset;
289*4d9fdb46SRobert Mustacchi         prev_loc = new_loc;
290*4d9fdb46SRobert Mustacchi         new_loc = prev_loc->lc_next;
291bc1f688bSRobert Mustacchi         dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
292bc1f688bSRobert Mustacchi     }
293bc1f688bSRobert Mustacchi 
294bc1f688bSRobert Mustacchi     locdesc =
295bc1f688bSRobert Mustacchi         (Dwarf_Locdesc *) _dwarf_get_alloc(dbg, DW_DLA_LOCDESC, 1);
296bc1f688bSRobert Mustacchi     if (locdesc == NULL) {
297bc1f688bSRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
298*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
299bc1f688bSRobert Mustacchi     }
300bc1f688bSRobert Mustacchi 
301bc1f688bSRobert Mustacchi     locdesc->ld_cents = op_count;
302bc1f688bSRobert Mustacchi     locdesc->ld_s = block_loc;
303bc1f688bSRobert Mustacchi     locdesc->ld_section_offset = loc_block->bl_section_offset;
304bc1f688bSRobert Mustacchi     locdesc->ld_lopc = lowpc;
305bc1f688bSRobert Mustacchi     locdesc->ld_hipc = highpc;
306*4d9fdb46SRobert Mustacchi     locdesc->ld_from_loclist = 1;
307*4d9fdb46SRobert Mustacchi     *locdesc_out = locdesc;
308*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
309bc1f688bSRobert Mustacchi }
310bc1f688bSRobert Mustacchi 
311bc1f688bSRobert Mustacchi /*  Using a loclist offset to get the in-memory
312bc1f688bSRobert Mustacchi     address of .debug_loc data to read, returns the loclist
313bc1f688bSRobert Mustacchi     'header' info in return_block.
314bc1f688bSRobert Mustacchi */
315bc1f688bSRobert Mustacchi 
316bc1f688bSRobert Mustacchi #define MAX_ADDR ((address_size == 8)?0xffffffffffffffffULL:0xffffffff)
317bc1f688bSRobert Mustacchi 
318*4d9fdb46SRobert Mustacchi 
319bc1f688bSRobert Mustacchi static int
_dwarf_read_loc_section(Dwarf_Debug dbg,Dwarf_Block_c * return_block,Dwarf_Addr * lowpc,Dwarf_Addr * hipc,Dwarf_Half * lle_val,Dwarf_Off sec_offset,Dwarf_Half address_size,UNUSEDARG unsigned lkind,Dwarf_Error * error)320bc1f688bSRobert Mustacchi _dwarf_read_loc_section(Dwarf_Debug dbg,
321*4d9fdb46SRobert Mustacchi     Dwarf_Block_c * return_block,
322*4d9fdb46SRobert Mustacchi     Dwarf_Addr    * lowpc,
323*4d9fdb46SRobert Mustacchi     Dwarf_Addr    * hipc,
324*4d9fdb46SRobert Mustacchi     Dwarf_Half    * lle_val,
325bc1f688bSRobert Mustacchi     Dwarf_Off       sec_offset,
326bc1f688bSRobert Mustacchi     Dwarf_Half      address_size,
327*4d9fdb46SRobert Mustacchi     UNUSEDARG unsigned   lkind,
328bc1f688bSRobert Mustacchi     Dwarf_Error   * error)
329bc1f688bSRobert Mustacchi {
330bc1f688bSRobert Mustacchi     Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
331*4d9fdb46SRobert Mustacchi     Dwarf_Small *loc_section_end =
332*4d9fdb46SRobert Mustacchi         dbg->de_debug_loc.dss_data + dbg->de_debug_loc.dss_size;
333bc1f688bSRobert Mustacchi 
334*4d9fdb46SRobert Mustacchi     /*  start_addr and end_addr are actually offsets
335*4d9fdb46SRobert Mustacchi         of the applicable base address of the CU.
336*4d9fdb46SRobert Mustacchi         They are address-size. */
337bc1f688bSRobert Mustacchi     Dwarf_Addr start_addr = 0;
338bc1f688bSRobert Mustacchi     Dwarf_Addr end_addr = 0;
339bc1f688bSRobert Mustacchi     Dwarf_Half exprblock_size = 0;
340bc1f688bSRobert Mustacchi     Dwarf_Unsigned exprblock_off =
341*4d9fdb46SRobert Mustacchi         2 * address_size + DWARF_HALF_SIZE;
342bc1f688bSRobert Mustacchi 
343bc1f688bSRobert Mustacchi     if (sec_offset >= dbg->de_debug_loc.dss_size) {
344bc1f688bSRobert Mustacchi         /* We're at the end. No more present. */
345bc1f688bSRobert Mustacchi         return DW_DLV_NO_ENTRY;
346bc1f688bSRobert Mustacchi     }
347bc1f688bSRobert Mustacchi 
348bc1f688bSRobert Mustacchi     /* If it goes past end, error */
349bc1f688bSRobert Mustacchi     if (exprblock_off > dbg->de_debug_loc.dss_size) {
350bc1f688bSRobert Mustacchi         _dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
351bc1f688bSRobert Mustacchi         return DW_DLV_ERROR;
352bc1f688bSRobert Mustacchi     }
353bc1f688bSRobert Mustacchi 
354*4d9fdb46SRobert Mustacchi 
355*4d9fdb46SRobert Mustacchi     READ_UNALIGNED_CK(dbg, start_addr, Dwarf_Addr, beg, address_size,
356*4d9fdb46SRobert Mustacchi         error,loc_section_end);
357*4d9fdb46SRobert Mustacchi     READ_UNALIGNED_CK(dbg, end_addr, Dwarf_Addr,
358*4d9fdb46SRobert Mustacchi         beg + address_size, address_size,
359*4d9fdb46SRobert Mustacchi         error,loc_section_end);
360bc1f688bSRobert Mustacchi     if (start_addr == 0 && end_addr == 0) {
361bc1f688bSRobert Mustacchi         /*  If start_addr and end_addr are 0, it's the end and no
362bc1f688bSRobert Mustacchi             exprblock_size field follows. */
363bc1f688bSRobert Mustacchi         exprblock_size = 0;
364*4d9fdb46SRobert Mustacchi         exprblock_off -= DWARF_HALF_SIZE;
365*4d9fdb46SRobert Mustacchi         *lle_val = DW_LLE_end_of_list;
366bc1f688bSRobert Mustacchi     } else if (start_addr == MAX_ADDR) {
367*4d9fdb46SRobert Mustacchi         /*  End address is a base address, no exprblock_size field here
368bc1f688bSRobert Mustacchi             either */
369bc1f688bSRobert Mustacchi         exprblock_size = 0;
370*4d9fdb46SRobert Mustacchi         exprblock_off -=  DWARF_HALF_SIZE;
371*4d9fdb46SRobert Mustacchi         *lle_val = DW_LLE_base_address;
372bc1f688bSRobert Mustacchi     } else {
373*4d9fdb46SRobert Mustacchi         /*  Here we note the address and length of the
374*4d9fdb46SRobert Mustacchi             expression operators, DW_OP_reg0 etc */
375*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, exprblock_size, Dwarf_Half,
376*4d9fdb46SRobert Mustacchi             beg + 2 * address_size, DWARF_HALF_SIZE,
377*4d9fdb46SRobert Mustacchi             error,loc_section_end);
378bc1f688bSRobert Mustacchi         /* exprblock_size can be zero, means no expression */
379*4d9fdb46SRobert Mustacchi         if ( exprblock_size >= dbg->de_debug_loc.dss_size) {
380*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
381bc1f688bSRobert Mustacchi             return DW_DLV_ERROR;
382bc1f688bSRobert Mustacchi         }
383*4d9fdb46SRobert Mustacchi         if ((sec_offset +exprblock_off + exprblock_size) >
384*4d9fdb46SRobert Mustacchi             dbg->de_debug_loc.dss_size) {
385*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
386*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
387bc1f688bSRobert Mustacchi         }
388*4d9fdb46SRobert Mustacchi         *lle_val = DW_LLE_start_end;
389*4d9fdb46SRobert Mustacchi     }
390bc1f688bSRobert Mustacchi     *lowpc = start_addr;
391bc1f688bSRobert Mustacchi     *hipc = end_addr;
392bc1f688bSRobert Mustacchi 
393bc1f688bSRobert Mustacchi     return_block->bl_len = exprblock_size;
394*4d9fdb46SRobert Mustacchi     return_block->bl_kind = DW_LKIND_loclist;
395bc1f688bSRobert Mustacchi     return_block->bl_data = beg + exprblock_off;
396bc1f688bSRobert Mustacchi     return_block->bl_section_offset =
397*4d9fdb46SRobert Mustacchi         ((Dwarf_Small *) return_block->bl_data) -
398*4d9fdb46SRobert Mustacchi         dbg->de_debug_loc.dss_data;
399bc1f688bSRobert Mustacchi     return DW_DLV_OK;
400bc1f688bSRobert Mustacchi }
401*4d9fdb46SRobert Mustacchi 
402bc1f688bSRobert Mustacchi static int
_dwarf_get_loclist_lle_count_dwo(Dwarf_Debug dbg,Dwarf_Off loclist_offset,Dwarf_Half address_size,unsigned lkind,int * loclist_count,Dwarf_Error * error)403*4d9fdb46SRobert Mustacchi _dwarf_get_loclist_lle_count_dwo(Dwarf_Debug dbg,
404bc1f688bSRobert Mustacchi     Dwarf_Off loclist_offset,
405bc1f688bSRobert Mustacchi     Dwarf_Half address_size,
406*4d9fdb46SRobert Mustacchi     unsigned lkind,
407*4d9fdb46SRobert Mustacchi     int *loclist_count,
408*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
409*4d9fdb46SRobert Mustacchi {
410*4d9fdb46SRobert Mustacchi     int count = 0;
411*4d9fdb46SRobert Mustacchi     Dwarf_Off offset = loclist_offset;
412*4d9fdb46SRobert Mustacchi 
413*4d9fdb46SRobert Mustacchi     for (;;) {
414*4d9fdb46SRobert Mustacchi         Dwarf_Block_c b;
415*4d9fdb46SRobert Mustacchi         Dwarf_Bool at_end = FALSE;
416*4d9fdb46SRobert Mustacchi         Dwarf_Addr lowpc = 0;
417*4d9fdb46SRobert Mustacchi         Dwarf_Addr highpc = 0;
418*4d9fdb46SRobert Mustacchi         Dwarf_Half lle_op = 0;
419*4d9fdb46SRobert Mustacchi         int res = _dwarf_read_loc_section_dwo(dbg, &b,
420*4d9fdb46SRobert Mustacchi             &lowpc,
421*4d9fdb46SRobert Mustacchi             &highpc,
422*4d9fdb46SRobert Mustacchi             &at_end,
423*4d9fdb46SRobert Mustacchi             &lle_op,
424*4d9fdb46SRobert Mustacchi             offset,
425*4d9fdb46SRobert Mustacchi             address_size,
426*4d9fdb46SRobert Mustacchi             lkind,
427*4d9fdb46SRobert Mustacchi             error);
428*4d9fdb46SRobert Mustacchi         if (res != DW_DLV_OK) {
429*4d9fdb46SRobert Mustacchi             return res;
430*4d9fdb46SRobert Mustacchi         }
431*4d9fdb46SRobert Mustacchi         if (at_end) {
432*4d9fdb46SRobert Mustacchi             count++;
433*4d9fdb46SRobert Mustacchi             break;
434*4d9fdb46SRobert Mustacchi         }
435*4d9fdb46SRobert Mustacchi         offset = b.bl_len + b.bl_section_offset;
436*4d9fdb46SRobert Mustacchi         count++;
437*4d9fdb46SRobert Mustacchi     }
438*4d9fdb46SRobert Mustacchi     *loclist_count = count;
439*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
440*4d9fdb46SRobert Mustacchi }
441*4d9fdb46SRobert Mustacchi 
442*4d9fdb46SRobert Mustacchi static int
_dwarf_get_loclist_lle_count(Dwarf_Debug dbg,Dwarf_Off loclist_offset,Dwarf_Half address_size,unsigned lkind,int * loclist_count,Dwarf_Error * error)443*4d9fdb46SRobert Mustacchi _dwarf_get_loclist_lle_count(Dwarf_Debug dbg,
444*4d9fdb46SRobert Mustacchi     Dwarf_Off loclist_offset,
445*4d9fdb46SRobert Mustacchi     Dwarf_Half address_size,
446*4d9fdb46SRobert Mustacchi     unsigned lkind,
447*4d9fdb46SRobert Mustacchi     int *loclist_count,
448*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
449bc1f688bSRobert Mustacchi {
450bc1f688bSRobert Mustacchi     int count = 0;
451bc1f688bSRobert Mustacchi     Dwarf_Off offset = loclist_offset;
452bc1f688bSRobert Mustacchi 
453bc1f688bSRobert Mustacchi 
454bc1f688bSRobert Mustacchi     for (;;) {
455*4d9fdb46SRobert Mustacchi         Dwarf_Block_c b;
456*4d9fdb46SRobert Mustacchi         Dwarf_Addr lowpc = 0;
457*4d9fdb46SRobert Mustacchi         Dwarf_Addr highpc = 0;
458*4d9fdb46SRobert Mustacchi         Dwarf_Half lle_val = 0;
459*4d9fdb46SRobert Mustacchi 
460bc1f688bSRobert Mustacchi         int res = _dwarf_read_loc_section(dbg, &b,
461bc1f688bSRobert Mustacchi             &lowpc, &highpc,
462*4d9fdb46SRobert Mustacchi             &lle_val,
463*4d9fdb46SRobert Mustacchi             offset, address_size,lkind,error);
464bc1f688bSRobert Mustacchi         if (res != DW_DLV_OK) {
465bc1f688bSRobert Mustacchi             return res;
466bc1f688bSRobert Mustacchi         }
467bc1f688bSRobert Mustacchi         offset = b.bl_len + b.bl_section_offset;
468bc1f688bSRobert Mustacchi         if (lowpc == 0 && highpc == 0) {
469bc1f688bSRobert Mustacchi             break;
470bc1f688bSRobert Mustacchi         }
471bc1f688bSRobert Mustacchi         count++;
472bc1f688bSRobert Mustacchi     }
473bc1f688bSRobert Mustacchi     *loclist_count = count;
474bc1f688bSRobert Mustacchi     return DW_DLV_OK;
475bc1f688bSRobert Mustacchi }
476bc1f688bSRobert Mustacchi 
477bc1f688bSRobert Mustacchi /* Helper routine to avoid code duplication.
478bc1f688bSRobert Mustacchi */
479bc1f688bSRobert Mustacchi static int
_dwarf_setup_loc(Dwarf_Attribute attr,Dwarf_Debug * dbg_ret,Dwarf_CU_Context * cucontext_ret,Dwarf_Half * form_ret,Dwarf_Error * error)480bc1f688bSRobert Mustacchi _dwarf_setup_loc(Dwarf_Attribute attr,
481bc1f688bSRobert Mustacchi     Dwarf_Debug *     dbg_ret,
482bc1f688bSRobert Mustacchi     Dwarf_CU_Context *cucontext_ret,
483*4d9fdb46SRobert Mustacchi     Dwarf_Half       *form_ret,
484*4d9fdb46SRobert Mustacchi     Dwarf_Error      *error)
485bc1f688bSRobert Mustacchi {
486bc1f688bSRobert Mustacchi     Dwarf_Debug dbg = 0;
487bc1f688bSRobert Mustacchi     Dwarf_Half form = 0;
488bc1f688bSRobert Mustacchi     int blkres = DW_DLV_ERROR;
489bc1f688bSRobert Mustacchi 
490*4d9fdb46SRobert Mustacchi     if (!attr) {
491bc1f688bSRobert Mustacchi         _dwarf_error(NULL, error, DW_DLE_ATTR_NULL);
492bc1f688bSRobert Mustacchi         return (DW_DLV_ERROR);
493bc1f688bSRobert Mustacchi     }
494bc1f688bSRobert Mustacchi     if (attr->ar_cu_context == NULL) {
495bc1f688bSRobert Mustacchi         _dwarf_error(NULL, error, DW_DLE_ATTR_NO_CU_CONTEXT);
496bc1f688bSRobert Mustacchi         return (DW_DLV_ERROR);
497bc1f688bSRobert Mustacchi     }
498bc1f688bSRobert Mustacchi     *cucontext_ret = attr->ar_cu_context;
499bc1f688bSRobert Mustacchi 
500bc1f688bSRobert Mustacchi     dbg = attr->ar_cu_context->cc_dbg;
501bc1f688bSRobert Mustacchi     if (dbg == NULL) {
502bc1f688bSRobert Mustacchi         _dwarf_error(NULL, error, DW_DLE_ATTR_DBG_NULL);
503bc1f688bSRobert Mustacchi         return (DW_DLV_ERROR);
504bc1f688bSRobert Mustacchi     }
505bc1f688bSRobert Mustacchi     *dbg_ret = dbg;
506bc1f688bSRobert Mustacchi     blkres = dwarf_whatform(attr, &form, error);
507bc1f688bSRobert Mustacchi     if (blkres != DW_DLV_OK) {
508bc1f688bSRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOC_EXPR_BAD);
509bc1f688bSRobert Mustacchi         return blkres;
510bc1f688bSRobert Mustacchi     }
511bc1f688bSRobert Mustacchi     *form_ret = form;
512bc1f688bSRobert Mustacchi     return DW_DLV_OK;
513bc1f688bSRobert Mustacchi }
514bc1f688bSRobert Mustacchi 
515bc1f688bSRobert Mustacchi /* Helper routine  to avoid code duplication.
516bc1f688bSRobert Mustacchi */
517bc1f688bSRobert Mustacchi static int
_dwarf_get_loclist_header_start(Dwarf_Debug dbg,Dwarf_Attribute attr,Dwarf_Unsigned * loclist_offset_out,Dwarf_Error * error)518bc1f688bSRobert Mustacchi _dwarf_get_loclist_header_start(Dwarf_Debug dbg,
519bc1f688bSRobert Mustacchi     Dwarf_Attribute attr,
520*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * loclist_offset_out,
521bc1f688bSRobert Mustacchi     Dwarf_Error * error)
522bc1f688bSRobert Mustacchi {
523*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned loc_sec_size = 0;
524*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned loclist_offset = 0;
525bc1f688bSRobert Mustacchi 
526*4d9fdb46SRobert Mustacchi     int blkres = dwarf_global_formref(attr, &loclist_offset, error);
527*4d9fdb46SRobert Mustacchi     if (blkres != DW_DLV_OK) {
528*4d9fdb46SRobert Mustacchi         return blkres;
529*4d9fdb46SRobert Mustacchi     }
530bc1f688bSRobert Mustacchi     if (!dbg->de_debug_loc.dss_data) {
531bc1f688bSRobert Mustacchi         int secload = _dwarf_load_section(dbg, &dbg->de_debug_loc,error);
532bc1f688bSRobert Mustacchi         if (secload != DW_DLV_OK) {
533bc1f688bSRobert Mustacchi             return secload;
534bc1f688bSRobert Mustacchi         }
535*4d9fdb46SRobert Mustacchi         if (!dbg->de_debug_loc.dss_size) {
536*4d9fdb46SRobert Mustacchi             return (DW_DLV_NO_ENTRY);
537bc1f688bSRobert Mustacchi         }
538*4d9fdb46SRobert Mustacchi     }
539*4d9fdb46SRobert Mustacchi     loc_sec_size = dbg->de_debug_loc.dss_size;
540*4d9fdb46SRobert Mustacchi     if (loclist_offset >= loc_sec_size) {
541*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
542*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
543*4d9fdb46SRobert Mustacchi     }
544*4d9fdb46SRobert Mustacchi 
545*4d9fdb46SRobert Mustacchi     {
546*4d9fdb46SRobert Mustacchi         int fisres = 0;
547*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned fissoff = 0;
548*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned size = 0;
549*4d9fdb46SRobert Mustacchi         fisres = _dwarf_get_fission_addition_die(attr->ar_die,
550*4d9fdb46SRobert Mustacchi             DW_SECT_LOCLISTS,
551*4d9fdb46SRobert Mustacchi             &fissoff, &size,error);
552*4d9fdb46SRobert Mustacchi         if(fisres != DW_DLV_OK) {
553*4d9fdb46SRobert Mustacchi             return fisres;
554*4d9fdb46SRobert Mustacchi         }
555*4d9fdb46SRobert Mustacchi         if (fissoff >= loc_sec_size) {
556*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
557*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
558*4d9fdb46SRobert Mustacchi         }
559*4d9fdb46SRobert Mustacchi         loclist_offset += fissoff;
560*4d9fdb46SRobert Mustacchi         if  (loclist_offset >= loc_sec_size) {
561*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_LOCLIST_OFFSET_BAD);
562*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
563*4d9fdb46SRobert Mustacchi         }
564*4d9fdb46SRobert Mustacchi     }
565*4d9fdb46SRobert Mustacchi     *loclist_offset_out = loclist_offset;
566bc1f688bSRobert Mustacchi     return DW_DLV_OK;
567bc1f688bSRobert Mustacchi }
568bc1f688bSRobert Mustacchi 
569bc1f688bSRobert Mustacchi /* When llbuf (see dwarf_loclist_n) is partially set up
570bc1f688bSRobert Mustacchi    and an error is encountered, tear it down as it
571bc1f688bSRobert Mustacchi    won't be used.
572bc1f688bSRobert Mustacchi */
573bc1f688bSRobert Mustacchi static void
_dwarf_cleanup_llbuf(Dwarf_Debug dbg,Dwarf_Locdesc ** llbuf,int count)574bc1f688bSRobert Mustacchi _dwarf_cleanup_llbuf(Dwarf_Debug dbg, Dwarf_Locdesc ** llbuf, int count)
575bc1f688bSRobert Mustacchi {
576bc1f688bSRobert Mustacchi     int i;
577bc1f688bSRobert Mustacchi     for (i = 0; i < count; ++i) {
578bc1f688bSRobert Mustacchi         dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
579bc1f688bSRobert Mustacchi         dwarf_dealloc(dbg, llbuf[i], DW_DLA_LOCDESC);
580bc1f688bSRobert Mustacchi     }
581bc1f688bSRobert Mustacchi     dwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
582bc1f688bSRobert Mustacchi }
583bc1f688bSRobert Mustacchi 
584*4d9fdb46SRobert Mustacchi static int
context_is_cu_not_tu(Dwarf_CU_Context context,Dwarf_Bool * r)585*4d9fdb46SRobert Mustacchi context_is_cu_not_tu(Dwarf_CU_Context context,
586*4d9fdb46SRobert Mustacchi     Dwarf_Bool *r)
587*4d9fdb46SRobert Mustacchi {
588*4d9fdb46SRobert Mustacchi     int ut = context->cc_unit_type;
589*4d9fdb46SRobert Mustacchi 
590*4d9fdb46SRobert Mustacchi     if (ut == DW_UT_type || ut == DW_UT_split_type ) {
591*4d9fdb46SRobert Mustacchi         *r =FALSE;
592*4d9fdb46SRobert Mustacchi         return DW_DLV_OK;
593*4d9fdb46SRobert Mustacchi     }
594*4d9fdb46SRobert Mustacchi     *r = TRUE;
595*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
596*4d9fdb46SRobert Mustacchi }
597*4d9fdb46SRobert Mustacchi 
598*4d9fdb46SRobert Mustacchi /*  Handles simple location entries and loclists.
599bc1f688bSRobert Mustacchi     Returns all the Locdesc's thru llbuf.
600bc1f688bSRobert Mustacchi 
601*4d9fdb46SRobert Mustacchi     Will not work properly for DWARF5 and may not
602*4d9fdb46SRobert Mustacchi     work for some recent versions of gcc or llvm emitting
603*4d9fdb46SRobert Mustacchi     DWARF4 with location extensions.
604*4d9fdb46SRobert Mustacchi 
605*4d9fdb46SRobert Mustacchi     Does not work for .debug_loc.dwo
606bc1f688bSRobert Mustacchi */
607bc1f688bSRobert Mustacchi int
dwarf_loclist_n(Dwarf_Attribute attr,Dwarf_Locdesc *** llbuf_out,Dwarf_Signed * listlen_out,Dwarf_Error * error)608bc1f688bSRobert Mustacchi dwarf_loclist_n(Dwarf_Attribute attr,
609bc1f688bSRobert Mustacchi     Dwarf_Locdesc *** llbuf_out,
610bc1f688bSRobert Mustacchi     Dwarf_Signed * listlen_out, Dwarf_Error * error)
611bc1f688bSRobert Mustacchi {
612*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg = 0;
613bc1f688bSRobert Mustacchi 
614*4d9fdb46SRobert Mustacchi     /*  Dwarf_Attribute that describes the DW_AT_location in die, if
615bc1f688bSRobert Mustacchi         present. */
616bc1f688bSRobert Mustacchi     Dwarf_Attribute loc_attr = attr;
617bc1f688bSRobert Mustacchi 
618bc1f688bSRobert Mustacchi     /* Dwarf_Block that describes a single location expression. */
619*4d9fdb46SRobert Mustacchi     Dwarf_Block_c loc_block;
620bc1f688bSRobert Mustacchi 
621bc1f688bSRobert Mustacchi     /* A pointer to the current Dwarf_Locdesc read. */
622bc1f688bSRobert Mustacchi     Dwarf_Locdesc *locdesc = 0;
623bc1f688bSRobert Mustacchi 
624bc1f688bSRobert Mustacchi     Dwarf_Half form = 0;
625bc1f688bSRobert Mustacchi     Dwarf_Addr lowpc = 0;
626bc1f688bSRobert Mustacchi     Dwarf_Addr highpc = 0;
627bc1f688bSRobert Mustacchi     Dwarf_Signed listlen = 0;
628bc1f688bSRobert Mustacchi     Dwarf_Locdesc **llbuf = 0;
629bc1f688bSRobert Mustacchi     Dwarf_CU_Context cucontext = 0;
630bc1f688bSRobert Mustacchi     unsigned address_size = 0;
631*4d9fdb46SRobert Mustacchi     int cuvstamp = 0;
632*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_cu = FALSE;
633*4d9fdb46SRobert Mustacchi     Dwarf_Half attrnum = 0;
634*4d9fdb46SRobert Mustacchi     int is_dwo = FALSE;
635*4d9fdb46SRobert Mustacchi     unsigned lkind = 0;
636bc1f688bSRobert Mustacchi 
637bc1f688bSRobert Mustacchi     int blkres = DW_DLV_ERROR;
638bc1f688bSRobert Mustacchi     int setup_res = DW_DLV_ERROR;
639*4d9fdb46SRobert Mustacchi     Dwarf_Small * info_section_end = 0;
640bc1f688bSRobert Mustacchi 
641bc1f688bSRobert Mustacchi     /* ***** BEGIN CODE ***** */
642bc1f688bSRobert Mustacchi     setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
643bc1f688bSRobert Mustacchi     if (setup_res != DW_DLV_OK) {
644bc1f688bSRobert Mustacchi         return setup_res;
645bc1f688bSRobert Mustacchi     }
646*4d9fdb46SRobert Mustacchi     info_section_end = _dwarf_calculate_info_section_end_ptr(cucontext);
647*4d9fdb46SRobert Mustacchi     cuvstamp = cucontext->cc_version_stamp;
648bc1f688bSRobert Mustacchi     address_size = cucontext->cc_address_size;
649bc1f688bSRobert Mustacchi     /*  If this is a form_block then it's a location expression. If it's
650*4d9fdb46SRobert Mustacchi         DW_FORM_data4 or DW_FORM_data8  in DWARF2 or DWARF3
651*4d9fdb46SRobert Mustacchi         (or in DWARF4 or 5 a DW_FORM_sec_offset) it's a loclist offset */
652*4d9fdb46SRobert Mustacchi     if (cuvstamp == DW_CU_VERSION5) {
653*4d9fdb46SRobert Mustacchi         /* Use a newer interface. */
654*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
655*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
656*4d9fdb46SRobert Mustacchi     }
657*4d9fdb46SRobert Mustacchi     attrnum = attr->ar_attribute;
658*4d9fdb46SRobert Mustacchi     lkind =  determine_location_lkind(cuvstamp,form, attrnum, is_dwo);
659*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_unknown ||
660*4d9fdb46SRobert Mustacchi         lkind == DW_LKIND_GNU_exp_list ||
661*4d9fdb46SRobert Mustacchi         lkind == DW_LKIND_loclists ) {
662*4d9fdb46SRobert Mustacchi         /*  We cannot handle this here. */
663*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
664*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
665*4d9fdb46SRobert Mustacchi     }
666bc1f688bSRobert Mustacchi 
667*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_loclist ) {
668bc1f688bSRobert Mustacchi         /*  A reference to .debug_loc, with an offset in .debug_loc of a
669bc1f688bSRobert Mustacchi             loclist */
670*4d9fdb46SRobert Mustacchi         Dwarf_Small *loc_section_end = 0;
671bc1f688bSRobert Mustacchi         Dwarf_Unsigned loclist_offset = 0;
672bc1f688bSRobert Mustacchi         int off_res  = DW_DLV_ERROR;
673bc1f688bSRobert Mustacchi         int count_res = DW_DLV_ERROR;
674*4d9fdb46SRobert Mustacchi         int loclist_count = 0;
675*4d9fdb46SRobert Mustacchi         int lli = 0;
676*4d9fdb46SRobert Mustacchi 
677*4d9fdb46SRobert Mustacchi         setup_res = context_is_cu_not_tu(cucontext,&is_cu);
678*4d9fdb46SRobert Mustacchi         if(setup_res != DW_DLV_OK) {
679*4d9fdb46SRobert Mustacchi             return setup_res;
680*4d9fdb46SRobert Mustacchi         }
681bc1f688bSRobert Mustacchi 
682bc1f688bSRobert Mustacchi         off_res = _dwarf_get_loclist_header_start(dbg,
683*4d9fdb46SRobert Mustacchi             attr, &loclist_offset, error);
684bc1f688bSRobert Mustacchi         if (off_res != DW_DLV_OK) {
685bc1f688bSRobert Mustacchi             return off_res;
686bc1f688bSRobert Mustacchi         }
687*4d9fdb46SRobert Mustacchi         count_res = _dwarf_get_loclist_lle_count(dbg, loclist_offset,
688*4d9fdb46SRobert Mustacchi             address_size,lkind, &loclist_count, error);
689bc1f688bSRobert Mustacchi         listlen = loclist_count;
690bc1f688bSRobert Mustacchi         if (count_res != DW_DLV_OK) {
691bc1f688bSRobert Mustacchi             return count_res;
692bc1f688bSRobert Mustacchi         }
693bc1f688bSRobert Mustacchi         if (loclist_count == 0) {
694bc1f688bSRobert Mustacchi             return DW_DLV_NO_ENTRY;
695bc1f688bSRobert Mustacchi         }
696bc1f688bSRobert Mustacchi 
697bc1f688bSRobert Mustacchi         llbuf = (Dwarf_Locdesc **)
698bc1f688bSRobert Mustacchi             _dwarf_get_alloc(dbg, DW_DLA_LIST, loclist_count);
699bc1f688bSRobert Mustacchi         if (!llbuf) {
700bc1f688bSRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
701bc1f688bSRobert Mustacchi             return (DW_DLV_ERROR);
702bc1f688bSRobert Mustacchi         }
703bc1f688bSRobert Mustacchi 
704bc1f688bSRobert Mustacchi         for (lli = 0; lli < loclist_count; ++lli) {
705*4d9fdb46SRobert Mustacchi             int lres = 0;
706*4d9fdb46SRobert Mustacchi             Dwarf_Half ll_op = 0;
707*4d9fdb46SRobert Mustacchi 
708*4d9fdb46SRobert Mustacchi             blkres = _dwarf_read_loc_section(dbg,
709*4d9fdb46SRobert Mustacchi                 &loc_block,
710bc1f688bSRobert Mustacchi                 &lowpc,
711bc1f688bSRobert Mustacchi                 &highpc,
712*4d9fdb46SRobert Mustacchi                 &ll_op,
713bc1f688bSRobert Mustacchi                 loclist_offset,
714*4d9fdb46SRobert Mustacchi                 address_size,lkind,
715bc1f688bSRobert Mustacchi                 error);
716bc1f688bSRobert Mustacchi             if (blkres != DW_DLV_OK) {
717bc1f688bSRobert Mustacchi                 _dwarf_cleanup_llbuf(dbg, llbuf, lli);
718bc1f688bSRobert Mustacchi                 return (blkres);
719bc1f688bSRobert Mustacchi             }
720*4d9fdb46SRobert Mustacchi             loc_section_end = dbg->de_debug_loc.dss_data+
721*4d9fdb46SRobert Mustacchi                 dbg->de_debug_loc.dss_size;
722*4d9fdb46SRobert Mustacchi             lres = _dwarf_get_locdesc(dbg,
723*4d9fdb46SRobert Mustacchi                 &loc_block,
724bc1f688bSRobert Mustacchi                 address_size,
725*4d9fdb46SRobert Mustacchi                 cucontext->cc_length_size,
726*4d9fdb46SRobert Mustacchi                 cucontext->cc_version_stamp,
727*4d9fdb46SRobert Mustacchi                 lowpc, highpc,
728*4d9fdb46SRobert Mustacchi                 loc_section_end,
729*4d9fdb46SRobert Mustacchi                 &locdesc,
730*4d9fdb46SRobert Mustacchi                 error);
731*4d9fdb46SRobert Mustacchi             if (lres != DW_DLV_OK) {
732bc1f688bSRobert Mustacchi                 _dwarf_cleanup_llbuf(dbg, llbuf, lli);
733bc1f688bSRobert Mustacchi                 /* low level error already set: let it be passed back */
734*4d9fdb46SRobert Mustacchi                 return lres;
735bc1f688bSRobert Mustacchi             }
736bc1f688bSRobert Mustacchi             llbuf[lli] = locdesc;
737bc1f688bSRobert Mustacchi 
738bc1f688bSRobert Mustacchi             /* Now get to next loclist entry offset. */
739bc1f688bSRobert Mustacchi             loclist_offset = loc_block.bl_section_offset +
740bc1f688bSRobert Mustacchi                 loc_block.bl_len;
741bc1f688bSRobert Mustacchi         }
742*4d9fdb46SRobert Mustacchi     } else { /* DW_LKIND_expression */
743*4d9fdb46SRobert Mustacchi         if( form == DW_FORM_exprloc) {
744*4d9fdb46SRobert Mustacchi             blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
745*4d9fdb46SRobert Mustacchi                 &loc_block.bl_data,error);
746*4d9fdb46SRobert Mustacchi             if(blkres != DW_DLV_OK) {
747*4d9fdb46SRobert Mustacchi                 return blkres;
748*4d9fdb46SRobert Mustacchi             }
749*4d9fdb46SRobert Mustacchi             loc_block.bl_kind = lkind;
750*4d9fdb46SRobert Mustacchi             loc_block.bl_section_offset  =
751*4d9fdb46SRobert Mustacchi                 (char *)loc_block.bl_data -
752*4d9fdb46SRobert Mustacchi                 (char *)dbg->de_debug_info.dss_data;
753bc1f688bSRobert Mustacchi         } else {
754bc1f688bSRobert Mustacchi             Dwarf_Block *tblock = 0;
755bc1f688bSRobert Mustacchi             blkres = dwarf_formblock(loc_attr, &tblock, error);
756bc1f688bSRobert Mustacchi             if (blkres != DW_DLV_OK) {
757bc1f688bSRobert Mustacchi                 return (blkres);
758bc1f688bSRobert Mustacchi             }
759*4d9fdb46SRobert Mustacchi             loc_block.bl_len = tblock->bl_len;
760*4d9fdb46SRobert Mustacchi             loc_block.bl_data = tblock->bl_data;
761*4d9fdb46SRobert Mustacchi             loc_block.bl_kind = lkind;
762*4d9fdb46SRobert Mustacchi             loc_block.bl_section_offset = tblock->bl_section_offset;
763*4d9fdb46SRobert Mustacchi             loc_block.bl_locdesc_offset = 0; /* not relevent */
764*4d9fdb46SRobert Mustacchi             /*  We copied tblock contents to the stack var,
765*4d9fdb46SRobert Mustacchi                 so can dealloc
766bc1f688bSRobert Mustacchi                 tblock now.  Avoids leaks. */
767bc1f688bSRobert Mustacchi             dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
768*4d9fdb46SRobert Mustacchi         }
769bc1f688bSRobert Mustacchi         listlen = 1; /* One by definition of a location entry. */
770*4d9fdb46SRobert Mustacchi         lowpc = 0;   /* HACK, but with bl_kind we do not need */
771bc1f688bSRobert Mustacchi         highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
772bc1f688bSRobert Mustacchi 
773bc1f688bSRobert Mustacchi         /*  An empty location description (block length 0) means the
774bc1f688bSRobert Mustacchi             code generator emitted no variable, the variable was not
775*4d9fdb46SRobert Mustacchi             generated, it was unused or perhaps never tested
776*4d9fdb46SRobert Mustacchi             after being set.
777*4d9fdb46SRobert Mustacchi             Dwarf2, section 2.4.1 In other words, it is not an
778*4d9fdb46SRobert Mustacchi             error, and we don't test for block length 0
779*4d9fdb46SRobert Mustacchi             specially here. */
780*4d9fdb46SRobert Mustacchi         blkres = _dwarf_get_locdesc(dbg, &loc_block,
781bc1f688bSRobert Mustacchi             address_size,
782*4d9fdb46SRobert Mustacchi             cucontext->cc_length_size,
783*4d9fdb46SRobert Mustacchi             cucontext->cc_version_stamp,
784*4d9fdb46SRobert Mustacchi             lowpc, highpc,
785*4d9fdb46SRobert Mustacchi             info_section_end,
786*4d9fdb46SRobert Mustacchi             &locdesc,
787*4d9fdb46SRobert Mustacchi             error);
788*4d9fdb46SRobert Mustacchi         if (blkres != DW_DLV_OK) {
789bc1f688bSRobert Mustacchi             /* low level error already set: let it be passed back */
790*4d9fdb46SRobert Mustacchi             return blkres;
791bc1f688bSRobert Mustacchi         }
792bc1f688bSRobert Mustacchi         llbuf = (Dwarf_Locdesc **)
793bc1f688bSRobert Mustacchi             _dwarf_get_alloc(dbg, DW_DLA_LIST, listlen);
794bc1f688bSRobert Mustacchi         if (!llbuf) {
795bc1f688bSRobert Mustacchi             /* Free the locdesc we allocated but won't use. */
796bc1f688bSRobert Mustacchi             dwarf_dealloc(dbg, locdesc, DW_DLA_LOCDESC);
797bc1f688bSRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
798bc1f688bSRobert Mustacchi             return (DW_DLV_ERROR);
799bc1f688bSRobert Mustacchi         }
800bc1f688bSRobert Mustacchi         llbuf[0] = locdesc;
801bc1f688bSRobert Mustacchi     }
802bc1f688bSRobert Mustacchi 
803bc1f688bSRobert Mustacchi     *llbuf_out = llbuf;
804bc1f688bSRobert Mustacchi     *listlen_out = listlen;
805bc1f688bSRobert Mustacchi     return (DW_DLV_OK);
806bc1f688bSRobert Mustacchi }
807bc1f688bSRobert Mustacchi 
808*4d9fdb46SRobert Mustacchi /*  Handles only a location expression.
809bc1f688bSRobert Mustacchi     If called on a loclist, just returns one of those.
810bc1f688bSRobert Mustacchi     Cannot not handle a real loclist.
811bc1f688bSRobert Mustacchi     It returns the location expression as a loclist with
812bc1f688bSRobert Mustacchi     a single entry.
813bc1f688bSRobert Mustacchi     See dwarf_loclist_n() which handles any number
814bc1f688bSRobert Mustacchi     of location list entries.
815bc1f688bSRobert Mustacchi 
816bc1f688bSRobert Mustacchi     This is the original definition, and it simply
817*4d9fdb46SRobert Mustacchi     does not work for loclists.
818*4d9fdb46SRobert Mustacchi     Nor does it work on DWARF4 nor on some
819*4d9fdb46SRobert Mustacchi     versions of gcc generating DWARF4.
820*4d9fdb46SRobert Mustacchi     Kept for compatibility.
821bc1f688bSRobert Mustacchi */
822bc1f688bSRobert Mustacchi int
dwarf_loclist(Dwarf_Attribute attr,Dwarf_Locdesc ** llbuf,Dwarf_Signed * listlen,Dwarf_Error * error)823bc1f688bSRobert Mustacchi dwarf_loclist(Dwarf_Attribute attr,
824bc1f688bSRobert Mustacchi     Dwarf_Locdesc ** llbuf,
825bc1f688bSRobert Mustacchi     Dwarf_Signed * listlen, Dwarf_Error * error)
826bc1f688bSRobert Mustacchi {
827*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg = 0;
828bc1f688bSRobert Mustacchi 
829bc1f688bSRobert Mustacchi     /*  Dwarf_Attribute that describes the DW_AT_location in die, if
830bc1f688bSRobert Mustacchi         present. */
831bc1f688bSRobert Mustacchi     Dwarf_Attribute loc_attr = attr;
832bc1f688bSRobert Mustacchi 
833bc1f688bSRobert Mustacchi     /*  Dwarf_Block that describes a single location expression. */
834*4d9fdb46SRobert Mustacchi     Dwarf_Block_c loc_block;
835bc1f688bSRobert Mustacchi 
836bc1f688bSRobert Mustacchi     /*  A pointer to the current Dwarf_Locdesc read. */
837bc1f688bSRobert Mustacchi     Dwarf_Locdesc *locdesc = 0;
838*4d9fdb46SRobert Mustacchi     int is_dwo             = FALSE;
839*4d9fdb46SRobert Mustacchi     Dwarf_Small *info_section_end = 0;
840bc1f688bSRobert Mustacchi     Dwarf_Half form        = 0;
841bc1f688bSRobert Mustacchi     Dwarf_Addr lowpc       = 0;
842bc1f688bSRobert Mustacchi     Dwarf_Addr highpc      = 0;
843bc1f688bSRobert Mustacchi     Dwarf_CU_Context cucontext = 0;
844bc1f688bSRobert Mustacchi     unsigned address_size  = 0;
845*4d9fdb46SRobert Mustacchi     unsigned lkind         = 0;
846bc1f688bSRobert Mustacchi     int blkres             = DW_DLV_ERROR;
847bc1f688bSRobert Mustacchi     int setup_res          = DW_DLV_ERROR;
848*4d9fdb46SRobert Mustacchi     int cuvstamp           = 0;
849*4d9fdb46SRobert Mustacchi     unsigned attrnum       = 0;
850bc1f688bSRobert Mustacchi 
851bc1f688bSRobert Mustacchi     /* ***** BEGIN CODE ***** */
852bc1f688bSRobert Mustacchi     setup_res = _dwarf_setup_loc(attr, &dbg, &cucontext, &form, error);
853bc1f688bSRobert Mustacchi     if (setup_res != DW_DLV_OK) {
854bc1f688bSRobert Mustacchi         return setup_res;
855bc1f688bSRobert Mustacchi     }
856*4d9fdb46SRobert Mustacchi     info_section_end = _dwarf_calculate_info_section_end_ptr(cucontext);
857*4d9fdb46SRobert Mustacchi     memset(&loc_block,0,sizeof(loc_block));
858*4d9fdb46SRobert Mustacchi     cuvstamp = cucontext->cc_version_stamp;
859bc1f688bSRobert Mustacchi     address_size = cucontext->cc_address_size;
860*4d9fdb46SRobert Mustacchi     attrnum = attr->ar_attribute;
861*4d9fdb46SRobert Mustacchi     lkind =  determine_location_lkind(cuvstamp,form, attrnum, is_dwo);
862*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_unknown ||
863*4d9fdb46SRobert Mustacchi         lkind == DW_LKIND_GNU_exp_list ||
864*4d9fdb46SRobert Mustacchi         lkind == DW_LKIND_loclists ) {
865*4d9fdb46SRobert Mustacchi         /*  We cannot handle this here. */
866*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_INTERFACE_ERROR);
867*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
868*4d9fdb46SRobert Mustacchi     }
869*4d9fdb46SRobert Mustacchi 
870bc1f688bSRobert Mustacchi     /*  If this is a form_block then it's a location expression. If it's
871bc1f688bSRobert Mustacchi         DW_FORM_data4 or DW_FORM_data8 it's a loclist offset */
872*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_loclist) {
873bc1f688bSRobert Mustacchi         /*  A reference to .debug_loc, with an offset in .debug_loc of a
874*4d9fdb46SRobert Mustacchi             loclist. */
875bc1f688bSRobert Mustacchi         Dwarf_Unsigned loclist_offset = 0;
876bc1f688bSRobert Mustacchi         int off_res = DW_DLV_ERROR;
877*4d9fdb46SRobert Mustacchi         Dwarf_Half  ll_op = 0;
878bc1f688bSRobert Mustacchi 
879bc1f688bSRobert Mustacchi         off_res = _dwarf_get_loclist_header_start(dbg,
880bc1f688bSRobert Mustacchi             attr, &loclist_offset,
881bc1f688bSRobert Mustacchi             error);
882bc1f688bSRobert Mustacchi         if (off_res != DW_DLV_OK) {
883bc1f688bSRobert Mustacchi             return off_res;
884bc1f688bSRobert Mustacchi         }
885bc1f688bSRobert Mustacchi 
886bc1f688bSRobert Mustacchi         /* With dwarf_loclist, just read a single entry */
887bc1f688bSRobert Mustacchi         blkres = _dwarf_read_loc_section(dbg, &loc_block,
888bc1f688bSRobert Mustacchi             &lowpc,
889bc1f688bSRobert Mustacchi             &highpc,
890*4d9fdb46SRobert Mustacchi             &ll_op,
891bc1f688bSRobert Mustacchi             loclist_offset,
892bc1f688bSRobert Mustacchi             address_size,
893*4d9fdb46SRobert Mustacchi             lkind,
894bc1f688bSRobert Mustacchi             error);
895bc1f688bSRobert Mustacchi         if (blkres != DW_DLV_OK) {
896bc1f688bSRobert Mustacchi             return (blkres);
897bc1f688bSRobert Mustacchi         }
898*4d9fdb46SRobert Mustacchi     } else { /* DW_LKIND_expression */
899*4d9fdb46SRobert Mustacchi         if( form == DW_FORM_exprloc) {
900*4d9fdb46SRobert Mustacchi             blkres = dwarf_formexprloc(loc_attr,&loc_block.bl_len,
901*4d9fdb46SRobert Mustacchi                 &loc_block.bl_data,error);
902*4d9fdb46SRobert Mustacchi             if(blkres != DW_DLV_OK) {
903*4d9fdb46SRobert Mustacchi                 return blkres;
904*4d9fdb46SRobert Mustacchi             }
905*4d9fdb46SRobert Mustacchi             loc_block.bl_kind = lkind;
906*4d9fdb46SRobert Mustacchi             loc_block.bl_section_offset  =
907*4d9fdb46SRobert Mustacchi                 (char *)loc_block.bl_data -
908*4d9fdb46SRobert Mustacchi                 (char *)dbg->de_debug_info.dss_data;
909bc1f688bSRobert Mustacchi         } else {
910bc1f688bSRobert Mustacchi             Dwarf_Block *tblock = 0;
911bc1f688bSRobert Mustacchi 
912*4d9fdb46SRobert Mustacchi             /* If DWARF5 this will surely fail, get an error. */
913bc1f688bSRobert Mustacchi             blkres = dwarf_formblock(loc_attr, &tblock, error);
914bc1f688bSRobert Mustacchi             if (blkres != DW_DLV_OK) {
915bc1f688bSRobert Mustacchi                 return (blkres);
916bc1f688bSRobert Mustacchi             }
917*4d9fdb46SRobert Mustacchi             loc_block.bl_len = tblock->bl_len;
918*4d9fdb46SRobert Mustacchi             loc_block.bl_data = tblock->bl_data;
919*4d9fdb46SRobert Mustacchi             loc_block.bl_kind = tblock->bl_from_loclist;
920*4d9fdb46SRobert Mustacchi             /* ASSERT: lkind == loc_block.bl_kind  */
921*4d9fdb46SRobert Mustacchi             loc_block.bl_section_offset = tblock->bl_section_offset;
922*4d9fdb46SRobert Mustacchi             /*  We copied tblock contents to the stack
923*4d9fdb46SRobert Mustacchi                 var, so can dealloc tblock now.
924*4d9fdb46SRobert Mustacchi                 Avoids leaks. */
925bc1f688bSRobert Mustacchi             dwarf_dealloc(dbg, tblock, DW_DLA_BLOCK);
926*4d9fdb46SRobert Mustacchi         }
927*4d9fdb46SRobert Mustacchi         /*  Because we set bl_kind we don't really
928*4d9fdb46SRobert Mustacchi             need this hack any more */
929bc1f688bSRobert Mustacchi         lowpc = 0;              /* HACK */
930bc1f688bSRobert Mustacchi         highpc = (Dwarf_Unsigned) (-1LL);       /* HACK */
931bc1f688bSRobert Mustacchi     }
932bc1f688bSRobert Mustacchi 
933*4d9fdb46SRobert Mustacchi     /*  An empty location description (block length 0) means
934*4d9fdb46SRobert Mustacchi         the code
935*4d9fdb46SRobert Mustacchi         generator emitted no variable, the variable was not
936*4d9fdb46SRobert Mustacchi         generated, it was unused or perhaps never tested after
937*4d9fdb46SRobert Mustacchi         being set. Dwarf2, section 2.4.1 In other words,
938*4d9fdb46SRobert Mustacchi         it is not an error, and we don't test for block
939*4d9fdb46SRobert Mustacchi         length 0 specially here.  See *dwarf_loclist_n()
940*4d9fdb46SRobert Mustacchi         which handles the general case, this case handles
941*4d9fdb46SRobert Mustacchi         only a single location expression.  */
942*4d9fdb46SRobert Mustacchi     blkres = _dwarf_get_locdesc(dbg, &loc_block,
943*4d9fdb46SRobert Mustacchi         address_size, cucontext->cc_length_size,
944*4d9fdb46SRobert Mustacchi         cucontext->cc_version_stamp, lowpc, highpc,
945*4d9fdb46SRobert Mustacchi         info_section_end, &locdesc, error);
946*4d9fdb46SRobert Mustacchi     if (blkres != DW_DLV_OK) {
947*4d9fdb46SRobert Mustacchi         /* low level error already set: let it be passed back
948*4d9fdb46SRobert Mustacchi         */ return blkres;
949bc1f688bSRobert Mustacchi     }
950bc1f688bSRobert Mustacchi 
951bc1f688bSRobert Mustacchi     *llbuf = locdesc;
952bc1f688bSRobert Mustacchi     *listlen = 1;
953bc1f688bSRobert Mustacchi     return (DW_DLV_OK);
954bc1f688bSRobert Mustacchi }
955bc1f688bSRobert Mustacchi 
956bc1f688bSRobert Mustacchi 
957bc1f688bSRobert Mustacchi 
958*4d9fdb46SRobert Mustacchi /*  Handles only a location expression.
959bc1f688bSRobert Mustacchi     It returns the location expression as a loclist with
960bc1f688bSRobert Mustacchi     a single entry.
961bc1f688bSRobert Mustacchi 
962bc1f688bSRobert Mustacchi     Usable to access dwarf expressions from any source, but
963bc1f688bSRobert Mustacchi     specifically from
964bc1f688bSRobert Mustacchi         DW_CFA_def_cfa_expression
965bc1f688bSRobert Mustacchi         DW_CFA_expression
966bc1f688bSRobert Mustacchi         DW_CFA_val_expression
967bc1f688bSRobert Mustacchi 
968bc1f688bSRobert Mustacchi     expression_in must point to a valid dwarf expression
969bc1f688bSRobert Mustacchi     set of bytes of length expression_length. Not
970bc1f688bSRobert Mustacchi     a DW_FORM_block*, just the expression bytes.
971bc1f688bSRobert Mustacchi 
972bc1f688bSRobert Mustacchi     If the address_size != de_pointer_size this will not work
973*4d9fdb46SRobert Mustacchi     right.
974*4d9fdb46SRobert Mustacchi     See dwarf_loclist_from_expr_b() for a better interface.
975bc1f688bSRobert Mustacchi */
976bc1f688bSRobert Mustacchi int
dwarf_loclist_from_expr(Dwarf_Debug dbg,Dwarf_Ptr expression_in,Dwarf_Unsigned expression_length,Dwarf_Locdesc ** llbuf,Dwarf_Signed * listlen,Dwarf_Error * error)977bc1f688bSRobert Mustacchi dwarf_loclist_from_expr(Dwarf_Debug dbg,
978bc1f688bSRobert Mustacchi     Dwarf_Ptr expression_in,
979bc1f688bSRobert Mustacchi     Dwarf_Unsigned expression_length,
980bc1f688bSRobert Mustacchi     Dwarf_Locdesc ** llbuf,
981bc1f688bSRobert Mustacchi     Dwarf_Signed * listlen, Dwarf_Error * error)
982bc1f688bSRobert Mustacchi {
983bc1f688bSRobert Mustacchi     int res = 0;
984bc1f688bSRobert Mustacchi     Dwarf_Half addr_size =  dbg->de_pointer_size;
985bc1f688bSRobert Mustacchi     res = dwarf_loclist_from_expr_a(dbg,expression_in,
986bc1f688bSRobert Mustacchi         expression_length, addr_size,llbuf,listlen,error);
987bc1f688bSRobert Mustacchi     return res;
988bc1f688bSRobert Mustacchi }
989*4d9fdb46SRobert Mustacchi 
990bc1f688bSRobert Mustacchi /*  New April 27 2009. Adding addr_size argument for the rare
991*4d9fdb46SRobert Mustacchi     cases where an object has CUs with a different address_size.
992*4d9fdb46SRobert Mustacchi 
993*4d9fdb46SRobert Mustacchi     As of 2012 we have yet another version, dwarf_loclist_from_expr_b()
994*4d9fdb46SRobert Mustacchi     with the version_stamp and offset size (length size) passed in.
995*4d9fdb46SRobert Mustacchi */
996bc1f688bSRobert Mustacchi int
dwarf_loclist_from_expr_a(Dwarf_Debug dbg,Dwarf_Ptr expression_in,Dwarf_Unsigned expression_length,Dwarf_Half addr_size,Dwarf_Locdesc ** llbuf,Dwarf_Signed * listlen,Dwarf_Error * error)997bc1f688bSRobert Mustacchi dwarf_loclist_from_expr_a(Dwarf_Debug dbg,
998bc1f688bSRobert Mustacchi     Dwarf_Ptr expression_in,
999bc1f688bSRobert Mustacchi     Dwarf_Unsigned expression_length,
1000bc1f688bSRobert Mustacchi     Dwarf_Half addr_size,
1001bc1f688bSRobert Mustacchi     Dwarf_Locdesc ** llbuf,
1002*4d9fdb46SRobert Mustacchi     Dwarf_Signed * listlen,
1003*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
1004*4d9fdb46SRobert Mustacchi {
1005*4d9fdb46SRobert Mustacchi     int res;
1006*4d9fdb46SRobert Mustacchi     Dwarf_Debug_InfoTypes info_reading = &dbg->de_info_reading;
1007*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context current_cu_context =
1008*4d9fdb46SRobert Mustacchi         info_reading->de_cu_context;
1009*4d9fdb46SRobert Mustacchi     Dwarf_Small version_stamp =  DW_CU_VERSION2;
1010*4d9fdb46SRobert Mustacchi     Dwarf_Half offset_size = dbg->de_length_size;
1011*4d9fdb46SRobert Mustacchi 
1012*4d9fdb46SRobert Mustacchi     if (current_cu_context) {
1013*4d9fdb46SRobert Mustacchi         /*  This is ugly. It is not necessarily right. Due to
1014*4d9fdb46SRobert Mustacchi             oddity in DW_OP_GNU_implicit_pointer, see its
1015*4d9fdb46SRobert Mustacchi             implementation above.
1016*4d9fdb46SRobert Mustacchi             For correctness, use dwarf_loclist_from_expr_b()
1017*4d9fdb46SRobert Mustacchi             instead of dwarf_loclist_from_expr_a(). */
1018*4d9fdb46SRobert Mustacchi         version_stamp = current_cu_context->cc_version_stamp;
1019*4d9fdb46SRobert Mustacchi         offset_size = current_cu_context->cc_length_size;
1020*4d9fdb46SRobert Mustacchi         if (version_stamp < 2) {
1021*4d9fdb46SRobert Mustacchi             /* This is probably totally silly.  */
1022*4d9fdb46SRobert Mustacchi             version_stamp = DW_CU_VERSION2;
1023*4d9fdb46SRobert Mustacchi         }
1024*4d9fdb46SRobert Mustacchi     }
1025*4d9fdb46SRobert Mustacchi     res = dwarf_loclist_from_expr_b(dbg,
1026*4d9fdb46SRobert Mustacchi         expression_in,
1027*4d9fdb46SRobert Mustacchi         expression_length,
1028*4d9fdb46SRobert Mustacchi         addr_size,
1029*4d9fdb46SRobert Mustacchi         offset_size,
1030*4d9fdb46SRobert Mustacchi         version_stamp, /* CU context DWARF version */
1031*4d9fdb46SRobert Mustacchi         llbuf,
1032*4d9fdb46SRobert Mustacchi         listlen,
1033*4d9fdb46SRobert Mustacchi         error);
1034*4d9fdb46SRobert Mustacchi     return res;
1035*4d9fdb46SRobert Mustacchi }
1036*4d9fdb46SRobert Mustacchi /*  New November 13 2012. Adding
1037*4d9fdb46SRobert Mustacchi     DWARF version number argument.
1038*4d9fdb46SRobert Mustacchi */
1039*4d9fdb46SRobert Mustacchi int
dwarf_loclist_from_expr_b(Dwarf_Debug dbg,Dwarf_Ptr expression_in,Dwarf_Unsigned expression_length,Dwarf_Half addr_size,Dwarf_Half offset_size,Dwarf_Small dwarf_version,Dwarf_Locdesc ** llbuf,Dwarf_Signed * listlen,Dwarf_Error * error)1040*4d9fdb46SRobert Mustacchi dwarf_loclist_from_expr_b(Dwarf_Debug dbg,
1041*4d9fdb46SRobert Mustacchi     Dwarf_Ptr expression_in,
1042*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned expression_length,
1043*4d9fdb46SRobert Mustacchi     Dwarf_Half addr_size,
1044*4d9fdb46SRobert Mustacchi     Dwarf_Half offset_size,
1045*4d9fdb46SRobert Mustacchi     Dwarf_Small dwarf_version,
1046*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc ** llbuf,
1047*4d9fdb46SRobert Mustacchi     Dwarf_Signed * listlen,
1048*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
1049bc1f688bSRobert Mustacchi {
1050bc1f688bSRobert Mustacchi     /* Dwarf_Block that describes a single location expression. */
1051*4d9fdb46SRobert Mustacchi     Dwarf_Block_c loc_block;
1052bc1f688bSRobert Mustacchi 
1053bc1f688bSRobert Mustacchi     /* A pointer to the current Dwarf_Locdesc read. */
1054bc1f688bSRobert Mustacchi     Dwarf_Locdesc *locdesc = 0;
1055bc1f688bSRobert Mustacchi     Dwarf_Addr lowpc = 0;
1056bc1f688bSRobert Mustacchi     Dwarf_Addr highpc = (Dwarf_Unsigned) (-1LL);
1057*4d9fdb46SRobert Mustacchi     Dwarf_Small version_stamp = dwarf_version;
1058*4d9fdb46SRobert Mustacchi     int res = 0;
1059*4d9fdb46SRobert Mustacchi     /* We do not know what the end is in this interface. */
1060*4d9fdb46SRobert Mustacchi     Dwarf_Small *section_start = 0;
1061*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned section_size = 0;
1062*4d9fdb46SRobert Mustacchi     Dwarf_Small *section_end = 0;
1063*4d9fdb46SRobert Mustacchi     const char *section_name = 0;
1064*4d9fdb46SRobert Mustacchi 
1065*4d9fdb46SRobert Mustacchi     res = _dwarf_what_section_are_we(dbg,
1066*4d9fdb46SRobert Mustacchi         expression_in,&section_name,&section_start,
1067*4d9fdb46SRobert Mustacchi         &section_size,&section_end,error);
1068*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
1069*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error,DW_DLE_POINTER_SECTION_UNKNOWN);
1070*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
1071*4d9fdb46SRobert Mustacchi     }
1072bc1f688bSRobert Mustacchi 
1073bc1f688bSRobert Mustacchi     memset(&loc_block,0,sizeof(loc_block));
1074bc1f688bSRobert Mustacchi     loc_block.bl_len = expression_length;
1075bc1f688bSRobert Mustacchi     loc_block.bl_data = expression_in;
1076*4d9fdb46SRobert Mustacchi     loc_block.bl_kind = DW_LKIND_expression;
1077bc1f688bSRobert Mustacchi     loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
1078bc1f688bSRobert Mustacchi 
1079bc1f688bSRobert Mustacchi     /* An empty location description (block length 0) means the code
1080bc1f688bSRobert Mustacchi     generator emitted no variable, the variable was not generated,
1081bc1f688bSRobert Mustacchi     it was unused or perhaps never tested after being set. Dwarf2,
1082bc1f688bSRobert Mustacchi     section 2.4.1 In other words, it is not an error, and we don't
1083bc1f688bSRobert Mustacchi     test for block length 0 specially here.  */
1084*4d9fdb46SRobert Mustacchi     /* We need the DWARF version to get a locdesc! */
1085*4d9fdb46SRobert Mustacchi     res = _dwarf_get_locdesc(dbg, &loc_block,
1086*4d9fdb46SRobert Mustacchi         addr_size,
1087*4d9fdb46SRobert Mustacchi         offset_size,
1088*4d9fdb46SRobert Mustacchi         version_stamp,
1089*4d9fdb46SRobert Mustacchi         lowpc, highpc,
1090*4d9fdb46SRobert Mustacchi         section_end,
1091*4d9fdb46SRobert Mustacchi         &locdesc,
1092*4d9fdb46SRobert Mustacchi         error);
1093*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
1094bc1f688bSRobert Mustacchi         /* low level error already set: let it be passed back */
1095*4d9fdb46SRobert Mustacchi         return res;
1096bc1f688bSRobert Mustacchi     }
1097bc1f688bSRobert Mustacchi 
1098bc1f688bSRobert Mustacchi     *llbuf = locdesc;
1099bc1f688bSRobert Mustacchi     *listlen = 1;
1100*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1101bc1f688bSRobert Mustacchi }
1102bc1f688bSRobert Mustacchi 
1103bc1f688bSRobert Mustacchi /* Usable to read a single loclist or to read a block of them
1104bc1f688bSRobert Mustacchi    or to read an entire section's loclists.
1105bc1f688bSRobert Mustacchi 
1106*4d9fdb46SRobert Mustacchi    It's BROKEN because it's not safe to read a loclist entry
1107bc1f688bSRobert Mustacchi    when we do not know the address size (in any object where
1108bc1f688bSRobert Mustacchi    address size can vary by compilation unit).
1109bc1f688bSRobert Mustacchi 
1110*4d9fdb46SRobert Mustacchi    It also does not recognize split dwarf or DWARF4
1111*4d9fdb46SRobert Mustacchi    or DWARF5 adequately.
1112*4d9fdb46SRobert Mustacchi 
1113*4d9fdb46SRobert Mustacchi    Use get_locdesc_entry_c() instead.
1114*4d9fdb46SRobert Mustacchi */
1115bc1f688bSRobert Mustacchi /*ARGSUSED*/ int
dwarf_get_loclist_entry(Dwarf_Debug dbg,Dwarf_Unsigned offset,Dwarf_Addr * hipc_offset,Dwarf_Addr * lopc_offset,Dwarf_Ptr * data,Dwarf_Unsigned * entry_len,Dwarf_Unsigned * next_entry,Dwarf_Error * error)1116bc1f688bSRobert Mustacchi dwarf_get_loclist_entry(Dwarf_Debug dbg,
1117bc1f688bSRobert Mustacchi     Dwarf_Unsigned offset,
1118bc1f688bSRobert Mustacchi     Dwarf_Addr * hipc_offset,
1119bc1f688bSRobert Mustacchi     Dwarf_Addr * lopc_offset,
1120bc1f688bSRobert Mustacchi     Dwarf_Ptr * data,
1121bc1f688bSRobert Mustacchi     Dwarf_Unsigned * entry_len,
1122bc1f688bSRobert Mustacchi     Dwarf_Unsigned * next_entry,
1123bc1f688bSRobert Mustacchi     Dwarf_Error * error)
1124bc1f688bSRobert Mustacchi {
1125*4d9fdb46SRobert Mustacchi     Dwarf_Block_c b;
1126bc1f688bSRobert Mustacchi     Dwarf_Addr lowpc = 0;
1127bc1f688bSRobert Mustacchi     Dwarf_Addr highpc = 0;
1128bc1f688bSRobert Mustacchi     Dwarf_Half address_size = 0;
1129bc1f688bSRobert Mustacchi     int res = DW_DLV_ERROR;
1130*4d9fdb46SRobert Mustacchi     Dwarf_Half ll_op = 0;
1131bc1f688bSRobert Mustacchi 
1132bc1f688bSRobert Mustacchi     if (!dbg->de_debug_loc.dss_data) {
1133bc1f688bSRobert Mustacchi         int secload = _dwarf_load_section(dbg, &dbg->de_debug_loc,error);
1134bc1f688bSRobert Mustacchi         if (secload != DW_DLV_OK) {
1135bc1f688bSRobert Mustacchi             return secload;
1136bc1f688bSRobert Mustacchi         }
1137bc1f688bSRobert Mustacchi     }
1138bc1f688bSRobert Mustacchi 
1139*4d9fdb46SRobert Mustacchi     /*  FIXME: DO NOT USE the call. address_size is not necessarily
1140*4d9fdb46SRobert Mustacchi         the same in every frame. */
1141bc1f688bSRobert Mustacchi     address_size = dbg->de_pointer_size;
1142bc1f688bSRobert Mustacchi     res = _dwarf_read_loc_section(dbg,
1143*4d9fdb46SRobert Mustacchi         &b, &lowpc, &highpc,
1144*4d9fdb46SRobert Mustacchi         &ll_op,offset,
1145*4d9fdb46SRobert Mustacchi         address_size,DW_LKIND_loclist,error);
1146bc1f688bSRobert Mustacchi     if (res != DW_DLV_OK) {
1147bc1f688bSRobert Mustacchi         return res;
1148bc1f688bSRobert Mustacchi     }
1149bc1f688bSRobert Mustacchi     *hipc_offset = highpc;
1150bc1f688bSRobert Mustacchi     *lopc_offset = lowpc;
1151bc1f688bSRobert Mustacchi     *entry_len = b.bl_len;
1152bc1f688bSRobert Mustacchi     *data = b.bl_data;
1153bc1f688bSRobert Mustacchi     *next_entry = b.bl_len + b.bl_section_offset;
1154bc1f688bSRobert Mustacchi     return DW_DLV_OK;
1155bc1f688bSRobert Mustacchi }
1156bc1f688bSRobert Mustacchi 
1157*4d9fdb46SRobert Mustacchi /* ============== the October 2015 interfaces. */
1158*4d9fdb46SRobert Mustacchi int
_dwarf_loc_block_sanity_check(Dwarf_Debug dbg,Dwarf_Block_c * loc_block,Dwarf_Error * error)1159*4d9fdb46SRobert Mustacchi _dwarf_loc_block_sanity_check(Dwarf_Debug dbg,
1160*4d9fdb46SRobert Mustacchi     Dwarf_Block_c *loc_block,Dwarf_Error* error)
1161*4d9fdb46SRobert Mustacchi {
1162*4d9fdb46SRobert Mustacchi     unsigned lkind = loc_block->bl_kind;
1163*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_loclist) {
1164*4d9fdb46SRobert Mustacchi         Dwarf_Small *loc_ptr = 0;
1165*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned loc_len = 0;
1166*4d9fdb46SRobert Mustacchi         Dwarf_Small *end_ptr = 0;
1167bc1f688bSRobert Mustacchi 
1168*4d9fdb46SRobert Mustacchi         loc_ptr = loc_block->bl_data;
1169*4d9fdb46SRobert Mustacchi         loc_len = loc_block->bl_len;
1170*4d9fdb46SRobert Mustacchi         end_ptr =  dbg->de_debug_loc.dss_size +
1171*4d9fdb46SRobert Mustacchi             dbg->de_debug_loc.dss_data;
1172*4d9fdb46SRobert Mustacchi         if ((loc_ptr +loc_len) > end_ptr) {
1173*4d9fdb46SRobert Mustacchi             dwarfstring m;
1174*4d9fdb46SRobert Mustacchi 
1175*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
1176*4d9fdb46SRobert Mustacchi             dwarfstring_append(&m,
1177*4d9fdb46SRobert Mustacchi                 "DW_DLE_DEBUG_LOC_SECTION_SHORT kind: ");
1178*4d9fdb46SRobert Mustacchi             _dwarf_lkind_name(lkind, &m);
1179*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg,error,
1180*4d9fdb46SRobert Mustacchi                 DW_DLE_DEBUG_LOC_SECTION_SHORT,
1181*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
1182*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
1183*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1184*4d9fdb46SRobert Mustacchi         }
1185*4d9fdb46SRobert Mustacchi         return DW_DLV_OK;
1186*4d9fdb46SRobert Mustacchi     }
1187*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_loclists) {
1188*4d9fdb46SRobert Mustacchi         Dwarf_Small *loc_ptr = 0;
1189*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned loc_len = 0;
1190*4d9fdb46SRobert Mustacchi         Dwarf_Small *end_ptr = 0;
1191*4d9fdb46SRobert Mustacchi 
1192*4d9fdb46SRobert Mustacchi         loc_ptr = loc_block->bl_data;
1193*4d9fdb46SRobert Mustacchi         loc_len = loc_block->bl_len;
1194*4d9fdb46SRobert Mustacchi         end_ptr =  dbg->de_debug_loclists.dss_size +
1195*4d9fdb46SRobert Mustacchi             dbg->de_debug_loclists.dss_data;
1196*4d9fdb46SRobert Mustacchi         if ((loc_ptr +loc_len) > end_ptr) {
1197*4d9fdb46SRobert Mustacchi             dwarfstring m;
1198*4d9fdb46SRobert Mustacchi 
1199*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
1200*4d9fdb46SRobert Mustacchi             dwarfstring_append(&m,
1201*4d9fdb46SRobert Mustacchi                 "DW_DLE_DEBUG_LOC_SECTION_SHORT "
1202*4d9fdb46SRobert Mustacchi                 "(the .debug_loclists section is short), kind: ");
1203*4d9fdb46SRobert Mustacchi             _dwarf_lkind_name(lkind, &m);
1204*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg,error,
1205*4d9fdb46SRobert Mustacchi                 DW_DLE_DEBUG_LOC_SECTION_SHORT,
1206*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
1207*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
1208*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1209*4d9fdb46SRobert Mustacchi         }
1210*4d9fdb46SRobert Mustacchi     }
1211*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1212*4d9fdb46SRobert Mustacchi }
1213*4d9fdb46SRobert Mustacchi 
1214*4d9fdb46SRobert Mustacchi /*  Sets locdesc operator list information in locdesc.
1215*4d9fdb46SRobert Mustacchi     Sets the locdesc values (rawlow, rawhigh etc).
1216*4d9fdb46SRobert Mustacchi     This synthesizes the ld_lle_value of the locdesc
1217*4d9fdb46SRobert Mustacchi     if it's not already provided.
1218*4d9fdb46SRobert Mustacchi     Not passing in locdesc pointer, the locdesc_index suffices
1219*4d9fdb46SRobert Mustacchi     to index to the relevant locdesc pointer.
1220*4d9fdb46SRobert Mustacchi     See also dwarf_loclists.c: build_array_of_lle*/
1221*4d9fdb46SRobert Mustacchi int
_dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,Dwarf_Unsigned locdesc_index,Dwarf_Loc_Head_c loc_head,Dwarf_Block_c * loc_block,Dwarf_Half address_size,Dwarf_Half offset_size,Dwarf_Small version_stamp,Dwarf_Addr lowpc,Dwarf_Addr highpc,Dwarf_Half lle_op,Dwarf_Error * error)1222*4d9fdb46SRobert Mustacchi _dwarf_fill_in_locdesc_op_c(Dwarf_Debug dbg,
1223*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned locdesc_index,
1224*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c loc_head,
1225*4d9fdb46SRobert Mustacchi     Dwarf_Block_c * loc_block,
1226*4d9fdb46SRobert Mustacchi     Dwarf_Half address_size,
1227*4d9fdb46SRobert Mustacchi     Dwarf_Half offset_size,
1228*4d9fdb46SRobert Mustacchi     Dwarf_Small version_stamp,
1229*4d9fdb46SRobert Mustacchi     Dwarf_Addr lowpc,
1230*4d9fdb46SRobert Mustacchi     Dwarf_Addr highpc,
1231*4d9fdb46SRobert Mustacchi     Dwarf_Half lle_op,
1232*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
1233*4d9fdb46SRobert Mustacchi {
1234*4d9fdb46SRobert Mustacchi     /* Offset of current operator from start of block. */
1235*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned offset = 0;
1236*4d9fdb46SRobert Mustacchi 
1237*4d9fdb46SRobert Mustacchi     /*  Chain the  DW_OPerator structs. */
1238*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain new_loc = NULL;
1239*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain prev_loc = NULL;
1240*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Chain head_loc = NULL;
1241*4d9fdb46SRobert Mustacchi 
1242*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned  op_count = 0;
1243*4d9fdb46SRobert Mustacchi 
1244*4d9fdb46SRobert Mustacchi     /*  Contiguous block of Dwarf_Loc_Expr_Op_s
1245*4d9fdb46SRobert Mustacchi         for Dwarf_Locdesc. */
1246*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Expr_Op block_loc = 0;
1247*4d9fdb46SRobert Mustacchi 
1248*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c locdesc = loc_head->ll_locdesc + locdesc_index;
1249*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned  i = 0;
1250*4d9fdb46SRobert Mustacchi     int             res = 0;
1251*4d9fdb46SRobert Mustacchi     Dwarf_Small    *section_start = 0;
1252*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned  section_size = 0;
1253*4d9fdb46SRobert Mustacchi     Dwarf_Small    *section_end = 0;
1254*4d9fdb46SRobert Mustacchi     const char     *section_name = 0;
1255*4d9fdb46SRobert Mustacchi     Dwarf_Small    *blockdataptr = 0;
1256*4d9fdb46SRobert Mustacchi     unsigned lkind = loc_head->ll_kind;
1257*4d9fdb46SRobert Mustacchi 
1258*4d9fdb46SRobert Mustacchi     /* ***** BEGIN CODE ***** */
1259*4d9fdb46SRobert Mustacchi     blockdataptr = loc_block->bl_data;
1260*4d9fdb46SRobert Mustacchi     if (!blockdataptr || !loc_block->bl_len) {
1261*4d9fdb46SRobert Mustacchi         /*  an empty block has no operations so
1262*4d9fdb46SRobert Mustacchi             no section or tests need be done.. */
1263*4d9fdb46SRobert Mustacchi     } else {
1264*4d9fdb46SRobert Mustacchi         res = _dwarf_what_section_are_we(dbg,
1265*4d9fdb46SRobert Mustacchi             blockdataptr,&section_name,&section_start,
1266*4d9fdb46SRobert Mustacchi             &section_size,&section_end,error);
1267*4d9fdb46SRobert Mustacchi         if (res != DW_DLV_OK) {
1268*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error,DW_DLE_POINTER_SECTION_UNKNOWN);
1269*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1270*4d9fdb46SRobert Mustacchi         }
1271*4d9fdb46SRobert Mustacchi         res = _dwarf_loc_block_sanity_check(dbg,loc_block,error);
1272*4d9fdb46SRobert Mustacchi         if (res != DW_DLV_OK) {
1273*4d9fdb46SRobert Mustacchi             return res;
1274*4d9fdb46SRobert Mustacchi         }
1275*4d9fdb46SRobert Mustacchi     }
1276*4d9fdb46SRobert Mustacchi     /* New loop getting Loc operators. Non DWO */
1277*4d9fdb46SRobert Mustacchi     while (offset <= loc_block->bl_len) {
1278*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned nextoffset = 0;
1279*4d9fdb46SRobert Mustacchi         struct Dwarf_Loc_Expr_Op_s temp_loc;
1280*4d9fdb46SRobert Mustacchi 
1281*4d9fdb46SRobert Mustacchi         /*  This call is ok even if bl_data NULL and bl_len 0 */
1282*4d9fdb46SRobert Mustacchi         res = _dwarf_read_loc_expr_op(dbg,loc_block,
1283*4d9fdb46SRobert Mustacchi             op_count,
1284*4d9fdb46SRobert Mustacchi             version_stamp,
1285*4d9fdb46SRobert Mustacchi             offset_size,
1286*4d9fdb46SRobert Mustacchi             address_size,
1287*4d9fdb46SRobert Mustacchi             offset,
1288*4d9fdb46SRobert Mustacchi             section_end,
1289*4d9fdb46SRobert Mustacchi             &nextoffset,
1290*4d9fdb46SRobert Mustacchi             &temp_loc,
1291*4d9fdb46SRobert Mustacchi             error);
1292*4d9fdb46SRobert Mustacchi         if (res == DW_DLV_ERROR) {
1293*4d9fdb46SRobert Mustacchi             return res;
1294*4d9fdb46SRobert Mustacchi         }
1295*4d9fdb46SRobert Mustacchi         if (res == DW_DLV_NO_ENTRY) {
1296*4d9fdb46SRobert Mustacchi             /*  Normal end.
1297*4d9fdb46SRobert Mustacchi                 Also the end for an empty loc_block.  */
1298*4d9fdb46SRobert Mustacchi             break;
1299*4d9fdb46SRobert Mustacchi         }
1300*4d9fdb46SRobert Mustacchi         op_count++;
1301*4d9fdb46SRobert Mustacchi         new_loc =
1302*4d9fdb46SRobert Mustacchi             (Dwarf_Loc_Chain) _dwarf_get_alloc(dbg, DW_DLA_LOC_CHAIN, 1);
1303*4d9fdb46SRobert Mustacchi         if (new_loc == NULL) {
1304*4d9fdb46SRobert Mustacchi             _dwarf_free_op_chain(dbg,head_loc);
1305*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1306*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1307*4d9fdb46SRobert Mustacchi         }
1308*4d9fdb46SRobert Mustacchi 
1309*4d9fdb46SRobert Mustacchi         /* Copying all the fields. DWARF 2,3,4,5. */
1310*4d9fdb46SRobert Mustacchi         new_loc->lc_atom    = temp_loc.lr_atom;
1311*4d9fdb46SRobert Mustacchi         new_loc->lc_opnumber= temp_loc.lr_opnumber;
1312*4d9fdb46SRobert Mustacchi         new_loc->lc_raw1    = temp_loc.lr_number;
1313*4d9fdb46SRobert Mustacchi         new_loc->lc_raw2    = temp_loc.lr_number2;
1314*4d9fdb46SRobert Mustacchi         new_loc->lc_raw3    = temp_loc.lr_number3;
1315*4d9fdb46SRobert Mustacchi         new_loc->lc_number  = temp_loc.lr_number;
1316*4d9fdb46SRobert Mustacchi         new_loc->lc_number2 = temp_loc.lr_number2;
1317*4d9fdb46SRobert Mustacchi         new_loc->lc_number3 = temp_loc.lr_number3;
1318*4d9fdb46SRobert Mustacchi         new_loc->lc_offset  = temp_loc.lr_offset;
1319*4d9fdb46SRobert Mustacchi         if (head_loc == NULL)
1320*4d9fdb46SRobert Mustacchi             head_loc = prev_loc = new_loc;
1321*4d9fdb46SRobert Mustacchi         else {
1322*4d9fdb46SRobert Mustacchi             prev_loc->lc_next = new_loc;
1323*4d9fdb46SRobert Mustacchi             prev_loc = new_loc;
1324*4d9fdb46SRobert Mustacchi         }
1325*4d9fdb46SRobert Mustacchi         offset = nextoffset;
1326*4d9fdb46SRobert Mustacchi     }
1327*4d9fdb46SRobert Mustacchi     block_loc =
1328*4d9fdb46SRobert Mustacchi         (Dwarf_Loc_Expr_Op ) _dwarf_get_alloc(dbg, DW_DLA_LOC_BLOCK_C,
1329*4d9fdb46SRobert Mustacchi         op_count);
1330*4d9fdb46SRobert Mustacchi     new_loc = head_loc;
1331*4d9fdb46SRobert Mustacchi     if (block_loc == NULL) {
1332*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1333*4d9fdb46SRobert Mustacchi         for (i = 0; i < op_count; i++) {
1334*4d9fdb46SRobert Mustacchi             prev_loc = new_loc;
1335*4d9fdb46SRobert Mustacchi             new_loc = prev_loc->lc_next;
1336*4d9fdb46SRobert Mustacchi             dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
1337*4d9fdb46SRobert Mustacchi         }
1338*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
1339*4d9fdb46SRobert Mustacchi     }
1340*4d9fdb46SRobert Mustacchi 
1341*4d9fdb46SRobert Mustacchi     /* op_count could be zero. */
1342*4d9fdb46SRobert Mustacchi     new_loc = head_loc;
1343*4d9fdb46SRobert Mustacchi     for (i = 0; i < op_count; i++) {
1344*4d9fdb46SRobert Mustacchi         /* Copying only the fields needed by DWARF 2,3,4 */
1345*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_atom = new_loc->lc_atom;
1346*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_raw1 = new_loc->lc_raw1;
1347*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_raw2 = new_loc->lc_raw2;
1348*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_raw3 = new_loc->lc_raw3;
1349*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_number = new_loc->lc_number;
1350*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_number2 = new_loc->lc_number2;
1351*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_number3 = new_loc->lc_number3;
1352*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_offset = new_loc->lc_offset;
1353*4d9fdb46SRobert Mustacchi         (block_loc + i)->lr_opnumber = new_loc->lc_opnumber;
1354*4d9fdb46SRobert Mustacchi         prev_loc = new_loc;
1355*4d9fdb46SRobert Mustacchi         new_loc = prev_loc->lc_next;
1356*4d9fdb46SRobert Mustacchi         dwarf_dealloc(dbg, prev_loc, DW_DLA_LOC_CHAIN);
1357*4d9fdb46SRobert Mustacchi     }
1358*4d9fdb46SRobert Mustacchi     /*  Synthesizing the DW_LLE values for the old loclist
1359*4d9fdb46SRobert Mustacchi         versions. */
1360*4d9fdb46SRobert Mustacchi     if (loc_head->ll_kind == DW_LKIND_loclist) {
1361*4d9fdb46SRobert Mustacchi         /*  Meaningless for a DW_LKIND_expression */
1362*4d9fdb46SRobert Mustacchi         if(highpc == 0 && lowpc == 0) {
1363*4d9fdb46SRobert Mustacchi             locdesc->ld_lle_value =  DW_LLE_end_of_list;
1364*4d9fdb46SRobert Mustacchi         } else if(lowpc == MAX_ADDR) {
1365*4d9fdb46SRobert Mustacchi             locdesc->ld_lle_value = DW_LLE_base_address;
1366*4d9fdb46SRobert Mustacchi         } else {
1367*4d9fdb46SRobert Mustacchi             locdesc->ld_lle_value = DW_LLE_offset_pair;
1368*4d9fdb46SRobert Mustacchi         }
1369*4d9fdb46SRobert Mustacchi     } else  if (DW_LKIND_GNU_exp_list){
1370*4d9fdb46SRobert Mustacchi         /* DW_LKIND_GNU_exp_list */
1371*4d9fdb46SRobert Mustacchi         locdesc->ld_lle_value = lle_op;
1372*4d9fdb46SRobert Mustacchi     }
1373*4d9fdb46SRobert Mustacchi     locdesc->ld_cents = op_count;
1374*4d9fdb46SRobert Mustacchi     locdesc->ld_s = block_loc;
1375*4d9fdb46SRobert Mustacchi     locdesc->ld_kind = lkind;
1376*4d9fdb46SRobert Mustacchi     locdesc->ld_section_offset = loc_block->bl_section_offset;
1377*4d9fdb46SRobert Mustacchi     locdesc->ld_locdesc_offset = loc_block->bl_locdesc_offset;
1378*4d9fdb46SRobert Mustacchi     locdesc->ld_rawlow = lowpc;
1379*4d9fdb46SRobert Mustacchi     locdesc->ld_rawhigh = highpc;
1380*4d9fdb46SRobert Mustacchi     /*  Leaving the cooked values zero. Filled in later. */
1381*4d9fdb46SRobert Mustacchi     /*  We have not yet looked for debug_addr, so we'll
1382*4d9fdb46SRobert Mustacchi         set it as not-missing. */
1383*4d9fdb46SRobert Mustacchi     locdesc->ld_index_failed = FALSE;
1384*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1385*4d9fdb46SRobert Mustacchi }
1386*4d9fdb46SRobert Mustacchi 
1387*4d9fdb46SRobert Mustacchi 
1388*4d9fdb46SRobert Mustacchi /* Non-standard DWARF4 dwo loclist */
1389*4d9fdb46SRobert Mustacchi static int
_dwarf_read_loc_section_dwo(Dwarf_Debug dbg,Dwarf_Block_c * return_block,Dwarf_Addr * lowpc,Dwarf_Addr * highpc,Dwarf_Bool * at_end,Dwarf_Half * lle_op,Dwarf_Off sec_offset,Dwarf_Half address_size,Dwarf_Half lkind,Dwarf_Error * error)1390*4d9fdb46SRobert Mustacchi _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
1391*4d9fdb46SRobert Mustacchi     Dwarf_Block_c * return_block,
1392*4d9fdb46SRobert Mustacchi     Dwarf_Addr * lowpc,
1393*4d9fdb46SRobert Mustacchi     Dwarf_Addr * highpc,
1394*4d9fdb46SRobert Mustacchi     Dwarf_Bool *at_end,
1395*4d9fdb46SRobert Mustacchi     Dwarf_Half * lle_op,
1396*4d9fdb46SRobert Mustacchi     Dwarf_Off sec_offset,
1397*4d9fdb46SRobert Mustacchi     Dwarf_Half address_size,
1398*4d9fdb46SRobert Mustacchi     Dwarf_Half lkind,
1399*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
1400*4d9fdb46SRobert Mustacchi {
1401*4d9fdb46SRobert Mustacchi     Dwarf_Small *beg = dbg->de_debug_loc.dss_data + sec_offset;
1402*4d9fdb46SRobert Mustacchi     Dwarf_Small *locptr = 0;
1403*4d9fdb46SRobert Mustacchi     Dwarf_Small llecode = 0;
1404*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned expr_offset  = sec_offset;
1405*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr section_end = dbg->de_debug_loc.dss_data
1406*4d9fdb46SRobert Mustacchi         + dbg->de_debug_loc.dss_size;
1407*4d9fdb46SRobert Mustacchi 
1408*4d9fdb46SRobert Mustacchi     if (sec_offset >= dbg->de_debug_loc.dss_size) {
1409*4d9fdb46SRobert Mustacchi         /* We're at the end. No more present. */
1410*4d9fdb46SRobert Mustacchi         return DW_DLV_NO_ENTRY;
1411*4d9fdb46SRobert Mustacchi     }
1412*4d9fdb46SRobert Mustacchi     memset(return_block,0,sizeof(*return_block));
1413*4d9fdb46SRobert Mustacchi 
1414*4d9fdb46SRobert Mustacchi     /* not the same as non-split loclist, but still a list. */
1415*4d9fdb46SRobert Mustacchi     return_block->bl_kind = lkind;
1416*4d9fdb46SRobert Mustacchi 
1417*4d9fdb46SRobert Mustacchi     /* This is non-standard  GNU Dwarf4 loclist */
1418*4d9fdb46SRobert Mustacchi     return_block->bl_locdesc_offset = sec_offset;
1419*4d9fdb46SRobert Mustacchi     llecode = *beg;
1420*4d9fdb46SRobert Mustacchi     locptr = beg +1;
1421*4d9fdb46SRobert Mustacchi     expr_offset++;
1422*4d9fdb46SRobert Mustacchi     switch(llecode) {
1423*4d9fdb46SRobert Mustacchi     case DW_LLEX_end_of_list_entry:
1424*4d9fdb46SRobert Mustacchi         *at_end = TRUE;
1425*4d9fdb46SRobert Mustacchi         return_block->bl_section_offset = expr_offset;
1426*4d9fdb46SRobert Mustacchi         expr_offset++;
1427*4d9fdb46SRobert Mustacchi         break;
1428*4d9fdb46SRobert Mustacchi     case DW_LLEX_base_address_selection_entry: {
1429*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned addr_index = 0;
1430*4d9fdb46SRobert Mustacchi 
1431*4d9fdb46SRobert Mustacchi         DECODE_LEB128_UWORD_CK(locptr,addr_index,
1432*4d9fdb46SRobert Mustacchi             dbg,error,section_end);
1433*4d9fdb46SRobert Mustacchi         return_block->bl_section_offset = expr_offset;
1434*4d9fdb46SRobert Mustacchi         /* So this behaves much like non-dwo loclist */
1435*4d9fdb46SRobert Mustacchi         *lowpc=MAX_ADDR;
1436*4d9fdb46SRobert Mustacchi         *highpc=addr_index;
1437*4d9fdb46SRobert Mustacchi         }
1438*4d9fdb46SRobert Mustacchi         break;
1439*4d9fdb46SRobert Mustacchi     case DW_LLEX_start_end_entry: {
1440*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned addr_indexs = 0;
1441*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned addr_indexe= 0;
1442*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned exprlen = 0;
1443*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned leb128_length = 0;
1444*4d9fdb46SRobert Mustacchi 
1445*4d9fdb46SRobert Mustacchi         DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexs,
1446*4d9fdb46SRobert Mustacchi             leb128_length,
1447*4d9fdb46SRobert Mustacchi             dbg,error,section_end);
1448*4d9fdb46SRobert Mustacchi         expr_offset += leb128_length;
1449*4d9fdb46SRobert Mustacchi 
1450*4d9fdb46SRobert Mustacchi         DECODE_LEB128_UWORD_LEN_CK(locptr,addr_indexe,
1451*4d9fdb46SRobert Mustacchi             leb128_length,
1452*4d9fdb46SRobert Mustacchi             dbg,error,section_end);
1453*4d9fdb46SRobert Mustacchi         expr_offset +=leb128_length;
1454*4d9fdb46SRobert Mustacchi 
1455*4d9fdb46SRobert Mustacchi         *lowpc=addr_indexs;
1456*4d9fdb46SRobert Mustacchi         *highpc=addr_indexe;
1457*4d9fdb46SRobert Mustacchi 
1458*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
1459*4d9fdb46SRobert Mustacchi             DWARF_HALF_SIZE,
1460*4d9fdb46SRobert Mustacchi             error,section_end);
1461*4d9fdb46SRobert Mustacchi         locptr += DWARF_HALF_SIZE;
1462*4d9fdb46SRobert Mustacchi         expr_offset += DWARF_HALF_SIZE;
1463*4d9fdb46SRobert Mustacchi 
1464*4d9fdb46SRobert Mustacchi         return_block->bl_len = exprlen;
1465*4d9fdb46SRobert Mustacchi         return_block->bl_data = locptr;
1466*4d9fdb46SRobert Mustacchi         return_block->bl_section_offset = expr_offset;
1467*4d9fdb46SRobert Mustacchi 
1468*4d9fdb46SRobert Mustacchi         expr_offset += exprlen;
1469*4d9fdb46SRobert Mustacchi         if (expr_offset > dbg->de_debug_loc.dss_size) {
1470*4d9fdb46SRobert Mustacchi 
1471*4d9fdb46SRobert Mustacchi             _dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
1472*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1473*4d9fdb46SRobert Mustacchi         }
1474*4d9fdb46SRobert Mustacchi         }
1475*4d9fdb46SRobert Mustacchi         break;
1476*4d9fdb46SRobert Mustacchi     case DW_LLEX_start_length_entry: {
1477*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned addr_index = 0;
1478*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned  range_length = 0;
1479*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned exprlen = 0;
1480*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned leb128_length = 0;
1481*4d9fdb46SRobert Mustacchi 
1482*4d9fdb46SRobert Mustacchi         DECODE_LEB128_UWORD_LEN_CK(locptr,addr_index,
1483*4d9fdb46SRobert Mustacchi             leb128_length,
1484*4d9fdb46SRobert Mustacchi             dbg,error,section_end);
1485*4d9fdb46SRobert Mustacchi         expr_offset +=leb128_length;
1486*4d9fdb46SRobert Mustacchi 
1487*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, range_length, Dwarf_Unsigned, locptr,
1488*4d9fdb46SRobert Mustacchi             DWARF_32BIT_SIZE,
1489*4d9fdb46SRobert Mustacchi             error,section_end);
1490*4d9fdb46SRobert Mustacchi         locptr += DWARF_32BIT_SIZE;
1491*4d9fdb46SRobert Mustacchi         expr_offset += DWARF_32BIT_SIZE;
1492*4d9fdb46SRobert Mustacchi 
1493*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
1494*4d9fdb46SRobert Mustacchi             DWARF_HALF_SIZE,
1495*4d9fdb46SRobert Mustacchi             error,section_end);
1496*4d9fdb46SRobert Mustacchi         locptr += DWARF_HALF_SIZE;
1497*4d9fdb46SRobert Mustacchi         expr_offset += DWARF_HALF_SIZE;
1498*4d9fdb46SRobert Mustacchi 
1499*4d9fdb46SRobert Mustacchi         *lowpc = addr_index;
1500*4d9fdb46SRobert Mustacchi         *highpc = range_length;
1501*4d9fdb46SRobert Mustacchi         return_block->bl_len = exprlen;
1502*4d9fdb46SRobert Mustacchi         return_block->bl_data = locptr;
1503*4d9fdb46SRobert Mustacchi         return_block->bl_section_offset = expr_offset;
1504*4d9fdb46SRobert Mustacchi         /* exprblock_size can be zero, means no expression */
1505*4d9fdb46SRobert Mustacchi 
1506*4d9fdb46SRobert Mustacchi         expr_offset += exprlen;
1507*4d9fdb46SRobert Mustacchi         if (expr_offset > dbg->de_debug_loc.dss_size) {
1508*4d9fdb46SRobert Mustacchi             _dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
1509*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1510*4d9fdb46SRobert Mustacchi         }
1511*4d9fdb46SRobert Mustacchi         }
1512*4d9fdb46SRobert Mustacchi         break;
1513*4d9fdb46SRobert Mustacchi     case DW_LLEX_offset_pair_entry: {
1514*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned  startoffset = 0;
1515*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned  endoffset = 0;
1516*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned exprlen = 0;
1517*4d9fdb46SRobert Mustacchi 
1518*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, startoffset,
1519*4d9fdb46SRobert Mustacchi             Dwarf_Unsigned, locptr,
1520*4d9fdb46SRobert Mustacchi             DWARF_32BIT_SIZE,
1521*4d9fdb46SRobert Mustacchi             error,section_end);
1522*4d9fdb46SRobert Mustacchi         locptr += DWARF_32BIT_SIZE;
1523*4d9fdb46SRobert Mustacchi         expr_offset += DWARF_32BIT_SIZE;
1524*4d9fdb46SRobert Mustacchi 
1525*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, endoffset,
1526*4d9fdb46SRobert Mustacchi             Dwarf_Unsigned, locptr,
1527*4d9fdb46SRobert Mustacchi             DWARF_32BIT_SIZE,
1528*4d9fdb46SRobert Mustacchi             error,section_end);
1529*4d9fdb46SRobert Mustacchi         locptr += DWARF_32BIT_SIZE;
1530*4d9fdb46SRobert Mustacchi         expr_offset +=  DWARF_32BIT_SIZE;
1531*4d9fdb46SRobert Mustacchi         *lowpc= startoffset;
1532*4d9fdb46SRobert Mustacchi         *highpc = endoffset;
1533*4d9fdb46SRobert Mustacchi 
1534*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, exprlen, Dwarf_Unsigned, locptr,
1535*4d9fdb46SRobert Mustacchi             DWARF_HALF_SIZE,
1536*4d9fdb46SRobert Mustacchi             error,section_end);
1537*4d9fdb46SRobert Mustacchi         locptr += DWARF_HALF_SIZE;
1538*4d9fdb46SRobert Mustacchi         expr_offset += DWARF_HALF_SIZE;
1539*4d9fdb46SRobert Mustacchi 
1540*4d9fdb46SRobert Mustacchi         return_block->bl_len = exprlen;
1541*4d9fdb46SRobert Mustacchi         return_block->bl_data = locptr;
1542*4d9fdb46SRobert Mustacchi         return_block->bl_section_offset = expr_offset;
1543*4d9fdb46SRobert Mustacchi 
1544*4d9fdb46SRobert Mustacchi         expr_offset += exprlen;
1545*4d9fdb46SRobert Mustacchi         if (expr_offset > dbg->de_debug_loc.dss_size) {
1546*4d9fdb46SRobert Mustacchi             _dwarf_error(NULL, error, DW_DLE_DEBUG_LOC_SECTION_SHORT);
1547*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1548*4d9fdb46SRobert Mustacchi         }
1549*4d9fdb46SRobert Mustacchi         }
1550*4d9fdb46SRobert Mustacchi         break;
1551*4d9fdb46SRobert Mustacchi     default:
1552*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg,error,DW_DLE_LLE_CODE_UNKNOWN);
1553*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
1554*4d9fdb46SRobert Mustacchi     }
1555*4d9fdb46SRobert Mustacchi     *lle_op = llecode;
1556*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1557*4d9fdb46SRobert Mustacchi }
1558*4d9fdb46SRobert Mustacchi 
1559*4d9fdb46SRobert Mustacchi 
1560*4d9fdb46SRobert Mustacchi int
dwarf_get_loclist_head_kind(Dwarf_Loc_Head_c ll_header,unsigned int * kind,UNUSEDARG Dwarf_Error * error)1561*4d9fdb46SRobert Mustacchi dwarf_get_loclist_head_kind(Dwarf_Loc_Head_c ll_header,
1562*4d9fdb46SRobert Mustacchi     unsigned int * kind,
1563*4d9fdb46SRobert Mustacchi     UNUSEDARG Dwarf_Error  * error)
1564*4d9fdb46SRobert Mustacchi {
1565*4d9fdb46SRobert Mustacchi     *kind = ll_header->ll_kind;
1566*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1567*4d9fdb46SRobert Mustacchi }
1568*4d9fdb46SRobert Mustacchi 
1569*4d9fdb46SRobert Mustacchi static int
_dwarf_original_loclist_build(Dwarf_Debug dbg,Dwarf_Loc_Head_c llhead,Dwarf_Attribute attr,Dwarf_Error * error)1570*4d9fdb46SRobert Mustacchi _dwarf_original_loclist_build(Dwarf_Debug dbg,
1571*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead,
1572*4d9fdb46SRobert Mustacchi     Dwarf_Attribute attr,
1573*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
1574*4d9fdb46SRobert Mustacchi {
1575*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned loclist_offset = 0;
1576*4d9fdb46SRobert Mustacchi     int off_res  = DW_DLV_ERROR;
1577*4d9fdb46SRobert Mustacchi     int count_res = DW_DLV_ERROR;
1578*4d9fdb46SRobert Mustacchi     int loclist_count = 0;
1579*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned lli = 0;
1580*4d9fdb46SRobert Mustacchi     unsigned lkind = llhead->ll_kind;
1581*4d9fdb46SRobert Mustacchi     unsigned address_size = llhead->ll_address_size;
1582*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned listlen = 0;
1583*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c llbuf = 0;
1584*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucontext;
1585*4d9fdb46SRobert Mustacchi 
1586*4d9fdb46SRobert Mustacchi     off_res = _dwarf_get_loclist_header_start(dbg,
1587*4d9fdb46SRobert Mustacchi         attr, &loclist_offset, error);
1588*4d9fdb46SRobert Mustacchi     if (off_res != DW_DLV_OK) {
1589*4d9fdb46SRobert Mustacchi         return off_res;
1590*4d9fdb46SRobert Mustacchi     }
1591*4d9fdb46SRobert Mustacchi #if 0
1592*4d9fdb46SRobert Mustacchi     res = dwarf_global_formref(attr,&loclist_offset,error);
1593*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
1594*4d9fdb46SRobert Mustacchi         return res;
1595*4d9fdb46SRobert Mustacchi     }
1596*4d9fdb46SRobert Mustacchi #endif
1597*4d9fdb46SRobert Mustacchi 
1598*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_GNU_exp_list) {
1599*4d9fdb46SRobert Mustacchi         count_res = _dwarf_get_loclist_lle_count_dwo(dbg,
1600*4d9fdb46SRobert Mustacchi             loclist_offset,
1601*4d9fdb46SRobert Mustacchi             address_size,
1602*4d9fdb46SRobert Mustacchi             llhead->ll_kind,
1603*4d9fdb46SRobert Mustacchi             &loclist_count,
1604*4d9fdb46SRobert Mustacchi             error);
1605*4d9fdb46SRobert Mustacchi     } else {
1606*4d9fdb46SRobert Mustacchi         count_res = _dwarf_get_loclist_lle_count(dbg,
1607*4d9fdb46SRobert Mustacchi             loclist_offset, address_size,
1608*4d9fdb46SRobert Mustacchi             llhead->ll_kind,
1609*4d9fdb46SRobert Mustacchi             &loclist_count,
1610*4d9fdb46SRobert Mustacchi             error);
1611*4d9fdb46SRobert Mustacchi     }
1612*4d9fdb46SRobert Mustacchi     if (count_res != DW_DLV_OK) {
1613*4d9fdb46SRobert Mustacchi         return count_res;
1614*4d9fdb46SRobert Mustacchi     }
1615*4d9fdb46SRobert Mustacchi     if (loclist_count == 0) {
1616*4d9fdb46SRobert Mustacchi         return DW_DLV_NO_ENTRY;
1617*4d9fdb46SRobert Mustacchi     }
1618*4d9fdb46SRobert Mustacchi 
1619*4d9fdb46SRobert Mustacchi     listlen = loclist_count;
1620*4d9fdb46SRobert Mustacchi     llbuf = (Dwarf_Locdesc_c)
1621*4d9fdb46SRobert Mustacchi         _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
1622*4d9fdb46SRobert Mustacchi     if (!llbuf) {
1623*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1624*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
1625*4d9fdb46SRobert Mustacchi     }
1626*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc = llbuf;
1627*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc_count = listlen;
1628*4d9fdb46SRobert Mustacchi     cucontext = llhead->ll_context;
1629*4d9fdb46SRobert Mustacchi     llhead->ll_llearea_offset = loclist_offset;
1630*4d9fdb46SRobert Mustacchi 
1631*4d9fdb46SRobert Mustacchi         /* New get loc ops */
1632*4d9fdb46SRobert Mustacchi     for (lli = 0; lli < listlen; ++lli) {
1633*4d9fdb46SRobert Mustacchi         int lres = 0;
1634*4d9fdb46SRobert Mustacchi         Dwarf_Half lle_op = 0;
1635*4d9fdb46SRobert Mustacchi         Dwarf_Bool at_end = 0;
1636*4d9fdb46SRobert Mustacchi         Dwarf_Block_c loc_block;
1637*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned lowpc = 0;
1638*4d9fdb46SRobert Mustacchi         Dwarf_Unsigned highpc = 0;
1639*4d9fdb46SRobert Mustacchi         int blkres = 0;
1640*4d9fdb46SRobert Mustacchi 
1641*4d9fdb46SRobert Mustacchi         memset(&loc_block,0,sizeof(loc_block));
1642*4d9fdb46SRobert Mustacchi         if( lkind == DW_LKIND_GNU_exp_list) {
1643*4d9fdb46SRobert Mustacchi             blkres = _dwarf_read_loc_section_dwo(dbg,
1644*4d9fdb46SRobert Mustacchi                 &loc_block,
1645*4d9fdb46SRobert Mustacchi                 &lowpc, &highpc,
1646*4d9fdb46SRobert Mustacchi                 &at_end, &lle_op,
1647*4d9fdb46SRobert Mustacchi                 loclist_offset,
1648*4d9fdb46SRobert Mustacchi                 address_size,
1649*4d9fdb46SRobert Mustacchi                 lkind,
1650*4d9fdb46SRobert Mustacchi                 error);
1651*4d9fdb46SRobert Mustacchi         } else {
1652*4d9fdb46SRobert Mustacchi             blkres = _dwarf_read_loc_section(dbg,
1653*4d9fdb46SRobert Mustacchi                 &loc_block,
1654*4d9fdb46SRobert Mustacchi                 &lowpc, &highpc,
1655*4d9fdb46SRobert Mustacchi                 &lle_op,
1656*4d9fdb46SRobert Mustacchi                 loclist_offset,
1657*4d9fdb46SRobert Mustacchi                 address_size,
1658*4d9fdb46SRobert Mustacchi                 lkind,
1659*4d9fdb46SRobert Mustacchi                 error);
1660*4d9fdb46SRobert Mustacchi         }
1661*4d9fdb46SRobert Mustacchi         if (blkres != DW_DLV_OK) {
1662*4d9fdb46SRobert Mustacchi             return blkres;
1663*4d9fdb46SRobert Mustacchi         }
1664*4d9fdb46SRobert Mustacchi         /* Fills in the locdesc and its operators list at index lli */
1665*4d9fdb46SRobert Mustacchi         lres = _dwarf_fill_in_locdesc_op_c(dbg,
1666*4d9fdb46SRobert Mustacchi             lli,
1667*4d9fdb46SRobert Mustacchi             llhead,
1668*4d9fdb46SRobert Mustacchi             &loc_block,
1669*4d9fdb46SRobert Mustacchi             address_size,
1670*4d9fdb46SRobert Mustacchi             cucontext->cc_length_size,
1671*4d9fdb46SRobert Mustacchi             cucontext->cc_version_stamp,
1672*4d9fdb46SRobert Mustacchi             lowpc,
1673*4d9fdb46SRobert Mustacchi             highpc,
1674*4d9fdb46SRobert Mustacchi             lle_op,
1675*4d9fdb46SRobert Mustacchi             error);
1676*4d9fdb46SRobert Mustacchi         if (lres != DW_DLV_OK) {
1677*4d9fdb46SRobert Mustacchi             return lres;
1678*4d9fdb46SRobert Mustacchi         }
1679*4d9fdb46SRobert Mustacchi         /* Now get to next loclist entry offset. */
1680*4d9fdb46SRobert Mustacchi         loclist_offset = loc_block.bl_section_offset +
1681*4d9fdb46SRobert Mustacchi             loc_block.bl_len;
1682*4d9fdb46SRobert Mustacchi     }
1683*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1684*4d9fdb46SRobert Mustacchi }
1685*4d9fdb46SRobert Mustacchi 
1686*4d9fdb46SRobert Mustacchi static int
_dwarf_original_expression_build(Dwarf_Debug dbg,Dwarf_Loc_Head_c llhead,Dwarf_Attribute attr,Dwarf_Error * error)1687*4d9fdb46SRobert Mustacchi _dwarf_original_expression_build(Dwarf_Debug dbg,
1688*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead,
1689*4d9fdb46SRobert Mustacchi     Dwarf_Attribute attr,
1690*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
1691*4d9fdb46SRobert Mustacchi {
1692*4d9fdb46SRobert Mustacchi 
1693*4d9fdb46SRobert Mustacchi     Dwarf_Block_c loc_blockc;
1694*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned lowpc = 0;
1695*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned highpc = 0;
1696*4d9fdb46SRobert Mustacchi     unsigned form = llhead->ll_attrform;
1697*4d9fdb46SRobert Mustacchi     int blkres = 0;
1698*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c llbuf = 0;
1699*4d9fdb46SRobert Mustacchi     unsigned listlen = 1;
1700*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucontext = llhead->ll_context;
1701*4d9fdb46SRobert Mustacchi 
1702*4d9fdb46SRobert Mustacchi     memset(&loc_blockc,0,sizeof(loc_blockc));
1703*4d9fdb46SRobert Mustacchi     if( form == DW_FORM_exprloc) {
1704*4d9fdb46SRobert Mustacchi         blkres = dwarf_formexprloc(attr,&loc_blockc.bl_len,
1705*4d9fdb46SRobert Mustacchi             &loc_blockc.bl_data,error);
1706*4d9fdb46SRobert Mustacchi         if(blkres != DW_DLV_OK) {
1707*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
1708*4d9fdb46SRobert Mustacchi             return blkres;
1709*4d9fdb46SRobert Mustacchi         }
1710*4d9fdb46SRobert Mustacchi         loc_blockc.bl_kind = llhead->ll_kind;
1711*4d9fdb46SRobert Mustacchi         loc_blockc.bl_section_offset  =
1712*4d9fdb46SRobert Mustacchi             (char *)loc_blockc.bl_data -
1713*4d9fdb46SRobert Mustacchi             (char *)dbg->de_debug_info.dss_data;
1714*4d9fdb46SRobert Mustacchi         loc_blockc.bl_locdesc_offset = 0; /* not relevant */
1715*4d9fdb46SRobert Mustacchi     } else {
1716*4d9fdb46SRobert Mustacchi         Dwarf_Block loc_block;
1717*4d9fdb46SRobert Mustacchi 
1718*4d9fdb46SRobert Mustacchi         memset(&loc_block,0,sizeof(loc_block));
1719*4d9fdb46SRobert Mustacchi         blkres = _dwarf_formblock_internal(dbg,attr,
1720*4d9fdb46SRobert Mustacchi             llhead->ll_context,
1721*4d9fdb46SRobert Mustacchi             &loc_block,
1722*4d9fdb46SRobert Mustacchi             error);
1723*4d9fdb46SRobert Mustacchi         if (blkres != DW_DLV_OK) {
1724*4d9fdb46SRobert Mustacchi             return blkres;
1725*4d9fdb46SRobert Mustacchi         }
1726*4d9fdb46SRobert Mustacchi         loc_blockc.bl_len = loc_block.bl_len;
1727*4d9fdb46SRobert Mustacchi         loc_blockc.bl_data = loc_block.bl_data;
1728*4d9fdb46SRobert Mustacchi         loc_blockc.bl_kind = llhead->ll_kind;
1729*4d9fdb46SRobert Mustacchi         loc_blockc.bl_section_offset = loc_block.bl_section_offset;
1730*4d9fdb46SRobert Mustacchi         loc_blockc.bl_locdesc_offset = 0; /* not relevant */
1731*4d9fdb46SRobert Mustacchi     }
1732*4d9fdb46SRobert Mustacchi     /*  This hack ensures that the Locdesc_c
1733*4d9fdb46SRobert Mustacchi         is marked DW_LLE_start_end. But really unncessary
1734*4d9fdb46SRobert Mustacchi         as we are marked as the correct ll_kind */
1735*4d9fdb46SRobert Mustacchi     lowpc = 0;   /* HACK */
1736*4d9fdb46SRobert Mustacchi     highpc = (Dwarf_Unsigned) (-1LL); /* HACK */
1737*4d9fdb46SRobert Mustacchi 
1738*4d9fdb46SRobert Mustacchi     llbuf = (Dwarf_Locdesc_c)
1739*4d9fdb46SRobert Mustacchi         _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, listlen);
1740*4d9fdb46SRobert Mustacchi     if (!llbuf) {
1741*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
1742*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
1743*4d9fdb46SRobert Mustacchi     }
1744*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc = llbuf;
1745*4d9fdb46SRobert Mustacchi     /* One by definition of a location entry. */
1746*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc_count = listlen;
1747*4d9fdb46SRobert Mustacchi 
1748*4d9fdb46SRobert Mustacchi     /*  An empty location description (block length 0)
1749*4d9fdb46SRobert Mustacchi         means the code generator emitted no variable,
1750*4d9fdb46SRobert Mustacchi         the variable was not generated, it was unused
1751*4d9fdb46SRobert Mustacchi         or perhaps never tested after being set. Dwarf2,
1752*4d9fdb46SRobert Mustacchi         section 2.4.1 In other words, it is not an error,
1753*4d9fdb46SRobert Mustacchi         and we don't test for block length 0 specially here.  */
1754*4d9fdb46SRobert Mustacchi 
1755*4d9fdb46SRobert Mustacchi     /* Fills in the locdesc and its operators list at index 0 */
1756*4d9fdb46SRobert Mustacchi     blkres = _dwarf_fill_in_locdesc_op_c(dbg,
1757*4d9fdb46SRobert Mustacchi         0, /* fake locdesc is index 0 */
1758*4d9fdb46SRobert Mustacchi         llhead,
1759*4d9fdb46SRobert Mustacchi         &loc_blockc,
1760*4d9fdb46SRobert Mustacchi         llhead->ll_address_size,
1761*4d9fdb46SRobert Mustacchi         cucontext->cc_length_size,
1762*4d9fdb46SRobert Mustacchi         cucontext->cc_version_stamp,
1763*4d9fdb46SRobert Mustacchi         lowpc, highpc,
1764*4d9fdb46SRobert Mustacchi         0,
1765*4d9fdb46SRobert Mustacchi         error);
1766*4d9fdb46SRobert Mustacchi     if (blkres != DW_DLV_OK) {
1767*4d9fdb46SRobert Mustacchi         /* low level error already set: let it be passed back */
1768*4d9fdb46SRobert Mustacchi         return blkres;
1769*4d9fdb46SRobert Mustacchi     }
1770*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1771*4d9fdb46SRobert Mustacchi }
1772*4d9fdb46SRobert Mustacchi 
1773*4d9fdb46SRobert Mustacchi /*  Following the original loclist definition the low
1774*4d9fdb46SRobert Mustacchi     value is all one bits, the high value is the base
1775*4d9fdb46SRobert Mustacchi     address. */
1776*4d9fdb46SRobert Mustacchi static int
cook_original_loclist_contents(Dwarf_Debug dbg,Dwarf_Loc_Head_c llhead,Dwarf_Error * error)1777*4d9fdb46SRobert Mustacchi cook_original_loclist_contents(Dwarf_Debug dbg,
1778*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead,
1779*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
1780*4d9fdb46SRobert Mustacchi {
1781*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1782*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned count = llhead->ll_locdesc_count;
1783*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned i = 0;
1784*4d9fdb46SRobert Mustacchi 
1785*4d9fdb46SRobert Mustacchi     for ( i = 0 ; i < count; ++i) {
1786*4d9fdb46SRobert Mustacchi         Dwarf_Locdesc_c  llc = 0;
1787*4d9fdb46SRobert Mustacchi 
1788*4d9fdb46SRobert Mustacchi         llc = llhead->ll_locdesc +i;
1789*4d9fdb46SRobert Mustacchi         switch(llc->ld_lle_value) {
1790*4d9fdb46SRobert Mustacchi         case DW_LLE_end_of_list: {
1791*4d9fdb46SRobert Mustacchi             /* nothing to do */
1792*4d9fdb46SRobert Mustacchi             break;
1793*4d9fdb46SRobert Mustacchi             }
1794*4d9fdb46SRobert Mustacchi         case DW_LLE_base_address: {
1795*4d9fdb46SRobert Mustacchi             llc->ld_lopc =  llc->ld_rawhigh;
1796*4d9fdb46SRobert Mustacchi             llc->ld_highpc =  llc->ld_rawhigh;
1797*4d9fdb46SRobert Mustacchi             baseaddress =  llc->ld_rawhigh;
1798*4d9fdb46SRobert Mustacchi             break;
1799*4d9fdb46SRobert Mustacchi             }
1800*4d9fdb46SRobert Mustacchi         case DW_LLE_offset_pair: {
1801*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow + baseaddress;
1802*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawhigh + baseaddress;
1803*4d9fdb46SRobert Mustacchi             break;
1804*4d9fdb46SRobert Mustacchi             }
1805*4d9fdb46SRobert Mustacchi         default: {
1806*4d9fdb46SRobert Mustacchi             dwarfstring m;
1807*4d9fdb46SRobert Mustacchi 
1808*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
1809*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m,
1810*4d9fdb46SRobert Mustacchi                 "DW_DLE_LOCLISTS_ERROR: improper synthesized LLE code "
1811*4d9fdb46SRobert Mustacchi                 "of 0x%x is unknown. In standard DWARF3/4 loclist",
1812*4d9fdb46SRobert Mustacchi                 llc->ld_lle_value);
1813*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg,error,
1814*4d9fdb46SRobert Mustacchi                 DW_DLE_LOCLISTS_ERROR,
1815*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
1816*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
1817*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1818*4d9fdb46SRobert Mustacchi             }
1819*4d9fdb46SRobert Mustacchi         }
1820*4d9fdb46SRobert Mustacchi     }
1821*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1822*4d9fdb46SRobert Mustacchi }
1823*4d9fdb46SRobert Mustacchi 
1824*4d9fdb46SRobert Mustacchi static int
cook_gnu_loclist_contents(Dwarf_Debug dbg,Dwarf_Loc_Head_c llhead,Dwarf_Error * error)1825*4d9fdb46SRobert Mustacchi cook_gnu_loclist_contents(Dwarf_Debug dbg,
1826*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead,
1827*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
1828*4d9fdb46SRobert Mustacchi {
1829*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1830*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned count = llhead->ll_locdesc_count;
1831*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned i = 0;
1832*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucontext = llhead->ll_context;
1833*4d9fdb46SRobert Mustacchi     int res = 0;
1834*4d9fdb46SRobert Mustacchi 
1835*4d9fdb46SRobert Mustacchi     for (i = 0 ; i < count ; ++i) {
1836*4d9fdb46SRobert Mustacchi         Dwarf_Locdesc_c  llc = 0;
1837*4d9fdb46SRobert Mustacchi 
1838*4d9fdb46SRobert Mustacchi         llc = llhead->ll_locdesc +i;
1839*4d9fdb46SRobert Mustacchi         switch(llc->ld_lle_value) {
1840*4d9fdb46SRobert Mustacchi         case DW_LLEX_base_address_selection_entry:{
1841*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
1842*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1843*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawhigh,&targaddr,error);
1844*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1845*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1846*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
1847*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = 0;
1848*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1849*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1850*4d9fdb46SRobert Mustacchi                     *error = 0;
1851*4d9fdb46SRobert Mustacchi                 }
1852*4d9fdb46SRobert Mustacchi             } else {
1853*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
1854*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = targaddr;
1855*4d9fdb46SRobert Mustacchi             }
1856*4d9fdb46SRobert Mustacchi             break;
1857*4d9fdb46SRobert Mustacchi             }
1858*4d9fdb46SRobert Mustacchi         case DW_LLEX_end_of_list_entry:{
1859*4d9fdb46SRobert Mustacchi             /* Nothing to do. */
1860*4d9fdb46SRobert Mustacchi             break;
1861*4d9fdb46SRobert Mustacchi             }
1862*4d9fdb46SRobert Mustacchi         case DW_LLEX_start_length_entry:{
1863*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
1864*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1865*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawlow,&targaddr,error);
1866*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1867*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1868*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
1869*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1870*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1871*4d9fdb46SRobert Mustacchi                     *error = 0;
1872*4d9fdb46SRobert Mustacchi                 }
1873*4d9fdb46SRobert Mustacchi             } else {
1874*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
1875*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = llc->ld_lopc +llc->ld_rawhigh;
1876*4d9fdb46SRobert Mustacchi             }
1877*4d9fdb46SRobert Mustacchi             break;
1878*4d9fdb46SRobert Mustacchi             }
1879*4d9fdb46SRobert Mustacchi         case DW_LLEX_offset_pair_entry:{
1880*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow + baseaddress;
1881*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawhigh + baseaddress;
1882*4d9fdb46SRobert Mustacchi             break;
1883*4d9fdb46SRobert Mustacchi             }
1884*4d9fdb46SRobert Mustacchi         case DW_LLEX_start_end_entry:{
1885*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
1886*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1887*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawlow,&targaddr,error);
1888*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1889*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1890*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
1891*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1892*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1893*4d9fdb46SRobert Mustacchi                     *error = 0;
1894*4d9fdb46SRobert Mustacchi                 }
1895*4d9fdb46SRobert Mustacchi             } else {
1896*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
1897*4d9fdb46SRobert Mustacchi             }
1898*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1899*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawhigh,&targaddr,error);
1900*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1901*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1902*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = 0;
1903*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1904*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1905*4d9fdb46SRobert Mustacchi                     *error = 0;
1906*4d9fdb46SRobert Mustacchi                 }
1907*4d9fdb46SRobert Mustacchi             } else {
1908*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = targaddr;
1909*4d9fdb46SRobert Mustacchi             }
1910*4d9fdb46SRobert Mustacchi 
1911*4d9fdb46SRobert Mustacchi 
1912*4d9fdb46SRobert Mustacchi             break;
1913*4d9fdb46SRobert Mustacchi             }
1914*4d9fdb46SRobert Mustacchi         default:{
1915*4d9fdb46SRobert Mustacchi             dwarfstring m;
1916*4d9fdb46SRobert Mustacchi 
1917*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
1918*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m,
1919*4d9fdb46SRobert Mustacchi                 "DW_DLE_LOCLISTS_ERROR: improper LLEX code "
1920*4d9fdb46SRobert Mustacchi                 "of 0x%x is unknown. GNU LLEX dwo loclists error",
1921*4d9fdb46SRobert Mustacchi                 llc->ld_lle_value);
1922*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg,error,
1923*4d9fdb46SRobert Mustacchi                 DW_DLE_LOCLISTS_ERROR,
1924*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
1925*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
1926*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
1927*4d9fdb46SRobert Mustacchi 
1928*4d9fdb46SRobert Mustacchi             break;
1929*4d9fdb46SRobert Mustacchi             }
1930*4d9fdb46SRobert Mustacchi         }
1931*4d9fdb46SRobert Mustacchi     }
1932*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
1933*4d9fdb46SRobert Mustacchi }
1934*4d9fdb46SRobert Mustacchi 
1935*4d9fdb46SRobert Mustacchi 
1936*4d9fdb46SRobert Mustacchi /* DWARF5 */
1937*4d9fdb46SRobert Mustacchi static int
cook_loclists_contents(Dwarf_Debug dbg,Dwarf_Loc_Head_c llhead,Dwarf_Error * error)1938*4d9fdb46SRobert Mustacchi cook_loclists_contents(Dwarf_Debug dbg,
1939*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead,
1940*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
1941*4d9fdb46SRobert Mustacchi {
1942*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned baseaddress = llhead->ll_cu_base_address;
1943*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned count = llhead->ll_locdesc_count;
1944*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned i = 0;
1945*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucontext = llhead->ll_context;
1946*4d9fdb46SRobert Mustacchi     int res = 0;
1947*4d9fdb46SRobert Mustacchi 
1948*4d9fdb46SRobert Mustacchi     for (i = 0 ; i < count ; ++i) {
1949*4d9fdb46SRobert Mustacchi         Dwarf_Locdesc_c  llc = 0;
1950*4d9fdb46SRobert Mustacchi 
1951*4d9fdb46SRobert Mustacchi         llc = llhead->ll_locdesc +i;
1952*4d9fdb46SRobert Mustacchi         switch(llc->ld_lle_value) {
1953*4d9fdb46SRobert Mustacchi         case DW_LLE_base_addressx: {
1954*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
1955*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1956*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawlow,&targaddr,error);
1957*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1958*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1959*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
1960*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1961*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1962*4d9fdb46SRobert Mustacchi                     *error = 0;
1963*4d9fdb46SRobert Mustacchi                 }
1964*4d9fdb46SRobert Mustacchi             } else {
1965*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
1966*4d9fdb46SRobert Mustacchi             }
1967*4d9fdb46SRobert Mustacchi             break;
1968*4d9fdb46SRobert Mustacchi         }
1969*4d9fdb46SRobert Mustacchi         case DW_LLE_startx_endx:{
1970*4d9fdb46SRobert Mustacchi             /* two indexes into debug_addr */
1971*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
1972*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1973*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawlow,&targaddr,error);
1974*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1975*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1976*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
1977*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1978*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1979*4d9fdb46SRobert Mustacchi                     *error = 0;
1980*4d9fdb46SRobert Mustacchi                 }
1981*4d9fdb46SRobert Mustacchi             } else {
1982*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
1983*4d9fdb46SRobert Mustacchi             }
1984*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
1985*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawhigh,&targaddr,error);
1986*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
1987*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
1988*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = 0;
1989*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
1990*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
1991*4d9fdb46SRobert Mustacchi                     *error = 0;
1992*4d9fdb46SRobert Mustacchi                 }
1993*4d9fdb46SRobert Mustacchi             } else {
1994*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = targaddr;
1995*4d9fdb46SRobert Mustacchi             }
1996*4d9fdb46SRobert Mustacchi             break;
1997*4d9fdb46SRobert Mustacchi         }
1998*4d9fdb46SRobert Mustacchi         case DW_LLE_startx_length:{
1999*4d9fdb46SRobert Mustacchi             /* one index to debug_addr other a length */
2000*4d9fdb46SRobert Mustacchi             Dwarf_Addr targaddr = 0;
2001*4d9fdb46SRobert Mustacchi             res = _dwarf_extract_address_from_debug_addr(dbg,
2002*4d9fdb46SRobert Mustacchi                 cucontext,llc->ld_rawlow,&targaddr,error);
2003*4d9fdb46SRobert Mustacchi             if (res != DW_DLV_OK) {
2004*4d9fdb46SRobert Mustacchi                 llc->ld_index_failed = TRUE;
2005*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = 0;
2006*4d9fdb46SRobert Mustacchi                 if (res == DW_DLV_ERROR) {
2007*4d9fdb46SRobert Mustacchi                     dwarf_dealloc_error(dbg, *error);
2008*4d9fdb46SRobert Mustacchi                     *error = 0;
2009*4d9fdb46SRobert Mustacchi                 }
2010*4d9fdb46SRobert Mustacchi             } else {
2011*4d9fdb46SRobert Mustacchi                 llc->ld_lopc = targaddr;
2012*4d9fdb46SRobert Mustacchi                 llc->ld_highpc = targaddr + llc->ld_rawhigh;
2013*4d9fdb46SRobert Mustacchi             }
2014*4d9fdb46SRobert Mustacchi             break;
2015*4d9fdb46SRobert Mustacchi         }
2016*4d9fdb46SRobert Mustacchi         case DW_LLE_offset_pair:{
2017*4d9fdb46SRobert Mustacchi             /*offsets of the current base address*/
2018*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow +baseaddress;
2019*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawhigh +baseaddress;
2020*4d9fdb46SRobert Mustacchi             break;
2021*4d9fdb46SRobert Mustacchi         }
2022*4d9fdb46SRobert Mustacchi         case DW_LLE_default_location:{
2023*4d9fdb46SRobert Mustacchi             /*  nothing to do here, just has a counted
2024*4d9fdb46SRobert Mustacchi                 location description */
2025*4d9fdb46SRobert Mustacchi             break;
2026*4d9fdb46SRobert Mustacchi         }
2027*4d9fdb46SRobert Mustacchi         case DW_LLE_base_address:{
2028*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow;
2029*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawlow;
2030*4d9fdb46SRobert Mustacchi             baseaddress = llc->ld_rawlow;
2031*4d9fdb46SRobert Mustacchi             break;
2032*4d9fdb46SRobert Mustacchi         }
2033*4d9fdb46SRobert Mustacchi         case DW_LLE_start_end:{
2034*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow;
2035*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawhigh;
2036*4d9fdb46SRobert Mustacchi             break;
2037*4d9fdb46SRobert Mustacchi         }
2038*4d9fdb46SRobert Mustacchi         case DW_LLE_start_length:{
2039*4d9fdb46SRobert Mustacchi             llc->ld_lopc = llc->ld_rawlow;
2040*4d9fdb46SRobert Mustacchi             llc->ld_highpc = llc->ld_rawlow + llc->ld_rawhigh;
2041*4d9fdb46SRobert Mustacchi             break;
2042*4d9fdb46SRobert Mustacchi         }
2043*4d9fdb46SRobert Mustacchi         case DW_LLE_end_of_list:{
2044*4d9fdb46SRobert Mustacchi             /* do nothing */
2045*4d9fdb46SRobert Mustacchi             break;
2046*4d9fdb46SRobert Mustacchi         }
2047*4d9fdb46SRobert Mustacchi         default: {
2048*4d9fdb46SRobert Mustacchi             dwarfstring m;
2049*4d9fdb46SRobert Mustacchi 
2050*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
2051*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m,
2052*4d9fdb46SRobert Mustacchi                 "DW_DLE_LOCLISTS_ERROR: improper DW_LLE code "
2053*4d9fdb46SRobert Mustacchi                 "of 0x%x is unknown. DWARF5 loclists error",
2054*4d9fdb46SRobert Mustacchi                 llc->ld_lle_value);
2055*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg,error,
2056*4d9fdb46SRobert Mustacchi                 DW_DLE_LOCLISTS_ERROR,
2057*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
2058*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
2059*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
2060*4d9fdb46SRobert Mustacchi         }
2061*4d9fdb46SRobert Mustacchi         }
2062*4d9fdb46SRobert Mustacchi     }
2063*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
2064*4d9fdb46SRobert Mustacchi }
2065*4d9fdb46SRobert Mustacchi 
2066*4d9fdb46SRobert Mustacchi /*  New October 2015
2067*4d9fdb46SRobert Mustacchi     This interface requires the use of interface functions
2068*4d9fdb46SRobert Mustacchi     to get data from Dwarf_Locdesc_c.  The structures
2069*4d9fdb46SRobert Mustacchi     are not visible to callers. */
2070*4d9fdb46SRobert Mustacchi int
dwarf_get_loclist_c(Dwarf_Attribute attr,Dwarf_Loc_Head_c * ll_header_out,Dwarf_Unsigned * listlen_out,Dwarf_Error * error)2071*4d9fdb46SRobert Mustacchi dwarf_get_loclist_c(Dwarf_Attribute attr,
2072*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c * ll_header_out,
2073*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   * listlen_out,
2074*4d9fdb46SRobert Mustacchi     Dwarf_Error      * error)
2075*4d9fdb46SRobert Mustacchi {
2076*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg;
2077*4d9fdb46SRobert Mustacchi     Dwarf_Half form          = 0;
2078*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead  = 0;
2079*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucontext = 0;
2080*4d9fdb46SRobert Mustacchi     unsigned address_size    = 0;
2081*4d9fdb46SRobert Mustacchi     int cuversionstamp       = 0;
2082*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_cu         = FALSE;
2083*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned attrnum   = 0;
2084*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_dwo        = 0;
2085*4d9fdb46SRobert Mustacchi     int setup_res            = DW_DLV_ERROR;
2086*4d9fdb46SRobert Mustacchi     int lkind                = 0;
2087*4d9fdb46SRobert Mustacchi 
2088*4d9fdb46SRobert Mustacchi     /* ***** BEGIN CODE ***** */
2089*4d9fdb46SRobert Mustacchi     setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
2090*4d9fdb46SRobert Mustacchi     if (setup_res != DW_DLV_OK) {
2091*4d9fdb46SRobert Mustacchi         return setup_res;
2092*4d9fdb46SRobert Mustacchi     }
2093*4d9fdb46SRobert Mustacchi     attrnum = attr->ar_attribute;
2094*4d9fdb46SRobert Mustacchi     cuversionstamp = cucontext->cc_version_stamp;
2095*4d9fdb46SRobert Mustacchi     address_size = cucontext->cc_address_size;
2096*4d9fdb46SRobert Mustacchi     is_dwo = cucontext->cc_is_dwo;
2097*4d9fdb46SRobert Mustacchi     lkind = determine_location_lkind(cuversionstamp,
2098*4d9fdb46SRobert Mustacchi         form, attrnum, is_dwo);
2099*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_unknown) {
2100*4d9fdb46SRobert Mustacchi         dwarfstring m;
2101*4d9fdb46SRobert Mustacchi         const char * formname = "<unknownform>";
2102*4d9fdb46SRobert Mustacchi         const char * attrname = "<unknown attribute>";
2103*4d9fdb46SRobert Mustacchi 
2104*4d9fdb46SRobert Mustacchi         dwarfstring_constructor(&m);
2105*4d9fdb46SRobert Mustacchi         dwarf_get_FORM_name(form,&formname);
2106*4d9fdb46SRobert Mustacchi         dwarf_get_AT_name(attrnum,&attrname);
2107*4d9fdb46SRobert Mustacchi         dwarfstring_append_printf_u(&m,
2108*4d9fdb46SRobert Mustacchi             "DW_DLE_LOC_EXPR_BAD: For Compilation Unit "
2109*4d9fdb46SRobert Mustacchi             "version %u",cuversionstamp);
2110*4d9fdb46SRobert Mustacchi         dwarfstring_append_printf_u(&m,
2111*4d9fdb46SRobert Mustacchi             ", attribute 0x%x (",attrnum);
2112*4d9fdb46SRobert Mustacchi         dwarfstring_append(&m,(char *)attrname);
2113*4d9fdb46SRobert Mustacchi         dwarfstring_append_printf_u(&m,
2114*4d9fdb46SRobert Mustacchi             ") form 0x%x (",form);
2115*4d9fdb46SRobert Mustacchi         dwarfstring_append(&m,(char *)formname);
2116*4d9fdb46SRobert Mustacchi         if (is_dwo) {
2117*4d9fdb46SRobert Mustacchi             dwarfstring_append(&m,") (the CU is a .dwo) ");
2118*4d9fdb46SRobert Mustacchi         } else {
2119*4d9fdb46SRobert Mustacchi             dwarfstring_append(&m,") (the CU is not a .dwo) ");
2120*4d9fdb46SRobert Mustacchi         }
2121*4d9fdb46SRobert Mustacchi         dwarfstring_append(&m," we don't undrstand the location");
2122*4d9fdb46SRobert Mustacchi         _dwarf_error_string(dbg,error,DW_DLE_LOC_EXPR_BAD,
2123*4d9fdb46SRobert Mustacchi             dwarfstring_string(&m));
2124*4d9fdb46SRobert Mustacchi         dwarfstring_destructor(&m);
2125*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
2126*4d9fdb46SRobert Mustacchi     }
2127*4d9fdb46SRobert Mustacchi     /*  Doing this early (first) to avoid repeating the alloc code
2128*4d9fdb46SRobert Mustacchi         for each type  */
2129*4d9fdb46SRobert Mustacchi     llhead = (Dwarf_Loc_Head_c)
2130*4d9fdb46SRobert Mustacchi         _dwarf_get_alloc(dbg, DW_DLA_LOC_HEAD_C, 1);
2131*4d9fdb46SRobert Mustacchi     if (!llhead) {
2132*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2133*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2134*4d9fdb46SRobert Mustacchi     }
2135*4d9fdb46SRobert Mustacchi     llhead->ll_cuversion = cuversionstamp;
2136*4d9fdb46SRobert Mustacchi     llhead->ll_kind = lkind;
2137*4d9fdb46SRobert Mustacchi     llhead->ll_attrnum = attrnum;
2138*4d9fdb46SRobert Mustacchi     llhead->ll_attrform = form;
2139*4d9fdb46SRobert Mustacchi     llhead->ll_dbg = dbg;
2140*4d9fdb46SRobert Mustacchi     llhead->ll_address_size = address_size;
2141*4d9fdb46SRobert Mustacchi     llhead->ll_offset_size = cucontext->cc_length_size;
2142*4d9fdb46SRobert Mustacchi     llhead->ll_context = cucontext;
2143*4d9fdb46SRobert Mustacchi 
2144*4d9fdb46SRobert Mustacchi     llhead->ll_at_loclists_base_present =
2145*4d9fdb46SRobert Mustacchi         cucontext->cc_loclists_base_present;
2146*4d9fdb46SRobert Mustacchi     llhead->ll_at_loclists_base =  cucontext->cc_loclists_base;
2147*4d9fdb46SRobert Mustacchi     llhead->ll_cu_base_address_present = cucontext->cc_low_pc_present;
2148*4d9fdb46SRobert Mustacchi     llhead->ll_cu_base_address = cucontext->cc_low_pc;
2149*4d9fdb46SRobert Mustacchi     llhead->ll_cu_addr_base = cucontext->cc_addr_base;
2150*4d9fdb46SRobert Mustacchi     llhead->ll_cu_addr_base_present = cucontext->cc_addr_base_present;
2151*4d9fdb46SRobert Mustacchi 
2152*4d9fdb46SRobert Mustacchi     if (lkind == DW_LKIND_loclist ||
2153*4d9fdb46SRobert Mustacchi         lkind == DW_LKIND_GNU_exp_list) {
2154*4d9fdb46SRobert Mustacchi         int ores = 0;
2155*4d9fdb46SRobert Mustacchi         /* Here we have a loclist to deal with. */
2156*4d9fdb46SRobert Mustacchi         ores = context_is_cu_not_tu(cucontext,&is_cu);
2157*4d9fdb46SRobert Mustacchi         if(ores != DW_DLV_OK) {
2158*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2159*4d9fdb46SRobert Mustacchi             return setup_res;
2160*4d9fdb46SRobert Mustacchi         }
2161*4d9fdb46SRobert Mustacchi         ores = _dwarf_original_loclist_build(dbg,
2162*4d9fdb46SRobert Mustacchi             llhead, attr, error);
2163*4d9fdb46SRobert Mustacchi         if (ores != DW_DLV_OK) {
2164*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2165*4d9fdb46SRobert Mustacchi             return ores;
2166*4d9fdb46SRobert Mustacchi         }
2167*4d9fdb46SRobert Mustacchi         if (lkind == DW_LKIND_loclist) {
2168*4d9fdb46SRobert Mustacchi             ores = cook_original_loclist_contents(dbg,llhead,error);
2169*4d9fdb46SRobert Mustacchi         } else {
2170*4d9fdb46SRobert Mustacchi             ores = cook_gnu_loclist_contents(dbg,llhead,error);
2171*4d9fdb46SRobert Mustacchi         }
2172*4d9fdb46SRobert Mustacchi         if (ores != DW_DLV_OK) {
2173*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2174*4d9fdb46SRobert Mustacchi             return ores;
2175*4d9fdb46SRobert Mustacchi         }
2176*4d9fdb46SRobert Mustacchi     } else if (lkind == DW_LKIND_expression) {
2177*4d9fdb46SRobert Mustacchi         /* DWARF2,3,4,5 */
2178*4d9fdb46SRobert Mustacchi         int eres = 0;
2179*4d9fdb46SRobert Mustacchi         eres = _dwarf_original_expression_build(dbg,
2180*4d9fdb46SRobert Mustacchi             llhead, attr, error);
2181*4d9fdb46SRobert Mustacchi         if (eres != DW_DLV_OK) {
2182*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2183*4d9fdb46SRobert Mustacchi             return eres;
2184*4d9fdb46SRobert Mustacchi         }
2185*4d9fdb46SRobert Mustacchi     } else if (lkind == DW_LKIND_loclists) {
2186*4d9fdb46SRobert Mustacchi         /* DWARF5! */
2187*4d9fdb46SRobert Mustacchi         int leres = 0;
2188*4d9fdb46SRobert Mustacchi 
2189*4d9fdb46SRobert Mustacchi         leres = _dwarf_loclists_fill_in_lle_head(dbg,
2190*4d9fdb46SRobert Mustacchi             attr,llhead,error);
2191*4d9fdb46SRobert Mustacchi         if (leres != DW_DLV_OK) {
2192*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2193*4d9fdb46SRobert Mustacchi             return leres;
2194*4d9fdb46SRobert Mustacchi         }
2195*4d9fdb46SRobert Mustacchi         leres = cook_loclists_contents(dbg,llhead,error);
2196*4d9fdb46SRobert Mustacchi         if (leres != DW_DLV_OK) {
2197*4d9fdb46SRobert Mustacchi             dwarf_loc_head_c_dealloc(llhead);
2198*4d9fdb46SRobert Mustacchi             return leres;
2199*4d9fdb46SRobert Mustacchi         }
2200*4d9fdb46SRobert Mustacchi     } /* ASSERT else impossible */
2201*4d9fdb46SRobert Mustacchi     *ll_header_out = llhead;
2202*4d9fdb46SRobert Mustacchi     *listlen_out = llhead->ll_locdesc_count;
2203*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
2204*4d9fdb46SRobert Mustacchi }
2205*4d9fdb46SRobert Mustacchi 
2206*4d9fdb46SRobert Mustacchi /*  An interface giving us no cu context!
2207*4d9fdb46SRobert Mustacchi     This is not going to be quite right. */
2208*4d9fdb46SRobert Mustacchi int
dwarf_loclist_from_expr_c(Dwarf_Debug dbg,Dwarf_Ptr expression_in,Dwarf_Unsigned expression_length,Dwarf_Half address_size,Dwarf_Half offset_size,Dwarf_Small dwarf_version,Dwarf_Loc_Head_c * loc_head,Dwarf_Unsigned * listlen,Dwarf_Error * error)2209*4d9fdb46SRobert Mustacchi dwarf_loclist_from_expr_c(Dwarf_Debug dbg,
2210*4d9fdb46SRobert Mustacchi     Dwarf_Ptr expression_in,
2211*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned expression_length,
2212*4d9fdb46SRobert Mustacchi     Dwarf_Half address_size,
2213*4d9fdb46SRobert Mustacchi     Dwarf_Half offset_size,
2214*4d9fdb46SRobert Mustacchi     Dwarf_Small dwarf_version,
2215*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c *loc_head,
2216*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * listlen,
2217*4d9fdb46SRobert Mustacchi     Dwarf_Error * error)
2218*4d9fdb46SRobert Mustacchi {
2219*4d9fdb46SRobert Mustacchi     /* Dwarf_Block that describes a single location expression. */
2220*4d9fdb46SRobert Mustacchi     Dwarf_Block_c loc_block;
2221*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Head_c llhead = 0;
2222*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c llbuf = 0;
2223*4d9fdb46SRobert Mustacchi     int local_listlen = 1;
2224*4d9fdb46SRobert Mustacchi     Dwarf_Addr lowpc = 0;
2225*4d9fdb46SRobert Mustacchi     Dwarf_Addr highpc = MAX_ADDR;
2226*4d9fdb46SRobert Mustacchi     Dwarf_Small version_stamp = dwarf_version;
2227*4d9fdb46SRobert Mustacchi     int res = 0;
2228*4d9fdb46SRobert Mustacchi 
2229*4d9fdb46SRobert Mustacchi     llhead = (Dwarf_Loc_Head_c)_dwarf_get_alloc(dbg,
2230*4d9fdb46SRobert Mustacchi         DW_DLA_LOC_HEAD_C, 1);
2231*4d9fdb46SRobert Mustacchi     if (!llhead) {
2232*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2233*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2234*4d9fdb46SRobert Mustacchi     }
2235*4d9fdb46SRobert Mustacchi     memset(&loc_block,0,sizeof(loc_block));
2236*4d9fdb46SRobert Mustacchi     loc_block.bl_len = expression_length;
2237*4d9fdb46SRobert Mustacchi     loc_block.bl_data = expression_in;
2238*4d9fdb46SRobert Mustacchi     loc_block.bl_kind = DW_LKIND_expression; /* Not from loclist. */
2239*4d9fdb46SRobert Mustacchi     loc_block.bl_section_offset = 0; /* Fake. Not meaningful. */
2240*4d9fdb46SRobert Mustacchi     loc_block.bl_locdesc_offset = 0; /* Fake. Not meaningful. */
2241*4d9fdb46SRobert Mustacchi     llbuf = (Dwarf_Locdesc_c)
2242*4d9fdb46SRobert Mustacchi         _dwarf_get_alloc(dbg, DW_DLA_LOCDESC_C, local_listlen);
2243*4d9fdb46SRobert Mustacchi     if (!llbuf) {
2244*4d9fdb46SRobert Mustacchi         dwarf_loc_head_c_dealloc(llhead);
2245*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
2246*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2247*4d9fdb46SRobert Mustacchi     }
2248*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc = llbuf;
2249*4d9fdb46SRobert Mustacchi     llhead->ll_locdesc_count = local_listlen;
2250*4d9fdb46SRobert Mustacchi     llhead->ll_context = 0; /* Not available! */
2251*4d9fdb46SRobert Mustacchi     llhead->ll_dbg = dbg;
2252*4d9fdb46SRobert Mustacchi     llhead->ll_kind = DW_LKIND_expression;
2253*4d9fdb46SRobert Mustacchi 
2254*4d9fdb46SRobert Mustacchi     /*  An empty location description (block length 0)
2255*4d9fdb46SRobert Mustacchi         means the code generator emitted no variable,
2256*4d9fdb46SRobert Mustacchi         the variable was not generated,
2257*4d9fdb46SRobert Mustacchi         it was unused or perhaps never tested
2258*4d9fdb46SRobert Mustacchi         after being set. Dwarf2,
2259*4d9fdb46SRobert Mustacchi         section 2.4.1 In other words, it is not
2260*4d9fdb46SRobert Mustacchi         an error, and we don't
2261*4d9fdb46SRobert Mustacchi         test for block length 0 specially here.  */
2262*4d9fdb46SRobert Mustacchi 
2263*4d9fdb46SRobert Mustacchi     /* Fills in the locdesc and its operators list at index 0 */
2264*4d9fdb46SRobert Mustacchi     res = _dwarf_fill_in_locdesc_op_c(dbg,
2265*4d9fdb46SRobert Mustacchi         0,
2266*4d9fdb46SRobert Mustacchi         llhead,
2267*4d9fdb46SRobert Mustacchi         &loc_block,
2268*4d9fdb46SRobert Mustacchi         address_size,
2269*4d9fdb46SRobert Mustacchi         offset_size,
2270*4d9fdb46SRobert Mustacchi         version_stamp,
2271*4d9fdb46SRobert Mustacchi         lowpc,
2272*4d9fdb46SRobert Mustacchi         highpc,
2273*4d9fdb46SRobert Mustacchi         DW_LKIND_expression,
2274*4d9fdb46SRobert Mustacchi         error);
2275*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
2276*4d9fdb46SRobert Mustacchi         /* low level error already set: let it be passed back */
2277*4d9fdb46SRobert Mustacchi         dwarf_loc_head_c_dealloc(llhead);
2278*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2279*4d9fdb46SRobert Mustacchi     }
2280*4d9fdb46SRobert Mustacchi     *loc_head = llhead;
2281*4d9fdb46SRobert Mustacchi     *listlen = local_listlen;
2282*4d9fdb46SRobert Mustacchi     return (DW_DLV_OK);
2283*4d9fdb46SRobert Mustacchi }
2284*4d9fdb46SRobert Mustacchi 
2285*4d9fdb46SRobert Mustacchi 
2286*4d9fdb46SRobert Mustacchi /*  New June 2020. */
2287*4d9fdb46SRobert Mustacchi int
dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c loclist_head,Dwarf_Unsigned index,Dwarf_Small * lle_value_out,Dwarf_Unsigned * rawval1,Dwarf_Unsigned * rawval2,Dwarf_Bool * debug_addr_unavailable,Dwarf_Addr * lowpc_out,Dwarf_Addr * hipc_out,Dwarf_Unsigned * loclist_expr_op_count_out,Dwarf_Locdesc_c * locdesc_entry_out,Dwarf_Small * loclist_source_out,Dwarf_Unsigned * expression_offset_out,Dwarf_Unsigned * locdesc_offset_out,Dwarf_Error * error)2288*4d9fdb46SRobert Mustacchi dwarf_get_locdesc_entry_d(Dwarf_Loc_Head_c loclist_head,
2289*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned   index,
2290*4d9fdb46SRobert Mustacchi    Dwarf_Small    * lle_value_out,
2291*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned * rawval1,
2292*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned * rawval2,
2293*4d9fdb46SRobert Mustacchi    Dwarf_Bool     * debug_addr_unavailable,
2294*4d9fdb46SRobert Mustacchi    Dwarf_Addr     * lowpc_out, /* 'cooked' value */
2295*4d9fdb46SRobert Mustacchi    Dwarf_Addr     * hipc_out, /* 'cooked' value */
2296*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned * loclist_expr_op_count_out,
2297*4d9fdb46SRobert Mustacchi    /* Returns pointer to the specific locdesc of the index; */
2298*4d9fdb46SRobert Mustacchi    Dwarf_Locdesc_c* locdesc_entry_out,
2299*4d9fdb46SRobert Mustacchi    Dwarf_Small    * loclist_source_out, /* 0,1, or 2 */
2300*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned * expression_offset_out,
2301*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned * locdesc_offset_out,
2302*4d9fdb46SRobert Mustacchi    Dwarf_Error    * error)
2303*4d9fdb46SRobert Mustacchi {
2304*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c descs_base =  0;
2305*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c desc =  0;
2306*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned desc_count = 0;
2307*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg;
2308*4d9fdb46SRobert Mustacchi 
2309*4d9fdb46SRobert Mustacchi     desc_count = loclist_head->ll_locdesc_count;
2310*4d9fdb46SRobert Mustacchi     descs_base  = loclist_head->ll_locdesc;
2311*4d9fdb46SRobert Mustacchi     dbg = loclist_head->ll_dbg;
2312*4d9fdb46SRobert Mustacchi     if (index >= desc_count) {
2313*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
2314*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2315*4d9fdb46SRobert Mustacchi     }
2316*4d9fdb46SRobert Mustacchi     desc = descs_base + index;
2317*4d9fdb46SRobert Mustacchi     *lle_value_out = desc->ld_lle_value;
2318*4d9fdb46SRobert Mustacchi     *rawval1 = desc->ld_rawlow;
2319*4d9fdb46SRobert Mustacchi     *rawval2 = desc->ld_rawhigh;
2320*4d9fdb46SRobert Mustacchi     *lowpc_out = desc->ld_lopc;
2321*4d9fdb46SRobert Mustacchi     *hipc_out = desc->ld_highpc;
2322*4d9fdb46SRobert Mustacchi     *debug_addr_unavailable = desc->ld_index_failed;
2323*4d9fdb46SRobert Mustacchi     *loclist_expr_op_count_out = desc->ld_cents;
2324*4d9fdb46SRobert Mustacchi     *locdesc_entry_out = desc;
2325*4d9fdb46SRobert Mustacchi     *loclist_source_out = desc->ld_kind;
2326*4d9fdb46SRobert Mustacchi     *expression_offset_out = desc->ld_section_offset;
2327*4d9fdb46SRobert Mustacchi     *locdesc_offset_out = desc->ld_locdesc_offset;
2328*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
2329*4d9fdb46SRobert Mustacchi }
2330*4d9fdb46SRobert Mustacchi int
dwarf_get_locdesc_entry_c(Dwarf_Loc_Head_c loclist_head,Dwarf_Unsigned index,Dwarf_Small * lle_value_out,Dwarf_Addr * lowpc_out,Dwarf_Addr * hipc_out,Dwarf_Unsigned * loclist_count_out,Dwarf_Locdesc_c * locdesc_entry_out,Dwarf_Small * loclist_source_out,Dwarf_Unsigned * expression_offset_out,Dwarf_Unsigned * locdesc_offset_out,Dwarf_Error * error)2331*4d9fdb46SRobert Mustacchi dwarf_get_locdesc_entry_c(Dwarf_Loc_Head_c loclist_head,
2332*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   index,
2333*4d9fdb46SRobert Mustacchi     Dwarf_Small    * lle_value_out,
2334*4d9fdb46SRobert Mustacchi     Dwarf_Addr     * lowpc_out,
2335*4d9fdb46SRobert Mustacchi     Dwarf_Addr     * hipc_out,
2336*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * loclist_count_out,
2337*4d9fdb46SRobert Mustacchi 
2338*4d9fdb46SRobert Mustacchi     /* Returns pointer to the specific locdesc of the index; */
2339*4d9fdb46SRobert Mustacchi     Dwarf_Locdesc_c* locdesc_entry_out,
2340*4d9fdb46SRobert Mustacchi     Dwarf_Small    * loclist_source_out, /* 0,1, or 2 */
2341*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * expression_offset_out,
2342*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * locdesc_offset_out,
2343*4d9fdb46SRobert Mustacchi     Dwarf_Error    * error)
2344*4d9fdb46SRobert Mustacchi {
2345*4d9fdb46SRobert Mustacchi     int res = 0;
2346*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned cookedlow = 0;
2347*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned cookedhigh = 0;
2348*4d9fdb46SRobert Mustacchi     Dwarf_Bool debug_addr_unavailable = FALSE;
2349*4d9fdb46SRobert Mustacchi 
2350*4d9fdb46SRobert Mustacchi     res = dwarf_get_locdesc_entry_d(loclist_head,
2351*4d9fdb46SRobert Mustacchi         index,lle_value_out,
2352*4d9fdb46SRobert Mustacchi         lowpc_out,hipc_out,
2353*4d9fdb46SRobert Mustacchi         &debug_addr_unavailable,
2354*4d9fdb46SRobert Mustacchi         &cookedlow,&cookedhigh,
2355*4d9fdb46SRobert Mustacchi         loclist_count_out,
2356*4d9fdb46SRobert Mustacchi         locdesc_entry_out,
2357*4d9fdb46SRobert Mustacchi         loclist_source_out,
2358*4d9fdb46SRobert Mustacchi         expression_offset_out,
2359*4d9fdb46SRobert Mustacchi         locdesc_offset_out,
2360*4d9fdb46SRobert Mustacchi         error);
2361*4d9fdb46SRobert Mustacchi     return res;
2362*4d9fdb46SRobert Mustacchi }
2363*4d9fdb46SRobert Mustacchi 
2364*4d9fdb46SRobert Mustacchi 
2365*4d9fdb46SRobert Mustacchi int
dwarf_get_location_op_value_d(Dwarf_Locdesc_c locdesc,Dwarf_Unsigned index,Dwarf_Small * atom_out,Dwarf_Unsigned * operand1,Dwarf_Unsigned * operand2,Dwarf_Unsigned * operand3,Dwarf_Unsigned * rawop1,Dwarf_Unsigned * rawop2,Dwarf_Unsigned * rawop3,Dwarf_Unsigned * offset_for_branch,Dwarf_Error * error)2366*4d9fdb46SRobert Mustacchi dwarf_get_location_op_value_d(Dwarf_Locdesc_c locdesc,
2367*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   index,
2368*4d9fdb46SRobert Mustacchi     Dwarf_Small    * atom_out,
2369*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand1,
2370*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand2,
2371*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand3,
2372*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * rawop1,
2373*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * rawop2,
2374*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * rawop3,
2375*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * offset_for_branch,
2376*4d9fdb46SRobert Mustacchi     Dwarf_Error*     error)
2377*4d9fdb46SRobert Mustacchi {
2378*4d9fdb46SRobert Mustacchi     Dwarf_Loc_Expr_Op op = 0;
2379*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned max = locdesc->ld_cents;
2380*4d9fdb46SRobert Mustacchi 
2381*4d9fdb46SRobert Mustacchi     if(index >= max) {
2382*4d9fdb46SRobert Mustacchi         Dwarf_Debug dbg = locdesc->ld_loclist_head->ll_dbg;
2383*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_LOCLIST_INDEX_ERROR);
2384*4d9fdb46SRobert Mustacchi         return (DW_DLV_ERROR);
2385*4d9fdb46SRobert Mustacchi     }
2386*4d9fdb46SRobert Mustacchi     op = locdesc->ld_s + index;
2387*4d9fdb46SRobert Mustacchi     *atom_out = op->lr_atom;
2388*4d9fdb46SRobert Mustacchi     *operand1 = op->lr_number;
2389*4d9fdb46SRobert Mustacchi     *operand2 = op->lr_number2;
2390*4d9fdb46SRobert Mustacchi     *operand3 = op->lr_number3;
2391*4d9fdb46SRobert Mustacchi     *rawop1 = op->lr_raw1;
2392*4d9fdb46SRobert Mustacchi     *rawop2 = op->lr_raw2;
2393*4d9fdb46SRobert Mustacchi     *rawop3 = op->lr_raw3;
2394*4d9fdb46SRobert Mustacchi     *offset_for_branch = op->lr_offset;
2395*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
2396*4d9fdb46SRobert Mustacchi }
2397*4d9fdb46SRobert Mustacchi 
2398*4d9fdb46SRobert Mustacchi 
2399*4d9fdb46SRobert Mustacchi int
dwarf_get_location_op_value_c(Dwarf_Locdesc_c locdesc,Dwarf_Unsigned index,Dwarf_Small * atom_out,Dwarf_Unsigned * operand1,Dwarf_Unsigned * operand2,Dwarf_Unsigned * operand3,Dwarf_Unsigned * offset_for_branch,Dwarf_Error * error)2400*4d9fdb46SRobert Mustacchi dwarf_get_location_op_value_c(Dwarf_Locdesc_c locdesc,
2401*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   index,
2402*4d9fdb46SRobert Mustacchi     Dwarf_Small    * atom_out,
2403*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand1,
2404*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand2,
2405*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * operand3,
2406*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * offset_for_branch,
2407*4d9fdb46SRobert Mustacchi     Dwarf_Error*     error)
2408*4d9fdb46SRobert Mustacchi {
2409*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned raw1 = 0;
2410*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned raw2 = 0;
2411*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned raw3 = 0;
2412*4d9fdb46SRobert Mustacchi     int res = 0;
2413*4d9fdb46SRobert Mustacchi 
2414*4d9fdb46SRobert Mustacchi     res = dwarf_get_location_op_value_d(locdesc,
2415*4d9fdb46SRobert Mustacchi         index,atom_out,
2416*4d9fdb46SRobert Mustacchi         operand1,operand2,operand3,
2417*4d9fdb46SRobert Mustacchi         &raw1,&raw2,&raw3,
2418*4d9fdb46SRobert Mustacchi         offset_for_branch,
2419*4d9fdb46SRobert Mustacchi         error);
2420*4d9fdb46SRobert Mustacchi     return res;
2421*4d9fdb46SRobert Mustacchi }
2422*4d9fdb46SRobert Mustacchi 
2423*4d9fdb46SRobert Mustacchi void
dwarf_loc_head_c_dealloc(Dwarf_Loc_Head_c loclist_head)2424*4d9fdb46SRobert Mustacchi dwarf_loc_head_c_dealloc(Dwarf_Loc_Head_c loclist_head)
2425*4d9fdb46SRobert Mustacchi {
2426*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg = loclist_head->ll_dbg;
2427*4d9fdb46SRobert Mustacchi     _dwarf_free_loclists_head(loclist_head);
2428*4d9fdb46SRobert Mustacchi     dwarf_dealloc(dbg,loclist_head,DW_DLA_LOC_HEAD_C);
2429*4d9fdb46SRobert Mustacchi }
2430*4d9fdb46SRobert Mustacchi /* ============== End of the October 2015 interfaces. */
2431