1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2022 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "complaints.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full
51 (struct type
*type
, struct frame_info
*frame
, const gdb_byte
*data
,
52 size_t size
, dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
53 struct type
*subobj_type
, LONGEST subobj_byte_offset
, bool as_lval
= true);
55 /* Until these have formal names, we define these here.
56 ref: http://gcc.gnu.org/wiki/DebugFission
57 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
58 and is then followed by data specific to that entry. */
62 /* Indicates the end of the list of entries. */
63 DEBUG_LOC_END_OF_LIST
= 0,
65 /* This is followed by an unsigned LEB128 number that is an index into
66 .debug_addr and specifies the base address for all following entries. */
67 DEBUG_LOC_BASE_ADDRESS
= 1,
69 /* This is followed by two unsigned LEB128 numbers that are indices into
70 .debug_addr and specify the beginning and ending addresses, and then
71 a normal location expression as in .debug_loc. */
72 DEBUG_LOC_START_END
= 2,
74 /* This is followed by an unsigned LEB128 number that is an index into
75 .debug_addr and specifies the beginning address, and a 4 byte unsigned
76 number that specifies the length, and then a normal location expression
78 DEBUG_LOC_START_LENGTH
= 3,
80 /* This is followed by two unsigned LEB128 operands. The values of these
81 operands are the starting and ending offsets, respectively, relative to
82 the applicable base address. */
83 DEBUG_LOC_OFFSET_PAIR
= 4,
85 /* An internal value indicating there is insufficient data. */
86 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
88 /* An internal value indicating an invalid kind of entry was found. */
89 DEBUG_LOC_INVALID_ENTRY
= -2
92 /* Helper function which throws an error if a synthetic pointer is
96 invalid_synthetic_pointer (void)
98 error (_("access outside bounds of object "
99 "referenced via synthetic pointer"));
102 /* Decode the addresses in a non-dwo .debug_loc entry.
103 A pointer to the next byte to examine is returned in *NEW_PTR.
104 The encoded low,high addresses are return in *LOW,*HIGH.
105 The result indicates the kind of entry found. */
107 static enum debug_loc_kind
108 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
109 const gdb_byte
**new_ptr
,
110 CORE_ADDR
*low
, CORE_ADDR
*high
,
111 enum bfd_endian byte_order
,
112 unsigned int addr_size
,
115 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
117 if (buf_end
- loc_ptr
< 2 * addr_size
)
118 return DEBUG_LOC_BUFFER_OVERFLOW
;
121 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
123 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
124 loc_ptr
+= addr_size
;
127 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
129 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
130 loc_ptr
+= addr_size
;
134 /* A base-address-selection entry. */
135 if ((*low
& base_mask
) == base_mask
)
136 return DEBUG_LOC_BASE_ADDRESS
;
138 /* An end-of-list entry. */
139 if (*low
== 0 && *high
== 0)
140 return DEBUG_LOC_END_OF_LIST
;
142 /* We want the caller to apply the base address, so we must return
143 DEBUG_LOC_OFFSET_PAIR here. */
144 return DEBUG_LOC_OFFSET_PAIR
;
147 /* Decode the addresses in .debug_loclists entry.
148 A pointer to the next byte to examine is returned in *NEW_PTR.
149 The encoded low,high addresses are return in *LOW,*HIGH.
150 The result indicates the kind of entry found. */
152 static enum debug_loc_kind
153 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
154 dwarf2_per_objfile
*per_objfile
,
155 const gdb_byte
*loc_ptr
,
156 const gdb_byte
*buf_end
,
157 const gdb_byte
**new_ptr
,
158 CORE_ADDR
*low
, CORE_ADDR
*high
,
159 enum bfd_endian byte_order
,
160 unsigned int addr_size
,
165 if (loc_ptr
== buf_end
)
166 return DEBUG_LOC_BUFFER_OVERFLOW
;
170 case DW_LLE_base_addressx
:
172 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
174 return DEBUG_LOC_BUFFER_OVERFLOW
;
176 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
178 return DEBUG_LOC_BASE_ADDRESS
;
180 case DW_LLE_startx_length
:
181 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
183 return DEBUG_LOC_BUFFER_OVERFLOW
;
185 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
187 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
189 return DEBUG_LOC_BUFFER_OVERFLOW
;
193 return DEBUG_LOC_START_LENGTH
;
195 case DW_LLE_start_length
:
196 if (buf_end
- loc_ptr
< addr_size
)
197 return DEBUG_LOC_BUFFER_OVERFLOW
;
200 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
202 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
204 loc_ptr
+= addr_size
;
207 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
209 return DEBUG_LOC_BUFFER_OVERFLOW
;
213 return DEBUG_LOC_START_LENGTH
;
215 case DW_LLE_end_of_list
:
217 return DEBUG_LOC_END_OF_LIST
;
219 case DW_LLE_base_address
:
220 if (loc_ptr
+ addr_size
> buf_end
)
221 return DEBUG_LOC_BUFFER_OVERFLOW
;
224 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
226 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
228 loc_ptr
+= addr_size
;
230 return DEBUG_LOC_BASE_ADDRESS
;
232 case DW_LLE_offset_pair
:
233 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
235 return DEBUG_LOC_BUFFER_OVERFLOW
;
238 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
240 return DEBUG_LOC_BUFFER_OVERFLOW
;
244 return DEBUG_LOC_OFFSET_PAIR
;
246 case DW_LLE_start_end
:
247 if (loc_ptr
+ 2 * addr_size
> buf_end
)
248 return DEBUG_LOC_BUFFER_OVERFLOW
;
251 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
253 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
255 loc_ptr
+= addr_size
;
257 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
259 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
261 loc_ptr
+= addr_size
;
263 return DEBUG_LOC_START_END
;
265 /* Following cases are not supported yet. */
266 case DW_LLE_startx_endx
:
267 case DW_LLE_default_location
:
269 return DEBUG_LOC_INVALID_ENTRY
;
273 /* Decode the addresses in .debug_loc.dwo entry.
274 A pointer to the next byte to examine is returned in *NEW_PTR.
275 The encoded low,high addresses are return in *LOW,*HIGH.
276 The result indicates the kind of entry found. */
278 static enum debug_loc_kind
279 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
280 dwarf2_per_objfile
*per_objfile
,
281 const gdb_byte
*loc_ptr
,
282 const gdb_byte
*buf_end
,
283 const gdb_byte
**new_ptr
,
284 CORE_ADDR
*low
, CORE_ADDR
*high
,
285 enum bfd_endian byte_order
)
287 uint64_t low_index
, high_index
;
289 if (loc_ptr
== buf_end
)
290 return DEBUG_LOC_BUFFER_OVERFLOW
;
294 case DW_LLE_GNU_end_of_list_entry
:
296 return DEBUG_LOC_END_OF_LIST
;
298 case DW_LLE_GNU_base_address_selection_entry
:
300 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
302 return DEBUG_LOC_BUFFER_OVERFLOW
;
304 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
306 return DEBUG_LOC_BASE_ADDRESS
;
308 case DW_LLE_GNU_start_end_entry
:
309 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
311 return DEBUG_LOC_BUFFER_OVERFLOW
;
313 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
314 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
316 return DEBUG_LOC_BUFFER_OVERFLOW
;
318 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
320 return DEBUG_LOC_START_END
;
322 case DW_LLE_GNU_start_length_entry
:
323 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
325 return DEBUG_LOC_BUFFER_OVERFLOW
;
327 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
328 if (loc_ptr
+ 4 > buf_end
)
329 return DEBUG_LOC_BUFFER_OVERFLOW
;
332 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
333 *new_ptr
= loc_ptr
+ 4;
334 return DEBUG_LOC_START_LENGTH
;
337 return DEBUG_LOC_INVALID_ENTRY
;
341 /* A function for dealing with location lists. Given a
342 symbol baton (BATON) and a pc value (PC), find the appropriate
343 location expression, set *LOCEXPR_LENGTH, and return a pointer
344 to the beginning of the expression. Returns NULL on failure.
346 For now, only return the first matching location expression; there
347 can be more than one in the list. */
350 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
351 size_t *locexpr_length
, CORE_ADDR pc
)
353 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
354 struct objfile
*objfile
= per_objfile
->objfile
;
355 struct gdbarch
*gdbarch
= objfile
->arch ();
356 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
357 unsigned int addr_size
= baton
->per_cu
->addr_size ();
358 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
359 /* Adjustment for relocatable objects. */
360 CORE_ADDR text_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
361 CORE_ADDR base_address
= baton
->base_address
;
362 const gdb_byte
*loc_ptr
, *buf_end
;
364 loc_ptr
= baton
->data
;
365 buf_end
= baton
->data
+ baton
->size
;
369 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
371 enum debug_loc_kind kind
;
372 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
374 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
375 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
377 loc_ptr
, buf_end
, &new_ptr
,
378 &low
, &high
, byte_order
);
379 else if (baton
->per_cu
->version () < 5)
380 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
382 byte_order
, addr_size
,
385 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
387 loc_ptr
, buf_end
, &new_ptr
,
388 &low
, &high
, byte_order
,
389 addr_size
, signed_addr_p
);
394 case DEBUG_LOC_END_OF_LIST
:
398 case DEBUG_LOC_BASE_ADDRESS
:
402 case DEBUG_LOC_START_END
:
403 case DEBUG_LOC_START_LENGTH
:
404 case DEBUG_LOC_OFFSET_PAIR
:
407 case DEBUG_LOC_BUFFER_OVERFLOW
:
408 case DEBUG_LOC_INVALID_ENTRY
:
409 error (_("dwarf2_find_location_expression: "
410 "Corrupted DWARF expression."));
413 gdb_assert_not_reached ("bad debug_loc_kind");
416 /* Otherwise, a location expression entry.
417 If the entry is from a DWO, don't add base address: the entry is from
418 .debug_addr which already has the DWARF "base address". We still add
419 text offset in case we're debugging a PIE executable. However, if the
420 entry is DW_LLE_offset_pair from a DWO, add the base address as the
421 operands are offsets relative to the applicable base address.
422 If the entry is DW_LLE_start_end or DW_LLE_start_length, then
423 it already is an address, and we don't need to add the base. */
426 if (!baton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
429 high
+= base_address
;
432 if (baton
->per_cu
->version () < 5)
434 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
439 unsigned int bytes_read
;
441 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
442 loc_ptr
+= bytes_read
;
445 if (low
== high
&& pc
== low
)
447 /* This is entry PC record present only at entry point
448 of a function. Verify it is really the function entry point. */
450 const struct block
*pc_block
= block_for_pc (pc
);
451 struct symbol
*pc_func
= NULL
;
454 pc_func
= block_linkage_function (pc_block
);
456 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
458 *locexpr_length
= length
;
463 if (pc
>= low
&& pc
< high
)
465 *locexpr_length
= length
;
473 /* Implement find_frame_base_location method for LOC_BLOCK functions using
474 DWARF expression for its DW_AT_frame_base. */
477 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
478 const gdb_byte
**start
, size_t *length
)
480 struct dwarf2_locexpr_baton
*symbaton
481 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
483 *length
= symbaton
->size
;
484 *start
= symbaton
->data
;
487 /* Implement the struct symbol_block_ops::get_frame_base method for
488 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
491 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
493 struct gdbarch
*gdbarch
;
495 struct dwarf2_locexpr_baton
*dlbaton
;
496 const gdb_byte
*start
;
498 struct value
*result
;
500 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
501 Thus, it's supposed to provide the find_frame_base_location method as
503 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
505 gdbarch
= get_frame_arch (frame
);
506 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
507 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
509 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
510 (framefunc
, get_frame_pc (frame
), &start
, &length
);
511 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
512 dlbaton
->per_cu
, dlbaton
->per_objfile
);
514 /* The DW_AT_frame_base attribute contains a location description which
515 computes the base address itself. However, the call to
516 dwarf2_evaluate_loc_desc returns a value representing a variable at
517 that address. The frame base address is thus this variable's
519 return value_address (result
);
522 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
523 function uses DWARF expression for its DW_AT_frame_base. */
525 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
527 locexpr_find_frame_base_location
,
528 locexpr_get_frame_base
531 /* Implement find_frame_base_location method for LOC_BLOCK functions using
532 DWARF location list for its DW_AT_frame_base. */
535 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
536 const gdb_byte
**start
, size_t *length
)
538 struct dwarf2_loclist_baton
*symbaton
539 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
541 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
544 /* Implement the struct symbol_block_ops::get_frame_base method for
545 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
548 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
550 struct gdbarch
*gdbarch
;
552 struct dwarf2_loclist_baton
*dlbaton
;
553 const gdb_byte
*start
;
555 struct value
*result
;
557 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
558 Thus, it's supposed to provide the find_frame_base_location method as
560 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
562 gdbarch
= get_frame_arch (frame
);
563 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
564 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
566 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
567 (framefunc
, get_frame_pc (frame
), &start
, &length
);
568 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
569 dlbaton
->per_cu
, dlbaton
->per_objfile
);
571 /* The DW_AT_frame_base attribute contains a location description which
572 computes the base address itself. However, the call to
573 dwarf2_evaluate_loc_desc returns a value representing a variable at
574 that address. The frame base address is thus this variable's
576 return value_address (result
);
579 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
580 function uses DWARF location list for its DW_AT_frame_base. */
582 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
584 loclist_find_frame_base_location
,
585 loclist_get_frame_base
588 /* See dwarf2loc.h. */
591 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
592 const gdb_byte
**start
, size_t *length
)
594 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
596 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
598 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
604 error (_("Could not find the frame base for \"%s\"."),
605 framefunc
->natural_name ());
611 compute_var_value (const char *name
)
613 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
615 if (sym
.symbol
!= nullptr)
616 return value_of_variable (sym
.symbol
, sym
.block
);
620 /* See dwarf2loc.h. */
622 unsigned int entry_values_debug
= 0;
624 /* Helper to set entry_values_debug. */
627 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
628 struct cmd_list_element
*c
, const char *value
)
630 fprintf_filtered (file
,
631 _("Entry values and tail call frames debugging is %s.\n"),
635 /* Find DW_TAG_call_site's DW_AT_call_target address.
636 CALLER_FRAME (for registers) can be NULL if it is not known. This function
637 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
640 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
641 struct call_site
*call_site
,
642 struct frame_info
*caller_frame
)
644 switch (call_site
->target
.loc_kind ())
646 case FIELD_LOC_KIND_DWARF_BLOCK
:
648 struct dwarf2_locexpr_baton
*dwarf_block
;
650 struct type
*caller_core_addr_type
;
651 struct gdbarch
*caller_arch
;
653 dwarf_block
= call_site
->target
.loc_dwarf_block ();
654 if (dwarf_block
== NULL
)
656 struct bound_minimal_symbol msym
;
658 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
659 throw_error (NO_ENTRY_VALUE_ERROR
,
660 _("DW_AT_call_target is not specified at %s in %s"),
661 paddress (call_site_gdbarch
, call_site
->pc ()),
662 (msym
.minsym
== NULL
? "???"
663 : msym
.minsym
->print_name ()));
666 if (caller_frame
== NULL
)
668 struct bound_minimal_symbol msym
;
670 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
671 throw_error (NO_ENTRY_VALUE_ERROR
,
672 _("DW_AT_call_target DWARF block resolving "
673 "requires known frame which is currently not "
674 "available at %s in %s"),
675 paddress (call_site_gdbarch
, call_site
->pc ()),
676 (msym
.minsym
== NULL
? "???"
677 : msym
.minsym
->print_name ()));
680 caller_arch
= get_frame_arch (caller_frame
);
681 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
682 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
683 dwarf_block
->data
, dwarf_block
->size
,
685 dwarf_block
->per_objfile
);
686 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
687 if (VALUE_LVAL (val
) == lval_memory
)
688 return value_address (val
);
690 return value_as_address (val
);
693 case FIELD_LOC_KIND_PHYSNAME
:
695 const char *physname
;
696 struct bound_minimal_symbol msym
;
698 physname
= call_site
->target
.loc_physname ();
700 /* Handle both the mangled and demangled PHYSNAME. */
701 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
702 if (msym
.minsym
== NULL
)
704 msym
= lookup_minimal_symbol_by_pc (call_site
->pc () - 1);
705 throw_error (NO_ENTRY_VALUE_ERROR
,
706 _("Cannot find function \"%s\" for a call site target "
708 physname
, paddress (call_site_gdbarch
, call_site
->pc ()),
709 (msym
.minsym
== NULL
? "???"
710 : msym
.minsym
->print_name ()));
713 return BMSYMBOL_VALUE_ADDRESS (msym
);
716 case FIELD_LOC_KIND_PHYSADDR
:
718 dwarf2_per_objfile
*per_objfile
= call_site
->per_objfile
;
719 compunit_symtab
*cust
= per_objfile
->get_symtab (call_site
->per_cu
);
720 int sect_idx
= cust
->block_line_section ();
721 CORE_ADDR delta
= per_objfile
->objfile
->section_offsets
[sect_idx
];
723 return call_site
->target
.loc_physaddr () + delta
;
727 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
731 /* Convert function entry point exact address ADDR to the function which is
732 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
733 NO_ENTRY_VALUE_ERROR otherwise. */
735 static struct symbol
*
736 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
738 struct symbol
*sym
= find_pc_function (addr
);
741 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
742 throw_error (NO_ENTRY_VALUE_ERROR
,
743 _("DW_TAG_call_site resolving failed to find function "
744 "name for address %s"),
745 paddress (gdbarch
, addr
));
748 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
749 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
754 /* Verify function with entry point exact address ADDR can never call itself
755 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
756 can call itself via tail calls.
758 If a funtion can tail call itself its entry value based parameters are
759 unreliable. There is no verification whether the value of some/all
760 parameters is unchanged through the self tail call, we expect if there is
761 a self tail call all the parameters can be modified. */
764 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
768 /* The verification is completely unordered. Track here function addresses
769 which still need to be iterated. */
770 std::vector
<CORE_ADDR
> todo
;
772 /* Track here CORE_ADDRs which were already visited. */
773 std::unordered_set
<CORE_ADDR
> addr_hash
;
775 todo
.push_back (verify_addr
);
776 while (!todo
.empty ())
778 struct symbol
*func_sym
;
779 struct call_site
*call_site
;
784 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
786 for (call_site
= TYPE_TAIL_CALL_LIST (func_sym
->type ());
787 call_site
; call_site
= call_site
->tail_call_next
)
789 CORE_ADDR target_addr
;
791 /* CALLER_FRAME with registers is not available for tail-call jumped
793 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
795 if (target_addr
== verify_addr
)
797 struct bound_minimal_symbol msym
;
799 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
800 throw_error (NO_ENTRY_VALUE_ERROR
,
801 _("DW_OP_entry_value resolving has found "
802 "function \"%s\" at %s can call itself via tail "
804 (msym
.minsym
== NULL
? "???"
805 : msym
.minsym
->print_name ()),
806 paddress (gdbarch
, verify_addr
));
809 if (addr_hash
.insert (target_addr
).second
)
810 todo
.push_back (target_addr
);
815 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
816 ENTRY_VALUES_DEBUG. */
819 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
821 CORE_ADDR addr
= call_site
->pc ();
822 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
824 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
825 (msym
.minsym
== NULL
? "???"
826 : msym
.minsym
->print_name ()));
830 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
831 only top callers and bottom callees which are present in both. GDBARCH is
832 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
833 no remaining possibilities to provide unambiguous non-trivial result.
834 RESULTP should point to NULL on the first (initialization) call. Caller is
835 responsible for xfree of any RESULTP data. */
838 chain_candidate (struct gdbarch
*gdbarch
,
839 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
840 std::vector
<struct call_site
*> *chain
)
842 long length
= chain
->size ();
843 int callers
, callees
, idx
;
845 if (*resultp
== NULL
)
847 /* Create the initial chain containing all the passed PCs. */
849 struct call_site_chain
*result
850 = ((struct call_site_chain
*)
851 xmalloc (sizeof (*result
)
852 + sizeof (*result
->call_site
) * (length
- 1)));
853 result
->length
= length
;
854 result
->callers
= result
->callees
= length
;
855 if (!chain
->empty ())
856 memcpy (result
->call_site
, chain
->data (),
857 sizeof (*result
->call_site
) * length
);
858 resultp
->reset (result
);
860 if (entry_values_debug
)
862 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
863 for (idx
= 0; idx
< length
; idx
++)
864 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
865 fputc_unfiltered ('\n', gdb_stdlog
);
871 if (entry_values_debug
)
873 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
874 for (idx
= 0; idx
< length
; idx
++)
875 tailcall_dump (gdbarch
, chain
->at (idx
));
876 fputc_unfiltered ('\n', gdb_stdlog
);
879 /* Intersect callers. */
881 callers
= std::min ((long) (*resultp
)->callers
, length
);
882 for (idx
= 0; idx
< callers
; idx
++)
883 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
885 (*resultp
)->callers
= idx
;
889 /* Intersect callees. */
891 callees
= std::min ((long) (*resultp
)->callees
, length
);
892 for (idx
= 0; idx
< callees
; idx
++)
893 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
894 != chain
->at (length
- 1 - idx
))
896 (*resultp
)->callees
= idx
;
900 if (entry_values_debug
)
902 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
903 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
904 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
905 fputs_unfiltered (" |", gdb_stdlog
);
906 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
907 tailcall_dump (gdbarch
,
908 (*resultp
)->call_site
[(*resultp
)->length
909 - (*resultp
)->callees
+ idx
]);
910 fputc_unfiltered ('\n', gdb_stdlog
);
913 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
915 /* There are no common callers or callees. It could be also a direct
916 call (which has length 0) with ambiguous possibility of an indirect
917 call - CALLERS == CALLEES == 0 is valid during the first allocation
918 but any subsequence processing of such entry means ambiguity. */
919 resultp
->reset (NULL
);
923 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
924 PC again. In such case there must be two different code paths to reach
925 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
926 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
929 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
930 assumed frames between them use GDBARCH. Use depth first search so we can
931 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
932 would have needless GDB stack overhead. Any unreliability results
933 in thrown NO_ENTRY_VALUE_ERROR. */
935 static gdb::unique_xmalloc_ptr
<call_site_chain
>
936 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
939 CORE_ADDR save_callee_pc
= callee_pc
;
940 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
941 struct call_site
*call_site
;
943 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
944 call_site nor any possible call_site at CALLEE_PC's function is there.
945 Any CALL_SITE in CHAIN will be iterated to its siblings - via
946 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
947 std::vector
<struct call_site
*> chain
;
949 /* We are not interested in the specific PC inside the callee function. */
950 callee_pc
= get_pc_function_start (callee_pc
);
952 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
953 paddress (gdbarch
, save_callee_pc
));
955 /* Mark CALL_SITEs so we do not visit the same ones twice. */
956 std::unordered_set
<CORE_ADDR
> addr_hash
;
958 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
959 at the target's function. All the possible tail call sites in the
960 target's function will get iterated as already pushed into CHAIN via their
962 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
966 CORE_ADDR target_func_addr
;
967 struct call_site
*target_call_site
;
969 /* CALLER_FRAME with registers is not available for tail-call jumped
971 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
973 if (target_func_addr
== callee_pc
)
975 chain_candidate (gdbarch
, &retval
, &chain
);
979 /* There is no way to reach CALLEE_PC again as we would prevent
980 entering it twice as being already marked in ADDR_HASH. */
981 target_call_site
= NULL
;
985 struct symbol
*target_func
;
987 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
988 target_call_site
= TYPE_TAIL_CALL_LIST (target_func
->type ());
993 /* Attempt to visit TARGET_CALL_SITE. */
995 if (target_call_site
)
997 if (addr_hash
.insert (target_call_site
->pc ()).second
)
999 /* Successfully entered TARGET_CALL_SITE. */
1001 chain
.push_back (target_call_site
);
1006 /* Backtrack (without revisiting the originating call_site). Try the
1007 callers's sibling; if there isn't any try the callers's callers's
1010 target_call_site
= NULL
;
1011 while (!chain
.empty ())
1013 call_site
= chain
.back ();
1016 size_t removed
= addr_hash
.erase (call_site
->pc ());
1017 gdb_assert (removed
== 1);
1019 target_call_site
= call_site
->tail_call_next
;
1020 if (target_call_site
)
1024 while (target_call_site
);
1029 call_site
= chain
.back ();
1034 struct bound_minimal_symbol msym_caller
, msym_callee
;
1036 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1037 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1038 throw_error (NO_ENTRY_VALUE_ERROR
,
1039 _("There are no unambiguously determinable intermediate "
1040 "callers or callees between caller function \"%s\" at %s "
1041 "and callee function \"%s\" at %s"),
1042 (msym_caller
.minsym
== NULL
1043 ? "???" : msym_caller
.minsym
->print_name ()),
1044 paddress (gdbarch
, caller_pc
),
1045 (msym_callee
.minsym
== NULL
1046 ? "???" : msym_callee
.minsym
->print_name ()),
1047 paddress (gdbarch
, callee_pc
));
1053 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1054 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1055 constructed return NULL. */
1057 gdb::unique_xmalloc_ptr
<call_site_chain
>
1058 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1059 CORE_ADDR callee_pc
)
1061 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1065 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1067 catch (const gdb_exception_error
&e
)
1069 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1071 if (entry_values_debug
)
1072 exception_print (gdb_stdout
, e
);
1083 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1086 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1087 enum call_site_parameter_kind kind
,
1088 union call_site_parameter_u kind_u
)
1090 if (kind
== parameter
->kind
)
1093 case CALL_SITE_PARAMETER_DWARF_REG
:
1094 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1096 case CALL_SITE_PARAMETER_FB_OFFSET
:
1097 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1099 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1100 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1107 struct call_site_parameter
*
1108 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1109 enum call_site_parameter_kind kind
,
1110 union call_site_parameter_u kind_u
,
1111 dwarf2_per_cu_data
**per_cu_return
,
1112 dwarf2_per_objfile
**per_objfile_return
)
1114 CORE_ADDR func_addr
, caller_pc
;
1115 struct gdbarch
*gdbarch
;
1116 struct frame_info
*caller_frame
;
1117 struct call_site
*call_site
;
1119 /* Initialize it just to avoid a GCC false warning. */
1120 struct call_site_parameter
*parameter
= NULL
;
1121 CORE_ADDR target_addr
;
1123 while (get_frame_type (frame
) == INLINE_FRAME
)
1125 frame
= get_prev_frame (frame
);
1126 gdb_assert (frame
!= NULL
);
1129 func_addr
= get_frame_func (frame
);
1130 gdbarch
= get_frame_arch (frame
);
1131 caller_frame
= get_prev_frame (frame
);
1132 if (gdbarch
!= frame_unwind_arch (frame
))
1134 struct bound_minimal_symbol msym
1135 = lookup_minimal_symbol_by_pc (func_addr
);
1136 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1138 throw_error (NO_ENTRY_VALUE_ERROR
,
1139 _("DW_OP_entry_value resolving callee gdbarch %s "
1140 "(of %s (%s)) does not match caller gdbarch %s"),
1141 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1142 paddress (gdbarch
, func_addr
),
1143 (msym
.minsym
== NULL
? "???"
1144 : msym
.minsym
->print_name ()),
1145 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1148 if (caller_frame
== NULL
)
1150 struct bound_minimal_symbol msym
1151 = lookup_minimal_symbol_by_pc (func_addr
);
1153 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1154 "requires caller of %s (%s)"),
1155 paddress (gdbarch
, func_addr
),
1156 (msym
.minsym
== NULL
? "???"
1157 : msym
.minsym
->print_name ()));
1159 caller_pc
= get_frame_pc (caller_frame
);
1160 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1162 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1163 if (target_addr
!= func_addr
)
1165 struct minimal_symbol
*target_msym
, *func_msym
;
1167 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1168 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1169 throw_error (NO_ENTRY_VALUE_ERROR
,
1170 _("DW_OP_entry_value resolving expects callee %s at %s "
1171 "but the called frame is for %s at %s"),
1172 (target_msym
== NULL
? "???"
1173 : target_msym
->print_name ()),
1174 paddress (gdbarch
, target_addr
),
1175 func_msym
== NULL
? "???" : func_msym
->print_name (),
1176 paddress (gdbarch
, func_addr
));
1179 /* No entry value based parameters would be reliable if this function can
1180 call itself via tail calls. */
1181 func_verify_no_selftailcall (gdbarch
, func_addr
);
1183 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1185 parameter
= &call_site
->parameter
[iparams
];
1186 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1189 if (iparams
== call_site
->parameter_count
)
1191 struct minimal_symbol
*msym
1192 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1194 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1195 determine its value. */
1196 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1197 "at DW_TAG_call_site %s at %s"),
1198 paddress (gdbarch
, caller_pc
),
1199 msym
== NULL
? "???" : msym
->print_name ());
1202 *per_cu_return
= call_site
->per_cu
;
1203 *per_objfile_return
= call_site
->per_objfile
;
1207 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1208 the normal DW_AT_call_value block. Otherwise return the
1209 DW_AT_call_data_value (dereferenced) block.
1211 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1214 Function always returns non-NULL, non-optimized out value. It throws
1215 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1217 static struct value
*
1218 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1219 CORE_ADDR deref_size
, struct type
*type
,
1220 struct frame_info
*caller_frame
,
1221 dwarf2_per_cu_data
*per_cu
,
1222 dwarf2_per_objfile
*per_objfile
)
1224 const gdb_byte
*data_src
;
1227 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1228 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1230 /* DEREF_SIZE size is not verified here. */
1231 if (data_src
== NULL
)
1232 throw_error (NO_ENTRY_VALUE_ERROR
,
1233 _("Cannot resolve DW_AT_call_data_value"));
1235 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data_src
, size
, per_cu
,
1236 per_objfile
, false);
1239 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1240 the indirect method on it, that is use its stored target value, the sole
1241 purpose of entry_data_value_funcs.. */
1243 static struct value
*
1244 entry_data_value_coerce_ref (const struct value
*value
)
1246 struct type
*checked_type
= check_typedef (value_type (value
));
1247 struct value
*target_val
;
1249 if (!TYPE_IS_REFERENCE (checked_type
))
1252 target_val
= (struct value
*) value_computed_closure (value
);
1253 value_incref (target_val
);
1257 /* Implement copy_closure. */
1260 entry_data_value_copy_closure (const struct value
*v
)
1262 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1264 value_incref (target_val
);
1268 /* Implement free_closure. */
1271 entry_data_value_free_closure (struct value
*v
)
1273 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1275 value_decref (target_val
);
1278 /* Vector for methods for an entry value reference where the referenced value
1279 is stored in the caller. On the first dereference use
1280 DW_AT_call_data_value in the caller. */
1282 static const struct lval_funcs entry_data_value_funcs
=
1287 NULL
, /* indirect */
1288 entry_data_value_coerce_ref
,
1289 NULL
, /* check_synthetic_pointer */
1290 entry_data_value_copy_closure
,
1291 entry_data_value_free_closure
1294 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1295 are used to match DW_AT_location at the caller's
1296 DW_TAG_call_site_parameter.
1298 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1299 cannot resolve the parameter for any reason. */
1301 static struct value
*
1302 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1303 enum call_site_parameter_kind kind
,
1304 union call_site_parameter_u kind_u
)
1306 struct type
*checked_type
= check_typedef (type
);
1307 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1308 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1309 struct value
*outer_val
, *target_val
, *val
;
1310 struct call_site_parameter
*parameter
;
1311 dwarf2_per_cu_data
*caller_per_cu
;
1312 dwarf2_per_objfile
*caller_per_objfile
;
1314 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1316 &caller_per_objfile
);
1318 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1321 caller_per_objfile
);
1323 /* Check if DW_AT_call_data_value cannot be used. If it should be
1324 used and it is not available do not fall back to OUTER_VAL - dereferencing
1325 TYPE_CODE_REF with non-entry data value would give current value - not the
1328 if (!TYPE_IS_REFERENCE (checked_type
)
1329 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1332 target_val
= dwarf_entry_parameter_to_value (parameter
,
1333 TYPE_LENGTH (target_type
),
1334 target_type
, caller_frame
,
1336 caller_per_objfile
);
1338 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1339 release_value (target_val
).release ());
1341 /* Copy the referencing pointer to the new computed value. */
1342 memcpy (value_contents_raw (val
).data (),
1343 value_contents_raw (outer_val
).data (),
1344 TYPE_LENGTH (checked_type
));
1345 set_value_lazy (val
, 0);
1350 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1351 SIZE are DWARF block used to match DW_AT_location at the caller's
1352 DW_TAG_call_site_parameter.
1354 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1355 cannot resolve the parameter for any reason. */
1357 static struct value
*
1358 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1359 const gdb_byte
*block
, size_t block_len
)
1361 union call_site_parameter_u kind_u
;
1363 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1364 if (kind_u
.dwarf_reg
!= -1)
1365 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1368 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1369 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1372 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1373 suppressed during normal operation. The expression can be arbitrary if
1374 there is no caller-callee entry value binding expected. */
1375 throw_error (NO_ENTRY_VALUE_ERROR
,
1376 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1377 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1380 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1382 static struct value
*
1383 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1384 dwarf2_per_cu_data
*per_cu
,
1385 dwarf2_per_objfile
*per_objfile
,
1388 struct value
*result
= NULL
;
1389 const gdb_byte
*bytes
;
1392 auto_obstack temp_obstack
;
1393 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1394 &temp_obstack
, &len
);
1398 if (byte_offset
>= 0
1399 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1401 bytes
+= byte_offset
;
1402 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1405 invalid_synthetic_pointer ();
1408 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1416 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1417 dwarf2_per_cu_data
*per_cu
,
1418 dwarf2_per_objfile
*per_objfile
,
1419 struct frame_info
*frame
, struct type
*type
,
1420 bool resolve_abstract_p
)
1422 /* Fetch the location expression of the DIE we're pointing to. */
1423 auto get_frame_address_in_block_wrapper
= [frame
] ()
1425 return get_frame_address_in_block (frame
);
1427 struct dwarf2_locexpr_baton baton
1428 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1429 get_frame_address_in_block_wrapper
,
1430 resolve_abstract_p
);
1432 /* Get type of pointed-to DIE. */
1433 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1435 if (orig_type
== NULL
)
1436 invalid_synthetic_pointer ();
1438 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1439 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1440 or it may've been optimized out. */
1441 if (baton
.data
!= NULL
)
1442 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1443 baton
.size
, baton
.per_cu
,
1445 TYPE_TARGET_TYPE (type
),
1448 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1452 /* Evaluate a location description, starting at DATA and with length
1453 SIZE, to find the current location of variable of TYPE in the
1454 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
1455 location of the subobject of type SUBOBJ_TYPE at byte offset
1456 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
1458 static struct value
*
1459 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
1460 const gdb_byte
*data
, size_t size
,
1461 dwarf2_per_cu_data
*per_cu
,
1462 dwarf2_per_objfile
*per_objfile
,
1463 struct type
*subobj_type
,
1464 LONGEST subobj_byte_offset
,
1467 if (subobj_type
== NULL
)
1470 subobj_byte_offset
= 0;
1472 else if (subobj_byte_offset
< 0)
1473 invalid_synthetic_pointer ();
1476 return allocate_optimized_out_value (subobj_type
);
1478 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1481 scoped_value_mark free_values
;
1485 retval
= ctx
.evaluate (data
, size
, as_lval
, per_cu
, frame
, nullptr,
1486 type
, subobj_type
, subobj_byte_offset
);
1488 catch (const gdb_exception_error
&ex
)
1490 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1492 free_values
.free_to_mark ();
1493 retval
= allocate_value (subobj_type
);
1494 mark_value_bytes_unavailable (retval
, 0,
1495 TYPE_LENGTH (subobj_type
));
1498 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1500 if (entry_values_debug
)
1501 exception_print (gdb_stdout
, ex
);
1502 free_values
.free_to_mark ();
1503 return allocate_optimized_out_value (subobj_type
);
1509 /* We need to clean up all the values that are not needed any more.
1510 The problem with a value_ref_ptr class is that it disconnects the
1511 RETVAL from the value garbage collection, so we need to make
1512 a copy of that value on the stack to keep everything consistent.
1513 The value_ref_ptr will clean up after itself at the end of this block. */
1514 value_ref_ptr value_holder
= value_ref_ptr::new_reference (retval
);
1515 free_values
.free_to_mark ();
1517 return value_copy (retval
);
1520 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
1521 passes 0 as the byte_offset. */
1524 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
1525 const gdb_byte
*data
, size_t size
,
1526 dwarf2_per_cu_data
*per_cu
,
1527 dwarf2_per_objfile
*per_objfile
, bool as_lval
)
1529 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
1530 per_objfile
, NULL
, 0, as_lval
);
1533 /* Evaluates a dwarf expression and stores the result in VAL,
1534 expecting that the dwarf expression only produces a single
1535 CORE_ADDR. FRAME is the frame in which the expression is
1536 evaluated. ADDR_STACK is a context (location of a variable) and
1537 might be needed to evaluate the location expression.
1538 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
1539 or the default of 0) should be pushed on the DWARF expression
1540 evaluation stack before evaluating the expression; this is required
1541 by certain forms of DWARF expression. Returns 1 on success, 0
1545 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
1546 struct frame_info
*frame
,
1547 const struct property_addr_info
*addr_stack
,
1549 bool push_initial_value
,
1552 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
1555 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
1556 dwarf2_per_cu_data
*per_cu
= dlbaton
->per_cu
;
1557 dwarf_expr_context
ctx (per_objfile
, per_cu
->addr_size ());
1560 scoped_value_mark free_values
;
1562 if (push_initial_value
)
1564 if (addr_stack
!= nullptr)
1565 ctx
.push_address (addr_stack
->addr
, false);
1567 ctx
.push_address (0, false);
1572 result
= ctx
.evaluate (dlbaton
->data
, dlbaton
->size
,
1573 true, per_cu
, frame
, addr_stack
);
1575 catch (const gdb_exception_error
&ex
)
1577 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1581 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
1583 if (entry_values_debug
)
1584 exception_print (gdb_stdout
, ex
);
1591 if (value_optimized_out (result
))
1594 if (VALUE_LVAL (result
) == lval_memory
)
1595 *valp
= value_address (result
);
1598 if (VALUE_LVAL (result
) == not_lval
)
1599 *is_reference
= false;
1601 *valp
= value_as_address (result
);
1607 /* See dwarf2loc.h. */
1610 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
1611 struct frame_info
*frame
,
1612 const struct property_addr_info
*addr_stack
,
1614 bool push_initial_value
)
1619 if (frame
== NULL
&& has_stack_frames ())
1620 frame
= get_selected_frame (NULL
);
1622 switch (prop
->kind ())
1626 const struct dwarf2_property_baton
*baton
1627 = (const struct dwarf2_property_baton
*) prop
->baton ();
1628 gdb_assert (baton
->property_type
!= NULL
);
1630 bool is_reference
= baton
->locexpr
.is_reference
;
1631 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
1632 value
, push_initial_value
, &is_reference
))
1636 struct value
*val
= value_at (baton
->property_type
, *value
);
1637 *value
= value_as_address (val
);
1641 gdb_assert (baton
->property_type
!= NULL
);
1643 struct type
*type
= check_typedef (baton
->property_type
);
1644 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
1645 && !type
->is_unsigned ())
1647 /* If we have a valid return candidate and it's value
1648 is signed, we have to sign-extend the value because
1649 CORE_ADDR on 64bit machine has 8 bytes but address
1650 size of an 32bit application is bytes. */
1652 = (baton
->locexpr
.per_cu
->addr_size ()
1654 const CORE_ADDR neg_mask
1655 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
1657 /* Check if signed bit is set and sign-extend values. */
1658 if (*value
& neg_mask
)
1669 struct dwarf2_property_baton
*baton
1670 = (struct dwarf2_property_baton
*) prop
->baton ();
1672 const gdb_byte
*data
;
1677 || !get_frame_address_in_block_if_available (frame
, &pc
))
1680 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1683 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
1684 size
, baton
->loclist
.per_cu
,
1685 baton
->loclist
.per_objfile
);
1686 if (!value_optimized_out (val
))
1688 *value
= value_as_address (val
);
1696 *value
= prop
->const_val ();
1699 case PROP_ADDR_OFFSET
:
1701 struct dwarf2_property_baton
*baton
1702 = (struct dwarf2_property_baton
*) prop
->baton ();
1703 const struct property_addr_info
*pinfo
;
1706 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
1708 /* This approach lets us avoid checking the qualifiers. */
1709 if (TYPE_MAIN_TYPE (pinfo
->type
)
1710 == TYPE_MAIN_TYPE (baton
->property_type
))
1714 error (_("cannot find reference address for offset property"));
1715 if (pinfo
->valaddr
.data () != NULL
)
1716 val
= value_from_contents
1717 (baton
->offset_info
.type
,
1718 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
1720 val
= value_at (baton
->offset_info
.type
,
1721 pinfo
->addr
+ baton
->offset_info
.offset
);
1722 *value
= value_as_address (val
);
1726 case PROP_VARIABLE_NAME
:
1728 struct value
*val
= compute_var_value (prop
->variable_name ());
1731 *value
= value_as_long (val
);
1741 /* See dwarf2loc.h. */
1744 dwarf2_compile_property_to_c (string_file
*stream
,
1745 const char *result_name
,
1746 struct gdbarch
*gdbarch
,
1747 std::vector
<bool> ®isters_used
,
1748 const struct dynamic_prop
*prop
,
1752 struct dwarf2_property_baton
*baton
1753 = (struct dwarf2_property_baton
*) prop
->baton ();
1754 const gdb_byte
*data
;
1756 dwarf2_per_cu_data
*per_cu
;
1757 dwarf2_per_objfile
*per_objfile
;
1759 if (prop
->kind () == PROP_LOCEXPR
)
1761 data
= baton
->locexpr
.data
;
1762 size
= baton
->locexpr
.size
;
1763 per_cu
= baton
->locexpr
.per_cu
;
1764 per_objfile
= baton
->locexpr
.per_objfile
;
1768 gdb_assert (prop
->kind () == PROP_LOCLIST
);
1770 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
1771 per_cu
= baton
->loclist
.per_cu
;
1772 per_objfile
= baton
->loclist
.per_objfile
;
1775 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
1776 gdbarch
, registers_used
,
1777 per_cu
->addr_size (),
1778 data
, data
+ size
, per_cu
, per_objfile
);
1781 /* Compute the correct symbol_needs_kind value for the location
1784 Implemented by traversing the logical control flow graph of the
1787 static enum symbol_needs_kind
1788 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
1789 dwarf2_per_cu_data
*per_cu
,
1790 dwarf2_per_objfile
*per_objfile
,
1791 bfd_endian byte_order
,
1796 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
1798 /* If the expression is empty, we have nothing to do. */
1800 return symbol_needs
;
1802 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
1804 /* List of operations to visit. Operations in this list are not visited yet,
1805 so are not in VISITED_OPS (and vice-versa). */
1806 std::vector
<const gdb_byte
*> ops_to_visit
;
1808 /* Operations already visited. */
1809 std::unordered_set
<const gdb_byte
*> visited_ops
;
1811 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
1812 hasn't been visited yet. */
1813 auto insert_in_ops_to_visit
1814 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
1816 if (op_ptr
>= expr_end
)
1819 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
1822 ops_to_visit
.push_back (op_ptr
);
1825 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
1827 const int max_depth
= 256;
1829 if (depth
> max_depth
)
1830 error (_("DWARF-2 expression error: Loop detected."));
1834 /* Initialize the to-visit list with the first operation. */
1835 insert_in_ops_to_visit (&expr
[0]);
1837 while (!ops_to_visit
.empty ())
1839 /* Pop one op to visit, mark it as visited. */
1840 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
1841 ops_to_visit
.pop_back ();
1842 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
1843 visited_ops
.insert (op_ptr
);
1845 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
1847 /* Most operations have a single possible following operation
1848 (they are not conditional branches). The code below updates
1849 OP_PTR to point to that following operation, which is pushed
1850 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
1851 OP_PTR pointing just after the operand. */
1854 /* The DWARF expression might have a bug causing an infinite
1855 loop. In that case, quitting is the only way out. */
1892 case DW_OP_stack_value
:
1919 case DW_OP_GNU_push_tls_address
:
1921 case DW_OP_GNU_uninit
:
1922 case DW_OP_push_object_address
:
1925 case DW_OP_form_tls_address
:
1926 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
1927 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
1931 case DW_OP_GNU_convert
:
1932 case DW_OP_reinterpret
:
1933 case DW_OP_GNU_reinterpret
:
1935 case DW_OP_GNU_addr_index
:
1936 case DW_OP_GNU_const_index
:
1938 case DW_OP_plus_uconst
:
1940 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1944 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1947 case DW_OP_bit_piece
:
1948 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1949 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1952 case DW_OP_deref_type
:
1953 case DW_OP_GNU_deref_type
:
1955 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
1959 op_ptr
+= addr_size
;
2049 case DW_OP_call_frame_cfa
:
2050 case DW_OP_entry_value
:
2051 case DW_OP_GNU_entry_value
:
2052 case DW_OP_GNU_parameter_ref
:
2053 case DW_OP_regval_type
:
2054 case DW_OP_GNU_regval_type
:
2055 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2058 case DW_OP_implicit_value
:
2061 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2066 case DW_OP_implicit_pointer
:
2067 case DW_OP_GNU_implicit_pointer
:
2068 op_ptr
+= ref_addr_size
;
2069 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2072 case DW_OP_deref_size
:
2079 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2087 /* This is the only operation that pushes two operations in
2088 the to-visit list, so handle it all here. */
2089 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2092 insert_in_ops_to_visit (op_ptr
+ offset
);
2093 insert_in_ops_to_visit (op_ptr
);
2100 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2102 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2105 auto get_frame_pc
= [&symbol_needs
] ()
2107 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2111 struct dwarf2_locexpr_baton baton
2112 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2116 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2117 we dont have to check the baton content. */
2118 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2120 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2121 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2124 = dwarf2_get_symbol_read_needs (sub_expr
,
2127 gdbarch_byte_order (arch
),
2128 baton
.per_cu
->addr_size (),
2129 baton
.per_cu
->ref_addr_size (),
2135 case DW_OP_GNU_variable_value
:
2137 sect_offset sect_off
2138 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2141 op_ptr
+= ref_addr_size
;
2143 struct type
*die_type
2144 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2147 if (die_type
== NULL
)
2148 error (_("Bad DW_OP_GNU_variable_value DIE."));
2150 /* Note: Things still work when the following test is
2151 removed. This test and error is here to conform to the
2152 proposed specification. */
2153 if (die_type
->code () != TYPE_CODE_INT
2154 && die_type
->code () != TYPE_CODE_PTR
)
2155 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2156 "an integer or pointer."));
2158 auto get_frame_pc
= [&symbol_needs
] ()
2160 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2164 struct dwarf2_locexpr_baton baton
2165 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2167 get_frame_pc
, true);
2169 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2170 we dont have to check the baton content. */
2171 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2173 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2174 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2177 = dwarf2_get_symbol_read_needs (sub_expr
,
2180 gdbarch_byte_order (arch
),
2181 baton
.per_cu
->addr_size (),
2182 baton
.per_cu
->ref_addr_size (),
2188 case DW_OP_const_type
:
2189 case DW_OP_GNU_const_type
:
2192 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2193 gdb_byte offset
= *op_ptr
++;
2199 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2202 /* If it is known that a frame information is
2203 needed we can stop parsing the expression. */
2204 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2207 insert_in_ops_to_visit (op_ptr
);
2210 return symbol_needs
;
2213 /* A helper function that throws an unimplemented error mentioning a
2214 given DWARF operator. */
2216 static void ATTRIBUTE_NORETURN
2217 unimplemented (unsigned int op
)
2219 const char *name
= get_DW_OP_name (op
);
2222 error (_("DWARF operator %s cannot be translated to an agent expression"),
2225 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2226 "to an agent expression"),
2232 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2233 can issue a complaint, which is better than having every target's
2234 implementation of dwarf2_reg_to_regnum do it. */
2237 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2239 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2243 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2248 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2249 Throw an error because DWARF_REG is bad. */
2252 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2254 /* Still want to print -1 as "-1".
2255 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2256 but that's overkill for now. */
2257 if ((int) dwarf_reg
== dwarf_reg
)
2258 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2259 error (_("Unable to access DWARF register number %s"),
2260 pulongest (dwarf_reg
));
2263 /* See dwarf2loc.h. */
2266 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2270 if (dwarf_reg
> INT_MAX
)
2271 throw_bad_regnum_error (dwarf_reg
);
2272 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2273 bad, but that's ok. */
2274 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2276 throw_bad_regnum_error (dwarf_reg
);
2280 /* A helper function that emits an access to memory. ARCH is the
2281 target architecture. EXPR is the expression which we are building.
2282 NBITS is the number of bits we want to read. This emits the
2283 opcodes needed to read the memory and then extract the desired
2287 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2289 ULONGEST nbytes
= (nbits
+ 7) / 8;
2291 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2294 ax_trace_quick (expr
, nbytes
);
2297 ax_simple (expr
, aop_ref8
);
2298 else if (nbits
<= 16)
2299 ax_simple (expr
, aop_ref16
);
2300 else if (nbits
<= 32)
2301 ax_simple (expr
, aop_ref32
);
2303 ax_simple (expr
, aop_ref64
);
2305 /* If we read exactly the number of bytes we wanted, we're done. */
2306 if (8 * nbytes
== nbits
)
2309 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2311 /* On a bits-big-endian machine, we want the high-order
2313 ax_const_l (expr
, 8 * nbytes
- nbits
);
2314 ax_simple (expr
, aop_rsh_unsigned
);
2318 /* On a bits-little-endian box, we want the low-order NBITS. */
2319 ax_zero_ext (expr
, nbits
);
2323 /* Compile a DWARF location expression to an agent expression.
2325 EXPR is the agent expression we are building.
2326 LOC is the agent value we modify.
2327 ARCH is the architecture.
2328 ADDR_SIZE is the size of addresses, in bytes.
2329 OP_PTR is the start of the location expression.
2330 OP_END is one past the last byte of the location expression.
2332 This will throw an exception for various kinds of errors -- for
2333 example, if the expression cannot be compiled, or if the expression
2337 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
2338 unsigned int addr_size
, const gdb_byte
*op_ptr
,
2339 const gdb_byte
*op_end
,
2340 dwarf2_per_cu_data
*per_cu
,
2341 dwarf2_per_objfile
*per_objfile
)
2343 gdbarch
*arch
= expr
->gdbarch
;
2344 std::vector
<int> dw_labels
, patches
;
2345 const gdb_byte
* const base
= op_ptr
;
2346 const gdb_byte
*previous_piece
= op_ptr
;
2347 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
2348 ULONGEST bits_collected
= 0;
2349 unsigned int addr_size_bits
= 8 * addr_size
;
2350 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
2352 std::vector
<int> offsets (op_end
- op_ptr
, -1);
2354 /* By default we are making an address. */
2355 loc
->kind
= axs_lvalue_memory
;
2357 while (op_ptr
< op_end
)
2359 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
2360 uint64_t uoffset
, reg
;
2364 offsets
[op_ptr
- base
] = expr
->len
;
2367 /* Our basic approach to code generation is to map DWARF
2368 operations directly to AX operations. However, there are
2371 First, DWARF works on address-sized units, but AX always uses
2372 LONGEST. For most operations we simply ignore this
2373 difference; instead we generate sign extensions as needed
2374 before division and comparison operations. It would be nice
2375 to omit the sign extensions, but there is no way to determine
2376 the size of the target's LONGEST. (This code uses the size
2377 of the host LONGEST in some cases -- that is a bug but it is
2380 Second, some DWARF operations cannot be translated to AX.
2381 For these we simply fail. See
2382 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2417 ax_const_l (expr
, op
- DW_OP_lit0
);
2421 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
2422 op_ptr
+= addr_size
;
2423 /* Some versions of GCC emit DW_OP_addr before
2424 DW_OP_GNU_push_tls_address. In this case the value is an
2425 index, not an address. We don't support things like
2426 branching between the address and the TLS op. */
2427 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
2428 uoffset
+= per_objfile
->objfile
->text_section_offset ();
2429 ax_const_l (expr
, uoffset
);
2433 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
2438 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
2443 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
2448 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
2453 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
2458 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
2463 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
2468 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
2473 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2474 ax_const_l (expr
, uoffset
);
2478 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2479 ax_const_l (expr
, offset
);
2514 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2515 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
2516 loc
->kind
= axs_lvalue_register
;
2520 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2521 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
2522 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2523 loc
->kind
= axs_lvalue_register
;
2526 case DW_OP_implicit_value
:
2530 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
2531 if (op_ptr
+ len
> op_end
)
2532 error (_("DW_OP_implicit_value: too few bytes available."));
2533 if (len
> sizeof (ULONGEST
))
2534 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
2537 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
2540 dwarf_expr_require_composition (op_ptr
, op_end
,
2541 "DW_OP_implicit_value");
2543 loc
->kind
= axs_rvalue
;
2547 case DW_OP_stack_value
:
2548 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
2549 loc
->kind
= axs_rvalue
;
2584 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2585 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
2589 ax_const_l (expr
, offset
);
2590 ax_simple (expr
, aop_add
);
2596 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2597 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2598 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
2602 ax_const_l (expr
, offset
);
2603 ax_simple (expr
, aop_add
);
2610 const gdb_byte
*datastart
;
2612 const struct block
*b
;
2613 struct symbol
*framefunc
;
2615 b
= block_for_pc (expr
->scope
);
2618 error (_("No block found for address"));
2620 framefunc
= block_linkage_function (b
);
2623 error (_("No function found for block"));
2625 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
2626 &datastart
, &datalen
);
2628 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
2629 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
2630 datastart
+ datalen
, per_cu
,
2632 if (loc
->kind
== axs_lvalue_register
)
2633 require_rvalue (expr
, loc
);
2637 ax_const_l (expr
, offset
);
2638 ax_simple (expr
, aop_add
);
2641 loc
->kind
= axs_lvalue_memory
;
2646 ax_simple (expr
, aop_dup
);
2650 ax_simple (expr
, aop_pop
);
2655 ax_pick (expr
, offset
);
2659 ax_simple (expr
, aop_swap
);
2667 ax_simple (expr
, aop_rot
);
2671 case DW_OP_deref_size
:
2675 if (op
== DW_OP_deref_size
)
2680 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
2681 error (_("Unsupported size %d in %s"),
2682 size
, get_DW_OP_name (op
));
2683 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
2688 /* Sign extend the operand. */
2689 ax_ext (expr
, addr_size_bits
);
2690 ax_simple (expr
, aop_dup
);
2691 ax_const_l (expr
, 0);
2692 ax_simple (expr
, aop_less_signed
);
2693 ax_simple (expr
, aop_log_not
);
2694 i
= ax_goto (expr
, aop_if_goto
);
2695 /* We have to emit 0 - X. */
2696 ax_const_l (expr
, 0);
2697 ax_simple (expr
, aop_swap
);
2698 ax_simple (expr
, aop_sub
);
2699 ax_label (expr
, i
, expr
->len
);
2703 /* No need to sign extend here. */
2704 ax_const_l (expr
, 0);
2705 ax_simple (expr
, aop_swap
);
2706 ax_simple (expr
, aop_sub
);
2710 /* Sign extend the operand. */
2711 ax_ext (expr
, addr_size_bits
);
2712 ax_simple (expr
, aop_bit_not
);
2715 case DW_OP_plus_uconst
:
2716 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
2717 /* It would be really weird to emit `DW_OP_plus_uconst 0',
2718 but we micro-optimize anyhow. */
2721 ax_const_l (expr
, reg
);
2722 ax_simple (expr
, aop_add
);
2727 ax_simple (expr
, aop_bit_and
);
2731 /* Sign extend the operands. */
2732 ax_ext (expr
, addr_size_bits
);
2733 ax_simple (expr
, aop_swap
);
2734 ax_ext (expr
, addr_size_bits
);
2735 ax_simple (expr
, aop_swap
);
2736 ax_simple (expr
, aop_div_signed
);
2740 ax_simple (expr
, aop_sub
);
2744 ax_simple (expr
, aop_rem_unsigned
);
2748 ax_simple (expr
, aop_mul
);
2752 ax_simple (expr
, aop_bit_or
);
2756 ax_simple (expr
, aop_add
);
2760 ax_simple (expr
, aop_lsh
);
2764 ax_simple (expr
, aop_rsh_unsigned
);
2768 ax_simple (expr
, aop_rsh_signed
);
2772 ax_simple (expr
, aop_bit_xor
);
2776 /* Sign extend the operands. */
2777 ax_ext (expr
, addr_size_bits
);
2778 ax_simple (expr
, aop_swap
);
2779 ax_ext (expr
, addr_size_bits
);
2780 /* Note no swap here: A <= B is !(B < A). */
2781 ax_simple (expr
, aop_less_signed
);
2782 ax_simple (expr
, aop_log_not
);
2786 /* Sign extend the operands. */
2787 ax_ext (expr
, addr_size_bits
);
2788 ax_simple (expr
, aop_swap
);
2789 ax_ext (expr
, addr_size_bits
);
2790 ax_simple (expr
, aop_swap
);
2791 /* A >= B is !(A < B). */
2792 ax_simple (expr
, aop_less_signed
);
2793 ax_simple (expr
, aop_log_not
);
2797 /* Sign extend the operands. */
2798 ax_ext (expr
, addr_size_bits
);
2799 ax_simple (expr
, aop_swap
);
2800 ax_ext (expr
, addr_size_bits
);
2801 /* No need for a second swap here. */
2802 ax_simple (expr
, aop_equal
);
2806 /* Sign extend the operands. */
2807 ax_ext (expr
, addr_size_bits
);
2808 ax_simple (expr
, aop_swap
);
2809 ax_ext (expr
, addr_size_bits
);
2810 ax_simple (expr
, aop_swap
);
2811 ax_simple (expr
, aop_less_signed
);
2815 /* Sign extend the operands. */
2816 ax_ext (expr
, addr_size_bits
);
2817 ax_simple (expr
, aop_swap
);
2818 ax_ext (expr
, addr_size_bits
);
2819 /* Note no swap here: A > B is B < A. */
2820 ax_simple (expr
, aop_less_signed
);
2824 /* Sign extend the operands. */
2825 ax_ext (expr
, addr_size_bits
);
2826 ax_simple (expr
, aop_swap
);
2827 ax_ext (expr
, addr_size_bits
);
2828 /* No need for a swap here. */
2829 ax_simple (expr
, aop_equal
);
2830 ax_simple (expr
, aop_log_not
);
2833 case DW_OP_call_frame_cfa
:
2836 CORE_ADDR text_offset
;
2838 const gdb_byte
*cfa_start
, *cfa_end
;
2840 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
2842 &text_offset
, &cfa_start
, &cfa_end
))
2845 ax_reg (expr
, regnum
);
2848 ax_const_l (expr
, off
);
2849 ax_simple (expr
, aop_add
);
2854 /* Another expression. */
2855 ax_const_l (expr
, text_offset
);
2856 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
2857 cfa_end
, per_cu
, per_objfile
);
2860 loc
->kind
= axs_lvalue_memory
;
2864 case DW_OP_GNU_push_tls_address
:
2865 case DW_OP_form_tls_address
:
2869 case DW_OP_push_object_address
:
2874 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2876 i
= ax_goto (expr
, aop_goto
);
2877 dw_labels
.push_back (op_ptr
+ offset
- base
);
2878 patches
.push_back (i
);
2882 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2884 /* Zero extend the operand. */
2885 ax_zero_ext (expr
, addr_size_bits
);
2886 i
= ax_goto (expr
, aop_if_goto
);
2887 dw_labels
.push_back (op_ptr
+ offset
- base
);
2888 patches
.push_back (i
);
2895 case DW_OP_bit_piece
:
2899 if (op_ptr
- 1 == previous_piece
)
2900 error (_("Cannot translate empty pieces to agent expressions"));
2901 previous_piece
= op_ptr
- 1;
2903 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
2904 if (op
== DW_OP_piece
)
2910 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
2912 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
2913 error (_("Expression pieces exceed word size"));
2915 /* Access the bits. */
2918 case axs_lvalue_register
:
2919 ax_reg (expr
, loc
->u
.reg
);
2922 case axs_lvalue_memory
:
2923 /* Offset the pointer, if needed. */
2926 ax_const_l (expr
, uoffset
/ 8);
2927 ax_simple (expr
, aop_add
);
2930 access_memory (arch
, expr
, size
);
2934 /* For a bits-big-endian target, shift up what we already
2935 have. For a bits-little-endian target, shift up the
2936 new data. Note that there is a potential bug here if
2937 the DWARF expression leaves multiple values on the
2939 if (bits_collected
> 0)
2941 if (bits_big_endian
)
2943 ax_simple (expr
, aop_swap
);
2944 ax_const_l (expr
, size
);
2945 ax_simple (expr
, aop_lsh
);
2946 /* We don't need a second swap here, because
2947 aop_bit_or is symmetric. */
2951 ax_const_l (expr
, size
);
2952 ax_simple (expr
, aop_lsh
);
2954 ax_simple (expr
, aop_bit_or
);
2957 bits_collected
+= size
;
2958 loc
->kind
= axs_rvalue
;
2962 case DW_OP_GNU_uninit
:
2968 struct dwarf2_locexpr_baton block
;
2969 int size
= (op
== DW_OP_call2
? 2 : 4);
2971 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
2974 auto get_frame_pc_from_expr
= [expr
] ()
2978 cu_offset cuoffset
= (cu_offset
) uoffset
;
2979 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
2980 get_frame_pc_from_expr
);
2982 /* DW_OP_call_ref is currently not supported. */
2983 gdb_assert (block
.per_cu
== per_cu
);
2985 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
2986 block
.data
+ block
.size
, per_cu
,
2991 case DW_OP_call_ref
:
2994 case DW_OP_GNU_variable_value
:
3002 /* Patch all the branches we emitted. */
3003 for (int i
= 0; i
< patches
.size (); ++i
)
3005 int targ
= offsets
[dw_labels
[i
]];
3007 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3008 ax_label (expr
, patches
[i
], targ
);
3013 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3014 evaluator to calculate the location. */
3015 static struct value
*
3016 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3018 struct dwarf2_locexpr_baton
*dlbaton
3019 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3022 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, dlbaton
->data
,
3023 dlbaton
->size
, dlbaton
->per_cu
,
3024 dlbaton
->per_objfile
);
3029 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3030 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3033 static struct value
*
3034 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3036 struct dwarf2_locexpr_baton
*dlbaton
3037 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3039 return value_of_dwarf_block_entry (symbol
->type (), frame
, dlbaton
->data
,
3043 /* Implementation of get_symbol_read_needs from
3044 symbol_computed_ops. */
3046 static enum symbol_needs_kind
3047 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3049 struct dwarf2_locexpr_baton
*dlbaton
3050 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3052 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3053 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3055 return dwarf2_get_symbol_read_needs (expr
,
3057 dlbaton
->per_objfile
,
3058 gdbarch_byte_order (arch
),
3059 dlbaton
->per_cu
->addr_size (),
3060 dlbaton
->per_cu
->ref_addr_size ());
3063 /* Return true if DATA points to the end of a piece. END is one past
3064 the last byte in the expression. */
3067 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3069 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3072 /* Helper for locexpr_describe_location_piece that finds the name of a
3076 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3080 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3081 We'd rather print *something* here than throw an error. */
3082 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3083 /* gdbarch_register_name may just return "", return something more
3084 descriptive for bad register numbers. */
3087 /* The text is output as "$bad_register_number".
3088 That is why we use the underscores. */
3089 return _("bad_register_number");
3091 return gdbarch_register_name (gdbarch
, regnum
);
3094 /* Nicely describe a single piece of a location, returning an updated
3095 position in the bytecode sequence. This function cannot recognize
3096 all locations; if a location is not recognized, it simply returns
3097 DATA. If there is an error during reading, e.g. we run off the end
3098 of the buffer, an error is thrown. */
3100 static const gdb_byte
*
3101 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3102 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3103 dwarf2_per_objfile
*per_objfile
,
3104 const gdb_byte
*data
, const gdb_byte
*end
,
3105 unsigned int addr_size
)
3107 objfile
*objfile
= per_objfile
->objfile
;
3108 struct gdbarch
*gdbarch
= objfile
->arch ();
3111 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3113 fprintf_filtered (stream
, _("a variable in $%s"),
3114 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3117 else if (data
[0] == DW_OP_regx
)
3121 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3122 fprintf_filtered (stream
, _("a variable in $%s"),
3123 locexpr_regname (gdbarch
, reg
));
3125 else if (data
[0] == DW_OP_fbreg
)
3127 const struct block
*b
;
3128 struct symbol
*framefunc
;
3130 int64_t frame_offset
;
3131 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3133 int64_t base_offset
= 0;
3135 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3136 if (!piece_end_p (new_data
, end
))
3140 b
= block_for_pc (addr
);
3143 error (_("No block found for address for symbol \"%s\"."),
3144 symbol
->print_name ());
3146 framefunc
= block_linkage_function (b
);
3149 error (_("No function found for block for symbol \"%s\"."),
3150 symbol
->print_name ());
3152 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3154 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3156 const gdb_byte
*buf_end
;
3158 frame_reg
= base_data
[0] - DW_OP_breg0
;
3159 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3161 if (buf_end
!= base_data
+ base_size
)
3162 error (_("Unexpected opcode after "
3163 "DW_OP_breg%u for symbol \"%s\"."),
3164 frame_reg
, symbol
->print_name ());
3166 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3168 /* The frame base is just the register, with no offset. */
3169 frame_reg
= base_data
[0] - DW_OP_reg0
;
3174 /* We don't know what to do with the frame base expression,
3175 so we can't trace this variable; give up. */
3179 fprintf_filtered (stream
,
3180 _("a variable at frame base reg $%s offset %s+%s"),
3181 locexpr_regname (gdbarch
, frame_reg
),
3182 plongest (base_offset
), plongest (frame_offset
));
3184 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3185 && piece_end_p (data
, end
))
3189 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3191 fprintf_filtered (stream
,
3192 _("a variable at offset %s from base reg $%s"),
3194 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3197 /* The location expression for a TLS variable looks like this (on a
3200 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3201 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3203 0x3 is the encoding for DW_OP_addr, which has an operand as long
3204 as the size of an address on the target machine (here is 8
3205 bytes). Note that more recent version of GCC emit DW_OP_const4u
3206 or DW_OP_const8u, depending on address size, rather than
3207 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3208 The operand represents the offset at which the variable is within
3209 the thread local storage. */
3211 else if (data
+ 1 + addr_size
< end
3212 && (data
[0] == DW_OP_addr
3213 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3214 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3215 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3216 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3217 && piece_end_p (data
+ 2 + addr_size
, end
))
3220 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3221 gdbarch_byte_order (gdbarch
));
3223 fprintf_filtered (stream
,
3224 _("a thread-local variable at offset 0x%s "
3225 "in the thread-local storage for `%s'"),
3226 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3228 data
+= 1 + addr_size
+ 1;
3231 /* With -gsplit-dwarf a TLS variable can also look like this:
3232 DW_AT_location : 3 byte block: fc 4 e0
3233 (DW_OP_GNU_const_index: 4;
3234 DW_OP_GNU_push_tls_address) */
3235 else if (data
+ 3 <= end
3236 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3237 && data
[0] == DW_OP_GNU_const_index
3239 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3240 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3241 && piece_end_p (data
+ 2 + leb128_size
, end
))
3245 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3246 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3247 fprintf_filtered (stream
,
3248 _("a thread-local variable at offset 0x%s "
3249 "in the thread-local storage for `%s'"),
3250 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3254 else if (data
[0] >= DW_OP_lit0
3255 && data
[0] <= DW_OP_lit31
3257 && data
[1] == DW_OP_stack_value
)
3259 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3266 /* Disassemble an expression, stopping at the end of a piece or at the
3267 end of the expression. Returns a pointer to the next unread byte
3268 in the input expression. If ALL is nonzero, then this function
3269 will keep going until it reaches the end of the expression.
3270 If there is an error during reading, e.g. we run off the end
3271 of the buffer, an error is thrown. */
3273 static const gdb_byte
*
3274 disassemble_dwarf_expression (struct ui_file
*stream
,
3275 struct gdbarch
*arch
, unsigned int addr_size
,
3276 int offset_size
, const gdb_byte
*start
,
3277 const gdb_byte
*data
, const gdb_byte
*end
,
3278 int indent
, int all
,
3279 dwarf2_per_cu_data
*per_cu
,
3280 dwarf2_per_objfile
*per_objfile
)
3284 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3286 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3291 name
= get_DW_OP_name (op
);
3294 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3295 op
, (long) (data
- 1 - start
));
3296 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3297 (long) (data
- 1 - start
), name
);
3302 ul
= extract_unsigned_integer (data
, addr_size
,
3303 gdbarch_byte_order (arch
));
3305 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3309 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3311 fprintf_filtered (stream
, " %s", pulongest (ul
));
3315 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3317 fprintf_filtered (stream
, " %s", plongest (l
));
3321 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3323 fprintf_filtered (stream
, " %s", pulongest (ul
));
3327 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3329 fprintf_filtered (stream
, " %s", plongest (l
));
3333 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3335 fprintf_filtered (stream
, " %s", pulongest (ul
));
3339 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3341 fprintf_filtered (stream
, " %s", plongest (l
));
3345 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3347 fprintf_filtered (stream
, " %s", pulongest (ul
));
3351 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3353 fprintf_filtered (stream
, " %s", plongest (l
));
3357 data
= safe_read_uleb128 (data
, end
, &ul
);
3358 fprintf_filtered (stream
, " %s", pulongest (ul
));
3362 data
= safe_read_sleb128 (data
, end
, &l
);
3363 fprintf_filtered (stream
, " %s", plongest (l
));
3398 fprintf_filtered (stream
, " [$%s]",
3399 locexpr_regname (arch
, op
- DW_OP_reg0
));
3403 data
= safe_read_uleb128 (data
, end
, &ul
);
3404 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
3405 locexpr_regname (arch
, (int) ul
));
3408 case DW_OP_implicit_value
:
3409 data
= safe_read_uleb128 (data
, end
, &ul
);
3411 fprintf_filtered (stream
, " %s", pulongest (ul
));
3446 data
= safe_read_sleb128 (data
, end
, &l
);
3447 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
3448 locexpr_regname (arch
, op
- DW_OP_breg0
));
3452 data
= safe_read_uleb128 (data
, end
, &ul
);
3453 data
= safe_read_sleb128 (data
, end
, &l
);
3454 fprintf_filtered (stream
, " register %s [$%s] offset %s",
3456 locexpr_regname (arch
, (int) ul
),
3461 data
= safe_read_sleb128 (data
, end
, &l
);
3462 fprintf_filtered (stream
, " %s", plongest (l
));
3465 case DW_OP_xderef_size
:
3466 case DW_OP_deref_size
:
3468 fprintf_filtered (stream
, " %d", *data
);
3472 case DW_OP_plus_uconst
:
3473 data
= safe_read_uleb128 (data
, end
, &ul
);
3474 fprintf_filtered (stream
, " %s", pulongest (ul
));
3478 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3480 fprintf_filtered (stream
, " to %ld",
3481 (long) (data
+ l
- start
));
3485 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3487 fprintf_filtered (stream
, " %ld",
3488 (long) (data
+ l
- start
));
3492 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3494 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
3498 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3500 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3503 case DW_OP_call_ref
:
3504 ul
= extract_unsigned_integer (data
, offset_size
,
3505 gdbarch_byte_order (arch
));
3506 data
+= offset_size
;
3507 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3511 data
= safe_read_uleb128 (data
, end
, &ul
);
3512 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
3515 case DW_OP_bit_piece
:
3519 data
= safe_read_uleb128 (data
, end
, &ul
);
3520 data
= safe_read_uleb128 (data
, end
, &offset
);
3521 fprintf_filtered (stream
, " size %s offset %s (bits)",
3522 pulongest (ul
), pulongest (offset
));
3526 case DW_OP_implicit_pointer
:
3527 case DW_OP_GNU_implicit_pointer
:
3529 ul
= extract_unsigned_integer (data
, offset_size
,
3530 gdbarch_byte_order (arch
));
3531 data
+= offset_size
;
3533 data
= safe_read_sleb128 (data
, end
, &l
);
3535 fprintf_filtered (stream
, " DIE %s offset %s",
3536 phex_nz (ul
, offset_size
),
3541 case DW_OP_deref_type
:
3542 case DW_OP_GNU_deref_type
:
3544 int deref_addr_size
= *data
++;
3547 data
= safe_read_uleb128 (data
, end
, &ul
);
3548 cu_offset offset
= (cu_offset
) ul
;
3549 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
3550 fprintf_filtered (stream
, "<");
3551 type_print (type
, "", stream
, -1);
3552 fprintf_filtered (stream
, " [0x%s]> %d",
3553 phex_nz (to_underlying (offset
), 0),
3558 case DW_OP_const_type
:
3559 case DW_OP_GNU_const_type
:
3563 data
= safe_read_uleb128 (data
, end
, &ul
);
3564 cu_offset type_die
= (cu_offset
) ul
;
3565 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3566 fprintf_filtered (stream
, "<");
3567 type_print (type
, "", stream
, -1);
3568 fprintf_filtered (stream
, " [0x%s]>",
3569 phex_nz (to_underlying (type_die
), 0));
3572 fprintf_filtered (stream
, " %d byte block:", n
);
3573 for (int i
= 0; i
< n
; ++i
)
3574 fprintf_filtered (stream
, " %02x", data
[i
]);
3579 case DW_OP_regval_type
:
3580 case DW_OP_GNU_regval_type
:
3585 data
= safe_read_uleb128 (data
, end
, ®
);
3586 data
= safe_read_uleb128 (data
, end
, &ul
);
3587 cu_offset type_die
= (cu_offset
) ul
;
3589 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3590 fprintf_filtered (stream
, "<");
3591 type_print (type
, "", stream
, -1);
3592 fprintf_filtered (stream
, " [0x%s]> [$%s]",
3593 phex_nz (to_underlying (type_die
), 0),
3594 locexpr_regname (arch
, reg
));
3599 case DW_OP_GNU_convert
:
3600 case DW_OP_reinterpret
:
3601 case DW_OP_GNU_reinterpret
:
3603 data
= safe_read_uleb128 (data
, end
, &ul
);
3604 cu_offset type_die
= (cu_offset
) ul
;
3606 if (to_underlying (type_die
) == 0)
3607 fprintf_filtered (stream
, "<0>");
3612 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
3613 fprintf_filtered (stream
, "<");
3614 type_print (type
, "", stream
, -1);
3615 fprintf_filtered (stream
, " [0x%s]>",
3616 phex_nz (to_underlying (type_die
), 0));
3621 case DW_OP_entry_value
:
3622 case DW_OP_GNU_entry_value
:
3623 data
= safe_read_uleb128 (data
, end
, &ul
);
3624 fputc_filtered ('\n', stream
);
3625 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
3626 start
, data
, data
+ ul
, indent
+ 2,
3627 all
, per_cu
, per_objfile
);
3631 case DW_OP_GNU_parameter_ref
:
3632 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3634 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
3638 case DW_OP_GNU_addr_index
:
3639 data
= safe_read_uleb128 (data
, end
, &ul
);
3640 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3641 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3644 case DW_OP_GNU_const_index
:
3645 data
= safe_read_uleb128 (data
, end
, &ul
);
3646 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
3647 fprintf_filtered (stream
, " %s", pulongest (ul
));
3650 case DW_OP_GNU_variable_value
:
3651 ul
= extract_unsigned_integer (data
, offset_size
,
3652 gdbarch_byte_order (arch
));
3653 data
+= offset_size
;
3654 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
3658 fprintf_filtered (stream
, "\n");
3664 static bool dwarf_always_disassemble
;
3667 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
3668 struct cmd_list_element
*c
, const char *value
)
3670 fprintf_filtered (file
,
3671 _("Whether to always disassemble "
3672 "DWARF expressions is %s.\n"),
3676 /* Describe a single location, which may in turn consist of multiple
3680 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
3681 struct ui_file
*stream
,
3682 const gdb_byte
*data
, size_t size
,
3683 unsigned int addr_size
,
3684 int offset_size
, dwarf2_per_cu_data
*per_cu
,
3685 dwarf2_per_objfile
*per_objfile
)
3687 const gdb_byte
*end
= data
+ size
;
3688 int first_piece
= 1, bad
= 0;
3689 objfile
*objfile
= per_objfile
->objfile
;
3693 const gdb_byte
*here
= data
;
3694 int disassemble
= 1;
3699 fprintf_filtered (stream
, _(", and "));
3701 if (!dwarf_always_disassemble
)
3703 data
= locexpr_describe_location_piece (symbol
, stream
,
3704 addr
, per_cu
, per_objfile
,
3705 data
, end
, addr_size
);
3706 /* If we printed anything, or if we have an empty piece,
3707 then don't disassemble. */
3709 || data
[0] == DW_OP_piece
3710 || data
[0] == DW_OP_bit_piece
)
3715 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
3716 data
= disassemble_dwarf_expression (stream
,
3718 addr_size
, offset_size
, data
,
3720 dwarf_always_disassemble
,
3721 per_cu
, per_objfile
);
3726 int empty
= data
== here
;
3729 fprintf_filtered (stream
, " ");
3730 if (data
[0] == DW_OP_piece
)
3734 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
3737 fprintf_filtered (stream
, _("an empty %s-byte piece"),
3740 fprintf_filtered (stream
, _(" [%s-byte piece]"),
3743 else if (data
[0] == DW_OP_bit_piece
)
3745 uint64_t bits
, offset
;
3747 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
3748 data
= safe_read_uleb128 (data
, end
, &offset
);
3751 fprintf_filtered (stream
,
3752 _("an empty %s-bit piece"),
3755 fprintf_filtered (stream
,
3756 _(" [%s-bit piece, offset %s bits]"),
3757 pulongest (bits
), pulongest (offset
));
3767 if (bad
|| data
> end
)
3768 error (_("Corrupted DWARF2 expression for \"%s\"."),
3769 symbol
->print_name ());
3772 /* Print a natural-language description of SYMBOL to STREAM. This
3773 version is for a symbol with a single location. */
3776 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3777 struct ui_file
*stream
)
3779 struct dwarf2_locexpr_baton
*dlbaton
3780 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3781 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3782 int offset_size
= dlbaton
->per_cu
->offset_size ();
3784 locexpr_describe_location_1 (symbol
, addr
, stream
,
3785 dlbaton
->data
, dlbaton
->size
,
3786 addr_size
, offset_size
,
3787 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3790 /* Describe the location of SYMBOL as an agent value in VALUE, generating
3791 any necessary bytecode in AX. */
3794 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
3795 struct axs_value
*value
)
3797 struct dwarf2_locexpr_baton
*dlbaton
3798 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3799 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3801 if (dlbaton
->size
== 0)
3802 value
->optimized_out
= 1;
3804 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
3805 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
3806 dlbaton
->per_objfile
);
3809 /* symbol_computed_ops 'generate_c_location' method. */
3812 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
3813 struct gdbarch
*gdbarch
,
3814 std::vector
<bool> ®isters_used
,
3815 CORE_ADDR pc
, const char *result_name
)
3817 struct dwarf2_locexpr_baton
*dlbaton
3818 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
3819 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3821 if (dlbaton
->size
== 0)
3822 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
3824 compile_dwarf_expr_to_c (stream
, result_name
,
3825 sym
, pc
, gdbarch
, registers_used
, addr_size
,
3826 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
3827 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3830 /* The set of location functions used with the DWARF-2 expression
3832 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
3833 locexpr_read_variable
,
3834 locexpr_read_variable_at_entry
,
3835 locexpr_get_symbol_read_needs
,
3836 locexpr_describe_location
,
3837 0, /* location_has_loclist */
3838 locexpr_tracepoint_var_ref
,
3839 locexpr_generate_c_location
3843 /* Wrapper functions for location lists. These generally find
3844 the appropriate location expression and call something above. */
3846 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3847 evaluator to calculate the location. */
3848 static struct value
*
3849 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3851 struct dwarf2_loclist_baton
*dlbaton
3852 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3854 const gdb_byte
*data
;
3856 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
3858 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3859 val
= dwarf2_evaluate_loc_desc (symbol
->type (), frame
, data
, size
,
3860 dlbaton
->per_cu
, dlbaton
->per_objfile
);
3865 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
3866 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3869 Function always returns non-NULL value, it may be marked optimized out if
3870 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
3871 if it cannot resolve the parameter for any reason. */
3873 static struct value
*
3874 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3876 struct dwarf2_loclist_baton
*dlbaton
3877 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3878 const gdb_byte
*data
;
3882 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
3883 return allocate_optimized_out_value (symbol
->type ());
3885 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
3887 return allocate_optimized_out_value (symbol
->type ());
3889 return value_of_dwarf_block_entry (symbol
->type (), frame
, data
, size
);
3892 /* Implementation of get_symbol_read_needs from
3893 symbol_computed_ops. */
3895 static enum symbol_needs_kind
3896 loclist_symbol_needs (struct symbol
*symbol
)
3898 /* If there's a location list, then assume we need to have a frame
3899 to choose the appropriate location expression. With tracking of
3900 global variables this is not necessarily true, but such tracking
3901 is disabled in GCC at the moment until we figure out how to
3904 return SYMBOL_NEEDS_FRAME
;
3907 /* Print a natural-language description of SYMBOL to STREAM. This
3908 version applies when there is a list of different locations, each
3909 with a specified address range. */
3912 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
3913 struct ui_file
*stream
)
3915 struct dwarf2_loclist_baton
*dlbaton
3916 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3917 const gdb_byte
*loc_ptr
, *buf_end
;
3918 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
3919 struct objfile
*objfile
= per_objfile
->objfile
;
3920 struct gdbarch
*gdbarch
= objfile
->arch ();
3921 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3922 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
3923 int offset_size
= dlbaton
->per_cu
->offset_size ();
3924 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
3925 /* Adjustment for relocatable objects. */
3926 CORE_ADDR text_offset
= objfile
->text_section_offset ();
3927 CORE_ADDR base_address
= dlbaton
->base_address
;
3930 loc_ptr
= dlbaton
->data
;
3931 buf_end
= dlbaton
->data
+ dlbaton
->size
;
3933 fprintf_filtered (stream
, _("multi-location:\n"));
3935 /* Iterate through locations until we run out. */
3938 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
3940 enum debug_loc_kind kind
;
3941 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
3943 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
3944 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
3945 dlbaton
->per_objfile
,
3946 loc_ptr
, buf_end
, &new_ptr
,
3947 &low
, &high
, byte_order
);
3948 else if (dlbaton
->per_cu
->version () < 5)
3949 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
3951 byte_order
, addr_size
,
3954 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
3955 dlbaton
->per_objfile
,
3956 loc_ptr
, buf_end
, &new_ptr
,
3957 &low
, &high
, byte_order
,
3958 addr_size
, signed_addr_p
);
3962 case DEBUG_LOC_END_OF_LIST
:
3966 case DEBUG_LOC_BASE_ADDRESS
:
3967 base_address
= high
;
3968 fprintf_filtered (stream
, _(" Base address %s"),
3969 paddress (gdbarch
, base_address
));
3972 case DEBUG_LOC_START_END
:
3973 case DEBUG_LOC_START_LENGTH
:
3974 case DEBUG_LOC_OFFSET_PAIR
:
3977 case DEBUG_LOC_BUFFER_OVERFLOW
:
3978 case DEBUG_LOC_INVALID_ENTRY
:
3979 error (_("Corrupted DWARF expression for symbol \"%s\"."),
3980 symbol
->print_name ());
3983 gdb_assert_not_reached ("bad debug_loc_kind");
3986 /* Otherwise, a location expression entry. */
3988 high
+= text_offset
;
3989 if (!dlbaton
->from_dwo
&& kind
== DEBUG_LOC_OFFSET_PAIR
)
3991 low
+= base_address
;
3992 high
+= base_address
;
3995 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
3996 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
3998 if (dlbaton
->per_cu
->version () < 5)
4000 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4005 unsigned int bytes_read
;
4006 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4007 loc_ptr
+= bytes_read
;
4010 /* (It would improve readability to print only the minimum
4011 necessary digits of the second number of the range.) */
4012 fprintf_filtered (stream
, _(" Range %s-%s: "),
4013 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4015 /* Now describe this particular location. */
4016 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4017 addr_size
, offset_size
,
4018 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4020 fprintf_filtered (stream
, "\n");
4026 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4027 any necessary bytecode in AX. */
4029 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4030 struct axs_value
*value
)
4032 struct dwarf2_loclist_baton
*dlbaton
4033 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4034 const gdb_byte
*data
;
4036 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4038 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4040 value
->optimized_out
= 1;
4042 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4043 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4046 /* symbol_computed_ops 'generate_c_location' method. */
4049 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4050 struct gdbarch
*gdbarch
,
4051 std::vector
<bool> ®isters_used
,
4052 CORE_ADDR pc
, const char *result_name
)
4054 struct dwarf2_loclist_baton
*dlbaton
4055 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4056 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4057 const gdb_byte
*data
;
4060 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4062 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4064 compile_dwarf_expr_to_c (stream
, result_name
,
4065 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4068 dlbaton
->per_objfile
);
4071 /* The set of location functions used with the DWARF-2 expression
4072 evaluator and location lists. */
4073 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4074 loclist_read_variable
,
4075 loclist_read_variable_at_entry
,
4076 loclist_symbol_needs
,
4077 loclist_describe_location
,
4078 1, /* location_has_loclist */
4079 loclist_tracepoint_var_ref
,
4080 loclist_generate_c_location
4083 void _initialize_dwarf2loc ();
4085 _initialize_dwarf2loc ()
4087 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4088 &entry_values_debug
,
4089 _("Set entry values and tail call frames "
4091 _("Show entry values and tail call frames "
4093 _("When non-zero, the process of determining "
4094 "parameter values from function entry point "
4095 "and tail call frames will be printed."),
4097 show_entry_values_debug
,
4098 &setdebuglist
, &showdebuglist
);
4100 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4101 &dwarf_always_disassemble
, _("\
4102 Set whether `info address' always disassembles DWARF expressions."), _("\
4103 Show whether `info address' always disassembles DWARF expressions."), _("\
4104 When enabled, DWARF expressions are always printed in an assembly-like\n\
4105 syntax. When disabled, expressions will be printed in a more\n\
4106 conversational style, when possible."),
4108 show_dwarf_always_disassemble
,
4110 &show_dwarf_cmdlist
);