1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2019 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/>. */
24 /* Standard C++ includes. */
26 #include <unordered_set>
29 /* Local non-gdb includes. */
33 #include "common/byte-vector.h"
34 #include "common/selftest.h"
35 #include "common/underlying.h"
36 #include "compile/compile.h"
37 #include "complaints.h"
38 #include "dwarf2-frame.h"
40 #include "dwarf2expr.h"
41 #include "dwarf2loc.h"
52 extern int dwarf_always_disassemble
;
54 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
55 struct frame_info
*frame
,
58 struct dwarf2_per_cu_data
*per_cu
,
59 struct type
*subobj_type
,
60 LONGEST subobj_byte_offset
);
62 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
63 (struct frame_info
*frame
,
64 enum call_site_parameter_kind kind
,
65 union call_site_parameter_u kind_u
,
66 struct dwarf2_per_cu_data
**per_cu_return
);
68 static struct value
*indirect_synthetic_pointer
69 (sect_offset die
, LONGEST byte_offset
,
70 struct dwarf2_per_cu_data
*per_cu
,
71 struct frame_info
*frame
,
72 struct type
*type
, bool resolve_abstract_p
= false);
74 /* Until these have formal names, we define these here.
75 ref: http://gcc.gnu.org/wiki/DebugFission
76 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
77 and is then followed by data specific to that entry. */
81 /* Indicates the end of the list of entries. */
82 DEBUG_LOC_END_OF_LIST
= 0,
84 /* This is followed by an unsigned LEB128 number that is an index into
85 .debug_addr and specifies the base address for all following entries. */
86 DEBUG_LOC_BASE_ADDRESS
= 1,
88 /* This is followed by two unsigned LEB128 numbers that are indices into
89 .debug_addr and specify the beginning and ending addresses, and then
90 a normal location expression as in .debug_loc. */
91 DEBUG_LOC_START_END
= 2,
93 /* This is followed by an unsigned LEB128 number that is an index into
94 .debug_addr and specifies the beginning address, and a 4 byte unsigned
95 number that specifies the length, and then a normal location expression
97 DEBUG_LOC_START_LENGTH
= 3,
99 /* An internal value indicating there is insufficient data. */
100 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
102 /* An internal value indicating an invalid kind of entry was found. */
103 DEBUG_LOC_INVALID_ENTRY
= -2
106 /* Helper function which throws an error if a synthetic pointer is
110 invalid_synthetic_pointer (void)
112 error (_("access outside bounds of object "
113 "referenced via synthetic pointer"));
116 /* Decode the addresses in a non-dwo .debug_loc entry.
117 A pointer to the next byte to examine is returned in *NEW_PTR.
118 The encoded low,high addresses are return in *LOW,*HIGH.
119 The result indicates the kind of entry found. */
121 static enum debug_loc_kind
122 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
123 const gdb_byte
**new_ptr
,
124 CORE_ADDR
*low
, CORE_ADDR
*high
,
125 enum bfd_endian byte_order
,
126 unsigned int addr_size
,
129 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
131 if (buf_end
- loc_ptr
< 2 * addr_size
)
132 return DEBUG_LOC_BUFFER_OVERFLOW
;
135 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
137 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
138 loc_ptr
+= addr_size
;
141 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
143 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
144 loc_ptr
+= addr_size
;
148 /* A base-address-selection entry. */
149 if ((*low
& base_mask
) == base_mask
)
150 return DEBUG_LOC_BASE_ADDRESS
;
152 /* An end-of-list entry. */
153 if (*low
== 0 && *high
== 0)
154 return DEBUG_LOC_END_OF_LIST
;
156 return DEBUG_LOC_START_END
;
159 /* Decode the addresses in .debug_loclists entry.
160 A pointer to the next byte to examine is returned in *NEW_PTR.
161 The encoded low,high addresses are return in *LOW,*HIGH.
162 The result indicates the kind of entry found. */
164 static enum debug_loc_kind
165 decode_debug_loclists_addresses (struct dwarf2_per_cu_data
*per_cu
,
166 const gdb_byte
*loc_ptr
,
167 const gdb_byte
*buf_end
,
168 const gdb_byte
**new_ptr
,
169 CORE_ADDR
*low
, CORE_ADDR
*high
,
170 enum bfd_endian byte_order
,
171 unsigned int addr_size
,
176 if (loc_ptr
== buf_end
)
177 return DEBUG_LOC_BUFFER_OVERFLOW
;
181 case DW_LLE_end_of_list
:
183 return DEBUG_LOC_END_OF_LIST
;
184 case DW_LLE_base_address
:
185 if (loc_ptr
+ addr_size
> buf_end
)
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
190 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
191 loc_ptr
+= addr_size
;
193 return DEBUG_LOC_BASE_ADDRESS
;
194 case DW_LLE_offset_pair
:
195 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
197 return DEBUG_LOC_BUFFER_OVERFLOW
;
199 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
201 return DEBUG_LOC_BUFFER_OVERFLOW
;
204 return DEBUG_LOC_START_END
;
206 return DEBUG_LOC_INVALID_ENTRY
;
210 /* Decode the addresses in .debug_loc.dwo entry.
211 A pointer to the next byte to examine is returned in *NEW_PTR.
212 The encoded low,high addresses are return in *LOW,*HIGH.
213 The result indicates the kind of entry found. */
215 static enum debug_loc_kind
216 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
217 const gdb_byte
*loc_ptr
,
218 const gdb_byte
*buf_end
,
219 const gdb_byte
**new_ptr
,
220 CORE_ADDR
*low
, CORE_ADDR
*high
,
221 enum bfd_endian byte_order
)
223 uint64_t low_index
, high_index
;
225 if (loc_ptr
== buf_end
)
226 return DEBUG_LOC_BUFFER_OVERFLOW
;
230 case DW_LLE_GNU_end_of_list_entry
:
232 return DEBUG_LOC_END_OF_LIST
;
233 case DW_LLE_GNU_base_address_selection_entry
:
235 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
237 return DEBUG_LOC_BUFFER_OVERFLOW
;
238 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
240 return DEBUG_LOC_BASE_ADDRESS
;
241 case DW_LLE_GNU_start_end_entry
:
242 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
244 return DEBUG_LOC_BUFFER_OVERFLOW
;
245 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
246 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
248 return DEBUG_LOC_BUFFER_OVERFLOW
;
249 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
251 return DEBUG_LOC_START_END
;
252 case DW_LLE_GNU_start_length_entry
:
253 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
255 return DEBUG_LOC_BUFFER_OVERFLOW
;
256 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
257 if (loc_ptr
+ 4 > buf_end
)
258 return DEBUG_LOC_BUFFER_OVERFLOW
;
260 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
261 *new_ptr
= loc_ptr
+ 4;
262 return DEBUG_LOC_START_LENGTH
;
264 return DEBUG_LOC_INVALID_ENTRY
;
268 /* A function for dealing with location lists. Given a
269 symbol baton (BATON) and a pc value (PC), find the appropriate
270 location expression, set *LOCEXPR_LENGTH, and return a pointer
271 to the beginning of the expression. Returns NULL on failure.
273 For now, only return the first matching location expression; there
274 can be more than one in the list. */
277 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
278 size_t *locexpr_length
, CORE_ADDR pc
)
280 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
281 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
282 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
283 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
284 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
285 /* Adjust base_address for relocatable objects. */
286 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
287 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
288 const gdb_byte
*loc_ptr
, *buf_end
;
290 loc_ptr
= baton
->data
;
291 buf_end
= baton
->data
+ baton
->size
;
295 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
297 enum debug_loc_kind kind
;
298 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
301 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
302 loc_ptr
, buf_end
, &new_ptr
,
303 &low
, &high
, byte_order
);
304 else if (dwarf2_version (baton
->per_cu
) < 5)
305 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
307 byte_order
, addr_size
,
310 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
311 loc_ptr
, buf_end
, &new_ptr
,
312 &low
, &high
, byte_order
,
313 addr_size
, signed_addr_p
);
318 case DEBUG_LOC_END_OF_LIST
:
321 case DEBUG_LOC_BASE_ADDRESS
:
322 base_address
= high
+ base_offset
;
324 case DEBUG_LOC_START_END
:
325 case DEBUG_LOC_START_LENGTH
:
327 case DEBUG_LOC_BUFFER_OVERFLOW
:
328 case DEBUG_LOC_INVALID_ENTRY
:
329 error (_("dwarf2_find_location_expression: "
330 "Corrupted DWARF expression."));
332 gdb_assert_not_reached ("bad debug_loc_kind");
335 /* Otherwise, a location expression entry.
336 If the entry is from a DWO, don't add base address: the entry is from
337 .debug_addr which already has the DWARF "base address". We still add
338 base_offset in case we're debugging a PIE executable. */
347 high
+= base_address
;
350 if (dwarf2_version (baton
->per_cu
) < 5)
352 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
357 unsigned int bytes_read
;
359 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
360 loc_ptr
+= bytes_read
;
363 if (low
== high
&& pc
== low
)
365 /* This is entry PC record present only at entry point
366 of a function. Verify it is really the function entry point. */
368 const struct block
*pc_block
= block_for_pc (pc
);
369 struct symbol
*pc_func
= NULL
;
372 pc_func
= block_linkage_function (pc_block
);
374 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
376 *locexpr_length
= length
;
381 if (pc
>= low
&& pc
< high
)
383 *locexpr_length
= length
;
391 /* This is the baton used when performing dwarf2 expression
393 struct dwarf_expr_baton
395 struct frame_info
*frame
;
396 struct dwarf2_per_cu_data
*per_cu
;
397 CORE_ADDR obj_address
;
400 /* Implement find_frame_base_location method for LOC_BLOCK functions using
401 DWARF expression for its DW_AT_frame_base. */
404 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
405 const gdb_byte
**start
, size_t *length
)
407 struct dwarf2_locexpr_baton
*symbaton
408 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
410 *length
= symbaton
->size
;
411 *start
= symbaton
->data
;
414 /* Implement the struct symbol_block_ops::get_frame_base method for
415 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
418 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
420 struct gdbarch
*gdbarch
;
422 struct dwarf2_locexpr_baton
*dlbaton
;
423 const gdb_byte
*start
;
425 struct value
*result
;
427 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
428 Thus, it's supposed to provide the find_frame_base_location method as
430 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
432 gdbarch
= get_frame_arch (frame
);
433 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
434 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
436 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
437 (framefunc
, get_frame_pc (frame
), &start
, &length
);
438 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
441 /* The DW_AT_frame_base attribute contains a location description which
442 computes the base address itself. However, the call to
443 dwarf2_evaluate_loc_desc returns a value representing a variable at
444 that address. The frame base address is thus this variable's
446 return value_address (result
);
449 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
450 function uses DWARF expression for its DW_AT_frame_base. */
452 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
454 locexpr_find_frame_base_location
,
455 locexpr_get_frame_base
458 /* Implement find_frame_base_location method for LOC_BLOCK functions using
459 DWARF location list for its DW_AT_frame_base. */
462 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
463 const gdb_byte
**start
, size_t *length
)
465 struct dwarf2_loclist_baton
*symbaton
466 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
468 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
471 /* Implement the struct symbol_block_ops::get_frame_base method for
472 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
475 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
477 struct gdbarch
*gdbarch
;
479 struct dwarf2_loclist_baton
*dlbaton
;
480 const gdb_byte
*start
;
482 struct value
*result
;
484 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
485 Thus, it's supposed to provide the find_frame_base_location method as
487 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
489 gdbarch
= get_frame_arch (frame
);
490 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
491 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
493 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
494 (framefunc
, get_frame_pc (frame
), &start
, &length
);
495 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
498 /* The DW_AT_frame_base attribute contains a location description which
499 computes the base address itself. However, the call to
500 dwarf2_evaluate_loc_desc returns a value representing a variable at
501 that address. The frame base address is thus this variable's
503 return value_address (result
);
506 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
507 function uses DWARF location list for its DW_AT_frame_base. */
509 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
511 loclist_find_frame_base_location
,
512 loclist_get_frame_base
515 /* See dwarf2loc.h. */
518 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
519 const gdb_byte
**start
, size_t *length
)
521 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
523 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
525 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
531 error (_("Could not find the frame base for \"%s\"."),
532 SYMBOL_NATURAL_NAME (framefunc
));
536 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
538 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
540 return ctx
->get_frame_pc ();
544 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
545 struct dwarf2_per_cu_data
*per_cu
)
547 struct dwarf2_locexpr_baton block
;
549 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
,
550 get_frame_pc_for_per_cu_dwarf_call
,
553 /* DW_OP_call_ref is currently not supported. */
554 gdb_assert (block
.per_cu
== per_cu
);
556 ctx
->eval (block
.data
, block
.size
);
559 /* Given context CTX, section offset SECT_OFF, and compilation unit
560 data PER_CU, execute the "variable value" operation on the DIE
561 found at SECT_OFF. */
563 static struct value
*
564 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
565 struct dwarf2_per_cu_data
*per_cu
)
567 struct type
*die_type
= dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
);
569 if (die_type
== NULL
)
570 error (_("Bad DW_OP_GNU_variable_value DIE."));
572 /* Note: Things still work when the following test is removed. This
573 test and error is here to conform to the proposed specification. */
574 if (TYPE_CODE (die_type
) != TYPE_CODE_INT
575 && TYPE_CODE (die_type
) != TYPE_CODE_PTR
)
576 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
578 struct type
*type
= lookup_pointer_type (die_type
);
579 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
580 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, frame
, type
, true);
583 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
587 struct frame_info
*frame
;
588 struct dwarf2_per_cu_data
*per_cu
;
589 CORE_ADDR obj_address
;
591 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
592 the frame in BATON. */
594 CORE_ADDR
get_frame_cfa () override
596 return dwarf2_frame_cfa (frame
);
599 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
600 the frame in BATON. */
602 CORE_ADDR
get_frame_pc () override
604 return get_frame_address_in_block (frame
);
607 /* Using the objfile specified in BATON, find the address for the
608 current thread's thread-local storage with offset OFFSET. */
609 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
611 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
613 return target_translate_tls_address (objfile
, offset
);
616 /* Helper interface of per_cu_dwarf_call for
617 dwarf2_evaluate_loc_desc. */
619 void dwarf_call (cu_offset die_offset
) override
621 per_cu_dwarf_call (this, die_offset
, per_cu
);
624 /* Helper interface of sect_variable_value for
625 dwarf2_evaluate_loc_desc. */
627 struct value
*dwarf_variable_value (sect_offset sect_off
) override
629 return sect_variable_value (this, sect_off
, per_cu
);
632 struct type
*get_base_type (cu_offset die_offset
, int size
) override
634 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
636 error (_("Could not find type for DW_OP_const_type"));
637 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
638 error (_("DW_OP_const_type has different sizes for type and data"));
642 /* Callback function for dwarf2_evaluate_loc_desc.
643 Fetch the address indexed by DW_OP_GNU_addr_index. */
645 CORE_ADDR
get_addr_index (unsigned int index
) override
647 return dwarf2_read_addr_index (per_cu
, index
);
650 /* Callback function for get_object_address. Return the address of the VLA
653 CORE_ADDR
get_object_address () override
655 if (obj_address
== 0)
656 error (_("Location address is not set."));
660 /* Execute DWARF block of call_site_parameter which matches KIND and
661 KIND_U. Choose DEREF_SIZE value of that parameter. Search
662 caller of this objects's frame.
664 The caller can be from a different CU - per_cu_dwarf_call
665 implementation can be more simple as it does not support cross-CU
668 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
669 union call_site_parameter_u kind_u
,
670 int deref_size
) override
672 struct frame_info
*caller_frame
;
673 struct dwarf2_per_cu_data
*caller_per_cu
;
674 struct call_site_parameter
*parameter
;
675 const gdb_byte
*data_src
;
678 caller_frame
= get_prev_frame (frame
);
680 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
682 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
683 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
685 /* DEREF_SIZE size is not verified here. */
686 if (data_src
== NULL
)
687 throw_error (NO_ENTRY_VALUE_ERROR
,
688 _("Cannot resolve DW_AT_call_data_value"));
690 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
692 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
694 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
697 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
699 = get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
700 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
701 this->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
702 scoped_restore save_offset
= make_scoped_restore (&this->offset
);
703 this->offset
= dwarf2_per_cu_text_offset (per_cu
);
705 this->eval (data_src
, size
);
708 /* Using the frame specified in BATON, find the location expression
709 describing the frame base. Return a pointer to it in START and
710 its length in LENGTH. */
711 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
713 /* FIXME: cagney/2003-03-26: This code should be using
714 get_frame_base_address(), and then implement a dwarf2 specific
716 struct symbol
*framefunc
;
717 const struct block
*bl
= get_frame_block (frame
, NULL
);
720 error (_("frame address is not available."));
722 /* Use block_linkage_function, which returns a real (not inlined)
723 function, instead of get_frame_function, which may return an
725 framefunc
= block_linkage_function (bl
);
727 /* If we found a frame-relative symbol then it was certainly within
728 some function associated with a frame. If we can't find the frame,
729 something has gone wrong. */
730 gdb_assert (framefunc
!= NULL
);
732 func_get_frame_base_dwarf_block (framefunc
,
733 get_frame_address_in_block (frame
),
737 /* Read memory at ADDR (length LEN) into BUF. */
739 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
741 read_memory (addr
, buf
, len
);
744 /* Using the frame specified in BATON, return the value of register
745 REGNUM, treated as a pointer. */
746 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
748 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
749 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
751 return address_from_register (regnum
, frame
);
754 /* Implement "get_reg_value" callback. */
756 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
758 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
759 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
761 return value_from_register (type
, regnum
, frame
);
765 /* See dwarf2loc.h. */
767 unsigned int entry_values_debug
= 0;
769 /* Helper to set entry_values_debug. */
772 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
773 struct cmd_list_element
*c
, const char *value
)
775 fprintf_filtered (file
,
776 _("Entry values and tail call frames debugging is %s.\n"),
780 /* Find DW_TAG_call_site's DW_AT_call_target address.
781 CALLER_FRAME (for registers) can be NULL if it is not known. This function
782 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
785 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
786 struct call_site
*call_site
,
787 struct frame_info
*caller_frame
)
789 switch (FIELD_LOC_KIND (call_site
->target
))
791 case FIELD_LOC_KIND_DWARF_BLOCK
:
793 struct dwarf2_locexpr_baton
*dwarf_block
;
795 struct type
*caller_core_addr_type
;
796 struct gdbarch
*caller_arch
;
798 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
799 if (dwarf_block
== NULL
)
801 struct bound_minimal_symbol msym
;
803 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
804 throw_error (NO_ENTRY_VALUE_ERROR
,
805 _("DW_AT_call_target is not specified at %s in %s"),
806 paddress (call_site_gdbarch
, call_site
->pc
),
807 (msym
.minsym
== NULL
? "???"
808 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
811 if (caller_frame
== NULL
)
813 struct bound_minimal_symbol msym
;
815 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
816 throw_error (NO_ENTRY_VALUE_ERROR
,
817 _("DW_AT_call_target DWARF block resolving "
818 "requires known frame which is currently not "
819 "available at %s in %s"),
820 paddress (call_site_gdbarch
, call_site
->pc
),
821 (msym
.minsym
== NULL
? "???"
822 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
825 caller_arch
= get_frame_arch (caller_frame
);
826 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
827 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
828 dwarf_block
->data
, dwarf_block
->size
,
829 dwarf_block
->per_cu
);
830 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
831 if (VALUE_LVAL (val
) == lval_memory
)
832 return value_address (val
);
834 return value_as_address (val
);
837 case FIELD_LOC_KIND_PHYSNAME
:
839 const char *physname
;
840 struct bound_minimal_symbol msym
;
842 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
844 /* Handle both the mangled and demangled PHYSNAME. */
845 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
846 if (msym
.minsym
== NULL
)
848 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
849 throw_error (NO_ENTRY_VALUE_ERROR
,
850 _("Cannot find function \"%s\" for a call site target "
852 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
853 (msym
.minsym
== NULL
? "???"
854 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
857 return BMSYMBOL_VALUE_ADDRESS (msym
);
860 case FIELD_LOC_KIND_PHYSADDR
:
861 return FIELD_STATIC_PHYSADDR (call_site
->target
);
864 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
868 /* Convert function entry point exact address ADDR to the function which is
869 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
870 NO_ENTRY_VALUE_ERROR otherwise. */
872 static struct symbol
*
873 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
875 struct symbol
*sym
= find_pc_function (addr
);
878 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
879 throw_error (NO_ENTRY_VALUE_ERROR
,
880 _("DW_TAG_call_site resolving failed to find function "
881 "name for address %s"),
882 paddress (gdbarch
, addr
));
884 type
= SYMBOL_TYPE (sym
);
885 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
886 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
891 /* Verify function with entry point exact address ADDR can never call itself
892 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
893 can call itself via tail calls.
895 If a funtion can tail call itself its entry value based parameters are
896 unreliable. There is no verification whether the value of some/all
897 parameters is unchanged through the self tail call, we expect if there is
898 a self tail call all the parameters can be modified. */
901 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
905 /* The verification is completely unordered. Track here function addresses
906 which still need to be iterated. */
907 std::vector
<CORE_ADDR
> todo
;
909 /* Track here CORE_ADDRs which were already visited. */
910 std::unordered_set
<CORE_ADDR
> addr_hash
;
912 todo
.push_back (verify_addr
);
913 while (!todo
.empty ())
915 struct symbol
*func_sym
;
916 struct call_site
*call_site
;
921 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
923 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
924 call_site
; call_site
= call_site
->tail_call_next
)
926 CORE_ADDR target_addr
;
928 /* CALLER_FRAME with registers is not available for tail-call jumped
930 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
932 if (target_addr
== verify_addr
)
934 struct bound_minimal_symbol msym
;
936 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
937 throw_error (NO_ENTRY_VALUE_ERROR
,
938 _("DW_OP_entry_value resolving has found "
939 "function \"%s\" at %s can call itself via tail "
941 (msym
.minsym
== NULL
? "???"
942 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
943 paddress (gdbarch
, verify_addr
));
946 if (addr_hash
.insert (target_addr
).second
)
947 todo
.push_back (target_addr
);
952 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
953 ENTRY_VALUES_DEBUG. */
956 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
958 CORE_ADDR addr
= call_site
->pc
;
959 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
961 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
962 (msym
.minsym
== NULL
? "???"
963 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
967 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
968 only top callers and bottom callees which are present in both. GDBARCH is
969 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
970 no remaining possibilities to provide unambiguous non-trivial result.
971 RESULTP should point to NULL on the first (initialization) call. Caller is
972 responsible for xfree of any RESULTP data. */
975 chain_candidate (struct gdbarch
*gdbarch
,
976 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
977 std::vector
<struct call_site
*> *chain
)
979 long length
= chain
->size ();
980 int callers
, callees
, idx
;
982 if (*resultp
== NULL
)
984 /* Create the initial chain containing all the passed PCs. */
986 struct call_site_chain
*result
987 = ((struct call_site_chain
*)
988 xmalloc (sizeof (*result
)
989 + sizeof (*result
->call_site
) * (length
- 1)));
990 result
->length
= length
;
991 result
->callers
= result
->callees
= length
;
992 if (!chain
->empty ())
993 memcpy (result
->call_site
, chain
->data (),
994 sizeof (*result
->call_site
) * length
);
995 resultp
->reset (result
);
997 if (entry_values_debug
)
999 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1000 for (idx
= 0; idx
< length
; idx
++)
1001 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1002 fputc_unfiltered ('\n', gdb_stdlog
);
1008 if (entry_values_debug
)
1010 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1011 for (idx
= 0; idx
< length
; idx
++)
1012 tailcall_dump (gdbarch
, chain
->at (idx
));
1013 fputc_unfiltered ('\n', gdb_stdlog
);
1016 /* Intersect callers. */
1018 callers
= std::min ((long) (*resultp
)->callers
, length
);
1019 for (idx
= 0; idx
< callers
; idx
++)
1020 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1022 (*resultp
)->callers
= idx
;
1026 /* Intersect callees. */
1028 callees
= std::min ((long) (*resultp
)->callees
, length
);
1029 for (idx
= 0; idx
< callees
; idx
++)
1030 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1031 != chain
->at (length
- 1 - idx
))
1033 (*resultp
)->callees
= idx
;
1037 if (entry_values_debug
)
1039 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1040 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1041 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1042 fputs_unfiltered (" |", gdb_stdlog
);
1043 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1044 tailcall_dump (gdbarch
,
1045 (*resultp
)->call_site
[(*resultp
)->length
1046 - (*resultp
)->callees
+ idx
]);
1047 fputc_unfiltered ('\n', gdb_stdlog
);
1050 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1052 /* There are no common callers or callees. It could be also a direct
1053 call (which has length 0) with ambiguous possibility of an indirect
1054 call - CALLERS == CALLEES == 0 is valid during the first allocation
1055 but any subsequence processing of such entry means ambiguity. */
1056 resultp
->reset (NULL
);
1060 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1061 PC again. In such case there must be two different code paths to reach
1062 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1063 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1066 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1067 assumed frames between them use GDBARCH. Use depth first search so we can
1068 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1069 would have needless GDB stack overhead. Caller is responsible for xfree of
1070 the returned result. Any unreliability results in thrown
1071 NO_ENTRY_VALUE_ERROR. */
1073 static struct call_site_chain
*
1074 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1075 CORE_ADDR callee_pc
)
1077 CORE_ADDR save_callee_pc
= callee_pc
;
1078 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1079 struct call_site
*call_site
;
1081 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1082 call_site nor any possible call_site at CALLEE_PC's function is there.
1083 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1084 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1085 std::vector
<struct call_site
*> chain
;
1087 /* We are not interested in the specific PC inside the callee function. */
1088 callee_pc
= get_pc_function_start (callee_pc
);
1090 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1091 paddress (gdbarch
, save_callee_pc
));
1093 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1094 std::unordered_set
<CORE_ADDR
> addr_hash
;
1096 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1097 at the target's function. All the possible tail call sites in the
1098 target's function will get iterated as already pushed into CHAIN via their
1100 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1104 CORE_ADDR target_func_addr
;
1105 struct call_site
*target_call_site
;
1107 /* CALLER_FRAME with registers is not available for tail-call jumped
1109 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1111 if (target_func_addr
== callee_pc
)
1113 chain_candidate (gdbarch
, &retval
, &chain
);
1117 /* There is no way to reach CALLEE_PC again as we would prevent
1118 entering it twice as being already marked in ADDR_HASH. */
1119 target_call_site
= NULL
;
1123 struct symbol
*target_func
;
1125 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1126 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1131 /* Attempt to visit TARGET_CALL_SITE. */
1133 if (target_call_site
)
1135 if (addr_hash
.insert (target_call_site
->pc
).second
)
1137 /* Successfully entered TARGET_CALL_SITE. */
1139 chain
.push_back (target_call_site
);
1144 /* Backtrack (without revisiting the originating call_site). Try the
1145 callers's sibling; if there isn't any try the callers's callers's
1148 target_call_site
= NULL
;
1149 while (!chain
.empty ())
1151 call_site
= chain
.back ();
1154 size_t removed
= addr_hash
.erase (call_site
->pc
);
1155 gdb_assert (removed
== 1);
1157 target_call_site
= call_site
->tail_call_next
;
1158 if (target_call_site
)
1162 while (target_call_site
);
1167 call_site
= chain
.back ();
1172 struct bound_minimal_symbol msym_caller
, msym_callee
;
1174 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1175 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1176 throw_error (NO_ENTRY_VALUE_ERROR
,
1177 _("There are no unambiguously determinable intermediate "
1178 "callers or callees between caller function \"%s\" at %s "
1179 "and callee function \"%s\" at %s"),
1180 (msym_caller
.minsym
== NULL
1181 ? "???" : MSYMBOL_PRINT_NAME (msym_caller
.minsym
)),
1182 paddress (gdbarch
, caller_pc
),
1183 (msym_callee
.minsym
== NULL
1184 ? "???" : MSYMBOL_PRINT_NAME (msym_callee
.minsym
)),
1185 paddress (gdbarch
, callee_pc
));
1188 return retval
.release ();
1191 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1192 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1193 constructed return NULL. Caller is responsible for xfree of the returned
1196 struct call_site_chain
*
1197 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1198 CORE_ADDR callee_pc
)
1200 struct call_site_chain
*retval
= NULL
;
1204 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1206 CATCH (e
, RETURN_MASK_ERROR
)
1208 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1210 if (entry_values_debug
)
1211 exception_print (gdb_stdout
, e
);
1216 throw_exception (e
);
1223 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1226 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1227 enum call_site_parameter_kind kind
,
1228 union call_site_parameter_u kind_u
)
1230 if (kind
== parameter
->kind
)
1233 case CALL_SITE_PARAMETER_DWARF_REG
:
1234 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1235 case CALL_SITE_PARAMETER_FB_OFFSET
:
1236 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1237 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1238 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1243 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1244 FRAME is for callee.
1246 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1249 static struct call_site_parameter
*
1250 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1251 enum call_site_parameter_kind kind
,
1252 union call_site_parameter_u kind_u
,
1253 struct dwarf2_per_cu_data
**per_cu_return
)
1255 CORE_ADDR func_addr
, caller_pc
;
1256 struct gdbarch
*gdbarch
;
1257 struct frame_info
*caller_frame
;
1258 struct call_site
*call_site
;
1260 /* Initialize it just to avoid a GCC false warning. */
1261 struct call_site_parameter
*parameter
= NULL
;
1262 CORE_ADDR target_addr
;
1264 while (get_frame_type (frame
) == INLINE_FRAME
)
1266 frame
= get_prev_frame (frame
);
1267 gdb_assert (frame
!= NULL
);
1270 func_addr
= get_frame_func (frame
);
1271 gdbarch
= get_frame_arch (frame
);
1272 caller_frame
= get_prev_frame (frame
);
1273 if (gdbarch
!= frame_unwind_arch (frame
))
1275 struct bound_minimal_symbol msym
1276 = lookup_minimal_symbol_by_pc (func_addr
);
1277 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1279 throw_error (NO_ENTRY_VALUE_ERROR
,
1280 _("DW_OP_entry_value resolving callee gdbarch %s "
1281 "(of %s (%s)) does not match caller gdbarch %s"),
1282 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1283 paddress (gdbarch
, func_addr
),
1284 (msym
.minsym
== NULL
? "???"
1285 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
1286 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1289 if (caller_frame
== NULL
)
1291 struct bound_minimal_symbol msym
1292 = lookup_minimal_symbol_by_pc (func_addr
);
1294 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1295 "requires caller of %s (%s)"),
1296 paddress (gdbarch
, func_addr
),
1297 (msym
.minsym
== NULL
? "???"
1298 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
1300 caller_pc
= get_frame_pc (caller_frame
);
1301 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1303 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1304 if (target_addr
!= func_addr
)
1306 struct minimal_symbol
*target_msym
, *func_msym
;
1308 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1309 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1310 throw_error (NO_ENTRY_VALUE_ERROR
,
1311 _("DW_OP_entry_value resolving expects callee %s at %s "
1312 "but the called frame is for %s at %s"),
1313 (target_msym
== NULL
? "???"
1314 : MSYMBOL_PRINT_NAME (target_msym
)),
1315 paddress (gdbarch
, target_addr
),
1316 func_msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (func_msym
),
1317 paddress (gdbarch
, func_addr
));
1320 /* No entry value based parameters would be reliable if this function can
1321 call itself via tail calls. */
1322 func_verify_no_selftailcall (gdbarch
, func_addr
);
1324 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1326 parameter
= &call_site
->parameter
[iparams
];
1327 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1330 if (iparams
== call_site
->parameter_count
)
1332 struct minimal_symbol
*msym
1333 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1335 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1336 determine its value. */
1337 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1338 "at DW_TAG_call_site %s at %s"),
1339 paddress (gdbarch
, caller_pc
),
1340 msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (msym
));
1343 *per_cu_return
= call_site
->per_cu
;
1347 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1348 the normal DW_AT_call_value block. Otherwise return the
1349 DW_AT_call_data_value (dereferenced) block.
1351 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1354 Function always returns non-NULL, non-optimized out value. It throws
1355 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1357 static struct value
*
1358 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1359 CORE_ADDR deref_size
, struct type
*type
,
1360 struct frame_info
*caller_frame
,
1361 struct dwarf2_per_cu_data
*per_cu
)
1363 const gdb_byte
*data_src
;
1367 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1368 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1370 /* DEREF_SIZE size is not verified here. */
1371 if (data_src
== NULL
)
1372 throw_error (NO_ENTRY_VALUE_ERROR
,
1373 _("Cannot resolve DW_AT_call_data_value"));
1375 /* DW_AT_call_value is a DWARF expression, not a DWARF
1376 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1378 data
= (gdb_byte
*) alloca (size
+ 1);
1379 memcpy (data
, data_src
, size
);
1380 data
[size
] = DW_OP_stack_value
;
1382 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1385 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1386 the indirect method on it, that is use its stored target value, the sole
1387 purpose of entry_data_value_funcs.. */
1389 static struct value
*
1390 entry_data_value_coerce_ref (const struct value
*value
)
1392 struct type
*checked_type
= check_typedef (value_type (value
));
1393 struct value
*target_val
;
1395 if (!TYPE_IS_REFERENCE (checked_type
))
1398 target_val
= (struct value
*) value_computed_closure (value
);
1399 value_incref (target_val
);
1403 /* Implement copy_closure. */
1406 entry_data_value_copy_closure (const struct value
*v
)
1408 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1410 value_incref (target_val
);
1414 /* Implement free_closure. */
1417 entry_data_value_free_closure (struct value
*v
)
1419 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1421 value_decref (target_val
);
1424 /* Vector for methods for an entry value reference where the referenced value
1425 is stored in the caller. On the first dereference use
1426 DW_AT_call_data_value in the caller. */
1428 static const struct lval_funcs entry_data_value_funcs
=
1432 NULL
, /* indirect */
1433 entry_data_value_coerce_ref
,
1434 NULL
, /* check_synthetic_pointer */
1435 entry_data_value_copy_closure
,
1436 entry_data_value_free_closure
1439 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1440 are used to match DW_AT_location at the caller's
1441 DW_TAG_call_site_parameter.
1443 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1444 cannot resolve the parameter for any reason. */
1446 static struct value
*
1447 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1448 enum call_site_parameter_kind kind
,
1449 union call_site_parameter_u kind_u
)
1451 struct type
*checked_type
= check_typedef (type
);
1452 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1453 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1454 struct value
*outer_val
, *target_val
, *val
;
1455 struct call_site_parameter
*parameter
;
1456 struct dwarf2_per_cu_data
*caller_per_cu
;
1458 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1461 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1465 /* Check if DW_AT_call_data_value cannot be used. If it should be
1466 used and it is not available do not fall back to OUTER_VAL - dereferencing
1467 TYPE_CODE_REF with non-entry data value would give current value - not the
1470 if (!TYPE_IS_REFERENCE (checked_type
)
1471 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1474 target_val
= dwarf_entry_parameter_to_value (parameter
,
1475 TYPE_LENGTH (target_type
),
1476 target_type
, caller_frame
,
1479 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1480 release_value (target_val
).release ());
1482 /* Copy the referencing pointer to the new computed value. */
1483 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1484 TYPE_LENGTH (checked_type
));
1485 set_value_lazy (val
, 0);
1490 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1491 SIZE are DWARF block used to match DW_AT_location at the caller's
1492 DW_TAG_call_site_parameter.
1494 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1495 cannot resolve the parameter for any reason. */
1497 static struct value
*
1498 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1499 const gdb_byte
*block
, size_t block_len
)
1501 union call_site_parameter_u kind_u
;
1503 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1504 if (kind_u
.dwarf_reg
!= -1)
1505 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1508 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1509 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1512 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1513 suppressed during normal operation. The expression can be arbitrary if
1514 there is no caller-callee entry value binding expected. */
1515 throw_error (NO_ENTRY_VALUE_ERROR
,
1516 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1517 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1520 struct piece_closure
1522 /* Reference count. */
1525 /* The CU from which this closure's expression came. */
1526 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1528 /* The pieces describing this variable. */
1529 std::vector
<dwarf_expr_piece
> pieces
;
1531 /* Frame ID of frame to which a register value is relative, used
1532 only by DWARF_VALUE_REGISTER. */
1533 struct frame_id frame_id
;
1536 /* Allocate a closure for a value formed from separately-described
1539 static struct piece_closure
*
1540 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1541 std::vector
<dwarf_expr_piece
> &&pieces
,
1542 struct frame_info
*frame
)
1544 struct piece_closure
*c
= new piece_closure
;
1548 c
->pieces
= std::move (pieces
);
1550 c
->frame_id
= null_frame_id
;
1552 c
->frame_id
= get_frame_id (frame
);
1554 for (dwarf_expr_piece
&piece
: c
->pieces
)
1555 if (piece
.location
== DWARF_VALUE_STACK
)
1556 value_incref (piece
.v
.value
);
1561 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1562 bits whose first bit is located at bit offset START. */
1565 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1567 return (start
% 8 + n_bits
+ 7) / 8;
1570 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1571 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1572 operate in "read mode": fetch the contents of the (lazy) value V by
1573 composing it from its pieces. */
1576 rw_pieced_value (struct value
*v
, struct value
*from
)
1579 LONGEST offset
= 0, max_offset
;
1580 ULONGEST bits_to_skip
;
1581 gdb_byte
*v_contents
;
1582 const gdb_byte
*from_contents
;
1583 struct piece_closure
*c
1584 = (struct piece_closure
*) value_computed_closure (v
);
1585 gdb::byte_vector buffer
;
1587 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1591 from_contents
= value_contents (from
);
1596 if (value_type (v
) != value_enclosing_type (v
))
1597 internal_error (__FILE__
, __LINE__
,
1598 _("Should not be able to create a lazy value with "
1599 "an enclosing type"));
1600 v_contents
= value_contents_raw (v
);
1601 from_contents
= NULL
;
1604 bits_to_skip
= 8 * value_offset (v
);
1605 if (value_bitsize (v
))
1607 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1608 + value_bitpos (v
));
1610 && (gdbarch_byte_order (get_type_arch (value_type (from
)))
1613 /* Use the least significant bits of FROM. */
1614 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1615 offset
= max_offset
- value_bitsize (v
);
1618 max_offset
= value_bitsize (v
);
1621 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1623 /* Advance to the first non-skipped piece. */
1624 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1625 bits_to_skip
-= c
->pieces
[i
].size
;
1627 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1629 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1630 size_t this_size_bits
, this_size
;
1632 this_size_bits
= p
->size
- bits_to_skip
;
1633 if (this_size_bits
> max_offset
- offset
)
1634 this_size_bits
= max_offset
- offset
;
1636 switch (p
->location
)
1638 case DWARF_VALUE_REGISTER
:
1640 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1641 struct gdbarch
*arch
= get_frame_arch (frame
);
1642 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1643 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1646 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1647 && p
->offset
+ p
->size
< reg_bits
)
1649 /* Big-endian, and we want less than full size. */
1650 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1653 bits_to_skip
+= p
->offset
;
1655 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1656 buffer
.resize (this_size
);
1661 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1663 this_size
, buffer
.data (),
1667 mark_value_bits_optimized_out (v
, offset
,
1670 mark_value_bits_unavailable (v
, offset
,
1675 copy_bitwise (v_contents
, offset
,
1676 buffer
.data (), bits_to_skip
% 8,
1677 this_size_bits
, bits_big_endian
);
1682 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1684 /* Data is copied non-byte-aligned into the register.
1685 Need some bits from original register value. */
1686 get_frame_register_bytes (frame
, gdb_regnum
,
1688 this_size
, buffer
.data (),
1691 throw_error (OPTIMIZED_OUT_ERROR
,
1692 _("Can't do read-modify-write to "
1693 "update bitfield; containing word "
1694 "has been optimized out"));
1696 throw_error (NOT_AVAILABLE_ERROR
,
1697 _("Can't do read-modify-write to "
1698 "update bitfield; containing word "
1702 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1703 from_contents
, offset
,
1704 this_size_bits
, bits_big_endian
);
1705 put_frame_register_bytes (frame
, gdb_regnum
,
1707 this_size
, buffer
.data ());
1712 case DWARF_VALUE_MEMORY
:
1714 bits_to_skip
+= p
->offset
;
1716 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1718 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1721 /* Everything is byte-aligned; no buffer needed. */
1723 write_memory_with_notification (start_addr
,
1726 this_size_bits
/ 8);
1728 read_value_memory (v
, offset
,
1729 p
->v
.mem
.in_stack_memory
,
1730 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1731 v_contents
+ offset
/ 8,
1732 this_size_bits
/ 8);
1736 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1737 buffer
.resize (this_size
);
1742 read_value_memory (v
, offset
,
1743 p
->v
.mem
.in_stack_memory
,
1744 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1745 buffer
.data (), this_size
);
1746 copy_bitwise (v_contents
, offset
,
1747 buffer
.data (), bits_to_skip
% 8,
1748 this_size_bits
, bits_big_endian
);
1753 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1757 /* Perform a single read for small sizes. */
1758 read_memory (start_addr
, buffer
.data (),
1763 /* Only the first and last bytes can possibly have
1765 read_memory (start_addr
, buffer
.data (), 1);
1766 read_memory (start_addr
+ this_size
- 1,
1767 &buffer
[this_size
- 1], 1);
1771 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1772 from_contents
, offset
,
1773 this_size_bits
, bits_big_endian
);
1774 write_memory_with_notification (start_addr
,
1781 case DWARF_VALUE_STACK
:
1785 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1789 struct objfile
*objfile
= dwarf2_per_cu_objfile (c
->per_cu
);
1790 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1791 ULONGEST stack_value_size_bits
1792 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1794 /* Use zeroes if piece reaches beyond stack value. */
1795 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1798 /* Piece is anchored at least significant bit end. */
1799 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1800 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1802 bits_to_skip
+= p
->offset
;
1804 copy_bitwise (v_contents
, offset
,
1805 value_contents_all (p
->v
.value
),
1807 this_size_bits
, bits_big_endian
);
1811 case DWARF_VALUE_LITERAL
:
1815 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1819 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1820 size_t n
= this_size_bits
;
1822 /* Cut off at the end of the implicit value. */
1823 bits_to_skip
+= p
->offset
;
1824 if (bits_to_skip
>= literal_size_bits
)
1826 if (n
> literal_size_bits
- bits_to_skip
)
1827 n
= literal_size_bits
- bits_to_skip
;
1829 copy_bitwise (v_contents
, offset
,
1830 p
->v
.literal
.data
, bits_to_skip
,
1831 n
, bits_big_endian
);
1835 case DWARF_VALUE_IMPLICIT_POINTER
:
1838 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1842 /* These bits show up as zeros -- but do not cause the value to
1843 be considered optimized-out. */
1846 case DWARF_VALUE_OPTIMIZED_OUT
:
1847 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1851 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1854 offset
+= this_size_bits
;
1861 read_pieced_value (struct value
*v
)
1863 rw_pieced_value (v
, NULL
);
1867 write_pieced_value (struct value
*to
, struct value
*from
)
1869 rw_pieced_value (to
, from
);
1872 /* An implementation of an lval_funcs method to see whether a value is
1873 a synthetic pointer. */
1876 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1879 struct piece_closure
*c
1880 = (struct piece_closure
*) value_computed_closure (value
);
1883 bit_offset
+= 8 * value_offset (value
);
1884 if (value_bitsize (value
))
1885 bit_offset
+= value_bitpos (value
);
1887 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1889 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1890 size_t this_size_bits
= p
->size
;
1894 if (bit_offset
>= this_size_bits
)
1896 bit_offset
-= this_size_bits
;
1900 bit_length
-= this_size_bits
- bit_offset
;
1904 bit_length
-= this_size_bits
;
1906 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1913 /* A wrapper function for get_frame_address_in_block. */
1916 get_frame_address_in_block_wrapper (void *baton
)
1918 return get_frame_address_in_block ((struct frame_info
*) baton
);
1921 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1923 static struct value
*
1924 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1925 struct dwarf2_per_cu_data
*per_cu
,
1928 struct value
*result
= NULL
;
1929 const gdb_byte
*bytes
;
1932 auto_obstack temp_obstack
;
1933 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
1937 if (byte_offset
>= 0
1938 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1940 bytes
+= byte_offset
;
1941 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1944 invalid_synthetic_pointer ();
1947 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1952 /* Fetch the value pointed to by a synthetic pointer. */
1954 static struct value
*
1955 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1956 struct dwarf2_per_cu_data
*per_cu
,
1957 struct frame_info
*frame
, struct type
*type
,
1958 bool resolve_abstract_p
)
1960 /* Fetch the location expression of the DIE we're pointing to. */
1961 struct dwarf2_locexpr_baton baton
1962 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
1963 get_frame_address_in_block_wrapper
, frame
,
1964 resolve_abstract_p
);
1966 /* Get type of pointed-to DIE. */
1967 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
);
1968 if (orig_type
== NULL
)
1969 invalid_synthetic_pointer ();
1971 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1972 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1973 or it may've been optimized out. */
1974 if (baton
.data
!= NULL
)
1975 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1976 baton
.size
, baton
.per_cu
,
1977 TYPE_TARGET_TYPE (type
),
1980 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1984 /* An implementation of an lval_funcs method to indirect through a
1985 pointer. This handles the synthetic pointer case when needed. */
1987 static struct value
*
1988 indirect_pieced_value (struct value
*value
)
1990 struct piece_closure
*c
1991 = (struct piece_closure
*) value_computed_closure (value
);
1993 struct frame_info
*frame
;
1996 struct dwarf_expr_piece
*piece
= NULL
;
1997 LONGEST byte_offset
;
1998 enum bfd_endian byte_order
;
2000 type
= check_typedef (value_type (value
));
2001 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2004 bit_length
= 8 * TYPE_LENGTH (type
);
2005 bit_offset
= 8 * value_offset (value
);
2006 if (value_bitsize (value
))
2007 bit_offset
+= value_bitpos (value
);
2009 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2011 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2012 size_t this_size_bits
= p
->size
;
2016 if (bit_offset
>= this_size_bits
)
2018 bit_offset
-= this_size_bits
;
2022 bit_length
-= this_size_bits
- bit_offset
;
2026 bit_length
-= this_size_bits
;
2028 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2031 if (bit_length
!= 0)
2032 error (_("Invalid use of DW_OP_implicit_pointer"));
2038 gdb_assert (piece
!= NULL
);
2039 frame
= get_selected_frame (_("No frame selected."));
2041 /* This is an offset requested by GDB, such as value subscripts.
2042 However, due to how synthetic pointers are implemented, this is
2043 always presented to us as a pointer type. This means we have to
2044 sign-extend it manually as appropriate. Use raw
2045 extract_signed_integer directly rather than value_as_address and
2046 sign extend afterwards on architectures that would need it
2047 (mostly everywhere except MIPS, which has signed addresses) as
2048 the later would go through gdbarch_pointer_to_address and thus
2049 return a CORE_ADDR with high bits set on architectures that
2050 encode address spaces and other things in CORE_ADDR. */
2051 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2052 byte_offset
= extract_signed_integer (value_contents (value
),
2053 TYPE_LENGTH (type
), byte_order
);
2054 byte_offset
+= piece
->v
.ptr
.offset
;
2056 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2057 byte_offset
, c
->per_cu
,
2061 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2064 static struct value
*
2065 coerce_pieced_ref (const struct value
*value
)
2067 struct type
*type
= check_typedef (value_type (value
));
2069 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2070 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2072 const struct piece_closure
*closure
2073 = (struct piece_closure
*) value_computed_closure (value
);
2074 struct frame_info
*frame
2075 = get_selected_frame (_("No frame selected."));
2077 /* gdb represents synthetic pointers as pieced values with a single
2079 gdb_assert (closure
!= NULL
);
2080 gdb_assert (closure
->pieces
.size () == 1);
2082 return indirect_synthetic_pointer
2083 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2084 closure
->pieces
[0].v
.ptr
.offset
,
2085 closure
->per_cu
, frame
, type
);
2089 /* Else: not a synthetic reference; do nothing. */
2095 copy_pieced_value_closure (const struct value
*v
)
2097 struct piece_closure
*c
2098 = (struct piece_closure
*) value_computed_closure (v
);
2105 free_pieced_value_closure (struct value
*v
)
2107 struct piece_closure
*c
2108 = (struct piece_closure
*) value_computed_closure (v
);
2113 for (dwarf_expr_piece
&p
: c
->pieces
)
2114 if (p
.location
== DWARF_VALUE_STACK
)
2115 value_decref (p
.v
.value
);
2121 /* Functions for accessing a variable described by DW_OP_piece. */
2122 static const struct lval_funcs pieced_value_funcs
= {
2125 indirect_pieced_value
,
2127 check_pieced_synthetic_pointer
,
2128 copy_pieced_value_closure
,
2129 free_pieced_value_closure
2132 /* Evaluate a location description, starting at DATA and with length
2133 SIZE, to find the current location of variable of TYPE in the
2134 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2135 location of the subobject of type SUBOBJ_TYPE at byte offset
2136 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2138 static struct value
*
2139 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2140 const gdb_byte
*data
, size_t size
,
2141 struct dwarf2_per_cu_data
*per_cu
,
2142 struct type
*subobj_type
,
2143 LONGEST subobj_byte_offset
)
2145 struct value
*retval
;
2146 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2148 if (subobj_type
== NULL
)
2151 subobj_byte_offset
= 0;
2153 else if (subobj_byte_offset
< 0)
2154 invalid_synthetic_pointer ();
2157 return allocate_optimized_out_value (subobj_type
);
2159 dwarf_evaluate_loc_desc ctx
;
2161 ctx
.per_cu
= per_cu
;
2162 ctx
.obj_address
= 0;
2164 scoped_value_mark free_values
;
2166 ctx
.gdbarch
= get_objfile_arch (objfile
);
2167 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2168 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2169 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2173 ctx
.eval (data
, size
);
2175 CATCH (ex
, RETURN_MASK_ERROR
)
2177 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2179 free_values
.free_to_mark ();
2180 retval
= allocate_value (subobj_type
);
2181 mark_value_bytes_unavailable (retval
, 0,
2182 TYPE_LENGTH (subobj_type
));
2185 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2187 if (entry_values_debug
)
2188 exception_print (gdb_stdout
, ex
);
2189 free_values
.free_to_mark ();
2190 return allocate_optimized_out_value (subobj_type
);
2193 throw_exception (ex
);
2197 if (ctx
.pieces
.size () > 0)
2199 struct piece_closure
*c
;
2200 ULONGEST bit_size
= 0;
2202 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2203 bit_size
+= piece
.size
;
2204 /* Complain if the expression is larger than the size of the
2206 if (bit_size
> 8 * TYPE_LENGTH (type
))
2207 invalid_synthetic_pointer ();
2209 c
= allocate_piece_closure (per_cu
, std::move (ctx
.pieces
), frame
);
2210 /* We must clean up the value chain after creating the piece
2211 closure but before allocating the result. */
2212 free_values
.free_to_mark ();
2213 retval
= allocate_computed_value (subobj_type
,
2214 &pieced_value_funcs
, c
);
2215 set_value_offset (retval
, subobj_byte_offset
);
2219 switch (ctx
.location
)
2221 case DWARF_VALUE_REGISTER
:
2223 struct gdbarch
*arch
= get_frame_arch (frame
);
2225 = longest_to_int (value_as_long (ctx
.fetch (0)));
2226 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2228 if (subobj_byte_offset
!= 0)
2229 error (_("cannot use offset on synthetic pointer to register"));
2230 free_values
.free_to_mark ();
2231 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2232 if (value_optimized_out (retval
))
2236 /* This means the register has undefined value / was
2237 not saved. As we're computing the location of some
2238 variable etc. in the program, not a value for
2239 inspecting a register ($pc, $sp, etc.), return a
2240 generic optimized out value instead, so that we show
2241 <optimized out> instead of <not saved>. */
2242 tmp
= allocate_value (subobj_type
);
2243 value_contents_copy (tmp
, 0, retval
, 0,
2244 TYPE_LENGTH (subobj_type
));
2250 case DWARF_VALUE_MEMORY
:
2252 struct type
*ptr_type
;
2253 CORE_ADDR address
= ctx
.fetch_address (0);
2254 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2256 /* DW_OP_deref_size (and possibly other operations too) may
2257 create a pointer instead of an address. Ideally, the
2258 pointer to address conversion would be performed as part
2259 of those operations, but the type of the object to
2260 which the address refers is not known at the time of
2261 the operation. Therefore, we do the conversion here
2262 since the type is readily available. */
2264 switch (TYPE_CODE (subobj_type
))
2266 case TYPE_CODE_FUNC
:
2267 case TYPE_CODE_METHOD
:
2268 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2271 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2274 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2276 free_values
.free_to_mark ();
2277 retval
= value_at_lazy (subobj_type
,
2278 address
+ subobj_byte_offset
);
2279 if (in_stack_memory
)
2280 set_value_stack (retval
, 1);
2284 case DWARF_VALUE_STACK
:
2286 struct value
*value
= ctx
.fetch (0);
2287 size_t n
= TYPE_LENGTH (value_type (value
));
2288 size_t len
= TYPE_LENGTH (subobj_type
);
2289 size_t max
= TYPE_LENGTH (type
);
2290 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2292 if (subobj_byte_offset
+ len
> max
)
2293 invalid_synthetic_pointer ();
2295 /* Preserve VALUE because we are going to free values back
2296 to the mark, but we still need the value contents
2298 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2299 free_values
.free_to_mark ();
2301 retval
= allocate_value (subobj_type
);
2303 /* The given offset is relative to the actual object. */
2304 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2305 subobj_byte_offset
+= n
- max
;
2307 memcpy (value_contents_raw (retval
),
2308 value_contents_all (value
) + subobj_byte_offset
, len
);
2312 case DWARF_VALUE_LITERAL
:
2315 size_t n
= TYPE_LENGTH (subobj_type
);
2317 if (subobj_byte_offset
+ n
> ctx
.len
)
2318 invalid_synthetic_pointer ();
2320 free_values
.free_to_mark ();
2321 retval
= allocate_value (subobj_type
);
2322 contents
= value_contents_raw (retval
);
2323 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2327 case DWARF_VALUE_OPTIMIZED_OUT
:
2328 free_values
.free_to_mark ();
2329 retval
= allocate_optimized_out_value (subobj_type
);
2332 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2333 operation by execute_stack_op. */
2334 case DWARF_VALUE_IMPLICIT_POINTER
:
2335 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2336 it can only be encountered when making a piece. */
2338 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2342 set_value_initialized (retval
, ctx
.initialized
);
2347 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2348 passes 0 as the byte_offset. */
2351 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2352 const gdb_byte
*data
, size_t size
,
2353 struct dwarf2_per_cu_data
*per_cu
)
2355 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2359 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2360 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2361 frame in which the expression is evaluated. ADDR is a context (location of
2362 a variable) and might be needed to evaluate the location expression.
2363 Returns 1 on success, 0 otherwise. */
2366 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2367 struct frame_info
*frame
,
2371 struct objfile
*objfile
;
2373 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2376 dwarf_evaluate_loc_desc ctx
;
2379 ctx
.per_cu
= dlbaton
->per_cu
;
2380 ctx
.obj_address
= addr
;
2382 objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2384 ctx
.gdbarch
= get_objfile_arch (objfile
);
2385 ctx
.addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2386 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (dlbaton
->per_cu
);
2387 ctx
.offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2391 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2393 CATCH (ex
, RETURN_MASK_ERROR
)
2395 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2399 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2401 if (entry_values_debug
)
2402 exception_print (gdb_stdout
, ex
);
2406 throw_exception (ex
);
2410 switch (ctx
.location
)
2412 case DWARF_VALUE_REGISTER
:
2413 case DWARF_VALUE_MEMORY
:
2414 case DWARF_VALUE_STACK
:
2415 *valp
= ctx
.fetch_address (0);
2416 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2417 *valp
= ctx
.read_addr_from_reg (*valp
);
2419 case DWARF_VALUE_LITERAL
:
2420 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2421 gdbarch_byte_order (ctx
.gdbarch
));
2423 /* Unsupported dwarf values. */
2424 case DWARF_VALUE_OPTIMIZED_OUT
:
2425 case DWARF_VALUE_IMPLICIT_POINTER
:
2432 /* See dwarf2loc.h. */
2435 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2436 struct frame_info
*frame
,
2437 struct property_addr_info
*addr_stack
,
2443 if (frame
== NULL
&& has_stack_frames ())
2444 frame
= get_selected_frame (NULL
);
2450 const struct dwarf2_property_baton
*baton
2451 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2453 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
,
2454 addr_stack
? addr_stack
->addr
: 0,
2457 if (baton
->referenced_type
)
2459 struct value
*val
= value_at (baton
->referenced_type
, *value
);
2461 *value
= value_as_address (val
);
2470 struct dwarf2_property_baton
*baton
2471 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2472 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2473 const gdb_byte
*data
;
2477 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2480 val
= dwarf2_evaluate_loc_desc (baton
->referenced_type
, frame
, data
,
2481 size
, baton
->loclist
.per_cu
);
2482 if (!value_optimized_out (val
))
2484 *value
= value_as_address (val
);
2492 *value
= prop
->data
.const_val
;
2495 case PROP_ADDR_OFFSET
:
2497 struct dwarf2_property_baton
*baton
2498 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2499 struct property_addr_info
*pinfo
;
2502 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2503 if (pinfo
->type
== baton
->referenced_type
)
2506 error (_("cannot find reference address for offset property"));
2507 if (pinfo
->valaddr
!= NULL
)
2508 val
= value_from_contents
2509 (baton
->offset_info
.type
,
2510 pinfo
->valaddr
+ baton
->offset_info
.offset
);
2512 val
= value_at (baton
->offset_info
.type
,
2513 pinfo
->addr
+ baton
->offset_info
.offset
);
2514 *value
= value_as_address (val
);
2522 /* See dwarf2loc.h. */
2525 dwarf2_compile_property_to_c (string_file
*stream
,
2526 const char *result_name
,
2527 struct gdbarch
*gdbarch
,
2528 unsigned char *registers_used
,
2529 const struct dynamic_prop
*prop
,
2533 struct dwarf2_property_baton
*baton
2534 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2535 const gdb_byte
*data
;
2537 struct dwarf2_per_cu_data
*per_cu
;
2539 if (prop
->kind
== PROP_LOCEXPR
)
2541 data
= baton
->locexpr
.data
;
2542 size
= baton
->locexpr
.size
;
2543 per_cu
= baton
->locexpr
.per_cu
;
2547 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2549 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2550 per_cu
= baton
->loclist
.per_cu
;
2553 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2554 gdbarch
, registers_used
,
2555 dwarf2_per_cu_addr_size (per_cu
),
2556 data
, data
+ size
, per_cu
);
2560 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2562 class symbol_needs_eval_context
: public dwarf_expr_context
2566 enum symbol_needs_kind needs
;
2567 struct dwarf2_per_cu_data
*per_cu
;
2569 /* Reads from registers do require a frame. */
2570 CORE_ADDR
read_addr_from_reg (int regnum
) override
2572 needs
= SYMBOL_NEEDS_FRAME
;
2576 /* "get_reg_value" callback: Reads from registers do require a
2579 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2581 needs
= SYMBOL_NEEDS_FRAME
;
2582 return value_zero (type
, not_lval
);
2585 /* Reads from memory do not require a frame. */
2586 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2588 memset (buf
, 0, len
);
2591 /* Frame-relative accesses do require a frame. */
2592 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2594 static gdb_byte lit0
= DW_OP_lit0
;
2599 needs
= SYMBOL_NEEDS_FRAME
;
2602 /* CFA accesses require a frame. */
2603 CORE_ADDR
get_frame_cfa () override
2605 needs
= SYMBOL_NEEDS_FRAME
;
2609 CORE_ADDR
get_frame_pc () override
2611 needs
= SYMBOL_NEEDS_FRAME
;
2615 /* Thread-local accesses require registers, but not a frame. */
2616 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2618 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2619 needs
= SYMBOL_NEEDS_REGISTERS
;
2623 /* Helper interface of per_cu_dwarf_call for
2624 dwarf2_loc_desc_get_symbol_read_needs. */
2626 void dwarf_call (cu_offset die_offset
) override
2628 per_cu_dwarf_call (this, die_offset
, per_cu
);
2631 /* Helper interface of sect_variable_value for
2632 dwarf2_loc_desc_get_symbol_read_needs. */
2634 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2636 return sect_variable_value (this, sect_off
, per_cu
);
2639 /* DW_OP_entry_value accesses require a caller, therefore a
2642 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2643 union call_site_parameter_u kind_u
,
2644 int deref_size
) override
2646 needs
= SYMBOL_NEEDS_FRAME
;
2648 /* The expression may require some stub values on DWARF stack. */
2649 push_address (0, 0);
2652 /* DW_OP_GNU_addr_index doesn't require a frame. */
2654 CORE_ADDR
get_addr_index (unsigned int index
) override
2656 /* Nothing to do. */
2660 /* DW_OP_push_object_address has a frame already passed through. */
2662 CORE_ADDR
get_object_address () override
2664 /* Nothing to do. */
2669 /* Compute the correct symbol_needs_kind value for the location
2670 expression at DATA (length SIZE). */
2672 static enum symbol_needs_kind
2673 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2674 struct dwarf2_per_cu_data
*per_cu
)
2677 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2679 scoped_value_mark free_values
;
2681 symbol_needs_eval_context ctx
;
2683 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2684 ctx
.per_cu
= per_cu
;
2685 ctx
.gdbarch
= get_objfile_arch (objfile
);
2686 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2687 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2688 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2690 ctx
.eval (data
, size
);
2692 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2694 /* If the location has several pieces, and any of them are in
2695 registers, then we will need a frame to fetch them from. */
2696 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2697 if (p
.location
== DWARF_VALUE_REGISTER
)
2701 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2705 /* A helper function that throws an unimplemented error mentioning a
2706 given DWARF operator. */
2708 static void ATTRIBUTE_NORETURN
2709 unimplemented (unsigned int op
)
2711 const char *name
= get_DW_OP_name (op
);
2714 error (_("DWARF operator %s cannot be translated to an agent expression"),
2717 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2718 "to an agent expression"),
2724 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2725 can issue a complaint, which is better than having every target's
2726 implementation of dwarf2_reg_to_regnum do it. */
2729 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2731 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2735 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2740 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2741 Throw an error because DWARF_REG is bad. */
2744 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2746 /* Still want to print -1 as "-1".
2747 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2748 but that's overkill for now. */
2749 if ((int) dwarf_reg
== dwarf_reg
)
2750 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2751 error (_("Unable to access DWARF register number %s"),
2752 pulongest (dwarf_reg
));
2755 /* See dwarf2loc.h. */
2758 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2762 if (dwarf_reg
> INT_MAX
)
2763 throw_bad_regnum_error (dwarf_reg
);
2764 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2765 bad, but that's ok. */
2766 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2768 throw_bad_regnum_error (dwarf_reg
);
2772 /* A helper function that emits an access to memory. ARCH is the
2773 target architecture. EXPR is the expression which we are building.
2774 NBITS is the number of bits we want to read. This emits the
2775 opcodes needed to read the memory and then extract the desired
2779 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2781 ULONGEST nbytes
= (nbits
+ 7) / 8;
2783 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2786 ax_trace_quick (expr
, nbytes
);
2789 ax_simple (expr
, aop_ref8
);
2790 else if (nbits
<= 16)
2791 ax_simple (expr
, aop_ref16
);
2792 else if (nbits
<= 32)
2793 ax_simple (expr
, aop_ref32
);
2795 ax_simple (expr
, aop_ref64
);
2797 /* If we read exactly the number of bytes we wanted, we're done. */
2798 if (8 * nbytes
== nbits
)
2801 if (gdbarch_bits_big_endian (arch
))
2803 /* On a bits-big-endian machine, we want the high-order
2805 ax_const_l (expr
, 8 * nbytes
- nbits
);
2806 ax_simple (expr
, aop_rsh_unsigned
);
2810 /* On a bits-little-endian box, we want the low-order NBITS. */
2811 ax_zero_ext (expr
, nbits
);
2815 /* A helper function to return the frame's PC. */
2818 get_ax_pc (void *baton
)
2820 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
2825 /* Compile a DWARF location expression to an agent expression.
2827 EXPR is the agent expression we are building.
2828 LOC is the agent value we modify.
2829 ARCH is the architecture.
2830 ADDR_SIZE is the size of addresses, in bytes.
2831 OP_PTR is the start of the location expression.
2832 OP_END is one past the last byte of the location expression.
2834 This will throw an exception for various kinds of errors -- for
2835 example, if the expression cannot be compiled, or if the expression
2839 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2840 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2841 const gdb_byte
*op_end
,
2842 struct dwarf2_per_cu_data
*per_cu
)
2844 gdbarch
*arch
= expr
->gdbarch
;
2845 std::vector
<int> dw_labels
, patches
;
2846 const gdb_byte
* const base
= op_ptr
;
2847 const gdb_byte
*previous_piece
= op_ptr
;
2848 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2849 ULONGEST bits_collected
= 0;
2850 unsigned int addr_size_bits
= 8 * addr_size
;
2851 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
2853 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2855 /* By default we are making an address. */
2856 loc
->kind
= axs_lvalue_memory
;
2858 while (op_ptr
< op_end
)
2860 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2861 uint64_t uoffset
, reg
;
2865 offsets
[op_ptr
- base
] = expr
->len
;
2868 /* Our basic approach to code generation is to map DWARF
2869 operations directly to AX operations. However, there are
2872 First, DWARF works on address-sized units, but AX always uses
2873 LONGEST. For most operations we simply ignore this
2874 difference; instead we generate sign extensions as needed
2875 before division and comparison operations. It would be nice
2876 to omit the sign extensions, but there is no way to determine
2877 the size of the target's LONGEST. (This code uses the size
2878 of the host LONGEST in some cases -- that is a bug but it is
2881 Second, some DWARF operations cannot be translated to AX.
2882 For these we simply fail. See
2883 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2918 ax_const_l (expr
, op
- DW_OP_lit0
);
2922 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2923 op_ptr
+= addr_size
;
2924 /* Some versions of GCC emit DW_OP_addr before
2925 DW_OP_GNU_push_tls_address. In this case the value is an
2926 index, not an address. We don't support things like
2927 branching between the address and the TLS op. */
2928 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2929 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
2930 ax_const_l (expr
, uoffset
);
2934 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2938 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2942 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2946 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2950 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2954 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2958 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2962 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2966 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2967 ax_const_l (expr
, uoffset
);
2970 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2971 ax_const_l (expr
, offset
);
3006 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3007 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3008 loc
->kind
= axs_lvalue_register
;
3012 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3013 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3014 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3015 loc
->kind
= axs_lvalue_register
;
3018 case DW_OP_implicit_value
:
3022 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3023 if (op_ptr
+ len
> op_end
)
3024 error (_("DW_OP_implicit_value: too few bytes available."));
3025 if (len
> sizeof (ULONGEST
))
3026 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3029 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3032 dwarf_expr_require_composition (op_ptr
, op_end
,
3033 "DW_OP_implicit_value");
3035 loc
->kind
= axs_rvalue
;
3039 case DW_OP_stack_value
:
3040 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3041 loc
->kind
= axs_rvalue
;
3076 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3077 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3081 ax_const_l (expr
, offset
);
3082 ax_simple (expr
, aop_add
);
3087 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3088 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3089 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3093 ax_const_l (expr
, offset
);
3094 ax_simple (expr
, aop_add
);
3100 const gdb_byte
*datastart
;
3102 const struct block
*b
;
3103 struct symbol
*framefunc
;
3105 b
= block_for_pc (expr
->scope
);
3108 error (_("No block found for address"));
3110 framefunc
= block_linkage_function (b
);
3113 error (_("No function found for block"));
3115 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3116 &datastart
, &datalen
);
3118 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3119 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3120 datastart
+ datalen
, per_cu
);
3121 if (loc
->kind
== axs_lvalue_register
)
3122 require_rvalue (expr
, loc
);
3126 ax_const_l (expr
, offset
);
3127 ax_simple (expr
, aop_add
);
3130 loc
->kind
= axs_lvalue_memory
;
3135 ax_simple (expr
, aop_dup
);
3139 ax_simple (expr
, aop_pop
);
3144 ax_pick (expr
, offset
);
3148 ax_simple (expr
, aop_swap
);
3156 ax_simple (expr
, aop_rot
);
3160 case DW_OP_deref_size
:
3164 if (op
== DW_OP_deref_size
)
3169 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3170 error (_("Unsupported size %d in %s"),
3171 size
, get_DW_OP_name (op
));
3172 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3177 /* Sign extend the operand. */
3178 ax_ext (expr
, addr_size_bits
);
3179 ax_simple (expr
, aop_dup
);
3180 ax_const_l (expr
, 0);
3181 ax_simple (expr
, aop_less_signed
);
3182 ax_simple (expr
, aop_log_not
);
3183 i
= ax_goto (expr
, aop_if_goto
);
3184 /* We have to emit 0 - X. */
3185 ax_const_l (expr
, 0);
3186 ax_simple (expr
, aop_swap
);
3187 ax_simple (expr
, aop_sub
);
3188 ax_label (expr
, i
, expr
->len
);
3192 /* No need to sign extend here. */
3193 ax_const_l (expr
, 0);
3194 ax_simple (expr
, aop_swap
);
3195 ax_simple (expr
, aop_sub
);
3199 /* Sign extend the operand. */
3200 ax_ext (expr
, addr_size_bits
);
3201 ax_simple (expr
, aop_bit_not
);
3204 case DW_OP_plus_uconst
:
3205 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3206 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3207 but we micro-optimize anyhow. */
3210 ax_const_l (expr
, reg
);
3211 ax_simple (expr
, aop_add
);
3216 ax_simple (expr
, aop_bit_and
);
3220 /* Sign extend the operands. */
3221 ax_ext (expr
, addr_size_bits
);
3222 ax_simple (expr
, aop_swap
);
3223 ax_ext (expr
, addr_size_bits
);
3224 ax_simple (expr
, aop_swap
);
3225 ax_simple (expr
, aop_div_signed
);
3229 ax_simple (expr
, aop_sub
);
3233 ax_simple (expr
, aop_rem_unsigned
);
3237 ax_simple (expr
, aop_mul
);
3241 ax_simple (expr
, aop_bit_or
);
3245 ax_simple (expr
, aop_add
);
3249 ax_simple (expr
, aop_lsh
);
3253 ax_simple (expr
, aop_rsh_unsigned
);
3257 ax_simple (expr
, aop_rsh_signed
);
3261 ax_simple (expr
, aop_bit_xor
);
3265 /* Sign extend the operands. */
3266 ax_ext (expr
, addr_size_bits
);
3267 ax_simple (expr
, aop_swap
);
3268 ax_ext (expr
, addr_size_bits
);
3269 /* Note no swap here: A <= B is !(B < A). */
3270 ax_simple (expr
, aop_less_signed
);
3271 ax_simple (expr
, aop_log_not
);
3275 /* Sign extend the operands. */
3276 ax_ext (expr
, addr_size_bits
);
3277 ax_simple (expr
, aop_swap
);
3278 ax_ext (expr
, addr_size_bits
);
3279 ax_simple (expr
, aop_swap
);
3280 /* A >= B is !(A < B). */
3281 ax_simple (expr
, aop_less_signed
);
3282 ax_simple (expr
, aop_log_not
);
3286 /* Sign extend the operands. */
3287 ax_ext (expr
, addr_size_bits
);
3288 ax_simple (expr
, aop_swap
);
3289 ax_ext (expr
, addr_size_bits
);
3290 /* No need for a second swap here. */
3291 ax_simple (expr
, aop_equal
);
3295 /* Sign extend the operands. */
3296 ax_ext (expr
, addr_size_bits
);
3297 ax_simple (expr
, aop_swap
);
3298 ax_ext (expr
, addr_size_bits
);
3299 ax_simple (expr
, aop_swap
);
3300 ax_simple (expr
, aop_less_signed
);
3304 /* Sign extend the operands. */
3305 ax_ext (expr
, addr_size_bits
);
3306 ax_simple (expr
, aop_swap
);
3307 ax_ext (expr
, addr_size_bits
);
3308 /* Note no swap here: A > B is B < A. */
3309 ax_simple (expr
, aop_less_signed
);
3313 /* Sign extend the operands. */
3314 ax_ext (expr
, addr_size_bits
);
3315 ax_simple (expr
, aop_swap
);
3316 ax_ext (expr
, addr_size_bits
);
3317 /* No need for a swap here. */
3318 ax_simple (expr
, aop_equal
);
3319 ax_simple (expr
, aop_log_not
);
3322 case DW_OP_call_frame_cfa
:
3325 CORE_ADDR text_offset
;
3327 const gdb_byte
*cfa_start
, *cfa_end
;
3329 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3331 &text_offset
, &cfa_start
, &cfa_end
))
3334 ax_reg (expr
, regnum
);
3337 ax_const_l (expr
, off
);
3338 ax_simple (expr
, aop_add
);
3343 /* Another expression. */
3344 ax_const_l (expr
, text_offset
);
3345 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3349 loc
->kind
= axs_lvalue_memory
;
3353 case DW_OP_GNU_push_tls_address
:
3354 case DW_OP_form_tls_address
:
3358 case DW_OP_push_object_address
:
3363 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3365 i
= ax_goto (expr
, aop_goto
);
3366 dw_labels
.push_back (op_ptr
+ offset
- base
);
3367 patches
.push_back (i
);
3371 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3373 /* Zero extend the operand. */
3374 ax_zero_ext (expr
, addr_size_bits
);
3375 i
= ax_goto (expr
, aop_if_goto
);
3376 dw_labels
.push_back (op_ptr
+ offset
- base
);
3377 patches
.push_back (i
);
3384 case DW_OP_bit_piece
:
3388 if (op_ptr
- 1 == previous_piece
)
3389 error (_("Cannot translate empty pieces to agent expressions"));
3390 previous_piece
= op_ptr
- 1;
3392 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3393 if (op
== DW_OP_piece
)
3399 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3401 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3402 error (_("Expression pieces exceed word size"));
3404 /* Access the bits. */
3407 case axs_lvalue_register
:
3408 ax_reg (expr
, loc
->u
.reg
);
3411 case axs_lvalue_memory
:
3412 /* Offset the pointer, if needed. */
3415 ax_const_l (expr
, uoffset
/ 8);
3416 ax_simple (expr
, aop_add
);
3419 access_memory (arch
, expr
, size
);
3423 /* For a bits-big-endian target, shift up what we already
3424 have. For a bits-little-endian target, shift up the
3425 new data. Note that there is a potential bug here if
3426 the DWARF expression leaves multiple values on the
3428 if (bits_collected
> 0)
3430 if (bits_big_endian
)
3432 ax_simple (expr
, aop_swap
);
3433 ax_const_l (expr
, size
);
3434 ax_simple (expr
, aop_lsh
);
3435 /* We don't need a second swap here, because
3436 aop_bit_or is symmetric. */
3440 ax_const_l (expr
, size
);
3441 ax_simple (expr
, aop_lsh
);
3443 ax_simple (expr
, aop_bit_or
);
3446 bits_collected
+= size
;
3447 loc
->kind
= axs_rvalue
;
3451 case DW_OP_GNU_uninit
:
3457 struct dwarf2_locexpr_baton block
;
3458 int size
= (op
== DW_OP_call2
? 2 : 4);
3460 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3463 cu_offset cuoffset
= (cu_offset
) uoffset
;
3464 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
,
3467 /* DW_OP_call_ref is currently not supported. */
3468 gdb_assert (block
.per_cu
== per_cu
);
3470 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3471 block
.data
+ block
.size
, per_cu
);
3475 case DW_OP_call_ref
:
3478 case DW_OP_GNU_variable_value
:
3486 /* Patch all the branches we emitted. */
3487 for (int i
= 0; i
< patches
.size (); ++i
)
3489 int targ
= offsets
[dw_labels
[i
]];
3491 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3492 ax_label (expr
, patches
[i
], targ
);
3497 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3498 evaluator to calculate the location. */
3499 static struct value
*
3500 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3502 struct dwarf2_locexpr_baton
*dlbaton
3503 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3506 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3507 dlbaton
->size
, dlbaton
->per_cu
);
3512 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3513 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3516 static struct value
*
3517 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3519 struct dwarf2_locexpr_baton
*dlbaton
3520 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3522 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3526 /* Implementation of get_symbol_read_needs from
3527 symbol_computed_ops. */
3529 static enum symbol_needs_kind
3530 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3532 struct dwarf2_locexpr_baton
*dlbaton
3533 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3535 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3539 /* Return true if DATA points to the end of a piece. END is one past
3540 the last byte in the expression. */
3543 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3545 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3548 /* Helper for locexpr_describe_location_piece that finds the name of a
3552 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3556 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3557 We'd rather print *something* here than throw an error. */
3558 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3559 /* gdbarch_register_name may just return "", return something more
3560 descriptive for bad register numbers. */
3563 /* The text is output as "$bad_register_number".
3564 That is why we use the underscores. */
3565 return _("bad_register_number");
3567 return gdbarch_register_name (gdbarch
, regnum
);
3570 /* Nicely describe a single piece of a location, returning an updated
3571 position in the bytecode sequence. This function cannot recognize
3572 all locations; if a location is not recognized, it simply returns
3573 DATA. If there is an error during reading, e.g. we run off the end
3574 of the buffer, an error is thrown. */
3576 static const gdb_byte
*
3577 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3578 CORE_ADDR addr
, struct objfile
*objfile
,
3579 struct dwarf2_per_cu_data
*per_cu
,
3580 const gdb_byte
*data
, const gdb_byte
*end
,
3581 unsigned int addr_size
)
3583 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3586 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3588 fprintf_filtered (stream
, _("a variable in $%s"),
3589 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3592 else if (data
[0] == DW_OP_regx
)
3596 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3597 fprintf_filtered (stream
, _("a variable in $%s"),
3598 locexpr_regname (gdbarch
, reg
));
3600 else if (data
[0] == DW_OP_fbreg
)
3602 const struct block
*b
;
3603 struct symbol
*framefunc
;
3605 int64_t frame_offset
;
3606 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3608 int64_t base_offset
= 0;
3610 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3611 if (!piece_end_p (new_data
, end
))
3615 b
= block_for_pc (addr
);
3618 error (_("No block found for address for symbol \"%s\"."),
3619 SYMBOL_PRINT_NAME (symbol
));
3621 framefunc
= block_linkage_function (b
);
3624 error (_("No function found for block for symbol \"%s\"."),
3625 SYMBOL_PRINT_NAME (symbol
));
3627 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3629 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3631 const gdb_byte
*buf_end
;
3633 frame_reg
= base_data
[0] - DW_OP_breg0
;
3634 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3636 if (buf_end
!= base_data
+ base_size
)
3637 error (_("Unexpected opcode after "
3638 "DW_OP_breg%u for symbol \"%s\"."),
3639 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3641 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3643 /* The frame base is just the register, with no offset. */
3644 frame_reg
= base_data
[0] - DW_OP_reg0
;
3649 /* We don't know what to do with the frame base expression,
3650 so we can't trace this variable; give up. */
3654 fprintf_filtered (stream
,
3655 _("a variable at frame base reg $%s offset %s+%s"),
3656 locexpr_regname (gdbarch
, frame_reg
),
3657 plongest (base_offset
), plongest (frame_offset
));
3659 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3660 && piece_end_p (data
, end
))
3664 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3666 fprintf_filtered (stream
,
3667 _("a variable at offset %s from base reg $%s"),
3669 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3672 /* The location expression for a TLS variable looks like this (on a
3675 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3676 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3678 0x3 is the encoding for DW_OP_addr, which has an operand as long
3679 as the size of an address on the target machine (here is 8
3680 bytes). Note that more recent version of GCC emit DW_OP_const4u
3681 or DW_OP_const8u, depending on address size, rather than
3682 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3683 The operand represents the offset at which the variable is within
3684 the thread local storage. */
3686 else if (data
+ 1 + addr_size
< end
3687 && (data
[0] == DW_OP_addr
3688 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3689 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3690 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3691 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3692 && piece_end_p (data
+ 2 + addr_size
, end
))
3695 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3696 gdbarch_byte_order (gdbarch
));
3698 fprintf_filtered (stream
,
3699 _("a thread-local variable at offset 0x%s "
3700 "in the thread-local storage for `%s'"),
3701 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3703 data
+= 1 + addr_size
+ 1;
3706 /* With -gsplit-dwarf a TLS variable can also look like this:
3707 DW_AT_location : 3 byte block: fc 4 e0
3708 (DW_OP_GNU_const_index: 4;
3709 DW_OP_GNU_push_tls_address) */
3710 else if (data
+ 3 <= end
3711 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3712 && data
[0] == DW_OP_GNU_const_index
3714 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3715 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3716 && piece_end_p (data
+ 2 + leb128_size
, end
))
3720 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3721 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3722 fprintf_filtered (stream
,
3723 _("a thread-local variable at offset 0x%s "
3724 "in the thread-local storage for `%s'"),
3725 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3729 else if (data
[0] >= DW_OP_lit0
3730 && data
[0] <= DW_OP_lit31
3732 && data
[1] == DW_OP_stack_value
)
3734 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3741 /* Disassemble an expression, stopping at the end of a piece or at the
3742 end of the expression. Returns a pointer to the next unread byte
3743 in the input expression. If ALL is nonzero, then this function
3744 will keep going until it reaches the end of the expression.
3745 If there is an error during reading, e.g. we run off the end
3746 of the buffer, an error is thrown. */
3748 static const gdb_byte
*
3749 disassemble_dwarf_expression (struct ui_file
*stream
,
3750 struct gdbarch
*arch
, unsigned int addr_size
,
3751 int offset_size
, const gdb_byte
*start
,
3752 const gdb_byte
*data
, const gdb_byte
*end
,
3753 int indent
, int all
,
3754 struct dwarf2_per_cu_data
*per_cu
)
3758 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3760 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3765 name
= get_DW_OP_name (op
);
3768 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3769 op
, (long) (data
- 1 - start
));
3770 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3771 (long) (data
- 1 - start
), name
);
3776 ul
= extract_unsigned_integer (data
, addr_size
,
3777 gdbarch_byte_order (arch
));
3779 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3783 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3785 fprintf_filtered (stream
, " %s", pulongest (ul
));
3788 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3790 fprintf_filtered (stream
, " %s", plongest (l
));
3793 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3795 fprintf_filtered (stream
, " %s", pulongest (ul
));
3798 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3800 fprintf_filtered (stream
, " %s", plongest (l
));
3803 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3805 fprintf_filtered (stream
, " %s", pulongest (ul
));
3808 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3810 fprintf_filtered (stream
, " %s", plongest (l
));
3813 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3815 fprintf_filtered (stream
, " %s", pulongest (ul
));
3818 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3820 fprintf_filtered (stream
, " %s", plongest (l
));
3823 data
= safe_read_uleb128 (data
, end
, &ul
);
3824 fprintf_filtered (stream
, " %s", pulongest (ul
));
3827 data
= safe_read_sleb128 (data
, end
, &l
);
3828 fprintf_filtered (stream
, " %s", plongest (l
));
3863 fprintf_filtered (stream
, " [$%s]",
3864 locexpr_regname (arch
, op
- DW_OP_reg0
));
3868 data
= safe_read_uleb128 (data
, end
, &ul
);
3869 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3870 locexpr_regname (arch
, (int) ul
));
3873 case DW_OP_implicit_value
:
3874 data
= safe_read_uleb128 (data
, end
, &ul
);
3876 fprintf_filtered (stream
, " %s", pulongest (ul
));
3911 data
= safe_read_sleb128 (data
, end
, &l
);
3912 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3913 locexpr_regname (arch
, op
- DW_OP_breg0
));
3917 data
= safe_read_uleb128 (data
, end
, &ul
);
3918 data
= safe_read_sleb128 (data
, end
, &l
);
3919 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3921 locexpr_regname (arch
, (int) ul
),
3926 data
= safe_read_sleb128 (data
, end
, &l
);
3927 fprintf_filtered (stream
, " %s", plongest (l
));
3930 case DW_OP_xderef_size
:
3931 case DW_OP_deref_size
:
3933 fprintf_filtered (stream
, " %d", *data
);
3937 case DW_OP_plus_uconst
:
3938 data
= safe_read_uleb128 (data
, end
, &ul
);
3939 fprintf_filtered (stream
, " %s", pulongest (ul
));
3943 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3945 fprintf_filtered (stream
, " to %ld",
3946 (long) (data
+ l
- start
));
3950 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3952 fprintf_filtered (stream
, " %ld",
3953 (long) (data
+ l
- start
));
3957 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3959 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3963 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3965 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3968 case DW_OP_call_ref
:
3969 ul
= extract_unsigned_integer (data
, offset_size
,
3970 gdbarch_byte_order (arch
));
3971 data
+= offset_size
;
3972 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3976 data
= safe_read_uleb128 (data
, end
, &ul
);
3977 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3980 case DW_OP_bit_piece
:
3984 data
= safe_read_uleb128 (data
, end
, &ul
);
3985 data
= safe_read_uleb128 (data
, end
, &offset
);
3986 fprintf_filtered (stream
, " size %s offset %s (bits)",
3987 pulongest (ul
), pulongest (offset
));
3991 case DW_OP_implicit_pointer
:
3992 case DW_OP_GNU_implicit_pointer
:
3994 ul
= extract_unsigned_integer (data
, offset_size
,
3995 gdbarch_byte_order (arch
));
3996 data
+= offset_size
;
3998 data
= safe_read_sleb128 (data
, end
, &l
);
4000 fprintf_filtered (stream
, " DIE %s offset %s",
4001 phex_nz (ul
, offset_size
),
4006 case DW_OP_deref_type
:
4007 case DW_OP_GNU_deref_type
:
4009 int deref_addr_size
= *data
++;
4012 data
= safe_read_uleb128 (data
, end
, &ul
);
4013 cu_offset offset
= (cu_offset
) ul
;
4014 type
= dwarf2_get_die_type (offset
, per_cu
);
4015 fprintf_filtered (stream
, "<");
4016 type_print (type
, "", stream
, -1);
4017 fprintf_filtered (stream
, " [0x%s]> %d",
4018 phex_nz (to_underlying (offset
), 0),
4023 case DW_OP_const_type
:
4024 case DW_OP_GNU_const_type
:
4028 data
= safe_read_uleb128 (data
, end
, &ul
);
4029 cu_offset type_die
= (cu_offset
) ul
;
4030 type
= dwarf2_get_die_type (type_die
, per_cu
);
4031 fprintf_filtered (stream
, "<");
4032 type_print (type
, "", stream
, -1);
4033 fprintf_filtered (stream
, " [0x%s]>",
4034 phex_nz (to_underlying (type_die
), 0));
4038 case DW_OP_regval_type
:
4039 case DW_OP_GNU_regval_type
:
4044 data
= safe_read_uleb128 (data
, end
, ®
);
4045 data
= safe_read_uleb128 (data
, end
, &ul
);
4046 cu_offset type_die
= (cu_offset
) ul
;
4048 type
= dwarf2_get_die_type (type_die
, per_cu
);
4049 fprintf_filtered (stream
, "<");
4050 type_print (type
, "", stream
, -1);
4051 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4052 phex_nz (to_underlying (type_die
), 0),
4053 locexpr_regname (arch
, reg
));
4058 case DW_OP_GNU_convert
:
4059 case DW_OP_reinterpret
:
4060 case DW_OP_GNU_reinterpret
:
4062 data
= safe_read_uleb128 (data
, end
, &ul
);
4063 cu_offset type_die
= (cu_offset
) ul
;
4065 if (to_underlying (type_die
) == 0)
4066 fprintf_filtered (stream
, "<0>");
4071 type
= dwarf2_get_die_type (type_die
, per_cu
);
4072 fprintf_filtered (stream
, "<");
4073 type_print (type
, "", stream
, -1);
4074 fprintf_filtered (stream
, " [0x%s]>",
4075 phex_nz (to_underlying (type_die
), 0));
4080 case DW_OP_entry_value
:
4081 case DW_OP_GNU_entry_value
:
4082 data
= safe_read_uleb128 (data
, end
, &ul
);
4083 fputc_filtered ('\n', stream
);
4084 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4085 start
, data
, data
+ ul
, indent
+ 2,
4090 case DW_OP_GNU_parameter_ref
:
4091 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4093 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4096 case DW_OP_GNU_addr_index
:
4097 data
= safe_read_uleb128 (data
, end
, &ul
);
4098 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4099 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4101 case DW_OP_GNU_const_index
:
4102 data
= safe_read_uleb128 (data
, end
, &ul
);
4103 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4104 fprintf_filtered (stream
, " %s", pulongest (ul
));
4107 case DW_OP_GNU_variable_value
:
4108 ul
= extract_unsigned_integer (data
, offset_size
,
4109 gdbarch_byte_order (arch
));
4110 data
+= offset_size
;
4111 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4115 fprintf_filtered (stream
, "\n");
4121 /* Describe a single location, which may in turn consist of multiple
4125 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4126 struct ui_file
*stream
,
4127 const gdb_byte
*data
, size_t size
,
4128 struct objfile
*objfile
, unsigned int addr_size
,
4129 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4131 const gdb_byte
*end
= data
+ size
;
4132 int first_piece
= 1, bad
= 0;
4136 const gdb_byte
*here
= data
;
4137 int disassemble
= 1;
4142 fprintf_filtered (stream
, _(", and "));
4144 if (!dwarf_always_disassemble
)
4146 data
= locexpr_describe_location_piece (symbol
, stream
,
4147 addr
, objfile
, per_cu
,
4148 data
, end
, addr_size
);
4149 /* If we printed anything, or if we have an empty piece,
4150 then don't disassemble. */
4152 || data
[0] == DW_OP_piece
4153 || data
[0] == DW_OP_bit_piece
)
4158 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4159 data
= disassemble_dwarf_expression (stream
,
4160 get_objfile_arch (objfile
),
4161 addr_size
, offset_size
, data
,
4163 dwarf_always_disassemble
,
4169 int empty
= data
== here
;
4172 fprintf_filtered (stream
, " ");
4173 if (data
[0] == DW_OP_piece
)
4177 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4180 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4183 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4186 else if (data
[0] == DW_OP_bit_piece
)
4188 uint64_t bits
, offset
;
4190 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4191 data
= safe_read_uleb128 (data
, end
, &offset
);
4194 fprintf_filtered (stream
,
4195 _("an empty %s-bit piece"),
4198 fprintf_filtered (stream
,
4199 _(" [%s-bit piece, offset %s bits]"),
4200 pulongest (bits
), pulongest (offset
));
4210 if (bad
|| data
> end
)
4211 error (_("Corrupted DWARF2 expression for \"%s\"."),
4212 SYMBOL_PRINT_NAME (symbol
));
4215 /* Print a natural-language description of SYMBOL to STREAM. This
4216 version is for a symbol with a single location. */
4219 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4220 struct ui_file
*stream
)
4222 struct dwarf2_locexpr_baton
*dlbaton
4223 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4224 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4225 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4226 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4228 locexpr_describe_location_1 (symbol
, addr
, stream
,
4229 dlbaton
->data
, dlbaton
->size
,
4230 objfile
, addr_size
, offset_size
,
4234 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4235 any necessary bytecode in AX. */
4238 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4239 struct axs_value
*value
)
4241 struct dwarf2_locexpr_baton
*dlbaton
4242 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4243 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4245 if (dlbaton
->size
== 0)
4246 value
->optimized_out
= 1;
4248 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4249 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
);
4252 /* symbol_computed_ops 'generate_c_location' method. */
4255 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4256 struct gdbarch
*gdbarch
,
4257 unsigned char *registers_used
,
4258 CORE_ADDR pc
, const char *result_name
)
4260 struct dwarf2_locexpr_baton
*dlbaton
4261 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4262 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4264 if (dlbaton
->size
== 0)
4265 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4267 compile_dwarf_expr_to_c (stream
, result_name
,
4268 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4269 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4273 /* The set of location functions used with the DWARF-2 expression
4275 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4276 locexpr_read_variable
,
4277 locexpr_read_variable_at_entry
,
4278 locexpr_get_symbol_read_needs
,
4279 locexpr_describe_location
,
4280 0, /* location_has_loclist */
4281 locexpr_tracepoint_var_ref
,
4282 locexpr_generate_c_location
4286 /* Wrapper functions for location lists. These generally find
4287 the appropriate location expression and call something above. */
4289 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4290 evaluator to calculate the location. */
4291 static struct value
*
4292 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4294 struct dwarf2_loclist_baton
*dlbaton
4295 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4297 const gdb_byte
*data
;
4299 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4301 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4302 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4308 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4309 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4312 Function always returns non-NULL value, it may be marked optimized out if
4313 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4314 if it cannot resolve the parameter for any reason. */
4316 static struct value
*
4317 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4319 struct dwarf2_loclist_baton
*dlbaton
4320 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4321 const gdb_byte
*data
;
4325 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4326 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4328 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4330 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4332 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4335 /* Implementation of get_symbol_read_needs from
4336 symbol_computed_ops. */
4338 static enum symbol_needs_kind
4339 loclist_symbol_needs (struct symbol
*symbol
)
4341 /* If there's a location list, then assume we need to have a frame
4342 to choose the appropriate location expression. With tracking of
4343 global variables this is not necessarily true, but such tracking
4344 is disabled in GCC at the moment until we figure out how to
4347 return SYMBOL_NEEDS_FRAME
;
4350 /* Print a natural-language description of SYMBOL to STREAM. This
4351 version applies when there is a list of different locations, each
4352 with a specified address range. */
4355 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4356 struct ui_file
*stream
)
4358 struct dwarf2_loclist_baton
*dlbaton
4359 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4360 const gdb_byte
*loc_ptr
, *buf_end
;
4361 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4362 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4363 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4364 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4365 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4366 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4367 /* Adjust base_address for relocatable objects. */
4368 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4369 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4372 loc_ptr
= dlbaton
->data
;
4373 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4375 fprintf_filtered (stream
, _("multi-location:\n"));
4377 /* Iterate through locations until we run out. */
4380 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4382 enum debug_loc_kind kind
;
4383 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4385 if (dlbaton
->from_dwo
)
4386 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4387 loc_ptr
, buf_end
, &new_ptr
,
4388 &low
, &high
, byte_order
);
4390 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4392 byte_order
, addr_size
,
4397 case DEBUG_LOC_END_OF_LIST
:
4400 case DEBUG_LOC_BASE_ADDRESS
:
4401 base_address
= high
+ base_offset
;
4402 fprintf_filtered (stream
, _(" Base address %s"),
4403 paddress (gdbarch
, base_address
));
4405 case DEBUG_LOC_START_END
:
4406 case DEBUG_LOC_START_LENGTH
:
4408 case DEBUG_LOC_BUFFER_OVERFLOW
:
4409 case DEBUG_LOC_INVALID_ENTRY
:
4410 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4411 SYMBOL_PRINT_NAME (symbol
));
4413 gdb_assert_not_reached ("bad debug_loc_kind");
4416 /* Otherwise, a location expression entry. */
4417 low
+= base_address
;
4418 high
+= base_address
;
4420 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4421 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4423 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4426 /* (It would improve readability to print only the minimum
4427 necessary digits of the second number of the range.) */
4428 fprintf_filtered (stream
, _(" Range %s-%s: "),
4429 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4431 /* Now describe this particular location. */
4432 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4433 objfile
, addr_size
, offset_size
,
4436 fprintf_filtered (stream
, "\n");
4442 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4443 any necessary bytecode in AX. */
4445 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4446 struct axs_value
*value
)
4448 struct dwarf2_loclist_baton
*dlbaton
4449 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4450 const gdb_byte
*data
;
4452 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4454 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4456 value
->optimized_out
= 1;
4458 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4462 /* symbol_computed_ops 'generate_c_location' method. */
4465 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4466 struct gdbarch
*gdbarch
,
4467 unsigned char *registers_used
,
4468 CORE_ADDR pc
, const char *result_name
)
4470 struct dwarf2_loclist_baton
*dlbaton
4471 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4472 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4473 const gdb_byte
*data
;
4476 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4478 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4480 compile_dwarf_expr_to_c (stream
, result_name
,
4481 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4486 /* The set of location functions used with the DWARF-2 expression
4487 evaluator and location lists. */
4488 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4489 loclist_read_variable
,
4490 loclist_read_variable_at_entry
,
4491 loclist_symbol_needs
,
4492 loclist_describe_location
,
4493 1, /* location_has_loclist */
4494 loclist_tracepoint_var_ref
,
4495 loclist_generate_c_location
4499 _initialize_dwarf2loc (void)
4501 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4502 &entry_values_debug
,
4503 _("Set entry values and tail call frames "
4505 _("Show entry values and tail call frames "
4507 _("When non-zero, the process of determining "
4508 "parameter values from function entry point "
4509 "and tail call frames will be printed."),
4511 show_entry_values_debug
,
4512 &setdebuglist
, &showdebuglist
);