1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2020 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 "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
51 struct frame_info
*frame
,
54 struct dwarf2_per_cu_data
*per_cu
,
55 struct type
*subobj_type
,
56 LONGEST subobj_byte_offset
);
58 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
59 (struct frame_info
*frame
,
60 enum call_site_parameter_kind kind
,
61 union call_site_parameter_u kind_u
,
62 struct dwarf2_per_cu_data
**per_cu_return
);
64 static struct value
*indirect_synthetic_pointer
65 (sect_offset die
, LONGEST byte_offset
,
66 struct dwarf2_per_cu_data
*per_cu
,
67 struct frame_info
*frame
,
68 struct type
*type
, bool resolve_abstract_p
= false);
70 /* Until these have formal names, we define these here.
71 ref: http://gcc.gnu.org/wiki/DebugFission
72 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
73 and is then followed by data specific to that entry. */
77 /* Indicates the end of the list of entries. */
78 DEBUG_LOC_END_OF_LIST
= 0,
80 /* This is followed by an unsigned LEB128 number that is an index into
81 .debug_addr and specifies the base address for all following entries. */
82 DEBUG_LOC_BASE_ADDRESS
= 1,
84 /* This is followed by two unsigned LEB128 numbers that are indices into
85 .debug_addr and specify the beginning and ending addresses, and then
86 a normal location expression as in .debug_loc. */
87 DEBUG_LOC_START_END
= 2,
89 /* This is followed by an unsigned LEB128 number that is an index into
90 .debug_addr and specifies the beginning address, and a 4 byte unsigned
91 number that specifies the length, and then a normal location expression
93 DEBUG_LOC_START_LENGTH
= 3,
95 /* An internal value indicating there is insufficient data. */
96 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
98 /* An internal value indicating an invalid kind of entry was found. */
99 DEBUG_LOC_INVALID_ENTRY
= -2
102 /* Helper function which throws an error if a synthetic pointer is
106 invalid_synthetic_pointer (void)
108 error (_("access outside bounds of object "
109 "referenced via synthetic pointer"));
112 /* Decode the addresses in a non-dwo .debug_loc entry.
113 A pointer to the next byte to examine is returned in *NEW_PTR.
114 The encoded low,high addresses are return in *LOW,*HIGH.
115 The result indicates the kind of entry found. */
117 static enum debug_loc_kind
118 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
119 const gdb_byte
**new_ptr
,
120 CORE_ADDR
*low
, CORE_ADDR
*high
,
121 enum bfd_endian byte_order
,
122 unsigned int addr_size
,
125 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
127 if (buf_end
- loc_ptr
< 2 * addr_size
)
128 return DEBUG_LOC_BUFFER_OVERFLOW
;
131 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
133 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
134 loc_ptr
+= addr_size
;
137 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
139 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
140 loc_ptr
+= addr_size
;
144 /* A base-address-selection entry. */
145 if ((*low
& base_mask
) == base_mask
)
146 return DEBUG_LOC_BASE_ADDRESS
;
148 /* An end-of-list entry. */
149 if (*low
== 0 && *high
== 0)
150 return DEBUG_LOC_END_OF_LIST
;
152 return DEBUG_LOC_START_END
;
155 /* Decode the addresses in .debug_loclists entry.
156 A pointer to the next byte to examine is returned in *NEW_PTR.
157 The encoded low,high addresses are return in *LOW,*HIGH.
158 The result indicates the kind of entry found. */
160 static enum debug_loc_kind
161 decode_debug_loclists_addresses (struct dwarf2_per_cu_data
*per_cu
,
162 const gdb_byte
*loc_ptr
,
163 const gdb_byte
*buf_end
,
164 const gdb_byte
**new_ptr
,
165 CORE_ADDR
*low
, CORE_ADDR
*high
,
166 enum bfd_endian byte_order
,
167 unsigned int addr_size
,
172 if (loc_ptr
== buf_end
)
173 return DEBUG_LOC_BUFFER_OVERFLOW
;
177 case DW_LLE_base_addressx
:
179 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
181 return DEBUG_LOC_BUFFER_OVERFLOW
;
182 *high
= dwarf2_read_addr_index (per_cu
, u64
);
184 return DEBUG_LOC_BASE_ADDRESS
;
185 case DW_LLE_startx_length
:
186 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
188 return DEBUG_LOC_BUFFER_OVERFLOW
;
189 *low
= dwarf2_read_addr_index (per_cu
, u64
);
191 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
193 return DEBUG_LOC_BUFFER_OVERFLOW
;
196 return DEBUG_LOC_START_LENGTH
;
197 case DW_LLE_start_length
:
198 if (buf_end
- loc_ptr
< addr_size
)
199 return DEBUG_LOC_BUFFER_OVERFLOW
;
201 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
203 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
204 loc_ptr
+= addr_size
;
206 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
208 return DEBUG_LOC_BUFFER_OVERFLOW
;
211 return DEBUG_LOC_START_LENGTH
;
212 case DW_LLE_end_of_list
:
214 return DEBUG_LOC_END_OF_LIST
;
215 case DW_LLE_base_address
:
216 if (loc_ptr
+ addr_size
> buf_end
)
217 return DEBUG_LOC_BUFFER_OVERFLOW
;
219 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
221 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
222 loc_ptr
+= addr_size
;
224 return DEBUG_LOC_BASE_ADDRESS
;
225 case DW_LLE_offset_pair
:
226 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
228 return DEBUG_LOC_BUFFER_OVERFLOW
;
230 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
232 return DEBUG_LOC_BUFFER_OVERFLOW
;
235 return DEBUG_LOC_START_END
;
236 /* Following cases are not supported yet. */
237 case DW_LLE_startx_endx
:
238 case DW_LLE_start_end
:
239 case DW_LLE_default_location
:
241 return DEBUG_LOC_INVALID_ENTRY
;
245 /* Decode the addresses in .debug_loc.dwo entry.
246 A pointer to the next byte to examine is returned in *NEW_PTR.
247 The encoded low,high addresses are return in *LOW,*HIGH.
248 The result indicates the kind of entry found. */
250 static enum debug_loc_kind
251 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
252 const gdb_byte
*loc_ptr
,
253 const gdb_byte
*buf_end
,
254 const gdb_byte
**new_ptr
,
255 CORE_ADDR
*low
, CORE_ADDR
*high
,
256 enum bfd_endian byte_order
)
258 uint64_t low_index
, high_index
;
260 if (loc_ptr
== buf_end
)
261 return DEBUG_LOC_BUFFER_OVERFLOW
;
265 case DW_LLE_GNU_end_of_list_entry
:
267 return DEBUG_LOC_END_OF_LIST
;
268 case DW_LLE_GNU_base_address_selection_entry
:
270 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
272 return DEBUG_LOC_BUFFER_OVERFLOW
;
273 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
275 return DEBUG_LOC_BASE_ADDRESS
;
276 case DW_LLE_GNU_start_end_entry
:
277 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
279 return DEBUG_LOC_BUFFER_OVERFLOW
;
280 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
281 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
283 return DEBUG_LOC_BUFFER_OVERFLOW
;
284 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
286 return DEBUG_LOC_START_END
;
287 case DW_LLE_GNU_start_length_entry
:
288 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
290 return DEBUG_LOC_BUFFER_OVERFLOW
;
291 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
292 if (loc_ptr
+ 4 > buf_end
)
293 return DEBUG_LOC_BUFFER_OVERFLOW
;
295 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
296 *new_ptr
= loc_ptr
+ 4;
297 return DEBUG_LOC_START_LENGTH
;
299 return DEBUG_LOC_INVALID_ENTRY
;
303 /* A function for dealing with location lists. Given a
304 symbol baton (BATON) and a pc value (PC), find the appropriate
305 location expression, set *LOCEXPR_LENGTH, and return a pointer
306 to the beginning of the expression. Returns NULL on failure.
308 For now, only return the first matching location expression; there
309 can be more than one in the list. */
312 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
313 size_t *locexpr_length
, CORE_ADDR pc
)
315 struct objfile
*objfile
= baton
->per_cu
->objfile ();
316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
317 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
318 unsigned int addr_size
= baton
->per_cu
->addr_size ();
319 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
320 /* Adjust base_address for relocatable objects. */
321 CORE_ADDR base_offset
= baton
->per_cu
->text_offset ();
322 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
323 const gdb_byte
*loc_ptr
, *buf_end
;
325 loc_ptr
= baton
->data
;
326 buf_end
= baton
->data
+ baton
->size
;
330 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
332 enum debug_loc_kind kind
;
333 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
336 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
337 loc_ptr
, buf_end
, &new_ptr
,
338 &low
, &high
, byte_order
);
339 else if (baton
->per_cu
->version () < 5)
340 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
342 byte_order
, addr_size
,
345 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
346 loc_ptr
, buf_end
, &new_ptr
,
347 &low
, &high
, byte_order
,
348 addr_size
, signed_addr_p
);
353 case DEBUG_LOC_END_OF_LIST
:
356 case DEBUG_LOC_BASE_ADDRESS
:
357 base_address
= high
+ base_offset
;
359 case DEBUG_LOC_START_END
:
360 case DEBUG_LOC_START_LENGTH
:
362 case DEBUG_LOC_BUFFER_OVERFLOW
:
363 case DEBUG_LOC_INVALID_ENTRY
:
364 error (_("dwarf2_find_location_expression: "
365 "Corrupted DWARF expression."));
367 gdb_assert_not_reached ("bad debug_loc_kind");
370 /* Otherwise, a location expression entry.
371 If the entry is from a DWO, don't add base address: the entry is from
372 .debug_addr which already has the DWARF "base address". We still add
373 base_offset in case we're debugging a PIE executable. */
382 high
+= base_address
;
385 if (baton
->per_cu
->version () < 5)
387 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
392 unsigned int bytes_read
;
394 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
395 loc_ptr
+= bytes_read
;
398 if (low
== high
&& pc
== low
)
400 /* This is entry PC record present only at entry point
401 of a function. Verify it is really the function entry point. */
403 const struct block
*pc_block
= block_for_pc (pc
);
404 struct symbol
*pc_func
= NULL
;
407 pc_func
= block_linkage_function (pc_block
);
409 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
411 *locexpr_length
= length
;
416 if (pc
>= low
&& pc
< high
)
418 *locexpr_length
= length
;
426 /* This is the baton used when performing dwarf2 expression
428 struct dwarf_expr_baton
430 struct frame_info
*frame
;
431 struct dwarf2_per_cu_data
*per_cu
;
432 CORE_ADDR obj_address
;
435 /* Implement find_frame_base_location method for LOC_BLOCK functions using
436 DWARF expression for its DW_AT_frame_base. */
439 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
440 const gdb_byte
**start
, size_t *length
)
442 struct dwarf2_locexpr_baton
*symbaton
443 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
445 *length
= symbaton
->size
;
446 *start
= symbaton
->data
;
449 /* Implement the struct symbol_block_ops::get_frame_base method for
450 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
453 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
455 struct gdbarch
*gdbarch
;
457 struct dwarf2_locexpr_baton
*dlbaton
;
458 const gdb_byte
*start
;
460 struct value
*result
;
462 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
463 Thus, it's supposed to provide the find_frame_base_location method as
465 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
467 gdbarch
= get_frame_arch (frame
);
468 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
469 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
471 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
472 (framefunc
, get_frame_pc (frame
), &start
, &length
);
473 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
476 /* The DW_AT_frame_base attribute contains a location description which
477 computes the base address itself. However, the call to
478 dwarf2_evaluate_loc_desc returns a value representing a variable at
479 that address. The frame base address is thus this variable's
481 return value_address (result
);
484 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
485 function uses DWARF expression for its DW_AT_frame_base. */
487 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
489 locexpr_find_frame_base_location
,
490 locexpr_get_frame_base
493 /* Implement find_frame_base_location method for LOC_BLOCK functions using
494 DWARF location list for its DW_AT_frame_base. */
497 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
498 const gdb_byte
**start
, size_t *length
)
500 struct dwarf2_loclist_baton
*symbaton
501 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
503 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
506 /* Implement the struct symbol_block_ops::get_frame_base method for
507 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
510 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
512 struct gdbarch
*gdbarch
;
514 struct dwarf2_loclist_baton
*dlbaton
;
515 const gdb_byte
*start
;
517 struct value
*result
;
519 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
520 Thus, it's supposed to provide the find_frame_base_location method as
522 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
524 gdbarch
= get_frame_arch (frame
);
525 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
526 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
528 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
529 (framefunc
, get_frame_pc (frame
), &start
, &length
);
530 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
533 /* The DW_AT_frame_base attribute contains a location description which
534 computes the base address itself. However, the call to
535 dwarf2_evaluate_loc_desc returns a value representing a variable at
536 that address. The frame base address is thus this variable's
538 return value_address (result
);
541 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
542 function uses DWARF location list for its DW_AT_frame_base. */
544 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
546 loclist_find_frame_base_location
,
547 loclist_get_frame_base
550 /* See dwarf2loc.h. */
553 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
554 const gdb_byte
**start
, size_t *length
)
556 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
558 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
560 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
566 error (_("Could not find the frame base for \"%s\"."),
567 framefunc
->natural_name ());
571 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
573 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
575 return ctx
->get_frame_pc ();
579 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
580 struct dwarf2_per_cu_data
*per_cu
)
582 struct dwarf2_locexpr_baton block
;
584 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
,
585 get_frame_pc_for_per_cu_dwarf_call
,
588 /* DW_OP_call_ref is currently not supported. */
589 gdb_assert (block
.per_cu
== per_cu
);
591 ctx
->eval (block
.data
, block
.size
);
594 /* Given context CTX, section offset SECT_OFF, and compilation unit
595 data PER_CU, execute the "variable value" operation on the DIE
596 found at SECT_OFF. */
598 static struct value
*
599 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
600 struct dwarf2_per_cu_data
*per_cu
)
602 struct type
*die_type
= dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
);
604 if (die_type
== NULL
)
605 error (_("Bad DW_OP_GNU_variable_value DIE."));
607 /* Note: Things still work when the following test is removed. This
608 test and error is here to conform to the proposed specification. */
609 if (TYPE_CODE (die_type
) != TYPE_CODE_INT
610 && TYPE_CODE (die_type
) != TYPE_CODE_PTR
)
611 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
613 struct type
*type
= lookup_pointer_type (die_type
);
614 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
615 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, frame
, type
, true);
618 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
622 struct frame_info
*frame
;
623 struct dwarf2_per_cu_data
*per_cu
;
624 CORE_ADDR obj_address
;
626 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
627 the frame in BATON. */
629 CORE_ADDR
get_frame_cfa () override
631 return dwarf2_frame_cfa (frame
);
634 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
635 the frame in BATON. */
637 CORE_ADDR
get_frame_pc () override
639 return get_frame_address_in_block (frame
);
642 /* Using the objfile specified in BATON, find the address for the
643 current thread's thread-local storage with offset OFFSET. */
644 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
646 struct objfile
*objfile
= per_cu
->objfile ();
648 return target_translate_tls_address (objfile
, offset
);
651 /* Helper interface of per_cu_dwarf_call for
652 dwarf2_evaluate_loc_desc. */
654 void dwarf_call (cu_offset die_offset
) override
656 per_cu_dwarf_call (this, die_offset
, per_cu
);
659 /* Helper interface of sect_variable_value for
660 dwarf2_evaluate_loc_desc. */
662 struct value
*dwarf_variable_value (sect_offset sect_off
) override
664 return sect_variable_value (this, sect_off
, per_cu
);
667 struct type
*get_base_type (cu_offset die_offset
, int size
) override
669 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
671 error (_("Could not find type for DW_OP_const_type"));
672 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
673 error (_("DW_OP_const_type has different sizes for type and data"));
677 /* Callback function for dwarf2_evaluate_loc_desc.
678 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
680 CORE_ADDR
get_addr_index (unsigned int index
) override
682 return dwarf2_read_addr_index (per_cu
, index
);
685 /* Callback function for get_object_address. Return the address of the VLA
688 CORE_ADDR
get_object_address () override
690 if (obj_address
== 0)
691 error (_("Location address is not set."));
695 /* Execute DWARF block of call_site_parameter which matches KIND and
696 KIND_U. Choose DEREF_SIZE value of that parameter. Search
697 caller of this objects's frame.
699 The caller can be from a different CU - per_cu_dwarf_call
700 implementation can be more simple as it does not support cross-CU
703 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
704 union call_site_parameter_u kind_u
,
705 int deref_size
) override
707 struct frame_info
*caller_frame
;
708 struct dwarf2_per_cu_data
*caller_per_cu
;
709 struct call_site_parameter
*parameter
;
710 const gdb_byte
*data_src
;
713 caller_frame
= get_prev_frame (frame
);
715 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
717 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
718 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
720 /* DEREF_SIZE size is not verified here. */
721 if (data_src
== NULL
)
722 throw_error (NO_ENTRY_VALUE_ERROR
,
723 _("Cannot resolve DW_AT_call_data_value"));
725 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
727 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
729 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
732 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
733 this->gdbarch
= get_objfile_arch (per_cu
->objfile ());
734 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
735 this->addr_size
= per_cu
->addr_size ();
736 scoped_restore save_offset
= make_scoped_restore (&this->offset
);
737 this->offset
= per_cu
->text_offset ();
739 this->eval (data_src
, size
);
742 /* Using the frame specified in BATON, find the location expression
743 describing the frame base. Return a pointer to it in START and
744 its length in LENGTH. */
745 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
747 /* FIXME: cagney/2003-03-26: This code should be using
748 get_frame_base_address(), and then implement a dwarf2 specific
750 struct symbol
*framefunc
;
751 const struct block
*bl
= get_frame_block (frame
, NULL
);
754 error (_("frame address is not available."));
756 /* Use block_linkage_function, which returns a real (not inlined)
757 function, instead of get_frame_function, which may return an
759 framefunc
= block_linkage_function (bl
);
761 /* If we found a frame-relative symbol then it was certainly within
762 some function associated with a frame. If we can't find the frame,
763 something has gone wrong. */
764 gdb_assert (framefunc
!= NULL
);
766 func_get_frame_base_dwarf_block (framefunc
,
767 get_frame_address_in_block (frame
),
771 /* Read memory at ADDR (length LEN) into BUF. */
773 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
775 read_memory (addr
, buf
, len
);
778 /* Using the frame specified in BATON, return the value of register
779 REGNUM, treated as a pointer. */
780 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
782 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
783 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
785 return address_from_register (regnum
, frame
);
788 /* Implement "get_reg_value" callback. */
790 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
792 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
793 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
795 return value_from_register (type
, regnum
, frame
);
799 /* See dwarf2loc.h. */
801 unsigned int entry_values_debug
= 0;
803 /* Helper to set entry_values_debug. */
806 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
807 struct cmd_list_element
*c
, const char *value
)
809 fprintf_filtered (file
,
810 _("Entry values and tail call frames debugging is %s.\n"),
814 /* Find DW_TAG_call_site's DW_AT_call_target address.
815 CALLER_FRAME (for registers) can be NULL if it is not known. This function
816 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
819 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
820 struct call_site
*call_site
,
821 struct frame_info
*caller_frame
)
823 switch (FIELD_LOC_KIND (call_site
->target
))
825 case FIELD_LOC_KIND_DWARF_BLOCK
:
827 struct dwarf2_locexpr_baton
*dwarf_block
;
829 struct type
*caller_core_addr_type
;
830 struct gdbarch
*caller_arch
;
832 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
833 if (dwarf_block
== NULL
)
835 struct bound_minimal_symbol msym
;
837 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
838 throw_error (NO_ENTRY_VALUE_ERROR
,
839 _("DW_AT_call_target is not specified at %s in %s"),
840 paddress (call_site_gdbarch
, call_site
->pc
),
841 (msym
.minsym
== NULL
? "???"
842 : msym
.minsym
->print_name ()));
845 if (caller_frame
== NULL
)
847 struct bound_minimal_symbol msym
;
849 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
850 throw_error (NO_ENTRY_VALUE_ERROR
,
851 _("DW_AT_call_target DWARF block resolving "
852 "requires known frame which is currently not "
853 "available at %s in %s"),
854 paddress (call_site_gdbarch
, call_site
->pc
),
855 (msym
.minsym
== NULL
? "???"
856 : msym
.minsym
->print_name ()));
859 caller_arch
= get_frame_arch (caller_frame
);
860 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
861 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
862 dwarf_block
->data
, dwarf_block
->size
,
863 dwarf_block
->per_cu
);
864 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
865 if (VALUE_LVAL (val
) == lval_memory
)
866 return value_address (val
);
868 return value_as_address (val
);
871 case FIELD_LOC_KIND_PHYSNAME
:
873 const char *physname
;
874 struct bound_minimal_symbol msym
;
876 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
878 /* Handle both the mangled and demangled PHYSNAME. */
879 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
880 if (msym
.minsym
== NULL
)
882 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
883 throw_error (NO_ENTRY_VALUE_ERROR
,
884 _("Cannot find function \"%s\" for a call site target "
886 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
887 (msym
.minsym
== NULL
? "???"
888 : msym
.minsym
->print_name ()));
891 return BMSYMBOL_VALUE_ADDRESS (msym
);
894 case FIELD_LOC_KIND_PHYSADDR
:
895 return FIELD_STATIC_PHYSADDR (call_site
->target
);
898 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
902 /* Convert function entry point exact address ADDR to the function which is
903 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
904 NO_ENTRY_VALUE_ERROR otherwise. */
906 static struct symbol
*
907 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
909 struct symbol
*sym
= find_pc_function (addr
);
912 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
913 throw_error (NO_ENTRY_VALUE_ERROR
,
914 _("DW_TAG_call_site resolving failed to find function "
915 "name for address %s"),
916 paddress (gdbarch
, addr
));
918 type
= SYMBOL_TYPE (sym
);
919 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
920 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
925 /* Verify function with entry point exact address ADDR can never call itself
926 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
927 can call itself via tail calls.
929 If a funtion can tail call itself its entry value based parameters are
930 unreliable. There is no verification whether the value of some/all
931 parameters is unchanged through the self tail call, we expect if there is
932 a self tail call all the parameters can be modified. */
935 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
939 /* The verification is completely unordered. Track here function addresses
940 which still need to be iterated. */
941 std::vector
<CORE_ADDR
> todo
;
943 /* Track here CORE_ADDRs which were already visited. */
944 std::unordered_set
<CORE_ADDR
> addr_hash
;
946 todo
.push_back (verify_addr
);
947 while (!todo
.empty ())
949 struct symbol
*func_sym
;
950 struct call_site
*call_site
;
955 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
957 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
958 call_site
; call_site
= call_site
->tail_call_next
)
960 CORE_ADDR target_addr
;
962 /* CALLER_FRAME with registers is not available for tail-call jumped
964 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
966 if (target_addr
== verify_addr
)
968 struct bound_minimal_symbol msym
;
970 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
971 throw_error (NO_ENTRY_VALUE_ERROR
,
972 _("DW_OP_entry_value resolving has found "
973 "function \"%s\" at %s can call itself via tail "
975 (msym
.minsym
== NULL
? "???"
976 : msym
.minsym
->print_name ()),
977 paddress (gdbarch
, verify_addr
));
980 if (addr_hash
.insert (target_addr
).second
)
981 todo
.push_back (target_addr
);
986 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
987 ENTRY_VALUES_DEBUG. */
990 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
992 CORE_ADDR addr
= call_site
->pc
;
993 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
995 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
996 (msym
.minsym
== NULL
? "???"
997 : msym
.minsym
->print_name ()));
1001 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1002 only top callers and bottom callees which are present in both. GDBARCH is
1003 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1004 no remaining possibilities to provide unambiguous non-trivial result.
1005 RESULTP should point to NULL on the first (initialization) call. Caller is
1006 responsible for xfree of any RESULTP data. */
1009 chain_candidate (struct gdbarch
*gdbarch
,
1010 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1011 std::vector
<struct call_site
*> *chain
)
1013 long length
= chain
->size ();
1014 int callers
, callees
, idx
;
1016 if (*resultp
== NULL
)
1018 /* Create the initial chain containing all the passed PCs. */
1020 struct call_site_chain
*result
1021 = ((struct call_site_chain
*)
1022 xmalloc (sizeof (*result
)
1023 + sizeof (*result
->call_site
) * (length
- 1)));
1024 result
->length
= length
;
1025 result
->callers
= result
->callees
= length
;
1026 if (!chain
->empty ())
1027 memcpy (result
->call_site
, chain
->data (),
1028 sizeof (*result
->call_site
) * length
);
1029 resultp
->reset (result
);
1031 if (entry_values_debug
)
1033 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1034 for (idx
= 0; idx
< length
; idx
++)
1035 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1036 fputc_unfiltered ('\n', gdb_stdlog
);
1042 if (entry_values_debug
)
1044 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1045 for (idx
= 0; idx
< length
; idx
++)
1046 tailcall_dump (gdbarch
, chain
->at (idx
));
1047 fputc_unfiltered ('\n', gdb_stdlog
);
1050 /* Intersect callers. */
1052 callers
= std::min ((long) (*resultp
)->callers
, length
);
1053 for (idx
= 0; idx
< callers
; idx
++)
1054 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1056 (*resultp
)->callers
= idx
;
1060 /* Intersect callees. */
1062 callees
= std::min ((long) (*resultp
)->callees
, length
);
1063 for (idx
= 0; idx
< callees
; idx
++)
1064 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1065 != chain
->at (length
- 1 - idx
))
1067 (*resultp
)->callees
= idx
;
1071 if (entry_values_debug
)
1073 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1074 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1075 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1076 fputs_unfiltered (" |", gdb_stdlog
);
1077 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1078 tailcall_dump (gdbarch
,
1079 (*resultp
)->call_site
[(*resultp
)->length
1080 - (*resultp
)->callees
+ idx
]);
1081 fputc_unfiltered ('\n', gdb_stdlog
);
1084 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1086 /* There are no common callers or callees. It could be also a direct
1087 call (which has length 0) with ambiguous possibility of an indirect
1088 call - CALLERS == CALLEES == 0 is valid during the first allocation
1089 but any subsequence processing of such entry means ambiguity. */
1090 resultp
->reset (NULL
);
1094 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1095 PC again. In such case there must be two different code paths to reach
1096 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1097 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1100 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1101 assumed frames between them use GDBARCH. Use depth first search so we can
1102 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1103 would have needless GDB stack overhead. Caller is responsible for xfree of
1104 the returned result. Any unreliability results in thrown
1105 NO_ENTRY_VALUE_ERROR. */
1107 static struct call_site_chain
*
1108 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1109 CORE_ADDR callee_pc
)
1111 CORE_ADDR save_callee_pc
= callee_pc
;
1112 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1113 struct call_site
*call_site
;
1115 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1116 call_site nor any possible call_site at CALLEE_PC's function is there.
1117 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1118 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1119 std::vector
<struct call_site
*> chain
;
1121 /* We are not interested in the specific PC inside the callee function. */
1122 callee_pc
= get_pc_function_start (callee_pc
);
1124 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1125 paddress (gdbarch
, save_callee_pc
));
1127 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1128 std::unordered_set
<CORE_ADDR
> addr_hash
;
1130 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1131 at the target's function. All the possible tail call sites in the
1132 target's function will get iterated as already pushed into CHAIN via their
1134 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1138 CORE_ADDR target_func_addr
;
1139 struct call_site
*target_call_site
;
1141 /* CALLER_FRAME with registers is not available for tail-call jumped
1143 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1145 if (target_func_addr
== callee_pc
)
1147 chain_candidate (gdbarch
, &retval
, &chain
);
1151 /* There is no way to reach CALLEE_PC again as we would prevent
1152 entering it twice as being already marked in ADDR_HASH. */
1153 target_call_site
= NULL
;
1157 struct symbol
*target_func
;
1159 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1160 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1165 /* Attempt to visit TARGET_CALL_SITE. */
1167 if (target_call_site
)
1169 if (addr_hash
.insert (target_call_site
->pc
).second
)
1171 /* Successfully entered TARGET_CALL_SITE. */
1173 chain
.push_back (target_call_site
);
1178 /* Backtrack (without revisiting the originating call_site). Try the
1179 callers's sibling; if there isn't any try the callers's callers's
1182 target_call_site
= NULL
;
1183 while (!chain
.empty ())
1185 call_site
= chain
.back ();
1188 size_t removed
= addr_hash
.erase (call_site
->pc
);
1189 gdb_assert (removed
== 1);
1191 target_call_site
= call_site
->tail_call_next
;
1192 if (target_call_site
)
1196 while (target_call_site
);
1201 call_site
= chain
.back ();
1206 struct bound_minimal_symbol msym_caller
, msym_callee
;
1208 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1209 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1210 throw_error (NO_ENTRY_VALUE_ERROR
,
1211 _("There are no unambiguously determinable intermediate "
1212 "callers or callees between caller function \"%s\" at %s "
1213 "and callee function \"%s\" at %s"),
1214 (msym_caller
.minsym
== NULL
1215 ? "???" : msym_caller
.minsym
->print_name ()),
1216 paddress (gdbarch
, caller_pc
),
1217 (msym_callee
.minsym
== NULL
1218 ? "???" : msym_callee
.minsym
->print_name ()),
1219 paddress (gdbarch
, callee_pc
));
1222 return retval
.release ();
1225 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1226 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1227 constructed return NULL. Caller is responsible for xfree of the returned
1230 struct call_site_chain
*
1231 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1232 CORE_ADDR callee_pc
)
1234 struct call_site_chain
*retval
= NULL
;
1238 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1240 catch (const gdb_exception_error
&e
)
1242 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1244 if (entry_values_debug
)
1245 exception_print (gdb_stdout
, e
);
1256 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1259 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1260 enum call_site_parameter_kind kind
,
1261 union call_site_parameter_u kind_u
)
1263 if (kind
== parameter
->kind
)
1266 case CALL_SITE_PARAMETER_DWARF_REG
:
1267 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1268 case CALL_SITE_PARAMETER_FB_OFFSET
:
1269 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1270 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1271 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1276 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1277 FRAME is for callee.
1279 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1282 static struct call_site_parameter
*
1283 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1284 enum call_site_parameter_kind kind
,
1285 union call_site_parameter_u kind_u
,
1286 struct dwarf2_per_cu_data
**per_cu_return
)
1288 CORE_ADDR func_addr
, caller_pc
;
1289 struct gdbarch
*gdbarch
;
1290 struct frame_info
*caller_frame
;
1291 struct call_site
*call_site
;
1293 /* Initialize it just to avoid a GCC false warning. */
1294 struct call_site_parameter
*parameter
= NULL
;
1295 CORE_ADDR target_addr
;
1297 while (get_frame_type (frame
) == INLINE_FRAME
)
1299 frame
= get_prev_frame (frame
);
1300 gdb_assert (frame
!= NULL
);
1303 func_addr
= get_frame_func (frame
);
1304 gdbarch
= get_frame_arch (frame
);
1305 caller_frame
= get_prev_frame (frame
);
1306 if (gdbarch
!= frame_unwind_arch (frame
))
1308 struct bound_minimal_symbol msym
1309 = lookup_minimal_symbol_by_pc (func_addr
);
1310 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1312 throw_error (NO_ENTRY_VALUE_ERROR
,
1313 _("DW_OP_entry_value resolving callee gdbarch %s "
1314 "(of %s (%s)) does not match caller gdbarch %s"),
1315 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1316 paddress (gdbarch
, func_addr
),
1317 (msym
.minsym
== NULL
? "???"
1318 : msym
.minsym
->print_name ()),
1319 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1322 if (caller_frame
== NULL
)
1324 struct bound_minimal_symbol msym
1325 = lookup_minimal_symbol_by_pc (func_addr
);
1327 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1328 "requires caller of %s (%s)"),
1329 paddress (gdbarch
, func_addr
),
1330 (msym
.minsym
== NULL
? "???"
1331 : msym
.minsym
->print_name ()));
1333 caller_pc
= get_frame_pc (caller_frame
);
1334 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1336 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1337 if (target_addr
!= func_addr
)
1339 struct minimal_symbol
*target_msym
, *func_msym
;
1341 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1342 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1343 throw_error (NO_ENTRY_VALUE_ERROR
,
1344 _("DW_OP_entry_value resolving expects callee %s at %s "
1345 "but the called frame is for %s at %s"),
1346 (target_msym
== NULL
? "???"
1347 : target_msym
->print_name ()),
1348 paddress (gdbarch
, target_addr
),
1349 func_msym
== NULL
? "???" : func_msym
->print_name (),
1350 paddress (gdbarch
, func_addr
));
1353 /* No entry value based parameters would be reliable if this function can
1354 call itself via tail calls. */
1355 func_verify_no_selftailcall (gdbarch
, func_addr
);
1357 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1359 parameter
= &call_site
->parameter
[iparams
];
1360 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1363 if (iparams
== call_site
->parameter_count
)
1365 struct minimal_symbol
*msym
1366 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1368 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1369 determine its value. */
1370 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1371 "at DW_TAG_call_site %s at %s"),
1372 paddress (gdbarch
, caller_pc
),
1373 msym
== NULL
? "???" : msym
->print_name ());
1376 *per_cu_return
= call_site
->per_cu
;
1380 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1381 the normal DW_AT_call_value block. Otherwise return the
1382 DW_AT_call_data_value (dereferenced) block.
1384 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1387 Function always returns non-NULL, non-optimized out value. It throws
1388 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1390 static struct value
*
1391 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1392 CORE_ADDR deref_size
, struct type
*type
,
1393 struct frame_info
*caller_frame
,
1394 struct dwarf2_per_cu_data
*per_cu
)
1396 const gdb_byte
*data_src
;
1400 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1401 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1403 /* DEREF_SIZE size is not verified here. */
1404 if (data_src
== NULL
)
1405 throw_error (NO_ENTRY_VALUE_ERROR
,
1406 _("Cannot resolve DW_AT_call_data_value"));
1408 /* DW_AT_call_value is a DWARF expression, not a DWARF
1409 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1411 data
= (gdb_byte
*) alloca (size
+ 1);
1412 memcpy (data
, data_src
, size
);
1413 data
[size
] = DW_OP_stack_value
;
1415 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1418 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1419 the indirect method on it, that is use its stored target value, the sole
1420 purpose of entry_data_value_funcs.. */
1422 static struct value
*
1423 entry_data_value_coerce_ref (const struct value
*value
)
1425 struct type
*checked_type
= check_typedef (value_type (value
));
1426 struct value
*target_val
;
1428 if (!TYPE_IS_REFERENCE (checked_type
))
1431 target_val
= (struct value
*) value_computed_closure (value
);
1432 value_incref (target_val
);
1436 /* Implement copy_closure. */
1439 entry_data_value_copy_closure (const struct value
*v
)
1441 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1443 value_incref (target_val
);
1447 /* Implement free_closure. */
1450 entry_data_value_free_closure (struct value
*v
)
1452 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1454 value_decref (target_val
);
1457 /* Vector for methods for an entry value reference where the referenced value
1458 is stored in the caller. On the first dereference use
1459 DW_AT_call_data_value in the caller. */
1461 static const struct lval_funcs entry_data_value_funcs
=
1465 NULL
, /* indirect */
1466 entry_data_value_coerce_ref
,
1467 NULL
, /* check_synthetic_pointer */
1468 entry_data_value_copy_closure
,
1469 entry_data_value_free_closure
1472 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1473 are used to match DW_AT_location at the caller's
1474 DW_TAG_call_site_parameter.
1476 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1477 cannot resolve the parameter for any reason. */
1479 static struct value
*
1480 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1481 enum call_site_parameter_kind kind
,
1482 union call_site_parameter_u kind_u
)
1484 struct type
*checked_type
= check_typedef (type
);
1485 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1486 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1487 struct value
*outer_val
, *target_val
, *val
;
1488 struct call_site_parameter
*parameter
;
1489 struct dwarf2_per_cu_data
*caller_per_cu
;
1491 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1494 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1498 /* Check if DW_AT_call_data_value cannot be used. If it should be
1499 used and it is not available do not fall back to OUTER_VAL - dereferencing
1500 TYPE_CODE_REF with non-entry data value would give current value - not the
1503 if (!TYPE_IS_REFERENCE (checked_type
)
1504 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1507 target_val
= dwarf_entry_parameter_to_value (parameter
,
1508 TYPE_LENGTH (target_type
),
1509 target_type
, caller_frame
,
1512 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1513 release_value (target_val
).release ());
1515 /* Copy the referencing pointer to the new computed value. */
1516 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1517 TYPE_LENGTH (checked_type
));
1518 set_value_lazy (val
, 0);
1523 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1524 SIZE are DWARF block used to match DW_AT_location at the caller's
1525 DW_TAG_call_site_parameter.
1527 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1528 cannot resolve the parameter for any reason. */
1530 static struct value
*
1531 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1532 const gdb_byte
*block
, size_t block_len
)
1534 union call_site_parameter_u kind_u
;
1536 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1537 if (kind_u
.dwarf_reg
!= -1)
1538 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1541 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1542 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1545 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1546 suppressed during normal operation. The expression can be arbitrary if
1547 there is no caller-callee entry value binding expected. */
1548 throw_error (NO_ENTRY_VALUE_ERROR
,
1549 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1550 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1553 struct piece_closure
1555 /* Reference count. */
1558 /* The CU from which this closure's expression came. */
1559 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1561 /* The pieces describing this variable. */
1562 std::vector
<dwarf_expr_piece
> pieces
;
1564 /* Frame ID of frame to which a register value is relative, used
1565 only by DWARF_VALUE_REGISTER. */
1566 struct frame_id frame_id
;
1569 /* Allocate a closure for a value formed from separately-described
1572 static struct piece_closure
*
1573 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1574 std::vector
<dwarf_expr_piece
> &&pieces
,
1575 struct frame_info
*frame
)
1577 struct piece_closure
*c
= new piece_closure
;
1581 c
->pieces
= std::move (pieces
);
1583 c
->frame_id
= null_frame_id
;
1585 c
->frame_id
= get_frame_id (frame
);
1587 for (dwarf_expr_piece
&piece
: c
->pieces
)
1588 if (piece
.location
== DWARF_VALUE_STACK
)
1589 value_incref (piece
.v
.value
);
1594 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1595 bits whose first bit is located at bit offset START. */
1598 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1600 return (start
% 8 + n_bits
+ 7) / 8;
1603 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1604 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1605 operate in "read mode": fetch the contents of the (lazy) value V by
1606 composing it from its pieces. */
1609 rw_pieced_value (struct value
*v
, struct value
*from
)
1612 LONGEST offset
= 0, max_offset
;
1613 ULONGEST bits_to_skip
;
1614 gdb_byte
*v_contents
;
1615 const gdb_byte
*from_contents
;
1616 struct piece_closure
*c
1617 = (struct piece_closure
*) value_computed_closure (v
);
1618 gdb::byte_vector buffer
;
1619 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1623 from_contents
= value_contents (from
);
1628 if (value_type (v
) != value_enclosing_type (v
))
1629 internal_error (__FILE__
, __LINE__
,
1630 _("Should not be able to create a lazy value with "
1631 "an enclosing type"));
1632 v_contents
= value_contents_raw (v
);
1633 from_contents
= NULL
;
1636 bits_to_skip
= 8 * value_offset (v
);
1637 if (value_bitsize (v
))
1639 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1640 + value_bitpos (v
));
1642 && (type_byte_order (value_type (from
))
1645 /* Use the least significant bits of FROM. */
1646 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1647 offset
= max_offset
- value_bitsize (v
);
1650 max_offset
= value_bitsize (v
);
1653 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1655 /* Advance to the first non-skipped piece. */
1656 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1657 bits_to_skip
-= c
->pieces
[i
].size
;
1659 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1661 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1662 size_t this_size_bits
, this_size
;
1664 this_size_bits
= p
->size
- bits_to_skip
;
1665 if (this_size_bits
> max_offset
- offset
)
1666 this_size_bits
= max_offset
- offset
;
1668 switch (p
->location
)
1670 case DWARF_VALUE_REGISTER
:
1672 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1673 struct gdbarch
*arch
= get_frame_arch (frame
);
1674 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1675 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1678 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1679 && p
->offset
+ p
->size
< reg_bits
)
1681 /* Big-endian, and we want less than full size. */
1682 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1685 bits_to_skip
+= p
->offset
;
1687 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1688 buffer
.resize (this_size
);
1693 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1695 this_size
, buffer
.data (),
1699 mark_value_bits_optimized_out (v
, offset
,
1702 mark_value_bits_unavailable (v
, offset
,
1707 copy_bitwise (v_contents
, offset
,
1708 buffer
.data (), bits_to_skip
% 8,
1709 this_size_bits
, bits_big_endian
);
1714 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1716 /* Data is copied non-byte-aligned into the register.
1717 Need some bits from original register value. */
1718 get_frame_register_bytes (frame
, gdb_regnum
,
1720 this_size
, buffer
.data (),
1723 throw_error (OPTIMIZED_OUT_ERROR
,
1724 _("Can't do read-modify-write to "
1725 "update bitfield; containing word "
1726 "has been optimized out"));
1728 throw_error (NOT_AVAILABLE_ERROR
,
1729 _("Can't do read-modify-write to "
1730 "update bitfield; containing word "
1734 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1735 from_contents
, offset
,
1736 this_size_bits
, bits_big_endian
);
1737 put_frame_register_bytes (frame
, gdb_regnum
,
1739 this_size
, buffer
.data ());
1744 case DWARF_VALUE_MEMORY
:
1746 bits_to_skip
+= p
->offset
;
1748 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1750 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1753 /* Everything is byte-aligned; no buffer needed. */
1755 write_memory_with_notification (start_addr
,
1758 this_size_bits
/ 8);
1760 read_value_memory (v
, offset
,
1761 p
->v
.mem
.in_stack_memory
,
1762 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1763 v_contents
+ offset
/ 8,
1764 this_size_bits
/ 8);
1768 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1769 buffer
.resize (this_size
);
1774 read_value_memory (v
, offset
,
1775 p
->v
.mem
.in_stack_memory
,
1776 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1777 buffer
.data (), this_size
);
1778 copy_bitwise (v_contents
, offset
,
1779 buffer
.data (), bits_to_skip
% 8,
1780 this_size_bits
, bits_big_endian
);
1785 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1789 /* Perform a single read for small sizes. */
1790 read_memory (start_addr
, buffer
.data (),
1795 /* Only the first and last bytes can possibly have
1797 read_memory (start_addr
, buffer
.data (), 1);
1798 read_memory (start_addr
+ this_size
- 1,
1799 &buffer
[this_size
- 1], 1);
1803 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1804 from_contents
, offset
,
1805 this_size_bits
, bits_big_endian
);
1806 write_memory_with_notification (start_addr
,
1813 case DWARF_VALUE_STACK
:
1817 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1821 struct objfile
*objfile
= c
->per_cu
->objfile ();
1822 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1823 ULONGEST stack_value_size_bits
1824 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1826 /* Use zeroes if piece reaches beyond stack value. */
1827 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1830 /* Piece is anchored at least significant bit end. */
1831 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1832 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1834 bits_to_skip
+= p
->offset
;
1836 copy_bitwise (v_contents
, offset
,
1837 value_contents_all (p
->v
.value
),
1839 this_size_bits
, bits_big_endian
);
1843 case DWARF_VALUE_LITERAL
:
1847 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1851 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1852 size_t n
= this_size_bits
;
1854 /* Cut off at the end of the implicit value. */
1855 bits_to_skip
+= p
->offset
;
1856 if (bits_to_skip
>= literal_size_bits
)
1858 if (n
> literal_size_bits
- bits_to_skip
)
1859 n
= literal_size_bits
- bits_to_skip
;
1861 copy_bitwise (v_contents
, offset
,
1862 p
->v
.literal
.data
, bits_to_skip
,
1863 n
, bits_big_endian
);
1867 case DWARF_VALUE_IMPLICIT_POINTER
:
1870 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1874 /* These bits show up as zeros -- but do not cause the value to
1875 be considered optimized-out. */
1878 case DWARF_VALUE_OPTIMIZED_OUT
:
1879 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1883 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1886 offset
+= this_size_bits
;
1893 read_pieced_value (struct value
*v
)
1895 rw_pieced_value (v
, NULL
);
1899 write_pieced_value (struct value
*to
, struct value
*from
)
1901 rw_pieced_value (to
, from
);
1904 /* An implementation of an lval_funcs method to see whether a value is
1905 a synthetic pointer. */
1908 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1911 struct piece_closure
*c
1912 = (struct piece_closure
*) value_computed_closure (value
);
1915 bit_offset
+= 8 * value_offset (value
);
1916 if (value_bitsize (value
))
1917 bit_offset
+= value_bitpos (value
);
1919 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1921 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1922 size_t this_size_bits
= p
->size
;
1926 if (bit_offset
>= this_size_bits
)
1928 bit_offset
-= this_size_bits
;
1932 bit_length
-= this_size_bits
- bit_offset
;
1936 bit_length
-= this_size_bits
;
1938 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1945 /* A wrapper function for get_frame_address_in_block. */
1948 get_frame_address_in_block_wrapper (void *baton
)
1950 return get_frame_address_in_block ((struct frame_info
*) baton
);
1953 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1955 static struct value
*
1956 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1957 struct dwarf2_per_cu_data
*per_cu
,
1960 struct value
*result
= NULL
;
1961 const gdb_byte
*bytes
;
1964 auto_obstack temp_obstack
;
1965 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
1969 if (byte_offset
>= 0
1970 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1972 bytes
+= byte_offset
;
1973 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1976 invalid_synthetic_pointer ();
1979 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1984 /* Fetch the value pointed to by a synthetic pointer. */
1986 static struct value
*
1987 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1988 struct dwarf2_per_cu_data
*per_cu
,
1989 struct frame_info
*frame
, struct type
*type
,
1990 bool resolve_abstract_p
)
1992 /* Fetch the location expression of the DIE we're pointing to. */
1993 struct dwarf2_locexpr_baton baton
1994 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
1995 get_frame_address_in_block_wrapper
, frame
,
1996 resolve_abstract_p
);
1998 /* Get type of pointed-to DIE. */
1999 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
);
2000 if (orig_type
== NULL
)
2001 invalid_synthetic_pointer ();
2003 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2004 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2005 or it may've been optimized out. */
2006 if (baton
.data
!= NULL
)
2007 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2008 baton
.size
, baton
.per_cu
,
2009 TYPE_TARGET_TYPE (type
),
2012 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2016 /* An implementation of an lval_funcs method to indirect through a
2017 pointer. This handles the synthetic pointer case when needed. */
2019 static struct value
*
2020 indirect_pieced_value (struct value
*value
)
2022 struct piece_closure
*c
2023 = (struct piece_closure
*) value_computed_closure (value
);
2025 struct frame_info
*frame
;
2028 struct dwarf_expr_piece
*piece
= NULL
;
2029 LONGEST byte_offset
;
2030 enum bfd_endian byte_order
;
2032 type
= check_typedef (value_type (value
));
2033 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2036 bit_length
= 8 * TYPE_LENGTH (type
);
2037 bit_offset
= 8 * value_offset (value
);
2038 if (value_bitsize (value
))
2039 bit_offset
+= value_bitpos (value
);
2041 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2043 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2044 size_t this_size_bits
= p
->size
;
2048 if (bit_offset
>= this_size_bits
)
2050 bit_offset
-= this_size_bits
;
2054 bit_length
-= this_size_bits
- bit_offset
;
2058 bit_length
-= this_size_bits
;
2060 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2063 if (bit_length
!= 0)
2064 error (_("Invalid use of DW_OP_implicit_pointer"));
2070 gdb_assert (piece
!= NULL
);
2071 frame
= get_selected_frame (_("No frame selected."));
2073 /* This is an offset requested by GDB, such as value subscripts.
2074 However, due to how synthetic pointers are implemented, this is
2075 always presented to us as a pointer type. This means we have to
2076 sign-extend it manually as appropriate. Use raw
2077 extract_signed_integer directly rather than value_as_address and
2078 sign extend afterwards on architectures that would need it
2079 (mostly everywhere except MIPS, which has signed addresses) as
2080 the later would go through gdbarch_pointer_to_address and thus
2081 return a CORE_ADDR with high bits set on architectures that
2082 encode address spaces and other things in CORE_ADDR. */
2083 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2084 byte_offset
= extract_signed_integer (value_contents (value
),
2085 TYPE_LENGTH (type
), byte_order
);
2086 byte_offset
+= piece
->v
.ptr
.offset
;
2088 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2089 byte_offset
, c
->per_cu
,
2093 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2096 static struct value
*
2097 coerce_pieced_ref (const struct value
*value
)
2099 struct type
*type
= check_typedef (value_type (value
));
2101 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2102 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2104 const struct piece_closure
*closure
2105 = (struct piece_closure
*) value_computed_closure (value
);
2106 struct frame_info
*frame
2107 = get_selected_frame (_("No frame selected."));
2109 /* gdb represents synthetic pointers as pieced values with a single
2111 gdb_assert (closure
!= NULL
);
2112 gdb_assert (closure
->pieces
.size () == 1);
2114 return indirect_synthetic_pointer
2115 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2116 closure
->pieces
[0].v
.ptr
.offset
,
2117 closure
->per_cu
, frame
, type
);
2121 /* Else: not a synthetic reference; do nothing. */
2127 copy_pieced_value_closure (const struct value
*v
)
2129 struct piece_closure
*c
2130 = (struct piece_closure
*) value_computed_closure (v
);
2137 free_pieced_value_closure (struct value
*v
)
2139 struct piece_closure
*c
2140 = (struct piece_closure
*) value_computed_closure (v
);
2145 for (dwarf_expr_piece
&p
: c
->pieces
)
2146 if (p
.location
== DWARF_VALUE_STACK
)
2147 value_decref (p
.v
.value
);
2153 /* Functions for accessing a variable described by DW_OP_piece. */
2154 static const struct lval_funcs pieced_value_funcs
= {
2157 indirect_pieced_value
,
2159 check_pieced_synthetic_pointer
,
2160 copy_pieced_value_closure
,
2161 free_pieced_value_closure
2164 /* Evaluate a location description, starting at DATA and with length
2165 SIZE, to find the current location of variable of TYPE in the
2166 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2167 location of the subobject of type SUBOBJ_TYPE at byte offset
2168 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2170 static struct value
*
2171 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2172 const gdb_byte
*data
, size_t size
,
2173 struct dwarf2_per_cu_data
*per_cu
,
2174 struct type
*subobj_type
,
2175 LONGEST subobj_byte_offset
)
2177 struct value
*retval
;
2178 struct objfile
*objfile
= per_cu
->objfile ();
2180 if (subobj_type
== NULL
)
2183 subobj_byte_offset
= 0;
2185 else if (subobj_byte_offset
< 0)
2186 invalid_synthetic_pointer ();
2189 return allocate_optimized_out_value (subobj_type
);
2191 dwarf_evaluate_loc_desc ctx
;
2193 ctx
.per_cu
= per_cu
;
2194 ctx
.obj_address
= 0;
2196 scoped_value_mark free_values
;
2198 ctx
.gdbarch
= get_objfile_arch (objfile
);
2199 ctx
.addr_size
= per_cu
->addr_size ();
2200 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2201 ctx
.offset
= per_cu
->text_offset ();
2205 ctx
.eval (data
, size
);
2207 catch (const gdb_exception_error
&ex
)
2209 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2211 free_values
.free_to_mark ();
2212 retval
= allocate_value (subobj_type
);
2213 mark_value_bytes_unavailable (retval
, 0,
2214 TYPE_LENGTH (subobj_type
));
2217 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2219 if (entry_values_debug
)
2220 exception_print (gdb_stdout
, ex
);
2221 free_values
.free_to_mark ();
2222 return allocate_optimized_out_value (subobj_type
);
2228 if (ctx
.pieces
.size () > 0)
2230 struct piece_closure
*c
;
2231 ULONGEST bit_size
= 0;
2233 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2234 bit_size
+= piece
.size
;
2235 /* Complain if the expression is larger than the size of the
2237 if (bit_size
> 8 * TYPE_LENGTH (type
))
2238 invalid_synthetic_pointer ();
2240 c
= allocate_piece_closure (per_cu
, std::move (ctx
.pieces
), frame
);
2241 /* We must clean up the value chain after creating the piece
2242 closure but before allocating the result. */
2243 free_values
.free_to_mark ();
2244 retval
= allocate_computed_value (subobj_type
,
2245 &pieced_value_funcs
, c
);
2246 set_value_offset (retval
, subobj_byte_offset
);
2250 switch (ctx
.location
)
2252 case DWARF_VALUE_REGISTER
:
2254 struct gdbarch
*arch
= get_frame_arch (frame
);
2256 = longest_to_int (value_as_long (ctx
.fetch (0)));
2257 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2259 if (subobj_byte_offset
!= 0)
2260 error (_("cannot use offset on synthetic pointer to register"));
2261 free_values
.free_to_mark ();
2262 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2263 if (value_optimized_out (retval
))
2267 /* This means the register has undefined value / was
2268 not saved. As we're computing the location of some
2269 variable etc. in the program, not a value for
2270 inspecting a register ($pc, $sp, etc.), return a
2271 generic optimized out value instead, so that we show
2272 <optimized out> instead of <not saved>. */
2273 tmp
= allocate_value (subobj_type
);
2274 value_contents_copy (tmp
, 0, retval
, 0,
2275 TYPE_LENGTH (subobj_type
));
2281 case DWARF_VALUE_MEMORY
:
2283 struct type
*ptr_type
;
2284 CORE_ADDR address
= ctx
.fetch_address (0);
2285 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2287 /* DW_OP_deref_size (and possibly other operations too) may
2288 create a pointer instead of an address. Ideally, the
2289 pointer to address conversion would be performed as part
2290 of those operations, but the type of the object to
2291 which the address refers is not known at the time of
2292 the operation. Therefore, we do the conversion here
2293 since the type is readily available. */
2295 switch (TYPE_CODE (subobj_type
))
2297 case TYPE_CODE_FUNC
:
2298 case TYPE_CODE_METHOD
:
2299 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2302 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2305 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2307 free_values
.free_to_mark ();
2308 retval
= value_at_lazy (subobj_type
,
2309 address
+ subobj_byte_offset
);
2310 if (in_stack_memory
)
2311 set_value_stack (retval
, 1);
2315 case DWARF_VALUE_STACK
:
2317 struct value
*value
= ctx
.fetch (0);
2318 size_t n
= TYPE_LENGTH (value_type (value
));
2319 size_t len
= TYPE_LENGTH (subobj_type
);
2320 size_t max
= TYPE_LENGTH (type
);
2321 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2323 if (subobj_byte_offset
+ len
> max
)
2324 invalid_synthetic_pointer ();
2326 /* Preserve VALUE because we are going to free values back
2327 to the mark, but we still need the value contents
2329 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2330 free_values
.free_to_mark ();
2332 retval
= allocate_value (subobj_type
);
2334 /* The given offset is relative to the actual object. */
2335 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2336 subobj_byte_offset
+= n
- max
;
2338 memcpy (value_contents_raw (retval
),
2339 value_contents_all (value
) + subobj_byte_offset
, len
);
2343 case DWARF_VALUE_LITERAL
:
2346 size_t n
= TYPE_LENGTH (subobj_type
);
2348 if (subobj_byte_offset
+ n
> ctx
.len
)
2349 invalid_synthetic_pointer ();
2351 free_values
.free_to_mark ();
2352 retval
= allocate_value (subobj_type
);
2353 contents
= value_contents_raw (retval
);
2354 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2358 case DWARF_VALUE_OPTIMIZED_OUT
:
2359 free_values
.free_to_mark ();
2360 retval
= allocate_optimized_out_value (subobj_type
);
2363 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2364 operation by execute_stack_op. */
2365 case DWARF_VALUE_IMPLICIT_POINTER
:
2366 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2367 it can only be encountered when making a piece. */
2369 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2373 set_value_initialized (retval
, ctx
.initialized
);
2378 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2379 passes 0 as the byte_offset. */
2382 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2383 const gdb_byte
*data
, size_t size
,
2384 struct dwarf2_per_cu_data
*per_cu
)
2386 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2390 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2391 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2392 frame in which the expression is evaluated. ADDR is a context (location of
2393 a variable) and might be needed to evaluate the location expression.
2394 Returns 1 on success, 0 otherwise. */
2397 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2398 struct frame_info
*frame
,
2402 struct objfile
*objfile
;
2404 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2407 dwarf_evaluate_loc_desc ctx
;
2410 ctx
.per_cu
= dlbaton
->per_cu
;
2411 ctx
.obj_address
= addr
;
2413 objfile
= dlbaton
->per_cu
->objfile ();
2415 ctx
.gdbarch
= get_objfile_arch (objfile
);
2416 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2417 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2418 ctx
.offset
= dlbaton
->per_cu
->text_offset ();
2422 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2424 catch (const gdb_exception_error
&ex
)
2426 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2430 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2432 if (entry_values_debug
)
2433 exception_print (gdb_stdout
, ex
);
2440 switch (ctx
.location
)
2442 case DWARF_VALUE_REGISTER
:
2443 case DWARF_VALUE_MEMORY
:
2444 case DWARF_VALUE_STACK
:
2445 *valp
= ctx
.fetch_address (0);
2446 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2447 *valp
= ctx
.read_addr_from_reg (*valp
);
2449 case DWARF_VALUE_LITERAL
:
2450 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2451 gdbarch_byte_order (ctx
.gdbarch
));
2453 /* Unsupported dwarf values. */
2454 case DWARF_VALUE_OPTIMIZED_OUT
:
2455 case DWARF_VALUE_IMPLICIT_POINTER
:
2462 /* See dwarf2loc.h. */
2465 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2466 struct frame_info
*frame
,
2467 struct property_addr_info
*addr_stack
,
2473 if (frame
== NULL
&& has_stack_frames ())
2474 frame
= get_selected_frame (NULL
);
2480 const struct dwarf2_property_baton
*baton
2481 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2482 gdb_assert (baton
->property_type
!= NULL
);
2484 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
,
2485 addr_stack
? addr_stack
->addr
: 0,
2488 if (baton
->locexpr
.is_reference
)
2490 struct value
*val
= value_at (baton
->property_type
, *value
);
2491 *value
= value_as_address (val
);
2495 gdb_assert (baton
->property_type
!= NULL
);
2497 struct type
*type
= check_typedef (baton
->property_type
);
2498 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2499 && !TYPE_UNSIGNED (type
))
2501 /* If we have a valid return candidate and it's value
2502 is signed, we have to sign-extend the value because
2503 CORE_ADDR on 64bit machine has 8 bytes but address
2504 size of an 32bit application is bytes. */
2506 = (baton
->locexpr
.per_cu
->addr_size ()
2508 const CORE_ADDR neg_mask
2509 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2511 /* Check if signed bit is set and sign-extend values. */
2512 if (*value
& neg_mask
)
2523 struct dwarf2_property_baton
*baton
2524 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2525 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2526 const gdb_byte
*data
;
2530 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2533 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2534 size
, baton
->loclist
.per_cu
);
2535 if (!value_optimized_out (val
))
2537 *value
= value_as_address (val
);
2545 *value
= prop
->data
.const_val
;
2548 case PROP_ADDR_OFFSET
:
2550 struct dwarf2_property_baton
*baton
2551 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2552 struct property_addr_info
*pinfo
;
2555 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2557 /* This approach lets us avoid checking the qualifiers. */
2558 if (TYPE_MAIN_TYPE (pinfo
->type
)
2559 == TYPE_MAIN_TYPE (baton
->property_type
))
2563 error (_("cannot find reference address for offset property"));
2564 if (pinfo
->valaddr
!= NULL
)
2565 val
= value_from_contents
2566 (baton
->offset_info
.type
,
2567 pinfo
->valaddr
+ baton
->offset_info
.offset
);
2569 val
= value_at (baton
->offset_info
.type
,
2570 pinfo
->addr
+ baton
->offset_info
.offset
);
2571 *value
= value_as_address (val
);
2579 /* See dwarf2loc.h. */
2582 dwarf2_compile_property_to_c (string_file
*stream
,
2583 const char *result_name
,
2584 struct gdbarch
*gdbarch
,
2585 unsigned char *registers_used
,
2586 const struct dynamic_prop
*prop
,
2590 struct dwarf2_property_baton
*baton
2591 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2592 const gdb_byte
*data
;
2594 struct dwarf2_per_cu_data
*per_cu
;
2596 if (prop
->kind
== PROP_LOCEXPR
)
2598 data
= baton
->locexpr
.data
;
2599 size
= baton
->locexpr
.size
;
2600 per_cu
= baton
->locexpr
.per_cu
;
2604 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2606 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2607 per_cu
= baton
->loclist
.per_cu
;
2610 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2611 gdbarch
, registers_used
,
2612 per_cu
->addr_size (),
2613 data
, data
+ size
, per_cu
);
2617 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2619 class symbol_needs_eval_context
: public dwarf_expr_context
2623 enum symbol_needs_kind needs
;
2624 struct dwarf2_per_cu_data
*per_cu
;
2626 /* Reads from registers do require a frame. */
2627 CORE_ADDR
read_addr_from_reg (int regnum
) override
2629 needs
= SYMBOL_NEEDS_FRAME
;
2633 /* "get_reg_value" callback: Reads from registers do require a
2636 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2638 needs
= SYMBOL_NEEDS_FRAME
;
2639 return value_zero (type
, not_lval
);
2642 /* Reads from memory do not require a frame. */
2643 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2645 memset (buf
, 0, len
);
2648 /* Frame-relative accesses do require a frame. */
2649 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2651 static gdb_byte lit0
= DW_OP_lit0
;
2656 needs
= SYMBOL_NEEDS_FRAME
;
2659 /* CFA accesses require a frame. */
2660 CORE_ADDR
get_frame_cfa () override
2662 needs
= SYMBOL_NEEDS_FRAME
;
2666 CORE_ADDR
get_frame_pc () override
2668 needs
= SYMBOL_NEEDS_FRAME
;
2672 /* Thread-local accesses require registers, but not a frame. */
2673 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2675 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2676 needs
= SYMBOL_NEEDS_REGISTERS
;
2680 /* Helper interface of per_cu_dwarf_call for
2681 dwarf2_loc_desc_get_symbol_read_needs. */
2683 void dwarf_call (cu_offset die_offset
) override
2685 per_cu_dwarf_call (this, die_offset
, per_cu
);
2688 /* Helper interface of sect_variable_value for
2689 dwarf2_loc_desc_get_symbol_read_needs. */
2691 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2693 return sect_variable_value (this, sect_off
, per_cu
);
2696 /* DW_OP_entry_value accesses require a caller, therefore a
2699 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2700 union call_site_parameter_u kind_u
,
2701 int deref_size
) override
2703 needs
= SYMBOL_NEEDS_FRAME
;
2705 /* The expression may require some stub values on DWARF stack. */
2706 push_address (0, 0);
2709 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2711 CORE_ADDR
get_addr_index (unsigned int index
) override
2713 /* Nothing to do. */
2717 /* DW_OP_push_object_address has a frame already passed through. */
2719 CORE_ADDR
get_object_address () override
2721 /* Nothing to do. */
2726 /* Compute the correct symbol_needs_kind value for the location
2727 expression at DATA (length SIZE). */
2729 static enum symbol_needs_kind
2730 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2731 struct dwarf2_per_cu_data
*per_cu
)
2734 struct objfile
*objfile
= per_cu
->objfile ();
2736 scoped_value_mark free_values
;
2738 symbol_needs_eval_context ctx
;
2740 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2741 ctx
.per_cu
= per_cu
;
2742 ctx
.gdbarch
= get_objfile_arch (objfile
);
2743 ctx
.addr_size
= per_cu
->addr_size ();
2744 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2745 ctx
.offset
= per_cu
->text_offset ();
2747 ctx
.eval (data
, size
);
2749 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2751 /* If the location has several pieces, and any of them are in
2752 registers, then we will need a frame to fetch them from. */
2753 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2754 if (p
.location
== DWARF_VALUE_REGISTER
)
2758 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2762 /* A helper function that throws an unimplemented error mentioning a
2763 given DWARF operator. */
2765 static void ATTRIBUTE_NORETURN
2766 unimplemented (unsigned int op
)
2768 const char *name
= get_DW_OP_name (op
);
2771 error (_("DWARF operator %s cannot be translated to an agent expression"),
2774 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2775 "to an agent expression"),
2781 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2782 can issue a complaint, which is better than having every target's
2783 implementation of dwarf2_reg_to_regnum do it. */
2786 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2788 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2792 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2797 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2798 Throw an error because DWARF_REG is bad. */
2801 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2803 /* Still want to print -1 as "-1".
2804 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2805 but that's overkill for now. */
2806 if ((int) dwarf_reg
== dwarf_reg
)
2807 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2808 error (_("Unable to access DWARF register number %s"),
2809 pulongest (dwarf_reg
));
2812 /* See dwarf2loc.h. */
2815 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2819 if (dwarf_reg
> INT_MAX
)
2820 throw_bad_regnum_error (dwarf_reg
);
2821 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2822 bad, but that's ok. */
2823 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2825 throw_bad_regnum_error (dwarf_reg
);
2829 /* A helper function that emits an access to memory. ARCH is the
2830 target architecture. EXPR is the expression which we are building.
2831 NBITS is the number of bits we want to read. This emits the
2832 opcodes needed to read the memory and then extract the desired
2836 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2838 ULONGEST nbytes
= (nbits
+ 7) / 8;
2840 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2843 ax_trace_quick (expr
, nbytes
);
2846 ax_simple (expr
, aop_ref8
);
2847 else if (nbits
<= 16)
2848 ax_simple (expr
, aop_ref16
);
2849 else if (nbits
<= 32)
2850 ax_simple (expr
, aop_ref32
);
2852 ax_simple (expr
, aop_ref64
);
2854 /* If we read exactly the number of bytes we wanted, we're done. */
2855 if (8 * nbytes
== nbits
)
2858 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2860 /* On a bits-big-endian machine, we want the high-order
2862 ax_const_l (expr
, 8 * nbytes
- nbits
);
2863 ax_simple (expr
, aop_rsh_unsigned
);
2867 /* On a bits-little-endian box, we want the low-order NBITS. */
2868 ax_zero_ext (expr
, nbits
);
2872 /* A helper function to return the frame's PC. */
2875 get_ax_pc (void *baton
)
2877 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
2882 /* Compile a DWARF location expression to an agent expression.
2884 EXPR is the agent expression we are building.
2885 LOC is the agent value we modify.
2886 ARCH is the architecture.
2887 ADDR_SIZE is the size of addresses, in bytes.
2888 OP_PTR is the start of the location expression.
2889 OP_END is one past the last byte of the location expression.
2891 This will throw an exception for various kinds of errors -- for
2892 example, if the expression cannot be compiled, or if the expression
2896 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2897 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2898 const gdb_byte
*op_end
,
2899 struct dwarf2_per_cu_data
*per_cu
)
2901 gdbarch
*arch
= expr
->gdbarch
;
2902 std::vector
<int> dw_labels
, patches
;
2903 const gdb_byte
* const base
= op_ptr
;
2904 const gdb_byte
*previous_piece
= op_ptr
;
2905 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2906 ULONGEST bits_collected
= 0;
2907 unsigned int addr_size_bits
= 8 * addr_size
;
2908 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2910 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2912 /* By default we are making an address. */
2913 loc
->kind
= axs_lvalue_memory
;
2915 while (op_ptr
< op_end
)
2917 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2918 uint64_t uoffset
, reg
;
2922 offsets
[op_ptr
- base
] = expr
->len
;
2925 /* Our basic approach to code generation is to map DWARF
2926 operations directly to AX operations. However, there are
2929 First, DWARF works on address-sized units, but AX always uses
2930 LONGEST. For most operations we simply ignore this
2931 difference; instead we generate sign extensions as needed
2932 before division and comparison operations. It would be nice
2933 to omit the sign extensions, but there is no way to determine
2934 the size of the target's LONGEST. (This code uses the size
2935 of the host LONGEST in some cases -- that is a bug but it is
2938 Second, some DWARF operations cannot be translated to AX.
2939 For these we simply fail. See
2940 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2975 ax_const_l (expr
, op
- DW_OP_lit0
);
2979 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2980 op_ptr
+= addr_size
;
2981 /* Some versions of GCC emit DW_OP_addr before
2982 DW_OP_GNU_push_tls_address. In this case the value is an
2983 index, not an address. We don't support things like
2984 branching between the address and the TLS op. */
2985 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2986 uoffset
+= per_cu
->text_offset ();
2987 ax_const_l (expr
, uoffset
);
2991 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2995 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2999 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3003 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3007 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3011 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3015 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3019 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3023 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3024 ax_const_l (expr
, uoffset
);
3027 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3028 ax_const_l (expr
, offset
);
3063 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3064 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3065 loc
->kind
= axs_lvalue_register
;
3069 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3070 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3071 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3072 loc
->kind
= axs_lvalue_register
;
3075 case DW_OP_implicit_value
:
3079 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3080 if (op_ptr
+ len
> op_end
)
3081 error (_("DW_OP_implicit_value: too few bytes available."));
3082 if (len
> sizeof (ULONGEST
))
3083 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3086 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3089 dwarf_expr_require_composition (op_ptr
, op_end
,
3090 "DW_OP_implicit_value");
3092 loc
->kind
= axs_rvalue
;
3096 case DW_OP_stack_value
:
3097 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3098 loc
->kind
= axs_rvalue
;
3133 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3134 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3138 ax_const_l (expr
, offset
);
3139 ax_simple (expr
, aop_add
);
3144 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3145 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3146 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3150 ax_const_l (expr
, offset
);
3151 ax_simple (expr
, aop_add
);
3157 const gdb_byte
*datastart
;
3159 const struct block
*b
;
3160 struct symbol
*framefunc
;
3162 b
= block_for_pc (expr
->scope
);
3165 error (_("No block found for address"));
3167 framefunc
= block_linkage_function (b
);
3170 error (_("No function found for block"));
3172 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3173 &datastart
, &datalen
);
3175 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3176 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3177 datastart
+ datalen
, per_cu
);
3178 if (loc
->kind
== axs_lvalue_register
)
3179 require_rvalue (expr
, loc
);
3183 ax_const_l (expr
, offset
);
3184 ax_simple (expr
, aop_add
);
3187 loc
->kind
= axs_lvalue_memory
;
3192 ax_simple (expr
, aop_dup
);
3196 ax_simple (expr
, aop_pop
);
3201 ax_pick (expr
, offset
);
3205 ax_simple (expr
, aop_swap
);
3213 ax_simple (expr
, aop_rot
);
3217 case DW_OP_deref_size
:
3221 if (op
== DW_OP_deref_size
)
3226 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3227 error (_("Unsupported size %d in %s"),
3228 size
, get_DW_OP_name (op
));
3229 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3234 /* Sign extend the operand. */
3235 ax_ext (expr
, addr_size_bits
);
3236 ax_simple (expr
, aop_dup
);
3237 ax_const_l (expr
, 0);
3238 ax_simple (expr
, aop_less_signed
);
3239 ax_simple (expr
, aop_log_not
);
3240 i
= ax_goto (expr
, aop_if_goto
);
3241 /* We have to emit 0 - X. */
3242 ax_const_l (expr
, 0);
3243 ax_simple (expr
, aop_swap
);
3244 ax_simple (expr
, aop_sub
);
3245 ax_label (expr
, i
, expr
->len
);
3249 /* No need to sign extend here. */
3250 ax_const_l (expr
, 0);
3251 ax_simple (expr
, aop_swap
);
3252 ax_simple (expr
, aop_sub
);
3256 /* Sign extend the operand. */
3257 ax_ext (expr
, addr_size_bits
);
3258 ax_simple (expr
, aop_bit_not
);
3261 case DW_OP_plus_uconst
:
3262 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3263 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3264 but we micro-optimize anyhow. */
3267 ax_const_l (expr
, reg
);
3268 ax_simple (expr
, aop_add
);
3273 ax_simple (expr
, aop_bit_and
);
3277 /* Sign extend the operands. */
3278 ax_ext (expr
, addr_size_bits
);
3279 ax_simple (expr
, aop_swap
);
3280 ax_ext (expr
, addr_size_bits
);
3281 ax_simple (expr
, aop_swap
);
3282 ax_simple (expr
, aop_div_signed
);
3286 ax_simple (expr
, aop_sub
);
3290 ax_simple (expr
, aop_rem_unsigned
);
3294 ax_simple (expr
, aop_mul
);
3298 ax_simple (expr
, aop_bit_or
);
3302 ax_simple (expr
, aop_add
);
3306 ax_simple (expr
, aop_lsh
);
3310 ax_simple (expr
, aop_rsh_unsigned
);
3314 ax_simple (expr
, aop_rsh_signed
);
3318 ax_simple (expr
, aop_bit_xor
);
3322 /* Sign extend the operands. */
3323 ax_ext (expr
, addr_size_bits
);
3324 ax_simple (expr
, aop_swap
);
3325 ax_ext (expr
, addr_size_bits
);
3326 /* Note no swap here: A <= B is !(B < A). */
3327 ax_simple (expr
, aop_less_signed
);
3328 ax_simple (expr
, aop_log_not
);
3332 /* Sign extend the operands. */
3333 ax_ext (expr
, addr_size_bits
);
3334 ax_simple (expr
, aop_swap
);
3335 ax_ext (expr
, addr_size_bits
);
3336 ax_simple (expr
, aop_swap
);
3337 /* A >= B is !(A < B). */
3338 ax_simple (expr
, aop_less_signed
);
3339 ax_simple (expr
, aop_log_not
);
3343 /* Sign extend the operands. */
3344 ax_ext (expr
, addr_size_bits
);
3345 ax_simple (expr
, aop_swap
);
3346 ax_ext (expr
, addr_size_bits
);
3347 /* No need for a second swap here. */
3348 ax_simple (expr
, aop_equal
);
3352 /* Sign extend the operands. */
3353 ax_ext (expr
, addr_size_bits
);
3354 ax_simple (expr
, aop_swap
);
3355 ax_ext (expr
, addr_size_bits
);
3356 ax_simple (expr
, aop_swap
);
3357 ax_simple (expr
, aop_less_signed
);
3361 /* Sign extend the operands. */
3362 ax_ext (expr
, addr_size_bits
);
3363 ax_simple (expr
, aop_swap
);
3364 ax_ext (expr
, addr_size_bits
);
3365 /* Note no swap here: A > B is B < A. */
3366 ax_simple (expr
, aop_less_signed
);
3370 /* Sign extend the operands. */
3371 ax_ext (expr
, addr_size_bits
);
3372 ax_simple (expr
, aop_swap
);
3373 ax_ext (expr
, addr_size_bits
);
3374 /* No need for a swap here. */
3375 ax_simple (expr
, aop_equal
);
3376 ax_simple (expr
, aop_log_not
);
3379 case DW_OP_call_frame_cfa
:
3382 CORE_ADDR text_offset
;
3384 const gdb_byte
*cfa_start
, *cfa_end
;
3386 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3388 &text_offset
, &cfa_start
, &cfa_end
))
3391 ax_reg (expr
, regnum
);
3394 ax_const_l (expr
, off
);
3395 ax_simple (expr
, aop_add
);
3400 /* Another expression. */
3401 ax_const_l (expr
, text_offset
);
3402 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3406 loc
->kind
= axs_lvalue_memory
;
3410 case DW_OP_GNU_push_tls_address
:
3411 case DW_OP_form_tls_address
:
3415 case DW_OP_push_object_address
:
3420 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3422 i
= ax_goto (expr
, aop_goto
);
3423 dw_labels
.push_back (op_ptr
+ offset
- base
);
3424 patches
.push_back (i
);
3428 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3430 /* Zero extend the operand. */
3431 ax_zero_ext (expr
, addr_size_bits
);
3432 i
= ax_goto (expr
, aop_if_goto
);
3433 dw_labels
.push_back (op_ptr
+ offset
- base
);
3434 patches
.push_back (i
);
3441 case DW_OP_bit_piece
:
3445 if (op_ptr
- 1 == previous_piece
)
3446 error (_("Cannot translate empty pieces to agent expressions"));
3447 previous_piece
= op_ptr
- 1;
3449 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3450 if (op
== DW_OP_piece
)
3456 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3458 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3459 error (_("Expression pieces exceed word size"));
3461 /* Access the bits. */
3464 case axs_lvalue_register
:
3465 ax_reg (expr
, loc
->u
.reg
);
3468 case axs_lvalue_memory
:
3469 /* Offset the pointer, if needed. */
3472 ax_const_l (expr
, uoffset
/ 8);
3473 ax_simple (expr
, aop_add
);
3476 access_memory (arch
, expr
, size
);
3480 /* For a bits-big-endian target, shift up what we already
3481 have. For a bits-little-endian target, shift up the
3482 new data. Note that there is a potential bug here if
3483 the DWARF expression leaves multiple values on the
3485 if (bits_collected
> 0)
3487 if (bits_big_endian
)
3489 ax_simple (expr
, aop_swap
);
3490 ax_const_l (expr
, size
);
3491 ax_simple (expr
, aop_lsh
);
3492 /* We don't need a second swap here, because
3493 aop_bit_or is symmetric. */
3497 ax_const_l (expr
, size
);
3498 ax_simple (expr
, aop_lsh
);
3500 ax_simple (expr
, aop_bit_or
);
3503 bits_collected
+= size
;
3504 loc
->kind
= axs_rvalue
;
3508 case DW_OP_GNU_uninit
:
3514 struct dwarf2_locexpr_baton block
;
3515 int size
= (op
== DW_OP_call2
? 2 : 4);
3517 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3520 cu_offset cuoffset
= (cu_offset
) uoffset
;
3521 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
,
3524 /* DW_OP_call_ref is currently not supported. */
3525 gdb_assert (block
.per_cu
== per_cu
);
3527 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3528 block
.data
+ block
.size
, per_cu
);
3532 case DW_OP_call_ref
:
3535 case DW_OP_GNU_variable_value
:
3543 /* Patch all the branches we emitted. */
3544 for (int i
= 0; i
< patches
.size (); ++i
)
3546 int targ
= offsets
[dw_labels
[i
]];
3548 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3549 ax_label (expr
, patches
[i
], targ
);
3554 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3555 evaluator to calculate the location. */
3556 static struct value
*
3557 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3559 struct dwarf2_locexpr_baton
*dlbaton
3560 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3563 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3564 dlbaton
->size
, dlbaton
->per_cu
);
3569 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3570 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3573 static struct value
*
3574 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3576 struct dwarf2_locexpr_baton
*dlbaton
3577 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3579 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3583 /* Implementation of get_symbol_read_needs from
3584 symbol_computed_ops. */
3586 static enum symbol_needs_kind
3587 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3589 struct dwarf2_locexpr_baton
*dlbaton
3590 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3592 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3596 /* Return true if DATA points to the end of a piece. END is one past
3597 the last byte in the expression. */
3600 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3602 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3605 /* Helper for locexpr_describe_location_piece that finds the name of a
3609 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3613 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3614 We'd rather print *something* here than throw an error. */
3615 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3616 /* gdbarch_register_name may just return "", return something more
3617 descriptive for bad register numbers. */
3620 /* The text is output as "$bad_register_number".
3621 That is why we use the underscores. */
3622 return _("bad_register_number");
3624 return gdbarch_register_name (gdbarch
, regnum
);
3627 /* Nicely describe a single piece of a location, returning an updated
3628 position in the bytecode sequence. This function cannot recognize
3629 all locations; if a location is not recognized, it simply returns
3630 DATA. If there is an error during reading, e.g. we run off the end
3631 of the buffer, an error is thrown. */
3633 static const gdb_byte
*
3634 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3635 CORE_ADDR addr
, struct objfile
*objfile
,
3636 struct dwarf2_per_cu_data
*per_cu
,
3637 const gdb_byte
*data
, const gdb_byte
*end
,
3638 unsigned int addr_size
)
3640 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3643 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3645 fprintf_filtered (stream
, _("a variable in $%s"),
3646 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3649 else if (data
[0] == DW_OP_regx
)
3653 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3654 fprintf_filtered (stream
, _("a variable in $%s"),
3655 locexpr_regname (gdbarch
, reg
));
3657 else if (data
[0] == DW_OP_fbreg
)
3659 const struct block
*b
;
3660 struct symbol
*framefunc
;
3662 int64_t frame_offset
;
3663 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3665 int64_t base_offset
= 0;
3667 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3668 if (!piece_end_p (new_data
, end
))
3672 b
= block_for_pc (addr
);
3675 error (_("No block found for address for symbol \"%s\"."),
3676 symbol
->print_name ());
3678 framefunc
= block_linkage_function (b
);
3681 error (_("No function found for block for symbol \"%s\"."),
3682 symbol
->print_name ());
3684 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3686 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3688 const gdb_byte
*buf_end
;
3690 frame_reg
= base_data
[0] - DW_OP_breg0
;
3691 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3693 if (buf_end
!= base_data
+ base_size
)
3694 error (_("Unexpected opcode after "
3695 "DW_OP_breg%u for symbol \"%s\"."),
3696 frame_reg
, symbol
->print_name ());
3698 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3700 /* The frame base is just the register, with no offset. */
3701 frame_reg
= base_data
[0] - DW_OP_reg0
;
3706 /* We don't know what to do with the frame base expression,
3707 so we can't trace this variable; give up. */
3711 fprintf_filtered (stream
,
3712 _("a variable at frame base reg $%s offset %s+%s"),
3713 locexpr_regname (gdbarch
, frame_reg
),
3714 plongest (base_offset
), plongest (frame_offset
));
3716 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3717 && piece_end_p (data
, end
))
3721 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3723 fprintf_filtered (stream
,
3724 _("a variable at offset %s from base reg $%s"),
3726 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3729 /* The location expression for a TLS variable looks like this (on a
3732 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3733 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3735 0x3 is the encoding for DW_OP_addr, which has an operand as long
3736 as the size of an address on the target machine (here is 8
3737 bytes). Note that more recent version of GCC emit DW_OP_const4u
3738 or DW_OP_const8u, depending on address size, rather than
3739 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3740 The operand represents the offset at which the variable is within
3741 the thread local storage. */
3743 else if (data
+ 1 + addr_size
< end
3744 && (data
[0] == DW_OP_addr
3745 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3746 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3747 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3748 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3749 && piece_end_p (data
+ 2 + addr_size
, end
))
3752 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3753 gdbarch_byte_order (gdbarch
));
3755 fprintf_filtered (stream
,
3756 _("a thread-local variable at offset 0x%s "
3757 "in the thread-local storage for `%s'"),
3758 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3760 data
+= 1 + addr_size
+ 1;
3763 /* With -gsplit-dwarf a TLS variable can also look like this:
3764 DW_AT_location : 3 byte block: fc 4 e0
3765 (DW_OP_GNU_const_index: 4;
3766 DW_OP_GNU_push_tls_address) */
3767 else if (data
+ 3 <= end
3768 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3769 && data
[0] == DW_OP_GNU_const_index
3771 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3772 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3773 && piece_end_p (data
+ 2 + leb128_size
, end
))
3777 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3778 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3779 fprintf_filtered (stream
,
3780 _("a thread-local variable at offset 0x%s "
3781 "in the thread-local storage for `%s'"),
3782 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3786 else if (data
[0] >= DW_OP_lit0
3787 && data
[0] <= DW_OP_lit31
3789 && data
[1] == DW_OP_stack_value
)
3791 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3798 /* Disassemble an expression, stopping at the end of a piece or at the
3799 end of the expression. Returns a pointer to the next unread byte
3800 in the input expression. If ALL is nonzero, then this function
3801 will keep going until it reaches the end of the expression.
3802 If there is an error during reading, e.g. we run off the end
3803 of the buffer, an error is thrown. */
3805 static const gdb_byte
*
3806 disassemble_dwarf_expression (struct ui_file
*stream
,
3807 struct gdbarch
*arch
, unsigned int addr_size
,
3808 int offset_size
, const gdb_byte
*start
,
3809 const gdb_byte
*data
, const gdb_byte
*end
,
3810 int indent
, int all
,
3811 struct dwarf2_per_cu_data
*per_cu
)
3815 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3817 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3822 name
= get_DW_OP_name (op
);
3825 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3826 op
, (long) (data
- 1 - start
));
3827 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3828 (long) (data
- 1 - start
), name
);
3833 ul
= extract_unsigned_integer (data
, addr_size
,
3834 gdbarch_byte_order (arch
));
3836 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3840 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3842 fprintf_filtered (stream
, " %s", pulongest (ul
));
3845 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3847 fprintf_filtered (stream
, " %s", plongest (l
));
3850 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3852 fprintf_filtered (stream
, " %s", pulongest (ul
));
3855 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3857 fprintf_filtered (stream
, " %s", plongest (l
));
3860 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3862 fprintf_filtered (stream
, " %s", pulongest (ul
));
3865 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3867 fprintf_filtered (stream
, " %s", plongest (l
));
3870 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3872 fprintf_filtered (stream
, " %s", pulongest (ul
));
3875 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3877 fprintf_filtered (stream
, " %s", plongest (l
));
3880 data
= safe_read_uleb128 (data
, end
, &ul
);
3881 fprintf_filtered (stream
, " %s", pulongest (ul
));
3884 data
= safe_read_sleb128 (data
, end
, &l
);
3885 fprintf_filtered (stream
, " %s", plongest (l
));
3920 fprintf_filtered (stream
, " [$%s]",
3921 locexpr_regname (arch
, op
- DW_OP_reg0
));
3925 data
= safe_read_uleb128 (data
, end
, &ul
);
3926 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3927 locexpr_regname (arch
, (int) ul
));
3930 case DW_OP_implicit_value
:
3931 data
= safe_read_uleb128 (data
, end
, &ul
);
3933 fprintf_filtered (stream
, " %s", pulongest (ul
));
3968 data
= safe_read_sleb128 (data
, end
, &l
);
3969 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3970 locexpr_regname (arch
, op
- DW_OP_breg0
));
3974 data
= safe_read_uleb128 (data
, end
, &ul
);
3975 data
= safe_read_sleb128 (data
, end
, &l
);
3976 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3978 locexpr_regname (arch
, (int) ul
),
3983 data
= safe_read_sleb128 (data
, end
, &l
);
3984 fprintf_filtered (stream
, " %s", plongest (l
));
3987 case DW_OP_xderef_size
:
3988 case DW_OP_deref_size
:
3990 fprintf_filtered (stream
, " %d", *data
);
3994 case DW_OP_plus_uconst
:
3995 data
= safe_read_uleb128 (data
, end
, &ul
);
3996 fprintf_filtered (stream
, " %s", pulongest (ul
));
4000 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4002 fprintf_filtered (stream
, " to %ld",
4003 (long) (data
+ l
- start
));
4007 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4009 fprintf_filtered (stream
, " %ld",
4010 (long) (data
+ l
- start
));
4014 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4016 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4020 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4022 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4025 case DW_OP_call_ref
:
4026 ul
= extract_unsigned_integer (data
, offset_size
,
4027 gdbarch_byte_order (arch
));
4028 data
+= offset_size
;
4029 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4033 data
= safe_read_uleb128 (data
, end
, &ul
);
4034 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4037 case DW_OP_bit_piece
:
4041 data
= safe_read_uleb128 (data
, end
, &ul
);
4042 data
= safe_read_uleb128 (data
, end
, &offset
);
4043 fprintf_filtered (stream
, " size %s offset %s (bits)",
4044 pulongest (ul
), pulongest (offset
));
4048 case DW_OP_implicit_pointer
:
4049 case DW_OP_GNU_implicit_pointer
:
4051 ul
= extract_unsigned_integer (data
, offset_size
,
4052 gdbarch_byte_order (arch
));
4053 data
+= offset_size
;
4055 data
= safe_read_sleb128 (data
, end
, &l
);
4057 fprintf_filtered (stream
, " DIE %s offset %s",
4058 phex_nz (ul
, offset_size
),
4063 case DW_OP_deref_type
:
4064 case DW_OP_GNU_deref_type
:
4066 int deref_addr_size
= *data
++;
4069 data
= safe_read_uleb128 (data
, end
, &ul
);
4070 cu_offset offset
= (cu_offset
) ul
;
4071 type
= dwarf2_get_die_type (offset
, per_cu
);
4072 fprintf_filtered (stream
, "<");
4073 type_print (type
, "", stream
, -1);
4074 fprintf_filtered (stream
, " [0x%s]> %d",
4075 phex_nz (to_underlying (offset
), 0),
4080 case DW_OP_const_type
:
4081 case DW_OP_GNU_const_type
:
4085 data
= safe_read_uleb128 (data
, end
, &ul
);
4086 cu_offset type_die
= (cu_offset
) ul
;
4087 type
= dwarf2_get_die_type (type_die
, per_cu
);
4088 fprintf_filtered (stream
, "<");
4089 type_print (type
, "", stream
, -1);
4090 fprintf_filtered (stream
, " [0x%s]>",
4091 phex_nz (to_underlying (type_die
), 0));
4095 case DW_OP_regval_type
:
4096 case DW_OP_GNU_regval_type
:
4101 data
= safe_read_uleb128 (data
, end
, ®
);
4102 data
= safe_read_uleb128 (data
, end
, &ul
);
4103 cu_offset type_die
= (cu_offset
) ul
;
4105 type
= dwarf2_get_die_type (type_die
, per_cu
);
4106 fprintf_filtered (stream
, "<");
4107 type_print (type
, "", stream
, -1);
4108 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4109 phex_nz (to_underlying (type_die
), 0),
4110 locexpr_regname (arch
, reg
));
4115 case DW_OP_GNU_convert
:
4116 case DW_OP_reinterpret
:
4117 case DW_OP_GNU_reinterpret
:
4119 data
= safe_read_uleb128 (data
, end
, &ul
);
4120 cu_offset type_die
= (cu_offset
) ul
;
4122 if (to_underlying (type_die
) == 0)
4123 fprintf_filtered (stream
, "<0>");
4128 type
= dwarf2_get_die_type (type_die
, per_cu
);
4129 fprintf_filtered (stream
, "<");
4130 type_print (type
, "", stream
, -1);
4131 fprintf_filtered (stream
, " [0x%s]>",
4132 phex_nz (to_underlying (type_die
), 0));
4137 case DW_OP_entry_value
:
4138 case DW_OP_GNU_entry_value
:
4139 data
= safe_read_uleb128 (data
, end
, &ul
);
4140 fputc_filtered ('\n', stream
);
4141 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4142 start
, data
, data
+ ul
, indent
+ 2,
4147 case DW_OP_GNU_parameter_ref
:
4148 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4150 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4154 case DW_OP_GNU_addr_index
:
4155 data
= safe_read_uleb128 (data
, end
, &ul
);
4156 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4157 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4159 case DW_OP_GNU_const_index
:
4160 data
= safe_read_uleb128 (data
, end
, &ul
);
4161 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4162 fprintf_filtered (stream
, " %s", pulongest (ul
));
4165 case DW_OP_GNU_variable_value
:
4166 ul
= extract_unsigned_integer (data
, offset_size
,
4167 gdbarch_byte_order (arch
));
4168 data
+= offset_size
;
4169 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4173 fprintf_filtered (stream
, "\n");
4179 static bool dwarf_always_disassemble
;
4182 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4183 struct cmd_list_element
*c
, const char *value
)
4185 fprintf_filtered (file
,
4186 _("Whether to always disassemble "
4187 "DWARF expressions is %s.\n"),
4191 /* Describe a single location, which may in turn consist of multiple
4195 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4196 struct ui_file
*stream
,
4197 const gdb_byte
*data
, size_t size
,
4198 struct objfile
*objfile
, unsigned int addr_size
,
4199 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4201 const gdb_byte
*end
= data
+ size
;
4202 int first_piece
= 1, bad
= 0;
4206 const gdb_byte
*here
= data
;
4207 int disassemble
= 1;
4212 fprintf_filtered (stream
, _(", and "));
4214 if (!dwarf_always_disassemble
)
4216 data
= locexpr_describe_location_piece (symbol
, stream
,
4217 addr
, objfile
, per_cu
,
4218 data
, end
, addr_size
);
4219 /* If we printed anything, or if we have an empty piece,
4220 then don't disassemble. */
4222 || data
[0] == DW_OP_piece
4223 || data
[0] == DW_OP_bit_piece
)
4228 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4229 data
= disassemble_dwarf_expression (stream
,
4230 get_objfile_arch (objfile
),
4231 addr_size
, offset_size
, data
,
4233 dwarf_always_disassemble
,
4239 int empty
= data
== here
;
4242 fprintf_filtered (stream
, " ");
4243 if (data
[0] == DW_OP_piece
)
4247 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4250 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4253 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4256 else if (data
[0] == DW_OP_bit_piece
)
4258 uint64_t bits
, offset
;
4260 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4261 data
= safe_read_uleb128 (data
, end
, &offset
);
4264 fprintf_filtered (stream
,
4265 _("an empty %s-bit piece"),
4268 fprintf_filtered (stream
,
4269 _(" [%s-bit piece, offset %s bits]"),
4270 pulongest (bits
), pulongest (offset
));
4280 if (bad
|| data
> end
)
4281 error (_("Corrupted DWARF2 expression for \"%s\"."),
4282 symbol
->print_name ());
4285 /* Print a natural-language description of SYMBOL to STREAM. This
4286 version is for a symbol with a single location. */
4289 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4290 struct ui_file
*stream
)
4292 struct dwarf2_locexpr_baton
*dlbaton
4293 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4294 struct objfile
*objfile
= dlbaton
->per_cu
->objfile ();
4295 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4296 int offset_size
= dlbaton
->per_cu
->offset_size ();
4298 locexpr_describe_location_1 (symbol
, addr
, stream
,
4299 dlbaton
->data
, dlbaton
->size
,
4300 objfile
, addr_size
, offset_size
,
4304 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4305 any necessary bytecode in AX. */
4308 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4309 struct axs_value
*value
)
4311 struct dwarf2_locexpr_baton
*dlbaton
4312 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4313 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4315 if (dlbaton
->size
== 0)
4316 value
->optimized_out
= 1;
4318 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4319 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
);
4322 /* symbol_computed_ops 'generate_c_location' method. */
4325 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4326 struct gdbarch
*gdbarch
,
4327 unsigned char *registers_used
,
4328 CORE_ADDR pc
, const char *result_name
)
4330 struct dwarf2_locexpr_baton
*dlbaton
4331 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4332 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4334 if (dlbaton
->size
== 0)
4335 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4337 compile_dwarf_expr_to_c (stream
, result_name
,
4338 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4339 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4343 /* The set of location functions used with the DWARF-2 expression
4345 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4346 locexpr_read_variable
,
4347 locexpr_read_variable_at_entry
,
4348 locexpr_get_symbol_read_needs
,
4349 locexpr_describe_location
,
4350 0, /* location_has_loclist */
4351 locexpr_tracepoint_var_ref
,
4352 locexpr_generate_c_location
4356 /* Wrapper functions for location lists. These generally find
4357 the appropriate location expression and call something above. */
4359 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4360 evaluator to calculate the location. */
4361 static struct value
*
4362 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4364 struct dwarf2_loclist_baton
*dlbaton
4365 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4367 const gdb_byte
*data
;
4369 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4371 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4372 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4378 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4379 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4382 Function always returns non-NULL value, it may be marked optimized out if
4383 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4384 if it cannot resolve the parameter for any reason. */
4386 static struct value
*
4387 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4389 struct dwarf2_loclist_baton
*dlbaton
4390 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4391 const gdb_byte
*data
;
4395 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4396 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4398 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4400 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4402 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4405 /* Implementation of get_symbol_read_needs from
4406 symbol_computed_ops. */
4408 static enum symbol_needs_kind
4409 loclist_symbol_needs (struct symbol
*symbol
)
4411 /* If there's a location list, then assume we need to have a frame
4412 to choose the appropriate location expression. With tracking of
4413 global variables this is not necessarily true, but such tracking
4414 is disabled in GCC at the moment until we figure out how to
4417 return SYMBOL_NEEDS_FRAME
;
4420 /* Print a natural-language description of SYMBOL to STREAM. This
4421 version applies when there is a list of different locations, each
4422 with a specified address range. */
4425 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4426 struct ui_file
*stream
)
4428 struct dwarf2_loclist_baton
*dlbaton
4429 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4430 const gdb_byte
*loc_ptr
, *buf_end
;
4431 struct objfile
*objfile
= dlbaton
->per_cu
->objfile ();
4432 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4433 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4434 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4435 int offset_size
= dlbaton
->per_cu
->offset_size ();
4436 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4437 /* Adjust base_address for relocatable objects. */
4438 CORE_ADDR base_offset
= dlbaton
->per_cu
->text_offset ();
4439 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4442 loc_ptr
= dlbaton
->data
;
4443 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4445 fprintf_filtered (stream
, _("multi-location:\n"));
4447 /* Iterate through locations until we run out. */
4450 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4452 enum debug_loc_kind kind
;
4453 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4455 if (dlbaton
->from_dwo
)
4456 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4457 loc_ptr
, buf_end
, &new_ptr
,
4458 &low
, &high
, byte_order
);
4460 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4462 byte_order
, addr_size
,
4467 case DEBUG_LOC_END_OF_LIST
:
4470 case DEBUG_LOC_BASE_ADDRESS
:
4471 base_address
= high
+ base_offset
;
4472 fprintf_filtered (stream
, _(" Base address %s"),
4473 paddress (gdbarch
, base_address
));
4475 case DEBUG_LOC_START_END
:
4476 case DEBUG_LOC_START_LENGTH
:
4478 case DEBUG_LOC_BUFFER_OVERFLOW
:
4479 case DEBUG_LOC_INVALID_ENTRY
:
4480 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4481 symbol
->print_name ());
4483 gdb_assert_not_reached ("bad debug_loc_kind");
4486 /* Otherwise, a location expression entry. */
4487 low
+= base_address
;
4488 high
+= base_address
;
4490 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4491 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4493 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4496 /* (It would improve readability to print only the minimum
4497 necessary digits of the second number of the range.) */
4498 fprintf_filtered (stream
, _(" Range %s-%s: "),
4499 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4501 /* Now describe this particular location. */
4502 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4503 objfile
, addr_size
, offset_size
,
4506 fprintf_filtered (stream
, "\n");
4512 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4513 any necessary bytecode in AX. */
4515 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4516 struct axs_value
*value
)
4518 struct dwarf2_loclist_baton
*dlbaton
4519 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4520 const gdb_byte
*data
;
4522 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4524 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4526 value
->optimized_out
= 1;
4528 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4532 /* symbol_computed_ops 'generate_c_location' method. */
4535 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4536 struct gdbarch
*gdbarch
,
4537 unsigned char *registers_used
,
4538 CORE_ADDR pc
, const char *result_name
)
4540 struct dwarf2_loclist_baton
*dlbaton
4541 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4542 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4543 const gdb_byte
*data
;
4546 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4548 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4550 compile_dwarf_expr_to_c (stream
, result_name
,
4551 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4556 /* The set of location functions used with the DWARF-2 expression
4557 evaluator and location lists. */
4558 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4559 loclist_read_variable
,
4560 loclist_read_variable_at_entry
,
4561 loclist_symbol_needs
,
4562 loclist_describe_location
,
4563 1, /* location_has_loclist */
4564 loclist_tracepoint_var_ref
,
4565 loclist_generate_c_location
4568 void _initialize_dwarf2loc ();
4570 _initialize_dwarf2loc ()
4572 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4573 &entry_values_debug
,
4574 _("Set entry values and tail call frames "
4576 _("Show entry values and tail call frames "
4578 _("When non-zero, the process of determining "
4579 "parameter values from function entry point "
4580 "and tail call frames will be printed."),
4582 show_entry_values_debug
,
4583 &setdebuglist
, &showdebuglist
);
4585 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4586 &dwarf_always_disassemble
, _("\
4587 Set whether `info address' always disassembles DWARF expressions."), _("\
4588 Show whether `info address' always disassembles DWARF expressions."), _("\
4589 When enabled, DWARF expressions are always printed in an assembly-like\n\
4590 syntax. When disabled, expressions will be printed in a more\n\
4591 conversational style, when possible."),
4593 show_dwarf_always_disassemble
,
4595 &show_dwarf_cmdlist
);