1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2021 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 return DEBUG_LOC_START_END
;
145 /* Decode the addresses in .debug_loclists entry.
146 A pointer to the next byte to examine is returned in *NEW_PTR.
147 The encoded low,high addresses are return in *LOW,*HIGH.
148 The result indicates the kind of entry found. */
150 static enum debug_loc_kind
151 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
152 dwarf2_per_objfile
*per_objfile
,
153 const gdb_byte
*loc_ptr
,
154 const gdb_byte
*buf_end
,
155 const gdb_byte
**new_ptr
,
156 CORE_ADDR
*low
, CORE_ADDR
*high
,
157 enum bfd_endian byte_order
,
158 unsigned int addr_size
,
163 if (loc_ptr
== buf_end
)
164 return DEBUG_LOC_BUFFER_OVERFLOW
;
168 case DW_LLE_base_addressx
:
170 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
172 return DEBUG_LOC_BUFFER_OVERFLOW
;
174 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
176 return DEBUG_LOC_BASE_ADDRESS
;
178 case DW_LLE_startx_length
:
179 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
181 return DEBUG_LOC_BUFFER_OVERFLOW
;
183 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
185 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
187 return DEBUG_LOC_BUFFER_OVERFLOW
;
191 return DEBUG_LOC_START_LENGTH
;
193 case DW_LLE_start_length
:
194 if (buf_end
- loc_ptr
< addr_size
)
195 return DEBUG_LOC_BUFFER_OVERFLOW
;
198 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
200 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
202 loc_ptr
+= addr_size
;
205 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
207 return DEBUG_LOC_BUFFER_OVERFLOW
;
211 return DEBUG_LOC_START_LENGTH
;
213 case DW_LLE_end_of_list
:
215 return DEBUG_LOC_END_OF_LIST
;
217 case DW_LLE_base_address
:
218 if (loc_ptr
+ addr_size
> buf_end
)
219 return DEBUG_LOC_BUFFER_OVERFLOW
;
222 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
224 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
226 loc_ptr
+= addr_size
;
228 return DEBUG_LOC_BASE_ADDRESS
;
230 case DW_LLE_offset_pair
:
231 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
233 return DEBUG_LOC_BUFFER_OVERFLOW
;
236 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
238 return DEBUG_LOC_BUFFER_OVERFLOW
;
242 return DEBUG_LOC_OFFSET_PAIR
;
244 case DW_LLE_start_end
:
245 if (loc_ptr
+ 2 * addr_size
> buf_end
)
246 return DEBUG_LOC_BUFFER_OVERFLOW
;
249 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
251 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
253 loc_ptr
+= addr_size
;
255 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
257 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
259 loc_ptr
+= addr_size
;
261 return DEBUG_LOC_START_END
;
263 /* Following cases are not supported yet. */
264 case DW_LLE_startx_endx
:
265 case DW_LLE_default_location
:
267 return DEBUG_LOC_INVALID_ENTRY
;
271 /* Decode the addresses in .debug_loc.dwo entry.
272 A pointer to the next byte to examine is returned in *NEW_PTR.
273 The encoded low,high addresses are return in *LOW,*HIGH.
274 The result indicates the kind of entry found. */
276 static enum debug_loc_kind
277 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
278 dwarf2_per_objfile
*per_objfile
,
279 const gdb_byte
*loc_ptr
,
280 const gdb_byte
*buf_end
,
281 const gdb_byte
**new_ptr
,
282 CORE_ADDR
*low
, CORE_ADDR
*high
,
283 enum bfd_endian byte_order
)
285 uint64_t low_index
, high_index
;
287 if (loc_ptr
== buf_end
)
288 return DEBUG_LOC_BUFFER_OVERFLOW
;
292 case DW_LLE_GNU_end_of_list_entry
:
294 return DEBUG_LOC_END_OF_LIST
;
296 case DW_LLE_GNU_base_address_selection_entry
:
298 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
300 return DEBUG_LOC_BUFFER_OVERFLOW
;
302 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
304 return DEBUG_LOC_BASE_ADDRESS
;
306 case DW_LLE_GNU_start_end_entry
:
307 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
309 return DEBUG_LOC_BUFFER_OVERFLOW
;
311 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
312 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
314 return DEBUG_LOC_BUFFER_OVERFLOW
;
316 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
318 return DEBUG_LOC_START_END
;
320 case DW_LLE_GNU_start_length_entry
:
321 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
323 return DEBUG_LOC_BUFFER_OVERFLOW
;
325 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
326 if (loc_ptr
+ 4 > buf_end
)
327 return DEBUG_LOC_BUFFER_OVERFLOW
;
330 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
331 *new_ptr
= loc_ptr
+ 4;
332 return DEBUG_LOC_START_LENGTH
;
335 return DEBUG_LOC_INVALID_ENTRY
;
339 /* A function for dealing with location lists. Given a
340 symbol baton (BATON) and a pc value (PC), find the appropriate
341 location expression, set *LOCEXPR_LENGTH, and return a pointer
342 to the beginning of the expression. Returns NULL on failure.
344 For now, only return the first matching location expression; there
345 can be more than one in the list. */
348 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
349 size_t *locexpr_length
, CORE_ADDR pc
)
351 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
352 struct objfile
*objfile
= per_objfile
->objfile
;
353 struct gdbarch
*gdbarch
= objfile
->arch ();
354 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
355 unsigned int addr_size
= baton
->per_cu
->addr_size ();
356 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
357 /* Adjust base_address for relocatable objects. */
358 CORE_ADDR base_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
359 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
360 const gdb_byte
*loc_ptr
, *buf_end
;
362 loc_ptr
= baton
->data
;
363 buf_end
= baton
->data
+ baton
->size
;
367 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
369 enum debug_loc_kind kind
;
370 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
372 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
373 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
375 loc_ptr
, buf_end
, &new_ptr
,
376 &low
, &high
, byte_order
);
377 else if (baton
->per_cu
->version () < 5)
378 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
380 byte_order
, addr_size
,
383 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
385 loc_ptr
, buf_end
, &new_ptr
,
386 &low
, &high
, byte_order
,
387 addr_size
, signed_addr_p
);
392 case DEBUG_LOC_END_OF_LIST
:
396 case DEBUG_LOC_BASE_ADDRESS
:
397 base_address
= high
+ base_offset
;
400 case DEBUG_LOC_START_END
:
401 case DEBUG_LOC_START_LENGTH
:
402 case DEBUG_LOC_OFFSET_PAIR
:
405 case DEBUG_LOC_BUFFER_OVERFLOW
:
406 case DEBUG_LOC_INVALID_ENTRY
:
407 error (_("dwarf2_find_location_expression: "
408 "Corrupted DWARF expression."));
411 gdb_assert_not_reached ("bad debug_loc_kind");
414 /* Otherwise, a location expression entry.
415 If the entry is from a DWO, don't add base address: the entry is from
416 .debug_addr which already has the DWARF "base address". We still add
417 base_offset in case we're debugging a PIE executable. However, if the
418 entry is DW_LLE_offset_pair from a DWO, add the base address as the
419 operands are offsets relative to the applicable base address. */
420 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
428 high
+= base_address
;
431 if (baton
->per_cu
->version () < 5)
433 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
438 unsigned int bytes_read
;
440 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
441 loc_ptr
+= bytes_read
;
444 if (low
== high
&& pc
== low
)
446 /* This is entry PC record present only at entry point
447 of a function. Verify it is really the function entry point. */
449 const struct block
*pc_block
= block_for_pc (pc
);
450 struct symbol
*pc_func
= NULL
;
453 pc_func
= block_linkage_function (pc_block
);
455 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
457 *locexpr_length
= length
;
462 if (pc
>= low
&& pc
< high
)
464 *locexpr_length
= length
;
472 /* Implement find_frame_base_location method for LOC_BLOCK functions using
473 DWARF expression for its DW_AT_frame_base. */
476 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
477 const gdb_byte
**start
, size_t *length
)
479 struct dwarf2_locexpr_baton
*symbaton
480 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
482 *length
= symbaton
->size
;
483 *start
= symbaton
->data
;
486 /* Implement the struct symbol_block_ops::get_frame_base method for
487 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
490 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
492 struct gdbarch
*gdbarch
;
494 struct dwarf2_locexpr_baton
*dlbaton
;
495 const gdb_byte
*start
;
497 struct value
*result
;
499 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
500 Thus, it's supposed to provide the find_frame_base_location method as
502 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
504 gdbarch
= get_frame_arch (frame
);
505 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
506 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
508 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
509 (framefunc
, get_frame_pc (frame
), &start
, &length
);
510 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
511 dlbaton
->per_cu
, dlbaton
->per_objfile
);
513 /* The DW_AT_frame_base attribute contains a location description which
514 computes the base address itself. However, the call to
515 dwarf2_evaluate_loc_desc returns a value representing a variable at
516 that address. The frame base address is thus this variable's
518 return value_address (result
);
521 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
522 function uses DWARF expression for its DW_AT_frame_base. */
524 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
526 locexpr_find_frame_base_location
,
527 locexpr_get_frame_base
530 /* Implement find_frame_base_location method for LOC_BLOCK functions using
531 DWARF location list for its DW_AT_frame_base. */
534 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
535 const gdb_byte
**start
, size_t *length
)
537 struct dwarf2_loclist_baton
*symbaton
538 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
540 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
543 /* Implement the struct symbol_block_ops::get_frame_base method for
544 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
547 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
549 struct gdbarch
*gdbarch
;
551 struct dwarf2_loclist_baton
*dlbaton
;
552 const gdb_byte
*start
;
554 struct value
*result
;
556 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
557 Thus, it's supposed to provide the find_frame_base_location method as
559 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
561 gdbarch
= get_frame_arch (frame
);
562 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
563 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
565 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
566 (framefunc
, get_frame_pc (frame
), &start
, &length
);
567 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
568 dlbaton
->per_cu
, dlbaton
->per_objfile
);
570 /* The DW_AT_frame_base attribute contains a location description which
571 computes the base address itself. However, the call to
572 dwarf2_evaluate_loc_desc returns a value representing a variable at
573 that address. The frame base address is thus this variable's
575 return value_address (result
);
578 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
579 function uses DWARF location list for its DW_AT_frame_base. */
581 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
583 loclist_find_frame_base_location
,
584 loclist_get_frame_base
587 /* See dwarf2loc.h. */
590 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
591 const gdb_byte
**start
, size_t *length
)
593 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
595 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
597 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
603 error (_("Could not find the frame base for \"%s\"."),
604 framefunc
->natural_name ());
610 compute_var_value (const char *name
)
612 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
614 if (sym
.symbol
!= nullptr)
615 return value_of_variable (sym
.symbol
, sym
.block
);
619 /* See dwarf2loc.h. */
621 unsigned int entry_values_debug
= 0;
623 /* Helper to set entry_values_debug. */
626 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
627 struct cmd_list_element
*c
, const char *value
)
629 fprintf_filtered (file
,
630 _("Entry values and tail call frames debugging is %s.\n"),
634 /* Find DW_TAG_call_site's DW_AT_call_target address.
635 CALLER_FRAME (for registers) can be NULL if it is not known. This function
636 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
639 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
640 struct call_site
*call_site
,
641 struct frame_info
*caller_frame
)
643 switch (call_site
->target
.loc_kind ())
645 case FIELD_LOC_KIND_DWARF_BLOCK
:
647 struct dwarf2_locexpr_baton
*dwarf_block
;
649 struct type
*caller_core_addr_type
;
650 struct gdbarch
*caller_arch
;
652 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
653 if (dwarf_block
== NULL
)
655 struct bound_minimal_symbol msym
;
657 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
658 throw_error (NO_ENTRY_VALUE_ERROR
,
659 _("DW_AT_call_target is not specified at %s in %s"),
660 paddress (call_site_gdbarch
, call_site
->pc ()),
661 (msym
.minsym
== NULL
? "???"
662 : msym
.minsym
->print_name ()));
665 if (caller_frame
== NULL
)
667 struct bound_minimal_symbol msym
;
669 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
670 throw_error (NO_ENTRY_VALUE_ERROR
,
671 _("DW_AT_call_target DWARF block resolving "
672 "requires known frame which is currently not "
673 "available at %s in %s"),
674 paddress (call_site_gdbarch
, call_site
->pc ()),
675 (msym
.minsym
== NULL
? "???"
676 : msym
.minsym
->print_name ()));
679 caller_arch
= get_frame_arch (caller_frame
);
680 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
681 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
682 dwarf_block
->data
, dwarf_block
->size
,
684 dwarf_block
->per_objfile
);
685 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
686 if (VALUE_LVAL (val
) == lval_memory
)
687 return value_address (val
);
689 return value_as_address (val
);
692 case FIELD_LOC_KIND_PHYSNAME
:
694 const char *physname
;
695 struct bound_minimal_symbol msym
;
697 physname
= call_site
->target
.loc_physname ();
699 /* Handle both the mangled and demangled PHYSNAME. */
700 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
701 if (msym
.minsym
== NULL
)
703 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
704 throw_error (NO_ENTRY_VALUE_ERROR
,
705 _("Cannot find function \"%s\" for a call site target "
707 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
708 (msym
.minsym
== NULL
? "???"
709 : msym
.minsym
->print_name ()));
712 return BMSYMBOL_VALUE_ADDRESS (msym
);
715 case FIELD_LOC_KIND_PHYSADDR
:
717 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
718 compunit_symtab
*cust
= per_objfile
->get_symtab (call_site
->per_cu
);
719 int sect_idx
= COMPUNIT_BLOCK_LINE_SECTION (cust
);
720 CORE_ADDR delta
= per_objfile
->objfile
->section_offsets
[sect_idx
];
722 return FIELD_STATIC_PHYSADDR (call_site
->target
) + delta
;
726 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
730 /* Convert function entry point exact address ADDR to the function which is
731 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
732 NO_ENTRY_VALUE_ERROR otherwise. */
734 static struct symbol
*
735 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
737 struct symbol
*sym
= find_pc_function (addr
);
740 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
741 throw_error (NO_ENTRY_VALUE_ERROR
,
742 _("DW_TAG_call_site resolving failed to find function "
743 "name for address %s"),
744 paddress (gdbarch
, addr
));
746 type
= SYMBOL_TYPE (sym
);
747 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
748 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
753 /* Verify function with entry point exact address ADDR can never call itself
754 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
755 can call itself via tail calls.
757 If a funtion can tail call itself its entry value based parameters are
758 unreliable. There is no verification whether the value of some/all
759 parameters is unchanged through the self tail call, we expect if there is
760 a self tail call all the parameters can be modified. */
763 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
767 /* The verification is completely unordered. Track here function addresses
768 which still need to be iterated. */
769 std::vector
<CORE_ADDR
> todo
;
771 /* Track here CORE_ADDRs which were already visited. */
772 std::unordered_set
<CORE_ADDR
> addr_hash
;
774 todo
.push_back (verify_addr
);
775 while (!todo
.empty ())
777 struct symbol
*func_sym
;
778 struct call_site
*call_site
;
783 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
785 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
786 call_site
; call_site
= call_site
->tail_call_next
)
788 CORE_ADDR target_addr
;
790 /* CALLER_FRAME with registers is not available for tail-call jumped
792 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
794 if (target_addr
== verify_addr
)
796 struct bound_minimal_symbol msym
;
798 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
799 throw_error (NO_ENTRY_VALUE_ERROR
,
800 _("DW_OP_entry_value resolving has found "
801 "function \"%s\" at %s can call itself via tail "
803 (msym
.minsym
== NULL
? "???"
804 : msym
.minsym
->print_name ()),
805 paddress (gdbarch
, verify_addr
));
808 if (addr_hash
.insert (target_addr
).second
)
809 todo
.push_back (target_addr
);
814 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
815 ENTRY_VALUES_DEBUG. */
818 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
820 CORE_ADDR addr
= call_site
->pc ();
821 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
823 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
824 (msym
.minsym
== NULL
? "???"
825 : msym
.minsym
->print_name ()));
829 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
830 only top callers and bottom callees which are present in both. GDBARCH is
831 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
832 no remaining possibilities to provide unambiguous non-trivial result.
833 RESULTP should point to NULL on the first (initialization) call. Caller is
834 responsible for xfree of any RESULTP data. */
837 chain_candidate (struct gdbarch
*gdbarch
,
838 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
839 std::vector
<struct call_site
*> *chain
)
841 long length
= chain
->size ();
842 int callers
, callees
, idx
;
844 if (*resultp
== NULL
)
846 /* Create the initial chain containing all the passed PCs. */
848 struct call_site_chain
*result
849 = ((struct call_site_chain
*)
850 xmalloc (sizeof (*result
)
851 + sizeof (*result
->call_site
) * (length
- 1)));
852 result
->length
= length
;
853 result
->callers
= result
->callees
= length
;
854 if (!chain
->empty ())
855 memcpy (result
->call_site
, chain
->data (),
856 sizeof (*result
->call_site
) * length
);
857 resultp
->reset (result
);
859 if (entry_values_debug
)
861 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
862 for (idx
= 0; idx
< length
; idx
++)
863 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
864 fputc_unfiltered ('\n', gdb_stdlog
);
870 if (entry_values_debug
)
872 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
873 for (idx
= 0; idx
< length
; idx
++)
874 tailcall_dump (gdbarch
, chain
->at (idx
));
875 fputc_unfiltered ('\n', gdb_stdlog
);
878 /* Intersect callers. */
880 callers
= std::min ((long) (*resultp
)->callers
, length
);
881 for (idx
= 0; idx
< callers
; idx
++)
882 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
884 (*resultp
)->callers
= idx
;
888 /* Intersect callees. */
890 callees
= std::min ((long) (*resultp
)->callees
, length
);
891 for (idx
= 0; idx
< callees
; idx
++)
892 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
893 != chain
->at (length
- 1 - idx
))
895 (*resultp
)->callees
= idx
;
899 if (entry_values_debug
)
901 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
902 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
903 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
904 fputs_unfiltered (" |", gdb_stdlog
);
905 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
906 tailcall_dump (gdbarch
,
907 (*resultp
)->call_site
[(*resultp
)->length
908 - (*resultp
)->callees
+ idx
]);
909 fputc_unfiltered ('\n', gdb_stdlog
);
912 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
914 /* There are no common callers or callees. It could be also a direct
915 call (which has length 0) with ambiguous possibility of an indirect
916 call - CALLERS == CALLEES == 0 is valid during the first allocation
917 but any subsequence processing of such entry means ambiguity. */
918 resultp
->reset (NULL
);
922 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
923 PC again. In such case there must be two different code paths to reach
924 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
925 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
928 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
929 assumed frames between them use GDBARCH. Use depth first search so we can
930 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
931 would have needless GDB stack overhead. Any unreliability results
932 in thrown NO_ENTRY_VALUE_ERROR. */
934 static gdb::unique_xmalloc_ptr
<call_site_chain
>
935 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
938 CORE_ADDR save_callee_pc
= callee_pc
;
939 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
940 struct call_site
*call_site
;
942 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
943 call_site nor any possible call_site at CALLEE_PC's function is there.
944 Any CALL_SITE in CHAIN will be iterated to its siblings - via
945 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
946 std::vector
<struct call_site
*> chain
;
948 /* We are not interested in the specific PC inside the callee function. */
949 callee_pc
= get_pc_function_start (callee_pc
);
951 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
952 paddress (gdbarch
, save_callee_pc
));
954 /* Mark CALL_SITEs so we do not visit the same ones twice. */
955 std::unordered_set
<CORE_ADDR
> addr_hash
;
957 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
958 at the target's function. All the possible tail call sites in the
959 target's function will get iterated as already pushed into CHAIN via their
961 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
965 CORE_ADDR target_func_addr
;
966 struct call_site
*target_call_site
;
968 /* CALLER_FRAME with registers is not available for tail-call jumped
970 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
972 if (target_func_addr
== callee_pc
)
974 chain_candidate (gdbarch
, &retval
, &chain
);
978 /* There is no way to reach CALLEE_PC again as we would prevent
979 entering it twice as being already marked in ADDR_HASH. */
980 target_call_site
= NULL
;
984 struct symbol
*target_func
;
986 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
987 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
992 /* Attempt to visit TARGET_CALL_SITE. */
994 if (target_call_site
)
996 if (addr_hash
.insert (target_call_site
->pc ()).second
)
998 /* Successfully entered TARGET_CALL_SITE. */
1000 chain
.push_back (target_call_site
);
1005 /* Backtrack (without revisiting the originating call_site). Try the
1006 callers's sibling; if there isn't any try the callers's callers's
1009 target_call_site
= NULL
;
1010 while (!chain
.empty ())
1012 call_site
= chain
.back ();
1015 size_t removed
= addr_hash
.erase (call_site
->pc ());
1016 gdb_assert (removed
== 1);
1018 target_call_site
= call_site
->tail_call_next
;
1019 if (target_call_site
)
1023 while (target_call_site
);
1028 call_site
= chain
.back ();
1033 struct bound_minimal_symbol msym_caller
, msym_callee
;
1035 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1036 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1037 throw_error (NO_ENTRY_VALUE_ERROR
,
1038 _("There are no unambiguously determinable intermediate "
1039 "callers or callees between caller function \"%s\" at %s "
1040 "and callee function \"%s\" at %s"),
1041 (msym_caller
.minsym
== NULL
1042 ? "???" : msym_caller
.minsym
->print_name ()),
1043 paddress (gdbarch
, caller_pc
),
1044 (msym_callee
.minsym
== NULL
1045 ? "???" : msym_callee
.minsym
->print_name ()),
1046 paddress (gdbarch
, callee_pc
));
1052 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1053 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1054 constructed return NULL. */
1056 gdb::unique_xmalloc_ptr
<call_site_chain
>
1057 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1058 CORE_ADDR callee_pc
)
1060 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1064 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1066 catch (const gdb_exception_error
&e
)
1068 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1070 if (entry_values_debug
)
1071 exception_print (gdb_stdout
, e
);
1082 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1085 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1086 enum call_site_parameter_kind kind
,
1087 union call_site_parameter_u kind_u
)
1089 if (kind
== parameter
->kind
)
1092 case CALL_SITE_PARAMETER_DWARF_REG
:
1093 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1095 case CALL_SITE_PARAMETER_FB_OFFSET
:
1096 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1098 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1099 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1106 struct call_site_parameter
*
1107 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1108 enum call_site_parameter_kind kind
,
1109 union call_site_parameter_u kind_u
,
1110 dwarf2_per_cu_data
**per_cu_return
,
1111 dwarf2_per_objfile
**per_objfile_return
)
1113 CORE_ADDR func_addr
, caller_pc
;
1114 struct gdbarch
*gdbarch
;
1115 struct frame_info
*caller_frame
;
1116 struct call_site
*call_site
;
1118 /* Initialize it just to avoid a GCC false warning. */
1119 struct call_site_parameter
*parameter
= NULL
;
1120 CORE_ADDR target_addr
;
1122 while (get_frame_type (frame
) == INLINE_FRAME
)
1124 frame
= get_prev_frame (frame
);
1125 gdb_assert (frame
!= NULL
);
1128 func_addr
= get_frame_func (frame
);
1129 gdbarch
= get_frame_arch (frame
);
1130 caller_frame
= get_prev_frame (frame
);
1131 if (gdbarch
!= frame_unwind_arch (frame
))
1133 struct bound_minimal_symbol msym
1134 = lookup_minimal_symbol_by_pc (func_addr
);
1135 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1137 throw_error (NO_ENTRY_VALUE_ERROR
,
1138 _("DW_OP_entry_value resolving callee gdbarch %s "
1139 "(of %s (%s)) does not match caller gdbarch %s"),
1140 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1141 paddress (gdbarch
, func_addr
),
1142 (msym
.minsym
== NULL
? "???"
1143 : msym
.minsym
->print_name ()),
1144 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1147 if (caller_frame
== NULL
)
1149 struct bound_minimal_symbol msym
1150 = lookup_minimal_symbol_by_pc (func_addr
);
1152 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1153 "requires caller of %s (%s)"),
1154 paddress (gdbarch
, func_addr
),
1155 (msym
.minsym
== NULL
? "???"
1156 : msym
.minsym
->print_name ()));
1158 caller_pc
= get_frame_pc (caller_frame
);
1159 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1161 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1162 if (target_addr
!= func_addr
)
1164 struct minimal_symbol
*target_msym
, *func_msym
;
1166 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1167 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1168 throw_error (NO_ENTRY_VALUE_ERROR
,
1169 _("DW_OP_entry_value resolving expects callee %s at %s "
1170 "but the called frame is for %s at %s"),
1171 (target_msym
== NULL
? "???"
1172 : target_msym
->print_name ()),
1173 paddress (gdbarch
, target_addr
),
1174 func_msym
== NULL
? "???" : func_msym
->print_name (),
1175 paddress (gdbarch
, func_addr
));
1178 /* No entry value based parameters would be reliable if this function can
1179 call itself via tail calls. */
1180 func_verify_no_selftailcall (gdbarch
, func_addr
);
1182 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1184 parameter
= &call_site
->parameter
[iparams
];
1185 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1188 if (iparams
== call_site
->parameter_count
)
1190 struct minimal_symbol
*msym
1191 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1193 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1194 determine its value. */
1195 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1196 "at DW_TAG_call_site %s at %s"),
1197 paddress (gdbarch
, caller_pc
),
1198 msym
== NULL
? "???" : msym
->print_name ());
1201 *per_cu_return
= call_site
->per_cu
;
1202 *per_objfile_return
= call_site
->per_objfile
;
1206 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1207 the normal DW_AT_call_value block. Otherwise return the
1208 DW_AT_call_data_value (dereferenced) block.
1210 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1213 Function always returns non-NULL, non-optimized out value. It throws
1214 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1216 static struct value
*
1217 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1218 CORE_ADDR deref_size
, struct type
*type
,
1219 struct frame_info
*caller_frame
,
1220 dwarf2_per_cu_data
*per_cu
,
1221 dwarf2_per_objfile
*per_objfile
)
1223 const gdb_byte
*data_src
;
1226 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1227 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1229 /* DEREF_SIZE size is not verified here. */
1230 if (data_src
== NULL
)
1231 throw_error (NO_ENTRY_VALUE_ERROR
,
1232 _("Cannot resolve DW_AT_call_data_value"));
1234 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1235 per_objfile
, false);
1238 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1239 the indirect method on it, that is use its stored target value, the sole
1240 purpose of entry_data_value_funcs.. */
1242 static struct value
*
1243 entry_data_value_coerce_ref (const struct value
*value
)
1245 struct type
*checked_type
= check_typedef (value_type (value
));
1246 struct value
*target_val
;
1248 if (!TYPE_IS_REFERENCE (checked_type
))
1251 target_val
= (struct value
*) value_computed_closure (value
);
1252 value_incref (target_val
);
1256 /* Implement copy_closure. */
1259 entry_data_value_copy_closure (const struct value
*v
)
1261 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1263 value_incref (target_val
);
1267 /* Implement free_closure. */
1270 entry_data_value_free_closure (struct value
*v
)
1272 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1274 value_decref (target_val
);
1277 /* Vector for methods for an entry value reference where the referenced value
1278 is stored in the caller. On the first dereference use
1279 DW_AT_call_data_value in the caller. */
1281 static const struct lval_funcs entry_data_value_funcs
=
1286 NULL
, /* indirect */
1287 entry_data_value_coerce_ref
,
1288 NULL
, /* check_synthetic_pointer */
1289 entry_data_value_copy_closure
,
1290 entry_data_value_free_closure
1293 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1294 are used to match DW_AT_location at the caller's
1295 DW_TAG_call_site_parameter.
1297 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1298 cannot resolve the parameter for any reason. */
1300 static struct value
*
1301 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1302 enum call_site_parameter_kind kind
,
1303 union call_site_parameter_u kind_u
)
1305 struct type
*checked_type
= check_typedef (type
);
1306 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1307 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1308 struct value
*outer_val
, *target_val
, *val
;
1309 struct call_site_parameter
*parameter
;
1310 dwarf2_per_cu_data
*caller_per_cu
;
1311 dwarf2_per_objfile
*caller_per_objfile
;
1313 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1315 &caller_per_objfile
);
1317 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1320 caller_per_objfile
);
1322 /* Check if DW_AT_call_data_value cannot be used. If it should be
1323 used and it is not available do not fall back to OUTER_VAL - dereferencing
1324 TYPE_CODE_REF with non-entry data value would give current value - not the
1327 if (!TYPE_IS_REFERENCE (checked_type
)
1328 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1331 target_val
= dwarf_entry_parameter_to_value (parameter
,
1332 TYPE_LENGTH (target_type
),
1333 target_type
, caller_frame
,
1335 caller_per_objfile
);
1337 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1338 release_value (target_val
).release ());
1340 /* Copy the referencing pointer to the new computed value. */
1341 memcpy (value_contents_raw (val
).data (),
1342 value_contents_raw (outer_val
).data (),
1343 TYPE_LENGTH (checked_type
));
1344 set_value_lazy (val
, 0);
1349 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1350 SIZE are DWARF block used to match DW_AT_location at the caller's
1351 DW_TAG_call_site_parameter.
1353 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1354 cannot resolve the parameter for any reason. */
1356 static struct value
*
1357 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1358 const gdb_byte
*block
, size_t block_len
)
1360 union call_site_parameter_u kind_u
;
1362 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1363 if (kind_u
.dwarf_reg
!= -1)
1364 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1367 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1368 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1371 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1372 suppressed during normal operation. The expression can be arbitrary if
1373 there is no caller-callee entry value binding expected. */
1374 throw_error (NO_ENTRY_VALUE_ERROR
,
1375 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1376 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1379 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1381 static struct value
*
1382 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1383 dwarf2_per_cu_data
*per_cu
,
1384 dwarf2_per_objfile
*per_objfile
,
1387 struct value
*result
= NULL
;
1388 const gdb_byte
*bytes
;
1391 auto_obstack temp_obstack
;
1392 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1393 &temp_obstack
, &len
);
1397 if (byte_offset
>= 0
1398 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1400 bytes
+= byte_offset
;
1401 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1404 invalid_synthetic_pointer ();
1407 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1415 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1416 dwarf2_per_cu_data
*per_cu
,
1417 dwarf2_per_objfile
*per_objfile
,
1418 struct frame_info
*frame
, struct type
*type
,
1419 bool resolve_abstract_p
)
1421 /* Fetch the location expression of the DIE we're pointing to. */
1422 auto get_frame_address_in_block_wrapper
= [frame
] ()
1424 return get_frame_address_in_block (frame
);
1426 struct dwarf2_locexpr_baton baton
1427 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1428 get_frame_address_in_block_wrapper
,
1429 resolve_abstract_p
);
1431 /* Get type of pointed-to DIE. */
1432 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1434 if (orig_type
== NULL
)
1435 invalid_synthetic_pointer ();
1437 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1438 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1439 or it may've been optimized out. */
1440 if (baton
.data
!= NULL
)
1441 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1442 baton
.size
, baton
.per_cu
,
1444 TYPE_TARGET_TYPE (type
),
1447 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1451 /* Evaluate a location description, starting at DATA and with length
1452 SIZE, to find the current location of variable of TYPE in the
1453 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1454 location of the subobject of type SUBOBJ_TYPE at byte offset
1455 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1457 static struct value
*
1458 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1459 const gdb_byte
*data
, size_t size
,
1460 dwarf2_per_cu_data
*per_cu
,
1461 dwarf2_per_objfile
*per_objfile
,
1462 struct type
*subobj_type
,
1463 LONGEST subobj_byte_offset
,
1466 if (subobj_type
== NULL
)
1469 subobj_byte_offset
= 0;
1471 else if (subobj_byte_offset
< 0)
1472 invalid_synthetic_pointer ();
1475 return allocate_optimized_out_value (subobj_type
);
1477 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1480 scoped_value_mark free_values
;
1484 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1485 type
, subobj_type
, subobj_byte_offset
);
1487 catch (const gdb_exception_error
&ex
)
1489 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1491 free_values
.free_to_mark ();
1492 retval
= allocate_value (subobj_type
);
1493 mark_value_bytes_unavailable (retval
, 0,
1494 TYPE_LENGTH (subobj_type
));
1497 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1499 if (entry_values_debug
)
1500 exception_print (gdb_stdout
, ex
);
1501 free_values
.free_to_mark ();
1502 return allocate_optimized_out_value (subobj_type
);
1508 /* We need to clean up all the values that are not needed any more.
1509 The problem with a value_ref_ptr class is that it disconnects the
1510 RETVAL from the value garbage collection, so we need to make
1511 a copy of that value on the stack to keep everything consistent.
1512 The value_ref_ptr will clean up after itself at the end of this block. */
1513 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1514 free_values
.free_to_mark ();
1516 return value_copy (retval
);
1519 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1520 passes 0 as the byte_offset. */
1523 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1524 const gdb_byte
*data
, size_t size
,
1525 dwarf2_per_cu_data
*per_cu
,
1526 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1528 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1529 per_objfile
, NULL
, 0, as_lval
);
1532 /* Evaluates a dwarf expression and stores the result in VAL,
1533 expecting that the dwarf expression only produces a single
1534 CORE_ADDR. FRAME is the frame in which the expression is
1535 evaluated. ADDR_STACK is a context (location of a variable) and
1536 might be needed to evaluate the location expression.
1537 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
1538 or the default of 0) should be pushed on the DWARF expression
1539 evaluation stack before evaluating the expression; this is required
1540 by certain forms of DWARF expression. Returns 1 on success, 0
1544 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1545 struct frame_info
*frame
,
1546 const struct property_addr_info
*addr_stack
,
1548 bool push_initial_value
,
1551 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1554 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1555 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1556 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1559 scoped_value_mark free_values
;
1561 if (push_initial_value
)
1563 if (addr_stack
!= nullptr)
1564 ctx
.push_address (addr_stack
->addr
, false);
1566 ctx
.push_address (0, false);
1571 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1572 true, per_cu
, frame
, addr_stack
);
1574 catch (const gdb_exception_error
&ex
)
1576 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1580 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1582 if (entry_values_debug
)
1583 exception_print (gdb_stdout
, ex
);
1590 if (value_optimized_out (result
))
1593 if (VALUE_LVAL (result
) == lval_memory
)
1594 *valp
= value_address (result
);
1597 if (VALUE_LVAL (result
) == not_lval
)
1598 *is_reference
= false;
1600 *valp
= value_as_address (result
);
1606 /* See dwarf2loc.h. */
1609 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1610 struct frame_info
*frame
,
1611 const struct property_addr_info
*addr_stack
,
1613 bool push_initial_value
)
1618 if (frame
== NULL
&& has_stack_frames ())
1619 frame
= get_selected_frame (NULL
);
1621 switch (prop
->kind ())
1625 const struct dwarf2_property_baton
*baton
1626 = (const struct dwarf2_property_baton
*) prop
->baton ();
1627 gdb_assert (baton
->property_type
!= NULL
);
1629 bool is_reference
= baton
->locexpr
.is_reference
;
1630 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1631 value
, push_initial_value
, &is_reference
))
1635 struct value
*val
= value_at (baton
->property_type
, *value
);
1636 *value
= value_as_address (val
);
1640 gdb_assert (baton
->property_type
!= NULL
);
1642 struct type
*type
= check_typedef (baton
->property_type
);
1643 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
1644 && !type
->is_unsigned ())
1646 /* If we have a valid return candidate and it's value
1647 is signed, we have to sign-extend the value because
1648 CORE_ADDR on 64bit machine has 8 bytes but address
1649 size of an 32bit application is bytes. */
1651 = (baton
->locexpr
.per_cu
->addr_size ()
1653 const CORE_ADDR neg_mask
1654 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1656 /* Check if signed bit is set and sign-extend values. */
1657 if (*value
& neg_mask
)
1668 struct dwarf2_property_baton
*baton
1669 = (struct dwarf2_property_baton
*) prop
->baton ();
1671 const gdb_byte
*data
;
1676 || !get_frame_address_in_block_if_available (frame
, &pc
))
1679 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1682 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1683 size
, baton
->loclist
.per_cu
,
1684 baton
->loclist
.per_objfile
);
1685 if (!value_optimized_out (val
))
1687 *value
= value_as_address (val
);
1695 *value
= prop
->const_val ();
1698 case PROP_ADDR_OFFSET
:
1700 struct dwarf2_property_baton
*baton
1701 = (struct dwarf2_property_baton
*) prop
->baton ();
1702 const struct property_addr_info
*pinfo
;
1705 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1707 /* This approach lets us avoid checking the qualifiers. */
1708 if (TYPE_MAIN_TYPE (pinfo
->type
)
1709 == TYPE_MAIN_TYPE (baton
->property_type
))
1713 error (_("cannot find reference address for offset property"));
1714 if (pinfo
->valaddr
.data () != NULL
)
1715 val
= value_from_contents
1716 (baton
->offset_info
.type
,
1717 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1719 val
= value_at (baton
->offset_info
.type
,
1720 pinfo
->addr
+ baton
->offset_info
.offset
);
1721 *value
= value_as_address (val
);
1725 case PROP_VARIABLE_NAME
:
1727 struct value
*val
= compute_var_value (prop
->variable_name ());
1730 *value
= value_as_long (val
);
1740 /* See dwarf2loc.h. */
1743 dwarf2_compile_property_to_c (string_file
*stream
,
1744 const char *result_name
,
1745 struct gdbarch
*gdbarch
,
1746 std::vector
<bool> ®isters_used
,
1747 const struct dynamic_prop
*prop
,
1751 struct dwarf2_property_baton
*baton
1752 = (struct dwarf2_property_baton
*) prop
->baton ();
1753 const gdb_byte
*data
;
1755 dwarf2_per_cu_data
*per_cu
;
1756 dwarf2_per_objfile
*per_objfile
;
1758 if (prop
->kind () == PROP_LOCEXPR
)
1760 data
= baton
->locexpr
.data
;
1761 size
= baton
->locexpr
.size
;
1762 per_cu
= baton
->locexpr
.per_cu
;
1763 per_objfile
= baton
->locexpr
.per_objfile
;
1767 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1769 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1770 per_cu
= baton
->loclist
.per_cu
;
1771 per_objfile
= baton
->loclist
.per_objfile
;
1774 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1775 gdbarch
, registers_used
,
1776 per_cu
->addr_size (),
1777 data
, data
+ size
, per_cu
, per_objfile
);
1780 /* Compute the correct symbol_needs_kind value for the location
1783 Implemented by traversing the logical control flow graph of the
1786 static enum symbol_needs_kind
1787 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1788 dwarf2_per_cu_data
*per_cu
,
1789 dwarf2_per_objfile
*per_objfile
,
1790 bfd_endian byte_order
,
1795 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1797 /* If the expression is empty, we have nothing to do. */
1799 return symbol_needs
;
1801 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1803 /* List of operations to visit. Operations in this list are not visited yet,
1804 so are not in VISITED_OPS (and vice-versa). */
1805 std::vector
<const gdb_byte
*> ops_to_visit
;
1807 /* Operations already visited. */
1808 std::unordered_set
<const gdb_byte
*> visited_ops
;
1810 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1811 hasn't been visited yet. */
1812 auto insert_in_ops_to_visit
1813 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1815 if (op_ptr
>= expr_end
)
1818 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1821 ops_to_visit
.push_back (op_ptr
);
1824 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1826 const int max_depth
= 256;
1828 if (depth
> max_depth
)
1829 error (_("DWARF-2 expression error: Loop detected."));
1833 /* Initialize the to-visit list with the first operation. */
1834 insert_in_ops_to_visit (&expr
[0]);
1836 while (!ops_to_visit
.empty ())
1838 /* Pop one op to visit, mark it as visited. */
1839 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1840 ops_to_visit
.pop_back ();
1841 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1842 visited_ops
.insert (op_ptr
);
1844 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1846 /* Most operations have a single possible following operation
1847 (they are not conditional branches). The code below updates
1848 OP_PTR to point to that following operation, which is pushed
1849 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1850 OP_PTR pointing just after the operand. */
1853 /* The DWARF expression might have a bug causing an infinite
1854 loop. In that case, quitting is the only way out. */
1891 case DW_OP_stack_value
:
1918 case DW_OP_GNU_push_tls_address
:
1920 case DW_OP_GNU_uninit
:
1921 case DW_OP_push_object_address
:
1924 case DW_OP_form_tls_address
:
1925 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1926 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1930 case DW_OP_GNU_convert
:
1931 case DW_OP_reinterpret
:
1932 case DW_OP_GNU_reinterpret
:
1934 case DW_OP_GNU_addr_index
:
1935 case DW_OP_GNU_const_index
:
1937 case DW_OP_plus_uconst
:
1939 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1943 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1946 case DW_OP_bit_piece
:
1947 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1948 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1951 case DW_OP_deref_type
:
1952 case DW_OP_GNU_deref_type
:
1954 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1958 op_ptr
+= addr_size
;
2048 case DW_OP_call_frame_cfa
:
2049 case DW_OP_entry_value
:
2050 case DW_OP_GNU_entry_value
:
2051 case DW_OP_GNU_parameter_ref
:
2052 case DW_OP_regval_type
:
2053 case DW_OP_GNU_regval_type
:
2054 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2057 case DW_OP_implicit_value
:
2060 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2065 case DW_OP_implicit_pointer
:
2066 case DW_OP_GNU_implicit_pointer
:
2067 op_ptr
+= ref_addr_size
;
2068 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2071 case DW_OP_deref_size
:
2078 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2086 /* This is the only operation that pushes two operations in
2087 the to-visit list, so handle it all here. */
2088 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2091 insert_in_ops_to_visit (op_ptr
+ offset
);
2092 insert_in_ops_to_visit (op_ptr
);
2099 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2101 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2104 auto get_frame_pc
= [&symbol_needs
] ()
2106 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2110 struct dwarf2_locexpr_baton baton
2111 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2115 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2116 we dont have to check the baton content. */
2117 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2119 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2120 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2123 = dwarf2_get_symbol_read_needs (sub_expr
,
2126 gdbarch_byte_order (arch
),
2127 baton
.per_cu
->addr_size (),
2128 baton
.per_cu
->ref_addr_size (),
2134 case DW_OP_GNU_variable_value
:
2136 sect_offset sect_off
2137 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2140 op_ptr
+= ref_addr_size
;
2142 struct type
*die_type
2143 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2146 if (die_type
== NULL
)
2147 error (_("Bad DW_OP_GNU_variable_value DIE."));
2149 /* Note: Things still work when the following test is
2150 removed. This test and error is here to conform to the
2151 proposed specification. */
2152 if (die_type
->code () != TYPE_CODE_INT
2153 && die_type
->code () != TYPE_CODE_PTR
)
2154 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2155 "an integer or pointer."));
2157 auto get_frame_pc
= [&symbol_needs
] ()
2159 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2163 struct dwarf2_locexpr_baton baton
2164 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2166 get_frame_pc
, true);
2168 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2169 we dont have to check the baton content. */
2170 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2172 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2173 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2176 = dwarf2_get_symbol_read_needs (sub_expr
,
2179 gdbarch_byte_order (arch
),
2180 baton
.per_cu
->addr_size (),
2181 baton
.per_cu
->ref_addr_size (),
2187 case DW_OP_const_type
:
2188 case DW_OP_GNU_const_type
:
2191 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2192 gdb_byte offset
= *op_ptr
++;
2198 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2201 /* If it is known that a frame information is
2202 needed we can stop parsing the expression. */
2203 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2206 insert_in_ops_to_visit (op_ptr
);
2209 return symbol_needs
;
2212 /* A helper function that throws an unimplemented error mentioning a
2213 given DWARF operator. */
2215 static void ATTRIBUTE_NORETURN
2216 unimplemented (unsigned int op
)
2218 const char *name
= get_DW_OP_name (op
);
2221 error (_("DWARF operator %s cannot be translated to an agent expression"),
2224 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2225 "to an agent expression"),
2231 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2232 can issue a complaint, which is better than having every target's
2233 implementation of dwarf2_reg_to_regnum do it. */
2236 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2238 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2242 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2247 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2248 Throw an error because DWARF_REG is bad. */
2251 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2253 /* Still want to print -1 as "-1".
2254 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2255 but that's overkill for now. */
2256 if ((int) dwarf_reg
== dwarf_reg
)
2257 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2258 error (_("Unable to access DWARF register number %s"),
2259 pulongest (dwarf_reg
));
2262 /* See dwarf2loc.h. */
2265 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2269 if (dwarf_reg
> INT_MAX
)
2270 throw_bad_regnum_error (dwarf_reg
);
2271 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2272 bad, but that's ok. */
2273 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2275 throw_bad_regnum_error (dwarf_reg
);
2279 /* A helper function that emits an access to memory. ARCH is the
2280 target architecture. EXPR is the expression which we are building.
2281 NBITS is the number of bits we want to read. This emits the
2282 opcodes needed to read the memory and then extract the desired
2286 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2288 ULONGEST nbytes
= (nbits
+ 7) / 8;
2290 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2293 ax_trace_quick (expr
, nbytes
);
2296 ax_simple (expr
, aop_ref8
);
2297 else if (nbits
<= 16)
2298 ax_simple (expr
, aop_ref16
);
2299 else if (nbits
<= 32)
2300 ax_simple (expr
, aop_ref32
);
2302 ax_simple (expr
, aop_ref64
);
2304 /* If we read exactly the number of bytes we wanted, we're done. */
2305 if (8 * nbytes
== nbits
)
2308 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2310 /* On a bits-big-endian machine, we want the high-order
2312 ax_const_l (expr
, 8 * nbytes
- nbits
);
2313 ax_simple (expr
, aop_rsh_unsigned
);
2317 /* On a bits-little-endian box, we want the low-order NBITS. */
2318 ax_zero_ext (expr
, nbits
);
2322 /* Compile a DWARF location expression to an agent expression.
2324 EXPR is the agent expression we are building.
2325 LOC is the agent value we modify.
2326 ARCH is the architecture.
2327 ADDR_SIZE is the size of addresses, in bytes.
2328 OP_PTR is the start of the location expression.
2329 OP_END is one past the last byte of the location expression.
2331 This will throw an exception for various kinds of errors -- for
2332 example, if the expression cannot be compiled, or if the expression
2336 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2337 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2338 const gdb_byte
*op_end
,
2339 dwarf2_per_cu_data
*per_cu
,
2340 dwarf2_per_objfile
*per_objfile
)
2342 gdbarch
*arch
= expr
->gdbarch
;
2343 std::vector
<int> dw_labels
, patches
;
2344 const gdb_byte
* const base
= op_ptr
;
2345 const gdb_byte
*previous_piece
= op_ptr
;
2346 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2347 ULONGEST bits_collected
= 0;
2348 unsigned int addr_size_bits
= 8 * addr_size
;
2349 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2351 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2353 /* By default we are making an address. */
2354 loc
->kind
= axs_lvalue_memory
;
2356 while (op_ptr
< op_end
)
2358 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2359 uint64_t uoffset
, reg
;
2363 offsets
[op_ptr
- base
] = expr
->len
;
2366 /* Our basic approach to code generation is to map DWARF
2367 operations directly to AX operations. However, there are
2370 First, DWARF works on address-sized units, but AX always uses
2371 LONGEST. For most operations we simply ignore this
2372 difference; instead we generate sign extensions as needed
2373 before division and comparison operations. It would be nice
2374 to omit the sign extensions, but there is no way to determine
2375 the size of the target's LONGEST. (This code uses the size
2376 of the host LONGEST in some cases -- that is a bug but it is
2379 Second, some DWARF operations cannot be translated to AX.
2380 For these we simply fail. See
2381 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2416 ax_const_l (expr
, op
- DW_OP_lit0
);
2420 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2421 op_ptr
+= addr_size
;
2422 /* Some versions of GCC emit DW_OP_addr before
2423 DW_OP_GNU_push_tls_address. In this case the value is an
2424 index, not an address. We don't support things like
2425 branching between the address and the TLS op. */
2426 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2427 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2428 ax_const_l (expr
, uoffset
);
2432 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2437 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2442 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2447 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2452 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2457 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2462 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2467 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2472 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2473 ax_const_l (expr
, uoffset
);
2477 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2478 ax_const_l (expr
, offset
);
2513 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2514 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2515 loc
->kind
= axs_lvalue_register
;
2519 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2520 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2521 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2522 loc
->kind
= axs_lvalue_register
;
2525 case DW_OP_implicit_value
:
2529 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2530 if (op_ptr
+ len
> op_end
)
2531 error (_("DW_OP_implicit_value: too few bytes available."));
2532 if (len
> sizeof (ULONGEST
))
2533 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2536 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2539 dwarf_expr_require_composition (op_ptr
, op_end
,
2540 "DW_OP_implicit_value");
2542 loc
->kind
= axs_rvalue
;
2546 case DW_OP_stack_value
:
2547 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2548 loc
->kind
= axs_rvalue
;
2583 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2584 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2588 ax_const_l (expr
, offset
);
2589 ax_simple (expr
, aop_add
);
2595 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2596 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2597 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2601 ax_const_l (expr
, offset
);
2602 ax_simple (expr
, aop_add
);
2609 const gdb_byte
*datastart
;
2611 const struct block
*b
;
2612 struct symbol
*framefunc
;
2614 b
= block_for_pc (expr
->scope
);
2617 error (_("No block found for address"));
2619 framefunc
= block_linkage_function (b
);
2622 error (_("No function found for block"));
2624 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2625 &datastart
, &datalen
);
2627 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2628 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2629 datastart
+ datalen
, per_cu
,
2631 if (loc
->kind
== axs_lvalue_register
)
2632 require_rvalue (expr
, loc
);
2636 ax_const_l (expr
, offset
);
2637 ax_simple (expr
, aop_add
);
2640 loc
->kind
= axs_lvalue_memory
;
2645 ax_simple (expr
, aop_dup
);
2649 ax_simple (expr
, aop_pop
);
2654 ax_pick (expr
, offset
);
2658 ax_simple (expr
, aop_swap
);
2666 ax_simple (expr
, aop_rot
);
2670 case DW_OP_deref_size
:
2674 if (op
== DW_OP_deref_size
)
2679 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2680 error (_("Unsupported size %d in %s"),
2681 size
, get_DW_OP_name (op
));
2682 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2687 /* Sign extend the operand. */
2688 ax_ext (expr
, addr_size_bits
);
2689 ax_simple (expr
, aop_dup
);
2690 ax_const_l (expr
, 0);
2691 ax_simple (expr
, aop_less_signed
);
2692 ax_simple (expr
, aop_log_not
);
2693 i
= ax_goto (expr
, aop_if_goto
);
2694 /* We have to emit 0 - X. */
2695 ax_const_l (expr
, 0);
2696 ax_simple (expr
, aop_swap
);
2697 ax_simple (expr
, aop_sub
);
2698 ax_label (expr
, i
, expr
->len
);
2702 /* No need to sign extend here. */
2703 ax_const_l (expr
, 0);
2704 ax_simple (expr
, aop_swap
);
2705 ax_simple (expr
, aop_sub
);
2709 /* Sign extend the operand. */
2710 ax_ext (expr
, addr_size_bits
);
2711 ax_simple (expr
, aop_bit_not
);
2714 case DW_OP_plus_uconst
:
2715 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2716 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2717 but we micro-optimize anyhow. */
2720 ax_const_l (expr
, reg
);
2721 ax_simple (expr
, aop_add
);
2726 ax_simple (expr
, aop_bit_and
);
2730 /* Sign extend the operands. */
2731 ax_ext (expr
, addr_size_bits
);
2732 ax_simple (expr
, aop_swap
);
2733 ax_ext (expr
, addr_size_bits
);
2734 ax_simple (expr
, aop_swap
);
2735 ax_simple (expr
, aop_div_signed
);
2739 ax_simple (expr
, aop_sub
);
2743 ax_simple (expr
, aop_rem_unsigned
);
2747 ax_simple (expr
, aop_mul
);
2751 ax_simple (expr
, aop_bit_or
);
2755 ax_simple (expr
, aop_add
);
2759 ax_simple (expr
, aop_lsh
);
2763 ax_simple (expr
, aop_rsh_unsigned
);
2767 ax_simple (expr
, aop_rsh_signed
);
2771 ax_simple (expr
, aop_bit_xor
);
2775 /* Sign extend the operands. */
2776 ax_ext (expr
, addr_size_bits
);
2777 ax_simple (expr
, aop_swap
);
2778 ax_ext (expr
, addr_size_bits
);
2779 /* Note no swap here: A <= B is !(B < A). */
2780 ax_simple (expr
, aop_less_signed
);
2781 ax_simple (expr
, aop_log_not
);
2785 /* Sign extend the operands. */
2786 ax_ext (expr
, addr_size_bits
);
2787 ax_simple (expr
, aop_swap
);
2788 ax_ext (expr
, addr_size_bits
);
2789 ax_simple (expr
, aop_swap
);
2790 /* A >= B is !(A < B). */
2791 ax_simple (expr
, aop_less_signed
);
2792 ax_simple (expr
, aop_log_not
);
2796 /* Sign extend the operands. */
2797 ax_ext (expr
, addr_size_bits
);
2798 ax_simple (expr
, aop_swap
);
2799 ax_ext (expr
, addr_size_bits
);
2800 /* No need for a second swap here. */
2801 ax_simple (expr
, aop_equal
);
2805 /* Sign extend the operands. */
2806 ax_ext (expr
, addr_size_bits
);
2807 ax_simple (expr
, aop_swap
);
2808 ax_ext (expr
, addr_size_bits
);
2809 ax_simple (expr
, aop_swap
);
2810 ax_simple (expr
, aop_less_signed
);
2814 /* Sign extend the operands. */
2815 ax_ext (expr
, addr_size_bits
);
2816 ax_simple (expr
, aop_swap
);
2817 ax_ext (expr
, addr_size_bits
);
2818 /* Note no swap here: A > B is B < A. */
2819 ax_simple (expr
, aop_less_signed
);
2823 /* Sign extend the operands. */
2824 ax_ext (expr
, addr_size_bits
);
2825 ax_simple (expr
, aop_swap
);
2826 ax_ext (expr
, addr_size_bits
);
2827 /* No need for a swap here. */
2828 ax_simple (expr
, aop_equal
);
2829 ax_simple (expr
, aop_log_not
);
2832 case DW_OP_call_frame_cfa
:
2835 CORE_ADDR text_offset
;
2837 const gdb_byte
*cfa_start
, *cfa_end
;
2839 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2841 &text_offset
, &cfa_start
, &cfa_end
))
2844 ax_reg (expr
, regnum
);
2847 ax_const_l (expr
, off
);
2848 ax_simple (expr
, aop_add
);
2853 /* Another expression. */
2854 ax_const_l (expr
, text_offset
);
2855 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2856 cfa_end
, per_cu
, per_objfile
);
2859 loc
->kind
= axs_lvalue_memory
;
2863 case DW_OP_GNU_push_tls_address
:
2864 case DW_OP_form_tls_address
:
2868 case DW_OP_push_object_address
:
2873 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2875 i
= ax_goto (expr
, aop_goto
);
2876 dw_labels
.push_back (op_ptr
+ offset
- base
);
2877 patches
.push_back (i
);
2881 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2883 /* Zero extend the operand. */
2884 ax_zero_ext (expr
, addr_size_bits
);
2885 i
= ax_goto (expr
, aop_if_goto
);
2886 dw_labels
.push_back (op_ptr
+ offset
- base
);
2887 patches
.push_back (i
);
2894 case DW_OP_bit_piece
:
2898 if (op_ptr
- 1 == previous_piece
)
2899 error (_("Cannot translate empty pieces to agent expressions"));
2900 previous_piece
= op_ptr
- 1;
2902 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2903 if (op
== DW_OP_piece
)
2909 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2911 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2912 error (_("Expression pieces exceed word size"));
2914 /* Access the bits. */
2917 case axs_lvalue_register
:
2918 ax_reg (expr
, loc
->u
.reg
);
2921 case axs_lvalue_memory
:
2922 /* Offset the pointer, if needed. */
2925 ax_const_l (expr
, uoffset
/ 8);
2926 ax_simple (expr
, aop_add
);
2929 access_memory (arch
, expr
, size
);
2933 /* For a bits-big-endian target, shift up what we already
2934 have. For a bits-little-endian target, shift up the
2935 new data. Note that there is a potential bug here if
2936 the DWARF expression leaves multiple values on the
2938 if (bits_collected
> 0)
2940 if (bits_big_endian
)
2942 ax_simple (expr
, aop_swap
);
2943 ax_const_l (expr
, size
);
2944 ax_simple (expr
, aop_lsh
);
2945 /* We don't need a second swap here, because
2946 aop_bit_or is symmetric. */
2950 ax_const_l (expr
, size
);
2951 ax_simple (expr
, aop_lsh
);
2953 ax_simple (expr
, aop_bit_or
);
2956 bits_collected
+= size
;
2957 loc
->kind
= axs_rvalue
;
2961 case DW_OP_GNU_uninit
:
2967 struct dwarf2_locexpr_baton block
;
2968 int size
= (op
== DW_OP_call2
? 2 : 4);
2970 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2973 auto get_frame_pc_from_expr
= [expr
] ()
2977 cu_offset cuoffset
= (cu_offset
) uoffset
;
2978 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
2979 get_frame_pc_from_expr
);
2981 /* DW_OP_call_ref is currently not supported. */
2982 gdb_assert (block
.per_cu
== per_cu
);
2984 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
2985 block
.data
+ block
.size
, per_cu
,
2990 case DW_OP_call_ref
:
2993 case DW_OP_GNU_variable_value
:
3001 /* Patch all the branches we emitted. */
3002 for (int i
= 0; i
< patches
.size (); ++i
)
3004 int targ
= offsets
[dw_labels
[i
]];
3006 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3007 ax_label (expr
, patches
[i
], targ
);
3012 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3013 evaluator to calculate the location. */
3014 static struct value
*
3015 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3017 struct dwarf2_locexpr_baton
*dlbaton
3018 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3021 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3022 dlbaton
->size
, dlbaton
->per_cu
,
3023 dlbaton
->per_objfile
);
3028 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3029 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3032 static struct value
*
3033 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3035 struct dwarf2_locexpr_baton
*dlbaton
3036 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3038 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3042 /* Implementation of get_symbol_read_needs from
3043 symbol_computed_ops. */
3045 static enum symbol_needs_kind
3046 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3048 struct dwarf2_locexpr_baton
*dlbaton
3049 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3051 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3052 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3054 return dwarf2_get_symbol_read_needs (expr
,
3056 dlbaton
->per_objfile
,
3057 gdbarch_byte_order (arch
),
3058 dlbaton
->per_cu
->addr_size (),
3059 dlbaton
->per_cu
->ref_addr_size ());
3062 /* Return true if DATA points to the end of a piece. END is one past
3063 the last byte in the expression. */
3066 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3068 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3071 /* Helper for locexpr_describe_location_piece that finds the name of a
3075 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3079 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3080 We'd rather print *something* here than throw an error. */
3081 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3082 /* gdbarch_register_name may just return "", return something more
3083 descriptive for bad register numbers. */
3086 /* The text is output as "$bad_register_number".
3087 That is why we use the underscores. */
3088 return _("bad_register_number");
3090 return gdbarch_register_name (gdbarch
, regnum
);
3093 /* Nicely describe a single piece of a location, returning an updated
3094 position in the bytecode sequence. This function cannot recognize
3095 all locations; if a location is not recognized, it simply returns
3096 DATA. If there is an error during reading, e.g. we run off the end
3097 of the buffer, an error is thrown. */
3099 static const gdb_byte
*
3100 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3101 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3102 dwarf2_per_objfile
*per_objfile
,
3103 const gdb_byte
*data
, const gdb_byte
*end
,
3104 unsigned int addr_size
)
3106 objfile
*objfile
= per_objfile
->objfile
;
3107 struct gdbarch
*gdbarch
= objfile
->arch ();
3110 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3112 fprintf_filtered (stream
, _("a variable in $%s"),
3113 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3116 else if (data
[0] == DW_OP_regx
)
3120 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3121 fprintf_filtered (stream
, _("a variable in $%s"),
3122 locexpr_regname (gdbarch
, reg
));
3124 else if (data
[0] == DW_OP_fbreg
)
3126 const struct block
*b
;
3127 struct symbol
*framefunc
;
3129 int64_t frame_offset
;
3130 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3132 int64_t base_offset
= 0;
3134 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3135 if (!piece_end_p (new_data
, end
))
3139 b
= block_for_pc (addr
);
3142 error (_("No block found for address for symbol \"%s\"."),
3143 symbol
->print_name ());
3145 framefunc
= block_linkage_function (b
);
3148 error (_("No function found for block for symbol \"%s\"."),
3149 symbol
->print_name ());
3151 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3153 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3155 const gdb_byte
*buf_end
;
3157 frame_reg
= base_data
[0] - DW_OP_breg0
;
3158 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3160 if (buf_end
!= base_data
+ base_size
)
3161 error (_("Unexpected opcode after "
3162 "DW_OP_breg%u for symbol \"%s\"."),
3163 frame_reg
, symbol
->print_name ());
3165 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3167 /* The frame base is just the register, with no offset. */
3168 frame_reg
= base_data
[0] - DW_OP_reg0
;
3173 /* We don't know what to do with the frame base expression,
3174 so we can't trace this variable; give up. */
3178 fprintf_filtered (stream
,
3179 _("a variable at frame base reg $%s offset %s+%s"),
3180 locexpr_regname (gdbarch
, frame_reg
),
3181 plongest (base_offset
), plongest (frame_offset
));
3183 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3184 && piece_end_p (data
, end
))
3188 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3190 fprintf_filtered (stream
,
3191 _("a variable at offset %s from base reg $%s"),
3193 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3196 /* The location expression for a TLS variable looks like this (on a
3199 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3200 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3202 0x3 is the encoding for DW_OP_addr, which has an operand as long
3203 as the size of an address on the target machine (here is 8
3204 bytes). Note that more recent version of GCC emit DW_OP_const4u
3205 or DW_OP_const8u, depending on address size, rather than
3206 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3207 The operand represents the offset at which the variable is within
3208 the thread local storage. */
3210 else if (data
+ 1 + addr_size
< end
3211 && (data
[0] == DW_OP_addr
3212 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3213 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3214 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3215 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3216 && piece_end_p (data
+ 2 + addr_size
, end
))
3219 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3220 gdbarch_byte_order (gdbarch
));
3222 fprintf_filtered (stream
,
3223 _("a thread-local variable at offset 0x%s "
3224 "in the thread-local storage for `%s'"),
3225 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3227 data
+= 1 + addr_size
+ 1;
3230 /* With -gsplit-dwarf a TLS variable can also look like this:
3231 DW_AT_location : 3 byte block: fc 4 e0
3232 (DW_OP_GNU_const_index: 4;
3233 DW_OP_GNU_push_tls_address) */
3234 else if (data
+ 3 <= end
3235 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3236 && data
[0] == DW_OP_GNU_const_index
3238 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3239 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3240 && piece_end_p (data
+ 2 + leb128_size
, end
))
3244 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3245 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3246 fprintf_filtered (stream
,
3247 _("a thread-local variable at offset 0x%s "
3248 "in the thread-local storage for `%s'"),
3249 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3253 else if (data
[0] >= DW_OP_lit0
3254 && data
[0] <= DW_OP_lit31
3256 && data
[1] == DW_OP_stack_value
)
3258 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3265 /* Disassemble an expression, stopping at the end of a piece or at the
3266 end of the expression. Returns a pointer to the next unread byte
3267 in the input expression. If ALL is nonzero, then this function
3268 will keep going until it reaches the end of the expression.
3269 If there is an error during reading, e.g. we run off the end
3270 of the buffer, an error is thrown. */
3272 static const gdb_byte
*
3273 disassemble_dwarf_expression (struct ui_file
*stream
,
3274 struct gdbarch
*arch
, unsigned int addr_size
,
3275 int offset_size
, const gdb_byte
*start
,
3276 const gdb_byte
*data
, const gdb_byte
*end
,
3277 int indent
, int all
,
3278 dwarf2_per_cu_data
*per_cu
,
3279 dwarf2_per_objfile
*per_objfile
)
3283 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3285 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3290 name
= get_DW_OP_name (op
);
3293 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3294 op
, (long) (data
- 1 - start
));
3295 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3296 (long) (data
- 1 - start
), name
);
3301 ul
= extract_unsigned_integer (data
, addr_size
,
3302 gdbarch_byte_order (arch
));
3304 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3308 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3310 fprintf_filtered (stream
, " %s", pulongest (ul
));
3314 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3316 fprintf_filtered (stream
, " %s", plongest (l
));
3320 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3322 fprintf_filtered (stream
, " %s", pulongest (ul
));
3326 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3328 fprintf_filtered (stream
, " %s", plongest (l
));
3332 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3334 fprintf_filtered (stream
, " %s", pulongest (ul
));
3338 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3340 fprintf_filtered (stream
, " %s", plongest (l
));
3344 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3346 fprintf_filtered (stream
, " %s", pulongest (ul
));
3350 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3352 fprintf_filtered (stream
, " %s", plongest (l
));
3356 data
= safe_read_uleb128 (data
, end
, &ul
);
3357 fprintf_filtered (stream
, " %s", pulongest (ul
));
3361 data
= safe_read_sleb128 (data
, end
, &l
);
3362 fprintf_filtered (stream
, " %s", plongest (l
));
3397 fprintf_filtered (stream
, " [$%s]",
3398 locexpr_regname (arch
, op
- DW_OP_reg0
));
3402 data
= safe_read_uleb128 (data
, end
, &ul
);
3403 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3404 locexpr_regname (arch
, (int) ul
));
3407 case DW_OP_implicit_value
:
3408 data
= safe_read_uleb128 (data
, end
, &ul
);
3410 fprintf_filtered (stream
, " %s", pulongest (ul
));
3445 data
= safe_read_sleb128 (data
, end
, &l
);
3446 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3447 locexpr_regname (arch
, op
- DW_OP_breg0
));
3451 data
= safe_read_uleb128 (data
, end
, &ul
);
3452 data
= safe_read_sleb128 (data
, end
, &l
);
3453 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3455 locexpr_regname (arch
, (int) ul
),
3460 data
= safe_read_sleb128 (data
, end
, &l
);
3461 fprintf_filtered (stream
, " %s", plongest (l
));
3464 case DW_OP_xderef_size
:
3465 case DW_OP_deref_size
:
3467 fprintf_filtered (stream
, " %d", *data
);
3471 case DW_OP_plus_uconst
:
3472 data
= safe_read_uleb128 (data
, end
, &ul
);
3473 fprintf_filtered (stream
, " %s", pulongest (ul
));
3477 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3479 fprintf_filtered (stream
, " to %ld",
3480 (long) (data
+ l
- start
));
3484 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3486 fprintf_filtered (stream
, " %ld",
3487 (long) (data
+ l
- start
));
3491 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3493 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3497 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3499 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3502 case DW_OP_call_ref
:
3503 ul
= extract_unsigned_integer (data
, offset_size
,
3504 gdbarch_byte_order (arch
));
3505 data
+= offset_size
;
3506 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3510 data
= safe_read_uleb128 (data
, end
, &ul
);
3511 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3514 case DW_OP_bit_piece
:
3518 data
= safe_read_uleb128 (data
, end
, &ul
);
3519 data
= safe_read_uleb128 (data
, end
, &offset
);
3520 fprintf_filtered (stream
, " size %s offset %s (bits)",
3521 pulongest (ul
), pulongest (offset
));
3525 case DW_OP_implicit_pointer
:
3526 case DW_OP_GNU_implicit_pointer
:
3528 ul
= extract_unsigned_integer (data
, offset_size
,
3529 gdbarch_byte_order (arch
));
3530 data
+= offset_size
;
3532 data
= safe_read_sleb128 (data
, end
, &l
);
3534 fprintf_filtered (stream
, " DIE %s offset %s",
3535 phex_nz (ul
, offset_size
),
3540 case DW_OP_deref_type
:
3541 case DW_OP_GNU_deref_type
:
3543 int deref_addr_size
= *data
++;
3546 data
= safe_read_uleb128 (data
, end
, &ul
);
3547 cu_offset offset
= (cu_offset
) ul
;
3548 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3549 fprintf_filtered (stream
, "<");
3550 type_print (type
, "", stream
, -1);
3551 fprintf_filtered (stream
, " [0x%s]> %d",
3552 phex_nz (to_underlying (offset
), 0),
3557 case DW_OP_const_type
:
3558 case DW_OP_GNU_const_type
:
3562 data
= safe_read_uleb128 (data
, end
, &ul
);
3563 cu_offset type_die
= (cu_offset
) ul
;
3564 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3565 fprintf_filtered (stream
, "<");
3566 type_print (type
, "", stream
, -1);
3567 fprintf_filtered (stream
, " [0x%s]>",
3568 phex_nz (to_underlying (type_die
), 0));
3571 fprintf_filtered (stream
, " %d byte block:", n
);
3572 for (int i
= 0; i
< n
; ++i
)
3573 fprintf_filtered (stream
, " %02x", data
[i
]);
3578 case DW_OP_regval_type
:
3579 case DW_OP_GNU_regval_type
:
3584 data
= safe_read_uleb128 (data
, end
, ®
);
3585 data
= safe_read_uleb128 (data
, end
, &ul
);
3586 cu_offset type_die
= (cu_offset
) ul
;
3588 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3589 fprintf_filtered (stream
, "<");
3590 type_print (type
, "", stream
, -1);
3591 fprintf_filtered (stream
, " [0x%s]> [$%s]",
3592 phex_nz (to_underlying (type_die
), 0),
3593 locexpr_regname (arch
, reg
));
3598 case DW_OP_GNU_convert
:
3599 case DW_OP_reinterpret
:
3600 case DW_OP_GNU_reinterpret
:
3602 data
= safe_read_uleb128 (data
, end
, &ul
);
3603 cu_offset type_die
= (cu_offset
) ul
;
3605 if (to_underlying (type_die
) == 0)
3606 fprintf_filtered (stream
, "<0>");
3611 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3612 fprintf_filtered (stream
, "<");
3613 type_print (type
, "", stream
, -1);
3614 fprintf_filtered (stream
, " [0x%s]>",
3615 phex_nz (to_underlying (type_die
), 0));
3620 case DW_OP_entry_value
:
3621 case DW_OP_GNU_entry_value
:
3622 data
= safe_read_uleb128 (data
, end
, &ul
);
3623 fputc_filtered ('\n', stream
);
3624 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3625 start
, data
, data
+ ul
, indent
+ 2,
3626 all
, per_cu
, per_objfile
);
3630 case DW_OP_GNU_parameter_ref
:
3631 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3633 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3637 case DW_OP_GNU_addr_index
:
3638 data
= safe_read_uleb128 (data
, end
, &ul
);
3639 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3640 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3643 case DW_OP_GNU_const_index
:
3644 data
= safe_read_uleb128 (data
, end
, &ul
);
3645 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3646 fprintf_filtered (stream
, " %s", pulongest (ul
));
3649 case DW_OP_GNU_variable_value
:
3650 ul
= extract_unsigned_integer (data
, offset_size
,
3651 gdbarch_byte_order (arch
));
3652 data
+= offset_size
;
3653 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3657 fprintf_filtered (stream
, "\n");
3663 static bool dwarf_always_disassemble
;
3666 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3667 struct cmd_list_element
*c
, const char *value
)
3669 fprintf_filtered (file
,
3670 _("Whether to always disassemble "
3671 "DWARF expressions is %s.\n"),
3675 /* Describe a single location, which may in turn consist of multiple
3679 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3680 struct ui_file
*stream
,
3681 const gdb_byte
*data
, size_t size
,
3682 unsigned int addr_size
,
3683 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3684 dwarf2_per_objfile
*per_objfile
)
3686 const gdb_byte
*end
= data
+ size
;
3687 int first_piece
= 1, bad
= 0;
3688 objfile
*objfile
= per_objfile
->objfile
;
3692 const gdb_byte
*here
= data
;
3693 int disassemble
= 1;
3698 fprintf_filtered (stream
, _(", and "));
3700 if (!dwarf_always_disassemble
)
3702 data
= locexpr_describe_location_piece (symbol
, stream
,
3703 addr
, per_cu
, per_objfile
,
3704 data
, end
, addr_size
);
3705 /* If we printed anything, or if we have an empty piece,
3706 then don't disassemble. */
3708 || data
[0] == DW_OP_piece
3709 || data
[0] == DW_OP_bit_piece
)
3714 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3715 data
= disassemble_dwarf_expression (stream
,
3717 addr_size
, offset_size
, data
,
3719 dwarf_always_disassemble
,
3720 per_cu
, per_objfile
);
3725 int empty
= data
== here
;
3728 fprintf_filtered (stream
, " ");
3729 if (data
[0] == DW_OP_piece
)
3733 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3736 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3739 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3742 else if (data
[0] == DW_OP_bit_piece
)
3744 uint64_t bits
, offset
;
3746 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3747 data
= safe_read_uleb128 (data
, end
, &offset
);
3750 fprintf_filtered (stream
,
3751 _("an empty %s-bit piece"),
3754 fprintf_filtered (stream
,
3755 _(" [%s-bit piece, offset %s bits]"),
3756 pulongest (bits
), pulongest (offset
));
3766 if (bad
|| data
> end
)
3767 error (_("Corrupted DWARF2 expression for \"%s\"."),
3768 symbol
->print_name ());
3771 /* Print a natural-language description of SYMBOL to STREAM. This
3772 version is for a symbol with a single location. */
3775 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3776 struct ui_file
*stream
)
3778 struct dwarf2_locexpr_baton
*dlbaton
3779 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3780 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3781 int offset_size
= dlbaton
->per_cu
->offset_size ();
3783 locexpr_describe_location_1 (symbol
, addr
, stream
,
3784 dlbaton
->data
, dlbaton
->size
,
3785 addr_size
, offset_size
,
3786 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3789 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3790 any necessary bytecode in AX. */
3793 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3794 struct axs_value
*value
)
3796 struct dwarf2_locexpr_baton
*dlbaton
3797 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3798 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3800 if (dlbaton
->size
== 0)
3801 value
->optimized_out
= 1;
3803 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3804 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3805 dlbaton
->per_objfile
);
3808 /* symbol_computed_ops 'generate_c_location' method. */
3811 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3812 struct gdbarch
*gdbarch
,
3813 std::vector
<bool> ®isters_used
,
3814 CORE_ADDR pc
, const char *result_name
)
3816 struct dwarf2_locexpr_baton
*dlbaton
3817 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3818 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3820 if (dlbaton
->size
== 0)
3821 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3823 compile_dwarf_expr_to_c (stream
, result_name
,
3824 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3825 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3826 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3829 /* The set of location functions used with the DWARF-2 expression
3831 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3832 locexpr_read_variable
,
3833 locexpr_read_variable_at_entry
,
3834 locexpr_get_symbol_read_needs
,
3835 locexpr_describe_location
,
3836 0, /* location_has_loclist */
3837 locexpr_tracepoint_var_ref
,
3838 locexpr_generate_c_location
3842 /* Wrapper functions for location lists. These generally find
3843 the appropriate location expression and call something above. */
3845 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3846 evaluator to calculate the location. */
3847 static struct value
*
3848 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3850 struct dwarf2_loclist_baton
*dlbaton
3851 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3853 const gdb_byte
*data
;
3855 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3857 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3858 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
3859 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3864 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3865 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3868 Function always returns non-NULL value, it may be marked optimized out if
3869 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3870 if it cannot resolve the parameter for any reason. */
3872 static struct value
*
3873 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3875 struct dwarf2_loclist_baton
*dlbaton
3876 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3877 const gdb_byte
*data
;
3881 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3882 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
3884 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3886 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
3888 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
3891 /* Implementation of get_symbol_read_needs from
3892 symbol_computed_ops. */
3894 static enum symbol_needs_kind
3895 loclist_symbol_needs (struct symbol
*symbol
)
3897 /* If there's a location list, then assume we need to have a frame
3898 to choose the appropriate location expression. With tracking of
3899 global variables this is not necessarily true, but such tracking
3900 is disabled in GCC at the moment until we figure out how to
3903 return SYMBOL_NEEDS_FRAME
;
3906 /* Print a natural-language description of SYMBOL to STREAM. This
3907 version applies when there is a list of different locations, each
3908 with a specified address range. */
3911 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3912 struct ui_file
*stream
)
3914 struct dwarf2_loclist_baton
*dlbaton
3915 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3916 const gdb_byte
*loc_ptr
, *buf_end
;
3917 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3918 struct objfile
*objfile
= per_objfile
->objfile
;
3919 struct gdbarch
*gdbarch
= objfile
->arch ();
3920 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3921 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3922 int offset_size
= dlbaton
->per_cu
->offset_size ();
3923 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3924 /* Adjust base_address for relocatable objects. */
3925 CORE_ADDR base_offset
= objfile
->text_section_offset ();
3926 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
3929 loc_ptr
= dlbaton
->data
;
3930 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3932 fprintf_filtered (stream
, _("multi-location:\n"));
3934 /* Iterate through locations until we run out. */
3937 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
3939 enum debug_loc_kind kind
;
3940 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3942 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3943 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3944 dlbaton
->per_objfile
,
3945 loc_ptr
, buf_end
, &new_ptr
,
3946 &low
, &high
, byte_order
);
3947 else if (dlbaton
->per_cu
->version () < 5)
3948 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3950 byte_order
, addr_size
,
3953 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3954 dlbaton
->per_objfile
,
3955 loc_ptr
, buf_end
, &new_ptr
,
3956 &low
, &high
, byte_order
,
3957 addr_size
, signed_addr_p
);
3961 case DEBUG_LOC_END_OF_LIST
:
3965 case DEBUG_LOC_BASE_ADDRESS
:
3966 base_address
= high
+ base_offset
;
3967 fprintf_filtered (stream
, _(" Base address %s"),
3968 paddress (gdbarch
, base_address
));
3971 case DEBUG_LOC_START_END
:
3972 case DEBUG_LOC_START_LENGTH
:
3973 case DEBUG_LOC_OFFSET_PAIR
:
3976 case DEBUG_LOC_BUFFER_OVERFLOW
:
3977 case DEBUG_LOC_INVALID_ENTRY
:
3978 error (_("Corrupted DWARF expression for symbol \"%s\"."),
3979 symbol
->print_name ());
3982 gdb_assert_not_reached ("bad debug_loc_kind");
3985 /* Otherwise, a location expression entry. */
3986 low
+= base_address
;
3987 high
+= base_address
;
3989 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
3990 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
3992 if (dlbaton
->per_cu
->version () < 5)
3994 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
3999 unsigned int bytes_read
;
4000 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4001 loc_ptr
+= bytes_read
;
4004 /* (It would improve readability to print only the minimum
4005 necessary digits of the second number of the range.) */
4006 fprintf_filtered (stream
, _(" Range %s-%s: "),
4007 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4009 /* Now describe this particular location. */
4010 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4011 addr_size
, offset_size
,
4012 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4014 fprintf_filtered (stream
, "\n");
4020 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4021 any necessary bytecode in AX. */
4023 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4024 struct axs_value
*value
)
4026 struct dwarf2_loclist_baton
*dlbaton
4027 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4028 const gdb_byte
*data
;
4030 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4032 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4034 value
->optimized_out
= 1;
4036 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4037 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4040 /* symbol_computed_ops 'generate_c_location' method. */
4043 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4044 struct gdbarch
*gdbarch
,
4045 std::vector
<bool> ®isters_used
,
4046 CORE_ADDR pc
, const char *result_name
)
4048 struct dwarf2_loclist_baton
*dlbaton
4049 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4050 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4051 const gdb_byte
*data
;
4054 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4056 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4058 compile_dwarf_expr_to_c (stream
, result_name
,
4059 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4062 dlbaton
->per_objfile
);
4065 /* The set of location functions used with the DWARF-2 expression
4066 evaluator and location lists. */
4067 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4068 loclist_read_variable
,
4069 loclist_read_variable_at_entry
,
4070 loclist_symbol_needs
,
4071 loclist_describe_location
,
4072 1, /* location_has_loclist */
4073 loclist_tracepoint_var_ref
,
4074 loclist_generate_c_location
4077 void _initialize_dwarf2loc ();
4079 _initialize_dwarf2loc ()
4081 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4082 &entry_values_debug
,
4083 _("Set entry values and tail call frames "
4085 _("Show entry values and tail call frames "
4087 _("When non-zero, the process of determining "
4088 "parameter values from function entry point "
4089 "and tail call frames will be printed."),
4091 show_entry_values_debug
,
4092 &setdebuglist
, &showdebuglist
);
4094 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4095 &dwarf_always_disassemble
, _("\
4096 Set whether `info address' always disassembles DWARF expressions."), _("\
4097 Show whether `info address' always disassembles DWARF expressions."), _("\
4098 When enabled, DWARF expressions are always printed in an assembly-like\n\
4099 syntax. When disabled, expressions will be printed in a more\n\
4100 conversational style, when possible."),
4102 show_dwarf_always_disassemble
,
4104 &show_dwarf_cmdlist
);