1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "complaints.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
51 struct frame_info
*frame
,
54 struct dwarf2_per_cu_data
*per_cu
,
55 struct type
*subobj_type
,
56 LONGEST subobj_byte_offset
);
58 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
59 (struct frame_info
*frame
,
60 enum call_site_parameter_kind kind
,
61 union call_site_parameter_u kind_u
,
62 struct dwarf2_per_cu_data
**per_cu_return
);
64 static struct value
*indirect_synthetic_pointer
65 (sect_offset die
, LONGEST byte_offset
,
66 dwarf2_per_cu_data
*per_cu
,
67 dwarf2_per_objfile
*per_objfile
,
68 struct frame_info
*frame
,
69 struct type
*type
, bool resolve_abstract_p
= false);
71 /* Until these have formal names, we define these here.
72 ref: http://gcc.gnu.org/wiki/DebugFission
73 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
74 and is then followed by data specific to that entry. */
78 /* Indicates the end of the list of entries. */
79 DEBUG_LOC_END_OF_LIST
= 0,
81 /* This is followed by an unsigned LEB128 number that is an index into
82 .debug_addr and specifies the base address for all following entries. */
83 DEBUG_LOC_BASE_ADDRESS
= 1,
85 /* This is followed by two unsigned LEB128 numbers that are indices into
86 .debug_addr and specify the beginning and ending addresses, and then
87 a normal location expression as in .debug_loc. */
88 DEBUG_LOC_START_END
= 2,
90 /* This is followed by an unsigned LEB128 number that is an index into
91 .debug_addr and specifies the beginning address, and a 4 byte unsigned
92 number that specifies the length, and then a normal location expression
94 DEBUG_LOC_START_LENGTH
= 3,
96 /* This is followed by two unsigned LEB128 operands. The values of these
97 operands are the starting and ending offsets, respectively, relative to
98 the applicable base address. */
99 DEBUG_LOC_OFFSET_PAIR
= 4,
101 /* An internal value indicating there is insufficient data. */
102 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
104 /* An internal value indicating an invalid kind of entry was found. */
105 DEBUG_LOC_INVALID_ENTRY
= -2
108 /* Helper function which throws an error if a synthetic pointer is
112 invalid_synthetic_pointer (void)
114 error (_("access outside bounds of object "
115 "referenced via synthetic pointer"));
118 /* Decode the addresses in a non-dwo .debug_loc entry.
119 A pointer to the next byte to examine is returned in *NEW_PTR.
120 The encoded low,high addresses are return in *LOW,*HIGH.
121 The result indicates the kind of entry found. */
123 static enum debug_loc_kind
124 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
125 const gdb_byte
**new_ptr
,
126 CORE_ADDR
*low
, CORE_ADDR
*high
,
127 enum bfd_endian byte_order
,
128 unsigned int addr_size
,
131 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
133 if (buf_end
- loc_ptr
< 2 * addr_size
)
134 return DEBUG_LOC_BUFFER_OVERFLOW
;
137 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
139 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
140 loc_ptr
+= addr_size
;
143 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
145 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
146 loc_ptr
+= addr_size
;
150 /* A base-address-selection entry. */
151 if ((*low
& base_mask
) == base_mask
)
152 return DEBUG_LOC_BASE_ADDRESS
;
154 /* An end-of-list entry. */
155 if (*low
== 0 && *high
== 0)
156 return DEBUG_LOC_END_OF_LIST
;
158 return DEBUG_LOC_START_END
;
161 /* Decode the addresses in .debug_loclists entry.
162 A pointer to the next byte to examine is returned in *NEW_PTR.
163 The encoded low,high addresses are return in *LOW,*HIGH.
164 The result indicates the kind of entry found. */
166 static enum debug_loc_kind
167 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
168 dwarf2_per_objfile
*per_objfile
,
169 const gdb_byte
*loc_ptr
,
170 const gdb_byte
*buf_end
,
171 const gdb_byte
**new_ptr
,
172 CORE_ADDR
*low
, CORE_ADDR
*high
,
173 enum bfd_endian byte_order
,
174 unsigned int addr_size
,
179 if (loc_ptr
== buf_end
)
180 return DEBUG_LOC_BUFFER_OVERFLOW
;
184 case DW_LLE_base_addressx
:
186 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
188 return DEBUG_LOC_BUFFER_OVERFLOW
;
189 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
191 return DEBUG_LOC_BASE_ADDRESS
;
192 case DW_LLE_startx_length
:
193 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
195 return DEBUG_LOC_BUFFER_OVERFLOW
;
196 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
198 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
200 return DEBUG_LOC_BUFFER_OVERFLOW
;
203 return DEBUG_LOC_START_LENGTH
;
204 case DW_LLE_start_length
:
205 if (buf_end
- loc_ptr
< addr_size
)
206 return DEBUG_LOC_BUFFER_OVERFLOW
;
208 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
210 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
211 loc_ptr
+= addr_size
;
213 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
215 return DEBUG_LOC_BUFFER_OVERFLOW
;
218 return DEBUG_LOC_START_LENGTH
;
219 case DW_LLE_end_of_list
:
221 return DEBUG_LOC_END_OF_LIST
;
222 case DW_LLE_base_address
:
223 if (loc_ptr
+ addr_size
> buf_end
)
224 return DEBUG_LOC_BUFFER_OVERFLOW
;
226 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
228 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
229 loc_ptr
+= addr_size
;
231 return DEBUG_LOC_BASE_ADDRESS
;
232 case DW_LLE_offset_pair
:
233 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
235 return DEBUG_LOC_BUFFER_OVERFLOW
;
237 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
239 return DEBUG_LOC_BUFFER_OVERFLOW
;
242 return DEBUG_LOC_OFFSET_PAIR
;
243 /* Following cases are not supported yet. */
244 case DW_LLE_startx_endx
:
245 case DW_LLE_start_end
:
246 case DW_LLE_default_location
:
248 return DEBUG_LOC_INVALID_ENTRY
;
252 /* Decode the addresses in .debug_loc.dwo entry.
253 A pointer to the next byte to examine is returned in *NEW_PTR.
254 The encoded low,high addresses are return in *LOW,*HIGH.
255 The result indicates the kind of entry found. */
257 static enum debug_loc_kind
258 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
259 dwarf2_per_objfile
*per_objfile
,
260 const gdb_byte
*loc_ptr
,
261 const gdb_byte
*buf_end
,
262 const gdb_byte
**new_ptr
,
263 CORE_ADDR
*low
, CORE_ADDR
*high
,
264 enum bfd_endian byte_order
)
266 uint64_t low_index
, high_index
;
268 if (loc_ptr
== buf_end
)
269 return DEBUG_LOC_BUFFER_OVERFLOW
;
273 case DW_LLE_GNU_end_of_list_entry
:
275 return DEBUG_LOC_END_OF_LIST
;
276 case DW_LLE_GNU_base_address_selection_entry
:
278 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
280 return DEBUG_LOC_BUFFER_OVERFLOW
;
281 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
283 return DEBUG_LOC_BASE_ADDRESS
;
284 case DW_LLE_GNU_start_end_entry
:
285 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
287 return DEBUG_LOC_BUFFER_OVERFLOW
;
288 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
289 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
291 return DEBUG_LOC_BUFFER_OVERFLOW
;
292 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
294 return DEBUG_LOC_START_END
;
295 case DW_LLE_GNU_start_length_entry
:
296 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
298 return DEBUG_LOC_BUFFER_OVERFLOW
;
299 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
300 if (loc_ptr
+ 4 > buf_end
)
301 return DEBUG_LOC_BUFFER_OVERFLOW
;
303 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
304 *new_ptr
= loc_ptr
+ 4;
305 return DEBUG_LOC_START_LENGTH
;
307 return DEBUG_LOC_INVALID_ENTRY
;
311 /* A function for dealing with location lists. Given a
312 symbol baton (BATON) and a pc value (PC), find the appropriate
313 location expression, set *LOCEXPR_LENGTH, and return a pointer
314 to the beginning of the expression. Returns NULL on failure.
316 For now, only return the first matching location expression; there
317 can be more than one in the list. */
320 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
321 size_t *locexpr_length
, CORE_ADDR pc
)
323 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
324 struct objfile
*objfile
= per_objfile
->objfile
;
325 struct gdbarch
*gdbarch
= objfile
->arch ();
326 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
327 unsigned int addr_size
= baton
->per_cu
->addr_size ();
328 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
329 /* Adjust base_address for relocatable objects. */
330 CORE_ADDR base_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
331 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
332 const gdb_byte
*loc_ptr
, *buf_end
;
334 loc_ptr
= baton
->data
;
335 buf_end
= baton
->data
+ baton
->size
;
339 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
341 enum debug_loc_kind kind
;
342 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
344 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
345 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
347 loc_ptr
, buf_end
, &new_ptr
,
348 &low
, &high
, byte_order
);
349 else if (baton
->per_cu
->version () < 5)
350 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
352 byte_order
, addr_size
,
355 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
357 loc_ptr
, buf_end
, &new_ptr
,
358 &low
, &high
, byte_order
,
359 addr_size
, signed_addr_p
);
364 case DEBUG_LOC_END_OF_LIST
:
367 case DEBUG_LOC_BASE_ADDRESS
:
368 base_address
= high
+ base_offset
;
370 case DEBUG_LOC_START_END
:
371 case DEBUG_LOC_START_LENGTH
:
372 case DEBUG_LOC_OFFSET_PAIR
:
374 case DEBUG_LOC_BUFFER_OVERFLOW
:
375 case DEBUG_LOC_INVALID_ENTRY
:
376 error (_("dwarf2_find_location_expression: "
377 "Corrupted DWARF expression."));
379 gdb_assert_not_reached ("bad debug_loc_kind");
382 /* Otherwise, a location expression entry.
383 If the entry is from a DWO, don't add base address: the entry is from
384 .debug_addr which already has the DWARF "base address". We still add
385 base_offset in case we're debugging a PIE executable. However, if the
386 entry is DW_LLE_offset_pair from a DWO, add the base address as the
387 operands are offsets relative to the applicable base address. */
388 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
396 high
+= base_address
;
399 if (baton
->per_cu
->version () < 5)
401 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
406 unsigned int bytes_read
;
408 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
409 loc_ptr
+= bytes_read
;
412 if (low
== high
&& pc
== low
)
414 /* This is entry PC record present only at entry point
415 of a function. Verify it is really the function entry point. */
417 const struct block
*pc_block
= block_for_pc (pc
);
418 struct symbol
*pc_func
= NULL
;
421 pc_func
= block_linkage_function (pc_block
);
423 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
425 *locexpr_length
= length
;
430 if (pc
>= low
&& pc
< high
)
432 *locexpr_length
= length
;
440 /* Implement find_frame_base_location method for LOC_BLOCK functions using
441 DWARF expression for its DW_AT_frame_base. */
444 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
445 const gdb_byte
**start
, size_t *length
)
447 struct dwarf2_locexpr_baton
*symbaton
448 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
450 *length
= symbaton
->size
;
451 *start
= symbaton
->data
;
454 /* Implement the struct symbol_block_ops::get_frame_base method for
455 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
458 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
460 struct gdbarch
*gdbarch
;
462 struct dwarf2_locexpr_baton
*dlbaton
;
463 const gdb_byte
*start
;
465 struct value
*result
;
467 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
468 Thus, it's supposed to provide the find_frame_base_location method as
470 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
472 gdbarch
= get_frame_arch (frame
);
473 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
474 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
476 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
477 (framefunc
, get_frame_pc (frame
), &start
, &length
);
478 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
481 /* The DW_AT_frame_base attribute contains a location description which
482 computes the base address itself. However, the call to
483 dwarf2_evaluate_loc_desc returns a value representing a variable at
484 that address. The frame base address is thus this variable's
486 return value_address (result
);
489 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
490 function uses DWARF expression for its DW_AT_frame_base. */
492 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
494 locexpr_find_frame_base_location
,
495 locexpr_get_frame_base
498 /* Implement find_frame_base_location method for LOC_BLOCK functions using
499 DWARF location list for its DW_AT_frame_base. */
502 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
503 const gdb_byte
**start
, size_t *length
)
505 struct dwarf2_loclist_baton
*symbaton
506 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
508 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
511 /* Implement the struct symbol_block_ops::get_frame_base method for
512 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
515 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
517 struct gdbarch
*gdbarch
;
519 struct dwarf2_loclist_baton
*dlbaton
;
520 const gdb_byte
*start
;
522 struct value
*result
;
524 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
525 Thus, it's supposed to provide the find_frame_base_location method as
527 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
529 gdbarch
= get_frame_arch (frame
);
530 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
531 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
533 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
534 (framefunc
, get_frame_pc (frame
), &start
, &length
);
535 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
538 /* The DW_AT_frame_base attribute contains a location description which
539 computes the base address itself. However, the call to
540 dwarf2_evaluate_loc_desc returns a value representing a variable at
541 that address. The frame base address is thus this variable's
543 return value_address (result
);
546 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
547 function uses DWARF location list for its DW_AT_frame_base. */
549 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
551 loclist_find_frame_base_location
,
552 loclist_get_frame_base
555 /* See dwarf2loc.h. */
558 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
559 const gdb_byte
**start
, size_t *length
)
561 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
563 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
565 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
571 error (_("Could not find the frame base for \"%s\"."),
572 framefunc
->natural_name ());
576 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
578 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
580 return ctx
->get_frame_pc ();
584 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
585 dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
)
587 struct dwarf2_locexpr_baton block
;
589 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, per_objfile
,
590 get_frame_pc_for_per_cu_dwarf_call
,
593 /* DW_OP_call_ref is currently not supported. */
594 gdb_assert (block
.per_cu
== per_cu
);
596 ctx
->eval (block
.data
, block
.size
);
599 /* Given context CTX, section offset SECT_OFF, and compilation unit
600 data PER_CU, execute the "variable value" operation on the DIE
601 found at SECT_OFF. */
603 static struct value
*
604 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
605 dwarf2_per_cu_data
*per_cu
,
606 dwarf2_per_objfile
*per_objfile
)
608 struct type
*die_type
609 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
, per_objfile
);
611 if (die_type
== NULL
)
612 error (_("Bad DW_OP_GNU_variable_value DIE."));
614 /* Note: Things still work when the following test is removed. This
615 test and error is here to conform to the proposed specification. */
616 if (die_type
->code () != TYPE_CODE_INT
617 && die_type
->code () != TYPE_CODE_PTR
)
618 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
620 struct type
*type
= lookup_pointer_type (die_type
);
621 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
622 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, per_objfile
, frame
,
626 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
629 dwarf_evaluate_loc_desc (dwarf2_per_objfile
*per_objfile
)
630 : dwarf_expr_context (per_objfile
)
633 struct frame_info
*frame
;
634 struct dwarf2_per_cu_data
*per_cu
;
635 CORE_ADDR obj_address
;
637 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
638 the frame in BATON. */
640 CORE_ADDR
get_frame_cfa () override
642 return dwarf2_frame_cfa (frame
);
645 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
646 the frame in BATON. */
648 CORE_ADDR
get_frame_pc () override
650 return get_frame_address_in_block (frame
);
653 /* Using the objfile specified in BATON, find the address for the
654 current thread's thread-local storage with offset OFFSET. */
655 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
657 struct objfile
*objfile
= per_cu
->objfile ();
659 return target_translate_tls_address (objfile
, offset
);
662 /* Helper interface of per_cu_dwarf_call for
663 dwarf2_evaluate_loc_desc. */
665 void dwarf_call (cu_offset die_offset
) override
667 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
670 /* Helper interface of sect_variable_value for
671 dwarf2_evaluate_loc_desc. */
673 struct value
*dwarf_variable_value (sect_offset sect_off
) override
675 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
678 struct type
*get_base_type (cu_offset die_offset
, int size
) override
680 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
682 error (_("Could not find type for DW_OP_const_type"));
683 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
684 error (_("DW_OP_const_type has different sizes for type and data"));
688 /* Callback function for dwarf2_evaluate_loc_desc.
689 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
691 CORE_ADDR
get_addr_index (unsigned int index
) override
693 return dwarf2_read_addr_index (per_cu
, per_objfile
, index
);
696 /* Callback function for get_object_address. Return the address of the VLA
699 CORE_ADDR
get_object_address () override
701 if (obj_address
== 0)
702 error (_("Location address is not set."));
706 /* Execute DWARF block of call_site_parameter which matches KIND and
707 KIND_U. Choose DEREF_SIZE value of that parameter. Search
708 caller of this objects's frame.
710 The caller can be from a different CU - per_cu_dwarf_call
711 implementation can be more simple as it does not support cross-CU
714 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
715 union call_site_parameter_u kind_u
,
716 int deref_size
) override
718 struct frame_info
*caller_frame
;
719 struct dwarf2_per_cu_data
*caller_per_cu
;
720 struct call_site_parameter
*parameter
;
721 const gdb_byte
*data_src
;
724 caller_frame
= get_prev_frame (frame
);
726 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
728 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
729 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
731 /* DEREF_SIZE size is not verified here. */
732 if (data_src
== NULL
)
733 throw_error (NO_ENTRY_VALUE_ERROR
,
734 _("Cannot resolve DW_AT_call_data_value"));
736 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
738 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
740 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
743 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
744 this->gdbarch
= per_cu
->objfile ()->arch ();
745 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
746 this->addr_size
= per_cu
->addr_size ();
748 this->eval (data_src
, size
);
751 /* Using the frame specified in BATON, find the location expression
752 describing the frame base. Return a pointer to it in START and
753 its length in LENGTH. */
754 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
756 /* FIXME: cagney/2003-03-26: This code should be using
757 get_frame_base_address(), and then implement a dwarf2 specific
759 struct symbol
*framefunc
;
760 const struct block
*bl
= get_frame_block (frame
, NULL
);
763 error (_("frame address is not available."));
765 /* Use block_linkage_function, which returns a real (not inlined)
766 function, instead of get_frame_function, which may return an
768 framefunc
= block_linkage_function (bl
);
770 /* If we found a frame-relative symbol then it was certainly within
771 some function associated with a frame. If we can't find the frame,
772 something has gone wrong. */
773 gdb_assert (framefunc
!= NULL
);
775 func_get_frame_base_dwarf_block (framefunc
,
776 get_frame_address_in_block (frame
),
780 /* Read memory at ADDR (length LEN) into BUF. */
782 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
784 read_memory (addr
, buf
, len
);
787 /* Using the frame specified in BATON, return the value of register
788 REGNUM, treated as a pointer. */
789 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
791 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
792 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
794 return address_from_register (regnum
, frame
);
797 /* Implement "get_reg_value" callback. */
799 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
801 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
802 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
804 return value_from_register (type
, regnum
, frame
);
808 /* See dwarf2loc.h. */
810 unsigned int entry_values_debug
= 0;
812 /* Helper to set entry_values_debug. */
815 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
816 struct cmd_list_element
*c
, const char *value
)
818 fprintf_filtered (file
,
819 _("Entry values and tail call frames debugging is %s.\n"),
823 /* Find DW_TAG_call_site's DW_AT_call_target address.
824 CALLER_FRAME (for registers) can be NULL if it is not known. This function
825 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
828 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
829 struct call_site
*call_site
,
830 struct frame_info
*caller_frame
)
832 switch (FIELD_LOC_KIND (call_site
->target
))
834 case FIELD_LOC_KIND_DWARF_BLOCK
:
836 struct dwarf2_locexpr_baton
*dwarf_block
;
838 struct type
*caller_core_addr_type
;
839 struct gdbarch
*caller_arch
;
841 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
842 if (dwarf_block
== NULL
)
844 struct bound_minimal_symbol msym
;
846 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
847 throw_error (NO_ENTRY_VALUE_ERROR
,
848 _("DW_AT_call_target is not specified at %s in %s"),
849 paddress (call_site_gdbarch
, call_site
->pc
),
850 (msym
.minsym
== NULL
? "???"
851 : msym
.minsym
->print_name ()));
854 if (caller_frame
== NULL
)
856 struct bound_minimal_symbol msym
;
858 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
859 throw_error (NO_ENTRY_VALUE_ERROR
,
860 _("DW_AT_call_target DWARF block resolving "
861 "requires known frame which is currently not "
862 "available at %s in %s"),
863 paddress (call_site_gdbarch
, call_site
->pc
),
864 (msym
.minsym
== NULL
? "???"
865 : msym
.minsym
->print_name ()));
868 caller_arch
= get_frame_arch (caller_frame
);
869 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
870 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
871 dwarf_block
->data
, dwarf_block
->size
,
872 dwarf_block
->per_cu
);
873 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
874 if (VALUE_LVAL (val
) == lval_memory
)
875 return value_address (val
);
877 return value_as_address (val
);
880 case FIELD_LOC_KIND_PHYSNAME
:
882 const char *physname
;
883 struct bound_minimal_symbol msym
;
885 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
887 /* Handle both the mangled and demangled PHYSNAME. */
888 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
889 if (msym
.minsym
== NULL
)
891 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
892 throw_error (NO_ENTRY_VALUE_ERROR
,
893 _("Cannot find function \"%s\" for a call site target "
895 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
896 (msym
.minsym
== NULL
? "???"
897 : msym
.minsym
->print_name ()));
900 return BMSYMBOL_VALUE_ADDRESS (msym
);
903 case FIELD_LOC_KIND_PHYSADDR
:
904 return FIELD_STATIC_PHYSADDR (call_site
->target
);
907 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
911 /* Convert function entry point exact address ADDR to the function which is
912 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
913 NO_ENTRY_VALUE_ERROR otherwise. */
915 static struct symbol
*
916 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
918 struct symbol
*sym
= find_pc_function (addr
);
921 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
922 throw_error (NO_ENTRY_VALUE_ERROR
,
923 _("DW_TAG_call_site resolving failed to find function "
924 "name for address %s"),
925 paddress (gdbarch
, addr
));
927 type
= SYMBOL_TYPE (sym
);
928 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
929 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
934 /* Verify function with entry point exact address ADDR can never call itself
935 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
936 can call itself via tail calls.
938 If a funtion can tail call itself its entry value based parameters are
939 unreliable. There is no verification whether the value of some/all
940 parameters is unchanged through the self tail call, we expect if there is
941 a self tail call all the parameters can be modified. */
944 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
948 /* The verification is completely unordered. Track here function addresses
949 which still need to be iterated. */
950 std::vector
<CORE_ADDR
> todo
;
952 /* Track here CORE_ADDRs which were already visited. */
953 std::unordered_set
<CORE_ADDR
> addr_hash
;
955 todo
.push_back (verify_addr
);
956 while (!todo
.empty ())
958 struct symbol
*func_sym
;
959 struct call_site
*call_site
;
964 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
966 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
967 call_site
; call_site
= call_site
->tail_call_next
)
969 CORE_ADDR target_addr
;
971 /* CALLER_FRAME with registers is not available for tail-call jumped
973 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
975 if (target_addr
== verify_addr
)
977 struct bound_minimal_symbol msym
;
979 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
980 throw_error (NO_ENTRY_VALUE_ERROR
,
981 _("DW_OP_entry_value resolving has found "
982 "function \"%s\" at %s can call itself via tail "
984 (msym
.minsym
== NULL
? "???"
985 : msym
.minsym
->print_name ()),
986 paddress (gdbarch
, verify_addr
));
989 if (addr_hash
.insert (target_addr
).second
)
990 todo
.push_back (target_addr
);
995 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
996 ENTRY_VALUES_DEBUG. */
999 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
1001 CORE_ADDR addr
= call_site
->pc
;
1002 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
1004 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
1005 (msym
.minsym
== NULL
? "???"
1006 : msym
.minsym
->print_name ()));
1010 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1011 only top callers and bottom callees which are present in both. GDBARCH is
1012 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1013 no remaining possibilities to provide unambiguous non-trivial result.
1014 RESULTP should point to NULL on the first (initialization) call. Caller is
1015 responsible for xfree of any RESULTP data. */
1018 chain_candidate (struct gdbarch
*gdbarch
,
1019 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1020 std::vector
<struct call_site
*> *chain
)
1022 long length
= chain
->size ();
1023 int callers
, callees
, idx
;
1025 if (*resultp
== NULL
)
1027 /* Create the initial chain containing all the passed PCs. */
1029 struct call_site_chain
*result
1030 = ((struct call_site_chain
*)
1031 xmalloc (sizeof (*result
)
1032 + sizeof (*result
->call_site
) * (length
- 1)));
1033 result
->length
= length
;
1034 result
->callers
= result
->callees
= length
;
1035 if (!chain
->empty ())
1036 memcpy (result
->call_site
, chain
->data (),
1037 sizeof (*result
->call_site
) * length
);
1038 resultp
->reset (result
);
1040 if (entry_values_debug
)
1042 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1043 for (idx
= 0; idx
< length
; idx
++)
1044 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1045 fputc_unfiltered ('\n', gdb_stdlog
);
1051 if (entry_values_debug
)
1053 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1054 for (idx
= 0; idx
< length
; idx
++)
1055 tailcall_dump (gdbarch
, chain
->at (idx
));
1056 fputc_unfiltered ('\n', gdb_stdlog
);
1059 /* Intersect callers. */
1061 callers
= std::min ((long) (*resultp
)->callers
, length
);
1062 for (idx
= 0; idx
< callers
; idx
++)
1063 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1065 (*resultp
)->callers
= idx
;
1069 /* Intersect callees. */
1071 callees
= std::min ((long) (*resultp
)->callees
, length
);
1072 for (idx
= 0; idx
< callees
; idx
++)
1073 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1074 != chain
->at (length
- 1 - idx
))
1076 (*resultp
)->callees
= idx
;
1080 if (entry_values_debug
)
1082 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1083 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1084 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1085 fputs_unfiltered (" |", gdb_stdlog
);
1086 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1087 tailcall_dump (gdbarch
,
1088 (*resultp
)->call_site
[(*resultp
)->length
1089 - (*resultp
)->callees
+ idx
]);
1090 fputc_unfiltered ('\n', gdb_stdlog
);
1093 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1095 /* There are no common callers or callees. It could be also a direct
1096 call (which has length 0) with ambiguous possibility of an indirect
1097 call - CALLERS == CALLEES == 0 is valid during the first allocation
1098 but any subsequence processing of such entry means ambiguity. */
1099 resultp
->reset (NULL
);
1103 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1104 PC again. In such case there must be two different code paths to reach
1105 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1106 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1109 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1110 assumed frames between them use GDBARCH. Use depth first search so we can
1111 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1112 would have needless GDB stack overhead. Any unreliability results
1113 in thrown NO_ENTRY_VALUE_ERROR. */
1115 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1116 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1117 CORE_ADDR callee_pc
)
1119 CORE_ADDR save_callee_pc
= callee_pc
;
1120 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1121 struct call_site
*call_site
;
1123 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1124 call_site nor any possible call_site at CALLEE_PC's function is there.
1125 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1126 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1127 std::vector
<struct call_site
*> chain
;
1129 /* We are not interested in the specific PC inside the callee function. */
1130 callee_pc
= get_pc_function_start (callee_pc
);
1132 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1133 paddress (gdbarch
, save_callee_pc
));
1135 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1136 std::unordered_set
<CORE_ADDR
> addr_hash
;
1138 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1139 at the target's function. All the possible tail call sites in the
1140 target's function will get iterated as already pushed into CHAIN via their
1142 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1146 CORE_ADDR target_func_addr
;
1147 struct call_site
*target_call_site
;
1149 /* CALLER_FRAME with registers is not available for tail-call jumped
1151 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1153 if (target_func_addr
== callee_pc
)
1155 chain_candidate (gdbarch
, &retval
, &chain
);
1159 /* There is no way to reach CALLEE_PC again as we would prevent
1160 entering it twice as being already marked in ADDR_HASH. */
1161 target_call_site
= NULL
;
1165 struct symbol
*target_func
;
1167 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1168 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1173 /* Attempt to visit TARGET_CALL_SITE. */
1175 if (target_call_site
)
1177 if (addr_hash
.insert (target_call_site
->pc
).second
)
1179 /* Successfully entered TARGET_CALL_SITE. */
1181 chain
.push_back (target_call_site
);
1186 /* Backtrack (without revisiting the originating call_site). Try the
1187 callers's sibling; if there isn't any try the callers's callers's
1190 target_call_site
= NULL
;
1191 while (!chain
.empty ())
1193 call_site
= chain
.back ();
1196 size_t removed
= addr_hash
.erase (call_site
->pc
);
1197 gdb_assert (removed
== 1);
1199 target_call_site
= call_site
->tail_call_next
;
1200 if (target_call_site
)
1204 while (target_call_site
);
1209 call_site
= chain
.back ();
1214 struct bound_minimal_symbol msym_caller
, msym_callee
;
1216 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1217 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1218 throw_error (NO_ENTRY_VALUE_ERROR
,
1219 _("There are no unambiguously determinable intermediate "
1220 "callers or callees between caller function \"%s\" at %s "
1221 "and callee function \"%s\" at %s"),
1222 (msym_caller
.minsym
== NULL
1223 ? "???" : msym_caller
.minsym
->print_name ()),
1224 paddress (gdbarch
, caller_pc
),
1225 (msym_callee
.minsym
== NULL
1226 ? "???" : msym_callee
.minsym
->print_name ()),
1227 paddress (gdbarch
, callee_pc
));
1233 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1234 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1235 constructed return NULL. */
1237 gdb::unique_xmalloc_ptr
<call_site_chain
>
1238 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1239 CORE_ADDR callee_pc
)
1241 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1245 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1247 catch (const gdb_exception_error
&e
)
1249 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1251 if (entry_values_debug
)
1252 exception_print (gdb_stdout
, e
);
1263 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1266 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1267 enum call_site_parameter_kind kind
,
1268 union call_site_parameter_u kind_u
)
1270 if (kind
== parameter
->kind
)
1273 case CALL_SITE_PARAMETER_DWARF_REG
:
1274 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1275 case CALL_SITE_PARAMETER_FB_OFFSET
:
1276 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1277 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1278 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1283 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1284 FRAME is for callee.
1286 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1289 static struct call_site_parameter
*
1290 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1291 enum call_site_parameter_kind kind
,
1292 union call_site_parameter_u kind_u
,
1293 struct dwarf2_per_cu_data
**per_cu_return
)
1295 CORE_ADDR func_addr
, caller_pc
;
1296 struct gdbarch
*gdbarch
;
1297 struct frame_info
*caller_frame
;
1298 struct call_site
*call_site
;
1300 /* Initialize it just to avoid a GCC false warning. */
1301 struct call_site_parameter
*parameter
= NULL
;
1302 CORE_ADDR target_addr
;
1304 while (get_frame_type (frame
) == INLINE_FRAME
)
1306 frame
= get_prev_frame (frame
);
1307 gdb_assert (frame
!= NULL
);
1310 func_addr
= get_frame_func (frame
);
1311 gdbarch
= get_frame_arch (frame
);
1312 caller_frame
= get_prev_frame (frame
);
1313 if (gdbarch
!= frame_unwind_arch (frame
))
1315 struct bound_minimal_symbol msym
1316 = lookup_minimal_symbol_by_pc (func_addr
);
1317 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1319 throw_error (NO_ENTRY_VALUE_ERROR
,
1320 _("DW_OP_entry_value resolving callee gdbarch %s "
1321 "(of %s (%s)) does not match caller gdbarch %s"),
1322 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1323 paddress (gdbarch
, func_addr
),
1324 (msym
.minsym
== NULL
? "???"
1325 : msym
.minsym
->print_name ()),
1326 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1329 if (caller_frame
== NULL
)
1331 struct bound_minimal_symbol msym
1332 = lookup_minimal_symbol_by_pc (func_addr
);
1334 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1335 "requires caller of %s (%s)"),
1336 paddress (gdbarch
, func_addr
),
1337 (msym
.minsym
== NULL
? "???"
1338 : msym
.minsym
->print_name ()));
1340 caller_pc
= get_frame_pc (caller_frame
);
1341 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1343 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1344 if (target_addr
!= func_addr
)
1346 struct minimal_symbol
*target_msym
, *func_msym
;
1348 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1349 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1350 throw_error (NO_ENTRY_VALUE_ERROR
,
1351 _("DW_OP_entry_value resolving expects callee %s at %s "
1352 "but the called frame is for %s at %s"),
1353 (target_msym
== NULL
? "???"
1354 : target_msym
->print_name ()),
1355 paddress (gdbarch
, target_addr
),
1356 func_msym
== NULL
? "???" : func_msym
->print_name (),
1357 paddress (gdbarch
, func_addr
));
1360 /* No entry value based parameters would be reliable if this function can
1361 call itself via tail calls. */
1362 func_verify_no_selftailcall (gdbarch
, func_addr
);
1364 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1366 parameter
= &call_site
->parameter
[iparams
];
1367 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1370 if (iparams
== call_site
->parameter_count
)
1372 struct minimal_symbol
*msym
1373 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1375 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1376 determine its value. */
1377 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1378 "at DW_TAG_call_site %s at %s"),
1379 paddress (gdbarch
, caller_pc
),
1380 msym
== NULL
? "???" : msym
->print_name ());
1383 *per_cu_return
= call_site
->per_cu
;
1387 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1388 the normal DW_AT_call_value block. Otherwise return the
1389 DW_AT_call_data_value (dereferenced) block.
1391 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1394 Function always returns non-NULL, non-optimized out value. It throws
1395 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1397 static struct value
*
1398 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1399 CORE_ADDR deref_size
, struct type
*type
,
1400 struct frame_info
*caller_frame
,
1401 struct dwarf2_per_cu_data
*per_cu
)
1403 const gdb_byte
*data_src
;
1407 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1408 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1410 /* DEREF_SIZE size is not verified here. */
1411 if (data_src
== NULL
)
1412 throw_error (NO_ENTRY_VALUE_ERROR
,
1413 _("Cannot resolve DW_AT_call_data_value"));
1415 /* DW_AT_call_value is a DWARF expression, not a DWARF
1416 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1418 data
= (gdb_byte
*) alloca (size
+ 1);
1419 memcpy (data
, data_src
, size
);
1420 data
[size
] = DW_OP_stack_value
;
1422 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1425 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1426 the indirect method on it, that is use its stored target value, the sole
1427 purpose of entry_data_value_funcs.. */
1429 static struct value
*
1430 entry_data_value_coerce_ref (const struct value
*value
)
1432 struct type
*checked_type
= check_typedef (value_type (value
));
1433 struct value
*target_val
;
1435 if (!TYPE_IS_REFERENCE (checked_type
))
1438 target_val
= (struct value
*) value_computed_closure (value
);
1439 value_incref (target_val
);
1443 /* Implement copy_closure. */
1446 entry_data_value_copy_closure (const struct value
*v
)
1448 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1450 value_incref (target_val
);
1454 /* Implement free_closure. */
1457 entry_data_value_free_closure (struct value
*v
)
1459 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1461 value_decref (target_val
);
1464 /* Vector for methods for an entry value reference where the referenced value
1465 is stored in the caller. On the first dereference use
1466 DW_AT_call_data_value in the caller. */
1468 static const struct lval_funcs entry_data_value_funcs
=
1472 NULL
, /* indirect */
1473 entry_data_value_coerce_ref
,
1474 NULL
, /* check_synthetic_pointer */
1475 entry_data_value_copy_closure
,
1476 entry_data_value_free_closure
1479 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1480 are used to match DW_AT_location at the caller's
1481 DW_TAG_call_site_parameter.
1483 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1484 cannot resolve the parameter for any reason. */
1486 static struct value
*
1487 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1488 enum call_site_parameter_kind kind
,
1489 union call_site_parameter_u kind_u
)
1491 struct type
*checked_type
= check_typedef (type
);
1492 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1493 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1494 struct value
*outer_val
, *target_val
, *val
;
1495 struct call_site_parameter
*parameter
;
1496 struct dwarf2_per_cu_data
*caller_per_cu
;
1498 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1501 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1505 /* Check if DW_AT_call_data_value cannot be used. If it should be
1506 used and it is not available do not fall back to OUTER_VAL - dereferencing
1507 TYPE_CODE_REF with non-entry data value would give current value - not the
1510 if (!TYPE_IS_REFERENCE (checked_type
)
1511 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1514 target_val
= dwarf_entry_parameter_to_value (parameter
,
1515 TYPE_LENGTH (target_type
),
1516 target_type
, caller_frame
,
1519 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1520 release_value (target_val
).release ());
1522 /* Copy the referencing pointer to the new computed value. */
1523 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1524 TYPE_LENGTH (checked_type
));
1525 set_value_lazy (val
, 0);
1530 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1531 SIZE are DWARF block used to match DW_AT_location at the caller's
1532 DW_TAG_call_site_parameter.
1534 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1535 cannot resolve the parameter for any reason. */
1537 static struct value
*
1538 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1539 const gdb_byte
*block
, size_t block_len
)
1541 union call_site_parameter_u kind_u
;
1543 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1544 if (kind_u
.dwarf_reg
!= -1)
1545 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1548 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1549 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1552 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1553 suppressed during normal operation. The expression can be arbitrary if
1554 there is no caller-callee entry value binding expected. */
1555 throw_error (NO_ENTRY_VALUE_ERROR
,
1556 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1557 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1560 struct piece_closure
1562 /* Reference count. */
1565 /* The objfile from which this closure's expression came. */
1566 dwarf2_per_objfile
*per_objfile
= nullptr;
1568 /* The CU from which this closure's expression came. */
1569 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1571 /* The pieces describing this variable. */
1572 std::vector
<dwarf_expr_piece
> pieces
;
1574 /* Frame ID of frame to which a register value is relative, used
1575 only by DWARF_VALUE_REGISTER. */
1576 struct frame_id frame_id
;
1579 /* Allocate a closure for a value formed from separately-described
1582 static struct piece_closure
*
1583 allocate_piece_closure (dwarf2_per_cu_data
*per_cu
,
1584 dwarf2_per_objfile
*per_objfile
,
1585 std::vector
<dwarf_expr_piece
> &&pieces
,
1586 struct frame_info
*frame
)
1588 struct piece_closure
*c
= new piece_closure
;
1591 /* We must capture this here due to sharing of DWARF state. */
1592 c
->per_objfile
= per_objfile
;
1594 c
->pieces
= std::move (pieces
);
1596 c
->frame_id
= null_frame_id
;
1598 c
->frame_id
= get_frame_id (frame
);
1600 for (dwarf_expr_piece
&piece
: c
->pieces
)
1601 if (piece
.location
== DWARF_VALUE_STACK
)
1602 value_incref (piece
.v
.value
);
1607 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1608 bits whose first bit is located at bit offset START. */
1611 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1613 return (start
% 8 + n_bits
+ 7) / 8;
1616 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1617 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1618 operate in "read mode": fetch the contents of the (lazy) value V by
1619 composing it from its pieces. */
1622 rw_pieced_value (struct value
*v
, struct value
*from
)
1625 LONGEST offset
= 0, max_offset
;
1626 ULONGEST bits_to_skip
;
1627 gdb_byte
*v_contents
;
1628 const gdb_byte
*from_contents
;
1629 struct piece_closure
*c
1630 = (struct piece_closure
*) value_computed_closure (v
);
1631 gdb::byte_vector buffer
;
1632 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1636 from_contents
= value_contents (from
);
1641 if (value_type (v
) != value_enclosing_type (v
))
1642 internal_error (__FILE__
, __LINE__
,
1643 _("Should not be able to create a lazy value with "
1644 "an enclosing type"));
1645 v_contents
= value_contents_raw (v
);
1646 from_contents
= NULL
;
1649 bits_to_skip
= 8 * value_offset (v
);
1650 if (value_bitsize (v
))
1652 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1653 + value_bitpos (v
));
1655 && (type_byte_order (value_type (from
))
1658 /* Use the least significant bits of FROM. */
1659 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1660 offset
= max_offset
- value_bitsize (v
);
1663 max_offset
= value_bitsize (v
);
1666 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1668 /* Advance to the first non-skipped piece. */
1669 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1670 bits_to_skip
-= c
->pieces
[i
].size
;
1672 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1674 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1675 size_t this_size_bits
, this_size
;
1677 this_size_bits
= p
->size
- bits_to_skip
;
1678 if (this_size_bits
> max_offset
- offset
)
1679 this_size_bits
= max_offset
- offset
;
1681 switch (p
->location
)
1683 case DWARF_VALUE_REGISTER
:
1685 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1686 struct gdbarch
*arch
= get_frame_arch (frame
);
1687 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1688 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1691 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1692 && p
->offset
+ p
->size
< reg_bits
)
1694 /* Big-endian, and we want less than full size. */
1695 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1698 bits_to_skip
+= p
->offset
;
1700 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1701 buffer
.resize (this_size
);
1706 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1708 this_size
, buffer
.data (),
1712 mark_value_bits_optimized_out (v
, offset
,
1715 mark_value_bits_unavailable (v
, offset
,
1720 copy_bitwise (v_contents
, offset
,
1721 buffer
.data (), bits_to_skip
% 8,
1722 this_size_bits
, bits_big_endian
);
1727 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1729 /* Data is copied non-byte-aligned into the register.
1730 Need some bits from original register value. */
1731 get_frame_register_bytes (frame
, gdb_regnum
,
1733 this_size
, buffer
.data (),
1736 throw_error (OPTIMIZED_OUT_ERROR
,
1737 _("Can't do read-modify-write to "
1738 "update bitfield; containing word "
1739 "has been optimized out"));
1741 throw_error (NOT_AVAILABLE_ERROR
,
1742 _("Can't do read-modify-write to "
1743 "update bitfield; containing word "
1747 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1748 from_contents
, offset
,
1749 this_size_bits
, bits_big_endian
);
1750 put_frame_register_bytes (frame
, gdb_regnum
,
1752 this_size
, buffer
.data ());
1757 case DWARF_VALUE_MEMORY
:
1759 bits_to_skip
+= p
->offset
;
1761 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1763 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1766 /* Everything is byte-aligned; no buffer needed. */
1768 write_memory_with_notification (start_addr
,
1771 this_size_bits
/ 8);
1773 read_value_memory (v
, offset
,
1774 p
->v
.mem
.in_stack_memory
,
1775 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1776 v_contents
+ offset
/ 8,
1777 this_size_bits
/ 8);
1781 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1782 buffer
.resize (this_size
);
1787 read_value_memory (v
, offset
,
1788 p
->v
.mem
.in_stack_memory
,
1789 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1790 buffer
.data (), this_size
);
1791 copy_bitwise (v_contents
, offset
,
1792 buffer
.data (), bits_to_skip
% 8,
1793 this_size_bits
, bits_big_endian
);
1798 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1802 /* Perform a single read for small sizes. */
1803 read_memory (start_addr
, buffer
.data (),
1808 /* Only the first and last bytes can possibly have
1810 read_memory (start_addr
, buffer
.data (), 1);
1811 read_memory (start_addr
+ this_size
- 1,
1812 &buffer
[this_size
- 1], 1);
1816 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1817 from_contents
, offset
,
1818 this_size_bits
, bits_big_endian
);
1819 write_memory_with_notification (start_addr
,
1826 case DWARF_VALUE_STACK
:
1830 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1834 struct objfile
*objfile
= c
->per_cu
->objfile ();
1835 struct gdbarch
*objfile_gdbarch
= objfile
->arch ();
1836 ULONGEST stack_value_size_bits
1837 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1839 /* Use zeroes if piece reaches beyond stack value. */
1840 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1843 /* Piece is anchored at least significant bit end. */
1844 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1845 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1847 bits_to_skip
+= p
->offset
;
1849 copy_bitwise (v_contents
, offset
,
1850 value_contents_all (p
->v
.value
),
1852 this_size_bits
, bits_big_endian
);
1856 case DWARF_VALUE_LITERAL
:
1860 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1864 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1865 size_t n
= this_size_bits
;
1867 /* Cut off at the end of the implicit value. */
1868 bits_to_skip
+= p
->offset
;
1869 if (bits_to_skip
>= literal_size_bits
)
1871 if (n
> literal_size_bits
- bits_to_skip
)
1872 n
= literal_size_bits
- bits_to_skip
;
1874 copy_bitwise (v_contents
, offset
,
1875 p
->v
.literal
.data
, bits_to_skip
,
1876 n
, bits_big_endian
);
1880 case DWARF_VALUE_IMPLICIT_POINTER
:
1883 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1887 /* These bits show up as zeros -- but do not cause the value to
1888 be considered optimized-out. */
1891 case DWARF_VALUE_OPTIMIZED_OUT
:
1892 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1896 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1899 offset
+= this_size_bits
;
1906 read_pieced_value (struct value
*v
)
1908 rw_pieced_value (v
, NULL
);
1912 write_pieced_value (struct value
*to
, struct value
*from
)
1914 rw_pieced_value (to
, from
);
1917 /* An implementation of an lval_funcs method to see whether a value is
1918 a synthetic pointer. */
1921 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1924 struct piece_closure
*c
1925 = (struct piece_closure
*) value_computed_closure (value
);
1928 bit_offset
+= 8 * value_offset (value
);
1929 if (value_bitsize (value
))
1930 bit_offset
+= value_bitpos (value
);
1932 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1934 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1935 size_t this_size_bits
= p
->size
;
1939 if (bit_offset
>= this_size_bits
)
1941 bit_offset
-= this_size_bits
;
1945 bit_length
-= this_size_bits
- bit_offset
;
1949 bit_length
-= this_size_bits
;
1951 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1958 /* A wrapper function for get_frame_address_in_block. */
1961 get_frame_address_in_block_wrapper (void *baton
)
1963 return get_frame_address_in_block ((struct frame_info
*) baton
);
1966 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1968 static struct value
*
1969 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1970 dwarf2_per_cu_data
*per_cu
,
1971 dwarf2_per_objfile
*per_objfile
,
1974 struct value
*result
= NULL
;
1975 const gdb_byte
*bytes
;
1978 auto_obstack temp_obstack
;
1979 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1980 &temp_obstack
, &len
);
1984 if (byte_offset
>= 0
1985 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1987 bytes
+= byte_offset
;
1988 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1991 invalid_synthetic_pointer ();
1994 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1999 /* Fetch the value pointed to by a synthetic pointer. */
2001 static struct value
*
2002 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2003 dwarf2_per_cu_data
*per_cu
,
2004 dwarf2_per_objfile
*per_objfile
,
2005 struct frame_info
*frame
, struct type
*type
,
2006 bool resolve_abstract_p
)
2008 /* Fetch the location expression of the DIE we're pointing to. */
2009 struct dwarf2_locexpr_baton baton
2010 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
2011 get_frame_address_in_block_wrapper
, frame
,
2012 resolve_abstract_p
);
2014 /* Get type of pointed-to DIE. */
2015 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
2017 if (orig_type
== NULL
)
2018 invalid_synthetic_pointer ();
2020 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2021 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2022 or it may've been optimized out. */
2023 if (baton
.data
!= NULL
)
2024 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2025 baton
.size
, baton
.per_cu
,
2026 TYPE_TARGET_TYPE (type
),
2029 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2033 /* An implementation of an lval_funcs method to indirect through a
2034 pointer. This handles the synthetic pointer case when needed. */
2036 static struct value
*
2037 indirect_pieced_value (struct value
*value
)
2039 struct piece_closure
*c
2040 = (struct piece_closure
*) value_computed_closure (value
);
2042 struct frame_info
*frame
;
2045 struct dwarf_expr_piece
*piece
= NULL
;
2046 LONGEST byte_offset
;
2047 enum bfd_endian byte_order
;
2049 type
= check_typedef (value_type (value
));
2050 if (type
->code () != TYPE_CODE_PTR
)
2053 bit_length
= 8 * TYPE_LENGTH (type
);
2054 bit_offset
= 8 * value_offset (value
);
2055 if (value_bitsize (value
))
2056 bit_offset
+= value_bitpos (value
);
2058 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2060 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2061 size_t this_size_bits
= p
->size
;
2065 if (bit_offset
>= this_size_bits
)
2067 bit_offset
-= this_size_bits
;
2071 bit_length
-= this_size_bits
- bit_offset
;
2075 bit_length
-= this_size_bits
;
2077 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2080 if (bit_length
!= 0)
2081 error (_("Invalid use of DW_OP_implicit_pointer"));
2087 gdb_assert (piece
!= NULL
);
2088 frame
= get_selected_frame (_("No frame selected."));
2090 /* This is an offset requested by GDB, such as value subscripts.
2091 However, due to how synthetic pointers are implemented, this is
2092 always presented to us as a pointer type. This means we have to
2093 sign-extend it manually as appropriate. Use raw
2094 extract_signed_integer directly rather than value_as_address and
2095 sign extend afterwards on architectures that would need it
2096 (mostly everywhere except MIPS, which has signed addresses) as
2097 the later would go through gdbarch_pointer_to_address and thus
2098 return a CORE_ADDR with high bits set on architectures that
2099 encode address spaces and other things in CORE_ADDR. */
2100 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2101 byte_offset
= extract_signed_integer (value_contents (value
),
2102 TYPE_LENGTH (type
), byte_order
);
2103 byte_offset
+= piece
->v
.ptr
.offset
;
2105 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2106 byte_offset
, c
->per_cu
,
2107 c
->per_objfile
, frame
, type
);
2110 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2113 static struct value
*
2114 coerce_pieced_ref (const struct value
*value
)
2116 struct type
*type
= check_typedef (value_type (value
));
2118 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2119 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2121 const struct piece_closure
*closure
2122 = (struct piece_closure
*) value_computed_closure (value
);
2123 struct frame_info
*frame
2124 = get_selected_frame (_("No frame selected."));
2126 /* gdb represents synthetic pointers as pieced values with a single
2128 gdb_assert (closure
!= NULL
);
2129 gdb_assert (closure
->pieces
.size () == 1);
2131 return indirect_synthetic_pointer
2132 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2133 closure
->pieces
[0].v
.ptr
.offset
,
2134 closure
->per_cu
, closure
->per_objfile
, frame
, type
);
2138 /* Else: not a synthetic reference; do nothing. */
2144 copy_pieced_value_closure (const struct value
*v
)
2146 struct piece_closure
*c
2147 = (struct piece_closure
*) value_computed_closure (v
);
2154 free_pieced_value_closure (struct value
*v
)
2156 struct piece_closure
*c
2157 = (struct piece_closure
*) value_computed_closure (v
);
2162 for (dwarf_expr_piece
&p
: c
->pieces
)
2163 if (p
.location
== DWARF_VALUE_STACK
)
2164 value_decref (p
.v
.value
);
2170 /* Functions for accessing a variable described by DW_OP_piece. */
2171 static const struct lval_funcs pieced_value_funcs
= {
2174 indirect_pieced_value
,
2176 check_pieced_synthetic_pointer
,
2177 copy_pieced_value_closure
,
2178 free_pieced_value_closure
2181 /* Evaluate a location description, starting at DATA and with length
2182 SIZE, to find the current location of variable of TYPE in the
2183 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2184 location of the subobject of type SUBOBJ_TYPE at byte offset
2185 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2187 static struct value
*
2188 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2189 const gdb_byte
*data
, size_t size
,
2190 struct dwarf2_per_cu_data
*per_cu
,
2191 struct type
*subobj_type
,
2192 LONGEST subobj_byte_offset
)
2194 struct value
*retval
;
2195 struct objfile
*objfile
= per_cu
->objfile ();
2197 if (subobj_type
== NULL
)
2200 subobj_byte_offset
= 0;
2202 else if (subobj_byte_offset
< 0)
2203 invalid_synthetic_pointer ();
2206 return allocate_optimized_out_value (subobj_type
);
2208 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2209 dwarf_evaluate_loc_desc
ctx (per_objfile
);
2211 ctx
.per_cu
= per_cu
;
2212 ctx
.obj_address
= 0;
2214 scoped_value_mark free_values
;
2216 ctx
.gdbarch
= objfile
->arch ();
2217 ctx
.addr_size
= per_cu
->addr_size ();
2218 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2222 ctx
.eval (data
, size
);
2224 catch (const gdb_exception_error
&ex
)
2226 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2228 free_values
.free_to_mark ();
2229 retval
= allocate_value (subobj_type
);
2230 mark_value_bytes_unavailable (retval
, 0,
2231 TYPE_LENGTH (subobj_type
));
2234 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2236 if (entry_values_debug
)
2237 exception_print (gdb_stdout
, ex
);
2238 free_values
.free_to_mark ();
2239 return allocate_optimized_out_value (subobj_type
);
2245 if (ctx
.pieces
.size () > 0)
2247 struct piece_closure
*c
;
2248 ULONGEST bit_size
= 0;
2250 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2251 bit_size
+= piece
.size
;
2252 /* Complain if the expression is larger than the size of the
2254 if (bit_size
> 8 * TYPE_LENGTH (type
))
2255 invalid_synthetic_pointer ();
2257 c
= allocate_piece_closure (per_cu
, per_objfile
, std::move (ctx
.pieces
),
2259 /* We must clean up the value chain after creating the piece
2260 closure but before allocating the result. */
2261 free_values
.free_to_mark ();
2262 retval
= allocate_computed_value (subobj_type
,
2263 &pieced_value_funcs
, c
);
2264 set_value_offset (retval
, subobj_byte_offset
);
2268 switch (ctx
.location
)
2270 case DWARF_VALUE_REGISTER
:
2272 struct gdbarch
*arch
= get_frame_arch (frame
);
2274 = longest_to_int (value_as_long (ctx
.fetch (0)));
2275 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2277 if (subobj_byte_offset
!= 0)
2278 error (_("cannot use offset on synthetic pointer to register"));
2279 free_values
.free_to_mark ();
2280 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2281 if (value_optimized_out (retval
))
2285 /* This means the register has undefined value / was
2286 not saved. As we're computing the location of some
2287 variable etc. in the program, not a value for
2288 inspecting a register ($pc, $sp, etc.), return a
2289 generic optimized out value instead, so that we show
2290 <optimized out> instead of <not saved>. */
2291 tmp
= allocate_value (subobj_type
);
2292 value_contents_copy (tmp
, 0, retval
, 0,
2293 TYPE_LENGTH (subobj_type
));
2299 case DWARF_VALUE_MEMORY
:
2301 struct type
*ptr_type
;
2302 CORE_ADDR address
= ctx
.fetch_address (0);
2303 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2305 /* DW_OP_deref_size (and possibly other operations too) may
2306 create a pointer instead of an address. Ideally, the
2307 pointer to address conversion would be performed as part
2308 of those operations, but the type of the object to
2309 which the address refers is not known at the time of
2310 the operation. Therefore, we do the conversion here
2311 since the type is readily available. */
2313 switch (subobj_type
->code ())
2315 case TYPE_CODE_FUNC
:
2316 case TYPE_CODE_METHOD
:
2317 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2320 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2323 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2325 free_values
.free_to_mark ();
2326 retval
= value_at_lazy (subobj_type
,
2327 address
+ subobj_byte_offset
);
2328 if (in_stack_memory
)
2329 set_value_stack (retval
, 1);
2333 case DWARF_VALUE_STACK
:
2335 struct value
*value
= ctx
.fetch (0);
2336 size_t n
= TYPE_LENGTH (value_type (value
));
2337 size_t len
= TYPE_LENGTH (subobj_type
);
2338 size_t max
= TYPE_LENGTH (type
);
2339 struct gdbarch
*objfile_gdbarch
= objfile
->arch ();
2341 if (subobj_byte_offset
+ len
> max
)
2342 invalid_synthetic_pointer ();
2344 /* Preserve VALUE because we are going to free values back
2345 to the mark, but we still need the value contents
2347 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2348 free_values
.free_to_mark ();
2350 retval
= allocate_value (subobj_type
);
2352 /* The given offset is relative to the actual object. */
2353 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2354 subobj_byte_offset
+= n
- max
;
2356 memcpy (value_contents_raw (retval
),
2357 value_contents_all (value
) + subobj_byte_offset
, len
);
2361 case DWARF_VALUE_LITERAL
:
2364 size_t n
= TYPE_LENGTH (subobj_type
);
2366 if (subobj_byte_offset
+ n
> ctx
.len
)
2367 invalid_synthetic_pointer ();
2369 free_values
.free_to_mark ();
2370 retval
= allocate_value (subobj_type
);
2371 contents
= value_contents_raw (retval
);
2372 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2376 case DWARF_VALUE_OPTIMIZED_OUT
:
2377 free_values
.free_to_mark ();
2378 retval
= allocate_optimized_out_value (subobj_type
);
2381 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2382 operation by execute_stack_op. */
2383 case DWARF_VALUE_IMPLICIT_POINTER
:
2384 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2385 it can only be encountered when making a piece. */
2387 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2391 set_value_initialized (retval
, ctx
.initialized
);
2396 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2397 passes 0 as the byte_offset. */
2400 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2401 const gdb_byte
*data
, size_t size
,
2402 struct dwarf2_per_cu_data
*per_cu
)
2404 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2408 /* A specialization of dwarf_evaluate_loc_desc that is used by
2409 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2410 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2411 but with the address being 0. In this situation, we arrange for
2412 memory reads to come from the passed-in buffer. */
2414 struct evaluate_for_locexpr_baton
: public dwarf_evaluate_loc_desc
2416 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2417 : dwarf_evaluate_loc_desc (per_objfile
)
2420 /* The data that was passed in. */
2421 gdb::array_view
<const gdb_byte
> data_view
;
2423 CORE_ADDR
get_object_address () override
2425 if (data_view
.data () == nullptr && obj_address
== 0)
2426 error (_("Location address is not set."));
2430 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2435 /* Prefer the passed-in memory, if it exists. */
2436 CORE_ADDR offset
= addr
- obj_address
;
2437 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2439 memcpy (buf
, data_view
.data (), len
);
2443 read_memory (addr
, buf
, len
);
2447 /* Evaluates a dwarf expression and stores the result in VAL,
2448 expecting that the dwarf expression only produces a single
2449 CORE_ADDR. FRAME is the frame in which the expression is
2450 evaluated. ADDR_STACK is a context (location of a variable) and
2451 might be needed to evaluate the location expression.
2452 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2453 or the default of 0) should be pushed on the DWARF expression
2454 evaluation stack before evaluating the expression; this is required
2455 by certain forms of DWARF expression. Returns 1 on success, 0
2459 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2460 struct frame_info
*frame
,
2461 const struct property_addr_info
*addr_stack
,
2463 bool push_initial_value
)
2465 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2468 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2469 evaluate_for_locexpr_baton
ctx (per_objfile
);
2472 ctx
.per_cu
= dlbaton
->per_cu
;
2473 if (addr_stack
== nullptr)
2474 ctx
.obj_address
= 0;
2477 ctx
.obj_address
= addr_stack
->addr
;
2478 ctx
.data_view
= addr_stack
->valaddr
;
2481 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2482 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2483 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2485 if (push_initial_value
)
2486 ctx
.push_address (ctx
.obj_address
, false);
2490 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2492 catch (const gdb_exception_error
&ex
)
2494 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2498 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2500 if (entry_values_debug
)
2501 exception_print (gdb_stdout
, ex
);
2508 switch (ctx
.location
)
2510 case DWARF_VALUE_REGISTER
:
2511 case DWARF_VALUE_MEMORY
:
2512 case DWARF_VALUE_STACK
:
2513 *valp
= ctx
.fetch_address (0);
2514 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2515 *valp
= ctx
.read_addr_from_reg (*valp
);
2517 case DWARF_VALUE_LITERAL
:
2518 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2519 gdbarch_byte_order (ctx
.gdbarch
));
2521 /* Unsupported dwarf values. */
2522 case DWARF_VALUE_OPTIMIZED_OUT
:
2523 case DWARF_VALUE_IMPLICIT_POINTER
:
2530 /* See dwarf2loc.h. */
2533 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2534 struct frame_info
*frame
,
2535 const struct property_addr_info
*addr_stack
,
2537 bool push_initial_value
)
2542 if (frame
== NULL
&& has_stack_frames ())
2543 frame
= get_selected_frame (NULL
);
2549 const struct dwarf2_property_baton
*baton
2550 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2551 gdb_assert (baton
->property_type
!= NULL
);
2553 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2554 value
, push_initial_value
))
2556 if (baton
->locexpr
.is_reference
)
2558 struct value
*val
= value_at (baton
->property_type
, *value
);
2559 *value
= value_as_address (val
);
2563 gdb_assert (baton
->property_type
!= NULL
);
2565 struct type
*type
= check_typedef (baton
->property_type
);
2566 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2567 && !TYPE_UNSIGNED (type
))
2569 /* If we have a valid return candidate and it's value
2570 is signed, we have to sign-extend the value because
2571 CORE_ADDR on 64bit machine has 8 bytes but address
2572 size of an 32bit application is bytes. */
2574 = (baton
->locexpr
.per_cu
->addr_size ()
2576 const CORE_ADDR neg_mask
2577 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2579 /* Check if signed bit is set and sign-extend values. */
2580 if (*value
& neg_mask
)
2591 struct dwarf2_property_baton
*baton
2592 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2594 const gdb_byte
*data
;
2599 || !get_frame_address_in_block_if_available (frame
, &pc
))
2602 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2605 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2606 size
, baton
->loclist
.per_cu
);
2607 if (!value_optimized_out (val
))
2609 *value
= value_as_address (val
);
2617 *value
= prop
->data
.const_val
;
2620 case PROP_ADDR_OFFSET
:
2622 struct dwarf2_property_baton
*baton
2623 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2624 const struct property_addr_info
*pinfo
;
2627 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2629 /* This approach lets us avoid checking the qualifiers. */
2630 if (TYPE_MAIN_TYPE (pinfo
->type
)
2631 == TYPE_MAIN_TYPE (baton
->property_type
))
2635 error (_("cannot find reference address for offset property"));
2636 if (pinfo
->valaddr
.data () != NULL
)
2637 val
= value_from_contents
2638 (baton
->offset_info
.type
,
2639 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2641 val
= value_at (baton
->offset_info
.type
,
2642 pinfo
->addr
+ baton
->offset_info
.offset
);
2643 *value
= value_as_address (val
);
2651 /* See dwarf2loc.h. */
2654 dwarf2_compile_property_to_c (string_file
*stream
,
2655 const char *result_name
,
2656 struct gdbarch
*gdbarch
,
2657 unsigned char *registers_used
,
2658 const struct dynamic_prop
*prop
,
2662 struct dwarf2_property_baton
*baton
2663 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2664 const gdb_byte
*data
;
2666 dwarf2_per_cu_data
*per_cu
;
2667 dwarf2_per_objfile
*per_objfile
;
2669 if (prop
->kind
== PROP_LOCEXPR
)
2671 data
= baton
->locexpr
.data
;
2672 size
= baton
->locexpr
.size
;
2673 per_cu
= baton
->locexpr
.per_cu
;
2674 per_objfile
= baton
->locexpr
.per_objfile
;
2678 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2680 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2681 per_cu
= baton
->loclist
.per_cu
;
2682 per_objfile
= baton
->loclist
.per_objfile
;
2685 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2686 gdbarch
, registers_used
,
2687 per_cu
->addr_size (),
2688 data
, data
+ size
, per_cu
, per_objfile
);
2692 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2694 class symbol_needs_eval_context
: public dwarf_expr_context
2697 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2698 : dwarf_expr_context (per_objfile
)
2701 enum symbol_needs_kind needs
;
2702 struct dwarf2_per_cu_data
*per_cu
;
2704 /* Reads from registers do require a frame. */
2705 CORE_ADDR
read_addr_from_reg (int regnum
) override
2707 needs
= SYMBOL_NEEDS_FRAME
;
2711 /* "get_reg_value" callback: Reads from registers do require a
2714 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2716 needs
= SYMBOL_NEEDS_FRAME
;
2717 return value_zero (type
, not_lval
);
2720 /* Reads from memory do not require a frame. */
2721 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2723 memset (buf
, 0, len
);
2726 /* Frame-relative accesses do require a frame. */
2727 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2729 static gdb_byte lit0
= DW_OP_lit0
;
2734 needs
= SYMBOL_NEEDS_FRAME
;
2737 /* CFA accesses require a frame. */
2738 CORE_ADDR
get_frame_cfa () override
2740 needs
= SYMBOL_NEEDS_FRAME
;
2744 CORE_ADDR
get_frame_pc () override
2746 needs
= SYMBOL_NEEDS_FRAME
;
2750 /* Thread-local accesses require registers, but not a frame. */
2751 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2753 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2754 needs
= SYMBOL_NEEDS_REGISTERS
;
2758 /* Helper interface of per_cu_dwarf_call for
2759 dwarf2_loc_desc_get_symbol_read_needs. */
2761 void dwarf_call (cu_offset die_offset
) override
2763 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
2766 /* Helper interface of sect_variable_value for
2767 dwarf2_loc_desc_get_symbol_read_needs. */
2769 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2771 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
2774 /* DW_OP_entry_value accesses require a caller, therefore a
2777 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2778 union call_site_parameter_u kind_u
,
2779 int deref_size
) override
2781 needs
= SYMBOL_NEEDS_FRAME
;
2783 /* The expression may require some stub values on DWARF stack. */
2784 push_address (0, 0);
2787 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2789 CORE_ADDR
get_addr_index (unsigned int index
) override
2791 /* Nothing to do. */
2795 /* DW_OP_push_object_address has a frame already passed through. */
2797 CORE_ADDR
get_object_address () override
2799 /* Nothing to do. */
2804 /* Compute the correct symbol_needs_kind value for the location
2805 expression at DATA (length SIZE). */
2807 static enum symbol_needs_kind
2808 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2809 struct dwarf2_per_cu_data
*per_cu
)
2812 struct objfile
*objfile
= per_cu
->objfile ();
2814 scoped_value_mark free_values
;
2816 symbol_needs_eval_context
ctx (get_dwarf2_per_objfile (objfile
));
2818 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2819 ctx
.per_cu
= per_cu
;
2820 ctx
.gdbarch
= objfile
->arch ();
2821 ctx
.addr_size
= per_cu
->addr_size ();
2822 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2824 ctx
.eval (data
, size
);
2826 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2828 /* If the location has several pieces, and any of them are in
2829 registers, then we will need a frame to fetch them from. */
2830 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2831 if (p
.location
== DWARF_VALUE_REGISTER
)
2835 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2839 /* A helper function that throws an unimplemented error mentioning a
2840 given DWARF operator. */
2842 static void ATTRIBUTE_NORETURN
2843 unimplemented (unsigned int op
)
2845 const char *name
= get_DW_OP_name (op
);
2848 error (_("DWARF operator %s cannot be translated to an agent expression"),
2851 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2852 "to an agent expression"),
2858 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2859 can issue a complaint, which is better than having every target's
2860 implementation of dwarf2_reg_to_regnum do it. */
2863 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2865 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2869 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2874 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2875 Throw an error because DWARF_REG is bad. */
2878 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2880 /* Still want to print -1 as "-1".
2881 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2882 but that's overkill for now. */
2883 if ((int) dwarf_reg
== dwarf_reg
)
2884 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2885 error (_("Unable to access DWARF register number %s"),
2886 pulongest (dwarf_reg
));
2889 /* See dwarf2loc.h. */
2892 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2896 if (dwarf_reg
> INT_MAX
)
2897 throw_bad_regnum_error (dwarf_reg
);
2898 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2899 bad, but that's ok. */
2900 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2902 throw_bad_regnum_error (dwarf_reg
);
2906 /* A helper function that emits an access to memory. ARCH is the
2907 target architecture. EXPR is the expression which we are building.
2908 NBITS is the number of bits we want to read. This emits the
2909 opcodes needed to read the memory and then extract the desired
2913 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2915 ULONGEST nbytes
= (nbits
+ 7) / 8;
2917 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2920 ax_trace_quick (expr
, nbytes
);
2923 ax_simple (expr
, aop_ref8
);
2924 else if (nbits
<= 16)
2925 ax_simple (expr
, aop_ref16
);
2926 else if (nbits
<= 32)
2927 ax_simple (expr
, aop_ref32
);
2929 ax_simple (expr
, aop_ref64
);
2931 /* If we read exactly the number of bytes we wanted, we're done. */
2932 if (8 * nbytes
== nbits
)
2935 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2937 /* On a bits-big-endian machine, we want the high-order
2939 ax_const_l (expr
, 8 * nbytes
- nbits
);
2940 ax_simple (expr
, aop_rsh_unsigned
);
2944 /* On a bits-little-endian box, we want the low-order NBITS. */
2945 ax_zero_ext (expr
, nbits
);
2949 /* A helper function to return the frame's PC. */
2952 get_ax_pc (void *baton
)
2954 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
2959 /* Compile a DWARF location expression to an agent expression.
2961 EXPR is the agent expression we are building.
2962 LOC is the agent value we modify.
2963 ARCH is the architecture.
2964 ADDR_SIZE is the size of addresses, in bytes.
2965 OP_PTR is the start of the location expression.
2966 OP_END is one past the last byte of the location expression.
2968 This will throw an exception for various kinds of errors -- for
2969 example, if the expression cannot be compiled, or if the expression
2973 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2974 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2975 const gdb_byte
*op_end
,
2976 dwarf2_per_cu_data
*per_cu
,
2977 dwarf2_per_objfile
*per_objfile
)
2979 gdbarch
*arch
= expr
->gdbarch
;
2980 std::vector
<int> dw_labels
, patches
;
2981 const gdb_byte
* const base
= op_ptr
;
2982 const gdb_byte
*previous_piece
= op_ptr
;
2983 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2984 ULONGEST bits_collected
= 0;
2985 unsigned int addr_size_bits
= 8 * addr_size
;
2986 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2988 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2990 /* By default we are making an address. */
2991 loc
->kind
= axs_lvalue_memory
;
2993 while (op_ptr
< op_end
)
2995 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2996 uint64_t uoffset
, reg
;
3000 offsets
[op_ptr
- base
] = expr
->len
;
3003 /* Our basic approach to code generation is to map DWARF
3004 operations directly to AX operations. However, there are
3007 First, DWARF works on address-sized units, but AX always uses
3008 LONGEST. For most operations we simply ignore this
3009 difference; instead we generate sign extensions as needed
3010 before division and comparison operations. It would be nice
3011 to omit the sign extensions, but there is no way to determine
3012 the size of the target's LONGEST. (This code uses the size
3013 of the host LONGEST in some cases -- that is a bug but it is
3016 Second, some DWARF operations cannot be translated to AX.
3017 For these we simply fail. See
3018 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3053 ax_const_l (expr
, op
- DW_OP_lit0
);
3057 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3058 op_ptr
+= addr_size
;
3059 /* Some versions of GCC emit DW_OP_addr before
3060 DW_OP_GNU_push_tls_address. In this case the value is an
3061 index, not an address. We don't support things like
3062 branching between the address and the TLS op. */
3063 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3064 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3065 ax_const_l (expr
, uoffset
);
3069 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3073 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3077 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3081 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3085 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3089 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3093 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3097 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3101 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3102 ax_const_l (expr
, uoffset
);
3105 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3106 ax_const_l (expr
, offset
);
3141 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3142 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3143 loc
->kind
= axs_lvalue_register
;
3147 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3148 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3149 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3150 loc
->kind
= axs_lvalue_register
;
3153 case DW_OP_implicit_value
:
3157 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3158 if (op_ptr
+ len
> op_end
)
3159 error (_("DW_OP_implicit_value: too few bytes available."));
3160 if (len
> sizeof (ULONGEST
))
3161 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3164 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3167 dwarf_expr_require_composition (op_ptr
, op_end
,
3168 "DW_OP_implicit_value");
3170 loc
->kind
= axs_rvalue
;
3174 case DW_OP_stack_value
:
3175 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3176 loc
->kind
= axs_rvalue
;
3211 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3212 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3216 ax_const_l (expr
, offset
);
3217 ax_simple (expr
, aop_add
);
3222 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3223 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3224 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3228 ax_const_l (expr
, offset
);
3229 ax_simple (expr
, aop_add
);
3235 const gdb_byte
*datastart
;
3237 const struct block
*b
;
3238 struct symbol
*framefunc
;
3240 b
= block_for_pc (expr
->scope
);
3243 error (_("No block found for address"));
3245 framefunc
= block_linkage_function (b
);
3248 error (_("No function found for block"));
3250 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3251 &datastart
, &datalen
);
3253 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3254 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3255 datastart
+ datalen
, per_cu
,
3257 if (loc
->kind
== axs_lvalue_register
)
3258 require_rvalue (expr
, loc
);
3262 ax_const_l (expr
, offset
);
3263 ax_simple (expr
, aop_add
);
3266 loc
->kind
= axs_lvalue_memory
;
3271 ax_simple (expr
, aop_dup
);
3275 ax_simple (expr
, aop_pop
);
3280 ax_pick (expr
, offset
);
3284 ax_simple (expr
, aop_swap
);
3292 ax_simple (expr
, aop_rot
);
3296 case DW_OP_deref_size
:
3300 if (op
== DW_OP_deref_size
)
3305 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3306 error (_("Unsupported size %d in %s"),
3307 size
, get_DW_OP_name (op
));
3308 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3313 /* Sign extend the operand. */
3314 ax_ext (expr
, addr_size_bits
);
3315 ax_simple (expr
, aop_dup
);
3316 ax_const_l (expr
, 0);
3317 ax_simple (expr
, aop_less_signed
);
3318 ax_simple (expr
, aop_log_not
);
3319 i
= ax_goto (expr
, aop_if_goto
);
3320 /* We have to emit 0 - X. */
3321 ax_const_l (expr
, 0);
3322 ax_simple (expr
, aop_swap
);
3323 ax_simple (expr
, aop_sub
);
3324 ax_label (expr
, i
, expr
->len
);
3328 /* No need to sign extend here. */
3329 ax_const_l (expr
, 0);
3330 ax_simple (expr
, aop_swap
);
3331 ax_simple (expr
, aop_sub
);
3335 /* Sign extend the operand. */
3336 ax_ext (expr
, addr_size_bits
);
3337 ax_simple (expr
, aop_bit_not
);
3340 case DW_OP_plus_uconst
:
3341 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3342 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3343 but we micro-optimize anyhow. */
3346 ax_const_l (expr
, reg
);
3347 ax_simple (expr
, aop_add
);
3352 ax_simple (expr
, aop_bit_and
);
3356 /* Sign extend the operands. */
3357 ax_ext (expr
, addr_size_bits
);
3358 ax_simple (expr
, aop_swap
);
3359 ax_ext (expr
, addr_size_bits
);
3360 ax_simple (expr
, aop_swap
);
3361 ax_simple (expr
, aop_div_signed
);
3365 ax_simple (expr
, aop_sub
);
3369 ax_simple (expr
, aop_rem_unsigned
);
3373 ax_simple (expr
, aop_mul
);
3377 ax_simple (expr
, aop_bit_or
);
3381 ax_simple (expr
, aop_add
);
3385 ax_simple (expr
, aop_lsh
);
3389 ax_simple (expr
, aop_rsh_unsigned
);
3393 ax_simple (expr
, aop_rsh_signed
);
3397 ax_simple (expr
, aop_bit_xor
);
3401 /* Sign extend the operands. */
3402 ax_ext (expr
, addr_size_bits
);
3403 ax_simple (expr
, aop_swap
);
3404 ax_ext (expr
, addr_size_bits
);
3405 /* Note no swap here: A <= B is !(B < A). */
3406 ax_simple (expr
, aop_less_signed
);
3407 ax_simple (expr
, aop_log_not
);
3411 /* Sign extend the operands. */
3412 ax_ext (expr
, addr_size_bits
);
3413 ax_simple (expr
, aop_swap
);
3414 ax_ext (expr
, addr_size_bits
);
3415 ax_simple (expr
, aop_swap
);
3416 /* A >= B is !(A < B). */
3417 ax_simple (expr
, aop_less_signed
);
3418 ax_simple (expr
, aop_log_not
);
3422 /* Sign extend the operands. */
3423 ax_ext (expr
, addr_size_bits
);
3424 ax_simple (expr
, aop_swap
);
3425 ax_ext (expr
, addr_size_bits
);
3426 /* No need for a second swap here. */
3427 ax_simple (expr
, aop_equal
);
3431 /* Sign extend the operands. */
3432 ax_ext (expr
, addr_size_bits
);
3433 ax_simple (expr
, aop_swap
);
3434 ax_ext (expr
, addr_size_bits
);
3435 ax_simple (expr
, aop_swap
);
3436 ax_simple (expr
, aop_less_signed
);
3440 /* Sign extend the operands. */
3441 ax_ext (expr
, addr_size_bits
);
3442 ax_simple (expr
, aop_swap
);
3443 ax_ext (expr
, addr_size_bits
);
3444 /* Note no swap here: A > B is B < A. */
3445 ax_simple (expr
, aop_less_signed
);
3449 /* Sign extend the operands. */
3450 ax_ext (expr
, addr_size_bits
);
3451 ax_simple (expr
, aop_swap
);
3452 ax_ext (expr
, addr_size_bits
);
3453 /* No need for a swap here. */
3454 ax_simple (expr
, aop_equal
);
3455 ax_simple (expr
, aop_log_not
);
3458 case DW_OP_call_frame_cfa
:
3461 CORE_ADDR text_offset
;
3463 const gdb_byte
*cfa_start
, *cfa_end
;
3465 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3467 &text_offset
, &cfa_start
, &cfa_end
))
3470 ax_reg (expr
, regnum
);
3473 ax_const_l (expr
, off
);
3474 ax_simple (expr
, aop_add
);
3479 /* Another expression. */
3480 ax_const_l (expr
, text_offset
);
3481 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3482 cfa_end
, per_cu
, per_objfile
);
3485 loc
->kind
= axs_lvalue_memory
;
3489 case DW_OP_GNU_push_tls_address
:
3490 case DW_OP_form_tls_address
:
3494 case DW_OP_push_object_address
:
3499 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3501 i
= ax_goto (expr
, aop_goto
);
3502 dw_labels
.push_back (op_ptr
+ offset
- base
);
3503 patches
.push_back (i
);
3507 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3509 /* Zero extend the operand. */
3510 ax_zero_ext (expr
, addr_size_bits
);
3511 i
= ax_goto (expr
, aop_if_goto
);
3512 dw_labels
.push_back (op_ptr
+ offset
- base
);
3513 patches
.push_back (i
);
3520 case DW_OP_bit_piece
:
3524 if (op_ptr
- 1 == previous_piece
)
3525 error (_("Cannot translate empty pieces to agent expressions"));
3526 previous_piece
= op_ptr
- 1;
3528 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3529 if (op
== DW_OP_piece
)
3535 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3537 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3538 error (_("Expression pieces exceed word size"));
3540 /* Access the bits. */
3543 case axs_lvalue_register
:
3544 ax_reg (expr
, loc
->u
.reg
);
3547 case axs_lvalue_memory
:
3548 /* Offset the pointer, if needed. */
3551 ax_const_l (expr
, uoffset
/ 8);
3552 ax_simple (expr
, aop_add
);
3555 access_memory (arch
, expr
, size
);
3559 /* For a bits-big-endian target, shift up what we already
3560 have. For a bits-little-endian target, shift up the
3561 new data. Note that there is a potential bug here if
3562 the DWARF expression leaves multiple values on the
3564 if (bits_collected
> 0)
3566 if (bits_big_endian
)
3568 ax_simple (expr
, aop_swap
);
3569 ax_const_l (expr
, size
);
3570 ax_simple (expr
, aop_lsh
);
3571 /* We don't need a second swap here, because
3572 aop_bit_or is symmetric. */
3576 ax_const_l (expr
, size
);
3577 ax_simple (expr
, aop_lsh
);
3579 ax_simple (expr
, aop_bit_or
);
3582 bits_collected
+= size
;
3583 loc
->kind
= axs_rvalue
;
3587 case DW_OP_GNU_uninit
:
3593 struct dwarf2_locexpr_baton block
;
3594 int size
= (op
== DW_OP_call2
? 2 : 4);
3596 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3599 cu_offset cuoffset
= (cu_offset
) uoffset
;
3600 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3603 /* DW_OP_call_ref is currently not supported. */
3604 gdb_assert (block
.per_cu
== per_cu
);
3606 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3607 block
.data
+ block
.size
, per_cu
,
3612 case DW_OP_call_ref
:
3615 case DW_OP_GNU_variable_value
:
3623 /* Patch all the branches we emitted. */
3624 for (int i
= 0; i
< patches
.size (); ++i
)
3626 int targ
= offsets
[dw_labels
[i
]];
3628 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3629 ax_label (expr
, patches
[i
], targ
);
3634 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3635 evaluator to calculate the location. */
3636 static struct value
*
3637 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3639 struct dwarf2_locexpr_baton
*dlbaton
3640 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3643 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3644 dlbaton
->size
, dlbaton
->per_cu
);
3649 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3650 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3653 static struct value
*
3654 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3656 struct dwarf2_locexpr_baton
*dlbaton
3657 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3659 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3663 /* Implementation of get_symbol_read_needs from
3664 symbol_computed_ops. */
3666 static enum symbol_needs_kind
3667 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3669 struct dwarf2_locexpr_baton
*dlbaton
3670 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3672 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3676 /* Return true if DATA points to the end of a piece. END is one past
3677 the last byte in the expression. */
3680 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3682 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3685 /* Helper for locexpr_describe_location_piece that finds the name of a
3689 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3693 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3694 We'd rather print *something* here than throw an error. */
3695 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3696 /* gdbarch_register_name may just return "", return something more
3697 descriptive for bad register numbers. */
3700 /* The text is output as "$bad_register_number".
3701 That is why we use the underscores. */
3702 return _("bad_register_number");
3704 return gdbarch_register_name (gdbarch
, regnum
);
3707 /* Nicely describe a single piece of a location, returning an updated
3708 position in the bytecode sequence. This function cannot recognize
3709 all locations; if a location is not recognized, it simply returns
3710 DATA. If there is an error during reading, e.g. we run off the end
3711 of the buffer, an error is thrown. */
3713 static const gdb_byte
*
3714 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3715 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3716 dwarf2_per_objfile
*per_objfile
,
3717 const gdb_byte
*data
, const gdb_byte
*end
,
3718 unsigned int addr_size
)
3720 objfile
*objfile
= per_objfile
->objfile
;
3721 struct gdbarch
*gdbarch
= objfile
->arch ();
3724 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3726 fprintf_filtered (stream
, _("a variable in $%s"),
3727 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3730 else if (data
[0] == DW_OP_regx
)
3734 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3735 fprintf_filtered (stream
, _("a variable in $%s"),
3736 locexpr_regname (gdbarch
, reg
));
3738 else if (data
[0] == DW_OP_fbreg
)
3740 const struct block
*b
;
3741 struct symbol
*framefunc
;
3743 int64_t frame_offset
;
3744 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3746 int64_t base_offset
= 0;
3748 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3749 if (!piece_end_p (new_data
, end
))
3753 b
= block_for_pc (addr
);
3756 error (_("No block found for address for symbol \"%s\"."),
3757 symbol
->print_name ());
3759 framefunc
= block_linkage_function (b
);
3762 error (_("No function found for block for symbol \"%s\"."),
3763 symbol
->print_name ());
3765 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3767 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3769 const gdb_byte
*buf_end
;
3771 frame_reg
= base_data
[0] - DW_OP_breg0
;
3772 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3774 if (buf_end
!= base_data
+ base_size
)
3775 error (_("Unexpected opcode after "
3776 "DW_OP_breg%u for symbol \"%s\"."),
3777 frame_reg
, symbol
->print_name ());
3779 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3781 /* The frame base is just the register, with no offset. */
3782 frame_reg
= base_data
[0] - DW_OP_reg0
;
3787 /* We don't know what to do with the frame base expression,
3788 so we can't trace this variable; give up. */
3792 fprintf_filtered (stream
,
3793 _("a variable at frame base reg $%s offset %s+%s"),
3794 locexpr_regname (gdbarch
, frame_reg
),
3795 plongest (base_offset
), plongest (frame_offset
));
3797 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3798 && piece_end_p (data
, end
))
3802 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3804 fprintf_filtered (stream
,
3805 _("a variable at offset %s from base reg $%s"),
3807 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3810 /* The location expression for a TLS variable looks like this (on a
3813 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3814 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3816 0x3 is the encoding for DW_OP_addr, which has an operand as long
3817 as the size of an address on the target machine (here is 8
3818 bytes). Note that more recent version of GCC emit DW_OP_const4u
3819 or DW_OP_const8u, depending on address size, rather than
3820 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3821 The operand represents the offset at which the variable is within
3822 the thread local storage. */
3824 else if (data
+ 1 + addr_size
< end
3825 && (data
[0] == DW_OP_addr
3826 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3827 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3828 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3829 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3830 && piece_end_p (data
+ 2 + addr_size
, end
))
3833 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3834 gdbarch_byte_order (gdbarch
));
3836 fprintf_filtered (stream
,
3837 _("a thread-local variable at offset 0x%s "
3838 "in the thread-local storage for `%s'"),
3839 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3841 data
+= 1 + addr_size
+ 1;
3844 /* With -gsplit-dwarf a TLS variable can also look like this:
3845 DW_AT_location : 3 byte block: fc 4 e0
3846 (DW_OP_GNU_const_index: 4;
3847 DW_OP_GNU_push_tls_address) */
3848 else if (data
+ 3 <= end
3849 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3850 && data
[0] == DW_OP_GNU_const_index
3852 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3853 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3854 && piece_end_p (data
+ 2 + leb128_size
, end
))
3858 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3859 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3860 fprintf_filtered (stream
,
3861 _("a thread-local variable at offset 0x%s "
3862 "in the thread-local storage for `%s'"),
3863 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3867 else if (data
[0] >= DW_OP_lit0
3868 && data
[0] <= DW_OP_lit31
3870 && data
[1] == DW_OP_stack_value
)
3872 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3879 /* Disassemble an expression, stopping at the end of a piece or at the
3880 end of the expression. Returns a pointer to the next unread byte
3881 in the input expression. If ALL is nonzero, then this function
3882 will keep going until it reaches the end of the expression.
3883 If there is an error during reading, e.g. we run off the end
3884 of the buffer, an error is thrown. */
3886 static const gdb_byte
*
3887 disassemble_dwarf_expression (struct ui_file
*stream
,
3888 struct gdbarch
*arch
, unsigned int addr_size
,
3889 int offset_size
, const gdb_byte
*start
,
3890 const gdb_byte
*data
, const gdb_byte
*end
,
3891 int indent
, int all
,
3892 dwarf2_per_cu_data
*per_cu
,
3893 dwarf2_per_objfile
*per_objfile
)
3897 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3899 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3904 name
= get_DW_OP_name (op
);
3907 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3908 op
, (long) (data
- 1 - start
));
3909 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3910 (long) (data
- 1 - start
), name
);
3915 ul
= extract_unsigned_integer (data
, addr_size
,
3916 gdbarch_byte_order (arch
));
3918 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3922 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3924 fprintf_filtered (stream
, " %s", pulongest (ul
));
3927 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3929 fprintf_filtered (stream
, " %s", plongest (l
));
3932 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3934 fprintf_filtered (stream
, " %s", pulongest (ul
));
3937 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3939 fprintf_filtered (stream
, " %s", plongest (l
));
3942 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3944 fprintf_filtered (stream
, " %s", pulongest (ul
));
3947 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3949 fprintf_filtered (stream
, " %s", plongest (l
));
3952 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3954 fprintf_filtered (stream
, " %s", pulongest (ul
));
3957 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3959 fprintf_filtered (stream
, " %s", plongest (l
));
3962 data
= safe_read_uleb128 (data
, end
, &ul
);
3963 fprintf_filtered (stream
, " %s", pulongest (ul
));
3966 data
= safe_read_sleb128 (data
, end
, &l
);
3967 fprintf_filtered (stream
, " %s", plongest (l
));
4002 fprintf_filtered (stream
, " [$%s]",
4003 locexpr_regname (arch
, op
- DW_OP_reg0
));
4007 data
= safe_read_uleb128 (data
, end
, &ul
);
4008 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4009 locexpr_regname (arch
, (int) ul
));
4012 case DW_OP_implicit_value
:
4013 data
= safe_read_uleb128 (data
, end
, &ul
);
4015 fprintf_filtered (stream
, " %s", pulongest (ul
));
4050 data
= safe_read_sleb128 (data
, end
, &l
);
4051 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4052 locexpr_regname (arch
, op
- DW_OP_breg0
));
4056 data
= safe_read_uleb128 (data
, end
, &ul
);
4057 data
= safe_read_sleb128 (data
, end
, &l
);
4058 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4060 locexpr_regname (arch
, (int) ul
),
4065 data
= safe_read_sleb128 (data
, end
, &l
);
4066 fprintf_filtered (stream
, " %s", plongest (l
));
4069 case DW_OP_xderef_size
:
4070 case DW_OP_deref_size
:
4072 fprintf_filtered (stream
, " %d", *data
);
4076 case DW_OP_plus_uconst
:
4077 data
= safe_read_uleb128 (data
, end
, &ul
);
4078 fprintf_filtered (stream
, " %s", pulongest (ul
));
4082 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4084 fprintf_filtered (stream
, " to %ld",
4085 (long) (data
+ l
- start
));
4089 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4091 fprintf_filtered (stream
, " %ld",
4092 (long) (data
+ l
- start
));
4096 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4098 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4102 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4104 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4107 case DW_OP_call_ref
:
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 data
= safe_read_uleb128 (data
, end
, &ul
);
4116 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4119 case DW_OP_bit_piece
:
4123 data
= safe_read_uleb128 (data
, end
, &ul
);
4124 data
= safe_read_uleb128 (data
, end
, &offset
);
4125 fprintf_filtered (stream
, " size %s offset %s (bits)",
4126 pulongest (ul
), pulongest (offset
));
4130 case DW_OP_implicit_pointer
:
4131 case DW_OP_GNU_implicit_pointer
:
4133 ul
= extract_unsigned_integer (data
, offset_size
,
4134 gdbarch_byte_order (arch
));
4135 data
+= offset_size
;
4137 data
= safe_read_sleb128 (data
, end
, &l
);
4139 fprintf_filtered (stream
, " DIE %s offset %s",
4140 phex_nz (ul
, offset_size
),
4145 case DW_OP_deref_type
:
4146 case DW_OP_GNU_deref_type
:
4148 int deref_addr_size
= *data
++;
4151 data
= safe_read_uleb128 (data
, end
, &ul
);
4152 cu_offset offset
= (cu_offset
) ul
;
4153 type
= dwarf2_get_die_type (offset
, per_cu
);
4154 fprintf_filtered (stream
, "<");
4155 type_print (type
, "", stream
, -1);
4156 fprintf_filtered (stream
, " [0x%s]> %d",
4157 phex_nz (to_underlying (offset
), 0),
4162 case DW_OP_const_type
:
4163 case DW_OP_GNU_const_type
:
4167 data
= safe_read_uleb128 (data
, end
, &ul
);
4168 cu_offset type_die
= (cu_offset
) ul
;
4169 type
= dwarf2_get_die_type (type_die
, per_cu
);
4170 fprintf_filtered (stream
, "<");
4171 type_print (type
, "", stream
, -1);
4172 fprintf_filtered (stream
, " [0x%s]>",
4173 phex_nz (to_underlying (type_die
), 0));
4176 fprintf_filtered (stream
, " %d byte block:", n
);
4177 for (int i
= 0; i
< n
; ++i
)
4178 fprintf_filtered (stream
, " %02x", data
[i
]);
4183 case DW_OP_regval_type
:
4184 case DW_OP_GNU_regval_type
:
4189 data
= safe_read_uleb128 (data
, end
, ®
);
4190 data
= safe_read_uleb128 (data
, end
, &ul
);
4191 cu_offset type_die
= (cu_offset
) ul
;
4193 type
= dwarf2_get_die_type (type_die
, per_cu
);
4194 fprintf_filtered (stream
, "<");
4195 type_print (type
, "", stream
, -1);
4196 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4197 phex_nz (to_underlying (type_die
), 0),
4198 locexpr_regname (arch
, reg
));
4203 case DW_OP_GNU_convert
:
4204 case DW_OP_reinterpret
:
4205 case DW_OP_GNU_reinterpret
:
4207 data
= safe_read_uleb128 (data
, end
, &ul
);
4208 cu_offset type_die
= (cu_offset
) ul
;
4210 if (to_underlying (type_die
) == 0)
4211 fprintf_filtered (stream
, "<0>");
4216 type
= dwarf2_get_die_type (type_die
, per_cu
);
4217 fprintf_filtered (stream
, "<");
4218 type_print (type
, "", stream
, -1);
4219 fprintf_filtered (stream
, " [0x%s]>",
4220 phex_nz (to_underlying (type_die
), 0));
4225 case DW_OP_entry_value
:
4226 case DW_OP_GNU_entry_value
:
4227 data
= safe_read_uleb128 (data
, end
, &ul
);
4228 fputc_filtered ('\n', stream
);
4229 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4230 start
, data
, data
+ ul
, indent
+ 2,
4231 all
, per_cu
, per_objfile
);
4235 case DW_OP_GNU_parameter_ref
:
4236 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4238 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4242 case DW_OP_GNU_addr_index
:
4243 data
= safe_read_uleb128 (data
, end
, &ul
);
4244 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4245 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4247 case DW_OP_GNU_const_index
:
4248 data
= safe_read_uleb128 (data
, end
, &ul
);
4249 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4250 fprintf_filtered (stream
, " %s", pulongest (ul
));
4253 case DW_OP_GNU_variable_value
:
4254 ul
= extract_unsigned_integer (data
, offset_size
,
4255 gdbarch_byte_order (arch
));
4256 data
+= offset_size
;
4257 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4261 fprintf_filtered (stream
, "\n");
4267 static bool dwarf_always_disassemble
;
4270 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4271 struct cmd_list_element
*c
, const char *value
)
4273 fprintf_filtered (file
,
4274 _("Whether to always disassemble "
4275 "DWARF expressions is %s.\n"),
4279 /* Describe a single location, which may in turn consist of multiple
4283 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4284 struct ui_file
*stream
,
4285 const gdb_byte
*data
, size_t size
,
4286 unsigned int addr_size
,
4287 int offset_size
, dwarf2_per_cu_data
*per_cu
,
4288 dwarf2_per_objfile
*per_objfile
)
4290 const gdb_byte
*end
= data
+ size
;
4291 int first_piece
= 1, bad
= 0;
4292 objfile
*objfile
= per_objfile
->objfile
;
4296 const gdb_byte
*here
= data
;
4297 int disassemble
= 1;
4302 fprintf_filtered (stream
, _(", and "));
4304 if (!dwarf_always_disassemble
)
4306 data
= locexpr_describe_location_piece (symbol
, stream
,
4307 addr
, per_cu
, per_objfile
,
4308 data
, end
, addr_size
);
4309 /* If we printed anything, or if we have an empty piece,
4310 then don't disassemble. */
4312 || data
[0] == DW_OP_piece
4313 || data
[0] == DW_OP_bit_piece
)
4318 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4319 data
= disassemble_dwarf_expression (stream
,
4321 addr_size
, offset_size
, data
,
4323 dwarf_always_disassemble
,
4324 per_cu
, per_objfile
);
4329 int empty
= data
== here
;
4332 fprintf_filtered (stream
, " ");
4333 if (data
[0] == DW_OP_piece
)
4337 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4340 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4343 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4346 else if (data
[0] == DW_OP_bit_piece
)
4348 uint64_t bits
, offset
;
4350 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4351 data
= safe_read_uleb128 (data
, end
, &offset
);
4354 fprintf_filtered (stream
,
4355 _("an empty %s-bit piece"),
4358 fprintf_filtered (stream
,
4359 _(" [%s-bit piece, offset %s bits]"),
4360 pulongest (bits
), pulongest (offset
));
4370 if (bad
|| data
> end
)
4371 error (_("Corrupted DWARF2 expression for \"%s\"."),
4372 symbol
->print_name ());
4375 /* Print a natural-language description of SYMBOL to STREAM. This
4376 version is for a symbol with a single location. */
4379 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4380 struct ui_file
*stream
)
4382 struct dwarf2_locexpr_baton
*dlbaton
4383 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4384 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4385 int offset_size
= dlbaton
->per_cu
->offset_size ();
4387 locexpr_describe_location_1 (symbol
, addr
, stream
,
4388 dlbaton
->data
, dlbaton
->size
,
4389 addr_size
, offset_size
,
4390 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4393 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4394 any necessary bytecode in AX. */
4397 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4398 struct axs_value
*value
)
4400 struct dwarf2_locexpr_baton
*dlbaton
4401 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4402 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4404 if (dlbaton
->size
== 0)
4405 value
->optimized_out
= 1;
4407 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4408 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4409 dlbaton
->per_objfile
);
4412 /* symbol_computed_ops 'generate_c_location' method. */
4415 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4416 struct gdbarch
*gdbarch
,
4417 unsigned char *registers_used
,
4418 CORE_ADDR pc
, const char *result_name
)
4420 struct dwarf2_locexpr_baton
*dlbaton
4421 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4422 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4424 if (dlbaton
->size
== 0)
4425 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4427 compile_dwarf_expr_to_c (stream
, result_name
,
4428 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4429 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4430 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4433 /* The set of location functions used with the DWARF-2 expression
4435 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4436 locexpr_read_variable
,
4437 locexpr_read_variable_at_entry
,
4438 locexpr_get_symbol_read_needs
,
4439 locexpr_describe_location
,
4440 0, /* location_has_loclist */
4441 locexpr_tracepoint_var_ref
,
4442 locexpr_generate_c_location
4446 /* Wrapper functions for location lists. These generally find
4447 the appropriate location expression and call something above. */
4449 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4450 evaluator to calculate the location. */
4451 static struct value
*
4452 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4454 struct dwarf2_loclist_baton
*dlbaton
4455 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4457 const gdb_byte
*data
;
4459 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4461 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4462 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4468 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4469 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4472 Function always returns non-NULL value, it may be marked optimized out if
4473 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4474 if it cannot resolve the parameter for any reason. */
4476 static struct value
*
4477 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4479 struct dwarf2_loclist_baton
*dlbaton
4480 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4481 const gdb_byte
*data
;
4485 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4486 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4488 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4490 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4492 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4495 /* Implementation of get_symbol_read_needs from
4496 symbol_computed_ops. */
4498 static enum symbol_needs_kind
4499 loclist_symbol_needs (struct symbol
*symbol
)
4501 /* If there's a location list, then assume we need to have a frame
4502 to choose the appropriate location expression. With tracking of
4503 global variables this is not necessarily true, but such tracking
4504 is disabled in GCC at the moment until we figure out how to
4507 return SYMBOL_NEEDS_FRAME
;
4510 /* Print a natural-language description of SYMBOL to STREAM. This
4511 version applies when there is a list of different locations, each
4512 with a specified address range. */
4515 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4516 struct ui_file
*stream
)
4518 struct dwarf2_loclist_baton
*dlbaton
4519 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4520 const gdb_byte
*loc_ptr
, *buf_end
;
4521 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4522 struct objfile
*objfile
= per_objfile
->objfile
;
4523 struct gdbarch
*gdbarch
= objfile
->arch ();
4524 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4525 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4526 int offset_size
= dlbaton
->per_cu
->offset_size ();
4527 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4528 /* Adjust base_address for relocatable objects. */
4529 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4530 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4533 loc_ptr
= dlbaton
->data
;
4534 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4536 fprintf_filtered (stream
, _("multi-location:\n"));
4538 /* Iterate through locations until we run out. */
4541 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4543 enum debug_loc_kind kind
;
4544 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4546 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4547 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4548 dlbaton
->per_objfile
,
4549 loc_ptr
, buf_end
, &new_ptr
,
4550 &low
, &high
, byte_order
);
4551 else if (dlbaton
->per_cu
->version () < 5)
4552 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4554 byte_order
, addr_size
,
4557 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4558 dlbaton
->per_objfile
,
4559 loc_ptr
, buf_end
, &new_ptr
,
4560 &low
, &high
, byte_order
,
4561 addr_size
, signed_addr_p
);
4565 case DEBUG_LOC_END_OF_LIST
:
4568 case DEBUG_LOC_BASE_ADDRESS
:
4569 base_address
= high
+ base_offset
;
4570 fprintf_filtered (stream
, _(" Base address %s"),
4571 paddress (gdbarch
, base_address
));
4573 case DEBUG_LOC_START_END
:
4574 case DEBUG_LOC_START_LENGTH
:
4575 case DEBUG_LOC_OFFSET_PAIR
:
4577 case DEBUG_LOC_BUFFER_OVERFLOW
:
4578 case DEBUG_LOC_INVALID_ENTRY
:
4579 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4580 symbol
->print_name ());
4582 gdb_assert_not_reached ("bad debug_loc_kind");
4585 /* Otherwise, a location expression entry. */
4586 low
+= base_address
;
4587 high
+= base_address
;
4589 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4590 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4592 if (dlbaton
->per_cu
->version () < 5)
4594 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4599 unsigned int bytes_read
;
4600 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4601 loc_ptr
+= bytes_read
;
4604 /* (It would improve readability to print only the minimum
4605 necessary digits of the second number of the range.) */
4606 fprintf_filtered (stream
, _(" Range %s-%s: "),
4607 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4609 /* Now describe this particular location. */
4610 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4611 addr_size
, offset_size
,
4612 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4614 fprintf_filtered (stream
, "\n");
4620 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4621 any necessary bytecode in AX. */
4623 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4624 struct axs_value
*value
)
4626 struct dwarf2_loclist_baton
*dlbaton
4627 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4628 const gdb_byte
*data
;
4630 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4632 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4634 value
->optimized_out
= 1;
4636 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4637 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4640 /* symbol_computed_ops 'generate_c_location' method. */
4643 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4644 struct gdbarch
*gdbarch
,
4645 unsigned char *registers_used
,
4646 CORE_ADDR pc
, const char *result_name
)
4648 struct dwarf2_loclist_baton
*dlbaton
4649 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4650 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4651 const gdb_byte
*data
;
4654 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4656 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4658 compile_dwarf_expr_to_c (stream
, result_name
,
4659 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4662 dlbaton
->per_objfile
);
4665 /* The set of location functions used with the DWARF-2 expression
4666 evaluator and location lists. */
4667 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4668 loclist_read_variable
,
4669 loclist_read_variable_at_entry
,
4670 loclist_symbol_needs
,
4671 loclist_describe_location
,
4672 1, /* location_has_loclist */
4673 loclist_tracepoint_var_ref
,
4674 loclist_generate_c_location
4677 void _initialize_dwarf2loc ();
4679 _initialize_dwarf2loc ()
4681 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4682 &entry_values_debug
,
4683 _("Set entry values and tail call frames "
4685 _("Show entry values and tail call frames "
4687 _("When non-zero, the process of determining "
4688 "parameter values from function entry point "
4689 "and tail call frames will be printed."),
4691 show_entry_values_debug
,
4692 &setdebuglist
, &showdebuglist
);
4694 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4695 &dwarf_always_disassemble
, _("\
4696 Set whether `info address' always disassembles DWARF expressions."), _("\
4697 Show whether `info address' always disassembles DWARF expressions."), _("\
4698 When enabled, DWARF expressions are always printed in an assembly-like\n\
4699 syntax. When disabled, expressions will be printed in a more\n\
4700 conversational style, when possible."),
4702 show_dwarf_always_disassemble
,
4704 &show_dwarf_cmdlist
);