1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2013 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 #include "exceptions.h"
38 #include "dwarf2expr.h"
39 #include "dwarf2loc.h"
40 #include "dwarf2-frame.h"
42 #include "gdb_string.h"
43 #include "gdb_assert.h"
47 extern int dwarf2_always_disassemble
;
49 static void dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
50 const gdb_byte
**start
, size_t *length
);
52 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
;
54 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
55 struct frame_info
*frame
,
58 struct dwarf2_per_cu_data
*per_cu
,
61 /* Until these have formal names, we define these here.
62 ref: http://gcc.gnu.org/wiki/DebugFission
63 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
64 and is then followed by data specific to that entry. */
68 /* Indicates the end of the list of entries. */
69 DEBUG_LOC_END_OF_LIST
= 0,
71 /* This is followed by an unsigned LEB128 number that is an index into
72 .debug_addr and specifies the base address for all following entries. */
73 DEBUG_LOC_BASE_ADDRESS
= 1,
75 /* This is followed by two unsigned LEB128 numbers that are indices into
76 .debug_addr and specify the beginning and ending addresses, and then
77 a normal location expression as in .debug_loc. */
78 DEBUG_LOC_START_END
= 2,
80 /* This is followed by an unsigned LEB128 number that is an index into
81 .debug_addr and specifies the beginning address, and a 4 byte unsigned
82 number that specifies the length, and then a normal location expression
84 DEBUG_LOC_START_LENGTH
= 3,
86 /* An internal value indicating there is insufficient data. */
87 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
89 /* An internal value indicating an invalid kind of entry was found. */
90 DEBUG_LOC_INVALID_ENTRY
= -2
93 /* Decode the addresses in a non-dwo .debug_loc entry.
94 A pointer to the next byte to examine is returned in *NEW_PTR.
95 The encoded low,high addresses are return in *LOW,*HIGH.
96 The result indicates the kind of entry found. */
98 static enum debug_loc_kind
99 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
100 const gdb_byte
**new_ptr
,
101 CORE_ADDR
*low
, CORE_ADDR
*high
,
102 enum bfd_endian byte_order
,
103 unsigned int addr_size
,
106 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
108 if (buf_end
- loc_ptr
< 2 * addr_size
)
109 return DEBUG_LOC_BUFFER_OVERFLOW
;
112 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
114 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
115 loc_ptr
+= addr_size
;
118 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
120 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
121 loc_ptr
+= addr_size
;
125 /* A base-address-selection entry. */
126 if ((*low
& base_mask
) == base_mask
)
127 return DEBUG_LOC_BASE_ADDRESS
;
129 /* An end-of-list entry. */
130 if (*low
== 0 && *high
== 0)
131 return DEBUG_LOC_END_OF_LIST
;
133 return DEBUG_LOC_START_END
;
136 /* Decode the addresses in .debug_loc.dwo entry.
137 A pointer to the next byte to examine is returned in *NEW_PTR.
138 The encoded low,high addresses are return in *LOW,*HIGH.
139 The result indicates the kind of entry found. */
141 static enum debug_loc_kind
142 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
143 const gdb_byte
*loc_ptr
,
144 const gdb_byte
*buf_end
,
145 const gdb_byte
**new_ptr
,
146 CORE_ADDR
*low
, CORE_ADDR
*high
,
147 enum bfd_endian byte_order
)
149 uint64_t low_index
, high_index
;
151 if (loc_ptr
== buf_end
)
152 return DEBUG_LOC_BUFFER_OVERFLOW
;
156 case DEBUG_LOC_END_OF_LIST
:
158 return DEBUG_LOC_END_OF_LIST
;
159 case DEBUG_LOC_BASE_ADDRESS
:
161 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
163 return DEBUG_LOC_BUFFER_OVERFLOW
;
164 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
166 return DEBUG_LOC_BASE_ADDRESS
;
167 case DEBUG_LOC_START_END
:
168 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
170 return DEBUG_LOC_BUFFER_OVERFLOW
;
171 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
172 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
174 return DEBUG_LOC_BUFFER_OVERFLOW
;
175 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
177 return DEBUG_LOC_START_END
;
178 case DEBUG_LOC_START_LENGTH
:
179 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
181 return DEBUG_LOC_BUFFER_OVERFLOW
;
182 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
183 if (loc_ptr
+ 4 > buf_end
)
184 return DEBUG_LOC_BUFFER_OVERFLOW
;
186 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
187 *new_ptr
= loc_ptr
+ 4;
188 return DEBUG_LOC_START_LENGTH
;
190 return DEBUG_LOC_INVALID_ENTRY
;
194 /* A function for dealing with location lists. Given a
195 symbol baton (BATON) and a pc value (PC), find the appropriate
196 location expression, set *LOCEXPR_LENGTH, and return a pointer
197 to the beginning of the expression. Returns NULL on failure.
199 For now, only return the first matching location expression; there
200 can be more than one in the list. */
203 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
204 size_t *locexpr_length
, CORE_ADDR pc
)
206 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
207 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
208 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
209 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
210 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
211 /* Adjust base_address for relocatable objects. */
212 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
213 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
214 const gdb_byte
*loc_ptr
, *buf_end
;
216 loc_ptr
= baton
->data
;
217 buf_end
= baton
->data
+ baton
->size
;
221 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
223 enum debug_loc_kind kind
;
224 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
227 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
228 loc_ptr
, buf_end
, &new_ptr
,
229 &low
, &high
, byte_order
);
231 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
233 byte_order
, addr_size
,
238 case DEBUG_LOC_END_OF_LIST
:
241 case DEBUG_LOC_BASE_ADDRESS
:
242 base_address
= high
+ base_offset
;
244 case DEBUG_LOC_START_END
:
245 case DEBUG_LOC_START_LENGTH
:
247 case DEBUG_LOC_BUFFER_OVERFLOW
:
248 case DEBUG_LOC_INVALID_ENTRY
:
249 error (_("dwarf2_find_location_expression: "
250 "Corrupted DWARF expression."));
252 gdb_assert_not_reached ("bad debug_loc_kind");
255 /* Otherwise, a location expression entry. */
257 high
+= base_address
;
259 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
262 if (low
== high
&& pc
== low
)
264 /* This is entry PC record present only at entry point
265 of a function. Verify it is really the function entry point. */
267 struct block
*pc_block
= block_for_pc (pc
);
268 struct symbol
*pc_func
= NULL
;
271 pc_func
= block_linkage_function (pc_block
);
273 if (pc_func
&& pc
== BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func
)))
275 *locexpr_length
= length
;
280 if (pc
>= low
&& pc
< high
)
282 *locexpr_length
= length
;
290 /* This is the baton used when performing dwarf2 expression
292 struct dwarf_expr_baton
294 struct frame_info
*frame
;
295 struct dwarf2_per_cu_data
*per_cu
;
298 /* Helper functions for dwarf2_evaluate_loc_desc. */
300 /* Using the frame specified in BATON, return the value of register
301 REGNUM, treated as a pointer. */
303 dwarf_expr_read_reg (void *baton
, int dwarf_regnum
)
305 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
306 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
310 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
311 result
= address_from_register (builtin_type (gdbarch
)->builtin_data_ptr
,
312 regnum
, debaton
->frame
);
316 /* Read memory at ADDR (length LEN) into BUF. */
319 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
321 read_memory (addr
, buf
, len
);
324 /* Using the frame specified in BATON, find the location expression
325 describing the frame base. Return a pointer to it in START and
326 its length in LENGTH. */
328 dwarf_expr_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
330 /* FIXME: cagney/2003-03-26: This code should be using
331 get_frame_base_address(), and then implement a dwarf2 specific
333 struct symbol
*framefunc
;
334 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
335 struct block
*bl
= get_frame_block (debaton
->frame
, NULL
);
338 error (_("frame address is not available."));
340 /* Use block_linkage_function, which returns a real (not inlined)
341 function, instead of get_frame_function, which may return an
343 framefunc
= block_linkage_function (bl
);
345 /* If we found a frame-relative symbol then it was certainly within
346 some function associated with a frame. If we can't find the frame,
347 something has gone wrong. */
348 gdb_assert (framefunc
!= NULL
);
350 dwarf_expr_frame_base_1 (framefunc
,
351 get_frame_address_in_block (debaton
->frame
),
356 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
357 const gdb_byte
**start
, size_t *length
)
359 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
361 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
363 struct dwarf2_loclist_baton
*symbaton
;
365 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
366 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
370 struct dwarf2_locexpr_baton
*symbaton
;
372 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
373 if (symbaton
!= NULL
)
375 *length
= symbaton
->size
;
376 *start
= symbaton
->data
;
383 error (_("Could not find the frame base for \"%s\"."),
384 SYMBOL_NATURAL_NAME (framefunc
));
387 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
388 the frame in BATON. */
391 dwarf_expr_frame_cfa (void *baton
)
393 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
395 return dwarf2_frame_cfa (debaton
->frame
);
398 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
399 the frame in BATON. */
402 dwarf_expr_frame_pc (void *baton
)
404 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
406 return get_frame_address_in_block (debaton
->frame
);
409 /* Using the objfile specified in BATON, find the address for the
410 current thread's thread-local storage with offset OFFSET. */
412 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
414 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
415 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
417 return target_translate_tls_address (objfile
, offset
);
420 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
421 current CU (as is PER_CU). State of the CTX is not affected by the
425 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
426 struct dwarf2_per_cu_data
*per_cu
,
427 CORE_ADDR (*get_frame_pc
) (void *baton
),
430 struct dwarf2_locexpr_baton block
;
432 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, get_frame_pc
, baton
);
434 /* DW_OP_call_ref is currently not supported. */
435 gdb_assert (block
.per_cu
== per_cu
);
437 dwarf_expr_eval (ctx
, block
.data
, block
.size
);
440 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
443 dwarf_expr_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
445 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
447 per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
448 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
451 /* Callback function for dwarf2_evaluate_loc_desc. */
454 dwarf_expr_get_base_type (struct dwarf_expr_context
*ctx
,
455 cu_offset die_offset
)
457 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
459 return dwarf2_get_die_type (die_offset
, debaton
->per_cu
);
462 /* See dwarf2loc.h. */
464 unsigned int entry_values_debug
= 0;
466 /* Helper to set entry_values_debug. */
469 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
470 struct cmd_list_element
*c
, const char *value
)
472 fprintf_filtered (file
,
473 _("Entry values and tail call frames debugging is %s.\n"),
477 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
478 CALLER_FRAME (for registers) can be NULL if it is not known. This function
479 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
482 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
483 struct call_site
*call_site
,
484 struct frame_info
*caller_frame
)
486 switch (FIELD_LOC_KIND (call_site
->target
))
488 case FIELD_LOC_KIND_DWARF_BLOCK
:
490 struct dwarf2_locexpr_baton
*dwarf_block
;
492 struct type
*caller_core_addr_type
;
493 struct gdbarch
*caller_arch
;
495 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
496 if (dwarf_block
== NULL
)
498 struct minimal_symbol
*msym
;
500 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
501 throw_error (NO_ENTRY_VALUE_ERROR
,
502 _("DW_AT_GNU_call_site_target is not specified "
504 paddress (call_site_gdbarch
, call_site
->pc
),
505 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
508 if (caller_frame
== NULL
)
510 struct minimal_symbol
*msym
;
512 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
513 throw_error (NO_ENTRY_VALUE_ERROR
,
514 _("DW_AT_GNU_call_site_target DWARF block resolving "
515 "requires known frame which is currently not "
516 "available at %s in %s"),
517 paddress (call_site_gdbarch
, call_site
->pc
),
518 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
521 caller_arch
= get_frame_arch (caller_frame
);
522 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
523 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
524 dwarf_block
->data
, dwarf_block
->size
,
525 dwarf_block
->per_cu
);
526 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
528 if (VALUE_LVAL (val
) == lval_memory
)
529 return value_address (val
);
531 return value_as_address (val
);
534 case FIELD_LOC_KIND_PHYSNAME
:
536 const char *physname
;
537 struct minimal_symbol
*msym
;
539 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
540 msym
= lookup_minimal_symbol_text (physname
, NULL
);
543 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
544 throw_error (NO_ENTRY_VALUE_ERROR
,
545 _("Cannot find function \"%s\" for a call site target "
547 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
548 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
551 return SYMBOL_VALUE_ADDRESS (msym
);
554 case FIELD_LOC_KIND_PHYSADDR
:
555 return FIELD_STATIC_PHYSADDR (call_site
->target
);
558 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
562 /* Convert function entry point exact address ADDR to the function which is
563 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
564 NO_ENTRY_VALUE_ERROR otherwise. */
566 static struct symbol
*
567 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
569 struct symbol
*sym
= find_pc_function (addr
);
572 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
573 throw_error (NO_ENTRY_VALUE_ERROR
,
574 _("DW_TAG_GNU_call_site resolving failed to find function "
575 "name for address %s"),
576 paddress (gdbarch
, addr
));
578 type
= SYMBOL_TYPE (sym
);
579 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
580 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
585 /* Verify function with entry point exact address ADDR can never call itself
586 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
587 can call itself via tail calls.
589 If a funtion can tail call itself its entry value based parameters are
590 unreliable. There is no verification whether the value of some/all
591 parameters is unchanged through the self tail call, we expect if there is
592 a self tail call all the parameters can be modified. */
595 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
597 struct obstack addr_obstack
;
598 struct cleanup
*old_chain
;
601 /* Track here CORE_ADDRs which were already visited. */
604 /* The verification is completely unordered. Track here function addresses
605 which still need to be iterated. */
606 VEC (CORE_ADDR
) *todo
= NULL
;
608 obstack_init (&addr_obstack
);
609 old_chain
= make_cleanup_obstack_free (&addr_obstack
);
610 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
611 &addr_obstack
, hashtab_obstack_allocate
,
613 make_cleanup_htab_delete (addr_hash
);
615 make_cleanup (VEC_cleanup (CORE_ADDR
), &todo
);
617 VEC_safe_push (CORE_ADDR
, todo
, verify_addr
);
618 while (!VEC_empty (CORE_ADDR
, todo
))
620 struct symbol
*func_sym
;
621 struct call_site
*call_site
;
623 addr
= VEC_pop (CORE_ADDR
, todo
);
625 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
627 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
628 call_site
; call_site
= call_site
->tail_call_next
)
630 CORE_ADDR target_addr
;
633 /* CALLER_FRAME with registers is not available for tail-call jumped
635 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
637 if (target_addr
== verify_addr
)
639 struct minimal_symbol
*msym
;
641 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
642 throw_error (NO_ENTRY_VALUE_ERROR
,
643 _("DW_OP_GNU_entry_value resolving has found "
644 "function \"%s\" at %s can call itself via tail "
646 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
647 paddress (gdbarch
, verify_addr
));
650 slot
= htab_find_slot (addr_hash
, &target_addr
, INSERT
);
653 *slot
= obstack_copy (&addr_obstack
, &target_addr
,
654 sizeof (target_addr
));
655 VEC_safe_push (CORE_ADDR
, todo
, target_addr
);
660 do_cleanups (old_chain
);
663 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
664 ENTRY_VALUES_DEBUG. */
667 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
669 CORE_ADDR addr
= call_site
->pc
;
670 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (addr
- 1);
672 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
673 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
677 /* vec.h needs single word type name, typedef it. */
678 typedef struct call_site
*call_sitep
;
680 /* Define VEC (call_sitep) functions. */
681 DEF_VEC_P (call_sitep
);
683 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
684 only top callers and bottom callees which are present in both. GDBARCH is
685 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
686 no remaining possibilities to provide unambiguous non-trivial result.
687 RESULTP should point to NULL on the first (initialization) call. Caller is
688 responsible for xfree of any RESULTP data. */
691 chain_candidate (struct gdbarch
*gdbarch
, struct call_site_chain
**resultp
,
692 VEC (call_sitep
) *chain
)
694 struct call_site_chain
*result
= *resultp
;
695 long length
= VEC_length (call_sitep
, chain
);
696 int callers
, callees
, idx
;
700 /* Create the initial chain containing all the passed PCs. */
702 result
= xmalloc (sizeof (*result
) + sizeof (*result
->call_site
)
704 result
->length
= length
;
705 result
->callers
= result
->callees
= length
;
706 memcpy (result
->call_site
, VEC_address (call_sitep
, chain
),
707 sizeof (*result
->call_site
) * length
);
710 if (entry_values_debug
)
712 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
713 for (idx
= 0; idx
< length
; idx
++)
714 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
715 fputc_unfiltered ('\n', gdb_stdlog
);
721 if (entry_values_debug
)
723 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
724 for (idx
= 0; idx
< length
; idx
++)
725 tailcall_dump (gdbarch
, VEC_index (call_sitep
, chain
, idx
));
726 fputc_unfiltered ('\n', gdb_stdlog
);
729 /* Intersect callers. */
731 callers
= min (result
->callers
, length
);
732 for (idx
= 0; idx
< callers
; idx
++)
733 if (result
->call_site
[idx
] != VEC_index (call_sitep
, chain
, idx
))
735 result
->callers
= idx
;
739 /* Intersect callees. */
741 callees
= min (result
->callees
, length
);
742 for (idx
= 0; idx
< callees
; idx
++)
743 if (result
->call_site
[result
->length
- 1 - idx
]
744 != VEC_index (call_sitep
, chain
, length
- 1 - idx
))
746 result
->callees
= idx
;
750 if (entry_values_debug
)
752 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
753 for (idx
= 0; idx
< result
->callers
; idx
++)
754 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
755 fputs_unfiltered (" |", gdb_stdlog
);
756 for (idx
= 0; idx
< result
->callees
; idx
++)
757 tailcall_dump (gdbarch
, result
->call_site
[result
->length
758 - result
->callees
+ idx
]);
759 fputc_unfiltered ('\n', gdb_stdlog
);
762 if (result
->callers
== 0 && result
->callees
== 0)
764 /* There are no common callers or callees. It could be also a direct
765 call (which has length 0) with ambiguous possibility of an indirect
766 call - CALLERS == CALLEES == 0 is valid during the first allocation
767 but any subsequence processing of such entry means ambiguity. */
773 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
774 PC again. In such case there must be two different code paths to reach
775 it, therefore some of the former determined intermediate PCs must differ
776 and the unambiguous chain gets shortened. */
777 gdb_assert (result
->callers
+ result
->callees
< result
->length
);
780 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
781 assumed frames between them use GDBARCH. Use depth first search so we can
782 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
783 would have needless GDB stack overhead. Caller is responsible for xfree of
784 the returned result. Any unreliability results in thrown
785 NO_ENTRY_VALUE_ERROR. */
787 static struct call_site_chain
*
788 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
791 struct obstack addr_obstack
;
792 struct cleanup
*back_to_retval
, *back_to_workdata
;
793 struct call_site_chain
*retval
= NULL
;
794 struct call_site
*call_site
;
796 /* Mark CALL_SITEs so we do not visit the same ones twice. */
799 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
800 call_site nor any possible call_site at CALLEE_PC's function is there.
801 Any CALL_SITE in CHAIN will be iterated to its siblings - via
802 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
803 VEC (call_sitep
) *chain
= NULL
;
805 /* We are not interested in the specific PC inside the callee function. */
806 callee_pc
= get_pc_function_start (callee_pc
);
808 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
809 paddress (gdbarch
, callee_pc
));
811 back_to_retval
= make_cleanup (free_current_contents
, &retval
);
813 obstack_init (&addr_obstack
);
814 back_to_workdata
= make_cleanup_obstack_free (&addr_obstack
);
815 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
816 &addr_obstack
, hashtab_obstack_allocate
,
818 make_cleanup_htab_delete (addr_hash
);
820 make_cleanup (VEC_cleanup (call_sitep
), &chain
);
822 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
823 at the target's function. All the possible tail call sites in the
824 target's function will get iterated as already pushed into CHAIN via their
826 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
830 CORE_ADDR target_func_addr
;
831 struct call_site
*target_call_site
;
833 /* CALLER_FRAME with registers is not available for tail-call jumped
835 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
837 if (target_func_addr
== callee_pc
)
839 chain_candidate (gdbarch
, &retval
, chain
);
843 /* There is no way to reach CALLEE_PC again as we would prevent
844 entering it twice as being already marked in ADDR_HASH. */
845 target_call_site
= NULL
;
849 struct symbol
*target_func
;
851 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
852 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
857 /* Attempt to visit TARGET_CALL_SITE. */
859 if (target_call_site
)
863 slot
= htab_find_slot (addr_hash
, &target_call_site
->pc
, INSERT
);
866 /* Successfully entered TARGET_CALL_SITE. */
868 *slot
= &target_call_site
->pc
;
869 VEC_safe_push (call_sitep
, chain
, target_call_site
);
874 /* Backtrack (without revisiting the originating call_site). Try the
875 callers's sibling; if there isn't any try the callers's callers's
878 target_call_site
= NULL
;
879 while (!VEC_empty (call_sitep
, chain
))
881 call_site
= VEC_pop (call_sitep
, chain
);
883 gdb_assert (htab_find_slot (addr_hash
, &call_site
->pc
,
885 htab_remove_elt (addr_hash
, &call_site
->pc
);
887 target_call_site
= call_site
->tail_call_next
;
888 if (target_call_site
)
892 while (target_call_site
);
894 if (VEC_empty (call_sitep
, chain
))
897 call_site
= VEC_last (call_sitep
, chain
);
902 struct minimal_symbol
*msym_caller
, *msym_callee
;
904 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
905 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
906 throw_error (NO_ENTRY_VALUE_ERROR
,
907 _("There are no unambiguously determinable intermediate "
908 "callers or callees between caller function \"%s\" at %s "
909 "and callee function \"%s\" at %s"),
911 ? "???" : SYMBOL_PRINT_NAME (msym_caller
)),
912 paddress (gdbarch
, caller_pc
),
914 ? "???" : SYMBOL_PRINT_NAME (msym_callee
)),
915 paddress (gdbarch
, callee_pc
));
918 do_cleanups (back_to_workdata
);
919 discard_cleanups (back_to_retval
);
923 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
924 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
925 constructed return NULL. Caller is responsible for xfree of the returned
928 struct call_site_chain
*
929 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
932 volatile struct gdb_exception e
;
933 struct call_site_chain
*retval
= NULL
;
935 TRY_CATCH (e
, RETURN_MASK_ERROR
)
937 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
941 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
943 if (entry_values_debug
)
944 exception_print (gdb_stdout
, e
);
954 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
957 call_site_parameter_matches (struct call_site_parameter
*parameter
,
958 enum call_site_parameter_kind kind
,
959 union call_site_parameter_u kind_u
)
961 if (kind
== parameter
->kind
)
964 case CALL_SITE_PARAMETER_DWARF_REG
:
965 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
966 case CALL_SITE_PARAMETER_FB_OFFSET
:
967 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
968 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
969 return kind_u
.param_offset
.cu_off
== parameter
->u
.param_offset
.cu_off
;
974 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
977 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
980 static struct call_site_parameter
*
981 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
982 enum call_site_parameter_kind kind
,
983 union call_site_parameter_u kind_u
,
984 struct dwarf2_per_cu_data
**per_cu_return
)
986 CORE_ADDR func_addr
, caller_pc
;
987 struct gdbarch
*gdbarch
;
988 struct frame_info
*caller_frame
;
989 struct call_site
*call_site
;
991 /* Initialize it just to avoid a GCC false warning. */
992 struct call_site_parameter
*parameter
= NULL
;
993 CORE_ADDR target_addr
;
995 while (get_frame_type (frame
) == INLINE_FRAME
)
997 frame
= get_prev_frame (frame
);
998 gdb_assert (frame
!= NULL
);
1001 func_addr
= get_frame_func (frame
);
1002 gdbarch
= get_frame_arch (frame
);
1003 caller_frame
= get_prev_frame (frame
);
1004 if (gdbarch
!= frame_unwind_arch (frame
))
1006 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
1007 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1009 throw_error (NO_ENTRY_VALUE_ERROR
,
1010 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
1011 "(of %s (%s)) does not match caller gdbarch %s"),
1012 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1013 paddress (gdbarch
, func_addr
),
1014 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
1015 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1018 if (caller_frame
== NULL
)
1020 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
1022 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_GNU_entry_value resolving "
1023 "requires caller of %s (%s)"),
1024 paddress (gdbarch
, func_addr
),
1025 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
1027 caller_pc
= get_frame_pc (caller_frame
);
1028 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1030 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1031 if (target_addr
!= func_addr
)
1033 struct minimal_symbol
*target_msym
, *func_msym
;
1035 target_msym
= lookup_minimal_symbol_by_pc (target_addr
);
1036 func_msym
= lookup_minimal_symbol_by_pc (func_addr
);
1037 throw_error (NO_ENTRY_VALUE_ERROR
,
1038 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
1039 "but the called frame is for %s at %s"),
1040 (target_msym
== NULL
? "???"
1041 : SYMBOL_PRINT_NAME (target_msym
)),
1042 paddress (gdbarch
, target_addr
),
1043 func_msym
== NULL
? "???" : SYMBOL_PRINT_NAME (func_msym
),
1044 paddress (gdbarch
, func_addr
));
1047 /* No entry value based parameters would be reliable if this function can
1048 call itself via tail calls. */
1049 func_verify_no_selftailcall (gdbarch
, func_addr
);
1051 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1053 parameter
= &call_site
->parameter
[iparams
];
1054 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1057 if (iparams
== call_site
->parameter_count
)
1059 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (caller_pc
);
1061 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
1062 determine its value. */
1063 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1064 "at DW_TAG_GNU_call_site %s at %s"),
1065 paddress (gdbarch
, caller_pc
),
1066 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
1069 *per_cu_return
= call_site
->per_cu
;
1073 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1074 the normal DW_AT_GNU_call_site_value block. Otherwise return the
1075 DW_AT_GNU_call_site_data_value (dereferenced) block.
1077 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1080 Function always returns non-NULL, non-optimized out value. It throws
1081 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1083 static struct value
*
1084 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1085 CORE_ADDR deref_size
, struct type
*type
,
1086 struct frame_info
*caller_frame
,
1087 struct dwarf2_per_cu_data
*per_cu
)
1089 const gdb_byte
*data_src
;
1093 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1094 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1096 /* DEREF_SIZE size is not verified here. */
1097 if (data_src
== NULL
)
1098 throw_error (NO_ENTRY_VALUE_ERROR
,
1099 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1101 /* DW_AT_GNU_call_site_value is a DWARF expression, not a DWARF
1102 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1104 data
= alloca (size
+ 1);
1105 memcpy (data
, data_src
, size
);
1106 data
[size
] = DW_OP_stack_value
;
1108 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1111 /* Execute DWARF block of call_site_parameter which matches KIND and KIND_U.
1112 Choose DEREF_SIZE value of that parameter. Search caller of the CTX's
1113 frame. CTX must be of dwarf_expr_ctx_funcs kind.
1115 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
1116 can be more simple as it does not support cross-CU DWARF executions. */
1119 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
1120 enum call_site_parameter_kind kind
,
1121 union call_site_parameter_u kind_u
,
1124 struct dwarf_expr_baton
*debaton
;
1125 struct frame_info
*frame
, *caller_frame
;
1126 struct dwarf2_per_cu_data
*caller_per_cu
;
1127 struct dwarf_expr_baton baton_local
;
1128 struct dwarf_expr_context saved_ctx
;
1129 struct call_site_parameter
*parameter
;
1130 const gdb_byte
*data_src
;
1133 gdb_assert (ctx
->funcs
== &dwarf_expr_ctx_funcs
);
1134 debaton
= ctx
->baton
;
1135 frame
= debaton
->frame
;
1136 caller_frame
= get_prev_frame (frame
);
1138 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1140 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1141 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1143 /* DEREF_SIZE size is not verified here. */
1144 if (data_src
== NULL
)
1145 throw_error (NO_ENTRY_VALUE_ERROR
,
1146 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1148 baton_local
.frame
= caller_frame
;
1149 baton_local
.per_cu
= caller_per_cu
;
1151 saved_ctx
.gdbarch
= ctx
->gdbarch
;
1152 saved_ctx
.addr_size
= ctx
->addr_size
;
1153 saved_ctx
.offset
= ctx
->offset
;
1154 saved_ctx
.baton
= ctx
->baton
;
1155 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (baton_local
.per_cu
));
1156 ctx
->addr_size
= dwarf2_per_cu_addr_size (baton_local
.per_cu
);
1157 ctx
->offset
= dwarf2_per_cu_text_offset (baton_local
.per_cu
);
1158 ctx
->baton
= &baton_local
;
1160 dwarf_expr_eval (ctx
, data_src
, size
);
1162 ctx
->gdbarch
= saved_ctx
.gdbarch
;
1163 ctx
->addr_size
= saved_ctx
.addr_size
;
1164 ctx
->offset
= saved_ctx
.offset
;
1165 ctx
->baton
= saved_ctx
.baton
;
1168 /* Callback function for dwarf2_evaluate_loc_desc.
1169 Fetch the address indexed by DW_OP_GNU_addr_index. */
1172 dwarf_expr_get_addr_index (void *baton
, unsigned int index
)
1174 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
1176 return dwarf2_read_addr_index (debaton
->per_cu
, index
);
1179 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1180 the indirect method on it, that is use its stored target value, the sole
1181 purpose of entry_data_value_funcs.. */
1183 static struct value
*
1184 entry_data_value_coerce_ref (const struct value
*value
)
1186 struct type
*checked_type
= check_typedef (value_type (value
));
1187 struct value
*target_val
;
1189 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
)
1192 target_val
= value_computed_closure (value
);
1193 value_incref (target_val
);
1197 /* Implement copy_closure. */
1200 entry_data_value_copy_closure (const struct value
*v
)
1202 struct value
*target_val
= value_computed_closure (v
);
1204 value_incref (target_val
);
1208 /* Implement free_closure. */
1211 entry_data_value_free_closure (struct value
*v
)
1213 struct value
*target_val
= value_computed_closure (v
);
1215 value_free (target_val
);
1218 /* Vector for methods for an entry value reference where the referenced value
1219 is stored in the caller. On the first dereference use
1220 DW_AT_GNU_call_site_data_value in the caller. */
1222 static const struct lval_funcs entry_data_value_funcs
=
1226 NULL
, /* check_validity */
1227 NULL
, /* check_any_valid */
1228 NULL
, /* indirect */
1229 entry_data_value_coerce_ref
,
1230 NULL
, /* check_synthetic_pointer */
1231 entry_data_value_copy_closure
,
1232 entry_data_value_free_closure
1235 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1236 are used to match DW_AT_location at the caller's
1237 DW_TAG_GNU_call_site_parameter.
1239 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1240 cannot resolve the parameter for any reason. */
1242 static struct value
*
1243 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1244 enum call_site_parameter_kind kind
,
1245 union call_site_parameter_u kind_u
)
1247 struct type
*checked_type
= check_typedef (type
);
1248 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1249 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1250 struct value
*outer_val
, *target_val
, *val
;
1251 struct call_site_parameter
*parameter
;
1252 struct dwarf2_per_cu_data
*caller_per_cu
;
1255 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1258 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1262 /* Check if DW_AT_GNU_call_site_data_value cannot be used. If it should be
1263 used and it is not available do not fall back to OUTER_VAL - dereferencing
1264 TYPE_CODE_REF with non-entry data value would give current value - not the
1267 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
1268 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1271 target_val
= dwarf_entry_parameter_to_value (parameter
,
1272 TYPE_LENGTH (target_type
),
1273 target_type
, caller_frame
,
1276 /* value_as_address dereferences TYPE_CODE_REF. */
1277 addr
= extract_typed_address (value_contents (outer_val
), checked_type
);
1279 /* The target entry value has artificial address of the entry value
1281 VALUE_LVAL (target_val
) = lval_memory
;
1282 set_value_address (target_val
, addr
);
1284 release_value (target_val
);
1285 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1286 target_val
/* closure */);
1288 /* Copy the referencing pointer to the new computed value. */
1289 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1290 TYPE_LENGTH (checked_type
));
1291 set_value_lazy (val
, 0);
1296 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1297 SIZE are DWARF block used to match DW_AT_location at the caller's
1298 DW_TAG_GNU_call_site_parameter.
1300 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1301 cannot resolve the parameter for any reason. */
1303 static struct value
*
1304 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1305 const gdb_byte
*block
, size_t block_len
)
1307 union call_site_parameter_u kind_u
;
1309 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1310 if (kind_u
.dwarf_reg
!= -1)
1311 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1314 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1315 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1318 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1319 suppressed during normal operation. The expression can be arbitrary if
1320 there is no caller-callee entry value binding expected. */
1321 throw_error (NO_ENTRY_VALUE_ERROR
,
1322 _("DWARF-2 expression error: DW_OP_GNU_entry_value is supported "
1323 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1326 struct piece_closure
1328 /* Reference count. */
1331 /* The CU from which this closure's expression came. */
1332 struct dwarf2_per_cu_data
*per_cu
;
1334 /* The number of pieces used to describe this variable. */
1337 /* The target address size, used only for DWARF_VALUE_STACK. */
1340 /* The pieces themselves. */
1341 struct dwarf_expr_piece
*pieces
;
1344 /* Allocate a closure for a value formed from separately-described
1347 static struct piece_closure
*
1348 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1349 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1352 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
1357 c
->n_pieces
= n_pieces
;
1358 c
->addr_size
= addr_size
;
1359 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
1361 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1362 for (i
= 0; i
< n_pieces
; ++i
)
1363 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1364 value_incref (c
->pieces
[i
].v
.value
);
1369 /* The lowest-level function to extract bits from a byte buffer.
1370 SOURCE is the buffer. It is updated if we read to the end of a
1372 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
1373 updated to reflect the number of bits actually read.
1374 NBITS is the number of bits we want to read. It is updated to
1375 reflect the number of bits actually read. This function may read
1377 BITS_BIG_ENDIAN is taken directly from gdbarch.
1378 This function returns the extracted bits. */
1381 extract_bits_primitive (const gdb_byte
**source
,
1382 unsigned int *source_offset_bits
,
1383 int *nbits
, int bits_big_endian
)
1385 unsigned int avail
, mask
, datum
;
1387 gdb_assert (*source_offset_bits
< 8);
1389 avail
= 8 - *source_offset_bits
;
1393 mask
= (1 << avail
) - 1;
1395 if (bits_big_endian
)
1396 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
1398 datum
>>= *source_offset_bits
;
1402 *source_offset_bits
+= avail
;
1403 if (*source_offset_bits
>= 8)
1405 *source_offset_bits
-= 8;
1412 /* Extract some bits from a source buffer and move forward in the
1415 SOURCE is the source buffer. It is updated as bytes are read.
1416 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1418 NBITS is the number of bits to read.
1419 BITS_BIG_ENDIAN is taken directly from gdbarch.
1421 This function returns the bits that were read. */
1424 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
1425 int nbits
, int bits_big_endian
)
1429 gdb_assert (nbits
> 0 && nbits
<= 8);
1431 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1437 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1439 if (bits_big_endian
)
1449 /* Write some bits into a buffer and move forward in the buffer.
1451 DATUM is the bits to write. The low-order bits of DATUM are used.
1452 DEST is the destination buffer. It is updated as bytes are
1454 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1456 NBITS is the number of valid bits in DATUM.
1457 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1460 insert_bits (unsigned int datum
,
1461 gdb_byte
*dest
, unsigned int dest_offset_bits
,
1462 int nbits
, int bits_big_endian
)
1466 gdb_assert (dest_offset_bits
+ nbits
<= 8);
1468 mask
= (1 << nbits
) - 1;
1469 if (bits_big_endian
)
1471 datum
<<= 8 - (dest_offset_bits
+ nbits
);
1472 mask
<<= 8 - (dest_offset_bits
+ nbits
);
1476 datum
<<= dest_offset_bits
;
1477 mask
<<= dest_offset_bits
;
1480 gdb_assert ((datum
& ~mask
) == 0);
1482 *dest
= (*dest
& ~mask
) | datum
;
1485 /* Copy bits from a source to a destination.
1487 DEST is where the bits should be written.
1488 DEST_OFFSET_BITS is the bit offset into DEST.
1489 SOURCE is the source of bits.
1490 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1491 BIT_COUNT is the number of bits to copy.
1492 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1495 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
1496 const gdb_byte
*source
, unsigned int source_offset_bits
,
1497 unsigned int bit_count
,
1498 int bits_big_endian
)
1500 unsigned int dest_avail
;
1503 /* Reduce everything to byte-size pieces. */
1504 dest
+= dest_offset_bits
/ 8;
1505 dest_offset_bits
%= 8;
1506 source
+= source_offset_bits
/ 8;
1507 source_offset_bits
%= 8;
1509 dest_avail
= 8 - dest_offset_bits
% 8;
1511 /* See if we can fill the first destination byte. */
1512 if (dest_avail
< bit_count
)
1514 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
1516 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
1518 dest_offset_bits
= 0;
1519 bit_count
-= dest_avail
;
1522 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1523 than 8 bits remaining. */
1524 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
1525 for (; bit_count
>= 8; bit_count
-= 8)
1527 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
1528 *dest
++ = (gdb_byte
) datum
;
1531 /* Finally, we may have a few leftover bits. */
1532 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
1535 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
1537 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
1542 read_pieced_value (struct value
*v
)
1546 ULONGEST bits_to_skip
;
1548 struct piece_closure
*c
1549 = (struct piece_closure
*) value_computed_closure (v
);
1550 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
1552 size_t buffer_size
= 0;
1553 char *buffer
= NULL
;
1554 struct cleanup
*cleanup
;
1556 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1558 if (value_type (v
) != value_enclosing_type (v
))
1559 internal_error (__FILE__
, __LINE__
,
1560 _("Should not be able to create a lazy value with "
1561 "an enclosing type"));
1563 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1565 contents
= value_contents_raw (v
);
1566 bits_to_skip
= 8 * value_offset (v
);
1567 if (value_bitsize (v
))
1569 bits_to_skip
+= value_bitpos (v
);
1570 type_len
= value_bitsize (v
);
1573 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1575 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1577 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1578 size_t this_size
, this_size_bits
;
1579 long dest_offset_bits
, source_offset_bits
, source_offset
;
1580 const gdb_byte
*intermediate_buffer
;
1582 /* Compute size, source, and destination offsets for copying, in
1584 this_size_bits
= p
->size
;
1585 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1587 bits_to_skip
-= this_size_bits
;
1590 if (this_size_bits
> type_len
- offset
)
1591 this_size_bits
= type_len
- offset
;
1592 if (bits_to_skip
> 0)
1594 dest_offset_bits
= 0;
1595 source_offset_bits
= bits_to_skip
;
1596 this_size_bits
-= bits_to_skip
;
1601 dest_offset_bits
= offset
;
1602 source_offset_bits
= 0;
1605 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1606 source_offset
= source_offset_bits
/ 8;
1607 if (buffer_size
< this_size
)
1609 buffer_size
= this_size
;
1610 buffer
= xrealloc (buffer
, buffer_size
);
1612 intermediate_buffer
= buffer
;
1614 /* Copy from the source to DEST_BUFFER. */
1615 switch (p
->location
)
1617 case DWARF_VALUE_REGISTER
:
1619 struct gdbarch
*arch
= get_frame_arch (frame
);
1620 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1621 int reg_offset
= source_offset
;
1623 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1624 && this_size
< register_size (arch
, gdb_regnum
))
1626 /* Big-endian, and we want less than full size. */
1627 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1628 /* We want the lower-order THIS_SIZE_BITS of the bytes
1629 we extract from the register. */
1630 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1633 if (gdb_regnum
!= -1)
1637 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1641 /* Just so garbage doesn't ever shine through. */
1642 memset (buffer
, 0, this_size
);
1645 set_value_optimized_out (v
, 1);
1647 mark_value_bytes_unavailable (v
, offset
, this_size
);
1652 error (_("Unable to access DWARF register number %s"),
1653 paddress (arch
, p
->v
.regno
));
1658 case DWARF_VALUE_MEMORY
:
1659 read_value_memory (v
, offset
,
1660 p
->v
.mem
.in_stack_memory
,
1661 p
->v
.mem
.addr
+ source_offset
,
1665 case DWARF_VALUE_STACK
:
1667 size_t n
= this_size
;
1669 if (n
> c
->addr_size
- source_offset
)
1670 n
= (c
->addr_size
>= source_offset
1671 ? c
->addr_size
- source_offset
1679 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
1681 intermediate_buffer
= val_bytes
+ source_offset
;
1686 case DWARF_VALUE_LITERAL
:
1688 size_t n
= this_size
;
1690 if (n
> p
->v
.literal
.length
- source_offset
)
1691 n
= (p
->v
.literal
.length
>= source_offset
1692 ? p
->v
.literal
.length
- source_offset
1695 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1699 /* These bits show up as zeros -- but do not cause the value
1700 to be considered optimized-out. */
1701 case DWARF_VALUE_IMPLICIT_POINTER
:
1704 case DWARF_VALUE_OPTIMIZED_OUT
:
1705 set_value_optimized_out (v
, 1);
1709 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1712 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
1713 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1714 copy_bitwise (contents
, dest_offset_bits
,
1715 intermediate_buffer
, source_offset_bits
% 8,
1716 this_size_bits
, bits_big_endian
);
1718 offset
+= this_size_bits
;
1721 do_cleanups (cleanup
);
1725 write_pieced_value (struct value
*to
, struct value
*from
)
1729 ULONGEST bits_to_skip
;
1730 const gdb_byte
*contents
;
1731 struct piece_closure
*c
1732 = (struct piece_closure
*) value_computed_closure (to
);
1733 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
1735 size_t buffer_size
= 0;
1736 char *buffer
= NULL
;
1737 struct cleanup
*cleanup
;
1739 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1743 set_value_optimized_out (to
, 1);
1747 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1749 contents
= value_contents (from
);
1750 bits_to_skip
= 8 * value_offset (to
);
1751 if (value_bitsize (to
))
1753 bits_to_skip
+= value_bitpos (to
);
1754 type_len
= value_bitsize (to
);
1757 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1759 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1761 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1762 size_t this_size_bits
, this_size
;
1763 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1765 const gdb_byte
*source_buffer
;
1767 this_size_bits
= p
->size
;
1768 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1770 bits_to_skip
-= this_size_bits
;
1773 if (this_size_bits
> type_len
- offset
)
1774 this_size_bits
= type_len
- offset
;
1775 if (bits_to_skip
> 0)
1777 dest_offset_bits
= bits_to_skip
;
1778 source_offset_bits
= 0;
1779 this_size_bits
-= bits_to_skip
;
1784 dest_offset_bits
= 0;
1785 source_offset_bits
= offset
;
1788 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1789 source_offset
= source_offset_bits
/ 8;
1790 dest_offset
= dest_offset_bits
/ 8;
1791 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1793 source_buffer
= contents
+ source_offset
;
1798 if (buffer_size
< this_size
)
1800 buffer_size
= this_size
;
1801 buffer
= xrealloc (buffer
, buffer_size
);
1803 source_buffer
= buffer
;
1807 switch (p
->location
)
1809 case DWARF_VALUE_REGISTER
:
1811 struct gdbarch
*arch
= get_frame_arch (frame
);
1812 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1813 int reg_offset
= dest_offset
;
1815 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1816 && this_size
<= register_size (arch
, gdb_regnum
))
1817 /* Big-endian, and we want less than full size. */
1818 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1820 if (gdb_regnum
!= -1)
1826 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1831 error (_("Can't do read-modify-write to "
1832 "update bitfield; containing word has been "
1835 throw_error (NOT_AVAILABLE_ERROR
,
1836 _("Can't do read-modify-write to update "
1837 "bitfield; containing word "
1840 copy_bitwise (buffer
, dest_offset_bits
,
1841 contents
, source_offset_bits
,
1846 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1847 this_size
, source_buffer
);
1851 error (_("Unable to write to DWARF register number %s"),
1852 paddress (arch
, p
->v
.regno
));
1856 case DWARF_VALUE_MEMORY
:
1859 /* Only the first and last bytes can possibly have any
1861 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
1862 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
1863 buffer
+ this_size
- 1, 1);
1864 copy_bitwise (buffer
, dest_offset_bits
,
1865 contents
, source_offset_bits
,
1870 write_memory (p
->v
.mem
.addr
+ dest_offset
,
1871 source_buffer
, this_size
);
1874 set_value_optimized_out (to
, 1);
1877 offset
+= this_size_bits
;
1880 do_cleanups (cleanup
);
1883 /* A helper function that checks bit validity in a pieced value.
1884 CHECK_FOR indicates the kind of validity checking.
1885 DWARF_VALUE_MEMORY means to check whether any bit is valid.
1886 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
1888 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
1889 implicit pointer. */
1892 check_pieced_value_bits (const struct value
*value
, int bit_offset
,
1894 enum dwarf_value_location check_for
)
1896 struct piece_closure
*c
1897 = (struct piece_closure
*) value_computed_closure (value
);
1899 int validity
= (check_for
== DWARF_VALUE_MEMORY
1900 || check_for
== DWARF_VALUE_IMPLICIT_POINTER
);
1902 bit_offset
+= 8 * value_offset (value
);
1903 if (value_bitsize (value
))
1904 bit_offset
+= value_bitpos (value
);
1906 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1908 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1909 size_t this_size_bits
= p
->size
;
1913 if (bit_offset
>= this_size_bits
)
1915 bit_offset
-= this_size_bits
;
1919 bit_length
-= this_size_bits
- bit_offset
;
1923 bit_length
-= this_size_bits
;
1925 if (check_for
== DWARF_VALUE_IMPLICIT_POINTER
)
1927 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1930 else if (p
->location
== DWARF_VALUE_OPTIMIZED_OUT
1931 || p
->location
== DWARF_VALUE_IMPLICIT_POINTER
)
1947 check_pieced_value_validity (const struct value
*value
, int bit_offset
,
1950 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1951 DWARF_VALUE_MEMORY
);
1955 check_pieced_value_invalid (const struct value
*value
)
1957 return check_pieced_value_bits (value
, 0,
1958 8 * TYPE_LENGTH (value_type (value
)),
1959 DWARF_VALUE_OPTIMIZED_OUT
);
1962 /* An implementation of an lval_funcs method to see whether a value is
1963 a synthetic pointer. */
1966 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
1969 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1970 DWARF_VALUE_IMPLICIT_POINTER
);
1973 /* A wrapper function for get_frame_address_in_block. */
1976 get_frame_address_in_block_wrapper (void *baton
)
1978 return get_frame_address_in_block (baton
);
1981 /* An implementation of an lval_funcs method to indirect through a
1982 pointer. This handles the synthetic pointer case when needed. */
1984 static struct value
*
1985 indirect_pieced_value (struct value
*value
)
1987 struct piece_closure
*c
1988 = (struct piece_closure
*) value_computed_closure (value
);
1990 struct frame_info
*frame
;
1991 struct dwarf2_locexpr_baton baton
;
1992 int i
, bit_offset
, bit_length
;
1993 struct dwarf_expr_piece
*piece
= NULL
;
1994 LONGEST byte_offset
;
1996 type
= check_typedef (value_type (value
));
1997 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2000 bit_length
= 8 * TYPE_LENGTH (type
);
2001 bit_offset
= 8 * value_offset (value
);
2002 if (value_bitsize (value
))
2003 bit_offset
+= value_bitpos (value
);
2005 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2007 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2008 size_t this_size_bits
= p
->size
;
2012 if (bit_offset
>= this_size_bits
)
2014 bit_offset
-= this_size_bits
;
2018 bit_length
-= this_size_bits
- bit_offset
;
2022 bit_length
-= this_size_bits
;
2024 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2027 if (bit_length
!= 0)
2028 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
2034 frame
= get_selected_frame (_("No frame selected."));
2036 /* This is an offset requested by GDB, such as value subcripts. */
2037 byte_offset
= value_as_address (value
);
2041 = dwarf2_fetch_die_loc_sect_off (piece
->v
.ptr
.die
, c
->per_cu
,
2042 get_frame_address_in_block_wrapper
,
2045 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
2046 baton
.data
, baton
.size
, baton
.per_cu
,
2047 piece
->v
.ptr
.offset
+ byte_offset
);
2051 copy_pieced_value_closure (const struct value
*v
)
2053 struct piece_closure
*c
2054 = (struct piece_closure
*) value_computed_closure (v
);
2061 free_pieced_value_closure (struct value
*v
)
2063 struct piece_closure
*c
2064 = (struct piece_closure
*) value_computed_closure (v
);
2071 for (i
= 0; i
< c
->n_pieces
; ++i
)
2072 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2073 value_free (c
->pieces
[i
].v
.value
);
2080 /* Functions for accessing a variable described by DW_OP_piece. */
2081 static const struct lval_funcs pieced_value_funcs
= {
2084 check_pieced_value_validity
,
2085 check_pieced_value_invalid
,
2086 indirect_pieced_value
,
2087 NULL
, /* coerce_ref */
2088 check_pieced_synthetic_pointer
,
2089 copy_pieced_value_closure
,
2090 free_pieced_value_closure
2093 /* Helper function which throws an error if a synthetic pointer is
2097 invalid_synthetic_pointer (void)
2099 error (_("access outside bounds of object "
2100 "referenced via synthetic pointer"));
2103 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
2105 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
2107 dwarf_expr_read_reg
,
2108 dwarf_expr_read_mem
,
2109 dwarf_expr_frame_base
,
2110 dwarf_expr_frame_cfa
,
2111 dwarf_expr_frame_pc
,
2112 dwarf_expr_tls_address
,
2113 dwarf_expr_dwarf_call
,
2114 dwarf_expr_get_base_type
,
2115 dwarf_expr_push_dwarf_reg_entry_value
,
2116 dwarf_expr_get_addr_index
2119 /* Evaluate a location description, starting at DATA and with length
2120 SIZE, to find the current location of variable of TYPE in the
2121 context of FRAME. BYTE_OFFSET is applied after the contents are
2124 static struct value
*
2125 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2126 const gdb_byte
*data
, size_t size
,
2127 struct dwarf2_per_cu_data
*per_cu
,
2128 LONGEST byte_offset
)
2130 struct value
*retval
;
2131 struct dwarf_expr_baton baton
;
2132 struct dwarf_expr_context
*ctx
;
2133 struct cleanup
*old_chain
, *value_chain
;
2134 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2135 volatile struct gdb_exception ex
;
2137 if (byte_offset
< 0)
2138 invalid_synthetic_pointer ();
2141 return allocate_optimized_out_value (type
);
2143 baton
.frame
= frame
;
2144 baton
.per_cu
= per_cu
;
2146 ctx
= new_dwarf_expr_context ();
2147 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2148 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
2150 ctx
->gdbarch
= get_objfile_arch (objfile
);
2151 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2152 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2153 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2154 ctx
->baton
= &baton
;
2155 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2157 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2159 dwarf_expr_eval (ctx
, data
, size
);
2163 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2165 do_cleanups (old_chain
);
2166 retval
= allocate_value (type
);
2167 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
2170 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2172 if (entry_values_debug
)
2173 exception_print (gdb_stdout
, ex
);
2174 do_cleanups (old_chain
);
2175 return allocate_optimized_out_value (type
);
2178 throw_exception (ex
);
2181 if (ctx
->num_pieces
> 0)
2183 struct piece_closure
*c
;
2184 struct frame_id frame_id
= get_frame_id (frame
);
2185 ULONGEST bit_size
= 0;
2188 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
2189 bit_size
+= ctx
->pieces
[i
].size
;
2190 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
2191 invalid_synthetic_pointer ();
2193 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
2195 /* We must clean up the value chain after creating the piece
2196 closure but before allocating the result. */
2197 do_cleanups (value_chain
);
2198 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
2199 VALUE_FRAME_ID (retval
) = frame_id
;
2200 set_value_offset (retval
, byte_offset
);
2204 switch (ctx
->location
)
2206 case DWARF_VALUE_REGISTER
:
2208 struct gdbarch
*arch
= get_frame_arch (frame
);
2209 ULONGEST dwarf_regnum
= value_as_long (dwarf_expr_fetch (ctx
, 0));
2210 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
2212 if (byte_offset
!= 0)
2213 error (_("cannot use offset on synthetic pointer to register"));
2214 do_cleanups (value_chain
);
2215 if (gdb_regnum
!= -1)
2216 retval
= value_from_register (type
, gdb_regnum
, frame
);
2218 error (_("Unable to access DWARF register number %s"),
2219 paddress (arch
, dwarf_regnum
));
2223 case DWARF_VALUE_MEMORY
:
2225 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
2226 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
2228 do_cleanups (value_chain
);
2229 retval
= allocate_value_lazy (type
);
2230 VALUE_LVAL (retval
) = lval_memory
;
2231 if (in_stack_memory
)
2232 set_value_stack (retval
, 1);
2233 set_value_address (retval
, address
+ byte_offset
);
2237 case DWARF_VALUE_STACK
:
2239 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
2241 const gdb_byte
*val_bytes
;
2242 size_t n
= TYPE_LENGTH (value_type (value
));
2244 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2245 invalid_synthetic_pointer ();
2247 val_bytes
= value_contents_all (value
);
2248 val_bytes
+= byte_offset
;
2251 /* Preserve VALUE because we are going to free values back
2252 to the mark, but we still need the value contents
2254 value_incref (value
);
2255 do_cleanups (value_chain
);
2256 make_cleanup_value_free (value
);
2258 retval
= allocate_value (type
);
2259 contents
= value_contents_raw (retval
);
2260 if (n
> TYPE_LENGTH (type
))
2262 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2264 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2265 val_bytes
+= n
- TYPE_LENGTH (type
);
2266 n
= TYPE_LENGTH (type
);
2268 memcpy (contents
, val_bytes
, n
);
2272 case DWARF_VALUE_LITERAL
:
2275 const bfd_byte
*ldata
;
2276 size_t n
= ctx
->len
;
2278 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2279 invalid_synthetic_pointer ();
2281 do_cleanups (value_chain
);
2282 retval
= allocate_value (type
);
2283 contents
= value_contents_raw (retval
);
2285 ldata
= ctx
->data
+ byte_offset
;
2288 if (n
> TYPE_LENGTH (type
))
2290 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2292 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2293 ldata
+= n
- TYPE_LENGTH (type
);
2294 n
= TYPE_LENGTH (type
);
2296 memcpy (contents
, ldata
, n
);
2300 case DWARF_VALUE_OPTIMIZED_OUT
:
2301 do_cleanups (value_chain
);
2302 retval
= allocate_optimized_out_value (type
);
2305 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2306 operation by execute_stack_op. */
2307 case DWARF_VALUE_IMPLICIT_POINTER
:
2308 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2309 it can only be encountered when making a piece. */
2311 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2315 set_value_initialized (retval
, ctx
->initialized
);
2317 do_cleanups (old_chain
);
2322 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2323 passes 0 as the byte_offset. */
2326 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2327 const gdb_byte
*data
, size_t size
,
2328 struct dwarf2_per_cu_data
*per_cu
)
2330 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
2334 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
2336 struct needs_frame_baton
2339 struct dwarf2_per_cu_data
*per_cu
;
2342 /* Reads from registers do require a frame. */
2344 needs_frame_read_reg (void *baton
, int regnum
)
2346 struct needs_frame_baton
*nf_baton
= baton
;
2348 nf_baton
->needs_frame
= 1;
2352 /* Reads from memory do not require a frame. */
2354 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
2356 memset (buf
, 0, len
);
2359 /* Frame-relative accesses do require a frame. */
2361 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
2363 static gdb_byte lit0
= DW_OP_lit0
;
2364 struct needs_frame_baton
*nf_baton
= baton
;
2369 nf_baton
->needs_frame
= 1;
2372 /* CFA accesses require a frame. */
2375 needs_frame_frame_cfa (void *baton
)
2377 struct needs_frame_baton
*nf_baton
= baton
;
2379 nf_baton
->needs_frame
= 1;
2383 /* Thread-local accesses do require a frame. */
2385 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
2387 struct needs_frame_baton
*nf_baton
= baton
;
2389 nf_baton
->needs_frame
= 1;
2393 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
2396 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
2398 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2400 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
2401 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
2404 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2407 needs_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
2408 enum call_site_parameter_kind kind
,
2409 union call_site_parameter_u kind_u
, int deref_size
)
2411 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2413 nf_baton
->needs_frame
= 1;
2415 /* The expression may require some stub values on DWARF stack. */
2416 dwarf_expr_push_address (ctx
, 0, 0);
2419 /* DW_OP_GNU_addr_index doesn't require a frame. */
2422 needs_get_addr_index (void *baton
, unsigned int index
)
2424 /* Nothing to do. */
2428 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
2430 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs
=
2432 needs_frame_read_reg
,
2433 needs_frame_read_mem
,
2434 needs_frame_frame_base
,
2435 needs_frame_frame_cfa
,
2436 needs_frame_frame_cfa
, /* get_frame_pc */
2437 needs_frame_tls_address
,
2438 needs_frame_dwarf_call
,
2439 NULL
, /* get_base_type */
2440 needs_dwarf_reg_entry_value
,
2441 needs_get_addr_index
2444 /* Return non-zero iff the location expression at DATA (length SIZE)
2445 requires a frame to evaluate. */
2448 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, size_t size
,
2449 struct dwarf2_per_cu_data
*per_cu
)
2451 struct needs_frame_baton baton
;
2452 struct dwarf_expr_context
*ctx
;
2454 struct cleanup
*old_chain
;
2455 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2457 baton
.needs_frame
= 0;
2458 baton
.per_cu
= per_cu
;
2460 ctx
= new_dwarf_expr_context ();
2461 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2462 make_cleanup_value_free_to_mark (value_mark ());
2464 ctx
->gdbarch
= get_objfile_arch (objfile
);
2465 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2466 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2467 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2468 ctx
->baton
= &baton
;
2469 ctx
->funcs
= &needs_frame_ctx_funcs
;
2471 dwarf_expr_eval (ctx
, data
, size
);
2473 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
2475 if (ctx
->num_pieces
> 0)
2479 /* If the location has several pieces, and any of them are in
2480 registers, then we will need a frame to fetch them from. */
2481 for (i
= 0; i
< ctx
->num_pieces
; i
++)
2482 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2486 do_cleanups (old_chain
);
2488 return baton
.needs_frame
|| in_reg
;
2491 /* A helper function that throws an unimplemented error mentioning a
2492 given DWARF operator. */
2495 unimplemented (unsigned int op
)
2497 const char *name
= get_DW_OP_name (op
);
2500 error (_("DWARF operator %s cannot be translated to an agent expression"),
2503 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2504 "to an agent expression"),
2508 /* A helper function to convert a DWARF register to an arch register.
2509 ARCH is the architecture.
2510 DWARF_REG is the register.
2511 This will throw an exception if the DWARF register cannot be
2512 translated to an architecture register. */
2515 translate_register (struct gdbarch
*arch
, int dwarf_reg
)
2517 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2519 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
2523 /* A helper function that emits an access to memory. ARCH is the
2524 target architecture. EXPR is the expression which we are building.
2525 NBITS is the number of bits we want to read. This emits the
2526 opcodes needed to read the memory and then extract the desired
2530 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2532 ULONGEST nbytes
= (nbits
+ 7) / 8;
2534 gdb_assert (nbits
> 0 && nbits
<= sizeof (LONGEST
));
2537 ax_trace_quick (expr
, nbytes
);
2540 ax_simple (expr
, aop_ref8
);
2541 else if (nbits
<= 16)
2542 ax_simple (expr
, aop_ref16
);
2543 else if (nbits
<= 32)
2544 ax_simple (expr
, aop_ref32
);
2546 ax_simple (expr
, aop_ref64
);
2548 /* If we read exactly the number of bytes we wanted, we're done. */
2549 if (8 * nbytes
== nbits
)
2552 if (gdbarch_bits_big_endian (arch
))
2554 /* On a bits-big-endian machine, we want the high-order
2556 ax_const_l (expr
, 8 * nbytes
- nbits
);
2557 ax_simple (expr
, aop_rsh_unsigned
);
2561 /* On a bits-little-endian box, we want the low-order NBITS. */
2562 ax_zero_ext (expr
, nbits
);
2566 /* A helper function to return the frame's PC. */
2569 get_ax_pc (void *baton
)
2571 struct agent_expr
*expr
= baton
;
2576 /* Compile a DWARF location expression to an agent expression.
2578 EXPR is the agent expression we are building.
2579 LOC is the agent value we modify.
2580 ARCH is the architecture.
2581 ADDR_SIZE is the size of addresses, in bytes.
2582 OP_PTR is the start of the location expression.
2583 OP_END is one past the last byte of the location expression.
2585 This will throw an exception for various kinds of errors -- for
2586 example, if the expression cannot be compiled, or if the expression
2590 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2591 struct gdbarch
*arch
, unsigned int addr_size
,
2592 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
2593 struct dwarf2_per_cu_data
*per_cu
)
2595 struct cleanup
*cleanups
;
2597 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
2598 const gdb_byte
* const base
= op_ptr
;
2599 const gdb_byte
*previous_piece
= op_ptr
;
2600 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2601 ULONGEST bits_collected
= 0;
2602 unsigned int addr_size_bits
= 8 * addr_size
;
2603 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
2605 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
2606 cleanups
= make_cleanup (xfree
, offsets
);
2608 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
2611 make_cleanup (VEC_cleanup (int), &dw_labels
);
2612 make_cleanup (VEC_cleanup (int), &patches
);
2614 /* By default we are making an address. */
2615 loc
->kind
= axs_lvalue_memory
;
2617 while (op_ptr
< op_end
)
2619 enum dwarf_location_atom op
= *op_ptr
;
2620 uint64_t uoffset
, reg
;
2624 offsets
[op_ptr
- base
] = expr
->len
;
2627 /* Our basic approach to code generation is to map DWARF
2628 operations directly to AX operations. However, there are
2631 First, DWARF works on address-sized units, but AX always uses
2632 LONGEST. For most operations we simply ignore this
2633 difference; instead we generate sign extensions as needed
2634 before division and comparison operations. It would be nice
2635 to omit the sign extensions, but there is no way to determine
2636 the size of the target's LONGEST. (This code uses the size
2637 of the host LONGEST in some cases -- that is a bug but it is
2640 Second, some DWARF operations cannot be translated to AX.
2641 For these we simply fail. See
2642 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2677 ax_const_l (expr
, op
- DW_OP_lit0
);
2681 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2682 op_ptr
+= addr_size
;
2683 /* Some versions of GCC emit DW_OP_addr before
2684 DW_OP_GNU_push_tls_address. In this case the value is an
2685 index, not an address. We don't support things like
2686 branching between the address and the TLS op. */
2687 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2688 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
2689 ax_const_l (expr
, uoffset
);
2693 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2697 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2701 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2705 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2709 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2713 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2717 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2721 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2725 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2726 ax_const_l (expr
, uoffset
);
2729 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2730 ax_const_l (expr
, offset
);
2765 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2766 loc
->u
.reg
= translate_register (arch
, op
- DW_OP_reg0
);
2767 loc
->kind
= axs_lvalue_register
;
2771 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2772 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2773 loc
->u
.reg
= translate_register (arch
, reg
);
2774 loc
->kind
= axs_lvalue_register
;
2777 case DW_OP_implicit_value
:
2781 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2782 if (op_ptr
+ len
> op_end
)
2783 error (_("DW_OP_implicit_value: too few bytes available."));
2784 if (len
> sizeof (ULONGEST
))
2785 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2788 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2791 dwarf_expr_require_composition (op_ptr
, op_end
,
2792 "DW_OP_implicit_value");
2794 loc
->kind
= axs_rvalue
;
2798 case DW_OP_stack_value
:
2799 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2800 loc
->kind
= axs_rvalue
;
2835 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2836 i
= translate_register (arch
, op
- DW_OP_breg0
);
2840 ax_const_l (expr
, offset
);
2841 ax_simple (expr
, aop_add
);
2846 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2847 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2848 i
= translate_register (arch
, reg
);
2852 ax_const_l (expr
, offset
);
2853 ax_simple (expr
, aop_add
);
2859 const gdb_byte
*datastart
;
2862 struct symbol
*framefunc
;
2863 LONGEST base_offset
= 0;
2865 b
= block_for_pc (expr
->scope
);
2868 error (_("No block found for address"));
2870 framefunc
= block_linkage_function (b
);
2873 error (_("No function found for block"));
2875 dwarf_expr_frame_base_1 (framefunc
, expr
->scope
,
2876 &datastart
, &datalen
);
2878 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2879 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
2880 datastart
+ datalen
, per_cu
);
2881 if (loc
->kind
== axs_lvalue_register
)
2882 require_rvalue (expr
, loc
);
2886 ax_const_l (expr
, offset
);
2887 ax_simple (expr
, aop_add
);
2890 loc
->kind
= axs_lvalue_memory
;
2895 ax_simple (expr
, aop_dup
);
2899 ax_simple (expr
, aop_pop
);
2904 ax_pick (expr
, offset
);
2908 ax_simple (expr
, aop_swap
);
2916 ax_simple (expr
, aop_rot
);
2920 case DW_OP_deref_size
:
2924 if (op
== DW_OP_deref_size
)
2932 ax_simple (expr
, aop_ref8
);
2935 ax_simple (expr
, aop_ref16
);
2938 ax_simple (expr
, aop_ref32
);
2941 ax_simple (expr
, aop_ref64
);
2944 /* Note that get_DW_OP_name will never return
2946 error (_("Unsupported size %d in %s"),
2947 size
, get_DW_OP_name (op
));
2953 /* Sign extend the operand. */
2954 ax_ext (expr
, addr_size_bits
);
2955 ax_simple (expr
, aop_dup
);
2956 ax_const_l (expr
, 0);
2957 ax_simple (expr
, aop_less_signed
);
2958 ax_simple (expr
, aop_log_not
);
2959 i
= ax_goto (expr
, aop_if_goto
);
2960 /* We have to emit 0 - X. */
2961 ax_const_l (expr
, 0);
2962 ax_simple (expr
, aop_swap
);
2963 ax_simple (expr
, aop_sub
);
2964 ax_label (expr
, i
, expr
->len
);
2968 /* No need to sign extend here. */
2969 ax_const_l (expr
, 0);
2970 ax_simple (expr
, aop_swap
);
2971 ax_simple (expr
, aop_sub
);
2975 /* Sign extend the operand. */
2976 ax_ext (expr
, addr_size_bits
);
2977 ax_simple (expr
, aop_bit_not
);
2980 case DW_OP_plus_uconst
:
2981 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2982 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2983 but we micro-optimize anyhow. */
2986 ax_const_l (expr
, reg
);
2987 ax_simple (expr
, aop_add
);
2992 ax_simple (expr
, aop_bit_and
);
2996 /* Sign extend the operands. */
2997 ax_ext (expr
, addr_size_bits
);
2998 ax_simple (expr
, aop_swap
);
2999 ax_ext (expr
, addr_size_bits
);
3000 ax_simple (expr
, aop_swap
);
3001 ax_simple (expr
, aop_div_signed
);
3005 ax_simple (expr
, aop_sub
);
3009 ax_simple (expr
, aop_rem_unsigned
);
3013 ax_simple (expr
, aop_mul
);
3017 ax_simple (expr
, aop_bit_or
);
3021 ax_simple (expr
, aop_add
);
3025 ax_simple (expr
, aop_lsh
);
3029 ax_simple (expr
, aop_rsh_unsigned
);
3033 ax_simple (expr
, aop_rsh_signed
);
3037 ax_simple (expr
, aop_bit_xor
);
3041 /* Sign extend the operands. */
3042 ax_ext (expr
, addr_size_bits
);
3043 ax_simple (expr
, aop_swap
);
3044 ax_ext (expr
, addr_size_bits
);
3045 /* Note no swap here: A <= B is !(B < A). */
3046 ax_simple (expr
, aop_less_signed
);
3047 ax_simple (expr
, aop_log_not
);
3051 /* Sign extend the operands. */
3052 ax_ext (expr
, addr_size_bits
);
3053 ax_simple (expr
, aop_swap
);
3054 ax_ext (expr
, addr_size_bits
);
3055 ax_simple (expr
, aop_swap
);
3056 /* A >= B is !(A < B). */
3057 ax_simple (expr
, aop_less_signed
);
3058 ax_simple (expr
, aop_log_not
);
3062 /* Sign extend the operands. */
3063 ax_ext (expr
, addr_size_bits
);
3064 ax_simple (expr
, aop_swap
);
3065 ax_ext (expr
, addr_size_bits
);
3066 /* No need for a second swap here. */
3067 ax_simple (expr
, aop_equal
);
3071 /* Sign extend the operands. */
3072 ax_ext (expr
, addr_size_bits
);
3073 ax_simple (expr
, aop_swap
);
3074 ax_ext (expr
, addr_size_bits
);
3075 ax_simple (expr
, aop_swap
);
3076 ax_simple (expr
, aop_less_signed
);
3080 /* Sign extend the operands. */
3081 ax_ext (expr
, addr_size_bits
);
3082 ax_simple (expr
, aop_swap
);
3083 ax_ext (expr
, addr_size_bits
);
3084 /* Note no swap here: A > B is B < A. */
3085 ax_simple (expr
, aop_less_signed
);
3089 /* Sign extend the operands. */
3090 ax_ext (expr
, addr_size_bits
);
3091 ax_simple (expr
, aop_swap
);
3092 ax_ext (expr
, addr_size_bits
);
3093 /* No need for a swap here. */
3094 ax_simple (expr
, aop_equal
);
3095 ax_simple (expr
, aop_log_not
);
3098 case DW_OP_call_frame_cfa
:
3099 dwarf2_compile_cfa_to_ax (expr
, loc
, arch
, expr
->scope
, per_cu
);
3100 loc
->kind
= axs_lvalue_memory
;
3103 case DW_OP_GNU_push_tls_address
:
3108 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3110 i
= ax_goto (expr
, aop_goto
);
3111 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3112 VEC_safe_push (int, patches
, i
);
3116 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3118 /* Zero extend the operand. */
3119 ax_zero_ext (expr
, addr_size_bits
);
3120 i
= ax_goto (expr
, aop_if_goto
);
3121 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3122 VEC_safe_push (int, patches
, i
);
3129 case DW_OP_bit_piece
:
3131 uint64_t size
, offset
;
3133 if (op_ptr
- 1 == previous_piece
)
3134 error (_("Cannot translate empty pieces to agent expressions"));
3135 previous_piece
= op_ptr
- 1;
3137 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3138 if (op
== DW_OP_piece
)
3144 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3146 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3147 error (_("Expression pieces exceed word size"));
3149 /* Access the bits. */
3152 case axs_lvalue_register
:
3153 ax_reg (expr
, loc
->u
.reg
);
3156 case axs_lvalue_memory
:
3157 /* Offset the pointer, if needed. */
3160 ax_const_l (expr
, offset
/ 8);
3161 ax_simple (expr
, aop_add
);
3164 access_memory (arch
, expr
, size
);
3168 /* For a bits-big-endian target, shift up what we already
3169 have. For a bits-little-endian target, shift up the
3170 new data. Note that there is a potential bug here if
3171 the DWARF expression leaves multiple values on the
3173 if (bits_collected
> 0)
3175 if (bits_big_endian
)
3177 ax_simple (expr
, aop_swap
);
3178 ax_const_l (expr
, size
);
3179 ax_simple (expr
, aop_lsh
);
3180 /* We don't need a second swap here, because
3181 aop_bit_or is symmetric. */
3185 ax_const_l (expr
, size
);
3186 ax_simple (expr
, aop_lsh
);
3188 ax_simple (expr
, aop_bit_or
);
3191 bits_collected
+= size
;
3192 loc
->kind
= axs_rvalue
;
3196 case DW_OP_GNU_uninit
:
3202 struct dwarf2_locexpr_baton block
;
3203 int size
= (op
== DW_OP_call2
? 2 : 4);
3206 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3209 offset
.cu_off
= uoffset
;
3210 block
= dwarf2_fetch_die_loc_cu_off (offset
, per_cu
,
3213 /* DW_OP_call_ref is currently not supported. */
3214 gdb_assert (block
.per_cu
== per_cu
);
3216 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3217 block
.data
, block
.data
+ block
.size
,
3222 case DW_OP_call_ref
:
3230 /* Patch all the branches we emitted. */
3231 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
3233 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
3235 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3236 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
3239 do_cleanups (cleanups
);
3243 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3244 evaluator to calculate the location. */
3245 static struct value
*
3246 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3248 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3251 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3252 dlbaton
->size
, dlbaton
->per_cu
);
3257 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3258 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3261 static struct value
*
3262 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3264 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3266 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3270 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3272 locexpr_read_needs_frame (struct symbol
*symbol
)
3274 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3276 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
3280 /* Return true if DATA points to the end of a piece. END is one past
3281 the last byte in the expression. */
3284 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3286 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3289 /* Helper for locexpr_describe_location_piece that finds the name of a
3293 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3297 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
3298 return gdbarch_register_name (gdbarch
, regnum
);
3301 /* Nicely describe a single piece of a location, returning an updated
3302 position in the bytecode sequence. This function cannot recognize
3303 all locations; if a location is not recognized, it simply returns
3304 DATA. If there is an error during reading, e.g. we run off the end
3305 of the buffer, an error is thrown. */
3307 static const gdb_byte
*
3308 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3309 CORE_ADDR addr
, struct objfile
*objfile
,
3310 struct dwarf2_per_cu_data
*per_cu
,
3311 const gdb_byte
*data
, const gdb_byte
*end
,
3312 unsigned int addr_size
)
3314 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3317 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3319 fprintf_filtered (stream
, _("a variable in $%s"),
3320 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3323 else if (data
[0] == DW_OP_regx
)
3327 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3328 fprintf_filtered (stream
, _("a variable in $%s"),
3329 locexpr_regname (gdbarch
, reg
));
3331 else if (data
[0] == DW_OP_fbreg
)
3334 struct symbol
*framefunc
;
3336 int64_t frame_offset
;
3337 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3339 int64_t base_offset
= 0;
3341 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3342 if (!piece_end_p (new_data
, end
))
3346 b
= block_for_pc (addr
);
3349 error (_("No block found for address for symbol \"%s\"."),
3350 SYMBOL_PRINT_NAME (symbol
));
3352 framefunc
= block_linkage_function (b
);
3355 error (_("No function found for block for symbol \"%s\"."),
3356 SYMBOL_PRINT_NAME (symbol
));
3358 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
3360 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3362 const gdb_byte
*buf_end
;
3364 frame_reg
= base_data
[0] - DW_OP_breg0
;
3365 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3367 if (buf_end
!= base_data
+ base_size
)
3368 error (_("Unexpected opcode after "
3369 "DW_OP_breg%u for symbol \"%s\"."),
3370 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3372 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3374 /* The frame base is just the register, with no offset. */
3375 frame_reg
= base_data
[0] - DW_OP_reg0
;
3380 /* We don't know what to do with the frame base expression,
3381 so we can't trace this variable; give up. */
3385 fprintf_filtered (stream
,
3386 _("a variable at frame base reg $%s offset %s+%s"),
3387 locexpr_regname (gdbarch
, frame_reg
),
3388 plongest (base_offset
), plongest (frame_offset
));
3390 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3391 && piece_end_p (data
, end
))
3395 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3397 fprintf_filtered (stream
,
3398 _("a variable at offset %s from base reg $%s"),
3400 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3403 /* The location expression for a TLS variable looks like this (on a
3406 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3407 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3409 0x3 is the encoding for DW_OP_addr, which has an operand as long
3410 as the size of an address on the target machine (here is 8
3411 bytes). Note that more recent version of GCC emit DW_OP_const4u
3412 or DW_OP_const8u, depending on address size, rather than
3413 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3414 The operand represents the offset at which the variable is within
3415 the thread local storage. */
3417 else if (data
+ 1 + addr_size
< end
3418 && (data
[0] == DW_OP_addr
3419 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3420 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3421 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3422 && piece_end_p (data
+ 2 + addr_size
, end
))
3425 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3426 gdbarch_byte_order (gdbarch
));
3428 fprintf_filtered (stream
,
3429 _("a thread-local variable at offset 0x%s "
3430 "in the thread-local storage for `%s'"),
3431 phex_nz (offset
, addr_size
), objfile
->name
);
3433 data
+= 1 + addr_size
+ 1;
3436 /* With -gsplit-dwarf a TLS variable can also look like this:
3437 DW_AT_location : 3 byte block: fc 4 e0
3438 (DW_OP_GNU_const_index: 4;
3439 DW_OP_GNU_push_tls_address) */
3440 else if (data
+ 3 <= end
3441 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3442 && data
[0] == DW_OP_GNU_const_index
3444 && data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3445 && piece_end_p (data
+ 2 + leb128_size
, end
))
3449 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3450 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3451 fprintf_filtered (stream
,
3452 _("a thread-local variable at offset 0x%s "
3453 "in the thread-local storage for `%s'"),
3454 phex_nz (offset
, addr_size
), objfile
->name
);
3458 else if (data
[0] >= DW_OP_lit0
3459 && data
[0] <= DW_OP_lit31
3461 && data
[1] == DW_OP_stack_value
)
3463 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3470 /* Disassemble an expression, stopping at the end of a piece or at the
3471 end of the expression. Returns a pointer to the next unread byte
3472 in the input expression. If ALL is nonzero, then this function
3473 will keep going until it reaches the end of the expression.
3474 If there is an error during reading, e.g. we run off the end
3475 of the buffer, an error is thrown. */
3477 static const gdb_byte
*
3478 disassemble_dwarf_expression (struct ui_file
*stream
,
3479 struct gdbarch
*arch
, unsigned int addr_size
,
3480 int offset_size
, const gdb_byte
*start
,
3481 const gdb_byte
*data
, const gdb_byte
*end
,
3482 int indent
, int all
,
3483 struct dwarf2_per_cu_data
*per_cu
)
3487 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3489 enum dwarf_location_atom op
= *data
++;
3494 name
= get_DW_OP_name (op
);
3497 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3498 op
, (long) (data
- 1 - start
));
3499 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3500 (long) (data
- 1 - start
), name
);
3505 ul
= extract_unsigned_integer (data
, addr_size
,
3506 gdbarch_byte_order (arch
));
3508 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3512 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3514 fprintf_filtered (stream
, " %s", pulongest (ul
));
3517 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3519 fprintf_filtered (stream
, " %s", plongest (l
));
3522 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3524 fprintf_filtered (stream
, " %s", pulongest (ul
));
3527 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3529 fprintf_filtered (stream
, " %s", plongest (l
));
3532 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3534 fprintf_filtered (stream
, " %s", pulongest (ul
));
3537 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3539 fprintf_filtered (stream
, " %s", plongest (l
));
3542 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3544 fprintf_filtered (stream
, " %s", pulongest (ul
));
3547 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3549 fprintf_filtered (stream
, " %s", plongest (l
));
3552 data
= safe_read_uleb128 (data
, end
, &ul
);
3553 fprintf_filtered (stream
, " %s", pulongest (ul
));
3556 data
= safe_read_sleb128 (data
, end
, &l
);
3557 fprintf_filtered (stream
, " %s", plongest (l
));
3592 fprintf_filtered (stream
, " [$%s]",
3593 locexpr_regname (arch
, op
- DW_OP_reg0
));
3597 data
= safe_read_uleb128 (data
, end
, &ul
);
3598 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3599 locexpr_regname (arch
, (int) ul
));
3602 case DW_OP_implicit_value
:
3603 data
= safe_read_uleb128 (data
, end
, &ul
);
3605 fprintf_filtered (stream
, " %s", pulongest (ul
));
3640 data
= safe_read_sleb128 (data
, end
, &l
);
3641 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3642 locexpr_regname (arch
, op
- DW_OP_breg0
));
3646 data
= safe_read_uleb128 (data
, end
, &ul
);
3647 data
= safe_read_sleb128 (data
, end
, &l
);
3648 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3650 locexpr_regname (arch
, (int) ul
),
3655 data
= safe_read_sleb128 (data
, end
, &l
);
3656 fprintf_filtered (stream
, " %s", plongest (l
));
3659 case DW_OP_xderef_size
:
3660 case DW_OP_deref_size
:
3662 fprintf_filtered (stream
, " %d", *data
);
3666 case DW_OP_plus_uconst
:
3667 data
= safe_read_uleb128 (data
, end
, &ul
);
3668 fprintf_filtered (stream
, " %s", pulongest (ul
));
3672 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3674 fprintf_filtered (stream
, " to %ld",
3675 (long) (data
+ l
- start
));
3679 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3681 fprintf_filtered (stream
, " %ld",
3682 (long) (data
+ l
- start
));
3686 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3688 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3692 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3694 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3697 case DW_OP_call_ref
:
3698 ul
= extract_unsigned_integer (data
, offset_size
,
3699 gdbarch_byte_order (arch
));
3700 data
+= offset_size
;
3701 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3705 data
= safe_read_uleb128 (data
, end
, &ul
);
3706 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3709 case DW_OP_bit_piece
:
3713 data
= safe_read_uleb128 (data
, end
, &ul
);
3714 data
= safe_read_uleb128 (data
, end
, &offset
);
3715 fprintf_filtered (stream
, " size %s offset %s (bits)",
3716 pulongest (ul
), pulongest (offset
));
3720 case DW_OP_GNU_implicit_pointer
:
3722 ul
= extract_unsigned_integer (data
, offset_size
,
3723 gdbarch_byte_order (arch
));
3724 data
+= offset_size
;
3726 data
= safe_read_sleb128 (data
, end
, &l
);
3728 fprintf_filtered (stream
, " DIE %s offset %s",
3729 phex_nz (ul
, offset_size
),
3734 case DW_OP_GNU_deref_type
:
3736 int addr_size
= *data
++;
3740 data
= safe_read_uleb128 (data
, end
, &ul
);
3742 type
= dwarf2_get_die_type (offset
, per_cu
);
3743 fprintf_filtered (stream
, "<");
3744 type_print (type
, "", stream
, -1);
3745 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
.cu_off
, 0),
3750 case DW_OP_GNU_const_type
:
3755 data
= safe_read_uleb128 (data
, end
, &ul
);
3756 type_die
.cu_off
= ul
;
3757 type
= dwarf2_get_die_type (type_die
, per_cu
);
3758 fprintf_filtered (stream
, "<");
3759 type_print (type
, "", stream
, -1);
3760 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
3764 case DW_OP_GNU_regval_type
:
3770 data
= safe_read_uleb128 (data
, end
, ®
);
3771 data
= safe_read_uleb128 (data
, end
, &ul
);
3772 type_die
.cu_off
= ul
;
3774 type
= dwarf2_get_die_type (type_die
, per_cu
);
3775 fprintf_filtered (stream
, "<");
3776 type_print (type
, "", stream
, -1);
3777 fprintf_filtered (stream
, " [0x%s]> [$%s]",
3778 phex_nz (type_die
.cu_off
, 0),
3779 locexpr_regname (arch
, reg
));
3783 case DW_OP_GNU_convert
:
3784 case DW_OP_GNU_reinterpret
:
3788 data
= safe_read_uleb128 (data
, end
, &ul
);
3789 type_die
.cu_off
= ul
;
3791 if (type_die
.cu_off
== 0)
3792 fprintf_filtered (stream
, "<0>");
3797 type
= dwarf2_get_die_type (type_die
, per_cu
);
3798 fprintf_filtered (stream
, "<");
3799 type_print (type
, "", stream
, -1);
3800 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
3805 case DW_OP_GNU_entry_value
:
3806 data
= safe_read_uleb128 (data
, end
, &ul
);
3807 fputc_filtered ('\n', stream
);
3808 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3809 start
, data
, data
+ ul
, indent
+ 2,
3814 case DW_OP_GNU_parameter_ref
:
3815 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3817 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3820 case DW_OP_GNU_addr_index
:
3821 data
= safe_read_uleb128 (data
, end
, &ul
);
3822 ul
= dwarf2_read_addr_index (per_cu
, ul
);
3823 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3825 case DW_OP_GNU_const_index
:
3826 data
= safe_read_uleb128 (data
, end
, &ul
);
3827 ul
= dwarf2_read_addr_index (per_cu
, ul
);
3828 fprintf_filtered (stream
, " %s", pulongest (ul
));
3832 fprintf_filtered (stream
, "\n");
3838 /* Describe a single location, which may in turn consist of multiple
3842 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3843 struct ui_file
*stream
,
3844 const gdb_byte
*data
, size_t size
,
3845 struct objfile
*objfile
, unsigned int addr_size
,
3846 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
3848 const gdb_byte
*end
= data
+ size
;
3849 int first_piece
= 1, bad
= 0;
3853 const gdb_byte
*here
= data
;
3854 int disassemble
= 1;
3859 fprintf_filtered (stream
, _(", and "));
3861 if (!dwarf2_always_disassemble
)
3863 data
= locexpr_describe_location_piece (symbol
, stream
,
3864 addr
, objfile
, per_cu
,
3865 data
, end
, addr_size
);
3866 /* If we printed anything, or if we have an empty piece,
3867 then don't disassemble. */
3869 || data
[0] == DW_OP_piece
3870 || data
[0] == DW_OP_bit_piece
)
3875 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3876 data
= disassemble_dwarf_expression (stream
,
3877 get_objfile_arch (objfile
),
3878 addr_size
, offset_size
, data
,
3880 dwarf2_always_disassemble
,
3886 int empty
= data
== here
;
3889 fprintf_filtered (stream
, " ");
3890 if (data
[0] == DW_OP_piece
)
3894 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3897 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3900 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3903 else if (data
[0] == DW_OP_bit_piece
)
3905 uint64_t bits
, offset
;
3907 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3908 data
= safe_read_uleb128 (data
, end
, &offset
);
3911 fprintf_filtered (stream
,
3912 _("an empty %s-bit piece"),
3915 fprintf_filtered (stream
,
3916 _(" [%s-bit piece, offset %s bits]"),
3917 pulongest (bits
), pulongest (offset
));
3927 if (bad
|| data
> end
)
3928 error (_("Corrupted DWARF2 expression for \"%s\"."),
3929 SYMBOL_PRINT_NAME (symbol
));
3932 /* Print a natural-language description of SYMBOL to STREAM. This
3933 version is for a symbol with a single location. */
3936 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3937 struct ui_file
*stream
)
3939 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3940 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
3941 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3942 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
3944 locexpr_describe_location_1 (symbol
, addr
, stream
,
3945 dlbaton
->data
, dlbaton
->size
,
3946 objfile
, addr_size
, offset_size
,
3950 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3951 any necessary bytecode in AX. */
3954 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
3955 struct agent_expr
*ax
, struct axs_value
*value
)
3957 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3958 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3960 if (dlbaton
->size
== 0)
3961 value
->optimized_out
= 1;
3963 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
3964 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3968 /* The set of location functions used with the DWARF-2 expression
3970 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3971 locexpr_read_variable
,
3972 locexpr_read_variable_at_entry
,
3973 locexpr_read_needs_frame
,
3974 locexpr_describe_location
,
3975 locexpr_tracepoint_var_ref
3979 /* Wrapper functions for location lists. These generally find
3980 the appropriate location expression and call something above. */
3982 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3983 evaluator to calculate the location. */
3984 static struct value
*
3985 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3987 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3989 const gdb_byte
*data
;
3991 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3993 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3994 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4000 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4001 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4004 Function always returns non-NULL value, it may be marked optimized out if
4005 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4006 if it cannot resolve the parameter for any reason. */
4008 static struct value
*
4009 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4011 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4012 const gdb_byte
*data
;
4016 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4017 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4019 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4021 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4023 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4026 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
4028 loclist_read_needs_frame (struct symbol
*symbol
)
4030 /* If there's a location list, then assume we need to have a frame
4031 to choose the appropriate location expression. With tracking of
4032 global variables this is not necessarily true, but such tracking
4033 is disabled in GCC at the moment until we figure out how to
4039 /* Print a natural-language description of SYMBOL to STREAM. This
4040 version applies when there is a list of different locations, each
4041 with a specified address range. */
4044 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4045 struct ui_file
*stream
)
4047 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4048 const gdb_byte
*loc_ptr
, *buf_end
;
4050 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4051 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4052 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4053 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4054 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4055 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4056 /* Adjust base_address for relocatable objects. */
4057 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4058 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4061 loc_ptr
= dlbaton
->data
;
4062 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4064 fprintf_filtered (stream
, _("multi-location:\n"));
4066 /* Iterate through locations until we run out. */
4069 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4071 enum debug_loc_kind kind
;
4072 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4074 if (dlbaton
->from_dwo
)
4075 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4076 loc_ptr
, buf_end
, &new_ptr
,
4077 &low
, &high
, byte_order
);
4079 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4081 byte_order
, addr_size
,
4086 case DEBUG_LOC_END_OF_LIST
:
4089 case DEBUG_LOC_BASE_ADDRESS
:
4090 base_address
= high
+ base_offset
;
4091 fprintf_filtered (stream
, _(" Base address %s"),
4092 paddress (gdbarch
, base_address
));
4094 case DEBUG_LOC_START_END
:
4095 case DEBUG_LOC_START_LENGTH
:
4097 case DEBUG_LOC_BUFFER_OVERFLOW
:
4098 case DEBUG_LOC_INVALID_ENTRY
:
4099 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4100 SYMBOL_PRINT_NAME (symbol
));
4102 gdb_assert_not_reached ("bad debug_loc_kind");
4105 /* Otherwise, a location expression entry. */
4106 low
+= base_address
;
4107 high
+= base_address
;
4109 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4112 /* (It would improve readability to print only the minimum
4113 necessary digits of the second number of the range.) */
4114 fprintf_filtered (stream
, _(" Range %s-%s: "),
4115 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4117 /* Now describe this particular location. */
4118 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4119 objfile
, addr_size
, offset_size
,
4122 fprintf_filtered (stream
, "\n");
4128 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4129 any necessary bytecode in AX. */
4131 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4132 struct agent_expr
*ax
, struct axs_value
*value
)
4134 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4135 const gdb_byte
*data
;
4137 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4139 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4141 value
->optimized_out
= 1;
4143 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4147 /* The set of location functions used with the DWARF-2 expression
4148 evaluator and location lists. */
4149 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4150 loclist_read_variable
,
4151 loclist_read_variable_at_entry
,
4152 loclist_read_needs_frame
,
4153 loclist_describe_location
,
4154 loclist_tracepoint_var_ref
4157 /* Provide a prototype to silence -Wmissing-prototypes. */
4158 extern initialize_file_ftype _initialize_dwarf2loc
;
4161 _initialize_dwarf2loc (void)
4163 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4164 &entry_values_debug
,
4165 _("Set entry values and tail call frames "
4167 _("Show entry values and tail call frames "
4169 _("When non-zero, the process of determining "
4170 "parameter values from function entry point "
4171 "and tail call frames will be printed."),
4173 show_entry_values_debug
,
4174 &setdebuglist
, &showdebuglist
);