1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "complaints.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
51 struct frame_info
*frame
,
54 struct dwarf2_per_cu_data
*per_cu
,
55 struct type
*subobj_type
,
56 LONGEST subobj_byte_offset
);
58 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
59 (struct frame_info
*frame
,
60 enum call_site_parameter_kind kind
,
61 union call_site_parameter_u kind_u
,
62 struct dwarf2_per_cu_data
**per_cu_return
);
64 static struct value
*indirect_synthetic_pointer
65 (sect_offset die
, LONGEST byte_offset
,
66 struct dwarf2_per_cu_data
*per_cu
,
67 struct frame_info
*frame
,
68 struct type
*type
, bool resolve_abstract_p
= false);
70 /* Until these have formal names, we define these here.
71 ref: http://gcc.gnu.org/wiki/DebugFission
72 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
73 and is then followed by data specific to that entry. */
77 /* Indicates the end of the list of entries. */
78 DEBUG_LOC_END_OF_LIST
= 0,
80 /* This is followed by an unsigned LEB128 number that is an index into
81 .debug_addr and specifies the base address for all following entries. */
82 DEBUG_LOC_BASE_ADDRESS
= 1,
84 /* This is followed by two unsigned LEB128 numbers that are indices into
85 .debug_addr and specify the beginning and ending addresses, and then
86 a normal location expression as in .debug_loc. */
87 DEBUG_LOC_START_END
= 2,
89 /* This is followed by an unsigned LEB128 number that is an index into
90 .debug_addr and specifies the beginning address, and a 4 byte unsigned
91 number that specifies the length, and then a normal location expression
93 DEBUG_LOC_START_LENGTH
= 3,
95 /* This is followed by two unsigned LEB128 operands. The values of these
96 operands are the starting and ending offsets, respectively, relative to
97 the applicable base address. */
98 DEBUG_LOC_OFFSET_PAIR
= 4,
100 /* An internal value indicating there is insufficient data. */
101 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
103 /* An internal value indicating an invalid kind of entry was found. */
104 DEBUG_LOC_INVALID_ENTRY
= -2
107 /* Helper function which throws an error if a synthetic pointer is
111 invalid_synthetic_pointer (void)
113 error (_("access outside bounds of object "
114 "referenced via synthetic pointer"));
117 /* Decode the addresses in a non-dwo .debug_loc entry.
118 A pointer to the next byte to examine is returned in *NEW_PTR.
119 The encoded low,high addresses are return in *LOW,*HIGH.
120 The result indicates the kind of entry found. */
122 static enum debug_loc_kind
123 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
124 const gdb_byte
**new_ptr
,
125 CORE_ADDR
*low
, CORE_ADDR
*high
,
126 enum bfd_endian byte_order
,
127 unsigned int addr_size
,
130 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
132 if (buf_end
- loc_ptr
< 2 * addr_size
)
133 return DEBUG_LOC_BUFFER_OVERFLOW
;
136 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
138 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
139 loc_ptr
+= addr_size
;
142 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
144 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
145 loc_ptr
+= addr_size
;
149 /* A base-address-selection entry. */
150 if ((*low
& base_mask
) == base_mask
)
151 return DEBUG_LOC_BASE_ADDRESS
;
153 /* An end-of-list entry. */
154 if (*low
== 0 && *high
== 0)
155 return DEBUG_LOC_END_OF_LIST
;
157 return DEBUG_LOC_START_END
;
160 /* Decode the addresses in .debug_loclists entry.
161 A pointer to the next byte to examine is returned in *NEW_PTR.
162 The encoded low,high addresses are return in *LOW,*HIGH.
163 The result indicates the kind of entry found. */
165 static enum debug_loc_kind
166 decode_debug_loclists_addresses (struct dwarf2_per_cu_data
*per_cu
,
167 const gdb_byte
*loc_ptr
,
168 const gdb_byte
*buf_end
,
169 const gdb_byte
**new_ptr
,
170 CORE_ADDR
*low
, CORE_ADDR
*high
,
171 enum bfd_endian byte_order
,
172 unsigned int addr_size
,
177 if (loc_ptr
== buf_end
)
178 return DEBUG_LOC_BUFFER_OVERFLOW
;
182 case DW_LLE_base_addressx
:
184 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
187 *high
= dwarf2_read_addr_index (per_cu
, u64
);
189 return DEBUG_LOC_BASE_ADDRESS
;
190 case DW_LLE_startx_length
:
191 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
193 return DEBUG_LOC_BUFFER_OVERFLOW
;
194 *low
= dwarf2_read_addr_index (per_cu
, u64
);
196 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
198 return DEBUG_LOC_BUFFER_OVERFLOW
;
201 return DEBUG_LOC_START_LENGTH
;
202 case DW_LLE_start_length
:
203 if (buf_end
- loc_ptr
< addr_size
)
204 return DEBUG_LOC_BUFFER_OVERFLOW
;
206 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
208 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
209 loc_ptr
+= addr_size
;
211 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
213 return DEBUG_LOC_BUFFER_OVERFLOW
;
216 return DEBUG_LOC_START_LENGTH
;
217 case DW_LLE_end_of_list
:
219 return DEBUG_LOC_END_OF_LIST
;
220 case DW_LLE_base_address
:
221 if (loc_ptr
+ addr_size
> buf_end
)
222 return DEBUG_LOC_BUFFER_OVERFLOW
;
224 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
226 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
227 loc_ptr
+= addr_size
;
229 return DEBUG_LOC_BASE_ADDRESS
;
230 case DW_LLE_offset_pair
:
231 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
233 return DEBUG_LOC_BUFFER_OVERFLOW
;
235 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
237 return DEBUG_LOC_BUFFER_OVERFLOW
;
240 return DEBUG_LOC_OFFSET_PAIR
;
241 /* Following cases are not supported yet. */
242 case DW_LLE_startx_endx
:
243 case DW_LLE_start_end
:
244 case DW_LLE_default_location
:
246 return DEBUG_LOC_INVALID_ENTRY
;
250 /* Decode the addresses in .debug_loc.dwo entry.
251 A pointer to the next byte to examine is returned in *NEW_PTR.
252 The encoded low,high addresses are return in *LOW,*HIGH.
253 The result indicates the kind of entry found. */
255 static enum debug_loc_kind
256 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
257 const gdb_byte
*loc_ptr
,
258 const gdb_byte
*buf_end
,
259 const gdb_byte
**new_ptr
,
260 CORE_ADDR
*low
, CORE_ADDR
*high
,
261 enum bfd_endian byte_order
)
263 uint64_t low_index
, high_index
;
265 if (loc_ptr
== buf_end
)
266 return DEBUG_LOC_BUFFER_OVERFLOW
;
270 case DW_LLE_GNU_end_of_list_entry
:
272 return DEBUG_LOC_END_OF_LIST
;
273 case DW_LLE_GNU_base_address_selection_entry
:
275 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
277 return DEBUG_LOC_BUFFER_OVERFLOW
;
278 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
280 return DEBUG_LOC_BASE_ADDRESS
;
281 case DW_LLE_GNU_start_end_entry
:
282 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
284 return DEBUG_LOC_BUFFER_OVERFLOW
;
285 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
286 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
288 return DEBUG_LOC_BUFFER_OVERFLOW
;
289 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
291 return DEBUG_LOC_START_END
;
292 case DW_LLE_GNU_start_length_entry
:
293 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
295 return DEBUG_LOC_BUFFER_OVERFLOW
;
296 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
297 if (loc_ptr
+ 4 > buf_end
)
298 return DEBUG_LOC_BUFFER_OVERFLOW
;
300 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
301 *new_ptr
= loc_ptr
+ 4;
302 return DEBUG_LOC_START_LENGTH
;
304 return DEBUG_LOC_INVALID_ENTRY
;
308 /* A function for dealing with location lists. Given a
309 symbol baton (BATON) and a pc value (PC), find the appropriate
310 location expression, set *LOCEXPR_LENGTH, and return a pointer
311 to the beginning of the expression. Returns NULL on failure.
313 For now, only return the first matching location expression; there
314 can be more than one in the list. */
317 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
318 size_t *locexpr_length
, CORE_ADDR pc
)
320 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
321 struct objfile
*objfile
= per_objfile
->objfile
;
322 struct gdbarch
*gdbarch
= objfile
->arch ();
323 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
324 unsigned int addr_size
= baton
->per_cu
->addr_size ();
325 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
326 /* Adjust base_address for relocatable objects. */
327 CORE_ADDR base_offset
= baton
->per_cu
->text_offset ();
328 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
329 const gdb_byte
*loc_ptr
, *buf_end
;
331 loc_ptr
= baton
->data
;
332 buf_end
= baton
->data
+ baton
->size
;
336 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
338 enum debug_loc_kind kind
;
339 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
341 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
342 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
343 loc_ptr
, buf_end
, &new_ptr
,
344 &low
, &high
, byte_order
);
345 else if (baton
->per_cu
->version () < 5)
346 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
348 byte_order
, addr_size
,
351 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
352 loc_ptr
, buf_end
, &new_ptr
,
353 &low
, &high
, byte_order
,
354 addr_size
, signed_addr_p
);
359 case DEBUG_LOC_END_OF_LIST
:
362 case DEBUG_LOC_BASE_ADDRESS
:
363 base_address
= high
+ base_offset
;
365 case DEBUG_LOC_START_END
:
366 case DEBUG_LOC_START_LENGTH
:
367 case DEBUG_LOC_OFFSET_PAIR
:
369 case DEBUG_LOC_BUFFER_OVERFLOW
:
370 case DEBUG_LOC_INVALID_ENTRY
:
371 error (_("dwarf2_find_location_expression: "
372 "Corrupted DWARF expression."));
374 gdb_assert_not_reached ("bad debug_loc_kind");
377 /* Otherwise, a location expression entry.
378 If the entry is from a DWO, don't add base address: the entry is from
379 .debug_addr which already has the DWARF "base address". We still add
380 base_offset in case we're debugging a PIE executable. However, if the
381 entry is DW_LLE_offset_pair from a DWO, add the base address as the
382 operands are offsets relative to the applicable base address. */
383 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
391 high
+= base_address
;
394 if (baton
->per_cu
->version () < 5)
396 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
401 unsigned int bytes_read
;
403 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
404 loc_ptr
+= bytes_read
;
407 if (low
== high
&& pc
== low
)
409 /* This is entry PC record present only at entry point
410 of a function. Verify it is really the function entry point. */
412 const struct block
*pc_block
= block_for_pc (pc
);
413 struct symbol
*pc_func
= NULL
;
416 pc_func
= block_linkage_function (pc_block
);
418 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
420 *locexpr_length
= length
;
425 if (pc
>= low
&& pc
< high
)
427 *locexpr_length
= length
;
435 /* Implement find_frame_base_location method for LOC_BLOCK functions using
436 DWARF expression for its DW_AT_frame_base. */
439 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
440 const gdb_byte
**start
, size_t *length
)
442 struct dwarf2_locexpr_baton
*symbaton
443 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
445 *length
= symbaton
->size
;
446 *start
= symbaton
->data
;
449 /* Implement the struct symbol_block_ops::get_frame_base method for
450 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
453 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
455 struct gdbarch
*gdbarch
;
457 struct dwarf2_locexpr_baton
*dlbaton
;
458 const gdb_byte
*start
;
460 struct value
*result
;
462 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
463 Thus, it's supposed to provide the find_frame_base_location method as
465 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
467 gdbarch
= get_frame_arch (frame
);
468 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
469 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
471 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
472 (framefunc
, get_frame_pc (frame
), &start
, &length
);
473 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
476 /* The DW_AT_frame_base attribute contains a location description which
477 computes the base address itself. However, the call to
478 dwarf2_evaluate_loc_desc returns a value representing a variable at
479 that address. The frame base address is thus this variable's
481 return value_address (result
);
484 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
485 function uses DWARF expression for its DW_AT_frame_base. */
487 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
489 locexpr_find_frame_base_location
,
490 locexpr_get_frame_base
493 /* Implement find_frame_base_location method for LOC_BLOCK functions using
494 DWARF location list for its DW_AT_frame_base. */
497 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
498 const gdb_byte
**start
, size_t *length
)
500 struct dwarf2_loclist_baton
*symbaton
501 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
503 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
506 /* Implement the struct symbol_block_ops::get_frame_base method for
507 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
510 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
512 struct gdbarch
*gdbarch
;
514 struct dwarf2_loclist_baton
*dlbaton
;
515 const gdb_byte
*start
;
517 struct value
*result
;
519 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
520 Thus, it's supposed to provide the find_frame_base_location method as
522 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
524 gdbarch
= get_frame_arch (frame
);
525 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
526 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
528 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
529 (framefunc
, get_frame_pc (frame
), &start
, &length
);
530 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
533 /* The DW_AT_frame_base attribute contains a location description which
534 computes the base address itself. However, the call to
535 dwarf2_evaluate_loc_desc returns a value representing a variable at
536 that address. The frame base address is thus this variable's
538 return value_address (result
);
541 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
542 function uses DWARF location list for its DW_AT_frame_base. */
544 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
546 loclist_find_frame_base_location
,
547 loclist_get_frame_base
550 /* See dwarf2loc.h. */
553 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
554 const gdb_byte
**start
, size_t *length
)
556 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
558 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
560 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
566 error (_("Could not find the frame base for \"%s\"."),
567 framefunc
->natural_name ());
571 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
573 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
575 return ctx
->get_frame_pc ();
579 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
580 struct dwarf2_per_cu_data
*per_cu
)
582 struct dwarf2_locexpr_baton block
;
584 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
,
585 get_frame_pc_for_per_cu_dwarf_call
,
588 /* DW_OP_call_ref is currently not supported. */
589 gdb_assert (block
.per_cu
== per_cu
);
591 ctx
->eval (block
.data
, block
.size
);
594 /* Given context CTX, section offset SECT_OFF, and compilation unit
595 data PER_CU, execute the "variable value" operation on the DIE
596 found at SECT_OFF. */
598 static struct value
*
599 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
600 struct dwarf2_per_cu_data
*per_cu
)
602 struct type
*die_type
= dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
);
604 if (die_type
== NULL
)
605 error (_("Bad DW_OP_GNU_variable_value DIE."));
607 /* Note: Things still work when the following test is removed. This
608 test and error is here to conform to the proposed specification. */
609 if (die_type
->code () != TYPE_CODE_INT
610 && die_type
->code () != TYPE_CODE_PTR
)
611 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
613 struct type
*type
= lookup_pointer_type (die_type
);
614 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
615 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, frame
, type
, true);
618 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
621 dwarf_evaluate_loc_desc (dwarf2_per_objfile
*per_objfile
)
622 : dwarf_expr_context (per_objfile
)
625 struct frame_info
*frame
;
626 struct dwarf2_per_cu_data
*per_cu
;
627 CORE_ADDR obj_address
;
629 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
630 the frame in BATON. */
632 CORE_ADDR
get_frame_cfa () override
634 return dwarf2_frame_cfa (frame
);
637 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
638 the frame in BATON. */
640 CORE_ADDR
get_frame_pc () override
642 return get_frame_address_in_block (frame
);
645 /* Using the objfile specified in BATON, find the address for the
646 current thread's thread-local storage with offset OFFSET. */
647 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
649 struct objfile
*objfile
= per_cu
->objfile ();
651 return target_translate_tls_address (objfile
, offset
);
654 /* Helper interface of per_cu_dwarf_call for
655 dwarf2_evaluate_loc_desc. */
657 void dwarf_call (cu_offset die_offset
) override
659 per_cu_dwarf_call (this, die_offset
, per_cu
);
662 /* Helper interface of sect_variable_value for
663 dwarf2_evaluate_loc_desc. */
665 struct value
*dwarf_variable_value (sect_offset sect_off
) override
667 return sect_variable_value (this, sect_off
, per_cu
);
670 struct type
*get_base_type (cu_offset die_offset
, int size
) override
672 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
674 error (_("Could not find type for DW_OP_const_type"));
675 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
676 error (_("DW_OP_const_type has different sizes for type and data"));
680 /* Callback function for dwarf2_evaluate_loc_desc.
681 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
683 CORE_ADDR
get_addr_index (unsigned int index
) override
685 return dwarf2_read_addr_index (per_cu
, index
);
688 /* Callback function for get_object_address. Return the address of the VLA
691 CORE_ADDR
get_object_address () override
693 if (obj_address
== 0)
694 error (_("Location address is not set."));
698 /* Execute DWARF block of call_site_parameter which matches KIND and
699 KIND_U. Choose DEREF_SIZE value of that parameter. Search
700 caller of this objects's frame.
702 The caller can be from a different CU - per_cu_dwarf_call
703 implementation can be more simple as it does not support cross-CU
706 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
707 union call_site_parameter_u kind_u
,
708 int deref_size
) override
710 struct frame_info
*caller_frame
;
711 struct dwarf2_per_cu_data
*caller_per_cu
;
712 struct call_site_parameter
*parameter
;
713 const gdb_byte
*data_src
;
716 caller_frame
= get_prev_frame (frame
);
718 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
720 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
721 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
723 /* DEREF_SIZE size is not verified here. */
724 if (data_src
== NULL
)
725 throw_error (NO_ENTRY_VALUE_ERROR
,
726 _("Cannot resolve DW_AT_call_data_value"));
728 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
730 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
732 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
735 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
736 this->gdbarch
= per_cu
->objfile ()->arch ();
737 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
738 this->addr_size
= per_cu
->addr_size ();
740 this->eval (data_src
, size
);
743 /* Using the frame specified in BATON, find the location expression
744 describing the frame base. Return a pointer to it in START and
745 its length in LENGTH. */
746 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
748 /* FIXME: cagney/2003-03-26: This code should be using
749 get_frame_base_address(), and then implement a dwarf2 specific
751 struct symbol
*framefunc
;
752 const struct block
*bl
= get_frame_block (frame
, NULL
);
755 error (_("frame address is not available."));
757 /* Use block_linkage_function, which returns a real (not inlined)
758 function, instead of get_frame_function, which may return an
760 framefunc
= block_linkage_function (bl
);
762 /* If we found a frame-relative symbol then it was certainly within
763 some function associated with a frame. If we can't find the frame,
764 something has gone wrong. */
765 gdb_assert (framefunc
!= NULL
);
767 func_get_frame_base_dwarf_block (framefunc
,
768 get_frame_address_in_block (frame
),
772 /* Read memory at ADDR (length LEN) into BUF. */
774 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
776 read_memory (addr
, buf
, len
);
779 /* Using the frame specified in BATON, return the value of register
780 REGNUM, treated as a pointer. */
781 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
783 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
784 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
786 return address_from_register (regnum
, frame
);
789 /* Implement "get_reg_value" callback. */
791 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
793 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
794 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
796 return value_from_register (type
, regnum
, frame
);
800 /* See dwarf2loc.h. */
802 unsigned int entry_values_debug
= 0;
804 /* Helper to set entry_values_debug. */
807 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
808 struct cmd_list_element
*c
, const char *value
)
810 fprintf_filtered (file
,
811 _("Entry values and tail call frames debugging is %s.\n"),
815 /* Find DW_TAG_call_site's DW_AT_call_target address.
816 CALLER_FRAME (for registers) can be NULL if it is not known. This function
817 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
820 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
821 struct call_site
*call_site
,
822 struct frame_info
*caller_frame
)
824 switch (FIELD_LOC_KIND (call_site
->target
))
826 case FIELD_LOC_KIND_DWARF_BLOCK
:
828 struct dwarf2_locexpr_baton
*dwarf_block
;
830 struct type
*caller_core_addr_type
;
831 struct gdbarch
*caller_arch
;
833 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
834 if (dwarf_block
== NULL
)
836 struct bound_minimal_symbol msym
;
838 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
839 throw_error (NO_ENTRY_VALUE_ERROR
,
840 _("DW_AT_call_target is not specified at %s in %s"),
841 paddress (call_site_gdbarch
, call_site
->pc
),
842 (msym
.minsym
== NULL
? "???"
843 : msym
.minsym
->print_name ()));
846 if (caller_frame
== NULL
)
848 struct bound_minimal_symbol msym
;
850 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
851 throw_error (NO_ENTRY_VALUE_ERROR
,
852 _("DW_AT_call_target DWARF block resolving "
853 "requires known frame which is currently not "
854 "available at %s in %s"),
855 paddress (call_site_gdbarch
, call_site
->pc
),
856 (msym
.minsym
== NULL
? "???"
857 : msym
.minsym
->print_name ()));
860 caller_arch
= get_frame_arch (caller_frame
);
861 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
862 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
863 dwarf_block
->data
, dwarf_block
->size
,
864 dwarf_block
->per_cu
);
865 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
866 if (VALUE_LVAL (val
) == lval_memory
)
867 return value_address (val
);
869 return value_as_address (val
);
872 case FIELD_LOC_KIND_PHYSNAME
:
874 const char *physname
;
875 struct bound_minimal_symbol msym
;
877 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
879 /* Handle both the mangled and demangled PHYSNAME. */
880 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
881 if (msym
.minsym
== NULL
)
883 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
884 throw_error (NO_ENTRY_VALUE_ERROR
,
885 _("Cannot find function \"%s\" for a call site target "
887 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
888 (msym
.minsym
== NULL
? "???"
889 : msym
.minsym
->print_name ()));
892 return BMSYMBOL_VALUE_ADDRESS (msym
);
895 case FIELD_LOC_KIND_PHYSADDR
:
896 return FIELD_STATIC_PHYSADDR (call_site
->target
);
899 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
903 /* Convert function entry point exact address ADDR to the function which is
904 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
905 NO_ENTRY_VALUE_ERROR otherwise. */
907 static struct symbol
*
908 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
910 struct symbol
*sym
= find_pc_function (addr
);
913 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
914 throw_error (NO_ENTRY_VALUE_ERROR
,
915 _("DW_TAG_call_site resolving failed to find function "
916 "name for address %s"),
917 paddress (gdbarch
, addr
));
919 type
= SYMBOL_TYPE (sym
);
920 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
921 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
926 /* Verify function with entry point exact address ADDR can never call itself
927 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
928 can call itself via tail calls.
930 If a funtion can tail call itself its entry value based parameters are
931 unreliable. There is no verification whether the value of some/all
932 parameters is unchanged through the self tail call, we expect if there is
933 a self tail call all the parameters can be modified. */
936 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
940 /* The verification is completely unordered. Track here function addresses
941 which still need to be iterated. */
942 std::vector
<CORE_ADDR
> todo
;
944 /* Track here CORE_ADDRs which were already visited. */
945 std::unordered_set
<CORE_ADDR
> addr_hash
;
947 todo
.push_back (verify_addr
);
948 while (!todo
.empty ())
950 struct symbol
*func_sym
;
951 struct call_site
*call_site
;
956 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
958 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
959 call_site
; call_site
= call_site
->tail_call_next
)
961 CORE_ADDR target_addr
;
963 /* CALLER_FRAME with registers is not available for tail-call jumped
965 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
967 if (target_addr
== verify_addr
)
969 struct bound_minimal_symbol msym
;
971 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
972 throw_error (NO_ENTRY_VALUE_ERROR
,
973 _("DW_OP_entry_value resolving has found "
974 "function \"%s\" at %s can call itself via tail "
976 (msym
.minsym
== NULL
? "???"
977 : msym
.minsym
->print_name ()),
978 paddress (gdbarch
, verify_addr
));
981 if (addr_hash
.insert (target_addr
).second
)
982 todo
.push_back (target_addr
);
987 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
988 ENTRY_VALUES_DEBUG. */
991 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
993 CORE_ADDR addr
= call_site
->pc
;
994 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
996 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
997 (msym
.minsym
== NULL
? "???"
998 : msym
.minsym
->print_name ()));
1002 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1003 only top callers and bottom callees which are present in both. GDBARCH is
1004 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1005 no remaining possibilities to provide unambiguous non-trivial result.
1006 RESULTP should point to NULL on the first (initialization) call. Caller is
1007 responsible for xfree of any RESULTP data. */
1010 chain_candidate (struct gdbarch
*gdbarch
,
1011 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1012 std::vector
<struct call_site
*> *chain
)
1014 long length
= chain
->size ();
1015 int callers
, callees
, idx
;
1017 if (*resultp
== NULL
)
1019 /* Create the initial chain containing all the passed PCs. */
1021 struct call_site_chain
*result
1022 = ((struct call_site_chain
*)
1023 xmalloc (sizeof (*result
)
1024 + sizeof (*result
->call_site
) * (length
- 1)));
1025 result
->length
= length
;
1026 result
->callers
= result
->callees
= length
;
1027 if (!chain
->empty ())
1028 memcpy (result
->call_site
, chain
->data (),
1029 sizeof (*result
->call_site
) * length
);
1030 resultp
->reset (result
);
1032 if (entry_values_debug
)
1034 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1035 for (idx
= 0; idx
< length
; idx
++)
1036 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1037 fputc_unfiltered ('\n', gdb_stdlog
);
1043 if (entry_values_debug
)
1045 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1046 for (idx
= 0; idx
< length
; idx
++)
1047 tailcall_dump (gdbarch
, chain
->at (idx
));
1048 fputc_unfiltered ('\n', gdb_stdlog
);
1051 /* Intersect callers. */
1053 callers
= std::min ((long) (*resultp
)->callers
, length
);
1054 for (idx
= 0; idx
< callers
; idx
++)
1055 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1057 (*resultp
)->callers
= idx
;
1061 /* Intersect callees. */
1063 callees
= std::min ((long) (*resultp
)->callees
, length
);
1064 for (idx
= 0; idx
< callees
; idx
++)
1065 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1066 != chain
->at (length
- 1 - idx
))
1068 (*resultp
)->callees
= idx
;
1072 if (entry_values_debug
)
1074 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1075 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1076 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1077 fputs_unfiltered (" |", gdb_stdlog
);
1078 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1079 tailcall_dump (gdbarch
,
1080 (*resultp
)->call_site
[(*resultp
)->length
1081 - (*resultp
)->callees
+ idx
]);
1082 fputc_unfiltered ('\n', gdb_stdlog
);
1085 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1087 /* There are no common callers or callees. It could be also a direct
1088 call (which has length 0) with ambiguous possibility of an indirect
1089 call - CALLERS == CALLEES == 0 is valid during the first allocation
1090 but any subsequence processing of such entry means ambiguity. */
1091 resultp
->reset (NULL
);
1095 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1096 PC again. In such case there must be two different code paths to reach
1097 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1098 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1101 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1102 assumed frames between them use GDBARCH. Use depth first search so we can
1103 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1104 would have needless GDB stack overhead. Any unreliability results
1105 in thrown NO_ENTRY_VALUE_ERROR. */
1107 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1108 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1109 CORE_ADDR callee_pc
)
1111 CORE_ADDR save_callee_pc
= callee_pc
;
1112 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1113 struct call_site
*call_site
;
1115 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1116 call_site nor any possible call_site at CALLEE_PC's function is there.
1117 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1118 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1119 std::vector
<struct call_site
*> chain
;
1121 /* We are not interested in the specific PC inside the callee function. */
1122 callee_pc
= get_pc_function_start (callee_pc
);
1124 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1125 paddress (gdbarch
, save_callee_pc
));
1127 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1128 std::unordered_set
<CORE_ADDR
> addr_hash
;
1130 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1131 at the target's function. All the possible tail call sites in the
1132 target's function will get iterated as already pushed into CHAIN via their
1134 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1138 CORE_ADDR target_func_addr
;
1139 struct call_site
*target_call_site
;
1141 /* CALLER_FRAME with registers is not available for tail-call jumped
1143 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1145 if (target_func_addr
== callee_pc
)
1147 chain_candidate (gdbarch
, &retval
, &chain
);
1151 /* There is no way to reach CALLEE_PC again as we would prevent
1152 entering it twice as being already marked in ADDR_HASH. */
1153 target_call_site
= NULL
;
1157 struct symbol
*target_func
;
1159 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1160 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1165 /* Attempt to visit TARGET_CALL_SITE. */
1167 if (target_call_site
)
1169 if (addr_hash
.insert (target_call_site
->pc
).second
)
1171 /* Successfully entered TARGET_CALL_SITE. */
1173 chain
.push_back (target_call_site
);
1178 /* Backtrack (without revisiting the originating call_site). Try the
1179 callers's sibling; if there isn't any try the callers's callers's
1182 target_call_site
= NULL
;
1183 while (!chain
.empty ())
1185 call_site
= chain
.back ();
1188 size_t removed
= addr_hash
.erase (call_site
->pc
);
1189 gdb_assert (removed
== 1);
1191 target_call_site
= call_site
->tail_call_next
;
1192 if (target_call_site
)
1196 while (target_call_site
);
1201 call_site
= chain
.back ();
1206 struct bound_minimal_symbol msym_caller
, msym_callee
;
1208 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1209 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1210 throw_error (NO_ENTRY_VALUE_ERROR
,
1211 _("There are no unambiguously determinable intermediate "
1212 "callers or callees between caller function \"%s\" at %s "
1213 "and callee function \"%s\" at %s"),
1214 (msym_caller
.minsym
== NULL
1215 ? "???" : msym_caller
.minsym
->print_name ()),
1216 paddress (gdbarch
, caller_pc
),
1217 (msym_callee
.minsym
== NULL
1218 ? "???" : msym_callee
.minsym
->print_name ()),
1219 paddress (gdbarch
, callee_pc
));
1225 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1226 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1227 constructed return NULL. */
1229 gdb::unique_xmalloc_ptr
<call_site_chain
>
1230 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1231 CORE_ADDR callee_pc
)
1233 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1237 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1239 catch (const gdb_exception_error
&e
)
1241 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1243 if (entry_values_debug
)
1244 exception_print (gdb_stdout
, e
);
1255 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1258 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1259 enum call_site_parameter_kind kind
,
1260 union call_site_parameter_u kind_u
)
1262 if (kind
== parameter
->kind
)
1265 case CALL_SITE_PARAMETER_DWARF_REG
:
1266 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1267 case CALL_SITE_PARAMETER_FB_OFFSET
:
1268 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1269 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1270 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1275 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1276 FRAME is for callee.
1278 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1281 static struct call_site_parameter
*
1282 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1283 enum call_site_parameter_kind kind
,
1284 union call_site_parameter_u kind_u
,
1285 struct dwarf2_per_cu_data
**per_cu_return
)
1287 CORE_ADDR func_addr
, caller_pc
;
1288 struct gdbarch
*gdbarch
;
1289 struct frame_info
*caller_frame
;
1290 struct call_site
*call_site
;
1292 /* Initialize it just to avoid a GCC false warning. */
1293 struct call_site_parameter
*parameter
= NULL
;
1294 CORE_ADDR target_addr
;
1296 while (get_frame_type (frame
) == INLINE_FRAME
)
1298 frame
= get_prev_frame (frame
);
1299 gdb_assert (frame
!= NULL
);
1302 func_addr
= get_frame_func (frame
);
1303 gdbarch
= get_frame_arch (frame
);
1304 caller_frame
= get_prev_frame (frame
);
1305 if (gdbarch
!= frame_unwind_arch (frame
))
1307 struct bound_minimal_symbol msym
1308 = lookup_minimal_symbol_by_pc (func_addr
);
1309 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1311 throw_error (NO_ENTRY_VALUE_ERROR
,
1312 _("DW_OP_entry_value resolving callee gdbarch %s "
1313 "(of %s (%s)) does not match caller gdbarch %s"),
1314 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1315 paddress (gdbarch
, func_addr
),
1316 (msym
.minsym
== NULL
? "???"
1317 : msym
.minsym
->print_name ()),
1318 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1321 if (caller_frame
== NULL
)
1323 struct bound_minimal_symbol msym
1324 = lookup_minimal_symbol_by_pc (func_addr
);
1326 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1327 "requires caller of %s (%s)"),
1328 paddress (gdbarch
, func_addr
),
1329 (msym
.minsym
== NULL
? "???"
1330 : msym
.minsym
->print_name ()));
1332 caller_pc
= get_frame_pc (caller_frame
);
1333 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1335 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1336 if (target_addr
!= func_addr
)
1338 struct minimal_symbol
*target_msym
, *func_msym
;
1340 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1341 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1342 throw_error (NO_ENTRY_VALUE_ERROR
,
1343 _("DW_OP_entry_value resolving expects callee %s at %s "
1344 "but the called frame is for %s at %s"),
1345 (target_msym
== NULL
? "???"
1346 : target_msym
->print_name ()),
1347 paddress (gdbarch
, target_addr
),
1348 func_msym
== NULL
? "???" : func_msym
->print_name (),
1349 paddress (gdbarch
, func_addr
));
1352 /* No entry value based parameters would be reliable if this function can
1353 call itself via tail calls. */
1354 func_verify_no_selftailcall (gdbarch
, func_addr
);
1356 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1358 parameter
= &call_site
->parameter
[iparams
];
1359 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1362 if (iparams
== call_site
->parameter_count
)
1364 struct minimal_symbol
*msym
1365 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1367 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1368 determine its value. */
1369 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1370 "at DW_TAG_call_site %s at %s"),
1371 paddress (gdbarch
, caller_pc
),
1372 msym
== NULL
? "???" : msym
->print_name ());
1375 *per_cu_return
= call_site
->per_cu
;
1379 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1380 the normal DW_AT_call_value block. Otherwise return the
1381 DW_AT_call_data_value (dereferenced) block.
1383 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1386 Function always returns non-NULL, non-optimized out value. It throws
1387 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1389 static struct value
*
1390 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1391 CORE_ADDR deref_size
, struct type
*type
,
1392 struct frame_info
*caller_frame
,
1393 struct dwarf2_per_cu_data
*per_cu
)
1395 const gdb_byte
*data_src
;
1399 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1400 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1402 /* DEREF_SIZE size is not verified here. */
1403 if (data_src
== NULL
)
1404 throw_error (NO_ENTRY_VALUE_ERROR
,
1405 _("Cannot resolve DW_AT_call_data_value"));
1407 /* DW_AT_call_value is a DWARF expression, not a DWARF
1408 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1410 data
= (gdb_byte
*) alloca (size
+ 1);
1411 memcpy (data
, data_src
, size
);
1412 data
[size
] = DW_OP_stack_value
;
1414 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1417 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1418 the indirect method on it, that is use its stored target value, the sole
1419 purpose of entry_data_value_funcs.. */
1421 static struct value
*
1422 entry_data_value_coerce_ref (const struct value
*value
)
1424 struct type
*checked_type
= check_typedef (value_type (value
));
1425 struct value
*target_val
;
1427 if (!TYPE_IS_REFERENCE (checked_type
))
1430 target_val
= (struct value
*) value_computed_closure (value
);
1431 value_incref (target_val
);
1435 /* Implement copy_closure. */
1438 entry_data_value_copy_closure (const struct value
*v
)
1440 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1442 value_incref (target_val
);
1446 /* Implement free_closure. */
1449 entry_data_value_free_closure (struct value
*v
)
1451 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1453 value_decref (target_val
);
1456 /* Vector for methods for an entry value reference where the referenced value
1457 is stored in the caller. On the first dereference use
1458 DW_AT_call_data_value in the caller. */
1460 static const struct lval_funcs entry_data_value_funcs
=
1464 NULL
, /* indirect */
1465 entry_data_value_coerce_ref
,
1466 NULL
, /* check_synthetic_pointer */
1467 entry_data_value_copy_closure
,
1468 entry_data_value_free_closure
1471 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1472 are used to match DW_AT_location at the caller's
1473 DW_TAG_call_site_parameter.
1475 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1476 cannot resolve the parameter for any reason. */
1478 static struct value
*
1479 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1480 enum call_site_parameter_kind kind
,
1481 union call_site_parameter_u kind_u
)
1483 struct type
*checked_type
= check_typedef (type
);
1484 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1485 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1486 struct value
*outer_val
, *target_val
, *val
;
1487 struct call_site_parameter
*parameter
;
1488 struct dwarf2_per_cu_data
*caller_per_cu
;
1490 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1493 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1497 /* Check if DW_AT_call_data_value cannot be used. If it should be
1498 used and it is not available do not fall back to OUTER_VAL - dereferencing
1499 TYPE_CODE_REF with non-entry data value would give current value - not the
1502 if (!TYPE_IS_REFERENCE (checked_type
)
1503 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1506 target_val
= dwarf_entry_parameter_to_value (parameter
,
1507 TYPE_LENGTH (target_type
),
1508 target_type
, caller_frame
,
1511 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1512 release_value (target_val
).release ());
1514 /* Copy the referencing pointer to the new computed value. */
1515 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1516 TYPE_LENGTH (checked_type
));
1517 set_value_lazy (val
, 0);
1522 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1523 SIZE are DWARF block used to match DW_AT_location at the caller's
1524 DW_TAG_call_site_parameter.
1526 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1527 cannot resolve the parameter for any reason. */
1529 static struct value
*
1530 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1531 const gdb_byte
*block
, size_t block_len
)
1533 union call_site_parameter_u kind_u
;
1535 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1536 if (kind_u
.dwarf_reg
!= -1)
1537 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1540 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1541 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1544 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1545 suppressed during normal operation. The expression can be arbitrary if
1546 there is no caller-callee entry value binding expected. */
1547 throw_error (NO_ENTRY_VALUE_ERROR
,
1548 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1549 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1552 struct piece_closure
1554 /* Reference count. */
1557 /* The objfile from which this closure's expression came. */
1558 dwarf2_per_objfile
*per_objfile
= nullptr;
1560 /* The CU from which this closure's expression came. */
1561 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1563 /* The pieces describing this variable. */
1564 std::vector
<dwarf_expr_piece
> pieces
;
1566 /* Frame ID of frame to which a register value is relative, used
1567 only by DWARF_VALUE_REGISTER. */
1568 struct frame_id frame_id
;
1571 /* Allocate a closure for a value formed from separately-described
1574 static struct piece_closure
*
1575 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1576 std::vector
<dwarf_expr_piece
> &&pieces
,
1577 struct frame_info
*frame
)
1579 struct piece_closure
*c
= new piece_closure
;
1582 /* We must capture this here due to sharing of DWARF state. */
1583 c
->per_objfile
= per_cu
->dwarf2_per_objfile
;
1585 c
->pieces
= std::move (pieces
);
1587 c
->frame_id
= null_frame_id
;
1589 c
->frame_id
= get_frame_id (frame
);
1591 for (dwarf_expr_piece
&piece
: c
->pieces
)
1592 if (piece
.location
== DWARF_VALUE_STACK
)
1593 value_incref (piece
.v
.value
);
1598 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1599 bits whose first bit is located at bit offset START. */
1602 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1604 return (start
% 8 + n_bits
+ 7) / 8;
1607 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1608 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1609 operate in "read mode": fetch the contents of the (lazy) value V by
1610 composing it from its pieces. */
1613 rw_pieced_value (struct value
*v
, struct value
*from
)
1616 LONGEST offset
= 0, max_offset
;
1617 ULONGEST bits_to_skip
;
1618 gdb_byte
*v_contents
;
1619 const gdb_byte
*from_contents
;
1620 struct piece_closure
*c
1621 = (struct piece_closure
*) value_computed_closure (v
);
1622 gdb::byte_vector buffer
;
1623 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1627 from_contents
= value_contents (from
);
1632 if (value_type (v
) != value_enclosing_type (v
))
1633 internal_error (__FILE__
, __LINE__
,
1634 _("Should not be able to create a lazy value with "
1635 "an enclosing type"));
1636 v_contents
= value_contents_raw (v
);
1637 from_contents
= NULL
;
1640 bits_to_skip
= 8 * value_offset (v
);
1641 if (value_bitsize (v
))
1643 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1644 + value_bitpos (v
));
1646 && (type_byte_order (value_type (from
))
1649 /* Use the least significant bits of FROM. */
1650 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1651 offset
= max_offset
- value_bitsize (v
);
1654 max_offset
= value_bitsize (v
);
1657 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1659 /* Advance to the first non-skipped piece. */
1660 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1661 bits_to_skip
-= c
->pieces
[i
].size
;
1663 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1665 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1666 size_t this_size_bits
, this_size
;
1668 this_size_bits
= p
->size
- bits_to_skip
;
1669 if (this_size_bits
> max_offset
- offset
)
1670 this_size_bits
= max_offset
- offset
;
1672 switch (p
->location
)
1674 case DWARF_VALUE_REGISTER
:
1676 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1677 struct gdbarch
*arch
= get_frame_arch (frame
);
1678 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1679 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1682 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1683 && p
->offset
+ p
->size
< reg_bits
)
1685 /* Big-endian, and we want less than full size. */
1686 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1689 bits_to_skip
+= p
->offset
;
1691 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1692 buffer
.resize (this_size
);
1697 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1699 this_size
, buffer
.data (),
1703 mark_value_bits_optimized_out (v
, offset
,
1706 mark_value_bits_unavailable (v
, offset
,
1711 copy_bitwise (v_contents
, offset
,
1712 buffer
.data (), bits_to_skip
% 8,
1713 this_size_bits
, bits_big_endian
);
1718 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1720 /* Data is copied non-byte-aligned into the register.
1721 Need some bits from original register value. */
1722 get_frame_register_bytes (frame
, gdb_regnum
,
1724 this_size
, buffer
.data (),
1727 throw_error (OPTIMIZED_OUT_ERROR
,
1728 _("Can't do read-modify-write to "
1729 "update bitfield; containing word "
1730 "has been optimized out"));
1732 throw_error (NOT_AVAILABLE_ERROR
,
1733 _("Can't do read-modify-write to "
1734 "update bitfield; containing word "
1738 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1739 from_contents
, offset
,
1740 this_size_bits
, bits_big_endian
);
1741 put_frame_register_bytes (frame
, gdb_regnum
,
1743 this_size
, buffer
.data ());
1748 case DWARF_VALUE_MEMORY
:
1750 bits_to_skip
+= p
->offset
;
1752 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1754 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1757 /* Everything is byte-aligned; no buffer needed. */
1759 write_memory_with_notification (start_addr
,
1762 this_size_bits
/ 8);
1764 read_value_memory (v
, offset
,
1765 p
->v
.mem
.in_stack_memory
,
1766 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1767 v_contents
+ offset
/ 8,
1768 this_size_bits
/ 8);
1772 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1773 buffer
.resize (this_size
);
1778 read_value_memory (v
, offset
,
1779 p
->v
.mem
.in_stack_memory
,
1780 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1781 buffer
.data (), this_size
);
1782 copy_bitwise (v_contents
, offset
,
1783 buffer
.data (), bits_to_skip
% 8,
1784 this_size_bits
, bits_big_endian
);
1789 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1793 /* Perform a single read for small sizes. */
1794 read_memory (start_addr
, buffer
.data (),
1799 /* Only the first and last bytes can possibly have
1801 read_memory (start_addr
, buffer
.data (), 1);
1802 read_memory (start_addr
+ this_size
- 1,
1803 &buffer
[this_size
- 1], 1);
1807 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1808 from_contents
, offset
,
1809 this_size_bits
, bits_big_endian
);
1810 write_memory_with_notification (start_addr
,
1817 case DWARF_VALUE_STACK
:
1821 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1825 struct objfile
*objfile
= c
->per_cu
->objfile ();
1826 struct gdbarch
*objfile_gdbarch
= objfile
->arch ();
1827 ULONGEST stack_value_size_bits
1828 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1830 /* Use zeroes if piece reaches beyond stack value. */
1831 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1834 /* Piece is anchored at least significant bit end. */
1835 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1836 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1838 bits_to_skip
+= p
->offset
;
1840 copy_bitwise (v_contents
, offset
,
1841 value_contents_all (p
->v
.value
),
1843 this_size_bits
, bits_big_endian
);
1847 case DWARF_VALUE_LITERAL
:
1851 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1855 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1856 size_t n
= this_size_bits
;
1858 /* Cut off at the end of the implicit value. */
1859 bits_to_skip
+= p
->offset
;
1860 if (bits_to_skip
>= literal_size_bits
)
1862 if (n
> literal_size_bits
- bits_to_skip
)
1863 n
= literal_size_bits
- bits_to_skip
;
1865 copy_bitwise (v_contents
, offset
,
1866 p
->v
.literal
.data
, bits_to_skip
,
1867 n
, bits_big_endian
);
1871 case DWARF_VALUE_IMPLICIT_POINTER
:
1874 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1878 /* These bits show up as zeros -- but do not cause the value to
1879 be considered optimized-out. */
1882 case DWARF_VALUE_OPTIMIZED_OUT
:
1883 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1887 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1890 offset
+= this_size_bits
;
1897 read_pieced_value (struct value
*v
)
1899 rw_pieced_value (v
, NULL
);
1903 write_pieced_value (struct value
*to
, struct value
*from
)
1905 rw_pieced_value (to
, from
);
1908 /* An implementation of an lval_funcs method to see whether a value is
1909 a synthetic pointer. */
1912 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1915 struct piece_closure
*c
1916 = (struct piece_closure
*) value_computed_closure (value
);
1919 bit_offset
+= 8 * value_offset (value
);
1920 if (value_bitsize (value
))
1921 bit_offset
+= value_bitpos (value
);
1923 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1925 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1926 size_t this_size_bits
= p
->size
;
1930 if (bit_offset
>= this_size_bits
)
1932 bit_offset
-= this_size_bits
;
1936 bit_length
-= this_size_bits
- bit_offset
;
1940 bit_length
-= this_size_bits
;
1942 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1949 /* A wrapper function for get_frame_address_in_block. */
1952 get_frame_address_in_block_wrapper (void *baton
)
1954 return get_frame_address_in_block ((struct frame_info
*) baton
);
1957 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1959 static struct value
*
1960 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1961 struct dwarf2_per_cu_data
*per_cu
,
1964 struct value
*result
= NULL
;
1965 const gdb_byte
*bytes
;
1968 auto_obstack temp_obstack
;
1969 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
1973 if (byte_offset
>= 0
1974 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1976 bytes
+= byte_offset
;
1977 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1980 invalid_synthetic_pointer ();
1983 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1988 /* Fetch the value pointed to by a synthetic pointer. */
1990 static struct value
*
1991 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1992 struct dwarf2_per_cu_data
*per_cu
,
1993 struct frame_info
*frame
, struct type
*type
,
1994 bool resolve_abstract_p
)
1996 /* Fetch the location expression of the DIE we're pointing to. */
1997 struct dwarf2_locexpr_baton baton
1998 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
1999 get_frame_address_in_block_wrapper
, frame
,
2000 resolve_abstract_p
);
2002 /* Get type of pointed-to DIE. */
2003 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
);
2004 if (orig_type
== NULL
)
2005 invalid_synthetic_pointer ();
2007 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2008 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2009 or it may've been optimized out. */
2010 if (baton
.data
!= NULL
)
2011 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2012 baton
.size
, baton
.per_cu
,
2013 TYPE_TARGET_TYPE (type
),
2016 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2020 /* An implementation of an lval_funcs method to indirect through a
2021 pointer. This handles the synthetic pointer case when needed. */
2023 static struct value
*
2024 indirect_pieced_value (struct value
*value
)
2026 struct piece_closure
*c
2027 = (struct piece_closure
*) value_computed_closure (value
);
2029 struct frame_info
*frame
;
2032 struct dwarf_expr_piece
*piece
= NULL
;
2033 LONGEST byte_offset
;
2034 enum bfd_endian byte_order
;
2036 type
= check_typedef (value_type (value
));
2037 if (type
->code () != TYPE_CODE_PTR
)
2040 bit_length
= 8 * TYPE_LENGTH (type
);
2041 bit_offset
= 8 * value_offset (value
);
2042 if (value_bitsize (value
))
2043 bit_offset
+= value_bitpos (value
);
2045 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2047 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2048 size_t this_size_bits
= p
->size
;
2052 if (bit_offset
>= this_size_bits
)
2054 bit_offset
-= this_size_bits
;
2058 bit_length
-= this_size_bits
- bit_offset
;
2062 bit_length
-= this_size_bits
;
2064 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2067 if (bit_length
!= 0)
2068 error (_("Invalid use of DW_OP_implicit_pointer"));
2074 gdb_assert (piece
!= NULL
);
2075 frame
= get_selected_frame (_("No frame selected."));
2077 /* This is an offset requested by GDB, such as value subscripts.
2078 However, due to how synthetic pointers are implemented, this is
2079 always presented to us as a pointer type. This means we have to
2080 sign-extend it manually as appropriate. Use raw
2081 extract_signed_integer directly rather than value_as_address and
2082 sign extend afterwards on architectures that would need it
2083 (mostly everywhere except MIPS, which has signed addresses) as
2084 the later would go through gdbarch_pointer_to_address and thus
2085 return a CORE_ADDR with high bits set on architectures that
2086 encode address spaces and other things in CORE_ADDR. */
2087 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2088 byte_offset
= extract_signed_integer (value_contents (value
),
2089 TYPE_LENGTH (type
), byte_order
);
2090 byte_offset
+= piece
->v
.ptr
.offset
;
2092 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2093 byte_offset
, c
->per_cu
,
2097 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2100 static struct value
*
2101 coerce_pieced_ref (const struct value
*value
)
2103 struct type
*type
= check_typedef (value_type (value
));
2105 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2106 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2108 const struct piece_closure
*closure
2109 = (struct piece_closure
*) value_computed_closure (value
);
2110 struct frame_info
*frame
2111 = get_selected_frame (_("No frame selected."));
2113 /* gdb represents synthetic pointers as pieced values with a single
2115 gdb_assert (closure
!= NULL
);
2116 gdb_assert (closure
->pieces
.size () == 1);
2118 return indirect_synthetic_pointer
2119 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2120 closure
->pieces
[0].v
.ptr
.offset
,
2121 closure
->per_cu
, frame
, type
);
2125 /* Else: not a synthetic reference; do nothing. */
2131 copy_pieced_value_closure (const struct value
*v
)
2133 struct piece_closure
*c
2134 = (struct piece_closure
*) value_computed_closure (v
);
2141 free_pieced_value_closure (struct value
*v
)
2143 struct piece_closure
*c
2144 = (struct piece_closure
*) value_computed_closure (v
);
2149 for (dwarf_expr_piece
&p
: c
->pieces
)
2150 if (p
.location
== DWARF_VALUE_STACK
)
2151 value_decref (p
.v
.value
);
2157 /* Functions for accessing a variable described by DW_OP_piece. */
2158 static const struct lval_funcs pieced_value_funcs
= {
2161 indirect_pieced_value
,
2163 check_pieced_synthetic_pointer
,
2164 copy_pieced_value_closure
,
2165 free_pieced_value_closure
2168 /* Evaluate a location description, starting at DATA and with length
2169 SIZE, to find the current location of variable of TYPE in the
2170 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2171 location of the subobject of type SUBOBJ_TYPE at byte offset
2172 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2174 static struct value
*
2175 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2176 const gdb_byte
*data
, size_t size
,
2177 struct dwarf2_per_cu_data
*per_cu
,
2178 struct type
*subobj_type
,
2179 LONGEST subobj_byte_offset
)
2181 struct value
*retval
;
2182 struct objfile
*objfile
= per_cu
->objfile ();
2184 if (subobj_type
== NULL
)
2187 subobj_byte_offset
= 0;
2189 else if (subobj_byte_offset
< 0)
2190 invalid_synthetic_pointer ();
2193 return allocate_optimized_out_value (subobj_type
);
2195 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2196 dwarf_evaluate_loc_desc
ctx (per_objfile
);
2198 ctx
.per_cu
= per_cu
;
2199 ctx
.obj_address
= 0;
2201 scoped_value_mark free_values
;
2203 ctx
.gdbarch
= objfile
->arch ();
2204 ctx
.addr_size
= per_cu
->addr_size ();
2205 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2209 ctx
.eval (data
, size
);
2211 catch (const gdb_exception_error
&ex
)
2213 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2215 free_values
.free_to_mark ();
2216 retval
= allocate_value (subobj_type
);
2217 mark_value_bytes_unavailable (retval
, 0,
2218 TYPE_LENGTH (subobj_type
));
2221 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2223 if (entry_values_debug
)
2224 exception_print (gdb_stdout
, ex
);
2225 free_values
.free_to_mark ();
2226 return allocate_optimized_out_value (subobj_type
);
2232 if (ctx
.pieces
.size () > 0)
2234 struct piece_closure
*c
;
2235 ULONGEST bit_size
= 0;
2237 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2238 bit_size
+= piece
.size
;
2239 /* Complain if the expression is larger than the size of the
2241 if (bit_size
> 8 * TYPE_LENGTH (type
))
2242 invalid_synthetic_pointer ();
2244 c
= allocate_piece_closure (per_cu
, std::move (ctx
.pieces
), frame
);
2245 /* We must clean up the value chain after creating the piece
2246 closure but before allocating the result. */
2247 free_values
.free_to_mark ();
2248 retval
= allocate_computed_value (subobj_type
,
2249 &pieced_value_funcs
, c
);
2250 set_value_offset (retval
, subobj_byte_offset
);
2254 switch (ctx
.location
)
2256 case DWARF_VALUE_REGISTER
:
2258 struct gdbarch
*arch
= get_frame_arch (frame
);
2260 = longest_to_int (value_as_long (ctx
.fetch (0)));
2261 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2263 if (subobj_byte_offset
!= 0)
2264 error (_("cannot use offset on synthetic pointer to register"));
2265 free_values
.free_to_mark ();
2266 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2267 if (value_optimized_out (retval
))
2271 /* This means the register has undefined value / was
2272 not saved. As we're computing the location of some
2273 variable etc. in the program, not a value for
2274 inspecting a register ($pc, $sp, etc.), return a
2275 generic optimized out value instead, so that we show
2276 <optimized out> instead of <not saved>. */
2277 tmp
= allocate_value (subobj_type
);
2278 value_contents_copy (tmp
, 0, retval
, 0,
2279 TYPE_LENGTH (subobj_type
));
2285 case DWARF_VALUE_MEMORY
:
2287 struct type
*ptr_type
;
2288 CORE_ADDR address
= ctx
.fetch_address (0);
2289 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2291 /* DW_OP_deref_size (and possibly other operations too) may
2292 create a pointer instead of an address. Ideally, the
2293 pointer to address conversion would be performed as part
2294 of those operations, but the type of the object to
2295 which the address refers is not known at the time of
2296 the operation. Therefore, we do the conversion here
2297 since the type is readily available. */
2299 switch (subobj_type
->code ())
2301 case TYPE_CODE_FUNC
:
2302 case TYPE_CODE_METHOD
:
2303 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2306 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2309 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2311 free_values
.free_to_mark ();
2312 retval
= value_at_lazy (subobj_type
,
2313 address
+ subobj_byte_offset
);
2314 if (in_stack_memory
)
2315 set_value_stack (retval
, 1);
2319 case DWARF_VALUE_STACK
:
2321 struct value
*value
= ctx
.fetch (0);
2322 size_t n
= TYPE_LENGTH (value_type (value
));
2323 size_t len
= TYPE_LENGTH (subobj_type
);
2324 size_t max
= TYPE_LENGTH (type
);
2325 struct gdbarch
*objfile_gdbarch
= objfile
->arch ();
2327 if (subobj_byte_offset
+ len
> max
)
2328 invalid_synthetic_pointer ();
2330 /* Preserve VALUE because we are going to free values back
2331 to the mark, but we still need the value contents
2333 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2334 free_values
.free_to_mark ();
2336 retval
= allocate_value (subobj_type
);
2338 /* The given offset is relative to the actual object. */
2339 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2340 subobj_byte_offset
+= n
- max
;
2342 memcpy (value_contents_raw (retval
),
2343 value_contents_all (value
) + subobj_byte_offset
, len
);
2347 case DWARF_VALUE_LITERAL
:
2350 size_t n
= TYPE_LENGTH (subobj_type
);
2352 if (subobj_byte_offset
+ n
> ctx
.len
)
2353 invalid_synthetic_pointer ();
2355 free_values
.free_to_mark ();
2356 retval
= allocate_value (subobj_type
);
2357 contents
= value_contents_raw (retval
);
2358 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2362 case DWARF_VALUE_OPTIMIZED_OUT
:
2363 free_values
.free_to_mark ();
2364 retval
= allocate_optimized_out_value (subobj_type
);
2367 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2368 operation by execute_stack_op. */
2369 case DWARF_VALUE_IMPLICIT_POINTER
:
2370 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2371 it can only be encountered when making a piece. */
2373 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2377 set_value_initialized (retval
, ctx
.initialized
);
2382 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2383 passes 0 as the byte_offset. */
2386 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2387 const gdb_byte
*data
, size_t size
,
2388 struct dwarf2_per_cu_data
*per_cu
)
2390 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2394 /* A specialization of dwarf_evaluate_loc_desc that is used by
2395 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2396 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2397 but with the address being 0. In this situation, we arrange for
2398 memory reads to come from the passed-in buffer. */
2400 struct evaluate_for_locexpr_baton
: public dwarf_evaluate_loc_desc
2402 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2403 : dwarf_evaluate_loc_desc (per_objfile
)
2406 /* The data that was passed in. */
2407 gdb::array_view
<const gdb_byte
> data_view
;
2409 CORE_ADDR
get_object_address () override
2411 if (data_view
.data () == nullptr && obj_address
== 0)
2412 error (_("Location address is not set."));
2416 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2421 /* Prefer the passed-in memory, if it exists. */
2422 CORE_ADDR offset
= addr
- obj_address
;
2423 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2425 memcpy (buf
, data_view
.data (), len
);
2429 read_memory (addr
, buf
, len
);
2433 /* Evaluates a dwarf expression and stores the result in VAL,
2434 expecting that the dwarf expression only produces a single
2435 CORE_ADDR. FRAME is the frame in which the expression is
2436 evaluated. ADDR_STACK is a context (location of a variable) and
2437 might be needed to evaluate the location expression.
2438 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2439 or the default of 0) should be pushed on the DWARF expression
2440 evaluation stack before evaluating the expression; this is required
2441 by certain forms of DWARF expression. Returns 1 on success, 0
2445 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2446 struct frame_info
*frame
,
2447 const struct property_addr_info
*addr_stack
,
2449 bool push_initial_value
)
2451 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2454 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2455 evaluate_for_locexpr_baton
ctx (per_objfile
);
2458 ctx
.per_cu
= dlbaton
->per_cu
;
2459 if (addr_stack
== nullptr)
2460 ctx
.obj_address
= 0;
2463 ctx
.obj_address
= addr_stack
->addr
;
2464 ctx
.data_view
= addr_stack
->valaddr
;
2467 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2468 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2469 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2471 if (push_initial_value
)
2472 ctx
.push_address (ctx
.obj_address
, false);
2476 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2478 catch (const gdb_exception_error
&ex
)
2480 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2484 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2486 if (entry_values_debug
)
2487 exception_print (gdb_stdout
, ex
);
2494 switch (ctx
.location
)
2496 case DWARF_VALUE_REGISTER
:
2497 case DWARF_VALUE_MEMORY
:
2498 case DWARF_VALUE_STACK
:
2499 *valp
= ctx
.fetch_address (0);
2500 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2501 *valp
= ctx
.read_addr_from_reg (*valp
);
2503 case DWARF_VALUE_LITERAL
:
2504 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2505 gdbarch_byte_order (ctx
.gdbarch
));
2507 /* Unsupported dwarf values. */
2508 case DWARF_VALUE_OPTIMIZED_OUT
:
2509 case DWARF_VALUE_IMPLICIT_POINTER
:
2516 /* See dwarf2loc.h. */
2519 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2520 struct frame_info
*frame
,
2521 const struct property_addr_info
*addr_stack
,
2523 bool push_initial_value
)
2528 if (frame
== NULL
&& has_stack_frames ())
2529 frame
= get_selected_frame (NULL
);
2535 const struct dwarf2_property_baton
*baton
2536 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2537 gdb_assert (baton
->property_type
!= NULL
);
2539 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2540 value
, push_initial_value
))
2542 if (baton
->locexpr
.is_reference
)
2544 struct value
*val
= value_at (baton
->property_type
, *value
);
2545 *value
= value_as_address (val
);
2549 gdb_assert (baton
->property_type
!= NULL
);
2551 struct type
*type
= check_typedef (baton
->property_type
);
2552 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2553 && !TYPE_UNSIGNED (type
))
2555 /* If we have a valid return candidate and it's value
2556 is signed, we have to sign-extend the value because
2557 CORE_ADDR on 64bit machine has 8 bytes but address
2558 size of an 32bit application is bytes. */
2560 = (baton
->locexpr
.per_cu
->addr_size ()
2562 const CORE_ADDR neg_mask
2563 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2565 /* Check if signed bit is set and sign-extend values. */
2566 if (*value
& neg_mask
)
2577 struct dwarf2_property_baton
*baton
2578 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2580 const gdb_byte
*data
;
2585 || !get_frame_address_in_block_if_available (frame
, &pc
))
2588 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2591 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2592 size
, baton
->loclist
.per_cu
);
2593 if (!value_optimized_out (val
))
2595 *value
= value_as_address (val
);
2603 *value
= prop
->data
.const_val
;
2606 case PROP_ADDR_OFFSET
:
2608 struct dwarf2_property_baton
*baton
2609 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2610 const struct property_addr_info
*pinfo
;
2613 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2615 /* This approach lets us avoid checking the qualifiers. */
2616 if (TYPE_MAIN_TYPE (pinfo
->type
)
2617 == TYPE_MAIN_TYPE (baton
->property_type
))
2621 error (_("cannot find reference address for offset property"));
2622 if (pinfo
->valaddr
.data () != NULL
)
2623 val
= value_from_contents
2624 (baton
->offset_info
.type
,
2625 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2627 val
= value_at (baton
->offset_info
.type
,
2628 pinfo
->addr
+ baton
->offset_info
.offset
);
2629 *value
= value_as_address (val
);
2637 /* See dwarf2loc.h. */
2640 dwarf2_compile_property_to_c (string_file
*stream
,
2641 const char *result_name
,
2642 struct gdbarch
*gdbarch
,
2643 unsigned char *registers_used
,
2644 const struct dynamic_prop
*prop
,
2648 struct dwarf2_property_baton
*baton
2649 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2650 const gdb_byte
*data
;
2652 struct dwarf2_per_cu_data
*per_cu
;
2654 if (prop
->kind
== PROP_LOCEXPR
)
2656 data
= baton
->locexpr
.data
;
2657 size
= baton
->locexpr
.size
;
2658 per_cu
= baton
->locexpr
.per_cu
;
2662 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2664 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2665 per_cu
= baton
->loclist
.per_cu
;
2668 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2669 gdbarch
, registers_used
,
2670 per_cu
->addr_size (),
2671 data
, data
+ size
, per_cu
);
2675 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2677 class symbol_needs_eval_context
: public dwarf_expr_context
2680 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2681 : dwarf_expr_context (per_objfile
)
2684 enum symbol_needs_kind needs
;
2685 struct dwarf2_per_cu_data
*per_cu
;
2687 /* Reads from registers do require a frame. */
2688 CORE_ADDR
read_addr_from_reg (int regnum
) override
2690 needs
= SYMBOL_NEEDS_FRAME
;
2694 /* "get_reg_value" callback: Reads from registers do require a
2697 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2699 needs
= SYMBOL_NEEDS_FRAME
;
2700 return value_zero (type
, not_lval
);
2703 /* Reads from memory do not require a frame. */
2704 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2706 memset (buf
, 0, len
);
2709 /* Frame-relative accesses do require a frame. */
2710 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2712 static gdb_byte lit0
= DW_OP_lit0
;
2717 needs
= SYMBOL_NEEDS_FRAME
;
2720 /* CFA accesses require a frame. */
2721 CORE_ADDR
get_frame_cfa () override
2723 needs
= SYMBOL_NEEDS_FRAME
;
2727 CORE_ADDR
get_frame_pc () override
2729 needs
= SYMBOL_NEEDS_FRAME
;
2733 /* Thread-local accesses require registers, but not a frame. */
2734 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2736 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2737 needs
= SYMBOL_NEEDS_REGISTERS
;
2741 /* Helper interface of per_cu_dwarf_call for
2742 dwarf2_loc_desc_get_symbol_read_needs. */
2744 void dwarf_call (cu_offset die_offset
) override
2746 per_cu_dwarf_call (this, die_offset
, per_cu
);
2749 /* Helper interface of sect_variable_value for
2750 dwarf2_loc_desc_get_symbol_read_needs. */
2752 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2754 return sect_variable_value (this, sect_off
, per_cu
);
2757 /* DW_OP_entry_value accesses require a caller, therefore a
2760 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2761 union call_site_parameter_u kind_u
,
2762 int deref_size
) override
2764 needs
= SYMBOL_NEEDS_FRAME
;
2766 /* The expression may require some stub values on DWARF stack. */
2767 push_address (0, 0);
2770 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2772 CORE_ADDR
get_addr_index (unsigned int index
) override
2774 /* Nothing to do. */
2778 /* DW_OP_push_object_address has a frame already passed through. */
2780 CORE_ADDR
get_object_address () override
2782 /* Nothing to do. */
2787 /* Compute the correct symbol_needs_kind value for the location
2788 expression at DATA (length SIZE). */
2790 static enum symbol_needs_kind
2791 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2792 struct dwarf2_per_cu_data
*per_cu
)
2795 struct objfile
*objfile
= per_cu
->objfile ();
2797 scoped_value_mark free_values
;
2799 symbol_needs_eval_context
ctx (get_dwarf2_per_objfile (objfile
));
2801 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2802 ctx
.per_cu
= per_cu
;
2803 ctx
.gdbarch
= objfile
->arch ();
2804 ctx
.addr_size
= per_cu
->addr_size ();
2805 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2807 ctx
.eval (data
, size
);
2809 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2811 /* If the location has several pieces, and any of them are in
2812 registers, then we will need a frame to fetch them from. */
2813 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2814 if (p
.location
== DWARF_VALUE_REGISTER
)
2818 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2822 /* A helper function that throws an unimplemented error mentioning a
2823 given DWARF operator. */
2825 static void ATTRIBUTE_NORETURN
2826 unimplemented (unsigned int op
)
2828 const char *name
= get_DW_OP_name (op
);
2831 error (_("DWARF operator %s cannot be translated to an agent expression"),
2834 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2835 "to an agent expression"),
2841 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2842 can issue a complaint, which is better than having every target's
2843 implementation of dwarf2_reg_to_regnum do it. */
2846 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2848 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2852 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2857 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2858 Throw an error because DWARF_REG is bad. */
2861 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2863 /* Still want to print -1 as "-1".
2864 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2865 but that's overkill for now. */
2866 if ((int) dwarf_reg
== dwarf_reg
)
2867 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2868 error (_("Unable to access DWARF register number %s"),
2869 pulongest (dwarf_reg
));
2872 /* See dwarf2loc.h. */
2875 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2879 if (dwarf_reg
> INT_MAX
)
2880 throw_bad_regnum_error (dwarf_reg
);
2881 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2882 bad, but that's ok. */
2883 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2885 throw_bad_regnum_error (dwarf_reg
);
2889 /* A helper function that emits an access to memory. ARCH is the
2890 target architecture. EXPR is the expression which we are building.
2891 NBITS is the number of bits we want to read. This emits the
2892 opcodes needed to read the memory and then extract the desired
2896 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2898 ULONGEST nbytes
= (nbits
+ 7) / 8;
2900 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2903 ax_trace_quick (expr
, nbytes
);
2906 ax_simple (expr
, aop_ref8
);
2907 else if (nbits
<= 16)
2908 ax_simple (expr
, aop_ref16
);
2909 else if (nbits
<= 32)
2910 ax_simple (expr
, aop_ref32
);
2912 ax_simple (expr
, aop_ref64
);
2914 /* If we read exactly the number of bytes we wanted, we're done. */
2915 if (8 * nbytes
== nbits
)
2918 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2920 /* On a bits-big-endian machine, we want the high-order
2922 ax_const_l (expr
, 8 * nbytes
- nbits
);
2923 ax_simple (expr
, aop_rsh_unsigned
);
2927 /* On a bits-little-endian box, we want the low-order NBITS. */
2928 ax_zero_ext (expr
, nbits
);
2932 /* A helper function to return the frame's PC. */
2935 get_ax_pc (void *baton
)
2937 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
2942 /* Compile a DWARF location expression to an agent expression.
2944 EXPR is the agent expression we are building.
2945 LOC is the agent value we modify.
2946 ARCH is the architecture.
2947 ADDR_SIZE is the size of addresses, in bytes.
2948 OP_PTR is the start of the location expression.
2949 OP_END is one past the last byte of the location expression.
2951 This will throw an exception for various kinds of errors -- for
2952 example, if the expression cannot be compiled, or if the expression
2956 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2957 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2958 const gdb_byte
*op_end
,
2959 struct dwarf2_per_cu_data
*per_cu
)
2961 gdbarch
*arch
= expr
->gdbarch
;
2962 std::vector
<int> dw_labels
, patches
;
2963 const gdb_byte
* const base
= op_ptr
;
2964 const gdb_byte
*previous_piece
= op_ptr
;
2965 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2966 ULONGEST bits_collected
= 0;
2967 unsigned int addr_size_bits
= 8 * addr_size
;
2968 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2970 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2972 /* By default we are making an address. */
2973 loc
->kind
= axs_lvalue_memory
;
2975 while (op_ptr
< op_end
)
2977 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2978 uint64_t uoffset
, reg
;
2982 offsets
[op_ptr
- base
] = expr
->len
;
2985 /* Our basic approach to code generation is to map DWARF
2986 operations directly to AX operations. However, there are
2989 First, DWARF works on address-sized units, but AX always uses
2990 LONGEST. For most operations we simply ignore this
2991 difference; instead we generate sign extensions as needed
2992 before division and comparison operations. It would be nice
2993 to omit the sign extensions, but there is no way to determine
2994 the size of the target's LONGEST. (This code uses the size
2995 of the host LONGEST in some cases -- that is a bug but it is
2998 Second, some DWARF operations cannot be translated to AX.
2999 For these we simply fail. See
3000 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3035 ax_const_l (expr
, op
- DW_OP_lit0
);
3039 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3040 op_ptr
+= addr_size
;
3041 /* Some versions of GCC emit DW_OP_addr before
3042 DW_OP_GNU_push_tls_address. In this case the value is an
3043 index, not an address. We don't support things like
3044 branching between the address and the TLS op. */
3045 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3046 uoffset
+= per_cu
->text_offset ();
3047 ax_const_l (expr
, uoffset
);
3051 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3055 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3059 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3063 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3067 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3071 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3075 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3079 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3083 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3084 ax_const_l (expr
, uoffset
);
3087 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3088 ax_const_l (expr
, offset
);
3123 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3124 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3125 loc
->kind
= axs_lvalue_register
;
3129 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3130 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3131 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3132 loc
->kind
= axs_lvalue_register
;
3135 case DW_OP_implicit_value
:
3139 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3140 if (op_ptr
+ len
> op_end
)
3141 error (_("DW_OP_implicit_value: too few bytes available."));
3142 if (len
> sizeof (ULONGEST
))
3143 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3146 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3149 dwarf_expr_require_composition (op_ptr
, op_end
,
3150 "DW_OP_implicit_value");
3152 loc
->kind
= axs_rvalue
;
3156 case DW_OP_stack_value
:
3157 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3158 loc
->kind
= axs_rvalue
;
3193 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3194 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3198 ax_const_l (expr
, offset
);
3199 ax_simple (expr
, aop_add
);
3204 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3205 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3206 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3210 ax_const_l (expr
, offset
);
3211 ax_simple (expr
, aop_add
);
3217 const gdb_byte
*datastart
;
3219 const struct block
*b
;
3220 struct symbol
*framefunc
;
3222 b
= block_for_pc (expr
->scope
);
3225 error (_("No block found for address"));
3227 framefunc
= block_linkage_function (b
);
3230 error (_("No function found for block"));
3232 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3233 &datastart
, &datalen
);
3235 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3236 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3237 datastart
+ datalen
, per_cu
);
3238 if (loc
->kind
== axs_lvalue_register
)
3239 require_rvalue (expr
, loc
);
3243 ax_const_l (expr
, offset
);
3244 ax_simple (expr
, aop_add
);
3247 loc
->kind
= axs_lvalue_memory
;
3252 ax_simple (expr
, aop_dup
);
3256 ax_simple (expr
, aop_pop
);
3261 ax_pick (expr
, offset
);
3265 ax_simple (expr
, aop_swap
);
3273 ax_simple (expr
, aop_rot
);
3277 case DW_OP_deref_size
:
3281 if (op
== DW_OP_deref_size
)
3286 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3287 error (_("Unsupported size %d in %s"),
3288 size
, get_DW_OP_name (op
));
3289 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3294 /* Sign extend the operand. */
3295 ax_ext (expr
, addr_size_bits
);
3296 ax_simple (expr
, aop_dup
);
3297 ax_const_l (expr
, 0);
3298 ax_simple (expr
, aop_less_signed
);
3299 ax_simple (expr
, aop_log_not
);
3300 i
= ax_goto (expr
, aop_if_goto
);
3301 /* We have to emit 0 - X. */
3302 ax_const_l (expr
, 0);
3303 ax_simple (expr
, aop_swap
);
3304 ax_simple (expr
, aop_sub
);
3305 ax_label (expr
, i
, expr
->len
);
3309 /* No need to sign extend here. */
3310 ax_const_l (expr
, 0);
3311 ax_simple (expr
, aop_swap
);
3312 ax_simple (expr
, aop_sub
);
3316 /* Sign extend the operand. */
3317 ax_ext (expr
, addr_size_bits
);
3318 ax_simple (expr
, aop_bit_not
);
3321 case DW_OP_plus_uconst
:
3322 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3323 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3324 but we micro-optimize anyhow. */
3327 ax_const_l (expr
, reg
);
3328 ax_simple (expr
, aop_add
);
3333 ax_simple (expr
, aop_bit_and
);
3337 /* Sign extend the operands. */
3338 ax_ext (expr
, addr_size_bits
);
3339 ax_simple (expr
, aop_swap
);
3340 ax_ext (expr
, addr_size_bits
);
3341 ax_simple (expr
, aop_swap
);
3342 ax_simple (expr
, aop_div_signed
);
3346 ax_simple (expr
, aop_sub
);
3350 ax_simple (expr
, aop_rem_unsigned
);
3354 ax_simple (expr
, aop_mul
);
3358 ax_simple (expr
, aop_bit_or
);
3362 ax_simple (expr
, aop_add
);
3366 ax_simple (expr
, aop_lsh
);
3370 ax_simple (expr
, aop_rsh_unsigned
);
3374 ax_simple (expr
, aop_rsh_signed
);
3378 ax_simple (expr
, aop_bit_xor
);
3382 /* Sign extend the operands. */
3383 ax_ext (expr
, addr_size_bits
);
3384 ax_simple (expr
, aop_swap
);
3385 ax_ext (expr
, addr_size_bits
);
3386 /* Note no swap here: A <= B is !(B < A). */
3387 ax_simple (expr
, aop_less_signed
);
3388 ax_simple (expr
, aop_log_not
);
3392 /* Sign extend the operands. */
3393 ax_ext (expr
, addr_size_bits
);
3394 ax_simple (expr
, aop_swap
);
3395 ax_ext (expr
, addr_size_bits
);
3396 ax_simple (expr
, aop_swap
);
3397 /* A >= B is !(A < B). */
3398 ax_simple (expr
, aop_less_signed
);
3399 ax_simple (expr
, aop_log_not
);
3403 /* Sign extend the operands. */
3404 ax_ext (expr
, addr_size_bits
);
3405 ax_simple (expr
, aop_swap
);
3406 ax_ext (expr
, addr_size_bits
);
3407 /* No need for a second swap here. */
3408 ax_simple (expr
, aop_equal
);
3412 /* Sign extend the operands. */
3413 ax_ext (expr
, addr_size_bits
);
3414 ax_simple (expr
, aop_swap
);
3415 ax_ext (expr
, addr_size_bits
);
3416 ax_simple (expr
, aop_swap
);
3417 ax_simple (expr
, aop_less_signed
);
3421 /* Sign extend the operands. */
3422 ax_ext (expr
, addr_size_bits
);
3423 ax_simple (expr
, aop_swap
);
3424 ax_ext (expr
, addr_size_bits
);
3425 /* Note no swap here: A > B is B < A. */
3426 ax_simple (expr
, aop_less_signed
);
3430 /* Sign extend the operands. */
3431 ax_ext (expr
, addr_size_bits
);
3432 ax_simple (expr
, aop_swap
);
3433 ax_ext (expr
, addr_size_bits
);
3434 /* No need for a swap here. */
3435 ax_simple (expr
, aop_equal
);
3436 ax_simple (expr
, aop_log_not
);
3439 case DW_OP_call_frame_cfa
:
3442 CORE_ADDR text_offset
;
3444 const gdb_byte
*cfa_start
, *cfa_end
;
3446 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3448 &text_offset
, &cfa_start
, &cfa_end
))
3451 ax_reg (expr
, regnum
);
3454 ax_const_l (expr
, off
);
3455 ax_simple (expr
, aop_add
);
3460 /* Another expression. */
3461 ax_const_l (expr
, text_offset
);
3462 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3466 loc
->kind
= axs_lvalue_memory
;
3470 case DW_OP_GNU_push_tls_address
:
3471 case DW_OP_form_tls_address
:
3475 case DW_OP_push_object_address
:
3480 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3482 i
= ax_goto (expr
, aop_goto
);
3483 dw_labels
.push_back (op_ptr
+ offset
- base
);
3484 patches
.push_back (i
);
3488 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3490 /* Zero extend the operand. */
3491 ax_zero_ext (expr
, addr_size_bits
);
3492 i
= ax_goto (expr
, aop_if_goto
);
3493 dw_labels
.push_back (op_ptr
+ offset
- base
);
3494 patches
.push_back (i
);
3501 case DW_OP_bit_piece
:
3505 if (op_ptr
- 1 == previous_piece
)
3506 error (_("Cannot translate empty pieces to agent expressions"));
3507 previous_piece
= op_ptr
- 1;
3509 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3510 if (op
== DW_OP_piece
)
3516 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3518 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3519 error (_("Expression pieces exceed word size"));
3521 /* Access the bits. */
3524 case axs_lvalue_register
:
3525 ax_reg (expr
, loc
->u
.reg
);
3528 case axs_lvalue_memory
:
3529 /* Offset the pointer, if needed. */
3532 ax_const_l (expr
, uoffset
/ 8);
3533 ax_simple (expr
, aop_add
);
3536 access_memory (arch
, expr
, size
);
3540 /* For a bits-big-endian target, shift up what we already
3541 have. For a bits-little-endian target, shift up the
3542 new data. Note that there is a potential bug here if
3543 the DWARF expression leaves multiple values on the
3545 if (bits_collected
> 0)
3547 if (bits_big_endian
)
3549 ax_simple (expr
, aop_swap
);
3550 ax_const_l (expr
, size
);
3551 ax_simple (expr
, aop_lsh
);
3552 /* We don't need a second swap here, because
3553 aop_bit_or is symmetric. */
3557 ax_const_l (expr
, size
);
3558 ax_simple (expr
, aop_lsh
);
3560 ax_simple (expr
, aop_bit_or
);
3563 bits_collected
+= size
;
3564 loc
->kind
= axs_rvalue
;
3568 case DW_OP_GNU_uninit
:
3574 struct dwarf2_locexpr_baton block
;
3575 int size
= (op
== DW_OP_call2
? 2 : 4);
3577 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3580 cu_offset cuoffset
= (cu_offset
) uoffset
;
3581 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
,
3584 /* DW_OP_call_ref is currently not supported. */
3585 gdb_assert (block
.per_cu
== per_cu
);
3587 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3588 block
.data
+ block
.size
, per_cu
);
3592 case DW_OP_call_ref
:
3595 case DW_OP_GNU_variable_value
:
3603 /* Patch all the branches we emitted. */
3604 for (int i
= 0; i
< patches
.size (); ++i
)
3606 int targ
= offsets
[dw_labels
[i
]];
3608 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3609 ax_label (expr
, patches
[i
], targ
);
3614 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3615 evaluator to calculate the location. */
3616 static struct value
*
3617 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3619 struct dwarf2_locexpr_baton
*dlbaton
3620 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3623 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3624 dlbaton
->size
, dlbaton
->per_cu
);
3629 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3630 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3633 static struct value
*
3634 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3636 struct dwarf2_locexpr_baton
*dlbaton
3637 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3639 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3643 /* Implementation of get_symbol_read_needs from
3644 symbol_computed_ops. */
3646 static enum symbol_needs_kind
3647 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3649 struct dwarf2_locexpr_baton
*dlbaton
3650 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3652 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3656 /* Return true if DATA points to the end of a piece. END is one past
3657 the last byte in the expression. */
3660 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3662 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3665 /* Helper for locexpr_describe_location_piece that finds the name of a
3669 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3673 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3674 We'd rather print *something* here than throw an error. */
3675 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3676 /* gdbarch_register_name may just return "", return something more
3677 descriptive for bad register numbers. */
3680 /* The text is output as "$bad_register_number".
3681 That is why we use the underscores. */
3682 return _("bad_register_number");
3684 return gdbarch_register_name (gdbarch
, regnum
);
3687 /* Nicely describe a single piece of a location, returning an updated
3688 position in the bytecode sequence. This function cannot recognize
3689 all locations; if a location is not recognized, it simply returns
3690 DATA. If there is an error during reading, e.g. we run off the end
3691 of the buffer, an error is thrown. */
3693 static const gdb_byte
*
3694 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3695 CORE_ADDR addr
, struct objfile
*objfile
,
3696 struct dwarf2_per_cu_data
*per_cu
,
3697 const gdb_byte
*data
, const gdb_byte
*end
,
3698 unsigned int addr_size
)
3700 struct gdbarch
*gdbarch
= objfile
->arch ();
3703 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3705 fprintf_filtered (stream
, _("a variable in $%s"),
3706 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3709 else if (data
[0] == DW_OP_regx
)
3713 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3714 fprintf_filtered (stream
, _("a variable in $%s"),
3715 locexpr_regname (gdbarch
, reg
));
3717 else if (data
[0] == DW_OP_fbreg
)
3719 const struct block
*b
;
3720 struct symbol
*framefunc
;
3722 int64_t frame_offset
;
3723 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3725 int64_t base_offset
= 0;
3727 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3728 if (!piece_end_p (new_data
, end
))
3732 b
= block_for_pc (addr
);
3735 error (_("No block found for address for symbol \"%s\"."),
3736 symbol
->print_name ());
3738 framefunc
= block_linkage_function (b
);
3741 error (_("No function found for block for symbol \"%s\"."),
3742 symbol
->print_name ());
3744 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3746 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3748 const gdb_byte
*buf_end
;
3750 frame_reg
= base_data
[0] - DW_OP_breg0
;
3751 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3753 if (buf_end
!= base_data
+ base_size
)
3754 error (_("Unexpected opcode after "
3755 "DW_OP_breg%u for symbol \"%s\"."),
3756 frame_reg
, symbol
->print_name ());
3758 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3760 /* The frame base is just the register, with no offset. */
3761 frame_reg
= base_data
[0] - DW_OP_reg0
;
3766 /* We don't know what to do with the frame base expression,
3767 so we can't trace this variable; give up. */
3771 fprintf_filtered (stream
,
3772 _("a variable at frame base reg $%s offset %s+%s"),
3773 locexpr_regname (gdbarch
, frame_reg
),
3774 plongest (base_offset
), plongest (frame_offset
));
3776 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3777 && piece_end_p (data
, end
))
3781 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3783 fprintf_filtered (stream
,
3784 _("a variable at offset %s from base reg $%s"),
3786 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3789 /* The location expression for a TLS variable looks like this (on a
3792 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3793 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3795 0x3 is the encoding for DW_OP_addr, which has an operand as long
3796 as the size of an address on the target machine (here is 8
3797 bytes). Note that more recent version of GCC emit DW_OP_const4u
3798 or DW_OP_const8u, depending on address size, rather than
3799 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3800 The operand represents the offset at which the variable is within
3801 the thread local storage. */
3803 else if (data
+ 1 + addr_size
< end
3804 && (data
[0] == DW_OP_addr
3805 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3806 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3807 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3808 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3809 && piece_end_p (data
+ 2 + addr_size
, end
))
3812 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3813 gdbarch_byte_order (gdbarch
));
3815 fprintf_filtered (stream
,
3816 _("a thread-local variable at offset 0x%s "
3817 "in the thread-local storage for `%s'"),
3818 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3820 data
+= 1 + addr_size
+ 1;
3823 /* With -gsplit-dwarf a TLS variable can also look like this:
3824 DW_AT_location : 3 byte block: fc 4 e0
3825 (DW_OP_GNU_const_index: 4;
3826 DW_OP_GNU_push_tls_address) */
3827 else if (data
+ 3 <= end
3828 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3829 && data
[0] == DW_OP_GNU_const_index
3831 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3832 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3833 && piece_end_p (data
+ 2 + leb128_size
, end
))
3837 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3838 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3839 fprintf_filtered (stream
,
3840 _("a thread-local variable at offset 0x%s "
3841 "in the thread-local storage for `%s'"),
3842 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3846 else if (data
[0] >= DW_OP_lit0
3847 && data
[0] <= DW_OP_lit31
3849 && data
[1] == DW_OP_stack_value
)
3851 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3858 /* Disassemble an expression, stopping at the end of a piece or at the
3859 end of the expression. Returns a pointer to the next unread byte
3860 in the input expression. If ALL is nonzero, then this function
3861 will keep going until it reaches the end of the expression.
3862 If there is an error during reading, e.g. we run off the end
3863 of the buffer, an error is thrown. */
3865 static const gdb_byte
*
3866 disassemble_dwarf_expression (struct ui_file
*stream
,
3867 struct gdbarch
*arch
, unsigned int addr_size
,
3868 int offset_size
, const gdb_byte
*start
,
3869 const gdb_byte
*data
, const gdb_byte
*end
,
3870 int indent
, int all
,
3871 struct dwarf2_per_cu_data
*per_cu
)
3875 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3877 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3882 name
= get_DW_OP_name (op
);
3885 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3886 op
, (long) (data
- 1 - start
));
3887 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3888 (long) (data
- 1 - start
), name
);
3893 ul
= extract_unsigned_integer (data
, addr_size
,
3894 gdbarch_byte_order (arch
));
3896 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3900 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3902 fprintf_filtered (stream
, " %s", pulongest (ul
));
3905 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3907 fprintf_filtered (stream
, " %s", plongest (l
));
3910 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3912 fprintf_filtered (stream
, " %s", pulongest (ul
));
3915 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3917 fprintf_filtered (stream
, " %s", plongest (l
));
3920 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3922 fprintf_filtered (stream
, " %s", pulongest (ul
));
3925 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3927 fprintf_filtered (stream
, " %s", plongest (l
));
3930 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3932 fprintf_filtered (stream
, " %s", pulongest (ul
));
3935 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3937 fprintf_filtered (stream
, " %s", plongest (l
));
3940 data
= safe_read_uleb128 (data
, end
, &ul
);
3941 fprintf_filtered (stream
, " %s", pulongest (ul
));
3944 data
= safe_read_sleb128 (data
, end
, &l
);
3945 fprintf_filtered (stream
, " %s", plongest (l
));
3980 fprintf_filtered (stream
, " [$%s]",
3981 locexpr_regname (arch
, op
- DW_OP_reg0
));
3985 data
= safe_read_uleb128 (data
, end
, &ul
);
3986 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3987 locexpr_regname (arch
, (int) ul
));
3990 case DW_OP_implicit_value
:
3991 data
= safe_read_uleb128 (data
, end
, &ul
);
3993 fprintf_filtered (stream
, " %s", pulongest (ul
));
4028 data
= safe_read_sleb128 (data
, end
, &l
);
4029 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4030 locexpr_regname (arch
, op
- DW_OP_breg0
));
4034 data
= safe_read_uleb128 (data
, end
, &ul
);
4035 data
= safe_read_sleb128 (data
, end
, &l
);
4036 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4038 locexpr_regname (arch
, (int) ul
),
4043 data
= safe_read_sleb128 (data
, end
, &l
);
4044 fprintf_filtered (stream
, " %s", plongest (l
));
4047 case DW_OP_xderef_size
:
4048 case DW_OP_deref_size
:
4050 fprintf_filtered (stream
, " %d", *data
);
4054 case DW_OP_plus_uconst
:
4055 data
= safe_read_uleb128 (data
, end
, &ul
);
4056 fprintf_filtered (stream
, " %s", pulongest (ul
));
4060 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4062 fprintf_filtered (stream
, " to %ld",
4063 (long) (data
+ l
- start
));
4067 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4069 fprintf_filtered (stream
, " %ld",
4070 (long) (data
+ l
- start
));
4074 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4076 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4080 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4082 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4085 case DW_OP_call_ref
:
4086 ul
= extract_unsigned_integer (data
, offset_size
,
4087 gdbarch_byte_order (arch
));
4088 data
+= offset_size
;
4089 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4093 data
= safe_read_uleb128 (data
, end
, &ul
);
4094 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4097 case DW_OP_bit_piece
:
4101 data
= safe_read_uleb128 (data
, end
, &ul
);
4102 data
= safe_read_uleb128 (data
, end
, &offset
);
4103 fprintf_filtered (stream
, " size %s offset %s (bits)",
4104 pulongest (ul
), pulongest (offset
));
4108 case DW_OP_implicit_pointer
:
4109 case DW_OP_GNU_implicit_pointer
:
4111 ul
= extract_unsigned_integer (data
, offset_size
,
4112 gdbarch_byte_order (arch
));
4113 data
+= offset_size
;
4115 data
= safe_read_sleb128 (data
, end
, &l
);
4117 fprintf_filtered (stream
, " DIE %s offset %s",
4118 phex_nz (ul
, offset_size
),
4123 case DW_OP_deref_type
:
4124 case DW_OP_GNU_deref_type
:
4126 int deref_addr_size
= *data
++;
4129 data
= safe_read_uleb128 (data
, end
, &ul
);
4130 cu_offset offset
= (cu_offset
) ul
;
4131 type
= dwarf2_get_die_type (offset
, per_cu
);
4132 fprintf_filtered (stream
, "<");
4133 type_print (type
, "", stream
, -1);
4134 fprintf_filtered (stream
, " [0x%s]> %d",
4135 phex_nz (to_underlying (offset
), 0),
4140 case DW_OP_const_type
:
4141 case DW_OP_GNU_const_type
:
4145 data
= safe_read_uleb128 (data
, end
, &ul
);
4146 cu_offset type_die
= (cu_offset
) ul
;
4147 type
= dwarf2_get_die_type (type_die
, per_cu
);
4148 fprintf_filtered (stream
, "<");
4149 type_print (type
, "", stream
, -1);
4150 fprintf_filtered (stream
, " [0x%s]>",
4151 phex_nz (to_underlying (type_die
), 0));
4154 fprintf_filtered (stream
, " %d byte block:", n
);
4155 for (int i
= 0; i
< n
; ++i
)
4156 fprintf_filtered (stream
, " %02x", data
[i
]);
4161 case DW_OP_regval_type
:
4162 case DW_OP_GNU_regval_type
:
4167 data
= safe_read_uleb128 (data
, end
, ®
);
4168 data
= safe_read_uleb128 (data
, end
, &ul
);
4169 cu_offset type_die
= (cu_offset
) ul
;
4171 type
= dwarf2_get_die_type (type_die
, per_cu
);
4172 fprintf_filtered (stream
, "<");
4173 type_print (type
, "", stream
, -1);
4174 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4175 phex_nz (to_underlying (type_die
), 0),
4176 locexpr_regname (arch
, reg
));
4181 case DW_OP_GNU_convert
:
4182 case DW_OP_reinterpret
:
4183 case DW_OP_GNU_reinterpret
:
4185 data
= safe_read_uleb128 (data
, end
, &ul
);
4186 cu_offset type_die
= (cu_offset
) ul
;
4188 if (to_underlying (type_die
) == 0)
4189 fprintf_filtered (stream
, "<0>");
4194 type
= dwarf2_get_die_type (type_die
, per_cu
);
4195 fprintf_filtered (stream
, "<");
4196 type_print (type
, "", stream
, -1);
4197 fprintf_filtered (stream
, " [0x%s]>",
4198 phex_nz (to_underlying (type_die
), 0));
4203 case DW_OP_entry_value
:
4204 case DW_OP_GNU_entry_value
:
4205 data
= safe_read_uleb128 (data
, end
, &ul
);
4206 fputc_filtered ('\n', stream
);
4207 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4208 start
, data
, data
+ ul
, indent
+ 2,
4213 case DW_OP_GNU_parameter_ref
:
4214 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4216 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4220 case DW_OP_GNU_addr_index
:
4221 data
= safe_read_uleb128 (data
, end
, &ul
);
4222 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4223 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4225 case DW_OP_GNU_const_index
:
4226 data
= safe_read_uleb128 (data
, end
, &ul
);
4227 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4228 fprintf_filtered (stream
, " %s", pulongest (ul
));
4231 case DW_OP_GNU_variable_value
:
4232 ul
= extract_unsigned_integer (data
, offset_size
,
4233 gdbarch_byte_order (arch
));
4234 data
+= offset_size
;
4235 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4239 fprintf_filtered (stream
, "\n");
4245 static bool dwarf_always_disassemble
;
4248 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4249 struct cmd_list_element
*c
, const char *value
)
4251 fprintf_filtered (file
,
4252 _("Whether to always disassemble "
4253 "DWARF expressions is %s.\n"),
4257 /* Describe a single location, which may in turn consist of multiple
4261 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4262 struct ui_file
*stream
,
4263 const gdb_byte
*data
, size_t size
,
4264 struct objfile
*objfile
, unsigned int addr_size
,
4265 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4267 const gdb_byte
*end
= data
+ size
;
4268 int first_piece
= 1, bad
= 0;
4272 const gdb_byte
*here
= data
;
4273 int disassemble
= 1;
4278 fprintf_filtered (stream
, _(", and "));
4280 if (!dwarf_always_disassemble
)
4282 data
= locexpr_describe_location_piece (symbol
, stream
,
4283 addr
, objfile
, per_cu
,
4284 data
, end
, addr_size
);
4285 /* If we printed anything, or if we have an empty piece,
4286 then don't disassemble. */
4288 || data
[0] == DW_OP_piece
4289 || data
[0] == DW_OP_bit_piece
)
4294 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4295 data
= disassemble_dwarf_expression (stream
,
4297 addr_size
, offset_size
, data
,
4299 dwarf_always_disassemble
,
4305 int empty
= data
== here
;
4308 fprintf_filtered (stream
, " ");
4309 if (data
[0] == DW_OP_piece
)
4313 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4316 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4319 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4322 else if (data
[0] == DW_OP_bit_piece
)
4324 uint64_t bits
, offset
;
4326 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4327 data
= safe_read_uleb128 (data
, end
, &offset
);
4330 fprintf_filtered (stream
,
4331 _("an empty %s-bit piece"),
4334 fprintf_filtered (stream
,
4335 _(" [%s-bit piece, offset %s bits]"),
4336 pulongest (bits
), pulongest (offset
));
4346 if (bad
|| data
> end
)
4347 error (_("Corrupted DWARF2 expression for \"%s\"."),
4348 symbol
->print_name ());
4351 /* Print a natural-language description of SYMBOL to STREAM. This
4352 version is for a symbol with a single location. */
4355 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4356 struct ui_file
*stream
)
4358 struct dwarf2_locexpr_baton
*dlbaton
4359 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4360 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4361 struct objfile
*objfile
= per_objfile
->objfile
;
4362 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4363 int offset_size
= dlbaton
->per_cu
->offset_size ();
4365 locexpr_describe_location_1 (symbol
, addr
, stream
,
4366 dlbaton
->data
, dlbaton
->size
,
4367 objfile
, addr_size
, offset_size
,
4371 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4372 any necessary bytecode in AX. */
4375 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4376 struct axs_value
*value
)
4378 struct dwarf2_locexpr_baton
*dlbaton
4379 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4380 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4382 if (dlbaton
->size
== 0)
4383 value
->optimized_out
= 1;
4385 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4386 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
);
4389 /* symbol_computed_ops 'generate_c_location' method. */
4392 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4393 struct gdbarch
*gdbarch
,
4394 unsigned char *registers_used
,
4395 CORE_ADDR pc
, const char *result_name
)
4397 struct dwarf2_locexpr_baton
*dlbaton
4398 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4399 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4401 if (dlbaton
->size
== 0)
4402 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4404 compile_dwarf_expr_to_c (stream
, result_name
,
4405 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4406 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4410 /* The set of location functions used with the DWARF-2 expression
4412 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4413 locexpr_read_variable
,
4414 locexpr_read_variable_at_entry
,
4415 locexpr_get_symbol_read_needs
,
4416 locexpr_describe_location
,
4417 0, /* location_has_loclist */
4418 locexpr_tracepoint_var_ref
,
4419 locexpr_generate_c_location
4423 /* Wrapper functions for location lists. These generally find
4424 the appropriate location expression and call something above. */
4426 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4427 evaluator to calculate the location. */
4428 static struct value
*
4429 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4431 struct dwarf2_loclist_baton
*dlbaton
4432 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4434 const gdb_byte
*data
;
4436 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4438 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4439 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4445 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4446 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4449 Function always returns non-NULL value, it may be marked optimized out if
4450 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4451 if it cannot resolve the parameter for any reason. */
4453 static struct value
*
4454 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4456 struct dwarf2_loclist_baton
*dlbaton
4457 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4458 const gdb_byte
*data
;
4462 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4463 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4465 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4467 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4469 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4472 /* Implementation of get_symbol_read_needs from
4473 symbol_computed_ops. */
4475 static enum symbol_needs_kind
4476 loclist_symbol_needs (struct symbol
*symbol
)
4478 /* If there's a location list, then assume we need to have a frame
4479 to choose the appropriate location expression. With tracking of
4480 global variables this is not necessarily true, but such tracking
4481 is disabled in GCC at the moment until we figure out how to
4484 return SYMBOL_NEEDS_FRAME
;
4487 /* Print a natural-language description of SYMBOL to STREAM. This
4488 version applies when there is a list of different locations, each
4489 with a specified address range. */
4492 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4493 struct ui_file
*stream
)
4495 struct dwarf2_loclist_baton
*dlbaton
4496 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4497 const gdb_byte
*loc_ptr
, *buf_end
;
4498 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4499 struct objfile
*objfile
= per_objfile
->objfile
;
4500 struct gdbarch
*gdbarch
= objfile
->arch ();
4501 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4502 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4503 int offset_size
= dlbaton
->per_cu
->offset_size ();
4504 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4505 /* Adjust base_address for relocatable objects. */
4506 CORE_ADDR base_offset
= dlbaton
->per_cu
->text_offset ();
4507 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4510 loc_ptr
= dlbaton
->data
;
4511 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4513 fprintf_filtered (stream
, _("multi-location:\n"));
4515 /* Iterate through locations until we run out. */
4518 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4520 enum debug_loc_kind kind
;
4521 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4523 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4524 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4525 loc_ptr
, buf_end
, &new_ptr
,
4526 &low
, &high
, byte_order
);
4527 else if (dlbaton
->per_cu
->version () < 5)
4528 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4530 byte_order
, addr_size
,
4533 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4534 loc_ptr
, buf_end
, &new_ptr
,
4535 &low
, &high
, byte_order
,
4536 addr_size
, signed_addr_p
);
4540 case DEBUG_LOC_END_OF_LIST
:
4543 case DEBUG_LOC_BASE_ADDRESS
:
4544 base_address
= high
+ base_offset
;
4545 fprintf_filtered (stream
, _(" Base address %s"),
4546 paddress (gdbarch
, base_address
));
4548 case DEBUG_LOC_START_END
:
4549 case DEBUG_LOC_START_LENGTH
:
4550 case DEBUG_LOC_OFFSET_PAIR
:
4552 case DEBUG_LOC_BUFFER_OVERFLOW
:
4553 case DEBUG_LOC_INVALID_ENTRY
:
4554 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4555 symbol
->print_name ());
4557 gdb_assert_not_reached ("bad debug_loc_kind");
4560 /* Otherwise, a location expression entry. */
4561 low
+= base_address
;
4562 high
+= base_address
;
4564 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4565 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4567 if (dlbaton
->per_cu
->version () < 5)
4569 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4574 unsigned int bytes_read
;
4575 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4576 loc_ptr
+= bytes_read
;
4579 /* (It would improve readability to print only the minimum
4580 necessary digits of the second number of the range.) */
4581 fprintf_filtered (stream
, _(" Range %s-%s: "),
4582 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4584 /* Now describe this particular location. */
4585 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4586 objfile
, addr_size
, offset_size
,
4589 fprintf_filtered (stream
, "\n");
4595 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4596 any necessary bytecode in AX. */
4598 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4599 struct axs_value
*value
)
4601 struct dwarf2_loclist_baton
*dlbaton
4602 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4603 const gdb_byte
*data
;
4605 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4607 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4609 value
->optimized_out
= 1;
4611 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4615 /* symbol_computed_ops 'generate_c_location' method. */
4618 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4619 struct gdbarch
*gdbarch
,
4620 unsigned char *registers_used
,
4621 CORE_ADDR pc
, const char *result_name
)
4623 struct dwarf2_loclist_baton
*dlbaton
4624 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4625 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4626 const gdb_byte
*data
;
4629 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4631 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4633 compile_dwarf_expr_to_c (stream
, result_name
,
4634 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4639 /* The set of location functions used with the DWARF-2 expression
4640 evaluator and location lists. */
4641 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4642 loclist_read_variable
,
4643 loclist_read_variable_at_entry
,
4644 loclist_symbol_needs
,
4645 loclist_describe_location
,
4646 1, /* location_has_loclist */
4647 loclist_tracepoint_var_ref
,
4648 loclist_generate_c_location
4651 void _initialize_dwarf2loc ();
4653 _initialize_dwarf2loc ()
4655 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4656 &entry_values_debug
,
4657 _("Set entry values and tail call frames "
4659 _("Show entry values and tail call frames "
4661 _("When non-zero, the process of determining "
4662 "parameter values from function entry point "
4663 "and tail call frames will be printed."),
4665 show_entry_values_debug
,
4666 &setdebuglist
, &showdebuglist
);
4668 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4669 &dwarf_always_disassemble
, _("\
4670 Set whether `info address' always disassembles DWARF expressions."), _("\
4671 Show whether `info address' always disassembles DWARF expressions."), _("\
4672 When enabled, DWARF expressions are always printed in an assembly-like\n\
4673 syntax. When disabled, expressions will be printed in a more\n\
4674 conversational style, when possible."),
4676 show_dwarf_always_disassemble
,
4678 &show_dwarf_cmdlist
);