1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010
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
);
51 /* A helper function for dealing with location lists. Given a
52 symbol baton (BATON) and a pc value (PC), find the appropriate
53 location expression, set *LOCEXPR_LENGTH, and return a pointer
54 to the beginning of the expression. Returns NULL on failure.
56 For now, only return the first matching location expression; there
57 can be more than one in the list. */
59 static const gdb_byte
*
60 find_location_expression (struct dwarf2_loclist_baton
*baton
,
61 size_t *locexpr_length
, CORE_ADDR pc
)
64 const gdb_byte
*loc_ptr
, *buf_end
;
66 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
67 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
68 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
69 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
70 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
71 /* Adjust base_address for relocatable objects. */
72 CORE_ADDR base_offset
= ANOFFSET (objfile
->section_offsets
,
73 SECT_OFF_TEXT (objfile
));
74 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
76 loc_ptr
= baton
->data
;
77 buf_end
= baton
->data
+ baton
->size
;
81 if (buf_end
- loc_ptr
< 2 * addr_size
)
82 error (_("find_location_expression: Corrupted DWARF expression."));
84 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
87 /* A base-address-selection entry. */
90 base_address
= dwarf2_read_address (gdbarch
,
91 loc_ptr
, buf_end
, addr_size
);
96 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
99 /* An end-of-list entry. */
100 if (low
== 0 && high
== 0)
103 /* Otherwise, a location expression entry. */
105 high
+= base_address
;
107 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
110 if (pc
>= low
&& pc
< high
)
112 *locexpr_length
= length
;
120 /* This is the baton used when performing dwarf2 expression
122 struct dwarf_expr_baton
124 struct frame_info
*frame
;
125 struct dwarf2_per_cu_data
*per_cu
;
128 /* Helper functions for dwarf2_evaluate_loc_desc. */
130 /* Using the frame specified in BATON, return the value of register
131 REGNUM, treated as a pointer. */
133 dwarf_expr_read_reg (void *baton
, int dwarf_regnum
)
135 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
136 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
140 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
141 result
= address_from_register (builtin_type (gdbarch
)->builtin_data_ptr
,
142 regnum
, debaton
->frame
);
146 /* Read memory at ADDR (length LEN) into BUF. */
149 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
151 read_memory (addr
, buf
, len
);
154 /* Using the frame specified in BATON, find the location expression
155 describing the frame base. Return a pointer to it in START and
156 its length in LENGTH. */
158 dwarf_expr_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
160 /* FIXME: cagney/2003-03-26: This code should be using
161 get_frame_base_address(), and then implement a dwarf2 specific
163 struct symbol
*framefunc
;
164 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
166 /* Use block_linkage_function, which returns a real (not inlined)
167 function, instead of get_frame_function, which may return an
169 framefunc
= block_linkage_function (get_frame_block (debaton
->frame
, NULL
));
171 /* If we found a frame-relative symbol then it was certainly within
172 some function associated with a frame. If we can't find the frame,
173 something has gone wrong. */
174 gdb_assert (framefunc
!= NULL
);
176 dwarf_expr_frame_base_1 (framefunc
,
177 get_frame_address_in_block (debaton
->frame
),
182 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
183 const gdb_byte
**start
, size_t *length
)
185 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
187 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
189 struct dwarf2_loclist_baton
*symbaton
;
191 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
192 *start
= find_location_expression (symbaton
, length
, pc
);
196 struct dwarf2_locexpr_baton
*symbaton
;
198 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
199 if (symbaton
!= NULL
)
201 *length
= symbaton
->size
;
202 *start
= symbaton
->data
;
209 error (_("Could not find the frame base for \"%s\"."),
210 SYMBOL_NATURAL_NAME (framefunc
));
213 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
214 the frame in BATON. */
217 dwarf_expr_frame_cfa (void *baton
)
219 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
221 return dwarf2_frame_cfa (debaton
->frame
);
224 /* Using the objfile specified in BATON, find the address for the
225 current thread's thread-local storage with offset OFFSET. */
227 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
229 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
230 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
232 return target_translate_tls_address (objfile
, offset
);
237 /* Reference count. */
240 /* The number of pieces used to describe this variable. */
243 /* The target address size, used only for DWARF_VALUE_STACK. */
246 /* The pieces themselves. */
247 struct dwarf_expr_piece
*pieces
;
250 /* Allocate a closure for a value formed from separately-described
253 static struct piece_closure
*
254 allocate_piece_closure (int n_pieces
, struct dwarf_expr_piece
*pieces
,
257 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
260 c
->n_pieces
= n_pieces
;
261 c
->addr_size
= addr_size
;
262 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
264 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
269 /* The lowest-level function to extract bits from a byte buffer.
270 SOURCE is the buffer. It is updated if we read to the end of a
272 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
273 updated to reflect the number of bits actually read.
274 NBITS is the number of bits we want to read. It is updated to
275 reflect the number of bits actually read. This function may read
277 BITS_BIG_ENDIAN is taken directly from gdbarch.
278 This function returns the extracted bits. */
281 extract_bits_primitive (const gdb_byte
**source
,
282 unsigned int *source_offset_bits
,
283 int *nbits
, int bits_big_endian
)
285 unsigned int avail
, mask
, datum
;
287 gdb_assert (*source_offset_bits
< 8);
289 avail
= 8 - *source_offset_bits
;
293 mask
= (1 << avail
) - 1;
296 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
298 datum
>>= *source_offset_bits
;
302 *source_offset_bits
+= avail
;
303 if (*source_offset_bits
>= 8)
305 *source_offset_bits
-= 8;
312 /* Extract some bits from a source buffer and move forward in the
315 SOURCE is the source buffer. It is updated as bytes are read.
316 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
318 NBITS is the number of bits to read.
319 BITS_BIG_ENDIAN is taken directly from gdbarch.
321 This function returns the bits that were read. */
324 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
325 int nbits
, int bits_big_endian
)
329 gdb_assert (nbits
> 0 && nbits
<= 8);
331 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
337 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
349 /* Write some bits into a buffer and move forward in the buffer.
351 DATUM is the bits to write. The low-order bits of DATUM are used.
352 DEST is the destination buffer. It is updated as bytes are
354 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
356 NBITS is the number of valid bits in DATUM.
357 BITS_BIG_ENDIAN is taken directly from gdbarch. */
360 insert_bits (unsigned int datum
,
361 gdb_byte
*dest
, unsigned int dest_offset_bits
,
362 int nbits
, int bits_big_endian
)
366 gdb_assert (dest_offset_bits
>= 0 && dest_offset_bits
+ nbits
<= 8);
368 mask
= (1 << nbits
) - 1;
371 datum
<<= 8 - (dest_offset_bits
+ nbits
);
372 mask
<<= 8 - (dest_offset_bits
+ nbits
);
376 datum
<<= dest_offset_bits
;
377 mask
<<= dest_offset_bits
;
380 gdb_assert ((datum
& ~mask
) == 0);
382 *dest
= (*dest
& ~mask
) | datum
;
385 /* Copy bits from a source to a destination.
387 DEST is where the bits should be written.
388 DEST_OFFSET_BITS is the bit offset into DEST.
389 SOURCE is the source of bits.
390 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
391 BIT_COUNT is the number of bits to copy.
392 BITS_BIG_ENDIAN is taken directly from gdbarch. */
395 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
396 const gdb_byte
*source
, unsigned int source_offset_bits
,
397 unsigned int bit_count
,
400 unsigned int dest_avail
;
403 /* Reduce everything to byte-size pieces. */
404 dest
+= dest_offset_bits
/ 8;
405 dest_offset_bits
%= 8;
406 source
+= source_offset_bits
/ 8;
407 source_offset_bits
%= 8;
409 dest_avail
= 8 - dest_offset_bits
% 8;
411 /* See if we can fill the first destination byte. */
412 if (dest_avail
< bit_count
)
414 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
416 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
418 dest_offset_bits
= 0;
419 bit_count
-= dest_avail
;
422 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
423 than 8 bits remaining. */
424 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
425 for (; bit_count
>= 8; bit_count
-= 8)
427 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
428 *dest
++ = (gdb_byte
) datum
;
431 /* Finally, we may have a few leftover bits. */
432 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
435 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
437 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
442 read_pieced_value (struct value
*v
)
446 ULONGEST bits_to_skip
;
448 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
449 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
451 size_t buffer_size
= 0;
453 struct cleanup
*cleanup
;
455 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
457 if (value_type (v
) != value_enclosing_type (v
))
458 internal_error (__FILE__
, __LINE__
,
459 _("Should not be able to create a lazy value with "
460 "an enclosing type"));
462 cleanup
= make_cleanup (free_current_contents
, &buffer
);
464 contents
= value_contents_raw (v
);
465 bits_to_skip
= 8 * value_offset (v
);
466 type_len
= 8 * TYPE_LENGTH (value_type (v
));
468 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
470 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
471 size_t this_size
, this_size_bits
;
472 long dest_offset_bits
, source_offset_bits
, source_offset
;
473 const gdb_byte
*intermediate_buffer
;
475 /* Compute size, source, and destination offsets for copying, in
477 this_size_bits
= p
->size
;
478 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
480 bits_to_skip
-= this_size_bits
;
483 if (this_size_bits
> type_len
- offset
)
484 this_size_bits
= type_len
- offset
;
485 if (bits_to_skip
> 0)
487 dest_offset_bits
= 0;
488 source_offset_bits
= bits_to_skip
;
489 this_size_bits
-= bits_to_skip
;
494 dest_offset_bits
= offset
;
495 source_offset_bits
= 0;
498 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
499 source_offset
= source_offset_bits
/ 8;
500 if (buffer_size
< this_size
)
502 buffer_size
= this_size
;
503 buffer
= xrealloc (buffer
, buffer_size
);
505 intermediate_buffer
= buffer
;
507 /* Copy from the source to DEST_BUFFER. */
510 case DWARF_VALUE_REGISTER
:
512 struct gdbarch
*arch
= get_frame_arch (frame
);
513 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
,
515 int reg_offset
= source_offset
;
517 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
518 && this_size
< register_size (arch
, gdb_regnum
))
520 /* Big-endian, and we want less than full size. */
521 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
522 /* We want the lower-order THIS_SIZE_BITS of the bytes
523 we extract from the register. */
524 source_offset_bits
+= 8 * this_size
- this_size_bits
;
527 if (gdb_regnum
!= -1)
529 get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
534 error (_("Unable to access DWARF register number %s"),
535 paddress (arch
, p
->v
.expr
.value
));
540 case DWARF_VALUE_MEMORY
:
541 if (p
->v
.expr
.in_stack_memory
)
542 read_stack (p
->v
.expr
.value
+ source_offset
, buffer
, this_size
);
544 read_memory (p
->v
.expr
.value
+ source_offset
, buffer
, this_size
);
547 case DWARF_VALUE_STACK
:
549 struct gdbarch
*gdbarch
= get_type_arch (value_type (v
));
550 size_t n
= this_size
;
552 if (n
> c
->addr_size
- source_offset
)
553 n
= (c
->addr_size
>= source_offset
554 ? c
->addr_size
- source_offset
560 else if (source_offset
== 0)
561 store_unsigned_integer (buffer
, n
,
562 gdbarch_byte_order (gdbarch
),
566 gdb_byte bytes
[sizeof (ULONGEST
)];
568 store_unsigned_integer (bytes
, n
+ source_offset
,
569 gdbarch_byte_order (gdbarch
),
571 memcpy (buffer
, bytes
+ source_offset
, n
);
576 case DWARF_VALUE_LITERAL
:
578 size_t n
= this_size
;
580 if (n
> p
->v
.literal
.length
- source_offset
)
581 n
= (p
->v
.literal
.length
>= source_offset
582 ? p
->v
.literal
.length
- source_offset
585 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
589 case DWARF_VALUE_OPTIMIZED_OUT
:
590 /* We just leave the bits empty for now. This is not ideal
591 but gdb currently does not have a nice way to represent
592 optimized-out pieces. */
593 warning (_("bits %ld-%ld in computed object were optimized out; "
594 "replacing with zeroes"),
596 offset
+ (long) this_size_bits
);
600 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
603 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
)
604 copy_bitwise (contents
, dest_offset_bits
,
605 intermediate_buffer
, source_offset_bits
% 8,
606 this_size_bits
, bits_big_endian
);
608 offset
+= this_size_bits
;
611 do_cleanups (cleanup
);
615 write_pieced_value (struct value
*to
, struct value
*from
)
619 ULONGEST bits_to_skip
;
620 const gdb_byte
*contents
;
621 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (to
);
622 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
624 size_t buffer_size
= 0;
626 struct cleanup
*cleanup
;
628 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
632 set_value_optimized_out (to
, 1);
636 cleanup
= make_cleanup (free_current_contents
, &buffer
);
638 contents
= value_contents (from
);
639 bits_to_skip
= 8 * value_offset (to
);
640 type_len
= 8 * TYPE_LENGTH (value_type (to
));
641 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
643 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
644 size_t this_size_bits
, this_size
;
645 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
647 const gdb_byte
*source_buffer
;
649 this_size_bits
= p
->size
;
650 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
652 bits_to_skip
-= this_size_bits
;
655 if (this_size_bits
> type_len
- offset
)
656 this_size_bits
= type_len
- offset
;
657 if (bits_to_skip
> 0)
659 dest_offset_bits
= bits_to_skip
;
660 source_offset_bits
= 0;
661 this_size_bits
-= bits_to_skip
;
666 dest_offset_bits
= 0;
667 source_offset_bits
= offset
;
670 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
671 source_offset
= source_offset_bits
/ 8;
672 dest_offset
= dest_offset_bits
/ 8;
673 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
675 source_buffer
= contents
+ source_offset
;
680 if (buffer_size
< this_size
)
682 buffer_size
= this_size
;
683 buffer
= xrealloc (buffer
, buffer_size
);
685 source_buffer
= buffer
;
691 case DWARF_VALUE_REGISTER
:
693 struct gdbarch
*arch
= get_frame_arch (frame
);
694 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.expr
.value
);
695 int reg_offset
= dest_offset
;
697 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
698 && this_size
<= register_size (arch
, gdb_regnum
))
699 /* Big-endian, and we want less than full size. */
700 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
702 if (gdb_regnum
!= -1)
706 get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
708 copy_bitwise (buffer
, dest_offset_bits
,
709 contents
, source_offset_bits
,
714 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
715 this_size
, source_buffer
);
719 error (_("Unable to write to DWARF register number %s"),
720 paddress (arch
, p
->v
.expr
.value
));
724 case DWARF_VALUE_MEMORY
:
727 /* Only the first and last bytes can possibly have any
729 read_memory (p
->v
.expr
.value
+ dest_offset
, buffer
, 1);
730 read_memory (p
->v
.expr
.value
+ dest_offset
+ this_size
- 1,
731 buffer
+ this_size
- 1, 1);
732 copy_bitwise (buffer
, dest_offset_bits
,
733 contents
, source_offset_bits
,
738 write_memory (p
->v
.expr
.value
+ dest_offset
,
739 source_buffer
, this_size
);
742 set_value_optimized_out (to
, 1);
745 offset
+= this_size_bits
;
749 do_cleanups (cleanup
);
753 copy_pieced_value_closure (struct value
*v
)
755 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
762 free_pieced_value_closure (struct value
*v
)
764 struct piece_closure
*c
= (struct piece_closure
*) value_computed_closure (v
);
774 /* Functions for accessing a variable described by DW_OP_piece. */
775 static struct lval_funcs pieced_value_funcs
= {
778 copy_pieced_value_closure
,
779 free_pieced_value_closure
782 /* Evaluate a location description, starting at DATA and with length
783 SIZE, to find the current location of variable of TYPE in the context
786 static struct value
*
787 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
788 const gdb_byte
*data
, unsigned short size
,
789 struct dwarf2_per_cu_data
*per_cu
)
791 struct value
*retval
;
792 struct dwarf_expr_baton baton
;
793 struct dwarf_expr_context
*ctx
;
794 struct cleanup
*old_chain
;
798 retval
= allocate_value (type
);
799 VALUE_LVAL (retval
) = not_lval
;
800 set_value_optimized_out (retval
, 1);
805 baton
.per_cu
= per_cu
;
807 ctx
= new_dwarf_expr_context ();
808 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
810 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
811 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
813 ctx
->read_reg
= dwarf_expr_read_reg
;
814 ctx
->read_mem
= dwarf_expr_read_mem
;
815 ctx
->get_frame_base
= dwarf_expr_frame_base
;
816 ctx
->get_frame_cfa
= dwarf_expr_frame_cfa
;
817 ctx
->get_tls_address
= dwarf_expr_tls_address
;
819 dwarf_expr_eval (ctx
, data
, size
);
820 if (ctx
->num_pieces
> 0)
822 struct piece_closure
*c
;
823 struct frame_id frame_id
= get_frame_id (frame
);
825 c
= allocate_piece_closure (ctx
->num_pieces
, ctx
->pieces
,
827 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
828 VALUE_FRAME_ID (retval
) = frame_id
;
832 switch (ctx
->location
)
834 case DWARF_VALUE_REGISTER
:
836 struct gdbarch
*arch
= get_frame_arch (frame
);
837 CORE_ADDR dwarf_regnum
= dwarf_expr_fetch (ctx
, 0);
838 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
840 if (gdb_regnum
!= -1)
841 retval
= value_from_register (type
, gdb_regnum
, frame
);
843 error (_("Unable to access DWARF register number %s"),
844 paddress (arch
, dwarf_regnum
));
848 case DWARF_VALUE_MEMORY
:
850 CORE_ADDR address
= dwarf_expr_fetch (ctx
, 0);
851 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
853 retval
= allocate_value (type
);
854 VALUE_LVAL (retval
) = lval_memory
;
855 set_value_lazy (retval
, 1);
857 set_value_stack (retval
, 1);
858 set_value_address (retval
, address
);
862 case DWARF_VALUE_STACK
:
864 ULONGEST value
= (ULONGEST
) dwarf_expr_fetch (ctx
, 0);
866 size_t n
= ctx
->addr_size
;
868 retval
= allocate_value (type
);
869 contents
= value_contents_raw (retval
);
870 if (n
> TYPE_LENGTH (type
))
871 n
= TYPE_LENGTH (type
);
872 store_unsigned_integer (contents
, n
,
873 gdbarch_byte_order (ctx
->gdbarch
),
878 case DWARF_VALUE_LITERAL
:
883 retval
= allocate_value (type
);
884 contents
= value_contents_raw (retval
);
885 if (n
> TYPE_LENGTH (type
))
886 n
= TYPE_LENGTH (type
);
887 memcpy (contents
, ctx
->data
, n
);
891 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
892 it can only be encountered when making a piece. */
893 case DWARF_VALUE_OPTIMIZED_OUT
:
895 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
899 set_value_initialized (retval
, ctx
->initialized
);
901 do_cleanups (old_chain
);
906 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
908 struct needs_frame_baton
911 struct dwarf2_per_cu_data
*per_cu
;
914 /* Reads from registers do require a frame. */
916 needs_frame_read_reg (void *baton
, int regnum
)
918 struct needs_frame_baton
*nf_baton
= baton
;
920 nf_baton
->needs_frame
= 1;
924 /* Reads from memory do not require a frame. */
926 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
928 memset (buf
, 0, len
);
931 /* Frame-relative accesses do require a frame. */
933 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
935 static gdb_byte lit0
= DW_OP_lit0
;
936 struct needs_frame_baton
*nf_baton
= baton
;
941 nf_baton
->needs_frame
= 1;
944 /* CFA accesses require a frame. */
947 needs_frame_frame_cfa (void *baton
)
949 struct needs_frame_baton
*nf_baton
= baton
;
951 nf_baton
->needs_frame
= 1;
955 /* Thread-local accesses do require a frame. */
957 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
959 struct needs_frame_baton
*nf_baton
= baton
;
961 nf_baton
->needs_frame
= 1;
965 /* Return non-zero iff the location expression at DATA (length SIZE)
966 requires a frame to evaluate. */
969 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, unsigned short size
,
970 struct dwarf2_per_cu_data
*per_cu
)
972 struct needs_frame_baton baton
;
973 struct dwarf_expr_context
*ctx
;
975 struct cleanup
*old_chain
;
977 baton
.needs_frame
= 0;
978 baton
.per_cu
= per_cu
;
980 ctx
= new_dwarf_expr_context ();
981 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
983 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
984 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
986 ctx
->read_reg
= needs_frame_read_reg
;
987 ctx
->read_mem
= needs_frame_read_mem
;
988 ctx
->get_frame_base
= needs_frame_frame_base
;
989 ctx
->get_frame_cfa
= needs_frame_frame_cfa
;
990 ctx
->get_tls_address
= needs_frame_tls_address
;
992 dwarf_expr_eval (ctx
, data
, size
);
994 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
996 if (ctx
->num_pieces
> 0)
1000 /* If the location has several pieces, and any of them are in
1001 registers, then we will need a frame to fetch them from. */
1002 for (i
= 0; i
< ctx
->num_pieces
; i
++)
1003 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
1007 do_cleanups (old_chain
);
1009 return baton
.needs_frame
|| in_reg
;
1012 /* This struct keeps track of the pieces that make up a multi-location
1013 object, for use in agent expression generation. It is
1014 superficially similar to struct dwarf_expr_piece, but
1015 dwarf_expr_piece is designed for use in immediate evaluation, and
1016 does not, for example, have a way to record both base register and
1021 /* Memory vs register, etc */
1022 enum axs_lvalue_kind kind
;
1024 /* If non-zero, number of bytes in this fragment */
1027 /* (GDB-numbered) reg, or base reg if >= 0 */
1030 /* offset from reg */
1034 static const gdb_byte
*
1035 dwarf2_tracepoint_var_loc (struct symbol
*symbol
,
1036 struct agent_expr
*ax
,
1037 struct axs_var_loc
*loc
,
1038 struct gdbarch
*gdbarch
,
1039 const gdb_byte
*data
, const gdb_byte
*end
)
1041 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
1043 loc
->kind
= axs_lvalue_register
;
1044 loc
->reg
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, data
[0] - DW_OP_reg0
);
1047 else if (data
[0] == DW_OP_regx
)
1051 data
= read_uleb128 (data
+ 1, end
, ®
);
1052 loc
->kind
= axs_lvalue_register
;
1053 loc
->reg
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
);
1055 else if (data
[0] == DW_OP_fbreg
)
1058 struct symbol
*framefunc
;
1060 LONGEST frame_offset
;
1061 const gdb_byte
*base_data
;
1063 LONGEST base_offset
= 0;
1065 b
= block_for_pc (ax
->scope
);
1068 error (_("No block found for address"));
1070 framefunc
= block_linkage_function (b
);
1073 error (_("No function found for block"));
1075 dwarf_expr_frame_base_1 (framefunc
, ax
->scope
,
1076 &base_data
, &base_size
);
1078 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
1080 const gdb_byte
*buf_end
;
1082 frame_reg
= base_data
[0] - DW_OP_breg0
;
1083 buf_end
= read_sleb128 (base_data
+ 1,
1084 base_data
+ base_size
, &base_offset
);
1085 if (buf_end
!= base_data
+ base_size
)
1086 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
1087 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
1089 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
1091 /* The frame base is just the register, with no offset. */
1092 frame_reg
= base_data
[0] - DW_OP_reg0
;
1097 /* We don't know what to do with the frame base expression,
1098 so we can't trace this variable; give up. */
1099 error (_("Cannot generate expression to collect symbol \"%s\"; DWARF 2 encoding not handled, first opcode in base data is 0x%x."),
1100 SYMBOL_PRINT_NAME (symbol
), base_data
[0]);
1103 data
= read_sleb128 (data
+ 1, end
, &frame_offset
);
1105 loc
->kind
= axs_lvalue_memory
;
1106 loc
->reg
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, frame_reg
);
1107 loc
->offset
= base_offset
+ frame_offset
;
1109 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
)
1114 reg
= data
[0] - DW_OP_breg0
;
1115 data
= read_sleb128 (data
+ 1, end
, &offset
);
1117 loc
->kind
= axs_lvalue_memory
;
1118 loc
->reg
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
);
1119 loc
->offset
= offset
;
1122 error (_("Unsupported DWARF opcode 0x%x in the location of \"%s\"."),
1123 data
[0], SYMBOL_PRINT_NAME (symbol
));
1128 /* Given the location of a piece, issue bytecodes that will access it. */
1131 dwarf2_tracepoint_var_access (struct agent_expr
*ax
,
1132 struct axs_value
*value
,
1133 struct axs_var_loc
*loc
)
1135 value
->kind
= loc
->kind
;
1139 case axs_lvalue_register
:
1140 value
->u
.reg
= loc
->reg
;
1143 case axs_lvalue_memory
:
1144 ax_reg (ax
, loc
->reg
);
1147 ax_const_l (ax
, loc
->offset
);
1148 ax_simple (ax
, aop_add
);
1153 internal_error (__FILE__
, __LINE__
, _("Unhandled value kind in dwarf2_tracepoint_var_access"));
1158 dwarf2_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
1159 struct agent_expr
*ax
, struct axs_value
*value
,
1160 const gdb_byte
*data
, int size
)
1162 const gdb_byte
*end
= data
+ size
;
1163 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1164 /* In practice, a variable is not going to be spread across
1165 dozens of registers or memory locations. If someone comes up
1166 with a real-world example, revisit this. */
1167 #define MAX_FRAGS 16
1168 struct axs_var_loc fragments
[MAX_FRAGS
];
1169 int nfrags
= 0, frag
;
1175 if (!data
|| size
== 0)
1177 value
->optimized_out
= 1;
1185 if (nfrags
== MAX_FRAGS
)
1186 error (_("Too many pieces in location for \"%s\"."),
1187 SYMBOL_PRINT_NAME (symbol
));
1189 fragments
[nfrags
].bytes
= 0;
1190 data
= dwarf2_tracepoint_var_loc (symbol
, ax
, &fragments
[nfrags
],
1191 gdbarch
, data
, end
);
1195 else if (data
[0] == DW_OP_piece
)
1199 data
= read_uleb128 (data
+ 1, end
, &bytes
);
1200 /* Only deal with 4 byte fragments for now. */
1202 error (_("DW_OP_piece %s not supported in location for \"%s\"."),
1203 pulongest (bytes
), SYMBOL_PRINT_NAME (symbol
));
1204 fragments
[nfrags
- 1].bytes
= bytes
;
1215 if (bad
|| data
> end
)
1216 error (_("Corrupted DWARF expression for \"%s\"."),
1217 SYMBOL_PRINT_NAME (symbol
));
1219 /* If single expression, no pieces, convert to external format. */
1222 dwarf2_tracepoint_var_access (ax
, value
, &fragments
[0]);
1226 if (length
!= TYPE_LENGTH (value
->type
))
1227 error (_("Inconsistent piece information for \"%s\"."),
1228 SYMBOL_PRINT_NAME (symbol
));
1230 /* Emit bytecodes to assemble the pieces into a single stack entry. */
1232 for ((frag
= (byte_order
== BFD_ENDIAN_BIG
? 0 : nfrags
- 1));
1234 (frag
+= (byte_order
== BFD_ENDIAN_BIG
? 1 : -1)))
1238 /* shift the previous fragment up 32 bits */
1239 ax_const_l (ax
, 32);
1240 ax_simple (ax
, aop_lsh
);
1243 dwarf2_tracepoint_var_access (ax
, value
, &fragments
[frag
]);
1245 switch (value
->kind
)
1247 case axs_lvalue_register
:
1248 ax_reg (ax
, value
->u
.reg
);
1251 case axs_lvalue_memory
:
1253 extern int trace_kludge
; /* Ugh. */
1255 gdb_assert (fragments
[frag
].bytes
== 4);
1257 ax_trace_quick (ax
, 4);
1258 ax_simple (ax
, aop_ref32
);
1265 /* or the new fragment into the previous */
1266 ax_zero_ext (ax
, 32);
1267 ax_simple (ax
, aop_bit_or
);
1271 value
->kind
= axs_rvalue
;
1275 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
1276 evaluator to calculate the location. */
1277 static struct value
*
1278 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
1280 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1283 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
1284 dlbaton
->size
, dlbaton
->per_cu
);
1289 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
1291 locexpr_read_needs_frame (struct symbol
*symbol
)
1293 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1295 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
1299 /* Return true if DATA points to the end of a piece. END is one past
1300 the last byte in the expression. */
1303 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
1305 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
1308 /* Nicely describe a single piece of a location, returning an updated
1309 position in the bytecode sequence. This function cannot recognize
1310 all locations; if a location is not recognized, it simply returns
1313 static const gdb_byte
*
1314 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
1315 CORE_ADDR addr
, struct objfile
*objfile
,
1316 const gdb_byte
*data
, const gdb_byte
*end
,
1317 unsigned int addr_size
)
1319 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1322 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
1324 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, data
[0] - DW_OP_reg0
);
1325 fprintf_filtered (stream
, _("a variable in $%s"),
1326 gdbarch_register_name (gdbarch
, regno
));
1329 else if (data
[0] == DW_OP_regx
)
1333 data
= read_uleb128 (data
+ 1, end
, ®
);
1334 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
);
1335 fprintf_filtered (stream
, _("a variable in $%s"),
1336 gdbarch_register_name (gdbarch
, regno
));
1338 else if (data
[0] == DW_OP_fbreg
)
1341 struct symbol
*framefunc
;
1343 LONGEST frame_offset
;
1344 const gdb_byte
*base_data
, *new_data
;
1346 LONGEST base_offset
= 0;
1348 new_data
= read_sleb128 (data
+ 1, end
, &frame_offset
);
1349 if (!piece_end_p (new_data
, end
))
1353 b
= block_for_pc (addr
);
1356 error (_("No block found for address for symbol \"%s\"."),
1357 SYMBOL_PRINT_NAME (symbol
));
1359 framefunc
= block_linkage_function (b
);
1362 error (_("No function found for block for symbol \"%s\"."),
1363 SYMBOL_PRINT_NAME (symbol
));
1365 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
1367 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
1369 const gdb_byte
*buf_end
;
1371 frame_reg
= base_data
[0] - DW_OP_breg0
;
1372 buf_end
= read_sleb128 (base_data
+ 1,
1373 base_data
+ base_size
, &base_offset
);
1374 if (buf_end
!= base_data
+ base_size
)
1375 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
1376 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
1378 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
1380 /* The frame base is just the register, with no offset. */
1381 frame_reg
= base_data
[0] - DW_OP_reg0
;
1386 /* We don't know what to do with the frame base expression,
1387 so we can't trace this variable; give up. */
1388 error (_("Cannot describe location of symbol \"%s\"; "
1389 "DWARF 2 encoding not handled, "
1390 "first opcode in base data is 0x%x."),
1391 SYMBOL_PRINT_NAME (symbol
), base_data
[0]);
1394 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, frame_reg
);
1396 fprintf_filtered (stream
, _("a variable at frame base reg $%s offset %s+%s"),
1397 gdbarch_register_name (gdbarch
, regno
),
1398 plongest (base_offset
), plongest (frame_offset
));
1400 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
1401 && piece_end_p (data
, end
))
1405 regno
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, data
[0] - DW_OP_breg0
);
1407 data
= read_sleb128 (data
+ 1, end
, &offset
);
1409 fprintf_filtered (stream
,
1410 _("a variable at offset %s from base reg $%s"),
1412 gdbarch_register_name (gdbarch
, regno
));
1415 /* The location expression for a TLS variable looks like this (on a
1418 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
1419 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
1421 0x3 is the encoding for DW_OP_addr, which has an operand as long
1422 as the size of an address on the target machine (here is 8
1423 bytes). 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
1424 The operand represents the offset at which the variable is within
1425 the thread local storage. */
1427 else if (data
+ 1 + addr_size
< end
1428 && data
[0] == DW_OP_addr
1429 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
1430 && piece_end_p (data
+ 2 + addr_size
, end
))
1432 CORE_ADDR offset
= dwarf2_read_address (gdbarch
,
1437 fprintf_filtered (stream
,
1438 _("a thread-local variable at offset %s "
1439 "in the thread-local storage for `%s'"),
1440 paddress (gdbarch
, offset
), objfile
->name
);
1442 data
+= 1 + addr_size
+ 1;
1444 else if (data
[0] >= DW_OP_lit0
1445 && data
[0] <= DW_OP_lit31
1447 && data
[1] == DW_OP_stack_value
)
1449 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
1456 /* Disassemble an expression, stopping at the end of a piece or at the
1457 end of the expression. Returns a pointer to the next unread byte
1458 in the input expression. If ALL is nonzero, then this function
1459 will keep going until it reaches the end of the expression. */
1461 static const gdb_byte
*
1462 disassemble_dwarf_expression (struct ui_file
*stream
,
1463 struct gdbarch
*arch
, unsigned int addr_size
,
1465 const gdb_byte
*data
, const gdb_byte
*end
,
1468 const gdb_byte
*start
= data
;
1470 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
1474 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
1476 enum dwarf_location_atom op
= *data
++;
1482 name
= dwarf_stack_op_name (op
, 0);
1485 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
1486 op
, (long) (data
- start
));
1487 fprintf_filtered (stream
, " % 4ld: %s", (long) (data
- start
), name
);
1492 addr
= dwarf2_read_address (arch
, data
, end
, addr_size
);
1494 fprintf_filtered (stream
, " %s", paddress (arch
, addr
));
1498 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
1500 fprintf_filtered (stream
, " %s", pulongest (ul
));
1503 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
1505 fprintf_filtered (stream
, " %s", plongest (l
));
1508 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
1510 fprintf_filtered (stream
, " %s", pulongest (ul
));
1513 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
1515 fprintf_filtered (stream
, " %s", plongest (l
));
1518 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
1520 fprintf_filtered (stream
, " %s", pulongest (ul
));
1523 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
1525 fprintf_filtered (stream
, " %s", plongest (l
));
1528 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
1530 fprintf_filtered (stream
, " %s", pulongest (ul
));
1533 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
1535 fprintf_filtered (stream
, " %s", plongest (l
));
1538 data
= read_uleb128 (data
, end
, &ul
);
1539 fprintf_filtered (stream
, " %s", pulongest (ul
));
1542 data
= read_sleb128 (data
, end
, &l
);
1543 fprintf_filtered (stream
, " %s", plongest (l
));
1578 fprintf_filtered (stream
, " [$%s]",
1579 gdbarch_register_name (arch
, op
- DW_OP_reg0
));
1583 data
= read_uleb128 (data
, end
, &ul
);
1584 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
1585 gdbarch_register_name (arch
, (int) ul
));
1588 case DW_OP_implicit_value
:
1589 data
= read_uleb128 (data
, end
, &ul
);
1591 fprintf_filtered (stream
, " %s", pulongest (ul
));
1626 data
= read_sleb128 (data
, end
, &ul
);
1627 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
1628 gdbarch_register_name (arch
, op
- DW_OP_breg0
));
1635 data
= read_uleb128 (data
, end
, &ul
);
1636 data
= read_sleb128 (data
, end
, &offset
);
1637 fprintf_filtered (stream
, " register %s [$%s] offset %s",
1639 gdbarch_register_name (arch
, (int) ul
),
1640 pulongest (offset
));
1645 data
= read_sleb128 (data
, end
, &ul
);
1646 fprintf_filtered (stream
, " %s", pulongest (ul
));
1649 case DW_OP_xderef_size
:
1650 case DW_OP_deref_size
:
1652 fprintf_filtered (stream
, " %d", *data
);
1656 case DW_OP_plus_uconst
:
1657 data
= read_uleb128 (data
, end
, &ul
);
1658 fprintf_filtered (stream
, " %s", pulongest (ul
));
1662 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
1664 fprintf_filtered (stream
, " to %ld",
1665 (long) (data
+ l
- start
));
1669 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
1671 fprintf_filtered (stream
, " %ld",
1672 (long) (data
+ l
- start
));
1676 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
1678 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
1682 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
1684 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
1687 case DW_OP_call_ref
:
1688 ul
= extract_unsigned_integer (data
, offset_size
,
1689 gdbarch_byte_order (arch
));
1690 data
+= offset_size
;
1691 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
1695 data
= read_uleb128 (data
, end
, &ul
);
1696 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
1699 case DW_OP_bit_piece
:
1703 data
= read_uleb128 (data
, end
, &ul
);
1704 data
= read_uleb128 (data
, end
, &offset
);
1705 fprintf_filtered (stream
, " size %s offset %s (bits)",
1706 pulongest (ul
), pulongest (offset
));
1711 fprintf_filtered (stream
, "\n");
1717 /* Describe a single location, which may in turn consist of multiple
1721 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
1722 struct ui_file
*stream
,
1723 const gdb_byte
*data
, int size
,
1724 struct objfile
*objfile
, unsigned int addr_size
,
1727 const gdb_byte
*end
= data
+ size
;
1728 int first_piece
= 1, bad
= 0;
1732 const gdb_byte
*here
= data
;
1733 int disassemble
= 1;
1738 fprintf_filtered (stream
, _(", and "));
1740 if (!dwarf2_always_disassemble
)
1742 data
= locexpr_describe_location_piece (symbol
, stream
, addr
, objfile
,
1743 data
, end
, addr_size
);
1744 /* If we printed anything, or if we have an empty piece,
1745 then don't disassemble. */
1747 || data
[0] == DW_OP_piece
1748 || data
[0] == DW_OP_bit_piece
)
1752 data
= disassemble_dwarf_expression (stream
, get_objfile_arch (objfile
),
1753 addr_size
, offset_size
, data
, end
,
1754 dwarf2_always_disassemble
);
1758 int empty
= data
== here
;
1761 fprintf_filtered (stream
, " ");
1762 if (data
[0] == DW_OP_piece
)
1766 data
= read_uleb128 (data
+ 1, end
, &bytes
);
1769 fprintf_filtered (stream
, _("an empty %s-byte piece"),
1772 fprintf_filtered (stream
, _(" [%s-byte piece]"),
1775 else if (data
[0] == DW_OP_bit_piece
)
1777 ULONGEST bits
, offset
;
1779 data
= read_uleb128 (data
+ 1, end
, &bits
);
1780 data
= read_uleb128 (data
, end
, &offset
);
1783 fprintf_filtered (stream
,
1784 _("an empty %s-bit piece"),
1787 fprintf_filtered (stream
,
1788 _(" [%s-bit piece, offset %s bits]"),
1789 pulongest (bits
), pulongest (offset
));
1799 if (bad
|| data
> end
)
1800 error (_("Corrupted DWARF2 expression for \"%s\"."),
1801 SYMBOL_PRINT_NAME (symbol
));
1804 /* Print a natural-language description of SYMBOL to STREAM. This
1805 version is for a symbol with a single location. */
1808 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
1809 struct ui_file
*stream
)
1811 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1812 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
1813 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
1814 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
1816 locexpr_describe_location_1 (symbol
, addr
, stream
, dlbaton
->data
, dlbaton
->size
,
1817 objfile
, addr_size
, offset_size
);
1820 /* Describe the location of SYMBOL as an agent value in VALUE, generating
1821 any necessary bytecode in AX. */
1824 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
1825 struct agent_expr
*ax
, struct axs_value
*value
)
1827 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1829 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
,
1830 dlbaton
->data
, dlbaton
->size
);
1833 /* The set of location functions used with the DWARF-2 expression
1835 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
1836 locexpr_read_variable
,
1837 locexpr_read_needs_frame
,
1838 locexpr_describe_location
,
1839 locexpr_tracepoint_var_ref
1843 /* Wrapper functions for location lists. These generally find
1844 the appropriate location expression and call something above. */
1846 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
1847 evaluator to calculate the location. */
1848 static struct value
*
1849 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
1851 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1853 const gdb_byte
*data
;
1856 data
= find_location_expression (dlbaton
, &size
,
1857 frame
? get_frame_address_in_block (frame
)
1861 val
= allocate_value (SYMBOL_TYPE (symbol
));
1862 VALUE_LVAL (val
) = not_lval
;
1863 set_value_optimized_out (val
, 1);
1866 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
1872 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
1874 loclist_read_needs_frame (struct symbol
*symbol
)
1876 /* If there's a location list, then assume we need to have a frame
1877 to choose the appropriate location expression. With tracking of
1878 global variables this is not necessarily true, but such tracking
1879 is disabled in GCC at the moment until we figure out how to
1885 /* Print a natural-language description of SYMBOL to STREAM. This
1886 version applies when there is a list of different locations, each
1887 with a specified address range. */
1890 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
1891 struct ui_file
*stream
)
1893 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1894 CORE_ADDR low
, high
;
1895 const gdb_byte
*loc_ptr
, *buf_end
;
1896 int length
, first
= 1;
1897 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
1898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1899 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1900 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
1901 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
1902 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
1903 /* Adjust base_address for relocatable objects. */
1904 CORE_ADDR base_offset
= ANOFFSET (objfile
->section_offsets
,
1905 SECT_OFF_TEXT (objfile
));
1906 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
1908 loc_ptr
= dlbaton
->data
;
1909 buf_end
= dlbaton
->data
+ dlbaton
->size
;
1911 fprintf_filtered (stream
, _("multi-location:\n"));
1913 /* Iterate through locations until we run out. */
1916 if (buf_end
- loc_ptr
< 2 * addr_size
)
1917 error (_("Corrupted DWARF expression for symbol \"%s\"."),
1918 SYMBOL_PRINT_NAME (symbol
));
1920 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
1921 loc_ptr
+= addr_size
;
1923 /* A base-address-selection entry. */
1924 if (low
== base_mask
)
1926 base_address
= dwarf2_read_address (gdbarch
,
1927 loc_ptr
, buf_end
, addr_size
);
1928 fprintf_filtered (stream
, _(" Base address %s"),
1929 paddress (gdbarch
, base_address
));
1930 loc_ptr
+= addr_size
;
1934 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
1935 loc_ptr
+= addr_size
;
1937 /* An end-of-list entry. */
1938 if (low
== 0 && high
== 0)
1941 /* Otherwise, a location expression entry. */
1942 low
+= base_address
;
1943 high
+= base_address
;
1945 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
1948 /* (It would improve readability to print only the minimum
1949 necessary digits of the second number of the range.) */
1950 fprintf_filtered (stream
, _(" Range %s-%s: "),
1951 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
1953 /* Now describe this particular location. */
1954 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
1955 objfile
, addr_size
, offset_size
);
1957 fprintf_filtered (stream
, "\n");
1963 /* Describe the location of SYMBOL as an agent value in VALUE, generating
1964 any necessary bytecode in AX. */
1966 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
1967 struct agent_expr
*ax
, struct axs_value
*value
)
1969 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
1970 const gdb_byte
*data
;
1973 data
= find_location_expression (dlbaton
, &size
, ax
->scope
);
1975 dwarf2_tracepoint_var_ref (symbol
, gdbarch
, ax
, value
, data
, size
);
1978 /* The set of location functions used with the DWARF-2 expression
1979 evaluator and location lists. */
1980 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
1981 loclist_read_variable
,
1982 loclist_read_needs_frame
,
1983 loclist_describe_location
,
1984 loclist_tracepoint_var_ref