1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2021 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "complaints.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full
51 (struct type
*type
, struct frame_info
*frame
, const gdb_byte
*data
,
52 size_t size
, dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
53 struct type
*subobj_type
, LONGEST subobj_byte_offset
);
55 static struct value
*indirect_synthetic_pointer
56 (sect_offset die
, LONGEST byte_offset
,
57 dwarf2_per_cu_data
*per_cu
,
58 dwarf2_per_objfile
*per_objfile
,
59 struct frame_info
*frame
,
60 struct type
*type
, bool resolve_abstract_p
= false);
62 /* Until these have formal names, we define these here.
63 ref: http://gcc.gnu.org/wiki/DebugFission
64 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
65 and is then followed by data specific to that entry. */
69 /* Indicates the end of the list of entries. */
70 DEBUG_LOC_END_OF_LIST
= 0,
72 /* This is followed by an unsigned LEB128 number that is an index into
73 .debug_addr and specifies the base address for all following entries. */
74 DEBUG_LOC_BASE_ADDRESS
= 1,
76 /* This is followed by two unsigned LEB128 numbers that are indices into
77 .debug_addr and specify the beginning and ending addresses, and then
78 a normal location expression as in .debug_loc. */
79 DEBUG_LOC_START_END
= 2,
81 /* This is followed by an unsigned LEB128 number that is an index into
82 .debug_addr and specifies the beginning address, and a 4 byte unsigned
83 number that specifies the length, and then a normal location expression
85 DEBUG_LOC_START_LENGTH
= 3,
87 /* This is followed by two unsigned LEB128 operands. The values of these
88 operands are the starting and ending offsets, respectively, relative to
89 the applicable base address. */
90 DEBUG_LOC_OFFSET_PAIR
= 4,
92 /* An internal value indicating there is insufficient data. */
93 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
95 /* An internal value indicating an invalid kind of entry was found. */
96 DEBUG_LOC_INVALID_ENTRY
= -2
99 /* Helper function which throws an error if a synthetic pointer is
103 invalid_synthetic_pointer (void)
105 error (_("access outside bounds of object "
106 "referenced via synthetic pointer"));
109 /* Decode the addresses in a non-dwo .debug_loc entry.
110 A pointer to the next byte to examine is returned in *NEW_PTR.
111 The encoded low,high addresses are return in *LOW,*HIGH.
112 The result indicates the kind of entry found. */
114 static enum debug_loc_kind
115 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
116 const gdb_byte
**new_ptr
,
117 CORE_ADDR
*low
, CORE_ADDR
*high
,
118 enum bfd_endian byte_order
,
119 unsigned int addr_size
,
122 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
124 if (buf_end
- loc_ptr
< 2 * addr_size
)
125 return DEBUG_LOC_BUFFER_OVERFLOW
;
128 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
130 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
131 loc_ptr
+= addr_size
;
134 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
136 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
137 loc_ptr
+= addr_size
;
141 /* A base-address-selection entry. */
142 if ((*low
& base_mask
) == base_mask
)
143 return DEBUG_LOC_BASE_ADDRESS
;
145 /* An end-of-list entry. */
146 if (*low
== 0 && *high
== 0)
147 return DEBUG_LOC_END_OF_LIST
;
149 return DEBUG_LOC_START_END
;
152 /* Decode the addresses in .debug_loclists entry.
153 A pointer to the next byte to examine is returned in *NEW_PTR.
154 The encoded low,high addresses are return in *LOW,*HIGH.
155 The result indicates the kind of entry found. */
157 static enum debug_loc_kind
158 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
159 dwarf2_per_objfile
*per_objfile
,
160 const gdb_byte
*loc_ptr
,
161 const gdb_byte
*buf_end
,
162 const gdb_byte
**new_ptr
,
163 CORE_ADDR
*low
, CORE_ADDR
*high
,
164 enum bfd_endian byte_order
,
165 unsigned int addr_size
,
170 if (loc_ptr
== buf_end
)
171 return DEBUG_LOC_BUFFER_OVERFLOW
;
175 case DW_LLE_base_addressx
:
177 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
179 return DEBUG_LOC_BUFFER_OVERFLOW
;
181 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
183 return DEBUG_LOC_BASE_ADDRESS
;
185 case DW_LLE_startx_length
:
186 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
188 return DEBUG_LOC_BUFFER_OVERFLOW
;
190 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
192 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
194 return DEBUG_LOC_BUFFER_OVERFLOW
;
198 return DEBUG_LOC_START_LENGTH
;
200 case DW_LLE_start_length
:
201 if (buf_end
- loc_ptr
< addr_size
)
202 return DEBUG_LOC_BUFFER_OVERFLOW
;
205 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
207 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
209 loc_ptr
+= addr_size
;
212 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
214 return DEBUG_LOC_BUFFER_OVERFLOW
;
218 return DEBUG_LOC_START_LENGTH
;
220 case DW_LLE_end_of_list
:
222 return DEBUG_LOC_END_OF_LIST
;
224 case DW_LLE_base_address
:
225 if (loc_ptr
+ addr_size
> buf_end
)
226 return DEBUG_LOC_BUFFER_OVERFLOW
;
229 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
231 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
233 loc_ptr
+= addr_size
;
235 return DEBUG_LOC_BASE_ADDRESS
;
237 case DW_LLE_offset_pair
:
238 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
240 return DEBUG_LOC_BUFFER_OVERFLOW
;
243 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
245 return DEBUG_LOC_BUFFER_OVERFLOW
;
249 return DEBUG_LOC_OFFSET_PAIR
;
251 case DW_LLE_start_end
:
252 if (loc_ptr
+ 2 * addr_size
> buf_end
)
253 return DEBUG_LOC_BUFFER_OVERFLOW
;
256 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
258 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
260 loc_ptr
+= addr_size
;
262 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
264 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
266 loc_ptr
+= addr_size
;
268 return DEBUG_LOC_START_END
;
270 /* Following cases are not supported yet. */
271 case DW_LLE_startx_endx
:
272 case DW_LLE_default_location
:
274 return DEBUG_LOC_INVALID_ENTRY
;
278 /* Decode the addresses in .debug_loc.dwo entry.
279 A pointer to the next byte to examine is returned in *NEW_PTR.
280 The encoded low,high addresses are return in *LOW,*HIGH.
281 The result indicates the kind of entry found. */
283 static enum debug_loc_kind
284 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
285 dwarf2_per_objfile
*per_objfile
,
286 const gdb_byte
*loc_ptr
,
287 const gdb_byte
*buf_end
,
288 const gdb_byte
**new_ptr
,
289 CORE_ADDR
*low
, CORE_ADDR
*high
,
290 enum bfd_endian byte_order
)
292 uint64_t low_index
, high_index
;
294 if (loc_ptr
== buf_end
)
295 return DEBUG_LOC_BUFFER_OVERFLOW
;
299 case DW_LLE_GNU_end_of_list_entry
:
301 return DEBUG_LOC_END_OF_LIST
;
303 case DW_LLE_GNU_base_address_selection_entry
:
305 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
307 return DEBUG_LOC_BUFFER_OVERFLOW
;
309 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
311 return DEBUG_LOC_BASE_ADDRESS
;
313 case DW_LLE_GNU_start_end_entry
:
314 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
316 return DEBUG_LOC_BUFFER_OVERFLOW
;
318 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
319 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
321 return DEBUG_LOC_BUFFER_OVERFLOW
;
323 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
325 return DEBUG_LOC_START_END
;
327 case DW_LLE_GNU_start_length_entry
:
328 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
330 return DEBUG_LOC_BUFFER_OVERFLOW
;
332 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
333 if (loc_ptr
+ 4 > buf_end
)
334 return DEBUG_LOC_BUFFER_OVERFLOW
;
337 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
338 *new_ptr
= loc_ptr
+ 4;
339 return DEBUG_LOC_START_LENGTH
;
342 return DEBUG_LOC_INVALID_ENTRY
;
346 /* A function for dealing with location lists. Given a
347 symbol baton (BATON) and a pc value (PC), find the appropriate
348 location expression, set *LOCEXPR_LENGTH, and return a pointer
349 to the beginning of the expression. Returns NULL on failure.
351 For now, only return the first matching location expression; there
352 can be more than one in the list. */
355 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
356 size_t *locexpr_length
, CORE_ADDR pc
)
358 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
359 struct objfile
*objfile
= per_objfile
->objfile
;
360 struct gdbarch
*gdbarch
= objfile
->arch ();
361 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
362 unsigned int addr_size
= baton
->per_cu
->addr_size ();
363 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
364 /* Adjust base_address for relocatable objects. */
365 CORE_ADDR base_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
366 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
367 const gdb_byte
*loc_ptr
, *buf_end
;
369 loc_ptr
= baton
->data
;
370 buf_end
= baton
->data
+ baton
->size
;
374 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
376 enum debug_loc_kind kind
;
377 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
379 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
380 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
382 loc_ptr
, buf_end
, &new_ptr
,
383 &low
, &high
, byte_order
);
384 else if (baton
->per_cu
->version () < 5)
385 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
387 byte_order
, addr_size
,
390 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
392 loc_ptr
, buf_end
, &new_ptr
,
393 &low
, &high
, byte_order
,
394 addr_size
, signed_addr_p
);
399 case DEBUG_LOC_END_OF_LIST
:
403 case DEBUG_LOC_BASE_ADDRESS
:
404 base_address
= high
+ base_offset
;
407 case DEBUG_LOC_START_END
:
408 case DEBUG_LOC_START_LENGTH
:
409 case DEBUG_LOC_OFFSET_PAIR
:
412 case DEBUG_LOC_BUFFER_OVERFLOW
:
413 case DEBUG_LOC_INVALID_ENTRY
:
414 error (_("dwarf2_find_location_expression: "
415 "Corrupted DWARF expression."));
418 gdb_assert_not_reached ("bad debug_loc_kind");
421 /* Otherwise, a location expression entry.
422 If the entry is from a DWO, don't add base address: the entry is from
423 .debug_addr which already has the DWARF "base address". We still add
424 base_offset in case we're debugging a PIE executable. However, if the
425 entry is DW_LLE_offset_pair from a DWO, add the base address as the
426 operands are offsets relative to the applicable base address. */
427 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
435 high
+= base_address
;
438 if (baton
->per_cu
->version () < 5)
440 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
445 unsigned int bytes_read
;
447 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
448 loc_ptr
+= bytes_read
;
451 if (low
== high
&& pc
== low
)
453 /* This is entry PC record present only at entry point
454 of a function. Verify it is really the function entry point. */
456 const struct block
*pc_block
= block_for_pc (pc
);
457 struct symbol
*pc_func
= NULL
;
460 pc_func
= block_linkage_function (pc_block
);
462 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
464 *locexpr_length
= length
;
469 if (pc
>= low
&& pc
< high
)
471 *locexpr_length
= length
;
479 /* Implement find_frame_base_location method for LOC_BLOCK functions using
480 DWARF expression for its DW_AT_frame_base. */
483 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
484 const gdb_byte
**start
, size_t *length
)
486 struct dwarf2_locexpr_baton
*symbaton
487 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
489 *length
= symbaton
->size
;
490 *start
= symbaton
->data
;
493 /* Implement the struct symbol_block_ops::get_frame_base method for
494 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
497 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
499 struct gdbarch
*gdbarch
;
501 struct dwarf2_locexpr_baton
*dlbaton
;
502 const gdb_byte
*start
;
504 struct value
*result
;
506 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
507 Thus, it's supposed to provide the find_frame_base_location method as
509 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
511 gdbarch
= get_frame_arch (frame
);
512 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
513 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
515 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
516 (framefunc
, get_frame_pc (frame
), &start
, &length
);
517 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
518 dlbaton
->per_cu
, dlbaton
->per_objfile
);
520 /* The DW_AT_frame_base attribute contains a location description which
521 computes the base address itself. However, the call to
522 dwarf2_evaluate_loc_desc returns a value representing a variable at
523 that address. The frame base address is thus this variable's
525 return value_address (result
);
528 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
529 function uses DWARF expression for its DW_AT_frame_base. */
531 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
533 locexpr_find_frame_base_location
,
534 locexpr_get_frame_base
537 /* Implement find_frame_base_location method for LOC_BLOCK functions using
538 DWARF location list for its DW_AT_frame_base. */
541 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
542 const gdb_byte
**start
, size_t *length
)
544 struct dwarf2_loclist_baton
*symbaton
545 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
547 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
550 /* Implement the struct symbol_block_ops::get_frame_base method for
551 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
554 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
556 struct gdbarch
*gdbarch
;
558 struct dwarf2_loclist_baton
*dlbaton
;
559 const gdb_byte
*start
;
561 struct value
*result
;
563 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
564 Thus, it's supposed to provide the find_frame_base_location method as
566 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
568 gdbarch
= get_frame_arch (frame
);
569 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
570 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
572 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
573 (framefunc
, get_frame_pc (frame
), &start
, &length
);
574 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
575 dlbaton
->per_cu
, dlbaton
->per_objfile
);
577 /* The DW_AT_frame_base attribute contains a location description which
578 computes the base address itself. However, the call to
579 dwarf2_evaluate_loc_desc returns a value representing a variable at
580 that address. The frame base address is thus this variable's
582 return value_address (result
);
585 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
586 function uses DWARF location list for its DW_AT_frame_base. */
588 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
590 loclist_find_frame_base_location
,
591 loclist_get_frame_base
594 /* See dwarf2loc.h. */
597 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
598 const gdb_byte
**start
, size_t *length
)
600 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
602 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
604 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
610 error (_("Could not find the frame base for \"%s\"."),
611 framefunc
->natural_name ());
614 /* A helper function to find the definition of NAME and compute its
615 value. Returns nullptr if the name is not found. */
618 compute_var_value (const char *name
)
620 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
622 if (sym
.symbol
!= nullptr)
623 return value_of_variable (sym
.symbol
, sym
.block
);
630 sect_variable_value (sect_offset sect_off
,
631 dwarf2_per_cu_data
*per_cu
,
632 dwarf2_per_objfile
*per_objfile
)
634 const char *var_name
= nullptr;
635 struct type
*die_type
636 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
, per_objfile
,
639 if (die_type
== NULL
)
640 error (_("Bad DW_OP_GNU_variable_value DIE."));
642 /* Note: Things still work when the following test is removed. This
643 test and error is here to conform to the proposed specification. */
644 if (die_type
->code () != TYPE_CODE_INT
645 && die_type
->code () != TYPE_CODE_ENUM
646 && die_type
->code () != TYPE_CODE_RANGE
647 && die_type
->code () != TYPE_CODE_PTR
)
648 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
650 if (var_name
!= nullptr)
652 value
*result
= compute_var_value (var_name
);
653 if (result
!= nullptr)
657 struct type
*type
= lookup_pointer_type (die_type
);
658 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
659 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, per_objfile
, frame
,
663 /* See dwarf2loc.h. */
665 unsigned int entry_values_debug
= 0;
667 /* Helper to set entry_values_debug. */
670 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
671 struct cmd_list_element
*c
, const char *value
)
673 fprintf_filtered (file
,
674 _("Entry values and tail call frames debugging is %s.\n"),
678 /* Find DW_TAG_call_site's DW_AT_call_target address.
679 CALLER_FRAME (for registers) can be NULL if it is not known. This function
680 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
683 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
684 struct call_site
*call_site
,
685 struct frame_info
*caller_frame
)
687 switch (FIELD_LOC_KIND (call_site
->target
))
689 case FIELD_LOC_KIND_DWARF_BLOCK
:
691 struct dwarf2_locexpr_baton
*dwarf_block
;
693 struct type
*caller_core_addr_type
;
694 struct gdbarch
*caller_arch
;
696 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
697 if (dwarf_block
== NULL
)
699 struct bound_minimal_symbol msym
;
701 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
702 throw_error (NO_ENTRY_VALUE_ERROR
,
703 _("DW_AT_call_target is not specified at %s in %s"),
704 paddress (call_site_gdbarch
, call_site
->pc
),
705 (msym
.minsym
== NULL
? "???"
706 : msym
.minsym
->print_name ()));
709 if (caller_frame
== NULL
)
711 struct bound_minimal_symbol msym
;
713 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
714 throw_error (NO_ENTRY_VALUE_ERROR
,
715 _("DW_AT_call_target DWARF block resolving "
716 "requires known frame which is currently not "
717 "available at %s in %s"),
718 paddress (call_site_gdbarch
, call_site
->pc
),
719 (msym
.minsym
== NULL
? "???"
720 : msym
.minsym
->print_name ()));
723 caller_arch
= get_frame_arch (caller_frame
);
724 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
725 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
726 dwarf_block
->data
, dwarf_block
->size
,
728 dwarf_block
->per_objfile
);
729 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
730 if (VALUE_LVAL (val
) == lval_memory
)
731 return value_address (val
);
733 return value_as_address (val
);
736 case FIELD_LOC_KIND_PHYSNAME
:
738 const char *physname
;
739 struct bound_minimal_symbol msym
;
741 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
743 /* Handle both the mangled and demangled PHYSNAME. */
744 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
745 if (msym
.minsym
== NULL
)
747 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
748 throw_error (NO_ENTRY_VALUE_ERROR
,
749 _("Cannot find function \"%s\" for a call site target "
751 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
752 (msym
.minsym
== NULL
? "???"
753 : msym
.minsym
->print_name ()));
756 return BMSYMBOL_VALUE_ADDRESS (msym
);
759 case FIELD_LOC_KIND_PHYSADDR
:
760 return FIELD_STATIC_PHYSADDR (call_site
->target
);
763 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
767 /* Convert function entry point exact address ADDR to the function which is
768 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
769 NO_ENTRY_VALUE_ERROR otherwise. */
771 static struct symbol
*
772 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
774 struct symbol
*sym
= find_pc_function (addr
);
777 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
778 throw_error (NO_ENTRY_VALUE_ERROR
,
779 _("DW_TAG_call_site resolving failed to find function "
780 "name for address %s"),
781 paddress (gdbarch
, addr
));
783 type
= SYMBOL_TYPE (sym
);
784 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
785 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
790 /* Verify function with entry point exact address ADDR can never call itself
791 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
792 can call itself via tail calls.
794 If a funtion can tail call itself its entry value based parameters are
795 unreliable. There is no verification whether the value of some/all
796 parameters is unchanged through the self tail call, we expect if there is
797 a self tail call all the parameters can be modified. */
800 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
804 /* The verification is completely unordered. Track here function addresses
805 which still need to be iterated. */
806 std::vector
<CORE_ADDR
> todo
;
808 /* Track here CORE_ADDRs which were already visited. */
809 std::unordered_set
<CORE_ADDR
> addr_hash
;
811 todo
.push_back (verify_addr
);
812 while (!todo
.empty ())
814 struct symbol
*func_sym
;
815 struct call_site
*call_site
;
820 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
822 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
823 call_site
; call_site
= call_site
->tail_call_next
)
825 CORE_ADDR target_addr
;
827 /* CALLER_FRAME with registers is not available for tail-call jumped
829 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
831 if (target_addr
== verify_addr
)
833 struct bound_minimal_symbol msym
;
835 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
836 throw_error (NO_ENTRY_VALUE_ERROR
,
837 _("DW_OP_entry_value resolving has found "
838 "function \"%s\" at %s can call itself via tail "
840 (msym
.minsym
== NULL
? "???"
841 : msym
.minsym
->print_name ()),
842 paddress (gdbarch
, verify_addr
));
845 if (addr_hash
.insert (target_addr
).second
)
846 todo
.push_back (target_addr
);
851 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
852 ENTRY_VALUES_DEBUG. */
855 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
857 CORE_ADDR addr
= call_site
->pc
;
858 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
860 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
861 (msym
.minsym
== NULL
? "???"
862 : msym
.minsym
->print_name ()));
866 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
867 only top callers and bottom callees which are present in both. GDBARCH is
868 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
869 no remaining possibilities to provide unambiguous non-trivial result.
870 RESULTP should point to NULL on the first (initialization) call. Caller is
871 responsible for xfree of any RESULTP data. */
874 chain_candidate (struct gdbarch
*gdbarch
,
875 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
876 std::vector
<struct call_site
*> *chain
)
878 long length
= chain
->size ();
879 int callers
, callees
, idx
;
881 if (*resultp
== NULL
)
883 /* Create the initial chain containing all the passed PCs. */
885 struct call_site_chain
*result
886 = ((struct call_site_chain
*)
887 xmalloc (sizeof (*result
)
888 + sizeof (*result
->call_site
) * (length
- 1)));
889 result
->length
= length
;
890 result
->callers
= result
->callees
= length
;
891 if (!chain
->empty ())
892 memcpy (result
->call_site
, chain
->data (),
893 sizeof (*result
->call_site
) * length
);
894 resultp
->reset (result
);
896 if (entry_values_debug
)
898 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
899 for (idx
= 0; idx
< length
; idx
++)
900 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
901 fputc_unfiltered ('\n', gdb_stdlog
);
907 if (entry_values_debug
)
909 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
910 for (idx
= 0; idx
< length
; idx
++)
911 tailcall_dump (gdbarch
, chain
->at (idx
));
912 fputc_unfiltered ('\n', gdb_stdlog
);
915 /* Intersect callers. */
917 callers
= std::min ((long) (*resultp
)->callers
, length
);
918 for (idx
= 0; idx
< callers
; idx
++)
919 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
921 (*resultp
)->callers
= idx
;
925 /* Intersect callees. */
927 callees
= std::min ((long) (*resultp
)->callees
, length
);
928 for (idx
= 0; idx
< callees
; idx
++)
929 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
930 != chain
->at (length
- 1 - idx
))
932 (*resultp
)->callees
= idx
;
936 if (entry_values_debug
)
938 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
939 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
940 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
941 fputs_unfiltered (" |", gdb_stdlog
);
942 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
943 tailcall_dump (gdbarch
,
944 (*resultp
)->call_site
[(*resultp
)->length
945 - (*resultp
)->callees
+ idx
]);
946 fputc_unfiltered ('\n', gdb_stdlog
);
949 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
951 /* There are no common callers or callees. It could be also a direct
952 call (which has length 0) with ambiguous possibility of an indirect
953 call - CALLERS == CALLEES == 0 is valid during the first allocation
954 but any subsequence processing of such entry means ambiguity. */
955 resultp
->reset (NULL
);
959 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
960 PC again. In such case there must be two different code paths to reach
961 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
962 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
965 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
966 assumed frames between them use GDBARCH. Use depth first search so we can
967 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
968 would have needless GDB stack overhead. Any unreliability results
969 in thrown NO_ENTRY_VALUE_ERROR. */
971 static gdb::unique_xmalloc_ptr
<call_site_chain
>
972 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
975 CORE_ADDR save_callee_pc
= callee_pc
;
976 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
977 struct call_site
*call_site
;
979 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
980 call_site nor any possible call_site at CALLEE_PC's function is there.
981 Any CALL_SITE in CHAIN will be iterated to its siblings - via
982 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
983 std::vector
<struct call_site
*> chain
;
985 /* We are not interested in the specific PC inside the callee function. */
986 callee_pc
= get_pc_function_start (callee_pc
);
988 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
989 paddress (gdbarch
, save_callee_pc
));
991 /* Mark CALL_SITEs so we do not visit the same ones twice. */
992 std::unordered_set
<CORE_ADDR
> addr_hash
;
994 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
995 at the target's function. All the possible tail call sites in the
996 target's function will get iterated as already pushed into CHAIN via their
998 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1002 CORE_ADDR target_func_addr
;
1003 struct call_site
*target_call_site
;
1005 /* CALLER_FRAME with registers is not available for tail-call jumped
1007 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1009 if (target_func_addr
== callee_pc
)
1011 chain_candidate (gdbarch
, &retval
, &chain
);
1015 /* There is no way to reach CALLEE_PC again as we would prevent
1016 entering it twice as being already marked in ADDR_HASH. */
1017 target_call_site
= NULL
;
1021 struct symbol
*target_func
;
1023 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1024 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1029 /* Attempt to visit TARGET_CALL_SITE. */
1031 if (target_call_site
)
1033 if (addr_hash
.insert (target_call_site
->pc
).second
)
1035 /* Successfully entered TARGET_CALL_SITE. */
1037 chain
.push_back (target_call_site
);
1042 /* Backtrack (without revisiting the originating call_site). Try the
1043 callers's sibling; if there isn't any try the callers's callers's
1046 target_call_site
= NULL
;
1047 while (!chain
.empty ())
1049 call_site
= chain
.back ();
1052 size_t removed
= addr_hash
.erase (call_site
->pc
);
1053 gdb_assert (removed
== 1);
1055 target_call_site
= call_site
->tail_call_next
;
1056 if (target_call_site
)
1060 while (target_call_site
);
1065 call_site
= chain
.back ();
1070 struct bound_minimal_symbol msym_caller
, msym_callee
;
1072 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1073 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1074 throw_error (NO_ENTRY_VALUE_ERROR
,
1075 _("There are no unambiguously determinable intermediate "
1076 "callers or callees between caller function \"%s\" at %s "
1077 "and callee function \"%s\" at %s"),
1078 (msym_caller
.minsym
== NULL
1079 ? "???" : msym_caller
.minsym
->print_name ()),
1080 paddress (gdbarch
, caller_pc
),
1081 (msym_callee
.minsym
== NULL
1082 ? "???" : msym_callee
.minsym
->print_name ()),
1083 paddress (gdbarch
, callee_pc
));
1089 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1090 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1091 constructed return NULL. */
1093 gdb::unique_xmalloc_ptr
<call_site_chain
>
1094 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1095 CORE_ADDR callee_pc
)
1097 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1101 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1103 catch (const gdb_exception_error
&e
)
1105 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1107 if (entry_values_debug
)
1108 exception_print (gdb_stdout
, e
);
1119 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1122 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1123 enum call_site_parameter_kind kind
,
1124 union call_site_parameter_u kind_u
)
1126 if (kind
== parameter
->kind
)
1129 case CALL_SITE_PARAMETER_DWARF_REG
:
1130 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1132 case CALL_SITE_PARAMETER_FB_OFFSET
:
1133 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1135 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1136 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1143 struct call_site_parameter
*
1144 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1145 enum call_site_parameter_kind kind
,
1146 union call_site_parameter_u kind_u
,
1147 dwarf2_per_cu_data
**per_cu_return
,
1148 dwarf2_per_objfile
**per_objfile_return
)
1150 CORE_ADDR func_addr
, caller_pc
;
1151 struct gdbarch
*gdbarch
;
1152 struct frame_info
*caller_frame
;
1153 struct call_site
*call_site
;
1155 /* Initialize it just to avoid a GCC false warning. */
1156 struct call_site_parameter
*parameter
= NULL
;
1157 CORE_ADDR target_addr
;
1159 while (get_frame_type (frame
) == INLINE_FRAME
)
1161 frame
= get_prev_frame (frame
);
1162 gdb_assert (frame
!= NULL
);
1165 func_addr
= get_frame_func (frame
);
1166 gdbarch
= get_frame_arch (frame
);
1167 caller_frame
= get_prev_frame (frame
);
1168 if (gdbarch
!= frame_unwind_arch (frame
))
1170 struct bound_minimal_symbol msym
1171 = lookup_minimal_symbol_by_pc (func_addr
);
1172 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1174 throw_error (NO_ENTRY_VALUE_ERROR
,
1175 _("DW_OP_entry_value resolving callee gdbarch %s "
1176 "(of %s (%s)) does not match caller gdbarch %s"),
1177 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1178 paddress (gdbarch
, func_addr
),
1179 (msym
.minsym
== NULL
? "???"
1180 : msym
.minsym
->print_name ()),
1181 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1184 if (caller_frame
== NULL
)
1186 struct bound_minimal_symbol msym
1187 = lookup_minimal_symbol_by_pc (func_addr
);
1189 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1190 "requires caller of %s (%s)"),
1191 paddress (gdbarch
, func_addr
),
1192 (msym
.minsym
== NULL
? "???"
1193 : msym
.minsym
->print_name ()));
1195 caller_pc
= get_frame_pc (caller_frame
);
1196 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1198 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1199 if (target_addr
!= func_addr
)
1201 struct minimal_symbol
*target_msym
, *func_msym
;
1203 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1204 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1205 throw_error (NO_ENTRY_VALUE_ERROR
,
1206 _("DW_OP_entry_value resolving expects callee %s at %s "
1207 "but the called frame is for %s at %s"),
1208 (target_msym
== NULL
? "???"
1209 : target_msym
->print_name ()),
1210 paddress (gdbarch
, target_addr
),
1211 func_msym
== NULL
? "???" : func_msym
->print_name (),
1212 paddress (gdbarch
, func_addr
));
1215 /* No entry value based parameters would be reliable if this function can
1216 call itself via tail calls. */
1217 func_verify_no_selftailcall (gdbarch
, func_addr
);
1219 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1221 parameter
= &call_site
->parameter
[iparams
];
1222 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1225 if (iparams
== call_site
->parameter_count
)
1227 struct minimal_symbol
*msym
1228 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1230 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1231 determine its value. */
1232 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1233 "at DW_TAG_call_site %s at %s"),
1234 paddress (gdbarch
, caller_pc
),
1235 msym
== NULL
? "???" : msym
->print_name ());
1238 *per_cu_return
= call_site
->per_cu
;
1239 *per_objfile_return
= call_site
->per_objfile
;
1243 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1244 the normal DW_AT_call_value block. Otherwise return the
1245 DW_AT_call_data_value (dereferenced) block.
1247 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1250 Function always returns non-NULL, non-optimized out value. It throws
1251 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1253 static struct value
*
1254 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1255 CORE_ADDR deref_size
, struct type
*type
,
1256 struct frame_info
*caller_frame
,
1257 dwarf2_per_cu_data
*per_cu
,
1258 dwarf2_per_objfile
*per_objfile
)
1260 const gdb_byte
*data_src
;
1264 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1265 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1267 /* DEREF_SIZE size is not verified here. */
1268 if (data_src
== NULL
)
1269 throw_error (NO_ENTRY_VALUE_ERROR
,
1270 _("Cannot resolve DW_AT_call_data_value"));
1272 /* DW_AT_call_value is a DWARF expression, not a DWARF
1273 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1275 data
= (gdb_byte
*) alloca (size
+ 1);
1276 memcpy (data
, data_src
, size
);
1277 data
[size
] = DW_OP_stack_value
;
1279 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
,
1283 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1284 the indirect method on it, that is use its stored target value, the sole
1285 purpose of entry_data_value_funcs.. */
1287 static struct value
*
1288 entry_data_value_coerce_ref (const struct value
*value
)
1290 struct type
*checked_type
= check_typedef (value_type (value
));
1291 struct value
*target_val
;
1293 if (!TYPE_IS_REFERENCE (checked_type
))
1296 target_val
= (struct value
*) value_computed_closure (value
);
1297 value_incref (target_val
);
1301 /* Implement copy_closure. */
1304 entry_data_value_copy_closure (const struct value
*v
)
1306 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1308 value_incref (target_val
);
1312 /* Implement free_closure. */
1315 entry_data_value_free_closure (struct value
*v
)
1317 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1319 value_decref (target_val
);
1322 /* Vector for methods for an entry value reference where the referenced value
1323 is stored in the caller. On the first dereference use
1324 DW_AT_call_data_value in the caller. */
1326 static const struct lval_funcs entry_data_value_funcs
=
1330 NULL
, /* indirect */
1331 entry_data_value_coerce_ref
,
1332 NULL
, /* check_synthetic_pointer */
1333 entry_data_value_copy_closure
,
1334 entry_data_value_free_closure
1337 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1338 are used to match DW_AT_location at the caller's
1339 DW_TAG_call_site_parameter.
1341 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1342 cannot resolve the parameter for any reason. */
1344 static struct value
*
1345 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1346 enum call_site_parameter_kind kind
,
1347 union call_site_parameter_u kind_u
)
1349 struct type
*checked_type
= check_typedef (type
);
1350 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1351 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1352 struct value
*outer_val
, *target_val
, *val
;
1353 struct call_site_parameter
*parameter
;
1354 dwarf2_per_cu_data
*caller_per_cu
;
1355 dwarf2_per_objfile
*caller_per_objfile
;
1357 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1359 &caller_per_objfile
);
1361 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1364 caller_per_objfile
);
1366 /* Check if DW_AT_call_data_value cannot be used. If it should be
1367 used and it is not available do not fall back to OUTER_VAL - dereferencing
1368 TYPE_CODE_REF with non-entry data value would give current value - not the
1371 if (!TYPE_IS_REFERENCE (checked_type
)
1372 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1375 target_val
= dwarf_entry_parameter_to_value (parameter
,
1376 TYPE_LENGTH (target_type
),
1377 target_type
, caller_frame
,
1379 caller_per_objfile
);
1381 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1382 release_value (target_val
).release ());
1384 /* Copy the referencing pointer to the new computed value. */
1385 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1386 TYPE_LENGTH (checked_type
));
1387 set_value_lazy (val
, 0);
1392 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1393 SIZE are DWARF block used to match DW_AT_location at the caller's
1394 DW_TAG_call_site_parameter.
1396 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1397 cannot resolve the parameter for any reason. */
1399 static struct value
*
1400 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1401 const gdb_byte
*block
, size_t block_len
)
1403 union call_site_parameter_u kind_u
;
1405 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1406 if (kind_u
.dwarf_reg
!= -1)
1407 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1410 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1411 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1414 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1415 suppressed during normal operation. The expression can be arbitrary if
1416 there is no caller-callee entry value binding expected. */
1417 throw_error (NO_ENTRY_VALUE_ERROR
,
1418 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1419 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1422 struct piece_closure
1424 /* Reference count. */
1427 /* The objfile from which this closure's expression came. */
1428 dwarf2_per_objfile
*per_objfile
= nullptr;
1430 /* The CU from which this closure's expression came. */
1431 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1433 /* The pieces describing this variable. */
1434 std::vector
<dwarf_expr_piece
> pieces
;
1436 /* Frame ID of frame to which a register value is relative, used
1437 only by DWARF_VALUE_REGISTER. */
1438 struct frame_id frame_id
;
1441 /* Allocate a closure for a value formed from separately-described
1444 static struct piece_closure
*
1445 allocate_piece_closure (dwarf2_per_cu_data
*per_cu
,
1446 dwarf2_per_objfile
*per_objfile
,
1447 std::vector
<dwarf_expr_piece
> &&pieces
,
1448 struct frame_info
*frame
)
1450 struct piece_closure
*c
= new piece_closure
;
1453 /* We must capture this here due to sharing of DWARF state. */
1454 c
->per_objfile
= per_objfile
;
1456 c
->pieces
= std::move (pieces
);
1458 c
->frame_id
= null_frame_id
;
1460 c
->frame_id
= get_frame_id (frame
);
1462 for (dwarf_expr_piece
&piece
: c
->pieces
)
1463 if (piece
.location
== DWARF_VALUE_STACK
)
1464 value_incref (piece
.v
.value
);
1469 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1470 bits whose first bit is located at bit offset START. */
1473 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1475 return (start
% 8 + n_bits
+ 7) / 8;
1478 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1479 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1480 operate in "read mode": fetch the contents of the (lazy) value V by
1481 composing it from its pieces. */
1484 rw_pieced_value (struct value
*v
, struct value
*from
)
1487 LONGEST offset
= 0, max_offset
;
1488 ULONGEST bits_to_skip
;
1489 gdb_byte
*v_contents
;
1490 const gdb_byte
*from_contents
;
1491 struct piece_closure
*c
1492 = (struct piece_closure
*) value_computed_closure (v
);
1493 gdb::byte_vector buffer
;
1494 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1498 from_contents
= value_contents (from
);
1503 if (value_type (v
) != value_enclosing_type (v
))
1504 internal_error (__FILE__
, __LINE__
,
1505 _("Should not be able to create a lazy value with "
1506 "an enclosing type"));
1507 v_contents
= value_contents_raw (v
);
1508 from_contents
= NULL
;
1511 bits_to_skip
= 8 * value_offset (v
);
1512 if (value_bitsize (v
))
1514 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1515 + value_bitpos (v
));
1517 && (type_byte_order (value_type (from
))
1520 /* Use the least significant bits of FROM. */
1521 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1522 offset
= max_offset
- value_bitsize (v
);
1525 max_offset
= value_bitsize (v
);
1528 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1530 /* Advance to the first non-skipped piece. */
1531 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1532 bits_to_skip
-= c
->pieces
[i
].size
;
1534 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1536 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1537 size_t this_size_bits
, this_size
;
1539 this_size_bits
= p
->size
- bits_to_skip
;
1540 if (this_size_bits
> max_offset
- offset
)
1541 this_size_bits
= max_offset
- offset
;
1543 switch (p
->location
)
1545 case DWARF_VALUE_REGISTER
:
1547 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1548 struct gdbarch
*arch
= get_frame_arch (frame
);
1549 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1550 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1553 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1554 && p
->offset
+ p
->size
< reg_bits
)
1556 /* Big-endian, and we want less than full size. */
1557 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1560 bits_to_skip
+= p
->offset
;
1562 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1563 buffer
.resize (this_size
);
1568 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1574 mark_value_bits_optimized_out (v
, offset
,
1577 mark_value_bits_unavailable (v
, offset
,
1582 copy_bitwise (v_contents
, offset
,
1583 buffer
.data (), bits_to_skip
% 8,
1584 this_size_bits
, bits_big_endian
);
1589 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1591 /* Data is copied non-byte-aligned into the register.
1592 Need some bits from original register value. */
1593 get_frame_register_bytes (frame
, gdb_regnum
,
1598 throw_error (OPTIMIZED_OUT_ERROR
,
1599 _("Can't do read-modify-write to "
1600 "update bitfield; containing word "
1601 "has been optimized out"));
1603 throw_error (NOT_AVAILABLE_ERROR
,
1604 _("Can't do read-modify-write to "
1605 "update bitfield; containing word "
1609 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1610 from_contents
, offset
,
1611 this_size_bits
, bits_big_endian
);
1612 put_frame_register_bytes (frame
, gdb_regnum
,
1619 case DWARF_VALUE_MEMORY
:
1621 bits_to_skip
+= p
->offset
;
1623 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1625 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1628 /* Everything is byte-aligned; no buffer needed. */
1630 write_memory_with_notification (start_addr
,
1633 this_size_bits
/ 8);
1635 read_value_memory (v
, offset
,
1636 p
->v
.mem
.in_stack_memory
,
1637 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1638 v_contents
+ offset
/ 8,
1639 this_size_bits
/ 8);
1643 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1644 buffer
.resize (this_size
);
1649 read_value_memory (v
, offset
,
1650 p
->v
.mem
.in_stack_memory
,
1651 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1652 buffer
.data (), this_size
);
1653 copy_bitwise (v_contents
, offset
,
1654 buffer
.data (), bits_to_skip
% 8,
1655 this_size_bits
, bits_big_endian
);
1660 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1664 /* Perform a single read for small sizes. */
1665 read_memory (start_addr
, buffer
.data (),
1670 /* Only the first and last bytes can possibly have
1672 read_memory (start_addr
, buffer
.data (), 1);
1673 read_memory (start_addr
+ this_size
- 1,
1674 &buffer
[this_size
- 1], 1);
1678 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1679 from_contents
, offset
,
1680 this_size_bits
, bits_big_endian
);
1681 write_memory_with_notification (start_addr
,
1688 case DWARF_VALUE_STACK
:
1692 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1696 gdbarch
*objfile_gdbarch
= c
->per_objfile
->objfile
->arch ();
1697 ULONGEST stack_value_size_bits
1698 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1700 /* Use zeroes if piece reaches beyond stack value. */
1701 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1704 /* Piece is anchored at least significant bit end. */
1705 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1706 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1708 bits_to_skip
+= p
->offset
;
1710 copy_bitwise (v_contents
, offset
,
1711 value_contents_all (p
->v
.value
),
1713 this_size_bits
, bits_big_endian
);
1717 case DWARF_VALUE_LITERAL
:
1721 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1725 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1726 size_t n
= this_size_bits
;
1728 /* Cut off at the end of the implicit value. */
1729 bits_to_skip
+= p
->offset
;
1730 if (bits_to_skip
>= literal_size_bits
)
1732 if (n
> literal_size_bits
- bits_to_skip
)
1733 n
= literal_size_bits
- bits_to_skip
;
1735 copy_bitwise (v_contents
, offset
,
1736 p
->v
.literal
.data
, bits_to_skip
,
1737 n
, bits_big_endian
);
1741 case DWARF_VALUE_IMPLICIT_POINTER
:
1744 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1748 /* These bits show up as zeros -- but do not cause the value to
1749 be considered optimized-out. */
1752 case DWARF_VALUE_OPTIMIZED_OUT
:
1753 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1757 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1760 offset
+= this_size_bits
;
1767 read_pieced_value (struct value
*v
)
1769 rw_pieced_value (v
, NULL
);
1773 write_pieced_value (struct value
*to
, struct value
*from
)
1775 rw_pieced_value (to
, from
);
1778 /* An implementation of an lval_funcs method to see whether a value is
1779 a synthetic pointer. */
1782 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1785 struct piece_closure
*c
1786 = (struct piece_closure
*) value_computed_closure (value
);
1789 bit_offset
+= 8 * value_offset (value
);
1790 if (value_bitsize (value
))
1791 bit_offset
+= value_bitpos (value
);
1793 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1795 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1796 size_t this_size_bits
= p
->size
;
1800 if (bit_offset
>= this_size_bits
)
1802 bit_offset
-= this_size_bits
;
1806 bit_length
-= this_size_bits
- bit_offset
;
1810 bit_length
-= this_size_bits
;
1812 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1819 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1821 static struct value
*
1822 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1823 dwarf2_per_cu_data
*per_cu
,
1824 dwarf2_per_objfile
*per_objfile
,
1827 struct value
*result
= NULL
;
1828 const gdb_byte
*bytes
;
1831 auto_obstack temp_obstack
;
1832 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
1833 &temp_obstack
, &len
);
1837 if (byte_offset
>= 0
1838 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
1840 bytes
+= byte_offset
;
1841 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
1844 invalid_synthetic_pointer ();
1847 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
1852 /* Fetch the value pointed to by a synthetic pointer. */
1854 static struct value
*
1855 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
1856 dwarf2_per_cu_data
*per_cu
,
1857 dwarf2_per_objfile
*per_objfile
,
1858 struct frame_info
*frame
, struct type
*type
,
1859 bool resolve_abstract_p
)
1861 /* Fetch the location expression of the DIE we're pointing to. */
1862 auto get_frame_address_in_block_wrapper
= [frame
] ()
1864 return get_frame_address_in_block (frame
);
1866 struct dwarf2_locexpr_baton baton
1867 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
1868 get_frame_address_in_block_wrapper
,
1869 resolve_abstract_p
);
1871 /* Get type of pointed-to DIE. */
1872 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
1874 if (orig_type
== NULL
)
1875 invalid_synthetic_pointer ();
1877 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
1878 resulting value. Otherwise, it may have a DW_AT_const_value instead,
1879 or it may've been optimized out. */
1880 if (baton
.data
!= NULL
)
1881 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
1882 baton
.size
, baton
.per_cu
,
1884 TYPE_TARGET_TYPE (type
),
1887 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
1891 /* An implementation of an lval_funcs method to indirect through a
1892 pointer. This handles the synthetic pointer case when needed. */
1894 static struct value
*
1895 indirect_pieced_value (struct value
*value
)
1897 struct piece_closure
*c
1898 = (struct piece_closure
*) value_computed_closure (value
);
1900 struct frame_info
*frame
;
1903 struct dwarf_expr_piece
*piece
= NULL
;
1904 LONGEST byte_offset
;
1905 enum bfd_endian byte_order
;
1907 type
= check_typedef (value_type (value
));
1908 if (type
->code () != TYPE_CODE_PTR
)
1911 bit_length
= 8 * TYPE_LENGTH (type
);
1912 bit_offset
= 8 * value_offset (value
);
1913 if (value_bitsize (value
))
1914 bit_offset
+= value_bitpos (value
);
1916 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1918 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1919 size_t this_size_bits
= p
->size
;
1923 if (bit_offset
>= this_size_bits
)
1925 bit_offset
-= this_size_bits
;
1929 bit_length
-= this_size_bits
- bit_offset
;
1933 bit_length
-= this_size_bits
;
1935 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
1938 if (bit_length
!= 0)
1939 error (_("Invalid use of DW_OP_implicit_pointer"));
1945 gdb_assert (piece
!= NULL
);
1946 frame
= get_selected_frame (_("No frame selected."));
1948 /* This is an offset requested by GDB, such as value subscripts.
1949 However, due to how synthetic pointers are implemented, this is
1950 always presented to us as a pointer type. This means we have to
1951 sign-extend it manually as appropriate. Use raw
1952 extract_signed_integer directly rather than value_as_address and
1953 sign extend afterwards on architectures that would need it
1954 (mostly everywhere except MIPS, which has signed addresses) as
1955 the later would go through gdbarch_pointer_to_address and thus
1956 return a CORE_ADDR with high bits set on architectures that
1957 encode address spaces and other things in CORE_ADDR. */
1958 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
1959 byte_offset
= extract_signed_integer (value_contents (value
),
1960 TYPE_LENGTH (type
), byte_order
);
1961 byte_offset
+= piece
->v
.ptr
.offset
;
1963 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
1964 byte_offset
, c
->per_cu
,
1965 c
->per_objfile
, frame
, type
);
1968 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
1971 static struct value
*
1972 coerce_pieced_ref (const struct value
*value
)
1974 struct type
*type
= check_typedef (value_type (value
));
1976 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
1977 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
1979 const struct piece_closure
*closure
1980 = (struct piece_closure
*) value_computed_closure (value
);
1981 struct frame_info
*frame
1982 = get_selected_frame (_("No frame selected."));
1984 /* gdb represents synthetic pointers as pieced values with a single
1986 gdb_assert (closure
!= NULL
);
1987 gdb_assert (closure
->pieces
.size () == 1);
1989 return indirect_synthetic_pointer
1990 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
1991 closure
->pieces
[0].v
.ptr
.offset
,
1992 closure
->per_cu
, closure
->per_objfile
, frame
, type
);
1996 /* Else: not a synthetic reference; do nothing. */
2002 copy_pieced_value_closure (const struct value
*v
)
2004 struct piece_closure
*c
2005 = (struct piece_closure
*) value_computed_closure (v
);
2012 free_pieced_value_closure (struct value
*v
)
2014 struct piece_closure
*c
2015 = (struct piece_closure
*) value_computed_closure (v
);
2020 for (dwarf_expr_piece
&p
: c
->pieces
)
2021 if (p
.location
== DWARF_VALUE_STACK
)
2022 value_decref (p
.v
.value
);
2028 /* Functions for accessing a variable described by DW_OP_piece. */
2029 static const struct lval_funcs pieced_value_funcs
= {
2032 indirect_pieced_value
,
2034 check_pieced_synthetic_pointer
,
2035 copy_pieced_value_closure
,
2036 free_pieced_value_closure
2039 /* Evaluate a location description, starting at DATA and with length
2040 SIZE, to find the current location of variable of TYPE in the
2041 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2042 location of the subobject of type SUBOBJ_TYPE at byte offset
2043 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2045 static struct value
*
2046 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2047 const gdb_byte
*data
, size_t size
,
2048 dwarf2_per_cu_data
*per_cu
,
2049 dwarf2_per_objfile
*per_objfile
,
2050 struct type
*subobj_type
,
2051 LONGEST subobj_byte_offset
)
2053 struct value
*retval
;
2055 if (subobj_type
== NULL
)
2058 subobj_byte_offset
= 0;
2060 else if (subobj_byte_offset
< 0)
2061 invalid_synthetic_pointer ();
2064 return allocate_optimized_out_value (subobj_type
);
2066 dwarf_expr_context
ctx (per_objfile
);
2068 ctx
.per_cu
= per_cu
;
2069 ctx
.obj_address
= 0;
2071 scoped_value_mark free_values
;
2073 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2074 ctx
.addr_size
= per_cu
->addr_size ();
2078 ctx
.eval (data
, size
);
2080 catch (const gdb_exception_error
&ex
)
2082 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2084 free_values
.free_to_mark ();
2085 retval
= allocate_value (subobj_type
);
2086 mark_value_bytes_unavailable (retval
, 0,
2087 TYPE_LENGTH (subobj_type
));
2090 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2092 if (entry_values_debug
)
2093 exception_print (gdb_stdout
, ex
);
2094 free_values
.free_to_mark ();
2095 return allocate_optimized_out_value (subobj_type
);
2101 if (ctx
.pieces
.size () > 0)
2103 struct piece_closure
*c
;
2104 ULONGEST bit_size
= 0;
2106 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2107 bit_size
+= piece
.size
;
2108 /* Complain if the expression is larger than the size of the
2110 if (bit_size
> 8 * TYPE_LENGTH (type
))
2111 invalid_synthetic_pointer ();
2113 c
= allocate_piece_closure (per_cu
, per_objfile
, std::move (ctx
.pieces
),
2115 /* We must clean up the value chain after creating the piece
2116 closure but before allocating the result. */
2117 free_values
.free_to_mark ();
2118 retval
= allocate_computed_value (subobj_type
,
2119 &pieced_value_funcs
, c
);
2120 set_value_offset (retval
, subobj_byte_offset
);
2124 switch (ctx
.location
)
2126 case DWARF_VALUE_REGISTER
:
2128 struct gdbarch
*arch
= get_frame_arch (frame
);
2130 = longest_to_int (value_as_long (ctx
.fetch (0)));
2131 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2133 if (subobj_byte_offset
!= 0)
2134 error (_("cannot use offset on synthetic pointer to register"));
2135 free_values
.free_to_mark ();
2136 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2137 if (value_optimized_out (retval
))
2141 /* This means the register has undefined value / was
2142 not saved. As we're computing the location of some
2143 variable etc. in the program, not a value for
2144 inspecting a register ($pc, $sp, etc.), return a
2145 generic optimized out value instead, so that we show
2146 <optimized out> instead of <not saved>. */
2147 tmp
= allocate_value (subobj_type
);
2148 value_contents_copy (tmp
, 0, retval
, 0,
2149 TYPE_LENGTH (subobj_type
));
2155 case DWARF_VALUE_MEMORY
:
2157 struct type
*ptr_type
;
2158 CORE_ADDR address
= ctx
.fetch_address (0);
2159 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2161 /* DW_OP_deref_size (and possibly other operations too) may
2162 create a pointer instead of an address. Ideally, the
2163 pointer to address conversion would be performed as part
2164 of those operations, but the type of the object to
2165 which the address refers is not known at the time of
2166 the operation. Therefore, we do the conversion here
2167 since the type is readily available. */
2169 switch (subobj_type
->code ())
2171 case TYPE_CODE_FUNC
:
2172 case TYPE_CODE_METHOD
:
2173 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2176 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2179 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2181 free_values
.free_to_mark ();
2182 retval
= value_at_lazy (subobj_type
,
2183 address
+ subobj_byte_offset
);
2184 if (in_stack_memory
)
2185 set_value_stack (retval
, 1);
2189 case DWARF_VALUE_STACK
:
2191 struct value
*value
= ctx
.fetch (0);
2192 size_t n
= TYPE_LENGTH (value_type (value
));
2193 size_t len
= TYPE_LENGTH (subobj_type
);
2194 size_t max
= TYPE_LENGTH (type
);
2195 gdbarch
*objfile_gdbarch
= per_objfile
->objfile
->arch ();
2197 if (subobj_byte_offset
+ len
> max
)
2198 invalid_synthetic_pointer ();
2200 /* Preserve VALUE because we are going to free values back
2201 to the mark, but we still need the value contents
2203 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2204 free_values
.free_to_mark ();
2206 retval
= allocate_value (subobj_type
);
2208 /* The given offset is relative to the actual object. */
2209 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2210 subobj_byte_offset
+= n
- max
;
2212 memcpy (value_contents_raw (retval
),
2213 value_contents_all (value
) + subobj_byte_offset
, len
);
2217 case DWARF_VALUE_LITERAL
:
2220 size_t n
= TYPE_LENGTH (subobj_type
);
2222 if (subobj_byte_offset
+ n
> ctx
.len
)
2223 invalid_synthetic_pointer ();
2225 free_values
.free_to_mark ();
2226 retval
= allocate_value (subobj_type
);
2227 contents
= value_contents_raw (retval
);
2228 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2232 case DWARF_VALUE_OPTIMIZED_OUT
:
2233 free_values
.free_to_mark ();
2234 retval
= allocate_optimized_out_value (subobj_type
);
2237 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2238 operation by execute_stack_op. */
2239 case DWARF_VALUE_IMPLICIT_POINTER
:
2240 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2241 it can only be encountered when making a piece. */
2243 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2247 set_value_initialized (retval
, ctx
.initialized
);
2252 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2253 passes 0 as the byte_offset. */
2256 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2257 const gdb_byte
*data
, size_t size
,
2258 dwarf2_per_cu_data
*per_cu
,
2259 dwarf2_per_objfile
*per_objfile
)
2261 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2262 per_objfile
, NULL
, 0);
2265 /* A specialization of dwarf_expr_context that is used by
2266 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2267 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2268 but with the address being 0. In this situation, we arrange for
2269 memory reads to come from the passed-in buffer. */
2271 struct evaluate_for_locexpr_baton
: public dwarf_expr_context
2273 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2274 : dwarf_expr_context (per_objfile
)
2277 /* The data that was passed in. */
2278 gdb::array_view
<const gdb_byte
> data_view
;
2280 CORE_ADDR
get_object_address () override
2282 if (data_view
.data () == nullptr && obj_address
== 0)
2283 error (_("Location address is not set."));
2287 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2292 /* Prefer the passed-in memory, if it exists. */
2293 CORE_ADDR offset
= addr
- obj_address
;
2294 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2296 memcpy (buf
, data_view
.data (), len
);
2300 read_memory (addr
, buf
, len
);
2304 /* Evaluates a dwarf expression and stores the result in VAL,
2305 expecting that the dwarf expression only produces a single
2306 CORE_ADDR. FRAME is the frame in which the expression is
2307 evaluated. ADDR_STACK is a context (location of a variable) and
2308 might be needed to evaluate the location expression.
2309 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2310 or the default of 0) should be pushed on the DWARF expression
2311 evaluation stack before evaluating the expression; this is required
2312 by certain forms of DWARF expression. Returns 1 on success, 0
2316 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2317 struct frame_info
*frame
,
2318 const struct property_addr_info
*addr_stack
,
2320 bool push_initial_value
,
2323 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2326 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2327 evaluate_for_locexpr_baton
ctx (per_objfile
);
2330 ctx
.per_cu
= dlbaton
->per_cu
;
2331 if (addr_stack
== nullptr)
2332 ctx
.obj_address
= 0;
2335 ctx
.obj_address
= addr_stack
->addr
;
2336 ctx
.data_view
= addr_stack
->valaddr
;
2339 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2340 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2342 if (push_initial_value
)
2343 ctx
.push_address (ctx
.obj_address
, false);
2347 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2349 catch (const gdb_exception_error
&ex
)
2351 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2355 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2357 if (entry_values_debug
)
2358 exception_print (gdb_stdout
, ex
);
2365 switch (ctx
.location
)
2367 case DWARF_VALUE_STACK
:
2368 *is_reference
= false;
2371 case DWARF_VALUE_REGISTER
:
2372 case DWARF_VALUE_MEMORY
:
2373 *valp
= ctx
.fetch_address (0);
2374 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2375 *valp
= read_addr_from_reg (frame
, *valp
);
2377 case DWARF_VALUE_LITERAL
:
2378 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2379 gdbarch_byte_order (ctx
.gdbarch
));
2381 /* Unsupported dwarf values. */
2382 case DWARF_VALUE_OPTIMIZED_OUT
:
2383 case DWARF_VALUE_IMPLICIT_POINTER
:
2390 /* See dwarf2loc.h. */
2393 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2394 struct frame_info
*frame
,
2395 const struct property_addr_info
*addr_stack
,
2397 bool push_initial_value
)
2402 if (frame
== NULL
&& has_stack_frames ())
2403 frame
= get_selected_frame (NULL
);
2405 switch (prop
->kind ())
2409 const struct dwarf2_property_baton
*baton
2410 = (const struct dwarf2_property_baton
*) prop
->baton ();
2411 gdb_assert (baton
->property_type
!= NULL
);
2413 bool is_reference
= baton
->locexpr
.is_reference
;
2414 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2415 value
, push_initial_value
, &is_reference
))
2419 struct value
*val
= value_at (baton
->property_type
, *value
);
2420 *value
= value_as_address (val
);
2424 gdb_assert (baton
->property_type
!= NULL
);
2426 struct type
*type
= check_typedef (baton
->property_type
);
2427 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2428 && !type
->is_unsigned ())
2430 /* If we have a valid return candidate and it's value
2431 is signed, we have to sign-extend the value because
2432 CORE_ADDR on 64bit machine has 8 bytes but address
2433 size of an 32bit application is bytes. */
2435 = (baton
->locexpr
.per_cu
->addr_size ()
2437 const CORE_ADDR neg_mask
2438 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2440 /* Check if signed bit is set and sign-extend values. */
2441 if (*value
& neg_mask
)
2452 struct dwarf2_property_baton
*baton
2453 = (struct dwarf2_property_baton
*) prop
->baton ();
2455 const gdb_byte
*data
;
2460 || !get_frame_address_in_block_if_available (frame
, &pc
))
2463 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2466 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2467 size
, baton
->loclist
.per_cu
,
2468 baton
->loclist
.per_objfile
);
2469 if (!value_optimized_out (val
))
2471 *value
= value_as_address (val
);
2479 *value
= prop
->const_val ();
2482 case PROP_ADDR_OFFSET
:
2484 struct dwarf2_property_baton
*baton
2485 = (struct dwarf2_property_baton
*) prop
->baton ();
2486 const struct property_addr_info
*pinfo
;
2489 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2491 /* This approach lets us avoid checking the qualifiers. */
2492 if (TYPE_MAIN_TYPE (pinfo
->type
)
2493 == TYPE_MAIN_TYPE (baton
->property_type
))
2497 error (_("cannot find reference address for offset property"));
2498 if (pinfo
->valaddr
.data () != NULL
)
2499 val
= value_from_contents
2500 (baton
->offset_info
.type
,
2501 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2503 val
= value_at (baton
->offset_info
.type
,
2504 pinfo
->addr
+ baton
->offset_info
.offset
);
2505 *value
= value_as_address (val
);
2509 case PROP_VARIABLE_NAME
:
2511 struct value
*val
= compute_var_value (prop
->variable_name ());
2514 *value
= value_as_long (val
);
2524 /* See dwarf2loc.h. */
2527 dwarf2_compile_property_to_c (string_file
*stream
,
2528 const char *result_name
,
2529 struct gdbarch
*gdbarch
,
2530 std::vector
<bool> ®isters_used
,
2531 const struct dynamic_prop
*prop
,
2535 struct dwarf2_property_baton
*baton
2536 = (struct dwarf2_property_baton
*) prop
->baton ();
2537 const gdb_byte
*data
;
2539 dwarf2_per_cu_data
*per_cu
;
2540 dwarf2_per_objfile
*per_objfile
;
2542 if (prop
->kind () == PROP_LOCEXPR
)
2544 data
= baton
->locexpr
.data
;
2545 size
= baton
->locexpr
.size
;
2546 per_cu
= baton
->locexpr
.per_cu
;
2547 per_objfile
= baton
->locexpr
.per_objfile
;
2551 gdb_assert (prop
->kind () == PROP_LOCLIST
);
2553 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2554 per_cu
= baton
->loclist
.per_cu
;
2555 per_objfile
= baton
->loclist
.per_objfile
;
2558 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2559 gdbarch
, registers_used
,
2560 per_cu
->addr_size (),
2561 data
, data
+ size
, per_cu
, per_objfile
);
2564 /* Compute the correct symbol_needs_kind value for the location
2567 Implemented by traversing the logical control flow graph of the
2570 static enum symbol_needs_kind
2571 dwarf2_get_symbol_read_needs (gdb::array_view
<const gdb_byte
> expr
,
2572 dwarf2_per_cu_data
*per_cu
,
2573 dwarf2_per_objfile
*per_objfile
,
2574 bfd_endian byte_order
,
2579 enum symbol_needs_kind symbol_needs
= SYMBOL_NEEDS_NONE
;
2581 /* If the expression is empty, we have nothing to do. */
2583 return symbol_needs
;
2585 const gdb_byte
*expr_end
= expr
.data () + expr
.size ();
2587 /* List of operations to visit. Operations in this list are not visited yet,
2588 so are not in VISITED_OPS (and vice-versa). */
2589 std::vector
<const gdb_byte
*> ops_to_visit
;
2591 /* Operations already visited. */
2592 std::unordered_set
<const gdb_byte
*> visited_ops
;
2594 /* Insert OP in OPS_TO_VISIT if it is within the expression's range and
2595 hasn't been visited yet. */
2596 auto insert_in_ops_to_visit
2597 = [expr_end
, &visited_ops
, &ops_to_visit
] (const gdb_byte
*op_ptr
)
2599 if (op_ptr
>= expr_end
)
2602 if (visited_ops
.find (op_ptr
) != visited_ops
.end ())
2605 ops_to_visit
.push_back (op_ptr
);
2608 /* Expressions can invoke other expressions with DW_OP_call*. Protect against
2610 const int max_depth
= 256;
2612 if (depth
> max_depth
)
2613 error (_("DWARF-2 expression error: Loop detected."));
2617 /* Initialize the to-visit list with the first operation. */
2618 insert_in_ops_to_visit (&expr
[0]);
2620 while (!ops_to_visit
.empty ())
2622 /* Pop one op to visit, mark it as visited. */
2623 const gdb_byte
*op_ptr
= ops_to_visit
.back ();
2624 ops_to_visit
.pop_back ();
2625 gdb_assert (visited_ops
.find (op_ptr
) == visited_ops
.end ());
2626 visited_ops
.insert (op_ptr
);
2628 dwarf_location_atom op
= (dwarf_location_atom
) *op_ptr
;
2630 /* Most operations have a single possible following operation
2631 (they are not conditional branches). The code below updates
2632 OP_PTR to point to that following operation, which is pushed
2633 back to OPS_TO_VISIT, if needed, at the bottom. Here, leave
2634 OP_PTR pointing just after the operand. */
2637 /* The DWARF expression might have a bug causing an infinite
2638 loop. In that case, quitting is the only way out. */
2675 case DW_OP_stack_value
:
2702 case DW_OP_GNU_push_tls_address
:
2704 case DW_OP_GNU_uninit
:
2705 case DW_OP_push_object_address
:
2708 case DW_OP_form_tls_address
:
2709 if (symbol_needs
<= SYMBOL_NEEDS_REGISTERS
)
2710 symbol_needs
= SYMBOL_NEEDS_REGISTERS
;
2714 case DW_OP_GNU_convert
:
2715 case DW_OP_reinterpret
:
2716 case DW_OP_GNU_reinterpret
:
2718 case DW_OP_GNU_addr_index
:
2719 case DW_OP_GNU_const_index
:
2721 case DW_OP_plus_uconst
:
2723 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2727 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2730 case DW_OP_bit_piece
:
2731 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2732 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2735 case DW_OP_deref_type
:
2736 case DW_OP_GNU_deref_type
:
2738 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2742 op_ptr
+= addr_size
;
2832 case DW_OP_call_frame_cfa
:
2833 case DW_OP_entry_value
:
2834 case DW_OP_GNU_entry_value
:
2835 case DW_OP_GNU_parameter_ref
:
2836 case DW_OP_regval_type
:
2837 case DW_OP_GNU_regval_type
:
2838 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2841 case DW_OP_implicit_value
:
2844 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2849 case DW_OP_implicit_pointer
:
2850 case DW_OP_GNU_implicit_pointer
:
2851 op_ptr
+= ref_addr_size
;
2852 op_ptr
= safe_skip_leb128 (op_ptr
, expr_end
);
2855 case DW_OP_deref_size
:
2862 int64_t offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2870 /* This is the only operation that pushes two operations in
2871 the to-visit list, so handle it all here. */
2872 LONGEST offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
2875 insert_in_ops_to_visit (op_ptr
+ offset
);
2876 insert_in_ops_to_visit (op_ptr
);
2883 unsigned int len
= op
== DW_OP_call2
? 2 : 4;
2885 = (cu_offset
) extract_unsigned_integer (op_ptr
, len
, byte_order
);
2888 auto get_frame_pc
= [&symbol_needs
] ()
2890 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2894 struct dwarf2_locexpr_baton baton
2895 = dwarf2_fetch_die_loc_cu_off (cu_off
, per_cu
,
2899 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2900 we dont have to check the baton content. */
2901 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2903 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2904 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2907 = dwarf2_get_symbol_read_needs (sub_expr
,
2910 gdbarch_byte_order (arch
),
2911 baton
.per_cu
->addr_size (),
2912 baton
.per_cu
->ref_addr_size (),
2918 case DW_OP_GNU_variable_value
:
2920 sect_offset sect_off
2921 = (sect_offset
) extract_unsigned_integer (op_ptr
,
2924 op_ptr
+= ref_addr_size
;
2926 struct type
*die_type
2927 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
,
2930 if (die_type
== NULL
)
2931 error (_("Bad DW_OP_GNU_variable_value DIE."));
2933 /* Note: Things still work when the following test is
2934 removed. This test and error is here to conform to the
2935 proposed specification. */
2936 if (die_type
->code () != TYPE_CODE_INT
2937 && die_type
->code () != TYPE_CODE_PTR
)
2938 error (_("Type of DW_OP_GNU_variable_value DIE must be "
2939 "an integer or pointer."));
2941 auto get_frame_pc
= [&symbol_needs
] ()
2943 symbol_needs
= SYMBOL_NEEDS_FRAME
;
2947 struct dwarf2_locexpr_baton baton
2948 = dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
,
2950 get_frame_pc
, true);
2952 /* If SYMBOL_NEEDS_FRAME is returned from the previous call,
2953 we dont have to check the baton content. */
2954 if (symbol_needs
!= SYMBOL_NEEDS_FRAME
)
2956 gdbarch
*arch
= baton
.per_objfile
->objfile
->arch ();
2957 gdb::array_view
<const gdb_byte
> sub_expr (baton
.data
,
2960 = dwarf2_get_symbol_read_needs (sub_expr
,
2963 gdbarch_byte_order (arch
),
2964 baton
.per_cu
->addr_size (),
2965 baton
.per_cu
->ref_addr_size (),
2971 case DW_OP_const_type
:
2972 case DW_OP_GNU_const_type
:
2975 op_ptr
= safe_read_uleb128 (op_ptr
, expr_end
, &uoffset
);
2976 gdb_byte offset
= *op_ptr
++;
2982 error (_("Unhandled DWARF expression opcode 0x%x"), op
);
2985 /* If it is known that a frame information is
2986 needed we can stop parsing the expression. */
2987 if (symbol_needs
== SYMBOL_NEEDS_FRAME
)
2990 insert_in_ops_to_visit (op_ptr
);
2993 return symbol_needs
;
2996 /* A helper function that throws an unimplemented error mentioning a
2997 given DWARF operator. */
2999 static void ATTRIBUTE_NORETURN
3000 unimplemented (unsigned int op
)
3002 const char *name
= get_DW_OP_name (op
);
3005 error (_("DWARF operator %s cannot be translated to an agent expression"),
3008 error (_("Unknown DWARF operator 0x%02x cannot be translated "
3009 "to an agent expression"),
3015 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
3016 can issue a complaint, which is better than having every target's
3017 implementation of dwarf2_reg_to_regnum do it. */
3020 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
3022 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
3026 complaint (_("bad DWARF register number %d"), dwarf_reg
);
3031 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
3032 Throw an error because DWARF_REG is bad. */
3035 throw_bad_regnum_error (ULONGEST dwarf_reg
)
3037 /* Still want to print -1 as "-1".
3038 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
3039 but that's overkill for now. */
3040 if ((int) dwarf_reg
== dwarf_reg
)
3041 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
3042 error (_("Unable to access DWARF register number %s"),
3043 pulongest (dwarf_reg
));
3046 /* See dwarf2loc.h. */
3049 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
3053 if (dwarf_reg
> INT_MAX
)
3054 throw_bad_regnum_error (dwarf_reg
);
3055 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
3056 bad, but that's ok. */
3057 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
3059 throw_bad_regnum_error (dwarf_reg
);
3063 /* A helper function that emits an access to memory. ARCH is the
3064 target architecture. EXPR is the expression which we are building.
3065 NBITS is the number of bits we want to read. This emits the
3066 opcodes needed to read the memory and then extract the desired
3070 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
3072 ULONGEST nbytes
= (nbits
+ 7) / 8;
3074 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
3077 ax_trace_quick (expr
, nbytes
);
3080 ax_simple (expr
, aop_ref8
);
3081 else if (nbits
<= 16)
3082 ax_simple (expr
, aop_ref16
);
3083 else if (nbits
<= 32)
3084 ax_simple (expr
, aop_ref32
);
3086 ax_simple (expr
, aop_ref64
);
3088 /* If we read exactly the number of bytes we wanted, we're done. */
3089 if (8 * nbytes
== nbits
)
3092 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
3094 /* On a bits-big-endian machine, we want the high-order
3096 ax_const_l (expr
, 8 * nbytes
- nbits
);
3097 ax_simple (expr
, aop_rsh_unsigned
);
3101 /* On a bits-little-endian box, we want the low-order NBITS. */
3102 ax_zero_ext (expr
, nbits
);
3106 /* Compile a DWARF location expression to an agent expression.
3108 EXPR is the agent expression we are building.
3109 LOC is the agent value we modify.
3110 ARCH is the architecture.
3111 ADDR_SIZE is the size of addresses, in bytes.
3112 OP_PTR is the start of the location expression.
3113 OP_END is one past the last byte of the location expression.
3115 This will throw an exception for various kinds of errors -- for
3116 example, if the expression cannot be compiled, or if the expression
3120 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3121 unsigned int addr_size
, const gdb_byte
*op_ptr
,
3122 const gdb_byte
*op_end
,
3123 dwarf2_per_cu_data
*per_cu
,
3124 dwarf2_per_objfile
*per_objfile
)
3126 gdbarch
*arch
= expr
->gdbarch
;
3127 std::vector
<int> dw_labels
, patches
;
3128 const gdb_byte
* const base
= op_ptr
;
3129 const gdb_byte
*previous_piece
= op_ptr
;
3130 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3131 ULONGEST bits_collected
= 0;
3132 unsigned int addr_size_bits
= 8 * addr_size
;
3133 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
3135 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3137 /* By default we are making an address. */
3138 loc
->kind
= axs_lvalue_memory
;
3140 while (op_ptr
< op_end
)
3142 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3143 uint64_t uoffset
, reg
;
3147 offsets
[op_ptr
- base
] = expr
->len
;
3150 /* Our basic approach to code generation is to map DWARF
3151 operations directly to AX operations. However, there are
3154 First, DWARF works on address-sized units, but AX always uses
3155 LONGEST. For most operations we simply ignore this
3156 difference; instead we generate sign extensions as needed
3157 before division and comparison operations. It would be nice
3158 to omit the sign extensions, but there is no way to determine
3159 the size of the target's LONGEST. (This code uses the size
3160 of the host LONGEST in some cases -- that is a bug but it is
3163 Second, some DWARF operations cannot be translated to AX.
3164 For these we simply fail. See
3165 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3200 ax_const_l (expr
, op
- DW_OP_lit0
);
3204 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3205 op_ptr
+= addr_size
;
3206 /* Some versions of GCC emit DW_OP_addr before
3207 DW_OP_GNU_push_tls_address. In this case the value is an
3208 index, not an address. We don't support things like
3209 branching between the address and the TLS op. */
3210 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3211 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3212 ax_const_l (expr
, uoffset
);
3216 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3221 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3226 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3231 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3236 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3241 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3246 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3251 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3256 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3257 ax_const_l (expr
, uoffset
);
3261 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3262 ax_const_l (expr
, offset
);
3297 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3298 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3299 loc
->kind
= axs_lvalue_register
;
3303 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3304 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3305 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3306 loc
->kind
= axs_lvalue_register
;
3309 case DW_OP_implicit_value
:
3313 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3314 if (op_ptr
+ len
> op_end
)
3315 error (_("DW_OP_implicit_value: too few bytes available."));
3316 if (len
> sizeof (ULONGEST
))
3317 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3320 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3323 dwarf_expr_require_composition (op_ptr
, op_end
,
3324 "DW_OP_implicit_value");
3326 loc
->kind
= axs_rvalue
;
3330 case DW_OP_stack_value
:
3331 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3332 loc
->kind
= axs_rvalue
;
3367 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3368 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3372 ax_const_l (expr
, offset
);
3373 ax_simple (expr
, aop_add
);
3379 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3380 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3381 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3385 ax_const_l (expr
, offset
);
3386 ax_simple (expr
, aop_add
);
3393 const gdb_byte
*datastart
;
3395 const struct block
*b
;
3396 struct symbol
*framefunc
;
3398 b
= block_for_pc (expr
->scope
);
3401 error (_("No block found for address"));
3403 framefunc
= block_linkage_function (b
);
3406 error (_("No function found for block"));
3408 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3409 &datastart
, &datalen
);
3411 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3412 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3413 datastart
+ datalen
, per_cu
,
3415 if (loc
->kind
== axs_lvalue_register
)
3416 require_rvalue (expr
, loc
);
3420 ax_const_l (expr
, offset
);
3421 ax_simple (expr
, aop_add
);
3424 loc
->kind
= axs_lvalue_memory
;
3429 ax_simple (expr
, aop_dup
);
3433 ax_simple (expr
, aop_pop
);
3438 ax_pick (expr
, offset
);
3442 ax_simple (expr
, aop_swap
);
3450 ax_simple (expr
, aop_rot
);
3454 case DW_OP_deref_size
:
3458 if (op
== DW_OP_deref_size
)
3463 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3464 error (_("Unsupported size %d in %s"),
3465 size
, get_DW_OP_name (op
));
3466 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3471 /* Sign extend the operand. */
3472 ax_ext (expr
, addr_size_bits
);
3473 ax_simple (expr
, aop_dup
);
3474 ax_const_l (expr
, 0);
3475 ax_simple (expr
, aop_less_signed
);
3476 ax_simple (expr
, aop_log_not
);
3477 i
= ax_goto (expr
, aop_if_goto
);
3478 /* We have to emit 0 - X. */
3479 ax_const_l (expr
, 0);
3480 ax_simple (expr
, aop_swap
);
3481 ax_simple (expr
, aop_sub
);
3482 ax_label (expr
, i
, expr
->len
);
3486 /* No need to sign extend here. */
3487 ax_const_l (expr
, 0);
3488 ax_simple (expr
, aop_swap
);
3489 ax_simple (expr
, aop_sub
);
3493 /* Sign extend the operand. */
3494 ax_ext (expr
, addr_size_bits
);
3495 ax_simple (expr
, aop_bit_not
);
3498 case DW_OP_plus_uconst
:
3499 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3500 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3501 but we micro-optimize anyhow. */
3504 ax_const_l (expr
, reg
);
3505 ax_simple (expr
, aop_add
);
3510 ax_simple (expr
, aop_bit_and
);
3514 /* Sign extend the operands. */
3515 ax_ext (expr
, addr_size_bits
);
3516 ax_simple (expr
, aop_swap
);
3517 ax_ext (expr
, addr_size_bits
);
3518 ax_simple (expr
, aop_swap
);
3519 ax_simple (expr
, aop_div_signed
);
3523 ax_simple (expr
, aop_sub
);
3527 ax_simple (expr
, aop_rem_unsigned
);
3531 ax_simple (expr
, aop_mul
);
3535 ax_simple (expr
, aop_bit_or
);
3539 ax_simple (expr
, aop_add
);
3543 ax_simple (expr
, aop_lsh
);
3547 ax_simple (expr
, aop_rsh_unsigned
);
3551 ax_simple (expr
, aop_rsh_signed
);
3555 ax_simple (expr
, aop_bit_xor
);
3559 /* Sign extend the operands. */
3560 ax_ext (expr
, addr_size_bits
);
3561 ax_simple (expr
, aop_swap
);
3562 ax_ext (expr
, addr_size_bits
);
3563 /* Note no swap here: A <= B is !(B < A). */
3564 ax_simple (expr
, aop_less_signed
);
3565 ax_simple (expr
, aop_log_not
);
3569 /* Sign extend the operands. */
3570 ax_ext (expr
, addr_size_bits
);
3571 ax_simple (expr
, aop_swap
);
3572 ax_ext (expr
, addr_size_bits
);
3573 ax_simple (expr
, aop_swap
);
3574 /* A >= B is !(A < B). */
3575 ax_simple (expr
, aop_less_signed
);
3576 ax_simple (expr
, aop_log_not
);
3580 /* Sign extend the operands. */
3581 ax_ext (expr
, addr_size_bits
);
3582 ax_simple (expr
, aop_swap
);
3583 ax_ext (expr
, addr_size_bits
);
3584 /* No need for a second swap here. */
3585 ax_simple (expr
, aop_equal
);
3589 /* Sign extend the operands. */
3590 ax_ext (expr
, addr_size_bits
);
3591 ax_simple (expr
, aop_swap
);
3592 ax_ext (expr
, addr_size_bits
);
3593 ax_simple (expr
, aop_swap
);
3594 ax_simple (expr
, aop_less_signed
);
3598 /* Sign extend the operands. */
3599 ax_ext (expr
, addr_size_bits
);
3600 ax_simple (expr
, aop_swap
);
3601 ax_ext (expr
, addr_size_bits
);
3602 /* Note no swap here: A > B is B < A. */
3603 ax_simple (expr
, aop_less_signed
);
3607 /* Sign extend the operands. */
3608 ax_ext (expr
, addr_size_bits
);
3609 ax_simple (expr
, aop_swap
);
3610 ax_ext (expr
, addr_size_bits
);
3611 /* No need for a swap here. */
3612 ax_simple (expr
, aop_equal
);
3613 ax_simple (expr
, aop_log_not
);
3616 case DW_OP_call_frame_cfa
:
3619 CORE_ADDR text_offset
;
3621 const gdb_byte
*cfa_start
, *cfa_end
;
3623 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3625 &text_offset
, &cfa_start
, &cfa_end
))
3628 ax_reg (expr
, regnum
);
3631 ax_const_l (expr
, off
);
3632 ax_simple (expr
, aop_add
);
3637 /* Another expression. */
3638 ax_const_l (expr
, text_offset
);
3639 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3640 cfa_end
, per_cu
, per_objfile
);
3643 loc
->kind
= axs_lvalue_memory
;
3647 case DW_OP_GNU_push_tls_address
:
3648 case DW_OP_form_tls_address
:
3652 case DW_OP_push_object_address
:
3657 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3659 i
= ax_goto (expr
, aop_goto
);
3660 dw_labels
.push_back (op_ptr
+ offset
- base
);
3661 patches
.push_back (i
);
3665 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3667 /* Zero extend the operand. */
3668 ax_zero_ext (expr
, addr_size_bits
);
3669 i
= ax_goto (expr
, aop_if_goto
);
3670 dw_labels
.push_back (op_ptr
+ offset
- base
);
3671 patches
.push_back (i
);
3678 case DW_OP_bit_piece
:
3682 if (op_ptr
- 1 == previous_piece
)
3683 error (_("Cannot translate empty pieces to agent expressions"));
3684 previous_piece
= op_ptr
- 1;
3686 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3687 if (op
== DW_OP_piece
)
3693 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3695 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3696 error (_("Expression pieces exceed word size"));
3698 /* Access the bits. */
3701 case axs_lvalue_register
:
3702 ax_reg (expr
, loc
->u
.reg
);
3705 case axs_lvalue_memory
:
3706 /* Offset the pointer, if needed. */
3709 ax_const_l (expr
, uoffset
/ 8);
3710 ax_simple (expr
, aop_add
);
3713 access_memory (arch
, expr
, size
);
3717 /* For a bits-big-endian target, shift up what we already
3718 have. For a bits-little-endian target, shift up the
3719 new data. Note that there is a potential bug here if
3720 the DWARF expression leaves multiple values on the
3722 if (bits_collected
> 0)
3724 if (bits_big_endian
)
3726 ax_simple (expr
, aop_swap
);
3727 ax_const_l (expr
, size
);
3728 ax_simple (expr
, aop_lsh
);
3729 /* We don't need a second swap here, because
3730 aop_bit_or is symmetric. */
3734 ax_const_l (expr
, size
);
3735 ax_simple (expr
, aop_lsh
);
3737 ax_simple (expr
, aop_bit_or
);
3740 bits_collected
+= size
;
3741 loc
->kind
= axs_rvalue
;
3745 case DW_OP_GNU_uninit
:
3751 struct dwarf2_locexpr_baton block
;
3752 int size
= (op
== DW_OP_call2
? 2 : 4);
3754 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3757 auto get_frame_pc_from_expr
= [expr
] ()
3761 cu_offset cuoffset
= (cu_offset
) uoffset
;
3762 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3763 get_frame_pc_from_expr
);
3765 /* DW_OP_call_ref is currently not supported. */
3766 gdb_assert (block
.per_cu
== per_cu
);
3768 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3769 block
.data
+ block
.size
, per_cu
,
3774 case DW_OP_call_ref
:
3777 case DW_OP_GNU_variable_value
:
3785 /* Patch all the branches we emitted. */
3786 for (int i
= 0; i
< patches
.size (); ++i
)
3788 int targ
= offsets
[dw_labels
[i
]];
3790 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3791 ax_label (expr
, patches
[i
], targ
);
3796 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3797 evaluator to calculate the location. */
3798 static struct value
*
3799 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3801 struct dwarf2_locexpr_baton
*dlbaton
3802 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3805 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3806 dlbaton
->size
, dlbaton
->per_cu
,
3807 dlbaton
->per_objfile
);
3812 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3813 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3816 static struct value
*
3817 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3819 struct dwarf2_locexpr_baton
*dlbaton
3820 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3822 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3826 /* Implementation of get_symbol_read_needs from
3827 symbol_computed_ops. */
3829 static enum symbol_needs_kind
3830 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3832 struct dwarf2_locexpr_baton
*dlbaton
3833 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3835 gdbarch
*arch
= dlbaton
->per_objfile
->objfile
->arch ();
3836 gdb::array_view
<const gdb_byte
> expr (dlbaton
->data
, dlbaton
->size
);
3838 return dwarf2_get_symbol_read_needs (expr
,
3840 dlbaton
->per_objfile
,
3841 gdbarch_byte_order (arch
),
3842 dlbaton
->per_cu
->addr_size (),
3843 dlbaton
->per_cu
->ref_addr_size ());
3846 /* Return true if DATA points to the end of a piece. END is one past
3847 the last byte in the expression. */
3850 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3852 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3855 /* Helper for locexpr_describe_location_piece that finds the name of a
3859 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3863 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3864 We'd rather print *something* here than throw an error. */
3865 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3866 /* gdbarch_register_name may just return "", return something more
3867 descriptive for bad register numbers. */
3870 /* The text is output as "$bad_register_number".
3871 That is why we use the underscores. */
3872 return _("bad_register_number");
3874 return gdbarch_register_name (gdbarch
, regnum
);
3877 /* Nicely describe a single piece of a location, returning an updated
3878 position in the bytecode sequence. This function cannot recognize
3879 all locations; if a location is not recognized, it simply returns
3880 DATA. If there is an error during reading, e.g. we run off the end
3881 of the buffer, an error is thrown. */
3883 static const gdb_byte
*
3884 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3885 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3886 dwarf2_per_objfile
*per_objfile
,
3887 const gdb_byte
*data
, const gdb_byte
*end
,
3888 unsigned int addr_size
)
3890 objfile
*objfile
= per_objfile
->objfile
;
3891 struct gdbarch
*gdbarch
= objfile
->arch ();
3894 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3896 fprintf_filtered (stream
, _("a variable in $%s"),
3897 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3900 else if (data
[0] == DW_OP_regx
)
3904 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3905 fprintf_filtered (stream
, _("a variable in $%s"),
3906 locexpr_regname (gdbarch
, reg
));
3908 else if (data
[0] == DW_OP_fbreg
)
3910 const struct block
*b
;
3911 struct symbol
*framefunc
;
3913 int64_t frame_offset
;
3914 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3916 int64_t base_offset
= 0;
3918 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3919 if (!piece_end_p (new_data
, end
))
3923 b
= block_for_pc (addr
);
3926 error (_("No block found for address for symbol \"%s\"."),
3927 symbol
->print_name ());
3929 framefunc
= block_linkage_function (b
);
3932 error (_("No function found for block for symbol \"%s\"."),
3933 symbol
->print_name ());
3935 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3937 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3939 const gdb_byte
*buf_end
;
3941 frame_reg
= base_data
[0] - DW_OP_breg0
;
3942 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3944 if (buf_end
!= base_data
+ base_size
)
3945 error (_("Unexpected opcode after "
3946 "DW_OP_breg%u for symbol \"%s\"."),
3947 frame_reg
, symbol
->print_name ());
3949 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3951 /* The frame base is just the register, with no offset. */
3952 frame_reg
= base_data
[0] - DW_OP_reg0
;
3957 /* We don't know what to do with the frame base expression,
3958 so we can't trace this variable; give up. */
3962 fprintf_filtered (stream
,
3963 _("a variable at frame base reg $%s offset %s+%s"),
3964 locexpr_regname (gdbarch
, frame_reg
),
3965 plongest (base_offset
), plongest (frame_offset
));
3967 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3968 && piece_end_p (data
, end
))
3972 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3974 fprintf_filtered (stream
,
3975 _("a variable at offset %s from base reg $%s"),
3977 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3980 /* The location expression for a TLS variable looks like this (on a
3983 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3984 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3986 0x3 is the encoding for DW_OP_addr, which has an operand as long
3987 as the size of an address on the target machine (here is 8
3988 bytes). Note that more recent version of GCC emit DW_OP_const4u
3989 or DW_OP_const8u, depending on address size, rather than
3990 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3991 The operand represents the offset at which the variable is within
3992 the thread local storage. */
3994 else if (data
+ 1 + addr_size
< end
3995 && (data
[0] == DW_OP_addr
3996 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3997 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3998 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3999 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
4000 && piece_end_p (data
+ 2 + addr_size
, end
))
4003 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
4004 gdbarch_byte_order (gdbarch
));
4006 fprintf_filtered (stream
,
4007 _("a thread-local variable at offset 0x%s "
4008 "in the thread-local storage for `%s'"),
4009 phex_nz (offset
, addr_size
), objfile_name (objfile
));
4011 data
+= 1 + addr_size
+ 1;
4014 /* With -gsplit-dwarf a TLS variable can also look like this:
4015 DW_AT_location : 3 byte block: fc 4 e0
4016 (DW_OP_GNU_const_index: 4;
4017 DW_OP_GNU_push_tls_address) */
4018 else if (data
+ 3 <= end
4019 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
4020 && data
[0] == DW_OP_GNU_const_index
4022 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
4023 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
4024 && piece_end_p (data
+ 2 + leb128_size
, end
))
4028 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
4029 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
4030 fprintf_filtered (stream
,
4031 _("a thread-local variable at offset 0x%s "
4032 "in the thread-local storage for `%s'"),
4033 phex_nz (offset
, addr_size
), objfile_name (objfile
));
4037 else if (data
[0] >= DW_OP_lit0
4038 && data
[0] <= DW_OP_lit31
4040 && data
[1] == DW_OP_stack_value
)
4042 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
4049 /* Disassemble an expression, stopping at the end of a piece or at the
4050 end of the expression. Returns a pointer to the next unread byte
4051 in the input expression. If ALL is nonzero, then this function
4052 will keep going until it reaches the end of the expression.
4053 If there is an error during reading, e.g. we run off the end
4054 of the buffer, an error is thrown. */
4056 static const gdb_byte
*
4057 disassemble_dwarf_expression (struct ui_file
*stream
,
4058 struct gdbarch
*arch
, unsigned int addr_size
,
4059 int offset_size
, const gdb_byte
*start
,
4060 const gdb_byte
*data
, const gdb_byte
*end
,
4061 int indent
, int all
,
4062 dwarf2_per_cu_data
*per_cu
,
4063 dwarf2_per_objfile
*per_objfile
)
4067 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
4069 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
4074 name
= get_DW_OP_name (op
);
4077 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
4078 op
, (long) (data
- 1 - start
));
4079 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
4080 (long) (data
- 1 - start
), name
);
4085 ul
= extract_unsigned_integer (data
, addr_size
,
4086 gdbarch_byte_order (arch
));
4088 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4092 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
4094 fprintf_filtered (stream
, " %s", pulongest (ul
));
4098 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
4100 fprintf_filtered (stream
, " %s", plongest (l
));
4104 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4106 fprintf_filtered (stream
, " %s", pulongest (ul
));
4110 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4112 fprintf_filtered (stream
, " %s", plongest (l
));
4116 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4118 fprintf_filtered (stream
, " %s", pulongest (ul
));
4122 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4124 fprintf_filtered (stream
, " %s", plongest (l
));
4128 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4130 fprintf_filtered (stream
, " %s", pulongest (ul
));
4134 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4136 fprintf_filtered (stream
, " %s", plongest (l
));
4140 data
= safe_read_uleb128 (data
, end
, &ul
);
4141 fprintf_filtered (stream
, " %s", pulongest (ul
));
4145 data
= safe_read_sleb128 (data
, end
, &l
);
4146 fprintf_filtered (stream
, " %s", plongest (l
));
4181 fprintf_filtered (stream
, " [$%s]",
4182 locexpr_regname (arch
, op
- DW_OP_reg0
));
4186 data
= safe_read_uleb128 (data
, end
, &ul
);
4187 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4188 locexpr_regname (arch
, (int) ul
));
4191 case DW_OP_implicit_value
:
4192 data
= safe_read_uleb128 (data
, end
, &ul
);
4194 fprintf_filtered (stream
, " %s", pulongest (ul
));
4229 data
= safe_read_sleb128 (data
, end
, &l
);
4230 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4231 locexpr_regname (arch
, op
- DW_OP_breg0
));
4235 data
= safe_read_uleb128 (data
, end
, &ul
);
4236 data
= safe_read_sleb128 (data
, end
, &l
);
4237 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4239 locexpr_regname (arch
, (int) ul
),
4244 data
= safe_read_sleb128 (data
, end
, &l
);
4245 fprintf_filtered (stream
, " %s", plongest (l
));
4248 case DW_OP_xderef_size
:
4249 case DW_OP_deref_size
:
4251 fprintf_filtered (stream
, " %d", *data
);
4255 case DW_OP_plus_uconst
:
4256 data
= safe_read_uleb128 (data
, end
, &ul
);
4257 fprintf_filtered (stream
, " %s", pulongest (ul
));
4261 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4263 fprintf_filtered (stream
, " to %ld",
4264 (long) (data
+ l
- start
));
4268 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4270 fprintf_filtered (stream
, " %ld",
4271 (long) (data
+ l
- start
));
4275 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4277 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4281 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4283 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4286 case DW_OP_call_ref
:
4287 ul
= extract_unsigned_integer (data
, offset_size
,
4288 gdbarch_byte_order (arch
));
4289 data
+= offset_size
;
4290 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4294 data
= safe_read_uleb128 (data
, end
, &ul
);
4295 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4298 case DW_OP_bit_piece
:
4302 data
= safe_read_uleb128 (data
, end
, &ul
);
4303 data
= safe_read_uleb128 (data
, end
, &offset
);
4304 fprintf_filtered (stream
, " size %s offset %s (bits)",
4305 pulongest (ul
), pulongest (offset
));
4309 case DW_OP_implicit_pointer
:
4310 case DW_OP_GNU_implicit_pointer
:
4312 ul
= extract_unsigned_integer (data
, offset_size
,
4313 gdbarch_byte_order (arch
));
4314 data
+= offset_size
;
4316 data
= safe_read_sleb128 (data
, end
, &l
);
4318 fprintf_filtered (stream
, " DIE %s offset %s",
4319 phex_nz (ul
, offset_size
),
4324 case DW_OP_deref_type
:
4325 case DW_OP_GNU_deref_type
:
4327 int deref_addr_size
= *data
++;
4330 data
= safe_read_uleb128 (data
, end
, &ul
);
4331 cu_offset offset
= (cu_offset
) ul
;
4332 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
4333 fprintf_filtered (stream
, "<");
4334 type_print (type
, "", stream
, -1);
4335 fprintf_filtered (stream
, " [0x%s]> %d",
4336 phex_nz (to_underlying (offset
), 0),
4341 case DW_OP_const_type
:
4342 case DW_OP_GNU_const_type
:
4346 data
= safe_read_uleb128 (data
, end
, &ul
);
4347 cu_offset type_die
= (cu_offset
) ul
;
4348 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4349 fprintf_filtered (stream
, "<");
4350 type_print (type
, "", stream
, -1);
4351 fprintf_filtered (stream
, " [0x%s]>",
4352 phex_nz (to_underlying (type_die
), 0));
4355 fprintf_filtered (stream
, " %d byte block:", n
);
4356 for (int i
= 0; i
< n
; ++i
)
4357 fprintf_filtered (stream
, " %02x", data
[i
]);
4362 case DW_OP_regval_type
:
4363 case DW_OP_GNU_regval_type
:
4368 data
= safe_read_uleb128 (data
, end
, ®
);
4369 data
= safe_read_uleb128 (data
, end
, &ul
);
4370 cu_offset type_die
= (cu_offset
) ul
;
4372 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4373 fprintf_filtered (stream
, "<");
4374 type_print (type
, "", stream
, -1);
4375 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4376 phex_nz (to_underlying (type_die
), 0),
4377 locexpr_regname (arch
, reg
));
4382 case DW_OP_GNU_convert
:
4383 case DW_OP_reinterpret
:
4384 case DW_OP_GNU_reinterpret
:
4386 data
= safe_read_uleb128 (data
, end
, &ul
);
4387 cu_offset type_die
= (cu_offset
) ul
;
4389 if (to_underlying (type_die
) == 0)
4390 fprintf_filtered (stream
, "<0>");
4395 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4396 fprintf_filtered (stream
, "<");
4397 type_print (type
, "", stream
, -1);
4398 fprintf_filtered (stream
, " [0x%s]>",
4399 phex_nz (to_underlying (type_die
), 0));
4404 case DW_OP_entry_value
:
4405 case DW_OP_GNU_entry_value
:
4406 data
= safe_read_uleb128 (data
, end
, &ul
);
4407 fputc_filtered ('\n', stream
);
4408 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4409 start
, data
, data
+ ul
, indent
+ 2,
4410 all
, per_cu
, per_objfile
);
4414 case DW_OP_GNU_parameter_ref
:
4415 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4417 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4421 case DW_OP_GNU_addr_index
:
4422 data
= safe_read_uleb128 (data
, end
, &ul
);
4423 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4424 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4427 case DW_OP_GNU_const_index
:
4428 data
= safe_read_uleb128 (data
, end
, &ul
);
4429 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4430 fprintf_filtered (stream
, " %s", pulongest (ul
));
4433 case DW_OP_GNU_variable_value
:
4434 ul
= extract_unsigned_integer (data
, offset_size
,
4435 gdbarch_byte_order (arch
));
4436 data
+= offset_size
;
4437 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4441 fprintf_filtered (stream
, "\n");
4447 static bool dwarf_always_disassemble
;
4450 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4451 struct cmd_list_element
*c
, const char *value
)
4453 fprintf_filtered (file
,
4454 _("Whether to always disassemble "
4455 "DWARF expressions is %s.\n"),
4459 /* Describe a single location, which may in turn consist of multiple
4463 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4464 struct ui_file
*stream
,
4465 const gdb_byte
*data
, size_t size
,
4466 unsigned int addr_size
,
4467 int offset_size
, dwarf2_per_cu_data
*per_cu
,
4468 dwarf2_per_objfile
*per_objfile
)
4470 const gdb_byte
*end
= data
+ size
;
4471 int first_piece
= 1, bad
= 0;
4472 objfile
*objfile
= per_objfile
->objfile
;
4476 const gdb_byte
*here
= data
;
4477 int disassemble
= 1;
4482 fprintf_filtered (stream
, _(", and "));
4484 if (!dwarf_always_disassemble
)
4486 data
= locexpr_describe_location_piece (symbol
, stream
,
4487 addr
, per_cu
, per_objfile
,
4488 data
, end
, addr_size
);
4489 /* If we printed anything, or if we have an empty piece,
4490 then don't disassemble. */
4492 || data
[0] == DW_OP_piece
4493 || data
[0] == DW_OP_bit_piece
)
4498 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4499 data
= disassemble_dwarf_expression (stream
,
4501 addr_size
, offset_size
, data
,
4503 dwarf_always_disassemble
,
4504 per_cu
, per_objfile
);
4509 int empty
= data
== here
;
4512 fprintf_filtered (stream
, " ");
4513 if (data
[0] == DW_OP_piece
)
4517 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4520 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4523 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4526 else if (data
[0] == DW_OP_bit_piece
)
4528 uint64_t bits
, offset
;
4530 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4531 data
= safe_read_uleb128 (data
, end
, &offset
);
4534 fprintf_filtered (stream
,
4535 _("an empty %s-bit piece"),
4538 fprintf_filtered (stream
,
4539 _(" [%s-bit piece, offset %s bits]"),
4540 pulongest (bits
), pulongest (offset
));
4550 if (bad
|| data
> end
)
4551 error (_("Corrupted DWARF2 expression for \"%s\"."),
4552 symbol
->print_name ());
4555 /* Print a natural-language description of SYMBOL to STREAM. This
4556 version is for a symbol with a single location. */
4559 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4560 struct ui_file
*stream
)
4562 struct dwarf2_locexpr_baton
*dlbaton
4563 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4564 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4565 int offset_size
= dlbaton
->per_cu
->offset_size ();
4567 locexpr_describe_location_1 (symbol
, addr
, stream
,
4568 dlbaton
->data
, dlbaton
->size
,
4569 addr_size
, offset_size
,
4570 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4573 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4574 any necessary bytecode in AX. */
4577 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4578 struct axs_value
*value
)
4580 struct dwarf2_locexpr_baton
*dlbaton
4581 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4582 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4584 if (dlbaton
->size
== 0)
4585 value
->optimized_out
= 1;
4587 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4588 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4589 dlbaton
->per_objfile
);
4592 /* symbol_computed_ops 'generate_c_location' method. */
4595 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4596 struct gdbarch
*gdbarch
,
4597 std::vector
<bool> ®isters_used
,
4598 CORE_ADDR pc
, const char *result_name
)
4600 struct dwarf2_locexpr_baton
*dlbaton
4601 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4602 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4604 if (dlbaton
->size
== 0)
4605 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4607 compile_dwarf_expr_to_c (stream
, result_name
,
4608 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4609 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4610 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4613 /* The set of location functions used with the DWARF-2 expression
4615 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4616 locexpr_read_variable
,
4617 locexpr_read_variable_at_entry
,
4618 locexpr_get_symbol_read_needs
,
4619 locexpr_describe_location
,
4620 0, /* location_has_loclist */
4621 locexpr_tracepoint_var_ref
,
4622 locexpr_generate_c_location
4626 /* Wrapper functions for location lists. These generally find
4627 the appropriate location expression and call something above. */
4629 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4630 evaluator to calculate the location. */
4631 static struct value
*
4632 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4634 struct dwarf2_loclist_baton
*dlbaton
4635 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4637 const gdb_byte
*data
;
4639 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4641 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4642 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4643 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4648 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4649 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4652 Function always returns non-NULL value, it may be marked optimized out if
4653 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4654 if it cannot resolve the parameter for any reason. */
4656 static struct value
*
4657 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4659 struct dwarf2_loclist_baton
*dlbaton
4660 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4661 const gdb_byte
*data
;
4665 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4666 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4668 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4670 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4672 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4675 /* Implementation of get_symbol_read_needs from
4676 symbol_computed_ops. */
4678 static enum symbol_needs_kind
4679 loclist_symbol_needs (struct symbol
*symbol
)
4681 /* If there's a location list, then assume we need to have a frame
4682 to choose the appropriate location expression. With tracking of
4683 global variables this is not necessarily true, but such tracking
4684 is disabled in GCC at the moment until we figure out how to
4687 return SYMBOL_NEEDS_FRAME
;
4690 /* Print a natural-language description of SYMBOL to STREAM. This
4691 version applies when there is a list of different locations, each
4692 with a specified address range. */
4695 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4696 struct ui_file
*stream
)
4698 struct dwarf2_loclist_baton
*dlbaton
4699 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4700 const gdb_byte
*loc_ptr
, *buf_end
;
4701 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4702 struct objfile
*objfile
= per_objfile
->objfile
;
4703 struct gdbarch
*gdbarch
= objfile
->arch ();
4704 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4705 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4706 int offset_size
= dlbaton
->per_cu
->offset_size ();
4707 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4708 /* Adjust base_address for relocatable objects. */
4709 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4710 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4713 loc_ptr
= dlbaton
->data
;
4714 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4716 fprintf_filtered (stream
, _("multi-location:\n"));
4718 /* Iterate through locations until we run out. */
4721 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4723 enum debug_loc_kind kind
;
4724 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4726 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4727 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4728 dlbaton
->per_objfile
,
4729 loc_ptr
, buf_end
, &new_ptr
,
4730 &low
, &high
, byte_order
);
4731 else if (dlbaton
->per_cu
->version () < 5)
4732 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4734 byte_order
, addr_size
,
4737 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4738 dlbaton
->per_objfile
,
4739 loc_ptr
, buf_end
, &new_ptr
,
4740 &low
, &high
, byte_order
,
4741 addr_size
, signed_addr_p
);
4745 case DEBUG_LOC_END_OF_LIST
:
4749 case DEBUG_LOC_BASE_ADDRESS
:
4750 base_address
= high
+ base_offset
;
4751 fprintf_filtered (stream
, _(" Base address %s"),
4752 paddress (gdbarch
, base_address
));
4755 case DEBUG_LOC_START_END
:
4756 case DEBUG_LOC_START_LENGTH
:
4757 case DEBUG_LOC_OFFSET_PAIR
:
4760 case DEBUG_LOC_BUFFER_OVERFLOW
:
4761 case DEBUG_LOC_INVALID_ENTRY
:
4762 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4763 symbol
->print_name ());
4766 gdb_assert_not_reached ("bad debug_loc_kind");
4769 /* Otherwise, a location expression entry. */
4770 low
+= base_address
;
4771 high
+= base_address
;
4773 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4774 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4776 if (dlbaton
->per_cu
->version () < 5)
4778 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4783 unsigned int bytes_read
;
4784 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4785 loc_ptr
+= bytes_read
;
4788 /* (It would improve readability to print only the minimum
4789 necessary digits of the second number of the range.) */
4790 fprintf_filtered (stream
, _(" Range %s-%s: "),
4791 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4793 /* Now describe this particular location. */
4794 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4795 addr_size
, offset_size
,
4796 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4798 fprintf_filtered (stream
, "\n");
4804 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4805 any necessary bytecode in AX. */
4807 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4808 struct axs_value
*value
)
4810 struct dwarf2_loclist_baton
*dlbaton
4811 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4812 const gdb_byte
*data
;
4814 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4816 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4818 value
->optimized_out
= 1;
4820 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4821 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4824 /* symbol_computed_ops 'generate_c_location' method. */
4827 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4828 struct gdbarch
*gdbarch
,
4829 std::vector
<bool> ®isters_used
,
4830 CORE_ADDR pc
, const char *result_name
)
4832 struct dwarf2_loclist_baton
*dlbaton
4833 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4834 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4835 const gdb_byte
*data
;
4838 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4840 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4842 compile_dwarf_expr_to_c (stream
, result_name
,
4843 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4846 dlbaton
->per_objfile
);
4849 /* The set of location functions used with the DWARF-2 expression
4850 evaluator and location lists. */
4851 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4852 loclist_read_variable
,
4853 loclist_read_variable_at_entry
,
4854 loclist_symbol_needs
,
4855 loclist_describe_location
,
4856 1, /* location_has_loclist */
4857 loclist_tracepoint_var_ref
,
4858 loclist_generate_c_location
4861 void _initialize_dwarf2loc ();
4863 _initialize_dwarf2loc ()
4865 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4866 &entry_values_debug
,
4867 _("Set entry values and tail call frames "
4869 _("Show entry values and tail call frames "
4871 _("When non-zero, the process of determining "
4872 "parameter values from function entry point "
4873 "and tail call frames will be printed."),
4875 show_entry_values_debug
,
4876 &setdebuglist
, &showdebuglist
);
4878 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4879 &dwarf_always_disassemble
, _("\
4880 Set whether `info address' always disassembles DWARF expressions."), _("\
4881 Show whether `info address' always disassembles DWARF expressions."), _("\
4882 When enabled, DWARF expressions are always printed in an assembly-like\n\
4883 syntax. When disabled, expressions will be printed in a more\n\
4884 conversational style, when possible."),
4886 show_dwarf_always_disassemble
,
4888 &show_dwarf_cmdlist
);