1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2022 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
, struct frame_info
*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 CORE_ADDR
*low
, CORE_ADDR
*high
,
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
;
121 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
123 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
124 loc_ptr
+= addr_size
;
127 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
129 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
130 loc_ptr
+= addr_size
;
134 /* A base-address-selection entry. */
135 if ((*low
& base_mask
) == base_mask
)
136 return DEBUG_LOC_BASE_ADDRESS
;
138 /* An end-of-list entry. */
139 if (*low
== 0 && *high
== 0)
140 return DEBUG_LOC_END_OF_LIST
;
142 /* We want the caller to apply the base address, so we must return
143 DEBUG_LOC_OFFSET_PAIR here. */
144 return DEBUG_LOC_OFFSET_PAIR
;
147 /* Decode the addresses in .debug_loclists entry.
148 A pointer to the next byte to examine is returned in *NEW_PTR.
149 The encoded low,high addresses are return in *LOW,*HIGH.
150 The result indicates the kind of entry found. */
152 static enum debug_loc_kind
153 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
154 dwarf2_per_objfile
*per_objfile
,
155 const gdb_byte
*loc_ptr
,
156 const gdb_byte
*buf_end
,
157 const gdb_byte
**new_ptr
,
158 CORE_ADDR
*low
, CORE_ADDR
*high
,
159 enum bfd_endian byte_order
,
160 unsigned int addr_size
,
165 if (loc_ptr
== buf_end
)
166 return DEBUG_LOC_BUFFER_OVERFLOW
;
170 case DW_LLE_base_addressx
:
172 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
174 return DEBUG_LOC_BUFFER_OVERFLOW
;
176 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
178 return DEBUG_LOC_BASE_ADDRESS
;
180 case DW_LLE_startx_length
:
181 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
183 return DEBUG_LOC_BUFFER_OVERFLOW
;
185 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
187 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
189 return DEBUG_LOC_BUFFER_OVERFLOW
;
193 return DEBUG_LOC_START_LENGTH
;
195 case DW_LLE_start_length
:
196 if (buf_end
- loc_ptr
< addr_size
)
197 return DEBUG_LOC_BUFFER_OVERFLOW
;
200 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
202 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
204 loc_ptr
+= addr_size
;
207 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
209 return DEBUG_LOC_BUFFER_OVERFLOW
;
213 return DEBUG_LOC_START_LENGTH
;
215 case DW_LLE_end_of_list
:
217 return DEBUG_LOC_END_OF_LIST
;
219 case DW_LLE_base_address
:
220 if (loc_ptr
+ addr_size
> buf_end
)
221 return DEBUG_LOC_BUFFER_OVERFLOW
;
224 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
226 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
228 loc_ptr
+= addr_size
;
230 return DEBUG_LOC_BASE_ADDRESS
;
232 case DW_LLE_offset_pair
:
233 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
235 return DEBUG_LOC_BUFFER_OVERFLOW
;
238 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
240 return DEBUG_LOC_BUFFER_OVERFLOW
;
244 return DEBUG_LOC_OFFSET_PAIR
;
246 case DW_LLE_start_end
:
247 if (loc_ptr
+ 2 * addr_size
> buf_end
)
248 return DEBUG_LOC_BUFFER_OVERFLOW
;
251 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
253 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
255 loc_ptr
+= addr_size
;
257 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
259 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
261 loc_ptr
+= addr_size
;
263 return DEBUG_LOC_START_END
;
265 /* Following cases are not supported yet. */
266 case DW_LLE_startx_endx
:
267 case DW_LLE_default_location
:
269 return DEBUG_LOC_INVALID_ENTRY
;
273 /* Decode the addresses in .debug_loc.dwo entry.
274 A pointer to the next byte to examine is returned in *NEW_PTR.
275 The encoded low,high addresses are return in *LOW,*HIGH.
276 The result indicates the kind of entry found. */
278 static enum debug_loc_kind
279 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
280 dwarf2_per_objfile
*per_objfile
,
281 const gdb_byte
*loc_ptr
,
282 const gdb_byte
*buf_end
,
283 const gdb_byte
**new_ptr
,
284 CORE_ADDR
*low
, CORE_ADDR
*high
,
285 enum bfd_endian byte_order
)
287 uint64_t low_index
, high_index
;
289 if (loc_ptr
== buf_end
)
290 return DEBUG_LOC_BUFFER_OVERFLOW
;
294 case DW_LLE_GNU_end_of_list_entry
:
296 return DEBUG_LOC_END_OF_LIST
;
298 case DW_LLE_GNU_base_address_selection_entry
:
300 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
302 return DEBUG_LOC_BUFFER_OVERFLOW
;
304 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
306 return DEBUG_LOC_BASE_ADDRESS
;
308 case DW_LLE_GNU_start_end_entry
:
309 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
311 return DEBUG_LOC_BUFFER_OVERFLOW
;
313 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
314 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
316 return DEBUG_LOC_BUFFER_OVERFLOW
;
318 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
320 return DEBUG_LOC_START_END
;
322 case DW_LLE_GNU_start_length_entry
:
323 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
325 return DEBUG_LOC_BUFFER_OVERFLOW
;
327 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
328 if (loc_ptr
+ 4 > buf_end
)
329 return DEBUG_LOC_BUFFER_OVERFLOW
;
332 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
333 *new_ptr
= loc_ptr
+ 4;
334 return DEBUG_LOC_START_LENGTH
;
337 return DEBUG_LOC_INVALID_ENTRY
;
341 /* A function for dealing with location lists. Given a
342 symbol baton (BATON) and a pc value (PC), find the appropriate
343 location expression, set *LOCEXPR_LENGTH, and return a pointer
344 to the beginning of the expression. Returns NULL on failure.
346 For now, only return the first matching location expression; there
347 can be more than one in the list. */
350 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
351 size_t *locexpr_length
, CORE_ADDR pc
)
353 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
354 struct objfile
*objfile
= per_objfile
->objfile
;
355 struct gdbarch
*gdbarch
= objfile
->arch ();
356 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
357 unsigned int addr_size
= baton
->per_cu
->addr_size ();
358 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
359 /* Adjustment for relocatable objects. */
360 CORE_ADDR text_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
361 CORE_ADDR base_address
= baton
->base_address
;
362 const gdb_byte
*loc_ptr
, *buf_end
;
364 loc_ptr
= baton
->data
;
365 buf_end
= baton
->data
+ baton
->size
;
369 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
371 enum debug_loc_kind kind
;
372 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
374 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
375 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
377 loc_ptr
, buf_end
, &new_ptr
,
378 &low
, &high
, byte_order
);
379 else if (baton
->per_cu
->version () < 5)
380 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
382 byte_order
, addr_size
,
385 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
387 loc_ptr
, buf_end
, &new_ptr
,
388 &low
, &high
, byte_order
,
389 addr_size
, signed_addr_p
);
394 case DEBUG_LOC_END_OF_LIST
:
398 case DEBUG_LOC_BASE_ADDRESS
:
402 case DEBUG_LOC_START_END
:
403 case DEBUG_LOC_START_LENGTH
:
404 case DEBUG_LOC_OFFSET_PAIR
:
407 case DEBUG_LOC_BUFFER_OVERFLOW
:
408 case DEBUG_LOC_INVALID_ENTRY
:
409 error (_("dwarf2_find_location_expression: "
410 "Corrupted DWARF expression."));
413 gdb_assert_not_reached ("bad debug_loc_kind");
416 /* Otherwise, a location expression entry.
417 If the entry is from a DWO, don't add base address: the entry is from
418 .debug_addr which already has the DWARF "base address". We still add
419 text offset in case we're debugging a PIE executable. However, if the
420 entry is DW_LLE_offset_pair from a DWO, add the base address as the
421 operands are offsets relative to the applicable base address.
422 If the entry is DW_LLE_start_end or DW_LLE_start_length, then
423 it already is an address, and we don't need to add the base. */
426 if (!baton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
429 high
+= base_address
;
432 if (baton
->per_cu
->version () < 5)
434 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
439 unsigned int bytes_read
;
441 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
442 loc_ptr
+= bytes_read
;
445 if (low
== high
&& pc
== low
)
447 /* This is entry PC record present only at entry point
448 of a function. Verify it is really the function entry point. */
450 const struct block
*pc_block
= block_for_pc (pc
);
451 struct symbol
*pc_func
= NULL
;
454 pc_func
= block_linkage_function (pc_block
);
456 if (pc_func
&& pc
== pc_func
->value_block ()->entry_pc ())
458 *locexpr_length
= length
;
463 if (pc
>= low
&& pc
< high
)
465 *locexpr_length
= length
;
473 /* Implement find_frame_base_location method for LOC_BLOCK functions using
474 DWARF expression for its DW_AT_frame_base. */
477 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
478 const gdb_byte
**start
, size_t *length
)
480 struct dwarf2_locexpr_baton
*symbaton
481 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
483 *length
= symbaton
->size
;
484 *start
= symbaton
->data
;
487 /* Implement the struct symbol_block_ops::get_frame_base method for
488 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
491 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
493 struct gdbarch
*gdbarch
;
495 struct dwarf2_locexpr_baton
*dlbaton
;
496 const gdb_byte
*start
;
498 struct value
*result
;
500 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
501 Thus, it's supposed to provide the find_frame_base_location method as
503 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
505 gdbarch
= get_frame_arch (frame
);
506 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
507 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
509 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
510 (framefunc
, get_frame_pc (frame
), &start
, &length
);
511 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
512 dlbaton
->per_cu
, dlbaton
->per_objfile
);
514 /* The DW_AT_frame_base attribute contains a location description which
515 computes the base address itself. However, the call to
516 dwarf2_evaluate_loc_desc returns a value representing a variable at
517 that address. The frame base address is thus this variable's
519 return value_address (result
);
522 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
523 function uses DWARF expression for its DW_AT_frame_base. */
525 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
527 locexpr_find_frame_base_location
,
528 locexpr_get_frame_base
531 /* Implement find_frame_base_location method for LOC_BLOCK functions using
532 DWARF location list for its DW_AT_frame_base. */
535 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
536 const gdb_byte
**start
, size_t *length
)
538 struct dwarf2_loclist_baton
*symbaton
539 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
541 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
544 /* Implement the struct symbol_block_ops::get_frame_base method for
545 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
548 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
550 struct gdbarch
*gdbarch
;
552 struct dwarf2_loclist_baton
*dlbaton
;
553 const gdb_byte
*start
;
555 struct value
*result
;
557 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
558 Thus, it's supposed to provide the find_frame_base_location method as
560 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
562 gdbarch
= get_frame_arch (frame
);
563 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
564 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
566 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
567 (framefunc
, get_frame_pc (frame
), &start
, &length
);
568 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
569 dlbaton
->per_cu
, dlbaton
->per_objfile
);
571 /* The DW_AT_frame_base attribute contains a location description which
572 computes the base address itself. However, the call to
573 dwarf2_evaluate_loc_desc returns a value representing a variable at
574 that address. The frame base address is thus this variable's
576 return value_address (result
);
579 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
580 function uses DWARF location list for its DW_AT_frame_base. */
582 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
584 loclist_find_frame_base_location
,
585 loclist_get_frame_base
588 /* See dwarf2/loc.h. */
591 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
592 const gdb_byte
**start
, size_t *length
)
594 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
596 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
598 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
604 error (_("Could not find the frame base for \"%s\"."),
605 framefunc
->natural_name ());
611 compute_var_value (const char *name
)
613 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
615 if (sym
.symbol
!= nullptr)
616 return value_of_variable (sym
.symbol
, sym
.block
);
620 /* See dwarf2/loc.h. */
622 unsigned int entry_values_debug
= 0;
624 /* Helper to set entry_values_debug. */
627 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
628 struct cmd_list_element
*c
, const char *value
)
631 _("Entry values and tail call frames debugging is %s.\n"),
635 /* See gdbtypes.h. */
638 call_site_target::iterate_over_addresses
639 (struct gdbarch
*call_site_gdbarch
,
640 const struct call_site
*call_site
,
641 struct frame_info
*caller_frame
,
642 iterate_ftype callback
) const
646 case call_site_target::DWARF_BLOCK
:
648 struct dwarf2_locexpr_baton
*dwarf_block
;
650 struct type
*caller_core_addr_type
;
651 struct gdbarch
*caller_arch
;
653 dwarf_block
= m_loc
.dwarf_block
;
654 if (dwarf_block
== NULL
)
656 struct bound_minimal_symbol msym
;
658 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
659 throw_error (NO_ENTRY_VALUE_ERROR
,
660 _("DW_AT_call_target is not specified at %s in %s"),
661 paddress (call_site_gdbarch
, call_site
->pc ()),
662 (msym
.minsym
== NULL
? "???"
663 : msym
.minsym
->print_name ()));
666 if (caller_frame
== NULL
)
668 struct bound_minimal_symbol msym
;
670 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
671 throw_error (NO_ENTRY_VALUE_ERROR
,
672 _("DW_AT_call_target DWARF block resolving "
673 "requires known frame which is currently not "
674 "available at %s in %s"),
675 paddress (call_site_gdbarch
, call_site
->pc ()),
676 (msym
.minsym
== NULL
? "???"
677 : msym
.minsym
->print_name ()));
680 caller_arch
= get_frame_arch (caller_frame
);
681 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
682 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
683 dwarf_block
->data
, dwarf_block
->size
,
685 dwarf_block
->per_objfile
);
686 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
687 if (VALUE_LVAL (val
) == lval_memory
)
688 callback (value_address (val
));
690 callback (value_as_address (val
));
694 case call_site_target::PHYSNAME
:
696 const char *physname
;
697 struct bound_minimal_symbol msym
;
699 physname
= m_loc
.physname
;
701 /* Handle both the mangled and demangled PHYSNAME. */
702 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
703 if (msym
.minsym
== NULL
)
705 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
706 throw_error (NO_ENTRY_VALUE_ERROR
,
707 _("Cannot find function \"%s\" for a call site target "
709 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
710 (msym
.minsym
== NULL
? "???"
711 : msym
.minsym
->print_name ()));
714 callback (msym
.value_address ());
718 case call_site_target::PHYSADDR
:
720 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
721 compunit_symtab
*cust
= per_objfile
->get_symtab (call_site
->per_cu
);
722 int sect_idx
= cust
->block_line_section ();
723 CORE_ADDR delta
= per_objfile
->objfile
->section_offsets
[sect_idx
];
725 callback (m_loc
.physaddr
+ delta
);
729 case call_site_target::ADDRESSES
:
731 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
732 compunit_symtab
*cust
= per_objfile
->get_symtab (call_site
->per_cu
);
733 int sect_idx
= cust
->block_line_section ();
734 CORE_ADDR delta
= per_objfile
->objfile
->section_offsets
[sect_idx
];
736 for (unsigned i
= 0; i
< m_loc
.addresses
.length
; ++i
)
737 callback (m_loc
.addresses
.values
[i
] + delta
);
742 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
746 /* Convert function entry point exact address ADDR to the function which is
747 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
748 NO_ENTRY_VALUE_ERROR otherwise. */
750 static struct symbol
*
751 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
753 struct symbol
*sym
= find_pc_function (addr
);
756 if (sym
== NULL
|| sym
->value_block ()->entry_pc () != addr
)
757 throw_error (NO_ENTRY_VALUE_ERROR
,
758 _("DW_TAG_call_site resolving failed to find function "
759 "name for address %s"),
760 paddress (gdbarch
, addr
));
763 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
764 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
769 /* Verify function with entry point exact address ADDR can never call itself
770 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
771 can call itself via tail calls.
773 If a funtion can tail call itself its entry value based parameters are
774 unreliable. There is no verification whether the value of some/all
775 parameters is unchanged through the self tail call, we expect if there is
776 a self tail call all the parameters can be modified. */
779 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
783 /* The verification is completely unordered. Track here function addresses
784 which still need to be iterated. */
785 std::vector
<CORE_ADDR
> todo
;
787 /* Track here CORE_ADDRs which were already visited. */
788 std::unordered_set
<CORE_ADDR
> addr_hash
;
790 todo
.push_back (verify_addr
);
791 while (!todo
.empty ())
793 struct symbol
*func_sym
;
794 struct call_site
*call_site
;
799 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
801 for (call_site
= TYPE_TAIL_CALL_LIST (func_sym
->type ());
802 call_site
; call_site
= call_site
->tail_call_next
)
804 /* CALLER_FRAME with registers is not available for tail-call jumped
806 call_site
->iterate_over_addresses (gdbarch
, nullptr,
807 [&] (CORE_ADDR target_addr
)
809 if (target_addr
== verify_addr
)
811 struct bound_minimal_symbol msym
;
813 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
814 throw_error (NO_ENTRY_VALUE_ERROR
,
815 _("DW_OP_entry_value resolving has found "
816 "function \"%s\" at %s can call itself via tail "
818 (msym
.minsym
== NULL
? "???"
819 : msym
.minsym
->print_name ()),
820 paddress (gdbarch
, verify_addr
));
823 if (addr_hash
.insert (target_addr
).second
)
824 todo
.push_back (target_addr
);
830 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
831 ENTRY_VALUES_DEBUG. */
834 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
836 CORE_ADDR addr
= call_site
->pc ();
837 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
839 gdb_printf (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
840 (msym
.minsym
== NULL
? "???"
841 : msym
.minsym
->print_name ()));
845 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
846 only top callers and bottom callees which are present in both. GDBARCH is
847 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
848 no remaining possibilities to provide unambiguous non-trivial result.
849 RESULTP should point to NULL on the first (initialization) call. Caller is
850 responsible for xfree of any RESULTP data. */
853 chain_candidate (struct gdbarch
*gdbarch
,
854 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
855 const std::vector
<struct call_site
*> &chain
)
857 long length
= chain
.size ();
858 int callers
, callees
, idx
;
860 if (*resultp
== NULL
)
862 /* Create the initial chain containing all the passed PCs. */
864 struct call_site_chain
*result
865 = ((struct call_site_chain
*)
866 xmalloc (sizeof (*result
)
867 + sizeof (*result
->call_site
) * (length
- 1)));
868 result
->length
= length
;
869 result
->callers
= result
->callees
= length
;
871 memcpy (result
->call_site
, chain
.data (),
872 sizeof (*result
->call_site
) * length
);
873 resultp
->reset (result
);
875 if (entry_values_debug
)
877 gdb_printf (gdb_stdlog
, "tailcall: initial:");
878 for (idx
= 0; idx
< length
; idx
++)
879 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
880 gdb_putc ('\n', gdb_stdlog
);
886 if (entry_values_debug
)
888 gdb_printf (gdb_stdlog
, "tailcall: compare:");
889 for (idx
= 0; idx
< length
; idx
++)
890 tailcall_dump (gdbarch
, chain
[idx
]);
891 gdb_putc ('\n', gdb_stdlog
);
894 /* Intersect callers. */
896 callers
= std::min ((long) (*resultp
)->callers
, length
);
897 for (idx
= 0; idx
< callers
; idx
++)
898 if ((*resultp
)->call_site
[idx
] != chain
[idx
])
900 (*resultp
)->callers
= idx
;
904 /* Intersect callees. */
906 callees
= std::min ((long) (*resultp
)->callees
, length
);
907 for (idx
= 0; idx
< callees
; idx
++)
908 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
909 != chain
[length
- 1 - idx
])
911 (*resultp
)->callees
= idx
;
915 if (entry_values_debug
)
917 gdb_printf (gdb_stdlog
, "tailcall: reduced:");
918 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
919 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
920 gdb_puts (" |", gdb_stdlog
);
921 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
922 tailcall_dump (gdbarch
,
923 (*resultp
)->call_site
[(*resultp
)->length
924 - (*resultp
)->callees
+ idx
]);
925 gdb_putc ('\n', gdb_stdlog
);
928 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
930 /* There are no common callers or callees. It could be also a direct
931 call (which has length 0) with ambiguous possibility of an indirect
932 call - CALLERS == CALLEES == 0 is valid during the first allocation
933 but any subsequence processing of such entry means ambiguity. */
934 resultp
->reset (NULL
);
938 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
939 PC again. In such case there must be two different code paths to reach
940 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
941 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
944 /* Recursively try to construct the call chain. GDBARCH, RESULTP, and
945 CHAIN are passed to chain_candidate. ADDR_HASH tracks which
946 addresses have already been seen along the current chain.
947 CALL_SITE is the call site to visit, and CALLEE_PC is the PC we're
948 trying to "reach". Returns false if an error has already been
949 detected and so an early return can be done. If it makes sense to
950 keep trying (even if no answer has yet been found), returns
954 call_site_find_chain_2
955 (struct gdbarch
*gdbarch
,
956 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
957 std::vector
<struct call_site
*> &chain
,
958 std::unordered_set
<CORE_ADDR
> &addr_hash
,
959 struct call_site
*call_site
,
962 std::vector
<CORE_ADDR
> addresses
;
963 bool found_exact
= false;
964 call_site
->iterate_over_addresses (gdbarch
, nullptr,
967 if (addr
== callee_pc
)
970 addresses
.push_back (addr
);
975 chain_candidate (gdbarch
, resultp
, chain
);
976 /* If RESULTP was reset, then chain_candidate failed, and so we
977 can tell our callers to early-return. */
978 return *resultp
!= nullptr;
981 for (CORE_ADDR target_func_addr
: addresses
)
983 struct symbol
*target_func
984 = func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
985 for (struct call_site
*target_call_site
986 = TYPE_TAIL_CALL_LIST (target_func
->type ());
987 target_call_site
!= nullptr;
988 target_call_site
= target_call_site
->tail_call_next
)
990 if (addr_hash
.insert (target_call_site
->pc ()).second
)
992 /* Successfully entered TARGET_CALL_SITE. */
993 chain
.push_back (target_call_site
);
995 if (!call_site_find_chain_2 (gdbarch
, resultp
, chain
,
996 addr_hash
, target_call_site
,
1000 size_t removed
= addr_hash
.erase (target_call_site
->pc ());
1001 gdb_assert (removed
== 1);
1010 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All
1011 the assumed frames between them use GDBARCH. Any unreliability
1012 results in thrown NO_ENTRY_VALUE_ERROR. */
1014 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1015 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1016 CORE_ADDR callee_pc
)
1018 CORE_ADDR save_callee_pc
= callee_pc
;
1019 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1020 struct call_site
*call_site
;
1022 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1023 call_site nor any possible call_site at CALLEE_PC's function is there.
1024 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1025 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1026 std::vector
<struct call_site
*> chain
;
1028 /* A given call site may have multiple associated addresses. This
1029 can happen if, e.g., the caller is split by hot/cold
1030 partitioning. This vector tracks the ones we haven't visited
1032 std::vector
<std::vector
<CORE_ADDR
>> unvisited_addresses
;
1034 /* We are not interested in the specific PC inside the callee function. */
1035 callee_pc
= get_pc_function_start (callee_pc
);
1037 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1038 paddress (gdbarch
, save_callee_pc
));
1040 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1041 std::unordered_set
<CORE_ADDR
> addr_hash
;
1043 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1044 at the target's function. All the possible tail call sites in the
1045 target's function will get iterated as already pushed into CHAIN via their
1047 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1048 /* No need to check the return value here, because we no longer care
1049 about possible early returns. */
1050 call_site_find_chain_2 (gdbarch
, &retval
, chain
, addr_hash
, call_site
,
1055 struct bound_minimal_symbol msym_caller
, msym_callee
;
1057 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1058 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1059 throw_error (NO_ENTRY_VALUE_ERROR
,
1060 _("There are no unambiguously determinable intermediate "
1061 "callers or callees between caller function \"%s\" at %s "
1062 "and callee function \"%s\" at %s"),
1063 (msym_caller
.minsym
== NULL
1064 ? "???" : msym_caller
.minsym
->print_name ()),
1065 paddress (gdbarch
, caller_pc
),
1066 (msym_callee
.minsym
== NULL
1067 ? "???" : msym_callee
.minsym
->print_name ()),
1068 paddress (gdbarch
, callee_pc
));
1074 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1075 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1076 constructed return NULL. */
1078 gdb::unique_xmalloc_ptr
<call_site_chain
>
1079 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1080 CORE_ADDR callee_pc
)
1082 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1086 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1088 catch (const gdb_exception_error
&e
)
1090 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1092 if (entry_values_debug
)
1093 exception_print (gdb_stdout
, e
);
1104 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1107 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1108 enum call_site_parameter_kind kind
,
1109 union call_site_parameter_u kind_u
)
1111 if (kind
== parameter
->kind
)
1114 case CALL_SITE_PARAMETER_DWARF_REG
:
1115 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1117 case CALL_SITE_PARAMETER_FB_OFFSET
:
1118 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1120 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1121 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1128 struct call_site_parameter
*
1129 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1130 enum call_site_parameter_kind kind
,
1131 union call_site_parameter_u kind_u
,
1132 dwarf2_per_cu_data
**per_cu_return
,
1133 dwarf2_per_objfile
**per_objfile_return
)
1135 CORE_ADDR func_addr
, caller_pc
;
1136 struct gdbarch
*gdbarch
;
1137 struct frame_info
*caller_frame
;
1138 struct call_site
*call_site
;
1140 /* Initialize it just to avoid a GCC false warning. */
1141 struct call_site_parameter
*parameter
= NULL
;
1142 CORE_ADDR target_addr
;
1144 while (get_frame_type (frame
) == INLINE_FRAME
)
1146 frame
= get_prev_frame (frame
);
1147 gdb_assert (frame
!= NULL
);
1150 func_addr
= get_frame_func (frame
);
1151 gdbarch
= get_frame_arch (frame
);
1152 caller_frame
= get_prev_frame (frame
);
1153 if (gdbarch
!= frame_unwind_arch (frame
))
1155 struct bound_minimal_symbol msym
1156 = lookup_minimal_symbol_by_pc (func_addr
);
1157 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1159 throw_error (NO_ENTRY_VALUE_ERROR
,
1160 _("DW_OP_entry_value resolving callee gdbarch %s "
1161 "(of %s (%s)) does not match caller gdbarch %s"),
1162 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1163 paddress (gdbarch
, func_addr
),
1164 (msym
.minsym
== NULL
? "???"
1165 : msym
.minsym
->print_name ()),
1166 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1169 if (caller_frame
== NULL
)
1171 struct bound_minimal_symbol msym
1172 = lookup_minimal_symbol_by_pc (func_addr
);
1174 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1175 "requires caller of %s (%s)"),
1176 paddress (gdbarch
, func_addr
),
1177 (msym
.minsym
== NULL
? "???"
1178 : msym
.minsym
->print_name ()));
1180 caller_pc
= get_frame_pc (caller_frame
);
1181 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1185 call_site
->iterate_over_addresses (gdbarch
, caller_frame
,
1186 [&] (CORE_ADDR addr
)
1188 /* Preserve any address. */
1191 if (addr
== func_addr
)
1196 struct minimal_symbol
*target_msym
, *func_msym
;
1198 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1199 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1200 throw_error (NO_ENTRY_VALUE_ERROR
,
1201 _("DW_OP_entry_value resolving expects callee %s at %s %s"
1202 "but the called frame is for %s at %s"),
1203 (target_msym
== NULL
? "???"
1204 : target_msym
->print_name ()),
1205 paddress (gdbarch
, target_addr
),
1207 ? _("(but note there are multiple addresses not listed)")
1209 func_msym
== NULL
? "???" : func_msym
->print_name (),
1210 paddress (gdbarch
, func_addr
));
1213 /* No entry value based parameters would be reliable if this function can
1214 call itself via tail calls. */
1215 func_verify_no_selftailcall (gdbarch
, func_addr
);
1217 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1219 parameter
= &call_site
->parameter
[iparams
];
1220 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1223 if (iparams
== call_site
->parameter_count
)
1225 struct minimal_symbol
*msym
1226 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1228 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1229 determine its value. */
1230 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1231 "at DW_TAG_call_site %s at %s"),
1232 paddress (gdbarch
, caller_pc
),
1233 msym
== NULL
? "???" : msym
->print_name ());
1236 *per_cu_return
= call_site
->per_cu
;
1237 *per_objfile_return
= call_site
->per_objfile
;
1241 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1242 the normal DW_AT_call_value block. Otherwise return the
1243 DW_AT_call_data_value (dereferenced) block.
1245 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1248 Function always returns non-NULL, non-optimized out value. It throws
1249 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1251 static struct value
*
1252 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1253 CORE_ADDR deref_size
, struct type
*type
,
1254 struct frame_info
*caller_frame
,
1255 dwarf2_per_cu_data
*per_cu
,
1256 dwarf2_per_objfile
*per_objfile
)
1258 const gdb_byte
*data_src
;
1261 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1262 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1264 /* DEREF_SIZE size is not verified here. */
1265 if (data_src
== NULL
)
1266 throw_error (NO_ENTRY_VALUE_ERROR
,
1267 _("Cannot resolve DW_AT_call_data_value"));
1269 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1270 per_objfile
, false);
1273 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1274 the indirect method on it, that is use its stored target value, the sole
1275 purpose of entry_data_value_funcs.. */
1277 static struct value
*
1278 entry_data_value_coerce_ref (const struct value
*value
)
1280 struct type
*checked_type
= check_typedef (value_type (value
));
1281 struct value
*target_val
;
1283 if (!TYPE_IS_REFERENCE (checked_type
))
1286 target_val
= (struct value
*) value_computed_closure (value
);
1287 value_incref (target_val
);
1291 /* Implement copy_closure. */
1294 entry_data_value_copy_closure (const struct value
*v
)
1296 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1298 value_incref (target_val
);
1302 /* Implement free_closure. */
1305 entry_data_value_free_closure (struct value
*v
)
1307 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1309 value_decref (target_val
);
1312 /* Vector for methods for an entry value reference where the referenced value
1313 is stored in the caller. On the first dereference use
1314 DW_AT_call_data_value in the caller. */
1316 static const struct lval_funcs entry_data_value_funcs
=
1321 NULL
, /* indirect */
1322 entry_data_value_coerce_ref
,
1323 NULL
, /* check_synthetic_pointer */
1324 entry_data_value_copy_closure
,
1325 entry_data_value_free_closure
1328 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1329 are used to match DW_AT_location at the caller's
1330 DW_TAG_call_site_parameter.
1332 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1333 cannot resolve the parameter for any reason. */
1335 static struct value
*
1336 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1337 enum call_site_parameter_kind kind
,
1338 union call_site_parameter_u kind_u
)
1340 struct type
*checked_type
= check_typedef (type
);
1341 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1342 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1343 struct value
*outer_val
, *target_val
, *val
;
1344 struct call_site_parameter
*parameter
;
1345 dwarf2_per_cu_data
*caller_per_cu
;
1346 dwarf2_per_objfile
*caller_per_objfile
;
1348 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1350 &caller_per_objfile
);
1352 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1355 caller_per_objfile
);
1357 /* Check if DW_AT_call_data_value cannot be used. If it should be
1358 used and it is not available do not fall back to OUTER_VAL - dereferencing
1359 TYPE_CODE_REF with non-entry data value would give current value - not the
1362 if (!TYPE_IS_REFERENCE (checked_type
)
1363 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1366 target_val
= dwarf_entry_parameter_to_value (parameter
,
1367 TYPE_LENGTH (target_type
),
1368 target_type
, caller_frame
,
1370 caller_per_objfile
);
1372 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1373 release_value (target_val
).release ());
1375 /* Copy the referencing pointer to the new computed value. */
1376 memcpy (value_contents_raw (val
).data (),
1377 value_contents_raw (outer_val
).data (),
1378 TYPE_LENGTH (checked_type
));
1379 set_value_lazy (val
, 0);
1384 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1385 SIZE are DWARF block used to match DW_AT_location at the caller's
1386 DW_TAG_call_site_parameter.
1388 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1389 cannot resolve the parameter for any reason. */
1391 static struct value
*
1392 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1393 const gdb_byte
*block
, size_t block_len
)
1395 union call_site_parameter_u kind_u
;
1397 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1398 if (kind_u
.dwarf_reg
!= -1)
1399 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1402 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1403 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1406 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1407 suppressed during normal operation. The expression can be arbitrary if
1408 there is no caller-callee entry value binding expected. */
1409 throw_error (NO_ENTRY_VALUE_ERROR
,
1410 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1411 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1414 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1416 static struct value
*
1417 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1418 dwarf2_per_cu_data
*per_cu
,
1419 dwarf2_per_objfile
*per_objfile
,
1422 struct value
*result
= NULL
;
1423 const gdb_byte
*bytes
;
1426 auto_obstack temp_obstack
;
1427 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1428 &temp_obstack
, &len
);
1432 if (byte_offset
>= 0
1433 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1435 bytes
+= byte_offset
;
1436 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1439 invalid_synthetic_pointer ();
1442 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1450 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1451 dwarf2_per_cu_data
*per_cu
,
1452 dwarf2_per_objfile
*per_objfile
,
1453 struct frame_info
*frame
, struct type
*type
,
1454 bool resolve_abstract_p
)
1456 /* Fetch the location expression of the DIE we're pointing to. */
1457 auto get_frame_address_in_block_wrapper
= [frame
] ()
1459 return get_frame_address_in_block (frame
);
1461 struct dwarf2_locexpr_baton baton
1462 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1463 get_frame_address_in_block_wrapper
,
1464 resolve_abstract_p
);
1466 /* Get type of pointed-to DIE. */
1467 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1469 if (orig_type
== NULL
)
1470 invalid_synthetic_pointer ();
1472 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1473 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1474 or it may've been optimized out. */
1475 if (baton
.data
!= NULL
)
1476 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1477 baton
.size
, baton
.per_cu
,
1479 TYPE_TARGET_TYPE (type
),
1482 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1486 /* Evaluate a location description, starting at DATA and with length
1487 SIZE, to find the current location of variable of TYPE in the
1488 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1489 location of the subobject of type SUBOBJ_TYPE at byte offset
1490 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1492 static struct value
*
1493 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1494 const gdb_byte
*data
, size_t size
,
1495 dwarf2_per_cu_data
*per_cu
,
1496 dwarf2_per_objfile
*per_objfile
,
1497 struct type
*subobj_type
,
1498 LONGEST subobj_byte_offset
,
1501 if (subobj_type
== NULL
)
1504 subobj_byte_offset
= 0;
1506 else if (subobj_byte_offset
< 0)
1507 invalid_synthetic_pointer ();
1510 return allocate_optimized_out_value (subobj_type
);
1512 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1515 scoped_value_mark free_values
;
1519 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1520 type
, subobj_type
, subobj_byte_offset
);
1522 catch (const gdb_exception_error
&ex
)
1524 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1526 free_values
.free_to_mark ();
1527 retval
= allocate_value (subobj_type
);
1528 mark_value_bytes_unavailable (retval
, 0,
1529 TYPE_LENGTH (subobj_type
));
1532 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1534 if (entry_values_debug
)
1535 exception_print (gdb_stdout
, ex
);
1536 free_values
.free_to_mark ();
1537 return allocate_optimized_out_value (subobj_type
);
1543 /* We need to clean up all the values that are not needed any more.
1544 The problem with a value_ref_ptr class is that it disconnects the
1545 RETVAL from the value garbage collection, so we need to make
1546 a copy of that value on the stack to keep everything consistent.
1547 The value_ref_ptr will clean up after itself at the end of this block. */
1548 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1549 free_values
.free_to_mark ();
1551 return value_copy (retval
);
1554 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1555 passes 0 as the byte_offset. */
1558 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1559 const gdb_byte
*data
, size_t size
,
1560 dwarf2_per_cu_data
*per_cu
,
1561 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1563 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1564 per_objfile
, NULL
, 0, as_lval
);
1567 /* Evaluates a dwarf expression and stores the result in VAL,
1568 expecting that the dwarf expression only produces a single
1569 CORE_ADDR. FRAME is the frame in which the expression is
1570 evaluated. ADDR_STACK is a context (location of a variable) and
1571 might be needed to evaluate the location expression.
1573 PUSH_VALUES is an array of values to be pushed to the expression stack
1574 before evaluation starts. PUSH_VALUES[0] is pushed first, then
1575 PUSH_VALUES[1], and so on.
1577 Returns 1 on success, 0 otherwise. */
1580 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1581 struct frame_info
*frame
,
1582 const struct property_addr_info
*addr_stack
,
1584 gdb::array_view
<CORE_ADDR
> push_values
,
1587 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1590 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1591 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1592 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1595 scoped_value_mark free_values
;
1597 /* Place any initial values onto the expression stack. */
1598 for (const auto &val
: push_values
)
1599 ctx
.push_address (val
, false);
1603 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1604 true, per_cu
, frame
, addr_stack
);
1606 catch (const gdb_exception_error
&ex
)
1608 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1612 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1614 if (entry_values_debug
)
1615 exception_print (gdb_stdout
, ex
);
1622 if (value_optimized_out (result
))
1625 if (VALUE_LVAL (result
) == lval_memory
)
1626 *valp
= value_address (result
);
1629 if (VALUE_LVAL (result
) == not_lval
)
1630 *is_reference
= false;
1632 *valp
= value_as_address (result
);
1638 /* See dwarf2/loc.h. */
1641 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1642 struct frame_info
*frame
,
1643 const struct property_addr_info
*addr_stack
,
1645 gdb::array_view
<CORE_ADDR
> push_values
)
1650 if (frame
== NULL
&& has_stack_frames ())
1651 frame
= get_selected_frame (NULL
);
1653 switch (prop
->kind ())
1657 const struct dwarf2_property_baton
*baton
1658 = (const struct dwarf2_property_baton
*) prop
->baton ();
1659 gdb_assert (baton
->property_type
!= NULL
);
1661 bool is_reference
= baton
->locexpr
.is_reference
;
1662 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1663 value
, push_values
, &is_reference
))
1667 struct value
*val
= value_at (baton
->property_type
, *value
);
1668 *value
= value_as_address (val
);
1672 gdb_assert (baton
->property_type
!= NULL
);
1674 struct type
*type
= check_typedef (baton
->property_type
);
1675 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
1676 && !type
->is_unsigned ())
1678 /* If we have a valid return candidate and it's value
1679 is signed, we have to sign-extend the value because
1680 CORE_ADDR on 64bit machine has 8 bytes but address
1681 size of an 32bit application is bytes. */
1683 = (baton
->locexpr
.per_cu
->addr_size ()
1685 const CORE_ADDR neg_mask
1686 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1688 /* Check if signed bit is set and sign-extend values. */
1689 if (*value
& neg_mask
)
1700 struct dwarf2_property_baton
*baton
1701 = (struct dwarf2_property_baton
*) prop
->baton ();
1703 const gdb_byte
*data
;
1708 || !get_frame_address_in_block_if_available (frame
, &pc
))
1711 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1714 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1715 size
, baton
->loclist
.per_cu
,
1716 baton
->loclist
.per_objfile
);
1717 if (!value_optimized_out (val
))
1719 *value
= value_as_address (val
);
1727 *value
= prop
->const_val ();
1730 case PROP_ADDR_OFFSET
:
1732 struct dwarf2_property_baton
*baton
1733 = (struct dwarf2_property_baton
*) prop
->baton ();
1734 const struct property_addr_info
*pinfo
;
1737 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1739 /* This approach lets us avoid checking the qualifiers. */
1740 if (TYPE_MAIN_TYPE (pinfo
->type
)
1741 == TYPE_MAIN_TYPE (baton
->property_type
))
1745 error (_("cannot find reference address for offset property"));
1746 if (pinfo
->valaddr
.data () != NULL
)
1747 val
= value_from_contents
1748 (baton
->offset_info
.type
,
1749 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1751 val
= value_at (baton
->offset_info
.type
,
1752 pinfo
->addr
+ baton
->offset_info
.offset
);
1753 *value
= value_as_address (val
);
1757 case PROP_VARIABLE_NAME
:
1759 struct value
*val
= compute_var_value (prop
->variable_name ());
1762 *value
= value_as_long (val
);
1772 /* See dwarf2/loc.h. */
1775 dwarf2_compile_property_to_c (string_file
*stream
,
1776 const char *result_name
,
1777 struct gdbarch
*gdbarch
,
1778 std::vector
<bool> ®isters_used
,
1779 const struct dynamic_prop
*prop
,
1783 struct dwarf2_property_baton
*baton
1784 = (struct dwarf2_property_baton
*) prop
->baton ();
1785 const gdb_byte
*data
;
1787 dwarf2_per_cu_data
*per_cu
;
1788 dwarf2_per_objfile
*per_objfile
;
1790 if (prop
->kind () == PROP_LOCEXPR
)
1792 data
= baton
->locexpr
.data
;
1793 size
= baton
->locexpr
.size
;
1794 per_cu
= baton
->locexpr
.per_cu
;
1795 per_objfile
= baton
->locexpr
.per_objfile
;
1799 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1801 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1802 per_cu
= baton
->loclist
.per_cu
;
1803 per_objfile
= baton
->loclist
.per_objfile
;
1806 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1807 gdbarch
, registers_used
,
1808 per_cu
->addr_size (),
1809 data
, data
+ size
, per_cu
, per_objfile
);
1812 /* Compute the correct symbol_needs_kind value for the location
1815 Implemented by traversing the logical control flow graph of the
1818 static enum symbol_needs_kind
1819 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1820 dwarf2_per_cu_data
*per_cu
,
1821 dwarf2_per_objfile
*per_objfile
,
1822 bfd_endian byte_order
,
1827 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1829 /* If the expression is empty, we have nothing to do. */
1831 return symbol_needs
;
1833 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1835 /* List of operations to visit. Operations in this list are not visited yet,
1836 so are not in VISITED_OPS (and vice-versa). */
1837 std::vector
<const gdb_byte
*> ops_to_visit
;
1839 /* Operations already visited. */
1840 std::unordered_set
<const gdb_byte
*> visited_ops
;
1842 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1843 hasn't been visited yet. */
1844 auto insert_in_ops_to_visit
1845 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1847 if (op_ptr
>= expr_end
)
1850 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1853 ops_to_visit
.push_back (op_ptr
);
1856 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1858 const int max_depth
= 256;
1860 if (depth
> max_depth
)
1861 error (_("DWARF-2 expression error: Loop detected."));
1865 /* Initialize the to-visit list with the first operation. */
1866 insert_in_ops_to_visit (&expr
[0]);
1868 while (!ops_to_visit
.empty ())
1870 /* Pop one op to visit, mark it as visited. */
1871 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1872 ops_to_visit
.pop_back ();
1873 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1874 visited_ops
.insert (op_ptr
);
1876 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1878 /* Most operations have a single possible following operation
1879 (they are not conditional branches). The code below updates
1880 OP_PTR to point to that following operation, which is pushed
1881 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1882 OP_PTR pointing just after the operand. */
1885 /* The DWARF expression might have a bug causing an infinite
1886 loop. In that case, quitting is the only way out. */
1923 case DW_OP_stack_value
:
1950 case DW_OP_GNU_push_tls_address
:
1952 case DW_OP_GNU_uninit
:
1953 case DW_OP_push_object_address
:
1956 case DW_OP_form_tls_address
:
1957 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1958 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1962 case DW_OP_GNU_convert
:
1963 case DW_OP_reinterpret
:
1964 case DW_OP_GNU_reinterpret
:
1966 case DW_OP_GNU_addr_index
:
1967 case DW_OP_GNU_const_index
:
1969 case DW_OP_plus_uconst
:
1971 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1975 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1978 case DW_OP_bit_piece
:
1979 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1980 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1983 case DW_OP_deref_type
:
1984 case DW_OP_GNU_deref_type
:
1986 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1990 op_ptr
+= addr_size
;
2080 case DW_OP_call_frame_cfa
:
2081 case DW_OP_entry_value
:
2082 case DW_OP_GNU_entry_value
:
2083 case DW_OP_GNU_parameter_ref
:
2084 case DW_OP_regval_type
:
2085 case DW_OP_GNU_regval_type
:
2086 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2089 case DW_OP_implicit_value
:
2092 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2097 case DW_OP_implicit_pointer
:
2098 case DW_OP_GNU_implicit_pointer
:
2099 op_ptr
+= ref_addr_size
;
2100 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2103 case DW_OP_deref_size
:
2110 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2118 /* This is the only operation that pushes two operations in
2119 the to-visit list, so handle it all here. */
2120 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2123 insert_in_ops_to_visit (op_ptr
+ offset
);
2124 insert_in_ops_to_visit (op_ptr
);
2131 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2133 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2136 auto get_frame_pc
= [&symbol_needs
] ()
2138 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2142 struct dwarf2_locexpr_baton baton
2143 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2147 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2148 we dont have to check the baton content. */
2149 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2151 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2152 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2155 = dwarf2_get_symbol_read_needs (sub_expr
,
2158 gdbarch_byte_order (arch
),
2159 baton
.per_cu
->addr_size (),
2160 baton
.per_cu
->ref_addr_size (),
2166 case DW_OP_GNU_variable_value
:
2168 sect_offset sect_off
2169 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2172 op_ptr
+= ref_addr_size
;
2174 struct type
*die_type
2175 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2178 if (die_type
== NULL
)
2179 error (_("Bad DW_OP_GNU_variable_value DIE."));
2181 /* Note: Things still work when the following test is
2182 removed. This test and error is here to conform to the
2183 proposed specification. */
2184 if (die_type
->code () != TYPE_CODE_INT
2185 && die_type
->code () != TYPE_CODE_PTR
)
2186 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2187 "an integer or pointer."));
2189 auto get_frame_pc
= [&symbol_needs
] ()
2191 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2195 struct dwarf2_locexpr_baton baton
2196 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2198 get_frame_pc
, true);
2200 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2201 we dont have to check the baton content. */
2202 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2204 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2205 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2208 = dwarf2_get_symbol_read_needs (sub_expr
,
2211 gdbarch_byte_order (arch
),
2212 baton
.per_cu
->addr_size (),
2213 baton
.per_cu
->ref_addr_size (),
2219 case DW_OP_const_type
:
2220 case DW_OP_GNU_const_type
:
2223 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2224 gdb_byte offset
= *op_ptr
++;
2230 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2233 /* If it is known that a frame information is
2234 needed we can stop parsing the expression. */
2235 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2238 insert_in_ops_to_visit (op_ptr
);
2241 return symbol_needs
;
2244 /* A helper function that throws an unimplemented error mentioning a
2245 given DWARF operator. */
2247 static void ATTRIBUTE_NORETURN
2248 unimplemented (unsigned int op
)
2250 const char *name
= get_DW_OP_name (op
);
2253 error (_("DWARF operator %s cannot be translated to an agent expression"),
2256 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2257 "to an agent expression"),
2261 /* See dwarf2/loc.h.
2263 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2264 can issue a complaint, which is better than having every target's
2265 implementation of dwarf2_reg_to_regnum do it. */
2268 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2270 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2274 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2279 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2280 Throw an error because DWARF_REG is bad. */
2283 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2285 /* Still want to print -1 as "-1".
2286 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2287 but that's overkill for now. */
2288 if ((int) dwarf_reg
== dwarf_reg
)
2289 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2290 error (_("Unable to access DWARF register number %s"),
2291 pulongest (dwarf_reg
));
2294 /* See dwarf2/loc.h. */
2297 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2301 if (dwarf_reg
> INT_MAX
)
2302 throw_bad_regnum_error (dwarf_reg
);
2303 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2304 bad, but that's ok. */
2305 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2307 throw_bad_regnum_error (dwarf_reg
);
2311 /* A helper function that emits an access to memory. ARCH is the
2312 target architecture. EXPR is the expression which we are building.
2313 NBITS is the number of bits we want to read. This emits the
2314 opcodes needed to read the memory and then extract the desired
2318 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2320 ULONGEST nbytes
= (nbits
+ 7) / 8;
2322 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2325 ax_trace_quick (expr
, nbytes
);
2328 ax_simple (expr
, aop_ref8
);
2329 else if (nbits
<= 16)
2330 ax_simple (expr
, aop_ref16
);
2331 else if (nbits
<= 32)
2332 ax_simple (expr
, aop_ref32
);
2334 ax_simple (expr
, aop_ref64
);
2336 /* If we read exactly the number of bytes we wanted, we're done. */
2337 if (8 * nbytes
== nbits
)
2340 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2342 /* On a bits-big-endian machine, we want the high-order
2344 ax_const_l (expr
, 8 * nbytes
- nbits
);
2345 ax_simple (expr
, aop_rsh_unsigned
);
2349 /* On a bits-little-endian box, we want the low-order NBITS. */
2350 ax_zero_ext (expr
, nbits
);
2354 /* Compile a DWARF location expression to an agent expression.
2356 EXPR is the agent expression we are building.
2357 LOC is the agent value we modify.
2358 ARCH is the architecture.
2359 ADDR_SIZE is the size of addresses, in bytes.
2360 OP_PTR is the start of the location expression.
2361 OP_END is one past the last byte of the location expression.
2363 This will throw an exception for various kinds of errors -- for
2364 example, if the expression cannot be compiled, or if the expression
2368 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2369 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2370 const gdb_byte
*op_end
,
2371 dwarf2_per_cu_data
*per_cu
,
2372 dwarf2_per_objfile
*per_objfile
)
2374 gdbarch
*arch
= expr
->gdbarch
;
2375 std::vector
<int> dw_labels
, patches
;
2376 const gdb_byte
* const base
= op_ptr
;
2377 const gdb_byte
*previous_piece
= op_ptr
;
2378 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2379 ULONGEST bits_collected
= 0;
2380 unsigned int addr_size_bits
= 8 * addr_size
;
2381 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2383 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2385 /* By default we are making an address. */
2386 loc
->kind
= axs_lvalue_memory
;
2388 while (op_ptr
< op_end
)
2390 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2391 uint64_t uoffset
, reg
;
2395 offsets
[op_ptr
- base
] = expr
->len
;
2398 /* Our basic approach to code generation is to map DWARF
2399 operations directly to AX operations. However, there are
2402 First, DWARF works on address-sized units, but AX always uses
2403 LONGEST. For most operations we simply ignore this
2404 difference; instead we generate sign extensions as needed
2405 before division and comparison operations. It would be nice
2406 to omit the sign extensions, but there is no way to determine
2407 the size of the target's LONGEST. (This code uses the size
2408 of the host LONGEST in some cases -- that is a bug but it is
2411 Second, some DWARF operations cannot be translated to AX.
2412 For these we simply fail. See
2413 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2448 ax_const_l (expr
, op
- DW_OP_lit0
);
2452 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2453 op_ptr
+= addr_size
;
2454 /* Some versions of GCC emit DW_OP_addr before
2455 DW_OP_GNU_push_tls_address. In this case the value is an
2456 index, not an address. We don't support things like
2457 branching between the address and the TLS op. */
2458 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2459 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2460 ax_const_l (expr
, uoffset
);
2464 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2469 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2474 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2479 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2484 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2489 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2494 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2499 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2504 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2505 ax_const_l (expr
, uoffset
);
2509 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2510 ax_const_l (expr
, offset
);
2545 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2546 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2547 loc
->kind
= axs_lvalue_register
;
2551 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2552 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2553 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2554 loc
->kind
= axs_lvalue_register
;
2557 case DW_OP_implicit_value
:
2561 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2562 if (op_ptr
+ len
> op_end
)
2563 error (_("DW_OP_implicit_value: too few bytes available."));
2564 if (len
> sizeof (ULONGEST
))
2565 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2568 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2571 dwarf_expr_require_composition (op_ptr
, op_end
,
2572 "DW_OP_implicit_value");
2574 loc
->kind
= axs_rvalue
;
2578 case DW_OP_stack_value
:
2579 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2580 loc
->kind
= axs_rvalue
;
2615 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2616 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2620 ax_const_l (expr
, offset
);
2621 ax_simple (expr
, aop_add
);
2627 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2628 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2629 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2633 ax_const_l (expr
, offset
);
2634 ax_simple (expr
, aop_add
);
2641 const gdb_byte
*datastart
;
2643 const struct block
*b
;
2644 struct symbol
*framefunc
;
2646 b
= block_for_pc (expr
->scope
);
2649 error (_("No block found for address"));
2651 framefunc
= block_linkage_function (b
);
2654 error (_("No function found for block"));
2656 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2657 &datastart
, &datalen
);
2659 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2660 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2661 datastart
+ datalen
, per_cu
,
2663 if (loc
->kind
== axs_lvalue_register
)
2664 require_rvalue (expr
, loc
);
2668 ax_const_l (expr
, offset
);
2669 ax_simple (expr
, aop_add
);
2672 loc
->kind
= axs_lvalue_memory
;
2677 ax_simple (expr
, aop_dup
);
2681 ax_simple (expr
, aop_pop
);
2686 ax_pick (expr
, offset
);
2690 ax_simple (expr
, aop_swap
);
2698 ax_simple (expr
, aop_rot
);
2702 case DW_OP_deref_size
:
2706 if (op
== DW_OP_deref_size
)
2711 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2712 error (_("Unsupported size %d in %s"),
2713 size
, get_DW_OP_name (op
));
2714 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2719 /* Sign extend the operand. */
2720 ax_ext (expr
, addr_size_bits
);
2721 ax_simple (expr
, aop_dup
);
2722 ax_const_l (expr
, 0);
2723 ax_simple (expr
, aop_less_signed
);
2724 ax_simple (expr
, aop_log_not
);
2725 i
= ax_goto (expr
, aop_if_goto
);
2726 /* We have to emit 0 - X. */
2727 ax_const_l (expr
, 0);
2728 ax_simple (expr
, aop_swap
);
2729 ax_simple (expr
, aop_sub
);
2730 ax_label (expr
, i
, expr
->len
);
2734 /* No need to sign extend here. */
2735 ax_const_l (expr
, 0);
2736 ax_simple (expr
, aop_swap
);
2737 ax_simple (expr
, aop_sub
);
2741 /* Sign extend the operand. */
2742 ax_ext (expr
, addr_size_bits
);
2743 ax_simple (expr
, aop_bit_not
);
2746 case DW_OP_plus_uconst
:
2747 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2748 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2749 but we micro-optimize anyhow. */
2752 ax_const_l (expr
, reg
);
2753 ax_simple (expr
, aop_add
);
2758 ax_simple (expr
, aop_bit_and
);
2762 /* Sign extend the operands. */
2763 ax_ext (expr
, addr_size_bits
);
2764 ax_simple (expr
, aop_swap
);
2765 ax_ext (expr
, addr_size_bits
);
2766 ax_simple (expr
, aop_swap
);
2767 ax_simple (expr
, aop_div_signed
);
2771 ax_simple (expr
, aop_sub
);
2775 ax_simple (expr
, aop_rem_unsigned
);
2779 ax_simple (expr
, aop_mul
);
2783 ax_simple (expr
, aop_bit_or
);
2787 ax_simple (expr
, aop_add
);
2791 ax_simple (expr
, aop_lsh
);
2795 ax_simple (expr
, aop_rsh_unsigned
);
2799 ax_simple (expr
, aop_rsh_signed
);
2803 ax_simple (expr
, aop_bit_xor
);
2807 /* Sign extend the operands. */
2808 ax_ext (expr
, addr_size_bits
);
2809 ax_simple (expr
, aop_swap
);
2810 ax_ext (expr
, addr_size_bits
);
2811 /* Note no swap here: A <= B is !(B < A). */
2812 ax_simple (expr
, aop_less_signed
);
2813 ax_simple (expr
, aop_log_not
);
2817 /* Sign extend the operands. */
2818 ax_ext (expr
, addr_size_bits
);
2819 ax_simple (expr
, aop_swap
);
2820 ax_ext (expr
, addr_size_bits
);
2821 ax_simple (expr
, aop_swap
);
2822 /* A >= B is !(A < B). */
2823 ax_simple (expr
, aop_less_signed
);
2824 ax_simple (expr
, aop_log_not
);
2828 /* Sign extend the operands. */
2829 ax_ext (expr
, addr_size_bits
);
2830 ax_simple (expr
, aop_swap
);
2831 ax_ext (expr
, addr_size_bits
);
2832 /* No need for a second swap here. */
2833 ax_simple (expr
, aop_equal
);
2837 /* Sign extend the operands. */
2838 ax_ext (expr
, addr_size_bits
);
2839 ax_simple (expr
, aop_swap
);
2840 ax_ext (expr
, addr_size_bits
);
2841 ax_simple (expr
, aop_swap
);
2842 ax_simple (expr
, aop_less_signed
);
2846 /* Sign extend the operands. */
2847 ax_ext (expr
, addr_size_bits
);
2848 ax_simple (expr
, aop_swap
);
2849 ax_ext (expr
, addr_size_bits
);
2850 /* Note no swap here: A > B is B < A. */
2851 ax_simple (expr
, aop_less_signed
);
2855 /* Sign extend the operands. */
2856 ax_ext (expr
, addr_size_bits
);
2857 ax_simple (expr
, aop_swap
);
2858 ax_ext (expr
, addr_size_bits
);
2859 /* No need for a swap here. */
2860 ax_simple (expr
, aop_equal
);
2861 ax_simple (expr
, aop_log_not
);
2864 case DW_OP_call_frame_cfa
:
2867 CORE_ADDR text_offset
;
2869 const gdb_byte
*cfa_start
, *cfa_end
;
2871 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2873 &text_offset
, &cfa_start
, &cfa_end
))
2876 ax_reg (expr
, regnum
);
2879 ax_const_l (expr
, off
);
2880 ax_simple (expr
, aop_add
);
2885 /* Another expression. */
2886 ax_const_l (expr
, text_offset
);
2887 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2888 cfa_end
, per_cu
, per_objfile
);
2891 loc
->kind
= axs_lvalue_memory
;
2895 case DW_OP_GNU_push_tls_address
:
2896 case DW_OP_form_tls_address
:
2900 case DW_OP_push_object_address
:
2905 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2907 i
= ax_goto (expr
, aop_goto
);
2908 dw_labels
.push_back (op_ptr
+ offset
- base
);
2909 patches
.push_back (i
);
2913 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2915 /* Zero extend the operand. */
2916 ax_zero_ext (expr
, addr_size_bits
);
2917 i
= ax_goto (expr
, aop_if_goto
);
2918 dw_labels
.push_back (op_ptr
+ offset
- base
);
2919 patches
.push_back (i
);
2926 case DW_OP_bit_piece
:
2930 if (op_ptr
- 1 == previous_piece
)
2931 error (_("Cannot translate empty pieces to agent expressions"));
2932 previous_piece
= op_ptr
- 1;
2934 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2935 if (op
== DW_OP_piece
)
2941 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2943 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2944 error (_("Expression pieces exceed word size"));
2946 /* Access the bits. */
2949 case axs_lvalue_register
:
2950 ax_reg (expr
, loc
->u
.reg
);
2953 case axs_lvalue_memory
:
2954 /* Offset the pointer, if needed. */
2957 ax_const_l (expr
, uoffset
/ 8);
2958 ax_simple (expr
, aop_add
);
2961 access_memory (arch
, expr
, size
);
2965 /* For a bits-big-endian target, shift up what we already
2966 have. For a bits-little-endian target, shift up the
2967 new data. Note that there is a potential bug here if
2968 the DWARF expression leaves multiple values on the
2970 if (bits_collected
> 0)
2972 if (bits_big_endian
)
2974 ax_simple (expr
, aop_swap
);
2975 ax_const_l (expr
, size
);
2976 ax_simple (expr
, aop_lsh
);
2977 /* We don't need a second swap here, because
2978 aop_bit_or is symmetric. */
2982 ax_const_l (expr
, size
);
2983 ax_simple (expr
, aop_lsh
);
2985 ax_simple (expr
, aop_bit_or
);
2988 bits_collected
+= size
;
2989 loc
->kind
= axs_rvalue
;
2993 case DW_OP_GNU_uninit
:
2999 struct dwarf2_locexpr_baton block
;
3000 int size
= (op
== DW_OP_call2
? 2 : 4);
3002 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3005 auto get_frame_pc_from_expr
= [expr
] ()
3009 cu_offset cuoffset
= (cu_offset
) uoffset
;
3010 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3011 get_frame_pc_from_expr
);
3013 /* DW_OP_call_ref is currently not supported. */
3014 gdb_assert (block
.per_cu
== per_cu
);
3016 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3017 block
.data
+ block
.size
, per_cu
,
3022 case DW_OP_call_ref
:
3025 case DW_OP_GNU_variable_value
:
3033 /* Patch all the branches we emitted. */
3034 for (int i
= 0; i
< patches
.size (); ++i
)
3036 int targ
= offsets
[dw_labels
[i
]];
3038 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3039 ax_label (expr
, patches
[i
], targ
);
3044 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3045 evaluator to calculate the location. */
3046 static struct value
*
3047 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3049 struct dwarf2_locexpr_baton
*dlbaton
3050 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3053 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, dlbaton
->data
,
3054 dlbaton
->size
, dlbaton
->per_cu
,
3055 dlbaton
->per_objfile
);
3060 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3061 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3064 static struct value
*
3065 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3067 struct dwarf2_locexpr_baton
*dlbaton
3068 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3070 return value_of_dwarf_block_entry (symbol
->type (), frame
, dlbaton
->data
,
3074 /* Implementation of get_symbol_read_needs from
3075 symbol_computed_ops. */
3077 static enum symbol_needs_kind
3078 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3080 struct dwarf2_locexpr_baton
*dlbaton
3081 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3083 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3084 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3086 return dwarf2_get_symbol_read_needs (expr
,
3088 dlbaton
->per_objfile
,
3089 gdbarch_byte_order (arch
),
3090 dlbaton
->per_cu
->addr_size (),
3091 dlbaton
->per_cu
->ref_addr_size ());
3094 /* Return true if DATA points to the end of a piece. END is one past
3095 the last byte in the expression. */
3098 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3100 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3103 /* Helper for locexpr_describe_location_piece that finds the name of a
3107 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3111 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3112 We'd rather print *something* here than throw an error. */
3113 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3114 /* gdbarch_register_name may just return "", return something more
3115 descriptive for bad register numbers. */
3118 /* The text is output as "$bad_register_number".
3119 That is why we use the underscores. */
3120 return _("bad_register_number");
3122 return gdbarch_register_name (gdbarch
, regnum
);
3125 /* Nicely describe a single piece of a location, returning an updated
3126 position in the bytecode sequence. This function cannot recognize
3127 all locations; if a location is not recognized, it simply returns
3128 DATA. If there is an error during reading, e.g. we run off the end
3129 of the buffer, an error is thrown. */
3131 static const gdb_byte
*
3132 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3133 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3134 dwarf2_per_objfile
*per_objfile
,
3135 const gdb_byte
*data
, const gdb_byte
*end
,
3136 unsigned int addr_size
)
3138 objfile
*objfile
= per_objfile
->objfile
;
3139 struct gdbarch
*gdbarch
= objfile
->arch ();
3142 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3144 gdb_printf (stream
, _("a variable in $%s"),
3145 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3148 else if (data
[0] == DW_OP_regx
)
3152 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3153 gdb_printf (stream
, _("a variable in $%s"),
3154 locexpr_regname (gdbarch
, reg
));
3156 else if (data
[0] == DW_OP_fbreg
)
3158 const struct block
*b
;
3159 struct symbol
*framefunc
;
3161 int64_t frame_offset
;
3162 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3164 int64_t base_offset
= 0;
3166 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3167 if (!piece_end_p (new_data
, end
))
3171 b
= block_for_pc (addr
);
3174 error (_("No block found for address for symbol \"%s\"."),
3175 symbol
->print_name ());
3177 framefunc
= block_linkage_function (b
);
3180 error (_("No function found for block for symbol \"%s\"."),
3181 symbol
->print_name ());
3183 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3185 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3187 const gdb_byte
*buf_end
;
3189 frame_reg
= base_data
[0] - DW_OP_breg0
;
3190 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3192 if (buf_end
!= base_data
+ base_size
)
3193 error (_("Unexpected opcode after "
3194 "DW_OP_breg%u for symbol \"%s\"."),
3195 frame_reg
, symbol
->print_name ());
3197 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3199 /* The frame base is just the register, with no offset. */
3200 frame_reg
= base_data
[0] - DW_OP_reg0
;
3205 /* We don't know what to do with the frame base expression,
3206 so we can't trace this variable; give up. */
3211 _("a variable at frame base reg $%s offset %s+%s"),
3212 locexpr_regname (gdbarch
, frame_reg
),
3213 plongest (base_offset
), plongest (frame_offset
));
3215 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3216 && piece_end_p (data
, end
))
3220 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3223 _("a variable at offset %s from base reg $%s"),
3225 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3228 /* The location expression for a TLS variable looks like this (on a
3231 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3232 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3234 0x3 is the encoding for DW_OP_addr, which has an operand as long
3235 as the size of an address on the target machine (here is 8
3236 bytes). Note that more recent version of GCC emit DW_OP_const4u
3237 or DW_OP_const8u, depending on address size, rather than
3238 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3239 The operand represents the offset at which the variable is within
3240 the thread local storage. */
3242 else if (data
+ 1 + addr_size
< end
3243 && (data
[0] == DW_OP_addr
3244 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3245 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3246 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3247 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3248 && piece_end_p (data
+ 2 + addr_size
, end
))
3251 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3252 gdbarch_byte_order (gdbarch
));
3255 _("a thread-local variable at offset 0x%s "
3256 "in the thread-local storage for `%s'"),
3257 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3259 data
+= 1 + addr_size
+ 1;
3262 /* With -gsplit-dwarf a TLS variable can also look like this:
3263 DW_AT_location : 3 byte block: fc 4 e0
3264 (DW_OP_GNU_const_index: 4;
3265 DW_OP_GNU_push_tls_address) */
3266 else if (data
+ 3 <= end
3267 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3268 && data
[0] == DW_OP_GNU_const_index
3270 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3271 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3272 && piece_end_p (data
+ 2 + leb128_size
, end
))
3276 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3277 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3279 _("a thread-local variable at offset 0x%s "
3280 "in the thread-local storage for `%s'"),
3281 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3285 else if (data
[0] >= DW_OP_lit0
3286 && data
[0] <= DW_OP_lit31
3288 && data
[1] == DW_OP_stack_value
)
3290 gdb_printf (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3297 /* Disassemble an expression, stopping at the end of a piece or at the
3298 end of the expression. Returns a pointer to the next unread byte
3299 in the input expression. If ALL is nonzero, then this function
3300 will keep going until it reaches the end of the expression.
3301 If there is an error during reading, e.g. we run off the end
3302 of the buffer, an error is thrown. */
3304 static const gdb_byte
*
3305 disassemble_dwarf_expression (struct ui_file
*stream
,
3306 struct gdbarch
*arch
, unsigned int addr_size
,
3307 int offset_size
, const gdb_byte
*start
,
3308 const gdb_byte
*data
, const gdb_byte
*end
,
3309 int indent
, int all
,
3310 dwarf2_per_cu_data
*per_cu
,
3311 dwarf2_per_objfile
*per_objfile
)
3315 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3317 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3322 name
= get_DW_OP_name (op
);
3325 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3326 op
, (long) (data
- 1 - start
));
3327 gdb_printf (stream
, " %*ld: %s", indent
+ 4,
3328 (long) (data
- 1 - start
), name
);
3333 ul
= extract_unsigned_integer (data
, addr_size
,
3334 gdbarch_byte_order (arch
));
3336 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3340 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3342 gdb_printf (stream
, " %s", pulongest (ul
));
3346 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3348 gdb_printf (stream
, " %s", plongest (l
));
3352 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3354 gdb_printf (stream
, " %s", pulongest (ul
));
3358 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3360 gdb_printf (stream
, " %s", plongest (l
));
3364 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3366 gdb_printf (stream
, " %s", pulongest (ul
));
3370 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3372 gdb_printf (stream
, " %s", plongest (l
));
3376 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3378 gdb_printf (stream
, " %s", pulongest (ul
));
3382 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3384 gdb_printf (stream
, " %s", plongest (l
));
3388 data
= safe_read_uleb128 (data
, end
, &ul
);
3389 gdb_printf (stream
, " %s", pulongest (ul
));
3393 data
= safe_read_sleb128 (data
, end
, &l
);
3394 gdb_printf (stream
, " %s", plongest (l
));
3429 gdb_printf (stream
, " [$%s]",
3430 locexpr_regname (arch
, op
- DW_OP_reg0
));
3434 data
= safe_read_uleb128 (data
, end
, &ul
);
3435 gdb_printf (stream
, " %s [$%s]", pulongest (ul
),
3436 locexpr_regname (arch
, (int) ul
));
3439 case DW_OP_implicit_value
:
3440 data
= safe_read_uleb128 (data
, end
, &ul
);
3442 gdb_printf (stream
, " %s", pulongest (ul
));
3477 data
= safe_read_sleb128 (data
, end
, &l
);
3478 gdb_printf (stream
, " %s [$%s]", plongest (l
),
3479 locexpr_regname (arch
, op
- DW_OP_breg0
));
3483 data
= safe_read_uleb128 (data
, end
, &ul
);
3484 data
= safe_read_sleb128 (data
, end
, &l
);
3485 gdb_printf (stream
, " register %s [$%s] offset %s",
3487 locexpr_regname (arch
, (int) ul
),
3492 data
= safe_read_sleb128 (data
, end
, &l
);
3493 gdb_printf (stream
, " %s", plongest (l
));
3496 case DW_OP_xderef_size
:
3497 case DW_OP_deref_size
:
3499 gdb_printf (stream
, " %d", *data
);
3503 case DW_OP_plus_uconst
:
3504 data
= safe_read_uleb128 (data
, end
, &ul
);
3505 gdb_printf (stream
, " %s", pulongest (ul
));
3509 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3511 gdb_printf (stream
, " to %ld",
3512 (long) (data
+ l
- start
));
3516 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3518 gdb_printf (stream
, " %ld",
3519 (long) (data
+ l
- start
));
3523 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3525 gdb_printf (stream
, " offset %s", phex_nz (ul
, 2));
3529 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3531 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3534 case DW_OP_call_ref
:
3535 ul
= extract_unsigned_integer (data
, offset_size
,
3536 gdbarch_byte_order (arch
));
3537 data
+= offset_size
;
3538 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3542 data
= safe_read_uleb128 (data
, end
, &ul
);
3543 gdb_printf (stream
, " %s (bytes)", pulongest (ul
));
3546 case DW_OP_bit_piece
:
3550 data
= safe_read_uleb128 (data
, end
, &ul
);
3551 data
= safe_read_uleb128 (data
, end
, &offset
);
3552 gdb_printf (stream
, " size %s offset %s (bits)",
3553 pulongest (ul
), pulongest (offset
));
3557 case DW_OP_implicit_pointer
:
3558 case DW_OP_GNU_implicit_pointer
:
3560 ul
= extract_unsigned_integer (data
, offset_size
,
3561 gdbarch_byte_order (arch
));
3562 data
+= offset_size
;
3564 data
= safe_read_sleb128 (data
, end
, &l
);
3566 gdb_printf (stream
, " DIE %s offset %s",
3567 phex_nz (ul
, offset_size
),
3572 case DW_OP_deref_type
:
3573 case DW_OP_GNU_deref_type
:
3575 int deref_addr_size
= *data
++;
3578 data
= safe_read_uleb128 (data
, end
, &ul
);
3579 cu_offset offset
= (cu_offset
) ul
;
3580 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3581 gdb_printf (stream
, "<");
3582 type_print (type
, "", stream
, -1);
3583 gdb_printf (stream
, " [0x%s]> %d",
3584 phex_nz (to_underlying (offset
), 0),
3589 case DW_OP_const_type
:
3590 case DW_OP_GNU_const_type
:
3594 data
= safe_read_uleb128 (data
, end
, &ul
);
3595 cu_offset type_die
= (cu_offset
) ul
;
3596 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3597 gdb_printf (stream
, "<");
3598 type_print (type
, "", stream
, -1);
3599 gdb_printf (stream
, " [0x%s]>",
3600 phex_nz (to_underlying (type_die
), 0));
3603 gdb_printf (stream
, " %d byte block:", n
);
3604 for (int i
= 0; i
< n
; ++i
)
3605 gdb_printf (stream
, " %02x", data
[i
]);
3610 case DW_OP_regval_type
:
3611 case DW_OP_GNU_regval_type
:
3616 data
= safe_read_uleb128 (data
, end
, ®
);
3617 data
= safe_read_uleb128 (data
, end
, &ul
);
3618 cu_offset type_die
= (cu_offset
) ul
;
3620 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3621 gdb_printf (stream
, "<");
3622 type_print (type
, "", stream
, -1);
3623 gdb_printf (stream
, " [0x%s]> [$%s]",
3624 phex_nz (to_underlying (type_die
), 0),
3625 locexpr_regname (arch
, reg
));
3630 case DW_OP_GNU_convert
:
3631 case DW_OP_reinterpret
:
3632 case DW_OP_GNU_reinterpret
:
3634 data
= safe_read_uleb128 (data
, end
, &ul
);
3635 cu_offset type_die
= (cu_offset
) ul
;
3637 if (to_underlying (type_die
) == 0)
3638 gdb_printf (stream
, "<0>");
3643 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3644 gdb_printf (stream
, "<");
3645 type_print (type
, "", stream
, -1);
3646 gdb_printf (stream
, " [0x%s]>",
3647 phex_nz (to_underlying (type_die
), 0));
3652 case DW_OP_entry_value
:
3653 case DW_OP_GNU_entry_value
:
3654 data
= safe_read_uleb128 (data
, end
, &ul
);
3655 gdb_putc ('\n', stream
);
3656 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3657 start
, data
, data
+ ul
, indent
+ 2,
3658 all
, per_cu
, per_objfile
);
3662 case DW_OP_GNU_parameter_ref
:
3663 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3665 gdb_printf (stream
, " offset %s", phex_nz (ul
, 4));
3669 case DW_OP_GNU_addr_index
:
3670 data
= safe_read_uleb128 (data
, end
, &ul
);
3671 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3672 gdb_printf (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3675 case DW_OP_GNU_const_index
:
3676 data
= safe_read_uleb128 (data
, end
, &ul
);
3677 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3678 gdb_printf (stream
, " %s", pulongest (ul
));
3681 case DW_OP_GNU_variable_value
:
3682 ul
= extract_unsigned_integer (data
, offset_size
,
3683 gdbarch_byte_order (arch
));
3684 data
+= offset_size
;
3685 gdb_printf (stream
, " offset %s", phex_nz (ul
, offset_size
));
3689 gdb_printf (stream
, "\n");
3695 static bool dwarf_always_disassemble
;
3698 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3699 struct cmd_list_element
*c
, const char *value
)
3702 _("Whether to always disassemble "
3703 "DWARF expressions is %s.\n"),
3707 /* Describe a single location, which may in turn consist of multiple
3711 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3712 struct ui_file
*stream
,
3713 const gdb_byte
*data
, size_t size
,
3714 unsigned int addr_size
,
3715 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3716 dwarf2_per_objfile
*per_objfile
)
3718 const gdb_byte
*end
= data
+ size
;
3719 int first_piece
= 1, bad
= 0;
3720 objfile
*objfile
= per_objfile
->objfile
;
3724 const gdb_byte
*here
= data
;
3725 int disassemble
= 1;
3730 gdb_printf (stream
, _(", and "));
3732 if (!dwarf_always_disassemble
)
3734 data
= locexpr_describe_location_piece (symbol
, stream
,
3735 addr
, per_cu
, per_objfile
,
3736 data
, end
, addr_size
);
3737 /* If we printed anything, or if we have an empty piece,
3738 then don't disassemble. */
3740 || data
[0] == DW_OP_piece
3741 || data
[0] == DW_OP_bit_piece
)
3746 gdb_printf (stream
, _("a complex DWARF expression:\n"));
3747 data
= disassemble_dwarf_expression (stream
,
3749 addr_size
, offset_size
, data
,
3751 dwarf_always_disassemble
,
3752 per_cu
, per_objfile
);
3757 int empty
= data
== here
;
3760 gdb_printf (stream
, " ");
3761 if (data
[0] == DW_OP_piece
)
3765 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3768 gdb_printf (stream
, _("an empty %s-byte piece"),
3771 gdb_printf (stream
, _(" [%s-byte piece]"),
3774 else if (data
[0] == DW_OP_bit_piece
)
3776 uint64_t bits
, offset
;
3778 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3779 data
= safe_read_uleb128 (data
, end
, &offset
);
3783 _("an empty %s-bit piece"),
3787 _(" [%s-bit piece, offset %s bits]"),
3788 pulongest (bits
), pulongest (offset
));
3798 if (bad
|| data
> end
)
3799 error (_("Corrupted DWARF2 expression for \"%s\"."),
3800 symbol
->print_name ());
3803 /* Print a natural-language description of SYMBOL to STREAM. This
3804 version is for a symbol with a single location. */
3807 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3808 struct ui_file
*stream
)
3810 struct dwarf2_locexpr_baton
*dlbaton
3811 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3812 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3813 int offset_size
= dlbaton
->per_cu
->offset_size ();
3815 locexpr_describe_location_1 (symbol
, addr
, stream
,
3816 dlbaton
->data
, dlbaton
->size
,
3817 addr_size
, offset_size
,
3818 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3821 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3822 any necessary bytecode in AX. */
3825 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3826 struct axs_value
*value
)
3828 struct dwarf2_locexpr_baton
*dlbaton
3829 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3830 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3832 if (dlbaton
->size
== 0)
3833 value
->optimized_out
= 1;
3835 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3836 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3837 dlbaton
->per_objfile
);
3840 /* symbol_computed_ops 'generate_c_location' method. */
3843 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3844 struct gdbarch
*gdbarch
,
3845 std::vector
<bool> ®isters_used
,
3846 CORE_ADDR pc
, const char *result_name
)
3848 struct dwarf2_locexpr_baton
*dlbaton
3849 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3850 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3852 if (dlbaton
->size
== 0)
3853 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3855 compile_dwarf_expr_to_c (stream
, result_name
,
3856 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3857 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3858 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3861 /* The set of location functions used with the DWARF-2 expression
3863 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3864 locexpr_read_variable
,
3865 locexpr_read_variable_at_entry
,
3866 locexpr_get_symbol_read_needs
,
3867 locexpr_describe_location
,
3868 0, /* location_has_loclist */
3869 locexpr_tracepoint_var_ref
,
3870 locexpr_generate_c_location
3874 /* Wrapper functions for location lists. These generally find
3875 the appropriate location expression and call something above. */
3877 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3878 evaluator to calculate the location. */
3879 static struct value
*
3880 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3882 struct dwarf2_loclist_baton
*dlbaton
3883 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3885 const gdb_byte
*data
;
3887 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3889 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3890 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, data
, size
,
3891 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3896 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3897 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3900 Function always returns non-NULL value, it may be marked optimized out if
3901 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3902 if it cannot resolve the parameter for any reason. */
3904 static struct value
*
3905 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3907 struct dwarf2_loclist_baton
*dlbaton
3908 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3909 const gdb_byte
*data
;
3913 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3914 return allocate_optimized_out_value (symbol
->type ());
3916 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3918 return allocate_optimized_out_value (symbol
->type ());
3920 return value_of_dwarf_block_entry (symbol
->type (), frame
, data
, size
);
3923 /* Implementation of get_symbol_read_needs from
3924 symbol_computed_ops. */
3926 static enum symbol_needs_kind
3927 loclist_symbol_needs (struct symbol
*symbol
)
3929 /* If there's a location list, then assume we need to have a frame
3930 to choose the appropriate location expression. With tracking of
3931 global variables this is not necessarily true, but such tracking
3932 is disabled in GCC at the moment until we figure out how to
3935 return SYMBOL_NEEDS_FRAME
;
3938 /* Print a natural-language description of SYMBOL to STREAM. This
3939 version applies when there is a list of different locations, each
3940 with a specified address range. */
3943 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3944 struct ui_file
*stream
)
3946 struct dwarf2_loclist_baton
*dlbaton
3947 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3948 const gdb_byte
*loc_ptr
, *buf_end
;
3949 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3950 struct objfile
*objfile
= per_objfile
->objfile
;
3951 struct gdbarch
*gdbarch
= objfile
->arch ();
3952 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3953 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3954 int offset_size
= dlbaton
->per_cu
->offset_size ();
3955 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3956 /* Adjustment for relocatable objects. */
3957 CORE_ADDR text_offset
= objfile
->text_section_offset ();
3958 CORE_ADDR base_address
= dlbaton
->base_address
;
3961 loc_ptr
= dlbaton
->data
;
3962 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3964 gdb_printf (stream
, _("multi-location:\n"));
3966 /* Iterate through locations until we run out. */
3969 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
3971 enum debug_loc_kind kind
;
3972 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3974 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3975 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3976 dlbaton
->per_objfile
,
3977 loc_ptr
, buf_end
, &new_ptr
,
3978 &low
, &high
, byte_order
);
3979 else if (dlbaton
->per_cu
->version () < 5)
3980 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3982 byte_order
, addr_size
,
3985 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3986 dlbaton
->per_objfile
,
3987 loc_ptr
, buf_end
, &new_ptr
,
3988 &low
, &high
, byte_order
,
3989 addr_size
, signed_addr_p
);
3993 case DEBUG_LOC_END_OF_LIST
:
3997 case DEBUG_LOC_BASE_ADDRESS
:
3998 base_address
= high
;
3999 gdb_printf (stream
, _(" Base address %s"),
4000 paddress (gdbarch
, base_address
));
4003 case DEBUG_LOC_START_END
:
4004 case DEBUG_LOC_START_LENGTH
:
4005 case DEBUG_LOC_OFFSET_PAIR
:
4008 case DEBUG_LOC_BUFFER_OVERFLOW
:
4009 case DEBUG_LOC_INVALID_ENTRY
:
4010 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4011 symbol
->print_name ());
4014 gdb_assert_not_reached ("bad debug_loc_kind");
4017 /* Otherwise, a location expression entry. */
4019 high
+= text_offset
;
4020 if (!dlbaton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
4022 low
+= base_address
;
4023 high
+= base_address
;
4026 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4027 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4029 if (dlbaton
->per_cu
->version () < 5)
4031 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4036 unsigned int bytes_read
;
4037 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4038 loc_ptr
+= bytes_read
;
4041 /* (It would improve readability to print only the minimum
4042 necessary digits of the second number of the range.) */
4043 gdb_printf (stream
, _(" Range %s-%s: "),
4044 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4046 /* Now describe this particular location. */
4047 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4048 addr_size
, offset_size
,
4049 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4051 gdb_printf (stream
, "\n");
4057 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4058 any necessary bytecode in AX. */
4060 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4061 struct axs_value
*value
)
4063 struct dwarf2_loclist_baton
*dlbaton
4064 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4065 const gdb_byte
*data
;
4067 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4069 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4071 value
->optimized_out
= 1;
4073 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4074 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4077 /* symbol_computed_ops 'generate_c_location' method. */
4080 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4081 struct gdbarch
*gdbarch
,
4082 std::vector
<bool> ®isters_used
,
4083 CORE_ADDR pc
, const char *result_name
)
4085 struct dwarf2_loclist_baton
*dlbaton
4086 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4087 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4088 const gdb_byte
*data
;
4091 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4093 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4095 compile_dwarf_expr_to_c (stream
, result_name
,
4096 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4099 dlbaton
->per_objfile
);
4102 /* The set of location functions used with the DWARF-2 expression
4103 evaluator and location lists. */
4104 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4105 loclist_read_variable
,
4106 loclist_read_variable_at_entry
,
4107 loclist_symbol_needs
,
4108 loclist_describe_location
,
4109 1, /* location_has_loclist */
4110 loclist_tracepoint_var_ref
,
4111 loclist_generate_c_location
4114 void _initialize_dwarf2loc ();
4116 _initialize_dwarf2loc ()
4118 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4119 &entry_values_debug
,
4120 _("Set entry values and tail call frames "
4122 _("Show entry values and tail call frames "
4124 _("When non-zero, the process of determining "
4125 "parameter values from function entry point "
4126 "and tail call frames will be printed."),
4128 show_entry_values_debug
,
4129 &setdebuglist
, &showdebuglist
);
4131 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4132 &dwarf_always_disassemble
, _("\
4133 Set whether `info address' always disassembles DWARF expressions."), _("\
4134 Show whether `info address' always disassembles DWARF expressions."), _("\
4135 When enabled, DWARF expressions are always printed in an assembly-like\n\
4136 syntax. When disabled, expressions will be printed in a more\n\
4137 conversational style, when possible."),
4139 show_dwarf_always_disassemble
,
4141 &show_dwarf_cmdlist
);