1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "exceptions.h"
38 #include "dwarf2expr.h"
39 #include "dwarf2loc.h"
40 #include "dwarf2-frame.h"
42 #include "gdb_string.h"
43 #include "gdb_assert.h"
45 extern int dwarf2_always_disassemble
;
48 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
49 const gdb_byte
**start
, size_t *length
);
52 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
53 const gdb_byte
*data
, unsigned short size
,
54 struct dwarf2_per_cu_data
*per_cu
,
57 /* A function for dealing with location lists. Given a
58 symbol baton (BATON) and a pc value (PC), find the appropriate
59 location expression, set *LOCEXPR_LENGTH, and return a pointer
60 to the beginning of the expression. Returns NULL on failure.
62 For now, only return the first matching location expression; there
63 can be more than one in the list. */
66 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
67 size_t *locexpr_length
, CORE_ADDR pc
)
70 const gdb_byte
*loc_ptr
, *buf_end
;
72 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
73 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
74 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
75 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
76 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
77 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
78 /* Adjust base_address for relocatable objects. */
79 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
80 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
82 loc_ptr
= baton
->data
;
83 buf_end
= baton
->data
+ baton
->size
;
87 if (buf_end
- loc_ptr
< 2 * addr_size
)
88 error (_("dwarf2_find_location_expression: "
89 "Corrupted DWARF expression."));
92 low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
94 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
98 high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
100 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
101 loc_ptr
+= addr_size
;
103 /* A base-address-selection entry. */
104 if ((low
& base_mask
) == base_mask
)
106 base_address
= high
+ base_offset
;
110 /* An end-of-list entry. */
111 if (low
== 0 && high
== 0)
114 /* Otherwise, a location expression entry. */
116 high
+= base_address
;
118 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
121 if (pc
>= low
&& pc
< high
)
123 *locexpr_length
= length
;
131 /* This is the baton used when performing dwarf2 expression
133 struct dwarf_expr_baton
135 struct frame_info
*frame
;
136 struct dwarf2_per_cu_data
*per_cu
;
139 /* Helper functions for dwarf2_evaluate_loc_desc. */
141 /* Using the frame specified in BATON, return the value of register
142 REGNUM, treated as a pointer. */
144 dwarf_expr_read_reg (void *baton
, int dwarf_regnum
)
146 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
147 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
151 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
152 result
= address_from_register (builtin_type (gdbarch
)->builtin_data_ptr
,
153 regnum
, debaton
->frame
);
157 /* Read memory at ADDR (length LEN) into BUF. */
160 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
162 read_memory (addr
, buf
, len
);
165 /* Using the frame specified in BATON, find the location expression
166 describing the frame base. Return a pointer to it in START and
167 its length in LENGTH. */
169 dwarf_expr_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
171 /* FIXME: cagney/2003-03-26: This code should be using
172 get_frame_base_address(), and then implement a dwarf2 specific
174 struct symbol
*framefunc
;
175 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
177 /* Use block_linkage_function, which returns a real (not inlined)
178 function, instead of get_frame_function, which may return an
180 framefunc
= block_linkage_function (get_frame_block (debaton
->frame
, NULL
));
182 /* If we found a frame-relative symbol then it was certainly within
183 some function associated with a frame. If we can't find the frame,
184 something has gone wrong. */
185 gdb_assert (framefunc
!= NULL
);
187 dwarf_expr_frame_base_1 (framefunc
,
188 get_frame_address_in_block (debaton
->frame
),
193 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
194 const gdb_byte
**start
, size_t *length
)
196 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
198 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
200 struct dwarf2_loclist_baton
*symbaton
;
202 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
203 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
207 struct dwarf2_locexpr_baton
*symbaton
;
209 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
210 if (symbaton
!= NULL
)
212 *length
= symbaton
->size
;
213 *start
= symbaton
->data
;
220 error (_("Could not find the frame base for \"%s\"."),
221 SYMBOL_NATURAL_NAME (framefunc
));
224 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
225 the frame in BATON. */
228 dwarf_expr_frame_cfa (void *baton
)
230 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
232 return dwarf2_frame_cfa (debaton
->frame
);
235 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
236 the frame in BATON. */
239 dwarf_expr_frame_pc (void *baton
)
241 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
243 return get_frame_address_in_block (debaton
->frame
);
246 /* Using the objfile specified in BATON, find the address for the
247 current thread's thread-local storage with offset OFFSET. */
249 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
251 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
252 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
254 return target_translate_tls_address (objfile
, offset
);
257 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
258 current CU (as is PER_CU). State of the CTX is not affected by the
262 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, size_t die_offset
,
263 struct dwarf2_per_cu_data
*per_cu
,
264 CORE_ADDR (*get_frame_pc
) (void *baton
),
267 struct dwarf2_locexpr_baton block
;
269 block
= dwarf2_fetch_die_location_block (die_offset
, per_cu
,
270 get_frame_pc
, baton
);
272 /* DW_OP_call_ref is currently not supported. */
273 gdb_assert (block
.per_cu
== per_cu
);
275 dwarf_expr_eval (ctx
, block
.data
, block
.size
);
278 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
281 dwarf_expr_dwarf_call (struct dwarf_expr_context
*ctx
, size_t die_offset
)
283 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
285 return per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
286 ctx
->get_frame_pc
, ctx
->baton
);
291 /* Reference count. */
294 /* The CU from which this closure's expression came. */
295 struct dwarf2_per_cu_data
*per_cu
;
297 /* The number of pieces used to describe this variable. */
300 /* The target address size, used only for DWARF_VALUE_STACK. */
303 /* The pieces themselves. */
304 struct dwarf_expr_piece
*pieces
;
307 /* Allocate a closure for a value formed from separately-described
310 static struct piece_closure
*
311 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
312 int n_pieces
, struct dwarf_expr_piece
*pieces
,
315 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
319 c
->n_pieces
= n_pieces
;
320 c
->addr_size
= addr_size
;
321 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
323 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
328 /* The lowest-level function to extract bits from a byte buffer.
329 SOURCE is the buffer. It is updated if we read to the end of a
331 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
332 updated to reflect the number of bits actually read.
333 NBITS is the number of bits we want to read. It is updated to
334 reflect the number of bits actually read. This function may read
336 BITS_BIG_ENDIAN is taken directly from gdbarch.
337 This function returns the extracted bits. */
340 extract_bits_primitive (const gdb_byte
**source
,
341 unsigned int *source_offset_bits
,
342 int *nbits
, int bits_big_endian
)
344 unsigned int avail
, mask
, datum
;
346 gdb_assert (*source_offset_bits
< 8);
348 avail
= 8 - *source_offset_bits
;
352 mask
= (1 << avail
) - 1;
355 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
357 datum
>>= *source_offset_bits
;
361 *source_offset_bits
+= avail
;
362 if (*source_offset_bits
>= 8)
364 *source_offset_bits
-= 8;
371 /* Extract some bits from a source buffer and move forward in the
374 SOURCE is the source buffer. It is updated as bytes are read.
375 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
377 NBITS is the number of bits to read.
378 BITS_BIG_ENDIAN is taken directly from gdbarch.
380 This function returns the bits that were read. */
383 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
384 int nbits
, int bits_big_endian
)
388 gdb_assert (nbits
> 0 && nbits
<= 8);
390 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
396 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
408 /* Write some bits into a buffer and move forward in the buffer.
410 DATUM is the bits to write. The low-order bits of DATUM are used.
411 DEST is the destination buffer. It is updated as bytes are
413 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
415 NBITS is the number of valid bits in DATUM.
416 BITS_BIG_ENDIAN is taken directly from gdbarch. */
419 insert_bits (unsigned int datum
,
420 gdb_byte
*dest
, unsigned int dest_offset_bits
,
421 int nbits
, int bits_big_endian
)
425 gdb_assert (dest_offset_bits
>= 0 && dest_offset_bits
+ nbits
<= 8);
427 mask
= (1 << nbits
) - 1;
430 datum
<<= 8 - (dest_offset_bits
+ nbits
);
431 mask
<<= 8 - (dest_offset_bits
+ nbits
);
435 datum
<<= dest_offset_bits
;
436 mask
<<= dest_offset_bits
;
439 gdb_assert ((datum
& ~mask
) == 0);
441 *dest
= (*dest
& ~mask
) | datum
;
444 /* Copy bits from a source to a destination.
446 DEST is where the bits should be written.
447 DEST_OFFSET_BITS is the bit offset into DEST.
448 SOURCE is the source of bits.
449 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
450 BIT_COUNT is the number of bits to copy.
451 BITS_BIG_ENDIAN is taken directly from gdbarch. */
454 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
455 const gdb_byte
*source
, unsigned int source_offset_bits
,
456 unsigned int bit_count
,
459 unsigned int dest_avail
;
462 /* Reduce everything to byte-size pieces. */
463 dest
+= dest_offset_bits
/ 8;
464 dest_offset_bits
%= 8;
465 source
+= source_offset_bits
/ 8;
466 source_offset_bits
%= 8;
468 dest_avail
= 8 - dest_offset_bits
% 8;
470 /* See if we can fill the first destination byte. */
471 if (dest_avail
< bit_count
)
473 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
475 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
477 dest_offset_bits
= 0;
478 bit_count
-= dest_avail
;
481 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
482 than 8 bits remaining. */
483 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
484 for (; bit_count
>= 8; bit_count
-= 8)
486 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
487 *dest
++ = (gdb_byte
) datum
;
490 /* Finally, we may have a few leftover bits. */
491 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
494 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
496 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
501 read_pieced_value (struct value
*v
)
505 ULONGEST bits_to_skip
;
507 struct piece_closure
*c
508 = (struct piece_closure
*) value_computed_closure (v
);
509 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
511 size_t buffer_size
= 0;
513 struct cleanup
*cleanup
;
515 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
517 if (value_type (v
) != value_enclosing_type (v
))
518 internal_error (__FILE__
, __LINE__
,
519 _("Should not be able to create a lazy value with "
520 "an enclosing type"));
522 cleanup
= make_cleanup (free_current_contents
, &buffer
);
524 contents
= value_contents_raw (v
);
525 bits_to_skip
= 8 * value_offset (v
);
526 if (value_bitsize (v
))
528 bits_to_skip
+= value_bitpos (v
);
529 type_len
= value_bitsize (v
);
532 type_len
= 8 * TYPE_LENGTH (value_type (v
));
534 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
536 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
537 size_t this_size
, this_size_bits
;
538 long dest_offset_bits
, source_offset_bits
, source_offset
;
539 const gdb_byte
*intermediate_buffer
;
541 /* Compute size, source, and destination offsets for copying, in
543 this_size_bits
= p
->size
;
544 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
546 bits_to_skip
-= this_size_bits
;
549 if (this_size_bits
> type_len
- offset
)
550 this_size_bits
= type_len
- offset
;
551 if (bits_to_skip
> 0)
553 dest_offset_bits
= 0;
554 source_offset_bits
= bits_to_skip
;
555 this_size_bits
-= bits_to_skip
;
560 dest_offset_bits
= offset
;
561 source_offset_bits
= 0;
564 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
565 source_offset
= source_offset_bits
/ 8;
566 if (buffer_size
< this_size
)
568 buffer_size
= this_size
;
569 buffer
= xrealloc (buffer
, buffer_size
);
571 intermediate_buffer
= buffer
;
573 /* Copy from the source to DEST_BUFFER. */
576 case DWARF_VALUE_REGISTER
:
578 struct gdbarch
*arch
= get_frame_arch (frame
);
579 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.value
);
580 int reg_offset
= source_offset
;
582 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
583 && this_size
< register_size (arch
, gdb_regnum
))
585 /* Big-endian, and we want less than full size. */
586 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
587 /* We want the lower-order THIS_SIZE_BITS of the bytes
588 we extract from the register. */
589 source_offset_bits
+= 8 * this_size
- this_size_bits
;
592 if (gdb_regnum
!= -1)
594 get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
599 error (_("Unable to access DWARF register number %s"),
600 paddress (arch
, p
->v
.value
));
605 case DWARF_VALUE_MEMORY
:
606 read_value_memory (v
, offset
,
607 p
->v
.mem
.in_stack_memory
,
608 p
->v
.mem
.addr
+ source_offset
,
612 case DWARF_VALUE_STACK
:
614 struct gdbarch
*gdbarch
= get_type_arch (value_type (v
));
615 size_t n
= this_size
;
617 if (n
> c
->addr_size
- source_offset
)
618 n
= (c
->addr_size
>= source_offset
619 ? c
->addr_size
- source_offset
625 else if (source_offset
== 0)
626 store_unsigned_integer (buffer
, n
,
627 gdbarch_byte_order (gdbarch
),
631 gdb_byte bytes
[sizeof (ULONGEST
)];
633 store_unsigned_integer (bytes
, n
+ source_offset
,
634 gdbarch_byte_order (gdbarch
),
636 memcpy (buffer
, bytes
+ source_offset
, n
);
641 case DWARF_VALUE_LITERAL
:
643 size_t n
= this_size
;
645 if (n
> p
->v
.literal
.length
- source_offset
)
646 n
= (p
->v
.literal
.length
>= source_offset
647 ? p
->v
.literal
.length
- source_offset
650 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
654 /* These bits show up as zeros -- but do not cause the value
655 to be considered optimized-out. */
656 case DWARF_VALUE_IMPLICIT_POINTER
:
659 case DWARF_VALUE_OPTIMIZED_OUT
:
660 set_value_optimized_out (v
, 1);
664 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
667 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
668 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
669 copy_bitwise (contents
, dest_offset_bits
,
670 intermediate_buffer
, source_offset_bits
% 8,
671 this_size_bits
, bits_big_endian
);
673 offset
+= this_size_bits
;
676 do_cleanups (cleanup
);
680 write_pieced_value (struct value
*to
, struct value
*from
)
684 ULONGEST bits_to_skip
;
685 const gdb_byte
*contents
;
686 struct piece_closure
*c
687 = (struct piece_closure
*) value_computed_closure (to
);
688 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
690 size_t buffer_size
= 0;
692 struct cleanup
*cleanup
;
694 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
698 set_value_optimized_out (to
, 1);
702 cleanup
= make_cleanup (free_current_contents
, &buffer
);
704 contents
= value_contents (from
);
705 bits_to_skip
= 8 * value_offset (to
);
706 if (value_bitsize (to
))
708 bits_to_skip
+= value_bitpos (to
);
709 type_len
= value_bitsize (to
);
712 type_len
= 8 * TYPE_LENGTH (value_type (to
));
714 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
716 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
717 size_t this_size_bits
, this_size
;
718 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
720 const gdb_byte
*source_buffer
;
722 this_size_bits
= p
->size
;
723 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
725 bits_to_skip
-= this_size_bits
;
728 if (this_size_bits
> type_len
- offset
)
729 this_size_bits
= type_len
- offset
;
730 if (bits_to_skip
> 0)
732 dest_offset_bits
= bits_to_skip
;
733 source_offset_bits
= 0;
734 this_size_bits
-= bits_to_skip
;
739 dest_offset_bits
= 0;
740 source_offset_bits
= offset
;
743 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
744 source_offset
= source_offset_bits
/ 8;
745 dest_offset
= dest_offset_bits
/ 8;
746 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
748 source_buffer
= contents
+ source_offset
;
753 if (buffer_size
< this_size
)
755 buffer_size
= this_size
;
756 buffer
= xrealloc (buffer
, buffer_size
);
758 source_buffer
= buffer
;
764 case DWARF_VALUE_REGISTER
:
766 struct gdbarch
*arch
= get_frame_arch (frame
);
767 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.value
);
768 int reg_offset
= dest_offset
;
770 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
771 && this_size
<= register_size (arch
, gdb_regnum
))
772 /* Big-endian, and we want less than full size. */
773 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
775 if (gdb_regnum
!= -1)
779 get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
781 copy_bitwise (buffer
, dest_offset_bits
,
782 contents
, source_offset_bits
,
787 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
788 this_size
, source_buffer
);
792 error (_("Unable to write to DWARF register number %s"),
793 paddress (arch
, p
->v
.value
));
797 case DWARF_VALUE_MEMORY
:
800 /* Only the first and last bytes can possibly have any
802 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
803 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
804 buffer
+ this_size
- 1, 1);
805 copy_bitwise (buffer
, dest_offset_bits
,
806 contents
, source_offset_bits
,
811 write_memory (p
->v
.mem
.addr
+ dest_offset
,
812 source_buffer
, this_size
);
815 set_value_optimized_out (to
, 1);
818 offset
+= this_size_bits
;
821 do_cleanups (cleanup
);
824 /* A helper function that checks bit validity in a pieced value.
825 CHECK_FOR indicates the kind of validity checking.
826 DWARF_VALUE_MEMORY means to check whether any bit is valid.
827 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
829 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
833 check_pieced_value_bits (const struct value
*value
, int bit_offset
,
835 enum dwarf_value_location check_for
)
837 struct piece_closure
*c
838 = (struct piece_closure
*) value_computed_closure (value
);
840 int validity
= (check_for
== DWARF_VALUE_MEMORY
841 || check_for
== DWARF_VALUE_IMPLICIT_POINTER
);
843 bit_offset
+= 8 * value_offset (value
);
844 if (value_bitsize (value
))
845 bit_offset
+= value_bitpos (value
);
847 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
849 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
850 size_t this_size_bits
= p
->size
;
854 if (bit_offset
>= this_size_bits
)
856 bit_offset
-= this_size_bits
;
860 bit_length
-= this_size_bits
- bit_offset
;
864 bit_length
-= this_size_bits
;
866 if (check_for
== DWARF_VALUE_IMPLICIT_POINTER
)
868 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
871 else if (p
->location
== DWARF_VALUE_OPTIMIZED_OUT
872 || p
->location
== DWARF_VALUE_IMPLICIT_POINTER
)
888 check_pieced_value_validity (const struct value
*value
, int bit_offset
,
891 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
896 check_pieced_value_invalid (const struct value
*value
)
898 return check_pieced_value_bits (value
, 0,
899 8 * TYPE_LENGTH (value_type (value
)),
900 DWARF_VALUE_OPTIMIZED_OUT
);
903 /* An implementation of an lval_funcs method to see whether a value is
904 a synthetic pointer. */
907 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
910 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
911 DWARF_VALUE_IMPLICIT_POINTER
);
914 /* A wrapper function for get_frame_address_in_block. */
917 get_frame_address_in_block_wrapper (void *baton
)
919 return get_frame_address_in_block (baton
);
922 /* An implementation of an lval_funcs method to indirect through a
923 pointer. This handles the synthetic pointer case when needed. */
925 static struct value
*
926 indirect_pieced_value (struct value
*value
)
928 struct piece_closure
*c
929 = (struct piece_closure
*) value_computed_closure (value
);
931 struct frame_info
*frame
;
932 struct dwarf2_locexpr_baton baton
;
933 int i
, bit_offset
, bit_length
;
934 struct dwarf_expr_piece
*piece
= NULL
;
935 struct value
*result
;
938 type
= value_type (value
);
939 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
942 bit_length
= 8 * TYPE_LENGTH (type
);
943 bit_offset
= 8 * value_offset (value
);
944 if (value_bitsize (value
))
945 bit_offset
+= value_bitpos (value
);
947 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
949 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
950 size_t this_size_bits
= p
->size
;
954 if (bit_offset
>= this_size_bits
)
956 bit_offset
-= this_size_bits
;
960 bit_length
-= this_size_bits
- bit_offset
;
964 bit_length
-= this_size_bits
;
966 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
970 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
976 frame
= get_selected_frame (_("No frame selected."));
977 byte_offset
= value_as_address (value
);
979 baton
= dwarf2_fetch_die_location_block (piece
->v
.ptr
.die
, c
->per_cu
,
980 get_frame_address_in_block_wrapper
,
983 result
= dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
984 baton
.data
, baton
.size
, baton
.per_cu
,
991 copy_pieced_value_closure (const struct value
*v
)
993 struct piece_closure
*c
994 = (struct piece_closure
*) value_computed_closure (v
);
1001 free_pieced_value_closure (struct value
*v
)
1003 struct piece_closure
*c
1004 = (struct piece_closure
*) value_computed_closure (v
);
1014 /* Functions for accessing a variable described by DW_OP_piece. */
1015 static struct lval_funcs pieced_value_funcs
= {
1018 check_pieced_value_validity
,
1019 check_pieced_value_invalid
,
1020 indirect_pieced_value
,
1021 check_pieced_synthetic_pointer
,
1022 copy_pieced_value_closure
,
1023 free_pieced_value_closure
1026 /* Helper function which throws an error if a synthetic pointer is
1030 invalid_synthetic_pointer (void)
1032 error (_("access outside bounds of object "
1033 "referenced via synthetic pointer"));
1036 /* Evaluate a location description, starting at DATA and with length
1037 SIZE, to find the current location of variable of TYPE in the
1038 context of FRAME. BYTE_OFFSET is applied after the contents are
1041 static struct value
*
1042 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1043 const gdb_byte
*data
, unsigned short size
,
1044 struct dwarf2_per_cu_data
*per_cu
,
1045 LONGEST byte_offset
)
1047 struct value
*retval
;
1048 struct dwarf_expr_baton baton
;
1049 struct dwarf_expr_context
*ctx
;
1050 struct cleanup
*old_chain
;
1051 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
1053 if (byte_offset
< 0)
1054 invalid_synthetic_pointer ();
1058 retval
= allocate_value (type
);
1059 VALUE_LVAL (retval
) = not_lval
;
1060 set_value_optimized_out (retval
, 1);
1064 baton
.frame
= frame
;
1065 baton
.per_cu
= per_cu
;
1067 ctx
= new_dwarf_expr_context ();
1068 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
1070 ctx
->gdbarch
= get_objfile_arch (objfile
);
1071 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
1072 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
1073 ctx
->baton
= &baton
;
1074 ctx
->read_reg
= dwarf_expr_read_reg
;
1075 ctx
->read_mem
= dwarf_expr_read_mem
;
1076 ctx
->get_frame_base
= dwarf_expr_frame_base
;
1077 ctx
->get_frame_cfa
= dwarf_expr_frame_cfa
;
1078 ctx
->get_frame_pc
= dwarf_expr_frame_pc
;
1079 ctx
->get_tls_address
= dwarf_expr_tls_address
;
1080 ctx
->dwarf_call
= dwarf_expr_dwarf_call
;
1082 dwarf_expr_eval (ctx
, data
, size
);
1083 if (ctx
->num_pieces
> 0)
1085 struct piece_closure
*c
;
1086 struct frame_id frame_id
= get_frame_id (frame
);
1087 ULONGEST bit_size
= 0;
1090 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
1091 bit_size
+= ctx
->pieces
[i
].size
;
1092 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
1093 invalid_synthetic_pointer ();
1095 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
1097 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
1098 VALUE_FRAME_ID (retval
) = frame_id
;
1099 set_value_offset (retval
, byte_offset
);
1103 switch (ctx
->location
)
1105 case DWARF_VALUE_REGISTER
:
1107 struct gdbarch
*arch
= get_frame_arch (frame
);
1108 ULONGEST dwarf_regnum
= dwarf_expr_fetch (ctx
, 0);
1109 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
1111 if (byte_offset
!= 0)
1112 error (_("cannot use offset on synthetic pointer to register"));
1113 if (gdb_regnum
!= -1)
1114 retval
= value_from_register (type
, gdb_regnum
, frame
);
1116 error (_("Unable to access DWARF register number %s"),
1117 paddress (arch
, dwarf_regnum
));
1121 case DWARF_VALUE_MEMORY
:
1123 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
1124 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
1126 retval
= allocate_value_lazy (type
);
1127 VALUE_LVAL (retval
) = lval_memory
;
1128 if (in_stack_memory
)
1129 set_value_stack (retval
, 1);
1130 set_value_address (retval
, address
+ byte_offset
);
1134 case DWARF_VALUE_STACK
:
1136 ULONGEST value
= dwarf_expr_fetch (ctx
, 0);
1137 bfd_byte
*contents
, *tem
;
1138 size_t n
= ctx
->addr_size
;
1140 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1141 invalid_synthetic_pointer ();
1144 store_unsigned_integer (tem
, n
,
1145 gdbarch_byte_order (ctx
->gdbarch
),
1151 retval
= allocate_value (type
);
1152 contents
= value_contents_raw (retval
);
1153 if (n
> TYPE_LENGTH (type
))
1154 n
= TYPE_LENGTH (type
);
1155 memcpy (contents
, tem
, n
);
1159 case DWARF_VALUE_LITERAL
:
1162 const bfd_byte
*data
;
1163 size_t n
= ctx
->len
;
1165 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1166 invalid_synthetic_pointer ();
1168 retval
= allocate_value (type
);
1169 contents
= value_contents_raw (retval
);
1171 data
= ctx
->data
+ byte_offset
;
1174 if (n
> TYPE_LENGTH (type
))
1175 n
= TYPE_LENGTH (type
);
1176 memcpy (contents
, data
, n
);
1180 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1181 operation by execute_stack_op. */
1182 case DWARF_VALUE_IMPLICIT_POINTER
:
1183 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1184 it can only be encountered when making a piece. */
1185 case DWARF_VALUE_OPTIMIZED_OUT
:
1187 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1191 set_value_initialized (retval
, ctx
->initialized
);
1193 do_cleanups (old_chain
);
1198 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1199 passes 0 as the byte_offset. */
1202 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1203 const gdb_byte
*data
, unsigned short size
,
1204 struct dwarf2_per_cu_data
*per_cu
)
1206 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
1210 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1212 struct needs_frame_baton
1215 struct dwarf2_per_cu_data
*per_cu
;
1218 /* Reads from registers do require a frame. */
1220 needs_frame_read_reg (void *baton
, int regnum
)
1222 struct needs_frame_baton
*nf_baton
= baton
;
1224 nf_baton
->needs_frame
= 1;
1228 /* Reads from memory do not require a frame. */
1230 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
1232 memset (buf
, 0, len
);
1235 /* Frame-relative accesses do require a frame. */
1237 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
1239 static gdb_byte lit0
= DW_OP_lit0
;
1240 struct needs_frame_baton
*nf_baton
= baton
;
1245 nf_baton
->needs_frame
= 1;
1248 /* CFA accesses require a frame. */
1251 needs_frame_frame_cfa (void *baton
)
1253 struct needs_frame_baton
*nf_baton
= baton
;
1255 nf_baton
->needs_frame
= 1;
1259 /* Thread-local accesses do require a frame. */
1261 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
1263 struct needs_frame_baton
*nf_baton
= baton
;
1265 nf_baton
->needs_frame
= 1;
1269 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
1272 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, size_t die_offset
)
1274 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
1276 return per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
1277 ctx
->get_frame_pc
, ctx
->baton
);
1280 /* Return non-zero iff the location expression at DATA (length SIZE)
1281 requires a frame to evaluate. */
1284 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, unsigned short size
,
1285 struct dwarf2_per_cu_data
*per_cu
)
1287 struct needs_frame_baton baton
;
1288 struct dwarf_expr_context
*ctx
;
1290 struct cleanup
*old_chain
;
1291 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
1293 baton
.needs_frame
= 0;
1294 baton
.per_cu
= per_cu
;
1296 ctx
= new_dwarf_expr_context ();
1297 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
1299 ctx
->gdbarch
= get_objfile_arch (objfile
);
1300 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
1301 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
1302 ctx
->baton
= &baton
;
1303 ctx
->read_reg
= needs_frame_read_reg
;
1304 ctx
->read_mem
= needs_frame_read_mem
;
1305 ctx
->get_frame_base
= needs_frame_frame_base
;
1306 ctx
->get_frame_cfa
= needs_frame_frame_cfa
;
1307 ctx
->get_frame_pc
= needs_frame_frame_cfa
;
1308 ctx
->get_tls_address
= needs_frame_tls_address
;
1309 ctx
->dwarf_call
= needs_frame_dwarf_call
;
1311 dwarf_expr_eval (ctx
, data
, size
);
1313 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
1315 if (ctx
->num_pieces
> 0)
1319 /* If the location has several pieces, and any of them are in
1320 registers, then we will need a frame to fetch them from. */
1321 for (i
= 0; i
< ctx
->num_pieces
; i
++)
1322 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
1326 do_cleanups (old_chain
);
1328 return baton
.needs_frame
|| in_reg
;
1331 /* A helper function that throws an unimplemented error mentioning a
1332 given DWARF operator. */
1335 unimplemented (unsigned int op
)
1337 const char *name
= dwarf_stack_op_name (op
);
1340 error (_("DWARF operator %s cannot be translated to an agent expression"),
1343 error (_("Unknown DWARF operator 0x%02x cannot be to an agent expression"),
1347 /* A helper function to convert a DWARF register to an arch register.
1348 ARCH is the architecture.
1349 DWARF_REG is the register.
1350 This will throw an exception if the DWARF register cannot be
1351 translated to an architecture register. */
1354 translate_register (struct gdbarch
*arch
, int dwarf_reg
)
1356 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
1358 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
1362 /* A helper function that emits an access to memory. ARCH is the
1363 target architecture. EXPR is the expression which we are building.
1364 NBITS is the number of bits we want to read. This emits the
1365 opcodes needed to read the memory and then extract the desired
1369 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
1371 ULONGEST nbytes
= (nbits
+ 7) / 8;
1373 gdb_assert (nbits
> 0 && nbits
<= sizeof (LONGEST
));
1376 ax_trace_quick (expr
, nbytes
);
1379 ax_simple (expr
, aop_ref8
);
1380 else if (nbits
<= 16)
1381 ax_simple (expr
, aop_ref16
);
1382 else if (nbits
<= 32)
1383 ax_simple (expr
, aop_ref32
);
1385 ax_simple (expr
, aop_ref64
);
1387 /* If we read exactly the number of bytes we wanted, we're done. */
1388 if (8 * nbytes
== nbits
)
1391 if (gdbarch_bits_big_endian (arch
))
1393 /* On a bits-big-endian machine, we want the high-order
1395 ax_const_l (expr
, 8 * nbytes
- nbits
);
1396 ax_simple (expr
, aop_rsh_unsigned
);
1400 /* On a bits-little-endian box, we want the low-order NBITS. */
1401 ax_zero_ext (expr
, nbits
);
1405 /* A helper function to return the frame's PC. */
1408 get_ax_pc (void *baton
)
1410 struct agent_expr
*expr
= baton
;
1415 /* Compile a DWARF location expression to an agent expression.
1417 EXPR is the agent expression we are building.
1418 LOC is the agent value we modify.
1419 ARCH is the architecture.
1420 ADDR_SIZE is the size of addresses, in bytes.
1421 OP_PTR is the start of the location expression.
1422 OP_END is one past the last byte of the location expression.
1424 This will throw an exception for various kinds of errors -- for
1425 example, if the expression cannot be compiled, or if the expression
1429 compile_dwarf_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
1430 struct gdbarch
*arch
, unsigned int addr_size
,
1431 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
1432 struct dwarf2_per_cu_data
*per_cu
)
1434 struct cleanup
*cleanups
;
1436 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
1437 const gdb_byte
* const base
= op_ptr
;
1438 const gdb_byte
*previous_piece
= op_ptr
;
1439 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
1440 ULONGEST bits_collected
= 0;
1441 unsigned int addr_size_bits
= 8 * addr_size
;
1442 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
1444 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
1445 cleanups
= make_cleanup (xfree
, offsets
);
1447 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
1450 make_cleanup (VEC_cleanup (int), &dw_labels
);
1451 make_cleanup (VEC_cleanup (int), &patches
);
1453 /* By default we are making an address. */
1454 loc
->kind
= axs_lvalue_memory
;
1456 while (op_ptr
< op_end
)
1458 enum dwarf_location_atom op
= *op_ptr
;
1459 ULONGEST uoffset
, reg
;
1463 offsets
[op_ptr
- base
] = expr
->len
;
1466 /* Our basic approach to code generation is to map DWARF
1467 operations directly to AX operations. However, there are
1470 First, DWARF works on address-sized units, but AX always uses
1471 LONGEST. For most operations we simply ignore this
1472 difference; instead we generate sign extensions as needed
1473 before division and comparison operations. It would be nice
1474 to omit the sign extensions, but there is no way to determine
1475 the size of the target's LONGEST. (This code uses the size
1476 of the host LONGEST in some cases -- that is a bug but it is
1479 Second, some DWARF operations cannot be translated to AX.
1480 For these we simply fail. See
1481 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
1516 ax_const_l (expr
, op
- DW_OP_lit0
);
1520 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
1521 op_ptr
+= addr_size
;
1522 /* Some versions of GCC emit DW_OP_addr before
1523 DW_OP_GNU_push_tls_address. In this case the value is an
1524 index, not an address. We don't support things like
1525 branching between the address and the TLS op. */
1526 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
1527 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
1528 ax_const_l (expr
, uoffset
);
1532 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
1536 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
1540 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
1544 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
1548 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
1552 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
1556 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
1560 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
1564 op_ptr
= read_uleb128 (op_ptr
, op_end
, &uoffset
);
1565 ax_const_l (expr
, uoffset
);
1568 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1569 ax_const_l (expr
, offset
);
1604 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
1605 loc
->u
.reg
= translate_register (arch
, op
- DW_OP_reg0
);
1606 loc
->kind
= axs_lvalue_register
;
1610 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1611 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
1612 loc
->u
.reg
= translate_register (arch
, reg
);
1613 loc
->kind
= axs_lvalue_register
;
1616 case DW_OP_implicit_value
:
1620 op_ptr
= read_uleb128 (op_ptr
, op_end
, &len
);
1621 if (op_ptr
+ len
> op_end
)
1622 error (_("DW_OP_implicit_value: too few bytes available."));
1623 if (len
> sizeof (ULONGEST
))
1624 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
1627 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
1630 dwarf_expr_require_composition (op_ptr
, op_end
,
1631 "DW_OP_implicit_value");
1633 loc
->kind
= axs_rvalue
;
1637 case DW_OP_stack_value
:
1638 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
1639 loc
->kind
= axs_rvalue
;
1674 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1675 i
= translate_register (arch
, op
- DW_OP_breg0
);
1679 ax_const_l (expr
, offset
);
1680 ax_simple (expr
, aop_add
);
1685 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1686 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1687 i
= translate_register (arch
, reg
);
1691 ax_const_l (expr
, offset
);
1692 ax_simple (expr
, aop_add
);
1698 const gdb_byte
*datastart
;
1700 unsigned int before_stack_len
;
1702 struct symbol
*framefunc
;
1703 LONGEST base_offset
= 0;
1705 b
= block_for_pc (expr
->scope
);
1708 error (_("No block found for address"));
1710 framefunc
= block_linkage_function (b
);
1713 error (_("No function found for block"));
1715 dwarf_expr_frame_base_1 (framefunc
, expr
->scope
,
1716 &datastart
, &datalen
);
1718 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1719 compile_dwarf_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
1720 datastart
+ datalen
, per_cu
);
1724 ax_const_l (expr
, offset
);
1725 ax_simple (expr
, aop_add
);
1728 loc
->kind
= axs_lvalue_memory
;
1733 ax_simple (expr
, aop_dup
);
1737 ax_simple (expr
, aop_pop
);
1746 ax_simple (expr
, aop_swap
);
1750 /* We can't directly support DW_OP_over, but GCC emits it as
1751 part of a sequence to implement signed modulus. As a
1752 hack, we recognize this sequence. Note that if GCC ever
1753 generates a branch to the middle of this sequence, then
1754 we will die somehow. */
1755 if (op_end
- op_ptr
>= 4
1756 && op_ptr
[0] == DW_OP_over
1757 && op_ptr
[1] == DW_OP_div
1758 && op_ptr
[2] == DW_OP_mul
1759 && op_ptr
[3] == DW_OP_minus
)
1761 /* Sign extend the operands. */
1762 ax_ext (expr
, addr_size_bits
);
1763 ax_simple (expr
, aop_swap
);
1764 ax_ext (expr
, addr_size_bits
);
1765 ax_simple (expr
, aop_swap
);
1766 ax_simple (expr
, aop_rem_signed
);
1778 case DW_OP_deref_size
:
1782 if (op
== DW_OP_deref_size
)
1790 ax_simple (expr
, aop_ref8
);
1793 ax_simple (expr
, aop_ref16
);
1796 ax_simple (expr
, aop_ref32
);
1799 ax_simple (expr
, aop_ref64
);
1802 /* Note that dwarf_stack_op_name will never return
1804 error (_("Unsupported size %d in %s"),
1805 size
, dwarf_stack_op_name (op
));
1811 /* Sign extend the operand. */
1812 ax_ext (expr
, addr_size_bits
);
1813 ax_simple (expr
, aop_dup
);
1814 ax_const_l (expr
, 0);
1815 ax_simple (expr
, aop_less_signed
);
1816 ax_simple (expr
, aop_log_not
);
1817 i
= ax_goto (expr
, aop_if_goto
);
1818 /* We have to emit 0 - X. */
1819 ax_const_l (expr
, 0);
1820 ax_simple (expr
, aop_swap
);
1821 ax_simple (expr
, aop_sub
);
1822 ax_label (expr
, i
, expr
->len
);
1826 /* No need to sign extend here. */
1827 ax_const_l (expr
, 0);
1828 ax_simple (expr
, aop_swap
);
1829 ax_simple (expr
, aop_sub
);
1833 /* Sign extend the operand. */
1834 ax_ext (expr
, addr_size_bits
);
1835 ax_simple (expr
, aop_bit_not
);
1838 case DW_OP_plus_uconst
:
1839 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1840 /* It would be really weird to emit `DW_OP_plus_uconst 0',
1841 but we micro-optimize anyhow. */
1844 ax_const_l (expr
, reg
);
1845 ax_simple (expr
, aop_add
);
1850 ax_simple (expr
, aop_bit_and
);
1854 /* Sign extend the operands. */
1855 ax_ext (expr
, addr_size_bits
);
1856 ax_simple (expr
, aop_swap
);
1857 ax_ext (expr
, addr_size_bits
);
1858 ax_simple (expr
, aop_swap
);
1859 ax_simple (expr
, aop_div_signed
);
1863 ax_simple (expr
, aop_sub
);
1867 ax_simple (expr
, aop_rem_unsigned
);
1871 ax_simple (expr
, aop_mul
);
1875 ax_simple (expr
, aop_bit_or
);
1879 ax_simple (expr
, aop_add
);
1883 ax_simple (expr
, aop_lsh
);
1887 ax_simple (expr
, aop_rsh_unsigned
);
1891 ax_simple (expr
, aop_rsh_signed
);
1895 ax_simple (expr
, aop_bit_xor
);
1899 /* Sign extend the operands. */
1900 ax_ext (expr
, addr_size_bits
);
1901 ax_simple (expr
, aop_swap
);
1902 ax_ext (expr
, addr_size_bits
);
1903 /* Note no swap here: A <= B is !(B < A). */
1904 ax_simple (expr
, aop_less_signed
);
1905 ax_simple (expr
, aop_log_not
);
1909 /* Sign extend the operands. */
1910 ax_ext (expr
, addr_size_bits
);
1911 ax_simple (expr
, aop_swap
);
1912 ax_ext (expr
, addr_size_bits
);
1913 ax_simple (expr
, aop_swap
);
1914 /* A >= B is !(A < B). */
1915 ax_simple (expr
, aop_less_signed
);
1916 ax_simple (expr
, aop_log_not
);
1920 /* Sign extend the operands. */
1921 ax_ext (expr
, addr_size_bits
);
1922 ax_simple (expr
, aop_swap
);
1923 ax_ext (expr
, addr_size_bits
);
1924 /* No need for a second swap here. */
1925 ax_simple (expr
, aop_equal
);
1929 /* Sign extend the operands. */
1930 ax_ext (expr
, addr_size_bits
);
1931 ax_simple (expr
, aop_swap
);
1932 ax_ext (expr
, addr_size_bits
);
1933 ax_simple (expr
, aop_swap
);
1934 ax_simple (expr
, aop_less_signed
);
1938 /* Sign extend the operands. */
1939 ax_ext (expr
, addr_size_bits
);
1940 ax_simple (expr
, aop_swap
);
1941 ax_ext (expr
, addr_size_bits
);
1942 /* Note no swap here: A > B is B < A. */
1943 ax_simple (expr
, aop_less_signed
);
1947 /* Sign extend the operands. */
1948 ax_ext (expr
, addr_size_bits
);
1949 ax_simple (expr
, aop_swap
);
1950 ax_ext (expr
, addr_size_bits
);
1951 /* No need for a swap here. */
1952 ax_simple (expr
, aop_equal
);
1953 ax_simple (expr
, aop_log_not
);
1956 case DW_OP_call_frame_cfa
:
1960 case DW_OP_GNU_push_tls_address
:
1965 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
1967 i
= ax_goto (expr
, aop_goto
);
1968 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
1969 VEC_safe_push (int, patches
, i
);
1973 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
1975 /* Zero extend the operand. */
1976 ax_zero_ext (expr
, addr_size_bits
);
1977 i
= ax_goto (expr
, aop_if_goto
);
1978 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
1979 VEC_safe_push (int, patches
, i
);
1986 case DW_OP_bit_piece
:
1988 ULONGEST size
, offset
;
1990 if (op_ptr
- 1 == previous_piece
)
1991 error (_("Cannot translate empty pieces to agent expressions"));
1992 previous_piece
= op_ptr
- 1;
1994 op_ptr
= read_uleb128 (op_ptr
, op_end
, &size
);
1995 if (op
== DW_OP_piece
)
2001 op_ptr
= read_uleb128 (op_ptr
, op_end
, &offset
);
2003 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2004 error (_("Expression pieces exceed word size"));
2006 /* Access the bits. */
2009 case axs_lvalue_register
:
2010 ax_reg (expr
, loc
->u
.reg
);
2013 case axs_lvalue_memory
:
2014 /* Offset the pointer, if needed. */
2017 ax_const_l (expr
, offset
/ 8);
2018 ax_simple (expr
, aop_add
);
2021 access_memory (arch
, expr
, size
);
2025 /* For a bits-big-endian target, shift up what we already
2026 have. For a bits-little-endian target, shift up the
2027 new data. Note that there is a potential bug here if
2028 the DWARF expression leaves multiple values on the
2030 if (bits_collected
> 0)
2032 if (bits_big_endian
)
2034 ax_simple (expr
, aop_swap
);
2035 ax_const_l (expr
, size
);
2036 ax_simple (expr
, aop_lsh
);
2037 /* We don't need a second swap here, because
2038 aop_bit_or is symmetric. */
2042 ax_const_l (expr
, size
);
2043 ax_simple (expr
, aop_lsh
);
2045 ax_simple (expr
, aop_bit_or
);
2048 bits_collected
+= size
;
2049 loc
->kind
= axs_rvalue
;
2053 case DW_OP_GNU_uninit
:
2059 struct dwarf2_locexpr_baton block
;
2060 int size
= (op
== DW_OP_call2
? 2 : 4);
2062 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2065 block
= dwarf2_fetch_die_location_block (uoffset
, per_cu
,
2068 /* DW_OP_call_ref is currently not supported. */
2069 gdb_assert (block
.per_cu
== per_cu
);
2071 compile_dwarf_to_ax (expr
, loc
, arch
, addr_size
,
2072 block
.data
, block
.data
+ block
.size
,
2077 case DW_OP_call_ref
:
2085 /* Patch all the branches we emitted. */
2086 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
2088 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
2090 internal_error (__FILE__
, __LINE__
, _("invalid label"));
2091 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
2094 do_cleanups (cleanups
);
2098 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2099 evaluator to calculate the location. */
2100 static struct value
*
2101 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
2103 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2106 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
2107 dlbaton
->size
, dlbaton
->per_cu
);
2112 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2114 locexpr_read_needs_frame (struct symbol
*symbol
)
2116 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2118 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
2122 /* Return true if DATA points to the end of a piece. END is one past
2123 the last byte in the expression. */
2126 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
2128 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
2131 /* Nicely describe a single piece of a location, returning an updated
2132 position in the bytecode sequence. This function cannot recognize
2133 all locations; if a location is not recognized, it simply returns
2136 static const gdb_byte
*
2137 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
2138 CORE_ADDR addr
, struct objfile
*objfile
,
2139 const gdb_byte
*data
, const gdb_byte
*end
,
2140 unsigned int addr_size
)
2142 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2145 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
2147 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, data
[0] - DW_OP_reg0
);
2148 fprintf_filtered (stream
, _("a variable in $%s"),
2149 gdbarch_register_name (gdbarch
, regno
));
2152 else if (data
[0] == DW_OP_regx
)
2156 data
= read_uleb128 (data
+ 1, end
, ®
);
2157 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
);
2158 fprintf_filtered (stream
, _("a variable in $%s"),
2159 gdbarch_register_name (gdbarch
, regno
));
2161 else if (data
[0] == DW_OP_fbreg
)
2164 struct symbol
*framefunc
;
2166 LONGEST frame_offset
;
2167 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
2169 LONGEST base_offset
= 0;
2171 new_data
= read_sleb128 (data
+ 1, end
, &frame_offset
);
2172 if (!piece_end_p (new_data
, end
))
2176 b
= block_for_pc (addr
);
2179 error (_("No block found for address for symbol \"%s\"."),
2180 SYMBOL_PRINT_NAME (symbol
));
2182 framefunc
= block_linkage_function (b
);
2185 error (_("No function found for block for symbol \"%s\"."),
2186 SYMBOL_PRINT_NAME (symbol
));
2188 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
2190 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
2192 const gdb_byte
*buf_end
;
2194 frame_reg
= base_data
[0] - DW_OP_breg0
;
2195 buf_end
= read_sleb128 (base_data
+ 1,
2196 base_data
+ base_size
, &base_offset
);
2197 if (buf_end
!= base_data
+ base_size
)
2198 error (_("Unexpected opcode after "
2199 "DW_OP_breg%u for symbol \"%s\"."),
2200 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
2202 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
2204 /* The frame base is just the register, with no offset. */
2205 frame_reg
= base_data
[0] - DW_OP_reg0
;
2210 /* We don't know what to do with the frame base expression,
2211 so we can't trace this variable; give up. */
2215 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, frame_reg
);
2217 fprintf_filtered (stream
,
2218 _("a variable at frame base reg $%s offset %s+%s"),
2219 gdbarch_register_name (gdbarch
, regno
),
2220 plongest (base_offset
), plongest (frame_offset
));
2222 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
2223 && piece_end_p (data
, end
))
2227 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, data
[0] - DW_OP_breg0
);
2229 data
= read_sleb128 (data
+ 1, end
, &offset
);
2231 fprintf_filtered (stream
,
2232 _("a variable at offset %s from base reg $%s"),
2234 gdbarch_register_name (gdbarch
, regno
));
2237 /* The location expression for a TLS variable looks like this (on a
2240 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2241 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2243 0x3 is the encoding for DW_OP_addr, which has an operand as long
2244 as the size of an address on the target machine (here is 8
2245 bytes). Note that more recent version of GCC emit DW_OP_const4u
2246 or DW_OP_const8u, depending on address size, rather than
2247 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
2248 The operand represents the offset at which the variable is within
2249 the thread local storage. */
2251 else if (data
+ 1 + addr_size
< end
2252 && (data
[0] == DW_OP_addr
2253 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
2254 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
2255 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
2256 && piece_end_p (data
+ 2 + addr_size
, end
))
2259 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
2260 gdbarch_byte_order (gdbarch
));
2262 fprintf_filtered (stream
,
2263 _("a thread-local variable at offset 0x%s "
2264 "in the thread-local storage for `%s'"),
2265 phex_nz (offset
, addr_size
), objfile
->name
);
2267 data
+= 1 + addr_size
+ 1;
2269 else if (data
[0] >= DW_OP_lit0
2270 && data
[0] <= DW_OP_lit31
2272 && data
[1] == DW_OP_stack_value
)
2274 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
2281 /* Disassemble an expression, stopping at the end of a piece or at the
2282 end of the expression. Returns a pointer to the next unread byte
2283 in the input expression. If ALL is nonzero, then this function
2284 will keep going until it reaches the end of the expression. */
2286 static const gdb_byte
*
2287 disassemble_dwarf_expression (struct ui_file
*stream
,
2288 struct gdbarch
*arch
, unsigned int addr_size
,
2290 const gdb_byte
*data
, const gdb_byte
*end
,
2293 const gdb_byte
*start
= data
;
2295 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
2299 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
2301 enum dwarf_location_atom op
= *data
++;
2306 name
= dwarf_stack_op_name (op
);
2309 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
2310 op
, (long) (data
- start
));
2311 fprintf_filtered (stream
, " % 4ld: %s", (long) (data
- start
), name
);
2316 ul
= extract_unsigned_integer (data
, addr_size
,
2317 gdbarch_byte_order (arch
));
2319 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
2323 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
2325 fprintf_filtered (stream
, " %s", pulongest (ul
));
2328 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
2330 fprintf_filtered (stream
, " %s", plongest (l
));
2333 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
2335 fprintf_filtered (stream
, " %s", pulongest (ul
));
2338 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2340 fprintf_filtered (stream
, " %s", plongest (l
));
2343 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
2345 fprintf_filtered (stream
, " %s", pulongest (ul
));
2348 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
2350 fprintf_filtered (stream
, " %s", plongest (l
));
2353 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
2355 fprintf_filtered (stream
, " %s", pulongest (ul
));
2358 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
2360 fprintf_filtered (stream
, " %s", plongest (l
));
2363 data
= read_uleb128 (data
, end
, &ul
);
2364 fprintf_filtered (stream
, " %s", pulongest (ul
));
2367 data
= read_sleb128 (data
, end
, &l
);
2368 fprintf_filtered (stream
, " %s", plongest (l
));
2403 fprintf_filtered (stream
, " [$%s]",
2404 gdbarch_register_name (arch
, op
- DW_OP_reg0
));
2408 data
= read_uleb128 (data
, end
, &ul
);
2409 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
2410 gdbarch_register_name (arch
, (int) ul
));
2413 case DW_OP_implicit_value
:
2414 data
= read_uleb128 (data
, end
, &ul
);
2416 fprintf_filtered (stream
, " %s", pulongest (ul
));
2451 data
= read_sleb128 (data
, end
, &ul
);
2452 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
2453 gdbarch_register_name (arch
, op
- DW_OP_breg0
));
2460 data
= read_uleb128 (data
, end
, &ul
);
2461 data
= read_sleb128 (data
, end
, &offset
);
2462 fprintf_filtered (stream
, " register %s [$%s] offset %s",
2464 gdbarch_register_name (arch
, (int) ul
),
2465 pulongest (offset
));
2470 data
= read_sleb128 (data
, end
, &ul
);
2471 fprintf_filtered (stream
, " %s", pulongest (ul
));
2474 case DW_OP_xderef_size
:
2475 case DW_OP_deref_size
:
2477 fprintf_filtered (stream
, " %d", *data
);
2481 case DW_OP_plus_uconst
:
2482 data
= read_uleb128 (data
, end
, &ul
);
2483 fprintf_filtered (stream
, " %s", pulongest (ul
));
2487 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2489 fprintf_filtered (stream
, " to %ld",
2490 (long) (data
+ l
- start
));
2494 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2496 fprintf_filtered (stream
, " %ld",
2497 (long) (data
+ l
- start
));
2501 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
2503 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
2507 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
2509 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
2512 case DW_OP_call_ref
:
2513 ul
= extract_unsigned_integer (data
, offset_size
,
2514 gdbarch_byte_order (arch
));
2515 data
+= offset_size
;
2516 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
2520 data
= read_uleb128 (data
, end
, &ul
);
2521 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
2524 case DW_OP_bit_piece
:
2528 data
= read_uleb128 (data
, end
, &ul
);
2529 data
= read_uleb128 (data
, end
, &offset
);
2530 fprintf_filtered (stream
, " size %s offset %s (bits)",
2531 pulongest (ul
), pulongest (offset
));
2535 case DW_OP_GNU_implicit_pointer
:
2537 ul
= extract_unsigned_integer (data
, offset_size
,
2538 gdbarch_byte_order (arch
));
2539 data
+= offset_size
;
2541 data
= read_sleb128 (data
, end
, &l
);
2543 fprintf_filtered (stream
, " DIE %s offset %s",
2544 phex_nz (ul
, offset_size
),
2550 fprintf_filtered (stream
, "\n");
2556 /* Describe a single location, which may in turn consist of multiple
2560 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
2561 struct ui_file
*stream
,
2562 const gdb_byte
*data
, int size
,
2563 struct objfile
*objfile
, unsigned int addr_size
,
2566 const gdb_byte
*end
= data
+ size
;
2567 int first_piece
= 1, bad
= 0;
2571 const gdb_byte
*here
= data
;
2572 int disassemble
= 1;
2577 fprintf_filtered (stream
, _(", and "));
2579 if (!dwarf2_always_disassemble
)
2581 data
= locexpr_describe_location_piece (symbol
, stream
,
2583 data
, end
, addr_size
);
2584 /* If we printed anything, or if we have an empty piece,
2585 then don't disassemble. */
2587 || data
[0] == DW_OP_piece
2588 || data
[0] == DW_OP_bit_piece
)
2592 data
= disassemble_dwarf_expression (stream
,
2593 get_objfile_arch (objfile
),
2594 addr_size
, offset_size
, data
, end
,
2595 dwarf2_always_disassemble
);
2599 int empty
= data
== here
;
2602 fprintf_filtered (stream
, " ");
2603 if (data
[0] == DW_OP_piece
)
2607 data
= read_uleb128 (data
+ 1, end
, &bytes
);
2610 fprintf_filtered (stream
, _("an empty %s-byte piece"),
2613 fprintf_filtered (stream
, _(" [%s-byte piece]"),
2616 else if (data
[0] == DW_OP_bit_piece
)
2618 ULONGEST bits
, offset
;
2620 data
= read_uleb128 (data
+ 1, end
, &bits
);
2621 data
= read_uleb128 (data
, end
, &offset
);
2624 fprintf_filtered (stream
,
2625 _("an empty %s-bit piece"),
2628 fprintf_filtered (stream
,
2629 _(" [%s-bit piece, offset %s bits]"),
2630 pulongest (bits
), pulongest (offset
));
2640 if (bad
|| data
> end
)
2641 error (_("Corrupted DWARF2 expression for \"%s\"."),
2642 SYMBOL_PRINT_NAME (symbol
));
2645 /* Print a natural-language description of SYMBOL to STREAM. This
2646 version is for a symbol with a single location. */
2649 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
2650 struct ui_file
*stream
)
2652 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2653 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2654 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2655 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
2657 locexpr_describe_location_1 (symbol
, addr
, stream
,
2658 dlbaton
->data
, dlbaton
->size
,
2659 objfile
, addr_size
, offset_size
);
2662 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2663 any necessary bytecode in AX. */
2666 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
2667 struct agent_expr
*ax
, struct axs_value
*value
)
2669 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2670 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2672 if (dlbaton
->data
== NULL
|| dlbaton
->size
== 0)
2673 value
->optimized_out
= 1;
2675 compile_dwarf_to_ax (ax
, value
, gdbarch
, addr_size
,
2676 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
2680 /* The set of location functions used with the DWARF-2 expression
2682 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
2683 locexpr_read_variable
,
2684 locexpr_read_needs_frame
,
2685 locexpr_describe_location
,
2686 locexpr_tracepoint_var_ref
2690 /* Wrapper functions for location lists. These generally find
2691 the appropriate location expression and call something above. */
2693 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2694 evaluator to calculate the location. */
2695 static struct value
*
2696 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
2698 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2700 const gdb_byte
*data
;
2702 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
2704 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
2707 val
= allocate_value (SYMBOL_TYPE (symbol
));
2708 VALUE_LVAL (val
) = not_lval
;
2709 set_value_optimized_out (val
, 1);
2712 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
2718 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2720 loclist_read_needs_frame (struct symbol
*symbol
)
2722 /* If there's a location list, then assume we need to have a frame
2723 to choose the appropriate location expression. With tracking of
2724 global variables this is not necessarily true, but such tracking
2725 is disabled in GCC at the moment until we figure out how to
2731 /* Print a natural-language description of SYMBOL to STREAM. This
2732 version applies when there is a list of different locations, each
2733 with a specified address range. */
2736 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
2737 struct ui_file
*stream
)
2739 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2740 CORE_ADDR low
, high
;
2741 const gdb_byte
*loc_ptr
, *buf_end
;
2742 int length
, first
= 1;
2743 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2744 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2745 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2746 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2747 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
2748 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
2749 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2750 /* Adjust base_address for relocatable objects. */
2751 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2752 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
2754 loc_ptr
= dlbaton
->data
;
2755 buf_end
= dlbaton
->data
+ dlbaton
->size
;
2757 fprintf_filtered (stream
, _("multi-location:\n"));
2759 /* Iterate through locations until we run out. */
2762 if (buf_end
- loc_ptr
< 2 * addr_size
)
2763 error (_("Corrupted DWARF expression for symbol \"%s\"."),
2764 SYMBOL_PRINT_NAME (symbol
));
2767 low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
2769 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
2770 loc_ptr
+= addr_size
;
2773 high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
2775 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
2776 loc_ptr
+= addr_size
;
2778 /* A base-address-selection entry. */
2779 if ((low
& base_mask
) == base_mask
)
2781 base_address
= high
+ base_offset
;
2782 fprintf_filtered (stream
, _(" Base address %s"),
2783 paddress (gdbarch
, base_address
));
2787 /* An end-of-list entry. */
2788 if (low
== 0 && high
== 0)
2791 /* Otherwise, a location expression entry. */
2792 low
+= base_address
;
2793 high
+= base_address
;
2795 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
2798 /* (It would improve readability to print only the minimum
2799 necessary digits of the second number of the range.) */
2800 fprintf_filtered (stream
, _(" Range %s-%s: "),
2801 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
2803 /* Now describe this particular location. */
2804 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
2805 objfile
, addr_size
, offset_size
);
2807 fprintf_filtered (stream
, "\n");
2813 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2814 any necessary bytecode in AX. */
2816 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
2817 struct agent_expr
*ax
, struct axs_value
*value
)
2819 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2820 const gdb_byte
*data
;
2822 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2824 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
2825 if (data
== NULL
|| size
== 0)
2826 value
->optimized_out
= 1;
2828 compile_dwarf_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
2832 /* The set of location functions used with the DWARF-2 expression
2833 evaluator and location lists. */
2834 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
2835 loclist_read_variable
,
2836 loclist_read_needs_frame
,
2837 loclist_describe_location
,
2838 loclist_tracepoint_var_ref