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 /* Define VEC (CORE_ADDR) functions. */
426 DEF_VEC_I (CORE_ADDR
);
428 /* Verify function with entry point exact address ADDR can never call itself
429 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
430 can call itself via tail calls.
432 If a funtion can tail call itself its entry value based parameters are
433 unreliable. There is no verification whether the value of some/all
434 parameters is unchanged through the self tail call, we expect if there is
435 a self tail call all the parameters can be modified. */
438 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
440 struct obstack addr_obstack
;
441 struct cleanup
*old_chain
;
444 /* Track here CORE_ADDRs which were already visited. */
447 /* The verification is completely unordered. Track here function addresses
448 which still need to be iterated. */
449 VEC (CORE_ADDR
) *todo
= NULL
;
451 obstack_init (&addr_obstack
);
452 old_chain
= make_cleanup_obstack_free (&addr_obstack
);
453 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
454 &addr_obstack
, hashtab_obstack_allocate
,
456 make_cleanup_htab_delete (addr_hash
);
458 make_cleanup (VEC_cleanup (CORE_ADDR
), &todo
);
460 VEC_safe_push (CORE_ADDR
, todo
, verify_addr
);
461 while (!VEC_empty (CORE_ADDR
, todo
))
463 struct symbol
*func_sym
;
464 struct call_site
*call_site
;
466 addr
= VEC_pop (CORE_ADDR
, todo
);
468 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
470 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
471 call_site
; call_site
= call_site
->tail_call_next
)
473 CORE_ADDR target_addr
;
476 /* CALLER_FRAME with registers is not available for tail-call jumped
478 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
480 if (target_addr
== verify_addr
)
482 struct minimal_symbol
*msym
;
484 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
485 throw_error (NO_ENTRY_VALUE_ERROR
,
486 _("DW_OP_GNU_entry_value resolving has found "
487 "function \"%s\" at %s can call itself via tail "
489 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
490 paddress (gdbarch
, verify_addr
));
493 slot
= htab_find_slot (addr_hash
, &target_addr
, INSERT
);
496 *slot
= obstack_copy (&addr_obstack
, &target_addr
,
497 sizeof (target_addr
));
498 VEC_safe_push (CORE_ADDR
, todo
, target_addr
);
503 do_cleanups (old_chain
);
506 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
507 ENTRY_VALUES_DEBUG. */
510 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
512 CORE_ADDR addr
= call_site
->pc
;
513 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (addr
- 1);
515 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
516 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
520 /* vec.h needs single word type name, typedef it. */
521 typedef struct call_site
*call_sitep
;
523 /* Define VEC (call_sitep) functions. */
524 DEF_VEC_P (call_sitep
);
526 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
527 only top callers and bottom callees which are present in both. GDBARCH is
528 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
529 no remaining possibilities to provide unambiguous non-trivial result.
530 RESULTP should point to NULL on the first (initialization) call. Caller is
531 responsible for xfree of any RESULTP data. */
534 chain_candidate (struct gdbarch
*gdbarch
, struct call_site_chain
**resultp
,
535 VEC (call_sitep
) *chain
)
537 struct call_site_chain
*result
= *resultp
;
538 long length
= VEC_length (call_sitep
, chain
);
539 int callers
, callees
, idx
;
543 /* Create the initial chain containing all the passed PCs. */
545 result
= xmalloc (sizeof (*result
) + sizeof (*result
->call_site
)
547 result
->length
= length
;
548 result
->callers
= result
->callees
= length
;
549 memcpy (result
->call_site
, VEC_address (call_sitep
, chain
),
550 sizeof (*result
->call_site
) * length
);
553 if (entry_values_debug
)
555 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
556 for (idx
= 0; idx
< length
; idx
++)
557 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
558 fputc_unfiltered ('\n', gdb_stdlog
);
564 if (entry_values_debug
)
566 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
567 for (idx
= 0; idx
< length
; idx
++)
568 tailcall_dump (gdbarch
, VEC_index (call_sitep
, chain
, idx
));
569 fputc_unfiltered ('\n', gdb_stdlog
);
572 /* Intersect callers. */
574 callers
= min (result
->callers
, length
);
575 for (idx
= 0; idx
< callers
; idx
++)
576 if (result
->call_site
[idx
] != VEC_index (call_sitep
, chain
, idx
))
578 result
->callers
= idx
;
582 /* Intersect callees. */
584 callees
= min (result
->callees
, length
);
585 for (idx
= 0; idx
< callees
; idx
++)
586 if (result
->call_site
[result
->length
- 1 - idx
]
587 != VEC_index (call_sitep
, chain
, length
- 1 - idx
))
589 result
->callees
= idx
;
593 if (entry_values_debug
)
595 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
596 for (idx
= 0; idx
< result
->callers
; idx
++)
597 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
598 fputs_unfiltered (" |", gdb_stdlog
);
599 for (idx
= 0; idx
< result
->callees
; idx
++)
600 tailcall_dump (gdbarch
, result
->call_site
[result
->length
601 - result
->callees
+ idx
]);
602 fputc_unfiltered ('\n', gdb_stdlog
);
605 if (result
->callers
== 0 && result
->callees
== 0)
607 /* There are no common callers or callees. It could be also a direct
608 call (which has length 0) with ambiguous possibility of an indirect
609 call - CALLERS == CALLEES == 0 is valid during the first allocation
610 but any subsequence processing of such entry means ambiguity. */
616 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
617 PC again. In such case there must be two different code paths to reach
618 it, therefore some of the former determined intermediate PCs must differ
619 and the unambiguous chain gets shortened. */
620 gdb_assert (result
->callers
+ result
->callees
< result
->length
);
623 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
624 assumed frames between them use GDBARCH. Use depth first search so we can
625 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
626 would have needless GDB stack overhead. Caller is responsible for xfree of
627 the returned result. Any unreliability results in thrown
628 NO_ENTRY_VALUE_ERROR. */
630 static struct call_site_chain
*
631 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
634 struct func_type
*func_specific
;
635 struct obstack addr_obstack
;
636 struct cleanup
*back_to_retval
, *back_to_workdata
;
637 struct call_site_chain
*retval
= NULL
;
638 struct call_site
*call_site
;
640 /* Mark CALL_SITEs so we do not visit the same ones twice. */
643 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
644 call_site nor any possible call_site at CALLEE_PC's function is there.
645 Any CALL_SITE in CHAIN will be iterated to its siblings - via
646 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
647 VEC (call_sitep
) *chain
= NULL
;
649 /* We are not interested in the specific PC inside the callee function. */
650 callee_pc
= get_pc_function_start (callee_pc
);
652 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
653 paddress (gdbarch
, callee_pc
));
655 back_to_retval
= make_cleanup (free_current_contents
, &retval
);
657 obstack_init (&addr_obstack
);
658 back_to_workdata
= make_cleanup_obstack_free (&addr_obstack
);
659 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
660 &addr_obstack
, hashtab_obstack_allocate
,
662 make_cleanup_htab_delete (addr_hash
);
664 make_cleanup (VEC_cleanup (call_sitep
), &chain
);
666 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
667 at the target's function. All the possible tail call sites in the
668 target's function will get iterated as already pushed into CHAIN via their
670 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
674 CORE_ADDR target_func_addr
;
675 struct call_site
*target_call_site
;
677 /* CALLER_FRAME with registers is not available for tail-call jumped
679 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
681 if (target_func_addr
== callee_pc
)
683 chain_candidate (gdbarch
, &retval
, chain
);
687 /* There is no way to reach CALLEE_PC again as we would prevent
688 entering it twice as being already marked in ADDR_HASH. */
689 target_call_site
= NULL
;
693 struct symbol
*target_func
;
695 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
696 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
701 /* Attempt to visit TARGET_CALL_SITE. */
703 if (target_call_site
)
707 slot
= htab_find_slot (addr_hash
, &target_call_site
->pc
, INSERT
);
710 /* Successfully entered TARGET_CALL_SITE. */
712 *slot
= &target_call_site
->pc
;
713 VEC_safe_push (call_sitep
, chain
, target_call_site
);
718 /* Backtrack (without revisiting the originating call_site). Try the
719 callers's sibling; if there isn't any try the callers's callers's
722 target_call_site
= NULL
;
723 while (!VEC_empty (call_sitep
, chain
))
725 call_site
= VEC_pop (call_sitep
, chain
);
727 gdb_assert (htab_find_slot (addr_hash
, &call_site
->pc
,
729 htab_remove_elt (addr_hash
, &call_site
->pc
);
731 target_call_site
= call_site
->tail_call_next
;
732 if (target_call_site
)
736 while (target_call_site
);
738 if (VEC_empty (call_sitep
, chain
))
741 call_site
= VEC_last (call_sitep
, chain
);
746 struct minimal_symbol
*msym_caller
, *msym_callee
;
748 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
749 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
750 throw_error (NO_ENTRY_VALUE_ERROR
,
751 _("There are no unambiguously determinable intermediate "
752 "callers or callees between caller function \"%s\" at %s "
753 "and callee function \"%s\" at %s"),
755 ? "???" : SYMBOL_PRINT_NAME (msym_caller
)),
756 paddress (gdbarch
, caller_pc
),
758 ? "???" : SYMBOL_PRINT_NAME (msym_callee
)),
759 paddress (gdbarch
, callee_pc
));
762 do_cleanups (back_to_workdata
);
763 discard_cleanups (back_to_retval
);
767 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
768 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
769 constructed return NULL. Caller is responsible for xfree of the returned
772 struct call_site_chain
*
773 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
776 volatile struct gdb_exception e
;
777 struct call_site_chain
*retval
= NULL
;
779 TRY_CATCH (e
, RETURN_MASK_ERROR
)
781 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
785 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
787 if (entry_values_debug
)
788 exception_print (gdb_stdout
, e
);
798 /* Fetch call_site_parameter from caller matching the parameters. FRAME is for
799 callee. See DWARF_REG and FB_OFFSET description at struct
800 dwarf_expr_context_funcs->push_dwarf_reg_entry_value.
802 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
805 static struct call_site_parameter
*
806 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
, int dwarf_reg
,
808 struct dwarf2_per_cu_data
**per_cu_return
)
810 CORE_ADDR func_addr
= get_frame_func (frame
);
812 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
813 struct frame_info
*caller_frame
= get_prev_frame (frame
);
814 struct call_site
*call_site
;
817 struct dwarf2_locexpr_baton
*dwarf_block
;
818 struct call_site_parameter
*parameter
;
819 CORE_ADDR target_addr
;
821 if (gdbarch
!= frame_unwind_arch (frame
))
823 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
824 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
826 throw_error (NO_ENTRY_VALUE_ERROR
,
827 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
828 "(of %s (%s)) does not match caller gdbarch %s"),
829 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
830 paddress (gdbarch
, func_addr
),
831 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
832 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
835 if (caller_frame
== NULL
)
837 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
839 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_GNU_entry_value resolving "
840 "requires caller of %s (%s)"),
841 paddress (gdbarch
, func_addr
),
842 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
844 caller_pc
= get_frame_pc (caller_frame
);
845 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
847 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
848 if (target_addr
!= func_addr
)
850 struct minimal_symbol
*target_msym
, *func_msym
;
852 target_msym
= lookup_minimal_symbol_by_pc (target_addr
);
853 func_msym
= lookup_minimal_symbol_by_pc (func_addr
);
854 throw_error (NO_ENTRY_VALUE_ERROR
,
855 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
856 "but the called frame is for %s at %s"),
857 (target_msym
== NULL
? "???"
858 : SYMBOL_PRINT_NAME (target_msym
)),
859 paddress (gdbarch
, target_addr
),
860 func_msym
== NULL
? "???" : SYMBOL_PRINT_NAME (func_msym
),
861 paddress (gdbarch
, func_addr
));
864 /* No entry value based parameters would be reliable if this function can
865 call itself via tail calls. */
866 func_verify_no_selftailcall (gdbarch
, func_addr
);
868 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
870 parameter
= &call_site
->parameter
[iparams
];
871 if (parameter
->dwarf_reg
== -1 && dwarf_reg
== -1)
873 if (parameter
->fb_offset
== fb_offset
)
876 else if (parameter
->dwarf_reg
== dwarf_reg
)
879 if (iparams
== call_site
->parameter_count
)
881 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (caller_pc
);
883 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
884 determine its value. */
885 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
886 "at DW_TAG_GNU_call_site %s at %s"),
887 paddress (gdbarch
, caller_pc
),
888 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
891 *per_cu_return
= call_site
->per_cu
;
895 /* Execute call_site_parameter's DWARF block for caller of the CTX's frame.
896 CTX must be of dwarf_expr_ctx_funcs kind. See DWARF_REG and FB_OFFSET
897 description at struct dwarf_expr_context_funcs->push_dwarf_reg_entry_value.
899 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
900 can be more simple as it does not support cross-CU DWARF executions. */
903 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
904 int dwarf_reg
, CORE_ADDR fb_offset
)
906 struct dwarf_expr_baton
*debaton
;
907 struct frame_info
*frame
, *caller_frame
;
908 struct dwarf2_per_cu_data
*caller_per_cu
;
909 struct dwarf_expr_baton baton_local
;
910 struct dwarf_expr_context saved_ctx
;
911 struct call_site_parameter
*parameter
;
912 const gdb_byte
*data_src
;
915 gdb_assert (ctx
->funcs
== &dwarf_expr_ctx_funcs
);
916 debaton
= ctx
->baton
;
917 frame
= debaton
->frame
;
918 caller_frame
= get_prev_frame (frame
);
920 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, dwarf_reg
, fb_offset
,
922 data_src
= parameter
->value
;
923 size
= parameter
->value_size
;
925 baton_local
.frame
= caller_frame
;
926 baton_local
.per_cu
= caller_per_cu
;
928 saved_ctx
.gdbarch
= ctx
->gdbarch
;
929 saved_ctx
.addr_size
= ctx
->addr_size
;
930 saved_ctx
.offset
= ctx
->offset
;
931 saved_ctx
.baton
= ctx
->baton
;
932 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (baton_local
.per_cu
));
933 ctx
->addr_size
= dwarf2_per_cu_addr_size (baton_local
.per_cu
);
934 ctx
->offset
= dwarf2_per_cu_text_offset (baton_local
.per_cu
);
935 ctx
->baton
= &baton_local
;
937 dwarf_expr_eval (ctx
, data_src
, size
);
939 ctx
->gdbarch
= saved_ctx
.gdbarch
;
940 ctx
->addr_size
= saved_ctx
.addr_size
;
941 ctx
->offset
= saved_ctx
.offset
;
942 ctx
->baton
= saved_ctx
.baton
;
947 /* Reference count. */
950 /* The CU from which this closure's expression came. */
951 struct dwarf2_per_cu_data
*per_cu
;
953 /* The number of pieces used to describe this variable. */
956 /* The target address size, used only for DWARF_VALUE_STACK. */
959 /* The pieces themselves. */
960 struct dwarf_expr_piece
*pieces
;
963 /* Allocate a closure for a value formed from separately-described
966 static struct piece_closure
*
967 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
968 int n_pieces
, struct dwarf_expr_piece
*pieces
,
971 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
976 c
->n_pieces
= n_pieces
;
977 c
->addr_size
= addr_size
;
978 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
980 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
981 for (i
= 0; i
< n_pieces
; ++i
)
982 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
983 value_incref (c
->pieces
[i
].v
.value
);
988 /* The lowest-level function to extract bits from a byte buffer.
989 SOURCE is the buffer. It is updated if we read to the end of a
991 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
992 updated to reflect the number of bits actually read.
993 NBITS is the number of bits we want to read. It is updated to
994 reflect the number of bits actually read. This function may read
996 BITS_BIG_ENDIAN is taken directly from gdbarch.
997 This function returns the extracted bits. */
1000 extract_bits_primitive (const gdb_byte
**source
,
1001 unsigned int *source_offset_bits
,
1002 int *nbits
, int bits_big_endian
)
1004 unsigned int avail
, mask
, datum
;
1006 gdb_assert (*source_offset_bits
< 8);
1008 avail
= 8 - *source_offset_bits
;
1012 mask
= (1 << avail
) - 1;
1014 if (bits_big_endian
)
1015 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
1017 datum
>>= *source_offset_bits
;
1021 *source_offset_bits
+= avail
;
1022 if (*source_offset_bits
>= 8)
1024 *source_offset_bits
-= 8;
1031 /* Extract some bits from a source buffer and move forward in the
1034 SOURCE is the source buffer. It is updated as bytes are read.
1035 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1037 NBITS is the number of bits to read.
1038 BITS_BIG_ENDIAN is taken directly from gdbarch.
1040 This function returns the bits that were read. */
1043 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
1044 int nbits
, int bits_big_endian
)
1048 gdb_assert (nbits
> 0 && nbits
<= 8);
1050 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1056 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1058 if (bits_big_endian
)
1068 /* Write some bits into a buffer and move forward in the buffer.
1070 DATUM is the bits to write. The low-order bits of DATUM are used.
1071 DEST is the destination buffer. It is updated as bytes are
1073 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1075 NBITS is the number of valid bits in DATUM.
1076 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1079 insert_bits (unsigned int datum
,
1080 gdb_byte
*dest
, unsigned int dest_offset_bits
,
1081 int nbits
, int bits_big_endian
)
1085 gdb_assert (dest_offset_bits
+ nbits
<= 8);
1087 mask
= (1 << nbits
) - 1;
1088 if (bits_big_endian
)
1090 datum
<<= 8 - (dest_offset_bits
+ nbits
);
1091 mask
<<= 8 - (dest_offset_bits
+ nbits
);
1095 datum
<<= dest_offset_bits
;
1096 mask
<<= dest_offset_bits
;
1099 gdb_assert ((datum
& ~mask
) == 0);
1101 *dest
= (*dest
& ~mask
) | datum
;
1104 /* Copy bits from a source to a destination.
1106 DEST is where the bits should be written.
1107 DEST_OFFSET_BITS is the bit offset into DEST.
1108 SOURCE is the source of bits.
1109 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1110 BIT_COUNT is the number of bits to copy.
1111 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1114 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
1115 const gdb_byte
*source
, unsigned int source_offset_bits
,
1116 unsigned int bit_count
,
1117 int bits_big_endian
)
1119 unsigned int dest_avail
;
1122 /* Reduce everything to byte-size pieces. */
1123 dest
+= dest_offset_bits
/ 8;
1124 dest_offset_bits
%= 8;
1125 source
+= source_offset_bits
/ 8;
1126 source_offset_bits
%= 8;
1128 dest_avail
= 8 - dest_offset_bits
% 8;
1130 /* See if we can fill the first destination byte. */
1131 if (dest_avail
< bit_count
)
1133 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
1135 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
1137 dest_offset_bits
= 0;
1138 bit_count
-= dest_avail
;
1141 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1142 than 8 bits remaining. */
1143 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
1144 for (; bit_count
>= 8; bit_count
-= 8)
1146 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
1147 *dest
++ = (gdb_byte
) datum
;
1150 /* Finally, we may have a few leftover bits. */
1151 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
1154 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
1156 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
1161 read_pieced_value (struct value
*v
)
1165 ULONGEST bits_to_skip
;
1167 struct piece_closure
*c
1168 = (struct piece_closure
*) value_computed_closure (v
);
1169 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
1171 size_t buffer_size
= 0;
1172 char *buffer
= NULL
;
1173 struct cleanup
*cleanup
;
1175 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1177 if (value_type (v
) != value_enclosing_type (v
))
1178 internal_error (__FILE__
, __LINE__
,
1179 _("Should not be able to create a lazy value with "
1180 "an enclosing type"));
1182 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1184 contents
= value_contents_raw (v
);
1185 bits_to_skip
= 8 * value_offset (v
);
1186 if (value_bitsize (v
))
1188 bits_to_skip
+= value_bitpos (v
);
1189 type_len
= value_bitsize (v
);
1192 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1194 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1196 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1197 size_t this_size
, this_size_bits
;
1198 long dest_offset_bits
, source_offset_bits
, source_offset
;
1199 const gdb_byte
*intermediate_buffer
;
1201 /* Compute size, source, and destination offsets for copying, in
1203 this_size_bits
= p
->size
;
1204 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1206 bits_to_skip
-= this_size_bits
;
1209 if (this_size_bits
> type_len
- offset
)
1210 this_size_bits
= type_len
- offset
;
1211 if (bits_to_skip
> 0)
1213 dest_offset_bits
= 0;
1214 source_offset_bits
= bits_to_skip
;
1215 this_size_bits
-= bits_to_skip
;
1220 dest_offset_bits
= offset
;
1221 source_offset_bits
= 0;
1224 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1225 source_offset
= source_offset_bits
/ 8;
1226 if (buffer_size
< this_size
)
1228 buffer_size
= this_size
;
1229 buffer
= xrealloc (buffer
, buffer_size
);
1231 intermediate_buffer
= buffer
;
1233 /* Copy from the source to DEST_BUFFER. */
1234 switch (p
->location
)
1236 case DWARF_VALUE_REGISTER
:
1238 struct gdbarch
*arch
= get_frame_arch (frame
);
1239 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1240 int reg_offset
= source_offset
;
1242 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1243 && this_size
< register_size (arch
, gdb_regnum
))
1245 /* Big-endian, and we want less than full size. */
1246 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1247 /* We want the lower-order THIS_SIZE_BITS of the bytes
1248 we extract from the register. */
1249 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1252 if (gdb_regnum
!= -1)
1256 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1260 /* Just so garbage doesn't ever shine through. */
1261 memset (buffer
, 0, this_size
);
1264 set_value_optimized_out (v
, 1);
1266 mark_value_bytes_unavailable (v
, offset
, this_size
);
1271 error (_("Unable to access DWARF register number %s"),
1272 paddress (arch
, p
->v
.regno
));
1277 case DWARF_VALUE_MEMORY
:
1278 read_value_memory (v
, offset
,
1279 p
->v
.mem
.in_stack_memory
,
1280 p
->v
.mem
.addr
+ source_offset
,
1284 case DWARF_VALUE_STACK
:
1286 size_t n
= this_size
;
1288 if (n
> c
->addr_size
- source_offset
)
1289 n
= (c
->addr_size
>= source_offset
1290 ? c
->addr_size
- source_offset
1298 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
1300 intermediate_buffer
= val_bytes
+ source_offset
;
1305 case DWARF_VALUE_LITERAL
:
1307 size_t n
= this_size
;
1309 if (n
> p
->v
.literal
.length
- source_offset
)
1310 n
= (p
->v
.literal
.length
>= source_offset
1311 ? p
->v
.literal
.length
- source_offset
1314 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1318 /* These bits show up as zeros -- but do not cause the value
1319 to be considered optimized-out. */
1320 case DWARF_VALUE_IMPLICIT_POINTER
:
1323 case DWARF_VALUE_OPTIMIZED_OUT
:
1324 set_value_optimized_out (v
, 1);
1328 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1331 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
1332 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1333 copy_bitwise (contents
, dest_offset_bits
,
1334 intermediate_buffer
, source_offset_bits
% 8,
1335 this_size_bits
, bits_big_endian
);
1337 offset
+= this_size_bits
;
1340 do_cleanups (cleanup
);
1344 write_pieced_value (struct value
*to
, struct value
*from
)
1348 ULONGEST bits_to_skip
;
1349 const gdb_byte
*contents
;
1350 struct piece_closure
*c
1351 = (struct piece_closure
*) value_computed_closure (to
);
1352 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
1354 size_t buffer_size
= 0;
1355 char *buffer
= NULL
;
1356 struct cleanup
*cleanup
;
1358 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1362 set_value_optimized_out (to
, 1);
1366 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1368 contents
= value_contents (from
);
1369 bits_to_skip
= 8 * value_offset (to
);
1370 if (value_bitsize (to
))
1372 bits_to_skip
+= value_bitpos (to
);
1373 type_len
= value_bitsize (to
);
1376 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1378 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1380 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1381 size_t this_size_bits
, this_size
;
1382 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1384 const gdb_byte
*source_buffer
;
1386 this_size_bits
= p
->size
;
1387 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1389 bits_to_skip
-= this_size_bits
;
1392 if (this_size_bits
> type_len
- offset
)
1393 this_size_bits
= type_len
- offset
;
1394 if (bits_to_skip
> 0)
1396 dest_offset_bits
= bits_to_skip
;
1397 source_offset_bits
= 0;
1398 this_size_bits
-= bits_to_skip
;
1403 dest_offset_bits
= 0;
1404 source_offset_bits
= offset
;
1407 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1408 source_offset
= source_offset_bits
/ 8;
1409 dest_offset
= dest_offset_bits
/ 8;
1410 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1412 source_buffer
= contents
+ source_offset
;
1417 if (buffer_size
< this_size
)
1419 buffer_size
= this_size
;
1420 buffer
= xrealloc (buffer
, buffer_size
);
1422 source_buffer
= buffer
;
1426 switch (p
->location
)
1428 case DWARF_VALUE_REGISTER
:
1430 struct gdbarch
*arch
= get_frame_arch (frame
);
1431 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1432 int reg_offset
= dest_offset
;
1434 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1435 && this_size
<= register_size (arch
, gdb_regnum
))
1436 /* Big-endian, and we want less than full size. */
1437 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1439 if (gdb_regnum
!= -1)
1445 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1450 error (_("Can't do read-modify-write to "
1451 "update bitfield; containing word has been "
1454 throw_error (NOT_AVAILABLE_ERROR
,
1455 _("Can't do read-modify-write to update "
1456 "bitfield; containing word "
1459 copy_bitwise (buffer
, dest_offset_bits
,
1460 contents
, source_offset_bits
,
1465 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1466 this_size
, source_buffer
);
1470 error (_("Unable to write to DWARF register number %s"),
1471 paddress (arch
, p
->v
.regno
));
1475 case DWARF_VALUE_MEMORY
:
1478 /* Only the first and last bytes can possibly have any
1480 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
1481 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
1482 buffer
+ this_size
- 1, 1);
1483 copy_bitwise (buffer
, dest_offset_bits
,
1484 contents
, source_offset_bits
,
1489 write_memory (p
->v
.mem
.addr
+ dest_offset
,
1490 source_buffer
, this_size
);
1493 set_value_optimized_out (to
, 1);
1496 offset
+= this_size_bits
;
1499 do_cleanups (cleanup
);
1502 /* A helper function that checks bit validity in a pieced value.
1503 CHECK_FOR indicates the kind of validity checking.
1504 DWARF_VALUE_MEMORY means to check whether any bit is valid.
1505 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
1507 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
1508 implicit pointer. */
1511 check_pieced_value_bits (const struct value
*value
, int bit_offset
,
1513 enum dwarf_value_location check_for
)
1515 struct piece_closure
*c
1516 = (struct piece_closure
*) value_computed_closure (value
);
1518 int validity
= (check_for
== DWARF_VALUE_MEMORY
1519 || check_for
== DWARF_VALUE_IMPLICIT_POINTER
);
1521 bit_offset
+= 8 * value_offset (value
);
1522 if (value_bitsize (value
))
1523 bit_offset
+= value_bitpos (value
);
1525 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1527 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1528 size_t this_size_bits
= p
->size
;
1532 if (bit_offset
>= this_size_bits
)
1534 bit_offset
-= this_size_bits
;
1538 bit_length
-= this_size_bits
- bit_offset
;
1542 bit_length
-= this_size_bits
;
1544 if (check_for
== DWARF_VALUE_IMPLICIT_POINTER
)
1546 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1549 else if (p
->location
== DWARF_VALUE_OPTIMIZED_OUT
1550 || p
->location
== DWARF_VALUE_IMPLICIT_POINTER
)
1566 check_pieced_value_validity (const struct value
*value
, int bit_offset
,
1569 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1570 DWARF_VALUE_MEMORY
);
1574 check_pieced_value_invalid (const struct value
*value
)
1576 return check_pieced_value_bits (value
, 0,
1577 8 * TYPE_LENGTH (value_type (value
)),
1578 DWARF_VALUE_OPTIMIZED_OUT
);
1581 /* An implementation of an lval_funcs method to see whether a value is
1582 a synthetic pointer. */
1585 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
1588 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1589 DWARF_VALUE_IMPLICIT_POINTER
);
1592 /* A wrapper function for get_frame_address_in_block. */
1595 get_frame_address_in_block_wrapper (void *baton
)
1597 return get_frame_address_in_block (baton
);
1600 /* An implementation of an lval_funcs method to indirect through a
1601 pointer. This handles the synthetic pointer case when needed. */
1603 static struct value
*
1604 indirect_pieced_value (struct value
*value
)
1606 struct piece_closure
*c
1607 = (struct piece_closure
*) value_computed_closure (value
);
1609 struct frame_info
*frame
;
1610 struct dwarf2_locexpr_baton baton
;
1611 int i
, bit_offset
, bit_length
;
1612 struct dwarf_expr_piece
*piece
= NULL
;
1613 LONGEST byte_offset
;
1615 type
= check_typedef (value_type (value
));
1616 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1619 bit_length
= 8 * TYPE_LENGTH (type
);
1620 bit_offset
= 8 * value_offset (value
);
1621 if (value_bitsize (value
))
1622 bit_offset
+= value_bitpos (value
);
1624 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1626 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1627 size_t this_size_bits
= p
->size
;
1631 if (bit_offset
>= this_size_bits
)
1633 bit_offset
-= this_size_bits
;
1637 bit_length
-= this_size_bits
- bit_offset
;
1641 bit_length
-= this_size_bits
;
1643 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1646 if (bit_length
!= 0)
1647 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
1653 frame
= get_selected_frame (_("No frame selected."));
1655 /* This is an offset requested by GDB, such as value subcripts. */
1656 byte_offset
= value_as_address (value
);
1659 baton
= dwarf2_fetch_die_location_block (piece
->v
.ptr
.die
, c
->per_cu
,
1660 get_frame_address_in_block_wrapper
,
1663 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
1664 baton
.data
, baton
.size
, baton
.per_cu
,
1665 piece
->v
.ptr
.offset
+ byte_offset
);
1669 copy_pieced_value_closure (const struct value
*v
)
1671 struct piece_closure
*c
1672 = (struct piece_closure
*) value_computed_closure (v
);
1679 free_pieced_value_closure (struct value
*v
)
1681 struct piece_closure
*c
1682 = (struct piece_closure
*) value_computed_closure (v
);
1689 for (i
= 0; i
< c
->n_pieces
; ++i
)
1690 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1691 value_free (c
->pieces
[i
].v
.value
);
1698 /* Functions for accessing a variable described by DW_OP_piece. */
1699 static const struct lval_funcs pieced_value_funcs
= {
1702 check_pieced_value_validity
,
1703 check_pieced_value_invalid
,
1704 indirect_pieced_value
,
1705 check_pieced_synthetic_pointer
,
1706 copy_pieced_value_closure
,
1707 free_pieced_value_closure
1710 /* Helper function which throws an error if a synthetic pointer is
1714 invalid_synthetic_pointer (void)
1716 error (_("access outside bounds of object "
1717 "referenced via synthetic pointer"));
1720 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
1722 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
1724 dwarf_expr_read_reg
,
1725 dwarf_expr_read_mem
,
1726 dwarf_expr_frame_base
,
1727 dwarf_expr_frame_cfa
,
1728 dwarf_expr_frame_pc
,
1729 dwarf_expr_tls_address
,
1730 dwarf_expr_dwarf_call
,
1731 dwarf_expr_get_base_type
,
1732 dwarf_expr_push_dwarf_reg_entry_value
1735 /* Evaluate a location description, starting at DATA and with length
1736 SIZE, to find the current location of variable of TYPE in the
1737 context of FRAME. BYTE_OFFSET is applied after the contents are
1740 static struct value
*
1741 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1742 const gdb_byte
*data
, unsigned short size
,
1743 struct dwarf2_per_cu_data
*per_cu
,
1744 LONGEST byte_offset
)
1746 struct value
*retval
;
1747 struct dwarf_expr_baton baton
;
1748 struct dwarf_expr_context
*ctx
;
1749 struct cleanup
*old_chain
, *value_chain
;
1750 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
1751 volatile struct gdb_exception ex
;
1753 if (byte_offset
< 0)
1754 invalid_synthetic_pointer ();
1757 return allocate_optimized_out_value (type
);
1759 baton
.frame
= frame
;
1760 baton
.per_cu
= per_cu
;
1762 ctx
= new_dwarf_expr_context ();
1763 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
1764 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
1766 ctx
->gdbarch
= get_objfile_arch (objfile
);
1767 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
1768 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
1769 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
1770 ctx
->baton
= &baton
;
1771 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
1773 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1775 dwarf_expr_eval (ctx
, data
, size
);
1779 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1781 do_cleanups (old_chain
);
1782 retval
= allocate_value (type
);
1783 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
1786 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1788 if (entry_values_debug
)
1789 exception_print (gdb_stdout
, ex
);
1790 do_cleanups (old_chain
);
1791 return allocate_optimized_out_value (type
);
1794 throw_exception (ex
);
1797 if (ctx
->num_pieces
> 0)
1799 struct piece_closure
*c
;
1800 struct frame_id frame_id
= get_frame_id (frame
);
1801 ULONGEST bit_size
= 0;
1804 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
1805 bit_size
+= ctx
->pieces
[i
].size
;
1806 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
1807 invalid_synthetic_pointer ();
1809 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
1811 /* We must clean up the value chain after creating the piece
1812 closure but before allocating the result. */
1813 do_cleanups (value_chain
);
1814 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
1815 VALUE_FRAME_ID (retval
) = frame_id
;
1816 set_value_offset (retval
, byte_offset
);
1820 switch (ctx
->location
)
1822 case DWARF_VALUE_REGISTER
:
1824 struct gdbarch
*arch
= get_frame_arch (frame
);
1825 ULONGEST dwarf_regnum
= value_as_long (dwarf_expr_fetch (ctx
, 0));
1826 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
1828 if (byte_offset
!= 0)
1829 error (_("cannot use offset on synthetic pointer to register"));
1830 do_cleanups (value_chain
);
1831 if (gdb_regnum
!= -1)
1832 retval
= value_from_register (type
, gdb_regnum
, frame
);
1834 error (_("Unable to access DWARF register number %s"),
1835 paddress (arch
, dwarf_regnum
));
1839 case DWARF_VALUE_MEMORY
:
1841 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
1842 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
1844 do_cleanups (value_chain
);
1845 retval
= allocate_value_lazy (type
);
1846 VALUE_LVAL (retval
) = lval_memory
;
1847 if (in_stack_memory
)
1848 set_value_stack (retval
, 1);
1849 set_value_address (retval
, address
+ byte_offset
);
1853 case DWARF_VALUE_STACK
:
1855 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
1857 const gdb_byte
*val_bytes
;
1858 size_t n
= TYPE_LENGTH (value_type (value
));
1860 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1861 invalid_synthetic_pointer ();
1863 val_bytes
= value_contents_all (value
);
1864 val_bytes
+= byte_offset
;
1867 /* Preserve VALUE because we are going to free values back
1868 to the mark, but we still need the value contents
1870 value_incref (value
);
1871 do_cleanups (value_chain
);
1872 make_cleanup_value_free (value
);
1874 retval
= allocate_value (type
);
1875 contents
= value_contents_raw (retval
);
1876 if (n
> TYPE_LENGTH (type
))
1878 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1880 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1881 val_bytes
+= n
- TYPE_LENGTH (type
);
1882 n
= TYPE_LENGTH (type
);
1884 memcpy (contents
, val_bytes
, n
);
1888 case DWARF_VALUE_LITERAL
:
1891 const bfd_byte
*ldata
;
1892 size_t n
= ctx
->len
;
1894 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
1895 invalid_synthetic_pointer ();
1897 do_cleanups (value_chain
);
1898 retval
= allocate_value (type
);
1899 contents
= value_contents_raw (retval
);
1901 ldata
= ctx
->data
+ byte_offset
;
1904 if (n
> TYPE_LENGTH (type
))
1906 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1908 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1909 ldata
+= n
- TYPE_LENGTH (type
);
1910 n
= TYPE_LENGTH (type
);
1912 memcpy (contents
, ldata
, n
);
1916 case DWARF_VALUE_OPTIMIZED_OUT
:
1917 do_cleanups (value_chain
);
1918 retval
= allocate_optimized_out_value (type
);
1921 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1922 operation by execute_stack_op. */
1923 case DWARF_VALUE_IMPLICIT_POINTER
:
1924 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1925 it can only be encountered when making a piece. */
1927 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1931 set_value_initialized (retval
, ctx
->initialized
);
1933 do_cleanups (old_chain
);
1938 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1939 passes 0 as the byte_offset. */
1942 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1943 const gdb_byte
*data
, unsigned short size
,
1944 struct dwarf2_per_cu_data
*per_cu
)
1946 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
1950 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
1952 struct needs_frame_baton
1955 struct dwarf2_per_cu_data
*per_cu
;
1958 /* Reads from registers do require a frame. */
1960 needs_frame_read_reg (void *baton
, int regnum
)
1962 struct needs_frame_baton
*nf_baton
= baton
;
1964 nf_baton
->needs_frame
= 1;
1968 /* Reads from memory do not require a frame. */
1970 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
1972 memset (buf
, 0, len
);
1975 /* Frame-relative accesses do require a frame. */
1977 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
1979 static gdb_byte lit0
= DW_OP_lit0
;
1980 struct needs_frame_baton
*nf_baton
= baton
;
1985 nf_baton
->needs_frame
= 1;
1988 /* CFA accesses require a frame. */
1991 needs_frame_frame_cfa (void *baton
)
1993 struct needs_frame_baton
*nf_baton
= baton
;
1995 nf_baton
->needs_frame
= 1;
1999 /* Thread-local accesses do require a frame. */
2001 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
2003 struct needs_frame_baton
*nf_baton
= baton
;
2005 nf_baton
->needs_frame
= 1;
2009 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
2012 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, size_t die_offset
)
2014 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2016 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
2017 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
2020 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2023 needs_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
2024 int dwarf_reg
, CORE_ADDR fb_offset
)
2026 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2028 nf_baton
->needs_frame
= 1;
2031 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
2033 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs
=
2035 needs_frame_read_reg
,
2036 needs_frame_read_mem
,
2037 needs_frame_frame_base
,
2038 needs_frame_frame_cfa
,
2039 needs_frame_frame_cfa
, /* get_frame_pc */
2040 needs_frame_tls_address
,
2041 needs_frame_dwarf_call
,
2042 NULL
, /* get_base_type */
2043 needs_dwarf_reg_entry_value
2046 /* Return non-zero iff the location expression at DATA (length SIZE)
2047 requires a frame to evaluate. */
2050 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, unsigned short size
,
2051 struct dwarf2_per_cu_data
*per_cu
)
2053 struct needs_frame_baton baton
;
2054 struct dwarf_expr_context
*ctx
;
2056 struct cleanup
*old_chain
;
2057 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2059 baton
.needs_frame
= 0;
2060 baton
.per_cu
= per_cu
;
2062 ctx
= new_dwarf_expr_context ();
2063 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2064 make_cleanup_value_free_to_mark (value_mark ());
2066 ctx
->gdbarch
= get_objfile_arch (objfile
);
2067 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2068 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2069 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2070 ctx
->baton
= &baton
;
2071 ctx
->funcs
= &needs_frame_ctx_funcs
;
2073 dwarf_expr_eval (ctx
, data
, size
);
2075 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
2077 if (ctx
->num_pieces
> 0)
2081 /* If the location has several pieces, and any of them are in
2082 registers, then we will need a frame to fetch them from. */
2083 for (i
= 0; i
< ctx
->num_pieces
; i
++)
2084 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2088 do_cleanups (old_chain
);
2090 return baton
.needs_frame
|| in_reg
;
2093 /* A helper function that throws an unimplemented error mentioning a
2094 given DWARF operator. */
2097 unimplemented (unsigned int op
)
2099 const char *name
= dwarf_stack_op_name (op
);
2102 error (_("DWARF operator %s cannot be translated to an agent expression"),
2105 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2106 "to an agent expression"),
2110 /* A helper function to convert a DWARF register to an arch register.
2111 ARCH is the architecture.
2112 DWARF_REG is the register.
2113 This will throw an exception if the DWARF register cannot be
2114 translated to an architecture register. */
2117 translate_register (struct gdbarch
*arch
, int dwarf_reg
)
2119 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2121 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
2125 /* A helper function that emits an access to memory. ARCH is the
2126 target architecture. EXPR is the expression which we are building.
2127 NBITS is the number of bits we want to read. This emits the
2128 opcodes needed to read the memory and then extract the desired
2132 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2134 ULONGEST nbytes
= (nbits
+ 7) / 8;
2136 gdb_assert (nbits
> 0 && nbits
<= sizeof (LONGEST
));
2139 ax_trace_quick (expr
, nbytes
);
2142 ax_simple (expr
, aop_ref8
);
2143 else if (nbits
<= 16)
2144 ax_simple (expr
, aop_ref16
);
2145 else if (nbits
<= 32)
2146 ax_simple (expr
, aop_ref32
);
2148 ax_simple (expr
, aop_ref64
);
2150 /* If we read exactly the number of bytes we wanted, we're done. */
2151 if (8 * nbytes
== nbits
)
2154 if (gdbarch_bits_big_endian (arch
))
2156 /* On a bits-big-endian machine, we want the high-order
2158 ax_const_l (expr
, 8 * nbytes
- nbits
);
2159 ax_simple (expr
, aop_rsh_unsigned
);
2163 /* On a bits-little-endian box, we want the low-order NBITS. */
2164 ax_zero_ext (expr
, nbits
);
2168 /* A helper function to return the frame's PC. */
2171 get_ax_pc (void *baton
)
2173 struct agent_expr
*expr
= baton
;
2178 /* Compile a DWARF location expression to an agent expression.
2180 EXPR is the agent expression we are building.
2181 LOC is the agent value we modify.
2182 ARCH is the architecture.
2183 ADDR_SIZE is the size of addresses, in bytes.
2184 OP_PTR is the start of the location expression.
2185 OP_END is one past the last byte of the location expression.
2187 This will throw an exception for various kinds of errors -- for
2188 example, if the expression cannot be compiled, or if the expression
2192 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2193 struct gdbarch
*arch
, unsigned int addr_size
,
2194 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
2195 struct dwarf2_per_cu_data
*per_cu
)
2197 struct cleanup
*cleanups
;
2199 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
2200 const gdb_byte
* const base
= op_ptr
;
2201 const gdb_byte
*previous_piece
= op_ptr
;
2202 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2203 ULONGEST bits_collected
= 0;
2204 unsigned int addr_size_bits
= 8 * addr_size
;
2205 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
2207 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
2208 cleanups
= make_cleanup (xfree
, offsets
);
2210 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
2213 make_cleanup (VEC_cleanup (int), &dw_labels
);
2214 make_cleanup (VEC_cleanup (int), &patches
);
2216 /* By default we are making an address. */
2217 loc
->kind
= axs_lvalue_memory
;
2219 while (op_ptr
< op_end
)
2221 enum dwarf_location_atom op
= *op_ptr
;
2222 ULONGEST uoffset
, reg
;
2226 offsets
[op_ptr
- base
] = expr
->len
;
2229 /* Our basic approach to code generation is to map DWARF
2230 operations directly to AX operations. However, there are
2233 First, DWARF works on address-sized units, but AX always uses
2234 LONGEST. For most operations we simply ignore this
2235 difference; instead we generate sign extensions as needed
2236 before division and comparison operations. It would be nice
2237 to omit the sign extensions, but there is no way to determine
2238 the size of the target's LONGEST. (This code uses the size
2239 of the host LONGEST in some cases -- that is a bug but it is
2242 Second, some DWARF operations cannot be translated to AX.
2243 For these we simply fail. See
2244 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2279 ax_const_l (expr
, op
- DW_OP_lit0
);
2283 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2284 op_ptr
+= addr_size
;
2285 /* Some versions of GCC emit DW_OP_addr before
2286 DW_OP_GNU_push_tls_address. In this case the value is an
2287 index, not an address. We don't support things like
2288 branching between the address and the TLS op. */
2289 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2290 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
2291 ax_const_l (expr
, uoffset
);
2295 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2299 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2303 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2307 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2311 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2315 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2319 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2323 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2327 op_ptr
= read_uleb128 (op_ptr
, op_end
, &uoffset
);
2328 ax_const_l (expr
, uoffset
);
2331 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
2332 ax_const_l (expr
, offset
);
2367 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2368 loc
->u
.reg
= translate_register (arch
, op
- DW_OP_reg0
);
2369 loc
->kind
= axs_lvalue_register
;
2373 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
2374 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2375 loc
->u
.reg
= translate_register (arch
, reg
);
2376 loc
->kind
= axs_lvalue_register
;
2379 case DW_OP_implicit_value
:
2383 op_ptr
= read_uleb128 (op_ptr
, op_end
, &len
);
2384 if (op_ptr
+ len
> op_end
)
2385 error (_("DW_OP_implicit_value: too few bytes available."));
2386 if (len
> sizeof (ULONGEST
))
2387 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2390 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2393 dwarf_expr_require_composition (op_ptr
, op_end
,
2394 "DW_OP_implicit_value");
2396 loc
->kind
= axs_rvalue
;
2400 case DW_OP_stack_value
:
2401 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2402 loc
->kind
= axs_rvalue
;
2437 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
2438 i
= translate_register (arch
, op
- DW_OP_breg0
);
2442 ax_const_l (expr
, offset
);
2443 ax_simple (expr
, aop_add
);
2448 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
2449 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
2450 i
= translate_register (arch
, reg
);
2454 ax_const_l (expr
, offset
);
2455 ax_simple (expr
, aop_add
);
2461 const gdb_byte
*datastart
;
2463 unsigned int before_stack_len
;
2465 struct symbol
*framefunc
;
2466 LONGEST base_offset
= 0;
2468 b
= block_for_pc (expr
->scope
);
2471 error (_("No block found for address"));
2473 framefunc
= block_linkage_function (b
);
2476 error (_("No function found for block"));
2478 dwarf_expr_frame_base_1 (framefunc
, expr
->scope
,
2479 &datastart
, &datalen
);
2481 op_ptr
= read_sleb128 (op_ptr
, op_end
, &offset
);
2482 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
2483 datastart
+ datalen
, per_cu
);
2487 ax_const_l (expr
, offset
);
2488 ax_simple (expr
, aop_add
);
2491 loc
->kind
= axs_lvalue_memory
;
2496 ax_simple (expr
, aop_dup
);
2500 ax_simple (expr
, aop_pop
);
2505 ax_pick (expr
, offset
);
2509 ax_simple (expr
, aop_swap
);
2517 ax_simple (expr
, aop_rot
);
2521 case DW_OP_deref_size
:
2525 if (op
== DW_OP_deref_size
)
2533 ax_simple (expr
, aop_ref8
);
2536 ax_simple (expr
, aop_ref16
);
2539 ax_simple (expr
, aop_ref32
);
2542 ax_simple (expr
, aop_ref64
);
2545 /* Note that dwarf_stack_op_name will never return
2547 error (_("Unsupported size %d in %s"),
2548 size
, dwarf_stack_op_name (op
));
2554 /* Sign extend the operand. */
2555 ax_ext (expr
, addr_size_bits
);
2556 ax_simple (expr
, aop_dup
);
2557 ax_const_l (expr
, 0);
2558 ax_simple (expr
, aop_less_signed
);
2559 ax_simple (expr
, aop_log_not
);
2560 i
= ax_goto (expr
, aop_if_goto
);
2561 /* We have to emit 0 - X. */
2562 ax_const_l (expr
, 0);
2563 ax_simple (expr
, aop_swap
);
2564 ax_simple (expr
, aop_sub
);
2565 ax_label (expr
, i
, expr
->len
);
2569 /* No need to sign extend here. */
2570 ax_const_l (expr
, 0);
2571 ax_simple (expr
, aop_swap
);
2572 ax_simple (expr
, aop_sub
);
2576 /* Sign extend the operand. */
2577 ax_ext (expr
, addr_size_bits
);
2578 ax_simple (expr
, aop_bit_not
);
2581 case DW_OP_plus_uconst
:
2582 op_ptr
= read_uleb128 (op_ptr
, op_end
, ®
);
2583 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2584 but we micro-optimize anyhow. */
2587 ax_const_l (expr
, reg
);
2588 ax_simple (expr
, aop_add
);
2593 ax_simple (expr
, aop_bit_and
);
2597 /* Sign extend the operands. */
2598 ax_ext (expr
, addr_size_bits
);
2599 ax_simple (expr
, aop_swap
);
2600 ax_ext (expr
, addr_size_bits
);
2601 ax_simple (expr
, aop_swap
);
2602 ax_simple (expr
, aop_div_signed
);
2606 ax_simple (expr
, aop_sub
);
2610 ax_simple (expr
, aop_rem_unsigned
);
2614 ax_simple (expr
, aop_mul
);
2618 ax_simple (expr
, aop_bit_or
);
2622 ax_simple (expr
, aop_add
);
2626 ax_simple (expr
, aop_lsh
);
2630 ax_simple (expr
, aop_rsh_unsigned
);
2634 ax_simple (expr
, aop_rsh_signed
);
2638 ax_simple (expr
, aop_bit_xor
);
2642 /* Sign extend the operands. */
2643 ax_ext (expr
, addr_size_bits
);
2644 ax_simple (expr
, aop_swap
);
2645 ax_ext (expr
, addr_size_bits
);
2646 /* Note no swap here: A <= B is !(B < A). */
2647 ax_simple (expr
, aop_less_signed
);
2648 ax_simple (expr
, aop_log_not
);
2652 /* Sign extend the operands. */
2653 ax_ext (expr
, addr_size_bits
);
2654 ax_simple (expr
, aop_swap
);
2655 ax_ext (expr
, addr_size_bits
);
2656 ax_simple (expr
, aop_swap
);
2657 /* A >= B is !(A < B). */
2658 ax_simple (expr
, aop_less_signed
);
2659 ax_simple (expr
, aop_log_not
);
2663 /* Sign extend the operands. */
2664 ax_ext (expr
, addr_size_bits
);
2665 ax_simple (expr
, aop_swap
);
2666 ax_ext (expr
, addr_size_bits
);
2667 /* No need for a second swap here. */
2668 ax_simple (expr
, aop_equal
);
2672 /* Sign extend the operands. */
2673 ax_ext (expr
, addr_size_bits
);
2674 ax_simple (expr
, aop_swap
);
2675 ax_ext (expr
, addr_size_bits
);
2676 ax_simple (expr
, aop_swap
);
2677 ax_simple (expr
, aop_less_signed
);
2681 /* Sign extend the operands. */
2682 ax_ext (expr
, addr_size_bits
);
2683 ax_simple (expr
, aop_swap
);
2684 ax_ext (expr
, addr_size_bits
);
2685 /* Note no swap here: A > B is B < A. */
2686 ax_simple (expr
, aop_less_signed
);
2690 /* Sign extend the operands. */
2691 ax_ext (expr
, addr_size_bits
);
2692 ax_simple (expr
, aop_swap
);
2693 ax_ext (expr
, addr_size_bits
);
2694 /* No need for a swap here. */
2695 ax_simple (expr
, aop_equal
);
2696 ax_simple (expr
, aop_log_not
);
2699 case DW_OP_call_frame_cfa
:
2700 dwarf2_compile_cfa_to_ax (expr
, loc
, arch
, expr
->scope
, per_cu
);
2701 loc
->kind
= axs_lvalue_memory
;
2704 case DW_OP_GNU_push_tls_address
:
2709 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2711 i
= ax_goto (expr
, aop_goto
);
2712 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
2713 VEC_safe_push (int, patches
, i
);
2717 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2719 /* Zero extend the operand. */
2720 ax_zero_ext (expr
, addr_size_bits
);
2721 i
= ax_goto (expr
, aop_if_goto
);
2722 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
2723 VEC_safe_push (int, patches
, i
);
2730 case DW_OP_bit_piece
:
2732 ULONGEST size
, offset
;
2734 if (op_ptr
- 1 == previous_piece
)
2735 error (_("Cannot translate empty pieces to agent expressions"));
2736 previous_piece
= op_ptr
- 1;
2738 op_ptr
= read_uleb128 (op_ptr
, op_end
, &size
);
2739 if (op
== DW_OP_piece
)
2745 op_ptr
= read_uleb128 (op_ptr
, op_end
, &offset
);
2747 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2748 error (_("Expression pieces exceed word size"));
2750 /* Access the bits. */
2753 case axs_lvalue_register
:
2754 ax_reg (expr
, loc
->u
.reg
);
2757 case axs_lvalue_memory
:
2758 /* Offset the pointer, if needed. */
2761 ax_const_l (expr
, offset
/ 8);
2762 ax_simple (expr
, aop_add
);
2765 access_memory (arch
, expr
, size
);
2769 /* For a bits-big-endian target, shift up what we already
2770 have. For a bits-little-endian target, shift up the
2771 new data. Note that there is a potential bug here if
2772 the DWARF expression leaves multiple values on the
2774 if (bits_collected
> 0)
2776 if (bits_big_endian
)
2778 ax_simple (expr
, aop_swap
);
2779 ax_const_l (expr
, size
);
2780 ax_simple (expr
, aop_lsh
);
2781 /* We don't need a second swap here, because
2782 aop_bit_or is symmetric. */
2786 ax_const_l (expr
, size
);
2787 ax_simple (expr
, aop_lsh
);
2789 ax_simple (expr
, aop_bit_or
);
2792 bits_collected
+= size
;
2793 loc
->kind
= axs_rvalue
;
2797 case DW_OP_GNU_uninit
:
2803 struct dwarf2_locexpr_baton block
;
2804 int size
= (op
== DW_OP_call2
? 2 : 4);
2806 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2809 block
= dwarf2_fetch_die_location_block (uoffset
, per_cu
,
2812 /* DW_OP_call_ref is currently not supported. */
2813 gdb_assert (block
.per_cu
== per_cu
);
2815 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
2816 block
.data
, block
.data
+ block
.size
,
2821 case DW_OP_call_ref
:
2829 /* Patch all the branches we emitted. */
2830 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
2832 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
2834 internal_error (__FILE__
, __LINE__
, _("invalid label"));
2835 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
2838 do_cleanups (cleanups
);
2842 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
2843 evaluator to calculate the location. */
2844 static struct value
*
2845 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
2847 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2850 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
2851 dlbaton
->size
, dlbaton
->per_cu
);
2856 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
2858 locexpr_read_needs_frame (struct symbol
*symbol
)
2860 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
2862 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
2866 /* Return true if DATA points to the end of a piece. END is one past
2867 the last byte in the expression. */
2870 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
2872 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
2875 /* Helper for locexpr_describe_location_piece that finds the name of a
2879 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
2883 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
2884 return gdbarch_register_name (gdbarch
, regnum
);
2887 /* Nicely describe a single piece of a location, returning an updated
2888 position in the bytecode sequence. This function cannot recognize
2889 all locations; if a location is not recognized, it simply returns
2892 static const gdb_byte
*
2893 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
2894 CORE_ADDR addr
, struct objfile
*objfile
,
2895 const gdb_byte
*data
, const gdb_byte
*end
,
2896 unsigned int addr_size
)
2898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2900 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
2902 fprintf_filtered (stream
, _("a variable in $%s"),
2903 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
2906 else if (data
[0] == DW_OP_regx
)
2910 data
= read_uleb128 (data
+ 1, end
, ®
);
2911 fprintf_filtered (stream
, _("a variable in $%s"),
2912 locexpr_regname (gdbarch
, reg
));
2914 else if (data
[0] == DW_OP_fbreg
)
2917 struct symbol
*framefunc
;
2919 LONGEST frame_offset
;
2920 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
2922 LONGEST base_offset
= 0;
2924 new_data
= read_sleb128 (data
+ 1, end
, &frame_offset
);
2925 if (!piece_end_p (new_data
, end
))
2929 b
= block_for_pc (addr
);
2932 error (_("No block found for address for symbol \"%s\"."),
2933 SYMBOL_PRINT_NAME (symbol
));
2935 framefunc
= block_linkage_function (b
);
2938 error (_("No function found for block for symbol \"%s\"."),
2939 SYMBOL_PRINT_NAME (symbol
));
2941 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
2943 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
2945 const gdb_byte
*buf_end
;
2947 frame_reg
= base_data
[0] - DW_OP_breg0
;
2948 buf_end
= read_sleb128 (base_data
+ 1,
2949 base_data
+ base_size
, &base_offset
);
2950 if (buf_end
!= base_data
+ base_size
)
2951 error (_("Unexpected opcode after "
2952 "DW_OP_breg%u for symbol \"%s\"."),
2953 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
2955 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
2957 /* The frame base is just the register, with no offset. */
2958 frame_reg
= base_data
[0] - DW_OP_reg0
;
2963 /* We don't know what to do with the frame base expression,
2964 so we can't trace this variable; give up. */
2968 fprintf_filtered (stream
,
2969 _("a variable at frame base reg $%s offset %s+%s"),
2970 locexpr_regname (gdbarch
, frame_reg
),
2971 plongest (base_offset
), plongest (frame_offset
));
2973 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
2974 && piece_end_p (data
, end
))
2978 data
= read_sleb128 (data
+ 1, end
, &offset
);
2980 fprintf_filtered (stream
,
2981 _("a variable at offset %s from base reg $%s"),
2983 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
2986 /* The location expression for a TLS variable looks like this (on a
2989 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
2990 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
2992 0x3 is the encoding for DW_OP_addr, which has an operand as long
2993 as the size of an address on the target machine (here is 8
2994 bytes). Note that more recent version of GCC emit DW_OP_const4u
2995 or DW_OP_const8u, depending on address size, rather than
2996 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
2997 The operand represents the offset at which the variable is within
2998 the thread local storage. */
3000 else if (data
+ 1 + addr_size
< end
3001 && (data
[0] == DW_OP_addr
3002 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3003 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3004 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3005 && piece_end_p (data
+ 2 + addr_size
, end
))
3008 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3009 gdbarch_byte_order (gdbarch
));
3011 fprintf_filtered (stream
,
3012 _("a thread-local variable at offset 0x%s "
3013 "in the thread-local storage for `%s'"),
3014 phex_nz (offset
, addr_size
), objfile
->name
);
3016 data
+= 1 + addr_size
+ 1;
3018 else if (data
[0] >= DW_OP_lit0
3019 && data
[0] <= DW_OP_lit31
3021 && data
[1] == DW_OP_stack_value
)
3023 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3030 /* Disassemble an expression, stopping at the end of a piece or at the
3031 end of the expression. Returns a pointer to the next unread byte
3032 in the input expression. If ALL is nonzero, then this function
3033 will keep going until it reaches the end of the expression. */
3035 static const gdb_byte
*
3036 disassemble_dwarf_expression (struct ui_file
*stream
,
3037 struct gdbarch
*arch
, unsigned int addr_size
,
3039 const gdb_byte
*data
, const gdb_byte
*end
,
3041 struct dwarf2_per_cu_data
*per_cu
)
3043 const gdb_byte
*start
= data
;
3045 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3049 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3051 enum dwarf_location_atom op
= *data
++;
3056 name
= dwarf_stack_op_name (op
);
3059 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3060 op
, (long) (data
- 1 - start
));
3061 fprintf_filtered (stream
, " % 4ld: %s", (long) (data
- 1 - start
), name
);
3066 ul
= extract_unsigned_integer (data
, addr_size
,
3067 gdbarch_byte_order (arch
));
3069 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3073 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3075 fprintf_filtered (stream
, " %s", pulongest (ul
));
3078 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3080 fprintf_filtered (stream
, " %s", plongest (l
));
3083 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3085 fprintf_filtered (stream
, " %s", pulongest (ul
));
3088 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3090 fprintf_filtered (stream
, " %s", plongest (l
));
3093 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3095 fprintf_filtered (stream
, " %s", pulongest (ul
));
3098 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3100 fprintf_filtered (stream
, " %s", plongest (l
));
3103 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3105 fprintf_filtered (stream
, " %s", pulongest (ul
));
3108 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3110 fprintf_filtered (stream
, " %s", plongest (l
));
3113 data
= read_uleb128 (data
, end
, &ul
);
3114 fprintf_filtered (stream
, " %s", pulongest (ul
));
3117 data
= read_sleb128 (data
, end
, &l
);
3118 fprintf_filtered (stream
, " %s", plongest (l
));
3153 fprintf_filtered (stream
, " [$%s]",
3154 locexpr_regname (arch
, op
- DW_OP_reg0
));
3158 data
= read_uleb128 (data
, end
, &ul
);
3159 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3160 locexpr_regname (arch
, (int) ul
));
3163 case DW_OP_implicit_value
:
3164 data
= read_uleb128 (data
, end
, &ul
);
3166 fprintf_filtered (stream
, " %s", pulongest (ul
));
3201 data
= read_sleb128 (data
, end
, &l
);
3202 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3203 locexpr_regname (arch
, op
- DW_OP_breg0
));
3207 data
= read_uleb128 (data
, end
, &ul
);
3208 data
= read_sleb128 (data
, end
, &l
);
3209 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3211 locexpr_regname (arch
, (int) ul
),
3216 data
= read_sleb128 (data
, end
, &l
);
3217 fprintf_filtered (stream
, " %s", plongest (l
));
3220 case DW_OP_xderef_size
:
3221 case DW_OP_deref_size
:
3223 fprintf_filtered (stream
, " %d", *data
);
3227 case DW_OP_plus_uconst
:
3228 data
= read_uleb128 (data
, end
, &ul
);
3229 fprintf_filtered (stream
, " %s", pulongest (ul
));
3233 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3235 fprintf_filtered (stream
, " to %ld",
3236 (long) (data
+ l
- start
));
3240 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3242 fprintf_filtered (stream
, " %ld",
3243 (long) (data
+ l
- start
));
3247 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3249 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3253 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3255 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3258 case DW_OP_call_ref
:
3259 ul
= extract_unsigned_integer (data
, offset_size
,
3260 gdbarch_byte_order (arch
));
3261 data
+= offset_size
;
3262 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3266 data
= read_uleb128 (data
, end
, &ul
);
3267 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3270 case DW_OP_bit_piece
:
3274 data
= read_uleb128 (data
, end
, &ul
);
3275 data
= read_uleb128 (data
, end
, &offset
);
3276 fprintf_filtered (stream
, " size %s offset %s (bits)",
3277 pulongest (ul
), pulongest (offset
));
3281 case DW_OP_GNU_implicit_pointer
:
3283 ul
= extract_unsigned_integer (data
, offset_size
,
3284 gdbarch_byte_order (arch
));
3285 data
+= offset_size
;
3287 data
= read_sleb128 (data
, end
, &l
);
3289 fprintf_filtered (stream
, " DIE %s offset %s",
3290 phex_nz (ul
, offset_size
),
3295 case DW_OP_GNU_deref_type
:
3297 int addr_size
= *data
++;
3301 data
= read_uleb128 (data
, end
, &offset
);
3302 type
= dwarf2_get_die_type (offset
, per_cu
);
3303 fprintf_filtered (stream
, "<");
3304 type_print (type
, "", stream
, -1);
3305 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
, 0),
3310 case DW_OP_GNU_const_type
:
3315 data
= read_uleb128 (data
, end
, &type_die
);
3316 type
= dwarf2_get_die_type (type_die
, per_cu
);
3317 fprintf_filtered (stream
, "<");
3318 type_print (type
, "", stream
, -1);
3319 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
, 0));
3323 case DW_OP_GNU_regval_type
:
3325 ULONGEST type_die
, reg
;
3328 data
= read_uleb128 (data
, end
, ®
);
3329 data
= read_uleb128 (data
, end
, &type_die
);
3331 type
= dwarf2_get_die_type (type_die
, per_cu
);
3332 fprintf_filtered (stream
, "<");
3333 type_print (type
, "", stream
, -1);
3334 fprintf_filtered (stream
, " [0x%s]> [$%s]", phex_nz (type_die
, 0),
3335 locexpr_regname (arch
, reg
));
3339 case DW_OP_GNU_convert
:
3340 case DW_OP_GNU_reinterpret
:
3344 data
= read_uleb128 (data
, end
, &type_die
);
3347 fprintf_filtered (stream
, "<0>");
3352 type
= dwarf2_get_die_type (type_die
, per_cu
);
3353 fprintf_filtered (stream
, "<");
3354 type_print (type
, "", stream
, -1);
3355 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
, 0));
3361 fprintf_filtered (stream
, "\n");
3367 /* Describe a single location, which may in turn consist of multiple
3371 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3372 struct ui_file
*stream
,
3373 const gdb_byte
*data
, int size
,
3374 struct objfile
*objfile
, unsigned int addr_size
,
3375 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
3377 const gdb_byte
*end
= data
+ size
;
3378 int first_piece
= 1, bad
= 0;
3382 const gdb_byte
*here
= data
;
3383 int disassemble
= 1;
3388 fprintf_filtered (stream
, _(", and "));
3390 if (!dwarf2_always_disassemble
)
3392 data
= locexpr_describe_location_piece (symbol
, stream
,
3394 data
, end
, addr_size
);
3395 /* If we printed anything, or if we have an empty piece,
3396 then don't disassemble. */
3398 || data
[0] == DW_OP_piece
3399 || data
[0] == DW_OP_bit_piece
)
3403 data
= disassemble_dwarf_expression (stream
,
3404 get_objfile_arch (objfile
),
3405 addr_size
, offset_size
, data
, end
,
3406 dwarf2_always_disassemble
,
3411 int empty
= data
== here
;
3414 fprintf_filtered (stream
, " ");
3415 if (data
[0] == DW_OP_piece
)
3419 data
= read_uleb128 (data
+ 1, end
, &bytes
);
3422 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3425 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3428 else if (data
[0] == DW_OP_bit_piece
)
3430 ULONGEST bits
, offset
;
3432 data
= read_uleb128 (data
+ 1, end
, &bits
);
3433 data
= read_uleb128 (data
, end
, &offset
);
3436 fprintf_filtered (stream
,
3437 _("an empty %s-bit piece"),
3440 fprintf_filtered (stream
,
3441 _(" [%s-bit piece, offset %s bits]"),
3442 pulongest (bits
), pulongest (offset
));
3452 if (bad
|| data
> end
)
3453 error (_("Corrupted DWARF2 expression for \"%s\"."),
3454 SYMBOL_PRINT_NAME (symbol
));
3457 /* Print a natural-language description of SYMBOL to STREAM. This
3458 version is for a symbol with a single location. */
3461 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3462 struct ui_file
*stream
)
3464 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3465 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
3466 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3467 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
3469 locexpr_describe_location_1 (symbol
, addr
, stream
,
3470 dlbaton
->data
, dlbaton
->size
,
3471 objfile
, addr_size
, offset_size
,
3475 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3476 any necessary bytecode in AX. */
3479 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
3480 struct agent_expr
*ax
, struct axs_value
*value
)
3482 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3483 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3485 if (dlbaton
->data
== NULL
|| dlbaton
->size
== 0)
3486 value
->optimized_out
= 1;
3488 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
3489 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3493 /* The set of location functions used with the DWARF-2 expression
3495 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3496 locexpr_read_variable
,
3497 locexpr_read_needs_frame
,
3498 locexpr_describe_location
,
3499 locexpr_tracepoint_var_ref
3503 /* Wrapper functions for location lists. These generally find
3504 the appropriate location expression and call something above. */
3506 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3507 evaluator to calculate the location. */
3508 static struct value
*
3509 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3511 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3513 const gdb_byte
*data
;
3515 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3517 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3519 val
= allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
3521 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
3527 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3529 loclist_read_needs_frame (struct symbol
*symbol
)
3531 /* If there's a location list, then assume we need to have a frame
3532 to choose the appropriate location expression. With tracking of
3533 global variables this is not necessarily true, but such tracking
3534 is disabled in GCC at the moment until we figure out how to
3540 /* Print a natural-language description of SYMBOL to STREAM. This
3541 version applies when there is a list of different locations, each
3542 with a specified address range. */
3545 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3546 struct ui_file
*stream
)
3548 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3549 CORE_ADDR low
, high
;
3550 const gdb_byte
*loc_ptr
, *buf_end
;
3551 int length
, first
= 1;
3552 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
3553 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3554 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3555 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3556 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
3557 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3558 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3559 /* Adjust base_address for relocatable objects. */
3560 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
3561 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
3563 loc_ptr
= dlbaton
->data
;
3564 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3566 fprintf_filtered (stream
, _("multi-location:\n"));
3568 /* Iterate through locations until we run out. */
3571 if (buf_end
- loc_ptr
< 2 * addr_size
)
3572 error (_("Corrupted DWARF expression for symbol \"%s\"."),
3573 SYMBOL_PRINT_NAME (symbol
));
3576 low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
3578 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
3579 loc_ptr
+= addr_size
;
3582 high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
3584 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
3585 loc_ptr
+= addr_size
;
3587 /* A base-address-selection entry. */
3588 if ((low
& base_mask
) == base_mask
)
3590 base_address
= high
+ base_offset
;
3591 fprintf_filtered (stream
, _(" Base address %s"),
3592 paddress (gdbarch
, base_address
));
3596 /* An end-of-list entry. */
3597 if (low
== 0 && high
== 0)
3600 /* Otherwise, a location expression entry. */
3601 low
+= base_address
;
3602 high
+= base_address
;
3604 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
3607 /* (It would improve readability to print only the minimum
3608 necessary digits of the second number of the range.) */
3609 fprintf_filtered (stream
, _(" Range %s-%s: "),
3610 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
3612 /* Now describe this particular location. */
3613 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
3614 objfile
, addr_size
, offset_size
,
3617 fprintf_filtered (stream
, "\n");
3623 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3624 any necessary bytecode in AX. */
3626 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
3627 struct agent_expr
*ax
, struct axs_value
*value
)
3629 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3630 const gdb_byte
*data
;
3632 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3634 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
3635 if (data
== NULL
|| size
== 0)
3636 value
->optimized_out
= 1;
3638 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
3642 /* The set of location functions used with the DWARF-2 expression
3643 evaluator and location lists. */
3644 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
3645 loclist_read_variable
,
3646 loclist_read_needs_frame
,
3647 loclist_describe_location
,
3648 loclist_tracepoint_var_ref
3652 _initialize_dwarf2loc (void)
3654 add_setshow_zinteger_cmd ("entry-values", class_maintenance
,
3655 &entry_values_debug
,
3656 _("Set entry values and tail call frames "
3658 _("Show entry values and tail call frames "
3660 _("When non-zero, the process of determining "
3661 "parameter values from function entry point "
3662 "and tail call frames will be printed."),
3664 show_entry_values_debug
,
3665 &setdebuglist
, &showdebuglist
);