1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2015 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "dwarf2expr.h"
38 #include "dwarf2loc.h"
39 #include "dwarf2-frame.h"
40 #include "compile/compile.h"
42 extern int dwarf2_always_disassemble
;
44 extern const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
;
46 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
47 struct frame_info
*frame
,
50 struct dwarf2_per_cu_data
*per_cu
,
53 /* Until these have formal names, we define these here.
54 ref: http://gcc.gnu.org/wiki/DebugFission
55 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
56 and is then followed by data specific to that entry. */
60 /* Indicates the end of the list of entries. */
61 DEBUG_LOC_END_OF_LIST
= 0,
63 /* This is followed by an unsigned LEB128 number that is an index into
64 .debug_addr and specifies the base address for all following entries. */
65 DEBUG_LOC_BASE_ADDRESS
= 1,
67 /* This is followed by two unsigned LEB128 numbers that are indices into
68 .debug_addr and specify the beginning and ending addresses, and then
69 a normal location expression as in .debug_loc. */
70 DEBUG_LOC_START_END
= 2,
72 /* This is followed by an unsigned LEB128 number that is an index into
73 .debug_addr and specifies the beginning address, and a 4 byte unsigned
74 number that specifies the length, and then a normal location expression
76 DEBUG_LOC_START_LENGTH
= 3,
78 /* An internal value indicating there is insufficient data. */
79 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
81 /* An internal value indicating an invalid kind of entry was found. */
82 DEBUG_LOC_INVALID_ENTRY
= -2
85 /* Helper function which throws an error if a synthetic pointer is
89 invalid_synthetic_pointer (void)
91 error (_("access outside bounds of object "
92 "referenced via synthetic pointer"));
95 /* Decode the addresses in a non-dwo .debug_loc entry.
96 A pointer to the next byte to examine is returned in *NEW_PTR.
97 The encoded low,high addresses are return in *LOW,*HIGH.
98 The result indicates the kind of entry found. */
100 static enum debug_loc_kind
101 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
102 const gdb_byte
**new_ptr
,
103 CORE_ADDR
*low
, CORE_ADDR
*high
,
104 enum bfd_endian byte_order
,
105 unsigned int addr_size
,
108 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
110 if (buf_end
- loc_ptr
< 2 * addr_size
)
111 return DEBUG_LOC_BUFFER_OVERFLOW
;
114 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
116 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
117 loc_ptr
+= addr_size
;
120 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
122 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
123 loc_ptr
+= addr_size
;
127 /* A base-address-selection entry. */
128 if ((*low
& base_mask
) == base_mask
)
129 return DEBUG_LOC_BASE_ADDRESS
;
131 /* An end-of-list entry. */
132 if (*low
== 0 && *high
== 0)
133 return DEBUG_LOC_END_OF_LIST
;
135 return DEBUG_LOC_START_END
;
138 /* Decode the addresses in .debug_loc.dwo entry.
139 A pointer to the next byte to examine is returned in *NEW_PTR.
140 The encoded low,high addresses are return in *LOW,*HIGH.
141 The result indicates the kind of entry found. */
143 static enum debug_loc_kind
144 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
145 const gdb_byte
*loc_ptr
,
146 const gdb_byte
*buf_end
,
147 const gdb_byte
**new_ptr
,
148 CORE_ADDR
*low
, CORE_ADDR
*high
,
149 enum bfd_endian byte_order
)
151 uint64_t low_index
, high_index
;
153 if (loc_ptr
== buf_end
)
154 return DEBUG_LOC_BUFFER_OVERFLOW
;
158 case DEBUG_LOC_END_OF_LIST
:
160 return DEBUG_LOC_END_OF_LIST
;
161 case DEBUG_LOC_BASE_ADDRESS
:
163 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
165 return DEBUG_LOC_BUFFER_OVERFLOW
;
166 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
168 return DEBUG_LOC_BASE_ADDRESS
;
169 case DEBUG_LOC_START_END
:
170 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
172 return DEBUG_LOC_BUFFER_OVERFLOW
;
173 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
174 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
176 return DEBUG_LOC_BUFFER_OVERFLOW
;
177 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
179 return DEBUG_LOC_START_END
;
180 case DEBUG_LOC_START_LENGTH
:
181 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
183 return DEBUG_LOC_BUFFER_OVERFLOW
;
184 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
185 if (loc_ptr
+ 4 > buf_end
)
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
189 *new_ptr
= loc_ptr
+ 4;
190 return DEBUG_LOC_START_LENGTH
;
192 return DEBUG_LOC_INVALID_ENTRY
;
196 /* A function for dealing with location lists. Given a
197 symbol baton (BATON) and a pc value (PC), find the appropriate
198 location expression, set *LOCEXPR_LENGTH, and return a pointer
199 to the beginning of the expression. Returns NULL on failure.
201 For now, only return the first matching location expression; there
202 can be more than one in the list. */
205 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
206 size_t *locexpr_length
, CORE_ADDR pc
)
208 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
209 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
210 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
211 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
212 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
213 /* Adjust base_address for relocatable objects. */
214 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
215 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
216 const gdb_byte
*loc_ptr
, *buf_end
;
218 loc_ptr
= baton
->data
;
219 buf_end
= baton
->data
+ baton
->size
;
223 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
225 enum debug_loc_kind kind
;
226 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
229 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
230 loc_ptr
, buf_end
, &new_ptr
,
231 &low
, &high
, byte_order
);
233 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
235 byte_order
, addr_size
,
240 case DEBUG_LOC_END_OF_LIST
:
243 case DEBUG_LOC_BASE_ADDRESS
:
244 base_address
= high
+ base_offset
;
246 case DEBUG_LOC_START_END
:
247 case DEBUG_LOC_START_LENGTH
:
249 case DEBUG_LOC_BUFFER_OVERFLOW
:
250 case DEBUG_LOC_INVALID_ENTRY
:
251 error (_("dwarf2_find_location_expression: "
252 "Corrupted DWARF expression."));
254 gdb_assert_not_reached ("bad debug_loc_kind");
257 /* Otherwise, a location expression entry.
258 If the entry is from a DWO, don't add base address: the entry is
259 from .debug_addr which has absolute addresses. */
260 if (! baton
->from_dwo
)
263 high
+= base_address
;
266 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
269 if (low
== high
&& pc
== low
)
271 /* This is entry PC record present only at entry point
272 of a function. Verify it is really the function entry point. */
274 const struct block
*pc_block
= block_for_pc (pc
);
275 struct symbol
*pc_func
= NULL
;
278 pc_func
= block_linkage_function (pc_block
);
280 if (pc_func
&& pc
== BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func
)))
282 *locexpr_length
= length
;
287 if (pc
>= low
&& pc
< high
)
289 *locexpr_length
= length
;
297 /* This is the baton used when performing dwarf2 expression
299 struct dwarf_expr_baton
301 struct frame_info
*frame
;
302 struct dwarf2_per_cu_data
*per_cu
;
303 CORE_ADDR obj_address
;
306 /* Helper functions for dwarf2_evaluate_loc_desc. */
308 /* Using the frame specified in BATON, return the value of register
309 REGNUM, treated as a pointer. */
311 dwarf_expr_read_addr_from_reg (void *baton
, int dwarf_regnum
)
313 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
314 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
315 int regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
317 return address_from_register (regnum
, debaton
->frame
);
320 /* Implement struct dwarf_expr_context_funcs' "get_reg_value" callback. */
322 static struct value
*
323 dwarf_expr_get_reg_value (void *baton
, struct type
*type
, int dwarf_regnum
)
325 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
326 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
327 int regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
329 return value_from_register (type
, regnum
, debaton
->frame
);
332 /* Read memory at ADDR (length LEN) into BUF. */
335 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
337 read_memory (addr
, buf
, len
);
340 /* Using the frame specified in BATON, find the location expression
341 describing the frame base. Return a pointer to it in START and
342 its length in LENGTH. */
344 dwarf_expr_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
346 /* FIXME: cagney/2003-03-26: This code should be using
347 get_frame_base_address(), and then implement a dwarf2 specific
349 struct symbol
*framefunc
;
350 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
351 const struct block
*bl
= get_frame_block (debaton
->frame
, NULL
);
354 error (_("frame address is not available."));
356 /* Use block_linkage_function, which returns a real (not inlined)
357 function, instead of get_frame_function, which may return an
359 framefunc
= block_linkage_function (bl
);
361 /* If we found a frame-relative symbol then it was certainly within
362 some function associated with a frame. If we can't find the frame,
363 something has gone wrong. */
364 gdb_assert (framefunc
!= NULL
);
366 func_get_frame_base_dwarf_block (framefunc
,
367 get_frame_address_in_block (debaton
->frame
),
371 /* Implement find_frame_base_location method for LOC_BLOCK functions using
372 DWARF expression for its DW_AT_frame_base. */
375 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
376 const gdb_byte
**start
, size_t *length
)
378 struct dwarf2_locexpr_baton
*symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
380 *length
= symbaton
->size
;
381 *start
= symbaton
->data
;
384 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
385 function uses DWARF expression for its DW_AT_frame_base. */
387 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
389 locexpr_find_frame_base_location
392 /* Implement find_frame_base_location method for LOC_BLOCK functions using
393 DWARF location list for its DW_AT_frame_base. */
396 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
397 const gdb_byte
**start
, size_t *length
)
399 struct dwarf2_loclist_baton
*symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
401 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
404 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
405 function uses DWARF location list for its DW_AT_frame_base. */
407 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
409 loclist_find_frame_base_location
412 /* See dwarf2loc.h. */
415 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
416 const gdb_byte
**start
, size_t *length
)
418 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
420 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
422 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
428 error (_("Could not find the frame base for \"%s\"."),
429 SYMBOL_NATURAL_NAME (framefunc
));
432 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
433 the frame in BATON. */
436 dwarf_expr_frame_cfa (void *baton
)
438 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
440 return dwarf2_frame_cfa (debaton
->frame
);
443 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
444 the frame in BATON. */
447 dwarf_expr_frame_pc (void *baton
)
449 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
451 return get_frame_address_in_block (debaton
->frame
);
454 /* Using the objfile specified in BATON, find the address for the
455 current thread's thread-local storage with offset OFFSET. */
457 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
459 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
460 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
462 return target_translate_tls_address (objfile
, offset
);
465 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
466 current CU (as is PER_CU). State of the CTX is not affected by the
470 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
471 struct dwarf2_per_cu_data
*per_cu
,
472 CORE_ADDR (*get_frame_pc
) (void *baton
),
475 struct dwarf2_locexpr_baton block
;
477 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, get_frame_pc
, baton
);
479 /* DW_OP_call_ref is currently not supported. */
480 gdb_assert (block
.per_cu
== per_cu
);
482 dwarf_expr_eval (ctx
, block
.data
, block
.size
);
485 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
488 dwarf_expr_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
490 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
492 per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
493 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
496 /* Callback function for dwarf2_evaluate_loc_desc. */
499 dwarf_expr_get_base_type (struct dwarf_expr_context
*ctx
,
500 cu_offset die_offset
)
502 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
504 return dwarf2_get_die_type (die_offset
, debaton
->per_cu
);
507 /* See dwarf2loc.h. */
509 unsigned int entry_values_debug
= 0;
511 /* Helper to set entry_values_debug. */
514 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
515 struct cmd_list_element
*c
, const char *value
)
517 fprintf_filtered (file
,
518 _("Entry values and tail call frames debugging is %s.\n"),
522 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
523 CALLER_FRAME (for registers) can be NULL if it is not known. This function
524 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
527 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
528 struct call_site
*call_site
,
529 struct frame_info
*caller_frame
)
531 switch (FIELD_LOC_KIND (call_site
->target
))
533 case FIELD_LOC_KIND_DWARF_BLOCK
:
535 struct dwarf2_locexpr_baton
*dwarf_block
;
537 struct type
*caller_core_addr_type
;
538 struct gdbarch
*caller_arch
;
540 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
541 if (dwarf_block
== NULL
)
543 struct bound_minimal_symbol msym
;
545 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
546 throw_error (NO_ENTRY_VALUE_ERROR
,
547 _("DW_AT_GNU_call_site_target is not specified "
549 paddress (call_site_gdbarch
, call_site
->pc
),
550 (msym
.minsym
== NULL
? "???"
551 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
554 if (caller_frame
== NULL
)
556 struct bound_minimal_symbol msym
;
558 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
559 throw_error (NO_ENTRY_VALUE_ERROR
,
560 _("DW_AT_GNU_call_site_target DWARF block resolving "
561 "requires known frame which is currently not "
562 "available at %s in %s"),
563 paddress (call_site_gdbarch
, call_site
->pc
),
564 (msym
.minsym
== NULL
? "???"
565 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
568 caller_arch
= get_frame_arch (caller_frame
);
569 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
570 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
571 dwarf_block
->data
, dwarf_block
->size
,
572 dwarf_block
->per_cu
);
573 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
575 if (VALUE_LVAL (val
) == lval_memory
)
576 return value_address (val
);
578 return value_as_address (val
);
581 case FIELD_LOC_KIND_PHYSNAME
:
583 const char *physname
;
584 struct bound_minimal_symbol msym
;
586 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
588 /* Handle both the mangled and demangled PHYSNAME. */
589 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
590 if (msym
.minsym
== NULL
)
592 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
593 throw_error (NO_ENTRY_VALUE_ERROR
,
594 _("Cannot find function \"%s\" for a call site target "
596 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
597 (msym
.minsym
== NULL
? "???"
598 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
601 return BMSYMBOL_VALUE_ADDRESS (msym
);
604 case FIELD_LOC_KIND_PHYSADDR
:
605 return FIELD_STATIC_PHYSADDR (call_site
->target
);
608 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
612 /* Convert function entry point exact address ADDR to the function which is
613 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
614 NO_ENTRY_VALUE_ERROR otherwise. */
616 static struct symbol
*
617 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
619 struct symbol
*sym
= find_pc_function (addr
);
622 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
623 throw_error (NO_ENTRY_VALUE_ERROR
,
624 _("DW_TAG_GNU_call_site resolving failed to find function "
625 "name for address %s"),
626 paddress (gdbarch
, addr
));
628 type
= SYMBOL_TYPE (sym
);
629 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
630 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
635 /* Verify function with entry point exact address ADDR can never call itself
636 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
637 can call itself via tail calls.
639 If a funtion can tail call itself its entry value based parameters are
640 unreliable. There is no verification whether the value of some/all
641 parameters is unchanged through the self tail call, we expect if there is
642 a self tail call all the parameters can be modified. */
645 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
647 struct obstack addr_obstack
;
648 struct cleanup
*old_chain
;
651 /* Track here CORE_ADDRs which were already visited. */
654 /* The verification is completely unordered. Track here function addresses
655 which still need to be iterated. */
656 VEC (CORE_ADDR
) *todo
= NULL
;
658 obstack_init (&addr_obstack
);
659 old_chain
= make_cleanup_obstack_free (&addr_obstack
);
660 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
661 &addr_obstack
, hashtab_obstack_allocate
,
663 make_cleanup_htab_delete (addr_hash
);
665 make_cleanup (VEC_cleanup (CORE_ADDR
), &todo
);
667 VEC_safe_push (CORE_ADDR
, todo
, verify_addr
);
668 while (!VEC_empty (CORE_ADDR
, todo
))
670 struct symbol
*func_sym
;
671 struct call_site
*call_site
;
673 addr
= VEC_pop (CORE_ADDR
, todo
);
675 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
677 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
678 call_site
; call_site
= call_site
->tail_call_next
)
680 CORE_ADDR target_addr
;
683 /* CALLER_FRAME with registers is not available for tail-call jumped
685 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
687 if (target_addr
== verify_addr
)
689 struct bound_minimal_symbol msym
;
691 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
692 throw_error (NO_ENTRY_VALUE_ERROR
,
693 _("DW_OP_GNU_entry_value resolving has found "
694 "function \"%s\" at %s can call itself via tail "
696 (msym
.minsym
== NULL
? "???"
697 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
698 paddress (gdbarch
, verify_addr
));
701 slot
= htab_find_slot (addr_hash
, &target_addr
, INSERT
);
704 *slot
= obstack_copy (&addr_obstack
, &target_addr
,
705 sizeof (target_addr
));
706 VEC_safe_push (CORE_ADDR
, todo
, target_addr
);
711 do_cleanups (old_chain
);
714 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
715 ENTRY_VALUES_DEBUG. */
718 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
720 CORE_ADDR addr
= call_site
->pc
;
721 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
723 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
724 (msym
.minsym
== NULL
? "???"
725 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
729 /* vec.h needs single word type name, typedef it. */
730 typedef struct call_site
*call_sitep
;
732 /* Define VEC (call_sitep) functions. */
733 DEF_VEC_P (call_sitep
);
735 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
736 only top callers and bottom callees which are present in both. GDBARCH is
737 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
738 no remaining possibilities to provide unambiguous non-trivial result.
739 RESULTP should point to NULL on the first (initialization) call. Caller is
740 responsible for xfree of any RESULTP data. */
743 chain_candidate (struct gdbarch
*gdbarch
, struct call_site_chain
**resultp
,
744 VEC (call_sitep
) *chain
)
746 struct call_site_chain
*result
= *resultp
;
747 long length
= VEC_length (call_sitep
, chain
);
748 int callers
, callees
, idx
;
752 /* Create the initial chain containing all the passed PCs. */
754 result
= xmalloc (sizeof (*result
) + sizeof (*result
->call_site
)
756 result
->length
= length
;
757 result
->callers
= result
->callees
= length
;
758 if (!VEC_empty (call_sitep
, chain
))
759 memcpy (result
->call_site
, VEC_address (call_sitep
, chain
),
760 sizeof (*result
->call_site
) * length
);
763 if (entry_values_debug
)
765 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
766 for (idx
= 0; idx
< length
; idx
++)
767 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
768 fputc_unfiltered ('\n', gdb_stdlog
);
774 if (entry_values_debug
)
776 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
777 for (idx
= 0; idx
< length
; idx
++)
778 tailcall_dump (gdbarch
, VEC_index (call_sitep
, chain
, idx
));
779 fputc_unfiltered ('\n', gdb_stdlog
);
782 /* Intersect callers. */
784 callers
= min (result
->callers
, length
);
785 for (idx
= 0; idx
< callers
; idx
++)
786 if (result
->call_site
[idx
] != VEC_index (call_sitep
, chain
, idx
))
788 result
->callers
= idx
;
792 /* Intersect callees. */
794 callees
= min (result
->callees
, length
);
795 for (idx
= 0; idx
< callees
; idx
++)
796 if (result
->call_site
[result
->length
- 1 - idx
]
797 != VEC_index (call_sitep
, chain
, length
- 1 - idx
))
799 result
->callees
= idx
;
803 if (entry_values_debug
)
805 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
806 for (idx
= 0; idx
< result
->callers
; idx
++)
807 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
808 fputs_unfiltered (" |", gdb_stdlog
);
809 for (idx
= 0; idx
< result
->callees
; idx
++)
810 tailcall_dump (gdbarch
, result
->call_site
[result
->length
811 - result
->callees
+ idx
]);
812 fputc_unfiltered ('\n', gdb_stdlog
);
815 if (result
->callers
== 0 && result
->callees
== 0)
817 /* There are no common callers or callees. It could be also a direct
818 call (which has length 0) with ambiguous possibility of an indirect
819 call - CALLERS == CALLEES == 0 is valid during the first allocation
820 but any subsequence processing of such entry means ambiguity. */
826 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
827 PC again. In such case there must be two different code paths to reach
828 it, therefore some of the former determined intermediate PCs must differ
829 and the unambiguous chain gets shortened. */
830 gdb_assert (result
->callers
+ result
->callees
< result
->length
);
833 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
834 assumed frames between them use GDBARCH. Use depth first search so we can
835 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
836 would have needless GDB stack overhead. Caller is responsible for xfree of
837 the returned result. Any unreliability results in thrown
838 NO_ENTRY_VALUE_ERROR. */
840 static struct call_site_chain
*
841 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
844 CORE_ADDR save_callee_pc
= callee_pc
;
845 struct obstack addr_obstack
;
846 struct cleanup
*back_to_retval
, *back_to_workdata
;
847 struct call_site_chain
*retval
= NULL
;
848 struct call_site
*call_site
;
850 /* Mark CALL_SITEs so we do not visit the same ones twice. */
853 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
854 call_site nor any possible call_site at CALLEE_PC's function is there.
855 Any CALL_SITE in CHAIN will be iterated to its siblings - via
856 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
857 VEC (call_sitep
) *chain
= NULL
;
859 /* We are not interested in the specific PC inside the callee function. */
860 callee_pc
= get_pc_function_start (callee_pc
);
862 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
863 paddress (gdbarch
, save_callee_pc
));
865 back_to_retval
= make_cleanup (free_current_contents
, &retval
);
867 obstack_init (&addr_obstack
);
868 back_to_workdata
= make_cleanup_obstack_free (&addr_obstack
);
869 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
870 &addr_obstack
, hashtab_obstack_allocate
,
872 make_cleanup_htab_delete (addr_hash
);
874 make_cleanup (VEC_cleanup (call_sitep
), &chain
);
876 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
877 at the target's function. All the possible tail call sites in the
878 target's function will get iterated as already pushed into CHAIN via their
880 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
884 CORE_ADDR target_func_addr
;
885 struct call_site
*target_call_site
;
887 /* CALLER_FRAME with registers is not available for tail-call jumped
889 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
891 if (target_func_addr
== callee_pc
)
893 chain_candidate (gdbarch
, &retval
, chain
);
897 /* There is no way to reach CALLEE_PC again as we would prevent
898 entering it twice as being already marked in ADDR_HASH. */
899 target_call_site
= NULL
;
903 struct symbol
*target_func
;
905 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
906 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
911 /* Attempt to visit TARGET_CALL_SITE. */
913 if (target_call_site
)
917 slot
= htab_find_slot (addr_hash
, &target_call_site
->pc
, INSERT
);
920 /* Successfully entered TARGET_CALL_SITE. */
922 *slot
= &target_call_site
->pc
;
923 VEC_safe_push (call_sitep
, chain
, target_call_site
);
928 /* Backtrack (without revisiting the originating call_site). Try the
929 callers's sibling; if there isn't any try the callers's callers's
932 target_call_site
= NULL
;
933 while (!VEC_empty (call_sitep
, chain
))
935 call_site
= VEC_pop (call_sitep
, chain
);
937 gdb_assert (htab_find_slot (addr_hash
, &call_site
->pc
,
939 htab_remove_elt (addr_hash
, &call_site
->pc
);
941 target_call_site
= call_site
->tail_call_next
;
942 if (target_call_site
)
946 while (target_call_site
);
948 if (VEC_empty (call_sitep
, chain
))
951 call_site
= VEC_last (call_sitep
, chain
);
956 struct bound_minimal_symbol msym_caller
, msym_callee
;
958 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
959 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
960 throw_error (NO_ENTRY_VALUE_ERROR
,
961 _("There are no unambiguously determinable intermediate "
962 "callers or callees between caller function \"%s\" at %s "
963 "and callee function \"%s\" at %s"),
964 (msym_caller
.minsym
== NULL
965 ? "???" : MSYMBOL_PRINT_NAME (msym_caller
.minsym
)),
966 paddress (gdbarch
, caller_pc
),
967 (msym_callee
.minsym
== NULL
968 ? "???" : MSYMBOL_PRINT_NAME (msym_callee
.minsym
)),
969 paddress (gdbarch
, callee_pc
));
972 do_cleanups (back_to_workdata
);
973 discard_cleanups (back_to_retval
);
977 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
978 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
979 constructed return NULL. Caller is responsible for xfree of the returned
982 struct call_site_chain
*
983 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
986 struct call_site_chain
*retval
= NULL
;
990 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
992 CATCH (e
, RETURN_MASK_ERROR
)
994 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
996 if (entry_values_debug
)
997 exception_print (gdb_stdout
, e
);
1002 throw_exception (e
);
1009 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1012 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1013 enum call_site_parameter_kind kind
,
1014 union call_site_parameter_u kind_u
)
1016 if (kind
== parameter
->kind
)
1019 case CALL_SITE_PARAMETER_DWARF_REG
:
1020 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1021 case CALL_SITE_PARAMETER_FB_OFFSET
:
1022 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1023 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1024 return kind_u
.param_offset
.cu_off
== parameter
->u
.param_offset
.cu_off
;
1029 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1030 FRAME is for callee.
1032 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1035 static struct call_site_parameter
*
1036 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1037 enum call_site_parameter_kind kind
,
1038 union call_site_parameter_u kind_u
,
1039 struct dwarf2_per_cu_data
**per_cu_return
)
1041 CORE_ADDR func_addr
, caller_pc
;
1042 struct gdbarch
*gdbarch
;
1043 struct frame_info
*caller_frame
;
1044 struct call_site
*call_site
;
1046 /* Initialize it just to avoid a GCC false warning. */
1047 struct call_site_parameter
*parameter
= NULL
;
1048 CORE_ADDR target_addr
;
1050 while (get_frame_type (frame
) == INLINE_FRAME
)
1052 frame
= get_prev_frame (frame
);
1053 gdb_assert (frame
!= NULL
);
1056 func_addr
= get_frame_func (frame
);
1057 gdbarch
= get_frame_arch (frame
);
1058 caller_frame
= get_prev_frame (frame
);
1059 if (gdbarch
!= frame_unwind_arch (frame
))
1061 struct bound_minimal_symbol msym
1062 = lookup_minimal_symbol_by_pc (func_addr
);
1063 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1065 throw_error (NO_ENTRY_VALUE_ERROR
,
1066 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
1067 "(of %s (%s)) does not match caller gdbarch %s"),
1068 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1069 paddress (gdbarch
, func_addr
),
1070 (msym
.minsym
== NULL
? "???"
1071 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
1072 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1075 if (caller_frame
== NULL
)
1077 struct bound_minimal_symbol msym
1078 = lookup_minimal_symbol_by_pc (func_addr
);
1080 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_GNU_entry_value resolving "
1081 "requires caller of %s (%s)"),
1082 paddress (gdbarch
, func_addr
),
1083 (msym
.minsym
== NULL
? "???"
1084 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
1086 caller_pc
= get_frame_pc (caller_frame
);
1087 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1089 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1090 if (target_addr
!= func_addr
)
1092 struct minimal_symbol
*target_msym
, *func_msym
;
1094 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1095 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1096 throw_error (NO_ENTRY_VALUE_ERROR
,
1097 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
1098 "but the called frame is for %s at %s"),
1099 (target_msym
== NULL
? "???"
1100 : MSYMBOL_PRINT_NAME (target_msym
)),
1101 paddress (gdbarch
, target_addr
),
1102 func_msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (func_msym
),
1103 paddress (gdbarch
, func_addr
));
1106 /* No entry value based parameters would be reliable if this function can
1107 call itself via tail calls. */
1108 func_verify_no_selftailcall (gdbarch
, func_addr
);
1110 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1112 parameter
= &call_site
->parameter
[iparams
];
1113 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1116 if (iparams
== call_site
->parameter_count
)
1118 struct minimal_symbol
*msym
1119 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1121 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
1122 determine its value. */
1123 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1124 "at DW_TAG_GNU_call_site %s at %s"),
1125 paddress (gdbarch
, caller_pc
),
1126 msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (msym
));
1129 *per_cu_return
= call_site
->per_cu
;
1133 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1134 the normal DW_AT_GNU_call_site_value block. Otherwise return the
1135 DW_AT_GNU_call_site_data_value (dereferenced) block.
1137 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1140 Function always returns non-NULL, non-optimized out value. It throws
1141 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1143 static struct value
*
1144 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1145 CORE_ADDR deref_size
, struct type
*type
,
1146 struct frame_info
*caller_frame
,
1147 struct dwarf2_per_cu_data
*per_cu
)
1149 const gdb_byte
*data_src
;
1153 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1154 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1156 /* DEREF_SIZE size is not verified here. */
1157 if (data_src
== NULL
)
1158 throw_error (NO_ENTRY_VALUE_ERROR
,
1159 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1161 /* DW_AT_GNU_call_site_value is a DWARF expression, not a DWARF
1162 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1164 data
= alloca (size
+ 1);
1165 memcpy (data
, data_src
, size
);
1166 data
[size
] = DW_OP_stack_value
;
1168 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1171 /* Execute DWARF block of call_site_parameter which matches KIND and KIND_U.
1172 Choose DEREF_SIZE value of that parameter. Search caller of the CTX's
1173 frame. CTX must be of dwarf_expr_ctx_funcs kind.
1175 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
1176 can be more simple as it does not support cross-CU DWARF executions. */
1179 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
1180 enum call_site_parameter_kind kind
,
1181 union call_site_parameter_u kind_u
,
1184 struct dwarf_expr_baton
*debaton
;
1185 struct frame_info
*frame
, *caller_frame
;
1186 struct dwarf2_per_cu_data
*caller_per_cu
;
1187 struct dwarf_expr_baton baton_local
;
1188 struct dwarf_expr_context saved_ctx
;
1189 struct call_site_parameter
*parameter
;
1190 const gdb_byte
*data_src
;
1193 gdb_assert (ctx
->funcs
== &dwarf_expr_ctx_funcs
);
1194 debaton
= ctx
->baton
;
1195 frame
= debaton
->frame
;
1196 caller_frame
= get_prev_frame (frame
);
1198 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1200 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1201 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1203 /* DEREF_SIZE size is not verified here. */
1204 if (data_src
== NULL
)
1205 throw_error (NO_ENTRY_VALUE_ERROR
,
1206 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1208 baton_local
.frame
= caller_frame
;
1209 baton_local
.per_cu
= caller_per_cu
;
1210 baton_local
.obj_address
= 0;
1212 saved_ctx
.gdbarch
= ctx
->gdbarch
;
1213 saved_ctx
.addr_size
= ctx
->addr_size
;
1214 saved_ctx
.offset
= ctx
->offset
;
1215 saved_ctx
.baton
= ctx
->baton
;
1216 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (baton_local
.per_cu
));
1217 ctx
->addr_size
= dwarf2_per_cu_addr_size (baton_local
.per_cu
);
1218 ctx
->offset
= dwarf2_per_cu_text_offset (baton_local
.per_cu
);
1219 ctx
->baton
= &baton_local
;
1221 dwarf_expr_eval (ctx
, data_src
, size
);
1223 ctx
->gdbarch
= saved_ctx
.gdbarch
;
1224 ctx
->addr_size
= saved_ctx
.addr_size
;
1225 ctx
->offset
= saved_ctx
.offset
;
1226 ctx
->baton
= saved_ctx
.baton
;
1229 /* Callback function for dwarf2_evaluate_loc_desc.
1230 Fetch the address indexed by DW_OP_GNU_addr_index. */
1233 dwarf_expr_get_addr_index (void *baton
, unsigned int index
)
1235 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
1237 return dwarf2_read_addr_index (debaton
->per_cu
, index
);
1240 /* Callback function for get_object_address. Return the address of the VLA
1244 dwarf_expr_get_obj_addr (void *baton
)
1246 struct dwarf_expr_baton
*debaton
= baton
;
1248 gdb_assert (debaton
!= NULL
);
1250 if (debaton
->obj_address
== 0)
1251 error (_("Location address is not set."));
1253 return debaton
->obj_address
;
1256 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1257 the indirect method on it, that is use its stored target value, the sole
1258 purpose of entry_data_value_funcs.. */
1260 static struct value
*
1261 entry_data_value_coerce_ref (const struct value
*value
)
1263 struct type
*checked_type
= check_typedef (value_type (value
));
1264 struct value
*target_val
;
1266 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
)
1269 target_val
= value_computed_closure (value
);
1270 value_incref (target_val
);
1274 /* Implement copy_closure. */
1277 entry_data_value_copy_closure (const struct value
*v
)
1279 struct value
*target_val
= value_computed_closure (v
);
1281 value_incref (target_val
);
1285 /* Implement free_closure. */
1288 entry_data_value_free_closure (struct value
*v
)
1290 struct value
*target_val
= value_computed_closure (v
);
1292 value_free (target_val
);
1295 /* Vector for methods for an entry value reference where the referenced value
1296 is stored in the caller. On the first dereference use
1297 DW_AT_GNU_call_site_data_value in the caller. */
1299 static const struct lval_funcs entry_data_value_funcs
=
1303 NULL
, /* indirect */
1304 entry_data_value_coerce_ref
,
1305 NULL
, /* check_synthetic_pointer */
1306 entry_data_value_copy_closure
,
1307 entry_data_value_free_closure
1310 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1311 are used to match DW_AT_location at the caller's
1312 DW_TAG_GNU_call_site_parameter.
1314 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1315 cannot resolve the parameter for any reason. */
1317 static struct value
*
1318 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1319 enum call_site_parameter_kind kind
,
1320 union call_site_parameter_u kind_u
)
1322 struct type
*checked_type
= check_typedef (type
);
1323 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1324 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1325 struct value
*outer_val
, *target_val
, *val
;
1326 struct call_site_parameter
*parameter
;
1327 struct dwarf2_per_cu_data
*caller_per_cu
;
1329 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1332 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1336 /* Check if DW_AT_GNU_call_site_data_value cannot be used. If it should be
1337 used and it is not available do not fall back to OUTER_VAL - dereferencing
1338 TYPE_CODE_REF with non-entry data value would give current value - not the
1341 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
1342 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1345 target_val
= dwarf_entry_parameter_to_value (parameter
,
1346 TYPE_LENGTH (target_type
),
1347 target_type
, caller_frame
,
1350 release_value (target_val
);
1351 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1352 target_val
/* closure */);
1354 /* Copy the referencing pointer to the new computed value. */
1355 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1356 TYPE_LENGTH (checked_type
));
1357 set_value_lazy (val
, 0);
1362 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1363 SIZE are DWARF block used to match DW_AT_location at the caller's
1364 DW_TAG_GNU_call_site_parameter.
1366 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1367 cannot resolve the parameter for any reason. */
1369 static struct value
*
1370 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1371 const gdb_byte
*block
, size_t block_len
)
1373 union call_site_parameter_u kind_u
;
1375 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1376 if (kind_u
.dwarf_reg
!= -1)
1377 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1380 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1381 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1384 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1385 suppressed during normal operation. The expression can be arbitrary if
1386 there is no caller-callee entry value binding expected. */
1387 throw_error (NO_ENTRY_VALUE_ERROR
,
1388 _("DWARF-2 expression error: DW_OP_GNU_entry_value is supported "
1389 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1392 struct piece_closure
1394 /* Reference count. */
1397 /* The CU from which this closure's expression came. */
1398 struct dwarf2_per_cu_data
*per_cu
;
1400 /* The number of pieces used to describe this variable. */
1403 /* The target address size, used only for DWARF_VALUE_STACK. */
1406 /* The pieces themselves. */
1407 struct dwarf_expr_piece
*pieces
;
1410 /* Allocate a closure for a value formed from separately-described
1413 static struct piece_closure
*
1414 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1415 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1418 struct piece_closure
*c
= XCNEW (struct piece_closure
);
1423 c
->n_pieces
= n_pieces
;
1424 c
->addr_size
= addr_size
;
1425 c
->pieces
= XCNEWVEC (struct dwarf_expr_piece
, n_pieces
);
1427 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1428 for (i
= 0; i
< n_pieces
; ++i
)
1429 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1430 value_incref (c
->pieces
[i
].v
.value
);
1435 /* The lowest-level function to extract bits from a byte buffer.
1436 SOURCE is the buffer. It is updated if we read to the end of a
1438 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
1439 updated to reflect the number of bits actually read.
1440 NBITS is the number of bits we want to read. It is updated to
1441 reflect the number of bits actually read. This function may read
1443 BITS_BIG_ENDIAN is taken directly from gdbarch.
1444 This function returns the extracted bits. */
1447 extract_bits_primitive (const gdb_byte
**source
,
1448 unsigned int *source_offset_bits
,
1449 int *nbits
, int bits_big_endian
)
1451 unsigned int avail
, mask
, datum
;
1453 gdb_assert (*source_offset_bits
< 8);
1455 avail
= 8 - *source_offset_bits
;
1459 mask
= (1 << avail
) - 1;
1461 if (bits_big_endian
)
1462 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
1464 datum
>>= *source_offset_bits
;
1468 *source_offset_bits
+= avail
;
1469 if (*source_offset_bits
>= 8)
1471 *source_offset_bits
-= 8;
1478 /* Extract some bits from a source buffer and move forward in the
1481 SOURCE is the source buffer. It is updated as bytes are read.
1482 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1484 NBITS is the number of bits to read.
1485 BITS_BIG_ENDIAN is taken directly from gdbarch.
1487 This function returns the bits that were read. */
1490 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
1491 int nbits
, int bits_big_endian
)
1495 gdb_assert (nbits
> 0 && nbits
<= 8);
1497 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1503 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1505 if (bits_big_endian
)
1515 /* Write some bits into a buffer and move forward in the buffer.
1517 DATUM is the bits to write. The low-order bits of DATUM are used.
1518 DEST is the destination buffer. It is updated as bytes are
1520 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1522 NBITS is the number of valid bits in DATUM.
1523 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1526 insert_bits (unsigned int datum
,
1527 gdb_byte
*dest
, unsigned int dest_offset_bits
,
1528 int nbits
, int bits_big_endian
)
1532 gdb_assert (dest_offset_bits
+ nbits
<= 8);
1534 mask
= (1 << nbits
) - 1;
1535 if (bits_big_endian
)
1537 datum
<<= 8 - (dest_offset_bits
+ nbits
);
1538 mask
<<= 8 - (dest_offset_bits
+ nbits
);
1542 datum
<<= dest_offset_bits
;
1543 mask
<<= dest_offset_bits
;
1546 gdb_assert ((datum
& ~mask
) == 0);
1548 *dest
= (*dest
& ~mask
) | datum
;
1551 /* Copy bits from a source to a destination.
1553 DEST is where the bits should be written.
1554 DEST_OFFSET_BITS is the bit offset into DEST.
1555 SOURCE is the source of bits.
1556 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1557 BIT_COUNT is the number of bits to copy.
1558 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1561 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
1562 const gdb_byte
*source
, unsigned int source_offset_bits
,
1563 unsigned int bit_count
,
1564 int bits_big_endian
)
1566 unsigned int dest_avail
;
1569 /* Reduce everything to byte-size pieces. */
1570 dest
+= dest_offset_bits
/ 8;
1571 dest_offset_bits
%= 8;
1572 source
+= source_offset_bits
/ 8;
1573 source_offset_bits
%= 8;
1575 dest_avail
= 8 - dest_offset_bits
% 8;
1577 /* See if we can fill the first destination byte. */
1578 if (dest_avail
< bit_count
)
1580 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
1582 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
1584 dest_offset_bits
= 0;
1585 bit_count
-= dest_avail
;
1588 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1589 than 8 bits remaining. */
1590 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
1591 for (; bit_count
>= 8; bit_count
-= 8)
1593 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
1594 *dest
++ = (gdb_byte
) datum
;
1597 /* Finally, we may have a few leftover bits. */
1598 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
1601 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
1603 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
1608 read_pieced_value (struct value
*v
)
1612 ULONGEST bits_to_skip
;
1614 struct piece_closure
*c
1615 = (struct piece_closure
*) value_computed_closure (v
);
1616 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
1618 size_t buffer_size
= 0;
1619 gdb_byte
*buffer
= NULL
;
1620 struct cleanup
*cleanup
;
1622 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1624 if (value_type (v
) != value_enclosing_type (v
))
1625 internal_error (__FILE__
, __LINE__
,
1626 _("Should not be able to create a lazy value with "
1627 "an enclosing type"));
1629 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1631 contents
= value_contents_raw (v
);
1632 bits_to_skip
= 8 * value_offset (v
);
1633 if (value_bitsize (v
))
1635 bits_to_skip
+= value_bitpos (v
);
1636 type_len
= value_bitsize (v
);
1639 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1641 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1643 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1644 size_t this_size
, this_size_bits
;
1645 long dest_offset_bits
, source_offset_bits
, source_offset
;
1646 const gdb_byte
*intermediate_buffer
;
1648 /* Compute size, source, and destination offsets for copying, in
1650 this_size_bits
= p
->size
;
1651 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1653 bits_to_skip
-= this_size_bits
;
1656 if (bits_to_skip
> 0)
1658 dest_offset_bits
= 0;
1659 source_offset_bits
= bits_to_skip
;
1660 this_size_bits
-= bits_to_skip
;
1665 dest_offset_bits
= offset
;
1666 source_offset_bits
= 0;
1668 if (this_size_bits
> type_len
- offset
)
1669 this_size_bits
= type_len
- offset
;
1671 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1672 source_offset
= source_offset_bits
/ 8;
1673 if (buffer_size
< this_size
)
1675 buffer_size
= this_size
;
1676 buffer
= xrealloc (buffer
, buffer_size
);
1678 intermediate_buffer
= buffer
;
1680 /* Copy from the source to DEST_BUFFER. */
1681 switch (p
->location
)
1683 case DWARF_VALUE_REGISTER
:
1685 struct gdbarch
*arch
= get_frame_arch (frame
);
1686 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1688 if (gdb_regnum
!= -1)
1691 int reg_offset
= source_offset
;
1693 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1694 && this_size
< register_size (arch
, gdb_regnum
))
1696 /* Big-endian, and we want less than full size. */
1697 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1698 /* We want the lower-order THIS_SIZE_BITS of the bytes
1699 we extract from the register. */
1700 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1703 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1707 /* Just so garbage doesn't ever shine through. */
1708 memset (buffer
, 0, this_size
);
1711 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1713 mark_value_bits_unavailable (v
, offset
, this_size_bits
);
1718 error (_("Unable to access DWARF register number %s"),
1719 paddress (arch
, p
->v
.regno
));
1724 case DWARF_VALUE_MEMORY
:
1725 read_value_memory (v
, offset
,
1726 p
->v
.mem
.in_stack_memory
,
1727 p
->v
.mem
.addr
+ source_offset
,
1731 case DWARF_VALUE_STACK
:
1733 size_t n
= this_size
;
1735 if (n
> c
->addr_size
- source_offset
)
1736 n
= (c
->addr_size
>= source_offset
1737 ? c
->addr_size
- source_offset
1745 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
1747 intermediate_buffer
= val_bytes
+ source_offset
;
1752 case DWARF_VALUE_LITERAL
:
1754 size_t n
= this_size
;
1756 if (n
> p
->v
.literal
.length
- source_offset
)
1757 n
= (p
->v
.literal
.length
>= source_offset
1758 ? p
->v
.literal
.length
- source_offset
1761 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1765 /* These bits show up as zeros -- but do not cause the value
1766 to be considered optimized-out. */
1767 case DWARF_VALUE_IMPLICIT_POINTER
:
1770 case DWARF_VALUE_OPTIMIZED_OUT
:
1771 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1775 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1778 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
1779 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1780 copy_bitwise (contents
, dest_offset_bits
,
1781 intermediate_buffer
, source_offset_bits
% 8,
1782 this_size_bits
, bits_big_endian
);
1784 offset
+= this_size_bits
;
1787 do_cleanups (cleanup
);
1791 write_pieced_value (struct value
*to
, struct value
*from
)
1795 ULONGEST bits_to_skip
;
1796 const gdb_byte
*contents
;
1797 struct piece_closure
*c
1798 = (struct piece_closure
*) value_computed_closure (to
);
1799 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
1801 size_t buffer_size
= 0;
1802 gdb_byte
*buffer
= NULL
;
1803 struct cleanup
*cleanup
;
1805 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1809 mark_value_bytes_optimized_out (to
, 0, TYPE_LENGTH (value_type (to
)));
1813 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1815 contents
= value_contents (from
);
1816 bits_to_skip
= 8 * value_offset (to
);
1817 if (value_bitsize (to
))
1819 bits_to_skip
+= value_bitpos (to
);
1820 type_len
= value_bitsize (to
);
1823 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1825 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1827 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1828 size_t this_size_bits
, this_size
;
1829 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1831 const gdb_byte
*source_buffer
;
1833 this_size_bits
= p
->size
;
1834 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1836 bits_to_skip
-= this_size_bits
;
1839 if (this_size_bits
> type_len
- offset
)
1840 this_size_bits
= type_len
- offset
;
1841 if (bits_to_skip
> 0)
1843 dest_offset_bits
= bits_to_skip
;
1844 source_offset_bits
= 0;
1845 this_size_bits
-= bits_to_skip
;
1850 dest_offset_bits
= 0;
1851 source_offset_bits
= offset
;
1854 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1855 source_offset
= source_offset_bits
/ 8;
1856 dest_offset
= dest_offset_bits
/ 8;
1857 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1859 source_buffer
= contents
+ source_offset
;
1864 if (buffer_size
< this_size
)
1866 buffer_size
= this_size
;
1867 buffer
= xrealloc (buffer
, buffer_size
);
1869 source_buffer
= buffer
;
1873 switch (p
->location
)
1875 case DWARF_VALUE_REGISTER
:
1877 struct gdbarch
*arch
= get_frame_arch (frame
);
1878 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1880 if (gdb_regnum
!= -1)
1882 int reg_offset
= dest_offset
;
1884 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1885 && this_size
<= register_size (arch
, gdb_regnum
))
1887 /* Big-endian, and we want less than full size. */
1888 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1895 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1900 throw_error (OPTIMIZED_OUT_ERROR
,
1901 _("Can't do read-modify-write to "
1902 "update bitfield; containing word "
1903 "has been optimized out"));
1905 throw_error (NOT_AVAILABLE_ERROR
,
1906 _("Can't do read-modify-write to update "
1907 "bitfield; containing word "
1910 copy_bitwise (buffer
, dest_offset_bits
,
1911 contents
, source_offset_bits
,
1916 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1917 this_size
, source_buffer
);
1921 error (_("Unable to write to DWARF register number %s"),
1922 paddress (arch
, p
->v
.regno
));
1926 case DWARF_VALUE_MEMORY
:
1929 /* Only the first and last bytes can possibly have any
1931 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
1932 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
1933 buffer
+ this_size
- 1, 1);
1934 copy_bitwise (buffer
, dest_offset_bits
,
1935 contents
, source_offset_bits
,
1940 write_memory (p
->v
.mem
.addr
+ dest_offset
,
1941 source_buffer
, this_size
);
1944 mark_value_bytes_optimized_out (to
, 0, TYPE_LENGTH (value_type (to
)));
1947 offset
+= this_size_bits
;
1950 do_cleanups (cleanup
);
1953 /* An implementation of an lval_funcs method to see whether a value is
1954 a synthetic pointer. */
1957 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
1960 struct piece_closure
*c
1961 = (struct piece_closure
*) value_computed_closure (value
);
1964 bit_offset
+= 8 * value_offset (value
);
1965 if (value_bitsize (value
))
1966 bit_offset
+= value_bitpos (value
);
1968 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1970 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1971 size_t this_size_bits
= p
->size
;
1975 if (bit_offset
>= this_size_bits
)
1977 bit_offset
-= this_size_bits
;
1981 bit_length
-= this_size_bits
- bit_offset
;
1985 bit_length
-= this_size_bits
;
1987 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1994 /* A wrapper function for get_frame_address_in_block. */
1997 get_frame_address_in_block_wrapper (void *baton
)
1999 return get_frame_address_in_block (baton
);
2002 /* An implementation of an lval_funcs method to indirect through a
2003 pointer. This handles the synthetic pointer case when needed. */
2005 static struct value
*
2006 indirect_pieced_value (struct value
*value
)
2008 struct piece_closure
*c
2009 = (struct piece_closure
*) value_computed_closure (value
);
2011 struct frame_info
*frame
;
2012 struct dwarf2_locexpr_baton baton
;
2013 int i
, bit_offset
, bit_length
;
2014 struct dwarf_expr_piece
*piece
= NULL
;
2015 LONGEST byte_offset
;
2016 enum bfd_endian byte_order
;
2018 type
= check_typedef (value_type (value
));
2019 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2022 bit_length
= 8 * TYPE_LENGTH (type
);
2023 bit_offset
= 8 * value_offset (value
);
2024 if (value_bitsize (value
))
2025 bit_offset
+= value_bitpos (value
);
2027 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2029 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2030 size_t this_size_bits
= p
->size
;
2034 if (bit_offset
>= this_size_bits
)
2036 bit_offset
-= this_size_bits
;
2040 bit_length
-= this_size_bits
- bit_offset
;
2044 bit_length
-= this_size_bits
;
2046 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2049 if (bit_length
!= 0)
2050 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
2056 frame
= get_selected_frame (_("No frame selected."));
2058 /* This is an offset requested by GDB, such as value subscripts.
2059 However, due to how synthetic pointers are implemented, this is
2060 always presented to us as a pointer type. This means we have to
2061 sign-extend it manually as appropriate. Use raw
2062 extract_signed_integer directly rather than value_as_address and
2063 sign extend afterwards on architectures that would need it
2064 (mostly everywhere except MIPS, which has signed addresses) as
2065 the later would go through gdbarch_pointer_to_address and thus
2066 return a CORE_ADDR with high bits set on architectures that
2067 encode address spaces and other things in CORE_ADDR. */
2068 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2069 byte_offset
= extract_signed_integer (value_contents (value
),
2070 TYPE_LENGTH (type
), byte_order
);
2071 byte_offset
+= piece
->v
.ptr
.offset
;
2075 = dwarf2_fetch_die_loc_sect_off (piece
->v
.ptr
.die
, c
->per_cu
,
2076 get_frame_address_in_block_wrapper
,
2079 if (baton
.data
!= NULL
)
2080 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
2081 baton
.data
, baton
.size
, baton
.per_cu
,
2085 struct obstack temp_obstack
;
2086 struct cleanup
*cleanup
;
2087 const gdb_byte
*bytes
;
2089 struct value
*result
;
2091 obstack_init (&temp_obstack
);
2092 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2094 bytes
= dwarf2_fetch_constant_bytes (piece
->v
.ptr
.die
, c
->per_cu
,
2095 &temp_obstack
, &len
);
2097 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2101 || byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > len
)
2102 invalid_synthetic_pointer ();
2103 bytes
+= byte_offset
;
2104 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2107 do_cleanups (cleanup
);
2113 copy_pieced_value_closure (const struct value
*v
)
2115 struct piece_closure
*c
2116 = (struct piece_closure
*) value_computed_closure (v
);
2123 free_pieced_value_closure (struct value
*v
)
2125 struct piece_closure
*c
2126 = (struct piece_closure
*) value_computed_closure (v
);
2133 for (i
= 0; i
< c
->n_pieces
; ++i
)
2134 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2135 value_free (c
->pieces
[i
].v
.value
);
2142 /* Functions for accessing a variable described by DW_OP_piece. */
2143 static const struct lval_funcs pieced_value_funcs
= {
2146 indirect_pieced_value
,
2147 NULL
, /* coerce_ref */
2148 check_pieced_synthetic_pointer
,
2149 copy_pieced_value_closure
,
2150 free_pieced_value_closure
2153 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
2155 const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
2157 dwarf_expr_read_addr_from_reg
,
2158 dwarf_expr_get_reg_value
,
2159 dwarf_expr_read_mem
,
2160 dwarf_expr_frame_base
,
2161 dwarf_expr_frame_cfa
,
2162 dwarf_expr_frame_pc
,
2163 dwarf_expr_tls_address
,
2164 dwarf_expr_dwarf_call
,
2165 dwarf_expr_get_base_type
,
2166 dwarf_expr_push_dwarf_reg_entry_value
,
2167 dwarf_expr_get_addr_index
,
2168 dwarf_expr_get_obj_addr
2171 /* Evaluate a location description, starting at DATA and with length
2172 SIZE, to find the current location of variable of TYPE in the
2173 context of FRAME. BYTE_OFFSET is applied after the contents are
2176 static struct value
*
2177 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2178 const gdb_byte
*data
, size_t size
,
2179 struct dwarf2_per_cu_data
*per_cu
,
2180 LONGEST byte_offset
)
2182 struct value
*retval
;
2183 struct dwarf_expr_baton baton
;
2184 struct dwarf_expr_context
*ctx
;
2185 struct cleanup
*old_chain
, *value_chain
;
2186 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2188 if (byte_offset
< 0)
2189 invalid_synthetic_pointer ();
2192 return allocate_optimized_out_value (type
);
2194 baton
.frame
= frame
;
2195 baton
.per_cu
= per_cu
;
2196 baton
.obj_address
= 0;
2198 ctx
= new_dwarf_expr_context ();
2199 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2200 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
2202 ctx
->gdbarch
= get_objfile_arch (objfile
);
2203 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2204 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2205 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2206 ctx
->baton
= &baton
;
2207 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2211 dwarf_expr_eval (ctx
, data
, size
);
2213 CATCH (ex
, RETURN_MASK_ERROR
)
2215 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2217 do_cleanups (old_chain
);
2218 retval
= allocate_value (type
);
2219 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
2222 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2224 if (entry_values_debug
)
2225 exception_print (gdb_stdout
, ex
);
2226 do_cleanups (old_chain
);
2227 return allocate_optimized_out_value (type
);
2230 throw_exception (ex
);
2234 if (ctx
->num_pieces
> 0)
2236 struct piece_closure
*c
;
2237 struct frame_id frame_id
= get_frame_id (frame
);
2238 ULONGEST bit_size
= 0;
2241 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
2242 bit_size
+= ctx
->pieces
[i
].size
;
2243 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
2244 invalid_synthetic_pointer ();
2246 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
2248 /* We must clean up the value chain after creating the piece
2249 closure but before allocating the result. */
2250 do_cleanups (value_chain
);
2251 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
2252 VALUE_FRAME_ID (retval
) = frame_id
;
2253 set_value_offset (retval
, byte_offset
);
2257 switch (ctx
->location
)
2259 case DWARF_VALUE_REGISTER
:
2261 struct gdbarch
*arch
= get_frame_arch (frame
);
2263 = longest_to_int (value_as_long (dwarf_expr_fetch (ctx
, 0)));
2264 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
2266 if (byte_offset
!= 0)
2267 error (_("cannot use offset on synthetic pointer to register"));
2268 do_cleanups (value_chain
);
2269 if (gdb_regnum
== -1)
2270 error (_("Unable to access DWARF register number %d"),
2272 retval
= value_from_register (type
, gdb_regnum
, frame
);
2273 if (value_optimized_out (retval
))
2277 /* This means the register has undefined value / was
2278 not saved. As we're computing the location of some
2279 variable etc. in the program, not a value for
2280 inspecting a register ($pc, $sp, etc.), return a
2281 generic optimized out value instead, so that we show
2282 <optimized out> instead of <not saved>. */
2283 do_cleanups (value_chain
);
2284 tmp
= allocate_value (type
);
2285 value_contents_copy (tmp
, 0, retval
, 0, TYPE_LENGTH (type
));
2291 case DWARF_VALUE_MEMORY
:
2293 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
2294 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
2296 do_cleanups (value_chain
);
2297 retval
= value_at_lazy (type
, address
+ byte_offset
);
2298 if (in_stack_memory
)
2299 set_value_stack (retval
, 1);
2303 case DWARF_VALUE_STACK
:
2305 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
2307 const gdb_byte
*val_bytes
;
2308 size_t n
= TYPE_LENGTH (value_type (value
));
2310 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2311 invalid_synthetic_pointer ();
2313 val_bytes
= value_contents_all (value
);
2314 val_bytes
+= byte_offset
;
2317 /* Preserve VALUE because we are going to free values back
2318 to the mark, but we still need the value contents
2320 value_incref (value
);
2321 do_cleanups (value_chain
);
2322 make_cleanup_value_free (value
);
2324 retval
= allocate_value (type
);
2325 contents
= value_contents_raw (retval
);
2326 if (n
> TYPE_LENGTH (type
))
2328 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2330 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2331 val_bytes
+= n
- TYPE_LENGTH (type
);
2332 n
= TYPE_LENGTH (type
);
2334 memcpy (contents
, val_bytes
, n
);
2338 case DWARF_VALUE_LITERAL
:
2341 const bfd_byte
*ldata
;
2342 size_t n
= ctx
->len
;
2344 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2345 invalid_synthetic_pointer ();
2347 do_cleanups (value_chain
);
2348 retval
= allocate_value (type
);
2349 contents
= value_contents_raw (retval
);
2351 ldata
= ctx
->data
+ byte_offset
;
2354 if (n
> TYPE_LENGTH (type
))
2356 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2358 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2359 ldata
+= n
- TYPE_LENGTH (type
);
2360 n
= TYPE_LENGTH (type
);
2362 memcpy (contents
, ldata
, n
);
2366 case DWARF_VALUE_OPTIMIZED_OUT
:
2367 do_cleanups (value_chain
);
2368 retval
= allocate_optimized_out_value (type
);
2371 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2372 operation by execute_stack_op. */
2373 case DWARF_VALUE_IMPLICIT_POINTER
:
2374 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2375 it can only be encountered when making a piece. */
2377 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2381 set_value_initialized (retval
, ctx
->initialized
);
2383 do_cleanups (old_chain
);
2388 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2389 passes 0 as the byte_offset. */
2392 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2393 const gdb_byte
*data
, size_t size
,
2394 struct dwarf2_per_cu_data
*per_cu
)
2396 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
2399 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2400 that the dwarf expression only produces a single CORE_ADDR. ADDR is a
2401 context (location of a variable) and might be needed to evaluate the
2402 location expression.
2403 Returns 1 on success, 0 otherwise. */
2406 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2410 struct dwarf_expr_context
*ctx
;
2411 struct dwarf_expr_baton baton
;
2412 struct objfile
*objfile
;
2413 struct cleanup
*cleanup
;
2415 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2418 ctx
= new_dwarf_expr_context ();
2419 cleanup
= make_cleanup_free_dwarf_expr_context (ctx
);
2421 baton
.frame
= get_selected_frame (NULL
);
2422 baton
.per_cu
= dlbaton
->per_cu
;
2423 baton
.obj_address
= addr
;
2425 objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2427 ctx
->gdbarch
= get_objfile_arch (objfile
);
2428 ctx
->addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2429 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (dlbaton
->per_cu
);
2430 ctx
->offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2431 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2432 ctx
->baton
= &baton
;
2434 dwarf_expr_eval (ctx
, dlbaton
->data
, dlbaton
->size
);
2436 switch (ctx
->location
)
2438 case DWARF_VALUE_REGISTER
:
2439 case DWARF_VALUE_MEMORY
:
2440 case DWARF_VALUE_STACK
:
2441 *valp
= dwarf_expr_fetch_address (ctx
, 0);
2442 if (ctx
->location
== DWARF_VALUE_REGISTER
)
2443 *valp
= dwarf_expr_read_addr_from_reg (&baton
, *valp
);
2444 do_cleanups (cleanup
);
2446 case DWARF_VALUE_LITERAL
:
2447 *valp
= extract_signed_integer (ctx
->data
, ctx
->len
,
2448 gdbarch_byte_order (ctx
->gdbarch
));
2449 do_cleanups (cleanup
);
2451 /* Unsupported dwarf values. */
2452 case DWARF_VALUE_OPTIMIZED_OUT
:
2453 case DWARF_VALUE_IMPLICIT_POINTER
:
2457 do_cleanups (cleanup
);
2461 /* See dwarf2loc.h. */
2464 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2465 struct property_addr_info
*addr_stack
,
2475 const struct dwarf2_property_baton
*baton
= prop
->data
.baton
;
2477 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, addr_stack
->addr
,
2480 if (baton
->referenced_type
)
2482 struct value
*val
= value_at (baton
->referenced_type
, *value
);
2484 *value
= value_as_address (val
);
2493 struct dwarf2_property_baton
*baton
= prop
->data
.baton
;
2494 struct frame_info
*frame
= get_selected_frame (NULL
);
2495 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2496 const gdb_byte
*data
;
2500 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2503 val
= dwarf2_evaluate_loc_desc (baton
->referenced_type
, frame
, data
,
2504 size
, baton
->loclist
.per_cu
);
2505 if (!value_optimized_out (val
))
2507 *value
= value_as_address (val
);
2515 *value
= prop
->data
.const_val
;
2518 case PROP_ADDR_OFFSET
:
2520 struct dwarf2_property_baton
*baton
= prop
->data
.baton
;
2521 struct property_addr_info
*pinfo
;
2524 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2525 if (pinfo
->type
== baton
->referenced_type
)
2528 error (_("cannot find reference address for offset property"));
2529 val
= value_at (baton
->offset_info
.type
,
2530 pinfo
->addr
+ baton
->offset_info
.offset
);
2531 *value
= value_as_address (val
);
2539 /* See dwarf2loc.h. */
2542 dwarf2_compile_property_to_c (struct ui_file
*stream
,
2543 const char *result_name
,
2544 struct gdbarch
*gdbarch
,
2545 unsigned char *registers_used
,
2546 const struct dynamic_prop
*prop
,
2550 struct dwarf2_property_baton
*baton
= prop
->data
.baton
;
2551 const gdb_byte
*data
;
2553 struct dwarf2_per_cu_data
*per_cu
;
2555 if (prop
->kind
== PROP_LOCEXPR
)
2557 data
= baton
->locexpr
.data
;
2558 size
= baton
->locexpr
.size
;
2559 per_cu
= baton
->locexpr
.per_cu
;
2563 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2565 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2566 per_cu
= baton
->loclist
.per_cu
;
2569 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2570 gdbarch
, registers_used
,
2571 dwarf2_per_cu_addr_size (per_cu
),
2572 data
, data
+ size
, per_cu
);
2576 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
2578 struct needs_frame_baton
2581 struct dwarf2_per_cu_data
*per_cu
;
2584 /* Reads from registers do require a frame. */
2586 needs_frame_read_addr_from_reg (void *baton
, int regnum
)
2588 struct needs_frame_baton
*nf_baton
= baton
;
2590 nf_baton
->needs_frame
= 1;
2594 /* struct dwarf_expr_context_funcs' "get_reg_value" callback:
2595 Reads from registers do require a frame. */
2597 static struct value
*
2598 needs_frame_get_reg_value (void *baton
, struct type
*type
, int regnum
)
2600 struct needs_frame_baton
*nf_baton
= baton
;
2602 nf_baton
->needs_frame
= 1;
2603 return value_zero (type
, not_lval
);
2606 /* Reads from memory do not require a frame. */
2608 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
2610 memset (buf
, 0, len
);
2613 /* Frame-relative accesses do require a frame. */
2615 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
2617 static gdb_byte lit0
= DW_OP_lit0
;
2618 struct needs_frame_baton
*nf_baton
= baton
;
2623 nf_baton
->needs_frame
= 1;
2626 /* CFA accesses require a frame. */
2629 needs_frame_frame_cfa (void *baton
)
2631 struct needs_frame_baton
*nf_baton
= baton
;
2633 nf_baton
->needs_frame
= 1;
2637 /* Thread-local accesses do require a frame. */
2639 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
2641 struct needs_frame_baton
*nf_baton
= baton
;
2643 nf_baton
->needs_frame
= 1;
2647 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
2650 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
2652 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2654 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
2655 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
2658 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2661 needs_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
2662 enum call_site_parameter_kind kind
,
2663 union call_site_parameter_u kind_u
, int deref_size
)
2665 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2667 nf_baton
->needs_frame
= 1;
2669 /* The expression may require some stub values on DWARF stack. */
2670 dwarf_expr_push_address (ctx
, 0, 0);
2673 /* DW_OP_GNU_addr_index doesn't require a frame. */
2676 needs_get_addr_index (void *baton
, unsigned int index
)
2678 /* Nothing to do. */
2682 /* DW_OP_push_object_address has a frame already passed through. */
2685 needs_get_obj_addr (void *baton
)
2687 /* Nothing to do. */
2691 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
2693 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs
=
2695 needs_frame_read_addr_from_reg
,
2696 needs_frame_get_reg_value
,
2697 needs_frame_read_mem
,
2698 needs_frame_frame_base
,
2699 needs_frame_frame_cfa
,
2700 needs_frame_frame_cfa
, /* get_frame_pc */
2701 needs_frame_tls_address
,
2702 needs_frame_dwarf_call
,
2703 NULL
, /* get_base_type */
2704 needs_dwarf_reg_entry_value
,
2705 needs_get_addr_index
,
2709 /* Return non-zero iff the location expression at DATA (length SIZE)
2710 requires a frame to evaluate. */
2713 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, size_t size
,
2714 struct dwarf2_per_cu_data
*per_cu
)
2716 struct needs_frame_baton baton
;
2717 struct dwarf_expr_context
*ctx
;
2719 struct cleanup
*old_chain
;
2720 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2722 baton
.needs_frame
= 0;
2723 baton
.per_cu
= per_cu
;
2725 ctx
= new_dwarf_expr_context ();
2726 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2727 make_cleanup_value_free_to_mark (value_mark ());
2729 ctx
->gdbarch
= get_objfile_arch (objfile
);
2730 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2731 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2732 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2733 ctx
->baton
= &baton
;
2734 ctx
->funcs
= &needs_frame_ctx_funcs
;
2736 dwarf_expr_eval (ctx
, data
, size
);
2738 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
2740 if (ctx
->num_pieces
> 0)
2744 /* If the location has several pieces, and any of them are in
2745 registers, then we will need a frame to fetch them from. */
2746 for (i
= 0; i
< ctx
->num_pieces
; i
++)
2747 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2751 do_cleanups (old_chain
);
2753 return baton
.needs_frame
|| in_reg
;
2756 /* A helper function that throws an unimplemented error mentioning a
2757 given DWARF operator. */
2760 unimplemented (unsigned int op
)
2762 const char *name
= get_DW_OP_name (op
);
2765 error (_("DWARF operator %s cannot be translated to an agent expression"),
2768 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2769 "to an agent expression"),
2773 /* See dwarf2loc.h. */
2776 dwarf2_reg_to_regnum_or_error (struct gdbarch
*arch
, int dwarf_reg
)
2778 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2780 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
2784 /* A helper function that emits an access to memory. ARCH is the
2785 target architecture. EXPR is the expression which we are building.
2786 NBITS is the number of bits we want to read. This emits the
2787 opcodes needed to read the memory and then extract the desired
2791 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2793 ULONGEST nbytes
= (nbits
+ 7) / 8;
2795 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2798 ax_trace_quick (expr
, nbytes
);
2801 ax_simple (expr
, aop_ref8
);
2802 else if (nbits
<= 16)
2803 ax_simple (expr
, aop_ref16
);
2804 else if (nbits
<= 32)
2805 ax_simple (expr
, aop_ref32
);
2807 ax_simple (expr
, aop_ref64
);
2809 /* If we read exactly the number of bytes we wanted, we're done. */
2810 if (8 * nbytes
== nbits
)
2813 if (gdbarch_bits_big_endian (arch
))
2815 /* On a bits-big-endian machine, we want the high-order
2817 ax_const_l (expr
, 8 * nbytes
- nbits
);
2818 ax_simple (expr
, aop_rsh_unsigned
);
2822 /* On a bits-little-endian box, we want the low-order NBITS. */
2823 ax_zero_ext (expr
, nbits
);
2827 /* A helper function to return the frame's PC. */
2830 get_ax_pc (void *baton
)
2832 struct agent_expr
*expr
= baton
;
2837 /* Compile a DWARF location expression to an agent expression.
2839 EXPR is the agent expression we are building.
2840 LOC is the agent value we modify.
2841 ARCH is the architecture.
2842 ADDR_SIZE is the size of addresses, in bytes.
2843 OP_PTR is the start of the location expression.
2844 OP_END is one past the last byte of the location expression.
2846 This will throw an exception for various kinds of errors -- for
2847 example, if the expression cannot be compiled, or if the expression
2851 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2852 struct gdbarch
*arch
, unsigned int addr_size
,
2853 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
2854 struct dwarf2_per_cu_data
*per_cu
)
2856 struct cleanup
*cleanups
;
2858 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
2859 const gdb_byte
* const base
= op_ptr
;
2860 const gdb_byte
*previous_piece
= op_ptr
;
2861 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2862 ULONGEST bits_collected
= 0;
2863 unsigned int addr_size_bits
= 8 * addr_size
;
2864 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
2866 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
2867 cleanups
= make_cleanup (xfree
, offsets
);
2869 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
2872 make_cleanup (VEC_cleanup (int), &dw_labels
);
2873 make_cleanup (VEC_cleanup (int), &patches
);
2875 /* By default we are making an address. */
2876 loc
->kind
= axs_lvalue_memory
;
2878 while (op_ptr
< op_end
)
2880 enum dwarf_location_atom op
= *op_ptr
;
2881 uint64_t uoffset
, reg
;
2885 offsets
[op_ptr
- base
] = expr
->len
;
2888 /* Our basic approach to code generation is to map DWARF
2889 operations directly to AX operations. However, there are
2892 First, DWARF works on address-sized units, but AX always uses
2893 LONGEST. For most operations we simply ignore this
2894 difference; instead we generate sign extensions as needed
2895 before division and comparison operations. It would be nice
2896 to omit the sign extensions, but there is no way to determine
2897 the size of the target's LONGEST. (This code uses the size
2898 of the host LONGEST in some cases -- that is a bug but it is
2901 Second, some DWARF operations cannot be translated to AX.
2902 For these we simply fail. See
2903 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2938 ax_const_l (expr
, op
- DW_OP_lit0
);
2942 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2943 op_ptr
+= addr_size
;
2944 /* Some versions of GCC emit DW_OP_addr before
2945 DW_OP_GNU_push_tls_address. In this case the value is an
2946 index, not an address. We don't support things like
2947 branching between the address and the TLS op. */
2948 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2949 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
2950 ax_const_l (expr
, uoffset
);
2954 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2958 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2962 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2966 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2970 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2974 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2978 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2982 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2986 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2987 ax_const_l (expr
, uoffset
);
2990 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2991 ax_const_l (expr
, offset
);
3026 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3027 loc
->u
.reg
= dwarf2_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3028 loc
->kind
= axs_lvalue_register
;
3032 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3033 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3034 loc
->u
.reg
= dwarf2_reg_to_regnum_or_error (arch
, reg
);
3035 loc
->kind
= axs_lvalue_register
;
3038 case DW_OP_implicit_value
:
3042 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3043 if (op_ptr
+ len
> op_end
)
3044 error (_("DW_OP_implicit_value: too few bytes available."));
3045 if (len
> sizeof (ULONGEST
))
3046 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3049 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3052 dwarf_expr_require_composition (op_ptr
, op_end
,
3053 "DW_OP_implicit_value");
3055 loc
->kind
= axs_rvalue
;
3059 case DW_OP_stack_value
:
3060 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3061 loc
->kind
= axs_rvalue
;
3096 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3097 i
= dwarf2_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3101 ax_const_l (expr
, offset
);
3102 ax_simple (expr
, aop_add
);
3107 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3108 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3109 i
= dwarf2_reg_to_regnum_or_error (arch
, reg
);
3113 ax_const_l (expr
, offset
);
3114 ax_simple (expr
, aop_add
);
3120 const gdb_byte
*datastart
;
3122 const struct block
*b
;
3123 struct symbol
*framefunc
;
3125 b
= block_for_pc (expr
->scope
);
3128 error (_("No block found for address"));
3130 framefunc
= block_linkage_function (b
);
3133 error (_("No function found for block"));
3135 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3136 &datastart
, &datalen
);
3138 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3139 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
3140 datastart
+ datalen
, per_cu
);
3141 if (loc
->kind
== axs_lvalue_register
)
3142 require_rvalue (expr
, loc
);
3146 ax_const_l (expr
, offset
);
3147 ax_simple (expr
, aop_add
);
3150 loc
->kind
= axs_lvalue_memory
;
3155 ax_simple (expr
, aop_dup
);
3159 ax_simple (expr
, aop_pop
);
3164 ax_pick (expr
, offset
);
3168 ax_simple (expr
, aop_swap
);
3176 ax_simple (expr
, aop_rot
);
3180 case DW_OP_deref_size
:
3184 if (op
== DW_OP_deref_size
)
3189 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3190 error (_("Unsupported size %d in %s"),
3191 size
, get_DW_OP_name (op
));
3192 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3197 /* Sign extend the operand. */
3198 ax_ext (expr
, addr_size_bits
);
3199 ax_simple (expr
, aop_dup
);
3200 ax_const_l (expr
, 0);
3201 ax_simple (expr
, aop_less_signed
);
3202 ax_simple (expr
, aop_log_not
);
3203 i
= ax_goto (expr
, aop_if_goto
);
3204 /* We have to emit 0 - X. */
3205 ax_const_l (expr
, 0);
3206 ax_simple (expr
, aop_swap
);
3207 ax_simple (expr
, aop_sub
);
3208 ax_label (expr
, i
, expr
->len
);
3212 /* No need to sign extend here. */
3213 ax_const_l (expr
, 0);
3214 ax_simple (expr
, aop_swap
);
3215 ax_simple (expr
, aop_sub
);
3219 /* Sign extend the operand. */
3220 ax_ext (expr
, addr_size_bits
);
3221 ax_simple (expr
, aop_bit_not
);
3224 case DW_OP_plus_uconst
:
3225 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3226 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3227 but we micro-optimize anyhow. */
3230 ax_const_l (expr
, reg
);
3231 ax_simple (expr
, aop_add
);
3236 ax_simple (expr
, aop_bit_and
);
3240 /* Sign extend the operands. */
3241 ax_ext (expr
, addr_size_bits
);
3242 ax_simple (expr
, aop_swap
);
3243 ax_ext (expr
, addr_size_bits
);
3244 ax_simple (expr
, aop_swap
);
3245 ax_simple (expr
, aop_div_signed
);
3249 ax_simple (expr
, aop_sub
);
3253 ax_simple (expr
, aop_rem_unsigned
);
3257 ax_simple (expr
, aop_mul
);
3261 ax_simple (expr
, aop_bit_or
);
3265 ax_simple (expr
, aop_add
);
3269 ax_simple (expr
, aop_lsh
);
3273 ax_simple (expr
, aop_rsh_unsigned
);
3277 ax_simple (expr
, aop_rsh_signed
);
3281 ax_simple (expr
, aop_bit_xor
);
3285 /* Sign extend the operands. */
3286 ax_ext (expr
, addr_size_bits
);
3287 ax_simple (expr
, aop_swap
);
3288 ax_ext (expr
, addr_size_bits
);
3289 /* Note no swap here: A <= B is !(B < A). */
3290 ax_simple (expr
, aop_less_signed
);
3291 ax_simple (expr
, aop_log_not
);
3295 /* Sign extend the operands. */
3296 ax_ext (expr
, addr_size_bits
);
3297 ax_simple (expr
, aop_swap
);
3298 ax_ext (expr
, addr_size_bits
);
3299 ax_simple (expr
, aop_swap
);
3300 /* A >= B is !(A < B). */
3301 ax_simple (expr
, aop_less_signed
);
3302 ax_simple (expr
, aop_log_not
);
3306 /* Sign extend the operands. */
3307 ax_ext (expr
, addr_size_bits
);
3308 ax_simple (expr
, aop_swap
);
3309 ax_ext (expr
, addr_size_bits
);
3310 /* No need for a second swap here. */
3311 ax_simple (expr
, aop_equal
);
3315 /* Sign extend the operands. */
3316 ax_ext (expr
, addr_size_bits
);
3317 ax_simple (expr
, aop_swap
);
3318 ax_ext (expr
, addr_size_bits
);
3319 ax_simple (expr
, aop_swap
);
3320 ax_simple (expr
, aop_less_signed
);
3324 /* Sign extend the operands. */
3325 ax_ext (expr
, addr_size_bits
);
3326 ax_simple (expr
, aop_swap
);
3327 ax_ext (expr
, addr_size_bits
);
3328 /* Note no swap here: A > B is B < A. */
3329 ax_simple (expr
, aop_less_signed
);
3333 /* Sign extend the operands. */
3334 ax_ext (expr
, addr_size_bits
);
3335 ax_simple (expr
, aop_swap
);
3336 ax_ext (expr
, addr_size_bits
);
3337 /* No need for a swap here. */
3338 ax_simple (expr
, aop_equal
);
3339 ax_simple (expr
, aop_log_not
);
3342 case DW_OP_call_frame_cfa
:
3345 CORE_ADDR text_offset
;
3347 const gdb_byte
*cfa_start
, *cfa_end
;
3349 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3351 &text_offset
, &cfa_start
, &cfa_end
))
3354 ax_reg (expr
, regnum
);
3357 ax_const_l (expr
, off
);
3358 ax_simple (expr
, aop_add
);
3363 /* Another expression. */
3364 ax_const_l (expr
, text_offset
);
3365 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3366 cfa_start
, cfa_end
, per_cu
);
3369 loc
->kind
= axs_lvalue_memory
;
3373 case DW_OP_GNU_push_tls_address
:
3377 case DW_OP_push_object_address
:
3382 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3384 i
= ax_goto (expr
, aop_goto
);
3385 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3386 VEC_safe_push (int, patches
, i
);
3390 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3392 /* Zero extend the operand. */
3393 ax_zero_ext (expr
, addr_size_bits
);
3394 i
= ax_goto (expr
, aop_if_goto
);
3395 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3396 VEC_safe_push (int, patches
, i
);
3403 case DW_OP_bit_piece
:
3405 uint64_t size
, offset
;
3407 if (op_ptr
- 1 == previous_piece
)
3408 error (_("Cannot translate empty pieces to agent expressions"));
3409 previous_piece
= op_ptr
- 1;
3411 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3412 if (op
== DW_OP_piece
)
3418 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3420 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3421 error (_("Expression pieces exceed word size"));
3423 /* Access the bits. */
3426 case axs_lvalue_register
:
3427 ax_reg (expr
, loc
->u
.reg
);
3430 case axs_lvalue_memory
:
3431 /* Offset the pointer, if needed. */
3434 ax_const_l (expr
, offset
/ 8);
3435 ax_simple (expr
, aop_add
);
3438 access_memory (arch
, expr
, size
);
3442 /* For a bits-big-endian target, shift up what we already
3443 have. For a bits-little-endian target, shift up the
3444 new data. Note that there is a potential bug here if
3445 the DWARF expression leaves multiple values on the
3447 if (bits_collected
> 0)
3449 if (bits_big_endian
)
3451 ax_simple (expr
, aop_swap
);
3452 ax_const_l (expr
, size
);
3453 ax_simple (expr
, aop_lsh
);
3454 /* We don't need a second swap here, because
3455 aop_bit_or is symmetric. */
3459 ax_const_l (expr
, size
);
3460 ax_simple (expr
, aop_lsh
);
3462 ax_simple (expr
, aop_bit_or
);
3465 bits_collected
+= size
;
3466 loc
->kind
= axs_rvalue
;
3470 case DW_OP_GNU_uninit
:
3476 struct dwarf2_locexpr_baton block
;
3477 int size
= (op
== DW_OP_call2
? 2 : 4);
3480 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3483 offset
.cu_off
= uoffset
;
3484 block
= dwarf2_fetch_die_loc_cu_off (offset
, per_cu
,
3487 /* DW_OP_call_ref is currently not supported. */
3488 gdb_assert (block
.per_cu
== per_cu
);
3490 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3491 block
.data
, block
.data
+ block
.size
,
3496 case DW_OP_call_ref
:
3504 /* Patch all the branches we emitted. */
3505 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
3507 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
3509 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3510 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
3513 do_cleanups (cleanups
);
3517 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3518 evaluator to calculate the location. */
3519 static struct value
*
3520 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3522 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3525 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3526 dlbaton
->size
, dlbaton
->per_cu
);
3531 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3532 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3535 static struct value
*
3536 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3538 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3540 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3544 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3546 locexpr_read_needs_frame (struct symbol
*symbol
)
3548 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3550 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
3554 /* Return true if DATA points to the end of a piece. END is one past
3555 the last byte in the expression. */
3558 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3560 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3563 /* Helper for locexpr_describe_location_piece that finds the name of a
3567 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3571 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
3572 return gdbarch_register_name (gdbarch
, regnum
);
3575 /* Nicely describe a single piece of a location, returning an updated
3576 position in the bytecode sequence. This function cannot recognize
3577 all locations; if a location is not recognized, it simply returns
3578 DATA. If there is an error during reading, e.g. we run off the end
3579 of the buffer, an error is thrown. */
3581 static const gdb_byte
*
3582 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3583 CORE_ADDR addr
, struct objfile
*objfile
,
3584 struct dwarf2_per_cu_data
*per_cu
,
3585 const gdb_byte
*data
, const gdb_byte
*end
,
3586 unsigned int addr_size
)
3588 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3591 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3593 fprintf_filtered (stream
, _("a variable in $%s"),
3594 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3597 else if (data
[0] == DW_OP_regx
)
3601 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3602 fprintf_filtered (stream
, _("a variable in $%s"),
3603 locexpr_regname (gdbarch
, reg
));
3605 else if (data
[0] == DW_OP_fbreg
)
3607 const struct block
*b
;
3608 struct symbol
*framefunc
;
3610 int64_t frame_offset
;
3611 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3613 int64_t base_offset
= 0;
3615 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3616 if (!piece_end_p (new_data
, end
))
3620 b
= block_for_pc (addr
);
3623 error (_("No block found for address for symbol \"%s\"."),
3624 SYMBOL_PRINT_NAME (symbol
));
3626 framefunc
= block_linkage_function (b
);
3629 error (_("No function found for block for symbol \"%s\"."),
3630 SYMBOL_PRINT_NAME (symbol
));
3632 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3634 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3636 const gdb_byte
*buf_end
;
3638 frame_reg
= base_data
[0] - DW_OP_breg0
;
3639 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3641 if (buf_end
!= base_data
+ base_size
)
3642 error (_("Unexpected opcode after "
3643 "DW_OP_breg%u for symbol \"%s\"."),
3644 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3646 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3648 /* The frame base is just the register, with no offset. */
3649 frame_reg
= base_data
[0] - DW_OP_reg0
;
3654 /* We don't know what to do with the frame base expression,
3655 so we can't trace this variable; give up. */
3659 fprintf_filtered (stream
,
3660 _("a variable at frame base reg $%s offset %s+%s"),
3661 locexpr_regname (gdbarch
, frame_reg
),
3662 plongest (base_offset
), plongest (frame_offset
));
3664 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3665 && piece_end_p (data
, end
))
3669 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3671 fprintf_filtered (stream
,
3672 _("a variable at offset %s from base reg $%s"),
3674 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3677 /* The location expression for a TLS variable looks like this (on a
3680 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3681 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3683 0x3 is the encoding for DW_OP_addr, which has an operand as long
3684 as the size of an address on the target machine (here is 8
3685 bytes). Note that more recent version of GCC emit DW_OP_const4u
3686 or DW_OP_const8u, depending on address size, rather than
3687 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3688 The operand represents the offset at which the variable is within
3689 the thread local storage. */
3691 else if (data
+ 1 + addr_size
< end
3692 && (data
[0] == DW_OP_addr
3693 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3694 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3695 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3696 && piece_end_p (data
+ 2 + addr_size
, end
))
3699 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3700 gdbarch_byte_order (gdbarch
));
3702 fprintf_filtered (stream
,
3703 _("a thread-local variable at offset 0x%s "
3704 "in the thread-local storage for `%s'"),
3705 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3707 data
+= 1 + addr_size
+ 1;
3710 /* With -gsplit-dwarf a TLS variable can also look like this:
3711 DW_AT_location : 3 byte block: fc 4 e0
3712 (DW_OP_GNU_const_index: 4;
3713 DW_OP_GNU_push_tls_address) */
3714 else if (data
+ 3 <= end
3715 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3716 && data
[0] == DW_OP_GNU_const_index
3718 && data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3719 && piece_end_p (data
+ 2 + leb128_size
, end
))
3723 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3724 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3725 fprintf_filtered (stream
,
3726 _("a thread-local variable at offset 0x%s "
3727 "in the thread-local storage for `%s'"),
3728 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3732 else if (data
[0] >= DW_OP_lit0
3733 && data
[0] <= DW_OP_lit31
3735 && data
[1] == DW_OP_stack_value
)
3737 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3744 /* Disassemble an expression, stopping at the end of a piece or at the
3745 end of the expression. Returns a pointer to the next unread byte
3746 in the input expression. If ALL is nonzero, then this function
3747 will keep going until it reaches the end of the expression.
3748 If there is an error during reading, e.g. we run off the end
3749 of the buffer, an error is thrown. */
3751 static const gdb_byte
*
3752 disassemble_dwarf_expression (struct ui_file
*stream
,
3753 struct gdbarch
*arch
, unsigned int addr_size
,
3754 int offset_size
, const gdb_byte
*start
,
3755 const gdb_byte
*data
, const gdb_byte
*end
,
3756 int indent
, int all
,
3757 struct dwarf2_per_cu_data
*per_cu
)
3761 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3763 enum dwarf_location_atom op
= *data
++;
3768 name
= get_DW_OP_name (op
);
3771 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3772 op
, (long) (data
- 1 - start
));
3773 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3774 (long) (data
- 1 - start
), name
);
3779 ul
= extract_unsigned_integer (data
, addr_size
,
3780 gdbarch_byte_order (arch
));
3782 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3786 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3788 fprintf_filtered (stream
, " %s", pulongest (ul
));
3791 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3793 fprintf_filtered (stream
, " %s", plongest (l
));
3796 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3798 fprintf_filtered (stream
, " %s", pulongest (ul
));
3801 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3803 fprintf_filtered (stream
, " %s", plongest (l
));
3806 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3808 fprintf_filtered (stream
, " %s", pulongest (ul
));
3811 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3813 fprintf_filtered (stream
, " %s", plongest (l
));
3816 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3818 fprintf_filtered (stream
, " %s", pulongest (ul
));
3821 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3823 fprintf_filtered (stream
, " %s", plongest (l
));
3826 data
= safe_read_uleb128 (data
, end
, &ul
);
3827 fprintf_filtered (stream
, " %s", pulongest (ul
));
3830 data
= safe_read_sleb128 (data
, end
, &l
);
3831 fprintf_filtered (stream
, " %s", plongest (l
));
3866 fprintf_filtered (stream
, " [$%s]",
3867 locexpr_regname (arch
, op
- DW_OP_reg0
));
3871 data
= safe_read_uleb128 (data
, end
, &ul
);
3872 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3873 locexpr_regname (arch
, (int) ul
));
3876 case DW_OP_implicit_value
:
3877 data
= safe_read_uleb128 (data
, end
, &ul
);
3879 fprintf_filtered (stream
, " %s", pulongest (ul
));
3914 data
= safe_read_sleb128 (data
, end
, &l
);
3915 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3916 locexpr_regname (arch
, op
- DW_OP_breg0
));
3920 data
= safe_read_uleb128 (data
, end
, &ul
);
3921 data
= safe_read_sleb128 (data
, end
, &l
);
3922 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3924 locexpr_regname (arch
, (int) ul
),
3929 data
= safe_read_sleb128 (data
, end
, &l
);
3930 fprintf_filtered (stream
, " %s", plongest (l
));
3933 case DW_OP_xderef_size
:
3934 case DW_OP_deref_size
:
3936 fprintf_filtered (stream
, " %d", *data
);
3940 case DW_OP_plus_uconst
:
3941 data
= safe_read_uleb128 (data
, end
, &ul
);
3942 fprintf_filtered (stream
, " %s", pulongest (ul
));
3946 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3948 fprintf_filtered (stream
, " to %ld",
3949 (long) (data
+ l
- start
));
3953 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3955 fprintf_filtered (stream
, " %ld",
3956 (long) (data
+ l
- start
));
3960 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3962 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3966 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3968 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3971 case DW_OP_call_ref
:
3972 ul
= extract_unsigned_integer (data
, offset_size
,
3973 gdbarch_byte_order (arch
));
3974 data
+= offset_size
;
3975 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3979 data
= safe_read_uleb128 (data
, end
, &ul
);
3980 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3983 case DW_OP_bit_piece
:
3987 data
= safe_read_uleb128 (data
, end
, &ul
);
3988 data
= safe_read_uleb128 (data
, end
, &offset
);
3989 fprintf_filtered (stream
, " size %s offset %s (bits)",
3990 pulongest (ul
), pulongest (offset
));
3994 case DW_OP_GNU_implicit_pointer
:
3996 ul
= extract_unsigned_integer (data
, offset_size
,
3997 gdbarch_byte_order (arch
));
3998 data
+= offset_size
;
4000 data
= safe_read_sleb128 (data
, end
, &l
);
4002 fprintf_filtered (stream
, " DIE %s offset %s",
4003 phex_nz (ul
, offset_size
),
4008 case DW_OP_GNU_deref_type
:
4010 int addr_size
= *data
++;
4014 data
= safe_read_uleb128 (data
, end
, &ul
);
4016 type
= dwarf2_get_die_type (offset
, per_cu
);
4017 fprintf_filtered (stream
, "<");
4018 type_print (type
, "", stream
, -1);
4019 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
.cu_off
, 0),
4024 case DW_OP_GNU_const_type
:
4029 data
= safe_read_uleb128 (data
, end
, &ul
);
4030 type_die
.cu_off
= ul
;
4031 type
= dwarf2_get_die_type (type_die
, per_cu
);
4032 fprintf_filtered (stream
, "<");
4033 type_print (type
, "", stream
, -1);
4034 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
4038 case DW_OP_GNU_regval_type
:
4044 data
= safe_read_uleb128 (data
, end
, ®
);
4045 data
= safe_read_uleb128 (data
, end
, &ul
);
4046 type_die
.cu_off
= ul
;
4048 type
= dwarf2_get_die_type (type_die
, per_cu
);
4049 fprintf_filtered (stream
, "<");
4050 type_print (type
, "", stream
, -1);
4051 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4052 phex_nz (type_die
.cu_off
, 0),
4053 locexpr_regname (arch
, reg
));
4057 case DW_OP_GNU_convert
:
4058 case DW_OP_GNU_reinterpret
:
4062 data
= safe_read_uleb128 (data
, end
, &ul
);
4063 type_die
.cu_off
= ul
;
4065 if (type_die
.cu_off
== 0)
4066 fprintf_filtered (stream
, "<0>");
4071 type
= dwarf2_get_die_type (type_die
, per_cu
);
4072 fprintf_filtered (stream
, "<");
4073 type_print (type
, "", stream
, -1);
4074 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
4079 case DW_OP_GNU_entry_value
:
4080 data
= safe_read_uleb128 (data
, end
, &ul
);
4081 fputc_filtered ('\n', stream
);
4082 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4083 start
, data
, data
+ ul
, indent
+ 2,
4088 case DW_OP_GNU_parameter_ref
:
4089 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4091 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4094 case DW_OP_GNU_addr_index
:
4095 data
= safe_read_uleb128 (data
, end
, &ul
);
4096 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4097 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4099 case DW_OP_GNU_const_index
:
4100 data
= safe_read_uleb128 (data
, end
, &ul
);
4101 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4102 fprintf_filtered (stream
, " %s", pulongest (ul
));
4106 fprintf_filtered (stream
, "\n");
4112 /* Describe a single location, which may in turn consist of multiple
4116 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4117 struct ui_file
*stream
,
4118 const gdb_byte
*data
, size_t size
,
4119 struct objfile
*objfile
, unsigned int addr_size
,
4120 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4122 const gdb_byte
*end
= data
+ size
;
4123 int first_piece
= 1, bad
= 0;
4127 const gdb_byte
*here
= data
;
4128 int disassemble
= 1;
4133 fprintf_filtered (stream
, _(", and "));
4135 if (!dwarf2_always_disassemble
)
4137 data
= locexpr_describe_location_piece (symbol
, stream
,
4138 addr
, objfile
, per_cu
,
4139 data
, end
, addr_size
);
4140 /* If we printed anything, or if we have an empty piece,
4141 then don't disassemble. */
4143 || data
[0] == DW_OP_piece
4144 || data
[0] == DW_OP_bit_piece
)
4149 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4150 data
= disassemble_dwarf_expression (stream
,
4151 get_objfile_arch (objfile
),
4152 addr_size
, offset_size
, data
,
4154 dwarf2_always_disassemble
,
4160 int empty
= data
== here
;
4163 fprintf_filtered (stream
, " ");
4164 if (data
[0] == DW_OP_piece
)
4168 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4171 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4174 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4177 else if (data
[0] == DW_OP_bit_piece
)
4179 uint64_t bits
, offset
;
4181 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4182 data
= safe_read_uleb128 (data
, end
, &offset
);
4185 fprintf_filtered (stream
,
4186 _("an empty %s-bit piece"),
4189 fprintf_filtered (stream
,
4190 _(" [%s-bit piece, offset %s bits]"),
4191 pulongest (bits
), pulongest (offset
));
4201 if (bad
|| data
> end
)
4202 error (_("Corrupted DWARF2 expression for \"%s\"."),
4203 SYMBOL_PRINT_NAME (symbol
));
4206 /* Print a natural-language description of SYMBOL to STREAM. This
4207 version is for a symbol with a single location. */
4210 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4211 struct ui_file
*stream
)
4213 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4214 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4215 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4216 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4218 locexpr_describe_location_1 (symbol
, addr
, stream
,
4219 dlbaton
->data
, dlbaton
->size
,
4220 objfile
, addr_size
, offset_size
,
4224 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4225 any necessary bytecode in AX. */
4228 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4229 struct agent_expr
*ax
, struct axs_value
*value
)
4231 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4232 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4234 if (dlbaton
->size
== 0)
4235 value
->optimized_out
= 1;
4237 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
4238 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4242 /* symbol_computed_ops 'generate_c_location' method. */
4245 locexpr_generate_c_location (struct symbol
*sym
, struct ui_file
*stream
,
4246 struct gdbarch
*gdbarch
,
4247 unsigned char *registers_used
,
4248 CORE_ADDR pc
, const char *result_name
)
4250 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (sym
);
4251 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4253 if (dlbaton
->size
== 0)
4254 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4256 compile_dwarf_expr_to_c (stream
, result_name
,
4257 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4258 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4262 /* The set of location functions used with the DWARF-2 expression
4264 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4265 locexpr_read_variable
,
4266 locexpr_read_variable_at_entry
,
4267 locexpr_read_needs_frame
,
4268 locexpr_describe_location
,
4269 0, /* location_has_loclist */
4270 locexpr_tracepoint_var_ref
,
4271 locexpr_generate_c_location
4275 /* Wrapper functions for location lists. These generally find
4276 the appropriate location expression and call something above. */
4278 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4279 evaluator to calculate the location. */
4280 static struct value
*
4281 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4283 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4285 const gdb_byte
*data
;
4287 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4289 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4290 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4296 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4297 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4300 Function always returns non-NULL value, it may be marked optimized out if
4301 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4302 if it cannot resolve the parameter for any reason. */
4304 static struct value
*
4305 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4307 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4308 const gdb_byte
*data
;
4312 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4313 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4315 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4317 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4319 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4322 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
4324 loclist_read_needs_frame (struct symbol
*symbol
)
4326 /* If there's a location list, then assume we need to have a frame
4327 to choose the appropriate location expression. With tracking of
4328 global variables this is not necessarily true, but such tracking
4329 is disabled in GCC at the moment until we figure out how to
4335 /* Print a natural-language description of SYMBOL to STREAM. This
4336 version applies when there is a list of different locations, each
4337 with a specified address range. */
4340 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4341 struct ui_file
*stream
)
4343 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4344 const gdb_byte
*loc_ptr
, *buf_end
;
4345 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4346 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4347 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4348 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4349 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4350 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4351 /* Adjust base_address for relocatable objects. */
4352 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4353 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4356 loc_ptr
= dlbaton
->data
;
4357 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4359 fprintf_filtered (stream
, _("multi-location:\n"));
4361 /* Iterate through locations until we run out. */
4364 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4366 enum debug_loc_kind kind
;
4367 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4369 if (dlbaton
->from_dwo
)
4370 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4371 loc_ptr
, buf_end
, &new_ptr
,
4372 &low
, &high
, byte_order
);
4374 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4376 byte_order
, addr_size
,
4381 case DEBUG_LOC_END_OF_LIST
:
4384 case DEBUG_LOC_BASE_ADDRESS
:
4385 base_address
= high
+ base_offset
;
4386 fprintf_filtered (stream
, _(" Base address %s"),
4387 paddress (gdbarch
, base_address
));
4389 case DEBUG_LOC_START_END
:
4390 case DEBUG_LOC_START_LENGTH
:
4392 case DEBUG_LOC_BUFFER_OVERFLOW
:
4393 case DEBUG_LOC_INVALID_ENTRY
:
4394 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4395 SYMBOL_PRINT_NAME (symbol
));
4397 gdb_assert_not_reached ("bad debug_loc_kind");
4400 /* Otherwise, a location expression entry. */
4401 low
+= base_address
;
4402 high
+= base_address
;
4404 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4405 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4407 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4410 /* (It would improve readability to print only the minimum
4411 necessary digits of the second number of the range.) */
4412 fprintf_filtered (stream
, _(" Range %s-%s: "),
4413 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4415 /* Now describe this particular location. */
4416 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4417 objfile
, addr_size
, offset_size
,
4420 fprintf_filtered (stream
, "\n");
4426 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4427 any necessary bytecode in AX. */
4429 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4430 struct agent_expr
*ax
, struct axs_value
*value
)
4432 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4433 const gdb_byte
*data
;
4435 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4437 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4439 value
->optimized_out
= 1;
4441 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4445 /* symbol_computed_ops 'generate_c_location' method. */
4448 loclist_generate_c_location (struct symbol
*sym
, struct ui_file
*stream
,
4449 struct gdbarch
*gdbarch
,
4450 unsigned char *registers_used
,
4451 CORE_ADDR pc
, const char *result_name
)
4453 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (sym
);
4454 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4455 const gdb_byte
*data
;
4458 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4460 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4462 compile_dwarf_expr_to_c (stream
, result_name
,
4463 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4468 /* The set of location functions used with the DWARF-2 expression
4469 evaluator and location lists. */
4470 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4471 loclist_read_variable
,
4472 loclist_read_variable_at_entry
,
4473 loclist_read_needs_frame
,
4474 loclist_describe_location
,
4475 1, /* location_has_loclist */
4476 loclist_tracepoint_var_ref
,
4477 loclist_generate_c_location
4480 /* Provide a prototype to silence -Wmissing-prototypes. */
4481 extern initialize_file_ftype _initialize_dwarf2loc
;
4484 _initialize_dwarf2loc (void)
4486 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4487 &entry_values_debug
,
4488 _("Set entry values and tail call frames "
4490 _("Show entry values and tail call frames "
4492 _("When non-zero, the process of determining "
4493 "parameter values from function entry point "
4494 "and tail call frames will be printed."),
4496 show_entry_values_debug
,
4497 &setdebuglist
, &showdebuglist
);