1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "exceptions.h"
38 #include "dwarf2expr.h"
39 #include "dwarf2loc.h"
40 #include "dwarf2-frame.h"
42 #include "gdb_string.h"
43 #include "gdb_assert.h"
45 extern int dwarf2_always_disassemble;
48 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
49 const gdb_byte **start, size_t *length);
52 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
53 const gdb_byte *data, unsigned short size,
54 struct dwarf2_per_cu_data *per_cu,
57 /* A function for dealing with location lists. Given a
58 symbol baton (BATON) and a pc value (PC), find the appropriate
59 location expression, set *LOCEXPR_LENGTH, and return a pointer
60 to the beginning of the expression. Returns NULL on failure.
62 For now, only return the first matching location expression; there
63 can be more than one in the list. */
66 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
67 size_t *locexpr_length, CORE_ADDR pc)
70 const gdb_byte *loc_ptr, *buf_end;
72 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
73 struct gdbarch *gdbarch = get_objfile_arch (objfile);
74 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
75 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
76 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
77 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
78 /* Adjust base_address for relocatable objects. */
79 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
80 CORE_ADDR base_address = baton->base_address + base_offset;
82 loc_ptr = baton->data;
83 buf_end = baton->data + baton->size;
87 if (buf_end - loc_ptr < 2 * addr_size)
88 error (_("dwarf2_find_location_expression: "
89 "Corrupted DWARF expression."));
92 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
94 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
98 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
100 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
101 loc_ptr += addr_size;
103 /* A base-address-selection entry. */
104 if ((low & base_mask) == base_mask)
106 base_address = high + base_offset;
110 /* An end-of-list entry. */
111 if (low == 0 && high == 0)
114 /* Otherwise, a location expression entry. */
116 high += base_address;
118 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
121 if (pc >= low && pc < high)
123 *locexpr_length = length;
131 /* This is the baton used when performing dwarf2 expression
133 struct dwarf_expr_baton
135 struct frame_info *frame;
136 struct dwarf2_per_cu_data *per_cu;
139 /* Helper functions for dwarf2_evaluate_loc_desc. */
141 /* Using the frame specified in BATON, return the value of register
142 REGNUM, treated as a pointer. */
144 dwarf_expr_read_reg (void *baton, int dwarf_regnum)
146 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
147 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
151 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
152 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
153 regnum, debaton->frame);
157 /* Read memory at ADDR (length LEN) into BUF. */
160 dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
162 read_memory (addr, buf, len);
165 /* Using the frame specified in BATON, find the location expression
166 describing the frame base. Return a pointer to it in START and
167 its length in LENGTH. */
169 dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
171 /* FIXME: cagney/2003-03-26: This code should be using
172 get_frame_base_address(), and then implement a dwarf2 specific
174 struct symbol *framefunc;
175 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
177 /* Use block_linkage_function, which returns a real (not inlined)
178 function, instead of get_frame_function, which may return an
180 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
182 /* If we found a frame-relative symbol then it was certainly within
183 some function associated with a frame. If we can't find the frame,
184 something has gone wrong. */
185 gdb_assert (framefunc != NULL);
187 dwarf_expr_frame_base_1 (framefunc,
188 get_frame_address_in_block (debaton->frame),
193 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
194 const gdb_byte **start, size_t *length)
196 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
198 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
200 struct dwarf2_loclist_baton *symbaton;
202 symbaton = SYMBOL_LOCATION_BATON (framefunc);
203 *start = dwarf2_find_location_expression (symbaton, length, pc);
207 struct dwarf2_locexpr_baton *symbaton;
209 symbaton = SYMBOL_LOCATION_BATON (framefunc);
210 if (symbaton != NULL)
212 *length = symbaton->size;
213 *start = symbaton->data;
220 error (_("Could not find the frame base for \"%s\"."),
221 SYMBOL_NATURAL_NAME (framefunc));
224 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
225 the frame in BATON. */
228 dwarf_expr_frame_cfa (void *baton)
230 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
232 return dwarf2_frame_cfa (debaton->frame);
235 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
236 the frame in BATON. */
239 dwarf_expr_frame_pc (void *baton)
241 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
243 return get_frame_address_in_block (debaton->frame);
246 /* Using the objfile specified in BATON, find the address for the
247 current thread's thread-local storage with offset OFFSET. */
249 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
251 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
252 struct objfile *objfile = dwarf2_per_cu_objfile (debaton->per_cu);
254 return target_translate_tls_address (objfile, offset);
257 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
258 current CU (as is PER_CU). State of the CTX is not affected by the
262 per_cu_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset,
263 struct dwarf2_per_cu_data *per_cu,
264 CORE_ADDR (*get_frame_pc) (void *baton),
267 struct dwarf2_locexpr_baton block;
269 block = dwarf2_fetch_die_location_block (die_offset, per_cu,
270 get_frame_pc, baton);
272 /* DW_OP_call_ref is currently not supported. */
273 gdb_assert (block.per_cu == per_cu);
275 dwarf_expr_eval (ctx, block.data, block.size);
278 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
281 dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
283 struct dwarf_expr_baton *debaton = ctx->baton;
285 per_cu_dwarf_call (ctx, die_offset, debaton->per_cu,
286 ctx->get_frame_pc, ctx->baton);
291 /* Reference count. */
294 /* The CU from which this closure's expression came. */
295 struct dwarf2_per_cu_data *per_cu;
297 /* The number of pieces used to describe this variable. */
300 /* The target address size, used only for DWARF_VALUE_STACK. */
303 /* The pieces themselves. */
304 struct dwarf_expr_piece *pieces;
307 /* Allocate a closure for a value formed from separately-described
310 static struct piece_closure *
311 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
312 int n_pieces, struct dwarf_expr_piece *pieces,
315 struct piece_closure *c = XZALLOC (struct piece_closure);
319 c->n_pieces = n_pieces;
320 c->addr_size = addr_size;
321 c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
323 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
328 /* The lowest-level function to extract bits from a byte buffer.
329 SOURCE is the buffer. It is updated if we read to the end of a
331 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
332 updated to reflect the number of bits actually read.
333 NBITS is the number of bits we want to read. It is updated to
334 reflect the number of bits actually read. This function may read
336 BITS_BIG_ENDIAN is taken directly from gdbarch.
337 This function returns the extracted bits. */
340 extract_bits_primitive (const gdb_byte **source,
341 unsigned int *source_offset_bits,
342 int *nbits, int bits_big_endian)
344 unsigned int avail, mask, datum;
346 gdb_assert (*source_offset_bits < 8);
348 avail = 8 - *source_offset_bits;
352 mask = (1 << avail) - 1;
355 datum >>= 8 - (*source_offset_bits + *nbits);
357 datum >>= *source_offset_bits;
361 *source_offset_bits += avail;
362 if (*source_offset_bits >= 8)
364 *source_offset_bits -= 8;
371 /* Extract some bits from a source buffer and move forward in the
374 SOURCE is the source buffer. It is updated as bytes are read.
375 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
377 NBITS is the number of bits to read.
378 BITS_BIG_ENDIAN is taken directly from gdbarch.
380 This function returns the bits that were read. */
383 extract_bits (const gdb_byte **source, unsigned int *source_offset_bits,
384 int nbits, int bits_big_endian)
388 gdb_assert (nbits > 0 && nbits <= 8);
390 datum = extract_bits_primitive (source, source_offset_bits, &nbits,
396 more = extract_bits_primitive (source, source_offset_bits, &nbits,
408 /* Write some bits into a buffer and move forward in the buffer.
410 DATUM is the bits to write. The low-order bits of DATUM are used.
411 DEST is the destination buffer. It is updated as bytes are
413 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
415 NBITS is the number of valid bits in DATUM.
416 BITS_BIG_ENDIAN is taken directly from gdbarch. */
419 insert_bits (unsigned int datum,
420 gdb_byte *dest, unsigned int dest_offset_bits,
421 int nbits, int bits_big_endian)
425 gdb_assert (dest_offset_bits + nbits <= 8);
427 mask = (1 << nbits) - 1;
430 datum <<= 8 - (dest_offset_bits + nbits);
431 mask <<= 8 - (dest_offset_bits + nbits);
435 datum <<= dest_offset_bits;
436 mask <<= dest_offset_bits;
439 gdb_assert ((datum & ~mask) == 0);
441 *dest = (*dest & ~mask) | datum;
444 /* Copy bits from a source to a destination.
446 DEST is where the bits should be written.
447 DEST_OFFSET_BITS is the bit offset into DEST.
448 SOURCE is the source of bits.
449 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
450 BIT_COUNT is the number of bits to copy.
451 BITS_BIG_ENDIAN is taken directly from gdbarch. */
454 copy_bitwise (gdb_byte *dest, unsigned int dest_offset_bits,
455 const gdb_byte *source, unsigned int source_offset_bits,
456 unsigned int bit_count,
459 unsigned int dest_avail;
462 /* Reduce everything to byte-size pieces. */
463 dest += dest_offset_bits / 8;
464 dest_offset_bits %= 8;
465 source += source_offset_bits / 8;
466 source_offset_bits %= 8;
468 dest_avail = 8 - dest_offset_bits % 8;
470 /* See if we can fill the first destination byte. */
471 if (dest_avail < bit_count)
473 datum = extract_bits (&source, &source_offset_bits, dest_avail,
475 insert_bits (datum, dest, dest_offset_bits, dest_avail, bits_big_endian);
477 dest_offset_bits = 0;
478 bit_count -= dest_avail;
481 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
482 than 8 bits remaining. */
483 gdb_assert (dest_offset_bits % 8 == 0 || bit_count < 8);
484 for (; bit_count >= 8; bit_count -= 8)
486 datum = extract_bits (&source, &source_offset_bits, 8, bits_big_endian);
487 *dest++ = (gdb_byte) datum;
490 /* Finally, we may have a few leftover bits. */
491 gdb_assert (bit_count <= 8 - dest_offset_bits % 8);
494 datum = extract_bits (&source, &source_offset_bits, bit_count,
496 insert_bits (datum, dest, dest_offset_bits, bit_count, bits_big_endian);
501 read_pieced_value (struct value *v)
505 ULONGEST bits_to_skip;
507 struct piece_closure *c
508 = (struct piece_closure *) value_computed_closure (v);
509 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v));
511 size_t buffer_size = 0;
513 struct cleanup *cleanup;
515 = gdbarch_bits_big_endian (get_type_arch (value_type (v)));
517 if (value_type (v) != value_enclosing_type (v))
518 internal_error (__FILE__, __LINE__,
519 _("Should not be able to create a lazy value with "
520 "an enclosing type"));
522 cleanup = make_cleanup (free_current_contents, &buffer);
524 contents = value_contents_raw (v);
525 bits_to_skip = 8 * value_offset (v);
526 if (value_bitsize (v))
528 bits_to_skip += value_bitpos (v);
529 type_len = value_bitsize (v);
532 type_len = 8 * TYPE_LENGTH (value_type (v));
534 for (i = 0; i < c->n_pieces && offset < type_len; i++)
536 struct dwarf_expr_piece *p = &c->pieces[i];
537 size_t this_size, this_size_bits;
538 long dest_offset_bits, source_offset_bits, source_offset;
539 const gdb_byte *intermediate_buffer;
541 /* Compute size, source, and destination offsets for copying, in
543 this_size_bits = p->size;
544 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
546 bits_to_skip -= this_size_bits;
549 if (this_size_bits > type_len - offset)
550 this_size_bits = type_len - offset;
551 if (bits_to_skip > 0)
553 dest_offset_bits = 0;
554 source_offset_bits = bits_to_skip;
555 this_size_bits -= bits_to_skip;
560 dest_offset_bits = offset;
561 source_offset_bits = 0;
564 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
565 source_offset = source_offset_bits / 8;
566 if (buffer_size < this_size)
568 buffer_size = this_size;
569 buffer = xrealloc (buffer, buffer_size);
571 intermediate_buffer = buffer;
573 /* Copy from the source to DEST_BUFFER. */
576 case DWARF_VALUE_REGISTER:
578 struct gdbarch *arch = get_frame_arch (frame);
579 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
580 int reg_offset = source_offset;
582 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
583 && this_size < register_size (arch, gdb_regnum))
585 /* Big-endian, and we want less than full size. */
586 reg_offset = register_size (arch, gdb_regnum) - this_size;
587 /* We want the lower-order THIS_SIZE_BITS of the bytes
588 we extract from the register. */
589 source_offset_bits += 8 * this_size - this_size_bits;
592 if (gdb_regnum != -1)
596 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
600 /* Just so garbage doesn't ever shine through. */
601 memset (buffer, 0, this_size);
604 set_value_optimized_out (v, 1);
606 mark_value_bytes_unavailable (v, offset, this_size);
611 error (_("Unable to access DWARF register number %s"),
612 paddress (arch, p->v.value));
617 case DWARF_VALUE_MEMORY:
618 read_value_memory (v, offset,
619 p->v.mem.in_stack_memory,
620 p->v.mem.addr + source_offset,
624 case DWARF_VALUE_STACK:
626 struct gdbarch *gdbarch = get_type_arch (value_type (v));
627 size_t n = this_size;
629 if (n > c->addr_size - source_offset)
630 n = (c->addr_size >= source_offset
631 ? c->addr_size - source_offset
637 else if (source_offset == 0)
638 store_unsigned_integer (buffer, n,
639 gdbarch_byte_order (gdbarch),
643 gdb_byte bytes[sizeof (ULONGEST)];
645 store_unsigned_integer (bytes, n + source_offset,
646 gdbarch_byte_order (gdbarch),
648 memcpy (buffer, bytes + source_offset, n);
653 case DWARF_VALUE_LITERAL:
655 size_t n = this_size;
657 if (n > p->v.literal.length - source_offset)
658 n = (p->v.literal.length >= source_offset
659 ? p->v.literal.length - source_offset
662 intermediate_buffer = p->v.literal.data + source_offset;
666 /* These bits show up as zeros -- but do not cause the value
667 to be considered optimized-out. */
668 case DWARF_VALUE_IMPLICIT_POINTER:
671 case DWARF_VALUE_OPTIMIZED_OUT:
672 set_value_optimized_out (v, 1);
676 internal_error (__FILE__, __LINE__, _("invalid location type"));
679 if (p->location != DWARF_VALUE_OPTIMIZED_OUT
680 && p->location != DWARF_VALUE_IMPLICIT_POINTER)
681 copy_bitwise (contents, dest_offset_bits,
682 intermediate_buffer, source_offset_bits % 8,
683 this_size_bits, bits_big_endian);
685 offset += this_size_bits;
688 do_cleanups (cleanup);
692 write_pieced_value (struct value *to, struct value *from)
696 ULONGEST bits_to_skip;
697 const gdb_byte *contents;
698 struct piece_closure *c
699 = (struct piece_closure *) value_computed_closure (to);
700 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
702 size_t buffer_size = 0;
704 struct cleanup *cleanup;
706 = gdbarch_bits_big_endian (get_type_arch (value_type (to)));
710 set_value_optimized_out (to, 1);
714 cleanup = make_cleanup (free_current_contents, &buffer);
716 contents = value_contents (from);
717 bits_to_skip = 8 * value_offset (to);
718 if (value_bitsize (to))
720 bits_to_skip += value_bitpos (to);
721 type_len = value_bitsize (to);
724 type_len = 8 * TYPE_LENGTH (value_type (to));
726 for (i = 0; i < c->n_pieces && offset < type_len; i++)
728 struct dwarf_expr_piece *p = &c->pieces[i];
729 size_t this_size_bits, this_size;
730 long dest_offset_bits, source_offset_bits, dest_offset, source_offset;
732 const gdb_byte *source_buffer;
734 this_size_bits = p->size;
735 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
737 bits_to_skip -= this_size_bits;
740 if (this_size_bits > type_len - offset)
741 this_size_bits = type_len - offset;
742 if (bits_to_skip > 0)
744 dest_offset_bits = bits_to_skip;
745 source_offset_bits = 0;
746 this_size_bits -= bits_to_skip;
751 dest_offset_bits = 0;
752 source_offset_bits = offset;
755 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
756 source_offset = source_offset_bits / 8;
757 dest_offset = dest_offset_bits / 8;
758 if (dest_offset_bits % 8 == 0 && source_offset_bits % 8 == 0)
760 source_buffer = contents + source_offset;
765 if (buffer_size < this_size)
767 buffer_size = this_size;
768 buffer = xrealloc (buffer, buffer_size);
770 source_buffer = buffer;
776 case DWARF_VALUE_REGISTER:
778 struct gdbarch *arch = get_frame_arch (frame);
779 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
780 int reg_offset = dest_offset;
782 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
783 && this_size <= register_size (arch, gdb_regnum))
784 /* Big-endian, and we want less than full size. */
785 reg_offset = register_size (arch, gdb_regnum) - this_size;
787 if (gdb_regnum != -1)
793 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
798 error (_("Can't do read-modify-write to "
799 "update bitfield; containing word has been "
802 throw_error (NOT_AVAILABLE_ERROR,
803 _("Can't do read-modify-write to update "
804 "bitfield; containing word "
807 copy_bitwise (buffer, dest_offset_bits,
808 contents, source_offset_bits,
813 put_frame_register_bytes (frame, gdb_regnum, reg_offset,
814 this_size, source_buffer);
818 error (_("Unable to write to DWARF register number %s"),
819 paddress (arch, p->v.value));
823 case DWARF_VALUE_MEMORY:
826 /* Only the first and last bytes can possibly have any
828 read_memory (p->v.mem.addr + dest_offset, buffer, 1);
829 read_memory (p->v.mem.addr + dest_offset + this_size - 1,
830 buffer + this_size - 1, 1);
831 copy_bitwise (buffer, dest_offset_bits,
832 contents, source_offset_bits,
837 write_memory (p->v.mem.addr + dest_offset,
838 source_buffer, this_size);
841 set_value_optimized_out (to, 1);
844 offset += this_size_bits;
847 do_cleanups (cleanup);
850 /* A helper function that checks bit validity in a pieced value.
851 CHECK_FOR indicates the kind of validity checking.
852 DWARF_VALUE_MEMORY means to check whether any bit is valid.
853 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
855 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
859 check_pieced_value_bits (const struct value *value, int bit_offset,
861 enum dwarf_value_location check_for)
863 struct piece_closure *c
864 = (struct piece_closure *) value_computed_closure (value);
866 int validity = (check_for == DWARF_VALUE_MEMORY
867 || check_for == DWARF_VALUE_IMPLICIT_POINTER);
869 bit_offset += 8 * value_offset (value);
870 if (value_bitsize (value))
871 bit_offset += value_bitpos (value);
873 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
875 struct dwarf_expr_piece *p = &c->pieces[i];
876 size_t this_size_bits = p->size;
880 if (bit_offset >= this_size_bits)
882 bit_offset -= this_size_bits;
886 bit_length -= this_size_bits - bit_offset;
890 bit_length -= this_size_bits;
892 if (check_for == DWARF_VALUE_IMPLICIT_POINTER)
894 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
897 else if (p->location == DWARF_VALUE_OPTIMIZED_OUT
898 || p->location == DWARF_VALUE_IMPLICIT_POINTER)
914 check_pieced_value_validity (const struct value *value, int bit_offset,
917 return check_pieced_value_bits (value, bit_offset, bit_length,
922 check_pieced_value_invalid (const struct value *value)
924 return check_pieced_value_bits (value, 0,
925 8 * TYPE_LENGTH (value_type (value)),
926 DWARF_VALUE_OPTIMIZED_OUT);
929 /* An implementation of an lval_funcs method to see whether a value is
930 a synthetic pointer. */
933 check_pieced_synthetic_pointer (const struct value *value, int bit_offset,
936 return check_pieced_value_bits (value, bit_offset, bit_length,
937 DWARF_VALUE_IMPLICIT_POINTER);
940 /* A wrapper function for get_frame_address_in_block. */
943 get_frame_address_in_block_wrapper (void *baton)
945 return get_frame_address_in_block (baton);
948 /* An implementation of an lval_funcs method to indirect through a
949 pointer. This handles the synthetic pointer case when needed. */
951 static struct value *
952 indirect_pieced_value (struct value *value)
954 struct piece_closure *c
955 = (struct piece_closure *) value_computed_closure (value);
957 struct frame_info *frame;
958 struct dwarf2_locexpr_baton baton;
959 int i, bit_offset, bit_length;
960 struct dwarf_expr_piece *piece = NULL;
961 struct value *result;
964 type = value_type (value);
965 if (TYPE_CODE (type) != TYPE_CODE_PTR)
968 bit_length = 8 * TYPE_LENGTH (type);
969 bit_offset = 8 * value_offset (value);
970 if (value_bitsize (value))
971 bit_offset += value_bitpos (value);
973 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
975 struct dwarf_expr_piece *p = &c->pieces[i];
976 size_t this_size_bits = p->size;
980 if (bit_offset >= this_size_bits)
982 bit_offset -= this_size_bits;
986 bit_length -= this_size_bits - bit_offset;
990 bit_length -= this_size_bits;
992 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
996 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
1002 frame = get_selected_frame (_("No frame selected."));
1003 byte_offset = value_as_address (value);
1006 baton = dwarf2_fetch_die_location_block (piece->v.ptr.die, c->per_cu,
1007 get_frame_address_in_block_wrapper,
1010 result = dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
1011 baton.data, baton.size, baton.per_cu,
1018 copy_pieced_value_closure (const struct value *v)
1020 struct piece_closure *c
1021 = (struct piece_closure *) value_computed_closure (v);
1028 free_pieced_value_closure (struct value *v)
1030 struct piece_closure *c
1031 = (struct piece_closure *) value_computed_closure (v);
1041 /* Functions for accessing a variable described by DW_OP_piece. */
1042 static struct lval_funcs pieced_value_funcs = {
1045 check_pieced_value_validity,
1046 check_pieced_value_invalid,
1047 indirect_pieced_value,
1048 check_pieced_synthetic_pointer,
1049 copy_pieced_value_closure,
1050 free_pieced_value_closure
1053 /* Helper function which throws an error if a synthetic pointer is
1057 invalid_synthetic_pointer (void)
1059 error (_("access outside bounds of object "
1060 "referenced via synthetic pointer"));
1063 /* Evaluate a location description, starting at DATA and with length
1064 SIZE, to find the current location of variable of TYPE in the
1065 context of FRAME. BYTE_OFFSET is applied after the contents are
1068 static struct value *
1069 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1070 const gdb_byte *data, unsigned short size,
1071 struct dwarf2_per_cu_data *per_cu,
1072 LONGEST byte_offset)
1074 struct value *retval;
1075 struct dwarf_expr_baton baton;
1076 struct dwarf_expr_context *ctx;
1077 struct cleanup *old_chain;
1078 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1079 volatile struct gdb_exception ex;
1081 if (byte_offset < 0)
1082 invalid_synthetic_pointer ();
1086 retval = allocate_value (type);
1087 VALUE_LVAL (retval) = not_lval;
1088 set_value_optimized_out (retval, 1);
1092 baton.frame = frame;
1093 baton.per_cu = per_cu;
1095 ctx = new_dwarf_expr_context ();
1096 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1098 ctx->gdbarch = get_objfile_arch (objfile);
1099 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1100 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1101 ctx->baton = &baton;
1102 ctx->read_reg = dwarf_expr_read_reg;
1103 ctx->read_mem = dwarf_expr_read_mem;
1104 ctx->get_frame_base = dwarf_expr_frame_base;
1105 ctx->get_frame_cfa = dwarf_expr_frame_cfa;
1106 ctx->get_frame_pc = dwarf_expr_frame_pc;
1107 ctx->get_tls_address = dwarf_expr_tls_address;
1108 ctx->dwarf_call = dwarf_expr_dwarf_call;
1110 TRY_CATCH (ex, RETURN_MASK_ERROR)
1112 dwarf_expr_eval (ctx, data, size);
1116 if (ex.error == NOT_AVAILABLE_ERROR)
1118 retval = allocate_value (type);
1119 mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
1123 throw_exception (ex);
1126 if (ctx->num_pieces > 0)
1128 struct piece_closure *c;
1129 struct frame_id frame_id = get_frame_id (frame);
1130 ULONGEST bit_size = 0;
1133 for (i = 0; i < ctx->num_pieces; ++i)
1134 bit_size += ctx->pieces[i].size;
1135 if (8 * (byte_offset + TYPE_LENGTH (type)) > bit_size)
1136 invalid_synthetic_pointer ();
1138 c = allocate_piece_closure (per_cu, ctx->num_pieces, ctx->pieces,
1140 retval = allocate_computed_value (type, &pieced_value_funcs, c);
1141 VALUE_FRAME_ID (retval) = frame_id;
1142 set_value_offset (retval, byte_offset);
1146 switch (ctx->location)
1148 case DWARF_VALUE_REGISTER:
1150 struct gdbarch *arch = get_frame_arch (frame);
1151 ULONGEST dwarf_regnum = dwarf_expr_fetch (ctx, 0);
1152 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
1154 if (byte_offset != 0)
1155 error (_("cannot use offset on synthetic pointer to register"));
1156 if (gdb_regnum != -1)
1157 retval = value_from_register (type, gdb_regnum, frame);
1159 error (_("Unable to access DWARF register number %s"),
1160 paddress (arch, dwarf_regnum));
1164 case DWARF_VALUE_MEMORY:
1166 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
1167 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
1169 retval = allocate_value_lazy (type);
1170 VALUE_LVAL (retval) = lval_memory;
1171 if (in_stack_memory)
1172 set_value_stack (retval, 1);
1173 set_value_address (retval, address + byte_offset);
1177 case DWARF_VALUE_STACK:
1179 ULONGEST value = dwarf_expr_fetch (ctx, 0);
1180 bfd_byte *contents, *tem;
1181 size_t n = ctx->addr_size;
1183 if (byte_offset + TYPE_LENGTH (type) > n)
1184 invalid_synthetic_pointer ();
1187 store_unsigned_integer (tem, n,
1188 gdbarch_byte_order (ctx->gdbarch),
1194 retval = allocate_value (type);
1195 contents = value_contents_raw (retval);
1196 if (n > TYPE_LENGTH (type))
1197 n = TYPE_LENGTH (type);
1198 memcpy (contents, tem, n);
1202 case DWARF_VALUE_LITERAL:
1205 const bfd_byte *ldata;
1206 size_t n = ctx->len;
1208 if (byte_offset + TYPE_LENGTH (type) > n)
1209 invalid_synthetic_pointer ();
1211 retval = allocate_value (type);
1212 contents = value_contents_raw (retval);
1214 ldata = ctx->data + byte_offset;
1217 if (n > TYPE_LENGTH (type))
1218 n = TYPE_LENGTH (type);
1219 memcpy (contents, ldata, n);
1223 case DWARF_VALUE_OPTIMIZED_OUT:
1224 retval = allocate_value (type);
1225 VALUE_LVAL (retval) = not_lval;
1226 set_value_optimized_out (retval, 1);
1229 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1230 operation by execute_stack_op. */
1231 case DWARF_VALUE_IMPLICIT_POINTER:
1232 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1233 it can only be encountered when making a piece. */
1235 internal_error (__FILE__, __LINE__, _("invalid location type"));
1239 set_value_initialized (retval, ctx->initialized);
1241 do_cleanups (old_chain);
1246 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1247 passes 0 as the byte_offset. */
1250 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
1251 const gdb_byte *data, unsigned short size,
1252 struct dwarf2_per_cu_data *per_cu)
1254 return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, 0);
1258 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1260 struct needs_frame_baton
1263 struct dwarf2_per_cu_data *per_cu;
1266 /* Reads from registers do require a frame. */
1268 needs_frame_read_reg (void *baton, int regnum)
1270 struct needs_frame_baton *nf_baton = baton;
1272 nf_baton->needs_frame = 1;
1276 /* Reads from memory do not require a frame. */
1278 needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
1280 memset (buf, 0, len);
1283 /* Frame-relative accesses do require a frame. */
1285 needs_frame_frame_base (void *baton, const gdb_byte **start, size_t * length)
1287 static gdb_byte lit0 = DW_OP_lit0;
1288 struct needs_frame_baton *nf_baton = baton;
1293 nf_baton->needs_frame = 1;
1296 /* CFA accesses require a frame. */
1299 needs_frame_frame_cfa (void *baton)
1301 struct needs_frame_baton *nf_baton = baton;
1303 nf_baton->needs_frame = 1;
1307 /* Thread-local accesses do require a frame. */
1309 needs_frame_tls_address (void *baton, CORE_ADDR offset)
1311 struct needs_frame_baton *nf_baton = baton;
1313 nf_baton->needs_frame = 1;
1317 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
1320 needs_frame_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1322 struct needs_frame_baton *nf_baton = ctx->baton;
1324 per_cu_dwarf_call (ctx, die_offset, nf_baton->per_cu,
1325 ctx->get_frame_pc, ctx->baton);
1328 /* Return non-zero iff the location expression at DATA (length SIZE)
1329 requires a frame to evaluate. */
1332 dwarf2_loc_desc_needs_frame (const gdb_byte *data, unsigned short size,
1333 struct dwarf2_per_cu_data *per_cu)
1335 struct needs_frame_baton baton;
1336 struct dwarf_expr_context *ctx;
1338 struct cleanup *old_chain;
1339 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1341 baton.needs_frame = 0;
1342 baton.per_cu = per_cu;
1344 ctx = new_dwarf_expr_context ();
1345 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1347 ctx->gdbarch = get_objfile_arch (objfile);
1348 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1349 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1350 ctx->baton = &baton;
1351 ctx->read_reg = needs_frame_read_reg;
1352 ctx->read_mem = needs_frame_read_mem;
1353 ctx->get_frame_base = needs_frame_frame_base;
1354 ctx->get_frame_cfa = needs_frame_frame_cfa;
1355 ctx->get_frame_pc = needs_frame_frame_cfa;
1356 ctx->get_tls_address = needs_frame_tls_address;
1357 ctx->dwarf_call = needs_frame_dwarf_call;
1359 dwarf_expr_eval (ctx, data, size);
1361 in_reg = ctx->location == DWARF_VALUE_REGISTER;
1363 if (ctx->num_pieces > 0)
1367 /* If the location has several pieces, and any of them are in
1368 registers, then we will need a frame to fetch them from. */
1369 for (i = 0; i < ctx->num_pieces; i++)
1370 if (ctx->pieces[i].location == DWARF_VALUE_REGISTER)
1374 do_cleanups (old_chain);
1376 return baton.needs_frame || in_reg;
1379 /* A helper function that throws an unimplemented error mentioning a
1380 given DWARF operator. */
1383 unimplemented (unsigned int op)
1385 const char *name = dwarf_stack_op_name (op);
1388 error (_("DWARF operator %s cannot be translated to an agent expression"),
1391 error (_("Unknown DWARF operator 0x%02x cannot be translated "
1392 "to an agent expression"),
1396 /* A helper function to convert a DWARF register to an arch register.
1397 ARCH is the architecture.
1398 DWARF_REG is the register.
1399 This will throw an exception if the DWARF register cannot be
1400 translated to an architecture register. */
1403 translate_register (struct gdbarch *arch, int dwarf_reg)
1405 int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
1407 error (_("Unable to access DWARF register number %d"), dwarf_reg);
1411 /* A helper function that emits an access to memory. ARCH is the
1412 target architecture. EXPR is the expression which we are building.
1413 NBITS is the number of bits we want to read. This emits the
1414 opcodes needed to read the memory and then extract the desired
1418 access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits)
1420 ULONGEST nbytes = (nbits + 7) / 8;
1422 gdb_assert (nbits > 0 && nbits <= sizeof (LONGEST));
1425 ax_trace_quick (expr, nbytes);
1428 ax_simple (expr, aop_ref8);
1429 else if (nbits <= 16)
1430 ax_simple (expr, aop_ref16);
1431 else if (nbits <= 32)
1432 ax_simple (expr, aop_ref32);
1434 ax_simple (expr, aop_ref64);
1436 /* If we read exactly the number of bytes we wanted, we're done. */
1437 if (8 * nbytes == nbits)
1440 if (gdbarch_bits_big_endian (arch))
1442 /* On a bits-big-endian machine, we want the high-order
1444 ax_const_l (expr, 8 * nbytes - nbits);
1445 ax_simple (expr, aop_rsh_unsigned);
1449 /* On a bits-little-endian box, we want the low-order NBITS. */
1450 ax_zero_ext (expr, nbits);
1454 /* A helper function to return the frame's PC. */
1457 get_ax_pc (void *baton)
1459 struct agent_expr *expr = baton;
1464 /* Compile a DWARF location expression to an agent expression.
1466 EXPR is the agent expression we are building.
1467 LOC is the agent value we modify.
1468 ARCH is the architecture.
1469 ADDR_SIZE is the size of addresses, in bytes.
1470 OP_PTR is the start of the location expression.
1471 OP_END is one past the last byte of the location expression.
1473 This will throw an exception for various kinds of errors -- for
1474 example, if the expression cannot be compiled, or if the expression
1478 dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
1479 struct gdbarch *arch, unsigned int addr_size,
1480 const gdb_byte *op_ptr, const gdb_byte *op_end,
1481 struct dwarf2_per_cu_data *per_cu)
1483 struct cleanup *cleanups;
1485 VEC(int) *dw_labels = NULL, *patches = NULL;
1486 const gdb_byte * const base = op_ptr;
1487 const gdb_byte *previous_piece = op_ptr;
1488 enum bfd_endian byte_order = gdbarch_byte_order (arch);
1489 ULONGEST bits_collected = 0;
1490 unsigned int addr_size_bits = 8 * addr_size;
1491 int bits_big_endian = gdbarch_bits_big_endian (arch);
1493 offsets = xmalloc ((op_end - op_ptr) * sizeof (int));
1494 cleanups = make_cleanup (xfree, offsets);
1496 for (i = 0; i < op_end - op_ptr; ++i)
1499 make_cleanup (VEC_cleanup (int), &dw_labels);
1500 make_cleanup (VEC_cleanup (int), &patches);
1502 /* By default we are making an address. */
1503 loc->kind = axs_lvalue_memory;
1505 while (op_ptr < op_end)
1507 enum dwarf_location_atom op = *op_ptr;
1508 ULONGEST uoffset, reg;
1512 offsets[op_ptr - base] = expr->len;
1515 /* Our basic approach to code generation is to map DWARF
1516 operations directly to AX operations. However, there are
1519 First, DWARF works on address-sized units, but AX always uses
1520 LONGEST. For most operations we simply ignore this
1521 difference; instead we generate sign extensions as needed
1522 before division and comparison operations. It would be nice
1523 to omit the sign extensions, but there is no way to determine
1524 the size of the target's LONGEST. (This code uses the size
1525 of the host LONGEST in some cases -- that is a bug but it is
1528 Second, some DWARF operations cannot be translated to AX.
1529 For these we simply fail. See
1530 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
1565 ax_const_l (expr, op - DW_OP_lit0);
1569 uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
1570 op_ptr += addr_size;
1571 /* Some versions of GCC emit DW_OP_addr before
1572 DW_OP_GNU_push_tls_address. In this case the value is an
1573 index, not an address. We don't support things like
1574 branching between the address and the TLS op. */
1575 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
1576 uoffset += dwarf2_per_cu_text_offset (per_cu);
1577 ax_const_l (expr, uoffset);
1581 ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order));
1585 ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order));
1589 ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order));
1593 ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order));
1597 ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order));
1601 ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order));
1605 ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order));
1609 ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order));
1613 op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
1614 ax_const_l (expr, uoffset);
1617 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1618 ax_const_l (expr, offset);
1653 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
1654 loc->u.reg = translate_register (arch, op - DW_OP_reg0);
1655 loc->kind = axs_lvalue_register;
1659 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1660 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
1661 loc->u.reg = translate_register (arch, reg);
1662 loc->kind = axs_lvalue_register;
1665 case DW_OP_implicit_value:
1669 op_ptr = read_uleb128 (op_ptr, op_end, &len);
1670 if (op_ptr + len > op_end)
1671 error (_("DW_OP_implicit_value: too few bytes available."));
1672 if (len > sizeof (ULONGEST))
1673 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
1676 ax_const_l (expr, extract_unsigned_integer (op_ptr, len,
1679 dwarf_expr_require_composition (op_ptr, op_end,
1680 "DW_OP_implicit_value");
1682 loc->kind = axs_rvalue;
1686 case DW_OP_stack_value:
1687 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
1688 loc->kind = axs_rvalue;
1723 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1724 i = translate_register (arch, op - DW_OP_breg0);
1728 ax_const_l (expr, offset);
1729 ax_simple (expr, aop_add);
1734 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1735 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1736 i = translate_register (arch, reg);
1740 ax_const_l (expr, offset);
1741 ax_simple (expr, aop_add);
1747 const gdb_byte *datastart;
1749 unsigned int before_stack_len;
1751 struct symbol *framefunc;
1752 LONGEST base_offset = 0;
1754 b = block_for_pc (expr->scope);
1757 error (_("No block found for address"));
1759 framefunc = block_linkage_function (b);
1762 error (_("No function found for block"));
1764 dwarf_expr_frame_base_1 (framefunc, expr->scope,
1765 &datastart, &datalen);
1767 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1768 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, datastart,
1769 datastart + datalen, per_cu);
1773 ax_const_l (expr, offset);
1774 ax_simple (expr, aop_add);
1777 loc->kind = axs_lvalue_memory;
1782 ax_simple (expr, aop_dup);
1786 ax_simple (expr, aop_pop);
1791 ax_pick (expr, offset);
1795 ax_simple (expr, aop_swap);
1803 ax_simple (expr, aop_rot);
1807 case DW_OP_deref_size:
1811 if (op == DW_OP_deref_size)
1819 ax_simple (expr, aop_ref8);
1822 ax_simple (expr, aop_ref16);
1825 ax_simple (expr, aop_ref32);
1828 ax_simple (expr, aop_ref64);
1831 /* Note that dwarf_stack_op_name will never return
1833 error (_("Unsupported size %d in %s"),
1834 size, dwarf_stack_op_name (op));
1840 /* Sign extend the operand. */
1841 ax_ext (expr, addr_size_bits);
1842 ax_simple (expr, aop_dup);
1843 ax_const_l (expr, 0);
1844 ax_simple (expr, aop_less_signed);
1845 ax_simple (expr, aop_log_not);
1846 i = ax_goto (expr, aop_if_goto);
1847 /* We have to emit 0 - X. */
1848 ax_const_l (expr, 0);
1849 ax_simple (expr, aop_swap);
1850 ax_simple (expr, aop_sub);
1851 ax_label (expr, i, expr->len);
1855 /* No need to sign extend here. */
1856 ax_const_l (expr, 0);
1857 ax_simple (expr, aop_swap);
1858 ax_simple (expr, aop_sub);
1862 /* Sign extend the operand. */
1863 ax_ext (expr, addr_size_bits);
1864 ax_simple (expr, aop_bit_not);
1867 case DW_OP_plus_uconst:
1868 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1869 /* It would be really weird to emit `DW_OP_plus_uconst 0',
1870 but we micro-optimize anyhow. */
1873 ax_const_l (expr, reg);
1874 ax_simple (expr, aop_add);
1879 ax_simple (expr, aop_bit_and);
1883 /* Sign extend the operands. */
1884 ax_ext (expr, addr_size_bits);
1885 ax_simple (expr, aop_swap);
1886 ax_ext (expr, addr_size_bits);
1887 ax_simple (expr, aop_swap);
1888 ax_simple (expr, aop_div_signed);
1892 ax_simple (expr, aop_sub);
1896 ax_simple (expr, aop_rem_unsigned);
1900 ax_simple (expr, aop_mul);
1904 ax_simple (expr, aop_bit_or);
1908 ax_simple (expr, aop_add);
1912 ax_simple (expr, aop_lsh);
1916 ax_simple (expr, aop_rsh_unsigned);
1920 ax_simple (expr, aop_rsh_signed);
1924 ax_simple (expr, aop_bit_xor);
1928 /* Sign extend the operands. */
1929 ax_ext (expr, addr_size_bits);
1930 ax_simple (expr, aop_swap);
1931 ax_ext (expr, addr_size_bits);
1932 /* Note no swap here: A <= B is !(B < A). */
1933 ax_simple (expr, aop_less_signed);
1934 ax_simple (expr, aop_log_not);
1938 /* Sign extend the operands. */
1939 ax_ext (expr, addr_size_bits);
1940 ax_simple (expr, aop_swap);
1941 ax_ext (expr, addr_size_bits);
1942 ax_simple (expr, aop_swap);
1943 /* A >= B is !(A < B). */
1944 ax_simple (expr, aop_less_signed);
1945 ax_simple (expr, aop_log_not);
1949 /* Sign extend the operands. */
1950 ax_ext (expr, addr_size_bits);
1951 ax_simple (expr, aop_swap);
1952 ax_ext (expr, addr_size_bits);
1953 /* No need for a second swap here. */
1954 ax_simple (expr, aop_equal);
1958 /* Sign extend the operands. */
1959 ax_ext (expr, addr_size_bits);
1960 ax_simple (expr, aop_swap);
1961 ax_ext (expr, addr_size_bits);
1962 ax_simple (expr, aop_swap);
1963 ax_simple (expr, aop_less_signed);
1967 /* Sign extend the operands. */
1968 ax_ext (expr, addr_size_bits);
1969 ax_simple (expr, aop_swap);
1970 ax_ext (expr, addr_size_bits);
1971 /* Note no swap here: A > B is B < A. */
1972 ax_simple (expr, aop_less_signed);
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 /* No need for a swap here. */
1981 ax_simple (expr, aop_equal);
1982 ax_simple (expr, aop_log_not);
1985 case DW_OP_call_frame_cfa:
1986 dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu);
1987 loc->kind = axs_lvalue_memory;
1990 case DW_OP_GNU_push_tls_address:
1995 offset = extract_signed_integer (op_ptr, 2, byte_order);
1997 i = ax_goto (expr, aop_goto);
1998 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
1999 VEC_safe_push (int, patches, i);
2003 offset = extract_signed_integer (op_ptr, 2, byte_order);
2005 /* Zero extend the operand. */
2006 ax_zero_ext (expr, addr_size_bits);
2007 i = ax_goto (expr, aop_if_goto);
2008 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
2009 VEC_safe_push (int, patches, i);
2016 case DW_OP_bit_piece:
2018 ULONGEST size, offset;
2020 if (op_ptr - 1 == previous_piece)
2021 error (_("Cannot translate empty pieces to agent expressions"));
2022 previous_piece = op_ptr - 1;
2024 op_ptr = read_uleb128 (op_ptr, op_end, &size);
2025 if (op == DW_OP_piece)
2031 op_ptr = read_uleb128 (op_ptr, op_end, &offset);
2033 if (bits_collected + size > 8 * sizeof (LONGEST))
2034 error (_("Expression pieces exceed word size"));
2036 /* Access the bits. */
2039 case axs_lvalue_register:
2040 ax_reg (expr, loc->u.reg);
2043 case axs_lvalue_memory:
2044 /* Offset the pointer, if needed. */
2047 ax_const_l (expr, offset / 8);
2048 ax_simple (expr, aop_add);
2051 access_memory (arch, expr, size);
2055 /* For a bits-big-endian target, shift up what we already
2056 have. For a bits-little-endian target, shift up the
2057 new data. Note that there is a potential bug here if
2058 the DWARF expression leaves multiple values on the
2060 if (bits_collected > 0)
2062 if (bits_big_endian)
2064 ax_simple (expr, aop_swap);
2065 ax_const_l (expr, size);
2066 ax_simple (expr, aop_lsh);
2067 /* We don't need a second swap here, because
2068 aop_bit_or is symmetric. */
2072 ax_const_l (expr, size);
2073 ax_simple (expr, aop_lsh);
2075 ax_simple (expr, aop_bit_or);
2078 bits_collected += size;
2079 loc->kind = axs_rvalue;
2083 case DW_OP_GNU_uninit:
2089 struct dwarf2_locexpr_baton block;
2090 int size = (op == DW_OP_call2 ? 2 : 4);
2092 uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
2095 block = dwarf2_fetch_die_location_block (uoffset, per_cu,
2098 /* DW_OP_call_ref is currently not supported. */
2099 gdb_assert (block.per_cu == per_cu);
2101 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
2102 block.data, block.data + block.size,
2107 case DW_OP_call_ref:
2115 /* Patch all the branches we emitted. */
2116 for (i = 0; i < VEC_length (int, patches); ++i)
2118 int targ = offsets[VEC_index (int, dw_labels, i)];
2120 internal_error (__FILE__, __LINE__, _("invalid label"));
2121 ax_label (expr, VEC_index (int, patches, i), targ);
2124 do_cleanups (cleanups);
2128 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2129 evaluator to calculate the location. */
2130 static struct value *
2131 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
2133 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2136 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
2137 dlbaton->size, dlbaton->per_cu);
2142 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2144 locexpr_read_needs_frame (struct symbol *symbol)
2146 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2148 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
2152 /* Return true if DATA points to the end of a piece. END is one past
2153 the last byte in the expression. */
2156 piece_end_p (const gdb_byte *data, const gdb_byte *end)
2158 return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece;
2161 /* Nicely describe a single piece of a location, returning an updated
2162 position in the bytecode sequence. This function cannot recognize
2163 all locations; if a location is not recognized, it simply returns
2166 static const gdb_byte *
2167 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
2168 CORE_ADDR addr, struct objfile *objfile,
2169 const gdb_byte *data, const gdb_byte *end,
2170 unsigned int addr_size)
2172 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2175 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
2177 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_reg0);
2178 fprintf_filtered (stream, _("a variable in $%s"),
2179 gdbarch_register_name (gdbarch, regno));
2182 else if (data[0] == DW_OP_regx)
2186 data = read_uleb128 (data + 1, end, ®);
2187 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
2188 fprintf_filtered (stream, _("a variable in $%s"),
2189 gdbarch_register_name (gdbarch, regno));
2191 else if (data[0] == DW_OP_fbreg)
2194 struct symbol *framefunc;
2196 LONGEST frame_offset;
2197 const gdb_byte *base_data, *new_data, *save_data = data;
2199 LONGEST base_offset = 0;
2201 new_data = read_sleb128 (data + 1, end, &frame_offset);
2202 if (!piece_end_p (new_data, end))
2206 b = block_for_pc (addr);
2209 error (_("No block found for address for symbol \"%s\"."),
2210 SYMBOL_PRINT_NAME (symbol));
2212 framefunc = block_linkage_function (b);
2215 error (_("No function found for block for symbol \"%s\"."),
2216 SYMBOL_PRINT_NAME (symbol));
2218 dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
2220 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
2222 const gdb_byte *buf_end;
2224 frame_reg = base_data[0] - DW_OP_breg0;
2225 buf_end = read_sleb128 (base_data + 1,
2226 base_data + base_size, &base_offset);
2227 if (buf_end != base_data + base_size)
2228 error (_("Unexpected opcode after "
2229 "DW_OP_breg%u for symbol \"%s\"."),
2230 frame_reg, SYMBOL_PRINT_NAME (symbol));
2232 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
2234 /* The frame base is just the register, with no offset. */
2235 frame_reg = base_data[0] - DW_OP_reg0;
2240 /* We don't know what to do with the frame base expression,
2241 so we can't trace this variable; give up. */
2245 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, frame_reg);
2247 fprintf_filtered (stream,
2248 _("a variable at frame base reg $%s offset %s+%s"),
2249 gdbarch_register_name (gdbarch, regno),
2250 plongest (base_offset), plongest (frame_offset));
2252 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31
2253 && piece_end_p (data, end))
2257 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_breg0);
2259 data = read_sleb128 (data + 1, end, &offset);
2261 fprintf_filtered (stream,
2262 _("a variable at offset %s from base reg $%s"),
2264 gdbarch_register_name (gdbarch, regno));
2267 /* The location expression for a TLS variable looks like this (on a
2270 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2271 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2273 0x3 is the encoding for DW_OP_addr, which has an operand as long
2274 as the size of an address on the target machine (here is 8
2275 bytes). Note that more recent version of GCC emit DW_OP_const4u
2276 or DW_OP_const8u, depending on address size, rather than
2277 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
2278 The operand represents the offset at which the variable is within
2279 the thread local storage. */
2281 else if (data + 1 + addr_size < end
2282 && (data[0] == DW_OP_addr
2283 || (addr_size == 4 && data[0] == DW_OP_const4u)
2284 || (addr_size == 8 && data[0] == DW_OP_const8u))
2285 && data[1 + addr_size] == DW_OP_GNU_push_tls_address
2286 && piece_end_p (data + 2 + addr_size, end))
2289 offset = extract_unsigned_integer (data + 1, addr_size,
2290 gdbarch_byte_order (gdbarch));
2292 fprintf_filtered (stream,
2293 _("a thread-local variable at offset 0x%s "
2294 "in the thread-local storage for `%s'"),
2295 phex_nz (offset, addr_size), objfile->name);
2297 data += 1 + addr_size + 1;
2299 else if (data[0] >= DW_OP_lit0
2300 && data[0] <= DW_OP_lit31
2302 && data[1] == DW_OP_stack_value)
2304 fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0);
2311 /* Disassemble an expression, stopping at the end of a piece or at the
2312 end of the expression. Returns a pointer to the next unread byte
2313 in the input expression. If ALL is nonzero, then this function
2314 will keep going until it reaches the end of the expression. */
2316 static const gdb_byte *
2317 disassemble_dwarf_expression (struct ui_file *stream,
2318 struct gdbarch *arch, unsigned int addr_size,
2320 const gdb_byte *data, const gdb_byte *end,
2323 const gdb_byte *start = data;
2325 fprintf_filtered (stream, _("a complex DWARF expression:\n"));
2329 || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
2331 enum dwarf_location_atom op = *data++;
2336 name = dwarf_stack_op_name (op);
2339 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
2340 op, (long) (data - start));
2341 fprintf_filtered (stream, " % 4ld: %s", (long) (data - start), name);
2346 ul = extract_unsigned_integer (data, addr_size,
2347 gdbarch_byte_order (arch));
2349 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
2353 ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch));
2355 fprintf_filtered (stream, " %s", pulongest (ul));
2358 l = extract_signed_integer (data, 1, gdbarch_byte_order (arch));
2360 fprintf_filtered (stream, " %s", plongest (l));
2363 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
2365 fprintf_filtered (stream, " %s", pulongest (ul));
2368 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2370 fprintf_filtered (stream, " %s", plongest (l));
2373 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
2375 fprintf_filtered (stream, " %s", pulongest (ul));
2378 l = extract_signed_integer (data, 4, gdbarch_byte_order (arch));
2380 fprintf_filtered (stream, " %s", plongest (l));
2383 ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch));
2385 fprintf_filtered (stream, " %s", pulongest (ul));
2388 l = extract_signed_integer (data, 8, gdbarch_byte_order (arch));
2390 fprintf_filtered (stream, " %s", plongest (l));
2393 data = read_uleb128 (data, end, &ul);
2394 fprintf_filtered (stream, " %s", pulongest (ul));
2397 data = read_sleb128 (data, end, &l);
2398 fprintf_filtered (stream, " %s", plongest (l));
2433 fprintf_filtered (stream, " [$%s]",
2434 gdbarch_register_name (arch, op - DW_OP_reg0));
2438 data = read_uleb128 (data, end, &ul);
2439 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
2440 gdbarch_register_name (arch, (int) ul));
2443 case DW_OP_implicit_value:
2444 data = read_uleb128 (data, end, &ul);
2446 fprintf_filtered (stream, " %s", pulongest (ul));
2481 data = read_sleb128 (data, end, &l);
2482 fprintf_filtered (stream, " %s [$%s]", plongest (l),
2483 gdbarch_register_name (arch, op - DW_OP_breg0));
2487 data = read_uleb128 (data, end, &ul);
2488 data = read_sleb128 (data, end, &l);
2489 fprintf_filtered (stream, " register %s [$%s] offset %s",
2491 gdbarch_register_name (arch, (int) ul),
2496 data = read_sleb128 (data, end, &l);
2497 fprintf_filtered (stream, " %s", plongest (l));
2500 case DW_OP_xderef_size:
2501 case DW_OP_deref_size:
2503 fprintf_filtered (stream, " %d", *data);
2507 case DW_OP_plus_uconst:
2508 data = read_uleb128 (data, end, &ul);
2509 fprintf_filtered (stream, " %s", pulongest (ul));
2513 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2515 fprintf_filtered (stream, " to %ld",
2516 (long) (data + l - start));
2520 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2522 fprintf_filtered (stream, " %ld",
2523 (long) (data + l - start));
2527 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
2529 fprintf_filtered (stream, " offset %s", phex_nz (ul, 2));
2533 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
2535 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
2538 case DW_OP_call_ref:
2539 ul = extract_unsigned_integer (data, offset_size,
2540 gdbarch_byte_order (arch));
2541 data += offset_size;
2542 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
2546 data = read_uleb128 (data, end, &ul);
2547 fprintf_filtered (stream, " %s (bytes)", pulongest (ul));
2550 case DW_OP_bit_piece:
2554 data = read_uleb128 (data, end, &ul);
2555 data = read_uleb128 (data, end, &offset);
2556 fprintf_filtered (stream, " size %s offset %s (bits)",
2557 pulongest (ul), pulongest (offset));
2561 case DW_OP_GNU_implicit_pointer:
2563 ul = extract_unsigned_integer (data, offset_size,
2564 gdbarch_byte_order (arch));
2565 data += offset_size;
2567 data = read_sleb128 (data, end, &l);
2569 fprintf_filtered (stream, " DIE %s offset %s",
2570 phex_nz (ul, offset_size),
2576 fprintf_filtered (stream, "\n");
2582 /* Describe a single location, which may in turn consist of multiple
2586 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
2587 struct ui_file *stream,
2588 const gdb_byte *data, int size,
2589 struct objfile *objfile, unsigned int addr_size,
2592 const gdb_byte *end = data + size;
2593 int first_piece = 1, bad = 0;
2597 const gdb_byte *here = data;
2598 int disassemble = 1;
2603 fprintf_filtered (stream, _(", and "));
2605 if (!dwarf2_always_disassemble)
2607 data = locexpr_describe_location_piece (symbol, stream,
2609 data, end, addr_size);
2610 /* If we printed anything, or if we have an empty piece,
2611 then don't disassemble. */
2613 || data[0] == DW_OP_piece
2614 || data[0] == DW_OP_bit_piece)
2618 data = disassemble_dwarf_expression (stream,
2619 get_objfile_arch (objfile),
2620 addr_size, offset_size, data, end,
2621 dwarf2_always_disassemble);
2625 int empty = data == here;
2628 fprintf_filtered (stream, " ");
2629 if (data[0] == DW_OP_piece)
2633 data = read_uleb128 (data + 1, end, &bytes);
2636 fprintf_filtered (stream, _("an empty %s-byte piece"),
2639 fprintf_filtered (stream, _(" [%s-byte piece]"),
2642 else if (data[0] == DW_OP_bit_piece)
2644 ULONGEST bits, offset;
2646 data = read_uleb128 (data + 1, end, &bits);
2647 data = read_uleb128 (data, end, &offset);
2650 fprintf_filtered (stream,
2651 _("an empty %s-bit piece"),
2654 fprintf_filtered (stream,
2655 _(" [%s-bit piece, offset %s bits]"),
2656 pulongest (bits), pulongest (offset));
2666 if (bad || data > end)
2667 error (_("Corrupted DWARF2 expression for \"%s\"."),
2668 SYMBOL_PRINT_NAME (symbol));
2671 /* Print a natural-language description of SYMBOL to STREAM. This
2672 version is for a symbol with a single location. */
2675 locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
2676 struct ui_file *stream)
2678 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2679 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
2680 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2681 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
2683 locexpr_describe_location_1 (symbol, addr, stream,
2684 dlbaton->data, dlbaton->size,
2685 objfile, addr_size, offset_size);
2688 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2689 any necessary bytecode in AX. */
2692 locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2693 struct agent_expr *ax, struct axs_value *value)
2695 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2696 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2698 if (dlbaton->data == NULL || dlbaton->size == 0)
2699 value->optimized_out = 1;
2701 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size,
2702 dlbaton->data, dlbaton->data + dlbaton->size,
2706 /* The set of location functions used with the DWARF-2 expression
2708 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
2709 locexpr_read_variable,
2710 locexpr_read_needs_frame,
2711 locexpr_describe_location,
2712 locexpr_tracepoint_var_ref
2716 /* Wrapper functions for location lists. These generally find
2717 the appropriate location expression and call something above. */
2719 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2720 evaluator to calculate the location. */
2721 static struct value *
2722 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
2724 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2726 const gdb_byte *data;
2728 CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0;
2730 data = dwarf2_find_location_expression (dlbaton, &size, pc);
2733 val = allocate_value (SYMBOL_TYPE (symbol));
2734 VALUE_LVAL (val) = not_lval;
2735 set_value_optimized_out (val, 1);
2738 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
2744 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2746 loclist_read_needs_frame (struct symbol *symbol)
2748 /* If there's a location list, then assume we need to have a frame
2749 to choose the appropriate location expression. With tracking of
2750 global variables this is not necessarily true, but such tracking
2751 is disabled in GCC at the moment until we figure out how to
2757 /* Print a natural-language description of SYMBOL to STREAM. This
2758 version applies when there is a list of different locations, each
2759 with a specified address range. */
2762 loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
2763 struct ui_file *stream)
2765 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2766 CORE_ADDR low, high;
2767 const gdb_byte *loc_ptr, *buf_end;
2768 int length, first = 1;
2769 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
2770 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2771 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2772 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2773 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
2774 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
2775 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2776 /* Adjust base_address for relocatable objects. */
2777 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
2778 CORE_ADDR base_address = dlbaton->base_address + base_offset;
2780 loc_ptr = dlbaton->data;
2781 buf_end = dlbaton->data + dlbaton->size;
2783 fprintf_filtered (stream, _("multi-location:\n"));
2785 /* Iterate through locations until we run out. */
2788 if (buf_end - loc_ptr < 2 * addr_size)
2789 error (_("Corrupted DWARF expression for symbol \"%s\"."),
2790 SYMBOL_PRINT_NAME (symbol));
2793 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
2795 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
2796 loc_ptr += addr_size;
2799 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
2801 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
2802 loc_ptr += addr_size;
2804 /* A base-address-selection entry. */
2805 if ((low & base_mask) == base_mask)
2807 base_address = high + base_offset;
2808 fprintf_filtered (stream, _(" Base address %s"),
2809 paddress (gdbarch, base_address));
2813 /* An end-of-list entry. */
2814 if (low == 0 && high == 0)
2817 /* Otherwise, a location expression entry. */
2818 low += base_address;
2819 high += base_address;
2821 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
2824 /* (It would improve readability to print only the minimum
2825 necessary digits of the second number of the range.) */
2826 fprintf_filtered (stream, _(" Range %s-%s: "),
2827 paddress (gdbarch, low), paddress (gdbarch, high));
2829 /* Now describe this particular location. */
2830 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
2831 objfile, addr_size, offset_size);
2833 fprintf_filtered (stream, "\n");
2839 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2840 any necessary bytecode in AX. */
2842 loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2843 struct agent_expr *ax, struct axs_value *value)
2845 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2846 const gdb_byte *data;
2848 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2850 data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
2851 if (data == NULL || size == 0)
2852 value->optimized_out = 1;
2854 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size, data, data + size,
2858 /* The set of location functions used with the DWARF-2 expression
2859 evaluator and location lists. */
2860 const struct symbol_computed_ops dwarf2_loclist_funcs = {
2861 loclist_read_variable,
2862 loclist_read_needs_frame,
2863 loclist_describe_location,
2864 loclist_tracepoint_var_ref