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 call_site_parameter
*dwarf_expr_reg_to_entry_parameter
56 (struct frame_info
*frame
,
57 enum call_site_parameter_kind kind
,
58 union call_site_parameter_u kind_u
,
59 dwarf2_per_cu_data
**per_cu_return
,
60 dwarf2_per_objfile
**per_objfile_return
);
62 static struct value
*indirect_synthetic_pointer
63 (sect_offset die
, LONGEST byte_offset
,
64 dwarf2_per_cu_data
*per_cu
,
65 dwarf2_per_objfile
*per_objfile
,
66 struct frame_info
*frame
,
67 struct type
*type
, bool resolve_abstract_p
= false);
69 /* Until these have formal names, we define these here.
70 ref: http://gcc.gnu.org/wiki/DebugFission
71 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
72 and is then followed by data specific to that entry. */
76 /* Indicates the end of the list of entries. */
77 DEBUG_LOC_END_OF_LIST
= 0,
79 /* This is followed by an unsigned LEB128 number that is an index into
80 .debug_addr and specifies the base address for all following entries. */
81 DEBUG_LOC_BASE_ADDRESS
= 1,
83 /* This is followed by two unsigned LEB128 numbers that are indices into
84 .debug_addr and specify the beginning and ending addresses, and then
85 a normal location expression as in .debug_loc. */
86 DEBUG_LOC_START_END
= 2,
88 /* This is followed by an unsigned LEB128 number that is an index into
89 .debug_addr and specifies the beginning address, and a 4 byte unsigned
90 number that specifies the length, and then a normal location expression
92 DEBUG_LOC_START_LENGTH
= 3,
94 /* This is followed by two unsigned LEB128 operands. The values of these
95 operands are the starting and ending offsets, respectively, relative to
96 the applicable base address. */
97 DEBUG_LOC_OFFSET_PAIR
= 4,
99 /* An internal value indicating there is insufficient data. */
100 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
102 /* An internal value indicating an invalid kind of entry was found. */
103 DEBUG_LOC_INVALID_ENTRY
= -2
106 /* Helper function which throws an error if a synthetic pointer is
110 invalid_synthetic_pointer (void)
112 error (_("access outside bounds of object "
113 "referenced via synthetic pointer"));
116 /* Decode the addresses in a non-dwo .debug_loc entry.
117 A pointer to the next byte to examine is returned in *NEW_PTR.
118 The encoded low,high addresses are return in *LOW,*HIGH.
119 The result indicates the kind of entry found. */
121 static enum debug_loc_kind
122 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
123 const gdb_byte
**new_ptr
,
124 CORE_ADDR
*low
, CORE_ADDR
*high
,
125 enum bfd_endian byte_order
,
126 unsigned int addr_size
,
129 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
131 if (buf_end
- loc_ptr
< 2 * addr_size
)
132 return DEBUG_LOC_BUFFER_OVERFLOW
;
135 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
137 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
138 loc_ptr
+= addr_size
;
141 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
143 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
144 loc_ptr
+= addr_size
;
148 /* A base-address-selection entry. */
149 if ((*low
& base_mask
) == base_mask
)
150 return DEBUG_LOC_BASE_ADDRESS
;
152 /* An end-of-list entry. */
153 if (*low
== 0 && *high
== 0)
154 return DEBUG_LOC_END_OF_LIST
;
156 return DEBUG_LOC_START_END
;
159 /* Decode the addresses in .debug_loclists entry.
160 A pointer to the next byte to examine is returned in *NEW_PTR.
161 The encoded low,high addresses are return in *LOW,*HIGH.
162 The result indicates the kind of entry found. */
164 static enum debug_loc_kind
165 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
166 dwarf2_per_objfile
*per_objfile
,
167 const gdb_byte
*loc_ptr
,
168 const gdb_byte
*buf_end
,
169 const gdb_byte
**new_ptr
,
170 CORE_ADDR
*low
, CORE_ADDR
*high
,
171 enum bfd_endian byte_order
,
172 unsigned int addr_size
,
177 if (loc_ptr
== buf_end
)
178 return DEBUG_LOC_BUFFER_OVERFLOW
;
182 case DW_LLE_base_addressx
:
184 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
190 return DEBUG_LOC_BASE_ADDRESS
;
192 case DW_LLE_startx_length
:
193 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
195 return DEBUG_LOC_BUFFER_OVERFLOW
;
197 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
199 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
201 return DEBUG_LOC_BUFFER_OVERFLOW
;
205 return DEBUG_LOC_START_LENGTH
;
207 case DW_LLE_start_length
:
208 if (buf_end
- loc_ptr
< addr_size
)
209 return DEBUG_LOC_BUFFER_OVERFLOW
;
212 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
214 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
216 loc_ptr
+= addr_size
;
219 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
221 return DEBUG_LOC_BUFFER_OVERFLOW
;
225 return DEBUG_LOC_START_LENGTH
;
227 case DW_LLE_end_of_list
:
229 return DEBUG_LOC_END_OF_LIST
;
231 case DW_LLE_base_address
:
232 if (loc_ptr
+ addr_size
> buf_end
)
233 return DEBUG_LOC_BUFFER_OVERFLOW
;
236 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
238 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
240 loc_ptr
+= addr_size
;
242 return DEBUG_LOC_BASE_ADDRESS
;
244 case DW_LLE_offset_pair
:
245 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
247 return DEBUG_LOC_BUFFER_OVERFLOW
;
250 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
252 return DEBUG_LOC_BUFFER_OVERFLOW
;
256 return DEBUG_LOC_OFFSET_PAIR
;
258 /* Following cases are not supported yet. */
259 case DW_LLE_startx_endx
:
260 case DW_LLE_start_end
:
261 case DW_LLE_default_location
:
263 return DEBUG_LOC_INVALID_ENTRY
;
267 /* Decode the addresses in .debug_loc.dwo entry.
268 A pointer to the next byte to examine is returned in *NEW_PTR.
269 The encoded low,high addresses are return in *LOW,*HIGH.
270 The result indicates the kind of entry found. */
272 static enum debug_loc_kind
273 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
274 dwarf2_per_objfile
*per_objfile
,
275 const gdb_byte
*loc_ptr
,
276 const gdb_byte
*buf_end
,
277 const gdb_byte
**new_ptr
,
278 CORE_ADDR
*low
, CORE_ADDR
*high
,
279 enum bfd_endian byte_order
)
281 uint64_t low_index
, high_index
;
283 if (loc_ptr
== buf_end
)
284 return DEBUG_LOC_BUFFER_OVERFLOW
;
288 case DW_LLE_GNU_end_of_list_entry
:
290 return DEBUG_LOC_END_OF_LIST
;
292 case DW_LLE_GNU_base_address_selection_entry
:
294 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
296 return DEBUG_LOC_BUFFER_OVERFLOW
;
298 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
300 return DEBUG_LOC_BASE_ADDRESS
;
302 case DW_LLE_GNU_start_end_entry
:
303 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
305 return DEBUG_LOC_BUFFER_OVERFLOW
;
307 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
308 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
310 return DEBUG_LOC_BUFFER_OVERFLOW
;
312 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
314 return DEBUG_LOC_START_END
;
316 case DW_LLE_GNU_start_length_entry
:
317 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
319 return DEBUG_LOC_BUFFER_OVERFLOW
;
321 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
322 if (loc_ptr
+ 4 > buf_end
)
323 return DEBUG_LOC_BUFFER_OVERFLOW
;
326 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
327 *new_ptr
= loc_ptr
+ 4;
328 return DEBUG_LOC_START_LENGTH
;
331 return DEBUG_LOC_INVALID_ENTRY
;
335 /* A function for dealing with location lists. Given a
336 symbol baton (BATON) and a pc value (PC), find the appropriate
337 location expression, set *LOCEXPR_LENGTH, and return a pointer
338 to the beginning of the expression. Returns NULL on failure.
340 For now, only return the first matching location expression; there
341 can be more than one in the list. */
344 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
345 size_t *locexpr_length
, CORE_ADDR pc
)
347 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
348 struct objfile
*objfile
= per_objfile
->objfile
;
349 struct gdbarch
*gdbarch
= objfile
->arch ();
350 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
351 unsigned int addr_size
= baton
->per_cu
->addr_size ();
352 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
353 /* Adjust base_address for relocatable objects. */
354 CORE_ADDR base_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
355 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
356 const gdb_byte
*loc_ptr
, *buf_end
;
358 loc_ptr
= baton
->data
;
359 buf_end
= baton
->data
+ baton
->size
;
363 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
365 enum debug_loc_kind kind
;
366 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
368 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
369 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
371 loc_ptr
, buf_end
, &new_ptr
,
372 &low
, &high
, byte_order
);
373 else if (baton
->per_cu
->version () < 5)
374 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
376 byte_order
, addr_size
,
379 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
381 loc_ptr
, buf_end
, &new_ptr
,
382 &low
, &high
, byte_order
,
383 addr_size
, signed_addr_p
);
388 case DEBUG_LOC_END_OF_LIST
:
392 case DEBUG_LOC_BASE_ADDRESS
:
393 base_address
= high
+ base_offset
;
396 case DEBUG_LOC_START_END
:
397 case DEBUG_LOC_START_LENGTH
:
398 case DEBUG_LOC_OFFSET_PAIR
:
401 case DEBUG_LOC_BUFFER_OVERFLOW
:
402 case DEBUG_LOC_INVALID_ENTRY
:
403 error (_("dwarf2_find_location_expression: "
404 "Corrupted DWARF expression."));
407 gdb_assert_not_reached ("bad debug_loc_kind");
410 /* Otherwise, a location expression entry.
411 If the entry is from a DWO, don't add base address: the entry is from
412 .debug_addr which already has the DWARF "base address". We still add
413 base_offset in case we're debugging a PIE executable. However, if the
414 entry is DW_LLE_offset_pair from a DWO, add the base address as the
415 operands are offsets relative to the applicable base address. */
416 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
424 high
+= base_address
;
427 if (baton
->per_cu
->version () < 5)
429 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
434 unsigned int bytes_read
;
436 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
437 loc_ptr
+= bytes_read
;
440 if (low
== high
&& pc
== low
)
442 /* This is entry PC record present only at entry point
443 of a function. Verify it is really the function entry point. */
445 const struct block
*pc_block
= block_for_pc (pc
);
446 struct symbol
*pc_func
= NULL
;
449 pc_func
= block_linkage_function (pc_block
);
451 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
453 *locexpr_length
= length
;
458 if (pc
>= low
&& pc
< high
)
460 *locexpr_length
= length
;
468 /* Implement find_frame_base_location method for LOC_BLOCK functions using
469 DWARF expression for its DW_AT_frame_base. */
472 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
473 const gdb_byte
**start
, size_t *length
)
475 struct dwarf2_locexpr_baton
*symbaton
476 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
478 *length
= symbaton
->size
;
479 *start
= symbaton
->data
;
482 /* Implement the struct symbol_block_ops::get_frame_base method for
483 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
486 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
488 struct gdbarch
*gdbarch
;
490 struct dwarf2_locexpr_baton
*dlbaton
;
491 const gdb_byte
*start
;
493 struct value
*result
;
495 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
496 Thus, it's supposed to provide the find_frame_base_location method as
498 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
500 gdbarch
= get_frame_arch (frame
);
501 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
502 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
504 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
505 (framefunc
, get_frame_pc (frame
), &start
, &length
);
506 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
507 dlbaton
->per_cu
, dlbaton
->per_objfile
);
509 /* The DW_AT_frame_base attribute contains a location description which
510 computes the base address itself. However, the call to
511 dwarf2_evaluate_loc_desc returns a value representing a variable at
512 that address. The frame base address is thus this variable's
514 return value_address (result
);
517 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
518 function uses DWARF expression for its DW_AT_frame_base. */
520 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
522 locexpr_find_frame_base_location
,
523 locexpr_get_frame_base
526 /* Implement find_frame_base_location method for LOC_BLOCK functions using
527 DWARF location list for its DW_AT_frame_base. */
530 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
531 const gdb_byte
**start
, size_t *length
)
533 struct dwarf2_loclist_baton
*symbaton
534 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
536 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
539 /* Implement the struct symbol_block_ops::get_frame_base method for
540 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
543 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
545 struct gdbarch
*gdbarch
;
547 struct dwarf2_loclist_baton
*dlbaton
;
548 const gdb_byte
*start
;
550 struct value
*result
;
552 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
553 Thus, it's supposed to provide the find_frame_base_location method as
555 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
557 gdbarch
= get_frame_arch (frame
);
558 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
559 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
561 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
562 (framefunc
, get_frame_pc (frame
), &start
, &length
);
563 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
564 dlbaton
->per_cu
, dlbaton
->per_objfile
);
566 /* The DW_AT_frame_base attribute contains a location description which
567 computes the base address itself. However, the call to
568 dwarf2_evaluate_loc_desc returns a value representing a variable at
569 that address. The frame base address is thus this variable's
571 return value_address (result
);
574 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
575 function uses DWARF location list for its DW_AT_frame_base. */
577 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
579 loclist_find_frame_base_location
,
580 loclist_get_frame_base
583 /* See dwarf2loc.h. */
586 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
587 const gdb_byte
**start
, size_t *length
)
589 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
591 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
593 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
599 error (_("Could not find the frame base for \"%s\"."),
600 framefunc
->natural_name ());
604 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
605 dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
)
607 struct dwarf2_locexpr_baton block
;
609 auto get_frame_pc_from_ctx
= [ctx
] ()
611 return ctx
->get_frame_pc ();
614 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, per_objfile
,
615 get_frame_pc_from_ctx
);
617 /* DW_OP_call_ref is currently not supported. */
618 gdb_assert (block
.per_cu
== per_cu
);
620 ctx
->eval (block
.data
, block
.size
);
623 /* A helper function to find the definition of NAME and compute its
624 value. Returns nullptr if the name is not found. */
627 compute_var_value (const char *name
)
629 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
631 if (sym
.symbol
!= nullptr)
632 return value_of_variable (sym
.symbol
, sym
.block
);
636 /* Given context CTX, section offset SECT_OFF, and compilation unit
637 data PER_CU, execute the "variable value" operation on the DIE
638 found at SECT_OFF. */
640 static struct value
*
641 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
642 dwarf2_per_cu_data
*per_cu
,
643 dwarf2_per_objfile
*per_objfile
)
645 const char *var_name
= nullptr;
646 struct type
*die_type
647 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
, per_objfile
,
650 if (die_type
== NULL
)
651 error (_("Bad DW_OP_GNU_variable_value DIE."));
653 /* Note: Things still work when the following test is removed. This
654 test and error is here to conform to the proposed specification. */
655 if (die_type
->code () != TYPE_CODE_INT
656 && die_type
->code () != TYPE_CODE_ENUM
657 && die_type
->code () != TYPE_CODE_RANGE
658 && die_type
->code () != TYPE_CODE_PTR
)
659 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
661 if (var_name
!= nullptr)
663 value
*result
= compute_var_value (var_name
);
664 if (result
!= nullptr)
668 struct type
*type
= lookup_pointer_type (die_type
);
669 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
670 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, per_objfile
, frame
,
674 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
677 dwarf_evaluate_loc_desc (dwarf2_per_objfile
*per_objfile
)
678 : dwarf_expr_context (per_objfile
)
681 struct frame_info
*frame
;
682 struct dwarf2_per_cu_data
*per_cu
;
683 CORE_ADDR obj_address
;
685 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
686 the frame in BATON. */
688 CORE_ADDR
get_frame_cfa () override
690 return dwarf2_frame_cfa (frame
);
693 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
694 the frame in BATON. */
696 CORE_ADDR
get_frame_pc () override
698 return get_frame_address_in_block (frame
);
701 /* Using the objfile specified in BATON, find the address for the
702 current thread's thread-local storage with offset OFFSET. */
703 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
705 return target_translate_tls_address (per_objfile
->objfile
, offset
);
708 /* Helper interface of per_cu_dwarf_call for
709 dwarf2_evaluate_loc_desc. */
711 void dwarf_call (cu_offset die_offset
) override
713 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
716 /* Helper interface of sect_variable_value for
717 dwarf2_evaluate_loc_desc. */
719 struct value
*dwarf_variable_value (sect_offset sect_off
) override
721 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
724 struct type
*get_base_type (cu_offset die_offset
, int size
) override
726 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
, per_objfile
);
728 error (_("Could not find type for DW_OP_const_type"));
729 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
730 error (_("DW_OP_const_type has different sizes for type and data"));
734 /* Callback function for dwarf2_evaluate_loc_desc.
735 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
737 CORE_ADDR
get_addr_index (unsigned int index
) override
739 return dwarf2_read_addr_index (per_cu
, per_objfile
, index
);
742 /* Callback function for get_object_address. Return the address of the VLA
745 CORE_ADDR
get_object_address () override
747 if (obj_address
== 0)
748 error (_("Location address is not set."));
752 /* Execute DWARF block of call_site_parameter which matches KIND and
753 KIND_U. Choose DEREF_SIZE value of that parameter. Search
754 caller of this objects's frame.
756 The caller can be from a different CU - per_cu_dwarf_call
757 implementation can be more simple as it does not support cross-CU
760 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
761 union call_site_parameter_u kind_u
,
762 int deref_size
) override
764 struct frame_info
*caller_frame
;
765 dwarf2_per_cu_data
*caller_per_cu
;
766 dwarf2_per_objfile
*caller_per_objfile
;
767 struct call_site_parameter
*parameter
;
768 const gdb_byte
*data_src
;
771 caller_frame
= get_prev_frame (frame
);
773 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
775 &caller_per_objfile
);
776 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
777 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
779 /* DEREF_SIZE size is not verified here. */
780 if (data_src
== NULL
)
781 throw_error (NO_ENTRY_VALUE_ERROR
,
782 _("Cannot resolve DW_AT_call_data_value"));
784 /* We are about to evaluate an expression in the context of the caller
785 of the current frame. This evaluation context may be different from
786 the current (callee's) context), so temporarily set the caller's context.
788 It is possible for the caller to be from a different objfile from the
789 callee if the call is made through a function pointer. */
790 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
792 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
794 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
796 scoped_restore save_per_objfile
= make_scoped_restore (&this->per_objfile
,
799 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
800 this->gdbarch
= this->per_objfile
->objfile
->arch ();
801 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
802 this->addr_size
= this->per_cu
->addr_size ();
804 this->eval (data_src
, size
);
807 /* Using the frame specified in BATON, find the location expression
808 describing the frame base. Return a pointer to it in START and
809 its length in LENGTH. */
810 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
812 if (frame
== nullptr)
813 error (_("frame address is not available."));
815 /* FIXME: cagney/2003-03-26: This code should be using
816 get_frame_base_address(), and then implement a dwarf2 specific
818 struct symbol
*framefunc
;
819 const struct block
*bl
= get_frame_block (frame
, NULL
);
822 error (_("frame address is not available."));
824 /* Use block_linkage_function, which returns a real (not inlined)
825 function, instead of get_frame_function, which may return an
827 framefunc
= block_linkage_function (bl
);
829 /* If we found a frame-relative symbol then it was certainly within
830 some function associated with a frame. If we can't find the frame,
831 something has gone wrong. */
832 gdb_assert (framefunc
!= NULL
);
834 func_get_frame_base_dwarf_block (framefunc
,
835 get_frame_address_in_block (frame
),
839 /* Read memory at ADDR (length LEN) into BUF. */
841 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
843 read_memory (addr
, buf
, len
);
846 /* Using the frame specified in BATON, return the value of register
847 REGNUM, treated as a pointer. */
848 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
850 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
851 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
853 return address_from_register (regnum
, frame
);
856 /* Implement "get_reg_value" callback. */
858 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
860 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
861 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
863 return value_from_register (type
, regnum
, frame
);
867 /* See dwarf2loc.h. */
869 unsigned int entry_values_debug
= 0;
871 /* Helper to set entry_values_debug. */
874 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
875 struct cmd_list_element
*c
, const char *value
)
877 fprintf_filtered (file
,
878 _("Entry values and tail call frames debugging is %s.\n"),
882 /* Find DW_TAG_call_site's DW_AT_call_target address.
883 CALLER_FRAME (for registers) can be NULL if it is not known. This function
884 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
887 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
888 struct call_site
*call_site
,
889 struct frame_info
*caller_frame
)
891 switch (FIELD_LOC_KIND (call_site
->target
))
893 case FIELD_LOC_KIND_DWARF_BLOCK
:
895 struct dwarf2_locexpr_baton
*dwarf_block
;
897 struct type
*caller_core_addr_type
;
898 struct gdbarch
*caller_arch
;
900 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
901 if (dwarf_block
== NULL
)
903 struct bound_minimal_symbol msym
;
905 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
906 throw_error (NO_ENTRY_VALUE_ERROR
,
907 _("DW_AT_call_target is not specified at %s in %s"),
908 paddress (call_site_gdbarch
, call_site
->pc
),
909 (msym
.minsym
== NULL
? "???"
910 : msym
.minsym
->print_name ()));
913 if (caller_frame
== NULL
)
915 struct bound_minimal_symbol msym
;
917 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
918 throw_error (NO_ENTRY_VALUE_ERROR
,
919 _("DW_AT_call_target DWARF block resolving "
920 "requires known frame which is currently not "
921 "available at %s in %s"),
922 paddress (call_site_gdbarch
, call_site
->pc
),
923 (msym
.minsym
== NULL
? "???"
924 : msym
.minsym
->print_name ()));
927 caller_arch
= get_frame_arch (caller_frame
);
928 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
929 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
930 dwarf_block
->data
, dwarf_block
->size
,
932 dwarf_block
->per_objfile
);
933 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
934 if (VALUE_LVAL (val
) == lval_memory
)
935 return value_address (val
);
937 return value_as_address (val
);
940 case FIELD_LOC_KIND_PHYSNAME
:
942 const char *physname
;
943 struct bound_minimal_symbol msym
;
945 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
947 /* Handle both the mangled and demangled PHYSNAME. */
948 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
949 if (msym
.minsym
== NULL
)
951 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
952 throw_error (NO_ENTRY_VALUE_ERROR
,
953 _("Cannot find function \"%s\" for a call site target "
955 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
956 (msym
.minsym
== NULL
? "???"
957 : msym
.minsym
->print_name ()));
960 return BMSYMBOL_VALUE_ADDRESS (msym
);
963 case FIELD_LOC_KIND_PHYSADDR
:
964 return FIELD_STATIC_PHYSADDR (call_site
->target
);
967 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
971 /* Convert function entry point exact address ADDR to the function which is
972 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
973 NO_ENTRY_VALUE_ERROR otherwise. */
975 static struct symbol
*
976 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
978 struct symbol
*sym
= find_pc_function (addr
);
981 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
982 throw_error (NO_ENTRY_VALUE_ERROR
,
983 _("DW_TAG_call_site resolving failed to find function "
984 "name for address %s"),
985 paddress (gdbarch
, addr
));
987 type
= SYMBOL_TYPE (sym
);
988 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
989 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
994 /* Verify function with entry point exact address ADDR can never call itself
995 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
996 can call itself via tail calls.
998 If a funtion can tail call itself its entry value based parameters are
999 unreliable. There is no verification whether the value of some/all
1000 parameters is unchanged through the self tail call, we expect if there is
1001 a self tail call all the parameters can be modified. */
1004 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
1008 /* The verification is completely unordered. Track here function addresses
1009 which still need to be iterated. */
1010 std::vector
<CORE_ADDR
> todo
;
1012 /* Track here CORE_ADDRs which were already visited. */
1013 std::unordered_set
<CORE_ADDR
> addr_hash
;
1015 todo
.push_back (verify_addr
);
1016 while (!todo
.empty ())
1018 struct symbol
*func_sym
;
1019 struct call_site
*call_site
;
1021 addr
= todo
.back ();
1024 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
1026 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
1027 call_site
; call_site
= call_site
->tail_call_next
)
1029 CORE_ADDR target_addr
;
1031 /* CALLER_FRAME with registers is not available for tail-call jumped
1033 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1035 if (target_addr
== verify_addr
)
1037 struct bound_minimal_symbol msym
;
1039 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
1040 throw_error (NO_ENTRY_VALUE_ERROR
,
1041 _("DW_OP_entry_value resolving has found "
1042 "function \"%s\" at %s can call itself via tail "
1044 (msym
.minsym
== NULL
? "???"
1045 : msym
.minsym
->print_name ()),
1046 paddress (gdbarch
, verify_addr
));
1049 if (addr_hash
.insert (target_addr
).second
)
1050 todo
.push_back (target_addr
);
1055 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
1056 ENTRY_VALUES_DEBUG. */
1059 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
1061 CORE_ADDR addr
= call_site
->pc
;
1062 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
1064 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
1065 (msym
.minsym
== NULL
? "???"
1066 : msym
.minsym
->print_name ()));
1070 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1071 only top callers and bottom callees which are present in both. GDBARCH is
1072 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1073 no remaining possibilities to provide unambiguous non-trivial result.
1074 RESULTP should point to NULL on the first (initialization) call. Caller is
1075 responsible for xfree of any RESULTP data. */
1078 chain_candidate (struct gdbarch
*gdbarch
,
1079 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1080 std::vector
<struct call_site
*> *chain
)
1082 long length
= chain
->size ();
1083 int callers
, callees
, idx
;
1085 if (*resultp
== NULL
)
1087 /* Create the initial chain containing all the passed PCs. */
1089 struct call_site_chain
*result
1090 = ((struct call_site_chain
*)
1091 xmalloc (sizeof (*result
)
1092 + sizeof (*result
->call_site
) * (length
- 1)));
1093 result
->length
= length
;
1094 result
->callers
= result
->callees
= length
;
1095 if (!chain
->empty ())
1096 memcpy (result
->call_site
, chain
->data (),
1097 sizeof (*result
->call_site
) * length
);
1098 resultp
->reset (result
);
1100 if (entry_values_debug
)
1102 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1103 for (idx
= 0; idx
< length
; idx
++)
1104 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1105 fputc_unfiltered ('\n', gdb_stdlog
);
1111 if (entry_values_debug
)
1113 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1114 for (idx
= 0; idx
< length
; idx
++)
1115 tailcall_dump (gdbarch
, chain
->at (idx
));
1116 fputc_unfiltered ('\n', gdb_stdlog
);
1119 /* Intersect callers. */
1121 callers
= std::min ((long) (*resultp
)->callers
, length
);
1122 for (idx
= 0; idx
< callers
; idx
++)
1123 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1125 (*resultp
)->callers
= idx
;
1129 /* Intersect callees. */
1131 callees
= std::min ((long) (*resultp
)->callees
, length
);
1132 for (idx
= 0; idx
< callees
; idx
++)
1133 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1134 != chain
->at (length
- 1 - idx
))
1136 (*resultp
)->callees
= idx
;
1140 if (entry_values_debug
)
1142 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1143 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1144 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1145 fputs_unfiltered (" |", gdb_stdlog
);
1146 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1147 tailcall_dump (gdbarch
,
1148 (*resultp
)->call_site
[(*resultp
)->length
1149 - (*resultp
)->callees
+ idx
]);
1150 fputc_unfiltered ('\n', gdb_stdlog
);
1153 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1155 /* There are no common callers or callees. It could be also a direct
1156 call (which has length 0) with ambiguous possibility of an indirect
1157 call - CALLERS == CALLEES == 0 is valid during the first allocation
1158 but any subsequence processing of such entry means ambiguity. */
1159 resultp
->reset (NULL
);
1163 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1164 PC again. In such case there must be two different code paths to reach
1165 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1166 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1169 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1170 assumed frames between them use GDBARCH. Use depth first search so we can
1171 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1172 would have needless GDB stack overhead. Any unreliability results
1173 in thrown NO_ENTRY_VALUE_ERROR. */
1175 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1176 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1177 CORE_ADDR callee_pc
)
1179 CORE_ADDR save_callee_pc
= callee_pc
;
1180 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1181 struct call_site
*call_site
;
1183 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1184 call_site nor any possible call_site at CALLEE_PC's function is there.
1185 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1186 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1187 std::vector
<struct call_site
*> chain
;
1189 /* We are not interested in the specific PC inside the callee function. */
1190 callee_pc
= get_pc_function_start (callee_pc
);
1192 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1193 paddress (gdbarch
, save_callee_pc
));
1195 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1196 std::unordered_set
<CORE_ADDR
> addr_hash
;
1198 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1199 at the target's function. All the possible tail call sites in the
1200 target's function will get iterated as already pushed into CHAIN via their
1202 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1206 CORE_ADDR target_func_addr
;
1207 struct call_site
*target_call_site
;
1209 /* CALLER_FRAME with registers is not available for tail-call jumped
1211 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1213 if (target_func_addr
== callee_pc
)
1215 chain_candidate (gdbarch
, &retval
, &chain
);
1219 /* There is no way to reach CALLEE_PC again as we would prevent
1220 entering it twice as being already marked in ADDR_HASH. */
1221 target_call_site
= NULL
;
1225 struct symbol
*target_func
;
1227 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1228 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1233 /* Attempt to visit TARGET_CALL_SITE. */
1235 if (target_call_site
)
1237 if (addr_hash
.insert (target_call_site
->pc
).second
)
1239 /* Successfully entered TARGET_CALL_SITE. */
1241 chain
.push_back (target_call_site
);
1246 /* Backtrack (without revisiting the originating call_site). Try the
1247 callers's sibling; if there isn't any try the callers's callers's
1250 target_call_site
= NULL
;
1251 while (!chain
.empty ())
1253 call_site
= chain
.back ();
1256 size_t removed
= addr_hash
.erase (call_site
->pc
);
1257 gdb_assert (removed
== 1);
1259 target_call_site
= call_site
->tail_call_next
;
1260 if (target_call_site
)
1264 while (target_call_site
);
1269 call_site
= chain
.back ();
1274 struct bound_minimal_symbol msym_caller
, msym_callee
;
1276 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1277 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1278 throw_error (NO_ENTRY_VALUE_ERROR
,
1279 _("There are no unambiguously determinable intermediate "
1280 "callers or callees between caller function \"%s\" at %s "
1281 "and callee function \"%s\" at %s"),
1282 (msym_caller
.minsym
== NULL
1283 ? "???" : msym_caller
.minsym
->print_name ()),
1284 paddress (gdbarch
, caller_pc
),
1285 (msym_callee
.minsym
== NULL
1286 ? "???" : msym_callee
.minsym
->print_name ()),
1287 paddress (gdbarch
, callee_pc
));
1293 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1294 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1295 constructed return NULL. */
1297 gdb::unique_xmalloc_ptr
<call_site_chain
>
1298 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1299 CORE_ADDR callee_pc
)
1301 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1305 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1307 catch (const gdb_exception_error
&e
)
1309 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1311 if (entry_values_debug
)
1312 exception_print (gdb_stdout
, e
);
1323 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1326 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1327 enum call_site_parameter_kind kind
,
1328 union call_site_parameter_u kind_u
)
1330 if (kind
== parameter
->kind
)
1333 case CALL_SITE_PARAMETER_DWARF_REG
:
1334 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1336 case CALL_SITE_PARAMETER_FB_OFFSET
:
1337 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1339 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1340 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1345 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1346 FRAME is for callee.
1348 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1351 static struct call_site_parameter
*
1352 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1353 enum call_site_parameter_kind kind
,
1354 union call_site_parameter_u kind_u
,
1355 dwarf2_per_cu_data
**per_cu_return
,
1356 dwarf2_per_objfile
**per_objfile_return
)
1358 CORE_ADDR func_addr
, caller_pc
;
1359 struct gdbarch
*gdbarch
;
1360 struct frame_info
*caller_frame
;
1361 struct call_site
*call_site
;
1363 /* Initialize it just to avoid a GCC false warning. */
1364 struct call_site_parameter
*parameter
= NULL
;
1365 CORE_ADDR target_addr
;
1367 while (get_frame_type (frame
) == INLINE_FRAME
)
1369 frame
= get_prev_frame (frame
);
1370 gdb_assert (frame
!= NULL
);
1373 func_addr
= get_frame_func (frame
);
1374 gdbarch
= get_frame_arch (frame
);
1375 caller_frame
= get_prev_frame (frame
);
1376 if (gdbarch
!= frame_unwind_arch (frame
))
1378 struct bound_minimal_symbol msym
1379 = lookup_minimal_symbol_by_pc (func_addr
);
1380 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1382 throw_error (NO_ENTRY_VALUE_ERROR
,
1383 _("DW_OP_entry_value resolving callee gdbarch %s "
1384 "(of %s (%s)) does not match caller gdbarch %s"),
1385 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1386 paddress (gdbarch
, func_addr
),
1387 (msym
.minsym
== NULL
? "???"
1388 : msym
.minsym
->print_name ()),
1389 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1392 if (caller_frame
== NULL
)
1394 struct bound_minimal_symbol msym
1395 = lookup_minimal_symbol_by_pc (func_addr
);
1397 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1398 "requires caller of %s (%s)"),
1399 paddress (gdbarch
, func_addr
),
1400 (msym
.minsym
== NULL
? "???"
1401 : msym
.minsym
->print_name ()));
1403 caller_pc
= get_frame_pc (caller_frame
);
1404 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1406 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1407 if (target_addr
!= func_addr
)
1409 struct minimal_symbol
*target_msym
, *func_msym
;
1411 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1412 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1413 throw_error (NO_ENTRY_VALUE_ERROR
,
1414 _("DW_OP_entry_value resolving expects callee %s at %s "
1415 "but the called frame is for %s at %s"),
1416 (target_msym
== NULL
? "???"
1417 : target_msym
->print_name ()),
1418 paddress (gdbarch
, target_addr
),
1419 func_msym
== NULL
? "???" : func_msym
->print_name (),
1420 paddress (gdbarch
, func_addr
));
1423 /* No entry value based parameters would be reliable if this function can
1424 call itself via tail calls. */
1425 func_verify_no_selftailcall (gdbarch
, func_addr
);
1427 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1429 parameter
= &call_site
->parameter
[iparams
];
1430 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1433 if (iparams
== call_site
->parameter_count
)
1435 struct minimal_symbol
*msym
1436 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1438 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1439 determine its value. */
1440 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1441 "at DW_TAG_call_site %s at %s"),
1442 paddress (gdbarch
, caller_pc
),
1443 msym
== NULL
? "???" : msym
->print_name ());
1446 *per_cu_return
= call_site
->per_cu
;
1447 *per_objfile_return
= call_site
->per_objfile
;
1451 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1452 the normal DW_AT_call_value block. Otherwise return the
1453 DW_AT_call_data_value (dereferenced) block.
1455 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1458 Function always returns non-NULL, non-optimized out value. It throws
1459 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1461 static struct value
*
1462 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1463 CORE_ADDR deref_size
, struct type
*type
,
1464 struct frame_info
*caller_frame
,
1465 dwarf2_per_cu_data
*per_cu
,
1466 dwarf2_per_objfile
*per_objfile
)
1468 const gdb_byte
*data_src
;
1472 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1473 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1475 /* DEREF_SIZE size is not verified here. */
1476 if (data_src
== NULL
)
1477 throw_error (NO_ENTRY_VALUE_ERROR
,
1478 _("Cannot resolve DW_AT_call_data_value"));
1480 /* DW_AT_call_value is a DWARF expression, not a DWARF
1481 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1483 data
= (gdb_byte
*) alloca (size
+ 1);
1484 memcpy (data
, data_src
, size
);
1485 data
[size
] = DW_OP_stack_value
;
1487 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
,
1491 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1492 the indirect method on it, that is use its stored target value, the sole
1493 purpose of entry_data_value_funcs.. */
1495 static struct value
*
1496 entry_data_value_coerce_ref (const struct value
*value
)
1498 struct type
*checked_type
= check_typedef (value_type (value
));
1499 struct value
*target_val
;
1501 if (!TYPE_IS_REFERENCE (checked_type
))
1504 target_val
= (struct value
*) value_computed_closure (value
);
1505 value_incref (target_val
);
1509 /* Implement copy_closure. */
1512 entry_data_value_copy_closure (const struct value
*v
)
1514 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1516 value_incref (target_val
);
1520 /* Implement free_closure. */
1523 entry_data_value_free_closure (struct value
*v
)
1525 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1527 value_decref (target_val
);
1530 /* Vector for methods for an entry value reference where the referenced value
1531 is stored in the caller. On the first dereference use
1532 DW_AT_call_data_value in the caller. */
1534 static const struct lval_funcs entry_data_value_funcs
=
1538 NULL
, /* indirect */
1539 entry_data_value_coerce_ref
,
1540 NULL
, /* check_synthetic_pointer */
1541 entry_data_value_copy_closure
,
1542 entry_data_value_free_closure
1545 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1546 are used to match DW_AT_location at the caller's
1547 DW_TAG_call_site_parameter.
1549 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1550 cannot resolve the parameter for any reason. */
1552 static struct value
*
1553 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1554 enum call_site_parameter_kind kind
,
1555 union call_site_parameter_u kind_u
)
1557 struct type
*checked_type
= check_typedef (type
);
1558 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1559 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1560 struct value
*outer_val
, *target_val
, *val
;
1561 struct call_site_parameter
*parameter
;
1562 dwarf2_per_cu_data
*caller_per_cu
;
1563 dwarf2_per_objfile
*caller_per_objfile
;
1565 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1567 &caller_per_objfile
);
1569 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1572 caller_per_objfile
);
1574 /* Check if DW_AT_call_data_value cannot be used. If it should be
1575 used and it is not available do not fall back to OUTER_VAL - dereferencing
1576 TYPE_CODE_REF with non-entry data value would give current value - not the
1579 if (!TYPE_IS_REFERENCE (checked_type
)
1580 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1583 target_val
= dwarf_entry_parameter_to_value (parameter
,
1584 TYPE_LENGTH (target_type
),
1585 target_type
, caller_frame
,
1587 caller_per_objfile
);
1589 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1590 release_value (target_val
).release ());
1592 /* Copy the referencing pointer to the new computed value. */
1593 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1594 TYPE_LENGTH (checked_type
));
1595 set_value_lazy (val
, 0);
1600 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1601 SIZE are DWARF block used to match DW_AT_location at the caller's
1602 DW_TAG_call_site_parameter.
1604 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1605 cannot resolve the parameter for any reason. */
1607 static struct value
*
1608 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1609 const gdb_byte
*block
, size_t block_len
)
1611 union call_site_parameter_u kind_u
;
1613 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1614 if (kind_u
.dwarf_reg
!= -1)
1615 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1618 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1619 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1622 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1623 suppressed during normal operation. The expression can be arbitrary if
1624 there is no caller-callee entry value binding expected. */
1625 throw_error (NO_ENTRY_VALUE_ERROR
,
1626 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1627 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1630 struct piece_closure
1632 /* Reference count. */
1635 /* The objfile from which this closure's expression came. */
1636 dwarf2_per_objfile
*per_objfile
= nullptr;
1638 /* The CU from which this closure's expression came. */
1639 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1641 /* The pieces describing this variable. */
1642 std::vector
<dwarf_expr_piece
> pieces
;
1644 /* Frame ID of frame to which a register value is relative, used
1645 only by DWARF_VALUE_REGISTER. */
1646 struct frame_id frame_id
;
1649 /* Allocate a closure for a value formed from separately-described
1652 static struct piece_closure
*
1653 allocate_piece_closure (dwarf2_per_cu_data
*per_cu
,
1654 dwarf2_per_objfile
*per_objfile
,
1655 std::vector
<dwarf_expr_piece
> &&pieces
,
1656 struct frame_info
*frame
)
1658 struct piece_closure
*c
= new piece_closure
;
1661 /* We must capture this here due to sharing of DWARF state. */
1662 c
->per_objfile
= per_objfile
;
1664 c
->pieces
= std::move (pieces
);
1666 c
->frame_id
= null_frame_id
;
1668 c
->frame_id
= get_frame_id (frame
);
1670 for (dwarf_expr_piece
&piece
: c
->pieces
)
1671 if (piece
.location
== DWARF_VALUE_STACK
)
1672 value_incref (piece
.v
.value
);
1677 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1678 bits whose first bit is located at bit offset START. */
1681 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1683 return (start
% 8 + n_bits
+ 7) / 8;
1686 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1687 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1688 operate in "read mode": fetch the contents of the (lazy) value V by
1689 composing it from its pieces. */
1692 rw_pieced_value (struct value
*v
, struct value
*from
)
1695 LONGEST offset
= 0, max_offset
;
1696 ULONGEST bits_to_skip
;
1697 gdb_byte
*v_contents
;
1698 const gdb_byte
*from_contents
;
1699 struct piece_closure
*c
1700 = (struct piece_closure
*) value_computed_closure (v
);
1701 gdb::byte_vector buffer
;
1702 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1706 from_contents
= value_contents (from
);
1711 if (value_type (v
) != value_enclosing_type (v
))
1712 internal_error (__FILE__
, __LINE__
,
1713 _("Should not be able to create a lazy value with "
1714 "an enclosing type"));
1715 v_contents
= value_contents_raw (v
);
1716 from_contents
= NULL
;
1719 bits_to_skip
= 8 * value_offset (v
);
1720 if (value_bitsize (v
))
1722 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1723 + value_bitpos (v
));
1725 && (type_byte_order (value_type (from
))
1728 /* Use the least significant bits of FROM. */
1729 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1730 offset
= max_offset
- value_bitsize (v
);
1733 max_offset
= value_bitsize (v
);
1736 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1738 /* Advance to the first non-skipped piece. */
1739 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1740 bits_to_skip
-= c
->pieces
[i
].size
;
1742 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1744 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1745 size_t this_size_bits
, this_size
;
1747 this_size_bits
= p
->size
- bits_to_skip
;
1748 if (this_size_bits
> max_offset
- offset
)
1749 this_size_bits
= max_offset
- offset
;
1751 switch (p
->location
)
1753 case DWARF_VALUE_REGISTER
:
1755 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1756 struct gdbarch
*arch
= get_frame_arch (frame
);
1757 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1758 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1761 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1762 && p
->offset
+ p
->size
< reg_bits
)
1764 /* Big-endian, and we want less than full size. */
1765 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1768 bits_to_skip
+= p
->offset
;
1770 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1771 buffer
.resize (this_size
);
1776 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1782 mark_value_bits_optimized_out (v
, offset
,
1785 mark_value_bits_unavailable (v
, offset
,
1790 copy_bitwise (v_contents
, offset
,
1791 buffer
.data (), bits_to_skip
% 8,
1792 this_size_bits
, bits_big_endian
);
1797 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1799 /* Data is copied non-byte-aligned into the register.
1800 Need some bits from original register value. */
1801 get_frame_register_bytes (frame
, gdb_regnum
,
1806 throw_error (OPTIMIZED_OUT_ERROR
,
1807 _("Can't do read-modify-write to "
1808 "update bitfield; containing word "
1809 "has been optimized out"));
1811 throw_error (NOT_AVAILABLE_ERROR
,
1812 _("Can't do read-modify-write to "
1813 "update bitfield; containing word "
1817 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1818 from_contents
, offset
,
1819 this_size_bits
, bits_big_endian
);
1820 put_frame_register_bytes (frame
, gdb_regnum
,
1827 case DWARF_VALUE_MEMORY
:
1829 bits_to_skip
+= p
->offset
;
1831 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1833 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1836 /* Everything is byte-aligned; no buffer needed. */
1838 write_memory_with_notification (start_addr
,
1841 this_size_bits
/ 8);
1843 read_value_memory (v
, offset
,
1844 p
->v
.mem
.in_stack_memory
,
1845 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1846 v_contents
+ offset
/ 8,
1847 this_size_bits
/ 8);
1851 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1852 buffer
.resize (this_size
);
1857 read_value_memory (v
, offset
,
1858 p
->v
.mem
.in_stack_memory
,
1859 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1860 buffer
.data (), this_size
);
1861 copy_bitwise (v_contents
, offset
,
1862 buffer
.data (), bits_to_skip
% 8,
1863 this_size_bits
, bits_big_endian
);
1868 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1872 /* Perform a single read for small sizes. */
1873 read_memory (start_addr
, buffer
.data (),
1878 /* Only the first and last bytes can possibly have
1880 read_memory (start_addr
, buffer
.data (), 1);
1881 read_memory (start_addr
+ this_size
- 1,
1882 &buffer
[this_size
- 1], 1);
1886 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1887 from_contents
, offset
,
1888 this_size_bits
, bits_big_endian
);
1889 write_memory_with_notification (start_addr
,
1896 case DWARF_VALUE_STACK
:
1900 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1904 gdbarch
*objfile_gdbarch
= c
->per_objfile
->objfile
->arch ();
1905 ULONGEST stack_value_size_bits
1906 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1908 /* Use zeroes if piece reaches beyond stack value. */
1909 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1912 /* Piece is anchored at least significant bit end. */
1913 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1914 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1916 bits_to_skip
+= p
->offset
;
1918 copy_bitwise (v_contents
, offset
,
1919 value_contents_all (p
->v
.value
),
1921 this_size_bits
, bits_big_endian
);
1925 case DWARF_VALUE_LITERAL
:
1929 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1933 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1934 size_t n
= this_size_bits
;
1936 /* Cut off at the end of the implicit value. */
1937 bits_to_skip
+= p
->offset
;
1938 if (bits_to_skip
>= literal_size_bits
)
1940 if (n
> literal_size_bits
- bits_to_skip
)
1941 n
= literal_size_bits
- bits_to_skip
;
1943 copy_bitwise (v_contents
, offset
,
1944 p
->v
.literal
.data
, bits_to_skip
,
1945 n
, bits_big_endian
);
1949 case DWARF_VALUE_IMPLICIT_POINTER
:
1952 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1956 /* These bits show up as zeros -- but do not cause the value to
1957 be considered optimized-out. */
1960 case DWARF_VALUE_OPTIMIZED_OUT
:
1961 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1965 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1968 offset
+= this_size_bits
;
1975 read_pieced_value (struct value
*v
)
1977 rw_pieced_value (v
, NULL
);
1981 write_pieced_value (struct value
*to
, struct value
*from
)
1983 rw_pieced_value (to
, from
);
1986 /* An implementation of an lval_funcs method to see whether a value is
1987 a synthetic pointer. */
1990 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1993 struct piece_closure
*c
1994 = (struct piece_closure
*) value_computed_closure (value
);
1997 bit_offset
+= 8 * value_offset (value
);
1998 if (value_bitsize (value
))
1999 bit_offset
+= value_bitpos (value
);
2001 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2003 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2004 size_t this_size_bits
= p
->size
;
2008 if (bit_offset
>= this_size_bits
)
2010 bit_offset
-= this_size_bits
;
2014 bit_length
-= this_size_bits
- bit_offset
;
2018 bit_length
-= this_size_bits
;
2020 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2027 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2029 static struct value
*
2030 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2031 dwarf2_per_cu_data
*per_cu
,
2032 dwarf2_per_objfile
*per_objfile
,
2035 struct value
*result
= NULL
;
2036 const gdb_byte
*bytes
;
2039 auto_obstack temp_obstack
;
2040 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
2041 &temp_obstack
, &len
);
2045 if (byte_offset
>= 0
2046 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2048 bytes
+= byte_offset
;
2049 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2052 invalid_synthetic_pointer ();
2055 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2060 /* Fetch the value pointed to by a synthetic pointer. */
2062 static struct value
*
2063 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2064 dwarf2_per_cu_data
*per_cu
,
2065 dwarf2_per_objfile
*per_objfile
,
2066 struct frame_info
*frame
, struct type
*type
,
2067 bool resolve_abstract_p
)
2069 /* Fetch the location expression of the DIE we're pointing to. */
2070 auto get_frame_address_in_block_wrapper
= [frame
] ()
2072 return get_frame_address_in_block (frame
);
2074 struct dwarf2_locexpr_baton baton
2075 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
2076 get_frame_address_in_block_wrapper
,
2077 resolve_abstract_p
);
2079 /* Get type of pointed-to DIE. */
2080 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
2082 if (orig_type
== NULL
)
2083 invalid_synthetic_pointer ();
2085 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2086 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2087 or it may've been optimized out. */
2088 if (baton
.data
!= NULL
)
2089 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2090 baton
.size
, baton
.per_cu
,
2092 TYPE_TARGET_TYPE (type
),
2095 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2099 /* An implementation of an lval_funcs method to indirect through a
2100 pointer. This handles the synthetic pointer case when needed. */
2102 static struct value
*
2103 indirect_pieced_value (struct value
*value
)
2105 struct piece_closure
*c
2106 = (struct piece_closure
*) value_computed_closure (value
);
2108 struct frame_info
*frame
;
2111 struct dwarf_expr_piece
*piece
= NULL
;
2112 LONGEST byte_offset
;
2113 enum bfd_endian byte_order
;
2115 type
= check_typedef (value_type (value
));
2116 if (type
->code () != TYPE_CODE_PTR
)
2119 bit_length
= 8 * TYPE_LENGTH (type
);
2120 bit_offset
= 8 * value_offset (value
);
2121 if (value_bitsize (value
))
2122 bit_offset
+= value_bitpos (value
);
2124 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2126 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2127 size_t this_size_bits
= p
->size
;
2131 if (bit_offset
>= this_size_bits
)
2133 bit_offset
-= this_size_bits
;
2137 bit_length
-= this_size_bits
- bit_offset
;
2141 bit_length
-= this_size_bits
;
2143 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2146 if (bit_length
!= 0)
2147 error (_("Invalid use of DW_OP_implicit_pointer"));
2153 gdb_assert (piece
!= NULL
);
2154 frame
= get_selected_frame (_("No frame selected."));
2156 /* This is an offset requested by GDB, such as value subscripts.
2157 However, due to how synthetic pointers are implemented, this is
2158 always presented to us as a pointer type. This means we have to
2159 sign-extend it manually as appropriate. Use raw
2160 extract_signed_integer directly rather than value_as_address and
2161 sign extend afterwards on architectures that would need it
2162 (mostly everywhere except MIPS, which has signed addresses) as
2163 the later would go through gdbarch_pointer_to_address and thus
2164 return a CORE_ADDR with high bits set on architectures that
2165 encode address spaces and other things in CORE_ADDR. */
2166 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2167 byte_offset
= extract_signed_integer (value_contents (value
),
2168 TYPE_LENGTH (type
), byte_order
);
2169 byte_offset
+= piece
->v
.ptr
.offset
;
2171 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2172 byte_offset
, c
->per_cu
,
2173 c
->per_objfile
, frame
, type
);
2176 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2179 static struct value
*
2180 coerce_pieced_ref (const struct value
*value
)
2182 struct type
*type
= check_typedef (value_type (value
));
2184 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2185 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2187 const struct piece_closure
*closure
2188 = (struct piece_closure
*) value_computed_closure (value
);
2189 struct frame_info
*frame
2190 = get_selected_frame (_("No frame selected."));
2192 /* gdb represents synthetic pointers as pieced values with a single
2194 gdb_assert (closure
!= NULL
);
2195 gdb_assert (closure
->pieces
.size () == 1);
2197 return indirect_synthetic_pointer
2198 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2199 closure
->pieces
[0].v
.ptr
.offset
,
2200 closure
->per_cu
, closure
->per_objfile
, frame
, type
);
2204 /* Else: not a synthetic reference; do nothing. */
2210 copy_pieced_value_closure (const struct value
*v
)
2212 struct piece_closure
*c
2213 = (struct piece_closure
*) value_computed_closure (v
);
2220 free_pieced_value_closure (struct value
*v
)
2222 struct piece_closure
*c
2223 = (struct piece_closure
*) value_computed_closure (v
);
2228 for (dwarf_expr_piece
&p
: c
->pieces
)
2229 if (p
.location
== DWARF_VALUE_STACK
)
2230 value_decref (p
.v
.value
);
2236 /* Functions for accessing a variable described by DW_OP_piece. */
2237 static const struct lval_funcs pieced_value_funcs
= {
2240 indirect_pieced_value
,
2242 check_pieced_synthetic_pointer
,
2243 copy_pieced_value_closure
,
2244 free_pieced_value_closure
2247 /* Evaluate a location description, starting at DATA and with length
2248 SIZE, to find the current location of variable of TYPE in the
2249 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2250 location of the subobject of type SUBOBJ_TYPE at byte offset
2251 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2253 static struct value
*
2254 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2255 const gdb_byte
*data
, size_t size
,
2256 dwarf2_per_cu_data
*per_cu
,
2257 dwarf2_per_objfile
*per_objfile
,
2258 struct type
*subobj_type
,
2259 LONGEST subobj_byte_offset
)
2261 struct value
*retval
;
2263 if (subobj_type
== NULL
)
2266 subobj_byte_offset
= 0;
2268 else if (subobj_byte_offset
< 0)
2269 invalid_synthetic_pointer ();
2272 return allocate_optimized_out_value (subobj_type
);
2274 dwarf_evaluate_loc_desc
ctx (per_objfile
);
2276 ctx
.per_cu
= per_cu
;
2277 ctx
.obj_address
= 0;
2279 scoped_value_mark free_values
;
2281 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2282 ctx
.addr_size
= per_cu
->addr_size ();
2283 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2287 ctx
.eval (data
, size
);
2289 catch (const gdb_exception_error
&ex
)
2291 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2293 free_values
.free_to_mark ();
2294 retval
= allocate_value (subobj_type
);
2295 mark_value_bytes_unavailable (retval
, 0,
2296 TYPE_LENGTH (subobj_type
));
2299 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2301 if (entry_values_debug
)
2302 exception_print (gdb_stdout
, ex
);
2303 free_values
.free_to_mark ();
2304 return allocate_optimized_out_value (subobj_type
);
2310 if (ctx
.pieces
.size () > 0)
2312 struct piece_closure
*c
;
2313 ULONGEST bit_size
= 0;
2315 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2316 bit_size
+= piece
.size
;
2317 /* Complain if the expression is larger than the size of the
2319 if (bit_size
> 8 * TYPE_LENGTH (type
))
2320 invalid_synthetic_pointer ();
2322 c
= allocate_piece_closure (per_cu
, per_objfile
, std::move (ctx
.pieces
),
2324 /* We must clean up the value chain after creating the piece
2325 closure but before allocating the result. */
2326 free_values
.free_to_mark ();
2327 retval
= allocate_computed_value (subobj_type
,
2328 &pieced_value_funcs
, c
);
2329 set_value_offset (retval
, subobj_byte_offset
);
2333 switch (ctx
.location
)
2335 case DWARF_VALUE_REGISTER
:
2337 struct gdbarch
*arch
= get_frame_arch (frame
);
2339 = longest_to_int (value_as_long (ctx
.fetch (0)));
2340 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2342 if (subobj_byte_offset
!= 0)
2343 error (_("cannot use offset on synthetic pointer to register"));
2344 free_values
.free_to_mark ();
2345 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2346 if (value_optimized_out (retval
))
2350 /* This means the register has undefined value / was
2351 not saved. As we're computing the location of some
2352 variable etc. in the program, not a value for
2353 inspecting a register ($pc, $sp, etc.), return a
2354 generic optimized out value instead, so that we show
2355 <optimized out> instead of <not saved>. */
2356 tmp
= allocate_value (subobj_type
);
2357 value_contents_copy (tmp
, 0, retval
, 0,
2358 TYPE_LENGTH (subobj_type
));
2364 case DWARF_VALUE_MEMORY
:
2366 struct type
*ptr_type
;
2367 CORE_ADDR address
= ctx
.fetch_address (0);
2368 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2370 /* DW_OP_deref_size (and possibly other operations too) may
2371 create a pointer instead of an address. Ideally, the
2372 pointer to address conversion would be performed as part
2373 of those operations, but the type of the object to
2374 which the address refers is not known at the time of
2375 the operation. Therefore, we do the conversion here
2376 since the type is readily available. */
2378 switch (subobj_type
->code ())
2380 case TYPE_CODE_FUNC
:
2381 case TYPE_CODE_METHOD
:
2382 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2385 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2388 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2390 free_values
.free_to_mark ();
2391 retval
= value_at_lazy (subobj_type
,
2392 address
+ subobj_byte_offset
);
2393 if (in_stack_memory
)
2394 set_value_stack (retval
, 1);
2398 case DWARF_VALUE_STACK
:
2400 struct value
*value
= ctx
.fetch (0);
2401 size_t n
= TYPE_LENGTH (value_type (value
));
2402 size_t len
= TYPE_LENGTH (subobj_type
);
2403 size_t max
= TYPE_LENGTH (type
);
2404 gdbarch
*objfile_gdbarch
= per_objfile
->objfile
->arch ();
2406 if (subobj_byte_offset
+ len
> max
)
2407 invalid_synthetic_pointer ();
2409 /* Preserve VALUE because we are going to free values back
2410 to the mark, but we still need the value contents
2412 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2413 free_values
.free_to_mark ();
2415 retval
= allocate_value (subobj_type
);
2417 /* The given offset is relative to the actual object. */
2418 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2419 subobj_byte_offset
+= n
- max
;
2421 memcpy (value_contents_raw (retval
),
2422 value_contents_all (value
) + subobj_byte_offset
, len
);
2426 case DWARF_VALUE_LITERAL
:
2429 size_t n
= TYPE_LENGTH (subobj_type
);
2431 if (subobj_byte_offset
+ n
> ctx
.len
)
2432 invalid_synthetic_pointer ();
2434 free_values
.free_to_mark ();
2435 retval
= allocate_value (subobj_type
);
2436 contents
= value_contents_raw (retval
);
2437 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2441 case DWARF_VALUE_OPTIMIZED_OUT
:
2442 free_values
.free_to_mark ();
2443 retval
= allocate_optimized_out_value (subobj_type
);
2446 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2447 operation by execute_stack_op. */
2448 case DWARF_VALUE_IMPLICIT_POINTER
:
2449 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2450 it can only be encountered when making a piece. */
2452 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2456 set_value_initialized (retval
, ctx
.initialized
);
2461 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2462 passes 0 as the byte_offset. */
2465 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2466 const gdb_byte
*data
, size_t size
,
2467 dwarf2_per_cu_data
*per_cu
,
2468 dwarf2_per_objfile
*per_objfile
)
2470 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2471 per_objfile
, NULL
, 0);
2474 /* A specialization of dwarf_evaluate_loc_desc that is used by
2475 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2476 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2477 but with the address being 0. In this situation, we arrange for
2478 memory reads to come from the passed-in buffer. */
2480 struct evaluate_for_locexpr_baton
: public dwarf_evaluate_loc_desc
2482 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2483 : dwarf_evaluate_loc_desc (per_objfile
)
2486 /* The data that was passed in. */
2487 gdb::array_view
<const gdb_byte
> data_view
;
2489 CORE_ADDR
get_object_address () override
2491 if (data_view
.data () == nullptr && obj_address
== 0)
2492 error (_("Location address is not set."));
2496 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2501 /* Prefer the passed-in memory, if it exists. */
2502 CORE_ADDR offset
= addr
- obj_address
;
2503 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2505 memcpy (buf
, data_view
.data (), len
);
2509 read_memory (addr
, buf
, len
);
2513 /* Evaluates a dwarf expression and stores the result in VAL,
2514 expecting that the dwarf expression only produces a single
2515 CORE_ADDR. FRAME is the frame in which the expression is
2516 evaluated. ADDR_STACK is a context (location of a variable) and
2517 might be needed to evaluate the location expression.
2518 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2519 or the default of 0) should be pushed on the DWARF expression
2520 evaluation stack before evaluating the expression; this is required
2521 by certain forms of DWARF expression. Returns 1 on success, 0
2525 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2526 struct frame_info
*frame
,
2527 const struct property_addr_info
*addr_stack
,
2529 bool push_initial_value
,
2532 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2535 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2536 evaluate_for_locexpr_baton
ctx (per_objfile
);
2539 ctx
.per_cu
= dlbaton
->per_cu
;
2540 if (addr_stack
== nullptr)
2541 ctx
.obj_address
= 0;
2544 ctx
.obj_address
= addr_stack
->addr
;
2545 ctx
.data_view
= addr_stack
->valaddr
;
2548 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2549 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2550 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2552 if (push_initial_value
)
2553 ctx
.push_address (ctx
.obj_address
, false);
2557 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2559 catch (const gdb_exception_error
&ex
)
2561 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2565 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2567 if (entry_values_debug
)
2568 exception_print (gdb_stdout
, ex
);
2575 switch (ctx
.location
)
2577 case DWARF_VALUE_STACK
:
2578 *is_reference
= false;
2581 case DWARF_VALUE_REGISTER
:
2582 case DWARF_VALUE_MEMORY
:
2583 *valp
= ctx
.fetch_address (0);
2584 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2585 *valp
= ctx
.read_addr_from_reg (*valp
);
2587 case DWARF_VALUE_LITERAL
:
2588 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2589 gdbarch_byte_order (ctx
.gdbarch
));
2591 /* Unsupported dwarf values. */
2592 case DWARF_VALUE_OPTIMIZED_OUT
:
2593 case DWARF_VALUE_IMPLICIT_POINTER
:
2600 /* See dwarf2loc.h. */
2603 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2604 struct frame_info
*frame
,
2605 const struct property_addr_info
*addr_stack
,
2607 bool push_initial_value
)
2612 if (frame
== NULL
&& has_stack_frames ())
2613 frame
= get_selected_frame (NULL
);
2615 switch (prop
->kind ())
2619 const struct dwarf2_property_baton
*baton
2620 = (const struct dwarf2_property_baton
*) prop
->baton ();
2621 gdb_assert (baton
->property_type
!= NULL
);
2623 bool is_reference
= baton
->locexpr
.is_reference
;
2624 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2625 value
, push_initial_value
, &is_reference
))
2629 struct value
*val
= value_at (baton
->property_type
, *value
);
2630 *value
= value_as_address (val
);
2634 gdb_assert (baton
->property_type
!= NULL
);
2636 struct type
*type
= check_typedef (baton
->property_type
);
2637 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2638 && !type
->is_unsigned ())
2640 /* If we have a valid return candidate and it's value
2641 is signed, we have to sign-extend the value because
2642 CORE_ADDR on 64bit machine has 8 bytes but address
2643 size of an 32bit application is bytes. */
2645 = (baton
->locexpr
.per_cu
->addr_size ()
2647 const CORE_ADDR neg_mask
2648 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2650 /* Check if signed bit is set and sign-extend values. */
2651 if (*value
& neg_mask
)
2662 struct dwarf2_property_baton
*baton
2663 = (struct dwarf2_property_baton
*) prop
->baton ();
2665 const gdb_byte
*data
;
2670 || !get_frame_address_in_block_if_available (frame
, &pc
))
2673 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2676 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2677 size
, baton
->loclist
.per_cu
,
2678 baton
->loclist
.per_objfile
);
2679 if (!value_optimized_out (val
))
2681 *value
= value_as_address (val
);
2689 *value
= prop
->const_val ();
2692 case PROP_ADDR_OFFSET
:
2694 struct dwarf2_property_baton
*baton
2695 = (struct dwarf2_property_baton
*) prop
->baton ();
2696 const struct property_addr_info
*pinfo
;
2699 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2701 /* This approach lets us avoid checking the qualifiers. */
2702 if (TYPE_MAIN_TYPE (pinfo
->type
)
2703 == TYPE_MAIN_TYPE (baton
->property_type
))
2707 error (_("cannot find reference address for offset property"));
2708 if (pinfo
->valaddr
.data () != NULL
)
2709 val
= value_from_contents
2710 (baton
->offset_info
.type
,
2711 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2713 val
= value_at (baton
->offset_info
.type
,
2714 pinfo
->addr
+ baton
->offset_info
.offset
);
2715 *value
= value_as_address (val
);
2719 case PROP_VARIABLE_NAME
:
2721 struct value
*val
= compute_var_value (prop
->variable_name ());
2724 *value
= value_as_long (val
);
2734 /* See dwarf2loc.h. */
2737 dwarf2_compile_property_to_c (string_file
*stream
,
2738 const char *result_name
,
2739 struct gdbarch
*gdbarch
,
2740 std::vector
<bool> ®isters_used
,
2741 const struct dynamic_prop
*prop
,
2745 struct dwarf2_property_baton
*baton
2746 = (struct dwarf2_property_baton
*) prop
->baton ();
2747 const gdb_byte
*data
;
2749 dwarf2_per_cu_data
*per_cu
;
2750 dwarf2_per_objfile
*per_objfile
;
2752 if (prop
->kind () == PROP_LOCEXPR
)
2754 data
= baton
->locexpr
.data
;
2755 size
= baton
->locexpr
.size
;
2756 per_cu
= baton
->locexpr
.per_cu
;
2757 per_objfile
= baton
->locexpr
.per_objfile
;
2761 gdb_assert (prop
->kind () == PROP_LOCLIST
);
2763 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2764 per_cu
= baton
->loclist
.per_cu
;
2765 per_objfile
= baton
->loclist
.per_objfile
;
2768 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2769 gdbarch
, registers_used
,
2770 per_cu
->addr_size (),
2771 data
, data
+ size
, per_cu
, per_objfile
);
2775 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2777 class symbol_needs_eval_context
: public dwarf_expr_context
2780 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2781 : dwarf_expr_context (per_objfile
)
2784 enum symbol_needs_kind needs
;
2785 struct dwarf2_per_cu_data
*per_cu
;
2787 /* Reads from registers do require a frame. */
2788 CORE_ADDR
read_addr_from_reg (int regnum
) override
2790 needs
= SYMBOL_NEEDS_FRAME
;
2794 /* "get_reg_value" callback: Reads from registers do require a
2797 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2799 needs
= SYMBOL_NEEDS_FRAME
;
2800 return value_zero (type
, not_lval
);
2803 /* Reads from memory do not require a frame. */
2804 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2806 memset (buf
, 0, len
);
2809 /* Frame-relative accesses do require a frame. */
2810 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2812 static gdb_byte lit0
= DW_OP_lit0
;
2817 needs
= SYMBOL_NEEDS_FRAME
;
2820 /* CFA accesses require a frame. */
2821 CORE_ADDR
get_frame_cfa () override
2823 needs
= SYMBOL_NEEDS_FRAME
;
2827 CORE_ADDR
get_frame_pc () override
2829 needs
= SYMBOL_NEEDS_FRAME
;
2833 /* Thread-local accesses require registers, but not a frame. */
2834 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2836 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2837 needs
= SYMBOL_NEEDS_REGISTERS
;
2841 /* Helper interface of per_cu_dwarf_call for
2842 dwarf2_loc_desc_get_symbol_read_needs. */
2844 void dwarf_call (cu_offset die_offset
) override
2846 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
2849 /* Helper interface of sect_variable_value for
2850 dwarf2_loc_desc_get_symbol_read_needs. */
2852 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2854 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
2857 /* DW_OP_entry_value accesses require a caller, therefore a
2860 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2861 union call_site_parameter_u kind_u
,
2862 int deref_size
) override
2864 needs
= SYMBOL_NEEDS_FRAME
;
2866 /* The expression may require some stub values on DWARF stack. */
2867 push_address (0, 0);
2870 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2872 CORE_ADDR
get_addr_index (unsigned int index
) override
2874 /* Nothing to do. */
2878 /* DW_OP_push_object_address has a frame already passed through. */
2880 CORE_ADDR
get_object_address () override
2882 /* Nothing to do. */
2887 /* Compute the correct symbol_needs_kind value for the location
2888 expression at DATA (length SIZE). */
2890 static enum symbol_needs_kind
2891 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2892 dwarf2_per_cu_data
*per_cu
,
2893 dwarf2_per_objfile
*per_objfile
)
2895 scoped_value_mark free_values
;
2897 symbol_needs_eval_context
ctx (per_objfile
);
2899 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2900 ctx
.per_cu
= per_cu
;
2901 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2902 ctx
.addr_size
= per_cu
->addr_size ();
2903 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2905 ctx
.eval (data
, size
);
2907 bool in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2909 /* If the location has several pieces, and any of them are in
2910 registers, then we will need a frame to fetch them from. */
2911 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2912 if (p
.location
== DWARF_VALUE_REGISTER
)
2916 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2921 /* A helper function that throws an unimplemented error mentioning a
2922 given DWARF operator. */
2924 static void ATTRIBUTE_NORETURN
2925 unimplemented (unsigned int op
)
2927 const char *name
= get_DW_OP_name (op
);
2930 error (_("DWARF operator %s cannot be translated to an agent expression"),
2933 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2934 "to an agent expression"),
2940 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2941 can issue a complaint, which is better than having every target's
2942 implementation of dwarf2_reg_to_regnum do it. */
2945 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2947 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2951 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2956 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2957 Throw an error because DWARF_REG is bad. */
2960 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2962 /* Still want to print -1 as "-1".
2963 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2964 but that's overkill for now. */
2965 if ((int) dwarf_reg
== dwarf_reg
)
2966 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2967 error (_("Unable to access DWARF register number %s"),
2968 pulongest (dwarf_reg
));
2971 /* See dwarf2loc.h. */
2974 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2978 if (dwarf_reg
> INT_MAX
)
2979 throw_bad_regnum_error (dwarf_reg
);
2980 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2981 bad, but that's ok. */
2982 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2984 throw_bad_regnum_error (dwarf_reg
);
2988 /* A helper function that emits an access to memory. ARCH is the
2989 target architecture. EXPR is the expression which we are building.
2990 NBITS is the number of bits we want to read. This emits the
2991 opcodes needed to read the memory and then extract the desired
2995 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2997 ULONGEST nbytes
= (nbits
+ 7) / 8;
2999 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
3002 ax_trace_quick (expr
, nbytes
);
3005 ax_simple (expr
, aop_ref8
);
3006 else if (nbits
<= 16)
3007 ax_simple (expr
, aop_ref16
);
3008 else if (nbits
<= 32)
3009 ax_simple (expr
, aop_ref32
);
3011 ax_simple (expr
, aop_ref64
);
3013 /* If we read exactly the number of bytes we wanted, we're done. */
3014 if (8 * nbytes
== nbits
)
3017 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
3019 /* On a bits-big-endian machine, we want the high-order
3021 ax_const_l (expr
, 8 * nbytes
- nbits
);
3022 ax_simple (expr
, aop_rsh_unsigned
);
3026 /* On a bits-little-endian box, we want the low-order NBITS. */
3027 ax_zero_ext (expr
, nbits
);
3031 /* Compile a DWARF location expression to an agent expression.
3033 EXPR is the agent expression we are building.
3034 LOC is the agent value we modify.
3035 ARCH is the architecture.
3036 ADDR_SIZE is the size of addresses, in bytes.
3037 OP_PTR is the start of the location expression.
3038 OP_END is one past the last byte of the location expression.
3040 This will throw an exception for various kinds of errors -- for
3041 example, if the expression cannot be compiled, or if the expression
3045 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3046 unsigned int addr_size
, const gdb_byte
*op_ptr
,
3047 const gdb_byte
*op_end
,
3048 dwarf2_per_cu_data
*per_cu
,
3049 dwarf2_per_objfile
*per_objfile
)
3051 gdbarch
*arch
= expr
->gdbarch
;
3052 std::vector
<int> dw_labels
, patches
;
3053 const gdb_byte
* const base
= op_ptr
;
3054 const gdb_byte
*previous_piece
= op_ptr
;
3055 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3056 ULONGEST bits_collected
= 0;
3057 unsigned int addr_size_bits
= 8 * addr_size
;
3058 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
3060 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3062 /* By default we are making an address. */
3063 loc
->kind
= axs_lvalue_memory
;
3065 while (op_ptr
< op_end
)
3067 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3068 uint64_t uoffset
, reg
;
3072 offsets
[op_ptr
- base
] = expr
->len
;
3075 /* Our basic approach to code generation is to map DWARF
3076 operations directly to AX operations. However, there are
3079 First, DWARF works on address-sized units, but AX always uses
3080 LONGEST. For most operations we simply ignore this
3081 difference; instead we generate sign extensions as needed
3082 before division and comparison operations. It would be nice
3083 to omit the sign extensions, but there is no way to determine
3084 the size of the target's LONGEST. (This code uses the size
3085 of the host LONGEST in some cases -- that is a bug but it is
3088 Second, some DWARF operations cannot be translated to AX.
3089 For these we simply fail. See
3090 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3125 ax_const_l (expr
, op
- DW_OP_lit0
);
3129 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3130 op_ptr
+= addr_size
;
3131 /* Some versions of GCC emit DW_OP_addr before
3132 DW_OP_GNU_push_tls_address. In this case the value is an
3133 index, not an address. We don't support things like
3134 branching between the address and the TLS op. */
3135 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3136 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3137 ax_const_l (expr
, uoffset
);
3141 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3146 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3151 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3156 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3161 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3166 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3171 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3176 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3181 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3182 ax_const_l (expr
, uoffset
);
3186 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3187 ax_const_l (expr
, offset
);
3222 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3223 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3224 loc
->kind
= axs_lvalue_register
;
3228 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3229 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3230 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3231 loc
->kind
= axs_lvalue_register
;
3234 case DW_OP_implicit_value
:
3238 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3239 if (op_ptr
+ len
> op_end
)
3240 error (_("DW_OP_implicit_value: too few bytes available."));
3241 if (len
> sizeof (ULONGEST
))
3242 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3245 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3248 dwarf_expr_require_composition (op_ptr
, op_end
,
3249 "DW_OP_implicit_value");
3251 loc
->kind
= axs_rvalue
;
3255 case DW_OP_stack_value
:
3256 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3257 loc
->kind
= axs_rvalue
;
3292 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3293 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3297 ax_const_l (expr
, offset
);
3298 ax_simple (expr
, aop_add
);
3304 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3305 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3306 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3310 ax_const_l (expr
, offset
);
3311 ax_simple (expr
, aop_add
);
3318 const gdb_byte
*datastart
;
3320 const struct block
*b
;
3321 struct symbol
*framefunc
;
3323 b
= block_for_pc (expr
->scope
);
3326 error (_("No block found for address"));
3328 framefunc
= block_linkage_function (b
);
3331 error (_("No function found for block"));
3333 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3334 &datastart
, &datalen
);
3336 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3337 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3338 datastart
+ datalen
, per_cu
,
3340 if (loc
->kind
== axs_lvalue_register
)
3341 require_rvalue (expr
, loc
);
3345 ax_const_l (expr
, offset
);
3346 ax_simple (expr
, aop_add
);
3349 loc
->kind
= axs_lvalue_memory
;
3354 ax_simple (expr
, aop_dup
);
3358 ax_simple (expr
, aop_pop
);
3363 ax_pick (expr
, offset
);
3367 ax_simple (expr
, aop_swap
);
3375 ax_simple (expr
, aop_rot
);
3379 case DW_OP_deref_size
:
3383 if (op
== DW_OP_deref_size
)
3388 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3389 error (_("Unsupported size %d in %s"),
3390 size
, get_DW_OP_name (op
));
3391 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3396 /* Sign extend the operand. */
3397 ax_ext (expr
, addr_size_bits
);
3398 ax_simple (expr
, aop_dup
);
3399 ax_const_l (expr
, 0);
3400 ax_simple (expr
, aop_less_signed
);
3401 ax_simple (expr
, aop_log_not
);
3402 i
= ax_goto (expr
, aop_if_goto
);
3403 /* We have to emit 0 - X. */
3404 ax_const_l (expr
, 0);
3405 ax_simple (expr
, aop_swap
);
3406 ax_simple (expr
, aop_sub
);
3407 ax_label (expr
, i
, expr
->len
);
3411 /* No need to sign extend here. */
3412 ax_const_l (expr
, 0);
3413 ax_simple (expr
, aop_swap
);
3414 ax_simple (expr
, aop_sub
);
3418 /* Sign extend the operand. */
3419 ax_ext (expr
, addr_size_bits
);
3420 ax_simple (expr
, aop_bit_not
);
3423 case DW_OP_plus_uconst
:
3424 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3425 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3426 but we micro-optimize anyhow. */
3429 ax_const_l (expr
, reg
);
3430 ax_simple (expr
, aop_add
);
3435 ax_simple (expr
, aop_bit_and
);
3439 /* Sign extend the operands. */
3440 ax_ext (expr
, addr_size_bits
);
3441 ax_simple (expr
, aop_swap
);
3442 ax_ext (expr
, addr_size_bits
);
3443 ax_simple (expr
, aop_swap
);
3444 ax_simple (expr
, aop_div_signed
);
3448 ax_simple (expr
, aop_sub
);
3452 ax_simple (expr
, aop_rem_unsigned
);
3456 ax_simple (expr
, aop_mul
);
3460 ax_simple (expr
, aop_bit_or
);
3464 ax_simple (expr
, aop_add
);
3468 ax_simple (expr
, aop_lsh
);
3472 ax_simple (expr
, aop_rsh_unsigned
);
3476 ax_simple (expr
, aop_rsh_signed
);
3480 ax_simple (expr
, aop_bit_xor
);
3484 /* Sign extend the operands. */
3485 ax_ext (expr
, addr_size_bits
);
3486 ax_simple (expr
, aop_swap
);
3487 ax_ext (expr
, addr_size_bits
);
3488 /* Note no swap here: A <= B is !(B < A). */
3489 ax_simple (expr
, aop_less_signed
);
3490 ax_simple (expr
, aop_log_not
);
3494 /* Sign extend the operands. */
3495 ax_ext (expr
, addr_size_bits
);
3496 ax_simple (expr
, aop_swap
);
3497 ax_ext (expr
, addr_size_bits
);
3498 ax_simple (expr
, aop_swap
);
3499 /* A >= B is !(A < B). */
3500 ax_simple (expr
, aop_less_signed
);
3501 ax_simple (expr
, aop_log_not
);
3505 /* Sign extend the operands. */
3506 ax_ext (expr
, addr_size_bits
);
3507 ax_simple (expr
, aop_swap
);
3508 ax_ext (expr
, addr_size_bits
);
3509 /* No need for a second swap here. */
3510 ax_simple (expr
, aop_equal
);
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_less_signed
);
3523 /* Sign extend the operands. */
3524 ax_ext (expr
, addr_size_bits
);
3525 ax_simple (expr
, aop_swap
);
3526 ax_ext (expr
, addr_size_bits
);
3527 /* Note no swap here: A > B is B < A. */
3528 ax_simple (expr
, aop_less_signed
);
3532 /* Sign extend the operands. */
3533 ax_ext (expr
, addr_size_bits
);
3534 ax_simple (expr
, aop_swap
);
3535 ax_ext (expr
, addr_size_bits
);
3536 /* No need for a swap here. */
3537 ax_simple (expr
, aop_equal
);
3538 ax_simple (expr
, aop_log_not
);
3541 case DW_OP_call_frame_cfa
:
3544 CORE_ADDR text_offset
;
3546 const gdb_byte
*cfa_start
, *cfa_end
;
3548 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3550 &text_offset
, &cfa_start
, &cfa_end
))
3553 ax_reg (expr
, regnum
);
3556 ax_const_l (expr
, off
);
3557 ax_simple (expr
, aop_add
);
3562 /* Another expression. */
3563 ax_const_l (expr
, text_offset
);
3564 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3565 cfa_end
, per_cu
, per_objfile
);
3568 loc
->kind
= axs_lvalue_memory
;
3572 case DW_OP_GNU_push_tls_address
:
3573 case DW_OP_form_tls_address
:
3577 case DW_OP_push_object_address
:
3582 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3584 i
= ax_goto (expr
, aop_goto
);
3585 dw_labels
.push_back (op_ptr
+ offset
- base
);
3586 patches
.push_back (i
);
3590 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3592 /* Zero extend the operand. */
3593 ax_zero_ext (expr
, addr_size_bits
);
3594 i
= ax_goto (expr
, aop_if_goto
);
3595 dw_labels
.push_back (op_ptr
+ offset
- base
);
3596 patches
.push_back (i
);
3603 case DW_OP_bit_piece
:
3607 if (op_ptr
- 1 == previous_piece
)
3608 error (_("Cannot translate empty pieces to agent expressions"));
3609 previous_piece
= op_ptr
- 1;
3611 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3612 if (op
== DW_OP_piece
)
3618 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3620 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3621 error (_("Expression pieces exceed word size"));
3623 /* Access the bits. */
3626 case axs_lvalue_register
:
3627 ax_reg (expr
, loc
->u
.reg
);
3630 case axs_lvalue_memory
:
3631 /* Offset the pointer, if needed. */
3634 ax_const_l (expr
, uoffset
/ 8);
3635 ax_simple (expr
, aop_add
);
3638 access_memory (arch
, expr
, size
);
3642 /* For a bits-big-endian target, shift up what we already
3643 have. For a bits-little-endian target, shift up the
3644 new data. Note that there is a potential bug here if
3645 the DWARF expression leaves multiple values on the
3647 if (bits_collected
> 0)
3649 if (bits_big_endian
)
3651 ax_simple (expr
, aop_swap
);
3652 ax_const_l (expr
, size
);
3653 ax_simple (expr
, aop_lsh
);
3654 /* We don't need a second swap here, because
3655 aop_bit_or is symmetric. */
3659 ax_const_l (expr
, size
);
3660 ax_simple (expr
, aop_lsh
);
3662 ax_simple (expr
, aop_bit_or
);
3665 bits_collected
+= size
;
3666 loc
->kind
= axs_rvalue
;
3670 case DW_OP_GNU_uninit
:
3676 struct dwarf2_locexpr_baton block
;
3677 int size
= (op
== DW_OP_call2
? 2 : 4);
3679 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3682 auto get_frame_pc_from_expr
= [expr
] ()
3686 cu_offset cuoffset
= (cu_offset
) uoffset
;
3687 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3688 get_frame_pc_from_expr
);
3690 /* DW_OP_call_ref is currently not supported. */
3691 gdb_assert (block
.per_cu
== per_cu
);
3693 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3694 block
.data
+ block
.size
, per_cu
,
3699 case DW_OP_call_ref
:
3702 case DW_OP_GNU_variable_value
:
3710 /* Patch all the branches we emitted. */
3711 for (int i
= 0; i
< patches
.size (); ++i
)
3713 int targ
= offsets
[dw_labels
[i
]];
3715 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3716 ax_label (expr
, patches
[i
], targ
);
3721 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3722 evaluator to calculate the location. */
3723 static struct value
*
3724 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3726 struct dwarf2_locexpr_baton
*dlbaton
3727 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3730 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3731 dlbaton
->size
, dlbaton
->per_cu
,
3732 dlbaton
->per_objfile
);
3737 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3738 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3741 static struct value
*
3742 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3744 struct dwarf2_locexpr_baton
*dlbaton
3745 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3747 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3751 /* Implementation of get_symbol_read_needs from
3752 symbol_computed_ops. */
3754 static enum symbol_needs_kind
3755 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3757 struct dwarf2_locexpr_baton
*dlbaton
3758 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3760 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3762 dlbaton
->per_objfile
);
3765 /* Return true if DATA points to the end of a piece. END is one past
3766 the last byte in the expression. */
3769 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3771 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3774 /* Helper for locexpr_describe_location_piece that finds the name of a
3778 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3782 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3783 We'd rather print *something* here than throw an error. */
3784 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3785 /* gdbarch_register_name may just return "", return something more
3786 descriptive for bad register numbers. */
3789 /* The text is output as "$bad_register_number".
3790 That is why we use the underscores. */
3791 return _("bad_register_number");
3793 return gdbarch_register_name (gdbarch
, regnum
);
3796 /* Nicely describe a single piece of a location, returning an updated
3797 position in the bytecode sequence. This function cannot recognize
3798 all locations; if a location is not recognized, it simply returns
3799 DATA. If there is an error during reading, e.g. we run off the end
3800 of the buffer, an error is thrown. */
3802 static const gdb_byte
*
3803 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3804 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3805 dwarf2_per_objfile
*per_objfile
,
3806 const gdb_byte
*data
, const gdb_byte
*end
,
3807 unsigned int addr_size
)
3809 objfile
*objfile
= per_objfile
->objfile
;
3810 struct gdbarch
*gdbarch
= objfile
->arch ();
3813 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3815 fprintf_filtered (stream
, _("a variable in $%s"),
3816 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3819 else if (data
[0] == DW_OP_regx
)
3823 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3824 fprintf_filtered (stream
, _("a variable in $%s"),
3825 locexpr_regname (gdbarch
, reg
));
3827 else if (data
[0] == DW_OP_fbreg
)
3829 const struct block
*b
;
3830 struct symbol
*framefunc
;
3832 int64_t frame_offset
;
3833 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3835 int64_t base_offset
= 0;
3837 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3838 if (!piece_end_p (new_data
, end
))
3842 b
= block_for_pc (addr
);
3845 error (_("No block found for address for symbol \"%s\"."),
3846 symbol
->print_name ());
3848 framefunc
= block_linkage_function (b
);
3851 error (_("No function found for block for symbol \"%s\"."),
3852 symbol
->print_name ());
3854 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3856 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3858 const gdb_byte
*buf_end
;
3860 frame_reg
= base_data
[0] - DW_OP_breg0
;
3861 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3863 if (buf_end
!= base_data
+ base_size
)
3864 error (_("Unexpected opcode after "
3865 "DW_OP_breg%u for symbol \"%s\"."),
3866 frame_reg
, symbol
->print_name ());
3868 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3870 /* The frame base is just the register, with no offset. */
3871 frame_reg
= base_data
[0] - DW_OP_reg0
;
3876 /* We don't know what to do with the frame base expression,
3877 so we can't trace this variable; give up. */
3881 fprintf_filtered (stream
,
3882 _("a variable at frame base reg $%s offset %s+%s"),
3883 locexpr_regname (gdbarch
, frame_reg
),
3884 plongest (base_offset
), plongest (frame_offset
));
3886 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3887 && piece_end_p (data
, end
))
3891 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3893 fprintf_filtered (stream
,
3894 _("a variable at offset %s from base reg $%s"),
3896 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3899 /* The location expression for a TLS variable looks like this (on a
3902 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3903 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3905 0x3 is the encoding for DW_OP_addr, which has an operand as long
3906 as the size of an address on the target machine (here is 8
3907 bytes). Note that more recent version of GCC emit DW_OP_const4u
3908 or DW_OP_const8u, depending on address size, rather than
3909 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3910 The operand represents the offset at which the variable is within
3911 the thread local storage. */
3913 else if (data
+ 1 + addr_size
< end
3914 && (data
[0] == DW_OP_addr
3915 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3916 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3917 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3918 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3919 && piece_end_p (data
+ 2 + addr_size
, end
))
3922 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3923 gdbarch_byte_order (gdbarch
));
3925 fprintf_filtered (stream
,
3926 _("a thread-local variable at offset 0x%s "
3927 "in the thread-local storage for `%s'"),
3928 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3930 data
+= 1 + addr_size
+ 1;
3933 /* With -gsplit-dwarf a TLS variable can also look like this:
3934 DW_AT_location : 3 byte block: fc 4 e0
3935 (DW_OP_GNU_const_index: 4;
3936 DW_OP_GNU_push_tls_address) */
3937 else if (data
+ 3 <= end
3938 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3939 && data
[0] == DW_OP_GNU_const_index
3941 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3942 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3943 && piece_end_p (data
+ 2 + leb128_size
, end
))
3947 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3948 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3949 fprintf_filtered (stream
,
3950 _("a thread-local variable at offset 0x%s "
3951 "in the thread-local storage for `%s'"),
3952 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3956 else if (data
[0] >= DW_OP_lit0
3957 && data
[0] <= DW_OP_lit31
3959 && data
[1] == DW_OP_stack_value
)
3961 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3968 /* Disassemble an expression, stopping at the end of a piece or at the
3969 end of the expression. Returns a pointer to the next unread byte
3970 in the input expression. If ALL is nonzero, then this function
3971 will keep going until it reaches the end of the expression.
3972 If there is an error during reading, e.g. we run off the end
3973 of the buffer, an error is thrown. */
3975 static const gdb_byte
*
3976 disassemble_dwarf_expression (struct ui_file
*stream
,
3977 struct gdbarch
*arch
, unsigned int addr_size
,
3978 int offset_size
, const gdb_byte
*start
,
3979 const gdb_byte
*data
, const gdb_byte
*end
,
3980 int indent
, int all
,
3981 dwarf2_per_cu_data
*per_cu
,
3982 dwarf2_per_objfile
*per_objfile
)
3986 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3988 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3993 name
= get_DW_OP_name (op
);
3996 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3997 op
, (long) (data
- 1 - start
));
3998 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3999 (long) (data
- 1 - start
), name
);
4004 ul
= extract_unsigned_integer (data
, addr_size
,
4005 gdbarch_byte_order (arch
));
4007 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4011 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
4013 fprintf_filtered (stream
, " %s", pulongest (ul
));
4017 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
4019 fprintf_filtered (stream
, " %s", plongest (l
));
4023 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4025 fprintf_filtered (stream
, " %s", pulongest (ul
));
4029 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4031 fprintf_filtered (stream
, " %s", plongest (l
));
4035 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4037 fprintf_filtered (stream
, " %s", pulongest (ul
));
4041 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4043 fprintf_filtered (stream
, " %s", plongest (l
));
4047 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4049 fprintf_filtered (stream
, " %s", pulongest (ul
));
4053 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4055 fprintf_filtered (stream
, " %s", plongest (l
));
4059 data
= safe_read_uleb128 (data
, end
, &ul
);
4060 fprintf_filtered (stream
, " %s", pulongest (ul
));
4064 data
= safe_read_sleb128 (data
, end
, &l
);
4065 fprintf_filtered (stream
, " %s", plongest (l
));
4100 fprintf_filtered (stream
, " [$%s]",
4101 locexpr_regname (arch
, op
- DW_OP_reg0
));
4105 data
= safe_read_uleb128 (data
, end
, &ul
);
4106 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4107 locexpr_regname (arch
, (int) ul
));
4110 case DW_OP_implicit_value
:
4111 data
= safe_read_uleb128 (data
, end
, &ul
);
4113 fprintf_filtered (stream
, " %s", pulongest (ul
));
4148 data
= safe_read_sleb128 (data
, end
, &l
);
4149 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4150 locexpr_regname (arch
, op
- DW_OP_breg0
));
4154 data
= safe_read_uleb128 (data
, end
, &ul
);
4155 data
= safe_read_sleb128 (data
, end
, &l
);
4156 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4158 locexpr_regname (arch
, (int) ul
),
4163 data
= safe_read_sleb128 (data
, end
, &l
);
4164 fprintf_filtered (stream
, " %s", plongest (l
));
4167 case DW_OP_xderef_size
:
4168 case DW_OP_deref_size
:
4170 fprintf_filtered (stream
, " %d", *data
);
4174 case DW_OP_plus_uconst
:
4175 data
= safe_read_uleb128 (data
, end
, &ul
);
4176 fprintf_filtered (stream
, " %s", pulongest (ul
));
4180 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4182 fprintf_filtered (stream
, " to %ld",
4183 (long) (data
+ l
- start
));
4187 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4189 fprintf_filtered (stream
, " %ld",
4190 (long) (data
+ l
- start
));
4194 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4196 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4200 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4202 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4205 case DW_OP_call_ref
:
4206 ul
= extract_unsigned_integer (data
, offset_size
,
4207 gdbarch_byte_order (arch
));
4208 data
+= offset_size
;
4209 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4213 data
= safe_read_uleb128 (data
, end
, &ul
);
4214 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4217 case DW_OP_bit_piece
:
4221 data
= safe_read_uleb128 (data
, end
, &ul
);
4222 data
= safe_read_uleb128 (data
, end
, &offset
);
4223 fprintf_filtered (stream
, " size %s offset %s (bits)",
4224 pulongest (ul
), pulongest (offset
));
4228 case DW_OP_implicit_pointer
:
4229 case DW_OP_GNU_implicit_pointer
:
4231 ul
= extract_unsigned_integer (data
, offset_size
,
4232 gdbarch_byte_order (arch
));
4233 data
+= offset_size
;
4235 data
= safe_read_sleb128 (data
, end
, &l
);
4237 fprintf_filtered (stream
, " DIE %s offset %s",
4238 phex_nz (ul
, offset_size
),
4243 case DW_OP_deref_type
:
4244 case DW_OP_GNU_deref_type
:
4246 int deref_addr_size
= *data
++;
4249 data
= safe_read_uleb128 (data
, end
, &ul
);
4250 cu_offset offset
= (cu_offset
) ul
;
4251 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
4252 fprintf_filtered (stream
, "<");
4253 type_print (type
, "", stream
, -1);
4254 fprintf_filtered (stream
, " [0x%s]> %d",
4255 phex_nz (to_underlying (offset
), 0),
4260 case DW_OP_const_type
:
4261 case DW_OP_GNU_const_type
:
4265 data
= safe_read_uleb128 (data
, end
, &ul
);
4266 cu_offset type_die
= (cu_offset
) ul
;
4267 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4268 fprintf_filtered (stream
, "<");
4269 type_print (type
, "", stream
, -1);
4270 fprintf_filtered (stream
, " [0x%s]>",
4271 phex_nz (to_underlying (type_die
), 0));
4274 fprintf_filtered (stream
, " %d byte block:", n
);
4275 for (int i
= 0; i
< n
; ++i
)
4276 fprintf_filtered (stream
, " %02x", data
[i
]);
4281 case DW_OP_regval_type
:
4282 case DW_OP_GNU_regval_type
:
4287 data
= safe_read_uleb128 (data
, end
, ®
);
4288 data
= safe_read_uleb128 (data
, end
, &ul
);
4289 cu_offset type_die
= (cu_offset
) ul
;
4291 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4292 fprintf_filtered (stream
, "<");
4293 type_print (type
, "", stream
, -1);
4294 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4295 phex_nz (to_underlying (type_die
), 0),
4296 locexpr_regname (arch
, reg
));
4301 case DW_OP_GNU_convert
:
4302 case DW_OP_reinterpret
:
4303 case DW_OP_GNU_reinterpret
:
4305 data
= safe_read_uleb128 (data
, end
, &ul
);
4306 cu_offset type_die
= (cu_offset
) ul
;
4308 if (to_underlying (type_die
) == 0)
4309 fprintf_filtered (stream
, "<0>");
4314 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4315 fprintf_filtered (stream
, "<");
4316 type_print (type
, "", stream
, -1);
4317 fprintf_filtered (stream
, " [0x%s]>",
4318 phex_nz (to_underlying (type_die
), 0));
4323 case DW_OP_entry_value
:
4324 case DW_OP_GNU_entry_value
:
4325 data
= safe_read_uleb128 (data
, end
, &ul
);
4326 fputc_filtered ('\n', stream
);
4327 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4328 start
, data
, data
+ ul
, indent
+ 2,
4329 all
, per_cu
, per_objfile
);
4333 case DW_OP_GNU_parameter_ref
:
4334 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4336 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4340 case DW_OP_GNU_addr_index
:
4341 data
= safe_read_uleb128 (data
, end
, &ul
);
4342 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4343 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4346 case DW_OP_GNU_const_index
:
4347 data
= safe_read_uleb128 (data
, end
, &ul
);
4348 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4349 fprintf_filtered (stream
, " %s", pulongest (ul
));
4352 case DW_OP_GNU_variable_value
:
4353 ul
= extract_unsigned_integer (data
, offset_size
,
4354 gdbarch_byte_order (arch
));
4355 data
+= offset_size
;
4356 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4360 fprintf_filtered (stream
, "\n");
4366 static bool dwarf_always_disassemble
;
4369 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4370 struct cmd_list_element
*c
, const char *value
)
4372 fprintf_filtered (file
,
4373 _("Whether to always disassemble "
4374 "DWARF expressions is %s.\n"),
4378 /* Describe a single location, which may in turn consist of multiple
4382 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4383 struct ui_file
*stream
,
4384 const gdb_byte
*data
, size_t size
,
4385 unsigned int addr_size
,
4386 int offset_size
, dwarf2_per_cu_data
*per_cu
,
4387 dwarf2_per_objfile
*per_objfile
)
4389 const gdb_byte
*end
= data
+ size
;
4390 int first_piece
= 1, bad
= 0;
4391 objfile
*objfile
= per_objfile
->objfile
;
4395 const gdb_byte
*here
= data
;
4396 int disassemble
= 1;
4401 fprintf_filtered (stream
, _(", and "));
4403 if (!dwarf_always_disassemble
)
4405 data
= locexpr_describe_location_piece (symbol
, stream
,
4406 addr
, per_cu
, per_objfile
,
4407 data
, end
, addr_size
);
4408 /* If we printed anything, or if we have an empty piece,
4409 then don't disassemble. */
4411 || data
[0] == DW_OP_piece
4412 || data
[0] == DW_OP_bit_piece
)
4417 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4418 data
= disassemble_dwarf_expression (stream
,
4420 addr_size
, offset_size
, data
,
4422 dwarf_always_disassemble
,
4423 per_cu
, per_objfile
);
4428 int empty
= data
== here
;
4431 fprintf_filtered (stream
, " ");
4432 if (data
[0] == DW_OP_piece
)
4436 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4439 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4442 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4445 else if (data
[0] == DW_OP_bit_piece
)
4447 uint64_t bits
, offset
;
4449 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4450 data
= safe_read_uleb128 (data
, end
, &offset
);
4453 fprintf_filtered (stream
,
4454 _("an empty %s-bit piece"),
4457 fprintf_filtered (stream
,
4458 _(" [%s-bit piece, offset %s bits]"),
4459 pulongest (bits
), pulongest (offset
));
4469 if (bad
|| data
> end
)
4470 error (_("Corrupted DWARF2 expression for \"%s\"."),
4471 symbol
->print_name ());
4474 /* Print a natural-language description of SYMBOL to STREAM. This
4475 version is for a symbol with a single location. */
4478 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4479 struct ui_file
*stream
)
4481 struct dwarf2_locexpr_baton
*dlbaton
4482 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4483 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4484 int offset_size
= dlbaton
->per_cu
->offset_size ();
4486 locexpr_describe_location_1 (symbol
, addr
, stream
,
4487 dlbaton
->data
, dlbaton
->size
,
4488 addr_size
, offset_size
,
4489 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4492 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4493 any necessary bytecode in AX. */
4496 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4497 struct axs_value
*value
)
4499 struct dwarf2_locexpr_baton
*dlbaton
4500 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4501 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4503 if (dlbaton
->size
== 0)
4504 value
->optimized_out
= 1;
4506 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4507 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4508 dlbaton
->per_objfile
);
4511 /* symbol_computed_ops 'generate_c_location' method. */
4514 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4515 struct gdbarch
*gdbarch
,
4516 std::vector
<bool> ®isters_used
,
4517 CORE_ADDR pc
, const char *result_name
)
4519 struct dwarf2_locexpr_baton
*dlbaton
4520 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4521 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4523 if (dlbaton
->size
== 0)
4524 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4526 compile_dwarf_expr_to_c (stream
, result_name
,
4527 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4528 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4529 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4532 /* The set of location functions used with the DWARF-2 expression
4534 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4535 locexpr_read_variable
,
4536 locexpr_read_variable_at_entry
,
4537 locexpr_get_symbol_read_needs
,
4538 locexpr_describe_location
,
4539 0, /* location_has_loclist */
4540 locexpr_tracepoint_var_ref
,
4541 locexpr_generate_c_location
4545 /* Wrapper functions for location lists. These generally find
4546 the appropriate location expression and call something above. */
4548 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4549 evaluator to calculate the location. */
4550 static struct value
*
4551 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4553 struct dwarf2_loclist_baton
*dlbaton
4554 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4556 const gdb_byte
*data
;
4558 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4560 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4561 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4562 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4567 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4568 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4571 Function always returns non-NULL value, it may be marked optimized out if
4572 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4573 if it cannot resolve the parameter for any reason. */
4575 static struct value
*
4576 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4578 struct dwarf2_loclist_baton
*dlbaton
4579 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4580 const gdb_byte
*data
;
4584 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4585 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4587 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4589 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4591 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4594 /* Implementation of get_symbol_read_needs from
4595 symbol_computed_ops. */
4597 static enum symbol_needs_kind
4598 loclist_symbol_needs (struct symbol
*symbol
)
4600 /* If there's a location list, then assume we need to have a frame
4601 to choose the appropriate location expression. With tracking of
4602 global variables this is not necessarily true, but such tracking
4603 is disabled in GCC at the moment until we figure out how to
4606 return SYMBOL_NEEDS_FRAME
;
4609 /* Print a natural-language description of SYMBOL to STREAM. This
4610 version applies when there is a list of different locations, each
4611 with a specified address range. */
4614 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4615 struct ui_file
*stream
)
4617 struct dwarf2_loclist_baton
*dlbaton
4618 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4619 const gdb_byte
*loc_ptr
, *buf_end
;
4620 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4621 struct objfile
*objfile
= per_objfile
->objfile
;
4622 struct gdbarch
*gdbarch
= objfile
->arch ();
4623 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4624 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4625 int offset_size
= dlbaton
->per_cu
->offset_size ();
4626 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4627 /* Adjust base_address for relocatable objects. */
4628 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4629 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4632 loc_ptr
= dlbaton
->data
;
4633 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4635 fprintf_filtered (stream
, _("multi-location:\n"));
4637 /* Iterate through locations until we run out. */
4640 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4642 enum debug_loc_kind kind
;
4643 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4645 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4646 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4647 dlbaton
->per_objfile
,
4648 loc_ptr
, buf_end
, &new_ptr
,
4649 &low
, &high
, byte_order
);
4650 else if (dlbaton
->per_cu
->version () < 5)
4651 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4653 byte_order
, addr_size
,
4656 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4657 dlbaton
->per_objfile
,
4658 loc_ptr
, buf_end
, &new_ptr
,
4659 &low
, &high
, byte_order
,
4660 addr_size
, signed_addr_p
);
4664 case DEBUG_LOC_END_OF_LIST
:
4668 case DEBUG_LOC_BASE_ADDRESS
:
4669 base_address
= high
+ base_offset
;
4670 fprintf_filtered (stream
, _(" Base address %s"),
4671 paddress (gdbarch
, base_address
));
4674 case DEBUG_LOC_START_END
:
4675 case DEBUG_LOC_START_LENGTH
:
4676 case DEBUG_LOC_OFFSET_PAIR
:
4679 case DEBUG_LOC_BUFFER_OVERFLOW
:
4680 case DEBUG_LOC_INVALID_ENTRY
:
4681 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4682 symbol
->print_name ());
4685 gdb_assert_not_reached ("bad debug_loc_kind");
4688 /* Otherwise, a location expression entry. */
4689 low
+= base_address
;
4690 high
+= base_address
;
4692 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4693 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4695 if (dlbaton
->per_cu
->version () < 5)
4697 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4702 unsigned int bytes_read
;
4703 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4704 loc_ptr
+= bytes_read
;
4707 /* (It would improve readability to print only the minimum
4708 necessary digits of the second number of the range.) */
4709 fprintf_filtered (stream
, _(" Range %s-%s: "),
4710 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4712 /* Now describe this particular location. */
4713 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4714 addr_size
, offset_size
,
4715 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4717 fprintf_filtered (stream
, "\n");
4723 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4724 any necessary bytecode in AX. */
4726 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4727 struct axs_value
*value
)
4729 struct dwarf2_loclist_baton
*dlbaton
4730 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4731 const gdb_byte
*data
;
4733 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4735 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4737 value
->optimized_out
= 1;
4739 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4740 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4743 /* symbol_computed_ops 'generate_c_location' method. */
4746 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4747 struct gdbarch
*gdbarch
,
4748 std::vector
<bool> ®isters_used
,
4749 CORE_ADDR pc
, const char *result_name
)
4751 struct dwarf2_loclist_baton
*dlbaton
4752 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4753 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4754 const gdb_byte
*data
;
4757 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4759 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4761 compile_dwarf_expr_to_c (stream
, result_name
,
4762 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4765 dlbaton
->per_objfile
);
4768 /* The set of location functions used with the DWARF-2 expression
4769 evaluator and location lists. */
4770 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4771 loclist_read_variable
,
4772 loclist_read_variable_at_entry
,
4773 loclist_symbol_needs
,
4774 loclist_describe_location
,
4775 1, /* location_has_loclist */
4776 loclist_tracepoint_var_ref
,
4777 loclist_generate_c_location
4780 void _initialize_dwarf2loc ();
4782 _initialize_dwarf2loc ()
4784 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4785 &entry_values_debug
,
4786 _("Set entry values and tail call frames "
4788 _("Show entry values and tail call frames "
4790 _("When non-zero, the process of determining "
4791 "parameter values from function entry point "
4792 "and tail call frames will be printed."),
4794 show_entry_values_debug
,
4795 &setdebuglist
, &showdebuglist
);
4797 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4798 &dwarf_always_disassemble
, _("\
4799 Set whether `info address' always disassembles DWARF expressions."), _("\
4800 Show whether `info address' always disassembles DWARF expressions."), _("\
4801 When enabled, DWARF expressions are always printed in an assembly-like\n\
4802 syntax. When disabled, expressions will be printed in a more\n\
4803 conversational style, when possible."),
4805 show_dwarf_always_disassemble
,
4807 &show_dwarf_cmdlist
);