1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2016 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/>. */
35 #include "complaints.h"
37 #include "dwarf2expr.h"
38 #include "dwarf2loc.h"
39 #include "dwarf2-frame.h"
40 #include "compile/compile.h"
42 extern int dwarf_always_disassemble
;
44 extern const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
;
46 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
47 struct frame_info
*frame
,
50 struct dwarf2_per_cu_data
*per_cu
,
53 /* Until these have formal names, we define these here.
54 ref: http://gcc.gnu.org/wiki/DebugFission
55 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
56 and is then followed by data specific to that entry. */
60 /* Indicates the end of the list of entries. */
61 DEBUG_LOC_END_OF_LIST
= 0,
63 /* This is followed by an unsigned LEB128 number that is an index into
64 .debug_addr and specifies the base address for all following entries. */
65 DEBUG_LOC_BASE_ADDRESS
= 1,
67 /* This is followed by two unsigned LEB128 numbers that are indices into
68 .debug_addr and specify the beginning and ending addresses, and then
69 a normal location expression as in .debug_loc. */
70 DEBUG_LOC_START_END
= 2,
72 /* This is followed by an unsigned LEB128 number that is an index into
73 .debug_addr and specifies the beginning address, and a 4 byte unsigned
74 number that specifies the length, and then a normal location expression
76 DEBUG_LOC_START_LENGTH
= 3,
78 /* An internal value indicating there is insufficient data. */
79 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
81 /* An internal value indicating an invalid kind of entry was found. */
82 DEBUG_LOC_INVALID_ENTRY
= -2
85 /* Helper function which throws an error if a synthetic pointer is
89 invalid_synthetic_pointer (void)
91 error (_("access outside bounds of object "
92 "referenced via synthetic pointer"));
95 /* Decode the addresses in a non-dwo .debug_loc entry.
96 A pointer to the next byte to examine is returned in *NEW_PTR.
97 The encoded low,high addresses are return in *LOW,*HIGH.
98 The result indicates the kind of entry found. */
100 static enum debug_loc_kind
101 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
102 const gdb_byte
**new_ptr
,
103 CORE_ADDR
*low
, CORE_ADDR
*high
,
104 enum bfd_endian byte_order
,
105 unsigned int addr_size
,
108 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
110 if (buf_end
- loc_ptr
< 2 * addr_size
)
111 return DEBUG_LOC_BUFFER_OVERFLOW
;
114 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
116 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
117 loc_ptr
+= addr_size
;
120 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
122 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
123 loc_ptr
+= addr_size
;
127 /* A base-address-selection entry. */
128 if ((*low
& base_mask
) == base_mask
)
129 return DEBUG_LOC_BASE_ADDRESS
;
131 /* An end-of-list entry. */
132 if (*low
== 0 && *high
== 0)
133 return DEBUG_LOC_END_OF_LIST
;
135 return DEBUG_LOC_START_END
;
138 /* Decode the addresses in .debug_loc.dwo entry.
139 A pointer to the next byte to examine is returned in *NEW_PTR.
140 The encoded low,high addresses are return in *LOW,*HIGH.
141 The result indicates the kind of entry found. */
143 static enum debug_loc_kind
144 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
145 const gdb_byte
*loc_ptr
,
146 const gdb_byte
*buf_end
,
147 const gdb_byte
**new_ptr
,
148 CORE_ADDR
*low
, CORE_ADDR
*high
,
149 enum bfd_endian byte_order
)
151 uint64_t low_index
, high_index
;
153 if (loc_ptr
== buf_end
)
154 return DEBUG_LOC_BUFFER_OVERFLOW
;
158 case DEBUG_LOC_END_OF_LIST
:
160 return DEBUG_LOC_END_OF_LIST
;
161 case DEBUG_LOC_BASE_ADDRESS
:
163 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
165 return DEBUG_LOC_BUFFER_OVERFLOW
;
166 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
168 return DEBUG_LOC_BASE_ADDRESS
;
169 case DEBUG_LOC_START_END
:
170 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
172 return DEBUG_LOC_BUFFER_OVERFLOW
;
173 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
174 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
176 return DEBUG_LOC_BUFFER_OVERFLOW
;
177 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
179 return DEBUG_LOC_START_END
;
180 case DEBUG_LOC_START_LENGTH
:
181 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
183 return DEBUG_LOC_BUFFER_OVERFLOW
;
184 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
185 if (loc_ptr
+ 4 > buf_end
)
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
189 *new_ptr
= loc_ptr
+ 4;
190 return DEBUG_LOC_START_LENGTH
;
192 return DEBUG_LOC_INVALID_ENTRY
;
196 /* A function for dealing with location lists. Given a
197 symbol baton (BATON) and a pc value (PC), find the appropriate
198 location expression, set *LOCEXPR_LENGTH, and return a pointer
199 to the beginning of the expression. Returns NULL on failure.
201 For now, only return the first matching location expression; there
202 can be more than one in the list. */
205 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
206 size_t *locexpr_length
, CORE_ADDR pc
)
208 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
209 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
210 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
211 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
212 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
213 /* Adjust base_address for relocatable objects. */
214 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
215 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
216 const gdb_byte
*loc_ptr
, *buf_end
;
218 loc_ptr
= baton
->data
;
219 buf_end
= baton
->data
+ baton
->size
;
223 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
225 enum debug_loc_kind kind
;
226 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
229 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
230 loc_ptr
, buf_end
, &new_ptr
,
231 &low
, &high
, byte_order
);
233 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
235 byte_order
, addr_size
,
240 case DEBUG_LOC_END_OF_LIST
:
243 case DEBUG_LOC_BASE_ADDRESS
:
244 base_address
= high
+ base_offset
;
246 case DEBUG_LOC_START_END
:
247 case DEBUG_LOC_START_LENGTH
:
249 case DEBUG_LOC_BUFFER_OVERFLOW
:
250 case DEBUG_LOC_INVALID_ENTRY
:
251 error (_("dwarf2_find_location_expression: "
252 "Corrupted DWARF expression."));
254 gdb_assert_not_reached ("bad debug_loc_kind");
257 /* Otherwise, a location expression entry.
258 If the entry is from a DWO, don't add base address: the entry is from
259 .debug_addr which already has the DWARF "base address". We still add
260 base_offset in case we're debugging a PIE executable. */
269 high
+= base_address
;
272 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
275 if (low
== high
&& pc
== low
)
277 /* This is entry PC record present only at entry point
278 of a function. Verify it is really the function entry point. */
280 const struct block
*pc_block
= block_for_pc (pc
);
281 struct symbol
*pc_func
= NULL
;
284 pc_func
= block_linkage_function (pc_block
);
286 if (pc_func
&& pc
== BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func
)))
288 *locexpr_length
= length
;
293 if (pc
>= low
&& pc
< high
)
295 *locexpr_length
= length
;
303 /* This is the baton used when performing dwarf2 expression
305 struct dwarf_expr_baton
307 struct frame_info
*frame
;
308 struct dwarf2_per_cu_data
*per_cu
;
309 CORE_ADDR obj_address
;
312 /* Helper functions for dwarf2_evaluate_loc_desc. */
314 /* Using the frame specified in BATON, return the value of register
315 REGNUM, treated as a pointer. */
317 dwarf_expr_read_addr_from_reg (void *baton
, int dwarf_regnum
)
319 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
320 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
321 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
323 return address_from_register (regnum
, debaton
->frame
);
326 /* Implement struct dwarf_expr_context_funcs' "get_reg_value" callback. */
328 static struct value
*
329 dwarf_expr_get_reg_value (void *baton
, struct type
*type
, int dwarf_regnum
)
331 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
332 struct gdbarch
*gdbarch
= get_frame_arch (debaton
->frame
);
333 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
335 return value_from_register (type
, regnum
, debaton
->frame
);
338 /* Read memory at ADDR (length LEN) into BUF. */
341 dwarf_expr_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
343 read_memory (addr
, buf
, len
);
346 /* Using the frame specified in BATON, find the location expression
347 describing the frame base. Return a pointer to it in START and
348 its length in LENGTH. */
350 dwarf_expr_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
352 /* FIXME: cagney/2003-03-26: This code should be using
353 get_frame_base_address(), and then implement a dwarf2 specific
355 struct symbol
*framefunc
;
356 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
357 const struct block
*bl
= get_frame_block (debaton
->frame
, NULL
);
360 error (_("frame address is not available."));
362 /* Use block_linkage_function, which returns a real (not inlined)
363 function, instead of get_frame_function, which may return an
365 framefunc
= block_linkage_function (bl
);
367 /* If we found a frame-relative symbol then it was certainly within
368 some function associated with a frame. If we can't find the frame,
369 something has gone wrong. */
370 gdb_assert (framefunc
!= NULL
);
372 func_get_frame_base_dwarf_block (framefunc
,
373 get_frame_address_in_block (debaton
->frame
),
377 /* Implement find_frame_base_location method for LOC_BLOCK functions using
378 DWARF expression for its DW_AT_frame_base. */
381 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
382 const gdb_byte
**start
, size_t *length
)
384 struct dwarf2_locexpr_baton
*symbaton
385 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
387 *length
= symbaton
->size
;
388 *start
= symbaton
->data
;
391 /* Implement the struct symbol_block_ops::get_frame_base method for
392 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
395 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
397 struct gdbarch
*gdbarch
;
399 struct dwarf2_locexpr_baton
*dlbaton
;
400 const gdb_byte
*start
;
402 struct value
*result
;
404 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
405 Thus, it's supposed to provide the find_frame_base_location method as
407 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
409 gdbarch
= get_frame_arch (frame
);
410 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
411 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
413 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
414 (framefunc
, get_frame_pc (frame
), &start
, &length
);
415 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
418 /* The DW_AT_frame_base attribute contains a location description which
419 computes the base address itself. However, the call to
420 dwarf2_evaluate_loc_desc returns a value representing a variable at
421 that address. The frame base address is thus this variable's
423 return value_address (result
);
426 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
427 function uses DWARF expression for its DW_AT_frame_base. */
429 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
431 locexpr_find_frame_base_location
,
432 locexpr_get_frame_base
435 /* Implement find_frame_base_location method for LOC_BLOCK functions using
436 DWARF location list for its DW_AT_frame_base. */
439 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
440 const gdb_byte
**start
, size_t *length
)
442 struct dwarf2_loclist_baton
*symbaton
443 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
445 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
448 /* Implement the struct symbol_block_ops::get_frame_base method for
449 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
452 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
454 struct gdbarch
*gdbarch
;
456 struct dwarf2_loclist_baton
*dlbaton
;
457 const gdb_byte
*start
;
459 struct value
*result
;
461 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
462 Thus, it's supposed to provide the find_frame_base_location method as
464 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
466 gdbarch
= get_frame_arch (frame
);
467 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
468 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
470 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
471 (framefunc
, get_frame_pc (frame
), &start
, &length
);
472 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
475 /* The DW_AT_frame_base attribute contains a location description which
476 computes the base address itself. However, the call to
477 dwarf2_evaluate_loc_desc returns a value representing a variable at
478 that address. The frame base address is thus this variable's
480 return value_address (result
);
483 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
484 function uses DWARF location list for its DW_AT_frame_base. */
486 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
488 loclist_find_frame_base_location
,
489 loclist_get_frame_base
492 /* See dwarf2loc.h. */
495 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
496 const gdb_byte
**start
, size_t *length
)
498 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
500 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
502 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
508 error (_("Could not find the frame base for \"%s\"."),
509 SYMBOL_NATURAL_NAME (framefunc
));
512 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
513 the frame in BATON. */
516 dwarf_expr_frame_cfa (void *baton
)
518 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
520 return dwarf2_frame_cfa (debaton
->frame
);
523 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
524 the frame in BATON. */
527 dwarf_expr_frame_pc (void *baton
)
529 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
531 return get_frame_address_in_block (debaton
->frame
);
534 /* Using the objfile specified in BATON, find the address for the
535 current thread's thread-local storage with offset OFFSET. */
537 dwarf_expr_tls_address (void *baton
, CORE_ADDR offset
)
539 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
540 struct objfile
*objfile
= dwarf2_per_cu_objfile (debaton
->per_cu
);
542 return target_translate_tls_address (objfile
, offset
);
545 /* Call DWARF subroutine from DW_AT_location of DIE at DIE_OFFSET in
546 current CU (as is PER_CU). State of the CTX is not affected by the
550 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
551 struct dwarf2_per_cu_data
*per_cu
,
552 CORE_ADDR (*get_frame_pc
) (void *baton
),
555 struct dwarf2_locexpr_baton block
;
557 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, get_frame_pc
, baton
);
559 /* DW_OP_call_ref is currently not supported. */
560 gdb_assert (block
.per_cu
== per_cu
);
562 dwarf_expr_eval (ctx
, block
.data
, block
.size
);
565 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc. */
568 dwarf_expr_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
570 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) ctx
->baton
;
572 per_cu_dwarf_call (ctx
, die_offset
, debaton
->per_cu
,
573 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
576 /* Callback function for dwarf2_evaluate_loc_desc. */
579 dwarf_expr_get_base_type (struct dwarf_expr_context
*ctx
,
580 cu_offset die_offset
)
582 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) ctx
->baton
;
584 return dwarf2_get_die_type (die_offset
, debaton
->per_cu
);
587 /* See dwarf2loc.h. */
589 unsigned int entry_values_debug
= 0;
591 /* Helper to set entry_values_debug. */
594 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
595 struct cmd_list_element
*c
, const char *value
)
597 fprintf_filtered (file
,
598 _("Entry values and tail call frames debugging is %s.\n"),
602 /* Find DW_TAG_GNU_call_site's DW_AT_GNU_call_site_target address.
603 CALLER_FRAME (for registers) can be NULL if it is not known. This function
604 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
607 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
608 struct call_site
*call_site
,
609 struct frame_info
*caller_frame
)
611 switch (FIELD_LOC_KIND (call_site
->target
))
613 case FIELD_LOC_KIND_DWARF_BLOCK
:
615 struct dwarf2_locexpr_baton
*dwarf_block
;
617 struct type
*caller_core_addr_type
;
618 struct gdbarch
*caller_arch
;
620 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
621 if (dwarf_block
== NULL
)
623 struct bound_minimal_symbol msym
;
625 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
626 throw_error (NO_ENTRY_VALUE_ERROR
,
627 _("DW_AT_GNU_call_site_target is not specified "
629 paddress (call_site_gdbarch
, call_site
->pc
),
630 (msym
.minsym
== NULL
? "???"
631 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
634 if (caller_frame
== NULL
)
636 struct bound_minimal_symbol msym
;
638 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
639 throw_error (NO_ENTRY_VALUE_ERROR
,
640 _("DW_AT_GNU_call_site_target DWARF block resolving "
641 "requires known frame which is currently not "
642 "available at %s in %s"),
643 paddress (call_site_gdbarch
, call_site
->pc
),
644 (msym
.minsym
== NULL
? "???"
645 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
648 caller_arch
= get_frame_arch (caller_frame
);
649 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
650 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
651 dwarf_block
->data
, dwarf_block
->size
,
652 dwarf_block
->per_cu
);
653 /* DW_AT_GNU_call_site_target is a DWARF expression, not a DWARF
655 if (VALUE_LVAL (val
) == lval_memory
)
656 return value_address (val
);
658 return value_as_address (val
);
661 case FIELD_LOC_KIND_PHYSNAME
:
663 const char *physname
;
664 struct bound_minimal_symbol msym
;
666 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
668 /* Handle both the mangled and demangled PHYSNAME. */
669 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
670 if (msym
.minsym
== NULL
)
672 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
673 throw_error (NO_ENTRY_VALUE_ERROR
,
674 _("Cannot find function \"%s\" for a call site target "
676 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
677 (msym
.minsym
== NULL
? "???"
678 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
681 return BMSYMBOL_VALUE_ADDRESS (msym
);
684 case FIELD_LOC_KIND_PHYSADDR
:
685 return FIELD_STATIC_PHYSADDR (call_site
->target
);
688 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
692 /* Convert function entry point exact address ADDR to the function which is
693 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
694 NO_ENTRY_VALUE_ERROR otherwise. */
696 static struct symbol
*
697 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
699 struct symbol
*sym
= find_pc_function (addr
);
702 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
703 throw_error (NO_ENTRY_VALUE_ERROR
,
704 _("DW_TAG_GNU_call_site resolving failed to find function "
705 "name for address %s"),
706 paddress (gdbarch
, addr
));
708 type
= SYMBOL_TYPE (sym
);
709 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
710 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
715 /* Verify function with entry point exact address ADDR can never call itself
716 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
717 can call itself via tail calls.
719 If a funtion can tail call itself its entry value based parameters are
720 unreliable. There is no verification whether the value of some/all
721 parameters is unchanged through the self tail call, we expect if there is
722 a self tail call all the parameters can be modified. */
725 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
727 struct obstack addr_obstack
;
728 struct cleanup
*old_chain
;
731 /* Track here CORE_ADDRs which were already visited. */
734 /* The verification is completely unordered. Track here function addresses
735 which still need to be iterated. */
736 VEC (CORE_ADDR
) *todo
= NULL
;
738 obstack_init (&addr_obstack
);
739 old_chain
= make_cleanup_obstack_free (&addr_obstack
);
740 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
741 &addr_obstack
, hashtab_obstack_allocate
,
743 make_cleanup_htab_delete (addr_hash
);
745 make_cleanup (VEC_cleanup (CORE_ADDR
), &todo
);
747 VEC_safe_push (CORE_ADDR
, todo
, verify_addr
);
748 while (!VEC_empty (CORE_ADDR
, todo
))
750 struct symbol
*func_sym
;
751 struct call_site
*call_site
;
753 addr
= VEC_pop (CORE_ADDR
, todo
);
755 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
757 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
758 call_site
; call_site
= call_site
->tail_call_next
)
760 CORE_ADDR target_addr
;
763 /* CALLER_FRAME with registers is not available for tail-call jumped
765 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
767 if (target_addr
== verify_addr
)
769 struct bound_minimal_symbol msym
;
771 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
772 throw_error (NO_ENTRY_VALUE_ERROR
,
773 _("DW_OP_GNU_entry_value resolving has found "
774 "function \"%s\" at %s can call itself via tail "
776 (msym
.minsym
== NULL
? "???"
777 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
778 paddress (gdbarch
, verify_addr
));
781 slot
= htab_find_slot (addr_hash
, &target_addr
, INSERT
);
784 *slot
= obstack_copy (&addr_obstack
, &target_addr
,
785 sizeof (target_addr
));
786 VEC_safe_push (CORE_ADDR
, todo
, target_addr
);
791 do_cleanups (old_chain
);
794 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
795 ENTRY_VALUES_DEBUG. */
798 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
800 CORE_ADDR addr
= call_site
->pc
;
801 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
803 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
804 (msym
.minsym
== NULL
? "???"
805 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
809 /* vec.h needs single word type name, typedef it. */
810 typedef struct call_site
*call_sitep
;
812 /* Define VEC (call_sitep) functions. */
813 DEF_VEC_P (call_sitep
);
815 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
816 only top callers and bottom callees which are present in both. GDBARCH is
817 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
818 no remaining possibilities to provide unambiguous non-trivial result.
819 RESULTP should point to NULL on the first (initialization) call. Caller is
820 responsible for xfree of any RESULTP data. */
823 chain_candidate (struct gdbarch
*gdbarch
, struct call_site_chain
**resultp
,
824 VEC (call_sitep
) *chain
)
826 struct call_site_chain
*result
= *resultp
;
827 long length
= VEC_length (call_sitep
, chain
);
828 int callers
, callees
, idx
;
832 /* Create the initial chain containing all the passed PCs. */
834 result
= ((struct call_site_chain
*)
835 xmalloc (sizeof (*result
)
836 + sizeof (*result
->call_site
) * (length
- 1)));
837 result
->length
= length
;
838 result
->callers
= result
->callees
= length
;
839 if (!VEC_empty (call_sitep
, chain
))
840 memcpy (result
->call_site
, VEC_address (call_sitep
, chain
),
841 sizeof (*result
->call_site
) * length
);
844 if (entry_values_debug
)
846 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
847 for (idx
= 0; idx
< length
; idx
++)
848 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
849 fputc_unfiltered ('\n', gdb_stdlog
);
855 if (entry_values_debug
)
857 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
858 for (idx
= 0; idx
< length
; idx
++)
859 tailcall_dump (gdbarch
, VEC_index (call_sitep
, chain
, idx
));
860 fputc_unfiltered ('\n', gdb_stdlog
);
863 /* Intersect callers. */
865 callers
= min (result
->callers
, length
);
866 for (idx
= 0; idx
< callers
; idx
++)
867 if (result
->call_site
[idx
] != VEC_index (call_sitep
, chain
, idx
))
869 result
->callers
= idx
;
873 /* Intersect callees. */
875 callees
= min (result
->callees
, length
);
876 for (idx
= 0; idx
< callees
; idx
++)
877 if (result
->call_site
[result
->length
- 1 - idx
]
878 != VEC_index (call_sitep
, chain
, length
- 1 - idx
))
880 result
->callees
= idx
;
884 if (entry_values_debug
)
886 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
887 for (idx
= 0; idx
< result
->callers
; idx
++)
888 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
889 fputs_unfiltered (" |", gdb_stdlog
);
890 for (idx
= 0; idx
< result
->callees
; idx
++)
891 tailcall_dump (gdbarch
, result
->call_site
[result
->length
892 - result
->callees
+ idx
]);
893 fputc_unfiltered ('\n', gdb_stdlog
);
896 if (result
->callers
== 0 && result
->callees
== 0)
898 /* There are no common callers or callees. It could be also a direct
899 call (which has length 0) with ambiguous possibility of an indirect
900 call - CALLERS == CALLEES == 0 is valid during the first allocation
901 but any subsequence processing of such entry means ambiguity. */
907 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
908 PC again. In such case there must be two different code paths to reach
909 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
910 gdb_assert (result
->callers
+ result
->callees
<= result
->length
);
913 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
914 assumed frames between them use GDBARCH. Use depth first search so we can
915 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
916 would have needless GDB stack overhead. Caller is responsible for xfree of
917 the returned result. Any unreliability results in thrown
918 NO_ENTRY_VALUE_ERROR. */
920 static struct call_site_chain
*
921 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
924 CORE_ADDR save_callee_pc
= callee_pc
;
925 struct obstack addr_obstack
;
926 struct cleanup
*back_to_retval
, *back_to_workdata
;
927 struct call_site_chain
*retval
= NULL
;
928 struct call_site
*call_site
;
930 /* Mark CALL_SITEs so we do not visit the same ones twice. */
933 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
934 call_site nor any possible call_site at CALLEE_PC's function is there.
935 Any CALL_SITE in CHAIN will be iterated to its siblings - via
936 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
937 VEC (call_sitep
) *chain
= NULL
;
939 /* We are not interested in the specific PC inside the callee function. */
940 callee_pc
= get_pc_function_start (callee_pc
);
942 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
943 paddress (gdbarch
, save_callee_pc
));
945 back_to_retval
= make_cleanup (free_current_contents
, &retval
);
947 obstack_init (&addr_obstack
);
948 back_to_workdata
= make_cleanup_obstack_free (&addr_obstack
);
949 addr_hash
= htab_create_alloc_ex (64, core_addr_hash
, core_addr_eq
, NULL
,
950 &addr_obstack
, hashtab_obstack_allocate
,
952 make_cleanup_htab_delete (addr_hash
);
954 make_cleanup (VEC_cleanup (call_sitep
), &chain
);
956 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
957 at the target's function. All the possible tail call sites in the
958 target's function will get iterated as already pushed into CHAIN via their
960 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
964 CORE_ADDR target_func_addr
;
965 struct call_site
*target_call_site
;
967 /* CALLER_FRAME with registers is not available for tail-call jumped
969 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
971 if (target_func_addr
== callee_pc
)
973 chain_candidate (gdbarch
, &retval
, chain
);
977 /* There is no way to reach CALLEE_PC again as we would prevent
978 entering it twice as being already marked in ADDR_HASH. */
979 target_call_site
= NULL
;
983 struct symbol
*target_func
;
985 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
986 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
991 /* Attempt to visit TARGET_CALL_SITE. */
993 if (target_call_site
)
997 slot
= htab_find_slot (addr_hash
, &target_call_site
->pc
, INSERT
);
1000 /* Successfully entered TARGET_CALL_SITE. */
1002 *slot
= &target_call_site
->pc
;
1003 VEC_safe_push (call_sitep
, chain
, target_call_site
);
1008 /* Backtrack (without revisiting the originating call_site). Try the
1009 callers's sibling; if there isn't any try the callers's callers's
1012 target_call_site
= NULL
;
1013 while (!VEC_empty (call_sitep
, chain
))
1015 call_site
= VEC_pop (call_sitep
, chain
);
1017 gdb_assert (htab_find_slot (addr_hash
, &call_site
->pc
,
1018 NO_INSERT
) != NULL
);
1019 htab_remove_elt (addr_hash
, &call_site
->pc
);
1021 target_call_site
= call_site
->tail_call_next
;
1022 if (target_call_site
)
1026 while (target_call_site
);
1028 if (VEC_empty (call_sitep
, chain
))
1031 call_site
= VEC_last (call_sitep
, chain
);
1036 struct bound_minimal_symbol msym_caller
, msym_callee
;
1038 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1039 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1040 throw_error (NO_ENTRY_VALUE_ERROR
,
1041 _("There are no unambiguously determinable intermediate "
1042 "callers or callees between caller function \"%s\" at %s "
1043 "and callee function \"%s\" at %s"),
1044 (msym_caller
.minsym
== NULL
1045 ? "???" : MSYMBOL_PRINT_NAME (msym_caller
.minsym
)),
1046 paddress (gdbarch
, caller_pc
),
1047 (msym_callee
.minsym
== NULL
1048 ? "???" : MSYMBOL_PRINT_NAME (msym_callee
.minsym
)),
1049 paddress (gdbarch
, callee_pc
));
1052 do_cleanups (back_to_workdata
);
1053 discard_cleanups (back_to_retval
);
1057 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1058 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1059 constructed return NULL. Caller is responsible for xfree of the returned
1062 struct call_site_chain
*
1063 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1064 CORE_ADDR callee_pc
)
1066 struct call_site_chain
*retval
= NULL
;
1070 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1072 CATCH (e
, RETURN_MASK_ERROR
)
1074 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1076 if (entry_values_debug
)
1077 exception_print (gdb_stdout
, e
);
1082 throw_exception (e
);
1089 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1092 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1093 enum call_site_parameter_kind kind
,
1094 union call_site_parameter_u kind_u
)
1096 if (kind
== parameter
->kind
)
1099 case CALL_SITE_PARAMETER_DWARF_REG
:
1100 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1101 case CALL_SITE_PARAMETER_FB_OFFSET
:
1102 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1103 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1104 return kind_u
.param_offset
.cu_off
== parameter
->u
.param_offset
.cu_off
;
1109 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1110 FRAME is for callee.
1112 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1115 static struct call_site_parameter
*
1116 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1117 enum call_site_parameter_kind kind
,
1118 union call_site_parameter_u kind_u
,
1119 struct dwarf2_per_cu_data
**per_cu_return
)
1121 CORE_ADDR func_addr
, caller_pc
;
1122 struct gdbarch
*gdbarch
;
1123 struct frame_info
*caller_frame
;
1124 struct call_site
*call_site
;
1126 /* Initialize it just to avoid a GCC false warning. */
1127 struct call_site_parameter
*parameter
= NULL
;
1128 CORE_ADDR target_addr
;
1130 while (get_frame_type (frame
) == INLINE_FRAME
)
1132 frame
= get_prev_frame (frame
);
1133 gdb_assert (frame
!= NULL
);
1136 func_addr
= get_frame_func (frame
);
1137 gdbarch
= get_frame_arch (frame
);
1138 caller_frame
= get_prev_frame (frame
);
1139 if (gdbarch
!= frame_unwind_arch (frame
))
1141 struct bound_minimal_symbol msym
1142 = lookup_minimal_symbol_by_pc (func_addr
);
1143 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1145 throw_error (NO_ENTRY_VALUE_ERROR
,
1146 _("DW_OP_GNU_entry_value resolving callee gdbarch %s "
1147 "(of %s (%s)) does not match caller gdbarch %s"),
1148 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1149 paddress (gdbarch
, func_addr
),
1150 (msym
.minsym
== NULL
? "???"
1151 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
1152 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1155 if (caller_frame
== NULL
)
1157 struct bound_minimal_symbol msym
1158 = lookup_minimal_symbol_by_pc (func_addr
);
1160 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_GNU_entry_value resolving "
1161 "requires caller of %s (%s)"),
1162 paddress (gdbarch
, func_addr
),
1163 (msym
.minsym
== NULL
? "???"
1164 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
1166 caller_pc
= get_frame_pc (caller_frame
);
1167 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1169 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1170 if (target_addr
!= func_addr
)
1172 struct minimal_symbol
*target_msym
, *func_msym
;
1174 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1175 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1176 throw_error (NO_ENTRY_VALUE_ERROR
,
1177 _("DW_OP_GNU_entry_value resolving expects callee %s at %s "
1178 "but the called frame is for %s at %s"),
1179 (target_msym
== NULL
? "???"
1180 : MSYMBOL_PRINT_NAME (target_msym
)),
1181 paddress (gdbarch
, target_addr
),
1182 func_msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (func_msym
),
1183 paddress (gdbarch
, func_addr
));
1186 /* No entry value based parameters would be reliable if this function can
1187 call itself via tail calls. */
1188 func_verify_no_selftailcall (gdbarch
, func_addr
);
1190 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1192 parameter
= &call_site
->parameter
[iparams
];
1193 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1196 if (iparams
== call_site
->parameter_count
)
1198 struct minimal_symbol
*msym
1199 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1201 /* DW_TAG_GNU_call_site_parameter will be missing just if GCC could not
1202 determine its value. */
1203 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1204 "at DW_TAG_GNU_call_site %s at %s"),
1205 paddress (gdbarch
, caller_pc
),
1206 msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (msym
));
1209 *per_cu_return
= call_site
->per_cu
;
1213 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1214 the normal DW_AT_GNU_call_site_value block. Otherwise return the
1215 DW_AT_GNU_call_site_data_value (dereferenced) block.
1217 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1220 Function always returns non-NULL, non-optimized out value. It throws
1221 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1223 static struct value
*
1224 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1225 CORE_ADDR deref_size
, struct type
*type
,
1226 struct frame_info
*caller_frame
,
1227 struct dwarf2_per_cu_data
*per_cu
)
1229 const gdb_byte
*data_src
;
1233 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1234 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1236 /* DEREF_SIZE size is not verified here. */
1237 if (data_src
== NULL
)
1238 throw_error (NO_ENTRY_VALUE_ERROR
,
1239 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1241 /* DW_AT_GNU_call_site_value is a DWARF expression, not a DWARF
1242 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1244 data
= (gdb_byte
*) alloca (size
+ 1);
1245 memcpy (data
, data_src
, size
);
1246 data
[size
] = DW_OP_stack_value
;
1248 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1251 /* Execute DWARF block of call_site_parameter which matches KIND and KIND_U.
1252 Choose DEREF_SIZE value of that parameter. Search caller of the CTX's
1253 frame. CTX must be of dwarf_expr_ctx_funcs kind.
1255 The CTX caller can be from a different CU - per_cu_dwarf_call implementation
1256 can be more simple as it does not support cross-CU DWARF executions. */
1259 dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
1260 enum call_site_parameter_kind kind
,
1261 union call_site_parameter_u kind_u
,
1264 struct dwarf_expr_baton
*debaton
;
1265 struct frame_info
*frame
, *caller_frame
;
1266 struct dwarf2_per_cu_data
*caller_per_cu
;
1267 struct dwarf_expr_baton baton_local
;
1268 struct dwarf_expr_context saved_ctx
;
1269 struct call_site_parameter
*parameter
;
1270 const gdb_byte
*data_src
;
1273 gdb_assert (ctx
->funcs
== &dwarf_expr_ctx_funcs
);
1274 debaton
= (struct dwarf_expr_baton
*) ctx
->baton
;
1275 frame
= debaton
->frame
;
1276 caller_frame
= get_prev_frame (frame
);
1278 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1280 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1281 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1283 /* DEREF_SIZE size is not verified here. */
1284 if (data_src
== NULL
)
1285 throw_error (NO_ENTRY_VALUE_ERROR
,
1286 _("Cannot resolve DW_AT_GNU_call_site_data_value"));
1288 baton_local
.frame
= caller_frame
;
1289 baton_local
.per_cu
= caller_per_cu
;
1290 baton_local
.obj_address
= 0;
1292 saved_ctx
.gdbarch
= ctx
->gdbarch
;
1293 saved_ctx
.addr_size
= ctx
->addr_size
;
1294 saved_ctx
.offset
= ctx
->offset
;
1295 saved_ctx
.baton
= ctx
->baton
;
1296 ctx
->gdbarch
= get_objfile_arch (dwarf2_per_cu_objfile (baton_local
.per_cu
));
1297 ctx
->addr_size
= dwarf2_per_cu_addr_size (baton_local
.per_cu
);
1298 ctx
->offset
= dwarf2_per_cu_text_offset (baton_local
.per_cu
);
1299 ctx
->baton
= &baton_local
;
1301 dwarf_expr_eval (ctx
, data_src
, size
);
1303 ctx
->gdbarch
= saved_ctx
.gdbarch
;
1304 ctx
->addr_size
= saved_ctx
.addr_size
;
1305 ctx
->offset
= saved_ctx
.offset
;
1306 ctx
->baton
= saved_ctx
.baton
;
1309 /* Callback function for dwarf2_evaluate_loc_desc.
1310 Fetch the address indexed by DW_OP_GNU_addr_index. */
1313 dwarf_expr_get_addr_index (void *baton
, unsigned int index
)
1315 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
1317 return dwarf2_read_addr_index (debaton
->per_cu
, index
);
1320 /* Callback function for get_object_address. Return the address of the VLA
1324 dwarf_expr_get_obj_addr (void *baton
)
1326 struct dwarf_expr_baton
*debaton
= (struct dwarf_expr_baton
*) baton
;
1328 gdb_assert (debaton
!= NULL
);
1330 if (debaton
->obj_address
== 0)
1331 error (_("Location address is not set."));
1333 return debaton
->obj_address
;
1336 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1337 the indirect method on it, that is use its stored target value, the sole
1338 purpose of entry_data_value_funcs.. */
1340 static struct value
*
1341 entry_data_value_coerce_ref (const struct value
*value
)
1343 struct type
*checked_type
= check_typedef (value_type (value
));
1344 struct value
*target_val
;
1346 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
)
1349 target_val
= (struct value
*) value_computed_closure (value
);
1350 value_incref (target_val
);
1354 /* Implement copy_closure. */
1357 entry_data_value_copy_closure (const struct value
*v
)
1359 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1361 value_incref (target_val
);
1365 /* Implement free_closure. */
1368 entry_data_value_free_closure (struct value
*v
)
1370 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1372 value_free (target_val
);
1375 /* Vector for methods for an entry value reference where the referenced value
1376 is stored in the caller. On the first dereference use
1377 DW_AT_GNU_call_site_data_value in the caller. */
1379 static const struct lval_funcs entry_data_value_funcs
=
1383 NULL
, /* indirect */
1384 entry_data_value_coerce_ref
,
1385 NULL
, /* check_synthetic_pointer */
1386 entry_data_value_copy_closure
,
1387 entry_data_value_free_closure
1390 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1391 are used to match DW_AT_location at the caller's
1392 DW_TAG_GNU_call_site_parameter.
1394 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1395 cannot resolve the parameter for any reason. */
1397 static struct value
*
1398 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1399 enum call_site_parameter_kind kind
,
1400 union call_site_parameter_u kind_u
)
1402 struct type
*checked_type
= check_typedef (type
);
1403 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1404 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1405 struct value
*outer_val
, *target_val
, *val
;
1406 struct call_site_parameter
*parameter
;
1407 struct dwarf2_per_cu_data
*caller_per_cu
;
1409 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1412 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1416 /* Check if DW_AT_GNU_call_site_data_value cannot be used. If it should be
1417 used and it is not available do not fall back to OUTER_VAL - dereferencing
1418 TYPE_CODE_REF with non-entry data value would give current value - not the
1421 if (TYPE_CODE (checked_type
) != TYPE_CODE_REF
1422 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1425 target_val
= dwarf_entry_parameter_to_value (parameter
,
1426 TYPE_LENGTH (target_type
),
1427 target_type
, caller_frame
,
1430 release_value (target_val
);
1431 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1432 target_val
/* closure */);
1434 /* Copy the referencing pointer to the new computed value. */
1435 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1436 TYPE_LENGTH (checked_type
));
1437 set_value_lazy (val
, 0);
1442 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1443 SIZE are DWARF block used to match DW_AT_location at the caller's
1444 DW_TAG_GNU_call_site_parameter.
1446 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1447 cannot resolve the parameter for any reason. */
1449 static struct value
*
1450 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1451 const gdb_byte
*block
, size_t block_len
)
1453 union call_site_parameter_u kind_u
;
1455 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1456 if (kind_u
.dwarf_reg
!= -1)
1457 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1460 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1461 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1464 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1465 suppressed during normal operation. The expression can be arbitrary if
1466 there is no caller-callee entry value binding expected. */
1467 throw_error (NO_ENTRY_VALUE_ERROR
,
1468 _("DWARF-2 expression error: DW_OP_GNU_entry_value is supported "
1469 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1472 struct piece_closure
1474 /* Reference count. */
1477 /* The CU from which this closure's expression came. */
1478 struct dwarf2_per_cu_data
*per_cu
;
1480 /* The number of pieces used to describe this variable. */
1483 /* The target address size, used only for DWARF_VALUE_STACK. */
1486 /* The pieces themselves. */
1487 struct dwarf_expr_piece
*pieces
;
1490 /* Allocate a closure for a value formed from separately-described
1493 static struct piece_closure
*
1494 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1495 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1498 struct piece_closure
*c
= XCNEW (struct piece_closure
);
1503 c
->n_pieces
= n_pieces
;
1504 c
->addr_size
= addr_size
;
1505 c
->pieces
= XCNEWVEC (struct dwarf_expr_piece
, n_pieces
);
1507 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1508 for (i
= 0; i
< n_pieces
; ++i
)
1509 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1510 value_incref (c
->pieces
[i
].v
.value
);
1515 /* The lowest-level function to extract bits from a byte buffer.
1516 SOURCE is the buffer. It is updated if we read to the end of a
1518 SOURCE_OFFSET_BITS is the offset of the first bit to read. It is
1519 updated to reflect the number of bits actually read.
1520 NBITS is the number of bits we want to read. It is updated to
1521 reflect the number of bits actually read. This function may read
1523 BITS_BIG_ENDIAN is taken directly from gdbarch.
1524 This function returns the extracted bits. */
1527 extract_bits_primitive (const gdb_byte
**source
,
1528 unsigned int *source_offset_bits
,
1529 int *nbits
, int bits_big_endian
)
1531 unsigned int avail
, mask
, datum
;
1533 gdb_assert (*source_offset_bits
< 8);
1535 avail
= 8 - *source_offset_bits
;
1539 mask
= (1 << avail
) - 1;
1541 if (bits_big_endian
)
1542 datum
>>= 8 - (*source_offset_bits
+ *nbits
);
1544 datum
>>= *source_offset_bits
;
1548 *source_offset_bits
+= avail
;
1549 if (*source_offset_bits
>= 8)
1551 *source_offset_bits
-= 8;
1558 /* Extract some bits from a source buffer and move forward in the
1561 SOURCE is the source buffer. It is updated as bytes are read.
1562 SOURCE_OFFSET_BITS is the offset into SOURCE. It is updated as
1564 NBITS is the number of bits to read.
1565 BITS_BIG_ENDIAN is taken directly from gdbarch.
1567 This function returns the bits that were read. */
1570 extract_bits (const gdb_byte
**source
, unsigned int *source_offset_bits
,
1571 int nbits
, int bits_big_endian
)
1575 gdb_assert (nbits
> 0 && nbits
<= 8);
1577 datum
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1583 more
= extract_bits_primitive (source
, source_offset_bits
, &nbits
,
1585 if (bits_big_endian
)
1595 /* Write some bits into a buffer and move forward in the buffer.
1597 DATUM is the bits to write. The low-order bits of DATUM are used.
1598 DEST is the destination buffer. It is updated as bytes are
1600 DEST_OFFSET_BITS is the bit offset in DEST at which writing is
1602 NBITS is the number of valid bits in DATUM.
1603 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1606 insert_bits (unsigned int datum
,
1607 gdb_byte
*dest
, unsigned int dest_offset_bits
,
1608 int nbits
, int bits_big_endian
)
1612 gdb_assert (dest_offset_bits
+ nbits
<= 8);
1614 mask
= (1 << nbits
) - 1;
1615 if (bits_big_endian
)
1617 datum
<<= 8 - (dest_offset_bits
+ nbits
);
1618 mask
<<= 8 - (dest_offset_bits
+ nbits
);
1622 datum
<<= dest_offset_bits
;
1623 mask
<<= dest_offset_bits
;
1626 gdb_assert ((datum
& ~mask
) == 0);
1628 *dest
= (*dest
& ~mask
) | datum
;
1631 /* Copy bits from a source to a destination.
1633 DEST is where the bits should be written.
1634 DEST_OFFSET_BITS is the bit offset into DEST.
1635 SOURCE is the source of bits.
1636 SOURCE_OFFSET_BITS is the bit offset into SOURCE.
1637 BIT_COUNT is the number of bits to copy.
1638 BITS_BIG_ENDIAN is taken directly from gdbarch. */
1641 copy_bitwise (gdb_byte
*dest
, unsigned int dest_offset_bits
,
1642 const gdb_byte
*source
, unsigned int source_offset_bits
,
1643 unsigned int bit_count
,
1644 int bits_big_endian
)
1646 unsigned int dest_avail
;
1649 /* Reduce everything to byte-size pieces. */
1650 dest
+= dest_offset_bits
/ 8;
1651 dest_offset_bits
%= 8;
1652 source
+= source_offset_bits
/ 8;
1653 source_offset_bits
%= 8;
1655 dest_avail
= 8 - dest_offset_bits
% 8;
1657 /* See if we can fill the first destination byte. */
1658 if (dest_avail
< bit_count
)
1660 datum
= extract_bits (&source
, &source_offset_bits
, dest_avail
,
1662 insert_bits (datum
, dest
, dest_offset_bits
, dest_avail
, bits_big_endian
);
1664 dest_offset_bits
= 0;
1665 bit_count
-= dest_avail
;
1668 /* Now, either DEST_OFFSET_BITS is byte-aligned, or we have fewer
1669 than 8 bits remaining. */
1670 gdb_assert (dest_offset_bits
% 8 == 0 || bit_count
< 8);
1671 for (; bit_count
>= 8; bit_count
-= 8)
1673 datum
= extract_bits (&source
, &source_offset_bits
, 8, bits_big_endian
);
1674 *dest
++ = (gdb_byte
) datum
;
1677 /* Finally, we may have a few leftover bits. */
1678 gdb_assert (bit_count
<= 8 - dest_offset_bits
% 8);
1681 datum
= extract_bits (&source
, &source_offset_bits
, bit_count
,
1683 insert_bits (datum
, dest
, dest_offset_bits
, bit_count
, bits_big_endian
);
1688 read_pieced_value (struct value
*v
)
1692 ULONGEST bits_to_skip
;
1694 struct piece_closure
*c
1695 = (struct piece_closure
*) value_computed_closure (v
);
1696 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (v
));
1698 size_t buffer_size
= 0;
1699 gdb_byte
*buffer
= NULL
;
1700 struct cleanup
*cleanup
;
1702 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1704 if (value_type (v
) != value_enclosing_type (v
))
1705 internal_error (__FILE__
, __LINE__
,
1706 _("Should not be able to create a lazy value with "
1707 "an enclosing type"));
1709 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1711 contents
= value_contents_raw (v
);
1712 bits_to_skip
= 8 * value_offset (v
);
1713 if (value_bitsize (v
))
1715 bits_to_skip
+= value_bitpos (v
);
1716 type_len
= value_bitsize (v
);
1719 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1721 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1723 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1724 size_t this_size
, this_size_bits
;
1725 long dest_offset_bits
, source_offset_bits
, source_offset
;
1726 const gdb_byte
*intermediate_buffer
;
1728 /* Compute size, source, and destination offsets for copying, in
1730 this_size_bits
= p
->size
;
1731 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1733 bits_to_skip
-= this_size_bits
;
1736 if (bits_to_skip
> 0)
1738 dest_offset_bits
= 0;
1739 source_offset_bits
= bits_to_skip
;
1740 this_size_bits
-= bits_to_skip
;
1745 dest_offset_bits
= offset
;
1746 source_offset_bits
= 0;
1748 if (this_size_bits
> type_len
- offset
)
1749 this_size_bits
= type_len
- offset
;
1751 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1752 source_offset
= source_offset_bits
/ 8;
1753 if (buffer_size
< this_size
)
1755 buffer_size
= this_size
;
1756 buffer
= (gdb_byte
*) xrealloc (buffer
, buffer_size
);
1758 intermediate_buffer
= buffer
;
1760 /* Copy from the source to DEST_BUFFER. */
1761 switch (p
->location
)
1763 case DWARF_VALUE_REGISTER
:
1765 struct gdbarch
*arch
= get_frame_arch (frame
);
1766 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1768 LONGEST reg_offset
= source_offset
;
1770 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1771 && this_size
< register_size (arch
, gdb_regnum
))
1773 /* Big-endian, and we want less than full size. */
1774 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1775 /* We want the lower-order THIS_SIZE_BITS of the bytes
1776 we extract from the register. */
1777 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1780 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1784 /* Just so garbage doesn't ever shine through. */
1785 memset (buffer
, 0, this_size
);
1788 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1790 mark_value_bits_unavailable (v
, offset
, this_size_bits
);
1795 case DWARF_VALUE_MEMORY
:
1796 read_value_memory (v
, offset
,
1797 p
->v
.mem
.in_stack_memory
,
1798 p
->v
.mem
.addr
+ source_offset
,
1802 case DWARF_VALUE_STACK
:
1804 size_t n
= this_size
;
1806 if (n
> c
->addr_size
- source_offset
)
1807 n
= (c
->addr_size
>= source_offset
1808 ? c
->addr_size
- source_offset
1816 const gdb_byte
*val_bytes
= value_contents_all (p
->v
.value
);
1818 intermediate_buffer
= val_bytes
+ source_offset
;
1823 case DWARF_VALUE_LITERAL
:
1825 size_t n
= this_size
;
1827 if (n
> p
->v
.literal
.length
- source_offset
)
1828 n
= (p
->v
.literal
.length
>= source_offset
1829 ? p
->v
.literal
.length
- source_offset
1832 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1836 /* These bits show up as zeros -- but do not cause the value
1837 to be considered optimized-out. */
1838 case DWARF_VALUE_IMPLICIT_POINTER
:
1841 case DWARF_VALUE_OPTIMIZED_OUT
:
1842 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1846 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1849 if (p
->location
!= DWARF_VALUE_OPTIMIZED_OUT
1850 && p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1851 copy_bitwise (contents
, dest_offset_bits
,
1852 intermediate_buffer
, source_offset_bits
% 8,
1853 this_size_bits
, bits_big_endian
);
1855 offset
+= this_size_bits
;
1858 do_cleanups (cleanup
);
1862 write_pieced_value (struct value
*to
, struct value
*from
)
1866 ULONGEST bits_to_skip
;
1867 const gdb_byte
*contents
;
1868 struct piece_closure
*c
1869 = (struct piece_closure
*) value_computed_closure (to
);
1870 struct frame_info
*frame
= frame_find_by_id (VALUE_FRAME_ID (to
));
1872 size_t buffer_size
= 0;
1873 gdb_byte
*buffer
= NULL
;
1874 struct cleanup
*cleanup
;
1876 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1880 mark_value_bytes_optimized_out (to
, 0, TYPE_LENGTH (value_type (to
)));
1884 cleanup
= make_cleanup (free_current_contents
, &buffer
);
1886 contents
= value_contents (from
);
1887 bits_to_skip
= 8 * value_offset (to
);
1888 if (value_bitsize (to
))
1890 bits_to_skip
+= value_bitpos (to
);
1891 type_len
= value_bitsize (to
);
1894 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1896 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1898 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1899 size_t this_size_bits
, this_size
;
1900 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1902 const gdb_byte
*source_buffer
;
1904 this_size_bits
= p
->size
;
1905 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1907 bits_to_skip
-= this_size_bits
;
1910 if (this_size_bits
> type_len
- offset
)
1911 this_size_bits
= type_len
- offset
;
1912 if (bits_to_skip
> 0)
1914 dest_offset_bits
= bits_to_skip
;
1915 source_offset_bits
= 0;
1916 this_size_bits
-= bits_to_skip
;
1921 dest_offset_bits
= 0;
1922 source_offset_bits
= offset
;
1925 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1926 source_offset
= source_offset_bits
/ 8;
1927 dest_offset
= dest_offset_bits
/ 8;
1928 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1930 source_buffer
= contents
+ source_offset
;
1935 if (buffer_size
< this_size
)
1937 buffer_size
= this_size
;
1938 buffer
= (gdb_byte
*) xrealloc (buffer
, buffer_size
);
1940 source_buffer
= buffer
;
1944 switch (p
->location
)
1946 case DWARF_VALUE_REGISTER
:
1948 struct gdbarch
*arch
= get_frame_arch (frame
);
1949 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1950 int reg_offset
= dest_offset
;
1952 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1953 && this_size
<= register_size (arch
, gdb_regnum
))
1955 /* Big-endian, and we want less than full size. */
1956 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1963 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1968 throw_error (OPTIMIZED_OUT_ERROR
,
1969 _("Can't do read-modify-write to "
1970 "update bitfield; containing word "
1971 "has been optimized out"));
1973 throw_error (NOT_AVAILABLE_ERROR
,
1974 _("Can't do read-modify-write to update "
1975 "bitfield; containing word "
1978 copy_bitwise (buffer
, dest_offset_bits
,
1979 contents
, source_offset_bits
,
1984 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1985 this_size
, source_buffer
);
1988 case DWARF_VALUE_MEMORY
:
1991 /* Only the first and last bytes can possibly have any
1993 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
, 1);
1994 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
1995 buffer
+ this_size
- 1, 1);
1996 copy_bitwise (buffer
, dest_offset_bits
,
1997 contents
, source_offset_bits
,
2002 write_memory (p
->v
.mem
.addr
+ dest_offset
,
2003 source_buffer
, this_size
);
2006 mark_value_bytes_optimized_out (to
, 0, TYPE_LENGTH (value_type (to
)));
2009 offset
+= this_size_bits
;
2012 do_cleanups (cleanup
);
2015 /* An implementation of an lval_funcs method to see whether a value is
2016 a synthetic pointer. */
2019 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
2022 struct piece_closure
*c
2023 = (struct piece_closure
*) value_computed_closure (value
);
2026 bit_offset
+= 8 * value_offset (value
);
2027 if (value_bitsize (value
))
2028 bit_offset
+= value_bitpos (value
);
2030 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2032 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2033 size_t this_size_bits
= p
->size
;
2037 if (bit_offset
>= this_size_bits
)
2039 bit_offset
-= this_size_bits
;
2043 bit_length
-= this_size_bits
- bit_offset
;
2047 bit_length
-= this_size_bits
;
2049 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2056 /* A wrapper function for get_frame_address_in_block. */
2059 get_frame_address_in_block_wrapper (void *baton
)
2061 return get_frame_address_in_block ((struct frame_info
*) baton
);
2064 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2066 static struct value
*
2067 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2068 struct dwarf2_per_cu_data
*per_cu
,
2071 struct value
*result
= NULL
;
2072 struct obstack temp_obstack
;
2073 struct cleanup
*cleanup
;
2074 const gdb_byte
*bytes
;
2077 obstack_init (&temp_obstack
);
2078 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2079 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
2083 if (byte_offset
>= 0
2084 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2086 bytes
+= byte_offset
;
2087 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2090 invalid_synthetic_pointer ();
2093 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2095 do_cleanups (cleanup
);
2100 /* Fetch the value pointed to by a synthetic pointer. */
2102 static struct value
*
2103 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2104 struct dwarf2_per_cu_data
*per_cu
,
2105 struct frame_info
*frame
, struct type
*type
)
2107 /* Fetch the location expression of the DIE we're pointing to. */
2108 struct dwarf2_locexpr_baton baton
2109 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
2110 get_frame_address_in_block_wrapper
, frame
);
2112 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2113 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2114 or it may've been optimized out. */
2115 if (baton
.data
!= NULL
)
2116 return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type
), frame
,
2117 baton
.data
, baton
.size
, baton
.per_cu
,
2120 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2124 /* An implementation of an lval_funcs method to indirect through a
2125 pointer. This handles the synthetic pointer case when needed. */
2127 static struct value
*
2128 indirect_pieced_value (struct value
*value
)
2130 struct piece_closure
*c
2131 = (struct piece_closure
*) value_computed_closure (value
);
2133 struct frame_info
*frame
;
2134 struct dwarf2_locexpr_baton baton
;
2137 struct dwarf_expr_piece
*piece
= NULL
;
2138 LONGEST byte_offset
;
2139 enum bfd_endian byte_order
;
2141 type
= check_typedef (value_type (value
));
2142 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2145 bit_length
= 8 * TYPE_LENGTH (type
);
2146 bit_offset
= 8 * value_offset (value
);
2147 if (value_bitsize (value
))
2148 bit_offset
+= value_bitpos (value
);
2150 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2152 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2153 size_t this_size_bits
= p
->size
;
2157 if (bit_offset
>= this_size_bits
)
2159 bit_offset
-= this_size_bits
;
2163 bit_length
-= this_size_bits
- bit_offset
;
2167 bit_length
-= this_size_bits
;
2169 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2172 if (bit_length
!= 0)
2173 error (_("Invalid use of DW_OP_GNU_implicit_pointer"));
2179 gdb_assert (piece
!= NULL
);
2180 frame
= get_selected_frame (_("No frame selected."));
2182 /* This is an offset requested by GDB, such as value subscripts.
2183 However, due to how synthetic pointers are implemented, this is
2184 always presented to us as a pointer type. This means we have to
2185 sign-extend it manually as appropriate. Use raw
2186 extract_signed_integer directly rather than value_as_address and
2187 sign extend afterwards on architectures that would need it
2188 (mostly everywhere except MIPS, which has signed addresses) as
2189 the later would go through gdbarch_pointer_to_address and thus
2190 return a CORE_ADDR with high bits set on architectures that
2191 encode address spaces and other things in CORE_ADDR. */
2192 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2193 byte_offset
= extract_signed_integer (value_contents (value
),
2194 TYPE_LENGTH (type
), byte_order
);
2195 byte_offset
+= piece
->v
.ptr
.offset
;
2197 return indirect_synthetic_pointer (piece
->v
.ptr
.die
, byte_offset
, c
->per_cu
,
2201 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2204 static struct value
*
2205 coerce_pieced_ref (const struct value
*value
)
2207 struct type
*type
= check_typedef (value_type (value
));
2209 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2210 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2212 const struct piece_closure
*closure
2213 = (struct piece_closure
*) value_computed_closure (value
);
2214 struct frame_info
*frame
2215 = get_selected_frame (_("No frame selected."));
2217 /* gdb represents synthetic pointers as pieced values with a single
2219 gdb_assert (closure
!= NULL
);
2220 gdb_assert (closure
->n_pieces
== 1);
2222 return indirect_synthetic_pointer (closure
->pieces
->v
.ptr
.die
,
2223 closure
->pieces
->v
.ptr
.offset
,
2224 closure
->per_cu
, frame
, type
);
2228 /* Else: not a synthetic reference; do nothing. */
2234 copy_pieced_value_closure (const struct value
*v
)
2236 struct piece_closure
*c
2237 = (struct piece_closure
*) value_computed_closure (v
);
2244 free_pieced_value_closure (struct value
*v
)
2246 struct piece_closure
*c
2247 = (struct piece_closure
*) value_computed_closure (v
);
2254 for (i
= 0; i
< c
->n_pieces
; ++i
)
2255 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2256 value_free (c
->pieces
[i
].v
.value
);
2263 /* Functions for accessing a variable described by DW_OP_piece. */
2264 static const struct lval_funcs pieced_value_funcs
= {
2267 indirect_pieced_value
,
2269 check_pieced_synthetic_pointer
,
2270 copy_pieced_value_closure
,
2271 free_pieced_value_closure
2274 /* Virtual method table for dwarf2_evaluate_loc_desc_full below. */
2276 const struct dwarf_expr_context_funcs dwarf_expr_ctx_funcs
=
2278 dwarf_expr_read_addr_from_reg
,
2279 dwarf_expr_get_reg_value
,
2280 dwarf_expr_read_mem
,
2281 dwarf_expr_frame_base
,
2282 dwarf_expr_frame_cfa
,
2283 dwarf_expr_frame_pc
,
2284 dwarf_expr_tls_address
,
2285 dwarf_expr_dwarf_call
,
2286 dwarf_expr_get_base_type
,
2287 dwarf_expr_push_dwarf_reg_entry_value
,
2288 dwarf_expr_get_addr_index
,
2289 dwarf_expr_get_obj_addr
2292 /* Evaluate a location description, starting at DATA and with length
2293 SIZE, to find the current location of variable of TYPE in the
2294 context of FRAME. BYTE_OFFSET is applied after the contents are
2297 static struct value
*
2298 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2299 const gdb_byte
*data
, size_t size
,
2300 struct dwarf2_per_cu_data
*per_cu
,
2301 LONGEST byte_offset
)
2303 struct value
*retval
;
2304 struct dwarf_expr_baton baton
;
2305 struct dwarf_expr_context
*ctx
;
2306 struct cleanup
*old_chain
, *value_chain
;
2307 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2309 if (byte_offset
< 0)
2310 invalid_synthetic_pointer ();
2313 return allocate_optimized_out_value (type
);
2315 baton
.frame
= frame
;
2316 baton
.per_cu
= per_cu
;
2317 baton
.obj_address
= 0;
2319 ctx
= new_dwarf_expr_context ();
2320 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2321 value_chain
= make_cleanup_value_free_to_mark (value_mark ());
2323 ctx
->gdbarch
= get_objfile_arch (objfile
);
2324 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2325 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2326 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2327 ctx
->baton
= &baton
;
2328 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2332 dwarf_expr_eval (ctx
, data
, size
);
2334 CATCH (ex
, RETURN_MASK_ERROR
)
2336 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2338 do_cleanups (old_chain
);
2339 retval
= allocate_value (type
);
2340 mark_value_bytes_unavailable (retval
, 0, TYPE_LENGTH (type
));
2343 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2345 if (entry_values_debug
)
2346 exception_print (gdb_stdout
, ex
);
2347 do_cleanups (old_chain
);
2348 return allocate_optimized_out_value (type
);
2351 throw_exception (ex
);
2355 if (ctx
->num_pieces
> 0)
2357 struct piece_closure
*c
;
2358 struct frame_id frame_id
= get_frame_id (frame
);
2359 ULONGEST bit_size
= 0;
2362 for (i
= 0; i
< ctx
->num_pieces
; ++i
)
2363 bit_size
+= ctx
->pieces
[i
].size
;
2364 if (8 * (byte_offset
+ TYPE_LENGTH (type
)) > bit_size
)
2365 invalid_synthetic_pointer ();
2367 c
= allocate_piece_closure (per_cu
, ctx
->num_pieces
, ctx
->pieces
,
2369 /* We must clean up the value chain after creating the piece
2370 closure but before allocating the result. */
2371 do_cleanups (value_chain
);
2372 retval
= allocate_computed_value (type
, &pieced_value_funcs
, c
);
2373 VALUE_FRAME_ID (retval
) = frame_id
;
2374 set_value_offset (retval
, byte_offset
);
2378 switch (ctx
->location
)
2380 case DWARF_VALUE_REGISTER
:
2382 struct gdbarch
*arch
= get_frame_arch (frame
);
2384 = longest_to_int (value_as_long (dwarf_expr_fetch (ctx
, 0)));
2385 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2387 if (byte_offset
!= 0)
2388 error (_("cannot use offset on synthetic pointer to register"));
2389 do_cleanups (value_chain
);
2390 retval
= value_from_register (type
, gdb_regnum
, frame
);
2391 if (value_optimized_out (retval
))
2395 /* This means the register has undefined value / was
2396 not saved. As we're computing the location of some
2397 variable etc. in the program, not a value for
2398 inspecting a register ($pc, $sp, etc.), return a
2399 generic optimized out value instead, so that we show
2400 <optimized out> instead of <not saved>. */
2401 do_cleanups (value_chain
);
2402 tmp
= allocate_value (type
);
2403 value_contents_copy (tmp
, 0, retval
, 0, TYPE_LENGTH (type
));
2409 case DWARF_VALUE_MEMORY
:
2411 struct type
*ptr_type
;
2412 CORE_ADDR address
= dwarf_expr_fetch_address (ctx
, 0);
2413 int in_stack_memory
= dwarf_expr_fetch_in_stack_memory (ctx
, 0);
2415 /* DW_OP_deref_size (and possibly other operations too) may
2416 create a pointer instead of an address. Ideally, the
2417 pointer to address conversion would be performed as part
2418 of those operations, but the type of the object to
2419 which the address refers is not known at the time of
2420 the operation. Therefore, we do the conversion here
2421 since the type is readily available. */
2423 switch (TYPE_CODE (type
))
2425 case TYPE_CODE_FUNC
:
2426 case TYPE_CODE_METHOD
:
2427 ptr_type
= builtin_type (ctx
->gdbarch
)->builtin_func_ptr
;
2430 ptr_type
= builtin_type (ctx
->gdbarch
)->builtin_data_ptr
;
2433 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2435 do_cleanups (value_chain
);
2436 retval
= value_at_lazy (type
, address
+ byte_offset
);
2437 if (in_stack_memory
)
2438 set_value_stack (retval
, 1);
2442 case DWARF_VALUE_STACK
:
2444 struct value
*value
= dwarf_expr_fetch (ctx
, 0);
2446 const gdb_byte
*val_bytes
;
2447 size_t n
= TYPE_LENGTH (value_type (value
));
2449 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2450 invalid_synthetic_pointer ();
2452 val_bytes
= value_contents_all (value
);
2453 val_bytes
+= byte_offset
;
2456 /* Preserve VALUE because we are going to free values back
2457 to the mark, but we still need the value contents
2459 value_incref (value
);
2460 do_cleanups (value_chain
);
2461 make_cleanup_value_free (value
);
2463 retval
= allocate_value (type
);
2464 contents
= value_contents_raw (retval
);
2465 if (n
> TYPE_LENGTH (type
))
2467 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2469 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2470 val_bytes
+= n
- TYPE_LENGTH (type
);
2471 n
= TYPE_LENGTH (type
);
2473 memcpy (contents
, val_bytes
, n
);
2477 case DWARF_VALUE_LITERAL
:
2480 const bfd_byte
*ldata
;
2481 size_t n
= ctx
->len
;
2483 if (byte_offset
+ TYPE_LENGTH (type
) > n
)
2484 invalid_synthetic_pointer ();
2486 do_cleanups (value_chain
);
2487 retval
= allocate_value (type
);
2488 contents
= value_contents_raw (retval
);
2490 ldata
= ctx
->data
+ byte_offset
;
2493 if (n
> TYPE_LENGTH (type
))
2495 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2497 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2498 ldata
+= n
- TYPE_LENGTH (type
);
2499 n
= TYPE_LENGTH (type
);
2501 memcpy (contents
, ldata
, n
);
2505 case DWARF_VALUE_OPTIMIZED_OUT
:
2506 do_cleanups (value_chain
);
2507 retval
= allocate_optimized_out_value (type
);
2510 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2511 operation by execute_stack_op. */
2512 case DWARF_VALUE_IMPLICIT_POINTER
:
2513 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2514 it can only be encountered when making a piece. */
2516 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2520 set_value_initialized (retval
, ctx
->initialized
);
2522 do_cleanups (old_chain
);
2527 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2528 passes 0 as the byte_offset. */
2531 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2532 const gdb_byte
*data
, size_t size
,
2533 struct dwarf2_per_cu_data
*per_cu
)
2535 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
, 0);
2538 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2539 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2540 frame in which the expression is evaluated. ADDR is a context (location of
2541 a variable) and might be needed to evaluate the location expression.
2542 Returns 1 on success, 0 otherwise. */
2545 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2546 struct frame_info
*frame
,
2550 struct dwarf_expr_context
*ctx
;
2551 struct dwarf_expr_baton baton
;
2552 struct objfile
*objfile
;
2553 struct cleanup
*cleanup
;
2555 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2558 ctx
= new_dwarf_expr_context ();
2559 cleanup
= make_cleanup_free_dwarf_expr_context (ctx
);
2561 baton
.frame
= frame
;
2562 baton
.per_cu
= dlbaton
->per_cu
;
2563 baton
.obj_address
= addr
;
2565 objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2567 ctx
->gdbarch
= get_objfile_arch (objfile
);
2568 ctx
->addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2569 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (dlbaton
->per_cu
);
2570 ctx
->offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2571 ctx
->funcs
= &dwarf_expr_ctx_funcs
;
2572 ctx
->baton
= &baton
;
2574 dwarf_expr_eval (ctx
, dlbaton
->data
, dlbaton
->size
);
2576 switch (ctx
->location
)
2578 case DWARF_VALUE_REGISTER
:
2579 case DWARF_VALUE_MEMORY
:
2580 case DWARF_VALUE_STACK
:
2581 *valp
= dwarf_expr_fetch_address (ctx
, 0);
2582 if (ctx
->location
== DWARF_VALUE_REGISTER
)
2583 *valp
= dwarf_expr_read_addr_from_reg (&baton
, *valp
);
2584 do_cleanups (cleanup
);
2586 case DWARF_VALUE_LITERAL
:
2587 *valp
= extract_signed_integer (ctx
->data
, ctx
->len
,
2588 gdbarch_byte_order (ctx
->gdbarch
));
2589 do_cleanups (cleanup
);
2591 /* Unsupported dwarf values. */
2592 case DWARF_VALUE_OPTIMIZED_OUT
:
2593 case DWARF_VALUE_IMPLICIT_POINTER
:
2597 do_cleanups (cleanup
);
2601 /* See dwarf2loc.h. */
2604 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2605 struct frame_info
*frame
,
2606 struct property_addr_info
*addr_stack
,
2612 if (frame
== NULL
&& has_stack_frames ())
2613 frame
= get_selected_frame (NULL
);
2619 const struct dwarf2_property_baton
*baton
2620 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2622 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
,
2623 addr_stack
? addr_stack
->addr
: 0,
2626 if (baton
->referenced_type
)
2628 struct value
*val
= value_at (baton
->referenced_type
, *value
);
2630 *value
= value_as_address (val
);
2639 struct dwarf2_property_baton
*baton
2640 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2641 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2642 const gdb_byte
*data
;
2646 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2649 val
= dwarf2_evaluate_loc_desc (baton
->referenced_type
, frame
, data
,
2650 size
, baton
->loclist
.per_cu
);
2651 if (!value_optimized_out (val
))
2653 *value
= value_as_address (val
);
2661 *value
= prop
->data
.const_val
;
2664 case PROP_ADDR_OFFSET
:
2666 struct dwarf2_property_baton
*baton
2667 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2668 struct property_addr_info
*pinfo
;
2671 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2672 if (pinfo
->type
== baton
->referenced_type
)
2675 error (_("cannot find reference address for offset property"));
2676 if (pinfo
->valaddr
!= NULL
)
2677 val
= value_from_contents
2678 (baton
->offset_info
.type
,
2679 pinfo
->valaddr
+ baton
->offset_info
.offset
);
2681 val
= value_at (baton
->offset_info
.type
,
2682 pinfo
->addr
+ baton
->offset_info
.offset
);
2683 *value
= value_as_address (val
);
2691 /* See dwarf2loc.h. */
2694 dwarf2_compile_property_to_c (struct ui_file
*stream
,
2695 const char *result_name
,
2696 struct gdbarch
*gdbarch
,
2697 unsigned char *registers_used
,
2698 const struct dynamic_prop
*prop
,
2702 struct dwarf2_property_baton
*baton
2703 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2704 const gdb_byte
*data
;
2706 struct dwarf2_per_cu_data
*per_cu
;
2708 if (prop
->kind
== PROP_LOCEXPR
)
2710 data
= baton
->locexpr
.data
;
2711 size
= baton
->locexpr
.size
;
2712 per_cu
= baton
->locexpr
.per_cu
;
2716 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2718 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2719 per_cu
= baton
->loclist
.per_cu
;
2722 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2723 gdbarch
, registers_used
,
2724 dwarf2_per_cu_addr_size (per_cu
),
2725 data
, data
+ size
, per_cu
);
2729 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2731 struct symbol_needs_baton
2733 enum symbol_needs_kind needs
;
2734 struct dwarf2_per_cu_data
*per_cu
;
2737 /* Reads from registers do require a frame. */
2739 symbol_needs_read_addr_from_reg (void *baton
, int regnum
)
2741 struct symbol_needs_baton
*nf_baton
= (struct symbol_needs_baton
*) baton
;
2743 nf_baton
->needs
= SYMBOL_NEEDS_FRAME
;
2747 /* struct dwarf_expr_context_funcs' "get_reg_value" callback:
2748 Reads from registers do require a frame. */
2750 static struct value
*
2751 symbol_needs_get_reg_value (void *baton
, struct type
*type
, int regnum
)
2753 struct symbol_needs_baton
*nf_baton
= (struct symbol_needs_baton
*) baton
;
2755 nf_baton
->needs
= SYMBOL_NEEDS_FRAME
;
2756 return value_zero (type
, not_lval
);
2759 /* Reads from memory do not require a frame. */
2761 symbol_needs_read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
2763 memset (buf
, 0, len
);
2766 /* Frame-relative accesses do require a frame. */
2768 symbol_needs_frame_base (void *baton
, const gdb_byte
**start
, size_t * length
)
2770 static gdb_byte lit0
= DW_OP_lit0
;
2771 struct symbol_needs_baton
*nf_baton
= (struct symbol_needs_baton
*) baton
;
2776 nf_baton
->needs
= SYMBOL_NEEDS_FRAME
;
2779 /* CFA accesses require a frame. */
2782 symbol_needs_frame_cfa (void *baton
)
2784 struct symbol_needs_baton
*nf_baton
= (struct symbol_needs_baton
*) baton
;
2786 nf_baton
->needs
= SYMBOL_NEEDS_FRAME
;
2790 /* Thread-local accesses require registers, but not a frame. */
2792 symbol_needs_tls_address (void *baton
, CORE_ADDR offset
)
2794 struct symbol_needs_baton
*nf_baton
= (struct symbol_needs_baton
*) baton
;
2796 if (nf_baton
->needs
<= SYMBOL_NEEDS_REGISTERS
)
2797 nf_baton
->needs
= SYMBOL_NEEDS_REGISTERS
;
2801 /* Helper interface of per_cu_dwarf_call for
2802 dwarf2_loc_desc_get_symbol_read_needs. */
2805 symbol_needs_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
)
2807 struct symbol_needs_baton
*nf_baton
=
2808 (struct symbol_needs_baton
*) ctx
->baton
;
2810 per_cu_dwarf_call (ctx
, die_offset
, nf_baton
->per_cu
,
2811 ctx
->funcs
->get_frame_pc
, ctx
->baton
);
2814 /* DW_OP_GNU_entry_value accesses require a caller, therefore a frame. */
2817 needs_dwarf_reg_entry_value (struct dwarf_expr_context
*ctx
,
2818 enum call_site_parameter_kind kind
,
2819 union call_site_parameter_u kind_u
, int deref_size
)
2821 struct symbol_needs_baton
*nf_baton
=
2822 (struct symbol_needs_baton
*) ctx
->baton
;
2824 nf_baton
->needs
= SYMBOL_NEEDS_FRAME
;
2826 /* The expression may require some stub values on DWARF stack. */
2827 dwarf_expr_push_address (ctx
, 0, 0);
2830 /* DW_OP_GNU_addr_index doesn't require a frame. */
2833 needs_get_addr_index (void *baton
, unsigned int index
)
2835 /* Nothing to do. */
2839 /* DW_OP_push_object_address has a frame already passed through. */
2842 needs_get_obj_addr (void *baton
)
2844 /* Nothing to do. */
2848 /* Virtual method table for dwarf2_loc_desc_get_symbol_read_needs
2851 static const struct dwarf_expr_context_funcs symbol_needs_ctx_funcs
=
2853 symbol_needs_read_addr_from_reg
,
2854 symbol_needs_get_reg_value
,
2855 symbol_needs_read_mem
,
2856 symbol_needs_frame_base
,
2857 symbol_needs_frame_cfa
,
2858 symbol_needs_frame_cfa
, /* get_frame_pc */
2859 symbol_needs_tls_address
,
2860 symbol_needs_dwarf_call
,
2861 NULL
, /* get_base_type */
2862 needs_dwarf_reg_entry_value
,
2863 needs_get_addr_index
,
2867 /* Compute the correct symbol_needs_kind value for the location
2868 expression at DATA (length SIZE). */
2870 static enum symbol_needs_kind
2871 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2872 struct dwarf2_per_cu_data
*per_cu
)
2874 struct symbol_needs_baton baton
;
2875 struct dwarf_expr_context
*ctx
;
2877 struct cleanup
*old_chain
;
2878 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2880 baton
.needs
= SYMBOL_NEEDS_NONE
;
2881 baton
.per_cu
= per_cu
;
2883 ctx
= new_dwarf_expr_context ();
2884 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
2885 make_cleanup_value_free_to_mark (value_mark ());
2887 ctx
->gdbarch
= get_objfile_arch (objfile
);
2888 ctx
->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2889 ctx
->ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2890 ctx
->offset
= dwarf2_per_cu_text_offset (per_cu
);
2891 ctx
->baton
= &baton
;
2892 ctx
->funcs
= &symbol_needs_ctx_funcs
;
2894 dwarf_expr_eval (ctx
, data
, size
);
2896 in_reg
= ctx
->location
== DWARF_VALUE_REGISTER
;
2898 if (ctx
->num_pieces
> 0)
2902 /* If the location has several pieces, and any of them are in
2903 registers, then we will need a frame to fetch them from. */
2904 for (i
= 0; i
< ctx
->num_pieces
; i
++)
2905 if (ctx
->pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2909 do_cleanups (old_chain
);
2912 baton
.needs
= SYMBOL_NEEDS_FRAME
;
2916 /* A helper function that throws an unimplemented error mentioning a
2917 given DWARF operator. */
2920 unimplemented (unsigned int op
)
2922 const char *name
= get_DW_OP_name (op
);
2925 error (_("DWARF operator %s cannot be translated to an agent expression"),
2928 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2929 "to an agent expression"),
2935 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2936 can issue a complaint, which is better than having every target's
2937 implementation of dwarf2_reg_to_regnum do it. */
2940 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2942 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2946 complaint (&symfile_complaints
,
2947 _("bad DWARF register number %d"), dwarf_reg
);
2952 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2953 Throw an error because DWARF_REG is bad. */
2956 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2958 /* Still want to print -1 as "-1".
2959 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2960 but that's overkill for now. */
2961 if ((int) dwarf_reg
== dwarf_reg
)
2962 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2963 error (_("Unable to access DWARF register number %s"),
2964 pulongest (dwarf_reg
));
2967 /* See dwarf2loc.h. */
2970 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2974 if (dwarf_reg
> INT_MAX
)
2975 throw_bad_regnum_error (dwarf_reg
);
2976 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2977 bad, but that's ok. */
2978 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2980 throw_bad_regnum_error (dwarf_reg
);
2984 /* A helper function that emits an access to memory. ARCH is the
2985 target architecture. EXPR is the expression which we are building.
2986 NBITS is the number of bits we want to read. This emits the
2987 opcodes needed to read the memory and then extract the desired
2991 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2993 ULONGEST nbytes
= (nbits
+ 7) / 8;
2995 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2998 ax_trace_quick (expr
, nbytes
);
3001 ax_simple (expr
, aop_ref8
);
3002 else if (nbits
<= 16)
3003 ax_simple (expr
, aop_ref16
);
3004 else if (nbits
<= 32)
3005 ax_simple (expr
, aop_ref32
);
3007 ax_simple (expr
, aop_ref64
);
3009 /* If we read exactly the number of bytes we wanted, we're done. */
3010 if (8 * nbytes
== nbits
)
3013 if (gdbarch_bits_big_endian (arch
))
3015 /* On a bits-big-endian machine, we want the high-order
3017 ax_const_l (expr
, 8 * nbytes
- nbits
);
3018 ax_simple (expr
, aop_rsh_unsigned
);
3022 /* On a bits-little-endian box, we want the low-order NBITS. */
3023 ax_zero_ext (expr
, nbits
);
3027 /* A helper function to return the frame's PC. */
3030 get_ax_pc (void *baton
)
3032 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
3037 /* Compile a DWARF location expression to an agent expression.
3039 EXPR is the agent expression we are building.
3040 LOC is the agent value we modify.
3041 ARCH is the architecture.
3042 ADDR_SIZE is the size of addresses, in bytes.
3043 OP_PTR is the start of the location expression.
3044 OP_END is one past the last byte of the location expression.
3046 This will throw an exception for various kinds of errors -- for
3047 example, if the expression cannot be compiled, or if the expression
3051 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3052 struct gdbarch
*arch
, unsigned int addr_size
,
3053 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
3054 struct dwarf2_per_cu_data
*per_cu
)
3056 struct cleanup
*cleanups
;
3058 VEC(int) *dw_labels
= NULL
, *patches
= NULL
;
3059 const gdb_byte
* const base
= op_ptr
;
3060 const gdb_byte
*previous_piece
= op_ptr
;
3061 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3062 ULONGEST bits_collected
= 0;
3063 unsigned int addr_size_bits
= 8 * addr_size
;
3064 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
3066 offsets
= XNEWVEC (int, op_end
- op_ptr
);
3067 cleanups
= make_cleanup (xfree
, offsets
);
3069 for (i
= 0; i
< op_end
- op_ptr
; ++i
)
3072 make_cleanup (VEC_cleanup (int), &dw_labels
);
3073 make_cleanup (VEC_cleanup (int), &patches
);
3075 /* By default we are making an address. */
3076 loc
->kind
= axs_lvalue_memory
;
3078 while (op_ptr
< op_end
)
3080 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3081 uint64_t uoffset
, reg
;
3085 offsets
[op_ptr
- base
] = expr
->len
;
3088 /* Our basic approach to code generation is to map DWARF
3089 operations directly to AX operations. However, there are
3092 First, DWARF works on address-sized units, but AX always uses
3093 LONGEST. For most operations we simply ignore this
3094 difference; instead we generate sign extensions as needed
3095 before division and comparison operations. It would be nice
3096 to omit the sign extensions, but there is no way to determine
3097 the size of the target's LONGEST. (This code uses the size
3098 of the host LONGEST in some cases -- that is a bug but it is
3101 Second, some DWARF operations cannot be translated to AX.
3102 For these we simply fail. See
3103 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3138 ax_const_l (expr
, op
- DW_OP_lit0
);
3142 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3143 op_ptr
+= addr_size
;
3144 /* Some versions of GCC emit DW_OP_addr before
3145 DW_OP_GNU_push_tls_address. In this case the value is an
3146 index, not an address. We don't support things like
3147 branching between the address and the TLS op. */
3148 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3149 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
3150 ax_const_l (expr
, uoffset
);
3154 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3158 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3162 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3166 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3170 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3174 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3178 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3182 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3186 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3187 ax_const_l (expr
, uoffset
);
3190 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3191 ax_const_l (expr
, offset
);
3226 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3227 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3228 loc
->kind
= axs_lvalue_register
;
3232 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3233 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3234 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3235 loc
->kind
= axs_lvalue_register
;
3238 case DW_OP_implicit_value
:
3242 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3243 if (op_ptr
+ len
> op_end
)
3244 error (_("DW_OP_implicit_value: too few bytes available."));
3245 if (len
> sizeof (ULONGEST
))
3246 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3249 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3252 dwarf_expr_require_composition (op_ptr
, op_end
,
3253 "DW_OP_implicit_value");
3255 loc
->kind
= axs_rvalue
;
3259 case DW_OP_stack_value
:
3260 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3261 loc
->kind
= axs_rvalue
;
3296 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3297 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3301 ax_const_l (expr
, offset
);
3302 ax_simple (expr
, aop_add
);
3307 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3308 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3309 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3313 ax_const_l (expr
, offset
);
3314 ax_simple (expr
, aop_add
);
3320 const gdb_byte
*datastart
;
3322 const struct block
*b
;
3323 struct symbol
*framefunc
;
3325 b
= block_for_pc (expr
->scope
);
3328 error (_("No block found for address"));
3330 framefunc
= block_linkage_function (b
);
3333 error (_("No function found for block"));
3335 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3336 &datastart
, &datalen
);
3338 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3339 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
3340 datastart
+ datalen
, per_cu
);
3341 if (loc
->kind
== axs_lvalue_register
)
3342 require_rvalue (expr
, loc
);
3346 ax_const_l (expr
, offset
);
3347 ax_simple (expr
, aop_add
);
3350 loc
->kind
= axs_lvalue_memory
;
3355 ax_simple (expr
, aop_dup
);
3359 ax_simple (expr
, aop_pop
);
3364 ax_pick (expr
, offset
);
3368 ax_simple (expr
, aop_swap
);
3376 ax_simple (expr
, aop_rot
);
3380 case DW_OP_deref_size
:
3384 if (op
== DW_OP_deref_size
)
3389 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3390 error (_("Unsupported size %d in %s"),
3391 size
, get_DW_OP_name (op
));
3392 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3397 /* Sign extend the operand. */
3398 ax_ext (expr
, addr_size_bits
);
3399 ax_simple (expr
, aop_dup
);
3400 ax_const_l (expr
, 0);
3401 ax_simple (expr
, aop_less_signed
);
3402 ax_simple (expr
, aop_log_not
);
3403 i
= ax_goto (expr
, aop_if_goto
);
3404 /* We have to emit 0 - X. */
3405 ax_const_l (expr
, 0);
3406 ax_simple (expr
, aop_swap
);
3407 ax_simple (expr
, aop_sub
);
3408 ax_label (expr
, i
, expr
->len
);
3412 /* No need to sign extend here. */
3413 ax_const_l (expr
, 0);
3414 ax_simple (expr
, aop_swap
);
3415 ax_simple (expr
, aop_sub
);
3419 /* Sign extend the operand. */
3420 ax_ext (expr
, addr_size_bits
);
3421 ax_simple (expr
, aop_bit_not
);
3424 case DW_OP_plus_uconst
:
3425 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3426 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3427 but we micro-optimize anyhow. */
3430 ax_const_l (expr
, reg
);
3431 ax_simple (expr
, aop_add
);
3436 ax_simple (expr
, aop_bit_and
);
3440 /* Sign extend the operands. */
3441 ax_ext (expr
, addr_size_bits
);
3442 ax_simple (expr
, aop_swap
);
3443 ax_ext (expr
, addr_size_bits
);
3444 ax_simple (expr
, aop_swap
);
3445 ax_simple (expr
, aop_div_signed
);
3449 ax_simple (expr
, aop_sub
);
3453 ax_simple (expr
, aop_rem_unsigned
);
3457 ax_simple (expr
, aop_mul
);
3461 ax_simple (expr
, aop_bit_or
);
3465 ax_simple (expr
, aop_add
);
3469 ax_simple (expr
, aop_lsh
);
3473 ax_simple (expr
, aop_rsh_unsigned
);
3477 ax_simple (expr
, aop_rsh_signed
);
3481 ax_simple (expr
, aop_bit_xor
);
3485 /* Sign extend the operands. */
3486 ax_ext (expr
, addr_size_bits
);
3487 ax_simple (expr
, aop_swap
);
3488 ax_ext (expr
, addr_size_bits
);
3489 /* Note no swap here: A <= B is !(B < A). */
3490 ax_simple (expr
, aop_less_signed
);
3491 ax_simple (expr
, aop_log_not
);
3495 /* Sign extend the operands. */
3496 ax_ext (expr
, addr_size_bits
);
3497 ax_simple (expr
, aop_swap
);
3498 ax_ext (expr
, addr_size_bits
);
3499 ax_simple (expr
, aop_swap
);
3500 /* A >= B is !(A < B). */
3501 ax_simple (expr
, aop_less_signed
);
3502 ax_simple (expr
, aop_log_not
);
3506 /* Sign extend the operands. */
3507 ax_ext (expr
, addr_size_bits
);
3508 ax_simple (expr
, aop_swap
);
3509 ax_ext (expr
, addr_size_bits
);
3510 /* No need for a second swap here. */
3511 ax_simple (expr
, aop_equal
);
3515 /* Sign extend the operands. */
3516 ax_ext (expr
, addr_size_bits
);
3517 ax_simple (expr
, aop_swap
);
3518 ax_ext (expr
, addr_size_bits
);
3519 ax_simple (expr
, aop_swap
);
3520 ax_simple (expr
, aop_less_signed
);
3524 /* Sign extend the operands. */
3525 ax_ext (expr
, addr_size_bits
);
3526 ax_simple (expr
, aop_swap
);
3527 ax_ext (expr
, addr_size_bits
);
3528 /* Note no swap here: A > B is B < A. */
3529 ax_simple (expr
, aop_less_signed
);
3533 /* Sign extend the operands. */
3534 ax_ext (expr
, addr_size_bits
);
3535 ax_simple (expr
, aop_swap
);
3536 ax_ext (expr
, addr_size_bits
);
3537 /* No need for a swap here. */
3538 ax_simple (expr
, aop_equal
);
3539 ax_simple (expr
, aop_log_not
);
3542 case DW_OP_call_frame_cfa
:
3545 CORE_ADDR text_offset
;
3547 const gdb_byte
*cfa_start
, *cfa_end
;
3549 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3551 &text_offset
, &cfa_start
, &cfa_end
))
3554 ax_reg (expr
, regnum
);
3557 ax_const_l (expr
, off
);
3558 ax_simple (expr
, aop_add
);
3563 /* Another expression. */
3564 ax_const_l (expr
, text_offset
);
3565 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3566 cfa_start
, cfa_end
, per_cu
);
3569 loc
->kind
= axs_lvalue_memory
;
3573 case DW_OP_GNU_push_tls_address
:
3574 case DW_OP_form_tls_address
:
3578 case DW_OP_push_object_address
:
3583 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3585 i
= ax_goto (expr
, aop_goto
);
3586 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3587 VEC_safe_push (int, patches
, i
);
3591 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3593 /* Zero extend the operand. */
3594 ax_zero_ext (expr
, addr_size_bits
);
3595 i
= ax_goto (expr
, aop_if_goto
);
3596 VEC_safe_push (int, dw_labels
, op_ptr
+ offset
- base
);
3597 VEC_safe_push (int, patches
, i
);
3604 case DW_OP_bit_piece
:
3606 uint64_t size
, offset
;
3608 if (op_ptr
- 1 == previous_piece
)
3609 error (_("Cannot translate empty pieces to agent expressions"));
3610 previous_piece
= op_ptr
- 1;
3612 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3613 if (op
== DW_OP_piece
)
3619 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3621 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3622 error (_("Expression pieces exceed word size"));
3624 /* Access the bits. */
3627 case axs_lvalue_register
:
3628 ax_reg (expr
, loc
->u
.reg
);
3631 case axs_lvalue_memory
:
3632 /* Offset the pointer, if needed. */
3635 ax_const_l (expr
, offset
/ 8);
3636 ax_simple (expr
, aop_add
);
3639 access_memory (arch
, expr
, size
);
3643 /* For a bits-big-endian target, shift up what we already
3644 have. For a bits-little-endian target, shift up the
3645 new data. Note that there is a potential bug here if
3646 the DWARF expression leaves multiple values on the
3648 if (bits_collected
> 0)
3650 if (bits_big_endian
)
3652 ax_simple (expr
, aop_swap
);
3653 ax_const_l (expr
, size
);
3654 ax_simple (expr
, aop_lsh
);
3655 /* We don't need a second swap here, because
3656 aop_bit_or is symmetric. */
3660 ax_const_l (expr
, size
);
3661 ax_simple (expr
, aop_lsh
);
3663 ax_simple (expr
, aop_bit_or
);
3666 bits_collected
+= size
;
3667 loc
->kind
= axs_rvalue
;
3671 case DW_OP_GNU_uninit
:
3677 struct dwarf2_locexpr_baton block
;
3678 int size
= (op
== DW_OP_call2
? 2 : 4);
3681 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3684 offset
.cu_off
= uoffset
;
3685 block
= dwarf2_fetch_die_loc_cu_off (offset
, per_cu
,
3688 /* DW_OP_call_ref is currently not supported. */
3689 gdb_assert (block
.per_cu
== per_cu
);
3691 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3692 block
.data
, block
.data
+ block
.size
,
3697 case DW_OP_call_ref
:
3705 /* Patch all the branches we emitted. */
3706 for (i
= 0; i
< VEC_length (int, patches
); ++i
)
3708 int targ
= offsets
[VEC_index (int, dw_labels
, i
)];
3710 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3711 ax_label (expr
, VEC_index (int, patches
, i
), targ
);
3714 do_cleanups (cleanups
);
3718 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3719 evaluator to calculate the location. */
3720 static struct value
*
3721 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3723 struct dwarf2_locexpr_baton
*dlbaton
3724 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3727 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3728 dlbaton
->size
, dlbaton
->per_cu
);
3733 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3734 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3737 static struct value
*
3738 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3740 struct dwarf2_locexpr_baton
*dlbaton
3741 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3743 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3747 /* Implementation of get_symbol_read_needs from
3748 symbol_computed_ops. */
3750 static enum symbol_needs_kind
3751 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3753 struct dwarf2_locexpr_baton
*dlbaton
3754 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3756 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3760 /* Return true if DATA points to the end of a piece. END is one past
3761 the last byte in the expression. */
3764 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3766 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3769 /* Helper for locexpr_describe_location_piece that finds the name of a
3773 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3777 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3778 We'd rather print *something* here than throw an error. */
3779 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3780 /* gdbarch_register_name may just return "", return something more
3781 descriptive for bad register numbers. */
3784 /* The text is output as "$bad_register_number".
3785 That is why we use the underscores. */
3786 return _("bad_register_number");
3788 return gdbarch_register_name (gdbarch
, regnum
);
3791 /* Nicely describe a single piece of a location, returning an updated
3792 position in the bytecode sequence. This function cannot recognize
3793 all locations; if a location is not recognized, it simply returns
3794 DATA. If there is an error during reading, e.g. we run off the end
3795 of the buffer, an error is thrown. */
3797 static const gdb_byte
*
3798 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3799 CORE_ADDR addr
, struct objfile
*objfile
,
3800 struct dwarf2_per_cu_data
*per_cu
,
3801 const gdb_byte
*data
, const gdb_byte
*end
,
3802 unsigned int addr_size
)
3804 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3807 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3809 fprintf_filtered (stream
, _("a variable in $%s"),
3810 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3813 else if (data
[0] == DW_OP_regx
)
3817 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3818 fprintf_filtered (stream
, _("a variable in $%s"),
3819 locexpr_regname (gdbarch
, reg
));
3821 else if (data
[0] == DW_OP_fbreg
)
3823 const struct block
*b
;
3824 struct symbol
*framefunc
;
3826 int64_t frame_offset
;
3827 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3829 int64_t base_offset
= 0;
3831 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3832 if (!piece_end_p (new_data
, end
))
3836 b
= block_for_pc (addr
);
3839 error (_("No block found for address for symbol \"%s\"."),
3840 SYMBOL_PRINT_NAME (symbol
));
3842 framefunc
= block_linkage_function (b
);
3845 error (_("No function found for block for symbol \"%s\"."),
3846 SYMBOL_PRINT_NAME (symbol
));
3848 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3850 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3852 const gdb_byte
*buf_end
;
3854 frame_reg
= base_data
[0] - DW_OP_breg0
;
3855 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3857 if (buf_end
!= base_data
+ base_size
)
3858 error (_("Unexpected opcode after "
3859 "DW_OP_breg%u for symbol \"%s\"."),
3860 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3862 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3864 /* The frame base is just the register, with no offset. */
3865 frame_reg
= base_data
[0] - DW_OP_reg0
;
3870 /* We don't know what to do with the frame base expression,
3871 so we can't trace this variable; give up. */
3875 fprintf_filtered (stream
,
3876 _("a variable at frame base reg $%s offset %s+%s"),
3877 locexpr_regname (gdbarch
, frame_reg
),
3878 plongest (base_offset
), plongest (frame_offset
));
3880 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3881 && piece_end_p (data
, end
))
3885 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3887 fprintf_filtered (stream
,
3888 _("a variable at offset %s from base reg $%s"),
3890 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3893 /* The location expression for a TLS variable looks like this (on a
3896 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3897 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3899 0x3 is the encoding for DW_OP_addr, which has an operand as long
3900 as the size of an address on the target machine (here is 8
3901 bytes). Note that more recent version of GCC emit DW_OP_const4u
3902 or DW_OP_const8u, depending on address size, rather than
3903 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3904 The operand represents the offset at which the variable is within
3905 the thread local storage. */
3907 else if (data
+ 1 + addr_size
< end
3908 && (data
[0] == DW_OP_addr
3909 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3910 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3911 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3912 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3913 && piece_end_p (data
+ 2 + addr_size
, end
))
3916 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3917 gdbarch_byte_order (gdbarch
));
3919 fprintf_filtered (stream
,
3920 _("a thread-local variable at offset 0x%s "
3921 "in the thread-local storage for `%s'"),
3922 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3924 data
+= 1 + addr_size
+ 1;
3927 /* With -gsplit-dwarf a TLS variable can also look like this:
3928 DW_AT_location : 3 byte block: fc 4 e0
3929 (DW_OP_GNU_const_index: 4;
3930 DW_OP_GNU_push_tls_address) */
3931 else if (data
+ 3 <= end
3932 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3933 && data
[0] == DW_OP_GNU_const_index
3935 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3936 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3937 && piece_end_p (data
+ 2 + leb128_size
, end
))
3941 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3942 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3943 fprintf_filtered (stream
,
3944 _("a thread-local variable at offset 0x%s "
3945 "in the thread-local storage for `%s'"),
3946 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3950 else if (data
[0] >= DW_OP_lit0
3951 && data
[0] <= DW_OP_lit31
3953 && data
[1] == DW_OP_stack_value
)
3955 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3962 /* Disassemble an expression, stopping at the end of a piece or at the
3963 end of the expression. Returns a pointer to the next unread byte
3964 in the input expression. If ALL is nonzero, then this function
3965 will keep going until it reaches the end of the expression.
3966 If there is an error during reading, e.g. we run off the end
3967 of the buffer, an error is thrown. */
3969 static const gdb_byte
*
3970 disassemble_dwarf_expression (struct ui_file
*stream
,
3971 struct gdbarch
*arch
, unsigned int addr_size
,
3972 int offset_size
, const gdb_byte
*start
,
3973 const gdb_byte
*data
, const gdb_byte
*end
,
3974 int indent
, int all
,
3975 struct dwarf2_per_cu_data
*per_cu
)
3979 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3981 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3986 name
= get_DW_OP_name (op
);
3989 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3990 op
, (long) (data
- 1 - start
));
3991 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3992 (long) (data
- 1 - start
), name
);
3997 ul
= extract_unsigned_integer (data
, addr_size
,
3998 gdbarch_byte_order (arch
));
4000 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4004 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
4006 fprintf_filtered (stream
, " %s", pulongest (ul
));
4009 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
4011 fprintf_filtered (stream
, " %s", plongest (l
));
4014 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4016 fprintf_filtered (stream
, " %s", pulongest (ul
));
4019 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4021 fprintf_filtered (stream
, " %s", plongest (l
));
4024 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4026 fprintf_filtered (stream
, " %s", pulongest (ul
));
4029 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4031 fprintf_filtered (stream
, " %s", plongest (l
));
4034 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4036 fprintf_filtered (stream
, " %s", pulongest (ul
));
4039 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4041 fprintf_filtered (stream
, " %s", plongest (l
));
4044 data
= safe_read_uleb128 (data
, end
, &ul
);
4045 fprintf_filtered (stream
, " %s", pulongest (ul
));
4048 data
= safe_read_sleb128 (data
, end
, &l
);
4049 fprintf_filtered (stream
, " %s", plongest (l
));
4084 fprintf_filtered (stream
, " [$%s]",
4085 locexpr_regname (arch
, op
- DW_OP_reg0
));
4089 data
= safe_read_uleb128 (data
, end
, &ul
);
4090 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4091 locexpr_regname (arch
, (int) ul
));
4094 case DW_OP_implicit_value
:
4095 data
= safe_read_uleb128 (data
, end
, &ul
);
4097 fprintf_filtered (stream
, " %s", pulongest (ul
));
4132 data
= safe_read_sleb128 (data
, end
, &l
);
4133 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4134 locexpr_regname (arch
, op
- DW_OP_breg0
));
4138 data
= safe_read_uleb128 (data
, end
, &ul
);
4139 data
= safe_read_sleb128 (data
, end
, &l
);
4140 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4142 locexpr_regname (arch
, (int) ul
),
4147 data
= safe_read_sleb128 (data
, end
, &l
);
4148 fprintf_filtered (stream
, " %s", plongest (l
));
4151 case DW_OP_xderef_size
:
4152 case DW_OP_deref_size
:
4154 fprintf_filtered (stream
, " %d", *data
);
4158 case DW_OP_plus_uconst
:
4159 data
= safe_read_uleb128 (data
, end
, &ul
);
4160 fprintf_filtered (stream
, " %s", pulongest (ul
));
4164 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4166 fprintf_filtered (stream
, " to %ld",
4167 (long) (data
+ l
- start
));
4171 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4173 fprintf_filtered (stream
, " %ld",
4174 (long) (data
+ l
- start
));
4178 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4180 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4184 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4186 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4189 case DW_OP_call_ref
:
4190 ul
= extract_unsigned_integer (data
, offset_size
,
4191 gdbarch_byte_order (arch
));
4192 data
+= offset_size
;
4193 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4197 data
= safe_read_uleb128 (data
, end
, &ul
);
4198 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4201 case DW_OP_bit_piece
:
4205 data
= safe_read_uleb128 (data
, end
, &ul
);
4206 data
= safe_read_uleb128 (data
, end
, &offset
);
4207 fprintf_filtered (stream
, " size %s offset %s (bits)",
4208 pulongest (ul
), pulongest (offset
));
4212 case DW_OP_GNU_implicit_pointer
:
4214 ul
= extract_unsigned_integer (data
, offset_size
,
4215 gdbarch_byte_order (arch
));
4216 data
+= offset_size
;
4218 data
= safe_read_sleb128 (data
, end
, &l
);
4220 fprintf_filtered (stream
, " DIE %s offset %s",
4221 phex_nz (ul
, offset_size
),
4226 case DW_OP_GNU_deref_type
:
4228 int addr_size
= *data
++;
4232 data
= safe_read_uleb128 (data
, end
, &ul
);
4234 type
= dwarf2_get_die_type (offset
, per_cu
);
4235 fprintf_filtered (stream
, "<");
4236 type_print (type
, "", stream
, -1);
4237 fprintf_filtered (stream
, " [0x%s]> %d", phex_nz (offset
.cu_off
, 0),
4242 case DW_OP_GNU_const_type
:
4247 data
= safe_read_uleb128 (data
, end
, &ul
);
4248 type_die
.cu_off
= ul
;
4249 type
= dwarf2_get_die_type (type_die
, per_cu
);
4250 fprintf_filtered (stream
, "<");
4251 type_print (type
, "", stream
, -1);
4252 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
4256 case DW_OP_GNU_regval_type
:
4262 data
= safe_read_uleb128 (data
, end
, ®
);
4263 data
= safe_read_uleb128 (data
, end
, &ul
);
4264 type_die
.cu_off
= ul
;
4266 type
= dwarf2_get_die_type (type_die
, per_cu
);
4267 fprintf_filtered (stream
, "<");
4268 type_print (type
, "", stream
, -1);
4269 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4270 phex_nz (type_die
.cu_off
, 0),
4271 locexpr_regname (arch
, reg
));
4275 case DW_OP_GNU_convert
:
4276 case DW_OP_GNU_reinterpret
:
4280 data
= safe_read_uleb128 (data
, end
, &ul
);
4281 type_die
.cu_off
= ul
;
4283 if (type_die
.cu_off
== 0)
4284 fprintf_filtered (stream
, "<0>");
4289 type
= dwarf2_get_die_type (type_die
, per_cu
);
4290 fprintf_filtered (stream
, "<");
4291 type_print (type
, "", stream
, -1);
4292 fprintf_filtered (stream
, " [0x%s]>", phex_nz (type_die
.cu_off
, 0));
4297 case DW_OP_GNU_entry_value
:
4298 data
= safe_read_uleb128 (data
, end
, &ul
);
4299 fputc_filtered ('\n', stream
);
4300 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4301 start
, data
, data
+ ul
, indent
+ 2,
4306 case DW_OP_GNU_parameter_ref
:
4307 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4309 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4312 case DW_OP_GNU_addr_index
:
4313 data
= safe_read_uleb128 (data
, end
, &ul
);
4314 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4315 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4317 case DW_OP_GNU_const_index
:
4318 data
= safe_read_uleb128 (data
, end
, &ul
);
4319 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4320 fprintf_filtered (stream
, " %s", pulongest (ul
));
4324 fprintf_filtered (stream
, "\n");
4330 /* Describe a single location, which may in turn consist of multiple
4334 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4335 struct ui_file
*stream
,
4336 const gdb_byte
*data
, size_t size
,
4337 struct objfile
*objfile
, unsigned int addr_size
,
4338 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4340 const gdb_byte
*end
= data
+ size
;
4341 int first_piece
= 1, bad
= 0;
4345 const gdb_byte
*here
= data
;
4346 int disassemble
= 1;
4351 fprintf_filtered (stream
, _(", and "));
4353 if (!dwarf_always_disassemble
)
4355 data
= locexpr_describe_location_piece (symbol
, stream
,
4356 addr
, objfile
, per_cu
,
4357 data
, end
, addr_size
);
4358 /* If we printed anything, or if we have an empty piece,
4359 then don't disassemble. */
4361 || data
[0] == DW_OP_piece
4362 || data
[0] == DW_OP_bit_piece
)
4367 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4368 data
= disassemble_dwarf_expression (stream
,
4369 get_objfile_arch (objfile
),
4370 addr_size
, offset_size
, data
,
4372 dwarf_always_disassemble
,
4378 int empty
= data
== here
;
4381 fprintf_filtered (stream
, " ");
4382 if (data
[0] == DW_OP_piece
)
4386 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4389 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4392 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4395 else if (data
[0] == DW_OP_bit_piece
)
4397 uint64_t bits
, offset
;
4399 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4400 data
= safe_read_uleb128 (data
, end
, &offset
);
4403 fprintf_filtered (stream
,
4404 _("an empty %s-bit piece"),
4407 fprintf_filtered (stream
,
4408 _(" [%s-bit piece, offset %s bits]"),
4409 pulongest (bits
), pulongest (offset
));
4419 if (bad
|| data
> end
)
4420 error (_("Corrupted DWARF2 expression for \"%s\"."),
4421 SYMBOL_PRINT_NAME (symbol
));
4424 /* Print a natural-language description of SYMBOL to STREAM. This
4425 version is for a symbol with a single location. */
4428 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4429 struct ui_file
*stream
)
4431 struct dwarf2_locexpr_baton
*dlbaton
4432 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4433 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4434 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4435 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4437 locexpr_describe_location_1 (symbol
, addr
, stream
,
4438 dlbaton
->data
, dlbaton
->size
,
4439 objfile
, addr_size
, offset_size
,
4443 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4444 any necessary bytecode in AX. */
4447 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4448 struct agent_expr
*ax
, struct axs_value
*value
)
4450 struct dwarf2_locexpr_baton
*dlbaton
4451 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4452 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4454 if (dlbaton
->size
== 0)
4455 value
->optimized_out
= 1;
4457 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
4458 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4462 /* symbol_computed_ops 'generate_c_location' method. */
4465 locexpr_generate_c_location (struct symbol
*sym
, struct ui_file
*stream
,
4466 struct gdbarch
*gdbarch
,
4467 unsigned char *registers_used
,
4468 CORE_ADDR pc
, const char *result_name
)
4470 struct dwarf2_locexpr_baton
*dlbaton
4471 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4472 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4474 if (dlbaton
->size
== 0)
4475 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4477 compile_dwarf_expr_to_c (stream
, result_name
,
4478 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4479 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4483 /* The set of location functions used with the DWARF-2 expression
4485 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4486 locexpr_read_variable
,
4487 locexpr_read_variable_at_entry
,
4488 locexpr_get_symbol_read_needs
,
4489 locexpr_describe_location
,
4490 0, /* location_has_loclist */
4491 locexpr_tracepoint_var_ref
,
4492 locexpr_generate_c_location
4496 /* Wrapper functions for location lists. These generally find
4497 the appropriate location expression and call something above. */
4499 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4500 evaluator to calculate the location. */
4501 static struct value
*
4502 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4504 struct dwarf2_loclist_baton
*dlbaton
4505 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4507 const gdb_byte
*data
;
4509 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4511 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4512 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4518 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4519 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4522 Function always returns non-NULL value, it may be marked optimized out if
4523 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4524 if it cannot resolve the parameter for any reason. */
4526 static struct value
*
4527 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4529 struct dwarf2_loclist_baton
*dlbaton
4530 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4531 const gdb_byte
*data
;
4535 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4536 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4538 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4540 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4542 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4545 /* Implementation of get_symbol_read_needs from
4546 symbol_computed_ops. */
4548 static enum symbol_needs_kind
4549 loclist_symbol_needs (struct symbol
*symbol
)
4551 /* If there's a location list, then assume we need to have a frame
4552 to choose the appropriate location expression. With tracking of
4553 global variables this is not necessarily true, but such tracking
4554 is disabled in GCC at the moment until we figure out how to
4557 return SYMBOL_NEEDS_FRAME
;
4560 /* Print a natural-language description of SYMBOL to STREAM. This
4561 version applies when there is a list of different locations, each
4562 with a specified address range. */
4565 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4566 struct ui_file
*stream
)
4568 struct dwarf2_loclist_baton
*dlbaton
4569 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4570 const gdb_byte
*loc_ptr
, *buf_end
;
4571 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4572 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4573 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4574 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4575 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4576 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4577 /* Adjust base_address for relocatable objects. */
4578 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4579 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4582 loc_ptr
= dlbaton
->data
;
4583 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4585 fprintf_filtered (stream
, _("multi-location:\n"));
4587 /* Iterate through locations until we run out. */
4590 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4592 enum debug_loc_kind kind
;
4593 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4595 if (dlbaton
->from_dwo
)
4596 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4597 loc_ptr
, buf_end
, &new_ptr
,
4598 &low
, &high
, byte_order
);
4600 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4602 byte_order
, addr_size
,
4607 case DEBUG_LOC_END_OF_LIST
:
4610 case DEBUG_LOC_BASE_ADDRESS
:
4611 base_address
= high
+ base_offset
;
4612 fprintf_filtered (stream
, _(" Base address %s"),
4613 paddress (gdbarch
, base_address
));
4615 case DEBUG_LOC_START_END
:
4616 case DEBUG_LOC_START_LENGTH
:
4618 case DEBUG_LOC_BUFFER_OVERFLOW
:
4619 case DEBUG_LOC_INVALID_ENTRY
:
4620 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4621 SYMBOL_PRINT_NAME (symbol
));
4623 gdb_assert_not_reached ("bad debug_loc_kind");
4626 /* Otherwise, a location expression entry. */
4627 low
+= base_address
;
4628 high
+= base_address
;
4630 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4631 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4633 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4636 /* (It would improve readability to print only the minimum
4637 necessary digits of the second number of the range.) */
4638 fprintf_filtered (stream
, _(" Range %s-%s: "),
4639 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4641 /* Now describe this particular location. */
4642 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4643 objfile
, addr_size
, offset_size
,
4646 fprintf_filtered (stream
, "\n");
4652 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4653 any necessary bytecode in AX. */
4655 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4656 struct agent_expr
*ax
, struct axs_value
*value
)
4658 struct dwarf2_loclist_baton
*dlbaton
4659 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4660 const gdb_byte
*data
;
4662 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4664 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4666 value
->optimized_out
= 1;
4668 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4672 /* symbol_computed_ops 'generate_c_location' method. */
4675 loclist_generate_c_location (struct symbol
*sym
, struct ui_file
*stream
,
4676 struct gdbarch
*gdbarch
,
4677 unsigned char *registers_used
,
4678 CORE_ADDR pc
, const char *result_name
)
4680 struct dwarf2_loclist_baton
*dlbaton
4681 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4682 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4683 const gdb_byte
*data
;
4686 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4688 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4690 compile_dwarf_expr_to_c (stream
, result_name
,
4691 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4696 /* The set of location functions used with the DWARF-2 expression
4697 evaluator and location lists. */
4698 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4699 loclist_read_variable
,
4700 loclist_read_variable_at_entry
,
4701 loclist_symbol_needs
,
4702 loclist_describe_location
,
4703 1, /* location_has_loclist */
4704 loclist_tracepoint_var_ref
,
4705 loclist_generate_c_location
4708 /* Provide a prototype to silence -Wmissing-prototypes. */
4709 extern initialize_file_ftype _initialize_dwarf2loc
;
4712 _initialize_dwarf2loc (void)
4714 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4715 &entry_values_debug
,
4716 _("Set entry values and tail call frames "
4718 _("Show entry values and tail call frames "
4720 _("When non-zero, the process of determining "
4721 "parameter values from function entry point "
4722 "and tail call frames will be printed."),
4724 show_entry_values_debug
,
4725 &setdebuglist
, &showdebuglist
);