1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2014 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "exceptions.h"
38 #include "dwarf2expr.h"
39 #include "dwarf2loc.h"
40 #include "dwarf2-frame.h"
43 #include "gdb_assert.h"
45 extern int dwarf2_always_disassemble;
47 static void dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
48 const gdb_byte **start, size_t *length);
50 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs;
52 static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
53 struct frame_info *frame,
56 struct dwarf2_per_cu_data *per_cu,
59 /* Until these have formal names, we define these here.
60 ref: http://gcc.gnu.org/wiki/DebugFission
61 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
62 and is then followed by data specific to that entry. */
66 /* Indicates the end of the list of entries. */
67 DEBUG_LOC_END_OF_LIST = 0,
69 /* This is followed by an unsigned LEB128 number that is an index into
70 .debug_addr and specifies the base address for all following entries. */
71 DEBUG_LOC_BASE_ADDRESS = 1,
73 /* This is followed by two unsigned LEB128 numbers that are indices into
74 .debug_addr and specify the beginning and ending addresses, and then
75 a normal location expression as in .debug_loc. */
76 DEBUG_LOC_START_END = 2,
78 /* This is followed by an unsigned LEB128 number that is an index into
79 .debug_addr and specifies the beginning address, and a 4 byte unsigned
80 number that specifies the length, and then a normal location expression
82 DEBUG_LOC_START_LENGTH = 3,
84 /* An internal value indicating there is insufficient data. */
85 DEBUG_LOC_BUFFER_OVERFLOW = -1,
87 /* An internal value indicating an invalid kind of entry was found. */
88 DEBUG_LOC_INVALID_ENTRY = -2
91 /* Helper function which throws an error if a synthetic pointer is
95 invalid_synthetic_pointer (void)
97 error (_("access outside bounds of object "
98 "referenced via synthetic pointer"));
101 /* Decode the addresses in a non-dwo .debug_loc entry.
102 A pointer to the next byte to examine is returned in *NEW_PTR.
103 The encoded low,high addresses are return in *LOW,*HIGH.
104 The result indicates the kind of entry found. */
106 static enum debug_loc_kind
107 decode_debug_loc_addresses (const gdb_byte *loc_ptr, const gdb_byte *buf_end,
108 const gdb_byte **new_ptr,
109 CORE_ADDR *low, CORE_ADDR *high,
110 enum bfd_endian byte_order,
111 unsigned int addr_size,
114 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
116 if (buf_end - loc_ptr < 2 * addr_size)
117 return DEBUG_LOC_BUFFER_OVERFLOW;
120 *low = extract_signed_integer (loc_ptr, addr_size, byte_order);
122 *low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
123 loc_ptr += addr_size;
126 *high = extract_signed_integer (loc_ptr, addr_size, byte_order);
128 *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
129 loc_ptr += addr_size;
133 /* A base-address-selection entry. */
134 if ((*low & base_mask) == base_mask)
135 return DEBUG_LOC_BASE_ADDRESS;
137 /* An end-of-list entry. */
138 if (*low == 0 && *high == 0)
139 return DEBUG_LOC_END_OF_LIST;
141 return DEBUG_LOC_START_END;
144 /* Decode the addresses in .debug_loc.dwo entry.
145 A pointer to the next byte to examine is returned in *NEW_PTR.
146 The encoded low,high addresses are return in *LOW,*HIGH.
147 The result indicates the kind of entry found. */
149 static enum debug_loc_kind
150 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
151 const gdb_byte *loc_ptr,
152 const gdb_byte *buf_end,
153 const gdb_byte **new_ptr,
154 CORE_ADDR *low, CORE_ADDR *high,
155 enum bfd_endian byte_order)
157 uint64_t low_index, high_index;
159 if (loc_ptr == buf_end)
160 return DEBUG_LOC_BUFFER_OVERFLOW;
164 case DEBUG_LOC_END_OF_LIST:
166 return DEBUG_LOC_END_OF_LIST;
167 case DEBUG_LOC_BASE_ADDRESS:
169 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
171 return DEBUG_LOC_BUFFER_OVERFLOW;
172 *high = dwarf2_read_addr_index (per_cu, high_index);
174 return DEBUG_LOC_BASE_ADDRESS;
175 case DEBUG_LOC_START_END:
176 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
178 return DEBUG_LOC_BUFFER_OVERFLOW;
179 *low = dwarf2_read_addr_index (per_cu, low_index);
180 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
182 return DEBUG_LOC_BUFFER_OVERFLOW;
183 *high = dwarf2_read_addr_index (per_cu, high_index);
185 return DEBUG_LOC_START_END;
186 case DEBUG_LOC_START_LENGTH:
187 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
189 return DEBUG_LOC_BUFFER_OVERFLOW;
190 *low = dwarf2_read_addr_index (per_cu, low_index);
191 if (loc_ptr + 4 > buf_end)
192 return DEBUG_LOC_BUFFER_OVERFLOW;
194 *high += extract_unsigned_integer (loc_ptr, 4, byte_order);
195 *new_ptr = loc_ptr + 4;
196 return DEBUG_LOC_START_LENGTH;
198 return DEBUG_LOC_INVALID_ENTRY;
202 /* A function for dealing with location lists. Given a
203 symbol baton (BATON) and a pc value (PC), find the appropriate
204 location expression, set *LOCEXPR_LENGTH, and return a pointer
205 to the beginning of the expression. Returns NULL on failure.
207 For now, only return the first matching location expression; there
208 can be more than one in the list. */
211 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
212 size_t *locexpr_length, CORE_ADDR pc)
214 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
215 struct gdbarch *gdbarch = get_objfile_arch (objfile);
216 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
217 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
218 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
219 /* Adjust base_address for relocatable objects. */
220 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
221 CORE_ADDR base_address = baton->base_address + base_offset;
222 const gdb_byte *loc_ptr, *buf_end;
224 loc_ptr = baton->data;
225 buf_end = baton->data + baton->size;
229 CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */
231 enum debug_loc_kind kind;
232 const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
235 kind = decode_debug_loc_dwo_addresses (baton->per_cu,
236 loc_ptr, buf_end, &new_ptr,
237 &low, &high, byte_order);
239 kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
241 byte_order, addr_size,
246 case DEBUG_LOC_END_OF_LIST:
249 case DEBUG_LOC_BASE_ADDRESS:
250 base_address = high + base_offset;
252 case DEBUG_LOC_START_END:
253 case DEBUG_LOC_START_LENGTH:
255 case DEBUG_LOC_BUFFER_OVERFLOW:
256 case DEBUG_LOC_INVALID_ENTRY:
257 error (_("dwarf2_find_location_expression: "
258 "Corrupted DWARF expression."));
260 gdb_assert_not_reached ("bad debug_loc_kind");
263 /* Otherwise, a location expression entry.
264 If the entry is from a DWO, don't add base address: the entry is
265 from .debug_addr which has absolute addresses. */
266 if (! baton->from_dwo)
269 high += base_address;
272 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
275 if (low == high && pc == low)
277 /* This is entry PC record present only at entry point
278 of a function. Verify it is really the function entry point. */
280 struct block *pc_block = block_for_pc (pc);
281 struct symbol *pc_func = NULL;
284 pc_func = block_linkage_function (pc_block);
286 if (pc_func && pc == BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func)))
288 *locexpr_length = length;
293 if (pc >= low && pc < high)
295 *locexpr_length = length;
303 /* This is the baton used when performing dwarf2 expression
305 struct dwarf_expr_baton
307 struct frame_info *frame;
308 struct dwarf2_per_cu_data *per_cu;
311 /* Helper functions for dwarf2_evaluate_loc_desc. */
313 /* Using the frame specified in BATON, return the value of register
314 REGNUM, treated as a pointer. */
316 dwarf_expr_read_addr_from_reg (void *baton, int dwarf_regnum)
318 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
319 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
323 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
324 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
325 regnum, debaton->frame);
329 /* Implement struct dwarf_expr_context_funcs' "get_reg_value" callback. */
331 static struct value *
332 dwarf_expr_get_reg_value (void *baton, struct type *type, int dwarf_regnum)
334 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
335 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
336 int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
338 return value_from_register (type, regnum, debaton->frame);
341 /* Read memory at ADDR (length LEN) into BUF. */
344 dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
346 read_memory (addr, buf, len);
349 /* Using the frame specified in BATON, find the location expression
350 describing the frame base. Return a pointer to it in START and
351 its length in LENGTH. */
353 dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
355 /* FIXME: cagney/2003-03-26: This code should be using
356 get_frame_base_address(), and then implement a dwarf2 specific
358 struct symbol *framefunc;
359 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
360 struct block *bl = get_frame_block (debaton->frame, NULL);
363 error (_("frame address is not available."));
365 /* Use block_linkage_function, which returns a real (not inlined)
366 function, instead of get_frame_function, which may return an
368 framefunc = block_linkage_function (bl);
370 /* If we found a frame-relative symbol then it was certainly within
371 some function associated with a frame. If we can't find the frame,
372 something has gone wrong. */
373 gdb_assert (framefunc != NULL);
375 dwarf_expr_frame_base_1 (framefunc,
376 get_frame_address_in_block (debaton->frame),
380 /* Implement find_frame_base_location method for LOC_BLOCK functions using
381 DWARF expression for its DW_AT_frame_base. */
384 locexpr_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
385 const gdb_byte **start, size_t *length)
387 struct dwarf2_locexpr_baton *symbaton = SYMBOL_LOCATION_BATON (framefunc);
389 *length = symbaton->size;
390 *start = symbaton->data;
393 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
394 function uses DWARF expression for its DW_AT_frame_base. */
396 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs =
398 locexpr_find_frame_base_location
401 /* Implement find_frame_base_location method for LOC_BLOCK functions using
402 DWARF location list for its DW_AT_frame_base. */
405 loclist_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
406 const gdb_byte **start, size_t *length)
408 struct dwarf2_loclist_baton *symbaton = SYMBOL_LOCATION_BATON (framefunc);
410 *start = dwarf2_find_location_expression (symbaton, length, pc);
413 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
414 function uses DWARF location list for its DW_AT_frame_base. */
416 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs =
418 loclist_find_frame_base_location
422 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
423 const gdb_byte **start, size_t *length)
425 if (SYMBOL_BLOCK_OPS (framefunc) != NULL)
427 const struct symbol_block_ops *ops_block = SYMBOL_BLOCK_OPS (framefunc);
429 ops_block->find_frame_base_location (framefunc, pc, start, length);
435 error (_("Could not find the frame base for \"%s\"."),
436 SYMBOL_NATURAL_NAME (framefunc));
439 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
440 the frame in BATON. */
443 dwarf_expr_frame_cfa (void *baton)
445 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
447 return dwarf2_frame_cfa (debaton->frame);
450 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
451 the frame in BATON. */
454 dwarf_expr_frame_pc (void *baton)
456 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
458 return get_frame_address_in_block (debaton->frame);
461 /* Using the objfile specified in BATON, find the address for the
462 current thread's thread-local storage with offset OFFSET. */
464 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
466 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
467 struct objfile *objfile = dwarf2_per_cu_objfile (debaton->per_cu);
469 return target_translate_tls_address (objfile, offset);
472 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
473 current CU (as is PER_CU). State of the CTX is not affected by the
477 per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset,
478 struct dwarf2_per_cu_data *per_cu,
479 CORE_ADDR (*get_frame_pc) (void *baton),
482 struct dwarf2_locexpr_baton block;
484 block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu, get_frame_pc, baton);
486 /* DW_OP_call_ref is currently not supported. */
487 gdb_assert (block.per_cu == per_cu);
489 dwarf_expr_eval (ctx, block.data, block.size);
492 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
495 dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
497 struct dwarf_expr_baton *debaton = ctx->baton;
499 per_cu_dwarf_call (ctx, die_offset, debaton->per_cu,
500 ctx->funcs->get_frame_pc, ctx->baton);
503 /* Callback function for dwarf2_evaluate_loc_desc. */
506 dwarf_expr_get_base_type (struct dwarf_expr_context *ctx,
507 cu_offset die_offset)
509 struct dwarf_expr_baton *debaton = ctx->baton;
511 return dwarf2_get_die_type (die_offset, debaton->per_cu);
514 /* See dwarf2loc.h. */
516 unsigned int entry_values_debug = 0;
518 /* Helper to set entry_values_debug. */
521 show_entry_values_debug (struct ui_file *file, int from_tty,
522 struct cmd_list_element *c, const char *value)
524 fprintf_filtered (file,
525 _("Entry values and tail call frames debugging is %s.\n"),
529 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
530 CALLER_FRAME (for registers) can be NULL if it is not known. This function
531 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
534 call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
535 struct call_site *call_site,
536 struct frame_info *caller_frame)
538 switch (FIELD_LOC_KIND (call_site->target))
540 case FIELD_LOC_KIND_DWARF_BLOCK:
542 struct dwarf2_locexpr_baton *dwarf_block;
544 struct type *caller_core_addr_type;
545 struct gdbarch *caller_arch;
547 dwarf_block = FIELD_DWARF_BLOCK (call_site->target);
548 if (dwarf_block == NULL)
550 struct bound_minimal_symbol msym;
552 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
553 throw_error (NO_ENTRY_VALUE_ERROR,
554 _("DW_AT_GNU_call_site_target is not specified "
556 paddress (call_site_gdbarch, call_site->pc),
557 (msym.minsym == NULL ? "???"
558 : MSYMBOL_PRINT_NAME (msym.minsym)));
561 if (caller_frame == NULL)
563 struct bound_minimal_symbol msym;
565 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
566 throw_error (NO_ENTRY_VALUE_ERROR,
567 _("DW_AT_GNU_call_site_target DWARF block resolving "
568 "requires known frame which is currently not "
569 "available at %s in %s"),
570 paddress (call_site_gdbarch, call_site->pc),
571 (msym.minsym == NULL ? "???"
572 : MSYMBOL_PRINT_NAME (msym.minsym)));
575 caller_arch = get_frame_arch (caller_frame);
576 caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr;
577 val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame,
578 dwarf_block->data, dwarf_block->size,
579 dwarf_block->per_cu);
580 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
582 if (VALUE_LVAL (val) == lval_memory)
583 return value_address (val);
585 return value_as_address (val);
588 case FIELD_LOC_KIND_PHYSNAME:
590 const char *physname;
591 struct minimal_symbol *msym;
593 physname = FIELD_STATIC_PHYSNAME (call_site->target);
595 /* Handle both the mangled and demangled PHYSNAME. */
596 msym = lookup_minimal_symbol (physname, NULL, NULL);
599 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1).minsym;
600 throw_error (NO_ENTRY_VALUE_ERROR,
601 _("Cannot find function \"%s\" for a call site target "
603 physname, paddress (call_site_gdbarch, call_site->pc),
604 msym == NULL ? "???" : MSYMBOL_PRINT_NAME (msym));
607 return MSYMBOL_VALUE_ADDRESS (msym);
610 case FIELD_LOC_KIND_PHYSADDR:
611 return FIELD_STATIC_PHYSADDR (call_site->target);
614 internal_error (__FILE__, __LINE__, _("invalid call site target kind"));
618 /* Convert function entry point exact address ADDR to the function which is
619 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
620 NO_ENTRY_VALUE_ERROR otherwise. */
622 static struct symbol *
623 func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
625 struct symbol *sym = find_pc_function (addr);
628 if (sym == NULL || BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) != addr)
629 throw_error (NO_ENTRY_VALUE_ERROR,
630 _("DW_TAG_GNU_call_site resolving failed to find function "
631 "name for address %s"),
632 paddress (gdbarch, addr));
634 type = SYMBOL_TYPE (sym);
635 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC);
636 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
641 /* Verify function with entry point exact address ADDR can never call itself
642 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
643 can call itself via tail calls.
645 If a funtion can tail call itself its entry value based parameters are
646 unreliable. There is no verification whether the value of some/all
647 parameters is unchanged through the self tail call, we expect if there is
648 a self tail call all the parameters can be modified. */
651 func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
653 struct obstack addr_obstack;
654 struct cleanup *old_chain;
657 /* Track here CORE_ADDRs which were already visited. */
660 /* The verification is completely unordered. Track here function addresses
661 which still need to be iterated. */
662 VEC (CORE_ADDR) *todo = NULL;
664 obstack_init (&addr_obstack);
665 old_chain = make_cleanup_obstack_free (&addr_obstack);
666 addr_hash = htab_create_alloc_ex (64, core_addr_hash, core_addr_eq, NULL,
667 &addr_obstack, hashtab_obstack_allocate,
669 make_cleanup_htab_delete (addr_hash);
671 make_cleanup (VEC_cleanup (CORE_ADDR), &todo);
673 VEC_safe_push (CORE_ADDR, todo, verify_addr);
674 while (!VEC_empty (CORE_ADDR, todo))
676 struct symbol *func_sym;
677 struct call_site *call_site;
679 addr = VEC_pop (CORE_ADDR, todo);
681 func_sym = func_addr_to_tail_call_list (gdbarch, addr);
683 for (call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym));
684 call_site; call_site = call_site->tail_call_next)
686 CORE_ADDR target_addr;
689 /* CALLER_FRAME with registers is not available for tail-call jumped
691 target_addr = call_site_to_target_addr (gdbarch, call_site, NULL);
693 if (target_addr == verify_addr)
695 struct bound_minimal_symbol msym;
697 msym = lookup_minimal_symbol_by_pc (verify_addr);
698 throw_error (NO_ENTRY_VALUE_ERROR,
699 _("DW_OP_GNU_entry_value resolving has found "
700 "function \"%s\" at %s can call itself via tail "
702 (msym.minsym == NULL ? "???"
703 : MSYMBOL_PRINT_NAME (msym.minsym)),
704 paddress (gdbarch, verify_addr));
707 slot = htab_find_slot (addr_hash, &target_addr, INSERT);
710 *slot = obstack_copy (&addr_obstack, &target_addr,
711 sizeof (target_addr));
712 VEC_safe_push (CORE_ADDR, todo, target_addr);
717 do_cleanups (old_chain);
720 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
721 ENTRY_VALUES_DEBUG. */
724 tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
726 CORE_ADDR addr = call_site->pc;
727 struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (addr - 1);
729 fprintf_unfiltered (gdb_stdlog, " %s(%s)", paddress (gdbarch, addr),
730 (msym.minsym == NULL ? "???"
731 : MSYMBOL_PRINT_NAME (msym.minsym)));
735 /* vec.h needs single word type name, typedef it. */
736 typedef struct call_site *call_sitep;
738 /* Define VEC (call_sitep) functions. */
739 DEF_VEC_P (call_sitep);
741 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
742 only top callers and bottom callees which are present in both. GDBARCH is
743 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
744 no remaining possibilities to provide unambiguous non-trivial result.
745 RESULTP should point to NULL on the first (initialization) call. Caller is
746 responsible for xfree of any RESULTP data. */
749 chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
750 VEC (call_sitep) *chain)
752 struct call_site_chain *result = *resultp;
753 long length = VEC_length (call_sitep, chain);
754 int callers, callees, idx;
758 /* Create the initial chain containing all the passed PCs. */
760 result = xmalloc (sizeof (*result) + sizeof (*result->call_site)
762 result->length = length;
763 result->callers = result->callees = length;
764 if (!VEC_empty (call_sitep, chain))
765 memcpy (result->call_site, VEC_address (call_sitep, chain),
766 sizeof (*result->call_site) * length);
769 if (entry_values_debug)
771 fprintf_unfiltered (gdb_stdlog, "tailcall: initial:");
772 for (idx = 0; idx < length; idx++)
773 tailcall_dump (gdbarch, result->call_site[idx]);
774 fputc_unfiltered ('\n', gdb_stdlog);
780 if (entry_values_debug)
782 fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
783 for (idx = 0; idx < length; idx++)
784 tailcall_dump (gdbarch, VEC_index (call_sitep, chain, idx));
785 fputc_unfiltered ('\n', gdb_stdlog);
788 /* Intersect callers. */
790 callers = min (result->callers, length);
791 for (idx = 0; idx < callers; idx++)
792 if (result->call_site[idx] != VEC_index (call_sitep, chain, idx))
794 result->callers = idx;
798 /* Intersect callees. */
800 callees = min (result->callees, length);
801 for (idx = 0; idx < callees; idx++)
802 if (result->call_site[result->length - 1 - idx]
803 != VEC_index (call_sitep, chain, length - 1 - idx))
805 result->callees = idx;
809 if (entry_values_debug)
811 fprintf_unfiltered (gdb_stdlog, "tailcall: reduced:");
812 for (idx = 0; idx < result->callers; idx++)
813 tailcall_dump (gdbarch, result->call_site[idx]);
814 fputs_unfiltered (" |", gdb_stdlog);
815 for (idx = 0; idx < result->callees; idx++)
816 tailcall_dump (gdbarch, result->call_site[result->length
817 - result->callees + idx]);
818 fputc_unfiltered ('\n', gdb_stdlog);
821 if (result->callers == 0 && result->callees == 0)
823 /* There are no common callers or callees. It could be also a direct
824 call (which has length 0) with ambiguous possibility of an indirect
825 call - CALLERS == CALLEES == 0 is valid during the first allocation
826 but any subsequence processing of such entry means ambiguity. */
832 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
833 PC again. In such case there must be two different code paths to reach
834 it, therefore some of the former determined intermediate PCs must differ
835 and the unambiguous chain gets shortened. */
836 gdb_assert (result->callers + result->callees < result->length);
839 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
840 assumed frames between them use GDBARCH. Use depth first search so we can
841 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
842 would have needless GDB stack overhead. Caller is responsible for xfree of
843 the returned result. Any unreliability results in thrown
844 NO_ENTRY_VALUE_ERROR. */
846 static struct call_site_chain *
847 call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
850 CORE_ADDR save_callee_pc = callee_pc;
851 struct obstack addr_obstack;
852 struct cleanup *back_to_retval, *back_to_workdata;
853 struct call_site_chain *retval = NULL;
854 struct call_site *call_site;
856 /* Mark CALL_SITEs so we do not visit the same ones twice. */
859 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
860 call_site nor any possible call_site at CALLEE_PC's function is there.
861 Any CALL_SITE in CHAIN will be iterated to its siblings - via
862 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
863 VEC (call_sitep) *chain = NULL;
865 /* We are not interested in the specific PC inside the callee function. */
866 callee_pc = get_pc_function_start (callee_pc);
868 throw_error (NO_ENTRY_VALUE_ERROR, _("Unable to find function for PC %s"),
869 paddress (gdbarch, save_callee_pc));
871 back_to_retval = make_cleanup (free_current_contents, &retval);
873 obstack_init (&addr_obstack);
874 back_to_workdata = make_cleanup_obstack_free (&addr_obstack);
875 addr_hash = htab_create_alloc_ex (64, core_addr_hash, core_addr_eq, NULL,
876 &addr_obstack, hashtab_obstack_allocate,
878 make_cleanup_htab_delete (addr_hash);
880 make_cleanup (VEC_cleanup (call_sitep), &chain);
882 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
883 at the target's function. All the possible tail call sites in the
884 target's function will get iterated as already pushed into CHAIN via their
886 call_site = call_site_for_pc (gdbarch, caller_pc);
890 CORE_ADDR target_func_addr;
891 struct call_site *target_call_site;
893 /* CALLER_FRAME with registers is not available for tail-call jumped
895 target_func_addr = call_site_to_target_addr (gdbarch, call_site, NULL);
897 if (target_func_addr == callee_pc)
899 chain_candidate (gdbarch, &retval, chain);
903 /* There is no way to reach CALLEE_PC again as we would prevent
904 entering it twice as being already marked in ADDR_HASH. */
905 target_call_site = NULL;
909 struct symbol *target_func;
911 target_func = func_addr_to_tail_call_list (gdbarch, target_func_addr);
912 target_call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func));
917 /* Attempt to visit TARGET_CALL_SITE. */
919 if (target_call_site)
923 slot = htab_find_slot (addr_hash, &target_call_site->pc, INSERT);
926 /* Successfully entered TARGET_CALL_SITE. */
928 *slot = &target_call_site->pc;
929 VEC_safe_push (call_sitep, chain, target_call_site);
934 /* Backtrack (without revisiting the originating call_site). Try the
935 callers's sibling; if there isn't any try the callers's callers's
938 target_call_site = NULL;
939 while (!VEC_empty (call_sitep, chain))
941 call_site = VEC_pop (call_sitep, chain);
943 gdb_assert (htab_find_slot (addr_hash, &call_site->pc,
945 htab_remove_elt (addr_hash, &call_site->pc);
947 target_call_site = call_site->tail_call_next;
948 if (target_call_site)
952 while (target_call_site);
954 if (VEC_empty (call_sitep, chain))
957 call_site = VEC_last (call_sitep, chain);
962 struct bound_minimal_symbol msym_caller, msym_callee;
964 msym_caller = lookup_minimal_symbol_by_pc (caller_pc);
965 msym_callee = lookup_minimal_symbol_by_pc (callee_pc);
966 throw_error (NO_ENTRY_VALUE_ERROR,
967 _("There are no unambiguously determinable intermediate "
968 "callers or callees between caller function \"%s\" at %s "
969 "and callee function \"%s\" at %s"),
970 (msym_caller.minsym == NULL
971 ? "???" : MSYMBOL_PRINT_NAME (msym_caller.minsym)),
972 paddress (gdbarch, caller_pc),
973 (msym_callee.minsym == NULL
974 ? "???" : MSYMBOL_PRINT_NAME (msym_callee.minsym)),
975 paddress (gdbarch, callee_pc));
978 do_cleanups (back_to_workdata);
979 discard_cleanups (back_to_retval);
983 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
984 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
985 constructed return NULL. Caller is responsible for xfree of the returned
988 struct call_site_chain *
989 call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
992 volatile struct gdb_exception e;
993 struct call_site_chain *retval = NULL;
995 TRY_CATCH (e, RETURN_MASK_ERROR)
997 retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc);
1001 if (e.error == NO_ENTRY_VALUE_ERROR)
1003 if (entry_values_debug)
1004 exception_print (gdb_stdout, e);
1009 throw_exception (e);
1014 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1017 call_site_parameter_matches (struct call_site_parameter *parameter,
1018 enum call_site_parameter_kind kind,
1019 union call_site_parameter_u kind_u)
1021 if (kind == parameter->kind)
1024 case CALL_SITE_PARAMETER_DWARF_REG:
1025 return kind_u.dwarf_reg == parameter->u.dwarf_reg;
1026 case CALL_SITE_PARAMETER_FB_OFFSET:
1027 return kind_u.fb_offset == parameter->u.fb_offset;
1028 case CALL_SITE_PARAMETER_PARAM_OFFSET:
1029 return kind_u.param_offset.cu_off == parameter->u.param_offset.cu_off;
1034 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1035 FRAME is for callee.
1037 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1040 static struct call_site_parameter *
1041 dwarf_expr_reg_to_entry_parameter (struct frame_info *frame,
1042 enum call_site_parameter_kind kind,
1043 union call_site_parameter_u kind_u,
1044 struct dwarf2_per_cu_data **per_cu_return)
1046 CORE_ADDR func_addr, caller_pc;
1047 struct gdbarch *gdbarch;
1048 struct frame_info *caller_frame;
1049 struct call_site *call_site;
1051 /* Initialize it just to avoid a GCC false warning. */
1052 struct call_site_parameter *parameter = NULL;
1053 CORE_ADDR target_addr;
1055 while (get_frame_type (frame) == INLINE_FRAME)
1057 frame = get_prev_frame (frame);
1058 gdb_assert (frame != NULL);
1061 func_addr = get_frame_func (frame);
1062 gdbarch = get_frame_arch (frame);
1063 caller_frame = get_prev_frame (frame);
1064 if (gdbarch != frame_unwind_arch (frame))
1066 struct bound_minimal_symbol msym
1067 = lookup_minimal_symbol_by_pc (func_addr);
1068 struct gdbarch *caller_gdbarch = frame_unwind_arch (frame);
1070 throw_error (NO_ENTRY_VALUE_ERROR,
1071 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
1072 "(of %s (%s)) does not match caller gdbarch %s"),
1073 gdbarch_bfd_arch_info (gdbarch)->printable_name,
1074 paddress (gdbarch, func_addr),
1075 (msym.minsym == NULL ? "???"
1076 : MSYMBOL_PRINT_NAME (msym.minsym)),
1077 gdbarch_bfd_arch_info (caller_gdbarch)->printable_name);
1080 if (caller_frame == NULL)
1082 struct bound_minimal_symbol msym
1083 = lookup_minimal_symbol_by_pc (func_addr);
1085 throw_error (NO_ENTRY_VALUE_ERROR, _("DW_OP_GNU_entry_value resolving "
1086 "requires caller of %s (%s)"),
1087 paddress (gdbarch, func_addr),
1088 (msym.minsym == NULL ? "???"
1089 : MSYMBOL_PRINT_NAME (msym.minsym)));
1091 caller_pc = get_frame_pc (caller_frame);
1092 call_site = call_site_for_pc (gdbarch, caller_pc);
1094 target_addr = call_site_to_target_addr (gdbarch, call_site, caller_frame);
1095 if (target_addr != func_addr)
1097 struct minimal_symbol *target_msym, *func_msym;
1099 target_msym = lookup_minimal_symbol_by_pc (target_addr).minsym;
1100 func_msym = lookup_minimal_symbol_by_pc (func_addr).minsym;
1101 throw_error (NO_ENTRY_VALUE_ERROR,
1102 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
1103 "but the called frame is for %s at %s"),
1104 (target_msym == NULL ? "???"
1105 : MSYMBOL_PRINT_NAME (target_msym)),
1106 paddress (gdbarch, target_addr),
1107 func_msym == NULL ? "???" : MSYMBOL_PRINT_NAME (func_msym),
1108 paddress (gdbarch, func_addr));
1111 /* No entry value based parameters would be reliable if this function can
1112 call itself via tail calls. */
1113 func_verify_no_selftailcall (gdbarch, func_addr);
1115 for (iparams = 0; iparams < call_site->parameter_count; iparams++)
1117 parameter = &call_site->parameter[iparams];
1118 if (call_site_parameter_matches (parameter, kind, kind_u))
1121 if (iparams == call_site->parameter_count)
1123 struct minimal_symbol *msym
1124 = lookup_minimal_symbol_by_pc (caller_pc).minsym;
1126 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
1127 determine its value. */
1128 throw_error (NO_ENTRY_VALUE_ERROR, _("Cannot find matching parameter "
1129 "at DW_TAG_GNU_call_site %s at %s"),
1130 paddress (gdbarch, caller_pc),
1131 msym == NULL ? "???" : MSYMBOL_PRINT_NAME (msym));
1134 *per_cu_return = call_site->per_cu;
1138 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1139 the normal DW_AT_GNU_call_site_value block. Otherwise return the
1140 DW_AT_GNU_call_site_data_value (dereferenced) block.
1142 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1145 Function always returns non-NULL, non-optimized out value. It throws
1146 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1148 static struct value *
1149 dwarf_entry_parameter_to_value (struct call_site_parameter *parameter,
1150 CORE_ADDR deref_size, struct type *type,
1151 struct frame_info *caller_frame,
1152 struct dwarf2_per_cu_data *per_cu)
1154 const gdb_byte *data_src;
1158 data_src = deref_size == -1 ? parameter->value : parameter->data_value;
1159 size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
1161 /* DEREF_SIZE size is not verified here. */
1162 if (data_src == NULL)
1163 throw_error (NO_ENTRY_VALUE_ERROR,
1164 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1166 /* DW_AT_GNU_call_site_value is a DWARF expression, not a DWARF
1167 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1169 data = alloca (size + 1);
1170 memcpy (data, data_src, size);
1171 data[size] = DW_OP_stack_value;
1173 return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu);
1176 /* Execute DWARF block of call_site_parameter which matches KIND and KIND_U.
1177 Choose DEREF_SIZE value of that parameter. Search caller of the CTX's
1178 frame. CTX must be of dwarf_expr_ctx_funcs kind.
1180 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
1181 can be more simple as it does not support cross-CU DWARF executions. */
1184 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
1185 enum call_site_parameter_kind kind,
1186 union call_site_parameter_u kind_u,
1189 struct dwarf_expr_baton *debaton;
1190 struct frame_info *frame, *caller_frame;
1191 struct dwarf2_per_cu_data *caller_per_cu;
1192 struct dwarf_expr_baton baton_local;
1193 struct dwarf_expr_context saved_ctx;
1194 struct call_site_parameter *parameter;
1195 const gdb_byte *data_src;
1198 gdb_assert (ctx->funcs == &dwarf_expr_ctx_funcs);
1199 debaton = ctx->baton;
1200 frame = debaton->frame;
1201 caller_frame = get_prev_frame (frame);
1203 parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
1205 data_src = deref_size == -1 ? parameter->value : parameter->data_value;
1206 size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
1208 /* DEREF_SIZE size is not verified here. */
1209 if (data_src == NULL)
1210 throw_error (NO_ENTRY_VALUE_ERROR,
1211 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1213 baton_local.frame = caller_frame;
1214 baton_local.per_cu = caller_per_cu;
1216 saved_ctx.gdbarch = ctx->gdbarch;
1217 saved_ctx.addr_size = ctx->addr_size;
1218 saved_ctx.offset = ctx->offset;
1219 saved_ctx.baton = ctx->baton;
1220 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (baton_local.per_cu));
1221 ctx->addr_size = dwarf2_per_cu_addr_size (baton_local.per_cu);
1222 ctx->offset = dwarf2_per_cu_text_offset (baton_local.per_cu);
1223 ctx->baton = &baton_local;
1225 dwarf_expr_eval (ctx, data_src, size);
1227 ctx->gdbarch = saved_ctx.gdbarch;
1228 ctx->addr_size = saved_ctx.addr_size;
1229 ctx->offset = saved_ctx.offset;
1230 ctx->baton = saved_ctx.baton;
1233 /* Callback function for dwarf2_evaluate_loc_desc.
1234 Fetch the address indexed by DW_OP_GNU_addr_index. */
1237 dwarf_expr_get_addr_index (void *baton, unsigned int index)
1239 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
1241 return dwarf2_read_addr_index (debaton->per_cu, index);
1244 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1245 the indirect method on it, that is use its stored target value, the sole
1246 purpose of entry_data_value_funcs.. */
1248 static struct value *
1249 entry_data_value_coerce_ref (const struct value *value)
1251 struct type *checked_type = check_typedef (value_type (value));
1252 struct value *target_val;
1254 if (TYPE_CODE (checked_type) != TYPE_CODE_REF)
1257 target_val = value_computed_closure (value);
1258 value_incref (target_val);
1262 /* Implement copy_closure. */
1265 entry_data_value_copy_closure (const struct value *v)
1267 struct value *target_val = value_computed_closure (v);
1269 value_incref (target_val);
1273 /* Implement free_closure. */
1276 entry_data_value_free_closure (struct value *v)
1278 struct value *target_val = value_computed_closure (v);
1280 value_free (target_val);
1283 /* Vector for methods for an entry value reference where the referenced value
1284 is stored in the caller. On the first dereference use
1285 DW_AT_GNU_call_site_data_value in the caller. */
1287 static const struct lval_funcs entry_data_value_funcs =
1291 NULL, /* check_validity */
1292 NULL, /* check_any_valid */
1293 NULL, /* indirect */
1294 entry_data_value_coerce_ref,
1295 NULL, /* check_synthetic_pointer */
1296 entry_data_value_copy_closure,
1297 entry_data_value_free_closure
1300 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1301 are used to match DW_AT_location at the caller's
1302 DW_TAG_GNU_call_site_parameter.
1304 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1305 cannot resolve the parameter for any reason. */
1307 static struct value *
1308 value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame,
1309 enum call_site_parameter_kind kind,
1310 union call_site_parameter_u kind_u)
1312 struct type *checked_type = check_typedef (type);
1313 struct type *target_type = TYPE_TARGET_TYPE (checked_type);
1314 struct frame_info *caller_frame = get_prev_frame (frame);
1315 struct value *outer_val, *target_val, *val;
1316 struct call_site_parameter *parameter;
1317 struct dwarf2_per_cu_data *caller_per_cu;
1320 parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
1323 outer_val = dwarf_entry_parameter_to_value (parameter, -1 /* deref_size */,
1327 /* Check if DW_AT_GNU_call_site_data_value cannot be used. If it should be
1328 used and it is not available do not fall back to OUTER_VAL - dereferencing
1329 TYPE_CODE_REF with non-entry data value would give current value - not the
1332 if (TYPE_CODE (checked_type) != TYPE_CODE_REF
1333 || TYPE_TARGET_TYPE (checked_type) == NULL)
1336 target_val = dwarf_entry_parameter_to_value (parameter,
1337 TYPE_LENGTH (target_type),
1338 target_type, caller_frame,
1341 /* value_as_address dereferences TYPE_CODE_REF. */
1342 addr = extract_typed_address (value_contents (outer_val), checked_type);
1344 /* The target entry value has artificial address of the entry value
1346 VALUE_LVAL (target_val) = lval_memory;
1347 set_value_address (target_val, addr);
1349 release_value (target_val);
1350 val = allocate_computed_value (type, &entry_data_value_funcs,
1351 target_val /* closure */);
1353 /* Copy the referencing pointer to the new computed value. */
1354 memcpy (value_contents_raw (val), value_contents_raw (outer_val),
1355 TYPE_LENGTH (checked_type));
1356 set_value_lazy (val, 0);
1361 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1362 SIZE are DWARF block used to match DW_AT_location at the caller's
1363 DW_TAG_GNU_call_site_parameter.
1365 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1366 cannot resolve the parameter for any reason. */
1368 static struct value *
1369 value_of_dwarf_block_entry (struct type *type, struct frame_info *frame,
1370 const gdb_byte *block, size_t block_len)
1372 union call_site_parameter_u kind_u;
1374 kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (block, block + block_len);
1375 if (kind_u.dwarf_reg != -1)
1376 return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_DWARF_REG,
1379 if (dwarf_block_to_fb_offset (block, block + block_len, &kind_u.fb_offset))
1380 return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_FB_OFFSET,
1383 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1384 suppressed during normal operation. The expression can be arbitrary if
1385 there is no caller-callee entry value binding expected. */
1386 throw_error (NO_ENTRY_VALUE_ERROR,
1387 _("DWARF-2 expression error: DW_OP_GNU_entry_value is supported "
1388 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1391 struct piece_closure
1393 /* Reference count. */
1396 /* The CU from which this closure's expression came. */
1397 struct dwarf2_per_cu_data *per_cu;
1399 /* The number of pieces used to describe this variable. */
1402 /* The target address size, used only for DWARF_VALUE_STACK. */
1405 /* The pieces themselves. */
1406 struct dwarf_expr_piece *pieces;
1409 /* Allocate a closure for a value formed from separately-described
1412 static struct piece_closure *
1413 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
1414 int n_pieces, struct dwarf_expr_piece *pieces,
1417 struct piece_closure *c = XCNEW (struct piece_closure);
1422 c->n_pieces = n_pieces;
1423 c->addr_size = addr_size;
1424 c->pieces = XCNEWVEC (struct dwarf_expr_piece, n_pieces);
1426 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
1427 for (i = 0; i < n_pieces; ++i)
1428 if (c->pieces[i].location == DWARF_VALUE_STACK)
1429 value_incref (c->pieces[i].v.value);
1434 /* The lowest-level function to extract bits from a byte buffer.
1435 SOURCE is the buffer. It is updated if we read to the end of a
1437 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
1438 updated to reflect the number of bits actually read.
1439 NBITS is the number of bits we want to read. It is updated to
1440 reflect the number of bits actually read. This function may read
1442 BITS_BIG_ENDIAN is taken directly from gdbarch.
1443 This function returns the extracted bits. */
1446 extract_bits_primitive (const gdb_byte **source,
1447 unsigned int *source_offset_bits,
1448 int *nbits, int bits_big_endian)
1450 unsigned int avail, mask, datum;
1452 gdb_assert (*source_offset_bits < 8);
1454 avail = 8 - *source_offset_bits;
1458 mask = (1 << avail) - 1;
1460 if (bits_big_endian)
1461 datum >>= 8 - (*source_offset_bits + *nbits);
1463 datum >>= *source_offset_bits;
1467 *source_offset_bits += avail;
1468 if (*source_offset_bits >= 8)
1470 *source_offset_bits -= 8;
1477 /* Extract some bits from a source buffer and move forward in the
1480 SOURCE is the source buffer. It is updated as bytes are read.
1481 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1483 NBITS is the number of bits to read.
1484 BITS_BIG_ENDIAN is taken directly from gdbarch.
1486 This function returns the bits that were read. */
1489 extract_bits (const gdb_byte **source, unsigned int *source_offset_bits,
1490 int nbits, int bits_big_endian)
1494 gdb_assert (nbits > 0 && nbits <= 8);
1496 datum = extract_bits_primitive (source, source_offset_bits, &nbits,
1502 more = extract_bits_primitive (source, source_offset_bits, &nbits,
1504 if (bits_big_endian)
1514 /* Write some bits into a buffer and move forward in the buffer.
1516 DATUM is the bits to write. The low-order bits of DATUM are used.
1517 DEST is the destination buffer. It is updated as bytes are
1519 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1521 NBITS is the number of valid bits in DATUM.
1522 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1525 insert_bits (unsigned int datum,
1526 gdb_byte *dest, unsigned int dest_offset_bits,
1527 int nbits, int bits_big_endian)
1531 gdb_assert (dest_offset_bits + nbits <= 8);
1533 mask = (1 << nbits) - 1;
1534 if (bits_big_endian)
1536 datum <<= 8 - (dest_offset_bits + nbits);
1537 mask <<= 8 - (dest_offset_bits + nbits);
1541 datum <<= dest_offset_bits;
1542 mask <<= dest_offset_bits;
1545 gdb_assert ((datum & ~mask) == 0);
1547 *dest = (*dest & ~mask) | datum;
1550 /* Copy bits from a source to a destination.
1552 DEST is where the bits should be written.
1553 DEST_OFFSET_BITS is the bit offset into DEST.
1554 SOURCE is the source of bits.
1555 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1556 BIT_COUNT is the number of bits to copy.
1557 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1560 copy_bitwise (gdb_byte *dest, unsigned int dest_offset_bits,
1561 const gdb_byte *source, unsigned int source_offset_bits,
1562 unsigned int bit_count,
1563 int bits_big_endian)
1565 unsigned int dest_avail;
1568 /* Reduce everything to byte-size pieces. */
1569 dest += dest_offset_bits / 8;
1570 dest_offset_bits %= 8;
1571 source += source_offset_bits / 8;
1572 source_offset_bits %= 8;
1574 dest_avail = 8 - dest_offset_bits % 8;
1576 /* See if we can fill the first destination byte. */
1577 if (dest_avail < bit_count)
1579 datum = extract_bits (&source, &source_offset_bits, dest_avail,
1581 insert_bits (datum, dest, dest_offset_bits, dest_avail, bits_big_endian);
1583 dest_offset_bits = 0;
1584 bit_count -= dest_avail;
1587 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1588 than 8 bits remaining. */
1589 gdb_assert (dest_offset_bits % 8 == 0 || bit_count < 8);
1590 for (; bit_count >= 8; bit_count -= 8)
1592 datum = extract_bits (&source, &source_offset_bits, 8, bits_big_endian);
1593 *dest++ = (gdb_byte) datum;
1596 /* Finally, we may have a few leftover bits. */
1597 gdb_assert (bit_count <= 8 - dest_offset_bits % 8);
1600 datum = extract_bits (&source, &source_offset_bits, bit_count,
1602 insert_bits (datum, dest, dest_offset_bits, bit_count, bits_big_endian);
1607 read_pieced_value (struct value *v)
1611 ULONGEST bits_to_skip;
1613 struct piece_closure *c
1614 = (struct piece_closure *) value_computed_closure (v);
1615 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v));
1617 size_t buffer_size = 0;
1618 gdb_byte *buffer = NULL;
1619 struct cleanup *cleanup;
1621 = gdbarch_bits_big_endian (get_type_arch (value_type (v)));
1623 if (value_type (v) != value_enclosing_type (v))
1624 internal_error (__FILE__, __LINE__,
1625 _("Should not be able to create a lazy value with "
1626 "an enclosing type"));
1628 cleanup = make_cleanup (free_current_contents, &buffer);
1630 contents = value_contents_raw (v);
1631 bits_to_skip = 8 * value_offset (v);
1632 if (value_bitsize (v))
1634 bits_to_skip += value_bitpos (v);
1635 type_len = value_bitsize (v);
1638 type_len = 8 * TYPE_LENGTH (value_type (v));
1640 for (i = 0; i < c->n_pieces && offset < type_len; i++)
1642 struct dwarf_expr_piece *p = &c->pieces[i];
1643 size_t this_size, this_size_bits;
1644 long dest_offset_bits, source_offset_bits, source_offset;
1645 const gdb_byte *intermediate_buffer;
1647 /* Compute size, source, and destination offsets for copying, in
1649 this_size_bits = p->size;
1650 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
1652 bits_to_skip -= this_size_bits;
1655 if (bits_to_skip > 0)
1657 dest_offset_bits = 0;
1658 source_offset_bits = bits_to_skip;
1659 this_size_bits -= bits_to_skip;
1664 dest_offset_bits = offset;
1665 source_offset_bits = 0;
1667 if (this_size_bits > type_len - offset)
1668 this_size_bits = type_len - offset;
1670 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
1671 source_offset = source_offset_bits / 8;
1672 if (buffer_size < this_size)
1674 buffer_size = this_size;
1675 buffer = xrealloc (buffer, buffer_size);
1677 intermediate_buffer = buffer;
1679 /* Copy from the source to DEST_BUFFER. */
1680 switch (p->location)
1682 case DWARF_VALUE_REGISTER:
1684 struct gdbarch *arch = get_frame_arch (frame);
1685 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.regno);
1686 int reg_offset = source_offset;
1688 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
1689 && this_size < register_size (arch, gdb_regnum))
1691 /* Big-endian, and we want less than full size. */
1692 reg_offset = register_size (arch, gdb_regnum) - this_size;
1693 /* We want the lower-order THIS_SIZE_BITS of the bytes
1694 we extract from the register. */
1695 source_offset_bits += 8 * this_size - this_size_bits;
1698 if (gdb_regnum != -1)
1702 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
1706 /* Just so garbage doesn't ever shine through. */
1707 memset (buffer, 0, this_size);
1710 set_value_optimized_out (v, 1);
1712 mark_value_bits_unavailable (v, offset, this_size_bits);
1717 error (_("Unable to access DWARF register number %s"),
1718 paddress (arch, p->v.regno));
1723 case DWARF_VALUE_MEMORY:
1724 read_value_memory (v, offset,
1725 p->v.mem.in_stack_memory,
1726 p->v.mem.addr + source_offset,
1730 case DWARF_VALUE_STACK:
1732 size_t n = this_size;
1734 if (n > c->addr_size - source_offset)
1735 n = (c->addr_size >= source_offset
1736 ? c->addr_size - source_offset
1744 const gdb_byte *val_bytes = value_contents_all (p->v.value);
1746 intermediate_buffer = val_bytes + source_offset;
1751 case DWARF_VALUE_LITERAL:
1753 size_t n = this_size;
1755 if (n > p->v.literal.length - source_offset)
1756 n = (p->v.literal.length >= source_offset
1757 ? p->v.literal.length - source_offset
1760 intermediate_buffer = p->v.literal.data + source_offset;
1764 /* These bits show up as zeros -- but do not cause the value
1765 to be considered optimized-out. */
1766 case DWARF_VALUE_IMPLICIT_POINTER:
1769 case DWARF_VALUE_OPTIMIZED_OUT:
1770 set_value_optimized_out (v, 1);
1774 internal_error (__FILE__, __LINE__, _("invalid location type"));
1777 if (p->location != DWARF_VALUE_OPTIMIZED_OUT
1778 && p->location != DWARF_VALUE_IMPLICIT_POINTER)
1779 copy_bitwise (contents, dest_offset_bits,
1780 intermediate_buffer, source_offset_bits % 8,
1781 this_size_bits, bits_big_endian);
1783 offset += this_size_bits;
1786 do_cleanups (cleanup);
1790 write_pieced_value (struct value *to, struct value *from)
1794 ULONGEST bits_to_skip;
1795 const gdb_byte *contents;
1796 struct piece_closure *c
1797 = (struct piece_closure *) value_computed_closure (to);
1798 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
1800 size_t buffer_size = 0;
1801 gdb_byte *buffer = NULL;
1802 struct cleanup *cleanup;
1804 = gdbarch_bits_big_endian (get_type_arch (value_type (to)));
1808 set_value_optimized_out (to, 1);
1812 cleanup = make_cleanup (free_current_contents, &buffer);
1814 contents = value_contents (from);
1815 bits_to_skip = 8 * value_offset (to);
1816 if (value_bitsize (to))
1818 bits_to_skip += value_bitpos (to);
1819 type_len = value_bitsize (to);
1822 type_len = 8 * TYPE_LENGTH (value_type (to));
1824 for (i = 0; i < c->n_pieces && offset < type_len; i++)
1826 struct dwarf_expr_piece *p = &c->pieces[i];
1827 size_t this_size_bits, this_size;
1828 long dest_offset_bits, source_offset_bits, dest_offset, source_offset;
1830 const gdb_byte *source_buffer;
1832 this_size_bits = p->size;
1833 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
1835 bits_to_skip -= this_size_bits;
1838 if (this_size_bits > type_len - offset)
1839 this_size_bits = type_len - offset;
1840 if (bits_to_skip > 0)
1842 dest_offset_bits = bits_to_skip;
1843 source_offset_bits = 0;
1844 this_size_bits -= bits_to_skip;
1849 dest_offset_bits = 0;
1850 source_offset_bits = offset;
1853 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
1854 source_offset = source_offset_bits / 8;
1855 dest_offset = dest_offset_bits / 8;
1856 if (dest_offset_bits % 8 == 0 && source_offset_bits % 8 == 0)
1858 source_buffer = contents + source_offset;
1863 if (buffer_size < this_size)
1865 buffer_size = this_size;
1866 buffer = xrealloc (buffer, buffer_size);
1868 source_buffer = buffer;
1872 switch (p->location)
1874 case DWARF_VALUE_REGISTER:
1876 struct gdbarch *arch = get_frame_arch (frame);
1877 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.regno);
1878 int reg_offset = dest_offset;
1880 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
1881 && this_size <= register_size (arch, gdb_regnum))
1882 /* Big-endian, and we want less than full size. */
1883 reg_offset = register_size (arch, gdb_regnum) - this_size;
1885 if (gdb_regnum != -1)
1891 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
1896 throw_error (OPTIMIZED_OUT_ERROR,
1897 _("Can't do read-modify-write to "
1898 "update bitfield; containing word "
1899 "has been optimized out"));
1901 throw_error (NOT_AVAILABLE_ERROR,
1902 _("Can't do read-modify-write to update "
1903 "bitfield; containing word "
1906 copy_bitwise (buffer, dest_offset_bits,
1907 contents, source_offset_bits,
1912 put_frame_register_bytes (frame, gdb_regnum, reg_offset,
1913 this_size, source_buffer);
1917 error (_("Unable to write to DWARF register number %s"),
1918 paddress (arch, p->v.regno));
1922 case DWARF_VALUE_MEMORY:
1925 /* Only the first and last bytes can possibly have any
1927 read_memory (p->v.mem.addr + dest_offset, buffer, 1);
1928 read_memory (p->v.mem.addr + dest_offset + this_size - 1,
1929 buffer + this_size - 1, 1);
1930 copy_bitwise (buffer, dest_offset_bits,
1931 contents, source_offset_bits,
1936 write_memory (p->v.mem.addr + dest_offset,
1937 source_buffer, this_size);
1940 set_value_optimized_out (to, 1);
1943 offset += this_size_bits;
1946 do_cleanups (cleanup);
1949 /* A helper function that checks bit validity in a pieced value.
1950 CHECK_FOR indicates the kind of validity checking.
1951 DWARF_VALUE_MEMORY means to check whether any bit is valid.
1952 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
1954 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
1955 implicit pointer. */
1958 check_pieced_value_bits (const struct value *value, int bit_offset,
1960 enum dwarf_value_location check_for)
1962 struct piece_closure *c
1963 = (struct piece_closure *) value_computed_closure (value);
1965 int validity = (check_for == DWARF_VALUE_MEMORY
1966 || check_for == DWARF_VALUE_IMPLICIT_POINTER);
1968 bit_offset += 8 * value_offset (value);
1969 if (value_bitsize (value))
1970 bit_offset += value_bitpos (value);
1972 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
1974 struct dwarf_expr_piece *p = &c->pieces[i];
1975 size_t this_size_bits = p->size;
1979 if (bit_offset >= this_size_bits)
1981 bit_offset -= this_size_bits;
1985 bit_length -= this_size_bits - bit_offset;
1989 bit_length -= this_size_bits;
1991 if (check_for == DWARF_VALUE_IMPLICIT_POINTER)
1993 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
1996 else if (p->location == DWARF_VALUE_OPTIMIZED_OUT
1997 || p->location == DWARF_VALUE_IMPLICIT_POINTER)
2013 check_pieced_value_validity (const struct value *value, int bit_offset,
2016 return check_pieced_value_bits (value, bit_offset, bit_length,
2017 DWARF_VALUE_MEMORY);
2021 check_pieced_value_invalid (const struct value *value)
2023 return check_pieced_value_bits (value, 0,
2024 8 * TYPE_LENGTH (value_type (value)),
2025 DWARF_VALUE_OPTIMIZED_OUT);
2028 /* An implementation of an lval_funcs method to see whether a value is
2029 a synthetic pointer. */
2032 check_pieced_synthetic_pointer (const struct value *value, int bit_offset,
2035 return check_pieced_value_bits (value, bit_offset, bit_length,
2036 DWARF_VALUE_IMPLICIT_POINTER);
2039 /* A wrapper function for get_frame_address_in_block. */
2042 get_frame_address_in_block_wrapper (void *baton)
2044 return get_frame_address_in_block (baton);
2047 /* An implementation of an lval_funcs method to indirect through a
2048 pointer. This handles the synthetic pointer case when needed. */
2050 static struct value *
2051 indirect_pieced_value (struct value *value)
2053 struct piece_closure *c
2054 = (struct piece_closure *) value_computed_closure (value);
2056 struct frame_info *frame;
2057 struct dwarf2_locexpr_baton baton;
2058 int i, bit_offset, bit_length;
2059 struct dwarf_expr_piece *piece = NULL;
2060 LONGEST byte_offset;
2062 type = check_typedef (value_type (value));
2063 if (TYPE_CODE (type) != TYPE_CODE_PTR)
2066 bit_length = 8 * TYPE_LENGTH (type);
2067 bit_offset = 8 * value_offset (value);
2068 if (value_bitsize (value))
2069 bit_offset += value_bitpos (value);
2071 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
2073 struct dwarf_expr_piece *p = &c->pieces[i];
2074 size_t this_size_bits = p->size;
2078 if (bit_offset >= this_size_bits)
2080 bit_offset -= this_size_bits;
2084 bit_length -= this_size_bits - bit_offset;
2088 bit_length -= this_size_bits;
2090 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
2093 if (bit_length != 0)
2094 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
2100 frame = get_selected_frame (_("No frame selected."));
2102 /* This is an offset requested by GDB, such as value subscripts.
2103 However, due to how synthetic pointers are implemented, this is
2104 always presented to us as a pointer type. This means we have to
2105 sign-extend it manually as appropriate. */
2106 byte_offset = value_as_address (value);
2107 if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
2108 byte_offset = gdb_sign_extend (byte_offset,
2109 8 * TYPE_LENGTH (value_type (value)));
2110 byte_offset += piece->v.ptr.offset;
2114 = dwarf2_fetch_die_loc_sect_off (piece->v.ptr.die, c->per_cu,
2115 get_frame_address_in_block_wrapper,
2118 if (baton.data != NULL)
2119 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
2120 baton.data, baton.size, baton.per_cu,
2124 struct obstack temp_obstack;
2125 struct cleanup *cleanup;
2126 const gdb_byte *bytes;
2128 struct value *result;
2130 obstack_init (&temp_obstack);
2131 cleanup = make_cleanup_obstack_free (&temp_obstack);
2133 bytes = dwarf2_fetch_constant_bytes (piece->v.ptr.die, c->per_cu,
2134 &temp_obstack, &len);
2136 result = allocate_optimized_out_value (TYPE_TARGET_TYPE (type));
2140 || byte_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > len)
2141 invalid_synthetic_pointer ();
2142 bytes += byte_offset;
2143 result = value_from_contents (TYPE_TARGET_TYPE (type), bytes);
2146 do_cleanups (cleanup);
2152 copy_pieced_value_closure (const struct value *v)
2154 struct piece_closure *c
2155 = (struct piece_closure *) value_computed_closure (v);
2162 free_pieced_value_closure (struct value *v)
2164 struct piece_closure *c
2165 = (struct piece_closure *) value_computed_closure (v);
2172 for (i = 0; i < c->n_pieces; ++i)
2173 if (c->pieces[i].location == DWARF_VALUE_STACK)
2174 value_free (c->pieces[i].v.value);
2181 /* Functions for accessing a variable described by DW_OP_piece. */
2182 static const struct lval_funcs pieced_value_funcs = {
2185 check_pieced_value_validity,
2186 check_pieced_value_invalid,
2187 indirect_pieced_value,
2188 NULL, /* coerce_ref */
2189 check_pieced_synthetic_pointer,
2190 copy_pieced_value_closure,
2191 free_pieced_value_closure
2194 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
2196 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
2198 dwarf_expr_read_addr_from_reg,
2199 dwarf_expr_get_reg_value,
2200 dwarf_expr_read_mem,
2201 dwarf_expr_frame_base,
2202 dwarf_expr_frame_cfa,
2203 dwarf_expr_frame_pc,
2204 dwarf_expr_tls_address,
2205 dwarf_expr_dwarf_call,
2206 dwarf_expr_get_base_type,
2207 dwarf_expr_push_dwarf_reg_entry_value,
2208 dwarf_expr_get_addr_index
2211 /* Evaluate a location description, starting at DATA and with length
2212 SIZE, to find the current location of variable of TYPE in the
2213 context of FRAME. BYTE_OFFSET is applied after the contents are
2216 static struct value *
2217 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
2218 const gdb_byte *data, size_t size,
2219 struct dwarf2_per_cu_data *per_cu,
2220 LONGEST byte_offset)
2222 struct value *retval;
2223 struct dwarf_expr_baton baton;
2224 struct dwarf_expr_context *ctx;
2225 struct cleanup *old_chain, *value_chain;
2226 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2227 volatile struct gdb_exception ex;
2229 if (byte_offset < 0)
2230 invalid_synthetic_pointer ();
2233 return allocate_optimized_out_value (type);
2235 baton.frame = frame;
2236 baton.per_cu = per_cu;
2238 ctx = new_dwarf_expr_context ();
2239 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
2240 value_chain = make_cleanup_value_free_to_mark (value_mark ());
2242 ctx->gdbarch = get_objfile_arch (objfile);
2243 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2244 ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
2245 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2246 ctx->baton = &baton;
2247 ctx->funcs = &dwarf_expr_ctx_funcs;
2249 TRY_CATCH (ex, RETURN_MASK_ERROR)
2251 dwarf_expr_eval (ctx, data, size);
2255 if (ex.error == NOT_AVAILABLE_ERROR)
2257 do_cleanups (old_chain);
2258 retval = allocate_value (type);
2259 mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
2262 else if (ex.error == NO_ENTRY_VALUE_ERROR)
2264 if (entry_values_debug)
2265 exception_print (gdb_stdout, ex);
2266 do_cleanups (old_chain);
2267 return allocate_optimized_out_value (type);
2270 throw_exception (ex);
2273 if (ctx->num_pieces > 0)
2275 struct piece_closure *c;
2276 struct frame_id frame_id = get_frame_id (frame);
2277 ULONGEST bit_size = 0;
2280 for (i = 0; i < ctx->num_pieces; ++i)
2281 bit_size += ctx->pieces[i].size;
2282 if (8 * (byte_offset + TYPE_LENGTH (type)) > bit_size)
2283 invalid_synthetic_pointer ();
2285 c = allocate_piece_closure (per_cu, ctx->num_pieces, ctx->pieces,
2287 /* We must clean up the value chain after creating the piece
2288 closure but before allocating the result. */
2289 do_cleanups (value_chain);
2290 retval = allocate_computed_value (type, &pieced_value_funcs, c);
2291 VALUE_FRAME_ID (retval) = frame_id;
2292 set_value_offset (retval, byte_offset);
2296 switch (ctx->location)
2298 case DWARF_VALUE_REGISTER:
2300 struct gdbarch *arch = get_frame_arch (frame);
2302 = longest_to_int (value_as_long (dwarf_expr_fetch (ctx, 0)));
2303 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
2305 if (byte_offset != 0)
2306 error (_("cannot use offset on synthetic pointer to register"));
2307 do_cleanups (value_chain);
2308 if (gdb_regnum == -1)
2309 error (_("Unable to access DWARF register number %d"),
2311 retval = value_from_register (type, gdb_regnum, frame);
2312 if (value_optimized_out (retval))
2314 /* This means the register has undefined value / was
2315 not saved. As we're computing the location of some
2316 variable etc. in the program, not a value for
2317 inspecting a register ($pc, $sp, etc.), return a
2318 generic optimized out value instead, so that we show
2319 <optimized out> instead of <not saved>. */
2320 do_cleanups (value_chain);
2321 retval = allocate_optimized_out_value (type);
2326 case DWARF_VALUE_MEMORY:
2328 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
2329 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
2331 do_cleanups (value_chain);
2332 retval = value_at_lazy (type, address + byte_offset);
2333 if (in_stack_memory)
2334 set_value_stack (retval, 1);
2338 case DWARF_VALUE_STACK:
2340 struct value *value = dwarf_expr_fetch (ctx, 0);
2342 const gdb_byte *val_bytes;
2343 size_t n = TYPE_LENGTH (value_type (value));
2345 if (byte_offset + TYPE_LENGTH (type) > n)
2346 invalid_synthetic_pointer ();
2348 val_bytes = value_contents_all (value);
2349 val_bytes += byte_offset;
2352 /* Preserve VALUE because we are going to free values back
2353 to the mark, but we still need the value contents
2355 value_incref (value);
2356 do_cleanups (value_chain);
2357 make_cleanup_value_free (value);
2359 retval = allocate_value (type);
2360 contents = value_contents_raw (retval);
2361 if (n > TYPE_LENGTH (type))
2363 struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
2365 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
2366 val_bytes += n - TYPE_LENGTH (type);
2367 n = TYPE_LENGTH (type);
2369 memcpy (contents, val_bytes, n);
2373 case DWARF_VALUE_LITERAL:
2376 const bfd_byte *ldata;
2377 size_t n = ctx->len;
2379 if (byte_offset + TYPE_LENGTH (type) > n)
2380 invalid_synthetic_pointer ();
2382 do_cleanups (value_chain);
2383 retval = allocate_value (type);
2384 contents = value_contents_raw (retval);
2386 ldata = ctx->data + byte_offset;
2389 if (n > TYPE_LENGTH (type))
2391 struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
2393 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
2394 ldata += n - TYPE_LENGTH (type);
2395 n = TYPE_LENGTH (type);
2397 memcpy (contents, ldata, n);
2401 case DWARF_VALUE_OPTIMIZED_OUT:
2402 do_cleanups (value_chain);
2403 retval = allocate_optimized_out_value (type);
2406 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2407 operation by execute_stack_op. */
2408 case DWARF_VALUE_IMPLICIT_POINTER:
2409 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2410 it can only be encountered when making a piece. */
2412 internal_error (__FILE__, __LINE__, _("invalid location type"));
2416 set_value_initialized (retval, ctx->initialized);
2418 do_cleanups (old_chain);
2423 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2424 passes 0 as the byte_offset. */
2427 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2428 const gdb_byte *data, size_t size,
2429 struct dwarf2_per_cu_data *per_cu)
2431 return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, 0);
2435 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
2437 struct needs_frame_baton
2440 struct dwarf2_per_cu_data *per_cu;
2443 /* Reads from registers do require a frame. */
2445 needs_frame_read_addr_from_reg (void *baton, int regnum)
2447 struct needs_frame_baton *nf_baton = baton;
2449 nf_baton->needs_frame = 1;
2453 /* struct dwarf_expr_context_funcs' "get_reg_value" callback:
2454 Reads from registers do require a frame. */
2456 static struct value *
2457 needs_frame_get_reg_value (void *baton, struct type *type, int regnum)
2459 struct needs_frame_baton *nf_baton = baton;
2461 nf_baton->needs_frame = 1;
2462 return value_zero (type, not_lval);
2465 /* Reads from memory do not require a frame. */
2467 needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
2469 memset (buf, 0, len);
2472 /* Frame-relative accesses do require a frame. */
2474 needs_frame_frame_base (void *baton, const gdb_byte **start, size_t * length)
2476 static gdb_byte lit0 = DW_OP_lit0;
2477 struct needs_frame_baton *nf_baton = baton;
2482 nf_baton->needs_frame = 1;
2485 /* CFA accesses require a frame. */
2488 needs_frame_frame_cfa (void *baton)
2490 struct needs_frame_baton *nf_baton = baton;
2492 nf_baton->needs_frame = 1;
2496 /* Thread-local accesses do require a frame. */
2498 needs_frame_tls_address (void *baton, CORE_ADDR offset)
2500 struct needs_frame_baton *nf_baton = baton;
2502 nf_baton->needs_frame = 1;
2506 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
2509 needs_frame_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
2511 struct needs_frame_baton *nf_baton = ctx->baton;
2513 per_cu_dwarf_call (ctx, die_offset, nf_baton->per_cu,
2514 ctx->funcs->get_frame_pc, ctx->baton);
2517 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2520 needs_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
2521 enum call_site_parameter_kind kind,
2522 union call_site_parameter_u kind_u, int deref_size)
2524 struct needs_frame_baton *nf_baton = ctx->baton;
2526 nf_baton->needs_frame = 1;
2528 /* The expression may require some stub values on DWARF stack. */
2529 dwarf_expr_push_address (ctx, 0, 0);
2532 /* DW_OP_GNU_addr_index doesn't require a frame. */
2535 needs_get_addr_index (void *baton, unsigned int index)
2537 /* Nothing to do. */
2541 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
2543 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs =
2545 needs_frame_read_addr_from_reg,
2546 needs_frame_get_reg_value,
2547 needs_frame_read_mem,
2548 needs_frame_frame_base,
2549 needs_frame_frame_cfa,
2550 needs_frame_frame_cfa, /* get_frame_pc */
2551 needs_frame_tls_address,
2552 needs_frame_dwarf_call,
2553 NULL, /* get_base_type */
2554 needs_dwarf_reg_entry_value,
2555 needs_get_addr_index
2558 /* Return non-zero iff the location expression at DATA (length SIZE)
2559 requires a frame to evaluate. */
2562 dwarf2_loc_desc_needs_frame (const gdb_byte *data, size_t size,
2563 struct dwarf2_per_cu_data *per_cu)
2565 struct needs_frame_baton baton;
2566 struct dwarf_expr_context *ctx;
2568 struct cleanup *old_chain;
2569 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2571 baton.needs_frame = 0;
2572 baton.per_cu = per_cu;
2574 ctx = new_dwarf_expr_context ();
2575 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
2576 make_cleanup_value_free_to_mark (value_mark ());
2578 ctx->gdbarch = get_objfile_arch (objfile);
2579 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2580 ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
2581 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
2582 ctx->baton = &baton;
2583 ctx->funcs = &needs_frame_ctx_funcs;
2585 dwarf_expr_eval (ctx, data, size);
2587 in_reg = ctx->location == DWARF_VALUE_REGISTER;
2589 if (ctx->num_pieces > 0)
2593 /* If the location has several pieces, and any of them are in
2594 registers, then we will need a frame to fetch them from. */
2595 for (i = 0; i < ctx->num_pieces; i++)
2596 if (ctx->pieces[i].location == DWARF_VALUE_REGISTER)
2600 do_cleanups (old_chain);
2602 return baton.needs_frame || in_reg;
2605 /* A helper function that throws an unimplemented error mentioning a
2606 given DWARF operator. */
2609 unimplemented (unsigned int op)
2611 const char *name = get_DW_OP_name (op);
2614 error (_("DWARF operator %s cannot be translated to an agent expression"),
2617 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2618 "to an agent expression"),
2622 /* A helper function to convert a DWARF register to an arch register.
2623 ARCH is the architecture.
2624 DWARF_REG is the register.
2625 This will throw an exception if the DWARF register cannot be
2626 translated to an architecture register. */
2629 translate_register (struct gdbarch *arch, int dwarf_reg)
2631 int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
2633 error (_("Unable to access DWARF register number %d"), dwarf_reg);
2637 /* A helper function that emits an access to memory. ARCH is the
2638 target architecture. EXPR is the expression which we are building.
2639 NBITS is the number of bits we want to read. This emits the
2640 opcodes needed to read the memory and then extract the desired
2644 access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits)
2646 ULONGEST nbytes = (nbits + 7) / 8;
2648 gdb_assert (nbytes > 0 && nbytes <= sizeof (LONGEST));
2651 ax_trace_quick (expr, nbytes);
2654 ax_simple (expr, aop_ref8);
2655 else if (nbits <= 16)
2656 ax_simple (expr, aop_ref16);
2657 else if (nbits <= 32)
2658 ax_simple (expr, aop_ref32);
2660 ax_simple (expr, aop_ref64);
2662 /* If we read exactly the number of bytes we wanted, we're done. */
2663 if (8 * nbytes == nbits)
2666 if (gdbarch_bits_big_endian (arch))
2668 /* On a bits-big-endian machine, we want the high-order
2670 ax_const_l (expr, 8 * nbytes - nbits);
2671 ax_simple (expr, aop_rsh_unsigned);
2675 /* On a bits-little-endian box, we want the low-order NBITS. */
2676 ax_zero_ext (expr, nbits);
2680 /* A helper function to return the frame's PC. */
2683 get_ax_pc (void *baton)
2685 struct agent_expr *expr = baton;
2690 /* Compile a DWARF location expression to an agent expression.
2692 EXPR is the agent expression we are building.
2693 LOC is the agent value we modify.
2694 ARCH is the architecture.
2695 ADDR_SIZE is the size of addresses, in bytes.
2696 OP_PTR is the start of the location expression.
2697 OP_END is one past the last byte of the location expression.
2699 This will throw an exception for various kinds of errors -- for
2700 example, if the expression cannot be compiled, or if the expression
2704 dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
2705 struct gdbarch *arch, unsigned int addr_size,
2706 const gdb_byte *op_ptr, const gdb_byte *op_end,
2707 struct dwarf2_per_cu_data *per_cu)
2709 struct cleanup *cleanups;
2711 VEC(int) *dw_labels = NULL, *patches = NULL;
2712 const gdb_byte * const base = op_ptr;
2713 const gdb_byte *previous_piece = op_ptr;
2714 enum bfd_endian byte_order = gdbarch_byte_order (arch);
2715 ULONGEST bits_collected = 0;
2716 unsigned int addr_size_bits = 8 * addr_size;
2717 int bits_big_endian = gdbarch_bits_big_endian (arch);
2719 offsets = xmalloc ((op_end - op_ptr) * sizeof (int));
2720 cleanups = make_cleanup (xfree, offsets);
2722 for (i = 0; i < op_end - op_ptr; ++i)
2725 make_cleanup (VEC_cleanup (int), &dw_labels);
2726 make_cleanup (VEC_cleanup (int), &patches);
2728 /* By default we are making an address. */
2729 loc->kind = axs_lvalue_memory;
2731 while (op_ptr < op_end)
2733 enum dwarf_location_atom op = *op_ptr;
2734 uint64_t uoffset, reg;
2738 offsets[op_ptr - base] = expr->len;
2741 /* Our basic approach to code generation is to map DWARF
2742 operations directly to AX operations. However, there are
2745 First, DWARF works on address-sized units, but AX always uses
2746 LONGEST. For most operations we simply ignore this
2747 difference; instead we generate sign extensions as needed
2748 before division and comparison operations. It would be nice
2749 to omit the sign extensions, but there is no way to determine
2750 the size of the target's LONGEST. (This code uses the size
2751 of the host LONGEST in some cases -- that is a bug but it is
2754 Second, some DWARF operations cannot be translated to AX.
2755 For these we simply fail. See
2756 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2791 ax_const_l (expr, op - DW_OP_lit0);
2795 uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
2796 op_ptr += addr_size;
2797 /* Some versions of GCC emit DW_OP_addr before
2798 DW_OP_GNU_push_tls_address. In this case the value is an
2799 index, not an address. We don't support things like
2800 branching between the address and the TLS op. */
2801 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
2802 uoffset += dwarf2_per_cu_text_offset (per_cu);
2803 ax_const_l (expr, uoffset);
2807 ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order));
2811 ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order));
2815 ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order));
2819 ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order));
2823 ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order));
2827 ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order));
2831 ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order));
2835 ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order));
2839 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
2840 ax_const_l (expr, uoffset);
2843 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
2844 ax_const_l (expr, offset);
2879 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
2880 loc->u.reg = translate_register (arch, op - DW_OP_reg0);
2881 loc->kind = axs_lvalue_register;
2885 op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
2886 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
2887 loc->u.reg = translate_register (arch, reg);
2888 loc->kind = axs_lvalue_register;
2891 case DW_OP_implicit_value:
2895 op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
2896 if (op_ptr + len > op_end)
2897 error (_("DW_OP_implicit_value: too few bytes available."));
2898 if (len > sizeof (ULONGEST))
2899 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2902 ax_const_l (expr, extract_unsigned_integer (op_ptr, len,
2905 dwarf_expr_require_composition (op_ptr, op_end,
2906 "DW_OP_implicit_value");
2908 loc->kind = axs_rvalue;
2912 case DW_OP_stack_value:
2913 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
2914 loc->kind = axs_rvalue;
2949 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
2950 i = translate_register (arch, op - DW_OP_breg0);
2954 ax_const_l (expr, offset);
2955 ax_simple (expr, aop_add);
2960 op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
2961 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
2962 i = translate_register (arch, reg);
2966 ax_const_l (expr, offset);
2967 ax_simple (expr, aop_add);
2973 const gdb_byte *datastart;
2976 struct symbol *framefunc;
2978 b = block_for_pc (expr->scope);
2981 error (_("No block found for address"));
2983 framefunc = block_linkage_function (b);
2986 error (_("No function found for block"));
2988 dwarf_expr_frame_base_1 (framefunc, expr->scope,
2989 &datastart, &datalen);
2991 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
2992 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, datastart,
2993 datastart + datalen, per_cu);
2994 if (loc->kind == axs_lvalue_register)
2995 require_rvalue (expr, loc);
2999 ax_const_l (expr, offset);
3000 ax_simple (expr, aop_add);
3003 loc->kind = axs_lvalue_memory;
3008 ax_simple (expr, aop_dup);
3012 ax_simple (expr, aop_pop);
3017 ax_pick (expr, offset);
3021 ax_simple (expr, aop_swap);
3029 ax_simple (expr, aop_rot);
3033 case DW_OP_deref_size:
3037 if (op == DW_OP_deref_size)
3042 if (size != 1 && size != 2 && size != 4 && size != 8)
3043 error (_("Unsupported size %d in %s"),
3044 size, get_DW_OP_name (op));
3045 access_memory (arch, expr, size * TARGET_CHAR_BIT);
3050 /* Sign extend the operand. */
3051 ax_ext (expr, addr_size_bits);
3052 ax_simple (expr, aop_dup);
3053 ax_const_l (expr, 0);
3054 ax_simple (expr, aop_less_signed);
3055 ax_simple (expr, aop_log_not);
3056 i = ax_goto (expr, aop_if_goto);
3057 /* We have to emit 0 - X. */
3058 ax_const_l (expr, 0);
3059 ax_simple (expr, aop_swap);
3060 ax_simple (expr, aop_sub);
3061 ax_label (expr, i, expr->len);
3065 /* No need to sign extend here. */
3066 ax_const_l (expr, 0);
3067 ax_simple (expr, aop_swap);
3068 ax_simple (expr, aop_sub);
3072 /* Sign extend the operand. */
3073 ax_ext (expr, addr_size_bits);
3074 ax_simple (expr, aop_bit_not);
3077 case DW_OP_plus_uconst:
3078 op_ptr = safe_read_uleb128 (op_ptr, op_end, ®);
3079 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3080 but we micro-optimize anyhow. */
3083 ax_const_l (expr, reg);
3084 ax_simple (expr, aop_add);
3089 ax_simple (expr, aop_bit_and);
3093 /* Sign extend the operands. */
3094 ax_ext (expr, addr_size_bits);
3095 ax_simple (expr, aop_swap);
3096 ax_ext (expr, addr_size_bits);
3097 ax_simple (expr, aop_swap);
3098 ax_simple (expr, aop_div_signed);
3102 ax_simple (expr, aop_sub);
3106 ax_simple (expr, aop_rem_unsigned);
3110 ax_simple (expr, aop_mul);
3114 ax_simple (expr, aop_bit_or);
3118 ax_simple (expr, aop_add);
3122 ax_simple (expr, aop_lsh);
3126 ax_simple (expr, aop_rsh_unsigned);
3130 ax_simple (expr, aop_rsh_signed);
3134 ax_simple (expr, aop_bit_xor);
3138 /* Sign extend the operands. */
3139 ax_ext (expr, addr_size_bits);
3140 ax_simple (expr, aop_swap);
3141 ax_ext (expr, addr_size_bits);
3142 /* Note no swap here: A <= B is !(B < A). */
3143 ax_simple (expr, aop_less_signed);
3144 ax_simple (expr, aop_log_not);
3148 /* Sign extend the operands. */
3149 ax_ext (expr, addr_size_bits);
3150 ax_simple (expr, aop_swap);
3151 ax_ext (expr, addr_size_bits);
3152 ax_simple (expr, aop_swap);
3153 /* A >= B is !(A < B). */
3154 ax_simple (expr, aop_less_signed);
3155 ax_simple (expr, aop_log_not);
3159 /* Sign extend the operands. */
3160 ax_ext (expr, addr_size_bits);
3161 ax_simple (expr, aop_swap);
3162 ax_ext (expr, addr_size_bits);
3163 /* No need for a second swap here. */
3164 ax_simple (expr, aop_equal);
3168 /* Sign extend the operands. */
3169 ax_ext (expr, addr_size_bits);
3170 ax_simple (expr, aop_swap);
3171 ax_ext (expr, addr_size_bits);
3172 ax_simple (expr, aop_swap);
3173 ax_simple (expr, aop_less_signed);
3177 /* Sign extend the operands. */
3178 ax_ext (expr, addr_size_bits);
3179 ax_simple (expr, aop_swap);
3180 ax_ext (expr, addr_size_bits);
3181 /* Note no swap here: A > B is B < A. */
3182 ax_simple (expr, aop_less_signed);
3186 /* Sign extend the operands. */
3187 ax_ext (expr, addr_size_bits);
3188 ax_simple (expr, aop_swap);
3189 ax_ext (expr, addr_size_bits);
3190 /* No need for a swap here. */
3191 ax_simple (expr, aop_equal);
3192 ax_simple (expr, aop_log_not);
3195 case DW_OP_call_frame_cfa:
3196 dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu);
3197 loc->kind = axs_lvalue_memory;
3200 case DW_OP_GNU_push_tls_address:
3205 offset = extract_signed_integer (op_ptr, 2, byte_order);
3207 i = ax_goto (expr, aop_goto);
3208 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
3209 VEC_safe_push (int, patches, i);
3213 offset = extract_signed_integer (op_ptr, 2, byte_order);
3215 /* Zero extend the operand. */
3216 ax_zero_ext (expr, addr_size_bits);
3217 i = ax_goto (expr, aop_if_goto);
3218 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
3219 VEC_safe_push (int, patches, i);
3226 case DW_OP_bit_piece:
3228 uint64_t size, offset;
3230 if (op_ptr - 1 == previous_piece)
3231 error (_("Cannot translate empty pieces to agent expressions"));
3232 previous_piece = op_ptr - 1;
3234 op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
3235 if (op == DW_OP_piece)
3241 op_ptr = safe_read_uleb128 (op_ptr, op_end, &offset);
3243 if (bits_collected + size > 8 * sizeof (LONGEST))
3244 error (_("Expression pieces exceed word size"));
3246 /* Access the bits. */
3249 case axs_lvalue_register:
3250 ax_reg (expr, loc->u.reg);
3253 case axs_lvalue_memory:
3254 /* Offset the pointer, if needed. */
3257 ax_const_l (expr, offset / 8);
3258 ax_simple (expr, aop_add);
3261 access_memory (arch, expr, size);
3265 /* For a bits-big-endian target, shift up what we already
3266 have. For a bits-little-endian target, shift up the
3267 new data. Note that there is a potential bug here if
3268 the DWARF expression leaves multiple values on the
3270 if (bits_collected > 0)
3272 if (bits_big_endian)
3274 ax_simple (expr, aop_swap);
3275 ax_const_l (expr, size);
3276 ax_simple (expr, aop_lsh);
3277 /* We don't need a second swap here, because
3278 aop_bit_or is symmetric. */
3282 ax_const_l (expr, size);
3283 ax_simple (expr, aop_lsh);
3285 ax_simple (expr, aop_bit_or);
3288 bits_collected += size;
3289 loc->kind = axs_rvalue;
3293 case DW_OP_GNU_uninit:
3299 struct dwarf2_locexpr_baton block;
3300 int size = (op == DW_OP_call2 ? 2 : 4);
3303 uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
3306 offset.cu_off = uoffset;
3307 block = dwarf2_fetch_die_loc_cu_off (offset, per_cu,
3310 /* DW_OP_call_ref is currently not supported. */
3311 gdb_assert (block.per_cu == per_cu);
3313 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
3314 block.data, block.data + block.size,
3319 case DW_OP_call_ref:
3327 /* Patch all the branches we emitted. */
3328 for (i = 0; i < VEC_length (int, patches); ++i)
3330 int targ = offsets[VEC_index (int, dw_labels, i)];
3332 internal_error (__FILE__, __LINE__, _("invalid label"));
3333 ax_label (expr, VEC_index (int, patches, i), targ);
3336 do_cleanups (cleanups);
3340 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3341 evaluator to calculate the location. */
3342 static struct value *
3343 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
3345 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3348 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
3349 dlbaton->size, dlbaton->per_cu);
3354 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3355 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3358 static struct value *
3359 locexpr_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
3361 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3363 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, dlbaton->data,
3367 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3369 locexpr_read_needs_frame (struct symbol *symbol)
3371 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3373 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
3377 /* Return true if DATA points to the end of a piece. END is one past
3378 the last byte in the expression. */
3381 piece_end_p (const gdb_byte *data, const gdb_byte *end)
3383 return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece;
3386 /* Helper for locexpr_describe_location_piece that finds the name of a
3390 locexpr_regname (struct gdbarch *gdbarch, int dwarf_regnum)
3394 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
3395 return gdbarch_register_name (gdbarch, regnum);
3398 /* Nicely describe a single piece of a location, returning an updated
3399 position in the bytecode sequence. This function cannot recognize
3400 all locations; if a location is not recognized, it simply returns
3401 DATA. If there is an error during reading, e.g. we run off the end
3402 of the buffer, an error is thrown. */
3404 static const gdb_byte *
3405 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
3406 CORE_ADDR addr, struct objfile *objfile,
3407 struct dwarf2_per_cu_data *per_cu,
3408 const gdb_byte *data, const gdb_byte *end,
3409 unsigned int addr_size)
3411 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3414 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
3416 fprintf_filtered (stream, _("a variable in $%s"),
3417 locexpr_regname (gdbarch, data[0] - DW_OP_reg0));
3420 else if (data[0] == DW_OP_regx)
3424 data = safe_read_uleb128 (data + 1, end, ®);
3425 fprintf_filtered (stream, _("a variable in $%s"),
3426 locexpr_regname (gdbarch, reg));
3428 else if (data[0] == DW_OP_fbreg)
3431 struct symbol *framefunc;
3433 int64_t frame_offset;
3434 const gdb_byte *base_data, *new_data, *save_data = data;
3436 int64_t base_offset = 0;
3438 new_data = safe_read_sleb128 (data + 1, end, &frame_offset);
3439 if (!piece_end_p (new_data, end))
3443 b = block_for_pc (addr);
3446 error (_("No block found for address for symbol \"%s\"."),
3447 SYMBOL_PRINT_NAME (symbol));
3449 framefunc = block_linkage_function (b);
3452 error (_("No function found for block for symbol \"%s\"."),
3453 SYMBOL_PRINT_NAME (symbol));
3455 dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
3457 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
3459 const gdb_byte *buf_end;
3461 frame_reg = base_data[0] - DW_OP_breg0;
3462 buf_end = safe_read_sleb128 (base_data + 1, base_data + base_size,
3464 if (buf_end != base_data + base_size)
3465 error (_("Unexpected opcode after "
3466 "DW_OP_breg%u for symbol \"%s\"."),
3467 frame_reg, SYMBOL_PRINT_NAME (symbol));
3469 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
3471 /* The frame base is just the register, with no offset. */
3472 frame_reg = base_data[0] - DW_OP_reg0;
3477 /* We don't know what to do with the frame base expression,
3478 so we can't trace this variable; give up. */
3482 fprintf_filtered (stream,
3483 _("a variable at frame base reg $%s offset %s+%s"),
3484 locexpr_regname (gdbarch, frame_reg),
3485 plongest (base_offset), plongest (frame_offset));
3487 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31
3488 && piece_end_p (data, end))
3492 data = safe_read_sleb128 (data + 1, end, &offset);
3494 fprintf_filtered (stream,
3495 _("a variable at offset %s from base reg $%s"),
3497 locexpr_regname (gdbarch, data[0] - DW_OP_breg0));
3500 /* The location expression for a TLS variable looks like this (on a
3503 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3504 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3506 0x3 is the encoding for DW_OP_addr, which has an operand as long
3507 as the size of an address on the target machine (here is 8
3508 bytes). Note that more recent version of GCC emit DW_OP_const4u
3509 or DW_OP_const8u, depending on address size, rather than
3510 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3511 The operand represents the offset at which the variable is within
3512 the thread local storage. */
3514 else if (data + 1 + addr_size < end
3515 && (data[0] == DW_OP_addr
3516 || (addr_size == 4 && data[0] == DW_OP_const4u)
3517 || (addr_size == 8 && data[0] == DW_OP_const8u))
3518 && data[1 + addr_size] == DW_OP_GNU_push_tls_address
3519 && piece_end_p (data + 2 + addr_size, end))
3522 offset = extract_unsigned_integer (data + 1, addr_size,
3523 gdbarch_byte_order (gdbarch));
3525 fprintf_filtered (stream,
3526 _("a thread-local variable at offset 0x%s "
3527 "in the thread-local storage for `%s'"),
3528 phex_nz (offset, addr_size), objfile_name (objfile));
3530 data += 1 + addr_size + 1;
3533 /* With -gsplit-dwarf a TLS variable can also look like this:
3534 DW_AT_location : 3 byte block: fc 4 e0
3535 (DW_OP_GNU_const_index: 4;
3536 DW_OP_GNU_push_tls_address) */
3537 else if (data + 3 <= end
3538 && data + 1 + (leb128_size = skip_leb128 (data + 1, end)) < end
3539 && data[0] == DW_OP_GNU_const_index
3541 && data[1 + leb128_size] == DW_OP_GNU_push_tls_address
3542 && piece_end_p (data + 2 + leb128_size, end))
3546 data = safe_read_uleb128 (data + 1, end, &offset);
3547 offset = dwarf2_read_addr_index (per_cu, offset);
3548 fprintf_filtered (stream,
3549 _("a thread-local variable at offset 0x%s "
3550 "in the thread-local storage for `%s'"),
3551 phex_nz (offset, addr_size), objfile_name (objfile));
3555 else if (data[0] >= DW_OP_lit0
3556 && data[0] <= DW_OP_lit31
3558 && data[1] == DW_OP_stack_value)
3560 fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0);
3567 /* Disassemble an expression, stopping at the end of a piece or at the
3568 end of the expression. Returns a pointer to the next unread byte
3569 in the input expression. If ALL is nonzero, then this function
3570 will keep going until it reaches the end of the expression.
3571 If there is an error during reading, e.g. we run off the end
3572 of the buffer, an error is thrown. */
3574 static const gdb_byte *
3575 disassemble_dwarf_expression (struct ui_file *stream,
3576 struct gdbarch *arch, unsigned int addr_size,
3577 int offset_size, const gdb_byte *start,
3578 const gdb_byte *data, const gdb_byte *end,
3579 int indent, int all,
3580 struct dwarf2_per_cu_data *per_cu)
3584 || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
3586 enum dwarf_location_atom op = *data++;
3591 name = get_DW_OP_name (op);
3594 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3595 op, (long) (data - 1 - start));
3596 fprintf_filtered (stream, " %*ld: %s", indent + 4,
3597 (long) (data - 1 - start), name);
3602 ul = extract_unsigned_integer (data, addr_size,
3603 gdbarch_byte_order (arch));
3605 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
3609 ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch));
3611 fprintf_filtered (stream, " %s", pulongest (ul));
3614 l = extract_signed_integer (data, 1, gdbarch_byte_order (arch));
3616 fprintf_filtered (stream, " %s", plongest (l));
3619 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
3621 fprintf_filtered (stream, " %s", pulongest (ul));
3624 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3626 fprintf_filtered (stream, " %s", plongest (l));
3629 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3631 fprintf_filtered (stream, " %s", pulongest (ul));
3634 l = extract_signed_integer (data, 4, gdbarch_byte_order (arch));
3636 fprintf_filtered (stream, " %s", plongest (l));
3639 ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch));
3641 fprintf_filtered (stream, " %s", pulongest (ul));
3644 l = extract_signed_integer (data, 8, gdbarch_byte_order (arch));
3646 fprintf_filtered (stream, " %s", plongest (l));
3649 data = safe_read_uleb128 (data, end, &ul);
3650 fprintf_filtered (stream, " %s", pulongest (ul));
3653 data = safe_read_sleb128 (data, end, &l);
3654 fprintf_filtered (stream, " %s", plongest (l));
3689 fprintf_filtered (stream, " [$%s]",
3690 locexpr_regname (arch, op - DW_OP_reg0));
3694 data = safe_read_uleb128 (data, end, &ul);
3695 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
3696 locexpr_regname (arch, (int) ul));
3699 case DW_OP_implicit_value:
3700 data = safe_read_uleb128 (data, end, &ul);
3702 fprintf_filtered (stream, " %s", pulongest (ul));
3737 data = safe_read_sleb128 (data, end, &l);
3738 fprintf_filtered (stream, " %s [$%s]", plongest (l),
3739 locexpr_regname (arch, op - DW_OP_breg0));
3743 data = safe_read_uleb128 (data, end, &ul);
3744 data = safe_read_sleb128 (data, end, &l);
3745 fprintf_filtered (stream, " register %s [$%s] offset %s",
3747 locexpr_regname (arch, (int) ul),
3752 data = safe_read_sleb128 (data, end, &l);
3753 fprintf_filtered (stream, " %s", plongest (l));
3756 case DW_OP_xderef_size:
3757 case DW_OP_deref_size:
3759 fprintf_filtered (stream, " %d", *data);
3763 case DW_OP_plus_uconst:
3764 data = safe_read_uleb128 (data, end, &ul);
3765 fprintf_filtered (stream, " %s", pulongest (ul));
3769 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3771 fprintf_filtered (stream, " to %ld",
3772 (long) (data + l - start));
3776 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3778 fprintf_filtered (stream, " %ld",
3779 (long) (data + l - start));
3783 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
3785 fprintf_filtered (stream, " offset %s", phex_nz (ul, 2));
3789 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3791 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
3794 case DW_OP_call_ref:
3795 ul = extract_unsigned_integer (data, offset_size,
3796 gdbarch_byte_order (arch));
3797 data += offset_size;
3798 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
3802 data = safe_read_uleb128 (data, end, &ul);
3803 fprintf_filtered (stream, " %s (bytes)", pulongest (ul));
3806 case DW_OP_bit_piece:
3810 data = safe_read_uleb128 (data, end, &ul);
3811 data = safe_read_uleb128 (data, end, &offset);
3812 fprintf_filtered (stream, " size %s offset %s (bits)",
3813 pulongest (ul), pulongest (offset));
3817 case DW_OP_GNU_implicit_pointer:
3819 ul = extract_unsigned_integer (data, offset_size,
3820 gdbarch_byte_order (arch));
3821 data += offset_size;
3823 data = safe_read_sleb128 (data, end, &l);
3825 fprintf_filtered (stream, " DIE %s offset %s",
3826 phex_nz (ul, offset_size),
3831 case DW_OP_GNU_deref_type:
3833 int addr_size = *data++;
3837 data = safe_read_uleb128 (data, end, &ul);
3839 type = dwarf2_get_die_type (offset, per_cu);
3840 fprintf_filtered (stream, "<");
3841 type_print (type, "", stream, -1);
3842 fprintf_filtered (stream, " [0x%s]> %d", phex_nz (offset.cu_off, 0),
3847 case DW_OP_GNU_const_type:
3852 data = safe_read_uleb128 (data, end, &ul);
3853 type_die.cu_off = ul;
3854 type = dwarf2_get_die_type (type_die, per_cu);
3855 fprintf_filtered (stream, "<");
3856 type_print (type, "", stream, -1);
3857 fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die.cu_off, 0));
3861 case DW_OP_GNU_regval_type:
3867 data = safe_read_uleb128 (data, end, ®);
3868 data = safe_read_uleb128 (data, end, &ul);
3869 type_die.cu_off = ul;
3871 type = dwarf2_get_die_type (type_die, per_cu);
3872 fprintf_filtered (stream, "<");
3873 type_print (type, "", stream, -1);
3874 fprintf_filtered (stream, " [0x%s]> [$%s]",
3875 phex_nz (type_die.cu_off, 0),
3876 locexpr_regname (arch, reg));
3880 case DW_OP_GNU_convert:
3881 case DW_OP_GNU_reinterpret:
3885 data = safe_read_uleb128 (data, end, &ul);
3886 type_die.cu_off = ul;
3888 if (type_die.cu_off == 0)
3889 fprintf_filtered (stream, "<0>");
3894 type = dwarf2_get_die_type (type_die, per_cu);
3895 fprintf_filtered (stream, "<");
3896 type_print (type, "", stream, -1);
3897 fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die.cu_off, 0));
3902 case DW_OP_GNU_entry_value:
3903 data = safe_read_uleb128 (data, end, &ul);
3904 fputc_filtered ('\n', stream);
3905 disassemble_dwarf_expression (stream, arch, addr_size, offset_size,
3906 start, data, data + ul, indent + 2,
3911 case DW_OP_GNU_parameter_ref:
3912 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3914 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
3917 case DW_OP_GNU_addr_index:
3918 data = safe_read_uleb128 (data, end, &ul);
3919 ul = dwarf2_read_addr_index (per_cu, ul);
3920 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
3922 case DW_OP_GNU_const_index:
3923 data = safe_read_uleb128 (data, end, &ul);
3924 ul = dwarf2_read_addr_index (per_cu, ul);
3925 fprintf_filtered (stream, " %s", pulongest (ul));
3929 fprintf_filtered (stream, "\n");
3935 /* Describe a single location, which may in turn consist of multiple
3939 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
3940 struct ui_file *stream,
3941 const gdb_byte *data, size_t size,
3942 struct objfile *objfile, unsigned int addr_size,
3943 int offset_size, struct dwarf2_per_cu_data *per_cu)
3945 const gdb_byte *end = data + size;
3946 int first_piece = 1, bad = 0;
3950 const gdb_byte *here = data;
3951 int disassemble = 1;
3956 fprintf_filtered (stream, _(", and "));
3958 if (!dwarf2_always_disassemble)
3960 data = locexpr_describe_location_piece (symbol, stream,
3961 addr, objfile, per_cu,
3962 data, end, addr_size);
3963 /* If we printed anything, or if we have an empty piece,
3964 then don't disassemble. */
3966 || data[0] == DW_OP_piece
3967 || data[0] == DW_OP_bit_piece)
3972 fprintf_filtered (stream, _("a complex DWARF expression:\n"));
3973 data = disassemble_dwarf_expression (stream,
3974 get_objfile_arch (objfile),
3975 addr_size, offset_size, data,
3977 dwarf2_always_disassemble,
3983 int empty = data == here;
3986 fprintf_filtered (stream, " ");
3987 if (data[0] == DW_OP_piece)
3991 data = safe_read_uleb128 (data + 1, end, &bytes);
3994 fprintf_filtered (stream, _("an empty %s-byte piece"),
3997 fprintf_filtered (stream, _(" [%s-byte piece]"),
4000 else if (data[0] == DW_OP_bit_piece)
4002 uint64_t bits, offset;
4004 data = safe_read_uleb128 (data + 1, end, &bits);
4005 data = safe_read_uleb128 (data, end, &offset);
4008 fprintf_filtered (stream,
4009 _("an empty %s-bit piece"),
4012 fprintf_filtered (stream,
4013 _(" [%s-bit piece, offset %s bits]"),
4014 pulongest (bits), pulongest (offset));
4024 if (bad || data > end)
4025 error (_("Corrupted DWARF2 expression for \"%s\"."),
4026 SYMBOL_PRINT_NAME (symbol));
4029 /* Print a natural-language description of SYMBOL to STREAM. This
4030 version is for a symbol with a single location. */
4033 locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
4034 struct ui_file *stream)
4036 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4037 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
4038 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
4039 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
4041 locexpr_describe_location_1 (symbol, addr, stream,
4042 dlbaton->data, dlbaton->size,
4043 objfile, addr_size, offset_size,
4047 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4048 any necessary bytecode in AX. */
4051 locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4052 struct agent_expr *ax, struct axs_value *value)
4054 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4055 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
4057 if (dlbaton->size == 0)
4058 value->optimized_out = 1;
4060 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size,
4061 dlbaton->data, dlbaton->data + dlbaton->size,
4065 /* The set of location functions used with the DWARF-2 expression
4067 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
4068 locexpr_read_variable,
4069 locexpr_read_variable_at_entry,
4070 locexpr_read_needs_frame,
4071 locexpr_describe_location,
4072 0, /* location_has_loclist */
4073 locexpr_tracepoint_var_ref
4077 /* Wrapper functions for location lists. These generally find
4078 the appropriate location expression and call something above. */
4080 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4081 evaluator to calculate the location. */
4082 static struct value *
4083 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
4085 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4087 const gdb_byte *data;
4089 CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0;
4091 data = dwarf2_find_location_expression (dlbaton, &size, pc);
4092 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
4098 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4099 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4102 Function always returns non-NULL value, it may be marked optimized out if
4103 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4104 if it cannot resolve the parameter for any reason. */
4106 static struct value *
4107 loclist_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
4109 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4110 const gdb_byte *data;
4114 if (frame == NULL || !get_frame_func_if_available (frame, &pc))
4115 return allocate_optimized_out_value (SYMBOL_TYPE (symbol));
4117 data = dwarf2_find_location_expression (dlbaton, &size, pc);
4119 return allocate_optimized_out_value (SYMBOL_TYPE (symbol));
4121 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, data, size);
4124 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
4126 loclist_read_needs_frame (struct symbol *symbol)
4128 /* If there's a location list, then assume we need to have a frame
4129 to choose the appropriate location expression. With tracking of
4130 global variables this is not necessarily true, but such tracking
4131 is disabled in GCC at the moment until we figure out how to
4137 /* Print a natural-language description of SYMBOL to STREAM. This
4138 version applies when there is a list of different locations, each
4139 with a specified address range. */
4142 loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
4143 struct ui_file *stream)
4145 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4146 const gdb_byte *loc_ptr, *buf_end;
4147 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
4148 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4149 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4150 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
4151 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
4152 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
4153 /* Adjust base_address for relocatable objects. */
4154 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
4155 CORE_ADDR base_address = dlbaton->base_address + base_offset;
4158 loc_ptr = dlbaton->data;
4159 buf_end = dlbaton->data + dlbaton->size;
4161 fprintf_filtered (stream, _("multi-location:\n"));
4163 /* Iterate through locations until we run out. */
4166 CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */
4168 enum debug_loc_kind kind;
4169 const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
4171 if (dlbaton->from_dwo)
4172 kind = decode_debug_loc_dwo_addresses (dlbaton->per_cu,
4173 loc_ptr, buf_end, &new_ptr,
4174 &low, &high, byte_order);
4176 kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
4178 byte_order, addr_size,
4183 case DEBUG_LOC_END_OF_LIST:
4186 case DEBUG_LOC_BASE_ADDRESS:
4187 base_address = high + base_offset;
4188 fprintf_filtered (stream, _(" Base address %s"),
4189 paddress (gdbarch, base_address));
4191 case DEBUG_LOC_START_END:
4192 case DEBUG_LOC_START_LENGTH:
4194 case DEBUG_LOC_BUFFER_OVERFLOW:
4195 case DEBUG_LOC_INVALID_ENTRY:
4196 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4197 SYMBOL_PRINT_NAME (symbol));
4199 gdb_assert_not_reached ("bad debug_loc_kind");
4202 /* Otherwise, a location expression entry. */
4203 low += base_address;
4204 high += base_address;
4206 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
4209 /* (It would improve readability to print only the minimum
4210 necessary digits of the second number of the range.) */
4211 fprintf_filtered (stream, _(" Range %s-%s: "),
4212 paddress (gdbarch, low), paddress (gdbarch, high));
4214 /* Now describe this particular location. */
4215 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
4216 objfile, addr_size, offset_size,
4219 fprintf_filtered (stream, "\n");
4225 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4226 any necessary bytecode in AX. */
4228 loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
4229 struct agent_expr *ax, struct axs_value *value)
4231 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
4232 const gdb_byte *data;
4234 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
4236 data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
4238 value->optimized_out = 1;
4240 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size, data, data + size,
4244 /* The set of location functions used with the DWARF-2 expression
4245 evaluator and location lists. */
4246 const struct symbol_computed_ops dwarf2_loclist_funcs = {
4247 loclist_read_variable,
4248 loclist_read_variable_at_entry,
4249 loclist_read_needs_frame,
4250 loclist_describe_location,
4251 1, /* location_has_loclist */
4252 loclist_tracepoint_var_ref
4255 /* Provide a prototype to silence -Wmissing-prototypes. */
4256 extern initialize_file_ftype _initialize_dwarf2loc;
4259 _initialize_dwarf2loc (void)
4261 add_setshow_zuinteger_cmd ("entry-values", class_maintenance,
4262 &entry_values_debug,
4263 _("Set entry values and tail call frames "
4265 _("Show entry values and tail call frames "
4267 _("When non-zero, the process of determining "
4268 "parameter values from function entry point "
4269 "and tail call frames will be printed."),
4271 show_entry_values_debug,
4272 &setdebuglist, &showdebuglist);