1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 #include "exceptions.h"
39 #include "dwarf2expr.h"
40 #include "dwarf2loc.h"
41 #include "dwarf2-frame.h"
43 #include "gdb_string.h"
44 #include "gdb_assert.h"
46 extern int dwarf2_always_disassemble;
48 static void dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
49 const gdb_byte **start, size_t *length);
51 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs;
53 static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
54 struct frame_info *frame,
57 struct dwarf2_per_cu_data *per_cu,
60 /* A function for dealing with location lists. Given a
61 symbol baton (BATON) and a pc value (PC), find the appropriate
62 location expression, set *LOCEXPR_LENGTH, and return a pointer
63 to the beginning of the expression. Returns NULL on failure.
65 For now, only return the first matching location expression; there
66 can be more than one in the list. */
69 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
70 size_t *locexpr_length, CORE_ADDR pc)
73 const gdb_byte *loc_ptr, *buf_end;
75 struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
76 struct gdbarch *gdbarch = get_objfile_arch (objfile);
77 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
78 unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
79 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
80 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
81 /* Adjust base_address for relocatable objects. */
82 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
83 CORE_ADDR base_address = baton->base_address + base_offset;
85 loc_ptr = baton->data;
86 buf_end = baton->data + baton->size;
90 if (buf_end - loc_ptr < 2 * addr_size)
91 error (_("dwarf2_find_location_expression: "
92 "Corrupted DWARF expression."));
95 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
97 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
101 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
103 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
104 loc_ptr += addr_size;
106 /* A base-address-selection entry. */
107 if ((low & base_mask) == base_mask)
109 base_address = high + base_offset;
113 /* An end-of-list entry. */
114 if (low == 0 && high == 0)
117 /* Otherwise, a location expression entry. */
119 high += base_address;
121 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
124 if (pc >= low && pc < high)
126 *locexpr_length = length;
134 /* This is the baton used when performing dwarf2 expression
136 struct dwarf_expr_baton
138 struct frame_info *frame;
139 struct dwarf2_per_cu_data *per_cu;
142 /* Helper functions for dwarf2_evaluate_loc_desc. */
144 /* Using the frame specified in BATON, return the value of register
145 REGNUM, treated as a pointer. */
147 dwarf_expr_read_reg (void *baton, int dwarf_regnum)
149 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
150 struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
154 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
155 result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
156 regnum, debaton->frame);
160 /* Read memory at ADDR (length LEN) into BUF. */
163 dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
165 read_memory (addr, buf, len);
168 /* Using the frame specified in BATON, find the location expression
169 describing the frame base. Return a pointer to it in START and
170 its length in LENGTH. */
172 dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
174 /* FIXME: cagney/2003-03-26: This code should be using
175 get_frame_base_address(), and then implement a dwarf2 specific
177 struct symbol *framefunc;
178 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
180 /* Use block_linkage_function, which returns a real (not inlined)
181 function, instead of get_frame_function, which may return an
183 framefunc = block_linkage_function (get_frame_block (debaton->frame, NULL));
185 /* If we found a frame-relative symbol then it was certainly within
186 some function associated with a frame. If we can't find the frame,
187 something has gone wrong. */
188 gdb_assert (framefunc != NULL);
190 dwarf_expr_frame_base_1 (framefunc,
191 get_frame_address_in_block (debaton->frame),
196 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
197 const gdb_byte **start, size_t *length)
199 if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
201 else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_loclist_funcs)
203 struct dwarf2_loclist_baton *symbaton;
205 symbaton = SYMBOL_LOCATION_BATON (framefunc);
206 *start = dwarf2_find_location_expression (symbaton, length, pc);
210 struct dwarf2_locexpr_baton *symbaton;
212 symbaton = SYMBOL_LOCATION_BATON (framefunc);
213 if (symbaton != NULL)
215 *length = symbaton->size;
216 *start = symbaton->data;
223 error (_("Could not find the frame base for \"%s\"."),
224 SYMBOL_NATURAL_NAME (framefunc));
227 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
228 the frame in BATON. */
231 dwarf_expr_frame_cfa (void *baton)
233 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
235 return dwarf2_frame_cfa (debaton->frame);
238 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
239 the frame in BATON. */
242 dwarf_expr_frame_pc (void *baton)
244 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
246 return get_frame_address_in_block (debaton->frame);
249 /* Using the objfile specified in BATON, find the address for the
250 current thread's thread-local storage with offset OFFSET. */
252 dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
254 struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
255 struct objfile *objfile = dwarf2_per_cu_objfile (debaton->per_cu);
257 return target_translate_tls_address (objfile, offset);
260 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
261 current CU (as is PER_CU). State of the CTX is not affected by the
265 per_cu_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset,
266 struct dwarf2_per_cu_data *per_cu,
267 CORE_ADDR (*get_frame_pc) (void *baton),
270 struct dwarf2_locexpr_baton block;
272 block = dwarf2_fetch_die_location_block (die_offset, per_cu,
273 get_frame_pc, baton);
275 /* DW_OP_call_ref is currently not supported. */
276 gdb_assert (block.per_cu == per_cu);
278 dwarf_expr_eval (ctx, block.data, block.size);
281 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
284 dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
286 struct dwarf_expr_baton *debaton = ctx->baton;
288 per_cu_dwarf_call (ctx, die_offset, debaton->per_cu,
289 ctx->funcs->get_frame_pc, ctx->baton);
292 /* Callback function for dwarf2_evaluate_loc_desc. */
295 dwarf_expr_get_base_type (struct dwarf_expr_context *ctx, size_t die_offset)
297 struct dwarf_expr_baton *debaton = ctx->baton;
299 return dwarf2_get_die_type (die_offset, debaton->per_cu);
302 /* See dwarf2loc.h. */
304 int entry_values_debug = 0;
306 /* Helper to set entry_values_debug. */
309 show_entry_values_debug (struct ui_file *file, int from_tty,
310 struct cmd_list_element *c, const char *value)
312 fprintf_filtered (file,
313 _("Entry values and tail call frames debugging is %s.\n"),
317 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
318 CALLER_FRAME (for registers) can be NULL if it is not known. This function
319 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
322 call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
323 struct call_site *call_site,
324 struct frame_info *caller_frame)
326 switch (FIELD_LOC_KIND (call_site->target))
328 case FIELD_LOC_KIND_DWARF_BLOCK:
330 struct dwarf2_locexpr_baton *dwarf_block;
332 struct type *caller_core_addr_type;
333 struct gdbarch *caller_arch;
335 dwarf_block = FIELD_DWARF_BLOCK (call_site->target);
336 if (dwarf_block == NULL)
338 struct minimal_symbol *msym;
340 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
341 throw_error (NO_ENTRY_VALUE_ERROR,
342 _("DW_AT_GNU_call_site_target is not specified "
344 paddress (call_site_gdbarch, call_site->pc),
345 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
348 if (caller_frame == NULL)
350 struct minimal_symbol *msym;
352 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
353 throw_error (NO_ENTRY_VALUE_ERROR,
354 _("DW_AT_GNU_call_site_target DWARF block resolving "
355 "requires known frame which is currently not "
356 "available at %s in %s"),
357 paddress (call_site_gdbarch, call_site->pc),
358 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
361 caller_arch = get_frame_arch (caller_frame);
362 caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr;
363 val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame,
364 dwarf_block->data, dwarf_block->size,
365 dwarf_block->per_cu);
366 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
368 if (VALUE_LVAL (val) == lval_memory)
369 return value_address (val);
371 return value_as_address (val);
374 case FIELD_LOC_KIND_PHYSNAME:
376 const char *physname;
377 struct minimal_symbol *msym;
379 physname = FIELD_STATIC_PHYSNAME (call_site->target);
380 msym = lookup_minimal_symbol_text (physname, NULL);
383 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
384 throw_error (NO_ENTRY_VALUE_ERROR,
385 _("Cannot find function \"%s\" for a call site target "
387 physname, paddress (call_site_gdbarch, call_site->pc),
388 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
391 return SYMBOL_VALUE_ADDRESS (msym);
394 case FIELD_LOC_KIND_PHYSADDR:
395 return FIELD_STATIC_PHYSADDR (call_site->target);
398 internal_error (__FILE__, __LINE__, _("invalid call site target kind"));
402 /* Convert function entry point exact address ADDR to the function which is
403 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
404 NO_ENTRY_VALUE_ERROR otherwise. */
406 static struct symbol *
407 func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
409 struct symbol *sym = find_pc_function (addr);
412 if (sym == NULL || BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) != addr)
413 throw_error (NO_ENTRY_VALUE_ERROR,
414 _("DW_TAG_GNU_call_site resolving failed to find function "
415 "name for address %s"),
416 paddress (gdbarch, addr));
418 type = SYMBOL_TYPE (sym);
419 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC);
420 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
425 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
426 ENTRY_VALUES_DEBUG. */
429 tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
431 CORE_ADDR addr = call_site->pc;
432 struct minimal_symbol *msym = lookup_minimal_symbol_by_pc (addr - 1);
434 fprintf_unfiltered (gdb_stdlog, " %s(%s)", paddress (gdbarch, addr),
435 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
439 /* vec.h needs single word type name, typedef it. */
440 typedef struct call_site *call_sitep;
442 /* Define VEC (call_sitep) functions. */
443 DEF_VEC_P (call_sitep);
445 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
446 only top callers and bottom callees which are present in both. GDBARCH is
447 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
448 no remaining possibilities to provide unambiguous non-trivial result.
449 RESULTP should point to NULL on the first (initialization) call. Caller is
450 responsible for xfree of any RESULTP data. */
453 chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
454 VEC (call_sitep) *chain)
456 struct call_site_chain *result = *resultp;
457 long length = VEC_length (call_sitep, chain);
458 int callers, callees, idx;
462 /* Create the initial chain containing all the passed PCs. */
464 result = xmalloc (sizeof (*result) + sizeof (*result->call_site)
466 result->length = length;
467 result->callers = result->callees = length;
468 memcpy (result->call_site, VEC_address (call_sitep, chain),
469 sizeof (*result->call_site) * length);
472 if (entry_values_debug)
474 fprintf_unfiltered (gdb_stdlog, "tailcall: initial:");
475 for (idx = 0; idx < length; idx++)
476 tailcall_dump (gdbarch, result->call_site[idx]);
477 fputc_unfiltered ('\n', gdb_stdlog);
483 if (entry_values_debug)
485 fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
486 for (idx = 0; idx < length; idx++)
487 tailcall_dump (gdbarch, VEC_index (call_sitep, chain, idx));
488 fputc_unfiltered ('\n', gdb_stdlog);
491 /* Intersect callers. */
493 callers = min (result->callers, length);
494 for (idx = 0; idx < callers; idx++)
495 if (result->call_site[idx] != VEC_index (call_sitep, chain, idx))
497 result->callers = idx;
501 /* Intersect callees. */
503 callees = min (result->callees, length);
504 for (idx = 0; idx < callees; idx++)
505 if (result->call_site[result->length - 1 - idx]
506 != VEC_index (call_sitep, chain, length - 1 - idx))
508 result->callees = idx;
512 if (entry_values_debug)
514 fprintf_unfiltered (gdb_stdlog, "tailcall: reduced:");
515 for (idx = 0; idx < result->callers; idx++)
516 tailcall_dump (gdbarch, result->call_site[idx]);
517 fputs_unfiltered (" |", gdb_stdlog);
518 for (idx = 0; idx < result->callees; idx++)
519 tailcall_dump (gdbarch, result->call_site[result->length
520 - result->callees + idx]);
521 fputc_unfiltered ('\n', gdb_stdlog);
524 if (result->callers == 0 && result->callees == 0)
526 /* There are no common callers or callees. It could be also a direct
527 call (which has length 0) with ambiguous possibility of an indirect
528 call - CALLERS == CALLEES == 0 is valid during the first allocation
529 but any subsequence processing of such entry means ambiguity. */
535 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
536 PC again. In such case there must be two different code paths to reach
537 it, therefore some of the former determined intermediate PCs must differ
538 and the unambiguous chain gets shortened. */
539 gdb_assert (result->callers + result->callees < result->length);
542 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
543 assumed frames between them use GDBARCH. Use depth first search so we can
544 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
545 would have needless GDB stack overhead. Caller is responsible for xfree of
546 the returned result. Any unreliability results in thrown
547 NO_ENTRY_VALUE_ERROR. */
549 static struct call_site_chain *
550 call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
553 struct func_type *func_specific;
554 struct obstack addr_obstack;
555 struct cleanup *back_to_retval, *back_to_workdata;
556 struct call_site_chain *retval = NULL;
557 struct call_site *call_site;
559 /* Mark CALL_SITEs so we do not visit the same ones twice. */
562 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
563 call_site nor any possible call_site at CALLEE_PC's function is there.
564 Any CALL_SITE in CHAIN will be iterated to its siblings - via
565 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
566 VEC (call_sitep) *chain = NULL;
568 /* We are not interested in the specific PC inside the callee function. */
569 callee_pc = get_pc_function_start (callee_pc);
571 throw_error (NO_ENTRY_VALUE_ERROR, _("Unable to find function for PC %s"),
572 paddress (gdbarch, callee_pc));
574 back_to_retval = make_cleanup (free_current_contents, &retval);
576 obstack_init (&addr_obstack);
577 back_to_workdata = make_cleanup_obstack_free (&addr_obstack);
578 addr_hash = htab_create_alloc_ex (64, core_addr_hash, core_addr_eq, NULL,
579 &addr_obstack, hashtab_obstack_allocate,
581 make_cleanup_htab_delete (addr_hash);
583 make_cleanup (VEC_cleanup (call_sitep), &chain);
585 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
586 at the target's function. All the possible tail call sites in the
587 target's function will get iterated as already pushed into CHAIN via their
589 call_site = call_site_for_pc (gdbarch, caller_pc);
593 CORE_ADDR target_func_addr;
594 struct call_site *target_call_site;
596 /* CALLER_FRAME with registers is not available for tail-call jumped
598 target_func_addr = call_site_to_target_addr (gdbarch, call_site, NULL);
600 if (target_func_addr == callee_pc)
602 chain_candidate (gdbarch, &retval, chain);
606 /* There is no way to reach CALLEE_PC again as we would prevent
607 entering it twice as being already marked in ADDR_HASH. */
608 target_call_site = NULL;
612 struct symbol *target_func;
614 target_func = func_addr_to_tail_call_list (gdbarch, target_func_addr);
615 target_call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func));
620 /* Attempt to visit TARGET_CALL_SITE. */
622 if (target_call_site)
626 slot = htab_find_slot (addr_hash, &target_call_site->pc, INSERT);
629 /* Successfully entered TARGET_CALL_SITE. */
631 *slot = &target_call_site->pc;
632 VEC_safe_push (call_sitep, chain, target_call_site);
637 /* Backtrack (without revisiting the originating call_site). Try the
638 callers's sibling; if there isn't any try the callers's callers's
641 target_call_site = NULL;
642 while (!VEC_empty (call_sitep, chain))
644 call_site = VEC_pop (call_sitep, chain);
646 gdb_assert (htab_find_slot (addr_hash, &call_site->pc,
648 htab_remove_elt (addr_hash, &call_site->pc);
650 target_call_site = call_site->tail_call_next;
651 if (target_call_site)
655 while (target_call_site);
657 if (VEC_empty (call_sitep, chain))
660 call_site = VEC_last (call_sitep, chain);
665 struct minimal_symbol *msym_caller, *msym_callee;
667 msym_caller = lookup_minimal_symbol_by_pc (caller_pc);
668 msym_callee = lookup_minimal_symbol_by_pc (callee_pc);
669 throw_error (NO_ENTRY_VALUE_ERROR,
670 _("There are no unambiguously determinable intermediate "
671 "callers or callees between caller function \"%s\" at %s "
672 "and callee function \"%s\" at %s"),
674 ? "???" : SYMBOL_PRINT_NAME (msym_caller)),
675 paddress (gdbarch, caller_pc),
677 ? "???" : SYMBOL_PRINT_NAME (msym_callee)),
678 paddress (gdbarch, callee_pc));
681 do_cleanups (back_to_workdata);
682 discard_cleanups (back_to_retval);
686 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
687 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
688 constructed return NULL. Caller is responsible for xfree of the returned
691 struct call_site_chain *
692 call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
695 volatile struct gdb_exception e;
696 struct call_site_chain *retval = NULL;
698 TRY_CATCH (e, RETURN_MASK_ERROR)
700 retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc);
704 if (e.error == NO_ENTRY_VALUE_ERROR)
706 if (entry_values_debug)
707 exception_print (gdb_stdout, e);
717 /* Fetch call_site_parameter from caller matching the parameters. FRAME is for
718 callee. See DWARF_REG and FB_OFFSET description at struct
719 dwarf_expr_context_funcs->push_dwarf_reg_entry_value.
721 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
724 static struct call_site_parameter *
725 dwarf_expr_reg_to_entry_parameter (struct frame_info *frame, int dwarf_reg,
727 struct dwarf2_per_cu_data **per_cu_return)
729 CORE_ADDR func_addr = get_frame_func (frame);
731 struct gdbarch *gdbarch = get_frame_arch (frame);
732 struct frame_info *caller_frame = get_prev_frame (frame);
733 struct call_site *call_site;
736 struct dwarf2_locexpr_baton *dwarf_block;
737 struct call_site_parameter *parameter;
738 CORE_ADDR target_addr;
740 if (gdbarch != frame_unwind_arch (frame))
742 struct minimal_symbol *msym = lookup_minimal_symbol_by_pc (func_addr);
743 struct gdbarch *caller_gdbarch = frame_unwind_arch (frame);
745 throw_error (NO_ENTRY_VALUE_ERROR,
746 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
747 "(of %s (%s)) does not match caller gdbarch %s"),
748 gdbarch_bfd_arch_info (gdbarch)->printable_name,
749 paddress (gdbarch, func_addr),
750 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym),
751 gdbarch_bfd_arch_info (caller_gdbarch)->printable_name);
754 if (caller_frame == NULL)
756 struct minimal_symbol *msym = lookup_minimal_symbol_by_pc (func_addr);
758 throw_error (NO_ENTRY_VALUE_ERROR, _("DW_OP_GNU_entry_value resolving "
759 "requires caller of %s (%s)"),
760 paddress (gdbarch, func_addr),
761 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
763 caller_pc = get_frame_pc (caller_frame);
764 call_site = call_site_for_pc (gdbarch, caller_pc);
766 target_addr = call_site_to_target_addr (gdbarch, call_site, caller_frame);
767 if (target_addr != func_addr)
769 struct minimal_symbol *target_msym, *func_msym;
771 target_msym = lookup_minimal_symbol_by_pc (target_addr);
772 func_msym = lookup_minimal_symbol_by_pc (func_addr);
773 throw_error (NO_ENTRY_VALUE_ERROR,
774 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
775 "but the called frame is for %s at %s"),
776 (target_msym == NULL ? "???"
777 : SYMBOL_PRINT_NAME (target_msym)),
778 paddress (gdbarch, target_addr),
779 func_msym == NULL ? "???" : SYMBOL_PRINT_NAME (func_msym),
780 paddress (gdbarch, func_addr));
783 for (iparams = 0; iparams < call_site->parameter_count; iparams++)
785 parameter = &call_site->parameter[iparams];
786 if (parameter->dwarf_reg == -1 && dwarf_reg == -1)
788 if (parameter->fb_offset == fb_offset)
791 else if (parameter->dwarf_reg == dwarf_reg)
794 if (iparams == call_site->parameter_count)
796 struct minimal_symbol *msym = lookup_minimal_symbol_by_pc (caller_pc);
798 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
799 determine its value. */
800 throw_error (NO_ENTRY_VALUE_ERROR, _("Cannot find matching parameter "
801 "at DW_TAG_GNU_call_site %s at %s"),
802 paddress (gdbarch, caller_pc),
803 msym == NULL ? "???" : SYMBOL_PRINT_NAME (msym));
806 *per_cu_return = call_site->per_cu;
810 /* Execute call_site_parameter's DWARF block for caller of the CTX's frame.
811 CTX must be of dwarf_expr_ctx_funcs kind. See DWARF_REG and FB_OFFSET
812 description at struct dwarf_expr_context_funcs->push_dwarf_reg_entry_value.
814 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
815 can be more simple as it does not support cross-CU DWARF executions. */
818 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
819 int dwarf_reg, CORE_ADDR fb_offset)
821 struct dwarf_expr_baton *debaton;
822 struct frame_info *frame, *caller_frame;
823 struct dwarf2_per_cu_data *caller_per_cu;
824 struct dwarf_expr_baton baton_local;
825 struct dwarf_expr_context saved_ctx;
826 struct call_site_parameter *parameter;
827 const gdb_byte *data_src;
830 gdb_assert (ctx->funcs == &dwarf_expr_ctx_funcs);
831 debaton = ctx->baton;
832 frame = debaton->frame;
833 caller_frame = get_prev_frame (frame);
835 parameter = dwarf_expr_reg_to_entry_parameter (frame, dwarf_reg, fb_offset,
837 data_src = parameter->value;
838 size = parameter->value_size;
840 baton_local.frame = caller_frame;
841 baton_local.per_cu = caller_per_cu;
843 saved_ctx.gdbarch = ctx->gdbarch;
844 saved_ctx.addr_size = ctx->addr_size;
845 saved_ctx.offset = ctx->offset;
846 saved_ctx.baton = ctx->baton;
847 ctx->gdbarch = get_objfile_arch (dwarf2_per_cu_objfile (baton_local.per_cu));
848 ctx->addr_size = dwarf2_per_cu_addr_size (baton_local.per_cu);
849 ctx->offset = dwarf2_per_cu_text_offset (baton_local.per_cu);
850 ctx->baton = &baton_local;
852 dwarf_expr_eval (ctx, data_src, size);
854 ctx->gdbarch = saved_ctx.gdbarch;
855 ctx->addr_size = saved_ctx.addr_size;
856 ctx->offset = saved_ctx.offset;
857 ctx->baton = saved_ctx.baton;
862 /* Reference count. */
865 /* The CU from which this closure's expression came. */
866 struct dwarf2_per_cu_data *per_cu;
868 /* The number of pieces used to describe this variable. */
871 /* The target address size, used only for DWARF_VALUE_STACK. */
874 /* The pieces themselves. */
875 struct dwarf_expr_piece *pieces;
878 /* Allocate a closure for a value formed from separately-described
881 static struct piece_closure *
882 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
883 int n_pieces, struct dwarf_expr_piece *pieces,
886 struct piece_closure *c = XZALLOC (struct piece_closure);
891 c->n_pieces = n_pieces;
892 c->addr_size = addr_size;
893 c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
895 memcpy (c->pieces, pieces, n_pieces * sizeof (struct dwarf_expr_piece));
896 for (i = 0; i < n_pieces; ++i)
897 if (c->pieces[i].location == DWARF_VALUE_STACK)
898 value_incref (c->pieces[i].v.value);
903 /* The lowest-level function to extract bits from a byte buffer.
904 SOURCE is the buffer. It is updated if we read to the end of a
906 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
907 updated to reflect the number of bits actually read.
908 NBITS is the number of bits we want to read. It is updated to
909 reflect the number of bits actually read. This function may read
911 BITS_BIG_ENDIAN is taken directly from gdbarch.
912 This function returns the extracted bits. */
915 extract_bits_primitive (const gdb_byte **source,
916 unsigned int *source_offset_bits,
917 int *nbits, int bits_big_endian)
919 unsigned int avail, mask, datum;
921 gdb_assert (*source_offset_bits < 8);
923 avail = 8 - *source_offset_bits;
927 mask = (1 << avail) - 1;
930 datum >>= 8 - (*source_offset_bits + *nbits);
932 datum >>= *source_offset_bits;
936 *source_offset_bits += avail;
937 if (*source_offset_bits >= 8)
939 *source_offset_bits -= 8;
946 /* Extract some bits from a source buffer and move forward in the
949 SOURCE is the source buffer. It is updated as bytes are read.
950 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
952 NBITS is the number of bits to read.
953 BITS_BIG_ENDIAN is taken directly from gdbarch.
955 This function returns the bits that were read. */
958 extract_bits (const gdb_byte **source, unsigned int *source_offset_bits,
959 int nbits, int bits_big_endian)
963 gdb_assert (nbits > 0 && nbits <= 8);
965 datum = extract_bits_primitive (source, source_offset_bits, &nbits,
971 more = extract_bits_primitive (source, source_offset_bits, &nbits,
983 /* Write some bits into a buffer and move forward in the buffer.
985 DATUM is the bits to write. The low-order bits of DATUM are used.
986 DEST is the destination buffer. It is updated as bytes are
988 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
990 NBITS is the number of valid bits in DATUM.
991 BITS_BIG_ENDIAN is taken directly from gdbarch. */
994 insert_bits (unsigned int datum,
995 gdb_byte *dest, unsigned int dest_offset_bits,
996 int nbits, int bits_big_endian)
1000 gdb_assert (dest_offset_bits + nbits <= 8);
1002 mask = (1 << nbits) - 1;
1003 if (bits_big_endian)
1005 datum <<= 8 - (dest_offset_bits + nbits);
1006 mask <<= 8 - (dest_offset_bits + nbits);
1010 datum <<= dest_offset_bits;
1011 mask <<= dest_offset_bits;
1014 gdb_assert ((datum & ~mask) == 0);
1016 *dest = (*dest & ~mask) | datum;
1019 /* Copy bits from a source to a destination.
1021 DEST is where the bits should be written.
1022 DEST_OFFSET_BITS is the bit offset into DEST.
1023 SOURCE is the source of bits.
1024 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1025 BIT_COUNT is the number of bits to copy.
1026 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1029 copy_bitwise (gdb_byte *dest, unsigned int dest_offset_bits,
1030 const gdb_byte *source, unsigned int source_offset_bits,
1031 unsigned int bit_count,
1032 int bits_big_endian)
1034 unsigned int dest_avail;
1037 /* Reduce everything to byte-size pieces. */
1038 dest += dest_offset_bits / 8;
1039 dest_offset_bits %= 8;
1040 source += source_offset_bits / 8;
1041 source_offset_bits %= 8;
1043 dest_avail = 8 - dest_offset_bits % 8;
1045 /* See if we can fill the first destination byte. */
1046 if (dest_avail < bit_count)
1048 datum = extract_bits (&source, &source_offset_bits, dest_avail,
1050 insert_bits (datum, dest, dest_offset_bits, dest_avail, bits_big_endian);
1052 dest_offset_bits = 0;
1053 bit_count -= dest_avail;
1056 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1057 than 8 bits remaining. */
1058 gdb_assert (dest_offset_bits % 8 == 0 || bit_count < 8);
1059 for (; bit_count >= 8; bit_count -= 8)
1061 datum = extract_bits (&source, &source_offset_bits, 8, bits_big_endian);
1062 *dest++ = (gdb_byte) datum;
1065 /* Finally, we may have a few leftover bits. */
1066 gdb_assert (bit_count <= 8 - dest_offset_bits % 8);
1069 datum = extract_bits (&source, &source_offset_bits, bit_count,
1071 insert_bits (datum, dest, dest_offset_bits, bit_count, bits_big_endian);
1076 read_pieced_value (struct value *v)
1080 ULONGEST bits_to_skip;
1082 struct piece_closure *c
1083 = (struct piece_closure *) value_computed_closure (v);
1084 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (v));
1086 size_t buffer_size = 0;
1087 char *buffer = NULL;
1088 struct cleanup *cleanup;
1090 = gdbarch_bits_big_endian (get_type_arch (value_type (v)));
1092 if (value_type (v) != value_enclosing_type (v))
1093 internal_error (__FILE__, __LINE__,
1094 _("Should not be able to create a lazy value with "
1095 "an enclosing type"));
1097 cleanup = make_cleanup (free_current_contents, &buffer);
1099 contents = value_contents_raw (v);
1100 bits_to_skip = 8 * value_offset (v);
1101 if (value_bitsize (v))
1103 bits_to_skip += value_bitpos (v);
1104 type_len = value_bitsize (v);
1107 type_len = 8 * TYPE_LENGTH (value_type (v));
1109 for (i = 0; i < c->n_pieces && offset < type_len; i++)
1111 struct dwarf_expr_piece *p = &c->pieces[i];
1112 size_t this_size, this_size_bits;
1113 long dest_offset_bits, source_offset_bits, source_offset;
1114 const gdb_byte *intermediate_buffer;
1116 /* Compute size, source, and destination offsets for copying, in
1118 this_size_bits = p->size;
1119 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
1121 bits_to_skip -= this_size_bits;
1124 if (this_size_bits > type_len - offset)
1125 this_size_bits = type_len - offset;
1126 if (bits_to_skip > 0)
1128 dest_offset_bits = 0;
1129 source_offset_bits = bits_to_skip;
1130 this_size_bits -= bits_to_skip;
1135 dest_offset_bits = offset;
1136 source_offset_bits = 0;
1139 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
1140 source_offset = source_offset_bits / 8;
1141 if (buffer_size < this_size)
1143 buffer_size = this_size;
1144 buffer = xrealloc (buffer, buffer_size);
1146 intermediate_buffer = buffer;
1148 /* Copy from the source to DEST_BUFFER. */
1149 switch (p->location)
1151 case DWARF_VALUE_REGISTER:
1153 struct gdbarch *arch = get_frame_arch (frame);
1154 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.regno);
1155 int reg_offset = source_offset;
1157 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
1158 && this_size < register_size (arch, gdb_regnum))
1160 /* Big-endian, and we want less than full size. */
1161 reg_offset = register_size (arch, gdb_regnum) - this_size;
1162 /* We want the lower-order THIS_SIZE_BITS of the bytes
1163 we extract from the register. */
1164 source_offset_bits += 8 * this_size - this_size_bits;
1167 if (gdb_regnum != -1)
1171 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
1175 /* Just so garbage doesn't ever shine through. */
1176 memset (buffer, 0, this_size);
1179 set_value_optimized_out (v, 1);
1181 mark_value_bytes_unavailable (v, offset, this_size);
1186 error (_("Unable to access DWARF register number %s"),
1187 paddress (arch, p->v.regno));
1192 case DWARF_VALUE_MEMORY:
1193 read_value_memory (v, offset,
1194 p->v.mem.in_stack_memory,
1195 p->v.mem.addr + source_offset,
1199 case DWARF_VALUE_STACK:
1201 size_t n = this_size;
1203 if (n > c->addr_size - source_offset)
1204 n = (c->addr_size >= source_offset
1205 ? c->addr_size - source_offset
1213 const gdb_byte *val_bytes = value_contents_all (p->v.value);
1215 intermediate_buffer = val_bytes + source_offset;
1220 case DWARF_VALUE_LITERAL:
1222 size_t n = this_size;
1224 if (n > p->v.literal.length - source_offset)
1225 n = (p->v.literal.length >= source_offset
1226 ? p->v.literal.length - source_offset
1229 intermediate_buffer = p->v.literal.data + source_offset;
1233 /* These bits show up as zeros -- but do not cause the value
1234 to be considered optimized-out. */
1235 case DWARF_VALUE_IMPLICIT_POINTER:
1238 case DWARF_VALUE_OPTIMIZED_OUT:
1239 set_value_optimized_out (v, 1);
1243 internal_error (__FILE__, __LINE__, _("invalid location type"));
1246 if (p->location != DWARF_VALUE_OPTIMIZED_OUT
1247 && p->location != DWARF_VALUE_IMPLICIT_POINTER)
1248 copy_bitwise (contents, dest_offset_bits,
1249 intermediate_buffer, source_offset_bits % 8,
1250 this_size_bits, bits_big_endian);
1252 offset += this_size_bits;
1255 do_cleanups (cleanup);
1259 write_pieced_value (struct value *to, struct value *from)
1263 ULONGEST bits_to_skip;
1264 const gdb_byte *contents;
1265 struct piece_closure *c
1266 = (struct piece_closure *) value_computed_closure (to);
1267 struct frame_info *frame = frame_find_by_id (VALUE_FRAME_ID (to));
1269 size_t buffer_size = 0;
1270 char *buffer = NULL;
1271 struct cleanup *cleanup;
1273 = gdbarch_bits_big_endian (get_type_arch (value_type (to)));
1277 set_value_optimized_out (to, 1);
1281 cleanup = make_cleanup (free_current_contents, &buffer);
1283 contents = value_contents (from);
1284 bits_to_skip = 8 * value_offset (to);
1285 if (value_bitsize (to))
1287 bits_to_skip += value_bitpos (to);
1288 type_len = value_bitsize (to);
1291 type_len = 8 * TYPE_LENGTH (value_type (to));
1293 for (i = 0; i < c->n_pieces && offset < type_len; i++)
1295 struct dwarf_expr_piece *p = &c->pieces[i];
1296 size_t this_size_bits, this_size;
1297 long dest_offset_bits, source_offset_bits, dest_offset, source_offset;
1299 const gdb_byte *source_buffer;
1301 this_size_bits = p->size;
1302 if (bits_to_skip > 0 && bits_to_skip >= this_size_bits)
1304 bits_to_skip -= this_size_bits;
1307 if (this_size_bits > type_len - offset)
1308 this_size_bits = type_len - offset;
1309 if (bits_to_skip > 0)
1311 dest_offset_bits = bits_to_skip;
1312 source_offset_bits = 0;
1313 this_size_bits -= bits_to_skip;
1318 dest_offset_bits = 0;
1319 source_offset_bits = offset;
1322 this_size = (this_size_bits + source_offset_bits % 8 + 7) / 8;
1323 source_offset = source_offset_bits / 8;
1324 dest_offset = dest_offset_bits / 8;
1325 if (dest_offset_bits % 8 == 0 && source_offset_bits % 8 == 0)
1327 source_buffer = contents + source_offset;
1332 if (buffer_size < this_size)
1334 buffer_size = this_size;
1335 buffer = xrealloc (buffer, buffer_size);
1337 source_buffer = buffer;
1341 switch (p->location)
1343 case DWARF_VALUE_REGISTER:
1345 struct gdbarch *arch = get_frame_arch (frame);
1346 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, p->v.regno);
1347 int reg_offset = dest_offset;
1349 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
1350 && this_size <= register_size (arch, gdb_regnum))
1351 /* Big-endian, and we want less than full size. */
1352 reg_offset = register_size (arch, gdb_regnum) - this_size;
1354 if (gdb_regnum != -1)
1360 if (!get_frame_register_bytes (frame, gdb_regnum, reg_offset,
1365 error (_("Can't do read-modify-write to "
1366 "update bitfield; containing word has been "
1369 throw_error (NOT_AVAILABLE_ERROR,
1370 _("Can't do read-modify-write to update "
1371 "bitfield; containing word "
1374 copy_bitwise (buffer, dest_offset_bits,
1375 contents, source_offset_bits,
1380 put_frame_register_bytes (frame, gdb_regnum, reg_offset,
1381 this_size, source_buffer);
1385 error (_("Unable to write to DWARF register number %s"),
1386 paddress (arch, p->v.regno));
1390 case DWARF_VALUE_MEMORY:
1393 /* Only the first and last bytes can possibly have any
1395 read_memory (p->v.mem.addr + dest_offset, buffer, 1);
1396 read_memory (p->v.mem.addr + dest_offset + this_size - 1,
1397 buffer + this_size - 1, 1);
1398 copy_bitwise (buffer, dest_offset_bits,
1399 contents, source_offset_bits,
1404 write_memory (p->v.mem.addr + dest_offset,
1405 source_buffer, this_size);
1408 set_value_optimized_out (to, 1);
1411 offset += this_size_bits;
1414 do_cleanups (cleanup);
1417 /* A helper function that checks bit validity in a pieced value.
1418 CHECK_FOR indicates the kind of validity checking.
1419 DWARF_VALUE_MEMORY means to check whether any bit is valid.
1420 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
1422 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
1423 implicit pointer. */
1426 check_pieced_value_bits (const struct value *value, int bit_offset,
1428 enum dwarf_value_location check_for)
1430 struct piece_closure *c
1431 = (struct piece_closure *) value_computed_closure (value);
1433 int validity = (check_for == DWARF_VALUE_MEMORY
1434 || check_for == DWARF_VALUE_IMPLICIT_POINTER);
1436 bit_offset += 8 * value_offset (value);
1437 if (value_bitsize (value))
1438 bit_offset += value_bitpos (value);
1440 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
1442 struct dwarf_expr_piece *p = &c->pieces[i];
1443 size_t this_size_bits = p->size;
1447 if (bit_offset >= this_size_bits)
1449 bit_offset -= this_size_bits;
1453 bit_length -= this_size_bits - bit_offset;
1457 bit_length -= this_size_bits;
1459 if (check_for == DWARF_VALUE_IMPLICIT_POINTER)
1461 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
1464 else if (p->location == DWARF_VALUE_OPTIMIZED_OUT
1465 || p->location == DWARF_VALUE_IMPLICIT_POINTER)
1481 check_pieced_value_validity (const struct value *value, int bit_offset,
1484 return check_pieced_value_bits (value, bit_offset, bit_length,
1485 DWARF_VALUE_MEMORY);
1489 check_pieced_value_invalid (const struct value *value)
1491 return check_pieced_value_bits (value, 0,
1492 8 * TYPE_LENGTH (value_type (value)),
1493 DWARF_VALUE_OPTIMIZED_OUT);
1496 /* An implementation of an lval_funcs method to see whether a value is
1497 a synthetic pointer. */
1500 check_pieced_synthetic_pointer (const struct value *value, int bit_offset,
1503 return check_pieced_value_bits (value, bit_offset, bit_length,
1504 DWARF_VALUE_IMPLICIT_POINTER);
1507 /* A wrapper function for get_frame_address_in_block. */
1510 get_frame_address_in_block_wrapper (void *baton)
1512 return get_frame_address_in_block (baton);
1515 /* An implementation of an lval_funcs method to indirect through a
1516 pointer. This handles the synthetic pointer case when needed. */
1518 static struct value *
1519 indirect_pieced_value (struct value *value)
1521 struct piece_closure *c
1522 = (struct piece_closure *) value_computed_closure (value);
1524 struct frame_info *frame;
1525 struct dwarf2_locexpr_baton baton;
1526 int i, bit_offset, bit_length;
1527 struct dwarf_expr_piece *piece = NULL;
1528 LONGEST byte_offset;
1530 type = check_typedef (value_type (value));
1531 if (TYPE_CODE (type) != TYPE_CODE_PTR)
1534 bit_length = 8 * TYPE_LENGTH (type);
1535 bit_offset = 8 * value_offset (value);
1536 if (value_bitsize (value))
1537 bit_offset += value_bitpos (value);
1539 for (i = 0; i < c->n_pieces && bit_length > 0; i++)
1541 struct dwarf_expr_piece *p = &c->pieces[i];
1542 size_t this_size_bits = p->size;
1546 if (bit_offset >= this_size_bits)
1548 bit_offset -= this_size_bits;
1552 bit_length -= this_size_bits - bit_offset;
1556 bit_length -= this_size_bits;
1558 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
1561 if (bit_length != 0)
1562 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
1568 frame = get_selected_frame (_("No frame selected."));
1570 /* This is an offset requested by GDB, such as value subcripts. */
1571 byte_offset = value_as_address (value);
1574 baton = dwarf2_fetch_die_location_block (piece->v.ptr.die, c->per_cu,
1575 get_frame_address_in_block_wrapper,
1578 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
1579 baton.data, baton.size, baton.per_cu,
1580 piece->v.ptr.offset + byte_offset);
1584 copy_pieced_value_closure (const struct value *v)
1586 struct piece_closure *c
1587 = (struct piece_closure *) value_computed_closure (v);
1594 free_pieced_value_closure (struct value *v)
1596 struct piece_closure *c
1597 = (struct piece_closure *) value_computed_closure (v);
1604 for (i = 0; i < c->n_pieces; ++i)
1605 if (c->pieces[i].location == DWARF_VALUE_STACK)
1606 value_free (c->pieces[i].v.value);
1613 /* Functions for accessing a variable described by DW_OP_piece. */
1614 static const struct lval_funcs pieced_value_funcs = {
1617 check_pieced_value_validity,
1618 check_pieced_value_invalid,
1619 indirect_pieced_value,
1620 check_pieced_synthetic_pointer,
1621 copy_pieced_value_closure,
1622 free_pieced_value_closure
1625 /* Helper function which throws an error if a synthetic pointer is
1629 invalid_synthetic_pointer (void)
1631 error (_("access outside bounds of object "
1632 "referenced via synthetic pointer"));
1635 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
1637 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs =
1639 dwarf_expr_read_reg,
1640 dwarf_expr_read_mem,
1641 dwarf_expr_frame_base,
1642 dwarf_expr_frame_cfa,
1643 dwarf_expr_frame_pc,
1644 dwarf_expr_tls_address,
1645 dwarf_expr_dwarf_call,
1646 dwarf_expr_get_base_type,
1647 dwarf_expr_push_dwarf_reg_entry_value
1650 /* Evaluate a location description, starting at DATA and with length
1651 SIZE, to find the current location of variable of TYPE in the
1652 context of FRAME. BYTE_OFFSET is applied after the contents are
1655 static struct value *
1656 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
1657 const gdb_byte *data, unsigned short size,
1658 struct dwarf2_per_cu_data *per_cu,
1659 LONGEST byte_offset)
1661 struct value *retval;
1662 struct dwarf_expr_baton baton;
1663 struct dwarf_expr_context *ctx;
1664 struct cleanup *old_chain, *value_chain;
1665 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1666 volatile struct gdb_exception ex;
1668 if (byte_offset < 0)
1669 invalid_synthetic_pointer ();
1672 return allocate_optimized_out_value (type);
1674 baton.frame = frame;
1675 baton.per_cu = per_cu;
1677 ctx = new_dwarf_expr_context ();
1678 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1679 value_chain = make_cleanup_value_free_to_mark (value_mark ());
1681 ctx->gdbarch = get_objfile_arch (objfile);
1682 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1683 ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
1684 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1685 ctx->baton = &baton;
1686 ctx->funcs = &dwarf_expr_ctx_funcs;
1688 TRY_CATCH (ex, RETURN_MASK_ERROR)
1690 dwarf_expr_eval (ctx, data, size);
1694 if (ex.error == NOT_AVAILABLE_ERROR)
1696 do_cleanups (old_chain);
1697 retval = allocate_value (type);
1698 mark_value_bytes_unavailable (retval, 0, TYPE_LENGTH (type));
1701 else if (ex.error == NO_ENTRY_VALUE_ERROR)
1703 if (entry_values_debug)
1704 exception_print (gdb_stdout, ex);
1705 do_cleanups (old_chain);
1706 return allocate_optimized_out_value (type);
1709 throw_exception (ex);
1712 if (ctx->num_pieces > 0)
1714 struct piece_closure *c;
1715 struct frame_id frame_id = get_frame_id (frame);
1716 ULONGEST bit_size = 0;
1719 for (i = 0; i < ctx->num_pieces; ++i)
1720 bit_size += ctx->pieces[i].size;
1721 if (8 * (byte_offset + TYPE_LENGTH (type)) > bit_size)
1722 invalid_synthetic_pointer ();
1724 c = allocate_piece_closure (per_cu, ctx->num_pieces, ctx->pieces,
1726 /* We must clean up the value chain after creating the piece
1727 closure but before allocating the result. */
1728 do_cleanups (value_chain);
1729 retval = allocate_computed_value (type, &pieced_value_funcs, c);
1730 VALUE_FRAME_ID (retval) = frame_id;
1731 set_value_offset (retval, byte_offset);
1735 switch (ctx->location)
1737 case DWARF_VALUE_REGISTER:
1739 struct gdbarch *arch = get_frame_arch (frame);
1740 ULONGEST dwarf_regnum = value_as_long (dwarf_expr_fetch (ctx, 0));
1741 int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_regnum);
1743 if (byte_offset != 0)
1744 error (_("cannot use offset on synthetic pointer to register"));
1745 do_cleanups (value_chain);
1746 if (gdb_regnum != -1)
1747 retval = value_from_register (type, gdb_regnum, frame);
1749 error (_("Unable to access DWARF register number %s"),
1750 paddress (arch, dwarf_regnum));
1754 case DWARF_VALUE_MEMORY:
1756 CORE_ADDR address = dwarf_expr_fetch_address (ctx, 0);
1757 int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
1759 do_cleanups (value_chain);
1760 retval = allocate_value_lazy (type);
1761 VALUE_LVAL (retval) = lval_memory;
1762 if (in_stack_memory)
1763 set_value_stack (retval, 1);
1764 set_value_address (retval, address + byte_offset);
1768 case DWARF_VALUE_STACK:
1770 struct value *value = dwarf_expr_fetch (ctx, 0);
1772 const gdb_byte *val_bytes;
1773 size_t n = TYPE_LENGTH (value_type (value));
1775 if (byte_offset + TYPE_LENGTH (type) > n)
1776 invalid_synthetic_pointer ();
1778 val_bytes = value_contents_all (value);
1779 val_bytes += byte_offset;
1782 /* Preserve VALUE because we are going to free values back
1783 to the mark, but we still need the value contents
1785 value_incref (value);
1786 do_cleanups (value_chain);
1787 make_cleanup_value_free (value);
1789 retval = allocate_value (type);
1790 contents = value_contents_raw (retval);
1791 if (n > TYPE_LENGTH (type))
1793 struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
1795 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
1796 val_bytes += n - TYPE_LENGTH (type);
1797 n = TYPE_LENGTH (type);
1799 memcpy (contents, val_bytes, n);
1803 case DWARF_VALUE_LITERAL:
1806 const bfd_byte *ldata;
1807 size_t n = ctx->len;
1809 if (byte_offset + TYPE_LENGTH (type) > n)
1810 invalid_synthetic_pointer ();
1812 do_cleanups (value_chain);
1813 retval = allocate_value (type);
1814 contents = value_contents_raw (retval);
1816 ldata = ctx->data + byte_offset;
1819 if (n > TYPE_LENGTH (type))
1821 struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
1823 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
1824 ldata += n - TYPE_LENGTH (type);
1825 n = TYPE_LENGTH (type);
1827 memcpy (contents, ldata, n);
1831 case DWARF_VALUE_OPTIMIZED_OUT:
1832 do_cleanups (value_chain);
1833 retval = allocate_optimized_out_value (type);
1836 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1837 operation by execute_stack_op. */
1838 case DWARF_VALUE_IMPLICIT_POINTER:
1839 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1840 it can only be encountered when making a piece. */
1842 internal_error (__FILE__, __LINE__, _("invalid location type"));
1846 set_value_initialized (retval, ctx->initialized);
1848 do_cleanups (old_chain);
1853 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1854 passes 0 as the byte_offset. */
1857 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
1858 const gdb_byte *data, unsigned short size,
1859 struct dwarf2_per_cu_data *per_cu)
1861 return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu, 0);
1865 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1867 struct needs_frame_baton
1870 struct dwarf2_per_cu_data *per_cu;
1873 /* Reads from registers do require a frame. */
1875 needs_frame_read_reg (void *baton, int regnum)
1877 struct needs_frame_baton *nf_baton = baton;
1879 nf_baton->needs_frame = 1;
1883 /* Reads from memory do not require a frame. */
1885 needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
1887 memset (buf, 0, len);
1890 /* Frame-relative accesses do require a frame. */
1892 needs_frame_frame_base (void *baton, const gdb_byte **start, size_t * length)
1894 static gdb_byte lit0 = DW_OP_lit0;
1895 struct needs_frame_baton *nf_baton = baton;
1900 nf_baton->needs_frame = 1;
1903 /* CFA accesses require a frame. */
1906 needs_frame_frame_cfa (void *baton)
1908 struct needs_frame_baton *nf_baton = baton;
1910 nf_baton->needs_frame = 1;
1914 /* Thread-local accesses do require a frame. */
1916 needs_frame_tls_address (void *baton, CORE_ADDR offset)
1918 struct needs_frame_baton *nf_baton = baton;
1920 nf_baton->needs_frame = 1;
1924 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
1927 needs_frame_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1929 struct needs_frame_baton *nf_baton = ctx->baton;
1931 per_cu_dwarf_call (ctx, die_offset, nf_baton->per_cu,
1932 ctx->funcs->get_frame_pc, ctx->baton);
1935 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
1938 needs_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
1939 int dwarf_reg, CORE_ADDR fb_offset)
1941 struct needs_frame_baton *nf_baton = ctx->baton;
1943 nf_baton->needs_frame = 1;
1946 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
1948 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs =
1950 needs_frame_read_reg,
1951 needs_frame_read_mem,
1952 needs_frame_frame_base,
1953 needs_frame_frame_cfa,
1954 needs_frame_frame_cfa, /* get_frame_pc */
1955 needs_frame_tls_address,
1956 needs_frame_dwarf_call,
1957 NULL, /* get_base_type */
1958 needs_dwarf_reg_entry_value
1961 /* Return non-zero iff the location expression at DATA (length SIZE)
1962 requires a frame to evaluate. */
1965 dwarf2_loc_desc_needs_frame (const gdb_byte *data, unsigned short size,
1966 struct dwarf2_per_cu_data *per_cu)
1968 struct needs_frame_baton baton;
1969 struct dwarf_expr_context *ctx;
1971 struct cleanup *old_chain;
1972 struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
1974 baton.needs_frame = 0;
1975 baton.per_cu = per_cu;
1977 ctx = new_dwarf_expr_context ();
1978 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
1979 make_cleanup_value_free_to_mark (value_mark ());
1981 ctx->gdbarch = get_objfile_arch (objfile);
1982 ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
1983 ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
1984 ctx->offset = dwarf2_per_cu_text_offset (per_cu);
1985 ctx->baton = &baton;
1986 ctx->funcs = &needs_frame_ctx_funcs;
1988 dwarf_expr_eval (ctx, data, size);
1990 in_reg = ctx->location == DWARF_VALUE_REGISTER;
1992 if (ctx->num_pieces > 0)
1996 /* If the location has several pieces, and any of them are in
1997 registers, then we will need a frame to fetch them from. */
1998 for (i = 0; i < ctx->num_pieces; i++)
1999 if (ctx->pieces[i].location == DWARF_VALUE_REGISTER)
2003 do_cleanups (old_chain);
2005 return baton.needs_frame || in_reg;
2008 /* A helper function that throws an unimplemented error mentioning a
2009 given DWARF operator. */
2012 unimplemented (unsigned int op)
2014 const char *name = dwarf_stack_op_name (op);
2017 error (_("DWARF operator %s cannot be translated to an agent expression"),
2020 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2021 "to an agent expression"),
2025 /* A helper function to convert a DWARF register to an arch register.
2026 ARCH is the architecture.
2027 DWARF_REG is the register.
2028 This will throw an exception if the DWARF register cannot be
2029 translated to an architecture register. */
2032 translate_register (struct gdbarch *arch, int dwarf_reg)
2034 int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
2036 error (_("Unable to access DWARF register number %d"), dwarf_reg);
2040 /* A helper function that emits an access to memory. ARCH is the
2041 target architecture. EXPR is the expression which we are building.
2042 NBITS is the number of bits we want to read. This emits the
2043 opcodes needed to read the memory and then extract the desired
2047 access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits)
2049 ULONGEST nbytes = (nbits + 7) / 8;
2051 gdb_assert (nbits > 0 && nbits <= sizeof (LONGEST));
2054 ax_trace_quick (expr, nbytes);
2057 ax_simple (expr, aop_ref8);
2058 else if (nbits <= 16)
2059 ax_simple (expr, aop_ref16);
2060 else if (nbits <= 32)
2061 ax_simple (expr, aop_ref32);
2063 ax_simple (expr, aop_ref64);
2065 /* If we read exactly the number of bytes we wanted, we're done. */
2066 if (8 * nbytes == nbits)
2069 if (gdbarch_bits_big_endian (arch))
2071 /* On a bits-big-endian machine, we want the high-order
2073 ax_const_l (expr, 8 * nbytes - nbits);
2074 ax_simple (expr, aop_rsh_unsigned);
2078 /* On a bits-little-endian box, we want the low-order NBITS. */
2079 ax_zero_ext (expr, nbits);
2083 /* A helper function to return the frame's PC. */
2086 get_ax_pc (void *baton)
2088 struct agent_expr *expr = baton;
2093 /* Compile a DWARF location expression to an agent expression.
2095 EXPR is the agent expression we are building.
2096 LOC is the agent value we modify.
2097 ARCH is the architecture.
2098 ADDR_SIZE is the size of addresses, in bytes.
2099 OP_PTR is the start of the location expression.
2100 OP_END is one past the last byte of the location expression.
2102 This will throw an exception for various kinds of errors -- for
2103 example, if the expression cannot be compiled, or if the expression
2107 dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
2108 struct gdbarch *arch, unsigned int addr_size,
2109 const gdb_byte *op_ptr, const gdb_byte *op_end,
2110 struct dwarf2_per_cu_data *per_cu)
2112 struct cleanup *cleanups;
2114 VEC(int) *dw_labels = NULL, *patches = NULL;
2115 const gdb_byte * const base = op_ptr;
2116 const gdb_byte *previous_piece = op_ptr;
2117 enum bfd_endian byte_order = gdbarch_byte_order (arch);
2118 ULONGEST bits_collected = 0;
2119 unsigned int addr_size_bits = 8 * addr_size;
2120 int bits_big_endian = gdbarch_bits_big_endian (arch);
2122 offsets = xmalloc ((op_end - op_ptr) * sizeof (int));
2123 cleanups = make_cleanup (xfree, offsets);
2125 for (i = 0; i < op_end - op_ptr; ++i)
2128 make_cleanup (VEC_cleanup (int), &dw_labels);
2129 make_cleanup (VEC_cleanup (int), &patches);
2131 /* By default we are making an address. */
2132 loc->kind = axs_lvalue_memory;
2134 while (op_ptr < op_end)
2136 enum dwarf_location_atom op = *op_ptr;
2137 ULONGEST uoffset, reg;
2141 offsets[op_ptr - base] = expr->len;
2144 /* Our basic approach to code generation is to map DWARF
2145 operations directly to AX operations. However, there are
2148 First, DWARF works on address-sized units, but AX always uses
2149 LONGEST. For most operations we simply ignore this
2150 difference; instead we generate sign extensions as needed
2151 before division and comparison operations. It would be nice
2152 to omit the sign extensions, but there is no way to determine
2153 the size of the target's LONGEST. (This code uses the size
2154 of the host LONGEST in some cases -- that is a bug but it is
2157 Second, some DWARF operations cannot be translated to AX.
2158 For these we simply fail. See
2159 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2194 ax_const_l (expr, op - DW_OP_lit0);
2198 uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
2199 op_ptr += addr_size;
2200 /* Some versions of GCC emit DW_OP_addr before
2201 DW_OP_GNU_push_tls_address. In this case the value is an
2202 index, not an address. We don't support things like
2203 branching between the address and the TLS op. */
2204 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
2205 uoffset += dwarf2_per_cu_text_offset (per_cu);
2206 ax_const_l (expr, uoffset);
2210 ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order));
2214 ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order));
2218 ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order));
2222 ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order));
2226 ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order));
2230 ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order));
2234 ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order));
2238 ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order));
2242 op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
2243 ax_const_l (expr, uoffset);
2246 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
2247 ax_const_l (expr, offset);
2282 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
2283 loc->u.reg = translate_register (arch, op - DW_OP_reg0);
2284 loc->kind = axs_lvalue_register;
2288 op_ptr = read_uleb128 (op_ptr, op_end, ®);
2289 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
2290 loc->u.reg = translate_register (arch, reg);
2291 loc->kind = axs_lvalue_register;
2294 case DW_OP_implicit_value:
2298 op_ptr = read_uleb128 (op_ptr, op_end, &len);
2299 if (op_ptr + len > op_end)
2300 error (_("DW_OP_implicit_value: too few bytes available."));
2301 if (len > sizeof (ULONGEST))
2302 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2305 ax_const_l (expr, extract_unsigned_integer (op_ptr, len,
2308 dwarf_expr_require_composition (op_ptr, op_end,
2309 "DW_OP_implicit_value");
2311 loc->kind = axs_rvalue;
2315 case DW_OP_stack_value:
2316 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
2317 loc->kind = axs_rvalue;
2352 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
2353 i = translate_register (arch, op - DW_OP_breg0);
2357 ax_const_l (expr, offset);
2358 ax_simple (expr, aop_add);
2363 op_ptr = read_uleb128 (op_ptr, op_end, ®);
2364 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
2365 i = translate_register (arch, reg);
2369 ax_const_l (expr, offset);
2370 ax_simple (expr, aop_add);
2376 const gdb_byte *datastart;
2378 unsigned int before_stack_len;
2380 struct symbol *framefunc;
2381 LONGEST base_offset = 0;
2383 b = block_for_pc (expr->scope);
2386 error (_("No block found for address"));
2388 framefunc = block_linkage_function (b);
2391 error (_("No function found for block"));
2393 dwarf_expr_frame_base_1 (framefunc, expr->scope,
2394 &datastart, &datalen);
2396 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
2397 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size, datastart,
2398 datastart + datalen, per_cu);
2402 ax_const_l (expr, offset);
2403 ax_simple (expr, aop_add);
2406 loc->kind = axs_lvalue_memory;
2411 ax_simple (expr, aop_dup);
2415 ax_simple (expr, aop_pop);
2420 ax_pick (expr, offset);
2424 ax_simple (expr, aop_swap);
2432 ax_simple (expr, aop_rot);
2436 case DW_OP_deref_size:
2440 if (op == DW_OP_deref_size)
2448 ax_simple (expr, aop_ref8);
2451 ax_simple (expr, aop_ref16);
2454 ax_simple (expr, aop_ref32);
2457 ax_simple (expr, aop_ref64);
2460 /* Note that dwarf_stack_op_name will never return
2462 error (_("Unsupported size %d in %s"),
2463 size, dwarf_stack_op_name (op));
2469 /* Sign extend the operand. */
2470 ax_ext (expr, addr_size_bits);
2471 ax_simple (expr, aop_dup);
2472 ax_const_l (expr, 0);
2473 ax_simple (expr, aop_less_signed);
2474 ax_simple (expr, aop_log_not);
2475 i = ax_goto (expr, aop_if_goto);
2476 /* We have to emit 0 - X. */
2477 ax_const_l (expr, 0);
2478 ax_simple (expr, aop_swap);
2479 ax_simple (expr, aop_sub);
2480 ax_label (expr, i, expr->len);
2484 /* No need to sign extend here. */
2485 ax_const_l (expr, 0);
2486 ax_simple (expr, aop_swap);
2487 ax_simple (expr, aop_sub);
2491 /* Sign extend the operand. */
2492 ax_ext (expr, addr_size_bits);
2493 ax_simple (expr, aop_bit_not);
2496 case DW_OP_plus_uconst:
2497 op_ptr = read_uleb128 (op_ptr, op_end, ®);
2498 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2499 but we micro-optimize anyhow. */
2502 ax_const_l (expr, reg);
2503 ax_simple (expr, aop_add);
2508 ax_simple (expr, aop_bit_and);
2512 /* Sign extend the operands. */
2513 ax_ext (expr, addr_size_bits);
2514 ax_simple (expr, aop_swap);
2515 ax_ext (expr, addr_size_bits);
2516 ax_simple (expr, aop_swap);
2517 ax_simple (expr, aop_div_signed);
2521 ax_simple (expr, aop_sub);
2525 ax_simple (expr, aop_rem_unsigned);
2529 ax_simple (expr, aop_mul);
2533 ax_simple (expr, aop_bit_or);
2537 ax_simple (expr, aop_add);
2541 ax_simple (expr, aop_lsh);
2545 ax_simple (expr, aop_rsh_unsigned);
2549 ax_simple (expr, aop_rsh_signed);
2553 ax_simple (expr, aop_bit_xor);
2557 /* Sign extend the operands. */
2558 ax_ext (expr, addr_size_bits);
2559 ax_simple (expr, aop_swap);
2560 ax_ext (expr, addr_size_bits);
2561 /* Note no swap here: A <= B is !(B < A). */
2562 ax_simple (expr, aop_less_signed);
2563 ax_simple (expr, aop_log_not);
2567 /* Sign extend the operands. */
2568 ax_ext (expr, addr_size_bits);
2569 ax_simple (expr, aop_swap);
2570 ax_ext (expr, addr_size_bits);
2571 ax_simple (expr, aop_swap);
2572 /* A >= B is !(A < B). */
2573 ax_simple (expr, aop_less_signed);
2574 ax_simple (expr, aop_log_not);
2578 /* Sign extend the operands. */
2579 ax_ext (expr, addr_size_bits);
2580 ax_simple (expr, aop_swap);
2581 ax_ext (expr, addr_size_bits);
2582 /* No need for a second swap here. */
2583 ax_simple (expr, aop_equal);
2587 /* Sign extend the operands. */
2588 ax_ext (expr, addr_size_bits);
2589 ax_simple (expr, aop_swap);
2590 ax_ext (expr, addr_size_bits);
2591 ax_simple (expr, aop_swap);
2592 ax_simple (expr, aop_less_signed);
2596 /* Sign extend the operands. */
2597 ax_ext (expr, addr_size_bits);
2598 ax_simple (expr, aop_swap);
2599 ax_ext (expr, addr_size_bits);
2600 /* Note no swap here: A > B is B < A. */
2601 ax_simple (expr, aop_less_signed);
2605 /* Sign extend the operands. */
2606 ax_ext (expr, addr_size_bits);
2607 ax_simple (expr, aop_swap);
2608 ax_ext (expr, addr_size_bits);
2609 /* No need for a swap here. */
2610 ax_simple (expr, aop_equal);
2611 ax_simple (expr, aop_log_not);
2614 case DW_OP_call_frame_cfa:
2615 dwarf2_compile_cfa_to_ax (expr, loc, arch, expr->scope, per_cu);
2616 loc->kind = axs_lvalue_memory;
2619 case DW_OP_GNU_push_tls_address:
2624 offset = extract_signed_integer (op_ptr, 2, byte_order);
2626 i = ax_goto (expr, aop_goto);
2627 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
2628 VEC_safe_push (int, patches, i);
2632 offset = extract_signed_integer (op_ptr, 2, byte_order);
2634 /* Zero extend the operand. */
2635 ax_zero_ext (expr, addr_size_bits);
2636 i = ax_goto (expr, aop_if_goto);
2637 VEC_safe_push (int, dw_labels, op_ptr + offset - base);
2638 VEC_safe_push (int, patches, i);
2645 case DW_OP_bit_piece:
2647 ULONGEST size, offset;
2649 if (op_ptr - 1 == previous_piece)
2650 error (_("Cannot translate empty pieces to agent expressions"));
2651 previous_piece = op_ptr - 1;
2653 op_ptr = read_uleb128 (op_ptr, op_end, &size);
2654 if (op == DW_OP_piece)
2660 op_ptr = read_uleb128 (op_ptr, op_end, &offset);
2662 if (bits_collected + size > 8 * sizeof (LONGEST))
2663 error (_("Expression pieces exceed word size"));
2665 /* Access the bits. */
2668 case axs_lvalue_register:
2669 ax_reg (expr, loc->u.reg);
2672 case axs_lvalue_memory:
2673 /* Offset the pointer, if needed. */
2676 ax_const_l (expr, offset / 8);
2677 ax_simple (expr, aop_add);
2680 access_memory (arch, expr, size);
2684 /* For a bits-big-endian target, shift up what we already
2685 have. For a bits-little-endian target, shift up the
2686 new data. Note that there is a potential bug here if
2687 the DWARF expression leaves multiple values on the
2689 if (bits_collected > 0)
2691 if (bits_big_endian)
2693 ax_simple (expr, aop_swap);
2694 ax_const_l (expr, size);
2695 ax_simple (expr, aop_lsh);
2696 /* We don't need a second swap here, because
2697 aop_bit_or is symmetric. */
2701 ax_const_l (expr, size);
2702 ax_simple (expr, aop_lsh);
2704 ax_simple (expr, aop_bit_or);
2707 bits_collected += size;
2708 loc->kind = axs_rvalue;
2712 case DW_OP_GNU_uninit:
2718 struct dwarf2_locexpr_baton block;
2719 int size = (op == DW_OP_call2 ? 2 : 4);
2721 uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
2724 block = dwarf2_fetch_die_location_block (uoffset, per_cu,
2727 /* DW_OP_call_ref is currently not supported. */
2728 gdb_assert (block.per_cu == per_cu);
2730 dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
2731 block.data, block.data + block.size,
2736 case DW_OP_call_ref:
2744 /* Patch all the branches we emitted. */
2745 for (i = 0; i < VEC_length (int, patches); ++i)
2747 int targ = offsets[VEC_index (int, dw_labels, i)];
2749 internal_error (__FILE__, __LINE__, _("invalid label"));
2750 ax_label (expr, VEC_index (int, patches, i), targ);
2753 do_cleanups (cleanups);
2757 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2758 evaluator to calculate the location. */
2759 static struct value *
2760 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
2762 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2765 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
2766 dlbaton->size, dlbaton->per_cu);
2771 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2773 locexpr_read_needs_frame (struct symbol *symbol)
2775 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
2777 return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size,
2781 /* Return true if DATA points to the end of a piece. END is one past
2782 the last byte in the expression. */
2785 piece_end_p (const gdb_byte *data, const gdb_byte *end)
2787 return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece;
2790 /* Helper for locexpr_describe_location_piece that finds the name of a
2794 locexpr_regname (struct gdbarch *gdbarch, int dwarf_regnum)
2798 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
2799 return gdbarch_register_name (gdbarch, regnum);
2802 /* Nicely describe a single piece of a location, returning an updated
2803 position in the bytecode sequence. This function cannot recognize
2804 all locations; if a location is not recognized, it simply returns
2807 static const gdb_byte *
2808 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
2809 CORE_ADDR addr, struct objfile *objfile,
2810 const gdb_byte *data, const gdb_byte *end,
2811 unsigned int addr_size)
2813 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2815 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
2817 fprintf_filtered (stream, _("a variable in $%s"),
2818 locexpr_regname (gdbarch, data[0] - DW_OP_reg0));
2821 else if (data[0] == DW_OP_regx)
2825 data = read_uleb128 (data + 1, end, ®);
2826 fprintf_filtered (stream, _("a variable in $%s"),
2827 locexpr_regname (gdbarch, reg));
2829 else if (data[0] == DW_OP_fbreg)
2832 struct symbol *framefunc;
2834 LONGEST frame_offset;
2835 const gdb_byte *base_data, *new_data, *save_data = data;
2837 LONGEST base_offset = 0;
2839 new_data = read_sleb128 (data + 1, end, &frame_offset);
2840 if (!piece_end_p (new_data, end))
2844 b = block_for_pc (addr);
2847 error (_("No block found for address for symbol \"%s\"."),
2848 SYMBOL_PRINT_NAME (symbol));
2850 framefunc = block_linkage_function (b);
2853 error (_("No function found for block for symbol \"%s\"."),
2854 SYMBOL_PRINT_NAME (symbol));
2856 dwarf_expr_frame_base_1 (framefunc, addr, &base_data, &base_size);
2858 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
2860 const gdb_byte *buf_end;
2862 frame_reg = base_data[0] - DW_OP_breg0;
2863 buf_end = read_sleb128 (base_data + 1,
2864 base_data + base_size, &base_offset);
2865 if (buf_end != base_data + base_size)
2866 error (_("Unexpected opcode after "
2867 "DW_OP_breg%u for symbol \"%s\"."),
2868 frame_reg, SYMBOL_PRINT_NAME (symbol));
2870 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
2872 /* The frame base is just the register, with no offset. */
2873 frame_reg = base_data[0] - DW_OP_reg0;
2878 /* We don't know what to do with the frame base expression,
2879 so we can't trace this variable; give up. */
2883 fprintf_filtered (stream,
2884 _("a variable at frame base reg $%s offset %s+%s"),
2885 locexpr_regname (gdbarch, frame_reg),
2886 plongest (base_offset), plongest (frame_offset));
2888 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31
2889 && piece_end_p (data, end))
2893 data = read_sleb128 (data + 1, end, &offset);
2895 fprintf_filtered (stream,
2896 _("a variable at offset %s from base reg $%s"),
2898 locexpr_regname (gdbarch, data[0] - DW_OP_breg0));
2901 /* The location expression for a TLS variable looks like this (on a
2904 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2905 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2907 0x3 is the encoding for DW_OP_addr, which has an operand as long
2908 as the size of an address on the target machine (here is 8
2909 bytes). Note that more recent version of GCC emit DW_OP_const4u
2910 or DW_OP_const8u, depending on address size, rather than
2911 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
2912 The operand represents the offset at which the variable is within
2913 the thread local storage. */
2915 else if (data + 1 + addr_size < end
2916 && (data[0] == DW_OP_addr
2917 || (addr_size == 4 && data[0] == DW_OP_const4u)
2918 || (addr_size == 8 && data[0] == DW_OP_const8u))
2919 && data[1 + addr_size] == DW_OP_GNU_push_tls_address
2920 && piece_end_p (data + 2 + addr_size, end))
2923 offset = extract_unsigned_integer (data + 1, addr_size,
2924 gdbarch_byte_order (gdbarch));
2926 fprintf_filtered (stream,
2927 _("a thread-local variable at offset 0x%s "
2928 "in the thread-local storage for `%s'"),
2929 phex_nz (offset, addr_size), objfile->name);
2931 data += 1 + addr_size + 1;
2933 else if (data[0] >= DW_OP_lit0
2934 && data[0] <= DW_OP_lit31
2936 && data[1] == DW_OP_stack_value)
2938 fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0);
2945 /* Disassemble an expression, stopping at the end of a piece or at the
2946 end of the expression. Returns a pointer to the next unread byte
2947 in the input expression. If ALL is nonzero, then this function
2948 will keep going until it reaches the end of the expression. */
2950 static const gdb_byte *
2951 disassemble_dwarf_expression (struct ui_file *stream,
2952 struct gdbarch *arch, unsigned int addr_size,
2954 const gdb_byte *data, const gdb_byte *end,
2956 struct dwarf2_per_cu_data *per_cu)
2958 const gdb_byte *start = data;
2960 fprintf_filtered (stream, _("a complex DWARF expression:\n"));
2964 || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
2966 enum dwarf_location_atom op = *data++;
2971 name = dwarf_stack_op_name (op);
2974 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
2975 op, (long) (data - 1 - start));
2976 fprintf_filtered (stream, " % 4ld: %s", (long) (data - 1 - start), name);
2981 ul = extract_unsigned_integer (data, addr_size,
2982 gdbarch_byte_order (arch));
2984 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
2988 ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch));
2990 fprintf_filtered (stream, " %s", pulongest (ul));
2993 l = extract_signed_integer (data, 1, gdbarch_byte_order (arch));
2995 fprintf_filtered (stream, " %s", plongest (l));
2998 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
3000 fprintf_filtered (stream, " %s", pulongest (ul));
3003 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3005 fprintf_filtered (stream, " %s", plongest (l));
3008 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3010 fprintf_filtered (stream, " %s", pulongest (ul));
3013 l = extract_signed_integer (data, 4, gdbarch_byte_order (arch));
3015 fprintf_filtered (stream, " %s", plongest (l));
3018 ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch));
3020 fprintf_filtered (stream, " %s", pulongest (ul));
3023 l = extract_signed_integer (data, 8, gdbarch_byte_order (arch));
3025 fprintf_filtered (stream, " %s", plongest (l));
3028 data = read_uleb128 (data, end, &ul);
3029 fprintf_filtered (stream, " %s", pulongest (ul));
3032 data = read_sleb128 (data, end, &l);
3033 fprintf_filtered (stream, " %s", plongest (l));
3068 fprintf_filtered (stream, " [$%s]",
3069 locexpr_regname (arch, op - DW_OP_reg0));
3073 data = read_uleb128 (data, end, &ul);
3074 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
3075 locexpr_regname (arch, (int) ul));
3078 case DW_OP_implicit_value:
3079 data = read_uleb128 (data, end, &ul);
3081 fprintf_filtered (stream, " %s", pulongest (ul));
3116 data = read_sleb128 (data, end, &l);
3117 fprintf_filtered (stream, " %s [$%s]", plongest (l),
3118 locexpr_regname (arch, op - DW_OP_breg0));
3122 data = read_uleb128 (data, end, &ul);
3123 data = read_sleb128 (data, end, &l);
3124 fprintf_filtered (stream, " register %s [$%s] offset %s",
3126 locexpr_regname (arch, (int) ul),
3131 data = read_sleb128 (data, end, &l);
3132 fprintf_filtered (stream, " %s", plongest (l));
3135 case DW_OP_xderef_size:
3136 case DW_OP_deref_size:
3138 fprintf_filtered (stream, " %d", *data);
3142 case DW_OP_plus_uconst:
3143 data = read_uleb128 (data, end, &ul);
3144 fprintf_filtered (stream, " %s", pulongest (ul));
3148 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3150 fprintf_filtered (stream, " to %ld",
3151 (long) (data + l - start));
3155 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3157 fprintf_filtered (stream, " %ld",
3158 (long) (data + l - start));
3162 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
3164 fprintf_filtered (stream, " offset %s", phex_nz (ul, 2));
3168 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3170 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
3173 case DW_OP_call_ref:
3174 ul = extract_unsigned_integer (data, offset_size,
3175 gdbarch_byte_order (arch));
3176 data += offset_size;
3177 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
3181 data = read_uleb128 (data, end, &ul);
3182 fprintf_filtered (stream, " %s (bytes)", pulongest (ul));
3185 case DW_OP_bit_piece:
3189 data = read_uleb128 (data, end, &ul);
3190 data = read_uleb128 (data, end, &offset);
3191 fprintf_filtered (stream, " size %s offset %s (bits)",
3192 pulongest (ul), pulongest (offset));
3196 case DW_OP_GNU_implicit_pointer:
3198 ul = extract_unsigned_integer (data, offset_size,
3199 gdbarch_byte_order (arch));
3200 data += offset_size;
3202 data = read_sleb128 (data, end, &l);
3204 fprintf_filtered (stream, " DIE %s offset %s",
3205 phex_nz (ul, offset_size),
3210 case DW_OP_GNU_deref_type:
3212 int addr_size = *data++;
3216 data = read_uleb128 (data, end, &offset);
3217 type = dwarf2_get_die_type (offset, per_cu);
3218 fprintf_filtered (stream, "<");
3219 type_print (type, "", stream, -1);
3220 fprintf_filtered (stream, " [0x%s]> %d", phex_nz (offset, 0),
3225 case DW_OP_GNU_const_type:
3230 data = read_uleb128 (data, end, &type_die);
3231 type = dwarf2_get_die_type (type_die, per_cu);
3232 fprintf_filtered (stream, "<");
3233 type_print (type, "", stream, -1);
3234 fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die, 0));
3238 case DW_OP_GNU_regval_type:
3240 ULONGEST type_die, reg;
3243 data = read_uleb128 (data, end, ®);
3244 data = read_uleb128 (data, end, &type_die);
3246 type = dwarf2_get_die_type (type_die, per_cu);
3247 fprintf_filtered (stream, "<");
3248 type_print (type, "", stream, -1);
3249 fprintf_filtered (stream, " [0x%s]> [$%s]", phex_nz (type_die, 0),
3250 locexpr_regname (arch, reg));
3254 case DW_OP_GNU_convert:
3255 case DW_OP_GNU_reinterpret:
3259 data = read_uleb128 (data, end, &type_die);
3262 fprintf_filtered (stream, "<0>");
3267 type = dwarf2_get_die_type (type_die, per_cu);
3268 fprintf_filtered (stream, "<");
3269 type_print (type, "", stream, -1);
3270 fprintf_filtered (stream, " [0x%s]>", phex_nz (type_die, 0));
3276 fprintf_filtered (stream, "\n");
3282 /* Describe a single location, which may in turn consist of multiple
3286 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
3287 struct ui_file *stream,
3288 const gdb_byte *data, int size,
3289 struct objfile *objfile, unsigned int addr_size,
3290 int offset_size, struct dwarf2_per_cu_data *per_cu)
3292 const gdb_byte *end = data + size;
3293 int first_piece = 1, bad = 0;
3297 const gdb_byte *here = data;
3298 int disassemble = 1;
3303 fprintf_filtered (stream, _(", and "));
3305 if (!dwarf2_always_disassemble)
3307 data = locexpr_describe_location_piece (symbol, stream,
3309 data, end, addr_size);
3310 /* If we printed anything, or if we have an empty piece,
3311 then don't disassemble. */
3313 || data[0] == DW_OP_piece
3314 || data[0] == DW_OP_bit_piece)
3318 data = disassemble_dwarf_expression (stream,
3319 get_objfile_arch (objfile),
3320 addr_size, offset_size, data, end,
3321 dwarf2_always_disassemble,
3326 int empty = data == here;
3329 fprintf_filtered (stream, " ");
3330 if (data[0] == DW_OP_piece)
3334 data = read_uleb128 (data + 1, end, &bytes);
3337 fprintf_filtered (stream, _("an empty %s-byte piece"),
3340 fprintf_filtered (stream, _(" [%s-byte piece]"),
3343 else if (data[0] == DW_OP_bit_piece)
3345 ULONGEST bits, offset;
3347 data = read_uleb128 (data + 1, end, &bits);
3348 data = read_uleb128 (data, end, &offset);
3351 fprintf_filtered (stream,
3352 _("an empty %s-bit piece"),
3355 fprintf_filtered (stream,
3356 _(" [%s-bit piece, offset %s bits]"),
3357 pulongest (bits), pulongest (offset));
3367 if (bad || data > end)
3368 error (_("Corrupted DWARF2 expression for \"%s\"."),
3369 SYMBOL_PRINT_NAME (symbol));
3372 /* Print a natural-language description of SYMBOL to STREAM. This
3373 version is for a symbol with a single location. */
3376 locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
3377 struct ui_file *stream)
3379 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3380 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
3381 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
3382 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
3384 locexpr_describe_location_1 (symbol, addr, stream,
3385 dlbaton->data, dlbaton->size,
3386 objfile, addr_size, offset_size,
3390 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3391 any necessary bytecode in AX. */
3394 locexpr_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
3395 struct agent_expr *ax, struct axs_value *value)
3397 struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3398 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
3400 if (dlbaton->data == NULL || dlbaton->size == 0)
3401 value->optimized_out = 1;
3403 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size,
3404 dlbaton->data, dlbaton->data + dlbaton->size,
3408 /* The set of location functions used with the DWARF-2 expression
3410 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
3411 locexpr_read_variable,
3412 locexpr_read_needs_frame,
3413 locexpr_describe_location,
3414 locexpr_tracepoint_var_ref
3418 /* Wrapper functions for location lists. These generally find
3419 the appropriate location expression and call something above. */
3421 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3422 evaluator to calculate the location. */
3423 static struct value *
3424 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
3426 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3428 const gdb_byte *data;
3430 CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0;
3432 data = dwarf2_find_location_expression (dlbaton, &size, pc);
3434 val = allocate_optimized_out_value (SYMBOL_TYPE (symbol));
3436 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
3442 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3444 loclist_read_needs_frame (struct symbol *symbol)
3446 /* If there's a location list, then assume we need to have a frame
3447 to choose the appropriate location expression. With tracking of
3448 global variables this is not necessarily true, but such tracking
3449 is disabled in GCC at the moment until we figure out how to
3455 /* Print a natural-language description of SYMBOL to STREAM. This
3456 version applies when there is a list of different locations, each
3457 with a specified address range. */
3460 loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
3461 struct ui_file *stream)
3463 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3464 CORE_ADDR low, high;
3465 const gdb_byte *loc_ptr, *buf_end;
3466 int length, first = 1;
3467 struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
3468 struct gdbarch *gdbarch = get_objfile_arch (objfile);
3469 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3470 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
3471 int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
3472 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
3473 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
3474 /* Adjust base_address for relocatable objects. */
3475 CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
3476 CORE_ADDR base_address = dlbaton->base_address + base_offset;
3478 loc_ptr = dlbaton->data;
3479 buf_end = dlbaton->data + dlbaton->size;
3481 fprintf_filtered (stream, _("multi-location:\n"));
3483 /* Iterate through locations until we run out. */
3486 if (buf_end - loc_ptr < 2 * addr_size)
3487 error (_("Corrupted DWARF expression for symbol \"%s\"."),
3488 SYMBOL_PRINT_NAME (symbol));
3491 low = extract_signed_integer (loc_ptr, addr_size, byte_order);
3493 low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
3494 loc_ptr += addr_size;
3497 high = extract_signed_integer (loc_ptr, addr_size, byte_order);
3499 high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
3500 loc_ptr += addr_size;
3502 /* A base-address-selection entry. */
3503 if ((low & base_mask) == base_mask)
3505 base_address = high + base_offset;
3506 fprintf_filtered (stream, _(" Base address %s"),
3507 paddress (gdbarch, base_address));
3511 /* An end-of-list entry. */
3512 if (low == 0 && high == 0)
3515 /* Otherwise, a location expression entry. */
3516 low += base_address;
3517 high += base_address;
3519 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
3522 /* (It would improve readability to print only the minimum
3523 necessary digits of the second number of the range.) */
3524 fprintf_filtered (stream, _(" Range %s-%s: "),
3525 paddress (gdbarch, low), paddress (gdbarch, high));
3527 /* Now describe this particular location. */
3528 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
3529 objfile, addr_size, offset_size,
3532 fprintf_filtered (stream, "\n");
3538 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3539 any necessary bytecode in AX. */
3541 loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
3542 struct agent_expr *ax, struct axs_value *value)
3544 struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
3545 const gdb_byte *data;
3547 unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
3549 data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
3550 if (data == NULL || size == 0)
3551 value->optimized_out = 1;
3553 dwarf2_compile_expr_to_ax (ax, value, gdbarch, addr_size, data, data + size,
3557 /* The set of location functions used with the DWARF-2 expression
3558 evaluator and location lists. */
3559 const struct symbol_computed_ops dwarf2_loclist_funcs = {
3560 loclist_read_variable,
3561 loclist_read_needs_frame,
3562 loclist_describe_location,
3563 loclist_tracepoint_var_ref
3567 _initialize_dwarf2loc (void)
3569 add_setshow_zinteger_cmd ("entry-values", class_maintenance,
3570 &entry_values_debug,
3571 _("Set entry values and tail call frames "
3573 _("Show entry values and tail call frames "
3575 _("When non-zero, the process of determining "
3576 "parameter values from function entry point "
3577 "and tail call frames will be printed."),
3579 show_entry_values_debug,
3580 &setdebuglist, &showdebuglist);