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
;
47 static void dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
48 const gdb_byte
**start
, size_t *length
);
50 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
51 struct frame_info
*frame
,
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 per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
286 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
289 /* Callback function for dwarf2_evaluate_loc_desc. */
292 dwarf_expr_get_base_type (struct dwarf_expr_context
*ctx
, size_t die_offset
)
294 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
296 return dwarf2_get_die_type (die_offset
, debaton
->per_cu
);
301 /* Reference count. */
304 /* The CU from which this closure's expression came. */
305 struct dwarf2_per_cu_data
*per_cu
;
307 /* The number of pieces used to describe this variable. */
310 /* The target address size, used only for DWARF_VALUE_STACK. */
313 /* The pieces themselves. */
314 struct dwarf_expr_piece
*pieces
;
317 /* Allocate a closure for a value formed from separately-described
320 static struct piece_closure
*
321 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
322 int n_pieces
, struct dwarf_expr_piece
*pieces
,
325 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
330 c
->n_pieces
= n_pieces
;
331 c
->addr_size
= addr_size
;
332 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
334 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
335 for (i
= 0; i
< n_pieces
; ++i
)
336 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
337 value_incref (c
->pieces
[i
].v
.value
);
342 /* The lowest-level function to extract bits from a byte buffer.
343 SOURCE is the buffer. It is updated if we read to the end of a
345 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
346 updated to reflect the number of bits actually read.
347 NBITS is the number of bits we want to read. It is updated to
348 reflect the number of bits actually read. This function may read
350 BITS_BIG_ENDIAN is taken directly from gdbarch.
351 This function returns the extracted bits. */
354 extract_bits_primitive (const gdb_byte
**source
,
355 unsigned int *source_offset_bits
,
356 int *nbits
, int bits_big_endian
)
358 unsigned int avail
, mask
, datum
;
360 gdb_assert (*source_offset_bits
< 8);
362 avail
= 8 - *source_offset_bits
;
366 mask
= (1 << avail
) - 1;
369 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
371 datum
>>= *source_offset_bits
;
375 *source_offset_bits
+= avail
;
376 if (*source_offset_bits
>= 8)
378 *source_offset_bits
-= 8;
385 /* Extract some bits from a source buffer and move forward in the
388 SOURCE is the source buffer. It is updated as bytes are read.
389 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
391 NBITS is the number of bits to read.
392 BITS_BIG_ENDIAN is taken directly from gdbarch.
394 This function returns the bits that were read. */
397 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
398 int nbits
, int bits_big_endian
)
402 gdb_assert (nbits
> 0 && nbits
<= 8);
404 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
410 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
422 /* Write some bits into a buffer and move forward in the buffer.
424 DATUM is the bits to write. The low-order bits of DATUM are used.
425 DEST is the destination buffer. It is updated as bytes are
427 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
429 NBITS is the number of valid bits in DATUM.
430 BITS_BIG_ENDIAN is taken directly from gdbarch. */
433 insert_bits (unsigned int datum
,
434 gdb_byte
*dest
, unsigned int dest_offset_bits
,
435 int nbits
, int bits_big_endian
)
439 gdb_assert (dest_offset_bits
+ nbits
<= 8);
441 mask
= (1 << nbits
) - 1;
444 datum
<<= 8 - (dest_offset_bits
+ nbits
);
445 mask
<<= 8 - (dest_offset_bits
+ nbits
);
449 datum
<<= dest_offset_bits
;
450 mask
<<= dest_offset_bits
;
453 gdb_assert ((datum
& ~mask
) == 0);
455 *dest
= (*dest
& ~mask
) | datum
;
458 /* Copy bits from a source to a destination.
460 DEST is where the bits should be written.
461 DEST_OFFSET_BITS is the bit offset into DEST.
462 SOURCE is the source of bits.
463 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
464 BIT_COUNT is the number of bits to copy.
465 BITS_BIG_ENDIAN is taken directly from gdbarch. */
468 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
469 const gdb_byte
*source
, unsigned int source_offset_bits
,
470 unsigned int bit_count
,
473 unsigned int dest_avail
;
476 /* Reduce everything to byte-size pieces. */
477 dest
+= dest_offset_bits
/ 8;
478 dest_offset_bits
%= 8;
479 source
+= source_offset_bits
/ 8;
480 source_offset_bits
%= 8;
482 dest_avail
= 8 - dest_offset_bits
% 8;
484 /* See if we can fill the first destination byte. */
485 if (dest_avail
< bit_count
)
487 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
489 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
491 dest_offset_bits
= 0;
492 bit_count
-= dest_avail
;
495 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
496 than 8 bits remaining. */
497 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
498 for (; bit_count
>= 8; bit_count
-= 8)
500 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
501 *dest
++ = (gdb_byte
) datum
;
504 /* Finally, we may have a few leftover bits. */
505 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
508 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
510 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
515 read_pieced_value (struct value
*v
)
519 ULONGEST bits_to_skip
;
521 struct piece_closure
*c
522 = (struct piece_closure
*) value_computed_closure (v
);
523 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
525 size_t buffer_size
= 0;
527 struct cleanup
*cleanup
;
529 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
531 if (value_type (v
) != value_enclosing_type (v
))
532 internal_error (__FILE__
, __LINE__
,
533 _("Should not be able to create a lazy value with "
534 "an enclosing type"));
536 cleanup
= make_cleanup (free_current_contents
, &buffer
);
538 contents
= value_contents_raw (v
);
539 bits_to_skip
= 8 * value_offset (v
);
540 if (value_bitsize (v
))
542 bits_to_skip
+= value_bitpos (v
);
543 type_len
= value_bitsize (v
);
546 type_len
= 8 * TYPE_LENGTH (value_type (v
));
548 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
550 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
551 size_t this_size
, this_size_bits
;
552 long dest_offset_bits
, source_offset_bits
, source_offset
;
553 const gdb_byte
*intermediate_buffer
;
555 /* Compute size, source, and destination offsets for copying, in
557 this_size_bits
= p
->size
;
558 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
560 bits_to_skip
-= this_size_bits
;
563 if (this_size_bits
> type_len
- offset
)
564 this_size_bits
= type_len
- offset
;
565 if (bits_to_skip
> 0)
567 dest_offset_bits
= 0;
568 source_offset_bits
= bits_to_skip
;
569 this_size_bits
-= bits_to_skip
;
574 dest_offset_bits
= offset
;
575 source_offset_bits
= 0;
578 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
579 source_offset
= source_offset_bits
/ 8;
580 if (buffer_size
< this_size
)
582 buffer_size
= this_size
;
583 buffer
= xrealloc (buffer
, buffer_size
);
585 intermediate_buffer
= buffer
;
587 /* Copy from the source to DEST_BUFFER. */
590 case DWARF_VALUE_REGISTER
:
592 struct gdbarch
*arch
= get_frame_arch (frame
);
593 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
594 int reg_offset
= source_offset
;
596 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
597 && this_size
< register_size (arch
, gdb_regnum
))
599 /* Big-endian, and we want less than full size. */
600 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
601 /* We want the lower-order THIS_SIZE_BITS of the bytes
602 we extract from the register. */
603 source_offset_bits
+= 8 * this_size
- this_size_bits
;
606 if (gdb_regnum
!= -1)
610 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
614 /* Just so garbage doesn't ever shine through. */
615 memset (buffer
, 0, this_size
);
618 set_value_optimized_out (v
, 1);
620 mark_value_bytes_unavailable (v
, offset
, this_size
);
625 error (_("Unable to access DWARF register number %s"),
626 paddress (arch
, p
->v
.regno
));
631 case DWARF_VALUE_MEMORY
:
632 read_value_memory (v
, offset
,
633 p
->v
.mem
.in_stack_memory
,
634 p
->v
.mem
.addr
+ source_offset
,
638 case DWARF_VALUE_STACK
:
640 size_t n
= this_size
;
642 if (n
> c
->addr_size
- source_offset
)
643 n
= (c
->addr_size
>= source_offset
644 ? c
->addr_size
- source_offset
652 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
654 intermediate_buffer
= val_bytes
+ source_offset
;
659 case DWARF_VALUE_LITERAL
:
661 size_t n
= this_size
;
663 if (n
> p
->v
.literal
.length
- source_offset
)
664 n
= (p
->v
.literal
.length
>= source_offset
665 ? p
->v
.literal
.length
- source_offset
668 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
672 /* These bits show up as zeros -- but do not cause the value
673 to be considered optimized-out. */
674 case DWARF_VALUE_IMPLICIT_POINTER
:
677 case DWARF_VALUE_OPTIMIZED_OUT
:
678 set_value_optimized_out (v
, 1);
682 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
685 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
686 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
687 copy_bitwise (contents
, dest_offset_bits
,
688 intermediate_buffer
, source_offset_bits
% 8,
689 this_size_bits
, bits_big_endian
);
691 offset
+= this_size_bits
;
694 do_cleanups (cleanup
);
698 write_pieced_value (struct value
*to
, struct value
*from
)
702 ULONGEST bits_to_skip
;
703 const gdb_byte
*contents
;
704 struct piece_closure
*c
705 = (struct piece_closure
*) value_computed_closure (to
);
706 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
708 size_t buffer_size
= 0;
710 struct cleanup
*cleanup
;
712 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
716 set_value_optimized_out (to
, 1);
720 cleanup
= make_cleanup (free_current_contents
, &buffer
);
722 contents
= value_contents (from
);
723 bits_to_skip
= 8 * value_offset (to
);
724 if (value_bitsize (to
))
726 bits_to_skip
+= value_bitpos (to
);
727 type_len
= value_bitsize (to
);
730 type_len
= 8 * TYPE_LENGTH (value_type (to
));
732 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
734 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
735 size_t this_size_bits
, this_size
;
736 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
738 const gdb_byte
*source_buffer
;
740 this_size_bits
= p
->size
;
741 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
743 bits_to_skip
-= this_size_bits
;
746 if (this_size_bits
> type_len
- offset
)
747 this_size_bits
= type_len
- offset
;
748 if (bits_to_skip
> 0)
750 dest_offset_bits
= bits_to_skip
;
751 source_offset_bits
= 0;
752 this_size_bits
-= bits_to_skip
;
757 dest_offset_bits
= 0;
758 source_offset_bits
= offset
;
761 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
762 source_offset
= source_offset_bits
/ 8;
763 dest_offset
= dest_offset_bits
/ 8;
764 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
766 source_buffer
= contents
+ source_offset
;
771 if (buffer_size
< this_size
)
773 buffer_size
= this_size
;
774 buffer
= xrealloc (buffer
, buffer_size
);
776 source_buffer
= buffer
;
782 case DWARF_VALUE_REGISTER
:
784 struct gdbarch
*arch
= get_frame_arch (frame
);
785 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
786 int reg_offset
= dest_offset
;
788 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
789 && this_size
<= register_size (arch
, gdb_regnum
))
790 /* Big-endian, and we want less than full size. */
791 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
793 if (gdb_regnum
!= -1)
799 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
804 error (_("Can't do read-modify-write to "
805 "update bitfield; containing word has been "
808 throw_error (NOT_AVAILABLE_ERROR
,
809 _("Can't do read-modify-write to update "
810 "bitfield; containing word "
813 copy_bitwise (buffer
, dest_offset_bits
,
814 contents
, source_offset_bits
,
819 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
820 this_size
, source_buffer
);
824 error (_("Unable to write to DWARF register number %s"),
825 paddress (arch
, p
->v
.regno
));
829 case DWARF_VALUE_MEMORY
:
832 /* Only the first and last bytes can possibly have any
834 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
835 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
836 buffer
+ this_size
- 1, 1);
837 copy_bitwise (buffer
, dest_offset_bits
,
838 contents
, source_offset_bits
,
843 write_memory (p
->v
.mem
.addr
+ dest_offset
,
844 source_buffer
, this_size
);
847 set_value_optimized_out (to
, 1);
850 offset
+= this_size_bits
;
853 do_cleanups (cleanup
);
856 /* A helper function that checks bit validity in a pieced value.
857 CHECK_FOR indicates the kind of validity checking.
858 DWARF_VALUE_MEMORY means to check whether any bit is valid.
859 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
861 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
865 check_pieced_value_bits (const struct value
*value
, int bit_offset
,
867 enum dwarf_value_location check_for
)
869 struct piece_closure
*c
870 = (struct piece_closure
*) value_computed_closure (value
);
872 int validity
= (check_for
== DWARF_VALUE_MEMORY
873 || check_for
== DWARF_VALUE_IMPLICIT_POINTER
);
875 bit_offset
+= 8 * value_offset (value
);
876 if (value_bitsize (value
))
877 bit_offset
+= value_bitpos (value
);
879 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
881 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
882 size_t this_size_bits
= p
->size
;
886 if (bit_offset
>= this_size_bits
)
888 bit_offset
-= this_size_bits
;
892 bit_length
-= this_size_bits
- bit_offset
;
896 bit_length
-= this_size_bits
;
898 if (check_for
== DWARF_VALUE_IMPLICIT_POINTER
)
900 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
903 else if (p
->location
== DWARF_VALUE_OPTIMIZED_OUT
904 || p
->location
== DWARF_VALUE_IMPLICIT_POINTER
)
920 check_pieced_value_validity (const struct value
*value
, int bit_offset
,
923 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
928 check_pieced_value_invalid (const struct value
*value
)
930 return check_pieced_value_bits (value
, 0,
931 8 * TYPE_LENGTH (value_type (value
)),
932 DWARF_VALUE_OPTIMIZED_OUT
);
935 /* An implementation of an lval_funcs method to see whether a value is
936 a synthetic pointer. */
939 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
942 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
943 DWARF_VALUE_IMPLICIT_POINTER
);
946 /* A wrapper function for get_frame_address_in_block. */
949 get_frame_address_in_block_wrapper (void *baton
)
951 return get_frame_address_in_block (baton
);
954 /* An implementation of an lval_funcs method to indirect through a
955 pointer. This handles the synthetic pointer case when needed. */
957 static struct value
*
958 indirect_pieced_value (struct value
*value
)
960 struct piece_closure
*c
961 = (struct piece_closure
*) value_computed_closure (value
);
963 struct frame_info
*frame
;
964 struct dwarf2_locexpr_baton baton
;
965 int i
, bit_offset
, bit_length
;
966 struct dwarf_expr_piece
*piece
= NULL
;
969 type
= check_typedef (value_type (value
));
970 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
973 bit_length
= 8 * TYPE_LENGTH (type
);
974 bit_offset
= 8 * value_offset (value
);
975 if (value_bitsize (value
))
976 bit_offset
+= value_bitpos (value
);
978 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
980 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
981 size_t this_size_bits
= p
->size
;
985 if (bit_offset
>= this_size_bits
)
987 bit_offset
-= this_size_bits
;
991 bit_length
-= this_size_bits
- bit_offset
;
995 bit_length
-= this_size_bits
;
997 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1000 if (bit_length
!= 0)
1001 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
1007 frame
= get_selected_frame (_("No frame selected."));
1009 /* This is an offset requested by GDB, such as value subcripts. */
1010 byte_offset
= value_as_address (value
);
1013 baton
= dwarf2_fetch_die_location_block (piece
->v
.ptr
.die
, c
->per_cu
,
1014 get_frame_address_in_block_wrapper
,
1017 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
1018 baton
.data
, baton
.size
, baton
.per_cu
,
1019 piece
->v
.ptr
.offset
+ byte_offset
);
1023 copy_pieced_value_closure (const struct value
*v
)
1025 struct piece_closure
*c
1026 = (struct piece_closure
*) value_computed_closure (v
);
1033 free_pieced_value_closure (struct value
*v
)
1035 struct piece_closure
*c
1036 = (struct piece_closure
*) value_computed_closure (v
);
1043 for (i
= 0; i
< c
->n_pieces
; ++i
)
1044 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1045 value_free (c
->pieces
[i
].v
.value
);
1052 /* Functions for accessing a variable described by DW_OP_piece. */
1053 static const struct lval_funcs pieced_value_funcs
= {
1056 check_pieced_value_validity
,
1057 check_pieced_value_invalid
,
1058 indirect_pieced_value
,
1059 check_pieced_synthetic_pointer
,
1060 copy_pieced_value_closure
,
1061 free_pieced_value_closure
1064 /* Helper function which throws an error if a synthetic pointer is
1068 invalid_synthetic_pointer (void)
1070 error (_("access outside bounds of object "
1071 "referenced via synthetic pointer"));
1074 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
1076 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
1078 dwarf_expr_read_reg
,
1079 dwarf_expr_read_mem
,
1080 dwarf_expr_frame_base
,
1081 dwarf_expr_frame_cfa
,
1082 dwarf_expr_frame_pc
,
1083 dwarf_expr_tls_address
,
1084 dwarf_expr_dwarf_call
,
1085 dwarf_expr_get_base_type
1088 /* Evaluate a location description, starting at DATA and with length
1089 SIZE, to find the current location of variable of TYPE in the
1090 context of FRAME. BYTE_OFFSET is applied after the contents are
1093 static struct value
*
1094 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1095 const gdb_byte
*data
, unsigned short size
,
1096 struct dwarf2_per_cu_data
*per_cu
,
1097 LONGEST byte_offset
)
1099 struct value
*retval
;
1100 struct dwarf_expr_baton baton
;
1101 struct dwarf_expr_context
*ctx
;
1102 struct cleanup
*old_chain
, *value_chain
;
1103 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
1104 volatile struct gdb_exception ex
;
1106 if (byte_offset
< 0)
1107 invalid_synthetic_pointer ();
1110 return allocate_optimized_out_value (type
);
1112 baton
.frame
= frame
;
1113 baton
.per_cu
= per_cu
;
1115 ctx
= new_dwarf_expr_context ();
1116 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
1117 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
1119 ctx
->gdbarch
= get_objfile_arch (objfile
);
1120 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
1121 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
1122 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
1123 ctx
->baton
= &baton
;
1124 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
1126 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1128 dwarf_expr_eval (ctx
, data
, size
);
1132 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1134 do_cleanups (old_chain
);
1135 retval
= allocate_value (type
);
1136 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
1140 throw_exception (ex
);
1143 if (ctx
->num_pieces
> 0)
1145 struct piece_closure
*c
;
1146 struct frame_id frame_id
= get_frame_id (frame
);
1147 ULONGEST bit_size
= 0;
1150 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
1151 bit_size
+= ctx
->pieces
[i
].size
;
1152 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
1153 invalid_synthetic_pointer ();
1155 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
1157 /* We must clean up the value chain after creating the piece
1158 closure but before allocating the result. */
1159 do_cleanups (value_chain
);
1160 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
1161 VALUE_FRAME_ID (retval
) = frame_id
;
1162 set_value_offset (retval
, byte_offset
);
1166 switch (ctx
->location
)
1168 case DWARF_VALUE_REGISTER
:
1170 struct gdbarch
*arch
= get_frame_arch (frame
);
1171 ULONGEST dwarf_regnum
= value_as_long (dwarf_expr_fetch (ctx
, 0));
1172 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
1174 if (byte_offset
!= 0)
1175 error (_("cannot use offset on synthetic pointer to register"));
1176 do_cleanups (value_chain
);
1177 if (gdb_regnum
!= -1)
1178 retval
= value_from_register (type
, gdb_regnum
, frame
);
1180 error (_("Unable to access DWARF register number %s"),
1181 paddress (arch
, dwarf_regnum
));
1185 case DWARF_VALUE_MEMORY
:
1187 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
1188 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
1190 do_cleanups (value_chain
);
1191 retval
= allocate_value_lazy (type
);
1192 VALUE_LVAL (retval
) = lval_memory
;
1193 if (in_stack_memory
)
1194 set_value_stack (retval
, 1);
1195 set_value_address (retval
, address
+ byte_offset
);
1199 case DWARF_VALUE_STACK
:
1201 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
1203 const gdb_byte
*val_bytes
;
1204 size_t n
= TYPE_LENGTH (value_type (value
));
1206 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1207 invalid_synthetic_pointer ();
1209 val_bytes
= value_contents_all (value
);
1210 val_bytes
+= byte_offset
;
1213 /* Preserve VALUE because we are going to free values back
1214 to the mark, but we still need the value contents
1216 value_incref (value
);
1217 do_cleanups (value_chain
);
1218 make_cleanup_value_free (value
);
1220 retval
= allocate_value (type
);
1221 contents
= value_contents_raw (retval
);
1222 if (n
> TYPE_LENGTH (type
))
1224 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1226 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1227 val_bytes
+= n
- TYPE_LENGTH (type
);
1228 n
= TYPE_LENGTH (type
);
1230 memcpy (contents
, val_bytes
, n
);
1234 case DWARF_VALUE_LITERAL
:
1237 const bfd_byte
*ldata
;
1238 size_t n
= ctx
->len
;
1240 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1241 invalid_synthetic_pointer ();
1243 do_cleanups (value_chain
);
1244 retval
= allocate_value (type
);
1245 contents
= value_contents_raw (retval
);
1247 ldata
= ctx
->data
+ byte_offset
;
1250 if (n
> TYPE_LENGTH (type
))
1252 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1254 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1255 ldata
+= n
- TYPE_LENGTH (type
);
1256 n
= TYPE_LENGTH (type
);
1258 memcpy (contents
, ldata
, n
);
1262 case DWARF_VALUE_OPTIMIZED_OUT
:
1263 do_cleanups (value_chain
);
1264 retval
= allocate_optimized_out_value (type
);
1267 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1268 operation by execute_stack_op. */
1269 case DWARF_VALUE_IMPLICIT_POINTER
:
1270 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1271 it can only be encountered when making a piece. */
1273 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1277 set_value_initialized (retval
, ctx
->initialized
);
1279 do_cleanups (old_chain
);
1284 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1285 passes 0 as the byte_offset. */
1288 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1289 const gdb_byte
*data
, unsigned short size
,
1290 struct dwarf2_per_cu_data
*per_cu
)
1292 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
1296 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1298 struct needs_frame_baton
1301 struct dwarf2_per_cu_data
*per_cu
;
1304 /* Reads from registers do require a frame. */
1306 needs_frame_read_reg (void *baton
, int regnum
)
1308 struct needs_frame_baton
*nf_baton
= baton
;
1310 nf_baton
->needs_frame
= 1;
1314 /* Reads from memory do not require a frame. */
1316 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
1318 memset (buf
, 0, len
);
1321 /* Frame-relative accesses do require a frame. */
1323 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
1325 static gdb_byte lit0
= DW_OP_lit0
;
1326 struct needs_frame_baton
*nf_baton
= baton
;
1331 nf_baton
->needs_frame
= 1;
1334 /* CFA accesses require a frame. */
1337 needs_frame_frame_cfa (void *baton
)
1339 struct needs_frame_baton
*nf_baton
= baton
;
1341 nf_baton
->needs_frame
= 1;
1345 /* Thread-local accesses do require a frame. */
1347 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
1349 struct needs_frame_baton
*nf_baton
= baton
;
1351 nf_baton
->needs_frame
= 1;
1355 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
1358 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, size_t die_offset
)
1360 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
1362 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
1363 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
1366 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
1368 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs
=
1370 needs_frame_read_reg
,
1371 needs_frame_read_mem
,
1372 needs_frame_frame_base
,
1373 needs_frame_frame_cfa
,
1374 needs_frame_frame_cfa
, /* get_frame_pc */
1375 needs_frame_tls_address
,
1376 needs_frame_dwarf_call
,
1377 NULL
/* get_base_type */
1380 /* Return non-zero iff the location expression at DATA (length SIZE)
1381 requires a frame to evaluate. */
1384 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, unsigned short size
,
1385 struct dwarf2_per_cu_data
*per_cu
)
1387 struct needs_frame_baton baton
;
1388 struct dwarf_expr_context
*ctx
;
1390 struct cleanup
*old_chain
;
1391 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
1393 baton
.needs_frame
= 0;
1394 baton
.per_cu
= per_cu
;
1396 ctx
= new_dwarf_expr_context ();
1397 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
1398 make_cleanup_value_free_to_mark (value_mark ());
1400 ctx
->gdbarch
= get_objfile_arch (objfile
);
1401 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
1402 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
1403 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
1404 ctx
->baton
= &baton
;
1405 ctx
->funcs
= &needs_frame_ctx_funcs
;
1407 dwarf_expr_eval (ctx
, data
, size
);
1409 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
1411 if (ctx
->num_pieces
> 0)
1415 /* If the location has several pieces, and any of them are in
1416 registers, then we will need a frame to fetch them from. */
1417 for (i
= 0; i
< ctx
->num_pieces
; i
++)
1418 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
1422 do_cleanups (old_chain
);
1424 return baton
.needs_frame
|| in_reg
;
1427 /* A helper function that throws an unimplemented error mentioning a
1428 given DWARF operator. */
1431 unimplemented (unsigned int op
)
1433 const char *name
= dwarf_stack_op_name (op
);
1436 error (_("DWARF operator %s cannot be translated to an agent expression"),
1439 error (_("Unknown DWARF operator 0x%02x cannot be translated "
1440 "to an agent expression"),
1444 /* A helper function to convert a DWARF register to an arch register.
1445 ARCH is the architecture.
1446 DWARF_REG is the register.
1447 This will throw an exception if the DWARF register cannot be
1448 translated to an architecture register. */
1451 translate_register (struct gdbarch
*arch
, int dwarf_reg
)
1453 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
1455 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
1459 /* A helper function that emits an access to memory. ARCH is the
1460 target architecture. EXPR is the expression which we are building.
1461 NBITS is the number of bits we want to read. This emits the
1462 opcodes needed to read the memory and then extract the desired
1466 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
1468 ULONGEST nbytes
= (nbits
+ 7) / 8;
1470 gdb_assert (nbits
> 0 && nbits
<= sizeof (LONGEST
));
1473 ax_trace_quick (expr
, nbytes
);
1476 ax_simple (expr
, aop_ref8
);
1477 else if (nbits
<= 16)
1478 ax_simple (expr
, aop_ref16
);
1479 else if (nbits
<= 32)
1480 ax_simple (expr
, aop_ref32
);
1482 ax_simple (expr
, aop_ref64
);
1484 /* If we read exactly the number of bytes we wanted, we're done. */
1485 if (8 * nbytes
== nbits
)
1488 if (gdbarch_bits_big_endian (arch
))
1490 /* On a bits-big-endian machine, we want the high-order
1492 ax_const_l (expr
, 8 * nbytes
- nbits
);
1493 ax_simple (expr
, aop_rsh_unsigned
);
1497 /* On a bits-little-endian box, we want the low-order NBITS. */
1498 ax_zero_ext (expr
, nbits
);
1502 /* A helper function to return the frame's PC. */
1505 get_ax_pc (void *baton
)
1507 struct agent_expr
*expr
= baton
;
1512 /* Compile a DWARF location expression to an agent expression.
1514 EXPR is the agent expression we are building.
1515 LOC is the agent value we modify.
1516 ARCH is the architecture.
1517 ADDR_SIZE is the size of addresses, in bytes.
1518 OP_PTR is the start of the location expression.
1519 OP_END is one past the last byte of the location expression.
1521 This will throw an exception for various kinds of errors -- for
1522 example, if the expression cannot be compiled, or if the expression
1526 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
1527 struct gdbarch
*arch
, unsigned int addr_size
,
1528 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
1529 struct dwarf2_per_cu_data
*per_cu
)
1531 struct cleanup
*cleanups
;
1533 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
1534 const gdb_byte
* const base
= op_ptr
;
1535 const gdb_byte
*previous_piece
= op_ptr
;
1536 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
1537 ULONGEST bits_collected
= 0;
1538 unsigned int addr_size_bits
= 8 * addr_size
;
1539 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
1541 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
1542 cleanups
= make_cleanup (xfree
, offsets
);
1544 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
1547 make_cleanup (VEC_cleanup (int), &dw_labels
);
1548 make_cleanup (VEC_cleanup (int), &patches
);
1550 /* By default we are making an address. */
1551 loc
->kind
= axs_lvalue_memory
;
1553 while (op_ptr
< op_end
)
1555 enum dwarf_location_atom op
= *op_ptr
;
1556 ULONGEST uoffset
, reg
;
1560 offsets
[op_ptr
- base
] = expr
->len
;
1563 /* Our basic approach to code generation is to map DWARF
1564 operations directly to AX operations. However, there are
1567 First, DWARF works on address-sized units, but AX always uses
1568 LONGEST. For most operations we simply ignore this
1569 difference; instead we generate sign extensions as needed
1570 before division and comparison operations. It would be nice
1571 to omit the sign extensions, but there is no way to determine
1572 the size of the target's LONGEST. (This code uses the size
1573 of the host LONGEST in some cases -- that is a bug but it is
1576 Second, some DWARF operations cannot be translated to AX.
1577 For these we simply fail. See
1578 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
1613 ax_const_l (expr
, op
- DW_OP_lit0
);
1617 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
1618 op_ptr
+= addr_size
;
1619 /* Some versions of GCC emit DW_OP_addr before
1620 DW_OP_GNU_push_tls_address. In this case the value is an
1621 index, not an address. We don't support things like
1622 branching between the address and the TLS op. */
1623 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
1624 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
1625 ax_const_l (expr
, uoffset
);
1629 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
1633 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
1637 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
1641 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
1645 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
1649 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
1653 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
1657 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
1661 op_ptr
= read_uleb128 (op_ptr
, op_end
, &uoffset
);
1662 ax_const_l (expr
, uoffset
);
1665 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1666 ax_const_l (expr
, offset
);
1701 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
1702 loc
->u
.reg
= translate_register (arch
, op
- DW_OP_reg0
);
1703 loc
->kind
= axs_lvalue_register
;
1707 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1708 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
1709 loc
->u
.reg
= translate_register (arch
, reg
);
1710 loc
->kind
= axs_lvalue_register
;
1713 case DW_OP_implicit_value
:
1717 op_ptr
= read_uleb128 (op_ptr
, op_end
, &len
);
1718 if (op_ptr
+ len
> op_end
)
1719 error (_("DW_OP_implicit_value: too few bytes available."));
1720 if (len
> sizeof (ULONGEST
))
1721 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
1724 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
1727 dwarf_expr_require_composition (op_ptr
, op_end
,
1728 "DW_OP_implicit_value");
1730 loc
->kind
= axs_rvalue
;
1734 case DW_OP_stack_value
:
1735 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
1736 loc
->kind
= axs_rvalue
;
1771 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1772 i
= translate_register (arch
, op
- DW_OP_breg0
);
1776 ax_const_l (expr
, offset
);
1777 ax_simple (expr
, aop_add
);
1782 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1783 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1784 i
= translate_register (arch
, reg
);
1788 ax_const_l (expr
, offset
);
1789 ax_simple (expr
, aop_add
);
1795 const gdb_byte
*datastart
;
1797 unsigned int before_stack_len
;
1799 struct symbol
*framefunc
;
1800 LONGEST base_offset
= 0;
1802 b
= block_for_pc (expr
->scope
);
1805 error (_("No block found for address"));
1807 framefunc
= block_linkage_function (b
);
1810 error (_("No function found for block"));
1812 dwarf_expr_frame_base_1 (framefunc
, expr
->scope
,
1813 &datastart
, &datalen
);
1815 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
1816 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
1817 datastart
+ datalen
, per_cu
);
1821 ax_const_l (expr
, offset
);
1822 ax_simple (expr
, aop_add
);
1825 loc
->kind
= axs_lvalue_memory
;
1830 ax_simple (expr
, aop_dup
);
1834 ax_simple (expr
, aop_pop
);
1839 ax_pick (expr
, offset
);
1843 ax_simple (expr
, aop_swap
);
1851 ax_simple (expr
, aop_rot
);
1855 case DW_OP_deref_size
:
1859 if (op
== DW_OP_deref_size
)
1867 ax_simple (expr
, aop_ref8
);
1870 ax_simple (expr
, aop_ref16
);
1873 ax_simple (expr
, aop_ref32
);
1876 ax_simple (expr
, aop_ref64
);
1879 /* Note that dwarf_stack_op_name will never return
1881 error (_("Unsupported size %d in %s"),
1882 size
, dwarf_stack_op_name (op
));
1888 /* Sign extend the operand. */
1889 ax_ext (expr
, addr_size_bits
);
1890 ax_simple (expr
, aop_dup
);
1891 ax_const_l (expr
, 0);
1892 ax_simple (expr
, aop_less_signed
);
1893 ax_simple (expr
, aop_log_not
);
1894 i
= ax_goto (expr
, aop_if_goto
);
1895 /* We have to emit 0 - X. */
1896 ax_const_l (expr
, 0);
1897 ax_simple (expr
, aop_swap
);
1898 ax_simple (expr
, aop_sub
);
1899 ax_label (expr
, i
, expr
->len
);
1903 /* No need to sign extend here. */
1904 ax_const_l (expr
, 0);
1905 ax_simple (expr
, aop_swap
);
1906 ax_simple (expr
, aop_sub
);
1910 /* Sign extend the operand. */
1911 ax_ext (expr
, addr_size_bits
);
1912 ax_simple (expr
, aop_bit_not
);
1915 case DW_OP_plus_uconst
:
1916 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
1917 /* It would be really weird to emit `DW_OP_plus_uconst 0',
1918 but we micro-optimize anyhow. */
1921 ax_const_l (expr
, reg
);
1922 ax_simple (expr
, aop_add
);
1927 ax_simple (expr
, aop_bit_and
);
1931 /* Sign extend the operands. */
1932 ax_ext (expr
, addr_size_bits
);
1933 ax_simple (expr
, aop_swap
);
1934 ax_ext (expr
, addr_size_bits
);
1935 ax_simple (expr
, aop_swap
);
1936 ax_simple (expr
, aop_div_signed
);
1940 ax_simple (expr
, aop_sub
);
1944 ax_simple (expr
, aop_rem_unsigned
);
1948 ax_simple (expr
, aop_mul
);
1952 ax_simple (expr
, aop_bit_or
);
1956 ax_simple (expr
, aop_add
);
1960 ax_simple (expr
, aop_lsh
);
1964 ax_simple (expr
, aop_rsh_unsigned
);
1968 ax_simple (expr
, aop_rsh_signed
);
1972 ax_simple (expr
, aop_bit_xor
);
1976 /* Sign extend the operands. */
1977 ax_ext (expr
, addr_size_bits
);
1978 ax_simple (expr
, aop_swap
);
1979 ax_ext (expr
, addr_size_bits
);
1980 /* Note no swap here: A <= B is !(B < A). */
1981 ax_simple (expr
, aop_less_signed
);
1982 ax_simple (expr
, aop_log_not
);
1986 /* Sign extend the operands. */
1987 ax_ext (expr
, addr_size_bits
);
1988 ax_simple (expr
, aop_swap
);
1989 ax_ext (expr
, addr_size_bits
);
1990 ax_simple (expr
, aop_swap
);
1991 /* A >= B is !(A < B). */
1992 ax_simple (expr
, aop_less_signed
);
1993 ax_simple (expr
, aop_log_not
);
1997 /* Sign extend the operands. */
1998 ax_ext (expr
, addr_size_bits
);
1999 ax_simple (expr
, aop_swap
);
2000 ax_ext (expr
, addr_size_bits
);
2001 /* No need for a second swap here. */
2002 ax_simple (expr
, aop_equal
);
2006 /* Sign extend the operands. */
2007 ax_ext (expr
, addr_size_bits
);
2008 ax_simple (expr
, aop_swap
);
2009 ax_ext (expr
, addr_size_bits
);
2010 ax_simple (expr
, aop_swap
);
2011 ax_simple (expr
, aop_less_signed
);
2015 /* Sign extend the operands. */
2016 ax_ext (expr
, addr_size_bits
);
2017 ax_simple (expr
, aop_swap
);
2018 ax_ext (expr
, addr_size_bits
);
2019 /* Note no swap here: A > B is B < A. */
2020 ax_simple (expr
, aop_less_signed
);
2024 /* Sign extend the operands. */
2025 ax_ext (expr
, addr_size_bits
);
2026 ax_simple (expr
, aop_swap
);
2027 ax_ext (expr
, addr_size_bits
);
2028 /* No need for a swap here. */
2029 ax_simple (expr
, aop_equal
);
2030 ax_simple (expr
, aop_log_not
);
2033 case DW_OP_call_frame_cfa
:
2034 dwarf2_compile_cfa_to_ax (expr
, loc
, arch
, expr
->scope
, per_cu
);
2035 loc
->kind
= axs_lvalue_memory
;
2038 case DW_OP_GNU_push_tls_address
:
2043 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2045 i
= ax_goto (expr
, aop_goto
);
2046 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
2047 VEC_safe_push (int, patches
, i
);
2051 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2053 /* Zero extend the operand. */
2054 ax_zero_ext (expr
, addr_size_bits
);
2055 i
= ax_goto (expr
, aop_if_goto
);
2056 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
2057 VEC_safe_push (int, patches
, i
);
2064 case DW_OP_bit_piece
:
2066 ULONGEST size
, offset
;
2068 if (op_ptr
- 1 == previous_piece
)
2069 error (_("Cannot translate empty pieces to agent expressions"));
2070 previous_piece
= op_ptr
- 1;
2072 op_ptr
= read_uleb128 (op_ptr
, op_end
, &size
);
2073 if (op
== DW_OP_piece
)
2079 op_ptr
= read_uleb128 (op_ptr
, op_end
, &offset
);
2081 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2082 error (_("Expression pieces exceed word size"));
2084 /* Access the bits. */
2087 case axs_lvalue_register
:
2088 ax_reg (expr
, loc
->u
.reg
);
2091 case axs_lvalue_memory
:
2092 /* Offset the pointer, if needed. */
2095 ax_const_l (expr
, offset
/ 8);
2096 ax_simple (expr
, aop_add
);
2099 access_memory (arch
, expr
, size
);
2103 /* For a bits-big-endian target, shift up what we already
2104 have. For a bits-little-endian target, shift up the
2105 new data. Note that there is a potential bug here if
2106 the DWARF expression leaves multiple values on the
2108 if (bits_collected
> 0)
2110 if (bits_big_endian
)
2112 ax_simple (expr
, aop_swap
);
2113 ax_const_l (expr
, size
);
2114 ax_simple (expr
, aop_lsh
);
2115 /* We don't need a second swap here, because
2116 aop_bit_or is symmetric. */
2120 ax_const_l (expr
, size
);
2121 ax_simple (expr
, aop_lsh
);
2123 ax_simple (expr
, aop_bit_or
);
2126 bits_collected
+= size
;
2127 loc
->kind
= axs_rvalue
;
2131 case DW_OP_GNU_uninit
:
2137 struct dwarf2_locexpr_baton block
;
2138 int size
= (op
== DW_OP_call2
? 2 : 4);
2140 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2143 block
= dwarf2_fetch_die_location_block (uoffset
, per_cu
,
2146 /* DW_OP_call_ref is currently not supported. */
2147 gdb_assert (block
.per_cu
== per_cu
);
2149 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
2150 block
.data
, block
.data
+ block
.size
,
2155 case DW_OP_call_ref
:
2163 /* Patch all the branches we emitted. */
2164 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
2166 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
2168 internal_error (__FILE__
, __LINE__
, _("invalid label"));
2169 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
2172 do_cleanups (cleanups
);
2176 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2177 evaluator to calculate the location. */
2178 static struct value
*
2179 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
2181 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2184 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
2185 dlbaton
->size
, dlbaton
->per_cu
);
2190 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2192 locexpr_read_needs_frame (struct symbol
*symbol
)
2194 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2196 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
2200 /* Return true if DATA points to the end of a piece. END is one past
2201 the last byte in the expression. */
2204 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
2206 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
2209 /* Helper for locexpr_describe_location_piece that finds the name of a
2213 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
2217 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
2218 return gdbarch_register_name (gdbarch
, regnum
);
2221 /* Nicely describe a single piece of a location, returning an updated
2222 position in the bytecode sequence. This function cannot recognize
2223 all locations; if a location is not recognized, it simply returns
2226 static const gdb_byte
*
2227 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
2228 CORE_ADDR addr
, struct objfile
*objfile
,
2229 const gdb_byte
*data
, const gdb_byte
*end
,
2230 unsigned int addr_size
)
2232 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2234 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
2236 fprintf_filtered (stream
, _("a variable in $%s"),
2237 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
2240 else if (data
[0] == DW_OP_regx
)
2244 data
= read_uleb128 (data
+ 1, end
, ®
);
2245 fprintf_filtered (stream
, _("a variable in $%s"),
2246 locexpr_regname (gdbarch
, reg
));
2248 else if (data
[0] == DW_OP_fbreg
)
2251 struct symbol
*framefunc
;
2253 LONGEST frame_offset
;
2254 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
2256 LONGEST base_offset
= 0;
2258 new_data
= read_sleb128 (data
+ 1, end
, &frame_offset
);
2259 if (!piece_end_p (new_data
, end
))
2263 b
= block_for_pc (addr
);
2266 error (_("No block found for address for symbol \"%s\"."),
2267 SYMBOL_PRINT_NAME (symbol
));
2269 framefunc
= block_linkage_function (b
);
2272 error (_("No function found for block for symbol \"%s\"."),
2273 SYMBOL_PRINT_NAME (symbol
));
2275 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
2277 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
2279 const gdb_byte
*buf_end
;
2281 frame_reg
= base_data
[0] - DW_OP_breg0
;
2282 buf_end
= read_sleb128 (base_data
+ 1,
2283 base_data
+ base_size
, &base_offset
);
2284 if (buf_end
!= base_data
+ base_size
)
2285 error (_("Unexpected opcode after "
2286 "DW_OP_breg%u for symbol \"%s\"."),
2287 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
2289 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
2291 /* The frame base is just the register, with no offset. */
2292 frame_reg
= base_data
[0] - DW_OP_reg0
;
2297 /* We don't know what to do with the frame base expression,
2298 so we can't trace this variable; give up. */
2302 fprintf_filtered (stream
,
2303 _("a variable at frame base reg $%s offset %s+%s"),
2304 locexpr_regname (gdbarch
, frame_reg
),
2305 plongest (base_offset
), plongest (frame_offset
));
2307 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
2308 && piece_end_p (data
, end
))
2312 data
= read_sleb128 (data
+ 1, end
, &offset
);
2314 fprintf_filtered (stream
,
2315 _("a variable at offset %s from base reg $%s"),
2317 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
2320 /* The location expression for a TLS variable looks like this (on a
2323 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2324 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2326 0x3 is the encoding for DW_OP_addr, which has an operand as long
2327 as the size of an address on the target machine (here is 8
2328 bytes). Note that more recent version of GCC emit DW_OP_const4u
2329 or DW_OP_const8u, depending on address size, rather than
2330 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
2331 The operand represents the offset at which the variable is within
2332 the thread local storage. */
2334 else if (data
+ 1 + addr_size
< end
2335 && (data
[0] == DW_OP_addr
2336 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
2337 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
2338 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
2339 && piece_end_p (data
+ 2 + addr_size
, end
))
2342 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
2343 gdbarch_byte_order (gdbarch
));
2345 fprintf_filtered (stream
,
2346 _("a thread-local variable at offset 0x%s "
2347 "in the thread-local storage for `%s'"),
2348 phex_nz (offset
, addr_size
), objfile
->name
);
2350 data
+= 1 + addr_size
+ 1;
2352 else if (data
[0] >= DW_OP_lit0
2353 && data
[0] <= DW_OP_lit31
2355 && data
[1] == DW_OP_stack_value
)
2357 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
2364 /* Disassemble an expression, stopping at the end of a piece or at the
2365 end of the expression. Returns a pointer to the next unread byte
2366 in the input expression. If ALL is nonzero, then this function
2367 will keep going until it reaches the end of the expression. */
2369 static const gdb_byte
*
2370 disassemble_dwarf_expression (struct ui_file
*stream
,
2371 struct gdbarch
*arch
, unsigned int addr_size
,
2373 const gdb_byte
*data
, const gdb_byte
*end
,
2375 struct dwarf2_per_cu_data
*per_cu
)
2377 const gdb_byte
*start
= data
;
2379 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
2383 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
2385 enum dwarf_location_atom op
= *data
++;
2390 name
= dwarf_stack_op_name (op
);
2393 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
2394 op
, (long) (data
- 1 - start
));
2395 fprintf_filtered (stream
, " % 4ld: %s", (long) (data
- 1 - start
), name
);
2400 ul
= extract_unsigned_integer (data
, addr_size
,
2401 gdbarch_byte_order (arch
));
2403 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
2407 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
2409 fprintf_filtered (stream
, " %s", pulongest (ul
));
2412 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
2414 fprintf_filtered (stream
, " %s", plongest (l
));
2417 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
2419 fprintf_filtered (stream
, " %s", pulongest (ul
));
2422 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2424 fprintf_filtered (stream
, " %s", plongest (l
));
2427 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
2429 fprintf_filtered (stream
, " %s", pulongest (ul
));
2432 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
2434 fprintf_filtered (stream
, " %s", plongest (l
));
2437 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
2439 fprintf_filtered (stream
, " %s", pulongest (ul
));
2442 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
2444 fprintf_filtered (stream
, " %s", plongest (l
));
2447 data
= read_uleb128 (data
, end
, &ul
);
2448 fprintf_filtered (stream
, " %s", pulongest (ul
));
2451 data
= read_sleb128 (data
, end
, &l
);
2452 fprintf_filtered (stream
, " %s", plongest (l
));
2487 fprintf_filtered (stream
, " [$%s]",
2488 locexpr_regname (arch
, op
- DW_OP_reg0
));
2492 data
= read_uleb128 (data
, end
, &ul
);
2493 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
2494 locexpr_regname (arch
, (int) ul
));
2497 case DW_OP_implicit_value
:
2498 data
= read_uleb128 (data
, end
, &ul
);
2500 fprintf_filtered (stream
, " %s", pulongest (ul
));
2535 data
= read_sleb128 (data
, end
, &l
);
2536 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
2537 locexpr_regname (arch
, op
- DW_OP_breg0
));
2541 data
= read_uleb128 (data
, end
, &ul
);
2542 data
= read_sleb128 (data
, end
, &l
);
2543 fprintf_filtered (stream
, " register %s [$%s] offset %s",
2545 locexpr_regname (arch
, (int) ul
),
2550 data
= read_sleb128 (data
, end
, &l
);
2551 fprintf_filtered (stream
, " %s", plongest (l
));
2554 case DW_OP_xderef_size
:
2555 case DW_OP_deref_size
:
2557 fprintf_filtered (stream
, " %d", *data
);
2561 case DW_OP_plus_uconst
:
2562 data
= read_uleb128 (data
, end
, &ul
);
2563 fprintf_filtered (stream
, " %s", pulongest (ul
));
2567 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2569 fprintf_filtered (stream
, " to %ld",
2570 (long) (data
+ l
- start
));
2574 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
2576 fprintf_filtered (stream
, " %ld",
2577 (long) (data
+ l
- start
));
2581 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
2583 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
2587 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
2589 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
2592 case DW_OP_call_ref
:
2593 ul
= extract_unsigned_integer (data
, offset_size
,
2594 gdbarch_byte_order (arch
));
2595 data
+= offset_size
;
2596 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
2600 data
= read_uleb128 (data
, end
, &ul
);
2601 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
2604 case DW_OP_bit_piece
:
2608 data
= read_uleb128 (data
, end
, &ul
);
2609 data
= read_uleb128 (data
, end
, &offset
);
2610 fprintf_filtered (stream
, " size %s offset %s (bits)",
2611 pulongest (ul
), pulongest (offset
));
2615 case DW_OP_GNU_implicit_pointer
:
2617 ul
= extract_unsigned_integer (data
, offset_size
,
2618 gdbarch_byte_order (arch
));
2619 data
+= offset_size
;
2621 data
= read_sleb128 (data
, end
, &l
);
2623 fprintf_filtered (stream
, " DIE %s offset %s",
2624 phex_nz (ul
, offset_size
),
2629 case DW_OP_GNU_deref_type
:
2631 int addr_size
= *data
++;
2635 data
= read_uleb128 (data
, end
, &offset
);
2636 type
= dwarf2_get_die_type (offset
, per_cu
);
2637 fprintf_filtered (stream
, "<");
2638 type_print (type
, "", stream
, -1);
2639 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
, 0),
2644 case DW_OP_GNU_const_type
:
2649 data
= read_uleb128 (data
, end
, &type_die
);
2650 type
= dwarf2_get_die_type (type_die
, per_cu
);
2651 fprintf_filtered (stream
, "<");
2652 type_print (type
, "", stream
, -1);
2653 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
, 0));
2657 case DW_OP_GNU_regval_type
:
2659 ULONGEST type_die
, reg
;
2662 data
= read_uleb128 (data
, end
, ®
);
2663 data
= read_uleb128 (data
, end
, &type_die
);
2665 type
= dwarf2_get_die_type (type_die
, per_cu
);
2666 fprintf_filtered (stream
, "<");
2667 type_print (type
, "", stream
, -1);
2668 fprintf_filtered (stream
, " [0x%s]> [$%s]", phex_nz (type_die
, 0),
2669 locexpr_regname (arch
, reg
));
2673 case DW_OP_GNU_convert
:
2674 case DW_OP_GNU_reinterpret
:
2678 data
= read_uleb128 (data
, end
, &type_die
);
2681 fprintf_filtered (stream
, "<0>");
2686 type
= dwarf2_get_die_type (type_die
, per_cu
);
2687 fprintf_filtered (stream
, "<");
2688 type_print (type
, "", stream
, -1);
2689 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
, 0));
2695 fprintf_filtered (stream
, "\n");
2701 /* Describe a single location, which may in turn consist of multiple
2705 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
2706 struct ui_file
*stream
,
2707 const gdb_byte
*data
, int size
,
2708 struct objfile
*objfile
, unsigned int addr_size
,
2709 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
2711 const gdb_byte
*end
= data
+ size
;
2712 int first_piece
= 1, bad
= 0;
2716 const gdb_byte
*here
= data
;
2717 int disassemble
= 1;
2722 fprintf_filtered (stream
, _(", and "));
2724 if (!dwarf2_always_disassemble
)
2726 data
= locexpr_describe_location_piece (symbol
, stream
,
2728 data
, end
, addr_size
);
2729 /* If we printed anything, or if we have an empty piece,
2730 then don't disassemble. */
2732 || data
[0] == DW_OP_piece
2733 || data
[0] == DW_OP_bit_piece
)
2737 data
= disassemble_dwarf_expression (stream
,
2738 get_objfile_arch (objfile
),
2739 addr_size
, offset_size
, data
, end
,
2740 dwarf2_always_disassemble
,
2745 int empty
= data
== here
;
2748 fprintf_filtered (stream
, " ");
2749 if (data
[0] == DW_OP_piece
)
2753 data
= read_uleb128 (data
+ 1, end
, &bytes
);
2756 fprintf_filtered (stream
, _("an empty %s-byte piece"),
2759 fprintf_filtered (stream
, _(" [%s-byte piece]"),
2762 else if (data
[0] == DW_OP_bit_piece
)
2764 ULONGEST bits
, offset
;
2766 data
= read_uleb128 (data
+ 1, end
, &bits
);
2767 data
= read_uleb128 (data
, end
, &offset
);
2770 fprintf_filtered (stream
,
2771 _("an empty %s-bit piece"),
2774 fprintf_filtered (stream
,
2775 _(" [%s-bit piece, offset %s bits]"),
2776 pulongest (bits
), pulongest (offset
));
2786 if (bad
|| data
> end
)
2787 error (_("Corrupted DWARF2 expression for \"%s\"."),
2788 SYMBOL_PRINT_NAME (symbol
));
2791 /* Print a natural-language description of SYMBOL to STREAM. This
2792 version is for a symbol with a single location. */
2795 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
2796 struct ui_file
*stream
)
2798 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2799 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2800 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2801 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
2803 locexpr_describe_location_1 (symbol
, addr
, stream
,
2804 dlbaton
->data
, dlbaton
->size
,
2805 objfile
, addr_size
, offset_size
,
2809 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2810 any necessary bytecode in AX. */
2813 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
2814 struct agent_expr
*ax
, struct axs_value
*value
)
2816 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2817 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2819 if (dlbaton
->data
== NULL
|| dlbaton
->size
== 0)
2820 value
->optimized_out
= 1;
2822 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
2823 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
2827 /* The set of location functions used with the DWARF-2 expression
2829 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
2830 locexpr_read_variable
,
2831 locexpr_read_needs_frame
,
2832 locexpr_describe_location
,
2833 locexpr_tracepoint_var_ref
2837 /* Wrapper functions for location lists. These generally find
2838 the appropriate location expression and call something above. */
2840 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2841 evaluator to calculate the location. */
2842 static struct value
*
2843 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
2845 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2847 const gdb_byte
*data
;
2849 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
2851 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
2853 val
= allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
2855 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
2861 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2863 loclist_read_needs_frame (struct symbol
*symbol
)
2865 /* If there's a location list, then assume we need to have a frame
2866 to choose the appropriate location expression. With tracking of
2867 global variables this is not necessarily true, but such tracking
2868 is disabled in GCC at the moment until we figure out how to
2874 /* Print a natural-language description of SYMBOL to STREAM. This
2875 version applies when there is a list of different locations, each
2876 with a specified address range. */
2879 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
2880 struct ui_file
*stream
)
2882 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2883 CORE_ADDR low
, high
;
2884 const gdb_byte
*loc_ptr
, *buf_end
;
2885 int length
, first
= 1;
2886 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2887 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2888 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2889 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2890 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
2891 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
2892 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2893 /* Adjust base_address for relocatable objects. */
2894 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2895 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
2897 loc_ptr
= dlbaton
->data
;
2898 buf_end
= dlbaton
->data
+ dlbaton
->size
;
2900 fprintf_filtered (stream
, _("multi-location:\n"));
2902 /* Iterate through locations until we run out. */
2905 if (buf_end
- loc_ptr
< 2 * addr_size
)
2906 error (_("Corrupted DWARF expression for symbol \"%s\"."),
2907 SYMBOL_PRINT_NAME (symbol
));
2910 low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
2912 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
2913 loc_ptr
+= addr_size
;
2916 high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
2918 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
2919 loc_ptr
+= addr_size
;
2921 /* A base-address-selection entry. */
2922 if ((low
& base_mask
) == base_mask
)
2924 base_address
= high
+ base_offset
;
2925 fprintf_filtered (stream
, _(" Base address %s"),
2926 paddress (gdbarch
, base_address
));
2930 /* An end-of-list entry. */
2931 if (low
== 0 && high
== 0)
2934 /* Otherwise, a location expression entry. */
2935 low
+= base_address
;
2936 high
+= base_address
;
2938 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
2941 /* (It would improve readability to print only the minimum
2942 necessary digits of the second number of the range.) */
2943 fprintf_filtered (stream
, _(" Range %s-%s: "),
2944 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
2946 /* Now describe this particular location. */
2947 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
2948 objfile
, addr_size
, offset_size
,
2951 fprintf_filtered (stream
, "\n");
2957 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2958 any necessary bytecode in AX. */
2960 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
2961 struct agent_expr
*ax
, struct axs_value
*value
)
2963 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2964 const gdb_byte
*data
;
2966 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2968 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
2969 if (data
== NULL
|| size
== 0)
2970 value
->optimized_out
= 1;
2972 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
2976 /* The set of location functions used with the DWARF-2 expression
2977 evaluator and location lists. */
2978 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
2979 loclist_read_variable
,
2980 loclist_read_needs_frame
,
2981 loclist_describe_location
,
2982 loclist_tracepoint_var_ref