1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2021 Free Software Foundation, Inc.
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "complaints.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
50 static struct value
*dwarf2_evaluate_loc_desc_full
51 (struct type
*type
, struct frame_info
*frame
, const gdb_byte
*data
,
52 size_t size
, dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
53 struct type
*subobj_type
, LONGEST subobj_byte_offset
);
55 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
56 (struct frame_info
*frame
,
57 enum call_site_parameter_kind kind
,
58 union call_site_parameter_u kind_u
,
59 dwarf2_per_cu_data
**per_cu_return
,
60 dwarf2_per_objfile
**per_objfile_return
);
62 static struct value
*indirect_synthetic_pointer
63 (sect_offset die
, LONGEST byte_offset
,
64 dwarf2_per_cu_data
*per_cu
,
65 dwarf2_per_objfile
*per_objfile
,
66 struct frame_info
*frame
,
67 struct type
*type
, bool resolve_abstract_p
= false);
69 /* Until these have formal names, we define these here.
70 ref: http://gcc.gnu.org/wiki/DebugFission
71 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
72 and is then followed by data specific to that entry. */
76 /* Indicates the end of the list of entries. */
77 DEBUG_LOC_END_OF_LIST
= 0,
79 /* This is followed by an unsigned LEB128 number that is an index into
80 .debug_addr and specifies the base address for all following entries. */
81 DEBUG_LOC_BASE_ADDRESS
= 1,
83 /* This is followed by two unsigned LEB128 numbers that are indices into
84 .debug_addr and specify the beginning and ending addresses, and then
85 a normal location expression as in .debug_loc. */
86 DEBUG_LOC_START_END
= 2,
88 /* This is followed by an unsigned LEB128 number that is an index into
89 .debug_addr and specifies the beginning address, and a 4 byte unsigned
90 number that specifies the length, and then a normal location expression
92 DEBUG_LOC_START_LENGTH
= 3,
94 /* This is followed by two unsigned LEB128 operands. The values of these
95 operands are the starting and ending offsets, respectively, relative to
96 the applicable base address. */
97 DEBUG_LOC_OFFSET_PAIR
= 4,
99 /* An internal value indicating there is insufficient data. */
100 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
102 /* An internal value indicating an invalid kind of entry was found. */
103 DEBUG_LOC_INVALID_ENTRY
= -2
106 /* Helper function which throws an error if a synthetic pointer is
110 invalid_synthetic_pointer (void)
112 error (_("access outside bounds of object "
113 "referenced via synthetic pointer"));
116 /* Decode the addresses in a non-dwo .debug_loc entry.
117 A pointer to the next byte to examine is returned in *NEW_PTR.
118 The encoded low,high addresses are return in *LOW,*HIGH.
119 The result indicates the kind of entry found. */
121 static enum debug_loc_kind
122 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
123 const gdb_byte
**new_ptr
,
124 CORE_ADDR
*low
, CORE_ADDR
*high
,
125 enum bfd_endian byte_order
,
126 unsigned int addr_size
,
129 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
131 if (buf_end
- loc_ptr
< 2 * addr_size
)
132 return DEBUG_LOC_BUFFER_OVERFLOW
;
135 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
137 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
138 loc_ptr
+= addr_size
;
141 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
143 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
144 loc_ptr
+= addr_size
;
148 /* A base-address-selection entry. */
149 if ((*low
& base_mask
) == base_mask
)
150 return DEBUG_LOC_BASE_ADDRESS
;
152 /* An end-of-list entry. */
153 if (*low
== 0 && *high
== 0)
154 return DEBUG_LOC_END_OF_LIST
;
156 return DEBUG_LOC_START_END
;
159 /* Decode the addresses in .debug_loclists entry.
160 A pointer to the next byte to examine is returned in *NEW_PTR.
161 The encoded low,high addresses are return in *LOW,*HIGH.
162 The result indicates the kind of entry found. */
164 static enum debug_loc_kind
165 decode_debug_loclists_addresses (dwarf2_per_cu_data
*per_cu
,
166 dwarf2_per_objfile
*per_objfile
,
167 const gdb_byte
*loc_ptr
,
168 const gdb_byte
*buf_end
,
169 const gdb_byte
**new_ptr
,
170 CORE_ADDR
*low
, CORE_ADDR
*high
,
171 enum bfd_endian byte_order
,
172 unsigned int addr_size
,
177 if (loc_ptr
== buf_end
)
178 return DEBUG_LOC_BUFFER_OVERFLOW
;
182 case DW_LLE_base_addressx
:
184 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
190 return DEBUG_LOC_BASE_ADDRESS
;
192 case DW_LLE_startx_length
:
193 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
195 return DEBUG_LOC_BUFFER_OVERFLOW
;
197 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, u64
);
199 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
201 return DEBUG_LOC_BUFFER_OVERFLOW
;
205 return DEBUG_LOC_START_LENGTH
;
207 case DW_LLE_start_length
:
208 if (buf_end
- loc_ptr
< addr_size
)
209 return DEBUG_LOC_BUFFER_OVERFLOW
;
212 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
214 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
216 loc_ptr
+= addr_size
;
219 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
221 return DEBUG_LOC_BUFFER_OVERFLOW
;
225 return DEBUG_LOC_START_LENGTH
;
227 case DW_LLE_end_of_list
:
229 return DEBUG_LOC_END_OF_LIST
;
231 case DW_LLE_base_address
:
232 if (loc_ptr
+ addr_size
> buf_end
)
233 return DEBUG_LOC_BUFFER_OVERFLOW
;
236 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
238 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
240 loc_ptr
+= addr_size
;
242 return DEBUG_LOC_BASE_ADDRESS
;
244 case DW_LLE_offset_pair
:
245 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
247 return DEBUG_LOC_BUFFER_OVERFLOW
;
250 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
252 return DEBUG_LOC_BUFFER_OVERFLOW
;
256 return DEBUG_LOC_OFFSET_PAIR
;
258 case DW_LLE_start_end
:
259 if (loc_ptr
+ 2 * addr_size
> buf_end
)
260 return DEBUG_LOC_BUFFER_OVERFLOW
;
263 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
265 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
267 loc_ptr
+= addr_size
;
269 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
271 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
273 loc_ptr
+= addr_size
;
275 return DEBUG_LOC_START_END
;
277 /* Following cases are not supported yet. */
278 case DW_LLE_startx_endx
:
279 case DW_LLE_default_location
:
281 return DEBUG_LOC_INVALID_ENTRY
;
285 /* Decode the addresses in .debug_loc.dwo entry.
286 A pointer to the next byte to examine is returned in *NEW_PTR.
287 The encoded low,high addresses are return in *LOW,*HIGH.
288 The result indicates the kind of entry found. */
290 static enum debug_loc_kind
291 decode_debug_loc_dwo_addresses (dwarf2_per_cu_data
*per_cu
,
292 dwarf2_per_objfile
*per_objfile
,
293 const gdb_byte
*loc_ptr
,
294 const gdb_byte
*buf_end
,
295 const gdb_byte
**new_ptr
,
296 CORE_ADDR
*low
, CORE_ADDR
*high
,
297 enum bfd_endian byte_order
)
299 uint64_t low_index
, high_index
;
301 if (loc_ptr
== buf_end
)
302 return DEBUG_LOC_BUFFER_OVERFLOW
;
306 case DW_LLE_GNU_end_of_list_entry
:
308 return DEBUG_LOC_END_OF_LIST
;
310 case DW_LLE_GNU_base_address_selection_entry
:
312 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
314 return DEBUG_LOC_BUFFER_OVERFLOW
;
316 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
318 return DEBUG_LOC_BASE_ADDRESS
;
320 case DW_LLE_GNU_start_end_entry
:
321 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
323 return DEBUG_LOC_BUFFER_OVERFLOW
;
325 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
326 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
328 return DEBUG_LOC_BUFFER_OVERFLOW
;
330 *high
= dwarf2_read_addr_index (per_cu
, per_objfile
, high_index
);
332 return DEBUG_LOC_START_END
;
334 case DW_LLE_GNU_start_length_entry
:
335 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
337 return DEBUG_LOC_BUFFER_OVERFLOW
;
339 *low
= dwarf2_read_addr_index (per_cu
, per_objfile
, low_index
);
340 if (loc_ptr
+ 4 > buf_end
)
341 return DEBUG_LOC_BUFFER_OVERFLOW
;
344 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
345 *new_ptr
= loc_ptr
+ 4;
346 return DEBUG_LOC_START_LENGTH
;
349 return DEBUG_LOC_INVALID_ENTRY
;
353 /* A function for dealing with location lists. Given a
354 symbol baton (BATON) and a pc value (PC), find the appropriate
355 location expression, set *LOCEXPR_LENGTH, and return a pointer
356 to the beginning of the expression. Returns NULL on failure.
358 For now, only return the first matching location expression; there
359 can be more than one in the list. */
362 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
363 size_t *locexpr_length
, CORE_ADDR pc
)
365 dwarf2_per_objfile
*per_objfile
= baton
->per_objfile
;
366 struct objfile
*objfile
= per_objfile
->objfile
;
367 struct gdbarch
*gdbarch
= objfile
->arch ();
368 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
369 unsigned int addr_size
= baton
->per_cu
->addr_size ();
370 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
371 /* Adjust base_address for relocatable objects. */
372 CORE_ADDR base_offset
= baton
->per_objfile
->objfile
->text_section_offset ();
373 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
374 const gdb_byte
*loc_ptr
, *buf_end
;
376 loc_ptr
= baton
->data
;
377 buf_end
= baton
->data
+ baton
->size
;
381 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
383 enum debug_loc_kind kind
;
384 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
386 if (baton
->per_cu
->version () < 5 && baton
->from_dwo
)
387 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
389 loc_ptr
, buf_end
, &new_ptr
,
390 &low
, &high
, byte_order
);
391 else if (baton
->per_cu
->version () < 5)
392 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
394 byte_order
, addr_size
,
397 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
399 loc_ptr
, buf_end
, &new_ptr
,
400 &low
, &high
, byte_order
,
401 addr_size
, signed_addr_p
);
406 case DEBUG_LOC_END_OF_LIST
:
410 case DEBUG_LOC_BASE_ADDRESS
:
411 base_address
= high
+ base_offset
;
414 case DEBUG_LOC_START_END
:
415 case DEBUG_LOC_START_LENGTH
:
416 case DEBUG_LOC_OFFSET_PAIR
:
419 case DEBUG_LOC_BUFFER_OVERFLOW
:
420 case DEBUG_LOC_INVALID_ENTRY
:
421 error (_("dwarf2_find_location_expression: "
422 "Corrupted DWARF expression."));
425 gdb_assert_not_reached ("bad debug_loc_kind");
428 /* Otherwise, a location expression entry.
429 If the entry is from a DWO, don't add base address: the entry is from
430 .debug_addr which already has the DWARF "base address". We still add
431 base_offset in case we're debugging a PIE executable. However, if the
432 entry is DW_LLE_offset_pair from a DWO, add the base address as the
433 operands are offsets relative to the applicable base address. */
434 if (baton
->from_dwo
&& kind
!= DEBUG_LOC_OFFSET_PAIR
)
442 high
+= base_address
;
445 if (baton
->per_cu
->version () < 5)
447 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
452 unsigned int bytes_read
;
454 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
455 loc_ptr
+= bytes_read
;
458 if (low
== high
&& pc
== low
)
460 /* This is entry PC record present only at entry point
461 of a function. Verify it is really the function entry point. */
463 const struct block
*pc_block
= block_for_pc (pc
);
464 struct symbol
*pc_func
= NULL
;
467 pc_func
= block_linkage_function (pc_block
);
469 if (pc_func
&& pc
== BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func
)))
471 *locexpr_length
= length
;
476 if (pc
>= low
&& pc
< high
)
478 *locexpr_length
= length
;
486 /* Implement find_frame_base_location method for LOC_BLOCK functions using
487 DWARF expression for its DW_AT_frame_base. */
490 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
491 const gdb_byte
**start
, size_t *length
)
493 struct dwarf2_locexpr_baton
*symbaton
494 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
496 *length
= symbaton
->size
;
497 *start
= symbaton
->data
;
500 /* Implement the struct symbol_block_ops::get_frame_base method for
501 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
504 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
506 struct gdbarch
*gdbarch
;
508 struct dwarf2_locexpr_baton
*dlbaton
;
509 const gdb_byte
*start
;
511 struct value
*result
;
513 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
514 Thus, it's supposed to provide the find_frame_base_location method as
516 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
518 gdbarch
= get_frame_arch (frame
);
519 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
520 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
522 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
523 (framefunc
, get_frame_pc (frame
), &start
, &length
);
524 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
525 dlbaton
->per_cu
, dlbaton
->per_objfile
);
527 /* The DW_AT_frame_base attribute contains a location description which
528 computes the base address itself. However, the call to
529 dwarf2_evaluate_loc_desc returns a value representing a variable at
530 that address. The frame base address is thus this variable's
532 return value_address (result
);
535 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
536 function uses DWARF expression for its DW_AT_frame_base. */
538 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
540 locexpr_find_frame_base_location
,
541 locexpr_get_frame_base
544 /* Implement find_frame_base_location method for LOC_BLOCK functions using
545 DWARF location list for its DW_AT_frame_base. */
548 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
549 const gdb_byte
**start
, size_t *length
)
551 struct dwarf2_loclist_baton
*symbaton
552 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
554 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
557 /* Implement the struct symbol_block_ops::get_frame_base method for
558 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
561 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
563 struct gdbarch
*gdbarch
;
565 struct dwarf2_loclist_baton
*dlbaton
;
566 const gdb_byte
*start
;
568 struct value
*result
;
570 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
571 Thus, it's supposed to provide the find_frame_base_location method as
573 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
575 gdbarch
= get_frame_arch (frame
);
576 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
577 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
579 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
580 (framefunc
, get_frame_pc (frame
), &start
, &length
);
581 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
582 dlbaton
->per_cu
, dlbaton
->per_objfile
);
584 /* The DW_AT_frame_base attribute contains a location description which
585 computes the base address itself. However, the call to
586 dwarf2_evaluate_loc_desc returns a value representing a variable at
587 that address. The frame base address is thus this variable's
589 return value_address (result
);
592 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
593 function uses DWARF location list for its DW_AT_frame_base. */
595 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
597 loclist_find_frame_base_location
,
598 loclist_get_frame_base
601 /* See dwarf2loc.h. */
604 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
605 const gdb_byte
**start
, size_t *length
)
607 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
609 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
611 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
617 error (_("Could not find the frame base for \"%s\"."),
618 framefunc
->natural_name ());
622 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
623 dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
)
625 struct dwarf2_locexpr_baton block
;
627 auto get_frame_pc_from_ctx
= [ctx
] ()
629 return ctx
->get_frame_pc ();
632 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
, per_objfile
,
633 get_frame_pc_from_ctx
);
635 /* DW_OP_call_ref is currently not supported. */
636 gdb_assert (block
.per_cu
== per_cu
);
638 ctx
->eval (block
.data
, block
.size
);
641 /* A helper function to find the definition of NAME and compute its
642 value. Returns nullptr if the name is not found. */
645 compute_var_value (const char *name
)
647 struct block_symbol sym
= lookup_symbol (name
, nullptr, VAR_DOMAIN
,
649 if (sym
.symbol
!= nullptr)
650 return value_of_variable (sym
.symbol
, sym
.block
);
654 /* Given context CTX, section offset SECT_OFF, and compilation unit
655 data PER_CU, execute the "variable value" operation on the DIE
656 found at SECT_OFF. */
658 static struct value
*
659 sect_variable_value (struct dwarf_expr_context
*ctx
, sect_offset sect_off
,
660 dwarf2_per_cu_data
*per_cu
,
661 dwarf2_per_objfile
*per_objfile
)
663 const char *var_name
= nullptr;
664 struct type
*die_type
665 = dwarf2_fetch_die_type_sect_off (sect_off
, per_cu
, per_objfile
,
668 if (die_type
== NULL
)
669 error (_("Bad DW_OP_GNU_variable_value DIE."));
671 /* Note: Things still work when the following test is removed. This
672 test and error is here to conform to the proposed specification. */
673 if (die_type
->code () != TYPE_CODE_INT
674 && die_type
->code () != TYPE_CODE_ENUM
675 && die_type
->code () != TYPE_CODE_RANGE
676 && die_type
->code () != TYPE_CODE_PTR
)
677 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
679 if (var_name
!= nullptr)
681 value
*result
= compute_var_value (var_name
);
682 if (result
!= nullptr)
686 struct type
*type
= lookup_pointer_type (die_type
);
687 struct frame_info
*frame
= get_selected_frame (_("No frame selected."));
688 return indirect_synthetic_pointer (sect_off
, 0, per_cu
, per_objfile
, frame
,
692 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
695 dwarf_evaluate_loc_desc (dwarf2_per_objfile
*per_objfile
)
696 : dwarf_expr_context (per_objfile
)
699 struct frame_info
*frame
;
700 struct dwarf2_per_cu_data
*per_cu
;
701 CORE_ADDR obj_address
;
703 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
704 the frame in BATON. */
706 CORE_ADDR
get_frame_cfa () override
708 return dwarf2_frame_cfa (frame
);
711 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
712 the frame in BATON. */
714 CORE_ADDR
get_frame_pc () override
716 return get_frame_address_in_block (frame
);
719 /* Using the objfile specified in BATON, find the address for the
720 current thread's thread-local storage with offset OFFSET. */
721 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
723 return target_translate_tls_address (per_objfile
->objfile
, offset
);
726 /* Helper interface of per_cu_dwarf_call for
727 dwarf2_evaluate_loc_desc. */
729 void dwarf_call (cu_offset die_offset
) override
731 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
734 /* Helper interface of sect_variable_value for
735 dwarf2_evaluate_loc_desc. */
737 struct value
*dwarf_variable_value (sect_offset sect_off
) override
739 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
742 struct type
*get_base_type (cu_offset die_offset
, int size
) override
744 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
, per_objfile
);
746 error (_("Could not find type for DW_OP_const_type"));
747 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
748 error (_("DW_OP_const_type has different sizes for type and data"));
752 /* Callback function for dwarf2_evaluate_loc_desc.
753 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
755 CORE_ADDR
get_addr_index (unsigned int index
) override
757 return dwarf2_read_addr_index (per_cu
, per_objfile
, index
);
760 /* Callback function for get_object_address. Return the address of the VLA
763 CORE_ADDR
get_object_address () override
765 if (obj_address
== 0)
766 error (_("Location address is not set."));
770 /* Execute DWARF block of call_site_parameter which matches KIND and
771 KIND_U. Choose DEREF_SIZE value of that parameter. Search
772 caller of this objects's frame.
774 The caller can be from a different CU - per_cu_dwarf_call
775 implementation can be more simple as it does not support cross-CU
778 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
779 union call_site_parameter_u kind_u
,
780 int deref_size
) override
782 struct frame_info
*caller_frame
;
783 dwarf2_per_cu_data
*caller_per_cu
;
784 dwarf2_per_objfile
*caller_per_objfile
;
785 struct call_site_parameter
*parameter
;
786 const gdb_byte
*data_src
;
789 caller_frame
= get_prev_frame (frame
);
791 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
793 &caller_per_objfile
);
794 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
795 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
797 /* DEREF_SIZE size is not verified here. */
798 if (data_src
== NULL
)
799 throw_error (NO_ENTRY_VALUE_ERROR
,
800 _("Cannot resolve DW_AT_call_data_value"));
802 /* We are about to evaluate an expression in the context of the caller
803 of the current frame. This evaluation context may be different from
804 the current (callee's) context), so temporarily set the caller's context.
806 It is possible for the caller to be from a different objfile from the
807 callee if the call is made through a function pointer. */
808 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
810 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
812 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
814 scoped_restore save_per_objfile
= make_scoped_restore (&this->per_objfile
,
817 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
818 this->gdbarch
= this->per_objfile
->objfile
->arch ();
819 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
820 this->addr_size
= this->per_cu
->addr_size ();
822 this->eval (data_src
, size
);
825 /* Using the frame specified in BATON, find the location expression
826 describing the frame base. Return a pointer to it in START and
827 its length in LENGTH. */
828 void get_frame_base (const gdb_byte
**start
, size_t * length
) override
830 if (frame
== nullptr)
831 error (_("frame address is not available."));
833 /* FIXME: cagney/2003-03-26: This code should be using
834 get_frame_base_address(), and then implement a dwarf2 specific
836 struct symbol
*framefunc
;
837 const struct block
*bl
= get_frame_block (frame
, NULL
);
840 error (_("frame address is not available."));
842 /* Use block_linkage_function, which returns a real (not inlined)
843 function, instead of get_frame_function, which may return an
845 framefunc
= block_linkage_function (bl
);
847 /* If we found a frame-relative symbol then it was certainly within
848 some function associated with a frame. If we can't find the frame,
849 something has gone wrong. */
850 gdb_assert (framefunc
!= NULL
);
852 func_get_frame_base_dwarf_block (framefunc
,
853 get_frame_address_in_block (frame
),
857 /* Read memory at ADDR (length LEN) into BUF. */
859 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
861 read_memory (addr
, buf
, len
);
864 /* Using the frame specified in BATON, return the value of register
865 REGNUM, treated as a pointer. */
866 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) override
868 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
869 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
871 return address_from_register (regnum
, frame
);
874 /* Implement "get_reg_value" callback. */
876 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) override
878 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
879 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
881 return value_from_register (type
, regnum
, frame
);
885 /* See dwarf2loc.h. */
887 unsigned int entry_values_debug
= 0;
889 /* Helper to set entry_values_debug. */
892 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
893 struct cmd_list_element
*c
, const char *value
)
895 fprintf_filtered (file
,
896 _("Entry values and tail call frames debugging is %s.\n"),
900 /* Find DW_TAG_call_site's DW_AT_call_target address.
901 CALLER_FRAME (for registers) can be NULL if it is not known. This function
902 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
905 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
906 struct call_site
*call_site
,
907 struct frame_info
*caller_frame
)
909 switch (FIELD_LOC_KIND (call_site
->target
))
911 case FIELD_LOC_KIND_DWARF_BLOCK
:
913 struct dwarf2_locexpr_baton
*dwarf_block
;
915 struct type
*caller_core_addr_type
;
916 struct gdbarch
*caller_arch
;
918 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
919 if (dwarf_block
== NULL
)
921 struct bound_minimal_symbol msym
;
923 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
924 throw_error (NO_ENTRY_VALUE_ERROR
,
925 _("DW_AT_call_target is not specified at %s in %s"),
926 paddress (call_site_gdbarch
, call_site
->pc
),
927 (msym
.minsym
== NULL
? "???"
928 : msym
.minsym
->print_name ()));
931 if (caller_frame
== NULL
)
933 struct bound_minimal_symbol msym
;
935 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
936 throw_error (NO_ENTRY_VALUE_ERROR
,
937 _("DW_AT_call_target DWARF block resolving "
938 "requires known frame which is currently not "
939 "available at %s in %s"),
940 paddress (call_site_gdbarch
, call_site
->pc
),
941 (msym
.minsym
== NULL
? "???"
942 : msym
.minsym
->print_name ()));
945 caller_arch
= get_frame_arch (caller_frame
);
946 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
947 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
948 dwarf_block
->data
, dwarf_block
->size
,
950 dwarf_block
->per_objfile
);
951 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
952 if (VALUE_LVAL (val
) == lval_memory
)
953 return value_address (val
);
955 return value_as_address (val
);
958 case FIELD_LOC_KIND_PHYSNAME
:
960 const char *physname
;
961 struct bound_minimal_symbol msym
;
963 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
965 /* Handle both the mangled and demangled PHYSNAME. */
966 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
967 if (msym
.minsym
== NULL
)
969 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
970 throw_error (NO_ENTRY_VALUE_ERROR
,
971 _("Cannot find function \"%s\" for a call site target "
973 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
974 (msym
.minsym
== NULL
? "???"
975 : msym
.minsym
->print_name ()));
978 return BMSYMBOL_VALUE_ADDRESS (msym
);
981 case FIELD_LOC_KIND_PHYSADDR
:
982 return FIELD_STATIC_PHYSADDR (call_site
->target
);
985 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
989 /* Convert function entry point exact address ADDR to the function which is
990 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
991 NO_ENTRY_VALUE_ERROR otherwise. */
993 static struct symbol
*
994 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
996 struct symbol
*sym
= find_pc_function (addr
);
999 if (sym
== NULL
|| BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
1000 throw_error (NO_ENTRY_VALUE_ERROR
,
1001 _("DW_TAG_call_site resolving failed to find function "
1002 "name for address %s"),
1003 paddress (gdbarch
, addr
));
1005 type
= SYMBOL_TYPE (sym
);
1006 gdb_assert (type
->code () == TYPE_CODE_FUNC
);
1007 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
1012 /* Verify function with entry point exact address ADDR can never call itself
1013 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
1014 can call itself via tail calls.
1016 If a funtion can tail call itself its entry value based parameters are
1017 unreliable. There is no verification whether the value of some/all
1018 parameters is unchanged through the self tail call, we expect if there is
1019 a self tail call all the parameters can be modified. */
1022 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
1026 /* The verification is completely unordered. Track here function addresses
1027 which still need to be iterated. */
1028 std::vector
<CORE_ADDR
> todo
;
1030 /* Track here CORE_ADDRs which were already visited. */
1031 std::unordered_set
<CORE_ADDR
> addr_hash
;
1033 todo
.push_back (verify_addr
);
1034 while (!todo
.empty ())
1036 struct symbol
*func_sym
;
1037 struct call_site
*call_site
;
1039 addr
= todo
.back ();
1042 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
1044 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
1045 call_site
; call_site
= call_site
->tail_call_next
)
1047 CORE_ADDR target_addr
;
1049 /* CALLER_FRAME with registers is not available for tail-call jumped
1051 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1053 if (target_addr
== verify_addr
)
1055 struct bound_minimal_symbol msym
;
1057 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
1058 throw_error (NO_ENTRY_VALUE_ERROR
,
1059 _("DW_OP_entry_value resolving has found "
1060 "function \"%s\" at %s can call itself via tail "
1062 (msym
.minsym
== NULL
? "???"
1063 : msym
.minsym
->print_name ()),
1064 paddress (gdbarch
, verify_addr
));
1067 if (addr_hash
.insert (target_addr
).second
)
1068 todo
.push_back (target_addr
);
1073 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
1074 ENTRY_VALUES_DEBUG. */
1077 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
1079 CORE_ADDR addr
= call_site
->pc
;
1080 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
1082 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
1083 (msym
.minsym
== NULL
? "???"
1084 : msym
.minsym
->print_name ()));
1088 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1089 only top callers and bottom callees which are present in both. GDBARCH is
1090 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1091 no remaining possibilities to provide unambiguous non-trivial result.
1092 RESULTP should point to NULL on the first (initialization) call. Caller is
1093 responsible for xfree of any RESULTP data. */
1096 chain_candidate (struct gdbarch
*gdbarch
,
1097 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
1098 std::vector
<struct call_site
*> *chain
)
1100 long length
= chain
->size ();
1101 int callers
, callees
, idx
;
1103 if (*resultp
== NULL
)
1105 /* Create the initial chain containing all the passed PCs. */
1107 struct call_site_chain
*result
1108 = ((struct call_site_chain
*)
1109 xmalloc (sizeof (*result
)
1110 + sizeof (*result
->call_site
) * (length
- 1)));
1111 result
->length
= length
;
1112 result
->callers
= result
->callees
= length
;
1113 if (!chain
->empty ())
1114 memcpy (result
->call_site
, chain
->data (),
1115 sizeof (*result
->call_site
) * length
);
1116 resultp
->reset (result
);
1118 if (entry_values_debug
)
1120 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
1121 for (idx
= 0; idx
< length
; idx
++)
1122 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
1123 fputc_unfiltered ('\n', gdb_stdlog
);
1129 if (entry_values_debug
)
1131 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
1132 for (idx
= 0; idx
< length
; idx
++)
1133 tailcall_dump (gdbarch
, chain
->at (idx
));
1134 fputc_unfiltered ('\n', gdb_stdlog
);
1137 /* Intersect callers. */
1139 callers
= std::min ((long) (*resultp
)->callers
, length
);
1140 for (idx
= 0; idx
< callers
; idx
++)
1141 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
1143 (*resultp
)->callers
= idx
;
1147 /* Intersect callees. */
1149 callees
= std::min ((long) (*resultp
)->callees
, length
);
1150 for (idx
= 0; idx
< callees
; idx
++)
1151 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
1152 != chain
->at (length
- 1 - idx
))
1154 (*resultp
)->callees
= idx
;
1158 if (entry_values_debug
)
1160 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
1161 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
1162 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1163 fputs_unfiltered (" |", gdb_stdlog
);
1164 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1165 tailcall_dump (gdbarch
,
1166 (*resultp
)->call_site
[(*resultp
)->length
1167 - (*resultp
)->callees
+ idx
]);
1168 fputc_unfiltered ('\n', gdb_stdlog
);
1171 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1173 /* There are no common callers or callees. It could be also a direct
1174 call (which has length 0) with ambiguous possibility of an indirect
1175 call - CALLERS == CALLEES == 0 is valid during the first allocation
1176 but any subsequence processing of such entry means ambiguity. */
1177 resultp
->reset (NULL
);
1181 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1182 PC again. In such case there must be two different code paths to reach
1183 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1184 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1187 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1188 assumed frames between them use GDBARCH. Use depth first search so we can
1189 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1190 would have needless GDB stack overhead. Any unreliability results
1191 in thrown NO_ENTRY_VALUE_ERROR. */
1193 static gdb::unique_xmalloc_ptr
<call_site_chain
>
1194 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1195 CORE_ADDR callee_pc
)
1197 CORE_ADDR save_callee_pc
= callee_pc
;
1198 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1199 struct call_site
*call_site
;
1201 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1202 call_site nor any possible call_site at CALLEE_PC's function is there.
1203 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1204 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1205 std::vector
<struct call_site
*> chain
;
1207 /* We are not interested in the specific PC inside the callee function. */
1208 callee_pc
= get_pc_function_start (callee_pc
);
1210 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1211 paddress (gdbarch
, save_callee_pc
));
1213 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1214 std::unordered_set
<CORE_ADDR
> addr_hash
;
1216 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1217 at the target's function. All the possible tail call sites in the
1218 target's function will get iterated as already pushed into CHAIN via their
1220 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1224 CORE_ADDR target_func_addr
;
1225 struct call_site
*target_call_site
;
1227 /* CALLER_FRAME with registers is not available for tail-call jumped
1229 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1231 if (target_func_addr
== callee_pc
)
1233 chain_candidate (gdbarch
, &retval
, &chain
);
1237 /* There is no way to reach CALLEE_PC again as we would prevent
1238 entering it twice as being already marked in ADDR_HASH. */
1239 target_call_site
= NULL
;
1243 struct symbol
*target_func
;
1245 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1246 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1251 /* Attempt to visit TARGET_CALL_SITE. */
1253 if (target_call_site
)
1255 if (addr_hash
.insert (target_call_site
->pc
).second
)
1257 /* Successfully entered TARGET_CALL_SITE. */
1259 chain
.push_back (target_call_site
);
1264 /* Backtrack (without revisiting the originating call_site). Try the
1265 callers's sibling; if there isn't any try the callers's callers's
1268 target_call_site
= NULL
;
1269 while (!chain
.empty ())
1271 call_site
= chain
.back ();
1274 size_t removed
= addr_hash
.erase (call_site
->pc
);
1275 gdb_assert (removed
== 1);
1277 target_call_site
= call_site
->tail_call_next
;
1278 if (target_call_site
)
1282 while (target_call_site
);
1287 call_site
= chain
.back ();
1292 struct bound_minimal_symbol msym_caller
, msym_callee
;
1294 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1295 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1296 throw_error (NO_ENTRY_VALUE_ERROR
,
1297 _("There are no unambiguously determinable intermediate "
1298 "callers or callees between caller function \"%s\" at %s "
1299 "and callee function \"%s\" at %s"),
1300 (msym_caller
.minsym
== NULL
1301 ? "???" : msym_caller
.minsym
->print_name ()),
1302 paddress (gdbarch
, caller_pc
),
1303 (msym_callee
.minsym
== NULL
1304 ? "???" : msym_callee
.minsym
->print_name ()),
1305 paddress (gdbarch
, callee_pc
));
1311 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1312 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1313 constructed return NULL. */
1315 gdb::unique_xmalloc_ptr
<call_site_chain
>
1316 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1317 CORE_ADDR callee_pc
)
1319 gdb::unique_xmalloc_ptr
<call_site_chain
> retval
;
1323 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1325 catch (const gdb_exception_error
&e
)
1327 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1329 if (entry_values_debug
)
1330 exception_print (gdb_stdout
, e
);
1341 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1344 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1345 enum call_site_parameter_kind kind
,
1346 union call_site_parameter_u kind_u
)
1348 if (kind
== parameter
->kind
)
1351 case CALL_SITE_PARAMETER_DWARF_REG
:
1352 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1354 case CALL_SITE_PARAMETER_FB_OFFSET
:
1355 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1357 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1358 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1363 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1364 FRAME is for callee.
1366 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1369 static struct call_site_parameter
*
1370 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1371 enum call_site_parameter_kind kind
,
1372 union call_site_parameter_u kind_u
,
1373 dwarf2_per_cu_data
**per_cu_return
,
1374 dwarf2_per_objfile
**per_objfile_return
)
1376 CORE_ADDR func_addr
, caller_pc
;
1377 struct gdbarch
*gdbarch
;
1378 struct frame_info
*caller_frame
;
1379 struct call_site
*call_site
;
1381 /* Initialize it just to avoid a GCC false warning. */
1382 struct call_site_parameter
*parameter
= NULL
;
1383 CORE_ADDR target_addr
;
1385 while (get_frame_type (frame
) == INLINE_FRAME
)
1387 frame
= get_prev_frame (frame
);
1388 gdb_assert (frame
!= NULL
);
1391 func_addr
= get_frame_func (frame
);
1392 gdbarch
= get_frame_arch (frame
);
1393 caller_frame
= get_prev_frame (frame
);
1394 if (gdbarch
!= frame_unwind_arch (frame
))
1396 struct bound_minimal_symbol msym
1397 = lookup_minimal_symbol_by_pc (func_addr
);
1398 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1400 throw_error (NO_ENTRY_VALUE_ERROR
,
1401 _("DW_OP_entry_value resolving callee gdbarch %s "
1402 "(of %s (%s)) does not match caller gdbarch %s"),
1403 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1404 paddress (gdbarch
, func_addr
),
1405 (msym
.minsym
== NULL
? "???"
1406 : msym
.minsym
->print_name ()),
1407 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1410 if (caller_frame
== NULL
)
1412 struct bound_minimal_symbol msym
1413 = lookup_minimal_symbol_by_pc (func_addr
);
1415 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1416 "requires caller of %s (%s)"),
1417 paddress (gdbarch
, func_addr
),
1418 (msym
.minsym
== NULL
? "???"
1419 : msym
.minsym
->print_name ()));
1421 caller_pc
= get_frame_pc (caller_frame
);
1422 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1424 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1425 if (target_addr
!= func_addr
)
1427 struct minimal_symbol
*target_msym
, *func_msym
;
1429 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1430 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1431 throw_error (NO_ENTRY_VALUE_ERROR
,
1432 _("DW_OP_entry_value resolving expects callee %s at %s "
1433 "but the called frame is for %s at %s"),
1434 (target_msym
== NULL
? "???"
1435 : target_msym
->print_name ()),
1436 paddress (gdbarch
, target_addr
),
1437 func_msym
== NULL
? "???" : func_msym
->print_name (),
1438 paddress (gdbarch
, func_addr
));
1441 /* No entry value based parameters would be reliable if this function can
1442 call itself via tail calls. */
1443 func_verify_no_selftailcall (gdbarch
, func_addr
);
1445 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1447 parameter
= &call_site
->parameter
[iparams
];
1448 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1451 if (iparams
== call_site
->parameter_count
)
1453 struct minimal_symbol
*msym
1454 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1456 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1457 determine its value. */
1458 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1459 "at DW_TAG_call_site %s at %s"),
1460 paddress (gdbarch
, caller_pc
),
1461 msym
== NULL
? "???" : msym
->print_name ());
1464 *per_cu_return
= call_site
->per_cu
;
1465 *per_objfile_return
= call_site
->per_objfile
;
1469 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1470 the normal DW_AT_call_value block. Otherwise return the
1471 DW_AT_call_data_value (dereferenced) block.
1473 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1476 Function always returns non-NULL, non-optimized out value. It throws
1477 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1479 static struct value
*
1480 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1481 CORE_ADDR deref_size
, struct type
*type
,
1482 struct frame_info
*caller_frame
,
1483 dwarf2_per_cu_data
*per_cu
,
1484 dwarf2_per_objfile
*per_objfile
)
1486 const gdb_byte
*data_src
;
1490 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1491 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1493 /* DEREF_SIZE size is not verified here. */
1494 if (data_src
== NULL
)
1495 throw_error (NO_ENTRY_VALUE_ERROR
,
1496 _("Cannot resolve DW_AT_call_data_value"));
1498 /* DW_AT_call_value is a DWARF expression, not a DWARF
1499 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1501 data
= (gdb_byte
*) alloca (size
+ 1);
1502 memcpy (data
, data_src
, size
);
1503 data
[size
] = DW_OP_stack_value
;
1505 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
,
1509 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1510 the indirect method on it, that is use its stored target value, the sole
1511 purpose of entry_data_value_funcs.. */
1513 static struct value
*
1514 entry_data_value_coerce_ref (const struct value
*value
)
1516 struct type
*checked_type
= check_typedef (value_type (value
));
1517 struct value
*target_val
;
1519 if (!TYPE_IS_REFERENCE (checked_type
))
1522 target_val
= (struct value
*) value_computed_closure (value
);
1523 value_incref (target_val
);
1527 /* Implement copy_closure. */
1530 entry_data_value_copy_closure (const struct value
*v
)
1532 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1534 value_incref (target_val
);
1538 /* Implement free_closure. */
1541 entry_data_value_free_closure (struct value
*v
)
1543 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1545 value_decref (target_val
);
1548 /* Vector for methods for an entry value reference where the referenced value
1549 is stored in the caller. On the first dereference use
1550 DW_AT_call_data_value in the caller. */
1552 static const struct lval_funcs entry_data_value_funcs
=
1556 NULL
, /* indirect */
1557 entry_data_value_coerce_ref
,
1558 NULL
, /* check_synthetic_pointer */
1559 entry_data_value_copy_closure
,
1560 entry_data_value_free_closure
1563 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1564 are used to match DW_AT_location at the caller's
1565 DW_TAG_call_site_parameter.
1567 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1568 cannot resolve the parameter for any reason. */
1570 static struct value
*
1571 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1572 enum call_site_parameter_kind kind
,
1573 union call_site_parameter_u kind_u
)
1575 struct type
*checked_type
= check_typedef (type
);
1576 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1577 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1578 struct value
*outer_val
, *target_val
, *val
;
1579 struct call_site_parameter
*parameter
;
1580 dwarf2_per_cu_data
*caller_per_cu
;
1581 dwarf2_per_objfile
*caller_per_objfile
;
1583 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1585 &caller_per_objfile
);
1587 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1590 caller_per_objfile
);
1592 /* Check if DW_AT_call_data_value cannot be used. If it should be
1593 used and it is not available do not fall back to OUTER_VAL - dereferencing
1594 TYPE_CODE_REF with non-entry data value would give current value - not the
1597 if (!TYPE_IS_REFERENCE (checked_type
)
1598 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1601 target_val
= dwarf_entry_parameter_to_value (parameter
,
1602 TYPE_LENGTH (target_type
),
1603 target_type
, caller_frame
,
1605 caller_per_objfile
);
1607 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1608 release_value (target_val
).release ());
1610 /* Copy the referencing pointer to the new computed value. */
1611 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1612 TYPE_LENGTH (checked_type
));
1613 set_value_lazy (val
, 0);
1618 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1619 SIZE are DWARF block used to match DW_AT_location at the caller's
1620 DW_TAG_call_site_parameter.
1622 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1623 cannot resolve the parameter for any reason. */
1625 static struct value
*
1626 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1627 const gdb_byte
*block
, size_t block_len
)
1629 union call_site_parameter_u kind_u
;
1631 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1632 if (kind_u
.dwarf_reg
!= -1)
1633 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1636 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1637 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1640 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1641 suppressed during normal operation. The expression can be arbitrary if
1642 there is no caller-callee entry value binding expected. */
1643 throw_error (NO_ENTRY_VALUE_ERROR
,
1644 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1645 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1648 struct piece_closure
1650 /* Reference count. */
1653 /* The objfile from which this closure's expression came. */
1654 dwarf2_per_objfile
*per_objfile
= nullptr;
1656 /* The CU from which this closure's expression came. */
1657 struct dwarf2_per_cu_data
*per_cu
= NULL
;
1659 /* The pieces describing this variable. */
1660 std::vector
<dwarf_expr_piece
> pieces
;
1662 /* Frame ID of frame to which a register value is relative, used
1663 only by DWARF_VALUE_REGISTER. */
1664 struct frame_id frame_id
;
1667 /* Allocate a closure for a value formed from separately-described
1670 static struct piece_closure
*
1671 allocate_piece_closure (dwarf2_per_cu_data
*per_cu
,
1672 dwarf2_per_objfile
*per_objfile
,
1673 std::vector
<dwarf_expr_piece
> &&pieces
,
1674 struct frame_info
*frame
)
1676 struct piece_closure
*c
= new piece_closure
;
1679 /* We must capture this here due to sharing of DWARF state. */
1680 c
->per_objfile
= per_objfile
;
1682 c
->pieces
= std::move (pieces
);
1684 c
->frame_id
= null_frame_id
;
1686 c
->frame_id
= get_frame_id (frame
);
1688 for (dwarf_expr_piece
&piece
: c
->pieces
)
1689 if (piece
.location
== DWARF_VALUE_STACK
)
1690 value_incref (piece
.v
.value
);
1695 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1696 bits whose first bit is located at bit offset START. */
1699 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1701 return (start
% 8 + n_bits
+ 7) / 8;
1704 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1705 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1706 operate in "read mode": fetch the contents of the (lazy) value V by
1707 composing it from its pieces. */
1710 rw_pieced_value (struct value
*v
, struct value
*from
)
1713 LONGEST offset
= 0, max_offset
;
1714 ULONGEST bits_to_skip
;
1715 gdb_byte
*v_contents
;
1716 const gdb_byte
*from_contents
;
1717 struct piece_closure
*c
1718 = (struct piece_closure
*) value_computed_closure (v
);
1719 gdb::byte_vector buffer
;
1720 bool bits_big_endian
= type_byte_order (value_type (v
)) == BFD_ENDIAN_BIG
;
1724 from_contents
= value_contents (from
);
1729 if (value_type (v
) != value_enclosing_type (v
))
1730 internal_error (__FILE__
, __LINE__
,
1731 _("Should not be able to create a lazy value with "
1732 "an enclosing type"));
1733 v_contents
= value_contents_raw (v
);
1734 from_contents
= NULL
;
1737 bits_to_skip
= 8 * value_offset (v
);
1738 if (value_bitsize (v
))
1740 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1741 + value_bitpos (v
));
1743 && (type_byte_order (value_type (from
))
1746 /* Use the least significant bits of FROM. */
1747 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1748 offset
= max_offset
- value_bitsize (v
);
1751 max_offset
= value_bitsize (v
);
1754 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1756 /* Advance to the first non-skipped piece. */
1757 for (i
= 0; i
< c
->pieces
.size () && bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1758 bits_to_skip
-= c
->pieces
[i
].size
;
1760 for (; i
< c
->pieces
.size () && offset
< max_offset
; i
++)
1762 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1763 size_t this_size_bits
, this_size
;
1765 this_size_bits
= p
->size
- bits_to_skip
;
1766 if (this_size_bits
> max_offset
- offset
)
1767 this_size_bits
= max_offset
- offset
;
1769 switch (p
->location
)
1771 case DWARF_VALUE_REGISTER
:
1773 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1774 struct gdbarch
*arch
= get_frame_arch (frame
);
1775 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1776 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1779 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1780 && p
->offset
+ p
->size
< reg_bits
)
1782 /* Big-endian, and we want less than full size. */
1783 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1786 bits_to_skip
+= p
->offset
;
1788 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1789 buffer
.resize (this_size
);
1794 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1800 mark_value_bits_optimized_out (v
, offset
,
1803 mark_value_bits_unavailable (v
, offset
,
1808 copy_bitwise (v_contents
, offset
,
1809 buffer
.data (), bits_to_skip
% 8,
1810 this_size_bits
, bits_big_endian
);
1815 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1817 /* Data is copied non-byte-aligned into the register.
1818 Need some bits from original register value. */
1819 get_frame_register_bytes (frame
, gdb_regnum
,
1824 throw_error (OPTIMIZED_OUT_ERROR
,
1825 _("Can't do read-modify-write to "
1826 "update bitfield; containing word "
1827 "has been optimized out"));
1829 throw_error (NOT_AVAILABLE_ERROR
,
1830 _("Can't do read-modify-write to "
1831 "update bitfield; containing word "
1835 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1836 from_contents
, offset
,
1837 this_size_bits
, bits_big_endian
);
1838 put_frame_register_bytes (frame
, gdb_regnum
,
1845 case DWARF_VALUE_MEMORY
:
1847 bits_to_skip
+= p
->offset
;
1849 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1851 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1854 /* Everything is byte-aligned; no buffer needed. */
1856 write_memory_with_notification (start_addr
,
1859 this_size_bits
/ 8);
1861 read_value_memory (v
, offset
,
1862 p
->v
.mem
.in_stack_memory
,
1863 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1864 v_contents
+ offset
/ 8,
1865 this_size_bits
/ 8);
1869 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1870 buffer
.resize (this_size
);
1875 read_value_memory (v
, offset
,
1876 p
->v
.mem
.in_stack_memory
,
1877 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1878 buffer
.data (), this_size
);
1879 copy_bitwise (v_contents
, offset
,
1880 buffer
.data (), bits_to_skip
% 8,
1881 this_size_bits
, bits_big_endian
);
1886 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1890 /* Perform a single read for small sizes. */
1891 read_memory (start_addr
, buffer
.data (),
1896 /* Only the first and last bytes can possibly have
1898 read_memory (start_addr
, buffer
.data (), 1);
1899 read_memory (start_addr
+ this_size
- 1,
1900 &buffer
[this_size
- 1], 1);
1904 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1905 from_contents
, offset
,
1906 this_size_bits
, bits_big_endian
);
1907 write_memory_with_notification (start_addr
,
1914 case DWARF_VALUE_STACK
:
1918 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1922 gdbarch
*objfile_gdbarch
= c
->per_objfile
->objfile
->arch ();
1923 ULONGEST stack_value_size_bits
1924 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1926 /* Use zeroes if piece reaches beyond stack value. */
1927 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1930 /* Piece is anchored at least significant bit end. */
1931 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1932 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1934 bits_to_skip
+= p
->offset
;
1936 copy_bitwise (v_contents
, offset
,
1937 value_contents_all (p
->v
.value
),
1939 this_size_bits
, bits_big_endian
);
1943 case DWARF_VALUE_LITERAL
:
1947 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1951 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
1952 size_t n
= this_size_bits
;
1954 /* Cut off at the end of the implicit value. */
1955 bits_to_skip
+= p
->offset
;
1956 if (bits_to_skip
>= literal_size_bits
)
1958 if (n
> literal_size_bits
- bits_to_skip
)
1959 n
= literal_size_bits
- bits_to_skip
;
1961 copy_bitwise (v_contents
, offset
,
1962 p
->v
.literal
.data
, bits_to_skip
,
1963 n
, bits_big_endian
);
1967 case DWARF_VALUE_IMPLICIT_POINTER
:
1970 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1974 /* These bits show up as zeros -- but do not cause the value to
1975 be considered optimized-out. */
1978 case DWARF_VALUE_OPTIMIZED_OUT
:
1979 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1983 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1986 offset
+= this_size_bits
;
1993 read_pieced_value (struct value
*v
)
1995 rw_pieced_value (v
, NULL
);
1999 write_pieced_value (struct value
*to
, struct value
*from
)
2001 rw_pieced_value (to
, from
);
2004 /* An implementation of an lval_funcs method to see whether a value is
2005 a synthetic pointer. */
2008 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
2011 struct piece_closure
*c
2012 = (struct piece_closure
*) value_computed_closure (value
);
2015 bit_offset
+= 8 * value_offset (value
);
2016 if (value_bitsize (value
))
2017 bit_offset
+= value_bitpos (value
);
2019 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2021 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2022 size_t this_size_bits
= p
->size
;
2026 if (bit_offset
>= this_size_bits
)
2028 bit_offset
-= this_size_bits
;
2032 bit_length
-= this_size_bits
- bit_offset
;
2036 bit_length
-= this_size_bits
;
2038 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2045 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2047 static struct value
*
2048 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2049 dwarf2_per_cu_data
*per_cu
,
2050 dwarf2_per_objfile
*per_objfile
,
2053 struct value
*result
= NULL
;
2054 const gdb_byte
*bytes
;
2057 auto_obstack temp_obstack
;
2058 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, per_objfile
,
2059 &temp_obstack
, &len
);
2063 if (byte_offset
>= 0
2064 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2066 bytes
+= byte_offset
;
2067 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2070 invalid_synthetic_pointer ();
2073 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2078 /* Fetch the value pointed to by a synthetic pointer. */
2080 static struct value
*
2081 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2082 dwarf2_per_cu_data
*per_cu
,
2083 dwarf2_per_objfile
*per_objfile
,
2084 struct frame_info
*frame
, struct type
*type
,
2085 bool resolve_abstract_p
)
2087 /* Fetch the location expression of the DIE we're pointing to. */
2088 auto get_frame_address_in_block_wrapper
= [frame
] ()
2090 return get_frame_address_in_block (frame
);
2092 struct dwarf2_locexpr_baton baton
2093 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
, per_objfile
,
2094 get_frame_address_in_block_wrapper
,
2095 resolve_abstract_p
);
2097 /* Get type of pointed-to DIE. */
2098 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
,
2100 if (orig_type
== NULL
)
2101 invalid_synthetic_pointer ();
2103 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2104 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2105 or it may've been optimized out. */
2106 if (baton
.data
!= NULL
)
2107 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2108 baton
.size
, baton
.per_cu
,
2110 TYPE_TARGET_TYPE (type
),
2113 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2117 /* An implementation of an lval_funcs method to indirect through a
2118 pointer. This handles the synthetic pointer case when needed. */
2120 static struct value
*
2121 indirect_pieced_value (struct value
*value
)
2123 struct piece_closure
*c
2124 = (struct piece_closure
*) value_computed_closure (value
);
2126 struct frame_info
*frame
;
2129 struct dwarf_expr_piece
*piece
= NULL
;
2130 LONGEST byte_offset
;
2131 enum bfd_endian byte_order
;
2133 type
= check_typedef (value_type (value
));
2134 if (type
->code () != TYPE_CODE_PTR
)
2137 bit_length
= 8 * TYPE_LENGTH (type
);
2138 bit_offset
= 8 * value_offset (value
);
2139 if (value_bitsize (value
))
2140 bit_offset
+= value_bitpos (value
);
2142 for (i
= 0; i
< c
->pieces
.size () && bit_length
> 0; i
++)
2144 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2145 size_t this_size_bits
= p
->size
;
2149 if (bit_offset
>= this_size_bits
)
2151 bit_offset
-= this_size_bits
;
2155 bit_length
-= this_size_bits
- bit_offset
;
2159 bit_length
-= this_size_bits
;
2161 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2164 if (bit_length
!= 0)
2165 error (_("Invalid use of DW_OP_implicit_pointer"));
2171 gdb_assert (piece
!= NULL
);
2172 frame
= get_selected_frame (_("No frame selected."));
2174 /* This is an offset requested by GDB, such as value subscripts.
2175 However, due to how synthetic pointers are implemented, this is
2176 always presented to us as a pointer type. This means we have to
2177 sign-extend it manually as appropriate. Use raw
2178 extract_signed_integer directly rather than value_as_address and
2179 sign extend afterwards on architectures that would need it
2180 (mostly everywhere except MIPS, which has signed addresses) as
2181 the later would go through gdbarch_pointer_to_address and thus
2182 return a CORE_ADDR with high bits set on architectures that
2183 encode address spaces and other things in CORE_ADDR. */
2184 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2185 byte_offset
= extract_signed_integer (value_contents (value
),
2186 TYPE_LENGTH (type
), byte_order
);
2187 byte_offset
+= piece
->v
.ptr
.offset
;
2189 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2190 byte_offset
, c
->per_cu
,
2191 c
->per_objfile
, frame
, type
);
2194 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2197 static struct value
*
2198 coerce_pieced_ref (const struct value
*value
)
2200 struct type
*type
= check_typedef (value_type (value
));
2202 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2203 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2205 const struct piece_closure
*closure
2206 = (struct piece_closure
*) value_computed_closure (value
);
2207 struct frame_info
*frame
2208 = get_selected_frame (_("No frame selected."));
2210 /* gdb represents synthetic pointers as pieced values with a single
2212 gdb_assert (closure
!= NULL
);
2213 gdb_assert (closure
->pieces
.size () == 1);
2215 return indirect_synthetic_pointer
2216 (closure
->pieces
[0].v
.ptr
.die_sect_off
,
2217 closure
->pieces
[0].v
.ptr
.offset
,
2218 closure
->per_cu
, closure
->per_objfile
, frame
, type
);
2222 /* Else: not a synthetic reference; do nothing. */
2228 copy_pieced_value_closure (const struct value
*v
)
2230 struct piece_closure
*c
2231 = (struct piece_closure
*) value_computed_closure (v
);
2238 free_pieced_value_closure (struct value
*v
)
2240 struct piece_closure
*c
2241 = (struct piece_closure
*) value_computed_closure (v
);
2246 for (dwarf_expr_piece
&p
: c
->pieces
)
2247 if (p
.location
== DWARF_VALUE_STACK
)
2248 value_decref (p
.v
.value
);
2254 /* Functions for accessing a variable described by DW_OP_piece. */
2255 static const struct lval_funcs pieced_value_funcs
= {
2258 indirect_pieced_value
,
2260 check_pieced_synthetic_pointer
,
2261 copy_pieced_value_closure
,
2262 free_pieced_value_closure
2265 /* Evaluate a location description, starting at DATA and with length
2266 SIZE, to find the current location of variable of TYPE in the
2267 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2268 location of the subobject of type SUBOBJ_TYPE at byte offset
2269 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2271 static struct value
*
2272 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2273 const gdb_byte
*data
, size_t size
,
2274 dwarf2_per_cu_data
*per_cu
,
2275 dwarf2_per_objfile
*per_objfile
,
2276 struct type
*subobj_type
,
2277 LONGEST subobj_byte_offset
)
2279 struct value
*retval
;
2281 if (subobj_type
== NULL
)
2284 subobj_byte_offset
= 0;
2286 else if (subobj_byte_offset
< 0)
2287 invalid_synthetic_pointer ();
2290 return allocate_optimized_out_value (subobj_type
);
2292 dwarf_evaluate_loc_desc
ctx (per_objfile
);
2294 ctx
.per_cu
= per_cu
;
2295 ctx
.obj_address
= 0;
2297 scoped_value_mark free_values
;
2299 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2300 ctx
.addr_size
= per_cu
->addr_size ();
2301 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2305 ctx
.eval (data
, size
);
2307 catch (const gdb_exception_error
&ex
)
2309 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2311 free_values
.free_to_mark ();
2312 retval
= allocate_value (subobj_type
);
2313 mark_value_bytes_unavailable (retval
, 0,
2314 TYPE_LENGTH (subobj_type
));
2317 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2319 if (entry_values_debug
)
2320 exception_print (gdb_stdout
, ex
);
2321 free_values
.free_to_mark ();
2322 return allocate_optimized_out_value (subobj_type
);
2328 if (ctx
.pieces
.size () > 0)
2330 struct piece_closure
*c
;
2331 ULONGEST bit_size
= 0;
2333 for (dwarf_expr_piece
&piece
: ctx
.pieces
)
2334 bit_size
+= piece
.size
;
2335 /* Complain if the expression is larger than the size of the
2337 if (bit_size
> 8 * TYPE_LENGTH (type
))
2338 invalid_synthetic_pointer ();
2340 c
= allocate_piece_closure (per_cu
, per_objfile
, std::move (ctx
.pieces
),
2342 /* We must clean up the value chain after creating the piece
2343 closure but before allocating the result. */
2344 free_values
.free_to_mark ();
2345 retval
= allocate_computed_value (subobj_type
,
2346 &pieced_value_funcs
, c
);
2347 set_value_offset (retval
, subobj_byte_offset
);
2351 switch (ctx
.location
)
2353 case DWARF_VALUE_REGISTER
:
2355 struct gdbarch
*arch
= get_frame_arch (frame
);
2357 = longest_to_int (value_as_long (ctx
.fetch (0)));
2358 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2360 if (subobj_byte_offset
!= 0)
2361 error (_("cannot use offset on synthetic pointer to register"));
2362 free_values
.free_to_mark ();
2363 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2364 if (value_optimized_out (retval
))
2368 /* This means the register has undefined value / was
2369 not saved. As we're computing the location of some
2370 variable etc. in the program, not a value for
2371 inspecting a register ($pc, $sp, etc.), return a
2372 generic optimized out value instead, so that we show
2373 <optimized out> instead of <not saved>. */
2374 tmp
= allocate_value (subobj_type
);
2375 value_contents_copy (tmp
, 0, retval
, 0,
2376 TYPE_LENGTH (subobj_type
));
2382 case DWARF_VALUE_MEMORY
:
2384 struct type
*ptr_type
;
2385 CORE_ADDR address
= ctx
.fetch_address (0);
2386 bool in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2388 /* DW_OP_deref_size (and possibly other operations too) may
2389 create a pointer instead of an address. Ideally, the
2390 pointer to address conversion would be performed as part
2391 of those operations, but the type of the object to
2392 which the address refers is not known at the time of
2393 the operation. Therefore, we do the conversion here
2394 since the type is readily available. */
2396 switch (subobj_type
->code ())
2398 case TYPE_CODE_FUNC
:
2399 case TYPE_CODE_METHOD
:
2400 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2403 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2406 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2408 free_values
.free_to_mark ();
2409 retval
= value_at_lazy (subobj_type
,
2410 address
+ subobj_byte_offset
);
2411 if (in_stack_memory
)
2412 set_value_stack (retval
, 1);
2416 case DWARF_VALUE_STACK
:
2418 struct value
*value
= ctx
.fetch (0);
2419 size_t n
= TYPE_LENGTH (value_type (value
));
2420 size_t len
= TYPE_LENGTH (subobj_type
);
2421 size_t max
= TYPE_LENGTH (type
);
2422 gdbarch
*objfile_gdbarch
= per_objfile
->objfile
->arch ();
2424 if (subobj_byte_offset
+ len
> max
)
2425 invalid_synthetic_pointer ();
2427 /* Preserve VALUE because we are going to free values back
2428 to the mark, but we still need the value contents
2430 value_ref_ptr value_holder
= value_ref_ptr::new_reference (value
);
2431 free_values
.free_to_mark ();
2433 retval
= allocate_value (subobj_type
);
2435 /* The given offset is relative to the actual object. */
2436 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2437 subobj_byte_offset
+= n
- max
;
2439 memcpy (value_contents_raw (retval
),
2440 value_contents_all (value
) + subobj_byte_offset
, len
);
2444 case DWARF_VALUE_LITERAL
:
2447 size_t n
= TYPE_LENGTH (subobj_type
);
2449 if (subobj_byte_offset
+ n
> ctx
.len
)
2450 invalid_synthetic_pointer ();
2452 free_values
.free_to_mark ();
2453 retval
= allocate_value (subobj_type
);
2454 contents
= value_contents_raw (retval
);
2455 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2459 case DWARF_VALUE_OPTIMIZED_OUT
:
2460 free_values
.free_to_mark ();
2461 retval
= allocate_optimized_out_value (subobj_type
);
2464 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2465 operation by execute_stack_op. */
2466 case DWARF_VALUE_IMPLICIT_POINTER
:
2467 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2468 it can only be encountered when making a piece. */
2470 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2474 set_value_initialized (retval
, ctx
.initialized
);
2479 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2480 passes 0 as the byte_offset. */
2483 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2484 const gdb_byte
*data
, size_t size
,
2485 dwarf2_per_cu_data
*per_cu
,
2486 dwarf2_per_objfile
*per_objfile
)
2488 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2489 per_objfile
, NULL
, 0);
2492 /* A specialization of dwarf_evaluate_loc_desc that is used by
2493 dwarf2_locexpr_baton_eval. This subclass exists to handle the case
2494 where a caller of dwarf2_locexpr_baton_eval passes in some data,
2495 but with the address being 0. In this situation, we arrange for
2496 memory reads to come from the passed-in buffer. */
2498 struct evaluate_for_locexpr_baton
: public dwarf_evaluate_loc_desc
2500 evaluate_for_locexpr_baton (dwarf2_per_objfile
*per_objfile
)
2501 : dwarf_evaluate_loc_desc (per_objfile
)
2504 /* The data that was passed in. */
2505 gdb::array_view
<const gdb_byte
> data_view
;
2507 CORE_ADDR
get_object_address () override
2509 if (data_view
.data () == nullptr && obj_address
== 0)
2510 error (_("Location address is not set."));
2514 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2519 /* Prefer the passed-in memory, if it exists. */
2520 CORE_ADDR offset
= addr
- obj_address
;
2521 if (offset
< data_view
.size () && offset
+ len
<= data_view
.size ())
2523 memcpy (buf
, data_view
.data (), len
);
2527 read_memory (addr
, buf
, len
);
2531 /* Evaluates a dwarf expression and stores the result in VAL,
2532 expecting that the dwarf expression only produces a single
2533 CORE_ADDR. FRAME is the frame in which the expression is
2534 evaluated. ADDR_STACK is a context (location of a variable) and
2535 might be needed to evaluate the location expression.
2536 PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
2537 or the default of 0) should be pushed on the DWARF expression
2538 evaluation stack before evaluating the expression; this is required
2539 by certain forms of DWARF expression. Returns 1 on success, 0
2543 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2544 struct frame_info
*frame
,
2545 const struct property_addr_info
*addr_stack
,
2547 bool push_initial_value
,
2550 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2553 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
2554 evaluate_for_locexpr_baton
ctx (per_objfile
);
2557 ctx
.per_cu
= dlbaton
->per_cu
;
2558 if (addr_stack
== nullptr)
2559 ctx
.obj_address
= 0;
2562 ctx
.obj_address
= addr_stack
->addr
;
2563 ctx
.data_view
= addr_stack
->valaddr
;
2566 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2567 ctx
.addr_size
= dlbaton
->per_cu
->addr_size ();
2568 ctx
.ref_addr_size
= dlbaton
->per_cu
->ref_addr_size ();
2570 if (push_initial_value
)
2571 ctx
.push_address (ctx
.obj_address
, false);
2575 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2577 catch (const gdb_exception_error
&ex
)
2579 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2583 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2585 if (entry_values_debug
)
2586 exception_print (gdb_stdout
, ex
);
2593 switch (ctx
.location
)
2595 case DWARF_VALUE_STACK
:
2596 *is_reference
= false;
2599 case DWARF_VALUE_REGISTER
:
2600 case DWARF_VALUE_MEMORY
:
2601 *valp
= ctx
.fetch_address (0);
2602 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2603 *valp
= ctx
.read_addr_from_reg (*valp
);
2605 case DWARF_VALUE_LITERAL
:
2606 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2607 gdbarch_byte_order (ctx
.gdbarch
));
2609 /* Unsupported dwarf values. */
2610 case DWARF_VALUE_OPTIMIZED_OUT
:
2611 case DWARF_VALUE_IMPLICIT_POINTER
:
2618 /* See dwarf2loc.h. */
2621 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2622 struct frame_info
*frame
,
2623 const struct property_addr_info
*addr_stack
,
2625 bool push_initial_value
)
2630 if (frame
== NULL
&& has_stack_frames ())
2631 frame
= get_selected_frame (NULL
);
2633 switch (prop
->kind ())
2637 const struct dwarf2_property_baton
*baton
2638 = (const struct dwarf2_property_baton
*) prop
->baton ();
2639 gdb_assert (baton
->property_type
!= NULL
);
2641 bool is_reference
= baton
->locexpr
.is_reference
;
2642 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
, addr_stack
,
2643 value
, push_initial_value
, &is_reference
))
2647 struct value
*val
= value_at (baton
->property_type
, *value
);
2648 *value
= value_as_address (val
);
2652 gdb_assert (baton
->property_type
!= NULL
);
2654 struct type
*type
= check_typedef (baton
->property_type
);
2655 if (TYPE_LENGTH (type
) < sizeof (CORE_ADDR
)
2656 && !type
->is_unsigned ())
2658 /* If we have a valid return candidate and it's value
2659 is signed, we have to sign-extend the value because
2660 CORE_ADDR on 64bit machine has 8 bytes but address
2661 size of an 32bit application is bytes. */
2663 = (baton
->locexpr
.per_cu
->addr_size ()
2665 const CORE_ADDR neg_mask
2666 = (~((CORE_ADDR
) 0) << (addr_size
- 1));
2668 /* Check if signed bit is set and sign-extend values. */
2669 if (*value
& neg_mask
)
2680 struct dwarf2_property_baton
*baton
2681 = (struct dwarf2_property_baton
*) prop
->baton ();
2683 const gdb_byte
*data
;
2688 || !get_frame_address_in_block_if_available (frame
, &pc
))
2691 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2694 val
= dwarf2_evaluate_loc_desc (baton
->property_type
, frame
, data
,
2695 size
, baton
->loclist
.per_cu
,
2696 baton
->loclist
.per_objfile
);
2697 if (!value_optimized_out (val
))
2699 *value
= value_as_address (val
);
2707 *value
= prop
->const_val ();
2710 case PROP_ADDR_OFFSET
:
2712 struct dwarf2_property_baton
*baton
2713 = (struct dwarf2_property_baton
*) prop
->baton ();
2714 const struct property_addr_info
*pinfo
;
2717 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2719 /* This approach lets us avoid checking the qualifiers. */
2720 if (TYPE_MAIN_TYPE (pinfo
->type
)
2721 == TYPE_MAIN_TYPE (baton
->property_type
))
2725 error (_("cannot find reference address for offset property"));
2726 if (pinfo
->valaddr
.data () != NULL
)
2727 val
= value_from_contents
2728 (baton
->offset_info
.type
,
2729 pinfo
->valaddr
.data () + baton
->offset_info
.offset
);
2731 val
= value_at (baton
->offset_info
.type
,
2732 pinfo
->addr
+ baton
->offset_info
.offset
);
2733 *value
= value_as_address (val
);
2737 case PROP_VARIABLE_NAME
:
2739 struct value
*val
= compute_var_value (prop
->variable_name ());
2742 *value
= value_as_long (val
);
2752 /* See dwarf2loc.h. */
2755 dwarf2_compile_property_to_c (string_file
*stream
,
2756 const char *result_name
,
2757 struct gdbarch
*gdbarch
,
2758 std::vector
<bool> ®isters_used
,
2759 const struct dynamic_prop
*prop
,
2763 struct dwarf2_property_baton
*baton
2764 = (struct dwarf2_property_baton
*) prop
->baton ();
2765 const gdb_byte
*data
;
2767 dwarf2_per_cu_data
*per_cu
;
2768 dwarf2_per_objfile
*per_objfile
;
2770 if (prop
->kind () == PROP_LOCEXPR
)
2772 data
= baton
->locexpr
.data
;
2773 size
= baton
->locexpr
.size
;
2774 per_cu
= baton
->locexpr
.per_cu
;
2775 per_objfile
= baton
->locexpr
.per_objfile
;
2779 gdb_assert (prop
->kind () == PROP_LOCLIST
);
2781 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2782 per_cu
= baton
->loclist
.per_cu
;
2783 per_objfile
= baton
->loclist
.per_objfile
;
2786 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2787 gdbarch
, registers_used
,
2788 per_cu
->addr_size (),
2789 data
, data
+ size
, per_cu
, per_objfile
);
2793 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2795 class symbol_needs_eval_context
: public dwarf_expr_context
2798 symbol_needs_eval_context (dwarf2_per_objfile
*per_objfile
)
2799 : dwarf_expr_context (per_objfile
)
2802 enum symbol_needs_kind needs
;
2803 struct dwarf2_per_cu_data
*per_cu
;
2805 /* Reads from registers do require a frame. */
2806 CORE_ADDR
read_addr_from_reg (int regnum
) override
2808 needs
= SYMBOL_NEEDS_FRAME
;
2812 /* "get_reg_value" callback: Reads from registers do require a
2815 struct value
*get_reg_value (struct type
*type
, int regnum
) override
2817 needs
= SYMBOL_NEEDS_FRAME
;
2818 return value_zero (type
, not_lval
);
2821 /* Reads from memory do not require a frame. */
2822 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) override
2824 memset (buf
, 0, len
);
2827 /* Frame-relative accesses do require a frame. */
2828 void get_frame_base (const gdb_byte
**start
, size_t *length
) override
2830 static gdb_byte lit0
= DW_OP_lit0
;
2835 needs
= SYMBOL_NEEDS_FRAME
;
2838 /* CFA accesses require a frame. */
2839 CORE_ADDR
get_frame_cfa () override
2841 needs
= SYMBOL_NEEDS_FRAME
;
2845 CORE_ADDR
get_frame_pc () override
2847 needs
= SYMBOL_NEEDS_FRAME
;
2851 /* Thread-local accesses require registers, but not a frame. */
2852 CORE_ADDR
get_tls_address (CORE_ADDR offset
) override
2854 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2855 needs
= SYMBOL_NEEDS_REGISTERS
;
2859 /* Helper interface of per_cu_dwarf_call for
2860 dwarf2_loc_desc_get_symbol_read_needs. */
2862 void dwarf_call (cu_offset die_offset
) override
2864 per_cu_dwarf_call (this, die_offset
, per_cu
, per_objfile
);
2867 /* Helper interface of sect_variable_value for
2868 dwarf2_loc_desc_get_symbol_read_needs. */
2870 struct value
*dwarf_variable_value (sect_offset sect_off
) override
2872 return sect_variable_value (this, sect_off
, per_cu
, per_objfile
);
2875 /* DW_OP_entry_value accesses require a caller, therefore a
2878 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2879 union call_site_parameter_u kind_u
,
2880 int deref_size
) override
2882 needs
= SYMBOL_NEEDS_FRAME
;
2884 /* The expression may require some stub values on DWARF stack. */
2885 push_address (0, 0);
2888 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2890 CORE_ADDR
get_addr_index (unsigned int index
) override
2892 /* Nothing to do. */
2896 /* DW_OP_push_object_address has a frame already passed through. */
2898 CORE_ADDR
get_object_address () override
2900 /* Nothing to do. */
2905 /* Compute the correct symbol_needs_kind value for the location
2906 expression at DATA (length SIZE). */
2908 static enum symbol_needs_kind
2909 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2910 dwarf2_per_cu_data
*per_cu
,
2911 dwarf2_per_objfile
*per_objfile
)
2913 scoped_value_mark free_values
;
2915 symbol_needs_eval_context
ctx (per_objfile
);
2917 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2918 ctx
.per_cu
= per_cu
;
2919 ctx
.gdbarch
= per_objfile
->objfile
->arch ();
2920 ctx
.addr_size
= per_cu
->addr_size ();
2921 ctx
.ref_addr_size
= per_cu
->ref_addr_size ();
2923 ctx
.eval (data
, size
);
2925 bool in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2927 /* If the location has several pieces, and any of them are in
2928 registers, then we will need a frame to fetch them from. */
2929 for (dwarf_expr_piece
&p
: ctx
.pieces
)
2930 if (p
.location
== DWARF_VALUE_REGISTER
)
2934 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2939 /* A helper function that throws an unimplemented error mentioning a
2940 given DWARF operator. */
2942 static void ATTRIBUTE_NORETURN
2943 unimplemented (unsigned int op
)
2945 const char *name
= get_DW_OP_name (op
);
2948 error (_("DWARF operator %s cannot be translated to an agent expression"),
2951 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2952 "to an agent expression"),
2958 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2959 can issue a complaint, which is better than having every target's
2960 implementation of dwarf2_reg_to_regnum do it. */
2963 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2965 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2969 complaint (_("bad DWARF register number %d"), dwarf_reg
);
2974 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2975 Throw an error because DWARF_REG is bad. */
2978 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2980 /* Still want to print -1 as "-1".
2981 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2982 but that's overkill for now. */
2983 if ((int) dwarf_reg
== dwarf_reg
)
2984 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2985 error (_("Unable to access DWARF register number %s"),
2986 pulongest (dwarf_reg
));
2989 /* See dwarf2loc.h. */
2992 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2996 if (dwarf_reg
> INT_MAX
)
2997 throw_bad_regnum_error (dwarf_reg
);
2998 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2999 bad, but that's ok. */
3000 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
3002 throw_bad_regnum_error (dwarf_reg
);
3006 /* A helper function that emits an access to memory. ARCH is the
3007 target architecture. EXPR is the expression which we are building.
3008 NBITS is the number of bits we want to read. This emits the
3009 opcodes needed to read the memory and then extract the desired
3013 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
3015 ULONGEST nbytes
= (nbits
+ 7) / 8;
3017 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
3020 ax_trace_quick (expr
, nbytes
);
3023 ax_simple (expr
, aop_ref8
);
3024 else if (nbits
<= 16)
3025 ax_simple (expr
, aop_ref16
);
3026 else if (nbits
<= 32)
3027 ax_simple (expr
, aop_ref32
);
3029 ax_simple (expr
, aop_ref64
);
3031 /* If we read exactly the number of bytes we wanted, we're done. */
3032 if (8 * nbytes
== nbits
)
3035 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
)
3037 /* On a bits-big-endian machine, we want the high-order
3039 ax_const_l (expr
, 8 * nbytes
- nbits
);
3040 ax_simple (expr
, aop_rsh_unsigned
);
3044 /* On a bits-little-endian box, we want the low-order NBITS. */
3045 ax_zero_ext (expr
, nbits
);
3049 /* Compile a DWARF location expression to an agent expression.
3051 EXPR is the agent expression we are building.
3052 LOC is the agent value we modify.
3053 ARCH is the architecture.
3054 ADDR_SIZE is the size of addresses, in bytes.
3055 OP_PTR is the start of the location expression.
3056 OP_END is one past the last byte of the location expression.
3058 This will throw an exception for various kinds of errors -- for
3059 example, if the expression cannot be compiled, or if the expression
3063 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3064 unsigned int addr_size
, const gdb_byte
*op_ptr
,
3065 const gdb_byte
*op_end
,
3066 dwarf2_per_cu_data
*per_cu
,
3067 dwarf2_per_objfile
*per_objfile
)
3069 gdbarch
*arch
= expr
->gdbarch
;
3070 std::vector
<int> dw_labels
, patches
;
3071 const gdb_byte
* const base
= op_ptr
;
3072 const gdb_byte
*previous_piece
= op_ptr
;
3073 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3074 ULONGEST bits_collected
= 0;
3075 unsigned int addr_size_bits
= 8 * addr_size
;
3076 bool bits_big_endian
= byte_order
== BFD_ENDIAN_BIG
;
3078 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3080 /* By default we are making an address. */
3081 loc
->kind
= axs_lvalue_memory
;
3083 while (op_ptr
< op_end
)
3085 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3086 uint64_t uoffset
, reg
;
3090 offsets
[op_ptr
- base
] = expr
->len
;
3093 /* Our basic approach to code generation is to map DWARF
3094 operations directly to AX operations. However, there are
3097 First, DWARF works on address-sized units, but AX always uses
3098 LONGEST. For most operations we simply ignore this
3099 difference; instead we generate sign extensions as needed
3100 before division and comparison operations. It would be nice
3101 to omit the sign extensions, but there is no way to determine
3102 the size of the target's LONGEST. (This code uses the size
3103 of the host LONGEST in some cases -- that is a bug but it is
3106 Second, some DWARF operations cannot be translated to AX.
3107 For these we simply fail. See
3108 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3143 ax_const_l (expr
, op
- DW_OP_lit0
);
3147 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3148 op_ptr
+= addr_size
;
3149 /* Some versions of GCC emit DW_OP_addr before
3150 DW_OP_GNU_push_tls_address. In this case the value is an
3151 index, not an address. We don't support things like
3152 branching between the address and the TLS op. */
3153 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3154 uoffset
+= per_objfile
->objfile
->text_section_offset ();
3155 ax_const_l (expr
, uoffset
);
3159 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3164 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3169 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3174 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3179 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3184 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3189 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3194 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3199 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3200 ax_const_l (expr
, uoffset
);
3204 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3205 ax_const_l (expr
, offset
);
3240 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3241 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3242 loc
->kind
= axs_lvalue_register
;
3246 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3247 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3248 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3249 loc
->kind
= axs_lvalue_register
;
3252 case DW_OP_implicit_value
:
3256 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3257 if (op_ptr
+ len
> op_end
)
3258 error (_("DW_OP_implicit_value: too few bytes available."));
3259 if (len
> sizeof (ULONGEST
))
3260 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3263 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3266 dwarf_expr_require_composition (op_ptr
, op_end
,
3267 "DW_OP_implicit_value");
3269 loc
->kind
= axs_rvalue
;
3273 case DW_OP_stack_value
:
3274 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3275 loc
->kind
= axs_rvalue
;
3310 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3311 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3315 ax_const_l (expr
, offset
);
3316 ax_simple (expr
, aop_add
);
3322 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3323 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3324 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3328 ax_const_l (expr
, offset
);
3329 ax_simple (expr
, aop_add
);
3336 const gdb_byte
*datastart
;
3338 const struct block
*b
;
3339 struct symbol
*framefunc
;
3341 b
= block_for_pc (expr
->scope
);
3344 error (_("No block found for address"));
3346 framefunc
= block_linkage_function (b
);
3349 error (_("No function found for block"));
3351 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3352 &datastart
, &datalen
);
3354 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3355 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, datastart
,
3356 datastart
+ datalen
, per_cu
,
3358 if (loc
->kind
== axs_lvalue_register
)
3359 require_rvalue (expr
, loc
);
3363 ax_const_l (expr
, offset
);
3364 ax_simple (expr
, aop_add
);
3367 loc
->kind
= axs_lvalue_memory
;
3372 ax_simple (expr
, aop_dup
);
3376 ax_simple (expr
, aop_pop
);
3381 ax_pick (expr
, offset
);
3385 ax_simple (expr
, aop_swap
);
3393 ax_simple (expr
, aop_rot
);
3397 case DW_OP_deref_size
:
3401 if (op
== DW_OP_deref_size
)
3406 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3407 error (_("Unsupported size %d in %s"),
3408 size
, get_DW_OP_name (op
));
3409 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3414 /* Sign extend the operand. */
3415 ax_ext (expr
, addr_size_bits
);
3416 ax_simple (expr
, aop_dup
);
3417 ax_const_l (expr
, 0);
3418 ax_simple (expr
, aop_less_signed
);
3419 ax_simple (expr
, aop_log_not
);
3420 i
= ax_goto (expr
, aop_if_goto
);
3421 /* We have to emit 0 - X. */
3422 ax_const_l (expr
, 0);
3423 ax_simple (expr
, aop_swap
);
3424 ax_simple (expr
, aop_sub
);
3425 ax_label (expr
, i
, expr
->len
);
3429 /* No need to sign extend here. */
3430 ax_const_l (expr
, 0);
3431 ax_simple (expr
, aop_swap
);
3432 ax_simple (expr
, aop_sub
);
3436 /* Sign extend the operand. */
3437 ax_ext (expr
, addr_size_bits
);
3438 ax_simple (expr
, aop_bit_not
);
3441 case DW_OP_plus_uconst
:
3442 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3443 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3444 but we micro-optimize anyhow. */
3447 ax_const_l (expr
, reg
);
3448 ax_simple (expr
, aop_add
);
3453 ax_simple (expr
, aop_bit_and
);
3457 /* Sign extend the operands. */
3458 ax_ext (expr
, addr_size_bits
);
3459 ax_simple (expr
, aop_swap
);
3460 ax_ext (expr
, addr_size_bits
);
3461 ax_simple (expr
, aop_swap
);
3462 ax_simple (expr
, aop_div_signed
);
3466 ax_simple (expr
, aop_sub
);
3470 ax_simple (expr
, aop_rem_unsigned
);
3474 ax_simple (expr
, aop_mul
);
3478 ax_simple (expr
, aop_bit_or
);
3482 ax_simple (expr
, aop_add
);
3486 ax_simple (expr
, aop_lsh
);
3490 ax_simple (expr
, aop_rsh_unsigned
);
3494 ax_simple (expr
, aop_rsh_signed
);
3498 ax_simple (expr
, aop_bit_xor
);
3502 /* Sign extend the operands. */
3503 ax_ext (expr
, addr_size_bits
);
3504 ax_simple (expr
, aop_swap
);
3505 ax_ext (expr
, addr_size_bits
);
3506 /* Note no swap here: A <= B is !(B < A). */
3507 ax_simple (expr
, aop_less_signed
);
3508 ax_simple (expr
, aop_log_not
);
3512 /* Sign extend the operands. */
3513 ax_ext (expr
, addr_size_bits
);
3514 ax_simple (expr
, aop_swap
);
3515 ax_ext (expr
, addr_size_bits
);
3516 ax_simple (expr
, aop_swap
);
3517 /* A >= B is !(A < B). */
3518 ax_simple (expr
, aop_less_signed
);
3519 ax_simple (expr
, aop_log_not
);
3523 /* Sign extend the operands. */
3524 ax_ext (expr
, addr_size_bits
);
3525 ax_simple (expr
, aop_swap
);
3526 ax_ext (expr
, addr_size_bits
);
3527 /* No need for a second swap here. */
3528 ax_simple (expr
, aop_equal
);
3532 /* Sign extend the operands. */
3533 ax_ext (expr
, addr_size_bits
);
3534 ax_simple (expr
, aop_swap
);
3535 ax_ext (expr
, addr_size_bits
);
3536 ax_simple (expr
, aop_swap
);
3537 ax_simple (expr
, aop_less_signed
);
3541 /* Sign extend the operands. */
3542 ax_ext (expr
, addr_size_bits
);
3543 ax_simple (expr
, aop_swap
);
3544 ax_ext (expr
, addr_size_bits
);
3545 /* Note no swap here: A > B is B < A. */
3546 ax_simple (expr
, aop_less_signed
);
3550 /* Sign extend the operands. */
3551 ax_ext (expr
, addr_size_bits
);
3552 ax_simple (expr
, aop_swap
);
3553 ax_ext (expr
, addr_size_bits
);
3554 /* No need for a swap here. */
3555 ax_simple (expr
, aop_equal
);
3556 ax_simple (expr
, aop_log_not
);
3559 case DW_OP_call_frame_cfa
:
3562 CORE_ADDR text_offset
;
3564 const gdb_byte
*cfa_start
, *cfa_end
;
3566 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3568 &text_offset
, &cfa_start
, &cfa_end
))
3571 ax_reg (expr
, regnum
);
3574 ax_const_l (expr
, off
);
3575 ax_simple (expr
, aop_add
);
3580 /* Another expression. */
3581 ax_const_l (expr
, text_offset
);
3582 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, cfa_start
,
3583 cfa_end
, per_cu
, per_objfile
);
3586 loc
->kind
= axs_lvalue_memory
;
3590 case DW_OP_GNU_push_tls_address
:
3591 case DW_OP_form_tls_address
:
3595 case DW_OP_push_object_address
:
3600 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3602 i
= ax_goto (expr
, aop_goto
);
3603 dw_labels
.push_back (op_ptr
+ offset
- base
);
3604 patches
.push_back (i
);
3608 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3610 /* Zero extend the operand. */
3611 ax_zero_ext (expr
, addr_size_bits
);
3612 i
= ax_goto (expr
, aop_if_goto
);
3613 dw_labels
.push_back (op_ptr
+ offset
- base
);
3614 patches
.push_back (i
);
3621 case DW_OP_bit_piece
:
3625 if (op_ptr
- 1 == previous_piece
)
3626 error (_("Cannot translate empty pieces to agent expressions"));
3627 previous_piece
= op_ptr
- 1;
3629 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3630 if (op
== DW_OP_piece
)
3636 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3638 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3639 error (_("Expression pieces exceed word size"));
3641 /* Access the bits. */
3644 case axs_lvalue_register
:
3645 ax_reg (expr
, loc
->u
.reg
);
3648 case axs_lvalue_memory
:
3649 /* Offset the pointer, if needed. */
3652 ax_const_l (expr
, uoffset
/ 8);
3653 ax_simple (expr
, aop_add
);
3656 access_memory (arch
, expr
, size
);
3660 /* For a bits-big-endian target, shift up what we already
3661 have. For a bits-little-endian target, shift up the
3662 new data. Note that there is a potential bug here if
3663 the DWARF expression leaves multiple values on the
3665 if (bits_collected
> 0)
3667 if (bits_big_endian
)
3669 ax_simple (expr
, aop_swap
);
3670 ax_const_l (expr
, size
);
3671 ax_simple (expr
, aop_lsh
);
3672 /* We don't need a second swap here, because
3673 aop_bit_or is symmetric. */
3677 ax_const_l (expr
, size
);
3678 ax_simple (expr
, aop_lsh
);
3680 ax_simple (expr
, aop_bit_or
);
3683 bits_collected
+= size
;
3684 loc
->kind
= axs_rvalue
;
3688 case DW_OP_GNU_uninit
:
3694 struct dwarf2_locexpr_baton block
;
3695 int size
= (op
== DW_OP_call2
? 2 : 4);
3697 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3700 auto get_frame_pc_from_expr
= [expr
] ()
3704 cu_offset cuoffset
= (cu_offset
) uoffset
;
3705 block
= dwarf2_fetch_die_loc_cu_off (cuoffset
, per_cu
, per_objfile
,
3706 get_frame_pc_from_expr
);
3708 /* DW_OP_call_ref is currently not supported. */
3709 gdb_assert (block
.per_cu
== per_cu
);
3711 dwarf2_compile_expr_to_ax (expr
, loc
, addr_size
, block
.data
,
3712 block
.data
+ block
.size
, per_cu
,
3717 case DW_OP_call_ref
:
3720 case DW_OP_GNU_variable_value
:
3728 /* Patch all the branches we emitted. */
3729 for (int i
= 0; i
< patches
.size (); ++i
)
3731 int targ
= offsets
[dw_labels
[i
]];
3733 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3734 ax_label (expr
, patches
[i
], targ
);
3739 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3740 evaluator to calculate the location. */
3741 static struct value
*
3742 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3744 struct dwarf2_locexpr_baton
*dlbaton
3745 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3748 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3749 dlbaton
->size
, dlbaton
->per_cu
,
3750 dlbaton
->per_objfile
);
3755 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3756 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3759 static struct value
*
3760 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3762 struct dwarf2_locexpr_baton
*dlbaton
3763 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3765 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3769 /* Implementation of get_symbol_read_needs from
3770 symbol_computed_ops. */
3772 static enum symbol_needs_kind
3773 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3775 struct dwarf2_locexpr_baton
*dlbaton
3776 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3778 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3780 dlbaton
->per_objfile
);
3783 /* Return true if DATA points to the end of a piece. END is one past
3784 the last byte in the expression. */
3787 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3789 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3792 /* Helper for locexpr_describe_location_piece that finds the name of a
3796 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3800 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3801 We'd rather print *something* here than throw an error. */
3802 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3803 /* gdbarch_register_name may just return "", return something more
3804 descriptive for bad register numbers. */
3807 /* The text is output as "$bad_register_number".
3808 That is why we use the underscores. */
3809 return _("bad_register_number");
3811 return gdbarch_register_name (gdbarch
, regnum
);
3814 /* Nicely describe a single piece of a location, returning an updated
3815 position in the bytecode sequence. This function cannot recognize
3816 all locations; if a location is not recognized, it simply returns
3817 DATA. If there is an error during reading, e.g. we run off the end
3818 of the buffer, an error is thrown. */
3820 static const gdb_byte
*
3821 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3822 CORE_ADDR addr
, dwarf2_per_cu_data
*per_cu
,
3823 dwarf2_per_objfile
*per_objfile
,
3824 const gdb_byte
*data
, const gdb_byte
*end
,
3825 unsigned int addr_size
)
3827 objfile
*objfile
= per_objfile
->objfile
;
3828 struct gdbarch
*gdbarch
= objfile
->arch ();
3831 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3833 fprintf_filtered (stream
, _("a variable in $%s"),
3834 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3837 else if (data
[0] == DW_OP_regx
)
3841 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3842 fprintf_filtered (stream
, _("a variable in $%s"),
3843 locexpr_regname (gdbarch
, reg
));
3845 else if (data
[0] == DW_OP_fbreg
)
3847 const struct block
*b
;
3848 struct symbol
*framefunc
;
3850 int64_t frame_offset
;
3851 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3853 int64_t base_offset
= 0;
3855 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3856 if (!piece_end_p (new_data
, end
))
3860 b
= block_for_pc (addr
);
3863 error (_("No block found for address for symbol \"%s\"."),
3864 symbol
->print_name ());
3866 framefunc
= block_linkage_function (b
);
3869 error (_("No function found for block for symbol \"%s\"."),
3870 symbol
->print_name ());
3872 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3874 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3876 const gdb_byte
*buf_end
;
3878 frame_reg
= base_data
[0] - DW_OP_breg0
;
3879 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3881 if (buf_end
!= base_data
+ base_size
)
3882 error (_("Unexpected opcode after "
3883 "DW_OP_breg%u for symbol \"%s\"."),
3884 frame_reg
, symbol
->print_name ());
3886 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3888 /* The frame base is just the register, with no offset. */
3889 frame_reg
= base_data
[0] - DW_OP_reg0
;
3894 /* We don't know what to do with the frame base expression,
3895 so we can't trace this variable; give up. */
3899 fprintf_filtered (stream
,
3900 _("a variable at frame base reg $%s offset %s+%s"),
3901 locexpr_regname (gdbarch
, frame_reg
),
3902 plongest (base_offset
), plongest (frame_offset
));
3904 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3905 && piece_end_p (data
, end
))
3909 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3911 fprintf_filtered (stream
,
3912 _("a variable at offset %s from base reg $%s"),
3914 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3917 /* The location expression for a TLS variable looks like this (on a
3920 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3921 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3923 0x3 is the encoding for DW_OP_addr, which has an operand as long
3924 as the size of an address on the target machine (here is 8
3925 bytes). Note that more recent version of GCC emit DW_OP_const4u
3926 or DW_OP_const8u, depending on address size, rather than
3927 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3928 The operand represents the offset at which the variable is within
3929 the thread local storage. */
3931 else if (data
+ 1 + addr_size
< end
3932 && (data
[0] == DW_OP_addr
3933 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3934 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3935 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3936 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3937 && piece_end_p (data
+ 2 + addr_size
, end
))
3940 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3941 gdbarch_byte_order (gdbarch
));
3943 fprintf_filtered (stream
,
3944 _("a thread-local variable at offset 0x%s "
3945 "in the thread-local storage for `%s'"),
3946 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3948 data
+= 1 + addr_size
+ 1;
3951 /* With -gsplit-dwarf a TLS variable can also look like this:
3952 DW_AT_location : 3 byte block: fc 4 e0
3953 (DW_OP_GNU_const_index: 4;
3954 DW_OP_GNU_push_tls_address) */
3955 else if (data
+ 3 <= end
3956 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3957 && data
[0] == DW_OP_GNU_const_index
3959 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3960 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3961 && piece_end_p (data
+ 2 + leb128_size
, end
))
3965 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3966 offset
= dwarf2_read_addr_index (per_cu
, per_objfile
, offset
);
3967 fprintf_filtered (stream
,
3968 _("a thread-local variable at offset 0x%s "
3969 "in the thread-local storage for `%s'"),
3970 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3974 else if (data
[0] >= DW_OP_lit0
3975 && data
[0] <= DW_OP_lit31
3977 && data
[1] == DW_OP_stack_value
)
3979 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3986 /* Disassemble an expression, stopping at the end of a piece or at the
3987 end of the expression. Returns a pointer to the next unread byte
3988 in the input expression. If ALL is nonzero, then this function
3989 will keep going until it reaches the end of the expression.
3990 If there is an error during reading, e.g. we run off the end
3991 of the buffer, an error is thrown. */
3993 static const gdb_byte
*
3994 disassemble_dwarf_expression (struct ui_file
*stream
,
3995 struct gdbarch
*arch
, unsigned int addr_size
,
3996 int offset_size
, const gdb_byte
*start
,
3997 const gdb_byte
*data
, const gdb_byte
*end
,
3998 int indent
, int all
,
3999 dwarf2_per_cu_data
*per_cu
,
4000 dwarf2_per_objfile
*per_objfile
)
4004 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
4006 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
4011 name
= get_DW_OP_name (op
);
4014 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
4015 op
, (long) (data
- 1 - start
));
4016 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
4017 (long) (data
- 1 - start
), name
);
4022 ul
= extract_unsigned_integer (data
, addr_size
,
4023 gdbarch_byte_order (arch
));
4025 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4029 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
4031 fprintf_filtered (stream
, " %s", pulongest (ul
));
4035 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
4037 fprintf_filtered (stream
, " %s", plongest (l
));
4041 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4043 fprintf_filtered (stream
, " %s", pulongest (ul
));
4047 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4049 fprintf_filtered (stream
, " %s", plongest (l
));
4053 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4055 fprintf_filtered (stream
, " %s", pulongest (ul
));
4059 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4061 fprintf_filtered (stream
, " %s", plongest (l
));
4065 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4067 fprintf_filtered (stream
, " %s", pulongest (ul
));
4071 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4073 fprintf_filtered (stream
, " %s", plongest (l
));
4077 data
= safe_read_uleb128 (data
, end
, &ul
);
4078 fprintf_filtered (stream
, " %s", pulongest (ul
));
4082 data
= safe_read_sleb128 (data
, end
, &l
);
4083 fprintf_filtered (stream
, " %s", plongest (l
));
4118 fprintf_filtered (stream
, " [$%s]",
4119 locexpr_regname (arch
, op
- DW_OP_reg0
));
4123 data
= safe_read_uleb128 (data
, end
, &ul
);
4124 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4125 locexpr_regname (arch
, (int) ul
));
4128 case DW_OP_implicit_value
:
4129 data
= safe_read_uleb128 (data
, end
, &ul
);
4131 fprintf_filtered (stream
, " %s", pulongest (ul
));
4166 data
= safe_read_sleb128 (data
, end
, &l
);
4167 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4168 locexpr_regname (arch
, op
- DW_OP_breg0
));
4172 data
= safe_read_uleb128 (data
, end
, &ul
);
4173 data
= safe_read_sleb128 (data
, end
, &l
);
4174 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4176 locexpr_regname (arch
, (int) ul
),
4181 data
= safe_read_sleb128 (data
, end
, &l
);
4182 fprintf_filtered (stream
, " %s", plongest (l
));
4185 case DW_OP_xderef_size
:
4186 case DW_OP_deref_size
:
4188 fprintf_filtered (stream
, " %d", *data
);
4192 case DW_OP_plus_uconst
:
4193 data
= safe_read_uleb128 (data
, end
, &ul
);
4194 fprintf_filtered (stream
, " %s", pulongest (ul
));
4198 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4200 fprintf_filtered (stream
, " to %ld",
4201 (long) (data
+ l
- start
));
4205 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4207 fprintf_filtered (stream
, " %ld",
4208 (long) (data
+ l
- start
));
4212 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4214 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4218 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4220 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4223 case DW_OP_call_ref
:
4224 ul
= extract_unsigned_integer (data
, offset_size
,
4225 gdbarch_byte_order (arch
));
4226 data
+= offset_size
;
4227 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4231 data
= safe_read_uleb128 (data
, end
, &ul
);
4232 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4235 case DW_OP_bit_piece
:
4239 data
= safe_read_uleb128 (data
, end
, &ul
);
4240 data
= safe_read_uleb128 (data
, end
, &offset
);
4241 fprintf_filtered (stream
, " size %s offset %s (bits)",
4242 pulongest (ul
), pulongest (offset
));
4246 case DW_OP_implicit_pointer
:
4247 case DW_OP_GNU_implicit_pointer
:
4249 ul
= extract_unsigned_integer (data
, offset_size
,
4250 gdbarch_byte_order (arch
));
4251 data
+= offset_size
;
4253 data
= safe_read_sleb128 (data
, end
, &l
);
4255 fprintf_filtered (stream
, " DIE %s offset %s",
4256 phex_nz (ul
, offset_size
),
4261 case DW_OP_deref_type
:
4262 case DW_OP_GNU_deref_type
:
4264 int deref_addr_size
= *data
++;
4267 data
= safe_read_uleb128 (data
, end
, &ul
);
4268 cu_offset offset
= (cu_offset
) ul
;
4269 type
= dwarf2_get_die_type (offset
, per_cu
, per_objfile
);
4270 fprintf_filtered (stream
, "<");
4271 type_print (type
, "", stream
, -1);
4272 fprintf_filtered (stream
, " [0x%s]> %d",
4273 phex_nz (to_underlying (offset
), 0),
4278 case DW_OP_const_type
:
4279 case DW_OP_GNU_const_type
:
4283 data
= safe_read_uleb128 (data
, end
, &ul
);
4284 cu_offset type_die
= (cu_offset
) ul
;
4285 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4286 fprintf_filtered (stream
, "<");
4287 type_print (type
, "", stream
, -1);
4288 fprintf_filtered (stream
, " [0x%s]>",
4289 phex_nz (to_underlying (type_die
), 0));
4292 fprintf_filtered (stream
, " %d byte block:", n
);
4293 for (int i
= 0; i
< n
; ++i
)
4294 fprintf_filtered (stream
, " %02x", data
[i
]);
4299 case DW_OP_regval_type
:
4300 case DW_OP_GNU_regval_type
:
4305 data
= safe_read_uleb128 (data
, end
, ®
);
4306 data
= safe_read_uleb128 (data
, end
, &ul
);
4307 cu_offset type_die
= (cu_offset
) ul
;
4309 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4310 fprintf_filtered (stream
, "<");
4311 type_print (type
, "", stream
, -1);
4312 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4313 phex_nz (to_underlying (type_die
), 0),
4314 locexpr_regname (arch
, reg
));
4319 case DW_OP_GNU_convert
:
4320 case DW_OP_reinterpret
:
4321 case DW_OP_GNU_reinterpret
:
4323 data
= safe_read_uleb128 (data
, end
, &ul
);
4324 cu_offset type_die
= (cu_offset
) ul
;
4326 if (to_underlying (type_die
) == 0)
4327 fprintf_filtered (stream
, "<0>");
4332 type
= dwarf2_get_die_type (type_die
, per_cu
, per_objfile
);
4333 fprintf_filtered (stream
, "<");
4334 type_print (type
, "", stream
, -1);
4335 fprintf_filtered (stream
, " [0x%s]>",
4336 phex_nz (to_underlying (type_die
), 0));
4341 case DW_OP_entry_value
:
4342 case DW_OP_GNU_entry_value
:
4343 data
= safe_read_uleb128 (data
, end
, &ul
);
4344 fputc_filtered ('\n', stream
);
4345 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4346 start
, data
, data
+ ul
, indent
+ 2,
4347 all
, per_cu
, per_objfile
);
4351 case DW_OP_GNU_parameter_ref
:
4352 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4354 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4358 case DW_OP_GNU_addr_index
:
4359 data
= safe_read_uleb128 (data
, end
, &ul
);
4360 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4361 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4364 case DW_OP_GNU_const_index
:
4365 data
= safe_read_uleb128 (data
, end
, &ul
);
4366 ul
= dwarf2_read_addr_index (per_cu
, per_objfile
, ul
);
4367 fprintf_filtered (stream
, " %s", pulongest (ul
));
4370 case DW_OP_GNU_variable_value
:
4371 ul
= extract_unsigned_integer (data
, offset_size
,
4372 gdbarch_byte_order (arch
));
4373 data
+= offset_size
;
4374 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4378 fprintf_filtered (stream
, "\n");
4384 static bool dwarf_always_disassemble
;
4387 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
4388 struct cmd_list_element
*c
, const char *value
)
4390 fprintf_filtered (file
,
4391 _("Whether to always disassemble "
4392 "DWARF expressions is %s.\n"),
4396 /* Describe a single location, which may in turn consist of multiple
4400 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4401 struct ui_file
*stream
,
4402 const gdb_byte
*data
, size_t size
,
4403 unsigned int addr_size
,
4404 int offset_size
, dwarf2_per_cu_data
*per_cu
,
4405 dwarf2_per_objfile
*per_objfile
)
4407 const gdb_byte
*end
= data
+ size
;
4408 int first_piece
= 1, bad
= 0;
4409 objfile
*objfile
= per_objfile
->objfile
;
4413 const gdb_byte
*here
= data
;
4414 int disassemble
= 1;
4419 fprintf_filtered (stream
, _(", and "));
4421 if (!dwarf_always_disassemble
)
4423 data
= locexpr_describe_location_piece (symbol
, stream
,
4424 addr
, per_cu
, per_objfile
,
4425 data
, end
, addr_size
);
4426 /* If we printed anything, or if we have an empty piece,
4427 then don't disassemble. */
4429 || data
[0] == DW_OP_piece
4430 || data
[0] == DW_OP_bit_piece
)
4435 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4436 data
= disassemble_dwarf_expression (stream
,
4438 addr_size
, offset_size
, data
,
4440 dwarf_always_disassemble
,
4441 per_cu
, per_objfile
);
4446 int empty
= data
== here
;
4449 fprintf_filtered (stream
, " ");
4450 if (data
[0] == DW_OP_piece
)
4454 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4457 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4460 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4463 else if (data
[0] == DW_OP_bit_piece
)
4465 uint64_t bits
, offset
;
4467 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4468 data
= safe_read_uleb128 (data
, end
, &offset
);
4471 fprintf_filtered (stream
,
4472 _("an empty %s-bit piece"),
4475 fprintf_filtered (stream
,
4476 _(" [%s-bit piece, offset %s bits]"),
4477 pulongest (bits
), pulongest (offset
));
4487 if (bad
|| data
> end
)
4488 error (_("Corrupted DWARF2 expression for \"%s\"."),
4489 symbol
->print_name ());
4492 /* Print a natural-language description of SYMBOL to STREAM. This
4493 version is for a symbol with a single location. */
4496 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4497 struct ui_file
*stream
)
4499 struct dwarf2_locexpr_baton
*dlbaton
4500 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4501 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4502 int offset_size
= dlbaton
->per_cu
->offset_size ();
4504 locexpr_describe_location_1 (symbol
, addr
, stream
,
4505 dlbaton
->data
, dlbaton
->size
,
4506 addr_size
, offset_size
,
4507 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4510 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4511 any necessary bytecode in AX. */
4514 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4515 struct axs_value
*value
)
4517 struct dwarf2_locexpr_baton
*dlbaton
4518 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4519 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4521 if (dlbaton
->size
== 0)
4522 value
->optimized_out
= 1;
4524 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, dlbaton
->data
,
4525 dlbaton
->data
+ dlbaton
->size
, dlbaton
->per_cu
,
4526 dlbaton
->per_objfile
);
4529 /* symbol_computed_ops 'generate_c_location' method. */
4532 locexpr_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4533 struct gdbarch
*gdbarch
,
4534 std::vector
<bool> ®isters_used
,
4535 CORE_ADDR pc
, const char *result_name
)
4537 struct dwarf2_locexpr_baton
*dlbaton
4538 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4539 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4541 if (dlbaton
->size
== 0)
4542 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4544 compile_dwarf_expr_to_c (stream
, result_name
,
4545 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4546 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4547 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4550 /* The set of location functions used with the DWARF-2 expression
4552 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4553 locexpr_read_variable
,
4554 locexpr_read_variable_at_entry
,
4555 locexpr_get_symbol_read_needs
,
4556 locexpr_describe_location
,
4557 0, /* location_has_loclist */
4558 locexpr_tracepoint_var_ref
,
4559 locexpr_generate_c_location
4563 /* Wrapper functions for location lists. These generally find
4564 the appropriate location expression and call something above. */
4566 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4567 evaluator to calculate the location. */
4568 static struct value
*
4569 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4571 struct dwarf2_loclist_baton
*dlbaton
4572 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4574 const gdb_byte
*data
;
4576 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4578 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4579 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4580 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4585 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4586 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4589 Function always returns non-NULL value, it may be marked optimized out if
4590 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4591 if it cannot resolve the parameter for any reason. */
4593 static struct value
*
4594 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4596 struct dwarf2_loclist_baton
*dlbaton
4597 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4598 const gdb_byte
*data
;
4602 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4603 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4605 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4607 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4609 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4612 /* Implementation of get_symbol_read_needs from
4613 symbol_computed_ops. */
4615 static enum symbol_needs_kind
4616 loclist_symbol_needs (struct symbol
*symbol
)
4618 /* If there's a location list, then assume we need to have a frame
4619 to choose the appropriate location expression. With tracking of
4620 global variables this is not necessarily true, but such tracking
4621 is disabled in GCC at the moment until we figure out how to
4624 return SYMBOL_NEEDS_FRAME
;
4627 /* Print a natural-language description of SYMBOL to STREAM. This
4628 version applies when there is a list of different locations, each
4629 with a specified address range. */
4632 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4633 struct ui_file
*stream
)
4635 struct dwarf2_loclist_baton
*dlbaton
4636 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4637 const gdb_byte
*loc_ptr
, *buf_end
;
4638 dwarf2_per_objfile
*per_objfile
= dlbaton
->per_objfile
;
4639 struct objfile
*objfile
= per_objfile
->objfile
;
4640 struct gdbarch
*gdbarch
= objfile
->arch ();
4641 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4642 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4643 int offset_size
= dlbaton
->per_cu
->offset_size ();
4644 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4645 /* Adjust base_address for relocatable objects. */
4646 CORE_ADDR base_offset
= objfile
->text_section_offset ();
4647 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4650 loc_ptr
= dlbaton
->data
;
4651 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4653 fprintf_filtered (stream
, _("multi-location:\n"));
4655 /* Iterate through locations until we run out. */
4658 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4660 enum debug_loc_kind kind
;
4661 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4663 if (dlbaton
->per_cu
->version () < 5 && dlbaton
->from_dwo
)
4664 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4665 dlbaton
->per_objfile
,
4666 loc_ptr
, buf_end
, &new_ptr
,
4667 &low
, &high
, byte_order
);
4668 else if (dlbaton
->per_cu
->version () < 5)
4669 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4671 byte_order
, addr_size
,
4674 kind
= decode_debug_loclists_addresses (dlbaton
->per_cu
,
4675 dlbaton
->per_objfile
,
4676 loc_ptr
, buf_end
, &new_ptr
,
4677 &low
, &high
, byte_order
,
4678 addr_size
, signed_addr_p
);
4682 case DEBUG_LOC_END_OF_LIST
:
4686 case DEBUG_LOC_BASE_ADDRESS
:
4687 base_address
= high
+ base_offset
;
4688 fprintf_filtered (stream
, _(" Base address %s"),
4689 paddress (gdbarch
, base_address
));
4692 case DEBUG_LOC_START_END
:
4693 case DEBUG_LOC_START_LENGTH
:
4694 case DEBUG_LOC_OFFSET_PAIR
:
4697 case DEBUG_LOC_BUFFER_OVERFLOW
:
4698 case DEBUG_LOC_INVALID_ENTRY
:
4699 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4700 symbol
->print_name ());
4703 gdb_assert_not_reached ("bad debug_loc_kind");
4706 /* Otherwise, a location expression entry. */
4707 low
+= base_address
;
4708 high
+= base_address
;
4710 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4711 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4713 if (dlbaton
->per_cu
->version () < 5)
4715 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4720 unsigned int bytes_read
;
4721 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
4722 loc_ptr
+= bytes_read
;
4725 /* (It would improve readability to print only the minimum
4726 necessary digits of the second number of the range.) */
4727 fprintf_filtered (stream
, _(" Range %s-%s: "),
4728 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4730 /* Now describe this particular location. */
4731 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4732 addr_size
, offset_size
,
4733 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4735 fprintf_filtered (stream
, "\n");
4741 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4742 any necessary bytecode in AX. */
4744 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct agent_expr
*ax
,
4745 struct axs_value
*value
)
4747 struct dwarf2_loclist_baton
*dlbaton
4748 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4749 const gdb_byte
*data
;
4751 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4753 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4755 value
->optimized_out
= 1;
4757 dwarf2_compile_expr_to_ax (ax
, value
, addr_size
, data
, data
+ size
,
4758 dlbaton
->per_cu
, dlbaton
->per_objfile
);
4761 /* symbol_computed_ops 'generate_c_location' method. */
4764 loclist_generate_c_location (struct symbol
*sym
, string_file
*stream
,
4765 struct gdbarch
*gdbarch
,
4766 std::vector
<bool> ®isters_used
,
4767 CORE_ADDR pc
, const char *result_name
)
4769 struct dwarf2_loclist_baton
*dlbaton
4770 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4771 unsigned int addr_size
= dlbaton
->per_cu
->addr_size ();
4772 const gdb_byte
*data
;
4775 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4777 error (_("symbol \"%s\" is optimized out"), sym
->natural_name ());
4779 compile_dwarf_expr_to_c (stream
, result_name
,
4780 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4783 dlbaton
->per_objfile
);
4786 /* The set of location functions used with the DWARF-2 expression
4787 evaluator and location lists. */
4788 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4789 loclist_read_variable
,
4790 loclist_read_variable_at_entry
,
4791 loclist_symbol_needs
,
4792 loclist_describe_location
,
4793 1, /* location_has_loclist */
4794 loclist_tracepoint_var_ref
,
4795 loclist_generate_c_location
4798 void _initialize_dwarf2loc ();
4800 _initialize_dwarf2loc ()
4802 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4803 &entry_values_debug
,
4804 _("Set entry values and tail call frames "
4806 _("Show entry values and tail call frames "
4808 _("When non-zero, the process of determining "
4809 "parameter values from function entry point "
4810 "and tail call frames will be printed."),
4812 show_entry_values_debug
,
4813 &setdebuglist
, &showdebuglist
);
4815 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
4816 &dwarf_always_disassemble
, _("\
4817 Set whether `info address' always disassembles DWARF expressions."), _("\
4818 Show whether `info address' always disassembles DWARF expressions."), _("\
4819 When enabled, DWARF expressions are always printed in an assembly-like\n\
4820 syntax. When disabled, expressions will be printed in a more\n\
4821 conversational style, when possible."),
4823 show_dwarf_always_disassemble
,
4825 &show_dwarf_cmdlist
);