1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2023 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
51 (struct type
*type
, frame_info_ptr frame
, const gdb_byte
*data
,
52 size_t size
, dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
53 struct type
*subobj_type
, LONGEST subobj_byte_offset
, bool as_lval
= true);
55 /* Until these have formal names, we define these here.
56 ref: http://gcc.gnu.org/wiki/DebugFission
57 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
58 and is then followed by data specific to that entry. */
62 /* Indicates the end of the list of entries. */
63 DEBUG_LOC_END_OF_LIST
= 0,
65 /* This is followed by an unsigned LEB128 number that is an index into
66 .debug_addr and specifies the base address for all following entries. */
67 DEBUG_LOC_BASE_ADDRESS
= 1,
69 /* This is followed by two unsigned LEB128 numbers that are indices into
70 .debug_addr and specify the beginning and ending addresses, and then
71 a normal location expression as in .debug_loc. */
72 DEBUG_LOC_START_END
= 2,
74 /* This is followed by an unsigned LEB128 number that is an index into
75 .debug_addr and specifies the beginning address, and a 4 byte unsigned
76 number that specifies the length, and then a normal location expression
78 DEBUG_LOC_START_LENGTH
= 3,
80 /* This is followed by two unsigned LEB128 operands. The values of these
81 operands are the starting and ending offsets, respectively, relative to
82 the applicable base address. */
83 DEBUG_LOC_OFFSET_PAIR
= 4,
85 /* An internal value indicating there is insufficient data. */
86 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
88 /* An internal value indicating an invalid kind of entry was found. */
89 DEBUG_LOC_INVALID_ENTRY
= -2
92 /* Helper function which throws an error if a synthetic pointer is
96 invalid_synthetic_pointer (void)
98 error (_("access outside bounds of object "
99 "referenced via synthetic pointer"));
102 /* Decode the addresses in a non-dwo .debug_loc entry.
103 A pointer to the next byte to examine is returned in *NEW_PTR.
104 The encoded low,high addresses are return in *LOW,*HIGH.
105 The result indicates the kind of entry found. */
107 static enum debug_loc_kind
108 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
109 const gdb_byte
**new_ptr
,
110 unrelocated_addr
*lowp
, unrelocated_addr
*highp
,
111 enum bfd_endian byte_order
,
112 unsigned int addr_size
,
115 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
117 if (buf_end
- loc_ptr
< 2 * addr_size
)
118 return DEBUG_LOC_BUFFER_OVERFLOW
;
122 low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
124 low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
125 loc_ptr
+= addr_size
;
128 high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
130 high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
131 loc_ptr
+= addr_size
;
134 *lowp
= (unrelocated_addr
) low
;
135 *highp
= (unrelocated_addr
) high
;
137 /* A base-address-selection entry. */
138 if ((low
& base_mask
) == base_mask
)
139 return DEBUG_LOC_BASE_ADDRESS
;
141 /* An end-of-list entry. */
142 if (low
== 0 && high
== 0)
143 return DEBUG_LOC_END_OF_LIST
;
145 /* We want the caller to apply the base address, so we must return
146 DEBUG_LOC_OFFSET_PAIR here. */
147 return DEBUG_LOC_OFFSET_PAIR
;
150 /* Decode the addresses in .debug_loclists entry.
151 A pointer to the next byte to examine is returned in *NEW_PTR.
152 The encoded low,high addresses are return in *LOW,*HIGH.
153 The result indicates the kind of entry found. */
155 static enum debug_loc_kind
156 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
157 dwarf2_per_objfile
*per_objfile
,
158 const gdb_byte
*loc_ptr
,
159 const gdb_byte
*buf_end
,
160 const gdb_byte
**new_ptr
,
161 unrelocated_addr
*low
,
162 unrelocated_addr
*high
,
163 enum bfd_endian byte_order
,
164 unsigned int addr_size
,
169 if (loc_ptr
== buf_end
)
170 return DEBUG_LOC_BUFFER_OVERFLOW
;
174 case DW_LLE_base_addressx
:
176 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
178 return DEBUG_LOC_BUFFER_OVERFLOW
;
180 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
182 return DEBUG_LOC_BASE_ADDRESS
;
184 case DW_LLE_startx_length
:
185 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
187 return DEBUG_LOC_BUFFER_OVERFLOW
;
189 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
191 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
193 return DEBUG_LOC_BUFFER_OVERFLOW
;
195 *high
= (unrelocated_addr
) ((uint64_t) *high
+ u64
);
197 return DEBUG_LOC_START_LENGTH
;
199 case DW_LLE_start_length
:
200 if (buf_end
- loc_ptr
< addr_size
)
201 return DEBUG_LOC_BUFFER_OVERFLOW
;
204 *low
= (unrelocated_addr
) extract_signed_integer (loc_ptr
, addr_size
,
207 *low
= (unrelocated_addr
) extract_unsigned_integer (loc_ptr
, addr_size
,
210 loc_ptr
+= addr_size
;
213 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
215 return DEBUG_LOC_BUFFER_OVERFLOW
;
217 *high
= (unrelocated_addr
) ((uint64_t) *high
+ u64
);
219 return DEBUG_LOC_START_LENGTH
;
221 case DW_LLE_end_of_list
:
223 return DEBUG_LOC_END_OF_LIST
;
225 case DW_LLE_base_address
:
226 if (loc_ptr
+ addr_size
> buf_end
)
227 return DEBUG_LOC_BUFFER_OVERFLOW
;
230 *high
= (unrelocated_addr
) extract_signed_integer (loc_ptr
, addr_size
,
233 *high
= (unrelocated_addr
) extract_unsigned_integer (loc_ptr
, addr_size
,
236 loc_ptr
+= addr_size
;
238 return DEBUG_LOC_BASE_ADDRESS
;
240 case DW_LLE_offset_pair
:
241 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
243 return DEBUG_LOC_BUFFER_OVERFLOW
;
245 *low
= (unrelocated_addr
) u64
;
246 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
248 return DEBUG_LOC_BUFFER_OVERFLOW
;
250 *high
= (unrelocated_addr
) u64
;
252 return DEBUG_LOC_OFFSET_PAIR
;
254 case DW_LLE_start_end
:
255 if (loc_ptr
+ 2 * addr_size
> buf_end
)
256 return DEBUG_LOC_BUFFER_OVERFLOW
;
259 *low
= (unrelocated_addr
) extract_signed_integer (loc_ptr
, addr_size
,
262 *low
= (unrelocated_addr
) extract_unsigned_integer (loc_ptr
, addr_size
,
265 loc_ptr
+= addr_size
;
267 *high
= (unrelocated_addr
) extract_signed_integer (loc_ptr
, addr_size
,
270 *high
= (unrelocated_addr
) extract_unsigned_integer (loc_ptr
, addr_size
,
273 loc_ptr
+= addr_size
;
275 return DEBUG_LOC_START_END
;
277 /* Following cases are not supported yet. */
278 case DW_LLE_startx_endx
:
279 case DW_LLE_default_location
:
281 return DEBUG_LOC_INVALID_ENTRY
;
285 /* Decode the addresses in .debug_loc.dwo entry.
286 A pointer to the next byte to examine is returned in *NEW_PTR.
287 The encoded low,high addresses are return in *LOW,*HIGH.
288 The result indicates the kind of entry found. */
290 static enum debug_loc_kind
291 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
292 dwarf2_per_objfile
*per_objfile
,
293 const gdb_byte
*loc_ptr
,
294 const gdb_byte
*buf_end
,
295 const gdb_byte
**new_ptr
,
296 unrelocated_addr
*low
,
297 unrelocated_addr
*high
,
298 enum bfd_endian byte_order
)
300 uint64_t low_index
, high_index
;
302 if (loc_ptr
== buf_end
)
303 return DEBUG_LOC_BUFFER_OVERFLOW
;
307 case DW_LLE_GNU_end_of_list_entry
:
309 return DEBUG_LOC_END_OF_LIST
;
311 case DW_LLE_GNU_base_address_selection_entry
:
313 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
315 return DEBUG_LOC_BUFFER_OVERFLOW
;
317 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
319 return DEBUG_LOC_BASE_ADDRESS
;
321 case DW_LLE_GNU_start_end_entry
:
322 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
324 return DEBUG_LOC_BUFFER_OVERFLOW
;
326 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
327 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
329 return DEBUG_LOC_BUFFER_OVERFLOW
;
331 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
333 return DEBUG_LOC_START_END
;
335 case DW_LLE_GNU_start_length_entry
:
336 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
338 return DEBUG_LOC_BUFFER_OVERFLOW
;
340 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
341 if (loc_ptr
+ 4 > buf_end
)
342 return DEBUG_LOC_BUFFER_OVERFLOW
;
345 *high
= (unrelocated_addr
) ((CORE_ADDR
) *high
346 + extract_unsigned_integer (loc_ptr
, 4,
348 *new_ptr
= loc_ptr
+ 4;
349 return DEBUG_LOC_START_LENGTH
;
352 return DEBUG_LOC_INVALID_ENTRY
;
356 /* A function for dealing with location lists. Given a
357 symbol baton (BATON) and a pc value (PC), find the appropriate
358 location expression, set *LOCEXPR_LENGTH, and return a pointer
359 to the beginning of the expression. Returns NULL on failure.
361 For now, only return the first matching location expression; there
362 can be more than one in the list. */
365 dwarf2_find_location_expression (const dwarf2_loclist_baton
*baton
,
366 size_t *locexpr_length
, const CORE_ADDR pc
,
369 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
370 struct objfile
*objfile
= per_objfile
->objfile
;
371 struct gdbarch
*gdbarch
= objfile
->arch ();
372 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
373 unsigned int addr_size
= baton
->per_cu
->addr_size ();
374 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
.get ());
375 /* Adjustment for relocatable objects. */
376 CORE_ADDR text_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
377 unrelocated_addr unrel_pc
= (unrelocated_addr
) (pc
- text_offset
);
378 unrelocated_addr base_address
= baton
->base_address
;
379 const gdb_byte
*loc_ptr
, *buf_end
;
381 loc_ptr
= baton
->data
;
382 buf_end
= baton
->data
+ baton
->size
;
386 unrelocated_addr low
= {}, high
= {}; /* init for gcc -Wall */
388 enum debug_loc_kind kind
;
389 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
391 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
392 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
394 loc_ptr
, buf_end
, &new_ptr
,
395 &low
, &high
, byte_order
);
396 else if (baton
->per_cu
->version () < 5)
397 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
399 byte_order
, addr_size
,
402 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
404 loc_ptr
, buf_end
, &new_ptr
,
405 &low
, &high
, byte_order
,
406 addr_size
, signed_addr_p
);
411 case DEBUG_LOC_END_OF_LIST
:
415 case DEBUG_LOC_BASE_ADDRESS
:
419 case DEBUG_LOC_START_END
:
420 case DEBUG_LOC_START_LENGTH
:
421 case DEBUG_LOC_OFFSET_PAIR
:
424 case DEBUG_LOC_BUFFER_OVERFLOW
:
425 case DEBUG_LOC_INVALID_ENTRY
:
426 error (_("dwarf2_find_location_expression: "
427 "Corrupted DWARF expression."));
430 gdb_assert_not_reached ("bad debug_loc_kind");
433 /* Otherwise, a location expression entry.
434 If the entry is from a DWO, don't add base address: the entry is from
435 .debug_addr which already has the DWARF "base address". We still add
436 text offset in case we're debugging a PIE executable. However, if the
437 entry is DW_LLE_offset_pair from a DWO, add the base address as the
438 operands are offsets relative to the applicable base address.
439 If the entry is DW_LLE_start_end or DW_LLE_start_length, then
440 it already is an address, and we don't need to add the base. */
441 if (!baton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
443 low
= (unrelocated_addr
) ((CORE_ADDR
) low
+ (CORE_ADDR
) base_address
);
444 high
= (unrelocated_addr
) ((CORE_ADDR
) high
+ (CORE_ADDR
) base_address
);
447 if (baton
->per_cu
->version () < 5)
449 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
454 unsigned int bytes_read
;
456 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
457 loc_ptr
+= bytes_read
;
460 if (low
== high
&& unrel_pc
== low
&& at_entry
)
462 /* This is entry PC record present only at entry point
463 of a function. Verify it is really the function entry point. */
465 const struct block
*pc_block
= block_for_pc (pc
);
466 struct symbol
*pc_func
= NULL
;
469 pc_func
= pc_block
->linkage_function ();
471 if (pc_func
&& pc
== pc_func
->value_block ()->entry_pc ())
473 *locexpr_length
= length
;
478 if (unrel_pc
>= low
&& unrel_pc
< high
)
480 *locexpr_length
= length
;
488 /* Implement find_frame_base_location method for LOC_BLOCK functions using
489 DWARF expression for its DW_AT_frame_base. */
492 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
493 const gdb_byte
**start
, size_t *length
)
495 struct dwarf2_locexpr_baton
*symbaton
496 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
498 *length
= symbaton
->size
;
499 *start
= symbaton
->data
;
502 /* Implement the struct symbol_block_ops::get_frame_base method for
503 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
506 locexpr_get_frame_base (struct symbol
*framefunc
, frame_info_ptr frame
)
508 struct gdbarch
*gdbarch
;
510 struct dwarf2_locexpr_baton
*dlbaton
;
511 const gdb_byte
*start
;
513 struct value
*result
;
515 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
516 Thus, it's supposed to provide the find_frame_base_location method as
518 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
520 gdbarch
= get_frame_arch (frame
);
521 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
522 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
524 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
525 (framefunc
, get_frame_pc (frame
), &start
, &length
);
526 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
527 dlbaton
->per_cu
, dlbaton
->per_objfile
);
529 /* The DW_AT_frame_base attribute contains a location description which
530 computes the base address itself. However, the call to
531 dwarf2_evaluate_loc_desc returns a value representing a variable at
532 that address. The frame base address is thus this variable's
534 return result
->address ();
537 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
538 function uses DWARF expression for its DW_AT_frame_base. */
540 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
542 locexpr_find_frame_base_location
,
543 locexpr_get_frame_base
546 /* Implement find_frame_base_location method for LOC_BLOCK functions using
547 DWARF location list for its DW_AT_frame_base. */
550 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
551 const gdb_byte
**start
, size_t *length
)
553 struct dwarf2_loclist_baton
*symbaton
554 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
556 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
559 /* Implement the struct symbol_block_ops::get_frame_base method for
560 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
563 loclist_get_frame_base (struct symbol
*framefunc
, frame_info_ptr frame
)
565 struct gdbarch
*gdbarch
;
567 struct dwarf2_loclist_baton
*dlbaton
;
568 const gdb_byte
*start
;
570 struct value
*result
;
572 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
573 Thus, it's supposed to provide the find_frame_base_location method as
575 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
577 gdbarch
= get_frame_arch (frame
);
578 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
579 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
581 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
582 (framefunc
, get_frame_pc (frame
), &start
, &length
);
583 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
584 dlbaton
->per_cu
, dlbaton
->per_objfile
);
586 /* The DW_AT_frame_base attribute contains a location description which
587 computes the base address itself. However, the call to
588 dwarf2_evaluate_loc_desc returns a value representing a variable at
589 that address. The frame base address is thus this variable's
591 return result
->address ();
594 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
595 function uses DWARF location list for its DW_AT_frame_base. */
597 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
599 loclist_find_frame_base_location
,
600 loclist_get_frame_base
603 /* See dwarf2/loc.h. */
606 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
607 const gdb_byte
**start
, size_t *length
)
609 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
611 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
613 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
619 error (_("Could not find the frame base for \"%s\"."),
620 framefunc
->natural_name ());
626 compute_var_value (const char *name
)
628 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
630 if (sym
.symbol
!= nullptr)
631 return value_of_variable (sym
.symbol
, sym
.block
);
635 /* See dwarf2/loc.h. */
637 unsigned int entry_values_debug
= 0;
639 /* Helper to set entry_values_debug. */
642 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
643 struct cmd_list_element
*c
, const char *value
)
646 _("Entry values and tail call frames debugging is %s.\n"),
650 /* See gdbtypes.h. */
653 call_site_target::iterate_over_addresses
654 (struct gdbarch
*call_site_gdbarch
,
655 const struct call_site
*call_site
,
656 frame_info_ptr caller_frame
,
657 iterate_ftype callback
) const
661 case call_site_target::DWARF_BLOCK
:
663 struct dwarf2_locexpr_baton
*dwarf_block
;
665 struct type
*caller_core_addr_type
;
666 struct gdbarch
*caller_arch
;
668 dwarf_block
= m_loc
.dwarf_block
;
669 if (dwarf_block
== NULL
)
671 struct bound_minimal_symbol msym
;
673 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
674 throw_error (NO_ENTRY_VALUE_ERROR
,
675 _("DW_AT_call_target is not specified at %s in %s"),
676 paddress (call_site_gdbarch
, call_site
->pc ()),
677 (msym
.minsym
== NULL
? "???"
678 : msym
.minsym
->print_name ()));
681 if (caller_frame
== NULL
)
683 struct bound_minimal_symbol msym
;
685 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
686 throw_error (NO_ENTRY_VALUE_ERROR
,
687 _("DW_AT_call_target DWARF block resolving "
688 "requires known frame which is currently not "
689 "available at %s in %s"),
690 paddress (call_site_gdbarch
, call_site
->pc ()),
691 (msym
.minsym
== NULL
? "???"
692 : msym
.minsym
->print_name ()));
695 caller_arch
= get_frame_arch (caller_frame
);
696 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
697 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
698 dwarf_block
->data
, dwarf_block
->size
,
700 dwarf_block
->per_objfile
);
701 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
702 if (val
->lval () == lval_memory
)
703 callback (val
->address ());
705 callback (value_as_address (val
));
709 case call_site_target::PHYSNAME
:
711 const char *physname
;
712 struct bound_minimal_symbol msym
;
714 physname
= m_loc
.physname
;
716 /* Handle both the mangled and demangled PHYSNAME. */
717 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
718 if (msym
.minsym
== NULL
)
720 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
721 throw_error (NO_ENTRY_VALUE_ERROR
,
722 _("Cannot find function \"%s\" for a call site target "
724 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
725 (msym
.minsym
== NULL
? "???"
726 : msym
.minsym
->print_name ()));
730 CORE_ADDR addr
= (gdbarch_convert_from_func_ptr_addr
731 (call_site_gdbarch
, msym
.value_address (),
732 current_inferior ()->top_target ()));
737 case call_site_target::PHYSADDR
:
739 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
741 callback (per_objfile
->relocate (m_loc
.physaddr
));
745 case call_site_target::ADDRESSES
:
747 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
749 for (unsigned i
= 0; i
< m_loc
.addresses
.length
; ++i
)
750 callback (per_objfile
->relocate (m_loc
.addresses
.values
[i
]));
755 internal_error (_("invalid call site target kind"));
759 /* Convert function entry point exact address ADDR to the function which is
760 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
761 NO_ENTRY_VALUE_ERROR otherwise. */
763 static struct symbol
*
764 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
766 struct symbol
*sym
= find_pc_function (addr
);
769 if (sym
== NULL
|| sym
->value_block ()->entry_pc () != addr
)
770 throw_error (NO_ENTRY_VALUE_ERROR
,
771 _("DW_TAG_call_site resolving failed to find function "
772 "name for address %s"),
773 paddress (gdbarch
, addr
));
776 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
777 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
782 /* Verify function with entry point exact address ADDR can never call itself
783 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
784 can call itself via tail calls.
786 If a funtion can tail call itself its entry value based parameters are
787 unreliable. There is no verification whether the value of some/all
788 parameters is unchanged through the self tail call, we expect if there is
789 a self tail call all the parameters can be modified. */
792 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
796 /* The verification is completely unordered. Track here function addresses
797 which still need to be iterated. */
798 std::vector
<CORE_ADDR
> todo
;
800 /* Track here CORE_ADDRs which were already visited. */
801 std::unordered_set
<CORE_ADDR
> addr_hash
;
803 todo
.push_back (verify_addr
);
804 while (!todo
.empty ())
806 struct symbol
*func_sym
;
807 struct call_site
*call_site
;
812 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
814 for (call_site
= TYPE_TAIL_CALL_LIST (func_sym
->type ());
815 call_site
; call_site
= call_site
->tail_call_next
)
817 /* CALLER_FRAME with registers is not available for tail-call jumped
819 call_site
->iterate_over_addresses (gdbarch
, nullptr,
820 [&] (CORE_ADDR target_addr
)
822 if (target_addr
== verify_addr
)
824 struct bound_minimal_symbol msym
;
826 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
827 throw_error (NO_ENTRY_VALUE_ERROR
,
828 _("DW_OP_entry_value resolving has found "
829 "function \"%s\" at %s can call itself via tail "
831 (msym
.minsym
== NULL
? "???"
832 : msym
.minsym
->print_name ()),
833 paddress (gdbarch
, verify_addr
));
836 if (addr_hash
.insert (target_addr
).second
)
837 todo
.push_back (target_addr
);
843 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
844 ENTRY_VALUES_DEBUG. */
847 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
849 CORE_ADDR addr
= call_site
->pc ();
850 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
852 gdb_printf (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
853 (msym
.minsym
== NULL
? "???"
854 : msym
.minsym
->print_name ()));
858 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
859 only top callers and bottom callees which are present in both. GDBARCH is
860 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
861 no remaining possibilities to provide unambiguous non-trivial result.
862 RESULTP should point to NULL on the first (initialization) call. Caller is
863 responsible for xfree of any RESULTP data. */
866 chain_candidate (struct gdbarch
*gdbarch
,
867 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
868 const std::vector
<struct call_site
*> &chain
)
870 long length
= chain
.size ();
871 int callers
, callees
, idx
;
873 if (*resultp
== NULL
)
875 /* Create the initial chain containing all the passed PCs. */
877 struct call_site_chain
*result
878 = ((struct call_site_chain
*)
879 xmalloc (sizeof (*result
)
880 + sizeof (*result
->call_site
) * (length
- 1)));
881 result
->length
= length
;
882 result
->callers
= result
->callees
= length
;
884 memcpy (result
->call_site
, chain
.data (),
885 sizeof (*result
->call_site
) * length
);
886 resultp
->reset (result
);
888 if (entry_values_debug
)
890 gdb_printf (gdb_stdlog
, "tailcall: initial:");
891 for (idx
= 0; idx
< length
; idx
++)
892 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
893 gdb_putc ('\n', gdb_stdlog
);
899 if (entry_values_debug
)
901 gdb_printf (gdb_stdlog
, "tailcall: compare:");
902 for (idx
= 0; idx
< length
; idx
++)
903 tailcall_dump (gdbarch
, chain
[idx
]);
904 gdb_putc ('\n', gdb_stdlog
);
907 /* Intersect callers. */
909 callers
= std::min ((long) (*resultp
)->callers
, length
);
910 for (idx
= 0; idx
< callers
; idx
++)
911 if ((*resultp
)->call_site
[idx
] != chain
[idx
])
913 (*resultp
)->callers
= idx
;
917 /* Intersect callees. */
919 callees
= std::min ((long) (*resultp
)->callees
, length
);
920 for (idx
= 0; idx
< callees
; idx
++)
921 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
922 != chain
[length
- 1 - idx
])
924 (*resultp
)->callees
= idx
;
928 if (entry_values_debug
)
930 gdb_printf (gdb_stdlog
, "tailcall: reduced:");
931 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
932 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
933 gdb_puts (" |", gdb_stdlog
);
934 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
935 tailcall_dump (gdbarch
,
936 (*resultp
)->call_site
[(*resultp
)->length
937 - (*resultp
)->callees
+ idx
]);
938 gdb_putc ('\n', gdb_stdlog
);
941 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
943 /* There are no common callers or callees. It could be also a direct
944 call (which has length 0) with ambiguous possibility of an indirect
945 call - CALLERS == CALLEES == 0 is valid during the first allocation
946 but any subsequence processing of such entry means ambiguity. */
947 resultp
->reset (NULL
);
951 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
952 PC again. In such case there must be two different code paths to reach
953 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
954 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
957 /* Recursively try to construct the call chain. GDBARCH, RESULTP, and
958 CHAIN are passed to chain_candidate. ADDR_HASH tracks which
959 addresses have already been seen along the current chain.
960 CALL_SITE is the call site to visit, and CALLEE_PC is the PC we're
961 trying to "reach". Returns false if an error has already been
962 detected and so an early return can be done. If it makes sense to
963 keep trying (even if no answer has yet been found), returns
967 call_site_find_chain_2
968 (struct gdbarch
*gdbarch
,
969 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
970 std::vector
<struct call_site
*> &chain
,
971 std::unordered_set
<CORE_ADDR
> &addr_hash
,
972 struct call_site
*call_site
,
975 std::vector
<CORE_ADDR
> addresses
;
976 bool found_exact
= false;
977 call_site
->iterate_over_addresses (gdbarch
, nullptr,
980 if (addr
== callee_pc
)
983 addresses
.push_back (addr
);
988 chain_candidate (gdbarch
, resultp
, chain
);
989 /* If RESULTP was reset, then chain_candidate failed, and so we
990 can tell our callers to early-return. */
991 return *resultp
!= nullptr;
994 for (CORE_ADDR target_func_addr
: addresses
)
996 struct symbol
*target_func
997 = func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
998 for (struct call_site
*target_call_site
999 = TYPE_TAIL_CALL_LIST (target_func
->type ());
1000 target_call_site
!= nullptr;
1001 target_call_site
= target_call_site
->tail_call_next
)
1003 if (addr_hash
.insert (target_call_site
->pc ()).second
)
1005 /* Successfully entered TARGET_CALL_SITE. */
1006 chain
.push_back (target_call_site
);
1008 if (!call_site_find_chain_2 (gdbarch
, resultp
, chain
,
1009 addr_hash
, target_call_site
,
1013 size_t removed
= addr_hash
.erase (target_call_site
->pc ());
1014 gdb_assert (removed
== 1);
1023 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All
1024 the assumed frames between them use GDBARCH. Any unreliability
1025 results in thrown NO_ENTRY_VALUE_ERROR. */
1027 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1028 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1029 CORE_ADDR callee_pc
)
1031 CORE_ADDR save_callee_pc
= callee_pc
;
1032 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1033 struct call_site
*call_site
;
1035 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1036 call_site nor any possible call_site at CALLEE_PC's function is there.
1037 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1038 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1039 std::vector
<struct call_site
*> chain
;
1041 /* A given call site may have multiple associated addresses. This
1042 can happen if, e.g., the caller is split by hot/cold
1043 partitioning. This vector tracks the ones we haven't visited
1045 std::vector
<std::vector
<CORE_ADDR
>> unvisited_addresses
;
1047 /* We are not interested in the specific PC inside the callee function. */
1048 callee_pc
= get_pc_function_start (callee_pc
);
1050 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1051 paddress (gdbarch
, save_callee_pc
));
1053 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1054 std::unordered_set
<CORE_ADDR
> addr_hash
;
1056 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1057 at the target's function. All the possible tail call sites in the
1058 target's function will get iterated as already pushed into CHAIN via their
1060 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1061 /* No need to check the return value here, because we no longer care
1062 about possible early returns. */
1063 call_site_find_chain_2 (gdbarch
, &retval
, chain
, addr_hash
, call_site
,
1068 struct bound_minimal_symbol msym_caller
, msym_callee
;
1070 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1071 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1072 throw_error (NO_ENTRY_VALUE_ERROR
,
1073 _("There are no unambiguously determinable intermediate "
1074 "callers or callees between caller function \"%s\" at %s "
1075 "and callee function \"%s\" at %s"),
1076 (msym_caller
.minsym
== NULL
1077 ? "???" : msym_caller
.minsym
->print_name ()),
1078 paddress (gdbarch
, caller_pc
),
1079 (msym_callee
.minsym
== NULL
1080 ? "???" : msym_callee
.minsym
->print_name ()),
1081 paddress (gdbarch
, callee_pc
));
1087 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1088 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1089 constructed return NULL. */
1091 gdb::unique_xmalloc_ptr
<call_site_chain
>
1092 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1093 CORE_ADDR callee_pc
)
1095 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1099 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1101 catch (const gdb_exception_error
&e
)
1103 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1105 if (entry_values_debug
)
1106 exception_print (gdb_stdout
, e
);
1117 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1120 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1121 enum call_site_parameter_kind kind
,
1122 union call_site_parameter_u kind_u
)
1124 if (kind
== parameter
->kind
)
1127 case CALL_SITE_PARAMETER_DWARF_REG
:
1128 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1130 case CALL_SITE_PARAMETER_FB_OFFSET
:
1131 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1133 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1134 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1141 struct call_site_parameter
*
1142 dwarf_expr_reg_to_entry_parameter (frame_info_ptr frame
,
1143 enum call_site_parameter_kind kind
,
1144 union call_site_parameter_u kind_u
,
1145 dwarf2_per_cu_data
**per_cu_return
,
1146 dwarf2_per_objfile
**per_objfile_return
)
1148 CORE_ADDR func_addr
, caller_pc
;
1149 struct gdbarch
*gdbarch
;
1150 frame_info_ptr caller_frame
;
1151 struct call_site
*call_site
;
1153 /* Initialize it just to avoid a GCC false warning. */
1154 struct call_site_parameter
*parameter
= NULL
;
1155 CORE_ADDR target_addr
;
1157 while (get_frame_type (frame
) == INLINE_FRAME
)
1159 frame
= get_prev_frame (frame
);
1160 gdb_assert (frame
!= NULL
);
1163 func_addr
= get_frame_func (frame
);
1164 gdbarch
= get_frame_arch (frame
);
1165 caller_frame
= get_prev_frame (frame
);
1166 if (gdbarch
!= frame_unwind_arch (frame
))
1168 struct bound_minimal_symbol msym
1169 = lookup_minimal_symbol_by_pc (func_addr
);
1170 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1172 throw_error (NO_ENTRY_VALUE_ERROR
,
1173 _("DW_OP_entry_value resolving callee gdbarch %s "
1174 "(of %s (%s)) does not match caller gdbarch %s"),
1175 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1176 paddress (gdbarch
, func_addr
),
1177 (msym
.minsym
== NULL
? "???"
1178 : msym
.minsym
->print_name ()),
1179 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1182 if (caller_frame
== NULL
)
1184 struct bound_minimal_symbol msym
1185 = lookup_minimal_symbol_by_pc (func_addr
);
1187 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1188 "requires caller of %s (%s)"),
1189 paddress (gdbarch
, func_addr
),
1190 (msym
.minsym
== NULL
? "???"
1191 : msym
.minsym
->print_name ()));
1193 caller_pc
= get_frame_pc (caller_frame
);
1194 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1198 call_site
->iterate_over_addresses (gdbarch
, caller_frame
,
1199 [&] (CORE_ADDR addr
)
1201 /* Preserve any address. */
1204 if (addr
== func_addr
)
1209 struct minimal_symbol
*target_msym
, *func_msym
;
1211 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1212 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1213 throw_error (NO_ENTRY_VALUE_ERROR
,
1214 _("DW_OP_entry_value resolving expects callee %s at %s %s"
1215 "but the called frame is for %s at %s"),
1216 (target_msym
== NULL
? "???"
1217 : target_msym
->print_name ()),
1218 paddress (gdbarch
, target_addr
),
1220 ? _("(but note there are multiple addresses not listed)")
1222 func_msym
== NULL
? "???" : func_msym
->print_name (),
1223 paddress (gdbarch
, func_addr
));
1226 /* No entry value based parameters would be reliable if this function can
1227 call itself via tail calls. */
1228 func_verify_no_selftailcall (gdbarch
, func_addr
);
1230 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1232 parameter
= &call_site
->parameter
[iparams
];
1233 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1236 if (iparams
== call_site
->parameter_count
)
1238 struct minimal_symbol
*msym
1239 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1241 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1242 determine its value. */
1243 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1244 "at DW_TAG_call_site %s at %s"),
1245 paddress (gdbarch
, caller_pc
),
1246 msym
== NULL
? "???" : msym
->print_name ());
1249 *per_cu_return
= call_site
->per_cu
;
1250 *per_objfile_return
= call_site
->per_objfile
;
1254 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1255 the normal DW_AT_call_value block. Otherwise return the
1256 DW_AT_call_data_value (dereferenced) block.
1258 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1261 Function always returns non-NULL, non-optimized out value. It throws
1262 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1264 static struct value
*
1265 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1266 CORE_ADDR deref_size
, struct type
*type
,
1267 frame_info_ptr caller_frame
,
1268 dwarf2_per_cu_data
*per_cu
,
1269 dwarf2_per_objfile
*per_objfile
)
1271 const gdb_byte
*data_src
;
1274 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1275 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1277 /* DEREF_SIZE size is not verified here. */
1278 if (data_src
== NULL
)
1279 throw_error (NO_ENTRY_VALUE_ERROR
,
1280 _("Cannot resolve DW_AT_call_data_value"));
1282 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1283 per_objfile
, false);
1286 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1287 the indirect method on it, that is use its stored target value, the sole
1288 purpose of entry_data_value_funcs.. */
1290 static struct value
*
1291 entry_data_value_coerce_ref (const struct value
*value
)
1293 struct type
*checked_type
= check_typedef (value
->type ());
1294 struct value
*target_val
;
1296 if (!TYPE_IS_REFERENCE (checked_type
))
1299 target_val
= (struct value
*) value
->computed_closure ();
1300 target_val
->incref ();
1304 /* Implement copy_closure. */
1307 entry_data_value_copy_closure (const struct value
*v
)
1309 struct value
*target_val
= (struct value
*) v
->computed_closure ();
1311 target_val
->incref ();
1315 /* Implement free_closure. */
1318 entry_data_value_free_closure (struct value
*v
)
1320 struct value
*target_val
= (struct value
*) v
->computed_closure ();
1322 target_val
->decref ();
1325 /* Vector for methods for an entry value reference where the referenced value
1326 is stored in the caller. On the first dereference use
1327 DW_AT_call_data_value in the caller. */
1329 static const struct lval_funcs entry_data_value_funcs
=
1334 NULL
, /* indirect */
1335 entry_data_value_coerce_ref
,
1336 NULL
, /* check_synthetic_pointer */
1337 entry_data_value_copy_closure
,
1338 entry_data_value_free_closure
1341 /* See dwarf2/loc.h. */
1343 value_of_dwarf_reg_entry (struct type
*type
, frame_info_ptr frame
,
1344 enum call_site_parameter_kind kind
,
1345 union call_site_parameter_u kind_u
)
1347 struct type
*checked_type
= check_typedef (type
);
1348 struct type
*target_type
= checked_type
->target_type ();
1349 frame_info_ptr caller_frame
= get_prev_frame (frame
);
1350 struct value
*outer_val
, *target_val
, *val
;
1351 struct call_site_parameter
*parameter
;
1352 dwarf2_per_cu_data
*caller_per_cu
;
1353 dwarf2_per_objfile
*caller_per_objfile
;
1355 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1357 &caller_per_objfile
);
1359 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1362 caller_per_objfile
);
1364 /* Check if DW_AT_call_data_value cannot be used. If it should be
1365 used and it is not available do not fall back to OUTER_VAL - dereferencing
1366 TYPE_CODE_REF with non-entry data value would give current value - not the
1369 if (!TYPE_IS_REFERENCE (checked_type
)
1370 || checked_type
->target_type () == NULL
)
1373 target_val
= dwarf_entry_parameter_to_value (parameter
,
1374 target_type
->length (),
1375 target_type
, caller_frame
,
1377 caller_per_objfile
);
1379 val
= value::allocate_computed (type
, &entry_data_value_funcs
,
1380 release_value (target_val
).release ());
1382 /* Copy the referencing pointer to the new computed value. */
1383 memcpy (val
->contents_raw ().data (),
1384 outer_val
->contents_raw ().data (),
1385 checked_type
->length ());
1386 val
->set_lazy (false);
1391 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1392 SIZE are DWARF block used to match DW_AT_location at the caller's
1393 DW_TAG_call_site_parameter.
1395 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1396 cannot resolve the parameter for any reason. */
1398 static struct value
*
1399 value_of_dwarf_block_entry (struct type
*type
, frame_info_ptr frame
,
1400 const gdb_byte
*block
, size_t block_len
)
1402 union call_site_parameter_u kind_u
;
1404 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1405 if (kind_u
.dwarf_reg
!= -1)
1406 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1409 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1410 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1413 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1414 suppressed during normal operation. The expression can be arbitrary if
1415 there is no caller-callee entry value binding expected. */
1416 throw_error (NO_ENTRY_VALUE_ERROR
,
1417 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1418 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1421 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1423 static struct value
*
1424 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1425 dwarf2_per_cu_data
*per_cu
,
1426 dwarf2_per_objfile
*per_objfile
,
1429 struct value
*result
= NULL
;
1430 const gdb_byte
*bytes
;
1433 auto_obstack temp_obstack
;
1434 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1435 &temp_obstack
, &len
);
1439 if (byte_offset
>= 0
1440 && byte_offset
+ type
->target_type ()->length () <= len
)
1442 bytes
+= byte_offset
;
1443 result
= value_from_contents (type
->target_type (), bytes
);
1446 invalid_synthetic_pointer ();
1449 result
= value::allocate_optimized_out (type
->target_type ());
1457 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1458 dwarf2_per_cu_data
*per_cu
,
1459 dwarf2_per_objfile
*per_objfile
,
1460 frame_info_ptr frame
, struct type
*type
,
1461 bool resolve_abstract_p
)
1463 /* Fetch the location expression of the DIE we're pointing to. */
1464 auto get_frame_address_in_block_wrapper
= [frame
] ()
1466 return get_frame_address_in_block (frame
);
1468 struct dwarf2_locexpr_baton baton
1469 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1470 get_frame_address_in_block_wrapper
,
1471 resolve_abstract_p
);
1473 /* Get type of pointed-to DIE. */
1474 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1476 if (orig_type
== NULL
)
1477 invalid_synthetic_pointer ();
1479 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1480 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1481 or it may've been optimized out. */
1482 if (baton
.data
!= NULL
)
1483 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1484 baton
.size
, baton
.per_cu
,
1486 type
->target_type (),
1489 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1493 /* Evaluate a location description, starting at DATA and with length
1494 SIZE, to find the current location of variable of TYPE in the
1495 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1496 location of the subobject of type SUBOBJ_TYPE at byte offset
1497 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1499 static struct value
*
1500 dwarf2_evaluate_loc_desc_full (struct type
*type
, frame_info_ptr frame
,
1501 const gdb_byte
*data
, size_t size
,
1502 dwarf2_per_cu_data
*per_cu
,
1503 dwarf2_per_objfile
*per_objfile
,
1504 struct type
*subobj_type
,
1505 LONGEST subobj_byte_offset
,
1508 if (subobj_type
== NULL
)
1511 subobj_byte_offset
= 0;
1513 else if (subobj_byte_offset
< 0)
1514 invalid_synthetic_pointer ();
1517 return value::allocate_optimized_out (subobj_type
);
1519 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1522 scoped_value_mark free_values
;
1526 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1527 type
, subobj_type
, subobj_byte_offset
);
1529 catch (const gdb_exception_error
&ex
)
1531 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1533 free_values
.free_to_mark ();
1534 retval
= value::allocate (subobj_type
);
1535 retval
->mark_bytes_unavailable (0,
1536 subobj_type
->length ());
1539 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1541 if (entry_values_debug
)
1542 exception_print (gdb_stdout
, ex
);
1543 free_values
.free_to_mark ();
1544 return value::allocate_optimized_out (subobj_type
);
1550 /* We need to clean up all the values that are not needed any more.
1551 The problem with a value_ref_ptr class is that it disconnects the
1552 RETVAL from the value garbage collection, so we need to make
1553 a copy of that value on the stack to keep everything consistent.
1554 The value_ref_ptr will clean up after itself at the end of this block. */
1555 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1556 free_values
.free_to_mark ();
1558 return retval
->copy ();
1561 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1562 passes 0 as the byte_offset. */
1565 dwarf2_evaluate_loc_desc (struct type
*type
, frame_info_ptr frame
,
1566 const gdb_byte
*data
, size_t size
,
1567 dwarf2_per_cu_data
*per_cu
,
1568 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1570 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1571 per_objfile
, NULL
, 0, as_lval
);
1574 /* Evaluates a dwarf expression and stores the result in VAL,
1575 expecting that the dwarf expression only produces a single
1576 CORE_ADDR. FRAME is the frame in which the expression is
1577 evaluated. ADDR_STACK is a context (location of a variable) and
1578 might be needed to evaluate the location expression.
1580 PUSH_VALUES is an array of values to be pushed to the expression stack
1581 before evaluation starts. PUSH_VALUES[0] is pushed first, then
1582 PUSH_VALUES[1], and so on.
1584 Returns 1 on success, 0 otherwise. */
1587 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1588 frame_info_ptr frame
,
1589 const struct property_addr_info
*addr_stack
,
1591 gdb::array_view
<CORE_ADDR
> push_values
,
1594 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1597 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1598 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1599 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1602 scoped_value_mark free_values
;
1604 /* Place any initial values onto the expression stack. */
1605 for (const auto &val
: push_values
)
1606 ctx
.push_address (val
, false);
1610 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1611 true, per_cu
, frame
, addr_stack
);
1613 catch (const gdb_exception_error
&ex
)
1615 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1619 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1621 if (entry_values_debug
)
1622 exception_print (gdb_stdout
, ex
);
1629 if (result
->optimized_out ())
1632 if (result
->lval () == lval_memory
)
1633 *valp
= result
->address ();
1636 if (result
->lval () == not_lval
)
1637 *is_reference
= false;
1639 *valp
= value_as_address (result
);
1645 /* See dwarf2/loc.h. */
1648 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1649 frame_info_ptr frame
,
1650 const struct property_addr_info
*addr_stack
,
1652 gdb::array_view
<CORE_ADDR
> push_values
)
1657 /* Evaluating a property should not change the current language.
1658 Without this here this could happen if the code below selects a
1660 scoped_restore_current_language save_language
;
1662 if (frame
== NULL
&& has_stack_frames ())
1663 frame
= get_selected_frame (NULL
);
1665 switch (prop
->kind ())
1669 const struct dwarf2_property_baton
*baton
= prop
->baton ();
1670 gdb_assert (baton
->property_type
!= NULL
);
1672 bool is_reference
= baton
->locexpr
.is_reference
;
1673 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1674 value
, push_values
, &is_reference
))
1678 struct value
*val
= value_at (baton
->property_type
, *value
);
1679 *value
= value_as_address (val
);
1683 gdb_assert (baton
->property_type
!= NULL
);
1685 struct type
*type
= check_typedef (baton
->property_type
);
1686 if (type
->length () < sizeof (CORE_ADDR
)
1687 && !type
->is_unsigned ())
1689 /* If we have a valid return candidate and it's value
1690 is signed, we have to sign-extend the value because
1691 CORE_ADDR on 64bit machine has 8 bytes but address
1692 size of an 32bit application is bytes. */
1694 = (baton
->locexpr
.per_cu
->addr_size ()
1696 const CORE_ADDR neg_mask
1697 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1699 /* Check if signed bit is set and sign-extend values. */
1700 if (*value
& neg_mask
)
1711 const dwarf2_property_baton
*baton
= prop
->baton ();
1713 const gdb_byte
*data
;
1718 || !get_frame_address_in_block_if_available (frame
, &pc
))
1721 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1724 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1725 size
, baton
->loclist
.per_cu
,
1726 baton
->loclist
.per_objfile
);
1727 if (!val
->optimized_out ())
1729 *value
= value_as_address (val
);
1737 *value
= prop
->const_val ();
1740 case PROP_ADDR_OFFSET
:
1742 const dwarf2_property_baton
*baton
= prop
->baton ();
1743 const struct property_addr_info
*pinfo
;
1746 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1748 /* This approach lets us avoid checking the qualifiers. */
1749 if (TYPE_MAIN_TYPE (pinfo
->type
)
1750 == TYPE_MAIN_TYPE (baton
->property_type
))
1754 error (_("cannot find reference address for offset property"));
1755 if (pinfo
->valaddr
.data () != NULL
)
1756 val
= value_from_contents
1757 (baton
->offset_info
.type
,
1758 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1760 val
= value_at (baton
->offset_info
.type
,
1761 pinfo
->addr
+ baton
->offset_info
.offset
);
1762 *value
= value_as_address (val
);
1766 case PROP_VARIABLE_NAME
:
1768 struct value
*val
= compute_var_value (prop
->variable_name ());
1771 *value
= value_as_long (val
);
1781 /* See dwarf2/loc.h. */
1784 dwarf2_compile_property_to_c (string_file
*stream
,
1785 const char *result_name
,
1786 struct gdbarch
*gdbarch
,
1787 std::vector
<bool> ®isters_used
,
1788 const struct dynamic_prop
*prop
,
1792 const dwarf2_property_baton
*baton
= prop
->baton ();
1793 const gdb_byte
*data
;
1795 dwarf2_per_cu_data
*per_cu
;
1796 dwarf2_per_objfile
*per_objfile
;
1798 if (prop
->kind () == PROP_LOCEXPR
)
1800 data
= baton
->locexpr
.data
;
1801 size
= baton
->locexpr
.size
;
1802 per_cu
= baton
->locexpr
.per_cu
;
1803 per_objfile
= baton
->locexpr
.per_objfile
;
1807 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1809 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1810 per_cu
= baton
->loclist
.per_cu
;
1811 per_objfile
= baton
->loclist
.per_objfile
;
1814 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1815 gdbarch
, registers_used
,
1816 per_cu
->addr_size (),
1817 data
, data
+ size
, per_cu
, per_objfile
);
1820 /* Compute the correct symbol_needs_kind value for the location
1823 Implemented by traversing the logical control flow graph of the
1826 static enum symbol_needs_kind
1827 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1828 dwarf2_per_cu_data
*per_cu
,
1829 dwarf2_per_objfile
*per_objfile
,
1830 bfd_endian byte_order
,
1835 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1837 /* If the expression is empty, we have nothing to do. */
1839 return symbol_needs
;
1841 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1843 /* List of operations to visit. Operations in this list are not visited yet,
1844 so are not in VISITED_OPS (and vice-versa). */
1845 std::vector
<const gdb_byte
*> ops_to_visit
;
1847 /* Operations already visited. */
1848 std::unordered_set
<const gdb_byte
*> visited_ops
;
1850 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1851 hasn't been visited yet. */
1852 auto insert_in_ops_to_visit
1853 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1855 if (op_ptr
>= expr_end
)
1858 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1861 ops_to_visit
.push_back (op_ptr
);
1864 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1866 const int max_depth
= 256;
1868 if (depth
> max_depth
)
1869 error (_("DWARF-2 expression error: Loop detected."));
1873 /* Initialize the to-visit list with the first operation. */
1874 insert_in_ops_to_visit (&expr
[0]);
1876 while (!ops_to_visit
.empty ())
1878 /* Pop one op to visit, mark it as visited. */
1879 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1880 ops_to_visit
.pop_back ();
1881 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1882 visited_ops
.insert (op_ptr
);
1884 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1886 /* Most operations have a single possible following operation
1887 (they are not conditional branches). The code below updates
1888 OP_PTR to point to that following operation, which is pushed
1889 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1890 OP_PTR pointing just after the operand. */
1893 /* The DWARF expression might have a bug causing an infinite
1894 loop. In that case, quitting is the only way out. */
1931 case DW_OP_stack_value
:
1958 case DW_OP_GNU_push_tls_address
:
1960 case DW_OP_GNU_uninit
:
1961 case DW_OP_push_object_address
:
1964 case DW_OP_form_tls_address
:
1965 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1966 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1970 case DW_OP_GNU_convert
:
1971 case DW_OP_reinterpret
:
1972 case DW_OP_GNU_reinterpret
:
1974 case DW_OP_GNU_addr_index
:
1975 case DW_OP_GNU_const_index
:
1977 case DW_OP_plus_uconst
:
1979 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1983 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1986 case DW_OP_bit_piece
:
1987 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1988 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1991 case DW_OP_deref_type
:
1992 case DW_OP_GNU_deref_type
:
1994 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1998 op_ptr
+= addr_size
;
2088 case DW_OP_call_frame_cfa
:
2089 case DW_OP_entry_value
:
2090 case DW_OP_GNU_entry_value
:
2091 case DW_OP_GNU_parameter_ref
:
2092 case DW_OP_regval_type
:
2093 case DW_OP_GNU_regval_type
:
2094 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2097 case DW_OP_implicit_value
:
2100 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2105 case DW_OP_implicit_pointer
:
2106 case DW_OP_GNU_implicit_pointer
:
2107 op_ptr
+= ref_addr_size
;
2108 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2111 case DW_OP_deref_size
:
2118 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2126 /* This is the only operation that pushes two operations in
2127 the to-visit list, so handle it all here. */
2128 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2131 insert_in_ops_to_visit (op_ptr
+ offset
);
2132 insert_in_ops_to_visit (op_ptr
);
2139 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2141 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2144 auto get_frame_pc
= [&symbol_needs
] ()
2146 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2150 struct dwarf2_locexpr_baton baton
2151 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2155 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2156 we dont have to check the baton content. */
2157 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2159 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2160 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2163 = dwarf2_get_symbol_read_needs (sub_expr
,
2166 gdbarch_byte_order (arch
),
2167 baton
.per_cu
->addr_size (),
2168 baton
.per_cu
->ref_addr_size (),
2174 case DW_OP_GNU_variable_value
:
2176 sect_offset sect_off
2177 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2180 op_ptr
+= ref_addr_size
;
2182 struct type
*die_type
2183 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2186 if (die_type
== NULL
)
2187 error (_("Bad DW_OP_GNU_variable_value DIE."));
2189 /* Note: Things still work when the following test is
2190 removed. This test and error is here to conform to the
2191 proposed specification. */
2192 if (die_type
->code () != TYPE_CODE_INT
2193 && die_type
->code () != TYPE_CODE_PTR
)
2194 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2195 "an integer or pointer."));
2197 auto get_frame_pc
= [&symbol_needs
] ()
2199 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2203 struct dwarf2_locexpr_baton baton
2204 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2206 get_frame_pc
, true);
2208 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2209 we dont have to check the baton content. */
2210 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2212 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2213 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2216 = dwarf2_get_symbol_read_needs (sub_expr
,
2219 gdbarch_byte_order (arch
),
2220 baton
.per_cu
->addr_size (),
2221 baton
.per_cu
->ref_addr_size (),
2227 case DW_OP_const_type
:
2228 case DW_OP_GNU_const_type
:
2231 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2232 gdb_byte offset
= *op_ptr
++;
2238 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2241 /* If it is known that a frame information is
2242 needed we can stop parsing the expression. */
2243 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2246 insert_in_ops_to_visit (op_ptr
);
2249 return symbol_needs
;
2252 /* A helper function that throws an unimplemented error mentioning a
2253 given DWARF operator. */
2255 static void ATTRIBUTE_NORETURN
2256 unimplemented (unsigned int op
)
2258 const char *name
= get_DW_OP_name (op
);
2261 error (_("DWARF operator %s cannot be translated to an agent expression"),
2264 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2265 "to an agent expression"),
2269 /* See dwarf2/loc.h.
2271 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2272 can issue a complaint, which is better than having every target's
2273 implementation of dwarf2_reg_to_regnum do it. */
2276 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2278 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2282 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2287 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2288 Throw an error because DWARF_REG is bad. */
2291 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2293 /* Still want to print -1 as "-1".
2294 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2295 but that's overkill for now. */
2296 if ((int) dwarf_reg
== dwarf_reg
)
2297 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2298 error (_("Unable to access DWARF register number %s"),
2299 pulongest (dwarf_reg
));
2302 /* See dwarf2/loc.h. */
2305 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2309 if (dwarf_reg
> INT_MAX
)
2310 throw_bad_regnum_error (dwarf_reg
);
2311 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2312 bad, but that's ok. */
2313 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2315 throw_bad_regnum_error (dwarf_reg
);
2319 /* A helper function that emits an access to memory. ARCH is the
2320 target architecture. EXPR is the expression which we are building.
2321 NBITS is the number of bits we want to read. This emits the
2322 opcodes needed to read the memory and then extract the desired
2326 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2328 ULONGEST nbytes
= (nbits
+ 7) / 8;
2330 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2333 ax_trace_quick (expr
, nbytes
);
2336 ax_simple (expr
, aop_ref8
);
2337 else if (nbits
<= 16)
2338 ax_simple (expr
, aop_ref16
);
2339 else if (nbits
<= 32)
2340 ax_simple (expr
, aop_ref32
);
2342 ax_simple (expr
, aop_ref64
);
2344 /* If we read exactly the number of bytes we wanted, we're done. */
2345 if (8 * nbytes
== nbits
)
2348 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2350 /* On a bits-big-endian machine, we want the high-order
2352 ax_const_l (expr
, 8 * nbytes
- nbits
);
2353 ax_simple (expr
, aop_rsh_unsigned
);
2357 /* On a bits-little-endian box, we want the low-order NBITS. */
2358 ax_zero_ext (expr
, nbits
);
2362 /* Compile a DWARF location expression to an agent expression.
2364 EXPR is the agent expression we are building.
2365 LOC is the agent value we modify.
2366 ARCH is the architecture.
2367 ADDR_SIZE is the size of addresses, in bytes.
2368 OP_PTR is the start of the location expression.
2369 OP_END is one past the last byte of the location expression.
2371 This will throw an exception for various kinds of errors -- for
2372 example, if the expression cannot be compiled, or if the expression
2376 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2377 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2378 const gdb_byte
*op_end
,
2379 dwarf2_per_cu_data
*per_cu
,
2380 dwarf2_per_objfile
*per_objfile
)
2382 gdbarch
*arch
= expr
->gdbarch
;
2383 std::vector
<int> dw_labels
, patches
;
2384 const gdb_byte
* const base
= op_ptr
;
2385 const gdb_byte
*previous_piece
= op_ptr
;
2386 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2387 ULONGEST bits_collected
= 0;
2388 unsigned int addr_size_bits
= 8 * addr_size
;
2389 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2391 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2393 /* By default we are making an address. */
2394 loc
->kind
= axs_lvalue_memory
;
2396 while (op_ptr
< op_end
)
2398 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2399 uint64_t uoffset
, reg
;
2403 offsets
[op_ptr
- base
] = expr
->buf
.size ();
2406 /* Our basic approach to code generation is to map DWARF
2407 operations directly to AX operations. However, there are
2410 First, DWARF works on address-sized units, but AX always uses
2411 LONGEST. For most operations we simply ignore this
2412 difference; instead we generate sign extensions as needed
2413 before division and comparison operations. It would be nice
2414 to omit the sign extensions, but there is no way to determine
2415 the size of the target's LONGEST. (This code uses the size
2416 of the host LONGEST in some cases -- that is a bug but it is
2419 Second, some DWARF operations cannot be translated to AX.
2420 For these we simply fail. See
2421 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2456 ax_const_l (expr
, op
- DW_OP_lit0
);
2460 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2461 op_ptr
+= addr_size
;
2462 /* Some versions of GCC emit DW_OP_addr before
2463 DW_OP_GNU_push_tls_address. In this case the value is an
2464 index, not an address. We don't support things like
2465 branching between the address and the TLS op. */
2466 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2467 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2468 ax_const_l (expr
, uoffset
);
2472 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2477 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2482 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2487 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2492 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2497 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2502 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2507 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2512 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2513 ax_const_l (expr
, uoffset
);
2517 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2518 ax_const_l (expr
, offset
);
2553 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2554 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2555 loc
->kind
= axs_lvalue_register
;
2559 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2560 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2561 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2562 loc
->kind
= axs_lvalue_register
;
2565 case DW_OP_implicit_value
:
2569 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2570 if (op_ptr
+ len
> op_end
)
2571 error (_("DW_OP_implicit_value: too few bytes available."));
2572 if (len
> sizeof (ULONGEST
))
2573 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2576 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2579 dwarf_expr_require_composition (op_ptr
, op_end
,
2580 "DW_OP_implicit_value");
2582 loc
->kind
= axs_rvalue
;
2586 case DW_OP_stack_value
:
2587 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2588 loc
->kind
= axs_rvalue
;
2623 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2624 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2628 ax_const_l (expr
, offset
);
2629 ax_simple (expr
, aop_add
);
2635 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2636 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2637 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2641 ax_const_l (expr
, offset
);
2642 ax_simple (expr
, aop_add
);
2649 const gdb_byte
*datastart
;
2651 const struct block
*b
;
2652 struct symbol
*framefunc
;
2654 b
= block_for_pc (expr
->scope
);
2657 error (_("No block found for address"));
2659 framefunc
= b
->linkage_function ();
2662 error (_("No function found for block"));
2664 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2665 &datastart
, &datalen
);
2667 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2668 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2669 datastart
+ datalen
, per_cu
,
2671 if (loc
->kind
== axs_lvalue_register
)
2672 require_rvalue (expr
, loc
);
2676 ax_const_l (expr
, offset
);
2677 ax_simple (expr
, aop_add
);
2680 loc
->kind
= axs_lvalue_memory
;
2685 ax_simple (expr
, aop_dup
);
2689 ax_simple (expr
, aop_pop
);
2694 ax_pick (expr
, offset
);
2698 ax_simple (expr
, aop_swap
);
2706 ax_simple (expr
, aop_rot
);
2710 case DW_OP_deref_size
:
2714 if (op
== DW_OP_deref_size
)
2719 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2720 error (_("Unsupported size %d in %s"),
2721 size
, get_DW_OP_name (op
));
2722 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2727 /* Sign extend the operand. */
2728 ax_ext (expr
, addr_size_bits
);
2729 ax_simple (expr
, aop_dup
);
2730 ax_const_l (expr
, 0);
2731 ax_simple (expr
, aop_less_signed
);
2732 ax_simple (expr
, aop_log_not
);
2733 i
= ax_goto (expr
, aop_if_goto
);
2734 /* We have to emit 0 - X. */
2735 ax_const_l (expr
, 0);
2736 ax_simple (expr
, aop_swap
);
2737 ax_simple (expr
, aop_sub
);
2738 ax_label (expr
, i
, expr
->buf
.size ());
2742 /* No need to sign extend here. */
2743 ax_const_l (expr
, 0);
2744 ax_simple (expr
, aop_swap
);
2745 ax_simple (expr
, aop_sub
);
2749 /* Sign extend the operand. */
2750 ax_ext (expr
, addr_size_bits
);
2751 ax_simple (expr
, aop_bit_not
);
2754 case DW_OP_plus_uconst
:
2755 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2756 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2757 but we micro-optimize anyhow. */
2760 ax_const_l (expr
, reg
);
2761 ax_simple (expr
, aop_add
);
2766 ax_simple (expr
, aop_bit_and
);
2770 /* Sign extend the operands. */
2771 ax_ext (expr
, addr_size_bits
);
2772 ax_simple (expr
, aop_swap
);
2773 ax_ext (expr
, addr_size_bits
);
2774 ax_simple (expr
, aop_swap
);
2775 ax_simple (expr
, aop_div_signed
);
2779 ax_simple (expr
, aop_sub
);
2783 ax_simple (expr
, aop_rem_unsigned
);
2787 ax_simple (expr
, aop_mul
);
2791 ax_simple (expr
, aop_bit_or
);
2795 ax_simple (expr
, aop_add
);
2799 ax_simple (expr
, aop_lsh
);
2803 ax_simple (expr
, aop_rsh_unsigned
);
2807 ax_simple (expr
, aop_rsh_signed
);
2811 ax_simple (expr
, aop_bit_xor
);
2815 /* Sign extend the operands. */
2816 ax_ext (expr
, addr_size_bits
);
2817 ax_simple (expr
, aop_swap
);
2818 ax_ext (expr
, addr_size_bits
);
2819 /* Note no swap here: A <= B is !(B < A). */
2820 ax_simple (expr
, aop_less_signed
);
2821 ax_simple (expr
, aop_log_not
);
2825 /* Sign extend the operands. */
2826 ax_ext (expr
, addr_size_bits
);
2827 ax_simple (expr
, aop_swap
);
2828 ax_ext (expr
, addr_size_bits
);
2829 ax_simple (expr
, aop_swap
);
2830 /* A >= B is !(A < B). */
2831 ax_simple (expr
, aop_less_signed
);
2832 ax_simple (expr
, aop_log_not
);
2836 /* Sign extend the operands. */
2837 ax_ext (expr
, addr_size_bits
);
2838 ax_simple (expr
, aop_swap
);
2839 ax_ext (expr
, addr_size_bits
);
2840 /* No need for a second swap here. */
2841 ax_simple (expr
, aop_equal
);
2845 /* Sign extend the operands. */
2846 ax_ext (expr
, addr_size_bits
);
2847 ax_simple (expr
, aop_swap
);
2848 ax_ext (expr
, addr_size_bits
);
2849 ax_simple (expr
, aop_swap
);
2850 ax_simple (expr
, aop_less_signed
);
2854 /* Sign extend the operands. */
2855 ax_ext (expr
, addr_size_bits
);
2856 ax_simple (expr
, aop_swap
);
2857 ax_ext (expr
, addr_size_bits
);
2858 /* Note no swap here: A > B is B < A. */
2859 ax_simple (expr
, aop_less_signed
);
2863 /* Sign extend the operands. */
2864 ax_ext (expr
, addr_size_bits
);
2865 ax_simple (expr
, aop_swap
);
2866 ax_ext (expr
, addr_size_bits
);
2867 /* No need for a swap here. */
2868 ax_simple (expr
, aop_equal
);
2869 ax_simple (expr
, aop_log_not
);
2872 case DW_OP_call_frame_cfa
:
2875 CORE_ADDR text_offset
;
2877 const gdb_byte
*cfa_start
, *cfa_end
;
2879 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2881 &text_offset
, &cfa_start
, &cfa_end
))
2884 ax_reg (expr
, regnum
);
2887 ax_const_l (expr
, off
);
2888 ax_simple (expr
, aop_add
);
2893 /* Another expression. */
2894 ax_const_l (expr
, text_offset
);
2895 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2896 cfa_end
, per_cu
, per_objfile
);
2899 loc
->kind
= axs_lvalue_memory
;
2903 case DW_OP_GNU_push_tls_address
:
2904 case DW_OP_form_tls_address
:
2908 case DW_OP_push_object_address
:
2913 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2915 i
= ax_goto (expr
, aop_goto
);
2916 dw_labels
.push_back (op_ptr
+ offset
- base
);
2917 patches
.push_back (i
);
2921 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2923 /* Zero extend the operand. */
2924 ax_zero_ext (expr
, addr_size_bits
);
2925 i
= ax_goto (expr
, aop_if_goto
);
2926 dw_labels
.push_back (op_ptr
+ offset
- base
);
2927 patches
.push_back (i
);
2934 case DW_OP_bit_piece
:
2938 if (op_ptr
- 1 == previous_piece
)
2939 error (_("Cannot translate empty pieces to agent expressions"));
2940 previous_piece
= op_ptr
- 1;
2942 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2943 if (op
== DW_OP_piece
)
2949 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2951 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2952 error (_("Expression pieces exceed word size"));
2954 /* Access the bits. */
2957 case axs_lvalue_register
:
2958 ax_reg (expr
, loc
->u
.reg
);
2961 case axs_lvalue_memory
:
2962 /* Offset the pointer, if needed. */
2965 ax_const_l (expr
, uoffset
/ 8);
2966 ax_simple (expr
, aop_add
);
2969 access_memory (arch
, expr
, size
);
2973 /* For a bits-big-endian target, shift up what we already
2974 have. For a bits-little-endian target, shift up the
2975 new data. Note that there is a potential bug here if
2976 the DWARF expression leaves multiple values on the
2978 if (bits_collected
> 0)
2980 if (bits_big_endian
)
2982 ax_simple (expr
, aop_swap
);
2983 ax_const_l (expr
, size
);
2984 ax_simple (expr
, aop_lsh
);
2985 /* We don't need a second swap here, because
2986 aop_bit_or is symmetric. */
2990 ax_const_l (expr
, size
);
2991 ax_simple (expr
, aop_lsh
);
2993 ax_simple (expr
, aop_bit_or
);
2996 bits_collected
+= size
;
2997 loc
->kind
= axs_rvalue
;
3001 case DW_OP_GNU_uninit
:
3007 struct dwarf2_locexpr_baton block
;
3008 int size
= (op
== DW_OP_call2
? 2 : 4);
3010 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3013 auto get_frame_pc_from_expr
= [expr
] ()
3017 cu_offset cuoffset
= (cu_offset
) uoffset
;
3018 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3019 get_frame_pc_from_expr
);
3021 /* DW_OP_call_ref is currently not supported. */
3022 gdb_assert (block
.per_cu
== per_cu
);
3024 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3025 block
.data
+ block
.size
, per_cu
,
3030 case DW_OP_call_ref
:
3033 case DW_OP_GNU_variable_value
:
3041 /* Patch all the branches we emitted. */
3042 for (int i
= 0; i
< patches
.size (); ++i
)
3044 int targ
= offsets
[dw_labels
[i
]];
3046 internal_error (_("invalid label"));
3047 ax_label (expr
, patches
[i
], targ
);
3052 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3053 evaluator to calculate the location. */
3054 static struct value
*
3055 locexpr_read_variable (struct symbol
*symbol
, frame_info_ptr frame
)
3057 struct dwarf2_locexpr_baton
*dlbaton
3058 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3061 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, dlbaton
->data
,
3062 dlbaton
->size
, dlbaton
->per_cu
,
3063 dlbaton
->per_objfile
);
3068 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3069 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3072 static struct value
*
3073 locexpr_read_variable_at_entry (struct symbol
*symbol
, frame_info_ptr frame
)
3075 struct dwarf2_locexpr_baton
*dlbaton
3076 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3078 return value_of_dwarf_block_entry (symbol
->type (), frame
, dlbaton
->data
,
3082 /* Implementation of get_symbol_read_needs from
3083 symbol_computed_ops. */
3085 static enum symbol_needs_kind
3086 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3088 struct dwarf2_locexpr_baton
*dlbaton
3089 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3091 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3092 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3094 return dwarf2_get_symbol_read_needs (expr
,
3096 dlbaton
->per_objfile
,
3097 gdbarch_byte_order (arch
),
3098 dlbaton
->per_cu
->addr_size (),
3099 dlbaton
->per_cu
->ref_addr_size ());
3102 /* Return true if DATA points to the end of a piece. END is one past
3103 the last byte in the expression. */
3106 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3108 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3111 /* Helper for locexpr_describe_location_piece that finds the name of a
3115 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3119 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3120 We'd rather print *something* here than throw an error. */
3121 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3122 /* gdbarch_register_name may just return "", return something more
3123 descriptive for bad register numbers. */
3126 /* The text is output as "$bad_register_number".
3127 That is why we use the underscores. */
3128 return _("bad_register_number");
3130 return gdbarch_register_name (gdbarch
, regnum
);
3133 /* Nicely describe a single piece of a location, returning an updated
3134 position in the bytecode sequence. This function cannot recognize
3135 all locations; if a location is not recognized, it simply returns
3136 DATA. If there is an error during reading, e.g. we run off the end
3137 of the buffer, an error is thrown. */
3139 static const gdb_byte
*
3140 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3141 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3142 dwarf2_per_objfile
*per_objfile
,
3143 const gdb_byte
*data
, const gdb_byte
*end
,
3144 unsigned int addr_size
)
3146 objfile
*objfile
= per_objfile
->objfile
;
3147 struct gdbarch
*gdbarch
= objfile
->arch ();
3150 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3152 gdb_printf (stream
, _("a variable in $%s"),
3153 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3156 else if (data
[0] == DW_OP_regx
)
3160 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3161 gdb_printf (stream
, _("a variable in $%s"),
3162 locexpr_regname (gdbarch
, reg
));
3164 else if (data
[0] == DW_OP_fbreg
)
3166 const struct block
*b
;
3167 struct symbol
*framefunc
;
3169 int64_t frame_offset
;
3170 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3172 int64_t base_offset
= 0;
3174 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3175 if (!piece_end_p (new_data
, end
))
3179 b
= block_for_pc (addr
);
3182 error (_("No block found for address for symbol \"%s\"."),
3183 symbol
->print_name ());
3185 framefunc
= b
->linkage_function ();
3188 error (_("No function found for block for symbol \"%s\"."),
3189 symbol
->print_name ());
3191 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3193 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3195 const gdb_byte
*buf_end
;
3197 frame_reg
= base_data
[0] - DW_OP_breg0
;
3198 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3200 if (buf_end
!= base_data
+ base_size
)
3201 error (_("Unexpected opcode after "
3202 "DW_OP_breg%u for symbol \"%s\"."),
3203 frame_reg
, symbol
->print_name ());
3205 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3207 /* The frame base is just the register, with no offset. */
3208 frame_reg
= base_data
[0] - DW_OP_reg0
;
3213 /* We don't know what to do with the frame base expression,
3214 so we can't trace this variable; give up. */
3219 _("a variable at frame base reg $%s offset %s+%s"),
3220 locexpr_regname (gdbarch
, frame_reg
),
3221 plongest (base_offset
), plongest (frame_offset
));
3223 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3224 && piece_end_p (data
, end
))
3228 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3231 _("a variable at offset %s from base reg $%s"),
3233 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3236 /* The location expression for a TLS variable looks like this (on a
3239 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3240 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3242 0x3 is the encoding for DW_OP_addr, which has an operand as long
3243 as the size of an address on the target machine (here is 8
3244 bytes). Note that more recent version of GCC emit DW_OP_const4u
3245 or DW_OP_const8u, depending on address size, rather than
3246 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3247 The operand represents the offset at which the variable is within
3248 the thread local storage. */
3250 else if (data
+ 1 + addr_size
< end
3251 && (data
[0] == DW_OP_addr
3252 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3253 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3254 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3255 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3256 && piece_end_p (data
+ 2 + addr_size
, end
))
3259 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3260 gdbarch_byte_order (gdbarch
));
3263 _("a thread-local variable at offset 0x%s "
3264 "in the thread-local storage for `%s'"),
3265 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3267 data
+= 1 + addr_size
+ 1;
3270 /* With -gsplit-dwarf a TLS variable can also look like this:
3271 DW_AT_location : 3 byte block: fc 4 e0
3272 (DW_OP_GNU_const_index: 4;
3273 DW_OP_GNU_push_tls_address) */
3274 else if (data
+ 3 <= end
3275 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3276 && data
[0] == DW_OP_GNU_const_index
3278 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3279 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3280 && piece_end_p (data
+ 2 + leb128_size
, end
))
3284 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3285 offset
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3287 _("a thread-local variable at offset 0x%s "
3288 "in the thread-local storage for `%s'"),
3289 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3293 else if (data
[0] >= DW_OP_lit0
3294 && data
[0] <= DW_OP_lit31
3296 && data
[1] == DW_OP_stack_value
)
3298 gdb_printf (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3305 /* Disassemble an expression, stopping at the end of a piece or at the
3306 end of the expression. Returns a pointer to the next unread byte
3307 in the input expression. If ALL is nonzero, then this function
3308 will keep going until it reaches the end of the expression.
3309 If there is an error during reading, e.g. we run off the end
3310 of the buffer, an error is thrown. */
3312 static const gdb_byte
*
3313 disassemble_dwarf_expression (struct ui_file
*stream
,
3314 struct gdbarch
*arch
, unsigned int addr_size
,
3315 int offset_size
, const gdb_byte
*start
,
3316 const gdb_byte
*data
, const gdb_byte
*end
,
3317 int indent
, int all
,
3318 dwarf2_per_cu_data
*per_cu
,
3319 dwarf2_per_objfile
*per_objfile
)
3323 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3325 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3330 name
= get_DW_OP_name (op
);
3333 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3334 op
, (long) (data
- 1 - start
));
3335 gdb_printf (stream
, " %*ld: %s", indent
+ 4,
3336 (long) (data
- 1 - start
), name
);
3341 ul
= extract_unsigned_integer (data
, addr_size
,
3342 gdbarch_byte_order (arch
));
3344 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3348 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3350 gdb_printf (stream
, " %s", pulongest (ul
));
3354 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3356 gdb_printf (stream
, " %s", plongest (l
));
3360 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3362 gdb_printf (stream
, " %s", pulongest (ul
));
3366 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3368 gdb_printf (stream
, " %s", plongest (l
));
3372 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3374 gdb_printf (stream
, " %s", pulongest (ul
));
3378 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3380 gdb_printf (stream
, " %s", plongest (l
));
3384 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3386 gdb_printf (stream
, " %s", pulongest (ul
));
3390 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3392 gdb_printf (stream
, " %s", plongest (l
));
3396 data
= safe_read_uleb128 (data
, end
, &ul
);
3397 gdb_printf (stream
, " %s", pulongest (ul
));
3401 data
= safe_read_sleb128 (data
, end
, &l
);
3402 gdb_printf (stream
, " %s", plongest (l
));
3437 gdb_printf (stream
, " [$%s]",
3438 locexpr_regname (arch
, op
- DW_OP_reg0
));
3442 data
= safe_read_uleb128 (data
, end
, &ul
);
3443 gdb_printf (stream
, " %s [$%s]", pulongest (ul
),
3444 locexpr_regname (arch
, (int) ul
));
3447 case DW_OP_implicit_value
:
3448 data
= safe_read_uleb128 (data
, end
, &ul
);
3450 gdb_printf (stream
, " %s", pulongest (ul
));
3485 data
= safe_read_sleb128 (data
, end
, &l
);
3486 gdb_printf (stream
, " %s [$%s]", plongest (l
),
3487 locexpr_regname (arch
, op
- DW_OP_breg0
));
3491 data
= safe_read_uleb128 (data
, end
, &ul
);
3492 data
= safe_read_sleb128 (data
, end
, &l
);
3493 gdb_printf (stream
, " register %s [$%s] offset %s",
3495 locexpr_regname (arch
, (int) ul
),
3500 data
= safe_read_sleb128 (data
, end
, &l
);
3501 gdb_printf (stream
, " %s", plongest (l
));
3504 case DW_OP_xderef_size
:
3505 case DW_OP_deref_size
:
3507 gdb_printf (stream
, " %d", *data
);
3511 case DW_OP_plus_uconst
:
3512 data
= safe_read_uleb128 (data
, end
, &ul
);
3513 gdb_printf (stream
, " %s", pulongest (ul
));
3517 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3519 gdb_printf (stream
, " to %ld",
3520 (long) (data
+ l
- start
));
3524 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3526 gdb_printf (stream
, " %ld",
3527 (long) (data
+ l
- start
));
3531 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3533 gdb_printf (stream
, " offset %s", phex_nz (ul
, 2));
3537 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3539 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3542 case DW_OP_call_ref
:
3543 ul
= extract_unsigned_integer (data
, offset_size
,
3544 gdbarch_byte_order (arch
));
3545 data
+= offset_size
;
3546 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3550 data
= safe_read_uleb128 (data
, end
, &ul
);
3551 gdb_printf (stream
, " %s (bytes)", pulongest (ul
));
3554 case DW_OP_bit_piece
:
3558 data
= safe_read_uleb128 (data
, end
, &ul
);
3559 data
= safe_read_uleb128 (data
, end
, &offset
);
3560 gdb_printf (stream
, " size %s offset %s (bits)",
3561 pulongest (ul
), pulongest (offset
));
3565 case DW_OP_implicit_pointer
:
3566 case DW_OP_GNU_implicit_pointer
:
3568 ul
= extract_unsigned_integer (data
, offset_size
,
3569 gdbarch_byte_order (arch
));
3570 data
+= offset_size
;
3572 data
= safe_read_sleb128 (data
, end
, &l
);
3574 gdb_printf (stream
, " DIE %s offset %s",
3575 phex_nz (ul
, offset_size
),
3580 case DW_OP_deref_type
:
3581 case DW_OP_GNU_deref_type
:
3583 int deref_addr_size
= *data
++;
3586 data
= safe_read_uleb128 (data
, end
, &ul
);
3587 cu_offset offset
= (cu_offset
) ul
;
3588 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3589 gdb_printf (stream
, "<");
3590 type_print (type
, "", stream
, -1);
3591 gdb_printf (stream
, " [0x%s]> %d",
3592 phex_nz (to_underlying (offset
), 0),
3597 case DW_OP_const_type
:
3598 case DW_OP_GNU_const_type
:
3602 data
= safe_read_uleb128 (data
, end
, &ul
);
3603 cu_offset type_die
= (cu_offset
) ul
;
3604 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3605 gdb_printf (stream
, "<");
3606 type_print (type
, "", stream
, -1);
3607 gdb_printf (stream
, " [0x%s]>",
3608 phex_nz (to_underlying (type_die
), 0));
3611 gdb_printf (stream
, " %d byte block:", n
);
3612 for (int i
= 0; i
< n
; ++i
)
3613 gdb_printf (stream
, " %02x", data
[i
]);
3618 case DW_OP_regval_type
:
3619 case DW_OP_GNU_regval_type
:
3624 data
= safe_read_uleb128 (data
, end
, ®
);
3625 data
= safe_read_uleb128 (data
, end
, &ul
);
3626 cu_offset type_die
= (cu_offset
) ul
;
3628 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3629 gdb_printf (stream
, "<");
3630 type_print (type
, "", stream
, -1);
3631 gdb_printf (stream
, " [0x%s]> [$%s]",
3632 phex_nz (to_underlying (type_die
), 0),
3633 locexpr_regname (arch
, reg
));
3638 case DW_OP_GNU_convert
:
3639 case DW_OP_reinterpret
:
3640 case DW_OP_GNU_reinterpret
:
3642 data
= safe_read_uleb128 (data
, end
, &ul
);
3643 cu_offset type_die
= (cu_offset
) ul
;
3645 if (to_underlying (type_die
) == 0)
3646 gdb_printf (stream
, "<0>");
3651 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3652 gdb_printf (stream
, "<");
3653 type_print (type
, "", stream
, -1);
3654 gdb_printf (stream
, " [0x%s]>",
3655 phex_nz (to_underlying (type_die
), 0));
3660 case DW_OP_entry_value
:
3661 case DW_OP_GNU_entry_value
:
3662 data
= safe_read_uleb128 (data
, end
, &ul
);
3663 gdb_putc ('\n', stream
);
3664 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3665 start
, data
, data
+ ul
, indent
+ 2,
3666 all
, per_cu
, per_objfile
);
3670 case DW_OP_GNU_parameter_ref
:
3671 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3673 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3677 case DW_OP_GNU_addr_index
:
3678 data
= safe_read_uleb128 (data
, end
, &ul
);
3679 ul
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3680 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3683 case DW_OP_GNU_const_index
:
3684 data
= safe_read_uleb128 (data
, end
, &ul
);
3685 ul
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3686 gdb_printf (stream
, " %s", pulongest (ul
));
3689 case DW_OP_GNU_variable_value
:
3690 ul
= extract_unsigned_integer (data
, offset_size
,
3691 gdbarch_byte_order (arch
));
3692 data
+= offset_size
;
3693 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3697 gdb_printf (stream
, "\n");
3703 static bool dwarf_always_disassemble
;
3706 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3707 struct cmd_list_element
*c
, const char *value
)
3710 _("Whether to always disassemble "
3711 "DWARF expressions is %s.\n"),
3715 /* Describe a single location, which may in turn consist of multiple
3719 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3720 struct ui_file
*stream
,
3721 const gdb_byte
*data
, size_t size
,
3722 unsigned int addr_size
,
3723 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3724 dwarf2_per_objfile
*per_objfile
)
3726 const gdb_byte
*end
= data
+ size
;
3727 int first_piece
= 1, bad
= 0;
3728 objfile
*objfile
= per_objfile
->objfile
;
3732 const gdb_byte
*here
= data
;
3733 int disassemble
= 1;
3738 gdb_printf (stream
, _(", and "));
3740 if (!dwarf_always_disassemble
)
3742 data
= locexpr_describe_location_piece (symbol
, stream
,
3743 addr
, per_cu
, per_objfile
,
3744 data
, end
, addr_size
);
3745 /* If we printed anything, or if we have an empty piece,
3746 then don't disassemble. */
3748 || data
[0] == DW_OP_piece
3749 || data
[0] == DW_OP_bit_piece
)
3754 gdb_printf (stream
, _("a complex DWARF expression:\n"));
3755 data
= disassemble_dwarf_expression (stream
,
3757 addr_size
, offset_size
, data
,
3759 dwarf_always_disassemble
,
3760 per_cu
, per_objfile
);
3765 int empty
= data
== here
;
3768 gdb_printf (stream
, " ");
3769 if (data
[0] == DW_OP_piece
)
3773 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3776 gdb_printf (stream
, _("an empty %s-byte piece"),
3779 gdb_printf (stream
, _(" [%s-byte piece]"),
3782 else if (data
[0] == DW_OP_bit_piece
)
3784 uint64_t bits
, offset
;
3786 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3787 data
= safe_read_uleb128 (data
, end
, &offset
);
3791 _("an empty %s-bit piece"),
3795 _(" [%s-bit piece, offset %s bits]"),
3796 pulongest (bits
), pulongest (offset
));
3806 if (bad
|| data
> end
)
3807 error (_("Corrupted DWARF2 expression for \"%s\"."),
3808 symbol
->print_name ());
3811 /* Print a natural-language description of SYMBOL to STREAM. This
3812 version is for a symbol with a single location. */
3815 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3816 struct ui_file
*stream
)
3818 struct dwarf2_locexpr_baton
*dlbaton
3819 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3820 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3821 int offset_size
= dlbaton
->per_cu
->offset_size ();
3823 locexpr_describe_location_1 (symbol
, addr
, stream
,
3824 dlbaton
->data
, dlbaton
->size
,
3825 addr_size
, offset_size
,
3826 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3829 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3830 any necessary bytecode in AX. */
3833 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3834 struct axs_value
*value
)
3836 struct dwarf2_locexpr_baton
*dlbaton
3837 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3838 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3840 if (dlbaton
->size
== 0)
3841 value
->optimized_out
= 1;
3843 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3844 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3845 dlbaton
->per_objfile
);
3848 /* symbol_computed_ops 'generate_c_location' method. */
3851 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3852 struct gdbarch
*gdbarch
,
3853 std::vector
<bool> ®isters_used
,
3854 CORE_ADDR pc
, const char *result_name
)
3856 struct dwarf2_locexpr_baton
*dlbaton
3857 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3858 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3860 if (dlbaton
->size
== 0)
3861 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3863 compile_dwarf_expr_to_c (stream
, result_name
,
3864 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3865 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3866 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3869 /* The set of location functions used with the DWARF-2 expression
3871 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3872 locexpr_read_variable
,
3873 locexpr_read_variable_at_entry
,
3874 locexpr_get_symbol_read_needs
,
3875 locexpr_describe_location
,
3876 0, /* location_has_loclist */
3877 locexpr_tracepoint_var_ref
,
3878 locexpr_generate_c_location
3882 /* Wrapper functions for location lists. These generally find
3883 the appropriate location expression and call something above. */
3885 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3886 evaluator to calculate the location. */
3887 static struct value
*
3888 loclist_read_variable (struct symbol
*symbol
, frame_info_ptr frame
)
3890 struct dwarf2_loclist_baton
*dlbaton
3891 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3893 const gdb_byte
*data
;
3895 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3897 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3898 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, data
, size
,
3899 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3904 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3905 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3908 Function always returns non-NULL value, it may be marked optimized out if
3909 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3910 if it cannot resolve the parameter for any reason. */
3912 static struct value
*
3913 loclist_read_variable_at_entry (struct symbol
*symbol
, frame_info_ptr frame
)
3915 struct dwarf2_loclist_baton
*dlbaton
3916 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3917 const gdb_byte
*data
;
3921 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3922 return value::allocate_optimized_out (symbol
->type ());
3924 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
, true);
3926 return value::allocate_optimized_out (symbol
->type ());
3928 return value_of_dwarf_block_entry (symbol
->type (), frame
, data
, size
);
3931 /* Implementation of get_symbol_read_needs from
3932 symbol_computed_ops. */
3934 static enum symbol_needs_kind
3935 loclist_symbol_needs (struct symbol
*symbol
)
3937 /* If there's a location list, then assume we need to have a frame
3938 to choose the appropriate location expression. With tracking of
3939 global variables this is not necessarily true, but such tracking
3940 is disabled in GCC at the moment until we figure out how to
3943 return SYMBOL_NEEDS_FRAME
;
3946 /* Print a natural-language description of SYMBOL to STREAM. This
3947 version applies when there is a list of different locations, each
3948 with a specified address range. */
3951 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3952 struct ui_file
*stream
)
3954 struct dwarf2_loclist_baton
*dlbaton
3955 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3956 const gdb_byte
*loc_ptr
, *buf_end
;
3957 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3958 struct objfile
*objfile
= per_objfile
->objfile
;
3959 struct gdbarch
*gdbarch
= objfile
->arch ();
3960 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3961 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3962 int offset_size
= dlbaton
->per_cu
->offset_size ();
3963 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
.get ());
3964 unrelocated_addr base_address
= dlbaton
->base_address
;
3967 loc_ptr
= dlbaton
->data
;
3968 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3970 gdb_printf (stream
, _("multi-location:\n"));
3972 /* Iterate through locations until we run out. */
3975 unrelocated_addr low
= {}, high
= {}; /* init for gcc -Wall */
3977 enum debug_loc_kind kind
;
3978 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3980 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3981 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3983 loc_ptr
, buf_end
, &new_ptr
,
3984 &low
, &high
, byte_order
);
3985 else if (dlbaton
->per_cu
->version () < 5)
3986 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3988 byte_order
, addr_size
,
3991 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3993 loc_ptr
, buf_end
, &new_ptr
,
3994 &low
, &high
, byte_order
,
3995 addr_size
, signed_addr_p
);
3999 case DEBUG_LOC_END_OF_LIST
:
4003 case DEBUG_LOC_BASE_ADDRESS
:
4004 base_address
= high
;
4005 gdb_printf (stream
, _(" Base address %s"),
4006 paddress (gdbarch
, (CORE_ADDR
) base_address
));
4009 case DEBUG_LOC_START_END
:
4010 case DEBUG_LOC_START_LENGTH
:
4011 case DEBUG_LOC_OFFSET_PAIR
:
4014 case DEBUG_LOC_BUFFER_OVERFLOW
:
4015 case DEBUG_LOC_INVALID_ENTRY
:
4016 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4017 symbol
->print_name ());
4020 gdb_assert_not_reached ("bad debug_loc_kind");
4023 /* Otherwise, a location expression entry. */
4024 if (!dlbaton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
4026 low
= (unrelocated_addr
) ((CORE_ADDR
) low
4027 + (CORE_ADDR
) base_address
);
4028 high
= (unrelocated_addr
) ((CORE_ADDR
) high
4029 + (CORE_ADDR
) base_address
);
4032 CORE_ADDR low_reloc
= per_objfile
->relocate (low
);
4033 CORE_ADDR high_reloc
= per_objfile
->relocate (high
);
4035 if (dlbaton
->per_cu
->version () < 5)
4037 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4042 unsigned int bytes_read
;
4043 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4044 loc_ptr
+= bytes_read
;
4047 /* (It would improve readability to print only the minimum
4048 necessary digits of the second number of the range.) */
4049 gdb_printf (stream
, _(" Range %s-%s: "),
4050 paddress (gdbarch
, low_reloc
),
4051 paddress (gdbarch
, high_reloc
));
4053 /* Now describe this particular location. */
4054 locexpr_describe_location_1 (symbol
, low_reloc
, stream
, loc_ptr
, length
,
4055 addr_size
, offset_size
,
4056 dlbaton
->per_cu
, per_objfile
);
4058 gdb_printf (stream
, "\n");
4064 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4065 any necessary bytecode in AX. */
4067 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4068 struct axs_value
*value
)
4070 struct dwarf2_loclist_baton
*dlbaton
4071 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4072 const gdb_byte
*data
;
4074 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4076 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4078 value
->optimized_out
= 1;
4080 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4081 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4084 /* symbol_computed_ops 'generate_c_location' method. */
4087 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4088 struct gdbarch
*gdbarch
,
4089 std::vector
<bool> ®isters_used
,
4090 CORE_ADDR pc
, const char *result_name
)
4092 struct dwarf2_loclist_baton
*dlbaton
4093 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4094 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4095 const gdb_byte
*data
;
4098 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4100 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4102 compile_dwarf_expr_to_c (stream
, result_name
,
4103 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4106 dlbaton
->per_objfile
);
4109 /* The set of location functions used with the DWARF-2 expression
4110 evaluator and location lists. */
4111 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4112 loclist_read_variable
,
4113 loclist_read_variable_at_entry
,
4114 loclist_symbol_needs
,
4115 loclist_describe_location
,
4116 1, /* location_has_loclist */
4117 loclist_tracepoint_var_ref
,
4118 loclist_generate_c_location
4121 void _initialize_dwarf2loc ();
4123 _initialize_dwarf2loc ()
4125 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4126 &entry_values_debug
,
4127 _("Set entry values and tail call frames "
4129 _("Show entry values and tail call frames "
4131 _("When non-zero, the process of determining "
4132 "parameter values from function entry point "
4133 "and tail call frames will be printed."),
4135 show_entry_values_debug
,
4136 &setdebuglist
, &showdebuglist
);
4138 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4139 &dwarf_always_disassemble
, _("\
4140 Set whether `info address' always disassembles DWARF expressions."), _("\
4141 Show whether `info address' always disassembles DWARF expressions."), _("\
4142 When enabled, DWARF expressions are always printed in an assembly-like\n\
4143 syntax. When disabled, expressions will be printed in a more\n\
4144 conversational style, when possible."),
4146 show_dwarf_always_disassemble
,
4148 &show_dwarf_cmdlist
);