1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003, 2005, 2007-2012 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
;
336 /* Use block_linkage_function, which returns a real (not inlined)
337 function, instead of get_frame_function, which may return an
339 framefunc
= block_linkage_function (get_frame_block (debaton
->frame
, NULL
));
341 /* If we found a frame-relative symbol then it was certainly within
342 some function associated with a frame. If we can't find the frame,
343 something has gone wrong. */
344 gdb_assert (framefunc
!= NULL
);
346 dwarf_expr_frame_base_1 (framefunc
,
347 get_frame_address_in_block (debaton
->frame
),
352 dwarf_expr_frame_base_1 (struct symbol
*framefunc
, CORE_ADDR pc
,
353 const gdb_byte
**start
, size_t *length
)
355 if (SYMBOL_LOCATION_BATON (framefunc
) == NULL
)
357 else if (SYMBOL_COMPUTED_OPS (framefunc
) == &dwarf2_loclist_funcs
)
359 struct dwarf2_loclist_baton
*symbaton
;
361 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
362 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
366 struct dwarf2_locexpr_baton
*symbaton
;
368 symbaton
= SYMBOL_LOCATION_BATON (framefunc
);
369 if (symbaton
!= NULL
)
371 *length
= symbaton
->size
;
372 *start
= symbaton
->data
;
379 error (_("Could not find the frame base for \"%s\"."),
380 SYMBOL_NATURAL_NAME (framefunc
));
383 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
384 the frame in BATON. */
387 dwarf_expr_frame_cfa (void *baton
)
389 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
391 return dwarf2_frame_cfa (debaton
->frame
);
394 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
395 the frame in BATON. */
398 dwarf_expr_frame_pc (void *baton
)
400 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
402 return get_frame_address_in_block (debaton
->frame
);
405 /* Using the objfile specified in BATON, find the address for the
406 current thread's thread-local storage with offset OFFSET. */
408 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
410 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
411 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
413 return target_translate_tls_address (objfile
, offset
);
416 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
417 current CU (as is PER_CU). State of the CTX is not affected by the
421 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
422 struct dwarf2_per_cu_data
*per_cu
,
423 CORE_ADDR (*get_frame_pc
) (void *baton
),
426 struct dwarf2_locexpr_baton block
;
428 block
= dwarf2_fetch_die_location_block (die_offset
, per_cu
,
429 get_frame_pc
, baton
);
431 /* DW_OP_call_ref is currently not supported. */
432 gdb_assert (block
.per_cu
== per_cu
);
434 dwarf_expr_eval (ctx
, block
.data
, block
.size
);
437 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
440 dwarf_expr_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
442 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
444 per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
445 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
448 /* Callback function for dwarf2_evaluate_loc_desc. */
451 dwarf_expr_get_base_type (struct dwarf_expr_context
*ctx
,
452 cu_offset die_offset
)
454 struct dwarf_expr_baton
*debaton
= ctx
->baton
;
456 return dwarf2_get_die_type (die_offset
, debaton
->per_cu
);
459 /* See dwarf2loc.h. */
461 int entry_values_debug
= 0;
463 /* Helper to set entry_values_debug. */
466 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
467 struct cmd_list_element
*c
, const char *value
)
469 fprintf_filtered (file
,
470 _("Entry values and tail call frames debugging is %s.\n"),
474 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
475 CALLER_FRAME (for registers) can be NULL if it is not known. This function
476 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
479 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
480 struct call_site
*call_site
,
481 struct frame_info
*caller_frame
)
483 switch (FIELD_LOC_KIND (call_site
->target
))
485 case FIELD_LOC_KIND_DWARF_BLOCK
:
487 struct dwarf2_locexpr_baton
*dwarf_block
;
489 struct type
*caller_core_addr_type
;
490 struct gdbarch
*caller_arch
;
492 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
493 if (dwarf_block
== NULL
)
495 struct minimal_symbol
*msym
;
497 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
498 throw_error (NO_ENTRY_VALUE_ERROR
,
499 _("DW_AT_GNU_call_site_target is not specified "
501 paddress (call_site_gdbarch
, call_site
->pc
),
502 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
505 if (caller_frame
== NULL
)
507 struct minimal_symbol
*msym
;
509 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
510 throw_error (NO_ENTRY_VALUE_ERROR
,
511 _("DW_AT_GNU_call_site_target DWARF block resolving "
512 "requires known frame which is currently not "
513 "available at %s in %s"),
514 paddress (call_site_gdbarch
, call_site
->pc
),
515 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
518 caller_arch
= get_frame_arch (caller_frame
);
519 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
520 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
521 dwarf_block
->data
, dwarf_block
->size
,
522 dwarf_block
->per_cu
);
523 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
525 if (VALUE_LVAL (val
) == lval_memory
)
526 return value_address (val
);
528 return value_as_address (val
);
531 case FIELD_LOC_KIND_PHYSNAME
:
533 const char *physname
;
534 struct minimal_symbol
*msym
;
536 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
537 msym
= lookup_minimal_symbol_text (physname
, NULL
);
540 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
541 throw_error (NO_ENTRY_VALUE_ERROR
,
542 _("Cannot find function \"%s\" for a call site target "
544 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
545 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
548 return SYMBOL_VALUE_ADDRESS (msym
);
551 case FIELD_LOC_KIND_PHYSADDR
:
552 return FIELD_STATIC_PHYSADDR (call_site
->target
);
555 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
559 /* Convert function entry point exact address ADDR to the function which is
560 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
561 NO_ENTRY_VALUE_ERROR otherwise. */
563 static struct symbol
*
564 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
566 struct symbol
*sym
= find_pc_function (addr
);
569 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
570 throw_error (NO_ENTRY_VALUE_ERROR
,
571 _("DW_TAG_GNU_call_site resolving failed to find function "
572 "name for address %s"),
573 paddress (gdbarch
, addr
));
575 type
= SYMBOL_TYPE (sym
);
576 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
577 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
582 /* Verify function with entry point exact address ADDR can never call itself
583 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
584 can call itself via tail calls.
586 If a funtion can tail call itself its entry value based parameters are
587 unreliable. There is no verification whether the value of some/all
588 parameters is unchanged through the self tail call, we expect if there is
589 a self tail call all the parameters can be modified. */
592 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
594 struct obstack addr_obstack
;
595 struct cleanup
*old_chain
;
598 /* Track here CORE_ADDRs which were already visited. */
601 /* The verification is completely unordered. Track here function addresses
602 which still need to be iterated. */
603 VEC (CORE_ADDR
) *todo
= NULL
;
605 obstack_init (&addr_obstack
);
606 old_chain
= make_cleanup_obstack_free (&addr_obstack
);
607 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
608 &addr_obstack
, hashtab_obstack_allocate
,
610 make_cleanup_htab_delete (addr_hash
);
612 make_cleanup (VEC_cleanup (CORE_ADDR
), &todo
);
614 VEC_safe_push (CORE_ADDR
, todo
, verify_addr
);
615 while (!VEC_empty (CORE_ADDR
, todo
))
617 struct symbol
*func_sym
;
618 struct call_site
*call_site
;
620 addr
= VEC_pop (CORE_ADDR
, todo
);
622 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
624 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
625 call_site
; call_site
= call_site
->tail_call_next
)
627 CORE_ADDR target_addr
;
630 /* CALLER_FRAME with registers is not available for tail-call jumped
632 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
634 if (target_addr
== verify_addr
)
636 struct minimal_symbol
*msym
;
638 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
639 throw_error (NO_ENTRY_VALUE_ERROR
,
640 _("DW_OP_GNU_entry_value resolving has found "
641 "function \"%s\" at %s can call itself via tail "
643 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
644 paddress (gdbarch
, verify_addr
));
647 slot
= htab_find_slot (addr_hash
, &target_addr
, INSERT
);
650 *slot
= obstack_copy (&addr_obstack
, &target_addr
,
651 sizeof (target_addr
));
652 VEC_safe_push (CORE_ADDR
, todo
, target_addr
);
657 do_cleanups (old_chain
);
660 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
661 ENTRY_VALUES_DEBUG. */
664 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
666 CORE_ADDR addr
= call_site
->pc
;
667 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (addr
- 1);
669 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
670 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
674 /* vec.h needs single word type name, typedef it. */
675 typedef struct call_site
*call_sitep
;
677 /* Define VEC (call_sitep) functions. */
678 DEF_VEC_P (call_sitep
);
680 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
681 only top callers and bottom callees which are present in both. GDBARCH is
682 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
683 no remaining possibilities to provide unambiguous non-trivial result.
684 RESULTP should point to NULL on the first (initialization) call. Caller is
685 responsible for xfree of any RESULTP data. */
688 chain_candidate (struct gdbarch
*gdbarch
, struct call_site_chain
**resultp
,
689 VEC (call_sitep
) *chain
)
691 struct call_site_chain
*result
= *resultp
;
692 long length
= VEC_length (call_sitep
, chain
);
693 int callers
, callees
, idx
;
697 /* Create the initial chain containing all the passed PCs. */
699 result
= xmalloc (sizeof (*result
) + sizeof (*result
->call_site
)
701 result
->length
= length
;
702 result
->callers
= result
->callees
= length
;
703 memcpy (result
->call_site
, VEC_address (call_sitep
, chain
),
704 sizeof (*result
->call_site
) * length
);
707 if (entry_values_debug
)
709 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
710 for (idx
= 0; idx
< length
; idx
++)
711 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
712 fputc_unfiltered ('\n', gdb_stdlog
);
718 if (entry_values_debug
)
720 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
721 for (idx
= 0; idx
< length
; idx
++)
722 tailcall_dump (gdbarch
, VEC_index (call_sitep
, chain
, idx
));
723 fputc_unfiltered ('\n', gdb_stdlog
);
726 /* Intersect callers. */
728 callers
= min (result
->callers
, length
);
729 for (idx
= 0; idx
< callers
; idx
++)
730 if (result
->call_site
[idx
] != VEC_index (call_sitep
, chain
, idx
))
732 result
->callers
= idx
;
736 /* Intersect callees. */
738 callees
= min (result
->callees
, length
);
739 for (idx
= 0; idx
< callees
; idx
++)
740 if (result
->call_site
[result
->length
- 1 - idx
]
741 != VEC_index (call_sitep
, chain
, length
- 1 - idx
))
743 result
->callees
= idx
;
747 if (entry_values_debug
)
749 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
750 for (idx
= 0; idx
< result
->callers
; idx
++)
751 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
752 fputs_unfiltered (" |", gdb_stdlog
);
753 for (idx
= 0; idx
< result
->callees
; idx
++)
754 tailcall_dump (gdbarch
, result
->call_site
[result
->length
755 - result
->callees
+ idx
]);
756 fputc_unfiltered ('\n', gdb_stdlog
);
759 if (result
->callers
== 0 && result
->callees
== 0)
761 /* There are no common callers or callees. It could be also a direct
762 call (which has length 0) with ambiguous possibility of an indirect
763 call - CALLERS == CALLEES == 0 is valid during the first allocation
764 but any subsequence processing of such entry means ambiguity. */
770 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
771 PC again. In such case there must be two different code paths to reach
772 it, therefore some of the former determined intermediate PCs must differ
773 and the unambiguous chain gets shortened. */
774 gdb_assert (result
->callers
+ result
->callees
< result
->length
);
777 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
778 assumed frames between them use GDBARCH. Use depth first search so we can
779 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
780 would have needless GDB stack overhead. Caller is responsible for xfree of
781 the returned result. Any unreliability results in thrown
782 NO_ENTRY_VALUE_ERROR. */
784 static struct call_site_chain
*
785 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
788 struct obstack addr_obstack
;
789 struct cleanup
*back_to_retval
, *back_to_workdata
;
790 struct call_site_chain
*retval
= NULL
;
791 struct call_site
*call_site
;
793 /* Mark CALL_SITEs so we do not visit the same ones twice. */
796 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
797 call_site nor any possible call_site at CALLEE_PC's function is there.
798 Any CALL_SITE in CHAIN will be iterated to its siblings - via
799 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
800 VEC (call_sitep
) *chain
= NULL
;
802 /* We are not interested in the specific PC inside the callee function. */
803 callee_pc
= get_pc_function_start (callee_pc
);
805 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
806 paddress (gdbarch
, callee_pc
));
808 back_to_retval
= make_cleanup (free_current_contents
, &retval
);
810 obstack_init (&addr_obstack
);
811 back_to_workdata
= make_cleanup_obstack_free (&addr_obstack
);
812 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
813 &addr_obstack
, hashtab_obstack_allocate
,
815 make_cleanup_htab_delete (addr_hash
);
817 make_cleanup (VEC_cleanup (call_sitep
), &chain
);
819 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
820 at the target's function. All the possible tail call sites in the
821 target's function will get iterated as already pushed into CHAIN via their
823 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
827 CORE_ADDR target_func_addr
;
828 struct call_site
*target_call_site
;
830 /* CALLER_FRAME with registers is not available for tail-call jumped
832 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
834 if (target_func_addr
== callee_pc
)
836 chain_candidate (gdbarch
, &retval
, chain
);
840 /* There is no way to reach CALLEE_PC again as we would prevent
841 entering it twice as being already marked in ADDR_HASH. */
842 target_call_site
= NULL
;
846 struct symbol
*target_func
;
848 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
849 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
854 /* Attempt to visit TARGET_CALL_SITE. */
856 if (target_call_site
)
860 slot
= htab_find_slot (addr_hash
, &target_call_site
->pc
, INSERT
);
863 /* Successfully entered TARGET_CALL_SITE. */
865 *slot
= &target_call_site
->pc
;
866 VEC_safe_push (call_sitep
, chain
, target_call_site
);
871 /* Backtrack (without revisiting the originating call_site). Try the
872 callers's sibling; if there isn't any try the callers's callers's
875 target_call_site
= NULL
;
876 while (!VEC_empty (call_sitep
, chain
))
878 call_site
= VEC_pop (call_sitep
, chain
);
880 gdb_assert (htab_find_slot (addr_hash
, &call_site
->pc
,
882 htab_remove_elt (addr_hash
, &call_site
->pc
);
884 target_call_site
= call_site
->tail_call_next
;
885 if (target_call_site
)
889 while (target_call_site
);
891 if (VEC_empty (call_sitep
, chain
))
894 call_site
= VEC_last (call_sitep
, chain
);
899 struct minimal_symbol
*msym_caller
, *msym_callee
;
901 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
902 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
903 throw_error (NO_ENTRY_VALUE_ERROR
,
904 _("There are no unambiguously determinable intermediate "
905 "callers or callees between caller function \"%s\" at %s "
906 "and callee function \"%s\" at %s"),
908 ? "???" : SYMBOL_PRINT_NAME (msym_caller
)),
909 paddress (gdbarch
, caller_pc
),
911 ? "???" : SYMBOL_PRINT_NAME (msym_callee
)),
912 paddress (gdbarch
, callee_pc
));
915 do_cleanups (back_to_workdata
);
916 discard_cleanups (back_to_retval
);
920 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
921 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
922 constructed return NULL. Caller is responsible for xfree of the returned
925 struct call_site_chain
*
926 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
929 volatile struct gdb_exception e
;
930 struct call_site_chain
*retval
= NULL
;
932 TRY_CATCH (e
, RETURN_MASK_ERROR
)
934 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
938 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
940 if (entry_values_debug
)
941 exception_print (gdb_stdout
, e
);
951 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
954 call_site_parameter_matches (struct call_site_parameter
*parameter
,
955 enum call_site_parameter_kind kind
,
956 union call_site_parameter_u kind_u
)
958 if (kind
== parameter
->kind
)
961 case CALL_SITE_PARAMETER_DWARF_REG
:
962 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
963 case CALL_SITE_PARAMETER_FB_OFFSET
:
964 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
969 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
972 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
975 static struct call_site_parameter
*
976 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
977 enum call_site_parameter_kind kind
,
978 union call_site_parameter_u kind_u
,
979 struct dwarf2_per_cu_data
**per_cu_return
)
981 CORE_ADDR func_addr
= get_frame_func (frame
);
983 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
984 struct frame_info
*caller_frame
= get_prev_frame (frame
);
985 struct call_site
*call_site
;
987 /* Initialize it just to avoid a GCC false warning. */
988 struct call_site_parameter
*parameter
= NULL
;
989 CORE_ADDR target_addr
;
991 if (gdbarch
!= frame_unwind_arch (frame
))
993 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
994 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
996 throw_error (NO_ENTRY_VALUE_ERROR
,
997 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
998 "(of %s (%s)) does not match caller gdbarch %s"),
999 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1000 paddress (gdbarch
, func_addr
),
1001 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
),
1002 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1005 if (caller_frame
== NULL
)
1007 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (func_addr
);
1009 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_GNU_entry_value resolving "
1010 "requires caller of %s (%s)"),
1011 paddress (gdbarch
, func_addr
),
1012 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
1014 caller_pc
= get_frame_pc (caller_frame
);
1015 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1017 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1018 if (target_addr
!= func_addr
)
1020 struct minimal_symbol
*target_msym
, *func_msym
;
1022 target_msym
= lookup_minimal_symbol_by_pc (target_addr
);
1023 func_msym
= lookup_minimal_symbol_by_pc (func_addr
);
1024 throw_error (NO_ENTRY_VALUE_ERROR
,
1025 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
1026 "but the called frame is for %s at %s"),
1027 (target_msym
== NULL
? "???"
1028 : SYMBOL_PRINT_NAME (target_msym
)),
1029 paddress (gdbarch
, target_addr
),
1030 func_msym
== NULL
? "???" : SYMBOL_PRINT_NAME (func_msym
),
1031 paddress (gdbarch
, func_addr
));
1034 /* No entry value based parameters would be reliable if this function can
1035 call itself via tail calls. */
1036 func_verify_no_selftailcall (gdbarch
, func_addr
);
1038 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1040 parameter
= &call_site
->parameter
[iparams
];
1041 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1044 if (iparams
== call_site
->parameter_count
)
1046 struct minimal_symbol
*msym
= lookup_minimal_symbol_by_pc (caller_pc
);
1048 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
1049 determine its value. */
1050 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1051 "at DW_TAG_GNU_call_site %s at %s"),
1052 paddress (gdbarch
, caller_pc
),
1053 msym
== NULL
? "???" : SYMBOL_PRINT_NAME (msym
));
1056 *per_cu_return
= call_site
->per_cu
;
1060 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1061 the normal DW_AT_GNU_call_site_value block. Otherwise return the
1062 DW_AT_GNU_call_site_data_value (dereferenced) block.
1064 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1067 Function always returns non-NULL, non-optimized out value. It throws
1068 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1070 static struct value
*
1071 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1072 CORE_ADDR deref_size
, struct type
*type
,
1073 struct frame_info
*caller_frame
,
1074 struct dwarf2_per_cu_data
*per_cu
)
1076 const gdb_byte
*data_src
;
1080 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1081 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1083 /* DEREF_SIZE size is not verified here. */
1084 if (data_src
== NULL
)
1085 throw_error (NO_ENTRY_VALUE_ERROR
,
1086 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1088 /* DW_AT_GNU_call_site_value is a DWARF expression, not a DWARF
1089 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1091 data
= alloca (size
+ 1);
1092 memcpy (data
, data_src
, size
);
1093 data
[size
] = DW_OP_stack_value
;
1095 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1098 /* Execute DWARF block of call_site_parameter which matches KIND and KIND_U.
1099 Choose DEREF_SIZE value of that parameter. Search caller of the CTX's
1100 frame. CTX must be of dwarf_expr_ctx_funcs kind.
1102 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
1103 can be more simple as it does not support cross-CU DWARF executions. */
1106 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
1107 enum call_site_parameter_kind kind
,
1108 union call_site_parameter_u kind_u
,
1111 struct dwarf_expr_baton
*debaton
;
1112 struct frame_info
*frame
, *caller_frame
;
1113 struct dwarf2_per_cu_data
*caller_per_cu
;
1114 struct dwarf_expr_baton baton_local
;
1115 struct dwarf_expr_context saved_ctx
;
1116 struct call_site_parameter
*parameter
;
1117 const gdb_byte
*data_src
;
1120 gdb_assert (ctx
->funcs
== &dwarf_expr_ctx_funcs
);
1121 debaton
= ctx
->baton
;
1122 frame
= debaton
->frame
;
1123 caller_frame
= get_prev_frame (frame
);
1125 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1127 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1128 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1130 /* DEREF_SIZE size is not verified here. */
1131 if (data_src
== NULL
)
1132 throw_error (NO_ENTRY_VALUE_ERROR
,
1133 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1135 baton_local
.frame
= caller_frame
;
1136 baton_local
.per_cu
= caller_per_cu
;
1138 saved_ctx
.gdbarch
= ctx
->gdbarch
;
1139 saved_ctx
.addr_size
= ctx
->addr_size
;
1140 saved_ctx
.offset
= ctx
->offset
;
1141 saved_ctx
.baton
= ctx
->baton
;
1142 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (baton_local
.per_cu
));
1143 ctx
->addr_size
= dwarf2_per_cu_addr_size (baton_local
.per_cu
);
1144 ctx
->offset
= dwarf2_per_cu_text_offset (baton_local
.per_cu
);
1145 ctx
->baton
= &baton_local
;
1147 dwarf_expr_eval (ctx
, data_src
, size
);
1149 ctx
->gdbarch
= saved_ctx
.gdbarch
;
1150 ctx
->addr_size
= saved_ctx
.addr_size
;
1151 ctx
->offset
= saved_ctx
.offset
;
1152 ctx
->baton
= saved_ctx
.baton
;
1155 /* Callback function for dwarf2_evaluate_loc_desc.
1156 Fetch the address indexed by DW_OP_GNU_addr_index. */
1159 dwarf_expr_get_addr_index (void *baton
, unsigned int index
)
1161 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
1163 return dwarf2_read_addr_index (debaton
->per_cu
, index
);
1166 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1167 the indirect method on it, that is use its stored target value, the sole
1168 purpose of entry_data_value_funcs.. */
1170 static struct value
*
1171 entry_data_value_coerce_ref (const struct value
*value
)
1173 struct type
*checked_type
= check_typedef (value_type (value
));
1174 struct value
*target_val
;
1176 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
)
1179 target_val
= value_computed_closure (value
);
1180 value_incref (target_val
);
1184 /* Implement copy_closure. */
1187 entry_data_value_copy_closure (const struct value
*v
)
1189 struct value
*target_val
= value_computed_closure (v
);
1191 value_incref (target_val
);
1195 /* Implement free_closure. */
1198 entry_data_value_free_closure (struct value
*v
)
1200 struct value
*target_val
= value_computed_closure (v
);
1202 value_free (target_val
);
1205 /* Vector for methods for an entry value reference where the referenced value
1206 is stored in the caller. On the first dereference use
1207 DW_AT_GNU_call_site_data_value in the caller. */
1209 static const struct lval_funcs entry_data_value_funcs
=
1213 NULL
, /* check_validity */
1214 NULL
, /* check_any_valid */
1215 NULL
, /* indirect */
1216 entry_data_value_coerce_ref
,
1217 NULL
, /* check_synthetic_pointer */
1218 entry_data_value_copy_closure
,
1219 entry_data_value_free_closure
1222 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1223 are used to match DW_AT_location at the caller's
1224 DW_TAG_GNU_call_site_parameter.
1226 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1227 cannot resolve the parameter for any reason. */
1229 static struct value
*
1230 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1231 enum call_site_parameter_kind kind
,
1232 union call_site_parameter_u kind_u
)
1234 struct type
*checked_type
= check_typedef (type
);
1235 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1236 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1237 struct value
*outer_val
, *target_val
, *val
;
1238 struct call_site_parameter
*parameter
;
1239 struct dwarf2_per_cu_data
*caller_per_cu
;
1242 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1245 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1249 /* Check if DW_AT_GNU_call_site_data_value cannot be used. If it should be
1250 used and it is not available do not fall back to OUTER_VAL - dereferencing
1251 TYPE_CODE_REF with non-entry data value would give current value - not the
1254 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
1255 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1258 target_val
= dwarf_entry_parameter_to_value (parameter
,
1259 TYPE_LENGTH (target_type
),
1260 target_type
, caller_frame
,
1263 /* value_as_address dereferences TYPE_CODE_REF. */
1264 addr
= extract_typed_address (value_contents (outer_val
), checked_type
);
1266 /* The target entry value has artificial address of the entry value
1268 VALUE_LVAL (target_val
) = lval_memory
;
1269 set_value_address (target_val
, addr
);
1271 release_value (target_val
);
1272 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1273 target_val
/* closure */);
1275 /* Copy the referencing pointer to the new computed value. */
1276 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1277 TYPE_LENGTH (checked_type
));
1278 set_value_lazy (val
, 0);
1283 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1284 SIZE are DWARF block used to match DW_AT_location at the caller's
1285 DW_TAG_GNU_call_site_parameter.
1287 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1288 cannot resolve the parameter for any reason. */
1290 static struct value
*
1291 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1292 const gdb_byte
*block
, size_t block_len
)
1294 union call_site_parameter_u kind_u
;
1296 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1297 if (kind_u
.dwarf_reg
!= -1)
1298 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1301 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1302 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1305 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1306 suppressed during normal operation. The expression can be arbitrary if
1307 there is no caller-callee entry value binding expected. */
1308 throw_error (NO_ENTRY_VALUE_ERROR
,
1309 _("DWARF-2 expression error: DW_OP_GNU_entry_value is supported "
1310 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1313 struct piece_closure
1315 /* Reference count. */
1318 /* The CU from which this closure's expression came. */
1319 struct dwarf2_per_cu_data
*per_cu
;
1321 /* The number of pieces used to describe this variable. */
1324 /* The target address size, used only for DWARF_VALUE_STACK. */
1327 /* The pieces themselves. */
1328 struct dwarf_expr_piece
*pieces
;
1331 /* Allocate a closure for a value formed from separately-described
1334 static struct piece_closure
*
1335 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1336 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1339 struct piece_closure
*c
= XZALLOC (struct piece_closure
);
1344 c
->n_pieces
= n_pieces
;
1345 c
->addr_size
= addr_size
;
1346 c
->pieces
= XCALLOC (n_pieces
, struct dwarf_expr_piece
);
1348 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1349 for (i
= 0; i
< n_pieces
; ++i
)
1350 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1351 value_incref (c
->pieces
[i
].v
.value
);
1356 /* The lowest-level function to extract bits from a byte buffer.
1357 SOURCE is the buffer. It is updated if we read to the end of a
1359 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
1360 updated to reflect the number of bits actually read.
1361 NBITS is the number of bits we want to read. It is updated to
1362 reflect the number of bits actually read. This function may read
1364 BITS_BIG_ENDIAN is taken directly from gdbarch.
1365 This function returns the extracted bits. */
1368 extract_bits_primitive (const gdb_byte
**source
,
1369 unsigned int *source_offset_bits
,
1370 int *nbits
, int bits_big_endian
)
1372 unsigned int avail
, mask
, datum
;
1374 gdb_assert (*source_offset_bits
< 8);
1376 avail
= 8 - *source_offset_bits
;
1380 mask
= (1 << avail
) - 1;
1382 if (bits_big_endian
)
1383 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
1385 datum
>>= *source_offset_bits
;
1389 *source_offset_bits
+= avail
;
1390 if (*source_offset_bits
>= 8)
1392 *source_offset_bits
-= 8;
1399 /* Extract some bits from a source buffer and move forward in the
1402 SOURCE is the source buffer. It is updated as bytes are read.
1403 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1405 NBITS is the number of bits to read.
1406 BITS_BIG_ENDIAN is taken directly from gdbarch.
1408 This function returns the bits that were read. */
1411 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
1412 int nbits
, int bits_big_endian
)
1416 gdb_assert (nbits
> 0 && nbits
<= 8);
1418 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1424 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1426 if (bits_big_endian
)
1436 /* Write some bits into a buffer and move forward in the buffer.
1438 DATUM is the bits to write. The low-order bits of DATUM are used.
1439 DEST is the destination buffer. It is updated as bytes are
1441 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1443 NBITS is the number of valid bits in DATUM.
1444 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1447 insert_bits (unsigned int datum
,
1448 gdb_byte
*dest
, unsigned int dest_offset_bits
,
1449 int nbits
, int bits_big_endian
)
1453 gdb_assert (dest_offset_bits
+ nbits
<= 8);
1455 mask
= (1 << nbits
) - 1;
1456 if (bits_big_endian
)
1458 datum
<<= 8 - (dest_offset_bits
+ nbits
);
1459 mask
<<= 8 - (dest_offset_bits
+ nbits
);
1463 datum
<<= dest_offset_bits
;
1464 mask
<<= dest_offset_bits
;
1467 gdb_assert ((datum
& ~mask
) == 0);
1469 *dest
= (*dest
& ~mask
) | datum
;
1472 /* Copy bits from a source to a destination.
1474 DEST is where the bits should be written.
1475 DEST_OFFSET_BITS is the bit offset into DEST.
1476 SOURCE is the source of bits.
1477 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1478 BIT_COUNT is the number of bits to copy.
1479 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1482 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
1483 const gdb_byte
*source
, unsigned int source_offset_bits
,
1484 unsigned int bit_count
,
1485 int bits_big_endian
)
1487 unsigned int dest_avail
;
1490 /* Reduce everything to byte-size pieces. */
1491 dest
+= dest_offset_bits
/ 8;
1492 dest_offset_bits
%= 8;
1493 source
+= source_offset_bits
/ 8;
1494 source_offset_bits
%= 8;
1496 dest_avail
= 8 - dest_offset_bits
% 8;
1498 /* See if we can fill the first destination byte. */
1499 if (dest_avail
< bit_count
)
1501 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
1503 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
1505 dest_offset_bits
= 0;
1506 bit_count
-= dest_avail
;
1509 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1510 than 8 bits remaining. */
1511 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
1512 for (; bit_count
>= 8; bit_count
-= 8)
1514 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
1515 *dest
++ = (gdb_byte
) datum
;
1518 /* Finally, we may have a few leftover bits. */
1519 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
1522 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
1524 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
1529 read_pieced_value (struct value
*v
)
1533 ULONGEST bits_to_skip
;
1535 struct piece_closure
*c
1536 = (struct piece_closure
*) value_computed_closure (v
);
1537 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
1539 size_t buffer_size
= 0;
1540 char *buffer
= NULL
;
1541 struct cleanup
*cleanup
;
1543 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1545 if (value_type (v
) != value_enclosing_type (v
))
1546 internal_error (__FILE__
, __LINE__
,
1547 _("Should not be able to create a lazy value with "
1548 "an enclosing type"));
1550 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1552 contents
= value_contents_raw (v
);
1553 bits_to_skip
= 8 * value_offset (v
);
1554 if (value_bitsize (v
))
1556 bits_to_skip
+= value_bitpos (v
);
1557 type_len
= value_bitsize (v
);
1560 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1562 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1564 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1565 size_t this_size
, this_size_bits
;
1566 long dest_offset_bits
, source_offset_bits
, source_offset
;
1567 const gdb_byte
*intermediate_buffer
;
1569 /* Compute size, source, and destination offsets for copying, in
1571 this_size_bits
= p
->size
;
1572 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1574 bits_to_skip
-= this_size_bits
;
1577 if (this_size_bits
> type_len
- offset
)
1578 this_size_bits
= type_len
- offset
;
1579 if (bits_to_skip
> 0)
1581 dest_offset_bits
= 0;
1582 source_offset_bits
= bits_to_skip
;
1583 this_size_bits
-= bits_to_skip
;
1588 dest_offset_bits
= offset
;
1589 source_offset_bits
= 0;
1592 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1593 source_offset
= source_offset_bits
/ 8;
1594 if (buffer_size
< this_size
)
1596 buffer_size
= this_size
;
1597 buffer
= xrealloc (buffer
, buffer_size
);
1599 intermediate_buffer
= buffer
;
1601 /* Copy from the source to DEST_BUFFER. */
1602 switch (p
->location
)
1604 case DWARF_VALUE_REGISTER
:
1606 struct gdbarch
*arch
= get_frame_arch (frame
);
1607 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1608 int reg_offset
= source_offset
;
1610 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1611 && this_size
< register_size (arch
, gdb_regnum
))
1613 /* Big-endian, and we want less than full size. */
1614 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1615 /* We want the lower-order THIS_SIZE_BITS of the bytes
1616 we extract from the register. */
1617 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1620 if (gdb_regnum
!= -1)
1624 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1628 /* Just so garbage doesn't ever shine through. */
1629 memset (buffer
, 0, this_size
);
1632 set_value_optimized_out (v
, 1);
1634 mark_value_bytes_unavailable (v
, offset
, this_size
);
1639 error (_("Unable to access DWARF register number %s"),
1640 paddress (arch
, p
->v
.regno
));
1645 case DWARF_VALUE_MEMORY
:
1646 read_value_memory (v
, offset
,
1647 p
->v
.mem
.in_stack_memory
,
1648 p
->v
.mem
.addr
+ source_offset
,
1652 case DWARF_VALUE_STACK
:
1654 size_t n
= this_size
;
1656 if (n
> c
->addr_size
- source_offset
)
1657 n
= (c
->addr_size
>= source_offset
1658 ? c
->addr_size
- source_offset
1666 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
1668 intermediate_buffer
= val_bytes
+ source_offset
;
1673 case DWARF_VALUE_LITERAL
:
1675 size_t n
= this_size
;
1677 if (n
> p
->v
.literal
.length
- source_offset
)
1678 n
= (p
->v
.literal
.length
>= source_offset
1679 ? p
->v
.literal
.length
- source_offset
1682 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1686 /* These bits show up as zeros -- but do not cause the value
1687 to be considered optimized-out. */
1688 case DWARF_VALUE_IMPLICIT_POINTER
:
1691 case DWARF_VALUE_OPTIMIZED_OUT
:
1692 set_value_optimized_out (v
, 1);
1696 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1699 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
1700 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1701 copy_bitwise (contents
, dest_offset_bits
,
1702 intermediate_buffer
, source_offset_bits
% 8,
1703 this_size_bits
, bits_big_endian
);
1705 offset
+= this_size_bits
;
1708 do_cleanups (cleanup
);
1712 write_pieced_value (struct value
*to
, struct value
*from
)
1716 ULONGEST bits_to_skip
;
1717 const gdb_byte
*contents
;
1718 struct piece_closure
*c
1719 = (struct piece_closure
*) value_computed_closure (to
);
1720 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
1722 size_t buffer_size
= 0;
1723 char *buffer
= NULL
;
1724 struct cleanup
*cleanup
;
1726 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1730 set_value_optimized_out (to
, 1);
1734 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1736 contents
= value_contents (from
);
1737 bits_to_skip
= 8 * value_offset (to
);
1738 if (value_bitsize (to
))
1740 bits_to_skip
+= value_bitpos (to
);
1741 type_len
= value_bitsize (to
);
1744 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1746 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1748 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1749 size_t this_size_bits
, this_size
;
1750 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1752 const gdb_byte
*source_buffer
;
1754 this_size_bits
= p
->size
;
1755 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1757 bits_to_skip
-= this_size_bits
;
1760 if (this_size_bits
> type_len
- offset
)
1761 this_size_bits
= type_len
- offset
;
1762 if (bits_to_skip
> 0)
1764 dest_offset_bits
= bits_to_skip
;
1765 source_offset_bits
= 0;
1766 this_size_bits
-= bits_to_skip
;
1771 dest_offset_bits
= 0;
1772 source_offset_bits
= offset
;
1775 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1776 source_offset
= source_offset_bits
/ 8;
1777 dest_offset
= dest_offset_bits
/ 8;
1778 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1780 source_buffer
= contents
+ source_offset
;
1785 if (buffer_size
< this_size
)
1787 buffer_size
= this_size
;
1788 buffer
= xrealloc (buffer
, buffer_size
);
1790 source_buffer
= buffer
;
1794 switch (p
->location
)
1796 case DWARF_VALUE_REGISTER
:
1798 struct gdbarch
*arch
= get_frame_arch (frame
);
1799 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, p
->v
.regno
);
1800 int reg_offset
= dest_offset
;
1802 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1803 && this_size
<= register_size (arch
, gdb_regnum
))
1804 /* Big-endian, and we want less than full size. */
1805 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1807 if (gdb_regnum
!= -1)
1813 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1818 error (_("Can't do read-modify-write to "
1819 "update bitfield; containing word has been "
1822 throw_error (NOT_AVAILABLE_ERROR
,
1823 _("Can't do read-modify-write to update "
1824 "bitfield; containing word "
1827 copy_bitwise (buffer
, dest_offset_bits
,
1828 contents
, source_offset_bits
,
1833 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1834 this_size
, source_buffer
);
1838 error (_("Unable to write to DWARF register number %s"),
1839 paddress (arch
, p
->v
.regno
));
1843 case DWARF_VALUE_MEMORY
:
1846 /* Only the first and last bytes can possibly have any
1848 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
1849 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
1850 buffer
+ this_size
- 1, 1);
1851 copy_bitwise (buffer
, dest_offset_bits
,
1852 contents
, source_offset_bits
,
1857 write_memory (p
->v
.mem
.addr
+ dest_offset
,
1858 source_buffer
, this_size
);
1861 set_value_optimized_out (to
, 1);
1864 offset
+= this_size_bits
;
1867 do_cleanups (cleanup
);
1870 /* A helper function that checks bit validity in a pieced value.
1871 CHECK_FOR indicates the kind of validity checking.
1872 DWARF_VALUE_MEMORY means to check whether any bit is valid.
1873 DWARF_VALUE_OPTIMIZED_OUT means to check whether any bit is
1875 DWARF_VALUE_IMPLICIT_POINTER means to check whether the bits are an
1876 implicit pointer. */
1879 check_pieced_value_bits (const struct value
*value
, int bit_offset
,
1881 enum dwarf_value_location check_for
)
1883 struct piece_closure
*c
1884 = (struct piece_closure
*) value_computed_closure (value
);
1886 int validity
= (check_for
== DWARF_VALUE_MEMORY
1887 || check_for
== DWARF_VALUE_IMPLICIT_POINTER
);
1889 bit_offset
+= 8 * value_offset (value
);
1890 if (value_bitsize (value
))
1891 bit_offset
+= value_bitpos (value
);
1893 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1895 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1896 size_t this_size_bits
= p
->size
;
1900 if (bit_offset
>= this_size_bits
)
1902 bit_offset
-= this_size_bits
;
1906 bit_length
-= this_size_bits
- bit_offset
;
1910 bit_length
-= this_size_bits
;
1912 if (check_for
== DWARF_VALUE_IMPLICIT_POINTER
)
1914 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1917 else if (p
->location
== DWARF_VALUE_OPTIMIZED_OUT
1918 || p
->location
== DWARF_VALUE_IMPLICIT_POINTER
)
1934 check_pieced_value_validity (const struct value
*value
, int bit_offset
,
1937 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1938 DWARF_VALUE_MEMORY
);
1942 check_pieced_value_invalid (const struct value
*value
)
1944 return check_pieced_value_bits (value
, 0,
1945 8 * TYPE_LENGTH (value_type (value
)),
1946 DWARF_VALUE_OPTIMIZED_OUT
);
1949 /* An implementation of an lval_funcs method to see whether a value is
1950 a synthetic pointer. */
1953 check_pieced_synthetic_pointer (const struct value
*value
, int bit_offset
,
1956 return check_pieced_value_bits (value
, bit_offset
, bit_length
,
1957 DWARF_VALUE_IMPLICIT_POINTER
);
1960 /* A wrapper function for get_frame_address_in_block. */
1963 get_frame_address_in_block_wrapper (void *baton
)
1965 return get_frame_address_in_block (baton
);
1968 /* An implementation of an lval_funcs method to indirect through a
1969 pointer. This handles the synthetic pointer case when needed. */
1971 static struct value
*
1972 indirect_pieced_value (struct value
*value
)
1974 struct piece_closure
*c
1975 = (struct piece_closure
*) value_computed_closure (value
);
1977 struct frame_info
*frame
;
1978 struct dwarf2_locexpr_baton baton
;
1979 int i
, bit_offset
, bit_length
;
1980 struct dwarf_expr_piece
*piece
= NULL
;
1981 LONGEST byte_offset
;
1983 type
= check_typedef (value_type (value
));
1984 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1987 bit_length
= 8 * TYPE_LENGTH (type
);
1988 bit_offset
= 8 * value_offset (value
);
1989 if (value_bitsize (value
))
1990 bit_offset
+= value_bitpos (value
);
1992 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
1994 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1995 size_t this_size_bits
= p
->size
;
1999 if (bit_offset
>= this_size_bits
)
2001 bit_offset
-= this_size_bits
;
2005 bit_length
-= this_size_bits
- bit_offset
;
2009 bit_length
-= this_size_bits
;
2011 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2014 if (bit_length
!= 0)
2015 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
2021 frame
= get_selected_frame (_("No frame selected."));
2023 /* This is an offset requested by GDB, such as value subcripts. */
2024 byte_offset
= value_as_address (value
);
2027 baton
= dwarf2_fetch_die_location_block (piece
->v
.ptr
.die
, c
->per_cu
,
2028 get_frame_address_in_block_wrapper
,
2031 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
2032 baton
.data
, baton
.size
, baton
.per_cu
,
2033 piece
->v
.ptr
.offset
+ byte_offset
);
2037 copy_pieced_value_closure (const struct value
*v
)
2039 struct piece_closure
*c
2040 = (struct piece_closure
*) value_computed_closure (v
);
2047 free_pieced_value_closure (struct value
*v
)
2049 struct piece_closure
*c
2050 = (struct piece_closure
*) value_computed_closure (v
);
2057 for (i
= 0; i
< c
->n_pieces
; ++i
)
2058 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2059 value_free (c
->pieces
[i
].v
.value
);
2066 /* Functions for accessing a variable described by DW_OP_piece. */
2067 static const struct lval_funcs pieced_value_funcs
= {
2070 check_pieced_value_validity
,
2071 check_pieced_value_invalid
,
2072 indirect_pieced_value
,
2073 NULL
, /* coerce_ref */
2074 check_pieced_synthetic_pointer
,
2075 copy_pieced_value_closure
,
2076 free_pieced_value_closure
2079 /* Helper function which throws an error if a synthetic pointer is
2083 invalid_synthetic_pointer (void)
2085 error (_("access outside bounds of object "
2086 "referenced via synthetic pointer"));
2089 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
2091 static const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
2093 dwarf_expr_read_reg
,
2094 dwarf_expr_read_mem
,
2095 dwarf_expr_frame_base
,
2096 dwarf_expr_frame_cfa
,
2097 dwarf_expr_frame_pc
,
2098 dwarf_expr_tls_address
,
2099 dwarf_expr_dwarf_call
,
2100 dwarf_expr_get_base_type
,
2101 dwarf_expr_push_dwarf_reg_entry_value
,
2102 dwarf_expr_get_addr_index
2105 /* Evaluate a location description, starting at DATA and with length
2106 SIZE, to find the current location of variable of TYPE in the
2107 context of FRAME. BYTE_OFFSET is applied after the contents are
2110 static struct value
*
2111 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2112 const gdb_byte
*data
, unsigned short size
,
2113 struct dwarf2_per_cu_data
*per_cu
,
2114 LONGEST byte_offset
)
2116 struct value
*retval
;
2117 struct dwarf_expr_baton baton
;
2118 struct dwarf_expr_context
*ctx
;
2119 struct cleanup
*old_chain
, *value_chain
;
2120 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2121 volatile struct gdb_exception ex
;
2123 if (byte_offset
< 0)
2124 invalid_synthetic_pointer ();
2127 return allocate_optimized_out_value (type
);
2129 baton
.frame
= frame
;
2130 baton
.per_cu
= per_cu
;
2132 ctx
= new_dwarf_expr_context ();
2133 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2134 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
2136 ctx
->gdbarch
= get_objfile_arch (objfile
);
2137 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2138 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2139 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2140 ctx
->baton
= &baton
;
2141 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2143 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2145 dwarf_expr_eval (ctx
, data
, size
);
2149 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2151 do_cleanups (old_chain
);
2152 retval
= allocate_value (type
);
2153 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
2156 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2158 if (entry_values_debug
)
2159 exception_print (gdb_stdout
, ex
);
2160 do_cleanups (old_chain
);
2161 return allocate_optimized_out_value (type
);
2164 throw_exception (ex
);
2167 if (ctx
->num_pieces
> 0)
2169 struct piece_closure
*c
;
2170 struct frame_id frame_id
= get_frame_id (frame
);
2171 ULONGEST bit_size
= 0;
2174 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
2175 bit_size
+= ctx
->pieces
[i
].size
;
2176 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
2177 invalid_synthetic_pointer ();
2179 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
2181 /* We must clean up the value chain after creating the piece
2182 closure but before allocating the result. */
2183 do_cleanups (value_chain
);
2184 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
2185 VALUE_FRAME_ID (retval
) = frame_id
;
2186 set_value_offset (retval
, byte_offset
);
2190 switch (ctx
->location
)
2192 case DWARF_VALUE_REGISTER
:
2194 struct gdbarch
*arch
= get_frame_arch (frame
);
2195 ULONGEST dwarf_regnum
= value_as_long (dwarf_expr_fetch (ctx
, 0));
2196 int gdb_regnum
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_regnum
);
2198 if (byte_offset
!= 0)
2199 error (_("cannot use offset on synthetic pointer to register"));
2200 do_cleanups (value_chain
);
2201 if (gdb_regnum
!= -1)
2202 retval
= value_from_register (type
, gdb_regnum
, frame
);
2204 error (_("Unable to access DWARF register number %s"),
2205 paddress (arch
, dwarf_regnum
));
2209 case DWARF_VALUE_MEMORY
:
2211 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
2212 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
2214 do_cleanups (value_chain
);
2215 retval
= allocate_value_lazy (type
);
2216 VALUE_LVAL (retval
) = lval_memory
;
2217 if (in_stack_memory
)
2218 set_value_stack (retval
, 1);
2219 set_value_address (retval
, address
+ byte_offset
);
2223 case DWARF_VALUE_STACK
:
2225 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
2227 const gdb_byte
*val_bytes
;
2228 size_t n
= TYPE_LENGTH (value_type (value
));
2230 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2231 invalid_synthetic_pointer ();
2233 val_bytes
= value_contents_all (value
);
2234 val_bytes
+= byte_offset
;
2237 /* Preserve VALUE because we are going to free values back
2238 to the mark, but we still need the value contents
2240 value_incref (value
);
2241 do_cleanups (value_chain
);
2242 make_cleanup_value_free (value
);
2244 retval
= allocate_value (type
);
2245 contents
= value_contents_raw (retval
);
2246 if (n
> TYPE_LENGTH (type
))
2248 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2250 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2251 val_bytes
+= n
- TYPE_LENGTH (type
);
2252 n
= TYPE_LENGTH (type
);
2254 memcpy (contents
, val_bytes
, n
);
2258 case DWARF_VALUE_LITERAL
:
2261 const bfd_byte
*ldata
;
2262 size_t n
= ctx
->len
;
2264 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2265 invalid_synthetic_pointer ();
2267 do_cleanups (value_chain
);
2268 retval
= allocate_value (type
);
2269 contents
= value_contents_raw (retval
);
2271 ldata
= ctx
->data
+ byte_offset
;
2274 if (n
> TYPE_LENGTH (type
))
2276 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2278 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2279 ldata
+= n
- TYPE_LENGTH (type
);
2280 n
= TYPE_LENGTH (type
);
2282 memcpy (contents
, ldata
, n
);
2286 case DWARF_VALUE_OPTIMIZED_OUT
:
2287 do_cleanups (value_chain
);
2288 retval
= allocate_optimized_out_value (type
);
2291 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2292 operation by execute_stack_op. */
2293 case DWARF_VALUE_IMPLICIT_POINTER
:
2294 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2295 it can only be encountered when making a piece. */
2297 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2301 set_value_initialized (retval
, ctx
->initialized
);
2303 do_cleanups (old_chain
);
2308 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2309 passes 0 as the byte_offset. */
2312 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2313 const gdb_byte
*data
, unsigned short size
,
2314 struct dwarf2_per_cu_data
*per_cu
)
2316 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
2320 /* Helper functions and baton for dwarf2_loc_desc_needs_frame. */
2322 struct needs_frame_baton
2325 struct dwarf2_per_cu_data
*per_cu
;
2328 /* Reads from registers do require a frame. */
2330 needs_frame_read_reg (void *baton
, int regnum
)
2332 struct needs_frame_baton
*nf_baton
= baton
;
2334 nf_baton
->needs_frame
= 1;
2338 /* Reads from memory do not require a frame. */
2340 needs_frame_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
2342 memset (buf
, 0, len
);
2345 /* Frame-relative accesses do require a frame. */
2347 needs_frame_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
2349 static gdb_byte lit0
= DW_OP_lit0
;
2350 struct needs_frame_baton
*nf_baton
= baton
;
2355 nf_baton
->needs_frame
= 1;
2358 /* CFA accesses require a frame. */
2361 needs_frame_frame_cfa (void *baton
)
2363 struct needs_frame_baton
*nf_baton
= baton
;
2365 nf_baton
->needs_frame
= 1;
2369 /* Thread-local accesses do require a frame. */
2371 needs_frame_tls_address (void *baton
, CORE_ADDR offset
)
2373 struct needs_frame_baton
*nf_baton
= baton
;
2375 nf_baton
->needs_frame
= 1;
2379 /* Helper interface of per_cu_dwarf_call for dwarf2_loc_desc_needs_frame. */
2382 needs_frame_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
2384 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2386 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
2387 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
2390 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2393 needs_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
2394 enum call_site_parameter_kind kind
,
2395 union call_site_parameter_u kind_u
, int deref_size
)
2397 struct needs_frame_baton
*nf_baton
= ctx
->baton
;
2399 nf_baton
->needs_frame
= 1;
2402 /* DW_OP_GNU_addr_index doesn't require a frame. */
2405 needs_get_addr_index (void *baton
, unsigned int index
)
2407 /* Nothing to do. */
2411 /* Virtual method table for dwarf2_loc_desc_needs_frame below. */
2413 static const struct dwarf_expr_context_funcs needs_frame_ctx_funcs
=
2415 needs_frame_read_reg
,
2416 needs_frame_read_mem
,
2417 needs_frame_frame_base
,
2418 needs_frame_frame_cfa
,
2419 needs_frame_frame_cfa
, /* get_frame_pc */
2420 needs_frame_tls_address
,
2421 needs_frame_dwarf_call
,
2422 NULL
, /* get_base_type */
2423 needs_dwarf_reg_entry_value
,
2424 needs_get_addr_index
2427 /* Return non-zero iff the location expression at DATA (length SIZE)
2428 requires a frame to evaluate. */
2431 dwarf2_loc_desc_needs_frame (const gdb_byte
*data
, unsigned short size
,
2432 struct dwarf2_per_cu_data
*per_cu
)
2434 struct needs_frame_baton baton
;
2435 struct dwarf_expr_context
*ctx
;
2437 struct cleanup
*old_chain
;
2438 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2440 baton
.needs_frame
= 0;
2441 baton
.per_cu
= per_cu
;
2443 ctx
= new_dwarf_expr_context ();
2444 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2445 make_cleanup_value_free_to_mark (value_mark ());
2447 ctx
->gdbarch
= get_objfile_arch (objfile
);
2448 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2449 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2450 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2451 ctx
->baton
= &baton
;
2452 ctx
->funcs
= &needs_frame_ctx_funcs
;
2454 dwarf_expr_eval (ctx
, data
, size
);
2456 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
2458 if (ctx
->num_pieces
> 0)
2462 /* If the location has several pieces, and any of them are in
2463 registers, then we will need a frame to fetch them from. */
2464 for (i
= 0; i
< ctx
->num_pieces
; i
++)
2465 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2469 do_cleanups (old_chain
);
2471 return baton
.needs_frame
|| in_reg
;
2474 /* A helper function that throws an unimplemented error mentioning a
2475 given DWARF operator. */
2478 unimplemented (unsigned int op
)
2480 const char *name
= get_DW_OP_name (op
);
2483 error (_("DWARF operator %s cannot be translated to an agent expression"),
2486 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2487 "to an agent expression"),
2491 /* A helper function to convert a DWARF register to an arch register.
2492 ARCH is the architecture.
2493 DWARF_REG is the register.
2494 This will throw an exception if the DWARF register cannot be
2495 translated to an architecture register. */
2498 translate_register (struct gdbarch
*arch
, int dwarf_reg
)
2500 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2502 error (_("Unable to access DWARF register number %d"), dwarf_reg
);
2506 /* A helper function that emits an access to memory. ARCH is the
2507 target architecture. EXPR is the expression which we are building.
2508 NBITS is the number of bits we want to read. This emits the
2509 opcodes needed to read the memory and then extract the desired
2513 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2515 ULONGEST nbytes
= (nbits
+ 7) / 8;
2517 gdb_assert (nbits
> 0 && nbits
<= sizeof (LONGEST
));
2520 ax_trace_quick (expr
, nbytes
);
2523 ax_simple (expr
, aop_ref8
);
2524 else if (nbits
<= 16)
2525 ax_simple (expr
, aop_ref16
);
2526 else if (nbits
<= 32)
2527 ax_simple (expr
, aop_ref32
);
2529 ax_simple (expr
, aop_ref64
);
2531 /* If we read exactly the number of bytes we wanted, we're done. */
2532 if (8 * nbytes
== nbits
)
2535 if (gdbarch_bits_big_endian (arch
))
2537 /* On a bits-big-endian machine, we want the high-order
2539 ax_const_l (expr
, 8 * nbytes
- nbits
);
2540 ax_simple (expr
, aop_rsh_unsigned
);
2544 /* On a bits-little-endian box, we want the low-order NBITS. */
2545 ax_zero_ext (expr
, nbits
);
2549 /* A helper function to return the frame's PC. */
2552 get_ax_pc (void *baton
)
2554 struct agent_expr
*expr
= baton
;
2559 /* Compile a DWARF location expression to an agent expression.
2561 EXPR is the agent expression we are building.
2562 LOC is the agent value we modify.
2563 ARCH is the architecture.
2564 ADDR_SIZE is the size of addresses, in bytes.
2565 OP_PTR is the start of the location expression.
2566 OP_END is one past the last byte of the location expression.
2568 This will throw an exception for various kinds of errors -- for
2569 example, if the expression cannot be compiled, or if the expression
2573 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2574 struct gdbarch
*arch
, unsigned int addr_size
,
2575 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
2576 struct dwarf2_per_cu_data
*per_cu
)
2578 struct cleanup
*cleanups
;
2580 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
2581 const gdb_byte
* const base
= op_ptr
;
2582 const gdb_byte
*previous_piece
= op_ptr
;
2583 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2584 ULONGEST bits_collected
= 0;
2585 unsigned int addr_size_bits
= 8 * addr_size
;
2586 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
2588 offsets
= xmalloc ((op_end
- op_ptr
) * sizeof (int));
2589 cleanups
= make_cleanup (xfree
, offsets
);
2591 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
2594 make_cleanup (VEC_cleanup (int), &dw_labels
);
2595 make_cleanup (VEC_cleanup (int), &patches
);
2597 /* By default we are making an address. */
2598 loc
->kind
= axs_lvalue_memory
;
2600 while (op_ptr
< op_end
)
2602 enum dwarf_location_atom op
= *op_ptr
;
2603 uint64_t uoffset
, reg
;
2607 offsets
[op_ptr
- base
] = expr
->len
;
2610 /* Our basic approach to code generation is to map DWARF
2611 operations directly to AX operations. However, there are
2614 First, DWARF works on address-sized units, but AX always uses
2615 LONGEST. For most operations we simply ignore this
2616 difference; instead we generate sign extensions as needed
2617 before division and comparison operations. It would be nice
2618 to omit the sign extensions, but there is no way to determine
2619 the size of the target's LONGEST. (This code uses the size
2620 of the host LONGEST in some cases -- that is a bug but it is
2623 Second, some DWARF operations cannot be translated to AX.
2624 For these we simply fail. See
2625 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2660 ax_const_l (expr
, op
- DW_OP_lit0
);
2664 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2665 op_ptr
+= addr_size
;
2666 /* Some versions of GCC emit DW_OP_addr before
2667 DW_OP_GNU_push_tls_address. In this case the value is an
2668 index, not an address. We don't support things like
2669 branching between the address and the TLS op. */
2670 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2671 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
2672 ax_const_l (expr
, uoffset
);
2676 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2680 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2684 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2688 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2692 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2696 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2700 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2704 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2708 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2709 ax_const_l (expr
, uoffset
);
2712 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2713 ax_const_l (expr
, offset
);
2748 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2749 loc
->u
.reg
= translate_register (arch
, op
- DW_OP_reg0
);
2750 loc
->kind
= axs_lvalue_register
;
2754 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2755 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2756 loc
->u
.reg
= translate_register (arch
, reg
);
2757 loc
->kind
= axs_lvalue_register
;
2760 case DW_OP_implicit_value
:
2764 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2765 if (op_ptr
+ len
> op_end
)
2766 error (_("DW_OP_implicit_value: too few bytes available."));
2767 if (len
> sizeof (ULONGEST
))
2768 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2771 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2774 dwarf_expr_require_composition (op_ptr
, op_end
,
2775 "DW_OP_implicit_value");
2777 loc
->kind
= axs_rvalue
;
2781 case DW_OP_stack_value
:
2782 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2783 loc
->kind
= axs_rvalue
;
2818 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2819 i
= translate_register (arch
, op
- DW_OP_breg0
);
2823 ax_const_l (expr
, offset
);
2824 ax_simple (expr
, aop_add
);
2829 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2830 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2831 i
= translate_register (arch
, reg
);
2835 ax_const_l (expr
, offset
);
2836 ax_simple (expr
, aop_add
);
2842 const gdb_byte
*datastart
;
2845 struct symbol
*framefunc
;
2846 LONGEST base_offset
= 0;
2848 b
= block_for_pc (expr
->scope
);
2851 error (_("No block found for address"));
2853 framefunc
= block_linkage_function (b
);
2856 error (_("No function found for block"));
2858 dwarf_expr_frame_base_1 (framefunc
, expr
->scope
,
2859 &datastart
, &datalen
);
2861 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2862 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
2863 datastart
+ datalen
, per_cu
);
2867 ax_const_l (expr
, offset
);
2868 ax_simple (expr
, aop_add
);
2871 loc
->kind
= axs_lvalue_memory
;
2876 ax_simple (expr
, aop_dup
);
2880 ax_simple (expr
, aop_pop
);
2885 ax_pick (expr
, offset
);
2889 ax_simple (expr
, aop_swap
);
2897 ax_simple (expr
, aop_rot
);
2901 case DW_OP_deref_size
:
2905 if (op
== DW_OP_deref_size
)
2913 ax_simple (expr
, aop_ref8
);
2916 ax_simple (expr
, aop_ref16
);
2919 ax_simple (expr
, aop_ref32
);
2922 ax_simple (expr
, aop_ref64
);
2925 /* Note that get_DW_OP_name will never return
2927 error (_("Unsupported size %d in %s"),
2928 size
, get_DW_OP_name (op
));
2934 /* Sign extend the operand. */
2935 ax_ext (expr
, addr_size_bits
);
2936 ax_simple (expr
, aop_dup
);
2937 ax_const_l (expr
, 0);
2938 ax_simple (expr
, aop_less_signed
);
2939 ax_simple (expr
, aop_log_not
);
2940 i
= ax_goto (expr
, aop_if_goto
);
2941 /* We have to emit 0 - X. */
2942 ax_const_l (expr
, 0);
2943 ax_simple (expr
, aop_swap
);
2944 ax_simple (expr
, aop_sub
);
2945 ax_label (expr
, i
, expr
->len
);
2949 /* No need to sign extend here. */
2950 ax_const_l (expr
, 0);
2951 ax_simple (expr
, aop_swap
);
2952 ax_simple (expr
, aop_sub
);
2956 /* Sign extend the operand. */
2957 ax_ext (expr
, addr_size_bits
);
2958 ax_simple (expr
, aop_bit_not
);
2961 case DW_OP_plus_uconst
:
2962 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2963 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2964 but we micro-optimize anyhow. */
2967 ax_const_l (expr
, reg
);
2968 ax_simple (expr
, aop_add
);
2973 ax_simple (expr
, aop_bit_and
);
2977 /* Sign extend the operands. */
2978 ax_ext (expr
, addr_size_bits
);
2979 ax_simple (expr
, aop_swap
);
2980 ax_ext (expr
, addr_size_bits
);
2981 ax_simple (expr
, aop_swap
);
2982 ax_simple (expr
, aop_div_signed
);
2986 ax_simple (expr
, aop_sub
);
2990 ax_simple (expr
, aop_rem_unsigned
);
2994 ax_simple (expr
, aop_mul
);
2998 ax_simple (expr
, aop_bit_or
);
3002 ax_simple (expr
, aop_add
);
3006 ax_simple (expr
, aop_lsh
);
3010 ax_simple (expr
, aop_rsh_unsigned
);
3014 ax_simple (expr
, aop_rsh_signed
);
3018 ax_simple (expr
, aop_bit_xor
);
3022 /* Sign extend the operands. */
3023 ax_ext (expr
, addr_size_bits
);
3024 ax_simple (expr
, aop_swap
);
3025 ax_ext (expr
, addr_size_bits
);
3026 /* Note no swap here: A <= B is !(B < A). */
3027 ax_simple (expr
, aop_less_signed
);
3028 ax_simple (expr
, aop_log_not
);
3032 /* Sign extend the operands. */
3033 ax_ext (expr
, addr_size_bits
);
3034 ax_simple (expr
, aop_swap
);
3035 ax_ext (expr
, addr_size_bits
);
3036 ax_simple (expr
, aop_swap
);
3037 /* A >= B is !(A < B). */
3038 ax_simple (expr
, aop_less_signed
);
3039 ax_simple (expr
, aop_log_not
);
3043 /* Sign extend the operands. */
3044 ax_ext (expr
, addr_size_bits
);
3045 ax_simple (expr
, aop_swap
);
3046 ax_ext (expr
, addr_size_bits
);
3047 /* No need for a second swap here. */
3048 ax_simple (expr
, aop_equal
);
3052 /* Sign extend the operands. */
3053 ax_ext (expr
, addr_size_bits
);
3054 ax_simple (expr
, aop_swap
);
3055 ax_ext (expr
, addr_size_bits
);
3056 ax_simple (expr
, aop_swap
);
3057 ax_simple (expr
, aop_less_signed
);
3061 /* Sign extend the operands. */
3062 ax_ext (expr
, addr_size_bits
);
3063 ax_simple (expr
, aop_swap
);
3064 ax_ext (expr
, addr_size_bits
);
3065 /* Note no swap here: A > B is B < A. */
3066 ax_simple (expr
, aop_less_signed
);
3070 /* Sign extend the operands. */
3071 ax_ext (expr
, addr_size_bits
);
3072 ax_simple (expr
, aop_swap
);
3073 ax_ext (expr
, addr_size_bits
);
3074 /* No need for a swap here. */
3075 ax_simple (expr
, aop_equal
);
3076 ax_simple (expr
, aop_log_not
);
3079 case DW_OP_call_frame_cfa
:
3080 dwarf2_compile_cfa_to_ax (expr
, loc
, arch
, expr
->scope
, per_cu
);
3081 loc
->kind
= axs_lvalue_memory
;
3084 case DW_OP_GNU_push_tls_address
:
3089 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3091 i
= ax_goto (expr
, aop_goto
);
3092 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3093 VEC_safe_push (int, patches
, i
);
3097 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3099 /* Zero extend the operand. */
3100 ax_zero_ext (expr
, addr_size_bits
);
3101 i
= ax_goto (expr
, aop_if_goto
);
3102 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3103 VEC_safe_push (int, patches
, i
);
3110 case DW_OP_bit_piece
:
3112 uint64_t size
, offset
;
3114 if (op_ptr
- 1 == previous_piece
)
3115 error (_("Cannot translate empty pieces to agent expressions"));
3116 previous_piece
= op_ptr
- 1;
3118 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3119 if (op
== DW_OP_piece
)
3125 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3127 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3128 error (_("Expression pieces exceed word size"));
3130 /* Access the bits. */
3133 case axs_lvalue_register
:
3134 ax_reg (expr
, loc
->u
.reg
);
3137 case axs_lvalue_memory
:
3138 /* Offset the pointer, if needed. */
3141 ax_const_l (expr
, offset
/ 8);
3142 ax_simple (expr
, aop_add
);
3145 access_memory (arch
, expr
, size
);
3149 /* For a bits-big-endian target, shift up what we already
3150 have. For a bits-little-endian target, shift up the
3151 new data. Note that there is a potential bug here if
3152 the DWARF expression leaves multiple values on the
3154 if (bits_collected
> 0)
3156 if (bits_big_endian
)
3158 ax_simple (expr
, aop_swap
);
3159 ax_const_l (expr
, size
);
3160 ax_simple (expr
, aop_lsh
);
3161 /* We don't need a second swap here, because
3162 aop_bit_or is symmetric. */
3166 ax_const_l (expr
, size
);
3167 ax_simple (expr
, aop_lsh
);
3169 ax_simple (expr
, aop_bit_or
);
3172 bits_collected
+= size
;
3173 loc
->kind
= axs_rvalue
;
3177 case DW_OP_GNU_uninit
:
3183 struct dwarf2_locexpr_baton block
;
3184 int size
= (op
== DW_OP_call2
? 2 : 4);
3187 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3190 offset
.cu_off
= uoffset
;
3191 block
= dwarf2_fetch_die_location_block (offset
, per_cu
,
3194 /* DW_OP_call_ref is currently not supported. */
3195 gdb_assert (block
.per_cu
== per_cu
);
3197 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3198 block
.data
, block
.data
+ block
.size
,
3203 case DW_OP_call_ref
:
3211 /* Patch all the branches we emitted. */
3212 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
3214 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
3216 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3217 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
3220 do_cleanups (cleanups
);
3224 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3225 evaluator to calculate the location. */
3226 static struct value
*
3227 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3229 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3232 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3233 dlbaton
->size
, dlbaton
->per_cu
);
3238 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3239 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3242 static struct value
*
3243 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3245 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3247 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3251 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3253 locexpr_read_needs_frame (struct symbol
*symbol
)
3255 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3257 return dwarf2_loc_desc_needs_frame (dlbaton
->data
, dlbaton
->size
,
3261 /* Return true if DATA points to the end of a piece. END is one past
3262 the last byte in the expression. */
3265 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3267 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3270 /* Helper for locexpr_describe_location_piece that finds the name of a
3274 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3278 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, dwarf_regnum
);
3279 return gdbarch_register_name (gdbarch
, regnum
);
3282 /* Nicely describe a single piece of a location, returning an updated
3283 position in the bytecode sequence. This function cannot recognize
3284 all locations; if a location is not recognized, it simply returns
3285 DATA. If there is an error during reading, e.g. we run off the end
3286 of the buffer, an error is thrown. */
3288 static const gdb_byte
*
3289 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3290 CORE_ADDR addr
, struct objfile
*objfile
,
3291 const gdb_byte
*data
, const gdb_byte
*end
,
3292 unsigned int addr_size
)
3294 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3296 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3298 fprintf_filtered (stream
, _("a variable in $%s"),
3299 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3302 else if (data
[0] == DW_OP_regx
)
3306 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3307 fprintf_filtered (stream
, _("a variable in $%s"),
3308 locexpr_regname (gdbarch
, reg
));
3310 else if (data
[0] == DW_OP_fbreg
)
3313 struct symbol
*framefunc
;
3315 int64_t frame_offset
;
3316 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3318 int64_t base_offset
= 0;
3320 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3321 if (!piece_end_p (new_data
, end
))
3325 b
= block_for_pc (addr
);
3328 error (_("No block found for address for symbol \"%s\"."),
3329 SYMBOL_PRINT_NAME (symbol
));
3331 framefunc
= block_linkage_function (b
);
3334 error (_("No function found for block for symbol \"%s\"."),
3335 SYMBOL_PRINT_NAME (symbol
));
3337 dwarf_expr_frame_base_1 (framefunc
, addr
, &base_data
, &base_size
);
3339 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3341 const gdb_byte
*buf_end
;
3343 frame_reg
= base_data
[0] - DW_OP_breg0
;
3344 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3346 if (buf_end
!= base_data
+ base_size
)
3347 error (_("Unexpected opcode after "
3348 "DW_OP_breg%u for symbol \"%s\"."),
3349 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3351 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3353 /* The frame base is just the register, with no offset. */
3354 frame_reg
= base_data
[0] - DW_OP_reg0
;
3359 /* We don't know what to do with the frame base expression,
3360 so we can't trace this variable; give up. */
3364 fprintf_filtered (stream
,
3365 _("a variable at frame base reg $%s offset %s+%s"),
3366 locexpr_regname (gdbarch
, frame_reg
),
3367 plongest (base_offset
), plongest (frame_offset
));
3369 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3370 && piece_end_p (data
, end
))
3374 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3376 fprintf_filtered (stream
,
3377 _("a variable at offset %s from base reg $%s"),
3379 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3382 /* The location expression for a TLS variable looks like this (on a
3385 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3386 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3388 0x3 is the encoding for DW_OP_addr, which has an operand as long
3389 as the size of an address on the target machine (here is 8
3390 bytes). Note that more recent version of GCC emit DW_OP_const4u
3391 or DW_OP_const8u, depending on address size, rather than
3392 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3393 The operand represents the offset at which the variable is within
3394 the thread local storage. */
3396 else if (data
+ 1 + addr_size
< end
3397 && (data
[0] == DW_OP_addr
3398 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3399 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3400 && data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3401 && piece_end_p (data
+ 2 + addr_size
, end
))
3404 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3405 gdbarch_byte_order (gdbarch
));
3407 fprintf_filtered (stream
,
3408 _("a thread-local variable at offset 0x%s "
3409 "in the thread-local storage for `%s'"),
3410 phex_nz (offset
, addr_size
), objfile
->name
);
3412 data
+= 1 + addr_size
+ 1;
3414 else if (data
[0] >= DW_OP_lit0
3415 && data
[0] <= DW_OP_lit31
3417 && data
[1] == DW_OP_stack_value
)
3419 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3426 /* Disassemble an expression, stopping at the end of a piece or at the
3427 end of the expression. Returns a pointer to the next unread byte
3428 in the input expression. If ALL is nonzero, then this function
3429 will keep going until it reaches the end of the expression.
3430 If there is an error during reading, e.g. we run off the end
3431 of the buffer, an error is thrown. */
3433 static const gdb_byte
*
3434 disassemble_dwarf_expression (struct ui_file
*stream
,
3435 struct gdbarch
*arch
, unsigned int addr_size
,
3436 int offset_size
, const gdb_byte
*start
,
3437 const gdb_byte
*data
, const gdb_byte
*end
,
3438 int indent
, int all
,
3439 struct dwarf2_per_cu_data
*per_cu
)
3443 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3445 enum dwarf_location_atom op
= *data
++;
3450 name
= get_DW_OP_name (op
);
3453 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3454 op
, (long) (data
- 1 - start
));
3455 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3456 (long) (data
- 1 - start
), name
);
3461 ul
= extract_unsigned_integer (data
, addr_size
,
3462 gdbarch_byte_order (arch
));
3464 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3468 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3470 fprintf_filtered (stream
, " %s", pulongest (ul
));
3473 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3475 fprintf_filtered (stream
, " %s", plongest (l
));
3478 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3480 fprintf_filtered (stream
, " %s", pulongest (ul
));
3483 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3485 fprintf_filtered (stream
, " %s", plongest (l
));
3488 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3490 fprintf_filtered (stream
, " %s", pulongest (ul
));
3493 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3495 fprintf_filtered (stream
, " %s", plongest (l
));
3498 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3500 fprintf_filtered (stream
, " %s", pulongest (ul
));
3503 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3505 fprintf_filtered (stream
, " %s", plongest (l
));
3508 data
= safe_read_uleb128 (data
, end
, &ul
);
3509 fprintf_filtered (stream
, " %s", pulongest (ul
));
3512 data
= safe_read_sleb128 (data
, end
, &l
);
3513 fprintf_filtered (stream
, " %s", plongest (l
));
3548 fprintf_filtered (stream
, " [$%s]",
3549 locexpr_regname (arch
, op
- DW_OP_reg0
));
3553 data
= safe_read_uleb128 (data
, end
, &ul
);
3554 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3555 locexpr_regname (arch
, (int) ul
));
3558 case DW_OP_implicit_value
:
3559 data
= safe_read_uleb128 (data
, end
, &ul
);
3561 fprintf_filtered (stream
, " %s", pulongest (ul
));
3596 data
= safe_read_sleb128 (data
, end
, &l
);
3597 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3598 locexpr_regname (arch
, op
- DW_OP_breg0
));
3602 data
= safe_read_uleb128 (data
, end
, &ul
);
3603 data
= safe_read_sleb128 (data
, end
, &l
);
3604 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3606 locexpr_regname (arch
, (int) ul
),
3611 data
= safe_read_sleb128 (data
, end
, &l
);
3612 fprintf_filtered (stream
, " %s", plongest (l
));
3615 case DW_OP_xderef_size
:
3616 case DW_OP_deref_size
:
3618 fprintf_filtered (stream
, " %d", *data
);
3622 case DW_OP_plus_uconst
:
3623 data
= safe_read_uleb128 (data
, end
, &ul
);
3624 fprintf_filtered (stream
, " %s", pulongest (ul
));
3628 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3630 fprintf_filtered (stream
, " to %ld",
3631 (long) (data
+ l
- start
));
3635 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3637 fprintf_filtered (stream
, " %ld",
3638 (long) (data
+ l
- start
));
3642 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3644 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3648 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3650 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3653 case DW_OP_call_ref
:
3654 ul
= extract_unsigned_integer (data
, offset_size
,
3655 gdbarch_byte_order (arch
));
3656 data
+= offset_size
;
3657 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3661 data
= safe_read_uleb128 (data
, end
, &ul
);
3662 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3665 case DW_OP_bit_piece
:
3669 data
= safe_read_uleb128 (data
, end
, &ul
);
3670 data
= safe_read_uleb128 (data
, end
, &offset
);
3671 fprintf_filtered (stream
, " size %s offset %s (bits)",
3672 pulongest (ul
), pulongest (offset
));
3676 case DW_OP_GNU_implicit_pointer
:
3678 ul
= extract_unsigned_integer (data
, offset_size
,
3679 gdbarch_byte_order (arch
));
3680 data
+= offset_size
;
3682 data
= safe_read_sleb128 (data
, end
, &l
);
3684 fprintf_filtered (stream
, " DIE %s offset %s",
3685 phex_nz (ul
, offset_size
),
3690 case DW_OP_GNU_deref_type
:
3692 int addr_size
= *data
++;
3696 data
= safe_read_uleb128 (data
, end
, &ul
);
3698 type
= dwarf2_get_die_type (offset
, per_cu
);
3699 fprintf_filtered (stream
, "<");
3700 type_print (type
, "", stream
, -1);
3701 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
.cu_off
, 0),
3706 case DW_OP_GNU_const_type
:
3711 data
= safe_read_uleb128 (data
, end
, &ul
);
3712 type_die
.cu_off
= ul
;
3713 type
= dwarf2_get_die_type (type_die
, per_cu
);
3714 fprintf_filtered (stream
, "<");
3715 type_print (type
, "", stream
, -1);
3716 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
3720 case DW_OP_GNU_regval_type
:
3726 data
= safe_read_uleb128 (data
, end
, ®
);
3727 data
= safe_read_uleb128 (data
, end
, &ul
);
3728 type_die
.cu_off
= ul
;
3730 type
= dwarf2_get_die_type (type_die
, per_cu
);
3731 fprintf_filtered (stream
, "<");
3732 type_print (type
, "", stream
, -1);
3733 fprintf_filtered (stream
, " [0x%s]> [$%s]",
3734 phex_nz (type_die
.cu_off
, 0),
3735 locexpr_regname (arch
, reg
));
3739 case DW_OP_GNU_convert
:
3740 case DW_OP_GNU_reinterpret
:
3744 data
= safe_read_uleb128 (data
, end
, &ul
);
3745 type_die
.cu_off
= ul
;
3747 if (type_die
.cu_off
== 0)
3748 fprintf_filtered (stream
, "<0>");
3753 type
= dwarf2_get_die_type (type_die
, per_cu
);
3754 fprintf_filtered (stream
, "<");
3755 type_print (type
, "", stream
, -1);
3756 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
3761 case DW_OP_GNU_entry_value
:
3762 data
= safe_read_uleb128 (data
, end
, &ul
);
3763 fputc_filtered ('\n', stream
);
3764 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3765 start
, data
, data
+ ul
, indent
+ 2,
3771 fprintf_filtered (stream
, "\n");
3777 /* Describe a single location, which may in turn consist of multiple
3781 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3782 struct ui_file
*stream
,
3783 const gdb_byte
*data
, int size
,
3784 struct objfile
*objfile
, unsigned int addr_size
,
3785 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
3787 const gdb_byte
*end
= data
+ size
;
3788 int first_piece
= 1, bad
= 0;
3792 const gdb_byte
*here
= data
;
3793 int disassemble
= 1;
3798 fprintf_filtered (stream
, _(", and "));
3800 if (!dwarf2_always_disassemble
)
3802 data
= locexpr_describe_location_piece (symbol
, stream
,
3804 data
, end
, addr_size
);
3805 /* If we printed anything, or if we have an empty piece,
3806 then don't disassemble. */
3808 || data
[0] == DW_OP_piece
3809 || data
[0] == DW_OP_bit_piece
)
3814 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3815 data
= disassemble_dwarf_expression (stream
,
3816 get_objfile_arch (objfile
),
3817 addr_size
, offset_size
, data
,
3819 dwarf2_always_disassemble
,
3825 int empty
= data
== here
;
3828 fprintf_filtered (stream
, " ");
3829 if (data
[0] == DW_OP_piece
)
3833 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3836 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3839 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3842 else if (data
[0] == DW_OP_bit_piece
)
3844 uint64_t bits
, offset
;
3846 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3847 data
= safe_read_uleb128 (data
, end
, &offset
);
3850 fprintf_filtered (stream
,
3851 _("an empty %s-bit piece"),
3854 fprintf_filtered (stream
,
3855 _(" [%s-bit piece, offset %s bits]"),
3856 pulongest (bits
), pulongest (offset
));
3866 if (bad
|| data
> end
)
3867 error (_("Corrupted DWARF2 expression for \"%s\"."),
3868 SYMBOL_PRINT_NAME (symbol
));
3871 /* Print a natural-language description of SYMBOL to STREAM. This
3872 version is for a symbol with a single location. */
3875 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3876 struct ui_file
*stream
)
3878 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3879 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
3880 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3881 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
3883 locexpr_describe_location_1 (symbol
, addr
, stream
,
3884 dlbaton
->data
, dlbaton
->size
,
3885 objfile
, addr_size
, offset_size
,
3889 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3890 any necessary bytecode in AX. */
3893 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
3894 struct agent_expr
*ax
, struct axs_value
*value
)
3896 struct dwarf2_locexpr_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3897 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3899 if (dlbaton
->size
== 0)
3900 value
->optimized_out
= 1;
3902 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
3903 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3907 /* The set of location functions used with the DWARF-2 expression
3909 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3910 locexpr_read_variable
,
3911 locexpr_read_variable_at_entry
,
3912 locexpr_read_needs_frame
,
3913 locexpr_describe_location
,
3914 locexpr_tracepoint_var_ref
3918 /* Wrapper functions for location lists. These generally find
3919 the appropriate location expression and call something above. */
3921 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3922 evaluator to calculate the location. */
3923 static struct value
*
3924 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3926 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3928 const gdb_byte
*data
;
3930 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3932 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3933 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
3939 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3940 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3943 Function always returns non-NULL value, it may be marked optimized out if
3944 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3945 if it cannot resolve the parameter for any reason. */
3947 static struct value
*
3948 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3950 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3951 const gdb_byte
*data
;
3955 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3956 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
3958 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3960 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
3962 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
3965 /* Return non-zero iff we need a frame to evaluate SYMBOL. */
3967 loclist_read_needs_frame (struct symbol
*symbol
)
3969 /* If there's a location list, then assume we need to have a frame
3970 to choose the appropriate location expression. With tracking of
3971 global variables this is not necessarily true, but such tracking
3972 is disabled in GCC at the moment until we figure out how to
3978 /* Print a natural-language description of SYMBOL to STREAM. This
3979 version applies when there is a list of different locations, each
3980 with a specified address range. */
3983 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3984 struct ui_file
*stream
)
3986 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
3987 const gdb_byte
*loc_ptr
, *buf_end
;
3989 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
3990 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3991 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3992 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
3993 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
3994 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3995 /* Adjust base_address for relocatable objects. */
3996 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
3997 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4000 loc_ptr
= dlbaton
->data
;
4001 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4003 fprintf_filtered (stream
, _("multi-location:\n"));
4005 /* Iterate through locations until we run out. */
4008 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4010 enum debug_loc_kind kind
;
4011 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4013 if (dlbaton
->from_dwo
)
4014 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4015 loc_ptr
, buf_end
, &new_ptr
,
4016 &low
, &high
, byte_order
);
4018 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4020 byte_order
, addr_size
,
4025 case DEBUG_LOC_END_OF_LIST
:
4028 case DEBUG_LOC_BASE_ADDRESS
:
4029 base_address
= high
+ base_offset
;
4030 fprintf_filtered (stream
, _(" Base address %s"),
4031 paddress (gdbarch
, base_address
));
4033 case DEBUG_LOC_START_END
:
4034 case DEBUG_LOC_START_LENGTH
:
4036 case DEBUG_LOC_BUFFER_OVERFLOW
:
4037 case DEBUG_LOC_INVALID_ENTRY
:
4038 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4039 SYMBOL_PRINT_NAME (symbol
));
4041 gdb_assert_not_reached ("bad debug_loc_kind");
4044 /* Otherwise, a location expression entry. */
4045 low
+= base_address
;
4046 high
+= base_address
;
4048 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4051 /* (It would improve readability to print only the minimum
4052 necessary digits of the second number of the range.) */
4053 fprintf_filtered (stream
, _(" Range %s-%s: "),
4054 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4056 /* Now describe this particular location. */
4057 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4058 objfile
, addr_size
, offset_size
,
4061 fprintf_filtered (stream
, "\n");
4067 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4068 any necessary bytecode in AX. */
4070 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4071 struct agent_expr
*ax
, struct axs_value
*value
)
4073 struct dwarf2_loclist_baton
*dlbaton
= SYMBOL_LOCATION_BATON (symbol
);
4074 const gdb_byte
*data
;
4076 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4078 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4080 value
->optimized_out
= 1;
4082 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4086 /* The set of location functions used with the DWARF-2 expression
4087 evaluator and location lists. */
4088 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4089 loclist_read_variable
,
4090 loclist_read_variable_at_entry
,
4091 loclist_read_needs_frame
,
4092 loclist_describe_location
,
4093 loclist_tracepoint_var_ref
4096 /* Provide a prototype to silence -Wmissing-prototypes. */
4097 extern initialize_file_ftype _initialize_dwarf2loc
;
4100 _initialize_dwarf2loc (void)
4102 add_setshow_zinteger_cmd ("entry-values", class_maintenance
,
4103 &entry_values_debug
,
4104 _("Set entry values and tail call frames "
4106 _("Show entry values and tail call frames "
4108 _("When non-zero, the process of determining "
4109 "parameter values from function entry point "
4110 "and tail call frames will be printed."),
4112 show_entry_values_debug
,
4113 &setdebuglist
, &showdebuglist
);