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_objfile
->objfile
->text_section_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 dwarf2_per_cu_data
*per_cu
;
2653 dwarf2_per_objfile
*per_objfile
;
2655 if (prop
->kind
== PROP_LOCEXPR
)
2657 data
= baton
->locexpr
.data
;
2658 size
= baton
->locexpr
.size
;
2659 per_cu
= baton
->locexpr
.per_cu
;
2660 per_objfile
= baton
->locexpr
.per_objfile
;
2664 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2666 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2667 per_cu
= baton
->loclist
.per_cu
;
2668 per_objfile
= baton
->loclist
.per_objfile
;
2671 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2672 gdbarch
, registers_used
,
2673 per_cu
->addr_size (),
2674 data
, data
+ size
, per_cu
, per_objfile
);
2678 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2680 class symbol_needs_eval_context
: public dwarf_expr_context
2683 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2684 : dwarf_expr_context (per_objfile
)
2687 enum symbol_needs_kind needs
;
2688 struct dwarf2_per_cu_data
*per_cu
;
2690 /* Reads from registers do require a frame. */
2691 CORE_ADDR
read_addr_from_reg (int regnum
) override
2693 needs
= SYMBOL_NEEDS_FRAME
;
2697 /* "get_reg_value" callback: Reads from registers do require a
2700 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2702 needs
= SYMBOL_NEEDS_FRAME
;
2703 return value_zero (type
, not_lval
);
2706 /* Reads from memory do not require a frame. */
2707 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2709 memset (buf
, 0, len
);
2712 /* Frame-relative accesses do require a frame. */
2713 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2715 static gdb_byte lit0
= DW_OP_lit0
;
2720 needs
= SYMBOL_NEEDS_FRAME
;
2723 /* CFA accesses require a frame. */
2724 CORE_ADDR
get_frame_cfa () override
2726 needs
= SYMBOL_NEEDS_FRAME
;
2730 CORE_ADDR
get_frame_pc () override
2732 needs
= SYMBOL_NEEDS_FRAME
;
2736 /* Thread-local accesses require registers, but not a frame. */
2737 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2739 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2740 needs
= SYMBOL_NEEDS_REGISTERS
;
2744 /* Helper interface of per_cu_dwarf_call for
2745 dwarf2_loc_desc_get_symbol_read_needs. */
2747 void dwarf_call (cu_offset die_offset
) override
2749 per_cu_dwarf_call (this, die_offset
, per_cu
);
2752 /* Helper interface of sect_variable_value for
2753 dwarf2_loc_desc_get_symbol_read_needs. */
2755 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2757 return sect_variable_value (this, sect_off
, per_cu
);
2760 /* DW_OP_entry_value accesses require a caller, therefore a
2763 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2764 union call_site_parameter_u kind_u
,
2765 int deref_size
) override
2767 needs
= SYMBOL_NEEDS_FRAME
;
2769 /* The expression may require some stub values on DWARF stack. */
2770 push_address (0, 0);
2773 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2775 CORE_ADDR
get_addr_index (unsigned int index
) override
2777 /* Nothing to do. */
2781 /* DW_OP_push_object_address has a frame already passed through. */
2783 CORE_ADDR
get_object_address () override
2785 /* Nothing to do. */
2790 /* Compute the correct symbol_needs_kind value for the location
2791 expression at DATA (length SIZE). */
2793 static enum symbol_needs_kind
2794 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2795 struct dwarf2_per_cu_data
*per_cu
)
2798 struct objfile
*objfile
= per_cu
->objfile ();
2800 scoped_value_mark free_values
;
2802 symbol_needs_eval_context
ctx (get_dwarf2_per_objfile (objfile
));
2804 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2805 ctx
.per_cu
= per_cu
;
2806 ctx
.gdbarch
= objfile
->arch ();
2807 ctx
.addr_size
= per_cu
->addr_size ();
2808 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2810 ctx
.eval (data
, size
);
2812 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2814 /* If the location has several pieces, and any of them are in
2815 registers, then we will need a frame to fetch them from. */
2816 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2817 if (p
.location
== DWARF_VALUE_REGISTER
)
2821 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2825 /* A helper function that throws an unimplemented error mentioning a
2826 given DWARF operator. */
2828 static void ATTRIBUTE_NORETURN
2829 unimplemented (unsigned int op
)
2831 const char *name
= get_DW_OP_name (op
);
2834 error (_("DWARF operator %s cannot be translated to an agent expression"),
2837 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2838 "to an agent expression"),
2844 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2845 can issue a complaint, which is better than having every target's
2846 implementation of dwarf2_reg_to_regnum do it. */
2849 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2851 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2855 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2860 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2861 Throw an error because DWARF_REG is bad. */
2864 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2866 /* Still want to print -1 as "-1".
2867 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2868 but that's overkill for now. */
2869 if ((int) dwarf_reg
== dwarf_reg
)
2870 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2871 error (_("Unable to access DWARF register number %s"),
2872 pulongest (dwarf_reg
));
2875 /* See dwarf2loc.h. */
2878 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2882 if (dwarf_reg
> INT_MAX
)
2883 throw_bad_regnum_error (dwarf_reg
);
2884 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2885 bad, but that's ok. */
2886 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2888 throw_bad_regnum_error (dwarf_reg
);
2892 /* A helper function that emits an access to memory. ARCH is the
2893 target architecture. EXPR is the expression which we are building.
2894 NBITS is the number of bits we want to read. This emits the
2895 opcodes needed to read the memory and then extract the desired
2899 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2901 ULONGEST nbytes
= (nbits
+ 7) / 8;
2903 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2906 ax_trace_quick (expr
, nbytes
);
2909 ax_simple (expr
, aop_ref8
);
2910 else if (nbits
<= 16)
2911 ax_simple (expr
, aop_ref16
);
2912 else if (nbits
<= 32)
2913 ax_simple (expr
, aop_ref32
);
2915 ax_simple (expr
, aop_ref64
);
2917 /* If we read exactly the number of bytes we wanted, we're done. */
2918 if (8 * nbytes
== nbits
)
2921 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2923 /* On a bits-big-endian machine, we want the high-order
2925 ax_const_l (expr
, 8 * nbytes
- nbits
);
2926 ax_simple (expr
, aop_rsh_unsigned
);
2930 /* On a bits-little-endian box, we want the low-order NBITS. */
2931 ax_zero_ext (expr
, nbits
);
2935 /* A helper function to return the frame's PC. */
2938 get_ax_pc (void *baton
)
2940 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
2945 /* Compile a DWARF location expression to an agent expression.
2947 EXPR is the agent expression we are building.
2948 LOC is the agent value we modify.
2949 ARCH is the architecture.
2950 ADDR_SIZE is the size of addresses, in bytes.
2951 OP_PTR is the start of the location expression.
2952 OP_END is one past the last byte of the location expression.
2954 This will throw an exception for various kinds of errors -- for
2955 example, if the expression cannot be compiled, or if the expression
2959 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2960 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2961 const gdb_byte
*op_end
,
2962 dwarf2_per_cu_data
*per_cu
,
2963 dwarf2_per_objfile
*per_objfile
)
2965 gdbarch
*arch
= expr
->gdbarch
;
2966 std::vector
<int> dw_labels
, patches
;
2967 const gdb_byte
* const base
= op_ptr
;
2968 const gdb_byte
*previous_piece
= op_ptr
;
2969 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2970 ULONGEST bits_collected
= 0;
2971 unsigned int addr_size_bits
= 8 * addr_size
;
2972 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2974 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2976 /* By default we are making an address. */
2977 loc
->kind
= axs_lvalue_memory
;
2979 while (op_ptr
< op_end
)
2981 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2982 uint64_t uoffset
, reg
;
2986 offsets
[op_ptr
- base
] = expr
->len
;
2989 /* Our basic approach to code generation is to map DWARF
2990 operations directly to AX operations. However, there are
2993 First, DWARF works on address-sized units, but AX always uses
2994 LONGEST. For most operations we simply ignore this
2995 difference; instead we generate sign extensions as needed
2996 before division and comparison operations. It would be nice
2997 to omit the sign extensions, but there is no way to determine
2998 the size of the target's LONGEST. (This code uses the size
2999 of the host LONGEST in some cases -- that is a bug but it is
3002 Second, some DWARF operations cannot be translated to AX.
3003 For these we simply fail. See
3004 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3039 ax_const_l (expr
, op
- DW_OP_lit0
);
3043 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3044 op_ptr
+= addr_size
;
3045 /* Some versions of GCC emit DW_OP_addr before
3046 DW_OP_GNU_push_tls_address. In this case the value is an
3047 index, not an address. We don't support things like
3048 branching between the address and the TLS op. */
3049 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3050 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3051 ax_const_l (expr
, uoffset
);
3055 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3059 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3063 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3067 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3071 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3075 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3079 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3083 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3087 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3088 ax_const_l (expr
, uoffset
);
3091 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3092 ax_const_l (expr
, offset
);
3127 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3128 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3129 loc
->kind
= axs_lvalue_register
;
3133 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3134 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3135 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3136 loc
->kind
= axs_lvalue_register
;
3139 case DW_OP_implicit_value
:
3143 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3144 if (op_ptr
+ len
> op_end
)
3145 error (_("DW_OP_implicit_value: too few bytes available."));
3146 if (len
> sizeof (ULONGEST
))
3147 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3150 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3153 dwarf_expr_require_composition (op_ptr
, op_end
,
3154 "DW_OP_implicit_value");
3156 loc
->kind
= axs_rvalue
;
3160 case DW_OP_stack_value
:
3161 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3162 loc
->kind
= axs_rvalue
;
3197 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3198 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3202 ax_const_l (expr
, offset
);
3203 ax_simple (expr
, aop_add
);
3208 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3209 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3210 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3214 ax_const_l (expr
, offset
);
3215 ax_simple (expr
, aop_add
);
3221 const gdb_byte
*datastart
;
3223 const struct block
*b
;
3224 struct symbol
*framefunc
;
3226 b
= block_for_pc (expr
->scope
);
3229 error (_("No block found for address"));
3231 framefunc
= block_linkage_function (b
);
3234 error (_("No function found for block"));
3236 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3237 &datastart
, &datalen
);
3239 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3240 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3241 datastart
+ datalen
, per_cu
,
3243 if (loc
->kind
== axs_lvalue_register
)
3244 require_rvalue (expr
, loc
);
3248 ax_const_l (expr
, offset
);
3249 ax_simple (expr
, aop_add
);
3252 loc
->kind
= axs_lvalue_memory
;
3257 ax_simple (expr
, aop_dup
);
3261 ax_simple (expr
, aop_pop
);
3266 ax_pick (expr
, offset
);
3270 ax_simple (expr
, aop_swap
);
3278 ax_simple (expr
, aop_rot
);
3282 case DW_OP_deref_size
:
3286 if (op
== DW_OP_deref_size
)
3291 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3292 error (_("Unsupported size %d in %s"),
3293 size
, get_DW_OP_name (op
));
3294 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3299 /* Sign extend the operand. */
3300 ax_ext (expr
, addr_size_bits
);
3301 ax_simple (expr
, aop_dup
);
3302 ax_const_l (expr
, 0);
3303 ax_simple (expr
, aop_less_signed
);
3304 ax_simple (expr
, aop_log_not
);
3305 i
= ax_goto (expr
, aop_if_goto
);
3306 /* We have to emit 0 - X. */
3307 ax_const_l (expr
, 0);
3308 ax_simple (expr
, aop_swap
);
3309 ax_simple (expr
, aop_sub
);
3310 ax_label (expr
, i
, expr
->len
);
3314 /* No need to sign extend here. */
3315 ax_const_l (expr
, 0);
3316 ax_simple (expr
, aop_swap
);
3317 ax_simple (expr
, aop_sub
);
3321 /* Sign extend the operand. */
3322 ax_ext (expr
, addr_size_bits
);
3323 ax_simple (expr
, aop_bit_not
);
3326 case DW_OP_plus_uconst
:
3327 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3328 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3329 but we micro-optimize anyhow. */
3332 ax_const_l (expr
, reg
);
3333 ax_simple (expr
, aop_add
);
3338 ax_simple (expr
, aop_bit_and
);
3342 /* Sign extend the operands. */
3343 ax_ext (expr
, addr_size_bits
);
3344 ax_simple (expr
, aop_swap
);
3345 ax_ext (expr
, addr_size_bits
);
3346 ax_simple (expr
, aop_swap
);
3347 ax_simple (expr
, aop_div_signed
);
3351 ax_simple (expr
, aop_sub
);
3355 ax_simple (expr
, aop_rem_unsigned
);
3359 ax_simple (expr
, aop_mul
);
3363 ax_simple (expr
, aop_bit_or
);
3367 ax_simple (expr
, aop_add
);
3371 ax_simple (expr
, aop_lsh
);
3375 ax_simple (expr
, aop_rsh_unsigned
);
3379 ax_simple (expr
, aop_rsh_signed
);
3383 ax_simple (expr
, aop_bit_xor
);
3387 /* Sign extend the operands. */
3388 ax_ext (expr
, addr_size_bits
);
3389 ax_simple (expr
, aop_swap
);
3390 ax_ext (expr
, addr_size_bits
);
3391 /* Note no swap here: A <= B is !(B < A). */
3392 ax_simple (expr
, aop_less_signed
);
3393 ax_simple (expr
, aop_log_not
);
3397 /* Sign extend the operands. */
3398 ax_ext (expr
, addr_size_bits
);
3399 ax_simple (expr
, aop_swap
);
3400 ax_ext (expr
, addr_size_bits
);
3401 ax_simple (expr
, aop_swap
);
3402 /* A >= B is !(A < B). */
3403 ax_simple (expr
, aop_less_signed
);
3404 ax_simple (expr
, aop_log_not
);
3408 /* Sign extend the operands. */
3409 ax_ext (expr
, addr_size_bits
);
3410 ax_simple (expr
, aop_swap
);
3411 ax_ext (expr
, addr_size_bits
);
3412 /* No need for a second swap here. */
3413 ax_simple (expr
, aop_equal
);
3417 /* Sign extend the operands. */
3418 ax_ext (expr
, addr_size_bits
);
3419 ax_simple (expr
, aop_swap
);
3420 ax_ext (expr
, addr_size_bits
);
3421 ax_simple (expr
, aop_swap
);
3422 ax_simple (expr
, aop_less_signed
);
3426 /* Sign extend the operands. */
3427 ax_ext (expr
, addr_size_bits
);
3428 ax_simple (expr
, aop_swap
);
3429 ax_ext (expr
, addr_size_bits
);
3430 /* Note no swap here: A > B is B < A. */
3431 ax_simple (expr
, aop_less_signed
);
3435 /* Sign extend the operands. */
3436 ax_ext (expr
, addr_size_bits
);
3437 ax_simple (expr
, aop_swap
);
3438 ax_ext (expr
, addr_size_bits
);
3439 /* No need for a swap here. */
3440 ax_simple (expr
, aop_equal
);
3441 ax_simple (expr
, aop_log_not
);
3444 case DW_OP_call_frame_cfa
:
3447 CORE_ADDR text_offset
;
3449 const gdb_byte
*cfa_start
, *cfa_end
;
3451 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3453 &text_offset
, &cfa_start
, &cfa_end
))
3456 ax_reg (expr
, regnum
);
3459 ax_const_l (expr
, off
);
3460 ax_simple (expr
, aop_add
);
3465 /* Another expression. */
3466 ax_const_l (expr
, text_offset
);
3467 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3468 cfa_end
, per_cu
, per_objfile
);
3471 loc
->kind
= axs_lvalue_memory
;
3475 case DW_OP_GNU_push_tls_address
:
3476 case DW_OP_form_tls_address
:
3480 case DW_OP_push_object_address
:
3485 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3487 i
= ax_goto (expr
, aop_goto
);
3488 dw_labels
.push_back (op_ptr
+ offset
- base
);
3489 patches
.push_back (i
);
3493 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3495 /* Zero extend the operand. */
3496 ax_zero_ext (expr
, addr_size_bits
);
3497 i
= ax_goto (expr
, aop_if_goto
);
3498 dw_labels
.push_back (op_ptr
+ offset
- base
);
3499 patches
.push_back (i
);
3506 case DW_OP_bit_piece
:
3510 if (op_ptr
- 1 == previous_piece
)
3511 error (_("Cannot translate empty pieces to agent expressions"));
3512 previous_piece
= op_ptr
- 1;
3514 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3515 if (op
== DW_OP_piece
)
3521 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3523 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3524 error (_("Expression pieces exceed word size"));
3526 /* Access the bits. */
3529 case axs_lvalue_register
:
3530 ax_reg (expr
, loc
->u
.reg
);
3533 case axs_lvalue_memory
:
3534 /* Offset the pointer, if needed. */
3537 ax_const_l (expr
, uoffset
/ 8);
3538 ax_simple (expr
, aop_add
);
3541 access_memory (arch
, expr
, size
);
3545 /* For a bits-big-endian target, shift up what we already
3546 have. For a bits-little-endian target, shift up the
3547 new data. Note that there is a potential bug here if
3548 the DWARF expression leaves multiple values on the
3550 if (bits_collected
> 0)
3552 if (bits_big_endian
)
3554 ax_simple (expr
, aop_swap
);
3555 ax_const_l (expr
, size
);
3556 ax_simple (expr
, aop_lsh
);
3557 /* We don't need a second swap here, because
3558 aop_bit_or is symmetric. */
3562 ax_const_l (expr
, size
);
3563 ax_simple (expr
, aop_lsh
);
3565 ax_simple (expr
, aop_bit_or
);
3568 bits_collected
+= size
;
3569 loc
->kind
= axs_rvalue
;
3573 case DW_OP_GNU_uninit
:
3579 struct dwarf2_locexpr_baton block
;
3580 int size
= (op
== DW_OP_call2
? 2 : 4);
3582 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3585 cu_offset cuoffset
= (cu_offset
) uoffset
;
3586 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
,
3589 /* DW_OP_call_ref is currently not supported. */
3590 gdb_assert (block
.per_cu
== per_cu
);
3592 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3593 block
.data
+ block
.size
, per_cu
,
3598 case DW_OP_call_ref
:
3601 case DW_OP_GNU_variable_value
:
3609 /* Patch all the branches we emitted. */
3610 for (int i
= 0; i
< patches
.size (); ++i
)
3612 int targ
= offsets
[dw_labels
[i
]];
3614 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3615 ax_label (expr
, patches
[i
], targ
);
3620 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3621 evaluator to calculate the location. */
3622 static struct value
*
3623 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3625 struct dwarf2_locexpr_baton
*dlbaton
3626 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3629 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3630 dlbaton
->size
, dlbaton
->per_cu
);
3635 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3636 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3639 static struct value
*
3640 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3642 struct dwarf2_locexpr_baton
*dlbaton
3643 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3645 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3649 /* Implementation of get_symbol_read_needs from
3650 symbol_computed_ops. */
3652 static enum symbol_needs_kind
3653 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3655 struct dwarf2_locexpr_baton
*dlbaton
3656 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3658 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3662 /* Return true if DATA points to the end of a piece. END is one past
3663 the last byte in the expression. */
3666 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3668 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3671 /* Helper for locexpr_describe_location_piece that finds the name of a
3675 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3679 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3680 We'd rather print *something* here than throw an error. */
3681 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3682 /* gdbarch_register_name may just return "", return something more
3683 descriptive for bad register numbers. */
3686 /* The text is output as "$bad_register_number".
3687 That is why we use the underscores. */
3688 return _("bad_register_number");
3690 return gdbarch_register_name (gdbarch
, regnum
);
3693 /* Nicely describe a single piece of a location, returning an updated
3694 position in the bytecode sequence. This function cannot recognize
3695 all locations; if a location is not recognized, it simply returns
3696 DATA. If there is an error during reading, e.g. we run off the end
3697 of the buffer, an error is thrown. */
3699 static const gdb_byte
*
3700 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3701 CORE_ADDR addr
, struct objfile
*objfile
,
3702 struct dwarf2_per_cu_data
*per_cu
,
3703 const gdb_byte
*data
, const gdb_byte
*end
,
3704 unsigned int addr_size
)
3706 struct gdbarch
*gdbarch
= objfile
->arch ();
3709 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3711 fprintf_filtered (stream
, _("a variable in $%s"),
3712 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3715 else if (data
[0] == DW_OP_regx
)
3719 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3720 fprintf_filtered (stream
, _("a variable in $%s"),
3721 locexpr_regname (gdbarch
, reg
));
3723 else if (data
[0] == DW_OP_fbreg
)
3725 const struct block
*b
;
3726 struct symbol
*framefunc
;
3728 int64_t frame_offset
;
3729 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3731 int64_t base_offset
= 0;
3733 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3734 if (!piece_end_p (new_data
, end
))
3738 b
= block_for_pc (addr
);
3741 error (_("No block found for address for symbol \"%s\"."),
3742 symbol
->print_name ());
3744 framefunc
= block_linkage_function (b
);
3747 error (_("No function found for block for symbol \"%s\"."),
3748 symbol
->print_name ());
3750 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3752 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3754 const gdb_byte
*buf_end
;
3756 frame_reg
= base_data
[0] - DW_OP_breg0
;
3757 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3759 if (buf_end
!= base_data
+ base_size
)
3760 error (_("Unexpected opcode after "
3761 "DW_OP_breg%u for symbol \"%s\"."),
3762 frame_reg
, symbol
->print_name ());
3764 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3766 /* The frame base is just the register, with no offset. */
3767 frame_reg
= base_data
[0] - DW_OP_reg0
;
3772 /* We don't know what to do with the frame base expression,
3773 so we can't trace this variable; give up. */
3777 fprintf_filtered (stream
,
3778 _("a variable at frame base reg $%s offset %s+%s"),
3779 locexpr_regname (gdbarch
, frame_reg
),
3780 plongest (base_offset
), plongest (frame_offset
));
3782 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3783 && piece_end_p (data
, end
))
3787 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3789 fprintf_filtered (stream
,
3790 _("a variable at offset %s from base reg $%s"),
3792 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3795 /* The location expression for a TLS variable looks like this (on a
3798 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3799 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3801 0x3 is the encoding for DW_OP_addr, which has an operand as long
3802 as the size of an address on the target machine (here is 8
3803 bytes). Note that more recent version of GCC emit DW_OP_const4u
3804 or DW_OP_const8u, depending on address size, rather than
3805 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3806 The operand represents the offset at which the variable is within
3807 the thread local storage. */
3809 else if (data
+ 1 + addr_size
< end
3810 && (data
[0] == DW_OP_addr
3811 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3812 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3813 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3814 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3815 && piece_end_p (data
+ 2 + addr_size
, end
))
3818 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3819 gdbarch_byte_order (gdbarch
));
3821 fprintf_filtered (stream
,
3822 _("a thread-local variable at offset 0x%s "
3823 "in the thread-local storage for `%s'"),
3824 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3826 data
+= 1 + addr_size
+ 1;
3829 /* With -gsplit-dwarf a TLS variable can also look like this:
3830 DW_AT_location : 3 byte block: fc 4 e0
3831 (DW_OP_GNU_const_index: 4;
3832 DW_OP_GNU_push_tls_address) */
3833 else if (data
+ 3 <= end
3834 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3835 && data
[0] == DW_OP_GNU_const_index
3837 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3838 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3839 && piece_end_p (data
+ 2 + leb128_size
, end
))
3843 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3844 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3845 fprintf_filtered (stream
,
3846 _("a thread-local variable at offset 0x%s "
3847 "in the thread-local storage for `%s'"),
3848 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3852 else if (data
[0] >= DW_OP_lit0
3853 && data
[0] <= DW_OP_lit31
3855 && data
[1] == DW_OP_stack_value
)
3857 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3864 /* Disassemble an expression, stopping at the end of a piece or at the
3865 end of the expression. Returns a pointer to the next unread byte
3866 in the input expression. If ALL is nonzero, then this function
3867 will keep going until it reaches the end of the expression.
3868 If there is an error during reading, e.g. we run off the end
3869 of the buffer, an error is thrown. */
3871 static const gdb_byte
*
3872 disassemble_dwarf_expression (struct ui_file
*stream
,
3873 struct gdbarch
*arch
, unsigned int addr_size
,
3874 int offset_size
, const gdb_byte
*start
,
3875 const gdb_byte
*data
, const gdb_byte
*end
,
3876 int indent
, int all
,
3877 struct dwarf2_per_cu_data
*per_cu
)
3881 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3883 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3888 name
= get_DW_OP_name (op
);
3891 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3892 op
, (long) (data
- 1 - start
));
3893 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3894 (long) (data
- 1 - start
), name
);
3899 ul
= extract_unsigned_integer (data
, addr_size
,
3900 gdbarch_byte_order (arch
));
3902 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3906 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3908 fprintf_filtered (stream
, " %s", pulongest (ul
));
3911 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3913 fprintf_filtered (stream
, " %s", plongest (l
));
3916 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3918 fprintf_filtered (stream
, " %s", pulongest (ul
));
3921 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3923 fprintf_filtered (stream
, " %s", plongest (l
));
3926 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3928 fprintf_filtered (stream
, " %s", pulongest (ul
));
3931 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3933 fprintf_filtered (stream
, " %s", plongest (l
));
3936 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3938 fprintf_filtered (stream
, " %s", pulongest (ul
));
3941 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3943 fprintf_filtered (stream
, " %s", plongest (l
));
3946 data
= safe_read_uleb128 (data
, end
, &ul
);
3947 fprintf_filtered (stream
, " %s", pulongest (ul
));
3950 data
= safe_read_sleb128 (data
, end
, &l
);
3951 fprintf_filtered (stream
, " %s", plongest (l
));
3986 fprintf_filtered (stream
, " [$%s]",
3987 locexpr_regname (arch
, op
- DW_OP_reg0
));
3991 data
= safe_read_uleb128 (data
, end
, &ul
);
3992 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3993 locexpr_regname (arch
, (int) ul
));
3996 case DW_OP_implicit_value
:
3997 data
= safe_read_uleb128 (data
, end
, &ul
);
3999 fprintf_filtered (stream
, " %s", pulongest (ul
));
4034 data
= safe_read_sleb128 (data
, end
, &l
);
4035 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4036 locexpr_regname (arch
, op
- DW_OP_breg0
));
4040 data
= safe_read_uleb128 (data
, end
, &ul
);
4041 data
= safe_read_sleb128 (data
, end
, &l
);
4042 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4044 locexpr_regname (arch
, (int) ul
),
4049 data
= safe_read_sleb128 (data
, end
, &l
);
4050 fprintf_filtered (stream
, " %s", plongest (l
));
4053 case DW_OP_xderef_size
:
4054 case DW_OP_deref_size
:
4056 fprintf_filtered (stream
, " %d", *data
);
4060 case DW_OP_plus_uconst
:
4061 data
= safe_read_uleb128 (data
, end
, &ul
);
4062 fprintf_filtered (stream
, " %s", pulongest (ul
));
4066 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4068 fprintf_filtered (stream
, " to %ld",
4069 (long) (data
+ l
- start
));
4073 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4075 fprintf_filtered (stream
, " %ld",
4076 (long) (data
+ l
- start
));
4080 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4082 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4086 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4088 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4091 case DW_OP_call_ref
:
4092 ul
= extract_unsigned_integer (data
, offset_size
,
4093 gdbarch_byte_order (arch
));
4094 data
+= offset_size
;
4095 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4099 data
= safe_read_uleb128 (data
, end
, &ul
);
4100 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4103 case DW_OP_bit_piece
:
4107 data
= safe_read_uleb128 (data
, end
, &ul
);
4108 data
= safe_read_uleb128 (data
, end
, &offset
);
4109 fprintf_filtered (stream
, " size %s offset %s (bits)",
4110 pulongest (ul
), pulongest (offset
));
4114 case DW_OP_implicit_pointer
:
4115 case DW_OP_GNU_implicit_pointer
:
4117 ul
= extract_unsigned_integer (data
, offset_size
,
4118 gdbarch_byte_order (arch
));
4119 data
+= offset_size
;
4121 data
= safe_read_sleb128 (data
, end
, &l
);
4123 fprintf_filtered (stream
, " DIE %s offset %s",
4124 phex_nz (ul
, offset_size
),
4129 case DW_OP_deref_type
:
4130 case DW_OP_GNU_deref_type
:
4132 int deref_addr_size
= *data
++;
4135 data
= safe_read_uleb128 (data
, end
, &ul
);
4136 cu_offset offset
= (cu_offset
) ul
;
4137 type
= dwarf2_get_die_type (offset
, per_cu
);
4138 fprintf_filtered (stream
, "<");
4139 type_print (type
, "", stream
, -1);
4140 fprintf_filtered (stream
, " [0x%s]> %d",
4141 phex_nz (to_underlying (offset
), 0),
4146 case DW_OP_const_type
:
4147 case DW_OP_GNU_const_type
:
4151 data
= safe_read_uleb128 (data
, end
, &ul
);
4152 cu_offset type_die
= (cu_offset
) ul
;
4153 type
= dwarf2_get_die_type (type_die
, per_cu
);
4154 fprintf_filtered (stream
, "<");
4155 type_print (type
, "", stream
, -1);
4156 fprintf_filtered (stream
, " [0x%s]>",
4157 phex_nz (to_underlying (type_die
), 0));
4160 fprintf_filtered (stream
, " %d byte block:", n
);
4161 for (int i
= 0; i
< n
; ++i
)
4162 fprintf_filtered (stream
, " %02x", data
[i
]);
4167 case DW_OP_regval_type
:
4168 case DW_OP_GNU_regval_type
:
4173 data
= safe_read_uleb128 (data
, end
, ®
);
4174 data
= safe_read_uleb128 (data
, end
, &ul
);
4175 cu_offset type_die
= (cu_offset
) ul
;
4177 type
= dwarf2_get_die_type (type_die
, per_cu
);
4178 fprintf_filtered (stream
, "<");
4179 type_print (type
, "", stream
, -1);
4180 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4181 phex_nz (to_underlying (type_die
), 0),
4182 locexpr_regname (arch
, reg
));
4187 case DW_OP_GNU_convert
:
4188 case DW_OP_reinterpret
:
4189 case DW_OP_GNU_reinterpret
:
4191 data
= safe_read_uleb128 (data
, end
, &ul
);
4192 cu_offset type_die
= (cu_offset
) ul
;
4194 if (to_underlying (type_die
) == 0)
4195 fprintf_filtered (stream
, "<0>");
4200 type
= dwarf2_get_die_type (type_die
, per_cu
);
4201 fprintf_filtered (stream
, "<");
4202 type_print (type
, "", stream
, -1);
4203 fprintf_filtered (stream
, " [0x%s]>",
4204 phex_nz (to_underlying (type_die
), 0));
4209 case DW_OP_entry_value
:
4210 case DW_OP_GNU_entry_value
:
4211 data
= safe_read_uleb128 (data
, end
, &ul
);
4212 fputc_filtered ('\n', stream
);
4213 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4214 start
, data
, data
+ ul
, indent
+ 2,
4219 case DW_OP_GNU_parameter_ref
:
4220 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4222 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4226 case DW_OP_GNU_addr_index
:
4227 data
= safe_read_uleb128 (data
, end
, &ul
);
4228 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4229 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4231 case DW_OP_GNU_const_index
:
4232 data
= safe_read_uleb128 (data
, end
, &ul
);
4233 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4234 fprintf_filtered (stream
, " %s", pulongest (ul
));
4237 case DW_OP_GNU_variable_value
:
4238 ul
= extract_unsigned_integer (data
, offset_size
,
4239 gdbarch_byte_order (arch
));
4240 data
+= offset_size
;
4241 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4245 fprintf_filtered (stream
, "\n");
4251 static bool dwarf_always_disassemble
;
4254 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4255 struct cmd_list_element
*c
, const char *value
)
4257 fprintf_filtered (file
,
4258 _("Whether to always disassemble "
4259 "DWARF expressions is %s.\n"),
4263 /* Describe a single location, which may in turn consist of multiple
4267 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4268 struct ui_file
*stream
,
4269 const gdb_byte
*data
, size_t size
,
4270 struct objfile
*objfile
, unsigned int addr_size
,
4271 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4273 const gdb_byte
*end
= data
+ size
;
4274 int first_piece
= 1, bad
= 0;
4278 const gdb_byte
*here
= data
;
4279 int disassemble
= 1;
4284 fprintf_filtered (stream
, _(", and "));
4286 if (!dwarf_always_disassemble
)
4288 data
= locexpr_describe_location_piece (symbol
, stream
,
4289 addr
, objfile
, per_cu
,
4290 data
, end
, addr_size
);
4291 /* If we printed anything, or if we have an empty piece,
4292 then don't disassemble. */
4294 || data
[0] == DW_OP_piece
4295 || data
[0] == DW_OP_bit_piece
)
4300 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4301 data
= disassemble_dwarf_expression (stream
,
4303 addr_size
, offset_size
, data
,
4305 dwarf_always_disassemble
,
4311 int empty
= data
== here
;
4314 fprintf_filtered (stream
, " ");
4315 if (data
[0] == DW_OP_piece
)
4319 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4322 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4325 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4328 else if (data
[0] == DW_OP_bit_piece
)
4330 uint64_t bits
, offset
;
4332 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4333 data
= safe_read_uleb128 (data
, end
, &offset
);
4336 fprintf_filtered (stream
,
4337 _("an empty %s-bit piece"),
4340 fprintf_filtered (stream
,
4341 _(" [%s-bit piece, offset %s bits]"),
4342 pulongest (bits
), pulongest (offset
));
4352 if (bad
|| data
> end
)
4353 error (_("Corrupted DWARF2 expression for \"%s\"."),
4354 symbol
->print_name ());
4357 /* Print a natural-language description of SYMBOL to STREAM. This
4358 version is for a symbol with a single location. */
4361 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4362 struct ui_file
*stream
)
4364 struct dwarf2_locexpr_baton
*dlbaton
4365 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4366 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4367 struct objfile
*objfile
= per_objfile
->objfile
;
4368 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4369 int offset_size
= dlbaton
->per_cu
->offset_size ();
4371 locexpr_describe_location_1 (symbol
, addr
, stream
,
4372 dlbaton
->data
, dlbaton
->size
,
4373 objfile
, addr_size
, offset_size
,
4377 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4378 any necessary bytecode in AX. */
4381 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4382 struct axs_value
*value
)
4384 struct dwarf2_locexpr_baton
*dlbaton
4385 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4386 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4388 if (dlbaton
->size
== 0)
4389 value
->optimized_out
= 1;
4391 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4392 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4393 dlbaton
->per_objfile
);
4396 /* symbol_computed_ops 'generate_c_location' method. */
4399 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4400 struct gdbarch
*gdbarch
,
4401 unsigned char *registers_used
,
4402 CORE_ADDR pc
, const char *result_name
)
4404 struct dwarf2_locexpr_baton
*dlbaton
4405 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4406 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4408 if (dlbaton
->size
== 0)
4409 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4411 compile_dwarf_expr_to_c (stream
, result_name
,
4412 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4413 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4414 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4417 /* The set of location functions used with the DWARF-2 expression
4419 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4420 locexpr_read_variable
,
4421 locexpr_read_variable_at_entry
,
4422 locexpr_get_symbol_read_needs
,
4423 locexpr_describe_location
,
4424 0, /* location_has_loclist */
4425 locexpr_tracepoint_var_ref
,
4426 locexpr_generate_c_location
4430 /* Wrapper functions for location lists. These generally find
4431 the appropriate location expression and call something above. */
4433 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4434 evaluator to calculate the location. */
4435 static struct value
*
4436 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4438 struct dwarf2_loclist_baton
*dlbaton
4439 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4441 const gdb_byte
*data
;
4443 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4445 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4446 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4452 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4453 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4456 Function always returns non-NULL value, it may be marked optimized out if
4457 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4458 if it cannot resolve the parameter for any reason. */
4460 static struct value
*
4461 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4463 struct dwarf2_loclist_baton
*dlbaton
4464 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4465 const gdb_byte
*data
;
4469 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4470 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4472 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4474 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4476 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4479 /* Implementation of get_symbol_read_needs from
4480 symbol_computed_ops. */
4482 static enum symbol_needs_kind
4483 loclist_symbol_needs (struct symbol
*symbol
)
4485 /* If there's a location list, then assume we need to have a frame
4486 to choose the appropriate location expression. With tracking of
4487 global variables this is not necessarily true, but such tracking
4488 is disabled in GCC at the moment until we figure out how to
4491 return SYMBOL_NEEDS_FRAME
;
4494 /* Print a natural-language description of SYMBOL to STREAM. This
4495 version applies when there is a list of different locations, each
4496 with a specified address range. */
4499 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4500 struct ui_file
*stream
)
4502 struct dwarf2_loclist_baton
*dlbaton
4503 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4504 const gdb_byte
*loc_ptr
, *buf_end
;
4505 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4506 struct objfile
*objfile
= per_objfile
->objfile
;
4507 struct gdbarch
*gdbarch
= objfile
->arch ();
4508 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4509 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4510 int offset_size
= dlbaton
->per_cu
->offset_size ();
4511 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4512 /* Adjust base_address for relocatable objects. */
4513 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4514 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4517 loc_ptr
= dlbaton
->data
;
4518 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4520 fprintf_filtered (stream
, _("multi-location:\n"));
4522 /* Iterate through locations until we run out. */
4525 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4527 enum debug_loc_kind kind
;
4528 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4530 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4531 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4532 loc_ptr
, buf_end
, &new_ptr
,
4533 &low
, &high
, byte_order
);
4534 else if (dlbaton
->per_cu
->version () < 5)
4535 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4537 byte_order
, addr_size
,
4540 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4541 loc_ptr
, buf_end
, &new_ptr
,
4542 &low
, &high
, byte_order
,
4543 addr_size
, signed_addr_p
);
4547 case DEBUG_LOC_END_OF_LIST
:
4550 case DEBUG_LOC_BASE_ADDRESS
:
4551 base_address
= high
+ base_offset
;
4552 fprintf_filtered (stream
, _(" Base address %s"),
4553 paddress (gdbarch
, base_address
));
4555 case DEBUG_LOC_START_END
:
4556 case DEBUG_LOC_START_LENGTH
:
4557 case DEBUG_LOC_OFFSET_PAIR
:
4559 case DEBUG_LOC_BUFFER_OVERFLOW
:
4560 case DEBUG_LOC_INVALID_ENTRY
:
4561 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4562 symbol
->print_name ());
4564 gdb_assert_not_reached ("bad debug_loc_kind");
4567 /* Otherwise, a location expression entry. */
4568 low
+= base_address
;
4569 high
+= base_address
;
4571 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4572 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4574 if (dlbaton
->per_cu
->version () < 5)
4576 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4581 unsigned int bytes_read
;
4582 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4583 loc_ptr
+= bytes_read
;
4586 /* (It would improve readability to print only the minimum
4587 necessary digits of the second number of the range.) */
4588 fprintf_filtered (stream
, _(" Range %s-%s: "),
4589 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4591 /* Now describe this particular location. */
4592 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4593 objfile
, addr_size
, offset_size
,
4596 fprintf_filtered (stream
, "\n");
4602 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4603 any necessary bytecode in AX. */
4605 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4606 struct axs_value
*value
)
4608 struct dwarf2_loclist_baton
*dlbaton
4609 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4610 const gdb_byte
*data
;
4612 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4614 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4616 value
->optimized_out
= 1;
4618 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4619 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4622 /* symbol_computed_ops 'generate_c_location' method. */
4625 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4626 struct gdbarch
*gdbarch
,
4627 unsigned char *registers_used
,
4628 CORE_ADDR pc
, const char *result_name
)
4630 struct dwarf2_loclist_baton
*dlbaton
4631 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4632 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4633 const gdb_byte
*data
;
4636 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4638 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4640 compile_dwarf_expr_to_c (stream
, result_name
,
4641 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4644 dlbaton
->per_objfile
);
4647 /* The set of location functions used with the DWARF-2 expression
4648 evaluator and location lists. */
4649 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4650 loclist_read_variable
,
4651 loclist_read_variable_at_entry
,
4652 loclist_symbol_needs
,
4653 loclist_describe_location
,
4654 1, /* location_has_loclist */
4655 loclist_tracepoint_var_ref
,
4656 loclist_generate_c_location
4659 void _initialize_dwarf2loc ();
4661 _initialize_dwarf2loc ()
4663 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4664 &entry_values_debug
,
4665 _("Set entry values and tail call frames "
4667 _("Show entry values and tail call frames "
4669 _("When non-zero, the process of determining "
4670 "parameter values from function entry point "
4671 "and tail call frames will be printed."),
4673 show_entry_values_debug
,
4674 &setdebuglist
, &showdebuglist
);
4676 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4677 &dwarf_always_disassemble
, _("\
4678 Set whether `info address' always disassembles DWARF expressions."), _("\
4679 Show whether `info address' always disassembles DWARF expressions."), _("\
4680 When enabled, DWARF expressions are always printed in an assembly-like\n\
4681 syntax. When disabled, expressions will be printed in a more\n\
4682 conversational style, when possible."),
4684 show_dwarf_always_disassemble
,
4686 &show_dwarf_cmdlist
);