1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2020 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 /* Given context CTX, section offset SECT_OFF, and compilation unit
624 data PER_CU, execute the "variable value" operation on the DIE
625 found at SECT_OFF. */
627 static struct value
*
628 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
629 dwarf2_per_cu_data
*per_cu
,
630 dwarf2_per_objfile
*per_objfile
)
632 struct type
*die_type
633 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
, per_objfile
);
635 if (die_type
== NULL
)
636 error (_("Bad DW_OP_GNU_variable_value DIE."));
638 /* Note: Things still work when the following test is removed. This
639 test and error is here to conform to the proposed specification. */
640 if (die_type
->code () != TYPE_CODE_INT
641 && die_type
->code () != TYPE_CODE_PTR
)
642 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
644 struct type
*type
= lookup_pointer_type (die_type
);
645 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
646 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, per_objfile
, frame
,
650 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
653 dwarf_evaluate_loc_desc (dwarf2_per_objfile
*per_objfile
)
654 : dwarf_expr_context (per_objfile
)
657 struct frame_info
*frame
;
658 struct dwarf2_per_cu_data
*per_cu
;
659 CORE_ADDR obj_address
;
661 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
662 the frame in BATON. */
664 CORE_ADDR
get_frame_cfa () override
666 return dwarf2_frame_cfa (frame
);
669 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
670 the frame in BATON. */
672 CORE_ADDR
get_frame_pc () override
674 return get_frame_address_in_block (frame
);
677 /* Using the objfile specified in BATON, find the address for the
678 current thread's thread-local storage with offset OFFSET. */
679 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
681 return target_translate_tls_address (per_objfile
->objfile
, offset
);
684 /* Helper interface of per_cu_dwarf_call for
685 dwarf2_evaluate_loc_desc. */
687 void dwarf_call (cu_offset die_offset
) override
689 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
692 /* Helper interface of sect_variable_value for
693 dwarf2_evaluate_loc_desc. */
695 struct value
*dwarf_variable_value (sect_offset sect_off
) override
697 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
700 struct type
*get_base_type (cu_offset die_offset
, int size
) override
702 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
, per_objfile
);
704 error (_("Could not find type for DW_OP_const_type"));
705 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
706 error (_("DW_OP_const_type has different sizes for type and data"));
710 /* Callback function for dwarf2_evaluate_loc_desc.
711 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
713 CORE_ADDR
get_addr_index (unsigned int index
) override
715 return dwarf2_read_addr_index (per_cu
, per_objfile
, index
);
718 /* Callback function for get_object_address. Return the address of the VLA
721 CORE_ADDR
get_object_address () override
723 if (obj_address
== 0)
724 error (_("Location address is not set."));
728 /* Execute DWARF block of call_site_parameter which matches KIND and
729 KIND_U. Choose DEREF_SIZE value of that parameter. Search
730 caller of this objects's frame.
732 The caller can be from a different CU - per_cu_dwarf_call
733 implementation can be more simple as it does not support cross-CU
736 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
737 union call_site_parameter_u kind_u
,
738 int deref_size
) override
740 struct frame_info
*caller_frame
;
741 dwarf2_per_cu_data
*caller_per_cu
;
742 dwarf2_per_objfile
*caller_per_objfile
;
743 struct call_site_parameter
*parameter
;
744 const gdb_byte
*data_src
;
747 caller_frame
= get_prev_frame (frame
);
749 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
751 &caller_per_objfile
);
752 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
753 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
755 /* DEREF_SIZE size is not verified here. */
756 if (data_src
== NULL
)
757 throw_error (NO_ENTRY_VALUE_ERROR
,
758 _("Cannot resolve DW_AT_call_data_value"));
760 /* We are about to evaluate an expression in the context of the caller
761 of the current frame. This evaluation context may be different from
762 the current (callee's) context), so temporarily set the caller's context.
764 It is possible for the caller to be from a different objfile from the
765 callee if the call is made through a function pointer. */
766 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
768 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
770 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
772 scoped_restore save_per_objfile
= make_scoped_restore (&this->per_objfile
,
775 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
776 this->gdbarch
= this->per_objfile
->objfile
->arch ();
777 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
778 this->addr_size
= this->per_cu
->addr_size ();
780 this->eval (data_src
, size
);
783 /* Using the frame specified in BATON, find the location expression
784 describing the frame base. Return a pointer to it in START and
785 its length in LENGTH. */
786 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
788 /* FIXME: cagney/2003-03-26: This code should be using
789 get_frame_base_address(), and then implement a dwarf2 specific
791 struct symbol
*framefunc
;
792 const struct block
*bl
= get_frame_block (frame
, NULL
);
795 error (_("frame address is not available."));
797 /* Use block_linkage_function, which returns a real (not inlined)
798 function, instead of get_frame_function, which may return an
800 framefunc
= block_linkage_function (bl
);
802 /* If we found a frame-relative symbol then it was certainly within
803 some function associated with a frame. If we can't find the frame,
804 something has gone wrong. */
805 gdb_assert (framefunc
!= NULL
);
807 func_get_frame_base_dwarf_block (framefunc
,
808 get_frame_address_in_block (frame
),
812 /* Read memory at ADDR (length LEN) into BUF. */
814 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
816 read_memory (addr
, buf
, len
);
819 /* Using the frame specified in BATON, return the value of register
820 REGNUM, treated as a pointer. */
821 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
823 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
824 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
826 return address_from_register (regnum
, frame
);
829 /* Implement "get_reg_value" callback. */
831 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
833 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
834 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
836 return value_from_register (type
, regnum
, frame
);
840 /* See dwarf2loc.h. */
842 unsigned int entry_values_debug
= 0;
844 /* Helper to set entry_values_debug. */
847 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
848 struct cmd_list_element
*c
, const char *value
)
850 fprintf_filtered (file
,
851 _("Entry values and tail call frames debugging is %s.\n"),
855 /* Find DW_TAG_call_site's DW_AT_call_target address.
856 CALLER_FRAME (for registers) can be NULL if it is not known. This function
857 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
860 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
861 struct call_site
*call_site
,
862 struct frame_info
*caller_frame
)
864 switch (FIELD_LOC_KIND (call_site
->target
))
866 case FIELD_LOC_KIND_DWARF_BLOCK
:
868 struct dwarf2_locexpr_baton
*dwarf_block
;
870 struct type
*caller_core_addr_type
;
871 struct gdbarch
*caller_arch
;
873 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
874 if (dwarf_block
== NULL
)
876 struct bound_minimal_symbol msym
;
878 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
879 throw_error (NO_ENTRY_VALUE_ERROR
,
880 _("DW_AT_call_target is not specified at %s in %s"),
881 paddress (call_site_gdbarch
, call_site
->pc
),
882 (msym
.minsym
== NULL
? "???"
883 : msym
.minsym
->print_name ()));
886 if (caller_frame
== NULL
)
888 struct bound_minimal_symbol msym
;
890 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
891 throw_error (NO_ENTRY_VALUE_ERROR
,
892 _("DW_AT_call_target DWARF block resolving "
893 "requires known frame which is currently not "
894 "available at %s in %s"),
895 paddress (call_site_gdbarch
, call_site
->pc
),
896 (msym
.minsym
== NULL
? "???"
897 : msym
.minsym
->print_name ()));
900 caller_arch
= get_frame_arch (caller_frame
);
901 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
902 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
903 dwarf_block
->data
, dwarf_block
->size
,
905 dwarf_block
->per_objfile
);
906 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
907 if (VALUE_LVAL (val
) == lval_memory
)
908 return value_address (val
);
910 return value_as_address (val
);
913 case FIELD_LOC_KIND_PHYSNAME
:
915 const char *physname
;
916 struct bound_minimal_symbol msym
;
918 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
920 /* Handle both the mangled and demangled PHYSNAME. */
921 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
922 if (msym
.minsym
== NULL
)
924 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
925 throw_error (NO_ENTRY_VALUE_ERROR
,
926 _("Cannot find function \"%s\" for a call site target "
928 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
929 (msym
.minsym
== NULL
? "???"
930 : msym
.minsym
->print_name ()));
933 return BMSYMBOL_VALUE_ADDRESS (msym
);
936 case FIELD_LOC_KIND_PHYSADDR
:
937 return FIELD_STATIC_PHYSADDR (call_site
->target
);
940 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
944 /* Convert function entry point exact address ADDR to the function which is
945 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
946 NO_ENTRY_VALUE_ERROR otherwise. */
948 static struct symbol
*
949 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
951 struct symbol
*sym
= find_pc_function (addr
);
954 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
955 throw_error (NO_ENTRY_VALUE_ERROR
,
956 _("DW_TAG_call_site resolving failed to find function "
957 "name for address %s"),
958 paddress (gdbarch
, addr
));
960 type
= SYMBOL_TYPE (sym
);
961 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
962 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
967 /* Verify function with entry point exact address ADDR can never call itself
968 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
969 can call itself via tail calls.
971 If a funtion can tail call itself its entry value based parameters are
972 unreliable. There is no verification whether the value of some/all
973 parameters is unchanged through the self tail call, we expect if there is
974 a self tail call all the parameters can be modified. */
977 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
981 /* The verification is completely unordered. Track here function addresses
982 which still need to be iterated. */
983 std::vector
<CORE_ADDR
> todo
;
985 /* Track here CORE_ADDRs which were already visited. */
986 std::unordered_set
<CORE_ADDR
> addr_hash
;
988 todo
.push_back (verify_addr
);
989 while (!todo
.empty ())
991 struct symbol
*func_sym
;
992 struct call_site
*call_site
;
997 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
999 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
1000 call_site
; call_site
= call_site
->tail_call_next
)
1002 CORE_ADDR target_addr
;
1004 /* CALLER_FRAME with registers is not available for tail-call jumped
1006 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1008 if (target_addr
== verify_addr
)
1010 struct bound_minimal_symbol msym
;
1012 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
1013 throw_error (NO_ENTRY_VALUE_ERROR
,
1014 _("DW_OP_entry_value resolving has found "
1015 "function \"%s\" at %s can call itself via tail "
1017 (msym
.minsym
== NULL
? "???"
1018 : msym
.minsym
->print_name ()),
1019 paddress (gdbarch
, verify_addr
));
1022 if (addr_hash
.insert (target_addr
).second
)
1023 todo
.push_back (target_addr
);
1028 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
1029 ENTRY_VALUES_DEBUG. */
1032 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
1034 CORE_ADDR addr
= call_site
->pc
;
1035 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
1037 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
1038 (msym
.minsym
== NULL
? "???"
1039 : msym
.minsym
->print_name ()));
1043 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1044 only top callers and bottom callees which are present in both. GDBARCH is
1045 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1046 no remaining possibilities to provide unambiguous non-trivial result.
1047 RESULTP should point to NULL on the first (initialization) call. Caller is
1048 responsible for xfree of any RESULTP data. */
1051 chain_candidate (struct gdbarch
*gdbarch
,
1052 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1053 std::vector
<struct call_site
*> *chain
)
1055 long length
= chain
->size ();
1056 int callers
, callees
, idx
;
1058 if (*resultp
== NULL
)
1060 /* Create the initial chain containing all the passed PCs. */
1062 struct call_site_chain
*result
1063 = ((struct call_site_chain
*)
1064 xmalloc (sizeof (*result
)
1065 + sizeof (*result
->call_site
) * (length
- 1)));
1066 result
->length
= length
;
1067 result
->callers
= result
->callees
= length
;
1068 if (!chain
->empty ())
1069 memcpy (result
->call_site
, chain
->data (),
1070 sizeof (*result
->call_site
) * length
);
1071 resultp
->reset (result
);
1073 if (entry_values_debug
)
1075 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1076 for (idx
= 0; idx
< length
; idx
++)
1077 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1078 fputc_unfiltered ('\n', gdb_stdlog
);
1084 if (entry_values_debug
)
1086 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1087 for (idx
= 0; idx
< length
; idx
++)
1088 tailcall_dump (gdbarch
, chain
->at (idx
));
1089 fputc_unfiltered ('\n', gdb_stdlog
);
1092 /* Intersect callers. */
1094 callers
= std::min ((long) (*resultp
)->callers
, length
);
1095 for (idx
= 0; idx
< callers
; idx
++)
1096 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1098 (*resultp
)->callers
= idx
;
1102 /* Intersect callees. */
1104 callees
= std::min ((long) (*resultp
)->callees
, length
);
1105 for (idx
= 0; idx
< callees
; idx
++)
1106 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1107 != chain
->at (length
- 1 - idx
))
1109 (*resultp
)->callees
= idx
;
1113 if (entry_values_debug
)
1115 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1116 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1117 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1118 fputs_unfiltered (" |", gdb_stdlog
);
1119 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1120 tailcall_dump (gdbarch
,
1121 (*resultp
)->call_site
[(*resultp
)->length
1122 - (*resultp
)->callees
+ idx
]);
1123 fputc_unfiltered ('\n', gdb_stdlog
);
1126 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1128 /* There are no common callers or callees. It could be also a direct
1129 call (which has length 0) with ambiguous possibility of an indirect
1130 call - CALLERS == CALLEES == 0 is valid during the first allocation
1131 but any subsequence processing of such entry means ambiguity. */
1132 resultp
->reset (NULL
);
1136 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1137 PC again. In such case there must be two different code paths to reach
1138 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1139 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1142 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1143 assumed frames between them use GDBARCH. Use depth first search so we can
1144 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1145 would have needless GDB stack overhead. Any unreliability results
1146 in thrown NO_ENTRY_VALUE_ERROR. */
1148 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1149 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1150 CORE_ADDR callee_pc
)
1152 CORE_ADDR save_callee_pc
= callee_pc
;
1153 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1154 struct call_site
*call_site
;
1156 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1157 call_site nor any possible call_site at CALLEE_PC's function is there.
1158 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1159 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1160 std::vector
<struct call_site
*> chain
;
1162 /* We are not interested in the specific PC inside the callee function. */
1163 callee_pc
= get_pc_function_start (callee_pc
);
1165 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1166 paddress (gdbarch
, save_callee_pc
));
1168 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1169 std::unordered_set
<CORE_ADDR
> addr_hash
;
1171 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1172 at the target's function. All the possible tail call sites in the
1173 target's function will get iterated as already pushed into CHAIN via their
1175 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1179 CORE_ADDR target_func_addr
;
1180 struct call_site
*target_call_site
;
1182 /* CALLER_FRAME with registers is not available for tail-call jumped
1184 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1186 if (target_func_addr
== callee_pc
)
1188 chain_candidate (gdbarch
, &retval
, &chain
);
1192 /* There is no way to reach CALLEE_PC again as we would prevent
1193 entering it twice as being already marked in ADDR_HASH. */
1194 target_call_site
= NULL
;
1198 struct symbol
*target_func
;
1200 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1201 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1206 /* Attempt to visit TARGET_CALL_SITE. */
1208 if (target_call_site
)
1210 if (addr_hash
.insert (target_call_site
->pc
).second
)
1212 /* Successfully entered TARGET_CALL_SITE. */
1214 chain
.push_back (target_call_site
);
1219 /* Backtrack (without revisiting the originating call_site). Try the
1220 callers's sibling; if there isn't any try the callers's callers's
1223 target_call_site
= NULL
;
1224 while (!chain
.empty ())
1226 call_site
= chain
.back ();
1229 size_t removed
= addr_hash
.erase (call_site
->pc
);
1230 gdb_assert (removed
== 1);
1232 target_call_site
= call_site
->tail_call_next
;
1233 if (target_call_site
)
1237 while (target_call_site
);
1242 call_site
= chain
.back ();
1247 struct bound_minimal_symbol msym_caller
, msym_callee
;
1249 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1250 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1251 throw_error (NO_ENTRY_VALUE_ERROR
,
1252 _("There are no unambiguously determinable intermediate "
1253 "callers or callees between caller function \"%s\" at %s "
1254 "and callee function \"%s\" at %s"),
1255 (msym_caller
.minsym
== NULL
1256 ? "???" : msym_caller
.minsym
->print_name ()),
1257 paddress (gdbarch
, caller_pc
),
1258 (msym_callee
.minsym
== NULL
1259 ? "???" : msym_callee
.minsym
->print_name ()),
1260 paddress (gdbarch
, callee_pc
));
1266 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1267 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1268 constructed return NULL. */
1270 gdb::unique_xmalloc_ptr
<call_site_chain
>
1271 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1272 CORE_ADDR callee_pc
)
1274 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1278 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1280 catch (const gdb_exception_error
&e
)
1282 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1284 if (entry_values_debug
)
1285 exception_print (gdb_stdout
, e
);
1296 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1299 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1300 enum call_site_parameter_kind kind
,
1301 union call_site_parameter_u kind_u
)
1303 if (kind
== parameter
->kind
)
1306 case CALL_SITE_PARAMETER_DWARF_REG
:
1307 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1309 case CALL_SITE_PARAMETER_FB_OFFSET
:
1310 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1312 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1313 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1318 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1319 FRAME is for callee.
1321 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1324 static struct call_site_parameter
*
1325 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1326 enum call_site_parameter_kind kind
,
1327 union call_site_parameter_u kind_u
,
1328 dwarf2_per_cu_data
**per_cu_return
,
1329 dwarf2_per_objfile
**per_objfile_return
)
1331 CORE_ADDR func_addr
, caller_pc
;
1332 struct gdbarch
*gdbarch
;
1333 struct frame_info
*caller_frame
;
1334 struct call_site
*call_site
;
1336 /* Initialize it just to avoid a GCC false warning. */
1337 struct call_site_parameter
*parameter
= NULL
;
1338 CORE_ADDR target_addr
;
1340 while (get_frame_type (frame
) == INLINE_FRAME
)
1342 frame
= get_prev_frame (frame
);
1343 gdb_assert (frame
!= NULL
);
1346 func_addr
= get_frame_func (frame
);
1347 gdbarch
= get_frame_arch (frame
);
1348 caller_frame
= get_prev_frame (frame
);
1349 if (gdbarch
!= frame_unwind_arch (frame
))
1351 struct bound_minimal_symbol msym
1352 = lookup_minimal_symbol_by_pc (func_addr
);
1353 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1355 throw_error (NO_ENTRY_VALUE_ERROR
,
1356 _("DW_OP_entry_value resolving callee gdbarch %s "
1357 "(of %s (%s)) does not match caller gdbarch %s"),
1358 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1359 paddress (gdbarch
, func_addr
),
1360 (msym
.minsym
== NULL
? "???"
1361 : msym
.minsym
->print_name ()),
1362 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1365 if (caller_frame
== NULL
)
1367 struct bound_minimal_symbol msym
1368 = lookup_minimal_symbol_by_pc (func_addr
);
1370 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1371 "requires caller of %s (%s)"),
1372 paddress (gdbarch
, func_addr
),
1373 (msym
.minsym
== NULL
? "???"
1374 : msym
.minsym
->print_name ()));
1376 caller_pc
= get_frame_pc (caller_frame
);
1377 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1379 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1380 if (target_addr
!= func_addr
)
1382 struct minimal_symbol
*target_msym
, *func_msym
;
1384 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1385 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1386 throw_error (NO_ENTRY_VALUE_ERROR
,
1387 _("DW_OP_entry_value resolving expects callee %s at %s "
1388 "but the called frame is for %s at %s"),
1389 (target_msym
== NULL
? "???"
1390 : target_msym
->print_name ()),
1391 paddress (gdbarch
, target_addr
),
1392 func_msym
== NULL
? "???" : func_msym
->print_name (),
1393 paddress (gdbarch
, func_addr
));
1396 /* No entry value based parameters would be reliable if this function can
1397 call itself via tail calls. */
1398 func_verify_no_selftailcall (gdbarch
, func_addr
);
1400 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1402 parameter
= &call_site
->parameter
[iparams
];
1403 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1406 if (iparams
== call_site
->parameter_count
)
1408 struct minimal_symbol
*msym
1409 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1411 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1412 determine its value. */
1413 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1414 "at DW_TAG_call_site %s at %s"),
1415 paddress (gdbarch
, caller_pc
),
1416 msym
== NULL
? "???" : msym
->print_name ());
1419 *per_cu_return
= call_site
->per_cu
;
1420 *per_objfile_return
= call_site
->per_objfile
;
1424 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1425 the normal DW_AT_call_value block. Otherwise return the
1426 DW_AT_call_data_value (dereferenced) block.
1428 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1431 Function always returns non-NULL, non-optimized out value. It throws
1432 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1434 static struct value
*
1435 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1436 CORE_ADDR deref_size
, struct type
*type
,
1437 struct frame_info
*caller_frame
,
1438 dwarf2_per_cu_data
*per_cu
,
1439 dwarf2_per_objfile
*per_objfile
)
1441 const gdb_byte
*data_src
;
1445 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1446 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1448 /* DEREF_SIZE size is not verified here. */
1449 if (data_src
== NULL
)
1450 throw_error (NO_ENTRY_VALUE_ERROR
,
1451 _("Cannot resolve DW_AT_call_data_value"));
1453 /* DW_AT_call_value is a DWARF expression, not a DWARF
1454 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1456 data
= (gdb_byte
*) alloca (size
+ 1);
1457 memcpy (data
, data_src
, size
);
1458 data
[size
] = DW_OP_stack_value
;
1460 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
,
1464 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1465 the indirect method on it, that is use its stored target value, the sole
1466 purpose of entry_data_value_funcs.. */
1468 static struct value
*
1469 entry_data_value_coerce_ref (const struct value
*value
)
1471 struct type
*checked_type
= check_typedef (value_type (value
));
1472 struct value
*target_val
;
1474 if (!TYPE_IS_REFERENCE (checked_type
))
1477 target_val
= (struct value
*) value_computed_closure (value
);
1478 value_incref (target_val
);
1482 /* Implement copy_closure. */
1485 entry_data_value_copy_closure (const struct value
*v
)
1487 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1489 value_incref (target_val
);
1493 /* Implement free_closure. */
1496 entry_data_value_free_closure (struct value
*v
)
1498 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1500 value_decref (target_val
);
1503 /* Vector for methods for an entry value reference where the referenced value
1504 is stored in the caller. On the first dereference use
1505 DW_AT_call_data_value in the caller. */
1507 static const struct lval_funcs entry_data_value_funcs
=
1511 NULL
, /* indirect */
1512 entry_data_value_coerce_ref
,
1513 NULL
, /* check_synthetic_pointer */
1514 entry_data_value_copy_closure
,
1515 entry_data_value_free_closure
1518 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1519 are used to match DW_AT_location at the caller's
1520 DW_TAG_call_site_parameter.
1522 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1523 cannot resolve the parameter for any reason. */
1525 static struct value
*
1526 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1527 enum call_site_parameter_kind kind
,
1528 union call_site_parameter_u kind_u
)
1530 struct type
*checked_type
= check_typedef (type
);
1531 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1532 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1533 struct value
*outer_val
, *target_val
, *val
;
1534 struct call_site_parameter
*parameter
;
1535 dwarf2_per_cu_data
*caller_per_cu
;
1536 dwarf2_per_objfile
*caller_per_objfile
;
1538 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1540 &caller_per_objfile
);
1542 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1545 caller_per_objfile
);
1547 /* Check if DW_AT_call_data_value cannot be used. If it should be
1548 used and it is not available do not fall back to OUTER_VAL - dereferencing
1549 TYPE_CODE_REF with non-entry data value would give current value - not the
1552 if (!TYPE_IS_REFERENCE (checked_type
)
1553 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1556 target_val
= dwarf_entry_parameter_to_value (parameter
,
1557 TYPE_LENGTH (target_type
),
1558 target_type
, caller_frame
,
1560 caller_per_objfile
);
1562 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1563 release_value (target_val
).release ());
1565 /* Copy the referencing pointer to the new computed value. */
1566 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1567 TYPE_LENGTH (checked_type
));
1568 set_value_lazy (val
, 0);
1573 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1574 SIZE are DWARF block used to match DW_AT_location at the caller's
1575 DW_TAG_call_site_parameter.
1577 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1578 cannot resolve the parameter for any reason. */
1580 static struct value
*
1581 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1582 const gdb_byte
*block
, size_t block_len
)
1584 union call_site_parameter_u kind_u
;
1586 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1587 if (kind_u
.dwarf_reg
!= -1)
1588 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1591 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1592 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1595 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1596 suppressed during normal operation. The expression can be arbitrary if
1597 there is no caller-callee entry value binding expected. */
1598 throw_error (NO_ENTRY_VALUE_ERROR
,
1599 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1600 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1603 struct piece_closure
1605 /* Reference count. */
1608 /* The objfile from which this closure's expression came. */
1609 dwarf2_per_objfile
*per_objfile
= nullptr;
1611 /* The CU from which this closure's expression came. */
1612 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1614 /* The pieces describing this variable. */
1615 std::vector
<dwarf_expr_piece
> pieces
;
1617 /* Frame ID of frame to which a register value is relative, used
1618 only by DWARF_VALUE_REGISTER. */
1619 struct frame_id frame_id
;
1622 /* Allocate a closure for a value formed from separately-described
1625 static struct piece_closure
*
1626 allocate_piece_closure (dwarf2_per_cu_data
*per_cu
,
1627 dwarf2_per_objfile
*per_objfile
,
1628 std::vector
<dwarf_expr_piece
> &&pieces
,
1629 struct frame_info
*frame
)
1631 struct piece_closure
*c
= new piece_closure
;
1634 /* We must capture this here due to sharing of DWARF state. */
1635 c
->per_objfile
= per_objfile
;
1637 c
->pieces
= std::move (pieces
);
1639 c
->frame_id
= null_frame_id
;
1641 c
->frame_id
= get_frame_id (frame
);
1643 for (dwarf_expr_piece
&piece
: c
->pieces
)
1644 if (piece
.location
== DWARF_VALUE_STACK
)
1645 value_incref (piece
.v
.value
);
1650 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1651 bits whose first bit is located at bit offset START. */
1654 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1656 return (start
% 8 + n_bits
+ 7) / 8;
1659 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1660 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1661 operate in "read mode": fetch the contents of the (lazy) value V by
1662 composing it from its pieces. */
1665 rw_pieced_value (struct value
*v
, struct value
*from
)
1668 LONGEST offset
= 0, max_offset
;
1669 ULONGEST bits_to_skip
;
1670 gdb_byte
*v_contents
;
1671 const gdb_byte
*from_contents
;
1672 struct piece_closure
*c
1673 = (struct piece_closure
*) value_computed_closure (v
);
1674 gdb::byte_vector buffer
;
1675 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1679 from_contents
= value_contents (from
);
1684 if (value_type (v
) != value_enclosing_type (v
))
1685 internal_error (__FILE__
, __LINE__
,
1686 _("Should not be able to create a lazy value with "
1687 "an enclosing type"));
1688 v_contents
= value_contents_raw (v
);
1689 from_contents
= NULL
;
1692 bits_to_skip
= 8 * value_offset (v
);
1693 if (value_bitsize (v
))
1695 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1696 + value_bitpos (v
));
1698 && (type_byte_order (value_type (from
))
1701 /* Use the least significant bits of FROM. */
1702 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1703 offset
= max_offset
- value_bitsize (v
);
1706 max_offset
= value_bitsize (v
);
1709 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1711 /* Advance to the first non-skipped piece. */
1712 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1713 bits_to_skip
-= c
->pieces
[i
].size
;
1715 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1717 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1718 size_t this_size_bits
, this_size
;
1720 this_size_bits
= p
->size
- bits_to_skip
;
1721 if (this_size_bits
> max_offset
- offset
)
1722 this_size_bits
= max_offset
- offset
;
1724 switch (p
->location
)
1726 case DWARF_VALUE_REGISTER
:
1728 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1729 struct gdbarch
*arch
= get_frame_arch (frame
);
1730 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1731 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1734 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1735 && p
->offset
+ p
->size
< reg_bits
)
1737 /* Big-endian, and we want less than full size. */
1738 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1741 bits_to_skip
+= p
->offset
;
1743 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1744 buffer
.resize (this_size
);
1749 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1751 this_size
, buffer
.data (),
1755 mark_value_bits_optimized_out (v
, offset
,
1758 mark_value_bits_unavailable (v
, offset
,
1763 copy_bitwise (v_contents
, offset
,
1764 buffer
.data (), bits_to_skip
% 8,
1765 this_size_bits
, bits_big_endian
);
1770 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1772 /* Data is copied non-byte-aligned into the register.
1773 Need some bits from original register value. */
1774 get_frame_register_bytes (frame
, gdb_regnum
,
1776 this_size
, buffer
.data (),
1779 throw_error (OPTIMIZED_OUT_ERROR
,
1780 _("Can't do read-modify-write to "
1781 "update bitfield; containing word "
1782 "has been optimized out"));
1784 throw_error (NOT_AVAILABLE_ERROR
,
1785 _("Can't do read-modify-write to "
1786 "update bitfield; containing word "
1790 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1791 from_contents
, offset
,
1792 this_size_bits
, bits_big_endian
);
1793 put_frame_register_bytes (frame
, gdb_regnum
,
1795 this_size
, buffer
.data ());
1800 case DWARF_VALUE_MEMORY
:
1802 bits_to_skip
+= p
->offset
;
1804 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1806 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1809 /* Everything is byte-aligned; no buffer needed. */
1811 write_memory_with_notification (start_addr
,
1814 this_size_bits
/ 8);
1816 read_value_memory (v
, offset
,
1817 p
->v
.mem
.in_stack_memory
,
1818 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1819 v_contents
+ offset
/ 8,
1820 this_size_bits
/ 8);
1824 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1825 buffer
.resize (this_size
);
1830 read_value_memory (v
, offset
,
1831 p
->v
.mem
.in_stack_memory
,
1832 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1833 buffer
.data (), this_size
);
1834 copy_bitwise (v_contents
, offset
,
1835 buffer
.data (), bits_to_skip
% 8,
1836 this_size_bits
, bits_big_endian
);
1841 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1845 /* Perform a single read for small sizes. */
1846 read_memory (start_addr
, buffer
.data (),
1851 /* Only the first and last bytes can possibly have
1853 read_memory (start_addr
, buffer
.data (), 1);
1854 read_memory (start_addr
+ this_size
- 1,
1855 &buffer
[this_size
- 1], 1);
1859 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1860 from_contents
, offset
,
1861 this_size_bits
, bits_big_endian
);
1862 write_memory_with_notification (start_addr
,
1869 case DWARF_VALUE_STACK
:
1873 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1877 gdbarch
*objfile_gdbarch
= c
->per_objfile
->objfile
->arch ();
1878 ULONGEST stack_value_size_bits
1879 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1881 /* Use zeroes if piece reaches beyond stack value. */
1882 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1885 /* Piece is anchored at least significant bit end. */
1886 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1887 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1889 bits_to_skip
+= p
->offset
;
1891 copy_bitwise (v_contents
, offset
,
1892 value_contents_all (p
->v
.value
),
1894 this_size_bits
, bits_big_endian
);
1898 case DWARF_VALUE_LITERAL
:
1902 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1906 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1907 size_t n
= this_size_bits
;
1909 /* Cut off at the end of the implicit value. */
1910 bits_to_skip
+= p
->offset
;
1911 if (bits_to_skip
>= literal_size_bits
)
1913 if (n
> literal_size_bits
- bits_to_skip
)
1914 n
= literal_size_bits
- bits_to_skip
;
1916 copy_bitwise (v_contents
, offset
,
1917 p
->v
.literal
.data
, bits_to_skip
,
1918 n
, bits_big_endian
);
1922 case DWARF_VALUE_IMPLICIT_POINTER
:
1925 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1929 /* These bits show up as zeros -- but do not cause the value to
1930 be considered optimized-out. */
1933 case DWARF_VALUE_OPTIMIZED_OUT
:
1934 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1938 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1941 offset
+= this_size_bits
;
1948 read_pieced_value (struct value
*v
)
1950 rw_pieced_value (v
, NULL
);
1954 write_pieced_value (struct value
*to
, struct value
*from
)
1956 rw_pieced_value (to
, from
);
1959 /* An implementation of an lval_funcs method to see whether a value is
1960 a synthetic pointer. */
1963 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
1966 struct piece_closure
*c
1967 = (struct piece_closure
*) value_computed_closure (value
);
1970 bit_offset
+= 8 * value_offset (value
);
1971 if (value_bitsize (value
))
1972 bit_offset
+= value_bitpos (value
);
1974 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
1976 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1977 size_t this_size_bits
= p
->size
;
1981 if (bit_offset
>= this_size_bits
)
1983 bit_offset
-= this_size_bits
;
1987 bit_length
-= this_size_bits
- bit_offset
;
1991 bit_length
-= this_size_bits
;
1993 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2000 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2002 static struct value
*
2003 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2004 dwarf2_per_cu_data
*per_cu
,
2005 dwarf2_per_objfile
*per_objfile
,
2008 struct value
*result
= NULL
;
2009 const gdb_byte
*bytes
;
2012 auto_obstack temp_obstack
;
2013 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
2014 &temp_obstack
, &len
);
2018 if (byte_offset
>= 0
2019 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2021 bytes
+= byte_offset
;
2022 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2025 invalid_synthetic_pointer ();
2028 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2033 /* Fetch the value pointed to by a synthetic pointer. */
2035 static struct value
*
2036 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2037 dwarf2_per_cu_data
*per_cu
,
2038 dwarf2_per_objfile
*per_objfile
,
2039 struct frame_info
*frame
, struct type
*type
,
2040 bool resolve_abstract_p
)
2042 /* Fetch the location expression of the DIE we're pointing to. */
2043 auto get_frame_address_in_block_wrapper
= [frame
] ()
2045 return get_frame_address_in_block (frame
);
2047 struct dwarf2_locexpr_baton baton
2048 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
2049 get_frame_address_in_block_wrapper
,
2050 resolve_abstract_p
);
2052 /* Get type of pointed-to DIE. */
2053 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
2055 if (orig_type
== NULL
)
2056 invalid_synthetic_pointer ();
2058 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2059 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2060 or it may've been optimized out. */
2061 if (baton
.data
!= NULL
)
2062 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2063 baton
.size
, baton
.per_cu
,
2065 TYPE_TARGET_TYPE (type
),
2068 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2072 /* An implementation of an lval_funcs method to indirect through a
2073 pointer. This handles the synthetic pointer case when needed. */
2075 static struct value
*
2076 indirect_pieced_value (struct value
*value
)
2078 struct piece_closure
*c
2079 = (struct piece_closure
*) value_computed_closure (value
);
2081 struct frame_info
*frame
;
2084 struct dwarf_expr_piece
*piece
= NULL
;
2085 LONGEST byte_offset
;
2086 enum bfd_endian byte_order
;
2088 type
= check_typedef (value_type (value
));
2089 if (type
->code () != TYPE_CODE_PTR
)
2092 bit_length
= 8 * TYPE_LENGTH (type
);
2093 bit_offset
= 8 * value_offset (value
);
2094 if (value_bitsize (value
))
2095 bit_offset
+= value_bitpos (value
);
2097 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2099 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2100 size_t this_size_bits
= p
->size
;
2104 if (bit_offset
>= this_size_bits
)
2106 bit_offset
-= this_size_bits
;
2110 bit_length
-= this_size_bits
- bit_offset
;
2114 bit_length
-= this_size_bits
;
2116 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2119 if (bit_length
!= 0)
2120 error (_("Invalid use of DW_OP_implicit_pointer"));
2126 gdb_assert (piece
!= NULL
);
2127 frame
= get_selected_frame (_("No frame selected."));
2129 /* This is an offset requested by GDB, such as value subscripts.
2130 However, due to how synthetic pointers are implemented, this is
2131 always presented to us as a pointer type. This means we have to
2132 sign-extend it manually as appropriate. Use raw
2133 extract_signed_integer directly rather than value_as_address and
2134 sign extend afterwards on architectures that would need it
2135 (mostly everywhere except MIPS, which has signed addresses) as
2136 the later would go through gdbarch_pointer_to_address and thus
2137 return a CORE_ADDR with high bits set on architectures that
2138 encode address spaces and other things in CORE_ADDR. */
2139 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2140 byte_offset
= extract_signed_integer (value_contents (value
),
2141 TYPE_LENGTH (type
), byte_order
);
2142 byte_offset
+= piece
->v
.ptr
.offset
;
2144 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2145 byte_offset
, c
->per_cu
,
2146 c
->per_objfile
, frame
, type
);
2149 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2152 static struct value
*
2153 coerce_pieced_ref (const struct value
*value
)
2155 struct type
*type
= check_typedef (value_type (value
));
2157 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2158 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2160 const struct piece_closure
*closure
2161 = (struct piece_closure
*) value_computed_closure (value
);
2162 struct frame_info
*frame
2163 = get_selected_frame (_("No frame selected."));
2165 /* gdb represents synthetic pointers as pieced values with a single
2167 gdb_assert (closure
!= NULL
);
2168 gdb_assert (closure
->pieces
.size () == 1);
2170 return indirect_synthetic_pointer
2171 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2172 closure
->pieces
[0].v
.ptr
.offset
,
2173 closure
->per_cu
, closure
->per_objfile
, frame
, type
);
2177 /* Else: not a synthetic reference; do nothing. */
2183 copy_pieced_value_closure (const struct value
*v
)
2185 struct piece_closure
*c
2186 = (struct piece_closure
*) value_computed_closure (v
);
2193 free_pieced_value_closure (struct value
*v
)
2195 struct piece_closure
*c
2196 = (struct piece_closure
*) value_computed_closure (v
);
2201 for (dwarf_expr_piece
&p
: c
->pieces
)
2202 if (p
.location
== DWARF_VALUE_STACK
)
2203 value_decref (p
.v
.value
);
2209 /* Functions for accessing a variable described by DW_OP_piece. */
2210 static const struct lval_funcs pieced_value_funcs
= {
2213 indirect_pieced_value
,
2215 check_pieced_synthetic_pointer
,
2216 copy_pieced_value_closure
,
2217 free_pieced_value_closure
2220 /* Evaluate a location description, starting at DATA and with length
2221 SIZE, to find the current location of variable of TYPE in the
2222 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2223 location of the subobject of type SUBOBJ_TYPE at byte offset
2224 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2226 static struct value
*
2227 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2228 const gdb_byte
*data
, size_t size
,
2229 dwarf2_per_cu_data
*per_cu
,
2230 dwarf2_per_objfile
*per_objfile
,
2231 struct type
*subobj_type
,
2232 LONGEST subobj_byte_offset
)
2234 struct value
*retval
;
2236 if (subobj_type
== NULL
)
2239 subobj_byte_offset
= 0;
2241 else if (subobj_byte_offset
< 0)
2242 invalid_synthetic_pointer ();
2245 return allocate_optimized_out_value (subobj_type
);
2247 dwarf_evaluate_loc_desc
ctx (per_objfile
);
2249 ctx
.per_cu
= per_cu
;
2250 ctx
.obj_address
= 0;
2252 scoped_value_mark free_values
;
2254 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2255 ctx
.addr_size
= per_cu
->addr_size ();
2256 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2260 ctx
.eval (data
, size
);
2262 catch (const gdb_exception_error
&ex
)
2264 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2266 free_values
.free_to_mark ();
2267 retval
= allocate_value (subobj_type
);
2268 mark_value_bytes_unavailable (retval
, 0,
2269 TYPE_LENGTH (subobj_type
));
2272 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2274 if (entry_values_debug
)
2275 exception_print (gdb_stdout
, ex
);
2276 free_values
.free_to_mark ();
2277 return allocate_optimized_out_value (subobj_type
);
2283 if (ctx
.pieces
.size () > 0)
2285 struct piece_closure
*c
;
2286 ULONGEST bit_size
= 0;
2288 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2289 bit_size
+= piece
.size
;
2290 /* Complain if the expression is larger than the size of the
2292 if (bit_size
> 8 * TYPE_LENGTH (type
))
2293 invalid_synthetic_pointer ();
2295 c
= allocate_piece_closure (per_cu
, per_objfile
, std::move (ctx
.pieces
),
2297 /* We must clean up the value chain after creating the piece
2298 closure but before allocating the result. */
2299 free_values
.free_to_mark ();
2300 retval
= allocate_computed_value (subobj_type
,
2301 &pieced_value_funcs
, c
);
2302 set_value_offset (retval
, subobj_byte_offset
);
2306 switch (ctx
.location
)
2308 case DWARF_VALUE_REGISTER
:
2310 struct gdbarch
*arch
= get_frame_arch (frame
);
2312 = longest_to_int (value_as_long (ctx
.fetch (0)));
2313 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2315 if (subobj_byte_offset
!= 0)
2316 error (_("cannot use offset on synthetic pointer to register"));
2317 free_values
.free_to_mark ();
2318 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2319 if (value_optimized_out (retval
))
2323 /* This means the register has undefined value / was
2324 not saved. As we're computing the location of some
2325 variable etc. in the program, not a value for
2326 inspecting a register ($pc, $sp, etc.), return a
2327 generic optimized out value instead, so that we show
2328 <optimized out> instead of <not saved>. */
2329 tmp
= allocate_value (subobj_type
);
2330 value_contents_copy (tmp
, 0, retval
, 0,
2331 TYPE_LENGTH (subobj_type
));
2337 case DWARF_VALUE_MEMORY
:
2339 struct type
*ptr_type
;
2340 CORE_ADDR address
= ctx
.fetch_address (0);
2341 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2343 /* DW_OP_deref_size (and possibly other operations too) may
2344 create a pointer instead of an address. Ideally, the
2345 pointer to address conversion would be performed as part
2346 of those operations, but the type of the object to
2347 which the address refers is not known at the time of
2348 the operation. Therefore, we do the conversion here
2349 since the type is readily available. */
2351 switch (subobj_type
->code ())
2353 case TYPE_CODE_FUNC
:
2354 case TYPE_CODE_METHOD
:
2355 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2358 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2361 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2363 free_values
.free_to_mark ();
2364 retval
= value_at_lazy (subobj_type
,
2365 address
+ subobj_byte_offset
);
2366 if (in_stack_memory
)
2367 set_value_stack (retval
, 1);
2371 case DWARF_VALUE_STACK
:
2373 struct value
*value
= ctx
.fetch (0);
2374 size_t n
= TYPE_LENGTH (value_type (value
));
2375 size_t len
= TYPE_LENGTH (subobj_type
);
2376 size_t max
= TYPE_LENGTH (type
);
2377 gdbarch
*objfile_gdbarch
= per_objfile
->objfile
->arch ();
2379 if (subobj_byte_offset
+ len
> max
)
2380 invalid_synthetic_pointer ();
2382 /* Preserve VALUE because we are going to free values back
2383 to the mark, but we still need the value contents
2385 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2386 free_values
.free_to_mark ();
2388 retval
= allocate_value (subobj_type
);
2390 /* The given offset is relative to the actual object. */
2391 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2392 subobj_byte_offset
+= n
- max
;
2394 memcpy (value_contents_raw (retval
),
2395 value_contents_all (value
) + subobj_byte_offset
, len
);
2399 case DWARF_VALUE_LITERAL
:
2402 size_t n
= TYPE_LENGTH (subobj_type
);
2404 if (subobj_byte_offset
+ n
> ctx
.len
)
2405 invalid_synthetic_pointer ();
2407 free_values
.free_to_mark ();
2408 retval
= allocate_value (subobj_type
);
2409 contents
= value_contents_raw (retval
);
2410 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2414 case DWARF_VALUE_OPTIMIZED_OUT
:
2415 free_values
.free_to_mark ();
2416 retval
= allocate_optimized_out_value (subobj_type
);
2419 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2420 operation by execute_stack_op. */
2421 case DWARF_VALUE_IMPLICIT_POINTER
:
2422 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2423 it can only be encountered when making a piece. */
2425 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2429 set_value_initialized (retval
, ctx
.initialized
);
2434 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2435 passes 0 as the byte_offset. */
2438 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2439 const gdb_byte
*data
, size_t size
,
2440 dwarf2_per_cu_data
*per_cu
,
2441 dwarf2_per_objfile
*per_objfile
)
2443 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2444 per_objfile
, NULL
, 0);
2447 /* A specialization of dwarf_evaluate_loc_desc that is used by
2448 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2449 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2450 but with the address being 0. In this situation, we arrange for
2451 memory reads to come from the passed-in buffer. */
2453 struct evaluate_for_locexpr_baton
: public dwarf_evaluate_loc_desc
2455 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2456 : dwarf_evaluate_loc_desc (per_objfile
)
2459 /* The data that was passed in. */
2460 gdb::array_view
<const gdb_byte
> data_view
;
2462 CORE_ADDR
get_object_address () override
2464 if (data_view
.data () == nullptr && obj_address
== 0)
2465 error (_("Location address is not set."));
2469 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2474 /* Prefer the passed-in memory, if it exists. */
2475 CORE_ADDR offset
= addr
- obj_address
;
2476 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2478 memcpy (buf
, data_view
.data (), len
);
2482 read_memory (addr
, buf
, len
);
2486 /* Evaluates a dwarf expression and stores the result in VAL,
2487 expecting that the dwarf expression only produces a single
2488 CORE_ADDR. FRAME is the frame in which the expression is
2489 evaluated. ADDR_STACK is a context (location of a variable) and
2490 might be needed to evaluate the location expression.
2491 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2492 or the default of 0) should be pushed on the DWARF expression
2493 evaluation stack before evaluating the expression; this is required
2494 by certain forms of DWARF expression. Returns 1 on success, 0
2498 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2499 struct frame_info
*frame
,
2500 const struct property_addr_info
*addr_stack
,
2502 bool push_initial_value
)
2504 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2507 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2508 evaluate_for_locexpr_baton
ctx (per_objfile
);
2511 ctx
.per_cu
= dlbaton
->per_cu
;
2512 if (addr_stack
== nullptr)
2513 ctx
.obj_address
= 0;
2516 ctx
.obj_address
= addr_stack
->addr
;
2517 ctx
.data_view
= addr_stack
->valaddr
;
2520 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2521 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2522 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2524 if (push_initial_value
)
2525 ctx
.push_address (ctx
.obj_address
, false);
2529 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2531 catch (const gdb_exception_error
&ex
)
2533 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2537 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2539 if (entry_values_debug
)
2540 exception_print (gdb_stdout
, ex
);
2547 switch (ctx
.location
)
2549 case DWARF_VALUE_REGISTER
:
2550 case DWARF_VALUE_MEMORY
:
2551 case DWARF_VALUE_STACK
:
2552 *valp
= ctx
.fetch_address (0);
2553 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2554 *valp
= ctx
.read_addr_from_reg (*valp
);
2556 case DWARF_VALUE_LITERAL
:
2557 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2558 gdbarch_byte_order (ctx
.gdbarch
));
2560 /* Unsupported dwarf values. */
2561 case DWARF_VALUE_OPTIMIZED_OUT
:
2562 case DWARF_VALUE_IMPLICIT_POINTER
:
2569 /* See dwarf2loc.h. */
2572 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2573 struct frame_info
*frame
,
2574 const struct property_addr_info
*addr_stack
,
2576 bool push_initial_value
)
2581 if (frame
== NULL
&& has_stack_frames ())
2582 frame
= get_selected_frame (NULL
);
2584 switch (prop
->kind ())
2588 const struct dwarf2_property_baton
*baton
2589 = (const struct dwarf2_property_baton
*) prop
->baton ();
2590 gdb_assert (baton
->property_type
!= NULL
);
2592 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2593 value
, push_initial_value
))
2595 if (baton
->locexpr
.is_reference
)
2597 struct value
*val
= value_at (baton
->property_type
, *value
);
2598 *value
= value_as_address (val
);
2602 gdb_assert (baton
->property_type
!= NULL
);
2604 struct type
*type
= check_typedef (baton
->property_type
);
2605 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2606 && !type
->is_unsigned ())
2608 /* If we have a valid return candidate and it's value
2609 is signed, we have to sign-extend the value because
2610 CORE_ADDR on 64bit machine has 8 bytes but address
2611 size of an 32bit application is bytes. */
2613 = (baton
->locexpr
.per_cu
->addr_size ()
2615 const CORE_ADDR neg_mask
2616 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2618 /* Check if signed bit is set and sign-extend values. */
2619 if (*value
& neg_mask
)
2630 struct dwarf2_property_baton
*baton
2631 = (struct dwarf2_property_baton
*) prop
->baton ();
2633 const gdb_byte
*data
;
2638 || !get_frame_address_in_block_if_available (frame
, &pc
))
2641 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2644 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2645 size
, baton
->loclist
.per_cu
,
2646 baton
->loclist
.per_objfile
);
2647 if (!value_optimized_out (val
))
2649 *value
= value_as_address (val
);
2657 *value
= prop
->const_val ();
2660 case PROP_ADDR_OFFSET
:
2662 struct dwarf2_property_baton
*baton
2663 = (struct dwarf2_property_baton
*) prop
->baton ();
2664 const struct property_addr_info
*pinfo
;
2667 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2669 /* This approach lets us avoid checking the qualifiers. */
2670 if (TYPE_MAIN_TYPE (pinfo
->type
)
2671 == TYPE_MAIN_TYPE (baton
->property_type
))
2675 error (_("cannot find reference address for offset property"));
2676 if (pinfo
->valaddr
.data () != NULL
)
2677 val
= value_from_contents
2678 (baton
->offset_info
.type
,
2679 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2681 val
= value_at (baton
->offset_info
.type
,
2682 pinfo
->addr
+ baton
->offset_info
.offset
);
2683 *value
= value_as_address (val
);
2691 /* See dwarf2loc.h. */
2694 dwarf2_compile_property_to_c (string_file
*stream
,
2695 const char *result_name
,
2696 struct gdbarch
*gdbarch
,
2697 unsigned char *registers_used
,
2698 const struct dynamic_prop
*prop
,
2702 struct dwarf2_property_baton
*baton
2703 = (struct dwarf2_property_baton
*) prop
->baton ();
2704 const gdb_byte
*data
;
2706 dwarf2_per_cu_data
*per_cu
;
2707 dwarf2_per_objfile
*per_objfile
;
2709 if (prop
->kind () == PROP_LOCEXPR
)
2711 data
= baton
->locexpr
.data
;
2712 size
= baton
->locexpr
.size
;
2713 per_cu
= baton
->locexpr
.per_cu
;
2714 per_objfile
= baton
->locexpr
.per_objfile
;
2718 gdb_assert (prop
->kind () == PROP_LOCLIST
);
2720 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2721 per_cu
= baton
->loclist
.per_cu
;
2722 per_objfile
= baton
->loclist
.per_objfile
;
2725 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2726 gdbarch
, registers_used
,
2727 per_cu
->addr_size (),
2728 data
, data
+ size
, per_cu
, per_objfile
);
2732 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2734 class symbol_needs_eval_context
: public dwarf_expr_context
2737 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2738 : dwarf_expr_context (per_objfile
)
2741 enum symbol_needs_kind needs
;
2742 struct dwarf2_per_cu_data
*per_cu
;
2744 /* Reads from registers do require a frame. */
2745 CORE_ADDR
read_addr_from_reg (int regnum
) override
2747 needs
= SYMBOL_NEEDS_FRAME
;
2751 /* "get_reg_value" callback: Reads from registers do require a
2754 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2756 needs
= SYMBOL_NEEDS_FRAME
;
2757 return value_zero (type
, not_lval
);
2760 /* Reads from memory do not require a frame. */
2761 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2763 memset (buf
, 0, len
);
2766 /* Frame-relative accesses do require a frame. */
2767 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2769 static gdb_byte lit0
= DW_OP_lit0
;
2774 needs
= SYMBOL_NEEDS_FRAME
;
2777 /* CFA accesses require a frame. */
2778 CORE_ADDR
get_frame_cfa () override
2780 needs
= SYMBOL_NEEDS_FRAME
;
2784 CORE_ADDR
get_frame_pc () override
2786 needs
= SYMBOL_NEEDS_FRAME
;
2790 /* Thread-local accesses require registers, but not a frame. */
2791 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2793 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2794 needs
= SYMBOL_NEEDS_REGISTERS
;
2798 /* Helper interface of per_cu_dwarf_call for
2799 dwarf2_loc_desc_get_symbol_read_needs. */
2801 void dwarf_call (cu_offset die_offset
) override
2803 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
2806 /* Helper interface of sect_variable_value for
2807 dwarf2_loc_desc_get_symbol_read_needs. */
2809 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2811 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
2814 /* DW_OP_entry_value accesses require a caller, therefore a
2817 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2818 union call_site_parameter_u kind_u
,
2819 int deref_size
) override
2821 needs
= SYMBOL_NEEDS_FRAME
;
2823 /* The expression may require some stub values on DWARF stack. */
2824 push_address (0, 0);
2827 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2829 CORE_ADDR
get_addr_index (unsigned int index
) override
2831 /* Nothing to do. */
2835 /* DW_OP_push_object_address has a frame already passed through. */
2837 CORE_ADDR
get_object_address () override
2839 /* Nothing to do. */
2844 /* Compute the correct symbol_needs_kind value for the location
2845 expression at DATA (length SIZE). */
2847 static enum symbol_needs_kind
2848 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2849 dwarf2_per_cu_data
*per_cu
,
2850 dwarf2_per_objfile
*per_objfile
)
2852 scoped_value_mark free_values
;
2854 symbol_needs_eval_context
ctx (per_objfile
);
2856 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2857 ctx
.per_cu
= per_cu
;
2858 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2859 ctx
.addr_size
= per_cu
->addr_size ();
2860 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2862 ctx
.eval (data
, size
);
2864 bool in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2866 /* If the location has several pieces, and any of them are in
2867 registers, then we will need a frame to fetch them from. */
2868 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2869 if (p
.location
== DWARF_VALUE_REGISTER
)
2873 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2878 /* A helper function that throws an unimplemented error mentioning a
2879 given DWARF operator. */
2881 static void ATTRIBUTE_NORETURN
2882 unimplemented (unsigned int op
)
2884 const char *name
= get_DW_OP_name (op
);
2887 error (_("DWARF operator %s cannot be translated to an agent expression"),
2890 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2891 "to an agent expression"),
2897 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2898 can issue a complaint, which is better than having every target's
2899 implementation of dwarf2_reg_to_regnum do it. */
2902 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2904 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2908 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2913 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2914 Throw an error because DWARF_REG is bad. */
2917 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2919 /* Still want to print -1 as "-1".
2920 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2921 but that's overkill for now. */
2922 if ((int) dwarf_reg
== dwarf_reg
)
2923 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2924 error (_("Unable to access DWARF register number %s"),
2925 pulongest (dwarf_reg
));
2928 /* See dwarf2loc.h. */
2931 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2935 if (dwarf_reg
> INT_MAX
)
2936 throw_bad_regnum_error (dwarf_reg
);
2937 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2938 bad, but that's ok. */
2939 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2941 throw_bad_regnum_error (dwarf_reg
);
2945 /* A helper function that emits an access to memory. ARCH is the
2946 target architecture. EXPR is the expression which we are building.
2947 NBITS is the number of bits we want to read. This emits the
2948 opcodes needed to read the memory and then extract the desired
2952 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2954 ULONGEST nbytes
= (nbits
+ 7) / 8;
2956 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2959 ax_trace_quick (expr
, nbytes
);
2962 ax_simple (expr
, aop_ref8
);
2963 else if (nbits
<= 16)
2964 ax_simple (expr
, aop_ref16
);
2965 else if (nbits
<= 32)
2966 ax_simple (expr
, aop_ref32
);
2968 ax_simple (expr
, aop_ref64
);
2970 /* If we read exactly the number of bytes we wanted, we're done. */
2971 if (8 * nbytes
== nbits
)
2974 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
2976 /* On a bits-big-endian machine, we want the high-order
2978 ax_const_l (expr
, 8 * nbytes
- nbits
);
2979 ax_simple (expr
, aop_rsh_unsigned
);
2983 /* On a bits-little-endian box, we want the low-order NBITS. */
2984 ax_zero_ext (expr
, nbits
);
2988 /* Compile a DWARF location expression to an agent expression.
2990 EXPR is the agent expression we are building.
2991 LOC is the agent value we modify.
2992 ARCH is the architecture.
2993 ADDR_SIZE is the size of addresses, in bytes.
2994 OP_PTR is the start of the location expression.
2995 OP_END is one past the last byte of the location expression.
2997 This will throw an exception for various kinds of errors -- for
2998 example, if the expression cannot be compiled, or if the expression
3002 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3003 unsigned int addr_size
, const gdb_byte
*op_ptr
,
3004 const gdb_byte
*op_end
,
3005 dwarf2_per_cu_data
*per_cu
,
3006 dwarf2_per_objfile
*per_objfile
)
3008 gdbarch
*arch
= expr
->gdbarch
;
3009 std::vector
<int> dw_labels
, patches
;
3010 const gdb_byte
* const base
= op_ptr
;
3011 const gdb_byte
*previous_piece
= op_ptr
;
3012 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3013 ULONGEST bits_collected
= 0;
3014 unsigned int addr_size_bits
= 8 * addr_size
;
3015 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
3017 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3019 /* By default we are making an address. */
3020 loc
->kind
= axs_lvalue_memory
;
3022 while (op_ptr
< op_end
)
3024 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3025 uint64_t uoffset
, reg
;
3029 offsets
[op_ptr
- base
] = expr
->len
;
3032 /* Our basic approach to code generation is to map DWARF
3033 operations directly to AX operations. However, there are
3036 First, DWARF works on address-sized units, but AX always uses
3037 LONGEST. For most operations we simply ignore this
3038 difference; instead we generate sign extensions as needed
3039 before division and comparison operations. It would be nice
3040 to omit the sign extensions, but there is no way to determine
3041 the size of the target's LONGEST. (This code uses the size
3042 of the host LONGEST in some cases -- that is a bug but it is
3045 Second, some DWARF operations cannot be translated to AX.
3046 For these we simply fail. See
3047 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3082 ax_const_l (expr
, op
- DW_OP_lit0
);
3086 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3087 op_ptr
+= addr_size
;
3088 /* Some versions of GCC emit DW_OP_addr before
3089 DW_OP_GNU_push_tls_address. In this case the value is an
3090 index, not an address. We don't support things like
3091 branching between the address and the TLS op. */
3092 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3093 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3094 ax_const_l (expr
, uoffset
);
3098 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3103 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3108 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3113 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3118 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3123 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3128 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3133 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3138 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3139 ax_const_l (expr
, uoffset
);
3143 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3144 ax_const_l (expr
, offset
);
3179 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3180 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3181 loc
->kind
= axs_lvalue_register
;
3185 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3186 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3187 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3188 loc
->kind
= axs_lvalue_register
;
3191 case DW_OP_implicit_value
:
3195 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3196 if (op_ptr
+ len
> op_end
)
3197 error (_("DW_OP_implicit_value: too few bytes available."));
3198 if (len
> sizeof (ULONGEST
))
3199 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3202 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3205 dwarf_expr_require_composition (op_ptr
, op_end
,
3206 "DW_OP_implicit_value");
3208 loc
->kind
= axs_rvalue
;
3212 case DW_OP_stack_value
:
3213 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3214 loc
->kind
= axs_rvalue
;
3249 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3250 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3254 ax_const_l (expr
, offset
);
3255 ax_simple (expr
, aop_add
);
3261 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3262 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3263 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3267 ax_const_l (expr
, offset
);
3268 ax_simple (expr
, aop_add
);
3275 const gdb_byte
*datastart
;
3277 const struct block
*b
;
3278 struct symbol
*framefunc
;
3280 b
= block_for_pc (expr
->scope
);
3283 error (_("No block found for address"));
3285 framefunc
= block_linkage_function (b
);
3288 error (_("No function found for block"));
3290 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3291 &datastart
, &datalen
);
3293 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3294 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3295 datastart
+ datalen
, per_cu
,
3297 if (loc
->kind
== axs_lvalue_register
)
3298 require_rvalue (expr
, loc
);
3302 ax_const_l (expr
, offset
);
3303 ax_simple (expr
, aop_add
);
3306 loc
->kind
= axs_lvalue_memory
;
3311 ax_simple (expr
, aop_dup
);
3315 ax_simple (expr
, aop_pop
);
3320 ax_pick (expr
, offset
);
3324 ax_simple (expr
, aop_swap
);
3332 ax_simple (expr
, aop_rot
);
3336 case DW_OP_deref_size
:
3340 if (op
== DW_OP_deref_size
)
3345 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3346 error (_("Unsupported size %d in %s"),
3347 size
, get_DW_OP_name (op
));
3348 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3353 /* Sign extend the operand. */
3354 ax_ext (expr
, addr_size_bits
);
3355 ax_simple (expr
, aop_dup
);
3356 ax_const_l (expr
, 0);
3357 ax_simple (expr
, aop_less_signed
);
3358 ax_simple (expr
, aop_log_not
);
3359 i
= ax_goto (expr
, aop_if_goto
);
3360 /* We have to emit 0 - X. */
3361 ax_const_l (expr
, 0);
3362 ax_simple (expr
, aop_swap
);
3363 ax_simple (expr
, aop_sub
);
3364 ax_label (expr
, i
, expr
->len
);
3368 /* No need to sign extend here. */
3369 ax_const_l (expr
, 0);
3370 ax_simple (expr
, aop_swap
);
3371 ax_simple (expr
, aop_sub
);
3375 /* Sign extend the operand. */
3376 ax_ext (expr
, addr_size_bits
);
3377 ax_simple (expr
, aop_bit_not
);
3380 case DW_OP_plus_uconst
:
3381 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3382 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3383 but we micro-optimize anyhow. */
3386 ax_const_l (expr
, reg
);
3387 ax_simple (expr
, aop_add
);
3392 ax_simple (expr
, aop_bit_and
);
3396 /* Sign extend the operands. */
3397 ax_ext (expr
, addr_size_bits
);
3398 ax_simple (expr
, aop_swap
);
3399 ax_ext (expr
, addr_size_bits
);
3400 ax_simple (expr
, aop_swap
);
3401 ax_simple (expr
, aop_div_signed
);
3405 ax_simple (expr
, aop_sub
);
3409 ax_simple (expr
, aop_rem_unsigned
);
3413 ax_simple (expr
, aop_mul
);
3417 ax_simple (expr
, aop_bit_or
);
3421 ax_simple (expr
, aop_add
);
3425 ax_simple (expr
, aop_lsh
);
3429 ax_simple (expr
, aop_rsh_unsigned
);
3433 ax_simple (expr
, aop_rsh_signed
);
3437 ax_simple (expr
, aop_bit_xor
);
3441 /* Sign extend the operands. */
3442 ax_ext (expr
, addr_size_bits
);
3443 ax_simple (expr
, aop_swap
);
3444 ax_ext (expr
, addr_size_bits
);
3445 /* Note no swap here: A <= B is !(B < A). */
3446 ax_simple (expr
, aop_less_signed
);
3447 ax_simple (expr
, aop_log_not
);
3451 /* Sign extend the operands. */
3452 ax_ext (expr
, addr_size_bits
);
3453 ax_simple (expr
, aop_swap
);
3454 ax_ext (expr
, addr_size_bits
);
3455 ax_simple (expr
, aop_swap
);
3456 /* A >= B is !(A < B). */
3457 ax_simple (expr
, aop_less_signed
);
3458 ax_simple (expr
, aop_log_not
);
3462 /* Sign extend the operands. */
3463 ax_ext (expr
, addr_size_bits
);
3464 ax_simple (expr
, aop_swap
);
3465 ax_ext (expr
, addr_size_bits
);
3466 /* No need for a second swap here. */
3467 ax_simple (expr
, aop_equal
);
3471 /* Sign extend the operands. */
3472 ax_ext (expr
, addr_size_bits
);
3473 ax_simple (expr
, aop_swap
);
3474 ax_ext (expr
, addr_size_bits
);
3475 ax_simple (expr
, aop_swap
);
3476 ax_simple (expr
, aop_less_signed
);
3480 /* Sign extend the operands. */
3481 ax_ext (expr
, addr_size_bits
);
3482 ax_simple (expr
, aop_swap
);
3483 ax_ext (expr
, addr_size_bits
);
3484 /* Note no swap here: A > B is B < A. */
3485 ax_simple (expr
, aop_less_signed
);
3489 /* Sign extend the operands. */
3490 ax_ext (expr
, addr_size_bits
);
3491 ax_simple (expr
, aop_swap
);
3492 ax_ext (expr
, addr_size_bits
);
3493 /* No need for a swap here. */
3494 ax_simple (expr
, aop_equal
);
3495 ax_simple (expr
, aop_log_not
);
3498 case DW_OP_call_frame_cfa
:
3501 CORE_ADDR text_offset
;
3503 const gdb_byte
*cfa_start
, *cfa_end
;
3505 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3507 &text_offset
, &cfa_start
, &cfa_end
))
3510 ax_reg (expr
, regnum
);
3513 ax_const_l (expr
, off
);
3514 ax_simple (expr
, aop_add
);
3519 /* Another expression. */
3520 ax_const_l (expr
, text_offset
);
3521 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3522 cfa_end
, per_cu
, per_objfile
);
3525 loc
->kind
= axs_lvalue_memory
;
3529 case DW_OP_GNU_push_tls_address
:
3530 case DW_OP_form_tls_address
:
3534 case DW_OP_push_object_address
:
3539 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3541 i
= ax_goto (expr
, aop_goto
);
3542 dw_labels
.push_back (op_ptr
+ offset
- base
);
3543 patches
.push_back (i
);
3547 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3549 /* Zero extend the operand. */
3550 ax_zero_ext (expr
, addr_size_bits
);
3551 i
= ax_goto (expr
, aop_if_goto
);
3552 dw_labels
.push_back (op_ptr
+ offset
- base
);
3553 patches
.push_back (i
);
3560 case DW_OP_bit_piece
:
3564 if (op_ptr
- 1 == previous_piece
)
3565 error (_("Cannot translate empty pieces to agent expressions"));
3566 previous_piece
= op_ptr
- 1;
3568 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3569 if (op
== DW_OP_piece
)
3575 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3577 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3578 error (_("Expression pieces exceed word size"));
3580 /* Access the bits. */
3583 case axs_lvalue_register
:
3584 ax_reg (expr
, loc
->u
.reg
);
3587 case axs_lvalue_memory
:
3588 /* Offset the pointer, if needed. */
3591 ax_const_l (expr
, uoffset
/ 8);
3592 ax_simple (expr
, aop_add
);
3595 access_memory (arch
, expr
, size
);
3599 /* For a bits-big-endian target, shift up what we already
3600 have. For a bits-little-endian target, shift up the
3601 new data. Note that there is a potential bug here if
3602 the DWARF expression leaves multiple values on the
3604 if (bits_collected
> 0)
3606 if (bits_big_endian
)
3608 ax_simple (expr
, aop_swap
);
3609 ax_const_l (expr
, size
);
3610 ax_simple (expr
, aop_lsh
);
3611 /* We don't need a second swap here, because
3612 aop_bit_or is symmetric. */
3616 ax_const_l (expr
, size
);
3617 ax_simple (expr
, aop_lsh
);
3619 ax_simple (expr
, aop_bit_or
);
3622 bits_collected
+= size
;
3623 loc
->kind
= axs_rvalue
;
3627 case DW_OP_GNU_uninit
:
3633 struct dwarf2_locexpr_baton block
;
3634 int size
= (op
== DW_OP_call2
? 2 : 4);
3636 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3639 auto get_frame_pc_from_expr
= [expr
] ()
3643 cu_offset cuoffset
= (cu_offset
) uoffset
;
3644 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3645 get_frame_pc_from_expr
);
3647 /* DW_OP_call_ref is currently not supported. */
3648 gdb_assert (block
.per_cu
== per_cu
);
3650 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3651 block
.data
+ block
.size
, per_cu
,
3656 case DW_OP_call_ref
:
3659 case DW_OP_GNU_variable_value
:
3667 /* Patch all the branches we emitted. */
3668 for (int i
= 0; i
< patches
.size (); ++i
)
3670 int targ
= offsets
[dw_labels
[i
]];
3672 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3673 ax_label (expr
, patches
[i
], targ
);
3678 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3679 evaluator to calculate the location. */
3680 static struct value
*
3681 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3683 struct dwarf2_locexpr_baton
*dlbaton
3684 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3687 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3688 dlbaton
->size
, dlbaton
->per_cu
,
3689 dlbaton
->per_objfile
);
3694 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3695 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3698 static struct value
*
3699 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3701 struct dwarf2_locexpr_baton
*dlbaton
3702 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3704 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3708 /* Implementation of get_symbol_read_needs from
3709 symbol_computed_ops. */
3711 static enum symbol_needs_kind
3712 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3714 struct dwarf2_locexpr_baton
*dlbaton
3715 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3717 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3719 dlbaton
->per_objfile
);
3722 /* Return true if DATA points to the end of a piece. END is one past
3723 the last byte in the expression. */
3726 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3728 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3731 /* Helper for locexpr_describe_location_piece that finds the name of a
3735 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3739 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3740 We'd rather print *something* here than throw an error. */
3741 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3742 /* gdbarch_register_name may just return "", return something more
3743 descriptive for bad register numbers. */
3746 /* The text is output as "$bad_register_number".
3747 That is why we use the underscores. */
3748 return _("bad_register_number");
3750 return gdbarch_register_name (gdbarch
, regnum
);
3753 /* Nicely describe a single piece of a location, returning an updated
3754 position in the bytecode sequence. This function cannot recognize
3755 all locations; if a location is not recognized, it simply returns
3756 DATA. If there is an error during reading, e.g. we run off the end
3757 of the buffer, an error is thrown. */
3759 static const gdb_byte
*
3760 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3761 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3762 dwarf2_per_objfile
*per_objfile
,
3763 const gdb_byte
*data
, const gdb_byte
*end
,
3764 unsigned int addr_size
)
3766 objfile
*objfile
= per_objfile
->objfile
;
3767 struct gdbarch
*gdbarch
= objfile
->arch ();
3770 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3772 fprintf_filtered (stream
, _("a variable in $%s"),
3773 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3776 else if (data
[0] == DW_OP_regx
)
3780 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3781 fprintf_filtered (stream
, _("a variable in $%s"),
3782 locexpr_regname (gdbarch
, reg
));
3784 else if (data
[0] == DW_OP_fbreg
)
3786 const struct block
*b
;
3787 struct symbol
*framefunc
;
3789 int64_t frame_offset
;
3790 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3792 int64_t base_offset
= 0;
3794 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3795 if (!piece_end_p (new_data
, end
))
3799 b
= block_for_pc (addr
);
3802 error (_("No block found for address for symbol \"%s\"."),
3803 symbol
->print_name ());
3805 framefunc
= block_linkage_function (b
);
3808 error (_("No function found for block for symbol \"%s\"."),
3809 symbol
->print_name ());
3811 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3813 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3815 const gdb_byte
*buf_end
;
3817 frame_reg
= base_data
[0] - DW_OP_breg0
;
3818 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3820 if (buf_end
!= base_data
+ base_size
)
3821 error (_("Unexpected opcode after "
3822 "DW_OP_breg%u for symbol \"%s\"."),
3823 frame_reg
, symbol
->print_name ());
3825 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3827 /* The frame base is just the register, with no offset. */
3828 frame_reg
= base_data
[0] - DW_OP_reg0
;
3833 /* We don't know what to do with the frame base expression,
3834 so we can't trace this variable; give up. */
3838 fprintf_filtered (stream
,
3839 _("a variable at frame base reg $%s offset %s+%s"),
3840 locexpr_regname (gdbarch
, frame_reg
),
3841 plongest (base_offset
), plongest (frame_offset
));
3843 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3844 && piece_end_p (data
, end
))
3848 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3850 fprintf_filtered (stream
,
3851 _("a variable at offset %s from base reg $%s"),
3853 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3856 /* The location expression for a TLS variable looks like this (on a
3859 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3860 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3862 0x3 is the encoding for DW_OP_addr, which has an operand as long
3863 as the size of an address on the target machine (here is 8
3864 bytes). Note that more recent version of GCC emit DW_OP_const4u
3865 or DW_OP_const8u, depending on address size, rather than
3866 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3867 The operand represents the offset at which the variable is within
3868 the thread local storage. */
3870 else if (data
+ 1 + addr_size
< end
3871 && (data
[0] == DW_OP_addr
3872 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3873 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3874 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3875 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3876 && piece_end_p (data
+ 2 + addr_size
, end
))
3879 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3880 gdbarch_byte_order (gdbarch
));
3882 fprintf_filtered (stream
,
3883 _("a thread-local variable at offset 0x%s "
3884 "in the thread-local storage for `%s'"),
3885 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3887 data
+= 1 + addr_size
+ 1;
3890 /* With -gsplit-dwarf a TLS variable can also look like this:
3891 DW_AT_location : 3 byte block: fc 4 e0
3892 (DW_OP_GNU_const_index: 4;
3893 DW_OP_GNU_push_tls_address) */
3894 else if (data
+ 3 <= end
3895 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3896 && data
[0] == DW_OP_GNU_const_index
3898 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3899 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3900 && piece_end_p (data
+ 2 + leb128_size
, end
))
3904 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3905 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3906 fprintf_filtered (stream
,
3907 _("a thread-local variable at offset 0x%s "
3908 "in the thread-local storage for `%s'"),
3909 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3913 else if (data
[0] >= DW_OP_lit0
3914 && data
[0] <= DW_OP_lit31
3916 && data
[1] == DW_OP_stack_value
)
3918 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3925 /* Disassemble an expression, stopping at the end of a piece or at the
3926 end of the expression. Returns a pointer to the next unread byte
3927 in the input expression. If ALL is nonzero, then this function
3928 will keep going until it reaches the end of the expression.
3929 If there is an error during reading, e.g. we run off the end
3930 of the buffer, an error is thrown. */
3932 static const gdb_byte
*
3933 disassemble_dwarf_expression (struct ui_file
*stream
,
3934 struct gdbarch
*arch
, unsigned int addr_size
,
3935 int offset_size
, const gdb_byte
*start
,
3936 const gdb_byte
*data
, const gdb_byte
*end
,
3937 int indent
, int all
,
3938 dwarf2_per_cu_data
*per_cu
,
3939 dwarf2_per_objfile
*per_objfile
)
3943 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3945 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3950 name
= get_DW_OP_name (op
);
3953 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3954 op
, (long) (data
- 1 - start
));
3955 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3956 (long) (data
- 1 - start
), name
);
3961 ul
= extract_unsigned_integer (data
, addr_size
,
3962 gdbarch_byte_order (arch
));
3964 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3968 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3970 fprintf_filtered (stream
, " %s", pulongest (ul
));
3974 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3976 fprintf_filtered (stream
, " %s", plongest (l
));
3980 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3982 fprintf_filtered (stream
, " %s", pulongest (ul
));
3986 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3988 fprintf_filtered (stream
, " %s", plongest (l
));
3992 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3994 fprintf_filtered (stream
, " %s", pulongest (ul
));
3998 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4000 fprintf_filtered (stream
, " %s", plongest (l
));
4004 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4006 fprintf_filtered (stream
, " %s", pulongest (ul
));
4010 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4012 fprintf_filtered (stream
, " %s", plongest (l
));
4016 data
= safe_read_uleb128 (data
, end
, &ul
);
4017 fprintf_filtered (stream
, " %s", pulongest (ul
));
4021 data
= safe_read_sleb128 (data
, end
, &l
);
4022 fprintf_filtered (stream
, " %s", plongest (l
));
4057 fprintf_filtered (stream
, " [$%s]",
4058 locexpr_regname (arch
, op
- DW_OP_reg0
));
4062 data
= safe_read_uleb128 (data
, end
, &ul
);
4063 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4064 locexpr_regname (arch
, (int) ul
));
4067 case DW_OP_implicit_value
:
4068 data
= safe_read_uleb128 (data
, end
, &ul
);
4070 fprintf_filtered (stream
, " %s", pulongest (ul
));
4105 data
= safe_read_sleb128 (data
, end
, &l
);
4106 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4107 locexpr_regname (arch
, op
- DW_OP_breg0
));
4111 data
= safe_read_uleb128 (data
, end
, &ul
);
4112 data
= safe_read_sleb128 (data
, end
, &l
);
4113 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4115 locexpr_regname (arch
, (int) ul
),
4120 data
= safe_read_sleb128 (data
, end
, &l
);
4121 fprintf_filtered (stream
, " %s", plongest (l
));
4124 case DW_OP_xderef_size
:
4125 case DW_OP_deref_size
:
4127 fprintf_filtered (stream
, " %d", *data
);
4131 case DW_OP_plus_uconst
:
4132 data
= safe_read_uleb128 (data
, end
, &ul
);
4133 fprintf_filtered (stream
, " %s", pulongest (ul
));
4137 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4139 fprintf_filtered (stream
, " to %ld",
4140 (long) (data
+ l
- start
));
4144 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4146 fprintf_filtered (stream
, " %ld",
4147 (long) (data
+ l
- start
));
4151 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4153 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4157 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4159 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4162 case DW_OP_call_ref
:
4163 ul
= extract_unsigned_integer (data
, offset_size
,
4164 gdbarch_byte_order (arch
));
4165 data
+= offset_size
;
4166 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4170 data
= safe_read_uleb128 (data
, end
, &ul
);
4171 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4174 case DW_OP_bit_piece
:
4178 data
= safe_read_uleb128 (data
, end
, &ul
);
4179 data
= safe_read_uleb128 (data
, end
, &offset
);
4180 fprintf_filtered (stream
, " size %s offset %s (bits)",
4181 pulongest (ul
), pulongest (offset
));
4185 case DW_OP_implicit_pointer
:
4186 case DW_OP_GNU_implicit_pointer
:
4188 ul
= extract_unsigned_integer (data
, offset_size
,
4189 gdbarch_byte_order (arch
));
4190 data
+= offset_size
;
4192 data
= safe_read_sleb128 (data
, end
, &l
);
4194 fprintf_filtered (stream
, " DIE %s offset %s",
4195 phex_nz (ul
, offset_size
),
4200 case DW_OP_deref_type
:
4201 case DW_OP_GNU_deref_type
:
4203 int deref_addr_size
= *data
++;
4206 data
= safe_read_uleb128 (data
, end
, &ul
);
4207 cu_offset offset
= (cu_offset
) ul
;
4208 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
4209 fprintf_filtered (stream
, "<");
4210 type_print (type
, "", stream
, -1);
4211 fprintf_filtered (stream
, " [0x%s]> %d",
4212 phex_nz (to_underlying (offset
), 0),
4217 case DW_OP_const_type
:
4218 case DW_OP_GNU_const_type
:
4222 data
= safe_read_uleb128 (data
, end
, &ul
);
4223 cu_offset type_die
= (cu_offset
) ul
;
4224 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4225 fprintf_filtered (stream
, "<");
4226 type_print (type
, "", stream
, -1);
4227 fprintf_filtered (stream
, " [0x%s]>",
4228 phex_nz (to_underlying (type_die
), 0));
4231 fprintf_filtered (stream
, " %d byte block:", n
);
4232 for (int i
= 0; i
< n
; ++i
)
4233 fprintf_filtered (stream
, " %02x", data
[i
]);
4238 case DW_OP_regval_type
:
4239 case DW_OP_GNU_regval_type
:
4244 data
= safe_read_uleb128 (data
, end
, ®
);
4245 data
= safe_read_uleb128 (data
, end
, &ul
);
4246 cu_offset type_die
= (cu_offset
) ul
;
4248 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4249 fprintf_filtered (stream
, "<");
4250 type_print (type
, "", stream
, -1);
4251 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4252 phex_nz (to_underlying (type_die
), 0),
4253 locexpr_regname (arch
, reg
));
4258 case DW_OP_GNU_convert
:
4259 case DW_OP_reinterpret
:
4260 case DW_OP_GNU_reinterpret
:
4262 data
= safe_read_uleb128 (data
, end
, &ul
);
4263 cu_offset type_die
= (cu_offset
) ul
;
4265 if (to_underlying (type_die
) == 0)
4266 fprintf_filtered (stream
, "<0>");
4271 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4272 fprintf_filtered (stream
, "<");
4273 type_print (type
, "", stream
, -1);
4274 fprintf_filtered (stream
, " [0x%s]>",
4275 phex_nz (to_underlying (type_die
), 0));
4280 case DW_OP_entry_value
:
4281 case DW_OP_GNU_entry_value
:
4282 data
= safe_read_uleb128 (data
, end
, &ul
);
4283 fputc_filtered ('\n', stream
);
4284 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4285 start
, data
, data
+ ul
, indent
+ 2,
4286 all
, per_cu
, per_objfile
);
4290 case DW_OP_GNU_parameter_ref
:
4291 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4293 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4297 case DW_OP_GNU_addr_index
:
4298 data
= safe_read_uleb128 (data
, end
, &ul
);
4299 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4300 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4303 case DW_OP_GNU_const_index
:
4304 data
= safe_read_uleb128 (data
, end
, &ul
);
4305 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4306 fprintf_filtered (stream
, " %s", pulongest (ul
));
4309 case DW_OP_GNU_variable_value
:
4310 ul
= extract_unsigned_integer (data
, offset_size
,
4311 gdbarch_byte_order (arch
));
4312 data
+= offset_size
;
4313 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4317 fprintf_filtered (stream
, "\n");
4323 static bool dwarf_always_disassemble
;
4326 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4327 struct cmd_list_element
*c
, const char *value
)
4329 fprintf_filtered (file
,
4330 _("Whether to always disassemble "
4331 "DWARF expressions is %s.\n"),
4335 /* Describe a single location, which may in turn consist of multiple
4339 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4340 struct ui_file
*stream
,
4341 const gdb_byte
*data
, size_t size
,
4342 unsigned int addr_size
,
4343 int offset_size
, dwarf2_per_cu_data
*per_cu
,
4344 dwarf2_per_objfile
*per_objfile
)
4346 const gdb_byte
*end
= data
+ size
;
4347 int first_piece
= 1, bad
= 0;
4348 objfile
*objfile
= per_objfile
->objfile
;
4352 const gdb_byte
*here
= data
;
4353 int disassemble
= 1;
4358 fprintf_filtered (stream
, _(", and "));
4360 if (!dwarf_always_disassemble
)
4362 data
= locexpr_describe_location_piece (symbol
, stream
,
4363 addr
, per_cu
, per_objfile
,
4364 data
, end
, addr_size
);
4365 /* If we printed anything, or if we have an empty piece,
4366 then don't disassemble. */
4368 || data
[0] == DW_OP_piece
4369 || data
[0] == DW_OP_bit_piece
)
4374 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4375 data
= disassemble_dwarf_expression (stream
,
4377 addr_size
, offset_size
, data
,
4379 dwarf_always_disassemble
,
4380 per_cu
, per_objfile
);
4385 int empty
= data
== here
;
4388 fprintf_filtered (stream
, " ");
4389 if (data
[0] == DW_OP_piece
)
4393 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4396 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4399 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4402 else if (data
[0] == DW_OP_bit_piece
)
4404 uint64_t bits
, offset
;
4406 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4407 data
= safe_read_uleb128 (data
, end
, &offset
);
4410 fprintf_filtered (stream
,
4411 _("an empty %s-bit piece"),
4414 fprintf_filtered (stream
,
4415 _(" [%s-bit piece, offset %s bits]"),
4416 pulongest (bits
), pulongest (offset
));
4426 if (bad
|| data
> end
)
4427 error (_("Corrupted DWARF2 expression for \"%s\"."),
4428 symbol
->print_name ());
4431 /* Print a natural-language description of SYMBOL to STREAM. This
4432 version is for a symbol with a single location. */
4435 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4436 struct ui_file
*stream
)
4438 struct dwarf2_locexpr_baton
*dlbaton
4439 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4440 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4441 int offset_size
= dlbaton
->per_cu
->offset_size ();
4443 locexpr_describe_location_1 (symbol
, addr
, stream
,
4444 dlbaton
->data
, dlbaton
->size
,
4445 addr_size
, offset_size
,
4446 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4449 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4450 any necessary bytecode in AX. */
4453 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4454 struct axs_value
*value
)
4456 struct dwarf2_locexpr_baton
*dlbaton
4457 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4458 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4460 if (dlbaton
->size
== 0)
4461 value
->optimized_out
= 1;
4463 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4464 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4465 dlbaton
->per_objfile
);
4468 /* symbol_computed_ops 'generate_c_location' method. */
4471 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4472 struct gdbarch
*gdbarch
,
4473 unsigned char *registers_used
,
4474 CORE_ADDR pc
, const char *result_name
)
4476 struct dwarf2_locexpr_baton
*dlbaton
4477 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4478 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4480 if (dlbaton
->size
== 0)
4481 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4483 compile_dwarf_expr_to_c (stream
, result_name
,
4484 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4485 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4486 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4489 /* The set of location functions used with the DWARF-2 expression
4491 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4492 locexpr_read_variable
,
4493 locexpr_read_variable_at_entry
,
4494 locexpr_get_symbol_read_needs
,
4495 locexpr_describe_location
,
4496 0, /* location_has_loclist */
4497 locexpr_tracepoint_var_ref
,
4498 locexpr_generate_c_location
4502 /* Wrapper functions for location lists. These generally find
4503 the appropriate location expression and call something above. */
4505 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4506 evaluator to calculate the location. */
4507 static struct value
*
4508 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4510 struct dwarf2_loclist_baton
*dlbaton
4511 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4513 const gdb_byte
*data
;
4515 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4517 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4518 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4519 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4524 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4525 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4528 Function always returns non-NULL value, it may be marked optimized out if
4529 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4530 if it cannot resolve the parameter for any reason. */
4532 static struct value
*
4533 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4535 struct dwarf2_loclist_baton
*dlbaton
4536 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4537 const gdb_byte
*data
;
4541 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4542 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4544 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4546 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4548 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4551 /* Implementation of get_symbol_read_needs from
4552 symbol_computed_ops. */
4554 static enum symbol_needs_kind
4555 loclist_symbol_needs (struct symbol
*symbol
)
4557 /* If there's a location list, then assume we need to have a frame
4558 to choose the appropriate location expression. With tracking of
4559 global variables this is not necessarily true, but such tracking
4560 is disabled in GCC at the moment until we figure out how to
4563 return SYMBOL_NEEDS_FRAME
;
4566 /* Print a natural-language description of SYMBOL to STREAM. This
4567 version applies when there is a list of different locations, each
4568 with a specified address range. */
4571 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4572 struct ui_file
*stream
)
4574 struct dwarf2_loclist_baton
*dlbaton
4575 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4576 const gdb_byte
*loc_ptr
, *buf_end
;
4577 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4578 struct objfile
*objfile
= per_objfile
->objfile
;
4579 struct gdbarch
*gdbarch
= objfile
->arch ();
4580 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4581 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4582 int offset_size
= dlbaton
->per_cu
->offset_size ();
4583 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4584 /* Adjust base_address for relocatable objects. */
4585 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4586 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4589 loc_ptr
= dlbaton
->data
;
4590 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4592 fprintf_filtered (stream
, _("multi-location:\n"));
4594 /* Iterate through locations until we run out. */
4597 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4599 enum debug_loc_kind kind
;
4600 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4602 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4603 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4604 dlbaton
->per_objfile
,
4605 loc_ptr
, buf_end
, &new_ptr
,
4606 &low
, &high
, byte_order
);
4607 else if (dlbaton
->per_cu
->version () < 5)
4608 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4610 byte_order
, addr_size
,
4613 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4614 dlbaton
->per_objfile
,
4615 loc_ptr
, buf_end
, &new_ptr
,
4616 &low
, &high
, byte_order
,
4617 addr_size
, signed_addr_p
);
4621 case DEBUG_LOC_END_OF_LIST
:
4625 case DEBUG_LOC_BASE_ADDRESS
:
4626 base_address
= high
+ base_offset
;
4627 fprintf_filtered (stream
, _(" Base address %s"),
4628 paddress (gdbarch
, base_address
));
4631 case DEBUG_LOC_START_END
:
4632 case DEBUG_LOC_START_LENGTH
:
4633 case DEBUG_LOC_OFFSET_PAIR
:
4636 case DEBUG_LOC_BUFFER_OVERFLOW
:
4637 case DEBUG_LOC_INVALID_ENTRY
:
4638 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4639 symbol
->print_name ());
4642 gdb_assert_not_reached ("bad debug_loc_kind");
4645 /* Otherwise, a location expression entry. */
4646 low
+= base_address
;
4647 high
+= base_address
;
4649 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4650 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4652 if (dlbaton
->per_cu
->version () < 5)
4654 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4659 unsigned int bytes_read
;
4660 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4661 loc_ptr
+= bytes_read
;
4664 /* (It would improve readability to print only the minimum
4665 necessary digits of the second number of the range.) */
4666 fprintf_filtered (stream
, _(" Range %s-%s: "),
4667 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4669 /* Now describe this particular location. */
4670 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4671 addr_size
, offset_size
,
4672 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4674 fprintf_filtered (stream
, "\n");
4680 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4681 any necessary bytecode in AX. */
4683 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4684 struct axs_value
*value
)
4686 struct dwarf2_loclist_baton
*dlbaton
4687 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4688 const gdb_byte
*data
;
4690 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4692 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4694 value
->optimized_out
= 1;
4696 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4697 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4700 /* symbol_computed_ops 'generate_c_location' method. */
4703 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4704 struct gdbarch
*gdbarch
,
4705 unsigned char *registers_used
,
4706 CORE_ADDR pc
, const char *result_name
)
4708 struct dwarf2_loclist_baton
*dlbaton
4709 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4710 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4711 const gdb_byte
*data
;
4714 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4716 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4718 compile_dwarf_expr_to_c (stream
, result_name
,
4719 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4722 dlbaton
->per_objfile
);
4725 /* The set of location functions used with the DWARF-2 expression
4726 evaluator and location lists. */
4727 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4728 loclist_read_variable
,
4729 loclist_read_variable_at_entry
,
4730 loclist_symbol_needs
,
4731 loclist_describe_location
,
4732 1, /* location_has_loclist */
4733 loclist_tracepoint_var_ref
,
4734 loclist_generate_c_location
4737 void _initialize_dwarf2loc ();
4739 _initialize_dwarf2loc ()
4741 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4742 &entry_values_debug
,
4743 _("Set entry values and tail call frames "
4745 _("Show entry values and tail call frames "
4747 _("When non-zero, the process of determining "
4748 "parameter values from function entry point "
4749 "and tail call frames will be printed."),
4751 show_entry_values_debug
,
4752 &setdebuglist
, &showdebuglist
);
4754 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4755 &dwarf_always_disassemble
, _("\
4756 Set whether `info address' always disassembles DWARF expressions."), _("\
4757 Show whether `info address' always disassembles DWARF expressions."), _("\
4758 When enabled, DWARF expressions are always printed in an assembly-like\n\
4759 syntax. When disabled, expressions will be printed in a more\n\
4760 conversational style, when possible."),
4762 show_dwarf_always_disassemble
,
4764 &show_dwarf_cmdlist
);