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
)
368 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
369 struct objfile
*objfile
= per_objfile
->objfile
;
370 struct gdbarch
*gdbarch
= objfile
->arch ();
371 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
372 unsigned int addr_size
= baton
->per_cu
->addr_size ();
373 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
.get ());
374 /* Adjustment for relocatable objects. */
375 CORE_ADDR text_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
376 unrelocated_addr unrel_pc
= (unrelocated_addr
) (pc
- text_offset
);
377 unrelocated_addr base_address
= baton
->base_address
;
378 const gdb_byte
*loc_ptr
, *buf_end
;
380 loc_ptr
= baton
->data
;
381 buf_end
= baton
->data
+ baton
->size
;
385 unrelocated_addr low
= {}, high
= {}; /* init for gcc -Wall */
387 enum debug_loc_kind kind
;
388 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
390 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
391 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
393 loc_ptr
, buf_end
, &new_ptr
,
394 &low
, &high
, byte_order
);
395 else if (baton
->per_cu
->version () < 5)
396 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
398 byte_order
, addr_size
,
401 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
403 loc_ptr
, buf_end
, &new_ptr
,
404 &low
, &high
, byte_order
,
405 addr_size
, signed_addr_p
);
410 case DEBUG_LOC_END_OF_LIST
:
414 case DEBUG_LOC_BASE_ADDRESS
:
418 case DEBUG_LOC_START_END
:
419 case DEBUG_LOC_START_LENGTH
:
420 case DEBUG_LOC_OFFSET_PAIR
:
423 case DEBUG_LOC_BUFFER_OVERFLOW
:
424 case DEBUG_LOC_INVALID_ENTRY
:
425 error (_("dwarf2_find_location_expression: "
426 "Corrupted DWARF expression."));
429 gdb_assert_not_reached ("bad debug_loc_kind");
432 /* Otherwise, a location expression entry.
433 If the entry is from a DWO, don't add base address: the entry is from
434 .debug_addr which already has the DWARF "base address". We still add
435 text offset in case we're debugging a PIE executable. However, if the
436 entry is DW_LLE_offset_pair from a DWO, add the base address as the
437 operands are offsets relative to the applicable base address.
438 If the entry is DW_LLE_start_end or DW_LLE_start_length, then
439 it already is an address, and we don't need to add the base. */
440 if (!baton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
442 low
= (unrelocated_addr
) ((CORE_ADDR
) low
+ (CORE_ADDR
) base_address
);
443 high
= (unrelocated_addr
) ((CORE_ADDR
) high
+ (CORE_ADDR
) base_address
);
446 if (baton
->per_cu
->version () < 5)
448 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
453 unsigned int bytes_read
;
455 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
456 loc_ptr
+= bytes_read
;
459 if (low
== high
&& unrel_pc
== low
)
461 /* This is entry PC record present only at entry point
462 of a function. Verify it is really the function entry point. */
464 const struct block
*pc_block
= block_for_pc (pc
);
465 struct symbol
*pc_func
= NULL
;
468 pc_func
= pc_block
->linkage_function ();
470 if (pc_func
&& pc
== pc_func
->value_block ()->entry_pc ())
472 *locexpr_length
= length
;
477 if (unrel_pc
>= low
&& unrel_pc
< high
)
479 *locexpr_length
= length
;
487 /* Implement find_frame_base_location method for LOC_BLOCK functions using
488 DWARF expression for its DW_AT_frame_base. */
491 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
492 const gdb_byte
**start
, size_t *length
)
494 struct dwarf2_locexpr_baton
*symbaton
495 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
497 *length
= symbaton
->size
;
498 *start
= symbaton
->data
;
501 /* Implement the struct symbol_block_ops::get_frame_base method for
502 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
505 locexpr_get_frame_base (struct symbol
*framefunc
, frame_info_ptr frame
)
507 struct gdbarch
*gdbarch
;
509 struct dwarf2_locexpr_baton
*dlbaton
;
510 const gdb_byte
*start
;
512 struct value
*result
;
514 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
515 Thus, it's supposed to provide the find_frame_base_location method as
517 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
519 gdbarch
= get_frame_arch (frame
);
520 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
521 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
523 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
524 (framefunc
, get_frame_pc (frame
), &start
, &length
);
525 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
526 dlbaton
->per_cu
, dlbaton
->per_objfile
);
528 /* The DW_AT_frame_base attribute contains a location description which
529 computes the base address itself. However, the call to
530 dwarf2_evaluate_loc_desc returns a value representing a variable at
531 that address. The frame base address is thus this variable's
533 return result
->address ();
536 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
537 function uses DWARF expression for its DW_AT_frame_base. */
539 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
541 locexpr_find_frame_base_location
,
542 locexpr_get_frame_base
545 /* Implement find_frame_base_location method for LOC_BLOCK functions using
546 DWARF location list for its DW_AT_frame_base. */
549 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
550 const gdb_byte
**start
, size_t *length
)
552 struct dwarf2_loclist_baton
*symbaton
553 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
555 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
558 /* Implement the struct symbol_block_ops::get_frame_base method for
559 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
562 loclist_get_frame_base (struct symbol
*framefunc
, frame_info_ptr frame
)
564 struct gdbarch
*gdbarch
;
566 struct dwarf2_loclist_baton
*dlbaton
;
567 const gdb_byte
*start
;
569 struct value
*result
;
571 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
572 Thus, it's supposed to provide the find_frame_base_location method as
574 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
576 gdbarch
= get_frame_arch (frame
);
577 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
578 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
580 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
581 (framefunc
, get_frame_pc (frame
), &start
, &length
);
582 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
583 dlbaton
->per_cu
, dlbaton
->per_objfile
);
585 /* The DW_AT_frame_base attribute contains a location description which
586 computes the base address itself. However, the call to
587 dwarf2_evaluate_loc_desc returns a value representing a variable at
588 that address. The frame base address is thus this variable's
590 return result
->address ();
593 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
594 function uses DWARF location list for its DW_AT_frame_base. */
596 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
598 loclist_find_frame_base_location
,
599 loclist_get_frame_base
602 /* See dwarf2/loc.h. */
605 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
606 const gdb_byte
**start
, size_t *length
)
608 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
610 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
612 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
618 error (_("Could not find the frame base for \"%s\"."),
619 framefunc
->natural_name ());
625 compute_var_value (const char *name
)
627 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
629 if (sym
.symbol
!= nullptr)
630 return value_of_variable (sym
.symbol
, sym
.block
);
634 /* See dwarf2/loc.h. */
636 unsigned int entry_values_debug
= 0;
638 /* Helper to set entry_values_debug. */
641 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
642 struct cmd_list_element
*c
, const char *value
)
645 _("Entry values and tail call frames debugging is %s.\n"),
649 /* See gdbtypes.h. */
652 call_site_target::iterate_over_addresses
653 (struct gdbarch
*call_site_gdbarch
,
654 const struct call_site
*call_site
,
655 frame_info_ptr caller_frame
,
656 iterate_ftype callback
) const
660 case call_site_target::DWARF_BLOCK
:
662 struct dwarf2_locexpr_baton
*dwarf_block
;
664 struct type
*caller_core_addr_type
;
665 struct gdbarch
*caller_arch
;
667 dwarf_block
= m_loc
.dwarf_block
;
668 if (dwarf_block
== NULL
)
670 struct bound_minimal_symbol msym
;
672 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
673 throw_error (NO_ENTRY_VALUE_ERROR
,
674 _("DW_AT_call_target is not specified at %s in %s"),
675 paddress (call_site_gdbarch
, call_site
->pc ()),
676 (msym
.minsym
== NULL
? "???"
677 : msym
.minsym
->print_name ()));
680 if (caller_frame
== NULL
)
682 struct bound_minimal_symbol msym
;
684 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
685 throw_error (NO_ENTRY_VALUE_ERROR
,
686 _("DW_AT_call_target DWARF block resolving "
687 "requires known frame which is currently not "
688 "available at %s in %s"),
689 paddress (call_site_gdbarch
, call_site
->pc ()),
690 (msym
.minsym
== NULL
? "???"
691 : msym
.minsym
->print_name ()));
694 caller_arch
= get_frame_arch (caller_frame
);
695 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
696 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
697 dwarf_block
->data
, dwarf_block
->size
,
699 dwarf_block
->per_objfile
);
700 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
701 if (val
->lval () == lval_memory
)
702 callback (val
->address ());
704 callback (value_as_address (val
));
708 case call_site_target::PHYSNAME
:
710 const char *physname
;
711 struct bound_minimal_symbol msym
;
713 physname
= m_loc
.physname
;
715 /* Handle both the mangled and demangled PHYSNAME. */
716 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
717 if (msym
.minsym
== NULL
)
719 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
720 throw_error (NO_ENTRY_VALUE_ERROR
,
721 _("Cannot find function \"%s\" for a call site target "
723 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
724 (msym
.minsym
== NULL
? "???"
725 : msym
.minsym
->print_name ()));
729 CORE_ADDR addr
= (gdbarch_convert_from_func_ptr_addr
730 (call_site_gdbarch
, msym
.value_address (),
731 current_inferior ()->top_target ()));
736 case call_site_target::PHYSADDR
:
738 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
740 callback (per_objfile
->relocate (m_loc
.physaddr
));
744 case call_site_target::ADDRESSES
:
746 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
748 for (unsigned i
= 0; i
< m_loc
.addresses
.length
; ++i
)
749 callback (per_objfile
->relocate (m_loc
.addresses
.values
[i
]));
754 internal_error (_("invalid call site target kind"));
758 /* Convert function entry point exact address ADDR to the function which is
759 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
760 NO_ENTRY_VALUE_ERROR otherwise. */
762 static struct symbol
*
763 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
765 struct symbol
*sym
= find_pc_function (addr
);
768 if (sym
== NULL
|| sym
->value_block ()->entry_pc () != addr
)
769 throw_error (NO_ENTRY_VALUE_ERROR
,
770 _("DW_TAG_call_site resolving failed to find function "
771 "name for address %s"),
772 paddress (gdbarch
, addr
));
775 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
776 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
781 /* Verify function with entry point exact address ADDR can never call itself
782 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
783 can call itself via tail calls.
785 If a funtion can tail call itself its entry value based parameters are
786 unreliable. There is no verification whether the value of some/all
787 parameters is unchanged through the self tail call, we expect if there is
788 a self tail call all the parameters can be modified. */
791 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
795 /* The verification is completely unordered. Track here function addresses
796 which still need to be iterated. */
797 std::vector
<CORE_ADDR
> todo
;
799 /* Track here CORE_ADDRs which were already visited. */
800 std::unordered_set
<CORE_ADDR
> addr_hash
;
802 todo
.push_back (verify_addr
);
803 while (!todo
.empty ())
805 struct symbol
*func_sym
;
806 struct call_site
*call_site
;
811 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
813 for (call_site
= TYPE_TAIL_CALL_LIST (func_sym
->type ());
814 call_site
; call_site
= call_site
->tail_call_next
)
816 /* CALLER_FRAME with registers is not available for tail-call jumped
818 call_site
->iterate_over_addresses (gdbarch
, nullptr,
819 [&] (CORE_ADDR target_addr
)
821 if (target_addr
== verify_addr
)
823 struct bound_minimal_symbol msym
;
825 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
826 throw_error (NO_ENTRY_VALUE_ERROR
,
827 _("DW_OP_entry_value resolving has found "
828 "function \"%s\" at %s can call itself via tail "
830 (msym
.minsym
== NULL
? "???"
831 : msym
.minsym
->print_name ()),
832 paddress (gdbarch
, verify_addr
));
835 if (addr_hash
.insert (target_addr
).second
)
836 todo
.push_back (target_addr
);
842 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
843 ENTRY_VALUES_DEBUG. */
846 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
848 CORE_ADDR addr
= call_site
->pc ();
849 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
851 gdb_printf (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
852 (msym
.minsym
== NULL
? "???"
853 : msym
.minsym
->print_name ()));
857 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
858 only top callers and bottom callees which are present in both. GDBARCH is
859 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
860 no remaining possibilities to provide unambiguous non-trivial result.
861 RESULTP should point to NULL on the first (initialization) call. Caller is
862 responsible for xfree of any RESULTP data. */
865 chain_candidate (struct gdbarch
*gdbarch
,
866 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
867 const std::vector
<struct call_site
*> &chain
)
869 long length
= chain
.size ();
870 int callers
, callees
, idx
;
872 if (*resultp
== NULL
)
874 /* Create the initial chain containing all the passed PCs. */
876 struct call_site_chain
*result
877 = ((struct call_site_chain
*)
878 xmalloc (sizeof (*result
)
879 + sizeof (*result
->call_site
) * (length
- 1)));
880 result
->length
= length
;
881 result
->callers
= result
->callees
= length
;
883 memcpy (result
->call_site
, chain
.data (),
884 sizeof (*result
->call_site
) * length
);
885 resultp
->reset (result
);
887 if (entry_values_debug
)
889 gdb_printf (gdb_stdlog
, "tailcall: initial:");
890 for (idx
= 0; idx
< length
; idx
++)
891 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
892 gdb_putc ('\n', gdb_stdlog
);
898 if (entry_values_debug
)
900 gdb_printf (gdb_stdlog
, "tailcall: compare:");
901 for (idx
= 0; idx
< length
; idx
++)
902 tailcall_dump (gdbarch
, chain
[idx
]);
903 gdb_putc ('\n', gdb_stdlog
);
906 /* Intersect callers. */
908 callers
= std::min ((long) (*resultp
)->callers
, length
);
909 for (idx
= 0; idx
< callers
; idx
++)
910 if ((*resultp
)->call_site
[idx
] != chain
[idx
])
912 (*resultp
)->callers
= idx
;
916 /* Intersect callees. */
918 callees
= std::min ((long) (*resultp
)->callees
, length
);
919 for (idx
= 0; idx
< callees
; idx
++)
920 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
921 != chain
[length
- 1 - idx
])
923 (*resultp
)->callees
= idx
;
927 if (entry_values_debug
)
929 gdb_printf (gdb_stdlog
, "tailcall: reduced:");
930 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
931 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
932 gdb_puts (" |", gdb_stdlog
);
933 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
934 tailcall_dump (gdbarch
,
935 (*resultp
)->call_site
[(*resultp
)->length
936 - (*resultp
)->callees
+ idx
]);
937 gdb_putc ('\n', gdb_stdlog
);
940 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
942 /* There are no common callers or callees. It could be also a direct
943 call (which has length 0) with ambiguous possibility of an indirect
944 call - CALLERS == CALLEES == 0 is valid during the first allocation
945 but any subsequence processing of such entry means ambiguity. */
946 resultp
->reset (NULL
);
950 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
951 PC again. In such case there must be two different code paths to reach
952 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
953 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
956 /* Recursively try to construct the call chain. GDBARCH, RESULTP, and
957 CHAIN are passed to chain_candidate. ADDR_HASH tracks which
958 addresses have already been seen along the current chain.
959 CALL_SITE is the call site to visit, and CALLEE_PC is the PC we're
960 trying to "reach". Returns false if an error has already been
961 detected and so an early return can be done. If it makes sense to
962 keep trying (even if no answer has yet been found), returns
966 call_site_find_chain_2
967 (struct gdbarch
*gdbarch
,
968 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
969 std::vector
<struct call_site
*> &chain
,
970 std::unordered_set
<CORE_ADDR
> &addr_hash
,
971 struct call_site
*call_site
,
974 std::vector
<CORE_ADDR
> addresses
;
975 bool found_exact
= false;
976 call_site
->iterate_over_addresses (gdbarch
, nullptr,
979 if (addr
== callee_pc
)
982 addresses
.push_back (addr
);
987 chain_candidate (gdbarch
, resultp
, chain
);
988 /* If RESULTP was reset, then chain_candidate failed, and so we
989 can tell our callers to early-return. */
990 return *resultp
!= nullptr;
993 for (CORE_ADDR target_func_addr
: addresses
)
995 struct symbol
*target_func
996 = func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
997 for (struct call_site
*target_call_site
998 = TYPE_TAIL_CALL_LIST (target_func
->type ());
999 target_call_site
!= nullptr;
1000 target_call_site
= target_call_site
->tail_call_next
)
1002 if (addr_hash
.insert (target_call_site
->pc ()).second
)
1004 /* Successfully entered TARGET_CALL_SITE. */
1005 chain
.push_back (target_call_site
);
1007 if (!call_site_find_chain_2 (gdbarch
, resultp
, chain
,
1008 addr_hash
, target_call_site
,
1012 size_t removed
= addr_hash
.erase (target_call_site
->pc ());
1013 gdb_assert (removed
== 1);
1022 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All
1023 the assumed frames between them use GDBARCH. Any unreliability
1024 results in thrown NO_ENTRY_VALUE_ERROR. */
1026 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1027 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1028 CORE_ADDR callee_pc
)
1030 CORE_ADDR save_callee_pc
= callee_pc
;
1031 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1032 struct call_site
*call_site
;
1034 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1035 call_site nor any possible call_site at CALLEE_PC's function is there.
1036 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1037 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1038 std::vector
<struct call_site
*> chain
;
1040 /* A given call site may have multiple associated addresses. This
1041 can happen if, e.g., the caller is split by hot/cold
1042 partitioning. This vector tracks the ones we haven't visited
1044 std::vector
<std::vector
<CORE_ADDR
>> unvisited_addresses
;
1046 /* We are not interested in the specific PC inside the callee function. */
1047 callee_pc
= get_pc_function_start (callee_pc
);
1049 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1050 paddress (gdbarch
, save_callee_pc
));
1052 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1053 std::unordered_set
<CORE_ADDR
> addr_hash
;
1055 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1056 at the target's function. All the possible tail call sites in the
1057 target's function will get iterated as already pushed into CHAIN via their
1059 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1060 /* No need to check the return value here, because we no longer care
1061 about possible early returns. */
1062 call_site_find_chain_2 (gdbarch
, &retval
, chain
, addr_hash
, call_site
,
1067 struct bound_minimal_symbol msym_caller
, msym_callee
;
1069 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1070 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1071 throw_error (NO_ENTRY_VALUE_ERROR
,
1072 _("There are no unambiguously determinable intermediate "
1073 "callers or callees between caller function \"%s\" at %s "
1074 "and callee function \"%s\" at %s"),
1075 (msym_caller
.minsym
== NULL
1076 ? "???" : msym_caller
.minsym
->print_name ()),
1077 paddress (gdbarch
, caller_pc
),
1078 (msym_callee
.minsym
== NULL
1079 ? "???" : msym_callee
.minsym
->print_name ()),
1080 paddress (gdbarch
, callee_pc
));
1086 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1087 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1088 constructed return NULL. */
1090 gdb::unique_xmalloc_ptr
<call_site_chain
>
1091 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1092 CORE_ADDR callee_pc
)
1094 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1098 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1100 catch (const gdb_exception_error
&e
)
1102 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1104 if (entry_values_debug
)
1105 exception_print (gdb_stdout
, e
);
1116 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1119 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1120 enum call_site_parameter_kind kind
,
1121 union call_site_parameter_u kind_u
)
1123 if (kind
== parameter
->kind
)
1126 case CALL_SITE_PARAMETER_DWARF_REG
:
1127 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1129 case CALL_SITE_PARAMETER_FB_OFFSET
:
1130 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1132 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1133 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1140 struct call_site_parameter
*
1141 dwarf_expr_reg_to_entry_parameter (frame_info_ptr frame
,
1142 enum call_site_parameter_kind kind
,
1143 union call_site_parameter_u kind_u
,
1144 dwarf2_per_cu_data
**per_cu_return
,
1145 dwarf2_per_objfile
**per_objfile_return
)
1147 CORE_ADDR func_addr
, caller_pc
;
1148 struct gdbarch
*gdbarch
;
1149 frame_info_ptr caller_frame
;
1150 struct call_site
*call_site
;
1152 /* Initialize it just to avoid a GCC false warning. */
1153 struct call_site_parameter
*parameter
= NULL
;
1154 CORE_ADDR target_addr
;
1156 while (get_frame_type (frame
) == INLINE_FRAME
)
1158 frame
= get_prev_frame (frame
);
1159 gdb_assert (frame
!= NULL
);
1162 func_addr
= get_frame_func (frame
);
1163 gdbarch
= get_frame_arch (frame
);
1164 caller_frame
= get_prev_frame (frame
);
1165 if (gdbarch
!= frame_unwind_arch (frame
))
1167 struct bound_minimal_symbol msym
1168 = lookup_minimal_symbol_by_pc (func_addr
);
1169 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1171 throw_error (NO_ENTRY_VALUE_ERROR
,
1172 _("DW_OP_entry_value resolving callee gdbarch %s "
1173 "(of %s (%s)) does not match caller gdbarch %s"),
1174 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1175 paddress (gdbarch
, func_addr
),
1176 (msym
.minsym
== NULL
? "???"
1177 : msym
.minsym
->print_name ()),
1178 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1181 if (caller_frame
== NULL
)
1183 struct bound_minimal_symbol msym
1184 = lookup_minimal_symbol_by_pc (func_addr
);
1186 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1187 "requires caller of %s (%s)"),
1188 paddress (gdbarch
, func_addr
),
1189 (msym
.minsym
== NULL
? "???"
1190 : msym
.minsym
->print_name ()));
1192 caller_pc
= get_frame_pc (caller_frame
);
1193 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1197 call_site
->iterate_over_addresses (gdbarch
, caller_frame
,
1198 [&] (CORE_ADDR addr
)
1200 /* Preserve any address. */
1203 if (addr
== func_addr
)
1208 struct minimal_symbol
*target_msym
, *func_msym
;
1210 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1211 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1212 throw_error (NO_ENTRY_VALUE_ERROR
,
1213 _("DW_OP_entry_value resolving expects callee %s at %s %s"
1214 "but the called frame is for %s at %s"),
1215 (target_msym
== NULL
? "???"
1216 : target_msym
->print_name ()),
1217 paddress (gdbarch
, target_addr
),
1219 ? _("(but note there are multiple addresses not listed)")
1221 func_msym
== NULL
? "???" : func_msym
->print_name (),
1222 paddress (gdbarch
, func_addr
));
1225 /* No entry value based parameters would be reliable if this function can
1226 call itself via tail calls. */
1227 func_verify_no_selftailcall (gdbarch
, func_addr
);
1229 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1231 parameter
= &call_site
->parameter
[iparams
];
1232 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1235 if (iparams
== call_site
->parameter_count
)
1237 struct minimal_symbol
*msym
1238 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1240 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1241 determine its value. */
1242 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1243 "at DW_TAG_call_site %s at %s"),
1244 paddress (gdbarch
, caller_pc
),
1245 msym
== NULL
? "???" : msym
->print_name ());
1248 *per_cu_return
= call_site
->per_cu
;
1249 *per_objfile_return
= call_site
->per_objfile
;
1253 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1254 the normal DW_AT_call_value block. Otherwise return the
1255 DW_AT_call_data_value (dereferenced) block.
1257 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1260 Function always returns non-NULL, non-optimized out value. It throws
1261 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1263 static struct value
*
1264 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1265 CORE_ADDR deref_size
, struct type
*type
,
1266 frame_info_ptr caller_frame
,
1267 dwarf2_per_cu_data
*per_cu
,
1268 dwarf2_per_objfile
*per_objfile
)
1270 const gdb_byte
*data_src
;
1273 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1274 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1276 /* DEREF_SIZE size is not verified here. */
1277 if (data_src
== NULL
)
1278 throw_error (NO_ENTRY_VALUE_ERROR
,
1279 _("Cannot resolve DW_AT_call_data_value"));
1281 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1282 per_objfile
, false);
1285 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1286 the indirect method on it, that is use its stored target value, the sole
1287 purpose of entry_data_value_funcs.. */
1289 static struct value
*
1290 entry_data_value_coerce_ref (const struct value
*value
)
1292 struct type
*checked_type
= check_typedef (value
->type ());
1293 struct value
*target_val
;
1295 if (!TYPE_IS_REFERENCE (checked_type
))
1298 target_val
= (struct value
*) value
->computed_closure ();
1299 target_val
->incref ();
1303 /* Implement copy_closure. */
1306 entry_data_value_copy_closure (const struct value
*v
)
1308 struct value
*target_val
= (struct value
*) v
->computed_closure ();
1310 target_val
->incref ();
1314 /* Implement free_closure. */
1317 entry_data_value_free_closure (struct value
*v
)
1319 struct value
*target_val
= (struct value
*) v
->computed_closure ();
1321 target_val
->decref ();
1324 /* Vector for methods for an entry value reference where the referenced value
1325 is stored in the caller. On the first dereference use
1326 DW_AT_call_data_value in the caller. */
1328 static const struct lval_funcs entry_data_value_funcs
=
1333 NULL
, /* indirect */
1334 entry_data_value_coerce_ref
,
1335 NULL
, /* check_synthetic_pointer */
1336 entry_data_value_copy_closure
,
1337 entry_data_value_free_closure
1340 /* See dwarf2/loc.h. */
1342 value_of_dwarf_reg_entry (struct type
*type
, frame_info_ptr frame
,
1343 enum call_site_parameter_kind kind
,
1344 union call_site_parameter_u kind_u
)
1346 struct type
*checked_type
= check_typedef (type
);
1347 struct type
*target_type
= checked_type
->target_type ();
1348 frame_info_ptr caller_frame
= get_prev_frame (frame
);
1349 struct value
*outer_val
, *target_val
, *val
;
1350 struct call_site_parameter
*parameter
;
1351 dwarf2_per_cu_data
*caller_per_cu
;
1352 dwarf2_per_objfile
*caller_per_objfile
;
1354 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1356 &caller_per_objfile
);
1358 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1361 caller_per_objfile
);
1363 /* Check if DW_AT_call_data_value cannot be used. If it should be
1364 used and it is not available do not fall back to OUTER_VAL - dereferencing
1365 TYPE_CODE_REF with non-entry data value would give current value - not the
1368 if (!TYPE_IS_REFERENCE (checked_type
)
1369 || checked_type
->target_type () == NULL
)
1372 target_val
= dwarf_entry_parameter_to_value (parameter
,
1373 target_type
->length (),
1374 target_type
, caller_frame
,
1376 caller_per_objfile
);
1378 val
= value::allocate_computed (type
, &entry_data_value_funcs
,
1379 release_value (target_val
).release ());
1381 /* Copy the referencing pointer to the new computed value. */
1382 memcpy (val
->contents_raw ().data (),
1383 outer_val
->contents_raw ().data (),
1384 checked_type
->length ());
1385 val
->set_lazy (false);
1390 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1391 SIZE are DWARF block used to match DW_AT_location at the caller's
1392 DW_TAG_call_site_parameter.
1394 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1395 cannot resolve the parameter for any reason. */
1397 static struct value
*
1398 value_of_dwarf_block_entry (struct type
*type
, frame_info_ptr frame
,
1399 const gdb_byte
*block
, size_t block_len
)
1401 union call_site_parameter_u kind_u
;
1403 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1404 if (kind_u
.dwarf_reg
!= -1)
1405 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1408 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1409 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1412 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1413 suppressed during normal operation. The expression can be arbitrary if
1414 there is no caller-callee entry value binding expected. */
1415 throw_error (NO_ENTRY_VALUE_ERROR
,
1416 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1417 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1420 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1422 static struct value
*
1423 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1424 dwarf2_per_cu_data
*per_cu
,
1425 dwarf2_per_objfile
*per_objfile
,
1428 struct value
*result
= NULL
;
1429 const gdb_byte
*bytes
;
1432 auto_obstack temp_obstack
;
1433 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1434 &temp_obstack
, &len
);
1438 if (byte_offset
>= 0
1439 && byte_offset
+ type
->target_type ()->length () <= len
)
1441 bytes
+= byte_offset
;
1442 result
= value_from_contents (type
->target_type (), bytes
);
1445 invalid_synthetic_pointer ();
1448 result
= value::allocate_optimized_out (type
->target_type ());
1456 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1457 dwarf2_per_cu_data
*per_cu
,
1458 dwarf2_per_objfile
*per_objfile
,
1459 frame_info_ptr frame
, struct type
*type
,
1460 bool resolve_abstract_p
)
1462 /* Fetch the location expression of the DIE we're pointing to. */
1463 auto get_frame_address_in_block_wrapper
= [frame
] ()
1465 return get_frame_address_in_block (frame
);
1467 struct dwarf2_locexpr_baton baton
1468 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1469 get_frame_address_in_block_wrapper
,
1470 resolve_abstract_p
);
1472 /* Get type of pointed-to DIE. */
1473 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1475 if (orig_type
== NULL
)
1476 invalid_synthetic_pointer ();
1478 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1479 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1480 or it may've been optimized out. */
1481 if (baton
.data
!= NULL
)
1482 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1483 baton
.size
, baton
.per_cu
,
1485 type
->target_type (),
1488 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1492 /* Evaluate a location description, starting at DATA and with length
1493 SIZE, to find the current location of variable of TYPE in the
1494 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1495 location of the subobject of type SUBOBJ_TYPE at byte offset
1496 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1498 static struct value
*
1499 dwarf2_evaluate_loc_desc_full (struct type
*type
, frame_info_ptr frame
,
1500 const gdb_byte
*data
, size_t size
,
1501 dwarf2_per_cu_data
*per_cu
,
1502 dwarf2_per_objfile
*per_objfile
,
1503 struct type
*subobj_type
,
1504 LONGEST subobj_byte_offset
,
1507 if (subobj_type
== NULL
)
1510 subobj_byte_offset
= 0;
1512 else if (subobj_byte_offset
< 0)
1513 invalid_synthetic_pointer ();
1516 return value::allocate_optimized_out (subobj_type
);
1518 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1521 scoped_value_mark free_values
;
1525 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1526 type
, subobj_type
, subobj_byte_offset
);
1528 catch (const gdb_exception_error
&ex
)
1530 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1532 free_values
.free_to_mark ();
1533 retval
= value::allocate (subobj_type
);
1534 retval
->mark_bytes_unavailable (0,
1535 subobj_type
->length ());
1538 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1540 if (entry_values_debug
)
1541 exception_print (gdb_stdout
, ex
);
1542 free_values
.free_to_mark ();
1543 return value::allocate_optimized_out (subobj_type
);
1549 /* We need to clean up all the values that are not needed any more.
1550 The problem with a value_ref_ptr class is that it disconnects the
1551 RETVAL from the value garbage collection, so we need to make
1552 a copy of that value on the stack to keep everything consistent.
1553 The value_ref_ptr will clean up after itself at the end of this block. */
1554 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1555 free_values
.free_to_mark ();
1557 return retval
->copy ();
1560 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1561 passes 0 as the byte_offset. */
1564 dwarf2_evaluate_loc_desc (struct type
*type
, frame_info_ptr frame
,
1565 const gdb_byte
*data
, size_t size
,
1566 dwarf2_per_cu_data
*per_cu
,
1567 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1569 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1570 per_objfile
, NULL
, 0, as_lval
);
1573 /* Evaluates a dwarf expression and stores the result in VAL,
1574 expecting that the dwarf expression only produces a single
1575 CORE_ADDR. FRAME is the frame in which the expression is
1576 evaluated. ADDR_STACK is a context (location of a variable) and
1577 might be needed to evaluate the location expression.
1579 PUSH_VALUES is an array of values to be pushed to the expression stack
1580 before evaluation starts. PUSH_VALUES[0] is pushed first, then
1581 PUSH_VALUES[1], and so on.
1583 Returns 1 on success, 0 otherwise. */
1586 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1587 frame_info_ptr frame
,
1588 const struct property_addr_info
*addr_stack
,
1590 gdb::array_view
<CORE_ADDR
> push_values
,
1593 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1596 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1597 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1598 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1601 scoped_value_mark free_values
;
1603 /* Place any initial values onto the expression stack. */
1604 for (const auto &val
: push_values
)
1605 ctx
.push_address (val
, false);
1609 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1610 true, per_cu
, frame
, addr_stack
);
1612 catch (const gdb_exception_error
&ex
)
1614 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1618 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1620 if (entry_values_debug
)
1621 exception_print (gdb_stdout
, ex
);
1628 if (result
->optimized_out ())
1631 if (result
->lval () == lval_memory
)
1632 *valp
= result
->address ();
1635 if (result
->lval () == not_lval
)
1636 *is_reference
= false;
1638 *valp
= value_as_address (result
);
1644 /* See dwarf2/loc.h. */
1647 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1648 frame_info_ptr frame
,
1649 const struct property_addr_info
*addr_stack
,
1651 gdb::array_view
<CORE_ADDR
> push_values
)
1656 /* Evaluating a property should not change the current language.
1657 Without this here this could happen if the code below selects a
1659 scoped_restore_current_language save_language
;
1661 if (frame
== NULL
&& has_stack_frames ())
1662 frame
= get_selected_frame (NULL
);
1664 switch (prop
->kind ())
1668 const struct dwarf2_property_baton
*baton
= prop
->baton ();
1669 gdb_assert (baton
->property_type
!= NULL
);
1671 bool is_reference
= baton
->locexpr
.is_reference
;
1672 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1673 value
, push_values
, &is_reference
))
1677 struct value
*val
= value_at (baton
->property_type
, *value
);
1678 *value
= value_as_address (val
);
1682 gdb_assert (baton
->property_type
!= NULL
);
1684 struct type
*type
= check_typedef (baton
->property_type
);
1685 if (type
->length () < sizeof (CORE_ADDR
)
1686 && !type
->is_unsigned ())
1688 /* If we have a valid return candidate and it's value
1689 is signed, we have to sign-extend the value because
1690 CORE_ADDR on 64bit machine has 8 bytes but address
1691 size of an 32bit application is bytes. */
1693 = (baton
->locexpr
.per_cu
->addr_size ()
1695 const CORE_ADDR neg_mask
1696 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1698 /* Check if signed bit is set and sign-extend values. */
1699 if (*value
& neg_mask
)
1710 const dwarf2_property_baton
*baton
= prop
->baton ();
1712 const gdb_byte
*data
;
1717 || !get_frame_address_in_block_if_available (frame
, &pc
))
1720 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1723 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1724 size
, baton
->loclist
.per_cu
,
1725 baton
->loclist
.per_objfile
);
1726 if (!val
->optimized_out ())
1728 *value
= value_as_address (val
);
1736 *value
= prop
->const_val ();
1739 case PROP_ADDR_OFFSET
:
1741 const dwarf2_property_baton
*baton
= prop
->baton ();
1742 const struct property_addr_info
*pinfo
;
1745 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1747 /* This approach lets us avoid checking the qualifiers. */
1748 if (TYPE_MAIN_TYPE (pinfo
->type
)
1749 == TYPE_MAIN_TYPE (baton
->property_type
))
1753 error (_("cannot find reference address for offset property"));
1754 if (pinfo
->valaddr
.data () != NULL
)
1755 val
= value_from_contents
1756 (baton
->offset_info
.type
,
1757 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1759 val
= value_at (baton
->offset_info
.type
,
1760 pinfo
->addr
+ baton
->offset_info
.offset
);
1761 *value
= value_as_address (val
);
1765 case PROP_VARIABLE_NAME
:
1767 struct value
*val
= compute_var_value (prop
->variable_name ());
1770 *value
= value_as_long (val
);
1780 /* See dwarf2/loc.h. */
1783 dwarf2_compile_property_to_c (string_file
*stream
,
1784 const char *result_name
,
1785 struct gdbarch
*gdbarch
,
1786 std::vector
<bool> ®isters_used
,
1787 const struct dynamic_prop
*prop
,
1791 const dwarf2_property_baton
*baton
= prop
->baton ();
1792 const gdb_byte
*data
;
1794 dwarf2_per_cu_data
*per_cu
;
1795 dwarf2_per_objfile
*per_objfile
;
1797 if (prop
->kind () == PROP_LOCEXPR
)
1799 data
= baton
->locexpr
.data
;
1800 size
= baton
->locexpr
.size
;
1801 per_cu
= baton
->locexpr
.per_cu
;
1802 per_objfile
= baton
->locexpr
.per_objfile
;
1806 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1808 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1809 per_cu
= baton
->loclist
.per_cu
;
1810 per_objfile
= baton
->loclist
.per_objfile
;
1813 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1814 gdbarch
, registers_used
,
1815 per_cu
->addr_size (),
1816 data
, data
+ size
, per_cu
, per_objfile
);
1819 /* Compute the correct symbol_needs_kind value for the location
1822 Implemented by traversing the logical control flow graph of the
1825 static enum symbol_needs_kind
1826 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1827 dwarf2_per_cu_data
*per_cu
,
1828 dwarf2_per_objfile
*per_objfile
,
1829 bfd_endian byte_order
,
1834 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1836 /* If the expression is empty, we have nothing to do. */
1838 return symbol_needs
;
1840 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1842 /* List of operations to visit. Operations in this list are not visited yet,
1843 so are not in VISITED_OPS (and vice-versa). */
1844 std::vector
<const gdb_byte
*> ops_to_visit
;
1846 /* Operations already visited. */
1847 std::unordered_set
<const gdb_byte
*> visited_ops
;
1849 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1850 hasn't been visited yet. */
1851 auto insert_in_ops_to_visit
1852 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1854 if (op_ptr
>= expr_end
)
1857 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1860 ops_to_visit
.push_back (op_ptr
);
1863 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1865 const int max_depth
= 256;
1867 if (depth
> max_depth
)
1868 error (_("DWARF-2 expression error: Loop detected."));
1872 /* Initialize the to-visit list with the first operation. */
1873 insert_in_ops_to_visit (&expr
[0]);
1875 while (!ops_to_visit
.empty ())
1877 /* Pop one op to visit, mark it as visited. */
1878 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1879 ops_to_visit
.pop_back ();
1880 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1881 visited_ops
.insert (op_ptr
);
1883 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1885 /* Most operations have a single possible following operation
1886 (they are not conditional branches). The code below updates
1887 OP_PTR to point to that following operation, which is pushed
1888 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1889 OP_PTR pointing just after the operand. */
1892 /* The DWARF expression might have a bug causing an infinite
1893 loop. In that case, quitting is the only way out. */
1930 case DW_OP_stack_value
:
1957 case DW_OP_GNU_push_tls_address
:
1959 case DW_OP_GNU_uninit
:
1960 case DW_OP_push_object_address
:
1963 case DW_OP_form_tls_address
:
1964 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1965 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1969 case DW_OP_GNU_convert
:
1970 case DW_OP_reinterpret
:
1971 case DW_OP_GNU_reinterpret
:
1973 case DW_OP_GNU_addr_index
:
1974 case DW_OP_GNU_const_index
:
1976 case DW_OP_plus_uconst
:
1978 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1982 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1985 case DW_OP_bit_piece
:
1986 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1987 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1990 case DW_OP_deref_type
:
1991 case DW_OP_GNU_deref_type
:
1993 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1997 op_ptr
+= addr_size
;
2087 case DW_OP_call_frame_cfa
:
2088 case DW_OP_entry_value
:
2089 case DW_OP_GNU_entry_value
:
2090 case DW_OP_GNU_parameter_ref
:
2091 case DW_OP_regval_type
:
2092 case DW_OP_GNU_regval_type
:
2093 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2096 case DW_OP_implicit_value
:
2099 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2104 case DW_OP_implicit_pointer
:
2105 case DW_OP_GNU_implicit_pointer
:
2106 op_ptr
+= ref_addr_size
;
2107 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2110 case DW_OP_deref_size
:
2117 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2125 /* This is the only operation that pushes two operations in
2126 the to-visit list, so handle it all here. */
2127 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2130 insert_in_ops_to_visit (op_ptr
+ offset
);
2131 insert_in_ops_to_visit (op_ptr
);
2138 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2140 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2143 auto get_frame_pc
= [&symbol_needs
] ()
2145 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2149 struct dwarf2_locexpr_baton baton
2150 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2154 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2155 we dont have to check the baton content. */
2156 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2158 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2159 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2162 = dwarf2_get_symbol_read_needs (sub_expr
,
2165 gdbarch_byte_order (arch
),
2166 baton
.per_cu
->addr_size (),
2167 baton
.per_cu
->ref_addr_size (),
2173 case DW_OP_GNU_variable_value
:
2175 sect_offset sect_off
2176 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2179 op_ptr
+= ref_addr_size
;
2181 struct type
*die_type
2182 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2185 if (die_type
== NULL
)
2186 error (_("Bad DW_OP_GNU_variable_value DIE."));
2188 /* Note: Things still work when the following test is
2189 removed. This test and error is here to conform to the
2190 proposed specification. */
2191 if (die_type
->code () != TYPE_CODE_INT
2192 && die_type
->code () != TYPE_CODE_PTR
)
2193 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2194 "an integer or pointer."));
2196 auto get_frame_pc
= [&symbol_needs
] ()
2198 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2202 struct dwarf2_locexpr_baton baton
2203 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2205 get_frame_pc
, true);
2207 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2208 we dont have to check the baton content. */
2209 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2211 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2212 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2215 = dwarf2_get_symbol_read_needs (sub_expr
,
2218 gdbarch_byte_order (arch
),
2219 baton
.per_cu
->addr_size (),
2220 baton
.per_cu
->ref_addr_size (),
2226 case DW_OP_const_type
:
2227 case DW_OP_GNU_const_type
:
2230 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2231 gdb_byte offset
= *op_ptr
++;
2237 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2240 /* If it is known that a frame information is
2241 needed we can stop parsing the expression. */
2242 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2245 insert_in_ops_to_visit (op_ptr
);
2248 return symbol_needs
;
2251 /* A helper function that throws an unimplemented error mentioning a
2252 given DWARF operator. */
2254 static void ATTRIBUTE_NORETURN
2255 unimplemented (unsigned int op
)
2257 const char *name
= get_DW_OP_name (op
);
2260 error (_("DWARF operator %s cannot be translated to an agent expression"),
2263 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2264 "to an agent expression"),
2268 /* See dwarf2/loc.h.
2270 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2271 can issue a complaint, which is better than having every target's
2272 implementation of dwarf2_reg_to_regnum do it. */
2275 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2277 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2281 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2286 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2287 Throw an error because DWARF_REG is bad. */
2290 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2292 /* Still want to print -1 as "-1".
2293 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2294 but that's overkill for now. */
2295 if ((int) dwarf_reg
== dwarf_reg
)
2296 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2297 error (_("Unable to access DWARF register number %s"),
2298 pulongest (dwarf_reg
));
2301 /* See dwarf2/loc.h. */
2304 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2308 if (dwarf_reg
> INT_MAX
)
2309 throw_bad_regnum_error (dwarf_reg
);
2310 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2311 bad, but that's ok. */
2312 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2314 throw_bad_regnum_error (dwarf_reg
);
2318 /* A helper function that emits an access to memory. ARCH is the
2319 target architecture. EXPR is the expression which we are building.
2320 NBITS is the number of bits we want to read. This emits the
2321 opcodes needed to read the memory and then extract the desired
2325 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2327 ULONGEST nbytes
= (nbits
+ 7) / 8;
2329 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2332 ax_trace_quick (expr
, nbytes
);
2335 ax_simple (expr
, aop_ref8
);
2336 else if (nbits
<= 16)
2337 ax_simple (expr
, aop_ref16
);
2338 else if (nbits
<= 32)
2339 ax_simple (expr
, aop_ref32
);
2341 ax_simple (expr
, aop_ref64
);
2343 /* If we read exactly the number of bytes we wanted, we're done. */
2344 if (8 * nbytes
== nbits
)
2347 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2349 /* On a bits-big-endian machine, we want the high-order
2351 ax_const_l (expr
, 8 * nbytes
- nbits
);
2352 ax_simple (expr
, aop_rsh_unsigned
);
2356 /* On a bits-little-endian box, we want the low-order NBITS. */
2357 ax_zero_ext (expr
, nbits
);
2361 /* Compile a DWARF location expression to an agent expression.
2363 EXPR is the agent expression we are building.
2364 LOC is the agent value we modify.
2365 ARCH is the architecture.
2366 ADDR_SIZE is the size of addresses, in bytes.
2367 OP_PTR is the start of the location expression.
2368 OP_END is one past the last byte of the location expression.
2370 This will throw an exception for various kinds of errors -- for
2371 example, if the expression cannot be compiled, or if the expression
2375 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2376 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2377 const gdb_byte
*op_end
,
2378 dwarf2_per_cu_data
*per_cu
,
2379 dwarf2_per_objfile
*per_objfile
)
2381 gdbarch
*arch
= expr
->gdbarch
;
2382 std::vector
<int> dw_labels
, patches
;
2383 const gdb_byte
* const base
= op_ptr
;
2384 const gdb_byte
*previous_piece
= op_ptr
;
2385 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2386 ULONGEST bits_collected
= 0;
2387 unsigned int addr_size_bits
= 8 * addr_size
;
2388 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2390 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2392 /* By default we are making an address. */
2393 loc
->kind
= axs_lvalue_memory
;
2395 while (op_ptr
< op_end
)
2397 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2398 uint64_t uoffset
, reg
;
2402 offsets
[op_ptr
- base
] = expr
->buf
.size ();
2405 /* Our basic approach to code generation is to map DWARF
2406 operations directly to AX operations. However, there are
2409 First, DWARF works on address-sized units, but AX always uses
2410 LONGEST. For most operations we simply ignore this
2411 difference; instead we generate sign extensions as needed
2412 before division and comparison operations. It would be nice
2413 to omit the sign extensions, but there is no way to determine
2414 the size of the target's LONGEST. (This code uses the size
2415 of the host LONGEST in some cases -- that is a bug but it is
2418 Second, some DWARF operations cannot be translated to AX.
2419 For these we simply fail. See
2420 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2455 ax_const_l (expr
, op
- DW_OP_lit0
);
2459 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2460 op_ptr
+= addr_size
;
2461 /* Some versions of GCC emit DW_OP_addr before
2462 DW_OP_GNU_push_tls_address. In this case the value is an
2463 index, not an address. We don't support things like
2464 branching between the address and the TLS op. */
2465 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2466 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2467 ax_const_l (expr
, uoffset
);
2471 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2476 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2481 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2486 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2491 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2496 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2501 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2506 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2511 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2512 ax_const_l (expr
, uoffset
);
2516 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2517 ax_const_l (expr
, offset
);
2552 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2553 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2554 loc
->kind
= axs_lvalue_register
;
2558 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2559 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2560 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2561 loc
->kind
= axs_lvalue_register
;
2564 case DW_OP_implicit_value
:
2568 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2569 if (op_ptr
+ len
> op_end
)
2570 error (_("DW_OP_implicit_value: too few bytes available."));
2571 if (len
> sizeof (ULONGEST
))
2572 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2575 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2578 dwarf_expr_require_composition (op_ptr
, op_end
,
2579 "DW_OP_implicit_value");
2581 loc
->kind
= axs_rvalue
;
2585 case DW_OP_stack_value
:
2586 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2587 loc
->kind
= axs_rvalue
;
2622 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2623 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2627 ax_const_l (expr
, offset
);
2628 ax_simple (expr
, aop_add
);
2634 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2635 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2636 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2640 ax_const_l (expr
, offset
);
2641 ax_simple (expr
, aop_add
);
2648 const gdb_byte
*datastart
;
2650 const struct block
*b
;
2651 struct symbol
*framefunc
;
2653 b
= block_for_pc (expr
->scope
);
2656 error (_("No block found for address"));
2658 framefunc
= b
->linkage_function ();
2661 error (_("No function found for block"));
2663 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2664 &datastart
, &datalen
);
2666 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2667 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2668 datastart
+ datalen
, per_cu
,
2670 if (loc
->kind
== axs_lvalue_register
)
2671 require_rvalue (expr
, loc
);
2675 ax_const_l (expr
, offset
);
2676 ax_simple (expr
, aop_add
);
2679 loc
->kind
= axs_lvalue_memory
;
2684 ax_simple (expr
, aop_dup
);
2688 ax_simple (expr
, aop_pop
);
2693 ax_pick (expr
, offset
);
2697 ax_simple (expr
, aop_swap
);
2705 ax_simple (expr
, aop_rot
);
2709 case DW_OP_deref_size
:
2713 if (op
== DW_OP_deref_size
)
2718 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2719 error (_("Unsupported size %d in %s"),
2720 size
, get_DW_OP_name (op
));
2721 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2726 /* Sign extend the operand. */
2727 ax_ext (expr
, addr_size_bits
);
2728 ax_simple (expr
, aop_dup
);
2729 ax_const_l (expr
, 0);
2730 ax_simple (expr
, aop_less_signed
);
2731 ax_simple (expr
, aop_log_not
);
2732 i
= ax_goto (expr
, aop_if_goto
);
2733 /* We have to emit 0 - X. */
2734 ax_const_l (expr
, 0);
2735 ax_simple (expr
, aop_swap
);
2736 ax_simple (expr
, aop_sub
);
2737 ax_label (expr
, i
, expr
->buf
.size ());
2741 /* No need to sign extend here. */
2742 ax_const_l (expr
, 0);
2743 ax_simple (expr
, aop_swap
);
2744 ax_simple (expr
, aop_sub
);
2748 /* Sign extend the operand. */
2749 ax_ext (expr
, addr_size_bits
);
2750 ax_simple (expr
, aop_bit_not
);
2753 case DW_OP_plus_uconst
:
2754 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2755 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2756 but we micro-optimize anyhow. */
2759 ax_const_l (expr
, reg
);
2760 ax_simple (expr
, aop_add
);
2765 ax_simple (expr
, aop_bit_and
);
2769 /* Sign extend the operands. */
2770 ax_ext (expr
, addr_size_bits
);
2771 ax_simple (expr
, aop_swap
);
2772 ax_ext (expr
, addr_size_bits
);
2773 ax_simple (expr
, aop_swap
);
2774 ax_simple (expr
, aop_div_signed
);
2778 ax_simple (expr
, aop_sub
);
2782 ax_simple (expr
, aop_rem_unsigned
);
2786 ax_simple (expr
, aop_mul
);
2790 ax_simple (expr
, aop_bit_or
);
2794 ax_simple (expr
, aop_add
);
2798 ax_simple (expr
, aop_lsh
);
2802 ax_simple (expr
, aop_rsh_unsigned
);
2806 ax_simple (expr
, aop_rsh_signed
);
2810 ax_simple (expr
, aop_bit_xor
);
2814 /* Sign extend the operands. */
2815 ax_ext (expr
, addr_size_bits
);
2816 ax_simple (expr
, aop_swap
);
2817 ax_ext (expr
, addr_size_bits
);
2818 /* Note no swap here: A <= B is !(B < A). */
2819 ax_simple (expr
, aop_less_signed
);
2820 ax_simple (expr
, aop_log_not
);
2824 /* Sign extend the operands. */
2825 ax_ext (expr
, addr_size_bits
);
2826 ax_simple (expr
, aop_swap
);
2827 ax_ext (expr
, addr_size_bits
);
2828 ax_simple (expr
, aop_swap
);
2829 /* A >= B is !(A < B). */
2830 ax_simple (expr
, aop_less_signed
);
2831 ax_simple (expr
, aop_log_not
);
2835 /* Sign extend the operands. */
2836 ax_ext (expr
, addr_size_bits
);
2837 ax_simple (expr
, aop_swap
);
2838 ax_ext (expr
, addr_size_bits
);
2839 /* No need for a second swap here. */
2840 ax_simple (expr
, aop_equal
);
2844 /* Sign extend the operands. */
2845 ax_ext (expr
, addr_size_bits
);
2846 ax_simple (expr
, aop_swap
);
2847 ax_ext (expr
, addr_size_bits
);
2848 ax_simple (expr
, aop_swap
);
2849 ax_simple (expr
, aop_less_signed
);
2853 /* Sign extend the operands. */
2854 ax_ext (expr
, addr_size_bits
);
2855 ax_simple (expr
, aop_swap
);
2856 ax_ext (expr
, addr_size_bits
);
2857 /* Note no swap here: A > B is B < A. */
2858 ax_simple (expr
, aop_less_signed
);
2862 /* Sign extend the operands. */
2863 ax_ext (expr
, addr_size_bits
);
2864 ax_simple (expr
, aop_swap
);
2865 ax_ext (expr
, addr_size_bits
);
2866 /* No need for a swap here. */
2867 ax_simple (expr
, aop_equal
);
2868 ax_simple (expr
, aop_log_not
);
2871 case DW_OP_call_frame_cfa
:
2874 CORE_ADDR text_offset
;
2876 const gdb_byte
*cfa_start
, *cfa_end
;
2878 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2880 &text_offset
, &cfa_start
, &cfa_end
))
2883 ax_reg (expr
, regnum
);
2886 ax_const_l (expr
, off
);
2887 ax_simple (expr
, aop_add
);
2892 /* Another expression. */
2893 ax_const_l (expr
, text_offset
);
2894 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2895 cfa_end
, per_cu
, per_objfile
);
2898 loc
->kind
= axs_lvalue_memory
;
2902 case DW_OP_GNU_push_tls_address
:
2903 case DW_OP_form_tls_address
:
2907 case DW_OP_push_object_address
:
2912 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2914 i
= ax_goto (expr
, aop_goto
);
2915 dw_labels
.push_back (op_ptr
+ offset
- base
);
2916 patches
.push_back (i
);
2920 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2922 /* Zero extend the operand. */
2923 ax_zero_ext (expr
, addr_size_bits
);
2924 i
= ax_goto (expr
, aop_if_goto
);
2925 dw_labels
.push_back (op_ptr
+ offset
- base
);
2926 patches
.push_back (i
);
2933 case DW_OP_bit_piece
:
2937 if (op_ptr
- 1 == previous_piece
)
2938 error (_("Cannot translate empty pieces to agent expressions"));
2939 previous_piece
= op_ptr
- 1;
2941 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2942 if (op
== DW_OP_piece
)
2948 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2950 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2951 error (_("Expression pieces exceed word size"));
2953 /* Access the bits. */
2956 case axs_lvalue_register
:
2957 ax_reg (expr
, loc
->u
.reg
);
2960 case axs_lvalue_memory
:
2961 /* Offset the pointer, if needed. */
2964 ax_const_l (expr
, uoffset
/ 8);
2965 ax_simple (expr
, aop_add
);
2968 access_memory (arch
, expr
, size
);
2972 /* For a bits-big-endian target, shift up what we already
2973 have. For a bits-little-endian target, shift up the
2974 new data. Note that there is a potential bug here if
2975 the DWARF expression leaves multiple values on the
2977 if (bits_collected
> 0)
2979 if (bits_big_endian
)
2981 ax_simple (expr
, aop_swap
);
2982 ax_const_l (expr
, size
);
2983 ax_simple (expr
, aop_lsh
);
2984 /* We don't need a second swap here, because
2985 aop_bit_or is symmetric. */
2989 ax_const_l (expr
, size
);
2990 ax_simple (expr
, aop_lsh
);
2992 ax_simple (expr
, aop_bit_or
);
2995 bits_collected
+= size
;
2996 loc
->kind
= axs_rvalue
;
3000 case DW_OP_GNU_uninit
:
3006 struct dwarf2_locexpr_baton block
;
3007 int size
= (op
== DW_OP_call2
? 2 : 4);
3009 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3012 auto get_frame_pc_from_expr
= [expr
] ()
3016 cu_offset cuoffset
= (cu_offset
) uoffset
;
3017 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3018 get_frame_pc_from_expr
);
3020 /* DW_OP_call_ref is currently not supported. */
3021 gdb_assert (block
.per_cu
== per_cu
);
3023 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3024 block
.data
+ block
.size
, per_cu
,
3029 case DW_OP_call_ref
:
3032 case DW_OP_GNU_variable_value
:
3040 /* Patch all the branches we emitted. */
3041 for (int i
= 0; i
< patches
.size (); ++i
)
3043 int targ
= offsets
[dw_labels
[i
]];
3045 internal_error (_("invalid label"));
3046 ax_label (expr
, patches
[i
], targ
);
3051 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3052 evaluator to calculate the location. */
3053 static struct value
*
3054 locexpr_read_variable (struct symbol
*symbol
, frame_info_ptr frame
)
3056 struct dwarf2_locexpr_baton
*dlbaton
3057 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3060 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, dlbaton
->data
,
3061 dlbaton
->size
, dlbaton
->per_cu
,
3062 dlbaton
->per_objfile
);
3067 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3068 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3071 static struct value
*
3072 locexpr_read_variable_at_entry (struct symbol
*symbol
, frame_info_ptr frame
)
3074 struct dwarf2_locexpr_baton
*dlbaton
3075 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3077 return value_of_dwarf_block_entry (symbol
->type (), frame
, dlbaton
->data
,
3081 /* Implementation of get_symbol_read_needs from
3082 symbol_computed_ops. */
3084 static enum symbol_needs_kind
3085 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3087 struct dwarf2_locexpr_baton
*dlbaton
3088 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3090 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3091 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3093 return dwarf2_get_symbol_read_needs (expr
,
3095 dlbaton
->per_objfile
,
3096 gdbarch_byte_order (arch
),
3097 dlbaton
->per_cu
->addr_size (),
3098 dlbaton
->per_cu
->ref_addr_size ());
3101 /* Return true if DATA points to the end of a piece. END is one past
3102 the last byte in the expression. */
3105 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3107 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3110 /* Helper for locexpr_describe_location_piece that finds the name of a
3114 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3118 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3119 We'd rather print *something* here than throw an error. */
3120 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3121 /* gdbarch_register_name may just return "", return something more
3122 descriptive for bad register numbers. */
3125 /* The text is output as "$bad_register_number".
3126 That is why we use the underscores. */
3127 return _("bad_register_number");
3129 return gdbarch_register_name (gdbarch
, regnum
);
3132 /* Nicely describe a single piece of a location, returning an updated
3133 position in the bytecode sequence. This function cannot recognize
3134 all locations; if a location is not recognized, it simply returns
3135 DATA. If there is an error during reading, e.g. we run off the end
3136 of the buffer, an error is thrown. */
3138 static const gdb_byte
*
3139 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3140 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3141 dwarf2_per_objfile
*per_objfile
,
3142 const gdb_byte
*data
, const gdb_byte
*end
,
3143 unsigned int addr_size
)
3145 objfile
*objfile
= per_objfile
->objfile
;
3146 struct gdbarch
*gdbarch
= objfile
->arch ();
3149 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3151 gdb_printf (stream
, _("a variable in $%s"),
3152 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3155 else if (data
[0] == DW_OP_regx
)
3159 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3160 gdb_printf (stream
, _("a variable in $%s"),
3161 locexpr_regname (gdbarch
, reg
));
3163 else if (data
[0] == DW_OP_fbreg
)
3165 const struct block
*b
;
3166 struct symbol
*framefunc
;
3168 int64_t frame_offset
;
3169 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3171 int64_t base_offset
= 0;
3173 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3174 if (!piece_end_p (new_data
, end
))
3178 b
= block_for_pc (addr
);
3181 error (_("No block found for address for symbol \"%s\"."),
3182 symbol
->print_name ());
3184 framefunc
= b
->linkage_function ();
3187 error (_("No function found for block for symbol \"%s\"."),
3188 symbol
->print_name ());
3190 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3192 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3194 const gdb_byte
*buf_end
;
3196 frame_reg
= base_data
[0] - DW_OP_breg0
;
3197 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3199 if (buf_end
!= base_data
+ base_size
)
3200 error (_("Unexpected opcode after "
3201 "DW_OP_breg%u for symbol \"%s\"."),
3202 frame_reg
, symbol
->print_name ());
3204 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3206 /* The frame base is just the register, with no offset. */
3207 frame_reg
= base_data
[0] - DW_OP_reg0
;
3212 /* We don't know what to do with the frame base expression,
3213 so we can't trace this variable; give up. */
3218 _("a variable at frame base reg $%s offset %s+%s"),
3219 locexpr_regname (gdbarch
, frame_reg
),
3220 plongest (base_offset
), plongest (frame_offset
));
3222 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3223 && piece_end_p (data
, end
))
3227 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3230 _("a variable at offset %s from base reg $%s"),
3232 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3235 /* The location expression for a TLS variable looks like this (on a
3238 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3239 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3241 0x3 is the encoding for DW_OP_addr, which has an operand as long
3242 as the size of an address on the target machine (here is 8
3243 bytes). Note that more recent version of GCC emit DW_OP_const4u
3244 or DW_OP_const8u, depending on address size, rather than
3245 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3246 The operand represents the offset at which the variable is within
3247 the thread local storage. */
3249 else if (data
+ 1 + addr_size
< end
3250 && (data
[0] == DW_OP_addr
3251 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3252 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3253 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3254 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3255 && piece_end_p (data
+ 2 + addr_size
, end
))
3258 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3259 gdbarch_byte_order (gdbarch
));
3262 _("a thread-local variable at offset 0x%s "
3263 "in the thread-local storage for `%s'"),
3264 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3266 data
+= 1 + addr_size
+ 1;
3269 /* With -gsplit-dwarf a TLS variable can also look like this:
3270 DW_AT_location : 3 byte block: fc 4 e0
3271 (DW_OP_GNU_const_index: 4;
3272 DW_OP_GNU_push_tls_address) */
3273 else if (data
+ 3 <= end
3274 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3275 && data
[0] == DW_OP_GNU_const_index
3277 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3278 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3279 && piece_end_p (data
+ 2 + leb128_size
, end
))
3283 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3284 offset
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3286 _("a thread-local variable at offset 0x%s "
3287 "in the thread-local storage for `%s'"),
3288 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3292 else if (data
[0] >= DW_OP_lit0
3293 && data
[0] <= DW_OP_lit31
3295 && data
[1] == DW_OP_stack_value
)
3297 gdb_printf (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3304 /* Disassemble an expression, stopping at the end of a piece or at the
3305 end of the expression. Returns a pointer to the next unread byte
3306 in the input expression. If ALL is nonzero, then this function
3307 will keep going until it reaches the end of the expression.
3308 If there is an error during reading, e.g. we run off the end
3309 of the buffer, an error is thrown. */
3311 static const gdb_byte
*
3312 disassemble_dwarf_expression (struct ui_file
*stream
,
3313 struct gdbarch
*arch
, unsigned int addr_size
,
3314 int offset_size
, const gdb_byte
*start
,
3315 const gdb_byte
*data
, const gdb_byte
*end
,
3316 int indent
, int all
,
3317 dwarf2_per_cu_data
*per_cu
,
3318 dwarf2_per_objfile
*per_objfile
)
3322 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3324 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3329 name
= get_DW_OP_name (op
);
3332 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3333 op
, (long) (data
- 1 - start
));
3334 gdb_printf (stream
, " %*ld: %s", indent
+ 4,
3335 (long) (data
- 1 - start
), name
);
3340 ul
= extract_unsigned_integer (data
, addr_size
,
3341 gdbarch_byte_order (arch
));
3343 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3347 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3349 gdb_printf (stream
, " %s", pulongest (ul
));
3353 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3355 gdb_printf (stream
, " %s", plongest (l
));
3359 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3361 gdb_printf (stream
, " %s", pulongest (ul
));
3365 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3367 gdb_printf (stream
, " %s", plongest (l
));
3371 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3373 gdb_printf (stream
, " %s", pulongest (ul
));
3377 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3379 gdb_printf (stream
, " %s", plongest (l
));
3383 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3385 gdb_printf (stream
, " %s", pulongest (ul
));
3389 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3391 gdb_printf (stream
, " %s", plongest (l
));
3395 data
= safe_read_uleb128 (data
, end
, &ul
);
3396 gdb_printf (stream
, " %s", pulongest (ul
));
3400 data
= safe_read_sleb128 (data
, end
, &l
);
3401 gdb_printf (stream
, " %s", plongest (l
));
3436 gdb_printf (stream
, " [$%s]",
3437 locexpr_regname (arch
, op
- DW_OP_reg0
));
3441 data
= safe_read_uleb128 (data
, end
, &ul
);
3442 gdb_printf (stream
, " %s [$%s]", pulongest (ul
),
3443 locexpr_regname (arch
, (int) ul
));
3446 case DW_OP_implicit_value
:
3447 data
= safe_read_uleb128 (data
, end
, &ul
);
3449 gdb_printf (stream
, " %s", pulongest (ul
));
3484 data
= safe_read_sleb128 (data
, end
, &l
);
3485 gdb_printf (stream
, " %s [$%s]", plongest (l
),
3486 locexpr_regname (arch
, op
- DW_OP_breg0
));
3490 data
= safe_read_uleb128 (data
, end
, &ul
);
3491 data
= safe_read_sleb128 (data
, end
, &l
);
3492 gdb_printf (stream
, " register %s [$%s] offset %s",
3494 locexpr_regname (arch
, (int) ul
),
3499 data
= safe_read_sleb128 (data
, end
, &l
);
3500 gdb_printf (stream
, " %s", plongest (l
));
3503 case DW_OP_xderef_size
:
3504 case DW_OP_deref_size
:
3506 gdb_printf (stream
, " %d", *data
);
3510 case DW_OP_plus_uconst
:
3511 data
= safe_read_uleb128 (data
, end
, &ul
);
3512 gdb_printf (stream
, " %s", pulongest (ul
));
3516 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3518 gdb_printf (stream
, " to %ld",
3519 (long) (data
+ l
- start
));
3523 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3525 gdb_printf (stream
, " %ld",
3526 (long) (data
+ l
- start
));
3530 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3532 gdb_printf (stream
, " offset %s", phex_nz (ul
, 2));
3536 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3538 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3541 case DW_OP_call_ref
:
3542 ul
= extract_unsigned_integer (data
, offset_size
,
3543 gdbarch_byte_order (arch
));
3544 data
+= offset_size
;
3545 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3549 data
= safe_read_uleb128 (data
, end
, &ul
);
3550 gdb_printf (stream
, " %s (bytes)", pulongest (ul
));
3553 case DW_OP_bit_piece
:
3557 data
= safe_read_uleb128 (data
, end
, &ul
);
3558 data
= safe_read_uleb128 (data
, end
, &offset
);
3559 gdb_printf (stream
, " size %s offset %s (bits)",
3560 pulongest (ul
), pulongest (offset
));
3564 case DW_OP_implicit_pointer
:
3565 case DW_OP_GNU_implicit_pointer
:
3567 ul
= extract_unsigned_integer (data
, offset_size
,
3568 gdbarch_byte_order (arch
));
3569 data
+= offset_size
;
3571 data
= safe_read_sleb128 (data
, end
, &l
);
3573 gdb_printf (stream
, " DIE %s offset %s",
3574 phex_nz (ul
, offset_size
),
3579 case DW_OP_deref_type
:
3580 case DW_OP_GNU_deref_type
:
3582 int deref_addr_size
= *data
++;
3585 data
= safe_read_uleb128 (data
, end
, &ul
);
3586 cu_offset offset
= (cu_offset
) ul
;
3587 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3588 gdb_printf (stream
, "<");
3589 type_print (type
, "", stream
, -1);
3590 gdb_printf (stream
, " [0x%s]> %d",
3591 phex_nz (to_underlying (offset
), 0),
3596 case DW_OP_const_type
:
3597 case DW_OP_GNU_const_type
:
3601 data
= safe_read_uleb128 (data
, end
, &ul
);
3602 cu_offset type_die
= (cu_offset
) ul
;
3603 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3604 gdb_printf (stream
, "<");
3605 type_print (type
, "", stream
, -1);
3606 gdb_printf (stream
, " [0x%s]>",
3607 phex_nz (to_underlying (type_die
), 0));
3610 gdb_printf (stream
, " %d byte block:", n
);
3611 for (int i
= 0; i
< n
; ++i
)
3612 gdb_printf (stream
, " %02x", data
[i
]);
3617 case DW_OP_regval_type
:
3618 case DW_OP_GNU_regval_type
:
3623 data
= safe_read_uleb128 (data
, end
, ®
);
3624 data
= safe_read_uleb128 (data
, end
, &ul
);
3625 cu_offset type_die
= (cu_offset
) ul
;
3627 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3628 gdb_printf (stream
, "<");
3629 type_print (type
, "", stream
, -1);
3630 gdb_printf (stream
, " [0x%s]> [$%s]",
3631 phex_nz (to_underlying (type_die
), 0),
3632 locexpr_regname (arch
, reg
));
3637 case DW_OP_GNU_convert
:
3638 case DW_OP_reinterpret
:
3639 case DW_OP_GNU_reinterpret
:
3641 data
= safe_read_uleb128 (data
, end
, &ul
);
3642 cu_offset type_die
= (cu_offset
) ul
;
3644 if (to_underlying (type_die
) == 0)
3645 gdb_printf (stream
, "<0>");
3650 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3651 gdb_printf (stream
, "<");
3652 type_print (type
, "", stream
, -1);
3653 gdb_printf (stream
, " [0x%s]>",
3654 phex_nz (to_underlying (type_die
), 0));
3659 case DW_OP_entry_value
:
3660 case DW_OP_GNU_entry_value
:
3661 data
= safe_read_uleb128 (data
, end
, &ul
);
3662 gdb_putc ('\n', stream
);
3663 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3664 start
, data
, data
+ ul
, indent
+ 2,
3665 all
, per_cu
, per_objfile
);
3669 case DW_OP_GNU_parameter_ref
:
3670 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3672 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3676 case DW_OP_GNU_addr_index
:
3677 data
= safe_read_uleb128 (data
, end
, &ul
);
3678 ul
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3679 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3682 case DW_OP_GNU_const_index
:
3683 data
= safe_read_uleb128 (data
, end
, &ul
);
3684 ul
= (uint64_t) dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3685 gdb_printf (stream
, " %s", pulongest (ul
));
3688 case DW_OP_GNU_variable_value
:
3689 ul
= extract_unsigned_integer (data
, offset_size
,
3690 gdbarch_byte_order (arch
));
3691 data
+= offset_size
;
3692 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3696 gdb_printf (stream
, "\n");
3702 static bool dwarf_always_disassemble
;
3705 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3706 struct cmd_list_element
*c
, const char *value
)
3709 _("Whether to always disassemble "
3710 "DWARF expressions is %s.\n"),
3714 /* Describe a single location, which may in turn consist of multiple
3718 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3719 struct ui_file
*stream
,
3720 const gdb_byte
*data
, size_t size
,
3721 unsigned int addr_size
,
3722 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3723 dwarf2_per_objfile
*per_objfile
)
3725 const gdb_byte
*end
= data
+ size
;
3726 int first_piece
= 1, bad
= 0;
3727 objfile
*objfile
= per_objfile
->objfile
;
3731 const gdb_byte
*here
= data
;
3732 int disassemble
= 1;
3737 gdb_printf (stream
, _(", and "));
3739 if (!dwarf_always_disassemble
)
3741 data
= locexpr_describe_location_piece (symbol
, stream
,
3742 addr
, per_cu
, per_objfile
,
3743 data
, end
, addr_size
);
3744 /* If we printed anything, or if we have an empty piece,
3745 then don't disassemble. */
3747 || data
[0] == DW_OP_piece
3748 || data
[0] == DW_OP_bit_piece
)
3753 gdb_printf (stream
, _("a complex DWARF expression:\n"));
3754 data
= disassemble_dwarf_expression (stream
,
3756 addr_size
, offset_size
, data
,
3758 dwarf_always_disassemble
,
3759 per_cu
, per_objfile
);
3764 int empty
= data
== here
;
3767 gdb_printf (stream
, " ");
3768 if (data
[0] == DW_OP_piece
)
3772 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3775 gdb_printf (stream
, _("an empty %s-byte piece"),
3778 gdb_printf (stream
, _(" [%s-byte piece]"),
3781 else if (data
[0] == DW_OP_bit_piece
)
3783 uint64_t bits
, offset
;
3785 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3786 data
= safe_read_uleb128 (data
, end
, &offset
);
3790 _("an empty %s-bit piece"),
3794 _(" [%s-bit piece, offset %s bits]"),
3795 pulongest (bits
), pulongest (offset
));
3805 if (bad
|| data
> end
)
3806 error (_("Corrupted DWARF2 expression for \"%s\"."),
3807 symbol
->print_name ());
3810 /* Print a natural-language description of SYMBOL to STREAM. This
3811 version is for a symbol with a single location. */
3814 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3815 struct ui_file
*stream
)
3817 struct dwarf2_locexpr_baton
*dlbaton
3818 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3819 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3820 int offset_size
= dlbaton
->per_cu
->offset_size ();
3822 locexpr_describe_location_1 (symbol
, addr
, stream
,
3823 dlbaton
->data
, dlbaton
->size
,
3824 addr_size
, offset_size
,
3825 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3828 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3829 any necessary bytecode in AX. */
3832 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3833 struct axs_value
*value
)
3835 struct dwarf2_locexpr_baton
*dlbaton
3836 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3837 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3839 if (dlbaton
->size
== 0)
3840 value
->optimized_out
= 1;
3842 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3843 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3844 dlbaton
->per_objfile
);
3847 /* symbol_computed_ops 'generate_c_location' method. */
3850 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3851 struct gdbarch
*gdbarch
,
3852 std::vector
<bool> ®isters_used
,
3853 CORE_ADDR pc
, const char *result_name
)
3855 struct dwarf2_locexpr_baton
*dlbaton
3856 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3857 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3859 if (dlbaton
->size
== 0)
3860 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3862 compile_dwarf_expr_to_c (stream
, result_name
,
3863 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3864 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3865 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3868 /* The set of location functions used with the DWARF-2 expression
3870 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3871 locexpr_read_variable
,
3872 locexpr_read_variable_at_entry
,
3873 locexpr_get_symbol_read_needs
,
3874 locexpr_describe_location
,
3875 0, /* location_has_loclist */
3876 locexpr_tracepoint_var_ref
,
3877 locexpr_generate_c_location
3881 /* Wrapper functions for location lists. These generally find
3882 the appropriate location expression and call something above. */
3884 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3885 evaluator to calculate the location. */
3886 static struct value
*
3887 loclist_read_variable (struct symbol
*symbol
, frame_info_ptr frame
)
3889 struct dwarf2_loclist_baton
*dlbaton
3890 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3892 const gdb_byte
*data
;
3894 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3896 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3897 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, data
, size
,
3898 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3903 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3904 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3907 Function always returns non-NULL value, it may be marked optimized out if
3908 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3909 if it cannot resolve the parameter for any reason. */
3911 static struct value
*
3912 loclist_read_variable_at_entry (struct symbol
*symbol
, frame_info_ptr frame
)
3914 struct dwarf2_loclist_baton
*dlbaton
3915 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3916 const gdb_byte
*data
;
3920 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3921 return value::allocate_optimized_out (symbol
->type ());
3923 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3925 return value::allocate_optimized_out (symbol
->type ());
3927 return value_of_dwarf_block_entry (symbol
->type (), frame
, data
, size
);
3930 /* Implementation of get_symbol_read_needs from
3931 symbol_computed_ops. */
3933 static enum symbol_needs_kind
3934 loclist_symbol_needs (struct symbol
*symbol
)
3936 /* If there's a location list, then assume we need to have a frame
3937 to choose the appropriate location expression. With tracking of
3938 global variables this is not necessarily true, but such tracking
3939 is disabled in GCC at the moment until we figure out how to
3942 return SYMBOL_NEEDS_FRAME
;
3945 /* Print a natural-language description of SYMBOL to STREAM. This
3946 version applies when there is a list of different locations, each
3947 with a specified address range. */
3950 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3951 struct ui_file
*stream
)
3953 struct dwarf2_loclist_baton
*dlbaton
3954 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3955 const gdb_byte
*loc_ptr
, *buf_end
;
3956 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3957 struct objfile
*objfile
= per_objfile
->objfile
;
3958 struct gdbarch
*gdbarch
= objfile
->arch ();
3959 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3960 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3961 int offset_size
= dlbaton
->per_cu
->offset_size ();
3962 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
.get ());
3963 unrelocated_addr base_address
= dlbaton
->base_address
;
3966 loc_ptr
= dlbaton
->data
;
3967 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3969 gdb_printf (stream
, _("multi-location:\n"));
3971 /* Iterate through locations until we run out. */
3974 unrelocated_addr low
= {}, high
= {}; /* init for gcc -Wall */
3976 enum debug_loc_kind kind
;
3977 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3979 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3980 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3982 loc_ptr
, buf_end
, &new_ptr
,
3983 &low
, &high
, byte_order
);
3984 else if (dlbaton
->per_cu
->version () < 5)
3985 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3987 byte_order
, addr_size
,
3990 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3992 loc_ptr
, buf_end
, &new_ptr
,
3993 &low
, &high
, byte_order
,
3994 addr_size
, signed_addr_p
);
3998 case DEBUG_LOC_END_OF_LIST
:
4002 case DEBUG_LOC_BASE_ADDRESS
:
4003 base_address
= high
;
4004 gdb_printf (stream
, _(" Base address %s"),
4005 paddress (gdbarch
, (CORE_ADDR
) base_address
));
4008 case DEBUG_LOC_START_END
:
4009 case DEBUG_LOC_START_LENGTH
:
4010 case DEBUG_LOC_OFFSET_PAIR
:
4013 case DEBUG_LOC_BUFFER_OVERFLOW
:
4014 case DEBUG_LOC_INVALID_ENTRY
:
4015 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4016 symbol
->print_name ());
4019 gdb_assert_not_reached ("bad debug_loc_kind");
4022 /* Otherwise, a location expression entry. */
4023 if (!dlbaton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
4025 low
= (unrelocated_addr
) ((CORE_ADDR
) low
4026 + (CORE_ADDR
) base_address
);
4027 high
= (unrelocated_addr
) ((CORE_ADDR
) high
4028 + (CORE_ADDR
) base_address
);
4031 CORE_ADDR low_reloc
= per_objfile
->relocate (low
);
4032 CORE_ADDR high_reloc
= per_objfile
->relocate (high
);
4034 if (dlbaton
->per_cu
->version () < 5)
4036 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4041 unsigned int bytes_read
;
4042 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4043 loc_ptr
+= bytes_read
;
4046 /* (It would improve readability to print only the minimum
4047 necessary digits of the second number of the range.) */
4048 gdb_printf (stream
, _(" Range %s-%s: "),
4049 paddress (gdbarch
, low_reloc
),
4050 paddress (gdbarch
, high_reloc
));
4052 /* Now describe this particular location. */
4053 locexpr_describe_location_1 (symbol
, low_reloc
, stream
, loc_ptr
, length
,
4054 addr_size
, offset_size
,
4055 dlbaton
->per_cu
, per_objfile
);
4057 gdb_printf (stream
, "\n");
4063 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4064 any necessary bytecode in AX. */
4066 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4067 struct axs_value
*value
)
4069 struct dwarf2_loclist_baton
*dlbaton
4070 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4071 const gdb_byte
*data
;
4073 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4075 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4077 value
->optimized_out
= 1;
4079 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4080 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4083 /* symbol_computed_ops 'generate_c_location' method. */
4086 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4087 struct gdbarch
*gdbarch
,
4088 std::vector
<bool> ®isters_used
,
4089 CORE_ADDR pc
, const char *result_name
)
4091 struct dwarf2_loclist_baton
*dlbaton
4092 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4093 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4094 const gdb_byte
*data
;
4097 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4099 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4101 compile_dwarf_expr_to_c (stream
, result_name
,
4102 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4105 dlbaton
->per_objfile
);
4108 /* The set of location functions used with the DWARF-2 expression
4109 evaluator and location lists. */
4110 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4111 loclist_read_variable
,
4112 loclist_read_variable_at_entry
,
4113 loclist_symbol_needs
,
4114 loclist_describe_location
,
4115 1, /* location_has_loclist */
4116 loclist_tracepoint_var_ref
,
4117 loclist_generate_c_location
4120 void _initialize_dwarf2loc ();
4122 _initialize_dwarf2loc ()
4124 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4125 &entry_values_debug
,
4126 _("Set entry values and tail call frames "
4128 _("Show entry values and tail call frames "
4130 _("When non-zero, the process of determining "
4131 "parameter values from function entry point "
4132 "and tail call frames will be printed."),
4134 show_entry_values_debug
,
4135 &setdebuglist
, &showdebuglist
);
4137 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4138 &dwarf_always_disassemble
, _("\
4139 Set whether `info address' always disassembles DWARF expressions."), _("\
4140 Show whether `info address' always disassembles DWARF expressions."), _("\
4141 When enabled, DWARF expressions are always printed in an assembly-like\n\
4142 syntax. When disabled, expressions will be printed in a more\n\
4143 conversational style, when possible."),
4145 show_dwarf_always_disassemble
,
4147 &show_dwarf_cmdlist
);