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: Corrupted DWARF expression."));
91 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
93 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
97 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
99 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
100 loc_ptr += addr_size;
102 /* A base-address-selection entry. */
103 if ((low & base_mask) == base_mask)
105 base_address = high + base_offset;
109 /* An end-of-list entry. */
110 if (low == 0 && high == 0)
113 /* Otherwise, a location expression entry. */
115 high += base_address;
117 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
120 if (pc >= low && pc < high)
122 *locexpr_length = length;
130 /* This is the baton used when performing dwarf2 expression
132 struct dwarf_expr_baton
134 struct frame_info *frame;
135 struct dwarf2_per_cu_data *per_cu;
138 /* Helper functions for dwarf2_evaluate_loc_desc. */
140 /* Using the frame specified in BATON, return the value of register
141 REGNUM, treated as a pointer. */
143 dwarf_expr_read_reg (void *baton, int dwarf_regnum)
145 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
146 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
150 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
151 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
152 regnum, debaton->frame);
156 /* Read memory at ADDR (length LEN) into BUF. */
159 dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
161 read_memory (addr, buf, len);
164 /* Using the frame specified in BATON, find the location expression
165 describing the frame base. Return a pointer to it in START and
166 its length in LENGTH. */
168 dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
170 /* FIXME: cagney/2003-03-26: This code should be using
171 get_frame_base_address(), and then implement a dwarf2 specific
173 struct symbol *framefunc;
174 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
176 /* Use block_linkage_function, which returns a real (not inlined)
177 function, instead of get_frame_function, which may return an
179 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
181 /* If we found a frame-relative symbol then it was certainly within
182 some function associated with a frame. If we can't find the frame,
183 something has gone wrong. */
184 gdb_assert (framefunc != NULL);
186 dwarf_expr_frame_base_1 (framefunc,
187 get_frame_address_in_block (debaton->frame),
192 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
193 const gdb_byte **start, size_t *length)
195 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
197 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
199 struct dwarf2_loclist_baton *symbaton;
201 symbaton = SYMBOL_LOCATION_BATON (framefunc);
202 *start = dwarf2_find_location_expression (symbaton, length, pc);
206 struct dwarf2_locexpr_baton *symbaton;
208 symbaton = SYMBOL_LOCATION_BATON (framefunc);
209 if (symbaton != NULL)
211 *length = symbaton->size;
212 *start = symbaton->data;
219 error (_("Could not find the frame base for \"%s\"."),
220 SYMBOL_NATURAL_NAME (framefunc));
223 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
224 the frame in BATON. */
227 dwarf_expr_frame_cfa (void *baton)
229 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
231 return dwarf2_frame_cfa (debaton->frame);
234 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
235 the frame in BATON. */
238 dwarf_expr_frame_pc (void *baton)
240 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
242 return get_frame_address_in_block (debaton->frame);
245 /* Using the objfile specified in BATON, find the address for the
246 current thread's thread-local storage with offset OFFSET. */
248 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
250 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
251 struct objfile *objfile = dwarf2_per_cu_objfile (debaton->per_cu);
253 return target_translate_tls_address (objfile, offset);
256 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in current CU
257 (as is PER_CU). State of the CTX is not affected by the call and return. */
260 per_cu_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset,
261 struct dwarf2_per_cu_data *per_cu,
262 CORE_ADDR (*get_frame_pc) (void *baton),
265 struct dwarf2_locexpr_baton block;
267 block = dwarf2_fetch_die_location_block (die_offset, per_cu,
268 get_frame_pc, baton);
270 /* DW_OP_call_ref is currently not supported. */
271 gdb_assert (block.per_cu == per_cu);
273 dwarf_expr_eval (ctx, block.data, block.size);
276 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
279 dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
281 struct dwarf_expr_baton *debaton = ctx->baton;
283 return per_cu_dwarf_call (ctx, die_offset, debaton->per_cu,
284 ctx->get_frame_pc, ctx->baton);
289 /* Reference count. */
292 /* The CU from which this closure's expression came. */
293 struct dwarf2_per_cu_data *per_cu;
295 /* The number of pieces used to describe this variable. */
298 /* The target address size, used only for DWARF_VALUE_STACK. */
301 /* The pieces themselves. */
302 struct dwarf_expr_piece *pieces;
305 /* Allocate a closure for a value formed from separately-described
308 static struct piece_closure *
309 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
310 int n_pieces, struct dwarf_expr_piece *pieces,
313 struct piece_closure *c = XZALLOC (struct piece_closure);
317 c->n_pieces = n_pieces;
318 c->addr_size = addr_size;
319 c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
321 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
326 /* The lowest-level function to extract bits from a byte buffer.
327 SOURCE is the buffer. It is updated if we read to the end of a
329 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
330 updated to reflect the number of bits actually read.
331 NBITS is the number of bits we want to read. It is updated to
332 reflect the number of bits actually read. This function may read
334 BITS_BIG_ENDIAN is taken directly from gdbarch.
335 This function returns the extracted bits. */
338 extract_bits_primitive (const gdb_byte **source,
339 unsigned int *source_offset_bits,
340 int *nbits, int bits_big_endian)
342 unsigned int avail, mask, datum;
344 gdb_assert (*source_offset_bits < 8);
346 avail = 8 - *source_offset_bits;
350 mask = (1 << avail) - 1;
353 datum >>= 8 - (*source_offset_bits + *nbits);
355 datum >>= *source_offset_bits;
359 *source_offset_bits += avail;
360 if (*source_offset_bits >= 8)
362 *source_offset_bits -= 8;
369 /* Extract some bits from a source buffer and move forward in the
372 SOURCE is the source buffer. It is updated as bytes are read.
373 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
375 NBITS is the number of bits to read.
376 BITS_BIG_ENDIAN is taken directly from gdbarch.
378 This function returns the bits that were read. */
381 extract_bits (const gdb_byte **source, unsigned int *source_offset_bits,
382 int nbits, int bits_big_endian)
386 gdb_assert (nbits > 0 && nbits <= 8);
388 datum = extract_bits_primitive (source, source_offset_bits, &nbits,
394 more = extract_bits_primitive (source, source_offset_bits, &nbits,
406 /* Write some bits into a buffer and move forward in the buffer.
408 DATUM is the bits to write. The low-order bits of DATUM are used.
409 DEST is the destination buffer. It is updated as bytes are
411 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
413 NBITS is the number of valid bits in DATUM.
414 BITS_BIG_ENDIAN is taken directly from gdbarch. */
417 insert_bits (unsigned int datum,
418 gdb_byte *dest, unsigned int dest_offset_bits,
419 int nbits, int bits_big_endian)
423 gdb_assert (dest_offset_bits >= 0 && dest_offset_bits + nbits <= 8);
425 mask = (1 << nbits) - 1;
428 datum <<= 8 - (dest_offset_bits + nbits);
429 mask <<= 8 - (dest_offset_bits + nbits);
433 datum <<= dest_offset_bits;
434 mask <<= dest_offset_bits;
437 gdb_assert ((datum & ~mask) == 0);
439 *dest = (*dest & ~mask) | datum;
442 /* Copy bits from a source to a destination.
444 DEST is where the bits should be written.
445 DEST_OFFSET_BITS is the bit offset into DEST.
446 SOURCE is the source of bits.
447 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
448 BIT_COUNT is the number of bits to copy.
449 BITS_BIG_ENDIAN is taken directly from gdbarch. */
452 copy_bitwise (gdb_byte *dest, unsigned int dest_offset_bits,
453 const gdb_byte *source, unsigned int source_offset_bits,
454 unsigned int bit_count,
457 unsigned int dest_avail;
460 /* Reduce everything to byte-size pieces. */
461 dest += dest_offset_bits / 8;
462 dest_offset_bits %= 8;
463 source += source_offset_bits / 8;
464 source_offset_bits %= 8;
466 dest_avail = 8 - dest_offset_bits % 8;
468 /* See if we can fill the first destination byte. */
469 if (dest_avail < bit_count)
471 datum = extract_bits (&source, &source_offset_bits, dest_avail,
473 insert_bits (datum, dest, dest_offset_bits, dest_avail, bits_big_endian);
475 dest_offset_bits = 0;
476 bit_count -= dest_avail;
479 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
480 than 8 bits remaining. */
481 gdb_assert (dest_offset_bits % 8 == 0 || bit_count < 8);
482 for (; bit_count >= 8; bit_count -= 8)
484 datum = extract_bits (&source, &source_offset_bits, 8, bits_big_endian);
485 *dest++ = (gdb_byte) datum;
488 /* Finally, we may have a few leftover bits. */
489 gdb_assert (bit_count <= 8 - dest_offset_bits % 8);
492 datum = extract_bits (&source, &source_offset_bits, bit_count,
494 insert_bits (datum, dest, dest_offset_bits, bit_count, bits_big_endian);
499 read_pieced_value (struct value *v)
503 ULONGEST bits_to_skip;
505 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
506 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v));
508 size_t buffer_size = 0;
510 struct cleanup *cleanup;
512 = gdbarch_bits_big_endian (get_type_arch (value_type (v)));
514 if (value_type (v) != value_enclosing_type (v))
515 internal_error (__FILE__, __LINE__,
516 _("Should not be able to create a lazy value with "
517 "an enclosing type"));
519 cleanup = make_cleanup (free_current_contents, &buffer);
521 contents = value_contents_raw (v);
522 bits_to_skip = 8 * value_offset (v);
523 if (value_bitsize (v))
525 bits_to_skip += value_bitpos (v);
526 type_len = value_bitsize (v);
529 type_len = 8 * TYPE_LENGTH (value_type (v));
531 for (i = 0; i < c->n_pieces && offset < type_len; i++)
533 struct dwarf_expr_piece *p = &c->pieces[i];
534 size_t this_size, this_size_bits;
535 long dest_offset_bits, source_offset_bits, source_offset;
536 const gdb_byte *intermediate_buffer;
538 /* Compute size, source, and destination offsets for copying, in
540 this_size_bits = p->size;
541 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
543 bits_to_skip -= this_size_bits;
546 if (this_size_bits > type_len - offset)
547 this_size_bits = type_len - offset;
548 if (bits_to_skip > 0)
550 dest_offset_bits = 0;
551 source_offset_bits = bits_to_skip;
552 this_size_bits -= bits_to_skip;
557 dest_offset_bits = offset;
558 source_offset_bits = 0;
561 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
562 source_offset = source_offset_bits / 8;
563 if (buffer_size < this_size)
565 buffer_size = this_size;
566 buffer = xrealloc (buffer, buffer_size);
568 intermediate_buffer = buffer;
570 /* Copy from the source to DEST_BUFFER. */
573 case DWARF_VALUE_REGISTER:
575 struct gdbarch *arch = get_frame_arch (frame);
576 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
577 int reg_offset = source_offset;
579 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
580 && this_size < register_size (arch, gdb_regnum))
582 /* Big-endian, and we want less than full size. */
583 reg_offset = register_size (arch, gdb_regnum) - this_size;
584 /* We want the lower-order THIS_SIZE_BITS of the bytes
585 we extract from the register. */
586 source_offset_bits += 8 * this_size - this_size_bits;
589 if (gdb_regnum != -1)
591 get_frame_register_bytes (frame, gdb_regnum, reg_offset,
596 error (_("Unable to access DWARF register number %s"),
597 paddress (arch, p->v.value));
602 case DWARF_VALUE_MEMORY:
603 if (p->v.mem.in_stack_memory)
604 read_stack (p->v.mem.addr + source_offset, buffer, this_size);
606 read_memory (p->v.mem.addr + source_offset, buffer, this_size);
609 case DWARF_VALUE_STACK:
611 struct gdbarch *gdbarch = get_type_arch (value_type (v));
612 size_t n = this_size;
614 if (n > c->addr_size - source_offset)
615 n = (c->addr_size >= source_offset
616 ? c->addr_size - source_offset
622 else if (source_offset == 0)
623 store_unsigned_integer (buffer, n,
624 gdbarch_byte_order (gdbarch),
628 gdb_byte bytes[sizeof (ULONGEST)];
630 store_unsigned_integer (bytes, n + source_offset,
631 gdbarch_byte_order (gdbarch),
633 memcpy (buffer, bytes + source_offset, n);
638 case DWARF_VALUE_LITERAL:
640 size_t n = this_size;
642 if (n > p->v.literal.length - source_offset)
643 n = (p->v.literal.length >= source_offset
644 ? p->v.literal.length - source_offset
647 intermediate_buffer = p->v.literal.data + source_offset;
651 /* These bits show up as zeros -- but do not cause the value
652 to be considered optimized-out. */
653 case DWARF_VALUE_IMPLICIT_POINTER:
656 case DWARF_VALUE_OPTIMIZED_OUT:
657 set_value_optimized_out (v, 1);
661 internal_error (__FILE__, __LINE__, _("invalid location type"));
664 if (p->location != DWARF_VALUE_OPTIMIZED_OUT
665 && p->location != DWARF_VALUE_IMPLICIT_POINTER)
666 copy_bitwise (contents, dest_offset_bits,
667 intermediate_buffer, source_offset_bits % 8,
668 this_size_bits, bits_big_endian);
670 offset += this_size_bits;
673 do_cleanups (cleanup);
677 write_pieced_value (struct value *to, struct value *from)
681 ULONGEST bits_to_skip;
682 const gdb_byte *contents;
683 struct piece_closure *c = (struct piece_closure *) value_computed_closure (to);
684 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
686 size_t buffer_size = 0;
688 struct cleanup *cleanup;
690 = gdbarch_bits_big_endian (get_type_arch (value_type (to)));
694 set_value_optimized_out (to, 1);
698 cleanup = make_cleanup (free_current_contents, &buffer);
700 contents = value_contents (from);
701 bits_to_skip = 8 * value_offset (to);
702 if (value_bitsize (to))
704 bits_to_skip += value_bitpos (to);
705 type_len = value_bitsize (to);
708 type_len = 8 * TYPE_LENGTH (value_type (to));
710 for (i = 0; i < c->n_pieces && offset < type_len; i++)
712 struct dwarf_expr_piece *p = &c->pieces[i];
713 size_t this_size_bits, this_size;
714 long dest_offset_bits, source_offset_bits, dest_offset, source_offset;
716 const gdb_byte *source_buffer;
718 this_size_bits = p->size;
719 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
721 bits_to_skip -= this_size_bits;
724 if (this_size_bits > type_len - offset)
725 this_size_bits = type_len - offset;
726 if (bits_to_skip > 0)
728 dest_offset_bits = bits_to_skip;
729 source_offset_bits = 0;
730 this_size_bits -= bits_to_skip;
735 dest_offset_bits = 0;
736 source_offset_bits = offset;
739 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
740 source_offset = source_offset_bits / 8;
741 dest_offset = dest_offset_bits / 8;
742 if (dest_offset_bits % 8 == 0 && source_offset_bits % 8 == 0)
744 source_buffer = contents + source_offset;
749 if (buffer_size < this_size)
751 buffer_size = this_size;
752 buffer = xrealloc (buffer, buffer_size);
754 source_buffer = buffer;
760 case DWARF_VALUE_REGISTER:
762 struct gdbarch *arch = get_frame_arch (frame);
763 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.value);
764 int reg_offset = dest_offset;
766 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
767 && this_size <= register_size (arch, gdb_regnum))
768 /* Big-endian, and we want less than full size. */
769 reg_offset = register_size (arch, gdb_regnum) - this_size;
771 if (gdb_regnum != -1)
775 get_frame_register_bytes (frame, gdb_regnum, reg_offset,
777 copy_bitwise (buffer, dest_offset_bits,
778 contents, source_offset_bits,
783 put_frame_register_bytes (frame, gdb_regnum, reg_offset,
784 this_size, source_buffer);
788 error (_("Unable to write to DWARF register number %s"),
789 paddress (arch, p->v.value));
793 case DWARF_VALUE_MEMORY:
796 /* Only the first and last bytes can possibly have any
798 read_memory (p->v.mem.addr + dest_offset, buffer, 1);
799 read_memory (p->v.mem.addr + dest_offset + this_size - 1,
800 buffer + this_size - 1, 1);
801 copy_bitwise (buffer, dest_offset_bits,
802 contents, source_offset_bits,
807 write_memory (p->v.mem.addr + dest_offset,
808 source_buffer, this_size);
811 set_value_optimized_out (to, 1);
814 offset += this_size_bits;
817 do_cleanups (cleanup);
820 /* A helper function that checks bit validity in a pieced value.
821 CHECK_FOR indicates the kind of validity checking.
822 DWARF_VALUE_MEMORY means to check whether any bit is valid.
823 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
825 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
829 check_pieced_value_bits (const struct value *value, int bit_offset,
831 enum dwarf_value_location check_for)
833 struct piece_closure *c
834 = (struct piece_closure *) value_computed_closure (value);
836 int validity = (check_for == DWARF_VALUE_MEMORY
837 || check_for == DWARF_VALUE_IMPLICIT_POINTER);
839 bit_offset += 8 * value_offset (value);
840 if (value_bitsize (value))
841 bit_offset += value_bitpos (value);
843 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
845 struct dwarf_expr_piece *p = &c->pieces[i];
846 size_t this_size_bits = p->size;
850 if (bit_offset >= this_size_bits)
852 bit_offset -= this_size_bits;
856 bit_length -= this_size_bits - bit_offset;
860 bit_length -= this_size_bits;
862 if (check_for == DWARF_VALUE_IMPLICIT_POINTER)
864 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
867 else if (p->location == DWARF_VALUE_OPTIMIZED_OUT
868 || p->location == DWARF_VALUE_IMPLICIT_POINTER)
884 check_pieced_value_validity (const struct value *value, int bit_offset,
887 return check_pieced_value_bits (value, bit_offset, bit_length,
892 check_pieced_value_invalid (const struct value *value)
894 return check_pieced_value_bits (value, 0,
895 8 * TYPE_LENGTH (value_type (value)),
896 DWARF_VALUE_OPTIMIZED_OUT);
899 /* An implementation of an lval_funcs method to see whether a value is
900 a synthetic pointer. */
903 check_pieced_synthetic_pointer (const struct value *value, int bit_offset,
906 return check_pieced_value_bits (value, bit_offset, bit_length,
907 DWARF_VALUE_IMPLICIT_POINTER);
910 /* A wrapper function for get_frame_address_in_block. */
913 get_frame_address_in_block_wrapper (void *baton)
915 return get_frame_address_in_block (baton);
918 /* An implementation of an lval_funcs method to indirect through a
919 pointer. This handles the synthetic pointer case when needed. */
921 static struct value *
922 indirect_pieced_value (struct value *value)
924 struct piece_closure *c
925 = (struct piece_closure *) value_computed_closure (value);
927 struct frame_info *frame;
928 struct dwarf2_locexpr_baton baton;
929 int i, bit_offset, bit_length;
930 struct dwarf_expr_piece *piece = NULL;
931 struct value *result;
934 type = value_type (value);
935 if (TYPE_CODE (type) != TYPE_CODE_PTR)
938 bit_length = 8 * TYPE_LENGTH (type);
939 bit_offset = 8 * value_offset (value);
940 if (value_bitsize (value))
941 bit_offset += value_bitpos (value);
943 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
945 struct dwarf_expr_piece *p = &c->pieces[i];
946 size_t this_size_bits = p->size;
950 if (bit_offset >= this_size_bits)
952 bit_offset -= this_size_bits;
956 bit_length -= this_size_bits - bit_offset;
960 bit_length -= this_size_bits;
962 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
966 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
972 frame = get_selected_frame (_("No frame selected."));
973 byte_offset = value_as_address (value);
975 baton = dwarf2_fetch_die_location_block (piece->v.ptr.die, c->per_cu,
976 get_frame_address_in_block_wrapper,
979 result = dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
980 baton.data, baton.size, baton.per_cu,
987 copy_pieced_value_closure (const struct value *v)
989 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
996 free_pieced_value_closure (struct value *v)
998 struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
1008 /* Functions for accessing a variable described by DW_OP_piece. */
1009 static struct lval_funcs pieced_value_funcs = {
1012 check_pieced_value_validity,
1013 check_pieced_value_invalid,
1014 indirect_pieced_value,
1015 check_pieced_synthetic_pointer,
1016 copy_pieced_value_closure,
1017 free_pieced_value_closure
1020 /* Helper function which throws an error if a synthetic pointer is
1024 invalid_synthetic_pointer (void)
1026 error (_("access outside bounds of object referenced via synthetic pointer"));
1029 /* Evaluate a location description, starting at DATA and with length
1030 SIZE, to find the current location of variable of TYPE in the
1031 context of FRAME. BYTE_OFFSET is applied after the contents are
1034 static struct value *
1035 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1036 const gdb_byte *data, unsigned short size,
1037 struct dwarf2_per_cu_data *per_cu,
1038 LONGEST byte_offset)
1040 struct value *retval;
1041 struct dwarf_expr_baton baton;
1042 struct dwarf_expr_context *ctx;
1043 struct cleanup *old_chain;
1044 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1046 if (byte_offset < 0)
1047 invalid_synthetic_pointer ();
1051 retval = allocate_value (type);
1052 VALUE_LVAL (retval) = not_lval;
1053 set_value_optimized_out (retval, 1);
1057 baton.frame = frame;
1058 baton.per_cu = per_cu;
1060 ctx = new_dwarf_expr_context ();
1061 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1063 ctx->gdbarch = get_objfile_arch (objfile);
1064 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1065 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1066 ctx->baton = &baton;
1067 ctx->read_reg = dwarf_expr_read_reg;
1068 ctx->read_mem = dwarf_expr_read_mem;
1069 ctx->get_frame_base = dwarf_expr_frame_base;
1070 ctx->get_frame_cfa = dwarf_expr_frame_cfa;
1071 ctx->get_frame_pc = dwarf_expr_frame_pc;
1072 ctx->get_tls_address = dwarf_expr_tls_address;
1073 ctx->dwarf_call = dwarf_expr_dwarf_call;
1075 dwarf_expr_eval (ctx, data, size);
1076 if (ctx->num_pieces > 0)
1078 struct piece_closure *c;
1079 struct frame_id frame_id = get_frame_id (frame);
1080 ULONGEST bit_size = 0;
1083 for (i = 0; i < ctx->num_pieces; ++i)
1084 bit_size += ctx->pieces[i].size;
1085 if (8 * (byte_offset + TYPE_LENGTH (type)) > bit_size)
1086 invalid_synthetic_pointer ();
1088 c = allocate_piece_closure (per_cu, ctx->num_pieces, ctx->pieces,
1090 retval = allocate_computed_value (type, &pieced_value_funcs, c);
1091 VALUE_FRAME_ID (retval) = frame_id;
1092 set_value_offset (retval, byte_offset);
1096 switch (ctx->location)
1098 case DWARF_VALUE_REGISTER:
1100 struct gdbarch *arch = get_frame_arch (frame);
1101 ULONGEST dwarf_regnum = dwarf_expr_fetch (ctx, 0);
1102 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
1104 if (byte_offset != 0)
1105 error (_("cannot use offset on synthetic pointer to register"));
1106 if (gdb_regnum != -1)
1107 retval = value_from_register (type, gdb_regnum, frame);
1109 error (_("Unable to access DWARF register number %s"),
1110 paddress (arch, dwarf_regnum));
1114 case DWARF_VALUE_MEMORY:
1116 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
1117 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
1119 retval = allocate_value (type);
1120 VALUE_LVAL (retval) = lval_memory;
1121 set_value_lazy (retval, 1);
1122 if (in_stack_memory)
1123 set_value_stack (retval, 1);
1124 set_value_address (retval, address + byte_offset);
1128 case DWARF_VALUE_STACK:
1130 ULONGEST value = dwarf_expr_fetch (ctx, 0);
1131 bfd_byte *contents, *tem;
1132 size_t n = ctx->addr_size;
1134 if (byte_offset + TYPE_LENGTH (type) > n)
1135 invalid_synthetic_pointer ();
1138 store_unsigned_integer (tem, n,
1139 gdbarch_byte_order (ctx->gdbarch),
1145 retval = allocate_value (type);
1146 contents = value_contents_raw (retval);
1147 if (n > TYPE_LENGTH (type))
1148 n = TYPE_LENGTH (type);
1149 memcpy (contents, tem, n);
1153 case DWARF_VALUE_LITERAL:
1156 const bfd_byte *data;
1157 size_t n = ctx->len;
1159 if (byte_offset + TYPE_LENGTH (type) > n)
1160 invalid_synthetic_pointer ();
1162 retval = allocate_value (type);
1163 contents = value_contents_raw (retval);
1165 data = ctx->data + byte_offset;
1168 if (n > TYPE_LENGTH (type))
1169 n = TYPE_LENGTH (type);
1170 memcpy (contents, data, n);
1174 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1175 operation by execute_stack_op. */
1176 case DWARF_VALUE_IMPLICIT_POINTER:
1177 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1178 it can only be encountered when making a piece. */
1179 case DWARF_VALUE_OPTIMIZED_OUT:
1181 internal_error (__FILE__, __LINE__, _("invalid location type"));
1185 set_value_initialized (retval, ctx->initialized);
1187 do_cleanups (old_chain);
1192 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1193 passes 0 as the byte_offset. */
1196 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
1197 const gdb_byte *data, unsigned short size,
1198 struct dwarf2_per_cu_data *per_cu)
1200 return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, 0);
1204 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1206 struct needs_frame_baton
1209 struct dwarf2_per_cu_data *per_cu;
1212 /* Reads from registers do require a frame. */
1214 needs_frame_read_reg (void *baton, int regnum)
1216 struct needs_frame_baton *nf_baton = baton;
1218 nf_baton->needs_frame = 1;
1222 /* Reads from memory do not require a frame. */
1224 needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
1226 memset (buf, 0, len);
1229 /* Frame-relative accesses do require a frame. */
1231 needs_frame_frame_base (void *baton, const gdb_byte **start, size_t * length)
1233 static gdb_byte lit0 = DW_OP_lit0;
1234 struct needs_frame_baton *nf_baton = baton;
1239 nf_baton->needs_frame = 1;
1242 /* CFA accesses require a frame. */
1245 needs_frame_frame_cfa (void *baton)
1247 struct needs_frame_baton *nf_baton = baton;
1249 nf_baton->needs_frame = 1;
1253 /* Thread-local accesses do require a frame. */
1255 needs_frame_tls_address (void *baton, CORE_ADDR offset)
1257 struct needs_frame_baton *nf_baton = baton;
1259 nf_baton->needs_frame = 1;
1263 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
1266 needs_frame_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1268 struct needs_frame_baton *nf_baton = ctx->baton;
1270 return per_cu_dwarf_call (ctx, die_offset, nf_baton->per_cu,
1271 ctx->get_frame_pc, ctx->baton);
1274 /* Return non-zero iff the location expression at DATA (length SIZE)
1275 requires a frame to evaluate. */
1278 dwarf2_loc_desc_needs_frame (const gdb_byte *data, unsigned short size,
1279 struct dwarf2_per_cu_data *per_cu)
1281 struct needs_frame_baton baton;
1282 struct dwarf_expr_context *ctx;
1284 struct cleanup *old_chain;
1285 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1287 baton.needs_frame = 0;
1288 baton.per_cu = per_cu;
1290 ctx = new_dwarf_expr_context ();
1291 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1293 ctx->gdbarch = get_objfile_arch (objfile);
1294 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1295 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1296 ctx->baton = &baton;
1297 ctx->read_reg = needs_frame_read_reg;
1298 ctx->read_mem = needs_frame_read_mem;
1299 ctx->get_frame_base = needs_frame_frame_base;
1300 ctx->get_frame_cfa = needs_frame_frame_cfa;
1301 ctx->get_frame_pc = needs_frame_frame_cfa;
1302 ctx->get_tls_address = needs_frame_tls_address;
1303 ctx->dwarf_call = needs_frame_dwarf_call;
1305 dwarf_expr_eval (ctx, data, size);
1307 in_reg = ctx->location == DWARF_VALUE_REGISTER;
1309 if (ctx->num_pieces > 0)
1313 /* If the location has several pieces, and any of them are in
1314 registers, then we will need a frame to fetch them from. */
1315 for (i = 0; i < ctx->num_pieces; i++)
1316 if (ctx->pieces[i].location == DWARF_VALUE_REGISTER)
1320 do_cleanups (old_chain);
1322 return baton.needs_frame || in_reg;
1325 /* A helper function that throws an unimplemented error mentioning a
1326 given DWARF operator. */
1329 unimplemented (unsigned int op)
1331 error (_("DWARF operator %s cannot be translated to an agent expression"),
1332 dwarf_stack_op_name (op, 1));
1335 /* A helper function to convert a DWARF register to an arch register.
1336 ARCH is the architecture.
1337 DWARF_REG is the register.
1338 This will throw an exception if the DWARF register cannot be
1339 translated to an architecture register. */
1342 translate_register (struct gdbarch *arch, int dwarf_reg)
1344 int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
1346 error (_("Unable to access DWARF register number %d"), dwarf_reg);
1350 /* A helper function that emits an access to memory. ARCH is the
1351 target architecture. EXPR is the expression which we are building.
1352 NBITS is the number of bits we want to read. This emits the
1353 opcodes needed to read the memory and then extract the desired
1357 access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits)
1359 ULONGEST nbytes = (nbits + 7) / 8;
1361 gdb_assert (nbits > 0 && nbits <= sizeof (LONGEST));
1364 ax_trace_quick (expr, nbytes);
1367 ax_simple (expr, aop_ref8);
1368 else if (nbits <= 16)
1369 ax_simple (expr, aop_ref16);
1370 else if (nbits <= 32)
1371 ax_simple (expr, aop_ref32);
1373 ax_simple (expr, aop_ref64);
1375 /* If we read exactly the number of bytes we wanted, we're done. */
1376 if (8 * nbytes == nbits)
1379 if (gdbarch_bits_big_endian (arch))
1381 /* On a bits-big-endian machine, we want the high-order
1383 ax_const_l (expr, 8 * nbytes - nbits);
1384 ax_simple (expr, aop_rsh_unsigned);
1388 /* On a bits-little-endian box, we want the low-order NBITS. */
1389 ax_zero_ext (expr, nbits);
1393 /* A helper function to return the frame's PC. */
1396 get_ax_pc (void *baton)
1398 struct agent_expr *expr = baton;
1403 /* Compile a DWARF location expression to an agent expression.
1405 EXPR is the agent expression we are building.
1406 LOC is the agent value we modify.
1407 ARCH is the architecture.
1408 ADDR_SIZE is the size of addresses, in bytes.
1409 OP_PTR is the start of the location expression.
1410 OP_END is one past the last byte of the location expression.
1412 This will throw an exception for various kinds of errors -- for
1413 example, if the expression cannot be compiled, or if the expression
1417 compile_dwarf_to_ax (struct agent_expr *expr, struct axs_value *loc,
1418 struct gdbarch *arch, unsigned int addr_size,
1419 const gdb_byte *op_ptr, const gdb_byte *op_end,
1420 struct dwarf2_per_cu_data *per_cu)
1422 struct cleanup *cleanups;
1424 VEC(int) *dw_labels = NULL, *patches = NULL;
1425 const gdb_byte * const base = op_ptr;
1426 const gdb_byte *previous_piece = op_ptr;
1427 enum bfd_endian byte_order = gdbarch_byte_order (arch);
1428 ULONGEST bits_collected = 0;
1429 unsigned int addr_size_bits = 8 * addr_size;
1430 int bits_big_endian = gdbarch_bits_big_endian (arch);
1432 offsets = xmalloc ((op_end - op_ptr) * sizeof (int));
1433 cleanups = make_cleanup (xfree, offsets);
1435 for (i = 0; i < op_end - op_ptr; ++i)
1438 make_cleanup (VEC_cleanup (int), &dw_labels);
1439 make_cleanup (VEC_cleanup (int), &patches);
1441 /* By default we are making an address. */
1442 loc->kind = axs_lvalue_memory;
1444 while (op_ptr < op_end)
1446 enum dwarf_location_atom op = *op_ptr;
1447 ULONGEST uoffset, reg;
1451 offsets[op_ptr - base] = expr->len;
1454 /* Our basic approach to code generation is to map DWARF
1455 operations directly to AX operations. However, there are
1458 First, DWARF works on address-sized units, but AX always uses
1459 LONGEST. For most operations we simply ignore this
1460 difference; instead we generate sign extensions as needed
1461 before division and comparison operations. It would be nice
1462 to omit the sign extensions, but there is no way to determine
1463 the size of the target's LONGEST. (This code uses the size
1464 of the host LONGEST in some cases -- that is a bug but it is
1467 Second, some DWARF operations cannot be translated to AX.
1468 For these we simply fail. See
1469 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
1504 ax_const_l (expr, op - DW_OP_lit0);
1508 uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
1509 op_ptr += addr_size;
1510 /* Some versions of GCC emit DW_OP_addr before
1511 DW_OP_GNU_push_tls_address. In this case the value is an
1512 index, not an address. We don't support things like
1513 branching between the address and the TLS op. */
1514 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
1515 uoffset += dwarf2_per_cu_text_offset (per_cu);
1516 ax_const_l (expr, uoffset);
1520 ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order));
1524 ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order));
1528 ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order));
1532 ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order));
1536 ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order));
1540 ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order));
1544 ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order));
1548 ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order));
1552 op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
1553 ax_const_l (expr, uoffset);
1556 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1557 ax_const_l (expr, offset);
1592 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
1593 loc->u.reg = translate_register (arch, op - DW_OP_reg0);
1594 loc->kind = axs_lvalue_register;
1598 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1599 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
1600 loc->u.reg = translate_register (arch, reg);
1601 loc->kind = axs_lvalue_register;
1604 case DW_OP_implicit_value:
1608 op_ptr = read_uleb128 (op_ptr, op_end, &len);
1609 if (op_ptr + len > op_end)
1610 error (_("DW_OP_implicit_value: too few bytes available."));
1611 if (len > sizeof (ULONGEST))
1612 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
1615 ax_const_l (expr, extract_unsigned_integer (op_ptr, len,
1618 dwarf_expr_require_composition (op_ptr, op_end,
1619 "DW_OP_implicit_value");
1621 loc->kind = axs_rvalue;
1625 case DW_OP_stack_value:
1626 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
1627 loc->kind = axs_rvalue;
1662 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1663 i = translate_register (arch, op - DW_OP_breg0);
1667 ax_const_l (expr, offset);
1668 ax_simple (expr, aop_add);
1673 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1674 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1675 i = translate_register (arch, reg);
1679 ax_const_l (expr, offset);
1680 ax_simple (expr, aop_add);
1686 const gdb_byte *datastart;
1688 unsigned int before_stack_len;
1690 struct symbol *framefunc;
1691 LONGEST base_offset = 0;
1693 b = block_for_pc (expr->scope);
1696 error (_("No block found for address"));
1698 framefunc = block_linkage_function (b);
1701 error (_("No function found for block"));
1703 dwarf_expr_frame_base_1 (framefunc, expr->scope,
1704 &datastart, &datalen);
1706 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
1707 compile_dwarf_to_ax (expr, loc, arch, addr_size, datastart,
1708 datastart + datalen, per_cu);
1712 ax_const_l (expr, offset);
1713 ax_simple (expr, aop_add);
1716 loc->kind = axs_lvalue_memory;
1721 ax_simple (expr, aop_dup);
1725 ax_simple (expr, aop_pop);
1734 ax_simple (expr, aop_swap);
1738 /* We can't directly support DW_OP_over, but GCC emits it as
1739 part of a sequence to implement signed modulus. As a
1740 hack, we recognize this sequence. Note that if GCC ever
1741 generates a branch to the middle of this sequence, then
1742 we will die somehow. */
1743 if (op_end - op_ptr >= 4
1744 && op_ptr[0] == DW_OP_over
1745 && op_ptr[1] == DW_OP_div
1746 && op_ptr[2] == DW_OP_mul
1747 && op_ptr[3] == DW_OP_minus)
1749 /* Sign extend the operands. */
1750 ax_ext (expr, addr_size_bits);
1751 ax_simple (expr, aop_swap);
1752 ax_ext (expr, addr_size_bits);
1753 ax_simple (expr, aop_swap);
1754 ax_simple (expr, aop_rem_signed);
1766 case DW_OP_deref_size:
1770 if (op == DW_OP_deref_size)
1778 ax_simple (expr, aop_ref8);
1781 ax_simple (expr, aop_ref16);
1784 ax_simple (expr, aop_ref32);
1787 ax_simple (expr, aop_ref64);
1790 error (_("Unsupported size %d in %s"),
1791 size, dwarf_stack_op_name (op, 1));
1797 /* Sign extend the operand. */
1798 ax_ext (expr, addr_size_bits);
1799 ax_simple (expr, aop_dup);
1800 ax_const_l (expr, 0);
1801 ax_simple (expr, aop_less_signed);
1802 ax_simple (expr, aop_log_not);
1803 i = ax_goto (expr, aop_if_goto);
1804 /* We have to emit 0 - X. */
1805 ax_const_l (expr, 0);
1806 ax_simple (expr, aop_swap);
1807 ax_simple (expr, aop_sub);
1808 ax_label (expr, i, expr->len);
1812 /* No need to sign extend here. */
1813 ax_const_l (expr, 0);
1814 ax_simple (expr, aop_swap);
1815 ax_simple (expr, aop_sub);
1819 /* Sign extend the operand. */
1820 ax_ext (expr, addr_size_bits);
1821 ax_simple (expr, aop_bit_not);
1824 case DW_OP_plus_uconst:
1825 op_ptr = read_uleb128 (op_ptr, op_end, ®);
1826 /* It would be really weird to emit `DW_OP_plus_uconst 0',
1827 but we micro-optimize anyhow. */
1830 ax_const_l (expr, reg);
1831 ax_simple (expr, aop_add);
1836 ax_simple (expr, aop_bit_and);
1840 /* Sign extend the operands. */
1841 ax_ext (expr, addr_size_bits);
1842 ax_simple (expr, aop_swap);
1843 ax_ext (expr, addr_size_bits);
1844 ax_simple (expr, aop_swap);
1845 ax_simple (expr, aop_div_signed);
1849 ax_simple (expr, aop_sub);
1853 ax_simple (expr, aop_rem_unsigned);
1857 ax_simple (expr, aop_mul);
1861 ax_simple (expr, aop_bit_or);
1865 ax_simple (expr, aop_add);
1869 ax_simple (expr, aop_lsh);
1873 ax_simple (expr, aop_rsh_unsigned);
1877 ax_simple (expr, aop_rsh_signed);
1881 ax_simple (expr, aop_bit_xor);
1885 /* Sign extend the operands. */
1886 ax_ext (expr, addr_size_bits);
1887 ax_simple (expr, aop_swap);
1888 ax_ext (expr, addr_size_bits);
1889 /* Note no swap here: A <= B is !(B < A). */
1890 ax_simple (expr, aop_less_signed);
1891 ax_simple (expr, aop_log_not);
1895 /* Sign extend the operands. */
1896 ax_ext (expr, addr_size_bits);
1897 ax_simple (expr, aop_swap);
1898 ax_ext (expr, addr_size_bits);
1899 ax_simple (expr, aop_swap);
1900 /* A >= B is !(A < B). */
1901 ax_simple (expr, aop_less_signed);
1902 ax_simple (expr, aop_log_not);
1906 /* Sign extend the operands. */
1907 ax_ext (expr, addr_size_bits);
1908 ax_simple (expr, aop_swap);
1909 ax_ext (expr, addr_size_bits);
1910 /* No need for a second swap here. */
1911 ax_simple (expr, aop_equal);
1915 /* Sign extend the operands. */
1916 ax_ext (expr, addr_size_bits);
1917 ax_simple (expr, aop_swap);
1918 ax_ext (expr, addr_size_bits);
1919 ax_simple (expr, aop_swap);
1920 ax_simple (expr, aop_less_signed);
1924 /* Sign extend the operands. */
1925 ax_ext (expr, addr_size_bits);
1926 ax_simple (expr, aop_swap);
1927 ax_ext (expr, addr_size_bits);
1928 /* Note no swap here: A > B is B < A. */
1929 ax_simple (expr, aop_less_signed);
1933 /* Sign extend the operands. */
1934 ax_ext (expr, addr_size_bits);
1935 ax_simple (expr, aop_swap);
1936 ax_ext (expr, addr_size_bits);
1937 /* No need for a swap here. */
1938 ax_simple (expr, aop_equal);
1939 ax_simple (expr, aop_log_not);
1942 case DW_OP_call_frame_cfa:
1946 case DW_OP_GNU_push_tls_address:
1951 offset = extract_signed_integer (op_ptr, 2, byte_order);
1953 i = ax_goto (expr, aop_goto);
1954 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
1955 VEC_safe_push (int, patches, i);
1959 offset = extract_signed_integer (op_ptr, 2, byte_order);
1961 /* Zero extend the operand. */
1962 ax_zero_ext (expr, addr_size_bits);
1963 i = ax_goto (expr, aop_if_goto);
1964 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
1965 VEC_safe_push (int, patches, i);
1972 case DW_OP_bit_piece:
1974 ULONGEST size, offset;
1976 if (op_ptr - 1 == previous_piece)
1977 error (_("Cannot translate empty pieces to agent expressions"));
1978 previous_piece = op_ptr - 1;
1980 op_ptr = read_uleb128 (op_ptr, op_end, &size);
1981 if (op == DW_OP_piece)
1987 op_ptr = read_uleb128 (op_ptr, op_end, &offset);
1989 if (bits_collected + size > 8 * sizeof (LONGEST))
1990 error (_("Expression pieces exceed word size"));
1992 /* Access the bits. */
1995 case axs_lvalue_register:
1996 ax_reg (expr, loc->u.reg);
1999 case axs_lvalue_memory:
2000 /* Offset the pointer, if needed. */
2003 ax_const_l (expr, offset / 8);
2004 ax_simple (expr, aop_add);
2007 access_memory (arch, expr, size);
2011 /* For a bits-big-endian target, shift up what we already
2012 have. For a bits-little-endian target, shift up the
2013 new data. Note that there is a potential bug here if
2014 the DWARF expression leaves multiple values on the
2016 if (bits_collected > 0)
2018 if (bits_big_endian)
2020 ax_simple (expr, aop_swap);
2021 ax_const_l (expr, size);
2022 ax_simple (expr, aop_lsh);
2023 /* We don't need a second swap here, because
2024 aop_bit_or is symmetric. */
2028 ax_const_l (expr, size);
2029 ax_simple (expr, aop_lsh);
2031 ax_simple (expr, aop_bit_or);
2034 bits_collected += size;
2035 loc->kind = axs_rvalue;
2039 case DW_OP_GNU_uninit:
2045 struct dwarf2_locexpr_baton block;
2046 int size = (op == DW_OP_call2 ? 2 : 4);
2048 uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
2051 block = dwarf2_fetch_die_location_block (uoffset, per_cu,
2054 /* DW_OP_call_ref is currently not supported. */
2055 gdb_assert (block.per_cu == per_cu);
2057 compile_dwarf_to_ax (expr, loc, arch, addr_size,
2058 block.data, block.data + block.size,
2063 case DW_OP_call_ref:
2067 error (_("Unhandled dwarf expression opcode 0x%x"), op);
2071 /* Patch all the branches we emitted. */
2072 for (i = 0; i < VEC_length (int, patches); ++i)
2074 int targ = offsets[VEC_index (int, dw_labels, i)];
2076 internal_error (__FILE__, __LINE__, _("invalid label"));
2077 ax_label (expr, VEC_index (int, patches, i), targ);
2080 do_cleanups (cleanups);
2084 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2085 evaluator to calculate the location. */
2086 static struct value *
2087 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
2089 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2092 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
2093 dlbaton->size, dlbaton->per_cu);
2098 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2100 locexpr_read_needs_frame (struct symbol *symbol)
2102 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2104 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
2108 /* Return true if DATA points to the end of a piece. END is one past
2109 the last byte in the expression. */
2112 piece_end_p (const gdb_byte *data, const gdb_byte *end)
2114 return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece;
2117 /* Nicely describe a single piece of a location, returning an updated
2118 position in the bytecode sequence. This function cannot recognize
2119 all locations; if a location is not recognized, it simply returns
2122 static const gdb_byte *
2123 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
2124 CORE_ADDR addr, struct objfile *objfile,
2125 const gdb_byte *data, const gdb_byte *end,
2126 unsigned int addr_size)
2128 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2131 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
2133 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_reg0);
2134 fprintf_filtered (stream, _("a variable in $%s"),
2135 gdbarch_register_name (gdbarch, regno));
2138 else if (data[0] == DW_OP_regx)
2142 data = read_uleb128 (data + 1, end, ®);
2143 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
2144 fprintf_filtered (stream, _("a variable in $%s"),
2145 gdbarch_register_name (gdbarch, regno));
2147 else if (data[0] == DW_OP_fbreg)
2150 struct symbol *framefunc;
2152 LONGEST frame_offset;
2153 const gdb_byte *base_data, *new_data, *save_data = data;
2155 LONGEST base_offset = 0;
2157 new_data = read_sleb128 (data + 1, end, &frame_offset);
2158 if (!piece_end_p (new_data, end))
2162 b = block_for_pc (addr);
2165 error (_("No block found for address for symbol \"%s\"."),
2166 SYMBOL_PRINT_NAME (symbol));
2168 framefunc = block_linkage_function (b);
2171 error (_("No function found for block for symbol \"%s\"."),
2172 SYMBOL_PRINT_NAME (symbol));
2174 dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
2176 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
2178 const gdb_byte *buf_end;
2180 frame_reg = base_data[0] - DW_OP_breg0;
2181 buf_end = read_sleb128 (base_data + 1,
2182 base_data + base_size, &base_offset);
2183 if (buf_end != base_data + base_size)
2184 error (_("Unexpected opcode after DW_OP_breg%u for symbol \"%s\"."),
2185 frame_reg, SYMBOL_PRINT_NAME (symbol));
2187 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
2189 /* The frame base is just the register, with no offset. */
2190 frame_reg = base_data[0] - DW_OP_reg0;
2195 /* We don't know what to do with the frame base expression,
2196 so we can't trace this variable; give up. */
2200 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, frame_reg);
2202 fprintf_filtered (stream, _("a variable at frame base reg $%s offset %s+%s"),
2203 gdbarch_register_name (gdbarch, regno),
2204 plongest (base_offset), plongest (frame_offset));
2206 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31
2207 && piece_end_p (data, end))
2211 regno = gdbarch_dwarf2_reg_to_regnum (gdbarch, data[0] - DW_OP_breg0);
2213 data = read_sleb128 (data + 1, end, &offset);
2215 fprintf_filtered (stream,
2216 _("a variable at offset %s from base reg $%s"),
2218 gdbarch_register_name (gdbarch, regno));
2221 /* The location expression for a TLS variable looks like this (on a
2224 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2225 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2227 0x3 is the encoding for DW_OP_addr, which has an operand as long
2228 as the size of an address on the target machine (here is 8
2229 bytes). Note that more recent version of GCC emit DW_OP_const4u
2230 or DW_OP_const8u, depending on address size, rather than
2231 DW_OP_addr. 0xe0 is the encoding for
2232 DW_OP_GNU_push_tls_address. The operand represents the offset at
2233 which the variable is within the thread local storage. */
2235 else if (data + 1 + addr_size < end
2236 && (data[0] == DW_OP_addr
2237 || (addr_size == 4 && data[0] == DW_OP_const4u)
2238 || (addr_size == 8 && data[0] == DW_OP_const8u))
2239 && data[1 + addr_size] == DW_OP_GNU_push_tls_address
2240 && piece_end_p (data + 2 + addr_size, end))
2243 offset = extract_unsigned_integer (data + 1, addr_size,
2244 gdbarch_byte_order (gdbarch));
2246 fprintf_filtered (stream,
2247 _("a thread-local variable at offset 0x%s "
2248 "in the thread-local storage for `%s'"),
2249 phex_nz (offset, addr_size), objfile->name);
2251 data += 1 + addr_size + 1;
2253 else if (data[0] >= DW_OP_lit0
2254 && data[0] <= DW_OP_lit31
2256 && data[1] == DW_OP_stack_value)
2258 fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0);
2265 /* Disassemble an expression, stopping at the end of a piece or at the
2266 end of the expression. Returns a pointer to the next unread byte
2267 in the input expression. If ALL is nonzero, then this function
2268 will keep going until it reaches the end of the expression. */
2270 static const gdb_byte *
2271 disassemble_dwarf_expression (struct ui_file *stream,
2272 struct gdbarch *arch, unsigned int addr_size,
2274 const gdb_byte *data, const gdb_byte *end,
2277 const gdb_byte *start = data;
2279 fprintf_filtered (stream, _("a complex DWARF expression:\n"));
2283 || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
2285 enum dwarf_location_atom op = *data++;
2290 name = dwarf_stack_op_name (op, 0);
2293 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
2294 op, (long) (data - start));
2295 fprintf_filtered (stream, " % 4ld: %s", (long) (data - start), name);
2300 ul = extract_unsigned_integer (data, addr_size,
2301 gdbarch_byte_order (arch));
2303 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
2307 ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch));
2309 fprintf_filtered (stream, " %s", pulongest (ul));
2312 l = extract_signed_integer (data, 1, gdbarch_byte_order (arch));
2314 fprintf_filtered (stream, " %s", plongest (l));
2317 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
2319 fprintf_filtered (stream, " %s", pulongest (ul));
2322 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2324 fprintf_filtered (stream, " %s", plongest (l));
2327 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
2329 fprintf_filtered (stream, " %s", pulongest (ul));
2332 l = extract_signed_integer (data, 4, gdbarch_byte_order (arch));
2334 fprintf_filtered (stream, " %s", plongest (l));
2337 ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch));
2339 fprintf_filtered (stream, " %s", pulongest (ul));
2342 l = extract_signed_integer (data, 8, gdbarch_byte_order (arch));
2344 fprintf_filtered (stream, " %s", plongest (l));
2347 data = read_uleb128 (data, end, &ul);
2348 fprintf_filtered (stream, " %s", pulongest (ul));
2351 data = read_sleb128 (data, end, &l);
2352 fprintf_filtered (stream, " %s", plongest (l));
2387 fprintf_filtered (stream, " [$%s]",
2388 gdbarch_register_name (arch, op - DW_OP_reg0));
2392 data = read_uleb128 (data, end, &ul);
2393 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
2394 gdbarch_register_name (arch, (int) ul));
2397 case DW_OP_implicit_value:
2398 data = read_uleb128 (data, end, &ul);
2400 fprintf_filtered (stream, " %s", pulongest (ul));
2435 data = read_sleb128 (data, end, &ul);
2436 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
2437 gdbarch_register_name (arch, op - DW_OP_breg0));
2444 data = read_uleb128 (data, end, &ul);
2445 data = read_sleb128 (data, end, &offset);
2446 fprintf_filtered (stream, " register %s [$%s] offset %s",
2448 gdbarch_register_name (arch, (int) ul),
2449 pulongest (offset));
2454 data = read_sleb128 (data, end, &ul);
2455 fprintf_filtered (stream, " %s", pulongest (ul));
2458 case DW_OP_xderef_size:
2459 case DW_OP_deref_size:
2461 fprintf_filtered (stream, " %d", *data);
2465 case DW_OP_plus_uconst:
2466 data = read_uleb128 (data, end, &ul);
2467 fprintf_filtered (stream, " %s", pulongest (ul));
2471 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2473 fprintf_filtered (stream, " to %ld",
2474 (long) (data + l - start));
2478 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
2480 fprintf_filtered (stream, " %ld",
2481 (long) (data + l - start));
2485 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
2487 fprintf_filtered (stream, " offset %s", phex_nz (ul, 2));
2491 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
2493 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
2496 case DW_OP_call_ref:
2497 ul = extract_unsigned_integer (data, offset_size,
2498 gdbarch_byte_order (arch));
2499 data += offset_size;
2500 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
2504 data = read_uleb128 (data, end, &ul);
2505 fprintf_filtered (stream, " %s (bytes)", pulongest (ul));
2508 case DW_OP_bit_piece:
2512 data = read_uleb128 (data, end, &ul);
2513 data = read_uleb128 (data, end, &offset);
2514 fprintf_filtered (stream, " size %s offset %s (bits)",
2515 pulongest (ul), pulongest (offset));
2519 case DW_OP_GNU_implicit_pointer:
2521 ul = extract_unsigned_integer (data, offset_size,
2522 gdbarch_byte_order (arch));
2523 data += offset_size;
2525 data = read_sleb128 (data, end, &l);
2527 fprintf_filtered (stream, " DIE %s offset %s",
2528 phex_nz (ul, offset_size),
2534 fprintf_filtered (stream, "\n");
2540 /* Describe a single location, which may in turn consist of multiple
2544 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
2545 struct ui_file *stream,
2546 const gdb_byte *data, int size,
2547 struct objfile *objfile, unsigned int addr_size,
2550 const gdb_byte *end = data + size;
2551 int first_piece = 1, bad = 0;
2555 const gdb_byte *here = data;
2556 int disassemble = 1;
2561 fprintf_filtered (stream, _(", and "));
2563 if (!dwarf2_always_disassemble)
2565 data = locexpr_describe_location_piece (symbol, stream, addr, objfile,
2566 data, end, addr_size);
2567 /* If we printed anything, or if we have an empty piece,
2568 then don't disassemble. */
2570 || data[0] == DW_OP_piece
2571 || data[0] == DW_OP_bit_piece)
2575 data = disassemble_dwarf_expression (stream, get_objfile_arch (objfile),
2576 addr_size, offset_size, data, end,
2577 dwarf2_always_disassemble);
2581 int empty = data == here;
2584 fprintf_filtered (stream, " ");
2585 if (data[0] == DW_OP_piece)
2589 data = read_uleb128 (data + 1, end, &bytes);
2592 fprintf_filtered (stream, _("an empty %s-byte piece"),
2595 fprintf_filtered (stream, _(" [%s-byte piece]"),
2598 else if (data[0] == DW_OP_bit_piece)
2600 ULONGEST bits, offset;
2602 data = read_uleb128 (data + 1, end, &bits);
2603 data = read_uleb128 (data, end, &offset);
2606 fprintf_filtered (stream,
2607 _("an empty %s-bit piece"),
2610 fprintf_filtered (stream,
2611 _(" [%s-bit piece, offset %s bits]"),
2612 pulongest (bits), pulongest (offset));
2622 if (bad || data > end)
2623 error (_("Corrupted DWARF2 expression for \"%s\"."),
2624 SYMBOL_PRINT_NAME (symbol));
2627 /* Print a natural-language description of SYMBOL to STREAM. This
2628 version is for a symbol with a single location. */
2631 locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
2632 struct ui_file *stream)
2634 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2635 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
2636 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2637 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
2639 locexpr_describe_location_1 (symbol, addr, stream, dlbaton->data, dlbaton->size,
2640 objfile, addr_size, offset_size);
2643 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2644 any necessary bytecode in AX. */
2647 locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2648 struct agent_expr *ax, struct axs_value *value)
2650 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2651 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2653 if (dlbaton->data == NULL || dlbaton->size == 0)
2654 value->optimized_out = 1;
2656 compile_dwarf_to_ax (ax, value, gdbarch, addr_size,
2657 dlbaton->data, dlbaton->data + dlbaton->size,
2661 /* The set of location functions used with the DWARF-2 expression
2663 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
2664 locexpr_read_variable,
2665 locexpr_read_needs_frame,
2666 locexpr_describe_location,
2667 locexpr_tracepoint_var_ref
2671 /* Wrapper functions for location lists. These generally find
2672 the appropriate location expression and call something above. */
2674 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2675 evaluator to calculate the location. */
2676 static struct value *
2677 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
2679 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2681 const gdb_byte *data;
2683 CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0;
2685 data = dwarf2_find_location_expression (dlbaton, &size, pc);
2688 val = allocate_value (SYMBOL_TYPE (symbol));
2689 VALUE_LVAL (val) = not_lval;
2690 set_value_optimized_out (val, 1);
2693 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
2699 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2701 loclist_read_needs_frame (struct symbol *symbol)
2703 /* If there's a location list, then assume we need to have a frame
2704 to choose the appropriate location expression. With tracking of
2705 global variables this is not necessarily true, but such tracking
2706 is disabled in GCC at the moment until we figure out how to
2712 /* Print a natural-language description of SYMBOL to STREAM. This
2713 version applies when there is a list of different locations, each
2714 with a specified address range. */
2717 loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
2718 struct ui_file *stream)
2720 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2721 CORE_ADDR low, high;
2722 const gdb_byte *loc_ptr, *buf_end;
2723 int length, first = 1;
2724 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
2725 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2726 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2727 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2728 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
2729 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
2730 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
2731 /* Adjust base_address for relocatable objects. */
2732 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
2733 CORE_ADDR base_address = dlbaton->base_address + base_offset;
2735 loc_ptr = dlbaton->data;
2736 buf_end = dlbaton->data + dlbaton->size;
2738 fprintf_filtered (stream, _("multi-location:\n"));
2740 /* Iterate through locations until we run out. */
2743 if (buf_end - loc_ptr < 2 * addr_size)
2744 error (_("Corrupted DWARF expression for symbol \"%s\"."),
2745 SYMBOL_PRINT_NAME (symbol));
2748 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
2750 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
2751 loc_ptr += addr_size;
2754 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
2756 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
2757 loc_ptr += addr_size;
2759 /* A base-address-selection entry. */
2760 if ((low & base_mask) == base_mask)
2762 base_address = high + base_offset;
2763 fprintf_filtered (stream, _(" Base address %s"),
2764 paddress (gdbarch, base_address));
2768 /* An end-of-list entry. */
2769 if (low == 0 && high == 0)
2772 /* Otherwise, a location expression entry. */
2773 low += base_address;
2774 high += base_address;
2776 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
2779 /* (It would improve readability to print only the minimum
2780 necessary digits of the second number of the range.) */
2781 fprintf_filtered (stream, _(" Range %s-%s: "),
2782 paddress (gdbarch, low), paddress (gdbarch, high));
2784 /* Now describe this particular location. */
2785 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
2786 objfile, addr_size, offset_size);
2788 fprintf_filtered (stream, "\n");
2794 /* Describe the location of SYMBOL as an agent value in VALUE, generating
2795 any necessary bytecode in AX. */
2797 loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2798 struct agent_expr *ax, struct axs_value *value)
2800 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2801 const gdb_byte *data;
2803 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
2805 data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
2806 if (data == NULL || size == 0)
2807 value->optimized_out = 1;
2809 compile_dwarf_to_ax (ax, value, gdbarch, addr_size, data, data + size,
2813 /* The set of location functions used with the DWARF-2 expression
2814 evaluator and location lists. */
2815 const struct symbol_computed_ops dwarf2_loclist_funcs = {
2816 loclist_read_variable,
2817 loclist_read_needs_frame,
2818 loclist_describe_location,
2819 loclist_tracepoint_var_ref