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
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
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
)
630 fprintf_filtered (file
,
631 _("Entry values and tail call frames debugging is %s.\n"),
635 /* See gdbtypes.h. */
638 call_site_target::address (struct gdbarch
*call_site_gdbarch
,
639 const struct call_site
*call_site
,
640 struct frame_info
*caller_frame
) const
644 case call_site_target::DWARF_BLOCK
:
646 struct dwarf2_locexpr_baton
*dwarf_block
;
648 struct type
*caller_core_addr_type
;
649 struct gdbarch
*caller_arch
;
651 dwarf_block
= m_loc
.dwarf_block
;
652 if (dwarf_block
== NULL
)
654 struct bound_minimal_symbol msym
;
656 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
657 throw_error (NO_ENTRY_VALUE_ERROR
,
658 _("DW_AT_call_target is not specified at %s in %s"),
659 paddress (call_site_gdbarch
, call_site
->pc ()),
660 (msym
.minsym
== NULL
? "???"
661 : msym
.minsym
->print_name ()));
664 if (caller_frame
== NULL
)
666 struct bound_minimal_symbol msym
;
668 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
669 throw_error (NO_ENTRY_VALUE_ERROR
,
670 _("DW_AT_call_target DWARF block resolving "
671 "requires known frame which is currently not "
672 "available at %s in %s"),
673 paddress (call_site_gdbarch
, call_site
->pc ()),
674 (msym
.minsym
== NULL
? "???"
675 : msym
.minsym
->print_name ()));
678 caller_arch
= get_frame_arch (caller_frame
);
679 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
680 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
681 dwarf_block
->data
, dwarf_block
->size
,
683 dwarf_block
->per_objfile
);
684 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
685 if (VALUE_LVAL (val
) == lval_memory
)
686 return value_address (val
);
688 return value_as_address (val
);
691 case call_site_target::PHYSNAME
:
693 const char *physname
;
694 struct bound_minimal_symbol msym
;
696 physname
= m_loc
.physname
;
698 /* Handle both the mangled and demangled PHYSNAME. */
699 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
700 if (msym
.minsym
== NULL
)
702 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
703 throw_error (NO_ENTRY_VALUE_ERROR
,
704 _("Cannot find function \"%s\" for a call site target "
706 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
707 (msym
.minsym
== NULL
? "???"
708 : msym
.minsym
->print_name ()));
711 return BMSYMBOL_VALUE_ADDRESS (msym
);
714 case call_site_target::PHYSADDR
:
716 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
717 compunit_symtab
*cust
= per_objfile
->get_symtab (call_site
->per_cu
);
718 int sect_idx
= cust
->block_line_section ();
719 CORE_ADDR delta
= per_objfile
->objfile
->section_offsets
[sect_idx
];
721 return m_loc
.physaddr
+ delta
;
725 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
729 /* Convert function entry point exact address ADDR to the function which is
730 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
731 NO_ENTRY_VALUE_ERROR otherwise. */
733 static struct symbol
*
734 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
736 struct symbol
*sym
= find_pc_function (addr
);
739 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
740 throw_error (NO_ENTRY_VALUE_ERROR
,
741 _("DW_TAG_call_site resolving failed to find function "
742 "name for address %s"),
743 paddress (gdbarch
, addr
));
746 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
747 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
752 /* Verify function with entry point exact address ADDR can never call itself
753 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
754 can call itself via tail calls.
756 If a funtion can tail call itself its entry value based parameters are
757 unreliable. There is no verification whether the value of some/all
758 parameters is unchanged through the self tail call, we expect if there is
759 a self tail call all the parameters can be modified. */
762 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
766 /* The verification is completely unordered. Track here function addresses
767 which still need to be iterated. */
768 std::vector
<CORE_ADDR
> todo
;
770 /* Track here CORE_ADDRs which were already visited. */
771 std::unordered_set
<CORE_ADDR
> addr_hash
;
773 todo
.push_back (verify_addr
);
774 while (!todo
.empty ())
776 struct symbol
*func_sym
;
777 struct call_site
*call_site
;
782 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
784 for (call_site
= TYPE_TAIL_CALL_LIST (func_sym
->type ());
785 call_site
; call_site
= call_site
->tail_call_next
)
787 CORE_ADDR target_addr
;
789 /* CALLER_FRAME with registers is not available for tail-call jumped
791 target_addr
= call_site
->address (gdbarch
, nullptr);
793 if (target_addr
== verify_addr
)
795 struct bound_minimal_symbol msym
;
797 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
798 throw_error (NO_ENTRY_VALUE_ERROR
,
799 _("DW_OP_entry_value resolving has found "
800 "function \"%s\" at %s can call itself via tail "
802 (msym
.minsym
== NULL
? "???"
803 : msym
.minsym
->print_name ()),
804 paddress (gdbarch
, verify_addr
));
807 if (addr_hash
.insert (target_addr
).second
)
808 todo
.push_back (target_addr
);
813 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
814 ENTRY_VALUES_DEBUG. */
817 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
819 CORE_ADDR addr
= call_site
->pc ();
820 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
822 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
823 (msym
.minsym
== NULL
? "???"
824 : msym
.minsym
->print_name ()));
828 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
829 only top callers and bottom callees which are present in both. GDBARCH is
830 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
831 no remaining possibilities to provide unambiguous non-trivial result.
832 RESULTP should point to NULL on the first (initialization) call. Caller is
833 responsible for xfree of any RESULTP data. */
836 chain_candidate (struct gdbarch
*gdbarch
,
837 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
838 const std::vector
<struct call_site
*> &chain
)
840 long length
= chain
.size ();
841 int callers
, callees
, idx
;
843 if (*resultp
== NULL
)
845 /* Create the initial chain containing all the passed PCs. */
847 struct call_site_chain
*result
848 = ((struct call_site_chain
*)
849 xmalloc (sizeof (*result
)
850 + sizeof (*result
->call_site
) * (length
- 1)));
851 result
->length
= length
;
852 result
->callers
= result
->callees
= length
;
854 memcpy (result
->call_site
, chain
.data (),
855 sizeof (*result
->call_site
) * length
);
856 resultp
->reset (result
);
858 if (entry_values_debug
)
860 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
861 for (idx
= 0; idx
< length
; idx
++)
862 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
863 fputc_unfiltered ('\n', gdb_stdlog
);
869 if (entry_values_debug
)
871 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
872 for (idx
= 0; idx
< length
; idx
++)
873 tailcall_dump (gdbarch
, chain
[idx
]);
874 fputc_unfiltered ('\n', gdb_stdlog
);
877 /* Intersect callers. */
879 callers
= std::min ((long) (*resultp
)->callers
, length
);
880 for (idx
= 0; idx
< callers
; idx
++)
881 if ((*resultp
)->call_site
[idx
] != chain
[idx
])
883 (*resultp
)->callers
= idx
;
887 /* Intersect callees. */
889 callees
= std::min ((long) (*resultp
)->callees
, length
);
890 for (idx
= 0; idx
< callees
; idx
++)
891 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
892 != chain
[length
- 1 - idx
])
894 (*resultp
)->callees
= idx
;
898 if (entry_values_debug
)
900 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
901 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
902 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
903 fputs_unfiltered (" |", gdb_stdlog
);
904 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
905 tailcall_dump (gdbarch
,
906 (*resultp
)->call_site
[(*resultp
)->length
907 - (*resultp
)->callees
+ idx
]);
908 fputc_unfiltered ('\n', gdb_stdlog
);
911 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
913 /* There are no common callers or callees. It could be also a direct
914 call (which has length 0) with ambiguous possibility of an indirect
915 call - CALLERS == CALLEES == 0 is valid during the first allocation
916 but any subsequence processing of such entry means ambiguity. */
917 resultp
->reset (NULL
);
921 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
922 PC again. In such case there must be two different code paths to reach
923 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
924 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
927 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
928 assumed frames between them use GDBARCH. Use depth first search so we can
929 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
930 would have needless GDB stack overhead. Any unreliability results
931 in thrown NO_ENTRY_VALUE_ERROR. */
933 static gdb::unique_xmalloc_ptr
<call_site_chain
>
934 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
937 CORE_ADDR save_callee_pc
= callee_pc
;
938 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
939 struct call_site
*call_site
;
941 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
942 call_site nor any possible call_site at CALLEE_PC's function is there.
943 Any CALL_SITE in CHAIN will be iterated to its siblings - via
944 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
945 std::vector
<struct call_site
*> chain
;
947 /* We are not interested in the specific PC inside the callee function. */
948 callee_pc
= get_pc_function_start (callee_pc
);
950 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
951 paddress (gdbarch
, save_callee_pc
));
953 /* Mark CALL_SITEs so we do not visit the same ones twice. */
954 std::unordered_set
<CORE_ADDR
> addr_hash
;
956 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
957 at the target's function. All the possible tail call sites in the
958 target's function will get iterated as already pushed into CHAIN via their
960 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
964 CORE_ADDR target_func_addr
;
965 struct call_site
*target_call_site
;
967 /* CALLER_FRAME with registers is not available for tail-call jumped
969 target_func_addr
= call_site
->address (gdbarch
, nullptr);
971 if (target_func_addr
== callee_pc
)
973 chain_candidate (gdbarch
, &retval
, chain
);
977 /* There is no way to reach CALLEE_PC again as we would prevent
978 entering it twice as being already marked in ADDR_HASH. */
979 target_call_site
= NULL
;
983 struct symbol
*target_func
;
985 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
986 target_call_site
= TYPE_TAIL_CALL_LIST (target_func
->type ());
991 /* Attempt to visit TARGET_CALL_SITE. */
993 if (target_call_site
)
995 if (addr_hash
.insert (target_call_site
->pc ()).second
)
997 /* Successfully entered TARGET_CALL_SITE. */
999 chain
.push_back (target_call_site
);
1004 /* Backtrack (without revisiting the originating call_site). Try the
1005 callers's sibling; if there isn't any try the callers's callers's
1008 target_call_site
= NULL
;
1009 while (!chain
.empty ())
1011 call_site
= chain
.back ();
1014 size_t removed
= addr_hash
.erase (call_site
->pc ());
1015 gdb_assert (removed
== 1);
1017 target_call_site
= call_site
->tail_call_next
;
1018 if (target_call_site
)
1022 while (target_call_site
);
1027 call_site
= chain
.back ();
1032 struct bound_minimal_symbol msym_caller
, msym_callee
;
1034 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1035 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1036 throw_error (NO_ENTRY_VALUE_ERROR
,
1037 _("There are no unambiguously determinable intermediate "
1038 "callers or callees between caller function \"%s\" at %s "
1039 "and callee function \"%s\" at %s"),
1040 (msym_caller
.minsym
== NULL
1041 ? "???" : msym_caller
.minsym
->print_name ()),
1042 paddress (gdbarch
, caller_pc
),
1043 (msym_callee
.minsym
== NULL
1044 ? "???" : msym_callee
.minsym
->print_name ()),
1045 paddress (gdbarch
, callee_pc
));
1051 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1052 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1053 constructed return NULL. */
1055 gdb::unique_xmalloc_ptr
<call_site_chain
>
1056 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1057 CORE_ADDR callee_pc
)
1059 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1063 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1065 catch (const gdb_exception_error
&e
)
1067 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1069 if (entry_values_debug
)
1070 exception_print (gdb_stdout
, e
);
1081 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1084 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1085 enum call_site_parameter_kind kind
,
1086 union call_site_parameter_u kind_u
)
1088 if (kind
== parameter
->kind
)
1091 case CALL_SITE_PARAMETER_DWARF_REG
:
1092 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1094 case CALL_SITE_PARAMETER_FB_OFFSET
:
1095 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1097 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1098 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1105 struct call_site_parameter
*
1106 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1107 enum call_site_parameter_kind kind
,
1108 union call_site_parameter_u kind_u
,
1109 dwarf2_per_cu_data
**per_cu_return
,
1110 dwarf2_per_objfile
**per_objfile_return
)
1112 CORE_ADDR func_addr
, caller_pc
;
1113 struct gdbarch
*gdbarch
;
1114 struct frame_info
*caller_frame
;
1115 struct call_site
*call_site
;
1117 /* Initialize it just to avoid a GCC false warning. */
1118 struct call_site_parameter
*parameter
= NULL
;
1119 CORE_ADDR target_addr
;
1121 while (get_frame_type (frame
) == INLINE_FRAME
)
1123 frame
= get_prev_frame (frame
);
1124 gdb_assert (frame
!= NULL
);
1127 func_addr
= get_frame_func (frame
);
1128 gdbarch
= get_frame_arch (frame
);
1129 caller_frame
= get_prev_frame (frame
);
1130 if (gdbarch
!= frame_unwind_arch (frame
))
1132 struct bound_minimal_symbol msym
1133 = lookup_minimal_symbol_by_pc (func_addr
);
1134 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1136 throw_error (NO_ENTRY_VALUE_ERROR
,
1137 _("DW_OP_entry_value resolving callee gdbarch %s "
1138 "(of %s (%s)) does not match caller gdbarch %s"),
1139 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1140 paddress (gdbarch
, func_addr
),
1141 (msym
.minsym
== NULL
? "???"
1142 : msym
.minsym
->print_name ()),
1143 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1146 if (caller_frame
== NULL
)
1148 struct bound_minimal_symbol msym
1149 = lookup_minimal_symbol_by_pc (func_addr
);
1151 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1152 "requires caller of %s (%s)"),
1153 paddress (gdbarch
, func_addr
),
1154 (msym
.minsym
== NULL
? "???"
1155 : msym
.minsym
->print_name ()));
1157 caller_pc
= get_frame_pc (caller_frame
);
1158 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1160 target_addr
= call_site
->address (gdbarch
, caller_frame
);
1161 if (target_addr
!= func_addr
)
1163 struct minimal_symbol
*target_msym
, *func_msym
;
1165 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1166 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1167 throw_error (NO_ENTRY_VALUE_ERROR
,
1168 _("DW_OP_entry_value resolving expects callee %s at %s "
1169 "but the called frame is for %s at %s"),
1170 (target_msym
== NULL
? "???"
1171 : target_msym
->print_name ()),
1172 paddress (gdbarch
, target_addr
),
1173 func_msym
== NULL
? "???" : func_msym
->print_name (),
1174 paddress (gdbarch
, func_addr
));
1177 /* No entry value based parameters would be reliable if this function can
1178 call itself via tail calls. */
1179 func_verify_no_selftailcall (gdbarch
, func_addr
);
1181 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1183 parameter
= &call_site
->parameter
[iparams
];
1184 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1187 if (iparams
== call_site
->parameter_count
)
1189 struct minimal_symbol
*msym
1190 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1192 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1193 determine its value. */
1194 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1195 "at DW_TAG_call_site %s at %s"),
1196 paddress (gdbarch
, caller_pc
),
1197 msym
== NULL
? "???" : msym
->print_name ());
1200 *per_cu_return
= call_site
->per_cu
;
1201 *per_objfile_return
= call_site
->per_objfile
;
1205 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1206 the normal DW_AT_call_value block. Otherwise return the
1207 DW_AT_call_data_value (dereferenced) block.
1209 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1212 Function always returns non-NULL, non-optimized out value. It throws
1213 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1215 static struct value
*
1216 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1217 CORE_ADDR deref_size
, struct type
*type
,
1218 struct frame_info
*caller_frame
,
1219 dwarf2_per_cu_data
*per_cu
,
1220 dwarf2_per_objfile
*per_objfile
)
1222 const gdb_byte
*data_src
;
1225 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1226 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1228 /* DEREF_SIZE size is not verified here. */
1229 if (data_src
== NULL
)
1230 throw_error (NO_ENTRY_VALUE_ERROR
,
1231 _("Cannot resolve DW_AT_call_data_value"));
1233 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1234 per_objfile
, false);
1237 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1238 the indirect method on it, that is use its stored target value, the sole
1239 purpose of entry_data_value_funcs.. */
1241 static struct value
*
1242 entry_data_value_coerce_ref (const struct value
*value
)
1244 struct type
*checked_type
= check_typedef (value_type (value
));
1245 struct value
*target_val
;
1247 if (!TYPE_IS_REFERENCE (checked_type
))
1250 target_val
= (struct value
*) value_computed_closure (value
);
1251 value_incref (target_val
);
1255 /* Implement copy_closure. */
1258 entry_data_value_copy_closure (const struct value
*v
)
1260 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1262 value_incref (target_val
);
1266 /* Implement free_closure. */
1269 entry_data_value_free_closure (struct value
*v
)
1271 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1273 value_decref (target_val
);
1276 /* Vector for methods for an entry value reference where the referenced value
1277 is stored in the caller. On the first dereference use
1278 DW_AT_call_data_value in the caller. */
1280 static const struct lval_funcs entry_data_value_funcs
=
1285 NULL
, /* indirect */
1286 entry_data_value_coerce_ref
,
1287 NULL
, /* check_synthetic_pointer */
1288 entry_data_value_copy_closure
,
1289 entry_data_value_free_closure
1292 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1293 are used to match DW_AT_location at the caller's
1294 DW_TAG_call_site_parameter.
1296 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1297 cannot resolve the parameter for any reason. */
1299 static struct value
*
1300 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1301 enum call_site_parameter_kind kind
,
1302 union call_site_parameter_u kind_u
)
1304 struct type
*checked_type
= check_typedef (type
);
1305 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1306 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1307 struct value
*outer_val
, *target_val
, *val
;
1308 struct call_site_parameter
*parameter
;
1309 dwarf2_per_cu_data
*caller_per_cu
;
1310 dwarf2_per_objfile
*caller_per_objfile
;
1312 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1314 &caller_per_objfile
);
1316 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1319 caller_per_objfile
);
1321 /* Check if DW_AT_call_data_value cannot be used. If it should be
1322 used and it is not available do not fall back to OUTER_VAL - dereferencing
1323 TYPE_CODE_REF with non-entry data value would give current value - not the
1326 if (!TYPE_IS_REFERENCE (checked_type
)
1327 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1330 target_val
= dwarf_entry_parameter_to_value (parameter
,
1331 TYPE_LENGTH (target_type
),
1332 target_type
, caller_frame
,
1334 caller_per_objfile
);
1336 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1337 release_value (target_val
).release ());
1339 /* Copy the referencing pointer to the new computed value. */
1340 memcpy (value_contents_raw (val
).data (),
1341 value_contents_raw (outer_val
).data (),
1342 TYPE_LENGTH (checked_type
));
1343 set_value_lazy (val
, 0);
1348 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1349 SIZE are DWARF block used to match DW_AT_location at the caller's
1350 DW_TAG_call_site_parameter.
1352 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1353 cannot resolve the parameter for any reason. */
1355 static struct value
*
1356 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1357 const gdb_byte
*block
, size_t block_len
)
1359 union call_site_parameter_u kind_u
;
1361 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1362 if (kind_u
.dwarf_reg
!= -1)
1363 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1366 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1367 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1370 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1371 suppressed during normal operation. The expression can be arbitrary if
1372 there is no caller-callee entry value binding expected. */
1373 throw_error (NO_ENTRY_VALUE_ERROR
,
1374 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1375 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1378 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1380 static struct value
*
1381 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1382 dwarf2_per_cu_data
*per_cu
,
1383 dwarf2_per_objfile
*per_objfile
,
1386 struct value
*result
= NULL
;
1387 const gdb_byte
*bytes
;
1390 auto_obstack temp_obstack
;
1391 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1392 &temp_obstack
, &len
);
1396 if (byte_offset
>= 0
1397 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1399 bytes
+= byte_offset
;
1400 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1403 invalid_synthetic_pointer ();
1406 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1414 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1415 dwarf2_per_cu_data
*per_cu
,
1416 dwarf2_per_objfile
*per_objfile
,
1417 struct frame_info
*frame
, struct type
*type
,
1418 bool resolve_abstract_p
)
1420 /* Fetch the location expression of the DIE we're pointing to. */
1421 auto get_frame_address_in_block_wrapper
= [frame
] ()
1423 return get_frame_address_in_block (frame
);
1425 struct dwarf2_locexpr_baton baton
1426 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1427 get_frame_address_in_block_wrapper
,
1428 resolve_abstract_p
);
1430 /* Get type of pointed-to DIE. */
1431 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1433 if (orig_type
== NULL
)
1434 invalid_synthetic_pointer ();
1436 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1437 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1438 or it may've been optimized out. */
1439 if (baton
.data
!= NULL
)
1440 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1441 baton
.size
, baton
.per_cu
,
1443 TYPE_TARGET_TYPE (type
),
1446 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1450 /* Evaluate a location description, starting at DATA and with length
1451 SIZE, to find the current location of variable of TYPE in the
1452 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1453 location of the subobject of type SUBOBJ_TYPE at byte offset
1454 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1456 static struct value
*
1457 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1458 const gdb_byte
*data
, size_t size
,
1459 dwarf2_per_cu_data
*per_cu
,
1460 dwarf2_per_objfile
*per_objfile
,
1461 struct type
*subobj_type
,
1462 LONGEST subobj_byte_offset
,
1465 if (subobj_type
== NULL
)
1468 subobj_byte_offset
= 0;
1470 else if (subobj_byte_offset
< 0)
1471 invalid_synthetic_pointer ();
1474 return allocate_optimized_out_value (subobj_type
);
1476 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1479 scoped_value_mark free_values
;
1483 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1484 type
, subobj_type
, subobj_byte_offset
);
1486 catch (const gdb_exception_error
&ex
)
1488 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1490 free_values
.free_to_mark ();
1491 retval
= allocate_value (subobj_type
);
1492 mark_value_bytes_unavailable (retval
, 0,
1493 TYPE_LENGTH (subobj_type
));
1496 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1498 if (entry_values_debug
)
1499 exception_print (gdb_stdout
, ex
);
1500 free_values
.free_to_mark ();
1501 return allocate_optimized_out_value (subobj_type
);
1507 /* We need to clean up all the values that are not needed any more.
1508 The problem with a value_ref_ptr class is that it disconnects the
1509 RETVAL from the value garbage collection, so we need to make
1510 a copy of that value on the stack to keep everything consistent.
1511 The value_ref_ptr will clean up after itself at the end of this block. */
1512 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1513 free_values
.free_to_mark ();
1515 return value_copy (retval
);
1518 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1519 passes 0 as the byte_offset. */
1522 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1523 const gdb_byte
*data
, size_t size
,
1524 dwarf2_per_cu_data
*per_cu
,
1525 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1527 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1528 per_objfile
, NULL
, 0, as_lval
);
1531 /* Evaluates a dwarf expression and stores the result in VAL,
1532 expecting that the dwarf expression only produces a single
1533 CORE_ADDR. FRAME is the frame in which the expression is
1534 evaluated. ADDR_STACK is a context (location of a variable) and
1535 might be needed to evaluate the location expression.
1536 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
1537 or the default of 0) should be pushed on the DWARF expression
1538 evaluation stack before evaluating the expression; this is required
1539 by certain forms of DWARF expression. Returns 1 on success, 0
1543 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1544 struct frame_info
*frame
,
1545 const struct property_addr_info
*addr_stack
,
1547 bool push_initial_value
,
1550 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1553 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1554 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1555 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1558 scoped_value_mark free_values
;
1560 if (push_initial_value
)
1562 if (addr_stack
!= nullptr)
1563 ctx
.push_address (addr_stack
->addr
, false);
1565 ctx
.push_address (0, false);
1570 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1571 true, per_cu
, frame
, addr_stack
);
1573 catch (const gdb_exception_error
&ex
)
1575 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1579 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1581 if (entry_values_debug
)
1582 exception_print (gdb_stdout
, ex
);
1589 if (value_optimized_out (result
))
1592 if (VALUE_LVAL (result
) == lval_memory
)
1593 *valp
= value_address (result
);
1596 if (VALUE_LVAL (result
) == not_lval
)
1597 *is_reference
= false;
1599 *valp
= value_as_address (result
);
1605 /* See dwarf2/loc.h. */
1608 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1609 struct frame_info
*frame
,
1610 const struct property_addr_info
*addr_stack
,
1612 bool push_initial_value
)
1617 if (frame
== NULL
&& has_stack_frames ())
1618 frame
= get_selected_frame (NULL
);
1620 switch (prop
->kind ())
1624 const struct dwarf2_property_baton
*baton
1625 = (const struct dwarf2_property_baton
*) prop
->baton ();
1626 gdb_assert (baton
->property_type
!= NULL
);
1628 bool is_reference
= baton
->locexpr
.is_reference
;
1629 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1630 value
, push_initial_value
, &is_reference
))
1634 struct value
*val
= value_at (baton
->property_type
, *value
);
1635 *value
= value_as_address (val
);
1639 gdb_assert (baton
->property_type
!= NULL
);
1641 struct type
*type
= check_typedef (baton
->property_type
);
1642 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
1643 && !type
->is_unsigned ())
1645 /* If we have a valid return candidate and it's value
1646 is signed, we have to sign-extend the value because
1647 CORE_ADDR on 64bit machine has 8 bytes but address
1648 size of an 32bit application is bytes. */
1650 = (baton
->locexpr
.per_cu
->addr_size ()
1652 const CORE_ADDR neg_mask
1653 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1655 /* Check if signed bit is set and sign-extend values. */
1656 if (*value
& neg_mask
)
1667 struct dwarf2_property_baton
*baton
1668 = (struct dwarf2_property_baton
*) prop
->baton ();
1670 const gdb_byte
*data
;
1675 || !get_frame_address_in_block_if_available (frame
, &pc
))
1678 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1681 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1682 size
, baton
->loclist
.per_cu
,
1683 baton
->loclist
.per_objfile
);
1684 if (!value_optimized_out (val
))
1686 *value
= value_as_address (val
);
1694 *value
= prop
->const_val ();
1697 case PROP_ADDR_OFFSET
:
1699 struct dwarf2_property_baton
*baton
1700 = (struct dwarf2_property_baton
*) prop
->baton ();
1701 const struct property_addr_info
*pinfo
;
1704 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1706 /* This approach lets us avoid checking the qualifiers. */
1707 if (TYPE_MAIN_TYPE (pinfo
->type
)
1708 == TYPE_MAIN_TYPE (baton
->property_type
))
1712 error (_("cannot find reference address for offset property"));
1713 if (pinfo
->valaddr
.data () != NULL
)
1714 val
= value_from_contents
1715 (baton
->offset_info
.type
,
1716 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1718 val
= value_at (baton
->offset_info
.type
,
1719 pinfo
->addr
+ baton
->offset_info
.offset
);
1720 *value
= value_as_address (val
);
1724 case PROP_VARIABLE_NAME
:
1726 struct value
*val
= compute_var_value (prop
->variable_name ());
1729 *value
= value_as_long (val
);
1739 /* See dwarf2/loc.h. */
1742 dwarf2_compile_property_to_c (string_file
*stream
,
1743 const char *result_name
,
1744 struct gdbarch
*gdbarch
,
1745 std::vector
<bool> ®isters_used
,
1746 const struct dynamic_prop
*prop
,
1750 struct dwarf2_property_baton
*baton
1751 = (struct dwarf2_property_baton
*) prop
->baton ();
1752 const gdb_byte
*data
;
1754 dwarf2_per_cu_data
*per_cu
;
1755 dwarf2_per_objfile
*per_objfile
;
1757 if (prop
->kind () == PROP_LOCEXPR
)
1759 data
= baton
->locexpr
.data
;
1760 size
= baton
->locexpr
.size
;
1761 per_cu
= baton
->locexpr
.per_cu
;
1762 per_objfile
= baton
->locexpr
.per_objfile
;
1766 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1768 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1769 per_cu
= baton
->loclist
.per_cu
;
1770 per_objfile
= baton
->loclist
.per_objfile
;
1773 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1774 gdbarch
, registers_used
,
1775 per_cu
->addr_size (),
1776 data
, data
+ size
, per_cu
, per_objfile
);
1779 /* Compute the correct symbol_needs_kind value for the location
1782 Implemented by traversing the logical control flow graph of the
1785 static enum symbol_needs_kind
1786 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1787 dwarf2_per_cu_data
*per_cu
,
1788 dwarf2_per_objfile
*per_objfile
,
1789 bfd_endian byte_order
,
1794 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1796 /* If the expression is empty, we have nothing to do. */
1798 return symbol_needs
;
1800 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1802 /* List of operations to visit. Operations in this list are not visited yet,
1803 so are not in VISITED_OPS (and vice-versa). */
1804 std::vector
<const gdb_byte
*> ops_to_visit
;
1806 /* Operations already visited. */
1807 std::unordered_set
<const gdb_byte
*> visited_ops
;
1809 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1810 hasn't been visited yet. */
1811 auto insert_in_ops_to_visit
1812 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1814 if (op_ptr
>= expr_end
)
1817 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1820 ops_to_visit
.push_back (op_ptr
);
1823 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1825 const int max_depth
= 256;
1827 if (depth
> max_depth
)
1828 error (_("DWARF-2 expression error: Loop detected."));
1832 /* Initialize the to-visit list with the first operation. */
1833 insert_in_ops_to_visit (&expr
[0]);
1835 while (!ops_to_visit
.empty ())
1837 /* Pop one op to visit, mark it as visited. */
1838 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1839 ops_to_visit
.pop_back ();
1840 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1841 visited_ops
.insert (op_ptr
);
1843 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1845 /* Most operations have a single possible following operation
1846 (they are not conditional branches). The code below updates
1847 OP_PTR to point to that following operation, which is pushed
1848 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1849 OP_PTR pointing just after the operand. */
1852 /* The DWARF expression might have a bug causing an infinite
1853 loop. In that case, quitting is the only way out. */
1890 case DW_OP_stack_value
:
1917 case DW_OP_GNU_push_tls_address
:
1919 case DW_OP_GNU_uninit
:
1920 case DW_OP_push_object_address
:
1923 case DW_OP_form_tls_address
:
1924 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1925 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1929 case DW_OP_GNU_convert
:
1930 case DW_OP_reinterpret
:
1931 case DW_OP_GNU_reinterpret
:
1933 case DW_OP_GNU_addr_index
:
1934 case DW_OP_GNU_const_index
:
1936 case DW_OP_plus_uconst
:
1938 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1942 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1945 case DW_OP_bit_piece
:
1946 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1947 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1950 case DW_OP_deref_type
:
1951 case DW_OP_GNU_deref_type
:
1953 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1957 op_ptr
+= addr_size
;
2047 case DW_OP_call_frame_cfa
:
2048 case DW_OP_entry_value
:
2049 case DW_OP_GNU_entry_value
:
2050 case DW_OP_GNU_parameter_ref
:
2051 case DW_OP_regval_type
:
2052 case DW_OP_GNU_regval_type
:
2053 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2056 case DW_OP_implicit_value
:
2059 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2064 case DW_OP_implicit_pointer
:
2065 case DW_OP_GNU_implicit_pointer
:
2066 op_ptr
+= ref_addr_size
;
2067 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2070 case DW_OP_deref_size
:
2077 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2085 /* This is the only operation that pushes two operations in
2086 the to-visit list, so handle it all here. */
2087 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2090 insert_in_ops_to_visit (op_ptr
+ offset
);
2091 insert_in_ops_to_visit (op_ptr
);
2098 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2100 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2103 auto get_frame_pc
= [&symbol_needs
] ()
2105 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2109 struct dwarf2_locexpr_baton baton
2110 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2114 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2115 we dont have to check the baton content. */
2116 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2118 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2119 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2122 = dwarf2_get_symbol_read_needs (sub_expr
,
2125 gdbarch_byte_order (arch
),
2126 baton
.per_cu
->addr_size (),
2127 baton
.per_cu
->ref_addr_size (),
2133 case DW_OP_GNU_variable_value
:
2135 sect_offset sect_off
2136 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2139 op_ptr
+= ref_addr_size
;
2141 struct type
*die_type
2142 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2145 if (die_type
== NULL
)
2146 error (_("Bad DW_OP_GNU_variable_value DIE."));
2148 /* Note: Things still work when the following test is
2149 removed. This test and error is here to conform to the
2150 proposed specification. */
2151 if (die_type
->code () != TYPE_CODE_INT
2152 && die_type
->code () != TYPE_CODE_PTR
)
2153 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2154 "an integer or pointer."));
2156 auto get_frame_pc
= [&symbol_needs
] ()
2158 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2162 struct dwarf2_locexpr_baton baton
2163 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2165 get_frame_pc
, true);
2167 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2168 we dont have to check the baton content. */
2169 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2171 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2172 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2175 = dwarf2_get_symbol_read_needs (sub_expr
,
2178 gdbarch_byte_order (arch
),
2179 baton
.per_cu
->addr_size (),
2180 baton
.per_cu
->ref_addr_size (),
2186 case DW_OP_const_type
:
2187 case DW_OP_GNU_const_type
:
2190 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2191 gdb_byte offset
= *op_ptr
++;
2197 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2200 /* If it is known that a frame information is
2201 needed we can stop parsing the expression. */
2202 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2205 insert_in_ops_to_visit (op_ptr
);
2208 return symbol_needs
;
2211 /* A helper function that throws an unimplemented error mentioning a
2212 given DWARF operator. */
2214 static void ATTRIBUTE_NORETURN
2215 unimplemented (unsigned int op
)
2217 const char *name
= get_DW_OP_name (op
);
2220 error (_("DWARF operator %s cannot be translated to an agent expression"),
2223 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2224 "to an agent expression"),
2228 /* See dwarf2/loc.h.
2230 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2231 can issue a complaint, which is better than having every target's
2232 implementation of dwarf2_reg_to_regnum do it. */
2235 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2237 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2241 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2246 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2247 Throw an error because DWARF_REG is bad. */
2250 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2252 /* Still want to print -1 as "-1".
2253 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2254 but that's overkill for now. */
2255 if ((int) dwarf_reg
== dwarf_reg
)
2256 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2257 error (_("Unable to access DWARF register number %s"),
2258 pulongest (dwarf_reg
));
2261 /* See dwarf2/loc.h. */
2264 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2268 if (dwarf_reg
> INT_MAX
)
2269 throw_bad_regnum_error (dwarf_reg
);
2270 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2271 bad, but that's ok. */
2272 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2274 throw_bad_regnum_error (dwarf_reg
);
2278 /* A helper function that emits an access to memory. ARCH is the
2279 target architecture. EXPR is the expression which we are building.
2280 NBITS is the number of bits we want to read. This emits the
2281 opcodes needed to read the memory and then extract the desired
2285 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2287 ULONGEST nbytes
= (nbits
+ 7) / 8;
2289 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2292 ax_trace_quick (expr
, nbytes
);
2295 ax_simple (expr
, aop_ref8
);
2296 else if (nbits
<= 16)
2297 ax_simple (expr
, aop_ref16
);
2298 else if (nbits
<= 32)
2299 ax_simple (expr
, aop_ref32
);
2301 ax_simple (expr
, aop_ref64
);
2303 /* If we read exactly the number of bytes we wanted, we're done. */
2304 if (8 * nbytes
== nbits
)
2307 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2309 /* On a bits-big-endian machine, we want the high-order
2311 ax_const_l (expr
, 8 * nbytes
- nbits
);
2312 ax_simple (expr
, aop_rsh_unsigned
);
2316 /* On a bits-little-endian box, we want the low-order NBITS. */
2317 ax_zero_ext (expr
, nbits
);
2321 /* Compile a DWARF location expression to an agent expression.
2323 EXPR is the agent expression we are building.
2324 LOC is the agent value we modify.
2325 ARCH is the architecture.
2326 ADDR_SIZE is the size of addresses, in bytes.
2327 OP_PTR is the start of the location expression.
2328 OP_END is one past the last byte of the location expression.
2330 This will throw an exception for various kinds of errors -- for
2331 example, if the expression cannot be compiled, or if the expression
2335 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2336 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2337 const gdb_byte
*op_end
,
2338 dwarf2_per_cu_data
*per_cu
,
2339 dwarf2_per_objfile
*per_objfile
)
2341 gdbarch
*arch
= expr
->gdbarch
;
2342 std::vector
<int> dw_labels
, patches
;
2343 const gdb_byte
* const base
= op_ptr
;
2344 const gdb_byte
*previous_piece
= op_ptr
;
2345 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2346 ULONGEST bits_collected
= 0;
2347 unsigned int addr_size_bits
= 8 * addr_size
;
2348 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2350 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2352 /* By default we are making an address. */
2353 loc
->kind
= axs_lvalue_memory
;
2355 while (op_ptr
< op_end
)
2357 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2358 uint64_t uoffset
, reg
;
2362 offsets
[op_ptr
- base
] = expr
->len
;
2365 /* Our basic approach to code generation is to map DWARF
2366 operations directly to AX operations. However, there are
2369 First, DWARF works on address-sized units, but AX always uses
2370 LONGEST. For most operations we simply ignore this
2371 difference; instead we generate sign extensions as needed
2372 before division and comparison operations. It would be nice
2373 to omit the sign extensions, but there is no way to determine
2374 the size of the target's LONGEST. (This code uses the size
2375 of the host LONGEST in some cases -- that is a bug but it is
2378 Second, some DWARF operations cannot be translated to AX.
2379 For these we simply fail. See
2380 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2415 ax_const_l (expr
, op
- DW_OP_lit0
);
2419 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2420 op_ptr
+= addr_size
;
2421 /* Some versions of GCC emit DW_OP_addr before
2422 DW_OP_GNU_push_tls_address. In this case the value is an
2423 index, not an address. We don't support things like
2424 branching between the address and the TLS op. */
2425 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2426 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2427 ax_const_l (expr
, uoffset
);
2431 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2436 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2441 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2446 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2451 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2456 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2461 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2466 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2471 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2472 ax_const_l (expr
, uoffset
);
2476 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2477 ax_const_l (expr
, offset
);
2512 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2513 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2514 loc
->kind
= axs_lvalue_register
;
2518 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2519 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2520 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2521 loc
->kind
= axs_lvalue_register
;
2524 case DW_OP_implicit_value
:
2528 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2529 if (op_ptr
+ len
> op_end
)
2530 error (_("DW_OP_implicit_value: too few bytes available."));
2531 if (len
> sizeof (ULONGEST
))
2532 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2535 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2538 dwarf_expr_require_composition (op_ptr
, op_end
,
2539 "DW_OP_implicit_value");
2541 loc
->kind
= axs_rvalue
;
2545 case DW_OP_stack_value
:
2546 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2547 loc
->kind
= axs_rvalue
;
2582 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2583 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2587 ax_const_l (expr
, offset
);
2588 ax_simple (expr
, aop_add
);
2594 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2595 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2596 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2600 ax_const_l (expr
, offset
);
2601 ax_simple (expr
, aop_add
);
2608 const gdb_byte
*datastart
;
2610 const struct block
*b
;
2611 struct symbol
*framefunc
;
2613 b
= block_for_pc (expr
->scope
);
2616 error (_("No block found for address"));
2618 framefunc
= block_linkage_function (b
);
2621 error (_("No function found for block"));
2623 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2624 &datastart
, &datalen
);
2626 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2627 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2628 datastart
+ datalen
, per_cu
,
2630 if (loc
->kind
== axs_lvalue_register
)
2631 require_rvalue (expr
, loc
);
2635 ax_const_l (expr
, offset
);
2636 ax_simple (expr
, aop_add
);
2639 loc
->kind
= axs_lvalue_memory
;
2644 ax_simple (expr
, aop_dup
);
2648 ax_simple (expr
, aop_pop
);
2653 ax_pick (expr
, offset
);
2657 ax_simple (expr
, aop_swap
);
2665 ax_simple (expr
, aop_rot
);
2669 case DW_OP_deref_size
:
2673 if (op
== DW_OP_deref_size
)
2678 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2679 error (_("Unsupported size %d in %s"),
2680 size
, get_DW_OP_name (op
));
2681 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2686 /* Sign extend the operand. */
2687 ax_ext (expr
, addr_size_bits
);
2688 ax_simple (expr
, aop_dup
);
2689 ax_const_l (expr
, 0);
2690 ax_simple (expr
, aop_less_signed
);
2691 ax_simple (expr
, aop_log_not
);
2692 i
= ax_goto (expr
, aop_if_goto
);
2693 /* We have to emit 0 - X. */
2694 ax_const_l (expr
, 0);
2695 ax_simple (expr
, aop_swap
);
2696 ax_simple (expr
, aop_sub
);
2697 ax_label (expr
, i
, expr
->len
);
2701 /* No need to sign extend here. */
2702 ax_const_l (expr
, 0);
2703 ax_simple (expr
, aop_swap
);
2704 ax_simple (expr
, aop_sub
);
2708 /* Sign extend the operand. */
2709 ax_ext (expr
, addr_size_bits
);
2710 ax_simple (expr
, aop_bit_not
);
2713 case DW_OP_plus_uconst
:
2714 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2715 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2716 but we micro-optimize anyhow. */
2719 ax_const_l (expr
, reg
);
2720 ax_simple (expr
, aop_add
);
2725 ax_simple (expr
, aop_bit_and
);
2729 /* Sign extend the operands. */
2730 ax_ext (expr
, addr_size_bits
);
2731 ax_simple (expr
, aop_swap
);
2732 ax_ext (expr
, addr_size_bits
);
2733 ax_simple (expr
, aop_swap
);
2734 ax_simple (expr
, aop_div_signed
);
2738 ax_simple (expr
, aop_sub
);
2742 ax_simple (expr
, aop_rem_unsigned
);
2746 ax_simple (expr
, aop_mul
);
2750 ax_simple (expr
, aop_bit_or
);
2754 ax_simple (expr
, aop_add
);
2758 ax_simple (expr
, aop_lsh
);
2762 ax_simple (expr
, aop_rsh_unsigned
);
2766 ax_simple (expr
, aop_rsh_signed
);
2770 ax_simple (expr
, aop_bit_xor
);
2774 /* Sign extend the operands. */
2775 ax_ext (expr
, addr_size_bits
);
2776 ax_simple (expr
, aop_swap
);
2777 ax_ext (expr
, addr_size_bits
);
2778 /* Note no swap here: A <= B is !(B < A). */
2779 ax_simple (expr
, aop_less_signed
);
2780 ax_simple (expr
, aop_log_not
);
2784 /* Sign extend the operands. */
2785 ax_ext (expr
, addr_size_bits
);
2786 ax_simple (expr
, aop_swap
);
2787 ax_ext (expr
, addr_size_bits
);
2788 ax_simple (expr
, aop_swap
);
2789 /* A >= B is !(A < B). */
2790 ax_simple (expr
, aop_less_signed
);
2791 ax_simple (expr
, aop_log_not
);
2795 /* Sign extend the operands. */
2796 ax_ext (expr
, addr_size_bits
);
2797 ax_simple (expr
, aop_swap
);
2798 ax_ext (expr
, addr_size_bits
);
2799 /* No need for a second swap here. */
2800 ax_simple (expr
, aop_equal
);
2804 /* Sign extend the operands. */
2805 ax_ext (expr
, addr_size_bits
);
2806 ax_simple (expr
, aop_swap
);
2807 ax_ext (expr
, addr_size_bits
);
2808 ax_simple (expr
, aop_swap
);
2809 ax_simple (expr
, aop_less_signed
);
2813 /* Sign extend the operands. */
2814 ax_ext (expr
, addr_size_bits
);
2815 ax_simple (expr
, aop_swap
);
2816 ax_ext (expr
, addr_size_bits
);
2817 /* Note no swap here: A > B is B < A. */
2818 ax_simple (expr
, aop_less_signed
);
2822 /* Sign extend the operands. */
2823 ax_ext (expr
, addr_size_bits
);
2824 ax_simple (expr
, aop_swap
);
2825 ax_ext (expr
, addr_size_bits
);
2826 /* No need for a swap here. */
2827 ax_simple (expr
, aop_equal
);
2828 ax_simple (expr
, aop_log_not
);
2831 case DW_OP_call_frame_cfa
:
2834 CORE_ADDR text_offset
;
2836 const gdb_byte
*cfa_start
, *cfa_end
;
2838 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2840 &text_offset
, &cfa_start
, &cfa_end
))
2843 ax_reg (expr
, regnum
);
2846 ax_const_l (expr
, off
);
2847 ax_simple (expr
, aop_add
);
2852 /* Another expression. */
2853 ax_const_l (expr
, text_offset
);
2854 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2855 cfa_end
, per_cu
, per_objfile
);
2858 loc
->kind
= axs_lvalue_memory
;
2862 case DW_OP_GNU_push_tls_address
:
2863 case DW_OP_form_tls_address
:
2867 case DW_OP_push_object_address
:
2872 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2874 i
= ax_goto (expr
, aop_goto
);
2875 dw_labels
.push_back (op_ptr
+ offset
- base
);
2876 patches
.push_back (i
);
2880 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2882 /* Zero extend the operand. */
2883 ax_zero_ext (expr
, addr_size_bits
);
2884 i
= ax_goto (expr
, aop_if_goto
);
2885 dw_labels
.push_back (op_ptr
+ offset
- base
);
2886 patches
.push_back (i
);
2893 case DW_OP_bit_piece
:
2897 if (op_ptr
- 1 == previous_piece
)
2898 error (_("Cannot translate empty pieces to agent expressions"));
2899 previous_piece
= op_ptr
- 1;
2901 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2902 if (op
== DW_OP_piece
)
2908 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2910 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2911 error (_("Expression pieces exceed word size"));
2913 /* Access the bits. */
2916 case axs_lvalue_register
:
2917 ax_reg (expr
, loc
->u
.reg
);
2920 case axs_lvalue_memory
:
2921 /* Offset the pointer, if needed. */
2924 ax_const_l (expr
, uoffset
/ 8);
2925 ax_simple (expr
, aop_add
);
2928 access_memory (arch
, expr
, size
);
2932 /* For a bits-big-endian target, shift up what we already
2933 have. For a bits-little-endian target, shift up the
2934 new data. Note that there is a potential bug here if
2935 the DWARF expression leaves multiple values on the
2937 if (bits_collected
> 0)
2939 if (bits_big_endian
)
2941 ax_simple (expr
, aop_swap
);
2942 ax_const_l (expr
, size
);
2943 ax_simple (expr
, aop_lsh
);
2944 /* We don't need a second swap here, because
2945 aop_bit_or is symmetric. */
2949 ax_const_l (expr
, size
);
2950 ax_simple (expr
, aop_lsh
);
2952 ax_simple (expr
, aop_bit_or
);
2955 bits_collected
+= size
;
2956 loc
->kind
= axs_rvalue
;
2960 case DW_OP_GNU_uninit
:
2966 struct dwarf2_locexpr_baton block
;
2967 int size
= (op
== DW_OP_call2
? 2 : 4);
2969 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2972 auto get_frame_pc_from_expr
= [expr
] ()
2976 cu_offset cuoffset
= (cu_offset
) uoffset
;
2977 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
2978 get_frame_pc_from_expr
);
2980 /* DW_OP_call_ref is currently not supported. */
2981 gdb_assert (block
.per_cu
== per_cu
);
2983 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
2984 block
.data
+ block
.size
, per_cu
,
2989 case DW_OP_call_ref
:
2992 case DW_OP_GNU_variable_value
:
3000 /* Patch all the branches we emitted. */
3001 for (int i
= 0; i
< patches
.size (); ++i
)
3003 int targ
= offsets
[dw_labels
[i
]];
3005 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3006 ax_label (expr
, patches
[i
], targ
);
3011 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3012 evaluator to calculate the location. */
3013 static struct value
*
3014 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3016 struct dwarf2_locexpr_baton
*dlbaton
3017 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3020 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, dlbaton
->data
,
3021 dlbaton
->size
, dlbaton
->per_cu
,
3022 dlbaton
->per_objfile
);
3027 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3028 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3031 static struct value
*
3032 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3034 struct dwarf2_locexpr_baton
*dlbaton
3035 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3037 return value_of_dwarf_block_entry (symbol
->type (), frame
, dlbaton
->data
,
3041 /* Implementation of get_symbol_read_needs from
3042 symbol_computed_ops. */
3044 static enum symbol_needs_kind
3045 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3047 struct dwarf2_locexpr_baton
*dlbaton
3048 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3050 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3051 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3053 return dwarf2_get_symbol_read_needs (expr
,
3055 dlbaton
->per_objfile
,
3056 gdbarch_byte_order (arch
),
3057 dlbaton
->per_cu
->addr_size (),
3058 dlbaton
->per_cu
->ref_addr_size ());
3061 /* Return true if DATA points to the end of a piece. END is one past
3062 the last byte in the expression. */
3065 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3067 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3070 /* Helper for locexpr_describe_location_piece that finds the name of a
3074 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3078 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3079 We'd rather print *something* here than throw an error. */
3080 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3081 /* gdbarch_register_name may just return "", return something more
3082 descriptive for bad register numbers. */
3085 /* The text is output as "$bad_register_number".
3086 That is why we use the underscores. */
3087 return _("bad_register_number");
3089 return gdbarch_register_name (gdbarch
, regnum
);
3092 /* Nicely describe a single piece of a location, returning an updated
3093 position in the bytecode sequence. This function cannot recognize
3094 all locations; if a location is not recognized, it simply returns
3095 DATA. If there is an error during reading, e.g. we run off the end
3096 of the buffer, an error is thrown. */
3098 static const gdb_byte
*
3099 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3100 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3101 dwarf2_per_objfile
*per_objfile
,
3102 const gdb_byte
*data
, const gdb_byte
*end
,
3103 unsigned int addr_size
)
3105 objfile
*objfile
= per_objfile
->objfile
;
3106 struct gdbarch
*gdbarch
= objfile
->arch ();
3109 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3111 fprintf_filtered (stream
, _("a variable in $%s"),
3112 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3115 else if (data
[0] == DW_OP_regx
)
3119 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3120 fprintf_filtered (stream
, _("a variable in $%s"),
3121 locexpr_regname (gdbarch
, reg
));
3123 else if (data
[0] == DW_OP_fbreg
)
3125 const struct block
*b
;
3126 struct symbol
*framefunc
;
3128 int64_t frame_offset
;
3129 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3131 int64_t base_offset
= 0;
3133 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3134 if (!piece_end_p (new_data
, end
))
3138 b
= block_for_pc (addr
);
3141 error (_("No block found for address for symbol \"%s\"."),
3142 symbol
->print_name ());
3144 framefunc
= block_linkage_function (b
);
3147 error (_("No function found for block for symbol \"%s\"."),
3148 symbol
->print_name ());
3150 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3152 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3154 const gdb_byte
*buf_end
;
3156 frame_reg
= base_data
[0] - DW_OP_breg0
;
3157 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3159 if (buf_end
!= base_data
+ base_size
)
3160 error (_("Unexpected opcode after "
3161 "DW_OP_breg%u for symbol \"%s\"."),
3162 frame_reg
, symbol
->print_name ());
3164 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3166 /* The frame base is just the register, with no offset. */
3167 frame_reg
= base_data
[0] - DW_OP_reg0
;
3172 /* We don't know what to do with the frame base expression,
3173 so we can't trace this variable; give up. */
3177 fprintf_filtered (stream
,
3178 _("a variable at frame base reg $%s offset %s+%s"),
3179 locexpr_regname (gdbarch
, frame_reg
),
3180 plongest (base_offset
), plongest (frame_offset
));
3182 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3183 && piece_end_p (data
, end
))
3187 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3189 fprintf_filtered (stream
,
3190 _("a variable at offset %s from base reg $%s"),
3192 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3195 /* The location expression for a TLS variable looks like this (on a
3198 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3199 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3201 0x3 is the encoding for DW_OP_addr, which has an operand as long
3202 as the size of an address on the target machine (here is 8
3203 bytes). Note that more recent version of GCC emit DW_OP_const4u
3204 or DW_OP_const8u, depending on address size, rather than
3205 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3206 The operand represents the offset at which the variable is within
3207 the thread local storage. */
3209 else if (data
+ 1 + addr_size
< end
3210 && (data
[0] == DW_OP_addr
3211 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3212 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3213 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3214 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3215 && piece_end_p (data
+ 2 + addr_size
, end
))
3218 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3219 gdbarch_byte_order (gdbarch
));
3221 fprintf_filtered (stream
,
3222 _("a thread-local variable at offset 0x%s "
3223 "in the thread-local storage for `%s'"),
3224 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3226 data
+= 1 + addr_size
+ 1;
3229 /* With -gsplit-dwarf a TLS variable can also look like this:
3230 DW_AT_location : 3 byte block: fc 4 e0
3231 (DW_OP_GNU_const_index: 4;
3232 DW_OP_GNU_push_tls_address) */
3233 else if (data
+ 3 <= end
3234 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3235 && data
[0] == DW_OP_GNU_const_index
3237 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3238 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3239 && piece_end_p (data
+ 2 + leb128_size
, end
))
3243 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3244 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3245 fprintf_filtered (stream
,
3246 _("a thread-local variable at offset 0x%s "
3247 "in the thread-local storage for `%s'"),
3248 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3252 else if (data
[0] >= DW_OP_lit0
3253 && data
[0] <= DW_OP_lit31
3255 && data
[1] == DW_OP_stack_value
)
3257 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3264 /* Disassemble an expression, stopping at the end of a piece or at the
3265 end of the expression. Returns a pointer to the next unread byte
3266 in the input expression. If ALL is nonzero, then this function
3267 will keep going until it reaches the end of the expression.
3268 If there is an error during reading, e.g. we run off the end
3269 of the buffer, an error is thrown. */
3271 static const gdb_byte
*
3272 disassemble_dwarf_expression (struct ui_file
*stream
,
3273 struct gdbarch
*arch
, unsigned int addr_size
,
3274 int offset_size
, const gdb_byte
*start
,
3275 const gdb_byte
*data
, const gdb_byte
*end
,
3276 int indent
, int all
,
3277 dwarf2_per_cu_data
*per_cu
,
3278 dwarf2_per_objfile
*per_objfile
)
3282 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3284 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3289 name
= get_DW_OP_name (op
);
3292 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3293 op
, (long) (data
- 1 - start
));
3294 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3295 (long) (data
- 1 - start
), name
);
3300 ul
= extract_unsigned_integer (data
, addr_size
,
3301 gdbarch_byte_order (arch
));
3303 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3307 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3309 fprintf_filtered (stream
, " %s", pulongest (ul
));
3313 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3315 fprintf_filtered (stream
, " %s", plongest (l
));
3319 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3321 fprintf_filtered (stream
, " %s", pulongest (ul
));
3325 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3327 fprintf_filtered (stream
, " %s", plongest (l
));
3331 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3333 fprintf_filtered (stream
, " %s", pulongest (ul
));
3337 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3339 fprintf_filtered (stream
, " %s", plongest (l
));
3343 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3345 fprintf_filtered (stream
, " %s", pulongest (ul
));
3349 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3351 fprintf_filtered (stream
, " %s", plongest (l
));
3355 data
= safe_read_uleb128 (data
, end
, &ul
);
3356 fprintf_filtered (stream
, " %s", pulongest (ul
));
3360 data
= safe_read_sleb128 (data
, end
, &l
);
3361 fprintf_filtered (stream
, " %s", plongest (l
));
3396 fprintf_filtered (stream
, " [$%s]",
3397 locexpr_regname (arch
, op
- DW_OP_reg0
));
3401 data
= safe_read_uleb128 (data
, end
, &ul
);
3402 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3403 locexpr_regname (arch
, (int) ul
));
3406 case DW_OP_implicit_value
:
3407 data
= safe_read_uleb128 (data
, end
, &ul
);
3409 fprintf_filtered (stream
, " %s", pulongest (ul
));
3444 data
= safe_read_sleb128 (data
, end
, &l
);
3445 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3446 locexpr_regname (arch
, op
- DW_OP_breg0
));
3450 data
= safe_read_uleb128 (data
, end
, &ul
);
3451 data
= safe_read_sleb128 (data
, end
, &l
);
3452 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3454 locexpr_regname (arch
, (int) ul
),
3459 data
= safe_read_sleb128 (data
, end
, &l
);
3460 fprintf_filtered (stream
, " %s", plongest (l
));
3463 case DW_OP_xderef_size
:
3464 case DW_OP_deref_size
:
3466 fprintf_filtered (stream
, " %d", *data
);
3470 case DW_OP_plus_uconst
:
3471 data
= safe_read_uleb128 (data
, end
, &ul
);
3472 fprintf_filtered (stream
, " %s", pulongest (ul
));
3476 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3478 fprintf_filtered (stream
, " to %ld",
3479 (long) (data
+ l
- start
));
3483 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3485 fprintf_filtered (stream
, " %ld",
3486 (long) (data
+ l
- start
));
3490 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3492 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3496 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3498 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3501 case DW_OP_call_ref
:
3502 ul
= extract_unsigned_integer (data
, offset_size
,
3503 gdbarch_byte_order (arch
));
3504 data
+= offset_size
;
3505 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3509 data
= safe_read_uleb128 (data
, end
, &ul
);
3510 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3513 case DW_OP_bit_piece
:
3517 data
= safe_read_uleb128 (data
, end
, &ul
);
3518 data
= safe_read_uleb128 (data
, end
, &offset
);
3519 fprintf_filtered (stream
, " size %s offset %s (bits)",
3520 pulongest (ul
), pulongest (offset
));
3524 case DW_OP_implicit_pointer
:
3525 case DW_OP_GNU_implicit_pointer
:
3527 ul
= extract_unsigned_integer (data
, offset_size
,
3528 gdbarch_byte_order (arch
));
3529 data
+= offset_size
;
3531 data
= safe_read_sleb128 (data
, end
, &l
);
3533 fprintf_filtered (stream
, " DIE %s offset %s",
3534 phex_nz (ul
, offset_size
),
3539 case DW_OP_deref_type
:
3540 case DW_OP_GNU_deref_type
:
3542 int deref_addr_size
= *data
++;
3545 data
= safe_read_uleb128 (data
, end
, &ul
);
3546 cu_offset offset
= (cu_offset
) ul
;
3547 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3548 fprintf_filtered (stream
, "<");
3549 type_print (type
, "", stream
, -1);
3550 fprintf_filtered (stream
, " [0x%s]> %d",
3551 phex_nz (to_underlying (offset
), 0),
3556 case DW_OP_const_type
:
3557 case DW_OP_GNU_const_type
:
3561 data
= safe_read_uleb128 (data
, end
, &ul
);
3562 cu_offset type_die
= (cu_offset
) ul
;
3563 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3564 fprintf_filtered (stream
, "<");
3565 type_print (type
, "", stream
, -1);
3566 fprintf_filtered (stream
, " [0x%s]>",
3567 phex_nz (to_underlying (type_die
), 0));
3570 fprintf_filtered (stream
, " %d byte block:", n
);
3571 for (int i
= 0; i
< n
; ++i
)
3572 fprintf_filtered (stream
, " %02x", data
[i
]);
3577 case DW_OP_regval_type
:
3578 case DW_OP_GNU_regval_type
:
3583 data
= safe_read_uleb128 (data
, end
, ®
);
3584 data
= safe_read_uleb128 (data
, end
, &ul
);
3585 cu_offset type_die
= (cu_offset
) ul
;
3587 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3588 fprintf_filtered (stream
, "<");
3589 type_print (type
, "", stream
, -1);
3590 fprintf_filtered (stream
, " [0x%s]> [$%s]",
3591 phex_nz (to_underlying (type_die
), 0),
3592 locexpr_regname (arch
, reg
));
3597 case DW_OP_GNU_convert
:
3598 case DW_OP_reinterpret
:
3599 case DW_OP_GNU_reinterpret
:
3601 data
= safe_read_uleb128 (data
, end
, &ul
);
3602 cu_offset type_die
= (cu_offset
) ul
;
3604 if (to_underlying (type_die
) == 0)
3605 fprintf_filtered (stream
, "<0>");
3610 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3611 fprintf_filtered (stream
, "<");
3612 type_print (type
, "", stream
, -1);
3613 fprintf_filtered (stream
, " [0x%s]>",
3614 phex_nz (to_underlying (type_die
), 0));
3619 case DW_OP_entry_value
:
3620 case DW_OP_GNU_entry_value
:
3621 data
= safe_read_uleb128 (data
, end
, &ul
);
3622 fputc_filtered ('\n', stream
);
3623 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3624 start
, data
, data
+ ul
, indent
+ 2,
3625 all
, per_cu
, per_objfile
);
3629 case DW_OP_GNU_parameter_ref
:
3630 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3632 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3636 case DW_OP_GNU_addr_index
:
3637 data
= safe_read_uleb128 (data
, end
, &ul
);
3638 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3639 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3642 case DW_OP_GNU_const_index
:
3643 data
= safe_read_uleb128 (data
, end
, &ul
);
3644 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3645 fprintf_filtered (stream
, " %s", pulongest (ul
));
3648 case DW_OP_GNU_variable_value
:
3649 ul
= extract_unsigned_integer (data
, offset_size
,
3650 gdbarch_byte_order (arch
));
3651 data
+= offset_size
;
3652 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3656 fprintf_filtered (stream
, "\n");
3662 static bool dwarf_always_disassemble
;
3665 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3666 struct cmd_list_element
*c
, const char *value
)
3668 fprintf_filtered (file
,
3669 _("Whether to always disassemble "
3670 "DWARF expressions is %s.\n"),
3674 /* Describe a single location, which may in turn consist of multiple
3678 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3679 struct ui_file
*stream
,
3680 const gdb_byte
*data
, size_t size
,
3681 unsigned int addr_size
,
3682 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3683 dwarf2_per_objfile
*per_objfile
)
3685 const gdb_byte
*end
= data
+ size
;
3686 int first_piece
= 1, bad
= 0;
3687 objfile
*objfile
= per_objfile
->objfile
;
3691 const gdb_byte
*here
= data
;
3692 int disassemble
= 1;
3697 fprintf_filtered (stream
, _(", and "));
3699 if (!dwarf_always_disassemble
)
3701 data
= locexpr_describe_location_piece (symbol
, stream
,
3702 addr
, per_cu
, per_objfile
,
3703 data
, end
, addr_size
);
3704 /* If we printed anything, or if we have an empty piece,
3705 then don't disassemble. */
3707 || data
[0] == DW_OP_piece
3708 || data
[0] == DW_OP_bit_piece
)
3713 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3714 data
= disassemble_dwarf_expression (stream
,
3716 addr_size
, offset_size
, data
,
3718 dwarf_always_disassemble
,
3719 per_cu
, per_objfile
);
3724 int empty
= data
== here
;
3727 fprintf_filtered (stream
, " ");
3728 if (data
[0] == DW_OP_piece
)
3732 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3735 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3738 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3741 else if (data
[0] == DW_OP_bit_piece
)
3743 uint64_t bits
, offset
;
3745 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3746 data
= safe_read_uleb128 (data
, end
, &offset
);
3749 fprintf_filtered (stream
,
3750 _("an empty %s-bit piece"),
3753 fprintf_filtered (stream
,
3754 _(" [%s-bit piece, offset %s bits]"),
3755 pulongest (bits
), pulongest (offset
));
3765 if (bad
|| data
> end
)
3766 error (_("Corrupted DWARF2 expression for \"%s\"."),
3767 symbol
->print_name ());
3770 /* Print a natural-language description of SYMBOL to STREAM. This
3771 version is for a symbol with a single location. */
3774 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3775 struct ui_file
*stream
)
3777 struct dwarf2_locexpr_baton
*dlbaton
3778 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3779 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3780 int offset_size
= dlbaton
->per_cu
->offset_size ();
3782 locexpr_describe_location_1 (symbol
, addr
, stream
,
3783 dlbaton
->data
, dlbaton
->size
,
3784 addr_size
, offset_size
,
3785 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3788 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3789 any necessary bytecode in AX. */
3792 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3793 struct axs_value
*value
)
3795 struct dwarf2_locexpr_baton
*dlbaton
3796 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3797 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3799 if (dlbaton
->size
== 0)
3800 value
->optimized_out
= 1;
3802 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3803 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3804 dlbaton
->per_objfile
);
3807 /* symbol_computed_ops 'generate_c_location' method. */
3810 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3811 struct gdbarch
*gdbarch
,
3812 std::vector
<bool> ®isters_used
,
3813 CORE_ADDR pc
, const char *result_name
)
3815 struct dwarf2_locexpr_baton
*dlbaton
3816 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3817 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3819 if (dlbaton
->size
== 0)
3820 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3822 compile_dwarf_expr_to_c (stream
, result_name
,
3823 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3824 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3825 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3828 /* The set of location functions used with the DWARF-2 expression
3830 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3831 locexpr_read_variable
,
3832 locexpr_read_variable_at_entry
,
3833 locexpr_get_symbol_read_needs
,
3834 locexpr_describe_location
,
3835 0, /* location_has_loclist */
3836 locexpr_tracepoint_var_ref
,
3837 locexpr_generate_c_location
3841 /* Wrapper functions for location lists. These generally find
3842 the appropriate location expression and call something above. */
3844 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3845 evaluator to calculate the location. */
3846 static struct value
*
3847 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3849 struct dwarf2_loclist_baton
*dlbaton
3850 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3852 const gdb_byte
*data
;
3854 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3856 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3857 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, data
, size
,
3858 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3863 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3864 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3867 Function always returns non-NULL value, it may be marked optimized out if
3868 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3869 if it cannot resolve the parameter for any reason. */
3871 static struct value
*
3872 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3874 struct dwarf2_loclist_baton
*dlbaton
3875 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3876 const gdb_byte
*data
;
3880 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3881 return allocate_optimized_out_value (symbol
->type ());
3883 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3885 return allocate_optimized_out_value (symbol
->type ());
3887 return value_of_dwarf_block_entry (symbol
->type (), frame
, data
, size
);
3890 /* Implementation of get_symbol_read_needs from
3891 symbol_computed_ops. */
3893 static enum symbol_needs_kind
3894 loclist_symbol_needs (struct symbol
*symbol
)
3896 /* If there's a location list, then assume we need to have a frame
3897 to choose the appropriate location expression. With tracking of
3898 global variables this is not necessarily true, but such tracking
3899 is disabled in GCC at the moment until we figure out how to
3902 return SYMBOL_NEEDS_FRAME
;
3905 /* Print a natural-language description of SYMBOL to STREAM. This
3906 version applies when there is a list of different locations, each
3907 with a specified address range. */
3910 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3911 struct ui_file
*stream
)
3913 struct dwarf2_loclist_baton
*dlbaton
3914 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3915 const gdb_byte
*loc_ptr
, *buf_end
;
3916 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3917 struct objfile
*objfile
= per_objfile
->objfile
;
3918 struct gdbarch
*gdbarch
= objfile
->arch ();
3919 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3920 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3921 int offset_size
= dlbaton
->per_cu
->offset_size ();
3922 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3923 /* Adjustment for relocatable objects. */
3924 CORE_ADDR text_offset
= objfile
->text_section_offset ();
3925 CORE_ADDR base_address
= dlbaton
->base_address
;
3928 loc_ptr
= dlbaton
->data
;
3929 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3931 fprintf_filtered (stream
, _("multi-location:\n"));
3933 /* Iterate through locations until we run out. */
3936 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
3938 enum debug_loc_kind kind
;
3939 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3941 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3942 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3943 dlbaton
->per_objfile
,
3944 loc_ptr
, buf_end
, &new_ptr
,
3945 &low
, &high
, byte_order
);
3946 else if (dlbaton
->per_cu
->version () < 5)
3947 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3949 byte_order
, addr_size
,
3952 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3953 dlbaton
->per_objfile
,
3954 loc_ptr
, buf_end
, &new_ptr
,
3955 &low
, &high
, byte_order
,
3956 addr_size
, signed_addr_p
);
3960 case DEBUG_LOC_END_OF_LIST
:
3964 case DEBUG_LOC_BASE_ADDRESS
:
3965 base_address
= high
;
3966 fprintf_filtered (stream
, _(" Base address %s"),
3967 paddress (gdbarch
, base_address
));
3970 case DEBUG_LOC_START_END
:
3971 case DEBUG_LOC_START_LENGTH
:
3972 case DEBUG_LOC_OFFSET_PAIR
:
3975 case DEBUG_LOC_BUFFER_OVERFLOW
:
3976 case DEBUG_LOC_INVALID_ENTRY
:
3977 error (_("Corrupted DWARF expression for symbol \"%s\"."),
3978 symbol
->print_name ());
3981 gdb_assert_not_reached ("bad debug_loc_kind");
3984 /* Otherwise, a location expression entry. */
3986 high
+= text_offset
;
3987 if (!dlbaton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
3989 low
+= base_address
;
3990 high
+= base_address
;
3993 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
3994 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
3996 if (dlbaton
->per_cu
->version () < 5)
3998 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4003 unsigned int bytes_read
;
4004 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4005 loc_ptr
+= bytes_read
;
4008 /* (It would improve readability to print only the minimum
4009 necessary digits of the second number of the range.) */
4010 fprintf_filtered (stream
, _(" Range %s-%s: "),
4011 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4013 /* Now describe this particular location. */
4014 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4015 addr_size
, offset_size
,
4016 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4018 fprintf_filtered (stream
, "\n");
4024 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4025 any necessary bytecode in AX. */
4027 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4028 struct axs_value
*value
)
4030 struct dwarf2_loclist_baton
*dlbaton
4031 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4032 const gdb_byte
*data
;
4034 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4036 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4038 value
->optimized_out
= 1;
4040 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4041 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4044 /* symbol_computed_ops 'generate_c_location' method. */
4047 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4048 struct gdbarch
*gdbarch
,
4049 std::vector
<bool> ®isters_used
,
4050 CORE_ADDR pc
, const char *result_name
)
4052 struct dwarf2_loclist_baton
*dlbaton
4053 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4054 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4055 const gdb_byte
*data
;
4058 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4060 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4062 compile_dwarf_expr_to_c (stream
, result_name
,
4063 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4066 dlbaton
->per_objfile
);
4069 /* The set of location functions used with the DWARF-2 expression
4070 evaluator and location lists. */
4071 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4072 loclist_read_variable
,
4073 loclist_read_variable_at_entry
,
4074 loclist_symbol_needs
,
4075 loclist_describe_location
,
4076 1, /* location_has_loclist */
4077 loclist_tracepoint_var_ref
,
4078 loclist_generate_c_location
4081 void _initialize_dwarf2loc ();
4083 _initialize_dwarf2loc ()
4085 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4086 &entry_values_debug
,
4087 _("Set entry values and tail call frames "
4089 _("Show entry values and tail call frames "
4091 _("When non-zero, the process of determining "
4092 "parameter values from function entry point "
4093 "and tail call frames will be printed."),
4095 show_entry_values_debug
,
4096 &setdebuglist
, &showdebuglist
);
4098 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4099 &dwarf_always_disassemble
, _("\
4100 Set whether `info address' always disassembles DWARF expressions."), _("\
4101 Show whether `info address' always disassembles DWARF expressions."), _("\
4102 When enabled, DWARF expressions are always printed in an assembly-like\n\
4103 syntax. When disabled, expressions will be printed in a more\n\
4104 conversational style, when possible."),
4106 show_dwarf_always_disassemble
,
4108 &show_dwarf_cmdlist
);