Debian Codegraph @

src/lib/libdwarf/dwarf_locationop_read.c

raw
1 /*
2 Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
3 Portions Copyright (C) 2007-2018 David Anderson. All Rights Reserved.
4 Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved.
5
6 This program is free software; you can redistribute it
7 and/or modify it under the terms of version 2.1 of the
8 GNU Lesser General Public License as published by the Free
9 Software Foundation.
10
11 This program is distributed in the hope that it would be
12 useful, but WITHOUT ANY WARRANTY; without even the implied
13 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE.
15
16 Further, this software is distributed without any warranty
17 that it is free of the rightful claim of any third person
18 regarding infringement or the like. Any license provided
19 herein, whether implied or otherwise, applies only to this
20 software file. Patent licenses, if any, provided herein
21 do not apply to combinations of this program with other
22 software, or any other product whatsoever.
23
24 You should have received a copy of the GNU Lesser General
25 Public License along with this program; if not, write the
26 Free Software Foundation, Inc., 51 Franklin Street - Fifth
27 Floor, Boston MA 02110-1301, USA.
28
29 */
30
31 #include <config.h>
32
33 #include <string.h> /* memcpy() memset() */
34
35 #if defined(_WIN32) && defined(HAVE_STDAFX_H)
36 #include "stdafx.h"
37 #endif /* HAVE_STDAFX_H */
38
39 #ifdef HAVE_STDINT_H
40 #include <stdint.h> /* uintptr_t */
41 #endif /* HAVE_STDINT_H */
42
43 #include "dwarf.h"
44 #include "libdwarf.h"
45 #include "libdwarf_private.h"
46 #include "dwarf_base_types.h"
47 #include "dwarf_opaque.h"
48 #include "dwarf_alloc.h"
49 #include "dwarf_error.h"
50 #include "dwarf_util.h"
51 #include "dwarf_loc.h"
52 #include "dwarf_string.h"
53
54 /* Richard Henderson, on DW_OP_GNU_encoded_addr:
55 The operand is an absolute address.
56 The first byte of the value is an encoding length:
57 0 2 4 or 8.
58 If zero it means the following is address-size.
59 The address then follows immediately for
60 that number of bytes. */
61 static int
62 read_encoded_addr(Dwarf_Small *loc_ptr,
63 Dwarf_Debug dbg,
64 Dwarf_Small *section_end_ptr,
65 Dwarf_Half address_size,
66 Dwarf_Unsigned * val_out,
67 int * len_out,
68 Dwarf_Error *error)
69 {
70 int len = 0;
71 Dwarf_Half op = *loc_ptr;
72 Dwarf_Unsigned operand = 0;
73
74 len++;
75 if (!op) {
76 op = address_size;
77 }
78 switch (op) {
79 case 1:
80 *val_out = *loc_ptr;
81 len++;
82 break;
83
84 case 2:
85 READ_UNALIGNED_CK(dbg, operand, Dwarf_Unsigned, loc_ptr, 2,
86 error,section_end_ptr);
87 *val_out = operand;
88 len +=2;
89 break;
90 case 4:
91 READ_UNALIGNED_CK(dbg, operand, Dwarf_Unsigned, loc_ptr, 4,
92 error,section_end_ptr);
93 *val_out = operand;
94 len +=4;
95 break;
96 case 8:
97 READ_UNALIGNED_CK(dbg, operand, Dwarf_Unsigned, loc_ptr, 8,
98 error,section_end_ptr);
99 *val_out = operand;
100 len +=8;
101 break;
102 default:
103 /* We do not know how much to read. */
104 _dwarf_error(dbg, error, DW_DLE_GNU_OPCODE_ERROR);
105 return DW_DLV_ERROR;
106 };
107 *len_out = len;
108 return DW_DLV_OK;
109 }
110
111 /* Return DW_DLV_NO_ENTRY when at the end of
112 the ops for this block (a single Dwarf_Loccesc
113 and multiple Dwarf_Locs will eventually result
114 from calling this till DW_DLV_NO_ENTRY).
115
116 All op reader code should call this to
117 extract operator fields. For any
118 DWARF version.
119 */
120 int
121 _dwarf_read_loc_expr_op(Dwarf_Debug dbg,
122 Dwarf_Block_c * loc_block,
123 /* Caller: Start numbering at 0. */
124 Dwarf_Signed opnumber,
125
126 /* 2 for DWARF 2 etc. */
127 Dwarf_Half version_stamp,
128 Dwarf_Half offset_size, /* 4 or 8 */
129 Dwarf_Half address_size, /* 2,4, 8 */
130 Dwarf_Signed startoffset_in, /* offset in block,
131 not section offset */
132 Dwarf_Small *section_end,
133
134 /* nextoffset_out so caller knows next entry startoffset */
135 Dwarf_Unsigned *nextoffset_out,
136
137 /* The values picked up. */
138 Dwarf_Loc_Expr_Op curr_loc,
139 Dwarf_Error * error)
140 {
141 Dwarf_Small *loc_ptr = 0;
142 Dwarf_Unsigned loc_len = 0;
143 Dwarf_Unsigned offset = startoffset_in;
144 Dwarf_Unsigned operand1 = 0;
145 Dwarf_Unsigned operand2 = 0;
146 Dwarf_Unsigned operand3 = 0;
147 Dwarf_Small atom = 0;
148 Dwarf_Unsigned leb128_length = 0;
149
150 if (offset > loc_block->bl_len) {
151 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
152 return DW_DLV_ERROR;
153 }
154 loc_len = loc_block->bl_len;
155 if (offset == loc_len) {
156 return DW_DLV_NO_ENTRY;
157 }
158
159 loc_ptr = (Dwarf_Small*)loc_block->bl_data + offset;
160 if ((loc_ptr+1) > section_end) {
161 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
162 return DW_DLV_ERROR;
163 }
164 memset(curr_loc,0,sizeof(*curr_loc));
165
166 curr_loc->lr_opnumber = opnumber;
167 curr_loc->lr_offset = offset;
168
169 /* loc_ptr is ok to deref, see loc_ptr+1 test just above. */
170 atom = *(Dwarf_Small *) loc_ptr;
171 loc_ptr++;
172 offset++;
173 curr_loc->lr_atom = atom;
174 switch (atom) {
175 case DW_OP_reg0:
176 case DW_OP_reg1:
177 case DW_OP_reg2:
178 case DW_OP_reg3:
179 case DW_OP_reg4:
180 case DW_OP_reg5:
181 case DW_OP_reg6:
182 case DW_OP_reg7:
183 case DW_OP_reg8:
184 case DW_OP_reg9:
185 case DW_OP_reg10:
186 case DW_OP_reg11:
187 case DW_OP_reg12:
188 case DW_OP_reg13:
189 case DW_OP_reg14:
190 case DW_OP_reg15:
191 case DW_OP_reg16:
192 case DW_OP_reg17:
193 case DW_OP_reg18:
194 case DW_OP_reg19:
195 case DW_OP_reg20:
196 case DW_OP_reg21:
197 case DW_OP_reg22:
198 case DW_OP_reg23:
199 case DW_OP_reg24:
200 case DW_OP_reg25:
201 case DW_OP_reg26:
202 case DW_OP_reg27:
203 case DW_OP_reg28:
204 case DW_OP_reg29:
205 case DW_OP_reg30:
206 case DW_OP_reg31:
207 break;
208
209 case DW_OP_regx:
210 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
211 dbg,error,section_end);
212 offset = offset + leb128_length;
213 break;
214
215 case DW_OP_lit0:
216 case DW_OP_lit1:
217 case DW_OP_lit2:
218 case DW_OP_lit3:
219 case DW_OP_lit4:
220 case DW_OP_lit5:
221 case DW_OP_lit6:
222 case DW_OP_lit7:
223 case DW_OP_lit8:
224 case DW_OP_lit9:
225 case DW_OP_lit10:
226 case DW_OP_lit11:
227 case DW_OP_lit12:
228 case DW_OP_lit13:
229 case DW_OP_lit14:
230 case DW_OP_lit15:
231 case DW_OP_lit16:
232 case DW_OP_lit17:
233 case DW_OP_lit18:
234 case DW_OP_lit19:
235 case DW_OP_lit20:
236 case DW_OP_lit21:
237 case DW_OP_lit22:
238 case DW_OP_lit23:
239 case DW_OP_lit24:
240 case DW_OP_lit25:
241 case DW_OP_lit26:
242 case DW_OP_lit27:
243 case DW_OP_lit28:
244 case DW_OP_lit29:
245 case DW_OP_lit30:
246 case DW_OP_lit31:
247 operand1 = atom - DW_OP_lit0;
248 break;
249
250 case DW_OP_addr:
251 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned,
252 loc_ptr, address_size,
253 error,section_end);
254 loc_ptr += address_size;
255 offset += address_size;
256 break;
257
258 case DW_OP_const1u:
259 if (loc_ptr >= section_end) {
260 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
261 return DW_DLV_ERROR;
262 }
263 operand1 = *(Dwarf_Small *) loc_ptr;
264 loc_ptr = loc_ptr + 1;
265 if (loc_ptr > section_end) {
266 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
267 return DW_DLV_ERROR;
268 }
269 offset = offset + 1;
270 break;
271
272 case DW_OP_const1s:
273 if (loc_ptr >= section_end) {
274 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
275 return DW_DLV_ERROR;
276 }
277 operand1 = *(Dwarf_Sbyte *) loc_ptr;
278 SIGN_EXTEND(operand1,1);
279 loc_ptr = loc_ptr + 1;
280 if (loc_ptr > section_end) {
281 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
282 return DW_DLV_ERROR;
283 }
284 offset = offset + 1;
285 break;
286
287 case DW_OP_const2u:
288 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2,
289 error,section_end);
290 loc_ptr = loc_ptr + 2;
291 offset = offset + 2;
292 break;
293
294 case DW_OP_const2s:
295 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2,
296 error, section_end);
297 SIGN_EXTEND(operand1,2);
298 loc_ptr = loc_ptr + 2;
299 offset = offset + 2;
300 break;
301
302 case DW_OP_const4u:
303 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4,
304 error, section_end);
305 loc_ptr = loc_ptr + 4;
306 offset = offset + 4;
307 break;
308
309 case DW_OP_const4s:
310 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4,
311 error, section_end);
312 SIGN_EXTEND(operand1,4);
313 loc_ptr = loc_ptr + 4;
314 offset = offset + 4;
315 break;
316
317 case DW_OP_const8u:
318 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8,
319 error, section_end);
320 loc_ptr = loc_ptr + 8;
321 offset = offset + 8;
322 break;
323
324 case DW_OP_const8s:
325 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 8,
326 error, section_end);
327 loc_ptr = loc_ptr + 8;
328 offset = offset + 8;
329 break;
330
331 case DW_OP_constu:
332 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
333 dbg,error,section_end);
334 offset = offset + leb128_length;
335 break;
336
337 case DW_OP_consts:
338 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand1,leb128_length,
339 dbg,error,section_end);
340 offset = offset + leb128_length;
341 break;
342
343 case DW_OP_fbreg:
344 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand1,leb128_length,
345 dbg,error,section_end);
346 offset = offset + leb128_length;
347 break;
348
349 case DW_OP_breg0:
350 case DW_OP_breg1:
351 case DW_OP_breg2:
352 case DW_OP_breg3:
353 case DW_OP_breg4:
354 case DW_OP_breg5:
355 case DW_OP_breg6:
356 case DW_OP_breg7:
357 case DW_OP_breg8:
358 case DW_OP_breg9:
359 case DW_OP_breg10:
360 case DW_OP_breg11:
361 case DW_OP_breg12:
362 case DW_OP_breg13:
363 case DW_OP_breg14:
364 case DW_OP_breg15:
365 case DW_OP_breg16:
366 case DW_OP_breg17:
367 case DW_OP_breg18:
368 case DW_OP_breg19:
369 case DW_OP_breg20:
370 case DW_OP_breg21:
371 case DW_OP_breg22:
372 case DW_OP_breg23:
373 case DW_OP_breg24:
374 case DW_OP_breg25:
375 case DW_OP_breg26:
376 case DW_OP_breg27:
377 case DW_OP_breg28:
378 case DW_OP_breg29:
379 case DW_OP_breg30:
380 case DW_OP_breg31:
381 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand1,leb128_length,
382 dbg,error,section_end);
383 offset = offset + leb128_length;
384 break;
385
386 case DW_OP_bregx:
387 /* uleb reg num followed by sleb offset */
388 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
389 dbg,error,section_end);
390 offset = offset + leb128_length;
391
392 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand2,leb128_length,
393 dbg,error,section_end);
394 offset = offset + leb128_length;
395 break;
396
397 case DW_OP_dup:
398 case DW_OP_drop:
399 break;
400
401 case DW_OP_pick:
402 if (loc_ptr >= section_end) {
403 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
404 return DW_DLV_ERROR;
405 }
406 operand1 = *(Dwarf_Small *) loc_ptr;
407 loc_ptr = loc_ptr + 1;
408 if (loc_ptr > section_end) {
409 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
410 return DW_DLV_ERROR;
411 }
412 offset = offset + 1;
413 break;
414
415 case DW_OP_over:
416 case DW_OP_swap:
417 case DW_OP_rot:
418 case DW_OP_deref:
419 break;
420
421 case DW_OP_deref_size:
422 if (loc_ptr >= section_end) {
423 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
424 return DW_DLV_ERROR;
425 }
426 operand1 = *(Dwarf_Small *) loc_ptr;
427 loc_ptr = loc_ptr + 1;
428 if (loc_ptr > section_end) {
429 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
430 return DW_DLV_ERROR;
431 }
432 offset = offset + 1;
433 break;
434
435 case DW_OP_xderef:
436 break;
437
438 case DW_OP_xderef_type: /* DWARF5 */
439 if (loc_ptr >= section_end) {
440 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
441 return DW_DLV_ERROR;
442 }
443 operand1 = *(Dwarf_Small *) loc_ptr;
444 loc_ptr = loc_ptr + 1;
445 if (loc_ptr > section_end) {
446 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
447 return DW_DLV_ERROR;
448 }
449 offset = offset + 1;
450 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand2,leb128_length,
451 dbg,error,section_end);
452 offset = offset + leb128_length;
453
454 break;
455
456 case DW_OP_xderef_size:
457 if (loc_ptr >= section_end) {
458 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
459 return DW_DLV_ERROR;
460 }
461 operand1 = *(Dwarf_Small *) loc_ptr;
462 loc_ptr = loc_ptr + 1;
463 if (loc_ptr > section_end) {
464 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
465 return DW_DLV_ERROR;
466 }
467 offset = offset + 1;
468 break;
469
470 case DW_OP_abs:
471 case DW_OP_and:
472 case DW_OP_div:
473 case DW_OP_minus:
474 case DW_OP_mod:
475 case DW_OP_mul:
476 case DW_OP_neg:
477 case DW_OP_not:
478 case DW_OP_or:
479 case DW_OP_plus:
480 break;
481
482 case DW_OP_plus_uconst:
483 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
484 dbg,error,section_end);
485 offset = offset + leb128_length;
486 break;
487
488 case DW_OP_shl:
489 case DW_OP_shr:
490 case DW_OP_shra:
491 case DW_OP_xor:
492 break;
493
494 case DW_OP_le:
495 case DW_OP_ge:
496 case DW_OP_eq:
497 case DW_OP_lt:
498 case DW_OP_gt:
499 case DW_OP_ne:
500 break;
501
502 case DW_OP_skip:
503 case DW_OP_bra:
504 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2,
505 error,section_end);
506 SIGN_EXTEND(operand1,2);
507 loc_ptr = loc_ptr + 2;
508 offset = offset + 2;
509 break;
510
511 case DW_OP_piece:
512 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
513 dbg,error,section_end);
514 offset = offset + leb128_length;
515 break;
516 case DW_OP_nop:
517 break;
518 case DW_OP_push_object_address: /* DWARF3 */
519 break;
520 case DW_OP_call2: /* DWARF3 */
521 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 2,
522 error,section_end);
523 loc_ptr = loc_ptr + 2;
524 offset = offset + 2;
525 break;
526
527 case DW_OP_call4: /* DWARF3 */
528 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4,
529 error,section_end);
530 loc_ptr = loc_ptr + 4;
531 offset = offset + 4;
532 break;
533 case DW_OP_call_ref: /* DWARF3 */
534 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr,
535 offset_size,
536 error,section_end);
537 loc_ptr = loc_ptr + offset_size;
538 offset = offset + offset_size;
539 break;
540
541 case DW_OP_form_tls_address: /* DWARF3f */
542 break;
543 case DW_OP_call_frame_cfa: /* DWARF3f */
544 break;
545 case DW_OP_bit_piece: /* DWARF3f */
546 /* uleb size in bits followed by uleb offset in bits */
547 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
548 dbg,error,section_end);
549 offset = offset + leb128_length;
550
551 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand2,leb128_length,
552 dbg,error,section_end);
553 offset = offset + leb128_length;
554 break;
555
556 /* The operator means: push the currently computed
557 (by the operations encountered so far in this
558 expression) onto the expression stack as the offset
559 in thread-local-storage of the variable. */
560 case DW_OP_GNU_push_tls_address: /* 0xe0 */
561 /* Believed to have no operands. */
562 /* Unimplemented in gdb 7.5.1 ? */
563 break;
564 case DW_OP_deref_type: /* DWARF5 */
565 case DW_OP_GNU_deref_type: /* 0xf6 */
566 if (loc_ptr >= section_end) {
567 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
568 return DW_DLV_ERROR;
569 }
570 operand1 = *(Dwarf_Small *) loc_ptr;
571 loc_ptr = loc_ptr + 1;
572 if (loc_ptr > section_end) {
573 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
574 return DW_DLV_ERROR;
575 }
576 offset = offset + 1;
577
578 /* die offset (uleb128). */
579 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand2,leb128_length,
580 dbg,error,section_end);
581 offset = offset + leb128_length;
582 break;
583
584 case DW_OP_implicit_value: /* DWARF4 0xa0 */
585 /* uleb length of value bytes followed by that
586 number of bytes of the value. */
587 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
588 dbg,error,section_end);
589 offset = offset + leb128_length;
590
591 /* Second operand is block of 'operand1' bytes of stuff. */
592 /* This using the second operand as a pointer
593 is quite ugly. */
594 /* This gets an ugly compiler warning. Sorry. */
595 operand2 = (Dwarf_Unsigned)(uintptr_t)loc_ptr;
596 offset = offset + operand1;
597 loc_ptr = loc_ptr + operand1;
598 if (loc_ptr > section_end) {
599 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
600 return DW_DLV_ERROR;
601 }
602 break;
603 case DW_OP_stack_value: /* DWARF4 */
604 break;
605 case DW_OP_GNU_uninit: /* 0xf0 */
606 /* Unimplemented in gdb 7.5.1 */
607 /* Carolyn Tice: Follows a DW_OP_reg or DW_OP_regx
608 and marks the reg as being uninitialized. */
609 break;
610 case DW_OP_GNU_encoded_addr: { /* 0xf1 */
611 /* Richard Henderson: The operand is an absolute
612 address. The first byte of the value
613 is an encoding length: 0 2 4 or 8. If zero
614 it means the following is address-size.
615 The address then follows immediately for
616 that number of bytes. */
617 int length = 0;
618 int reares = 0;
619
620 if (loc_ptr >= section_end) {
621 _dwarf_error_string(dbg,error,
622 DW_DLE_LOCEXPR_OFF_SECTION_END,
623 "DW_DLE_LOCEXPR_OFF_SECTION_END "
624 "at DW_OP_GNU_encoded_addr. "
625 "Corrupt DWARF");
626 return DW_DLV_ERROR;
627 }
628 reares = read_encoded_addr(loc_ptr,dbg,
629 section_end,
630 address_size,
631 &operand1, &length,error);
632 if (reares != DW_DLV_OK) {
633 return reares;
634 }
635 loc_ptr += length;
636 if (loc_ptr > section_end) {
637 _dwarf_error(dbg,error,
638 DW_DLE_LOCEXPR_OFF_SECTION_END);
639 return DW_DLV_ERROR;
640 }
641 offset += length;
642 }
643 break;
644 case DW_OP_implicit_pointer: /* DWARF5 */
645 case DW_OP_GNU_implicit_pointer:{ /* 0xf2 */
646 /* Jakub Jelinek: The value is an optimized-out
647 pointer value. Represented as
648 an offset_size DIE offset
649 (a simple unsigned integer) in DWARF3,4
650 followed by a signed leb128 offset.
651 For DWARF2, it is actually pointer size
652 (address size).
653 The offset is global a section offset, not cu-relative.
654 Relocation to a different object file is up to
655 the user, per DWARF5 Page 41.
656 http://www.dwarfstd.org/ShowIssue.php?issue=100831.1 */
657 Dwarf_Half iplen = offset_size;
658 if (version_stamp == DW_CU_VERSION2 /* 2 */ ) {
659 iplen = address_size;
660 }
661 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr,
662 iplen,error,section_end);
663 loc_ptr = loc_ptr + iplen;
664 if (loc_ptr > section_end) {
665 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
666 return DW_DLV_ERROR;
667 }
668 offset = offset + iplen;
669
670 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand2,leb128_length,
671 dbg,error,section_end);
672 offset = offset + leb128_length;
673 }
674
675 break;
676 case DW_OP_entry_value: /* DWARF5 */
677 case DW_OP_GNU_entry_value: /* 0xf3 */
678 /* Jakub Jelinek: A register reused really soon,
679 but the value is unchanged. So to represent
680 that value we have a uleb128 size followed
681 by a DWARF expression block that size.
682 http://www.dwarfstd.org/ShowIssue.php?issue=100909.1 */
683
684 /* uleb length of value bytes followed by that
685 number of bytes of the value. */
686 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
687 dbg,error,section_end);
688 offset = offset + leb128_length;
689
690 /* Second operand is block of 'operand1' bytes of stuff. */
691 /* This using the second operand as a pointer
692 is quite ugly. */
693 /* This gets an ugly compiler warning. Sorry. */
694 operand2 = (Dwarf_Unsigned)(uintptr_t)loc_ptr;
695 offset = offset + operand1;
696 loc_ptr = loc_ptr + operand1;
697 if (loc_ptr > section_end) {
698 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
699 return DW_DLV_ERROR;
700 }
701 break;
702 case DW_OP_const_type: /* DWARF5 */
703 case DW_OP_GNU_const_type: /* 0xf4 */
704 {
705 /* die offset as uleb. cu-relative */
706 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
707 dbg,error,section_end);
708 offset = offset + leb128_length;
709
710 if (loc_ptr >= section_end) {
711 _dwarf_error_string(dbg,error,
712 DW_DLE_LOCEXPR_OFF_SECTION_END,
713 "DW_DLE_LOCEXPR_OFF_SECTION_END: Error reading "
714 "DW_OP_const_type/DW_OP_GNU_const_type content");
715 return DW_DLV_ERROR;
716 }
717 /* Next byte is size of following data block. */
718 operand2 = *loc_ptr;
719 loc_ptr = loc_ptr + 1;
720 offset = offset + 1;
721
722 /* Operand 3 points to a value in the block of size
723 just gotten as operand2.
724 It must fit in a Dwarf_Unsigned.
725 Get the type from the die at operand1
726 (a CU relative offset). */
727 /* FIXME: We should do something very different than
728 what we do here! */
729 operand3 = (Dwarf_Unsigned)(uintptr_t)loc_ptr;
730 loc_ptr = loc_ptr + operand2;
731 if (loc_ptr > section_end) {
732 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
733 return DW_DLV_ERROR;
734 }
735 offset = offset + operand2;
736 }
737 break;
738
739 case DW_OP_regval_type: /* DWARF5 */
740 case DW_OP_GNU_regval_type: /* 0xf5 */
741 /* reg num uleb*/
742 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
743 dbg,error,section_end);
744 offset = offset + leb128_length;
745 /* cu die off uleb*/
746 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand2,leb128_length,
747 dbg,error,section_end);
748 offset = offset + leb128_length;
749 break;
750 case DW_OP_convert: /* DWARF5 */
751 case DW_OP_GNU_convert: /* 0xf7 */
752 case DW_OP_reinterpret: /* DWARF5 */
753 case DW_OP_GNU_reinterpret: /* 0xf9 */
754 /* die offset or zero */
755 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
756 dbg,error,section_end);
757 offset = offset + leb128_length;
758 break;
759 case DW_OP_GNU_parameter_ref : /* 0xfa */
760 /* 4 byte unsigned int */
761 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr, 4,
762 error,section_end);;
763 loc_ptr = loc_ptr + 4;
764 if (loc_ptr > section_end) {
765 _dwarf_error_string(dbg,error,
766 DW_DLE_LOCEXPR_OFF_SECTION_END,
767 "DW_DLE_LOCEXPR_OFF_SECTION_END: Error reading "
768 "DW_OP_GNU_parameter_ref.");
769 return DW_DLV_ERROR;
770 }
771 offset = offset + 4;
772 break;
773 case DW_OP_addrx : /* DWARF5 */
774 case DW_OP_GNU_addr_index : /* 0xfb DebugFission */
775 /* Index into .debug_addr. The value in .debug_addr
776 is an address. */
777 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
778 dbg,error,section_end);
779 offset = offset + leb128_length;
780 break;
781 case DW_OP_constx : /* DWARF5 */
782 case DW_OP_GNU_const_index : /* 0xfc DebugFission */
783 /* Index into .debug_addr. The value in .debug_addr
784 is a constant that fits in an address. */
785 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
786 dbg,error,section_end);
787 offset = offset + leb128_length;
788 break;
789 case DW_OP_GNU_variable_value: { /* 0xfd, 2017 By J Jelinek */
790 /* https://gcc.gnu.org/legacy-ml/gcc-patches/2017-02/
791 msg01499.html */
792 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr,
793 offset_size,error,section_end);
794 loc_ptr = loc_ptr + offset_size;
795 if (loc_ptr > section_end) {
796 _dwarf_error_string(dbg,error,
797 DW_DLE_LOCEXPR_OFF_SECTION_END,
798 "DW_DLE_LOCEXPR_OFF_SECTION_END: Error reading "
799 "DW_OP_GNU_variable_value.");
800 return DW_DLV_ERROR;
801 }
802 break;
803 }
804 /* See https://www.llvm.org/docs/
805 AMDGPUDwarfExtensionsForHeterogeneousDebugging.html */
806 case DW_OP_LLVM_form_aspace_address:
807 case DW_OP_LLVM_push_lane:
808 case DW_OP_LLVM_offset:
809 case DW_OP_LLVM_bit_offset:
810 case DW_OP_LLVM_undefined:
811 case DW_OP_LLVM_piece_end:
812 /* no operands on these */
813 break;
814 case DW_OP_LLVM_offset_uconst: /*uleb operand*/
815 case DW_OP_LLVM_call_frame_entry_reg: /*uleb operand*/
816 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
817 dbg,error,section_end);
818 offset = offset + leb128_length;
819 break;
820
821 case DW_OP_LLVM_aspace_implicit_pointer:
822 READ_UNALIGNED_CK(dbg, operand1, Dwarf_Unsigned, loc_ptr,
823 offset_size,error,section_end);
824 loc_ptr = loc_ptr + offset_size;
825 if (loc_ptr > section_end) {
826 _dwarf_error_string(dbg,error,
827 DW_DLE_LOCEXPR_OFF_SECTION_END,
828 "DW_DLE_LOCEXPR_OFF_SECTION_END: Error reading "
829 "DW_OP_LLVM_aspace_implicit_pointer.");
830 return DW_DLV_ERROR;
831 }
832
833 DECODE_LEB128_SWORD_LEN_CK(loc_ptr, operand2,leb128_length,
834 dbg,error,section_end);
835 offset = offset + leb128_length;
836 break;
837
838 case DW_OP_LLVM_aspace_bregx:
839 case DW_OP_LLVM_extend:
840 case DW_OP_LLVM_select_bit_piece:
841 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand1,leb128_length,
842 dbg,error,section_end);
843 offset = offset + leb128_length;
844
845 DECODE_LEB128_UWORD_LEN_CK(loc_ptr, operand2,leb128_length,
846 dbg,error,section_end);
847 offset = offset + leb128_length;
848 break;
849
850 default: {
851 dwarfstring m;
852 const char *atomname = 0;
853
854 /* This can happen if the offset_size or address_size
855 in the OP stream was incorrect for the object file.*/
856 dwarfstring_constructor(&m);
857 dwarfstring_append_printf_u(&m,
858 "ERROR: DW_DLE_LOC_EXPR_BAD as DW_OP atom "
859 "0x%x ",atom);
860 dwarfstring_append(&m, "(");
861 dwarf_get_OP_name(atom,&atomname);
862 dwarfstring_append(&m,(char *)(atomname?
863 atomname:"<no name>"));
864 dwarfstring_append(&m, ")");
865 dwarfstring_append(&m,"is unknown.");
866 _dwarf_error_string(dbg, error, DW_DLE_LOC_EXPR_BAD,
867 dwarfstring_string(&m));
868 dwarfstring_destructor(&m);
869 return DW_DLV_ERROR;
870 }
871 }
872 if (loc_ptr > section_end) {
873 _dwarf_error(dbg,error,DW_DLE_LOCEXPR_OFF_SECTION_END);
874 return DW_DLV_ERROR;
875 }
876 /* If offset == loc_len this would be normal end-of-expression. */
877 if (offset > loc_len) {
878 /* We stepped past the end of the expression.
879 This has to be a compiler bug.
880 Operators missing their values cannot be detected
881 as such except at the end of an expression (like this).
882 The results would be wrong if returned.
883 */
884 _dwarf_error(dbg, error, DW_DLE_LOC_BAD_TERMINATION);
885 return DW_DLV_ERROR;
886 }
887 curr_loc->lr_atom = atom;
888 curr_loc->lr_number = operand1;
889 curr_loc->lr_number2 = operand2;
890 /* lr_number 3 is a pointer to a value iff DW_OP_const or
891 DW_OP_GNU_const_type */
892 curr_loc->lr_number3 = operand3;
893 *nextoffset_out = offset;
894 return DW_DLV_OK;
895 }