1 /* DWARF 2 location expression support for GDB.
3 Copyright (C) 2003-2017 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 "dwarf2expr.h"
38 #include "dwarf2loc.h"
39 #include "dwarf2-frame.h"
40 #include "compile/compile.h"
44 #include <unordered_set>
45 #include "common/underlying.h"
47 extern int dwarf_always_disassemble
;
49 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
50 struct frame_info
*frame
,
53 struct dwarf2_per_cu_data
*per_cu
,
54 struct type
*subobj_type
,
55 LONGEST subobj_byte_offset
);
57 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
58 (struct frame_info
*frame
,
59 enum call_site_parameter_kind kind
,
60 union call_site_parameter_u kind_u
,
61 struct dwarf2_per_cu_data
**per_cu_return
);
63 /* Until these have formal names, we define these here.
64 ref: http://gcc.gnu.org/wiki/DebugFission
65 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
66 and is then followed by data specific to that entry. */
70 /* Indicates the end of the list of entries. */
71 DEBUG_LOC_END_OF_LIST
= 0,
73 /* This is followed by an unsigned LEB128 number that is an index into
74 .debug_addr and specifies the base address for all following entries. */
75 DEBUG_LOC_BASE_ADDRESS
= 1,
77 /* This is followed by two unsigned LEB128 numbers that are indices into
78 .debug_addr and specify the beginning and ending addresses, and then
79 a normal location expression as in .debug_loc. */
80 DEBUG_LOC_START_END
= 2,
82 /* This is followed by an unsigned LEB128 number that is an index into
83 .debug_addr and specifies the beginning address, and a 4 byte unsigned
84 number that specifies the length, and then a normal location expression
86 DEBUG_LOC_START_LENGTH
= 3,
88 /* An internal value indicating there is insufficient data. */
89 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
91 /* An internal value indicating an invalid kind of entry was found. */
92 DEBUG_LOC_INVALID_ENTRY
= -2
95 /* Helper function which throws an error if a synthetic pointer is
99 invalid_synthetic_pointer (void)
101 error (_("access outside bounds of object "
102 "referenced via synthetic pointer"));
105 /* Decode the addresses in a non-dwo .debug_loc entry.
106 A pointer to the next byte to examine is returned in *NEW_PTR.
107 The encoded low,high addresses are return in *LOW,*HIGH.
108 The result indicates the kind of entry found. */
110 static enum debug_loc_kind
111 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
112 const gdb_byte
**new_ptr
,
113 CORE_ADDR
*low
, CORE_ADDR
*high
,
114 enum bfd_endian byte_order
,
115 unsigned int addr_size
,
118 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
120 if (buf_end
- loc_ptr
< 2 * addr_size
)
121 return DEBUG_LOC_BUFFER_OVERFLOW
;
124 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
126 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
127 loc_ptr
+= addr_size
;
130 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
132 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
133 loc_ptr
+= addr_size
;
137 /* A base-address-selection entry. */
138 if ((*low
& base_mask
) == base_mask
)
139 return DEBUG_LOC_BASE_ADDRESS
;
141 /* An end-of-list entry. */
142 if (*low
== 0 && *high
== 0)
143 return DEBUG_LOC_END_OF_LIST
;
145 return DEBUG_LOC_START_END
;
148 /* Decode the addresses in .debug_loclists entry.
149 A pointer to the next byte to examine is returned in *NEW_PTR.
150 The encoded low,high addresses are return in *LOW,*HIGH.
151 The result indicates the kind of entry found. */
153 static enum debug_loc_kind
154 decode_debug_loclists_addresses (struct dwarf2_per_cu_data
*per_cu
,
155 const gdb_byte
*loc_ptr
,
156 const gdb_byte
*buf_end
,
157 const gdb_byte
**new_ptr
,
158 CORE_ADDR
*low
, CORE_ADDR
*high
,
159 enum bfd_endian byte_order
,
160 unsigned int addr_size
,
165 if (loc_ptr
== buf_end
)
166 return DEBUG_LOC_BUFFER_OVERFLOW
;
170 case DW_LLE_end_of_list
:
172 return DEBUG_LOC_END_OF_LIST
;
173 case DW_LLE_base_address
:
174 if (loc_ptr
+ addr_size
> buf_end
)
175 return DEBUG_LOC_BUFFER_OVERFLOW
;
177 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
179 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
180 loc_ptr
+= addr_size
;
182 return DEBUG_LOC_BASE_ADDRESS
;
183 case DW_LLE_offset_pair
:
184 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
186 return DEBUG_LOC_BUFFER_OVERFLOW
;
188 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
190 return DEBUG_LOC_BUFFER_OVERFLOW
;
193 return DEBUG_LOC_START_END
;
195 return DEBUG_LOC_INVALID_ENTRY
;
199 /* Decode the addresses in .debug_loc.dwo entry.
200 A pointer to the next byte to examine is returned in *NEW_PTR.
201 The encoded low,high addresses are return in *LOW,*HIGH.
202 The result indicates the kind of entry found. */
204 static enum debug_loc_kind
205 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
206 const gdb_byte
*loc_ptr
,
207 const gdb_byte
*buf_end
,
208 const gdb_byte
**new_ptr
,
209 CORE_ADDR
*low
, CORE_ADDR
*high
,
210 enum bfd_endian byte_order
)
212 uint64_t low_index
, high_index
;
214 if (loc_ptr
== buf_end
)
215 return DEBUG_LOC_BUFFER_OVERFLOW
;
219 case DW_LLE_GNU_end_of_list_entry
:
221 return DEBUG_LOC_END_OF_LIST
;
222 case DW_LLE_GNU_base_address_selection_entry
:
224 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
226 return DEBUG_LOC_BUFFER_OVERFLOW
;
227 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
229 return DEBUG_LOC_BASE_ADDRESS
;
230 case DW_LLE_GNU_start_end_entry
:
231 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
233 return DEBUG_LOC_BUFFER_OVERFLOW
;
234 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
235 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
237 return DEBUG_LOC_BUFFER_OVERFLOW
;
238 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
240 return DEBUG_LOC_START_END
;
241 case DW_LLE_GNU_start_length_entry
:
242 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
244 return DEBUG_LOC_BUFFER_OVERFLOW
;
245 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
246 if (loc_ptr
+ 4 > buf_end
)
247 return DEBUG_LOC_BUFFER_OVERFLOW
;
249 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
250 *new_ptr
= loc_ptr
+ 4;
251 return DEBUG_LOC_START_LENGTH
;
253 return DEBUG_LOC_INVALID_ENTRY
;
257 /* A function for dealing with location lists. Given a
258 symbol baton (BATON) and a pc value (PC), find the appropriate
259 location expression, set *LOCEXPR_LENGTH, and return a pointer
260 to the beginning of the expression. Returns NULL on failure.
262 For now, only return the first matching location expression; there
263 can be more than one in the list. */
266 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
267 size_t *locexpr_length
, CORE_ADDR pc
)
269 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
270 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
271 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
272 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
273 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
274 /* Adjust base_address for relocatable objects. */
275 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
276 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
277 const gdb_byte
*loc_ptr
, *buf_end
;
279 loc_ptr
= baton
->data
;
280 buf_end
= baton
->data
+ baton
->size
;
284 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
286 enum debug_loc_kind kind
;
287 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
290 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
291 loc_ptr
, buf_end
, &new_ptr
,
292 &low
, &high
, byte_order
);
293 else if (dwarf2_version (baton
->per_cu
) < 5)
294 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
296 byte_order
, addr_size
,
299 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
300 loc_ptr
, buf_end
, &new_ptr
,
301 &low
, &high
, byte_order
,
302 addr_size
, signed_addr_p
);
307 case DEBUG_LOC_END_OF_LIST
:
310 case DEBUG_LOC_BASE_ADDRESS
:
311 base_address
= high
+ base_offset
;
313 case DEBUG_LOC_START_END
:
314 case DEBUG_LOC_START_LENGTH
:
316 case DEBUG_LOC_BUFFER_OVERFLOW
:
317 case DEBUG_LOC_INVALID_ENTRY
:
318 error (_("dwarf2_find_location_expression: "
319 "Corrupted DWARF expression."));
321 gdb_assert_not_reached ("bad debug_loc_kind");
324 /* Otherwise, a location expression entry.
325 If the entry is from a DWO, don't add base address: the entry is from
326 .debug_addr which already has the DWARF "base address". We still add
327 base_offset in case we're debugging a PIE executable. */
336 high
+= base_address
;
339 if (dwarf2_version (baton
->per_cu
) < 5)
341 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
346 unsigned int bytes_read
;
348 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
349 loc_ptr
+= bytes_read
;
352 if (low
== high
&& pc
== low
)
354 /* This is entry PC record present only at entry point
355 of a function. Verify it is really the function entry point. */
357 const struct block
*pc_block
= block_for_pc (pc
);
358 struct symbol
*pc_func
= NULL
;
361 pc_func
= block_linkage_function (pc_block
);
363 if (pc_func
&& pc
== BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func
)))
365 *locexpr_length
= length
;
370 if (pc
>= low
&& pc
< high
)
372 *locexpr_length
= length
;
380 /* This is the baton used when performing dwarf2 expression
382 struct dwarf_expr_baton
384 struct frame_info
*frame
;
385 struct dwarf2_per_cu_data
*per_cu
;
386 CORE_ADDR obj_address
;
389 /* Implement find_frame_base_location method for LOC_BLOCK functions using
390 DWARF expression for its DW_AT_frame_base. */
393 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
394 const gdb_byte
**start
, size_t *length
)
396 struct dwarf2_locexpr_baton
*symbaton
397 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
399 *length
= symbaton
->size
;
400 *start
= symbaton
->data
;
403 /* Implement the struct symbol_block_ops::get_frame_base method for
404 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
407 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
409 struct gdbarch
*gdbarch
;
411 struct dwarf2_locexpr_baton
*dlbaton
;
412 const gdb_byte
*start
;
414 struct value
*result
;
416 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
417 Thus, it's supposed to provide the find_frame_base_location method as
419 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
421 gdbarch
= get_frame_arch (frame
);
422 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
423 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
425 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
426 (framefunc
, get_frame_pc (frame
), &start
, &length
);
427 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
430 /* The DW_AT_frame_base attribute contains a location description which
431 computes the base address itself. However, the call to
432 dwarf2_evaluate_loc_desc returns a value representing a variable at
433 that address. The frame base address is thus this variable's
435 return value_address (result
);
438 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
439 function uses DWARF expression for its DW_AT_frame_base. */
441 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
443 locexpr_find_frame_base_location
,
444 locexpr_get_frame_base
447 /* Implement find_frame_base_location method for LOC_BLOCK functions using
448 DWARF location list for its DW_AT_frame_base. */
451 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
452 const gdb_byte
**start
, size_t *length
)
454 struct dwarf2_loclist_baton
*symbaton
455 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
457 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
460 /* Implement the struct symbol_block_ops::get_frame_base method for
461 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
464 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
466 struct gdbarch
*gdbarch
;
468 struct dwarf2_loclist_baton
*dlbaton
;
469 const gdb_byte
*start
;
471 struct value
*result
;
473 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
474 Thus, it's supposed to provide the find_frame_base_location method as
476 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
478 gdbarch
= get_frame_arch (frame
);
479 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
480 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
482 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
483 (framefunc
, get_frame_pc (frame
), &start
, &length
);
484 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
487 /* The DW_AT_frame_base attribute contains a location description which
488 computes the base address itself. However, the call to
489 dwarf2_evaluate_loc_desc returns a value representing a variable at
490 that address. The frame base address is thus this variable's
492 return value_address (result
);
495 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
496 function uses DWARF location list for its DW_AT_frame_base. */
498 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
500 loclist_find_frame_base_location
,
501 loclist_get_frame_base
504 /* See dwarf2loc.h. */
507 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
508 const gdb_byte
**start
, size_t *length
)
510 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
512 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
514 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
520 error (_("Could not find the frame base for \"%s\"."),
521 SYMBOL_NATURAL_NAME (framefunc
));
525 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
527 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
529 return ctx
->get_frame_pc ();
533 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
534 struct dwarf2_per_cu_data
*per_cu
)
536 struct dwarf2_locexpr_baton block
;
538 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
,
539 get_frame_pc_for_per_cu_dwarf_call
,
542 /* DW_OP_call_ref is currently not supported. */
543 gdb_assert (block
.per_cu
== per_cu
);
545 ctx
->eval (block
.data
, block
.size
);
548 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
552 struct frame_info
*frame
;
553 struct dwarf2_per_cu_data
*per_cu
;
554 CORE_ADDR obj_address
;
556 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
557 the frame in BATON. */
559 CORE_ADDR
get_frame_cfa () OVERRIDE
561 return dwarf2_frame_cfa (frame
);
564 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
565 the frame in BATON. */
567 CORE_ADDR
get_frame_pc () OVERRIDE
569 return get_frame_address_in_block (frame
);
572 /* Using the objfile specified in BATON, find the address for the
573 current thread's thread-local storage with offset OFFSET. */
574 CORE_ADDR
get_tls_address (CORE_ADDR offset
) OVERRIDE
576 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
578 return target_translate_tls_address (objfile
, offset
);
581 /* Helper interface of per_cu_dwarf_call for
582 dwarf2_evaluate_loc_desc. */
584 void dwarf_call (cu_offset die_offset
) OVERRIDE
586 per_cu_dwarf_call (this, die_offset
, per_cu
);
589 struct type
*get_base_type (cu_offset die_offset
, int size
) OVERRIDE
591 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
593 error (_("Could not find type for DW_OP_const_type"));
594 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
595 error (_("DW_OP_const_type has different sizes for type and data"));
599 /* Callback function for dwarf2_evaluate_loc_desc.
600 Fetch the address indexed by DW_OP_GNU_addr_index. */
602 CORE_ADDR
get_addr_index (unsigned int index
) OVERRIDE
604 return dwarf2_read_addr_index (per_cu
, index
);
607 /* Callback function for get_object_address. Return the address of the VLA
610 CORE_ADDR
get_object_address () OVERRIDE
612 if (obj_address
== 0)
613 error (_("Location address is not set."));
617 /* Execute DWARF block of call_site_parameter which matches KIND and
618 KIND_U. Choose DEREF_SIZE value of that parameter. Search
619 caller of this objects's frame.
621 The caller can be from a different CU - per_cu_dwarf_call
622 implementation can be more simple as it does not support cross-CU
625 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
626 union call_site_parameter_u kind_u
,
627 int deref_size
) OVERRIDE
629 struct frame_info
*caller_frame
;
630 struct dwarf2_per_cu_data
*caller_per_cu
;
631 struct call_site_parameter
*parameter
;
632 const gdb_byte
*data_src
;
635 caller_frame
= get_prev_frame (frame
);
637 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
639 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
640 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
642 /* DEREF_SIZE size is not verified here. */
643 if (data_src
== NULL
)
644 throw_error (NO_ENTRY_VALUE_ERROR
,
645 _("Cannot resolve DW_AT_call_data_value"));
647 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
649 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
651 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
654 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
656 = get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
657 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
658 this->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
659 scoped_restore save_offset
= make_scoped_restore (&this->offset
);
660 this->offset
= dwarf2_per_cu_text_offset (per_cu
);
662 this->eval (data_src
, size
);
665 /* Using the frame specified in BATON, find the location expression
666 describing the frame base. Return a pointer to it in START and
667 its length in LENGTH. */
668 void get_frame_base (const gdb_byte
**start
, size_t * length
) OVERRIDE
670 /* FIXME: cagney/2003-03-26: This code should be using
671 get_frame_base_address(), and then implement a dwarf2 specific
673 struct symbol
*framefunc
;
674 const struct block
*bl
= get_frame_block (frame
, NULL
);
677 error (_("frame address is not available."));
679 /* Use block_linkage_function, which returns a real (not inlined)
680 function, instead of get_frame_function, which may return an
682 framefunc
= block_linkage_function (bl
);
684 /* If we found a frame-relative symbol then it was certainly within
685 some function associated with a frame. If we can't find the frame,
686 something has gone wrong. */
687 gdb_assert (framefunc
!= NULL
);
689 func_get_frame_base_dwarf_block (framefunc
,
690 get_frame_address_in_block (frame
),
694 /* Read memory at ADDR (length LEN) into BUF. */
696 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) OVERRIDE
698 read_memory (addr
, buf
, len
);
701 /* Using the frame specified in BATON, return the value of register
702 REGNUM, treated as a pointer. */
703 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) OVERRIDE
705 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
706 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
708 return address_from_register (regnum
, frame
);
711 /* Implement "get_reg_value" callback. */
713 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) OVERRIDE
715 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
716 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
718 return value_from_register (type
, regnum
, frame
);
722 /* See dwarf2loc.h. */
724 unsigned int entry_values_debug
= 0;
726 /* Helper to set entry_values_debug. */
729 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
730 struct cmd_list_element
*c
, const char *value
)
732 fprintf_filtered (file
,
733 _("Entry values and tail call frames debugging is %s.\n"),
737 /* Find DW_TAG_call_site's DW_AT_call_target address.
738 CALLER_FRAME (for registers) can be NULL if it is not known. This function
739 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
742 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
743 struct call_site
*call_site
,
744 struct frame_info
*caller_frame
)
746 switch (FIELD_LOC_KIND (call_site
->target
))
748 case FIELD_LOC_KIND_DWARF_BLOCK
:
750 struct dwarf2_locexpr_baton
*dwarf_block
;
752 struct type
*caller_core_addr_type
;
753 struct gdbarch
*caller_arch
;
755 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
756 if (dwarf_block
== NULL
)
758 struct bound_minimal_symbol msym
;
760 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
761 throw_error (NO_ENTRY_VALUE_ERROR
,
762 _("DW_AT_call_target is not specified at %s in %s"),
763 paddress (call_site_gdbarch
, call_site
->pc
),
764 (msym
.minsym
== NULL
? "???"
765 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
768 if (caller_frame
== NULL
)
770 struct bound_minimal_symbol msym
;
772 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
773 throw_error (NO_ENTRY_VALUE_ERROR
,
774 _("DW_AT_call_target DWARF block resolving "
775 "requires known frame which is currently not "
776 "available at %s in %s"),
777 paddress (call_site_gdbarch
, call_site
->pc
),
778 (msym
.minsym
== NULL
? "???"
779 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
782 caller_arch
= get_frame_arch (caller_frame
);
783 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
784 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
785 dwarf_block
->data
, dwarf_block
->size
,
786 dwarf_block
->per_cu
);
787 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
788 if (VALUE_LVAL (val
) == lval_memory
)
789 return value_address (val
);
791 return value_as_address (val
);
794 case FIELD_LOC_KIND_PHYSNAME
:
796 const char *physname
;
797 struct bound_minimal_symbol msym
;
799 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
801 /* Handle both the mangled and demangled PHYSNAME. */
802 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
803 if (msym
.minsym
== NULL
)
805 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
806 throw_error (NO_ENTRY_VALUE_ERROR
,
807 _("Cannot find function \"%s\" for a call site target "
809 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
810 (msym
.minsym
== NULL
? "???"
811 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
814 return BMSYMBOL_VALUE_ADDRESS (msym
);
817 case FIELD_LOC_KIND_PHYSADDR
:
818 return FIELD_STATIC_PHYSADDR (call_site
->target
);
821 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
825 /* Convert function entry point exact address ADDR to the function which is
826 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
827 NO_ENTRY_VALUE_ERROR otherwise. */
829 static struct symbol
*
830 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
832 struct symbol
*sym
= find_pc_function (addr
);
835 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
836 throw_error (NO_ENTRY_VALUE_ERROR
,
837 _("DW_TAG_call_site resolving failed to find function "
838 "name for address %s"),
839 paddress (gdbarch
, addr
));
841 type
= SYMBOL_TYPE (sym
);
842 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
843 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
848 /* Verify function with entry point exact address ADDR can never call itself
849 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
850 can call itself via tail calls.
852 If a funtion can tail call itself its entry value based parameters are
853 unreliable. There is no verification whether the value of some/all
854 parameters is unchanged through the self tail call, we expect if there is
855 a self tail call all the parameters can be modified. */
858 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
862 /* The verification is completely unordered. Track here function addresses
863 which still need to be iterated. */
864 std::vector
<CORE_ADDR
> todo
;
866 /* Track here CORE_ADDRs which were already visited. */
867 std::unordered_set
<CORE_ADDR
> addr_hash
;
869 todo
.push_back (verify_addr
);
870 while (!todo
.empty ())
872 struct symbol
*func_sym
;
873 struct call_site
*call_site
;
878 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
880 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
881 call_site
; call_site
= call_site
->tail_call_next
)
883 CORE_ADDR target_addr
;
885 /* CALLER_FRAME with registers is not available for tail-call jumped
887 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
889 if (target_addr
== verify_addr
)
891 struct bound_minimal_symbol msym
;
893 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
894 throw_error (NO_ENTRY_VALUE_ERROR
,
895 _("DW_OP_entry_value resolving has found "
896 "function \"%s\" at %s can call itself via tail "
898 (msym
.minsym
== NULL
? "???"
899 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
900 paddress (gdbarch
, verify_addr
));
903 if (addr_hash
.insert (target_addr
).second
)
904 todo
.push_back (target_addr
);
909 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
910 ENTRY_VALUES_DEBUG. */
913 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
915 CORE_ADDR addr
= call_site
->pc
;
916 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
918 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
919 (msym
.minsym
== NULL
? "???"
920 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
924 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
925 only top callers and bottom callees which are present in both. GDBARCH is
926 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
927 no remaining possibilities to provide unambiguous non-trivial result.
928 RESULTP should point to NULL on the first (initialization) call. Caller is
929 responsible for xfree of any RESULTP data. */
932 chain_candidate (struct gdbarch
*gdbarch
,
933 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
934 std::vector
<struct call_site
*> *chain
)
936 long length
= chain
->size ();
937 int callers
, callees
, idx
;
939 if (*resultp
== NULL
)
941 /* Create the initial chain containing all the passed PCs. */
943 struct call_site_chain
*result
944 = ((struct call_site_chain
*)
945 xmalloc (sizeof (*result
)
946 + sizeof (*result
->call_site
) * (length
- 1)));
947 result
->length
= length
;
948 result
->callers
= result
->callees
= length
;
949 if (!chain
->empty ())
950 memcpy (result
->call_site
, chain
->data (),
951 sizeof (*result
->call_site
) * length
);
952 resultp
->reset (result
);
954 if (entry_values_debug
)
956 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
957 for (idx
= 0; idx
< length
; idx
++)
958 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
959 fputc_unfiltered ('\n', gdb_stdlog
);
965 if (entry_values_debug
)
967 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
968 for (idx
= 0; idx
< length
; idx
++)
969 tailcall_dump (gdbarch
, chain
->at (idx
));
970 fputc_unfiltered ('\n', gdb_stdlog
);
973 /* Intersect callers. */
975 callers
= std::min ((long) (*resultp
)->callers
, length
);
976 for (idx
= 0; idx
< callers
; idx
++)
977 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
979 (*resultp
)->callers
= idx
;
983 /* Intersect callees. */
985 callees
= std::min ((long) (*resultp
)->callees
, length
);
986 for (idx
= 0; idx
< callees
; idx
++)
987 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
988 != chain
->at (length
- 1 - idx
))
990 (*resultp
)->callees
= idx
;
994 if (entry_values_debug
)
996 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
997 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
998 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
999 fputs_unfiltered (" |", gdb_stdlog
);
1000 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1001 tailcall_dump (gdbarch
,
1002 (*resultp
)->call_site
[(*resultp
)->length
1003 - (*resultp
)->callees
+ idx
]);
1004 fputc_unfiltered ('\n', gdb_stdlog
);
1007 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1009 /* There are no common callers or callees. It could be also a direct
1010 call (which has length 0) with ambiguous possibility of an indirect
1011 call - CALLERS == CALLEES == 0 is valid during the first allocation
1012 but any subsequence processing of such entry means ambiguity. */
1013 resultp
->reset (NULL
);
1017 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1018 PC again. In such case there must be two different code paths to reach
1019 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1020 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1023 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1024 assumed frames between them use GDBARCH. Use depth first search so we can
1025 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1026 would have needless GDB stack overhead. Caller is responsible for xfree of
1027 the returned result. Any unreliability results in thrown
1028 NO_ENTRY_VALUE_ERROR. */
1030 static struct call_site_chain
*
1031 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1032 CORE_ADDR callee_pc
)
1034 CORE_ADDR save_callee_pc
= callee_pc
;
1035 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1036 struct call_site
*call_site
;
1038 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1039 call_site nor any possible call_site at CALLEE_PC's function is there.
1040 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1041 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1042 std::vector
<struct call_site
*> chain
;
1044 /* We are not interested in the specific PC inside the callee function. */
1045 callee_pc
= get_pc_function_start (callee_pc
);
1047 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1048 paddress (gdbarch
, save_callee_pc
));
1050 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1051 std::unordered_set
<CORE_ADDR
> addr_hash
;
1053 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1054 at the target's function. All the possible tail call sites in the
1055 target's function will get iterated as already pushed into CHAIN via their
1057 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1061 CORE_ADDR target_func_addr
;
1062 struct call_site
*target_call_site
;
1064 /* CALLER_FRAME with registers is not available for tail-call jumped
1066 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1068 if (target_func_addr
== callee_pc
)
1070 chain_candidate (gdbarch
, &retval
, &chain
);
1074 /* There is no way to reach CALLEE_PC again as we would prevent
1075 entering it twice as being already marked in ADDR_HASH. */
1076 target_call_site
= NULL
;
1080 struct symbol
*target_func
;
1082 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1083 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1088 /* Attempt to visit TARGET_CALL_SITE. */
1090 if (target_call_site
)
1092 if (addr_hash
.insert (target_call_site
->pc
).second
)
1094 /* Successfully entered TARGET_CALL_SITE. */
1096 chain
.push_back (target_call_site
);
1101 /* Backtrack (without revisiting the originating call_site). Try the
1102 callers's sibling; if there isn't any try the callers's callers's
1105 target_call_site
= NULL
;
1106 while (!chain
.empty ())
1108 call_site
= chain
.back ();
1111 size_t removed
= addr_hash
.erase (call_site
->pc
);
1112 gdb_assert (removed
== 1);
1114 target_call_site
= call_site
->tail_call_next
;
1115 if (target_call_site
)
1119 while (target_call_site
);
1124 call_site
= chain
.back ();
1129 struct bound_minimal_symbol msym_caller
, msym_callee
;
1131 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1132 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1133 throw_error (NO_ENTRY_VALUE_ERROR
,
1134 _("There are no unambiguously determinable intermediate "
1135 "callers or callees between caller function \"%s\" at %s "
1136 "and callee function \"%s\" at %s"),
1137 (msym_caller
.minsym
== NULL
1138 ? "???" : MSYMBOL_PRINT_NAME (msym_caller
.minsym
)),
1139 paddress (gdbarch
, caller_pc
),
1140 (msym_callee
.minsym
== NULL
1141 ? "???" : MSYMBOL_PRINT_NAME (msym_callee
.minsym
)),
1142 paddress (gdbarch
, callee_pc
));
1145 return retval
.release ();
1148 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1149 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1150 constructed return NULL. Caller is responsible for xfree of the returned
1153 struct call_site_chain
*
1154 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1155 CORE_ADDR callee_pc
)
1157 struct call_site_chain
*retval
= NULL
;
1161 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1163 CATCH (e
, RETURN_MASK_ERROR
)
1165 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1167 if (entry_values_debug
)
1168 exception_print (gdb_stdout
, e
);
1173 throw_exception (e
);
1180 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1183 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1184 enum call_site_parameter_kind kind
,
1185 union call_site_parameter_u kind_u
)
1187 if (kind
== parameter
->kind
)
1190 case CALL_SITE_PARAMETER_DWARF_REG
:
1191 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1192 case CALL_SITE_PARAMETER_FB_OFFSET
:
1193 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1194 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1195 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1200 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1201 FRAME is for callee.
1203 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1206 static struct call_site_parameter
*
1207 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1208 enum call_site_parameter_kind kind
,
1209 union call_site_parameter_u kind_u
,
1210 struct dwarf2_per_cu_data
**per_cu_return
)
1212 CORE_ADDR func_addr
, caller_pc
;
1213 struct gdbarch
*gdbarch
;
1214 struct frame_info
*caller_frame
;
1215 struct call_site
*call_site
;
1217 /* Initialize it just to avoid a GCC false warning. */
1218 struct call_site_parameter
*parameter
= NULL
;
1219 CORE_ADDR target_addr
;
1221 while (get_frame_type (frame
) == INLINE_FRAME
)
1223 frame
= get_prev_frame (frame
);
1224 gdb_assert (frame
!= NULL
);
1227 func_addr
= get_frame_func (frame
);
1228 gdbarch
= get_frame_arch (frame
);
1229 caller_frame
= get_prev_frame (frame
);
1230 if (gdbarch
!= frame_unwind_arch (frame
))
1232 struct bound_minimal_symbol msym
1233 = lookup_minimal_symbol_by_pc (func_addr
);
1234 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1236 throw_error (NO_ENTRY_VALUE_ERROR
,
1237 _("DW_OP_entry_value resolving callee gdbarch %s "
1238 "(of %s (%s)) does not match caller gdbarch %s"),
1239 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1240 paddress (gdbarch
, func_addr
),
1241 (msym
.minsym
== NULL
? "???"
1242 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
1243 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1246 if (caller_frame
== NULL
)
1248 struct bound_minimal_symbol msym
1249 = lookup_minimal_symbol_by_pc (func_addr
);
1251 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1252 "requires caller of %s (%s)"),
1253 paddress (gdbarch
, func_addr
),
1254 (msym
.minsym
== NULL
? "???"
1255 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
1257 caller_pc
= get_frame_pc (caller_frame
);
1258 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1260 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1261 if (target_addr
!= func_addr
)
1263 struct minimal_symbol
*target_msym
, *func_msym
;
1265 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1266 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1267 throw_error (NO_ENTRY_VALUE_ERROR
,
1268 _("DW_OP_entry_value resolving expects callee %s at %s "
1269 "but the called frame is for %s at %s"),
1270 (target_msym
== NULL
? "???"
1271 : MSYMBOL_PRINT_NAME (target_msym
)),
1272 paddress (gdbarch
, target_addr
),
1273 func_msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (func_msym
),
1274 paddress (gdbarch
, func_addr
));
1277 /* No entry value based parameters would be reliable if this function can
1278 call itself via tail calls. */
1279 func_verify_no_selftailcall (gdbarch
, func_addr
);
1281 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1283 parameter
= &call_site
->parameter
[iparams
];
1284 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1287 if (iparams
== call_site
->parameter_count
)
1289 struct minimal_symbol
*msym
1290 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1292 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1293 determine its value. */
1294 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1295 "at DW_TAG_call_site %s at %s"),
1296 paddress (gdbarch
, caller_pc
),
1297 msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (msym
));
1300 *per_cu_return
= call_site
->per_cu
;
1304 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1305 the normal DW_AT_call_value block. Otherwise return the
1306 DW_AT_call_data_value (dereferenced) block.
1308 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1311 Function always returns non-NULL, non-optimized out value. It throws
1312 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1314 static struct value
*
1315 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1316 CORE_ADDR deref_size
, struct type
*type
,
1317 struct frame_info
*caller_frame
,
1318 struct dwarf2_per_cu_data
*per_cu
)
1320 const gdb_byte
*data_src
;
1324 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1325 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1327 /* DEREF_SIZE size is not verified here. */
1328 if (data_src
== NULL
)
1329 throw_error (NO_ENTRY_VALUE_ERROR
,
1330 _("Cannot resolve DW_AT_call_data_value"));
1332 /* DW_AT_call_value is a DWARF expression, not a DWARF
1333 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1335 data
= (gdb_byte
*) alloca (size
+ 1);
1336 memcpy (data
, data_src
, size
);
1337 data
[size
] = DW_OP_stack_value
;
1339 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1342 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1343 the indirect method on it, that is use its stored target value, the sole
1344 purpose of entry_data_value_funcs.. */
1346 static struct value
*
1347 entry_data_value_coerce_ref (const struct value
*value
)
1349 struct type
*checked_type
= check_typedef (value_type (value
));
1350 struct value
*target_val
;
1352 if (!TYPE_IS_REFERENCE (checked_type
))
1355 target_val
= (struct value
*) value_computed_closure (value
);
1356 value_incref (target_val
);
1360 /* Implement copy_closure. */
1363 entry_data_value_copy_closure (const struct value
*v
)
1365 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1367 value_incref (target_val
);
1371 /* Implement free_closure. */
1374 entry_data_value_free_closure (struct value
*v
)
1376 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1378 value_free (target_val
);
1381 /* Vector for methods for an entry value reference where the referenced value
1382 is stored in the caller. On the first dereference use
1383 DW_AT_call_data_value in the caller. */
1385 static const struct lval_funcs entry_data_value_funcs
=
1389 NULL
, /* indirect */
1390 entry_data_value_coerce_ref
,
1391 NULL
, /* check_synthetic_pointer */
1392 entry_data_value_copy_closure
,
1393 entry_data_value_free_closure
1396 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1397 are used to match DW_AT_location at the caller's
1398 DW_TAG_call_site_parameter.
1400 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1401 cannot resolve the parameter for any reason. */
1403 static struct value
*
1404 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1405 enum call_site_parameter_kind kind
,
1406 union call_site_parameter_u kind_u
)
1408 struct type
*checked_type
= check_typedef (type
);
1409 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1410 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1411 struct value
*outer_val
, *target_val
, *val
;
1412 struct call_site_parameter
*parameter
;
1413 struct dwarf2_per_cu_data
*caller_per_cu
;
1415 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1418 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1422 /* Check if DW_AT_call_data_value cannot be used. If it should be
1423 used and it is not available do not fall back to OUTER_VAL - dereferencing
1424 TYPE_CODE_REF with non-entry data value would give current value - not the
1427 if (!TYPE_IS_REFERENCE (checked_type
)
1428 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1431 target_val
= dwarf_entry_parameter_to_value (parameter
,
1432 TYPE_LENGTH (target_type
),
1433 target_type
, caller_frame
,
1436 release_value (target_val
);
1437 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1438 target_val
/* closure */);
1440 /* Copy the referencing pointer to the new computed value. */
1441 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1442 TYPE_LENGTH (checked_type
));
1443 set_value_lazy (val
, 0);
1448 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1449 SIZE are DWARF block used to match DW_AT_location at the caller's
1450 DW_TAG_call_site_parameter.
1452 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1453 cannot resolve the parameter for any reason. */
1455 static struct value
*
1456 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1457 const gdb_byte
*block
, size_t block_len
)
1459 union call_site_parameter_u kind_u
;
1461 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1462 if (kind_u
.dwarf_reg
!= -1)
1463 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1466 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1467 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1470 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1471 suppressed during normal operation. The expression can be arbitrary if
1472 there is no caller-callee entry value binding expected. */
1473 throw_error (NO_ENTRY_VALUE_ERROR
,
1474 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1475 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1478 struct piece_closure
1480 /* Reference count. */
1483 /* The CU from which this closure's expression came. */
1484 struct dwarf2_per_cu_data
*per_cu
;
1486 /* The number of pieces used to describe this variable. */
1489 /* The pieces themselves. */
1490 struct dwarf_expr_piece
*pieces
;
1492 /* Frame ID of frame to which a register value is relative, used
1493 only by DWARF_VALUE_REGISTER. */
1494 struct frame_id frame_id
;
1497 /* Allocate a closure for a value formed from separately-described
1500 static struct piece_closure
*
1501 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1502 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1503 struct frame_info
*frame
)
1505 struct piece_closure
*c
= XCNEW (struct piece_closure
);
1510 c
->n_pieces
= n_pieces
;
1511 c
->pieces
= XCNEWVEC (struct dwarf_expr_piece
, n_pieces
);
1513 c
->frame_id
= null_frame_id
;
1515 c
->frame_id
= get_frame_id (frame
);
1517 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1518 for (i
= 0; i
< n_pieces
; ++i
)
1519 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1520 value_incref (c
->pieces
[i
].v
.value
);
1525 /* Copy NBITS bits from SOURCE to DEST starting at the given bit
1526 offsets. Use the bit order as specified by BITS_BIG_ENDIAN.
1527 Source and destination buffers must not overlap. */
1530 copy_bitwise (gdb_byte
*dest
, ULONGEST dest_offset
,
1531 const gdb_byte
*source
, ULONGEST source_offset
,
1532 ULONGEST nbits
, int bits_big_endian
)
1534 unsigned int buf
, avail
;
1539 if (bits_big_endian
)
1541 /* Start from the end, then work backwards. */
1542 dest_offset
+= nbits
- 1;
1543 dest
+= dest_offset
/ 8;
1544 dest_offset
= 7 - dest_offset
% 8;
1545 source_offset
+= nbits
- 1;
1546 source
+= source_offset
/ 8;
1547 source_offset
= 7 - source_offset
% 8;
1551 dest
+= dest_offset
/ 8;
1553 source
+= source_offset
/ 8;
1557 /* Fill BUF with DEST_OFFSET bits from the destination and 8 -
1558 SOURCE_OFFSET bits from the source. */
1559 buf
= *(bits_big_endian
? source
-- : source
++) >> source_offset
;
1560 buf
<<= dest_offset
;
1561 buf
|= *dest
& ((1 << dest_offset
) - 1);
1563 /* NBITS: bits yet to be written; AVAIL: BUF's fill level. */
1564 nbits
+= dest_offset
;
1565 avail
= dest_offset
+ 8 - source_offset
;
1567 /* Flush 8 bits from BUF, if appropriate. */
1568 if (nbits
>= 8 && avail
>= 8)
1570 *(bits_big_endian
? dest
-- : dest
++) = buf
;
1576 /* Copy the middle part. */
1579 size_t len
= nbits
/ 8;
1581 /* Use a faster method for byte-aligned copies. */
1584 if (bits_big_endian
)
1588 memcpy (dest
+ 1, source
+ 1, len
);
1592 memcpy (dest
, source
, len
);
1601 buf
|= *(bits_big_endian
? source
-- : source
++) << avail
;
1602 *(bits_big_endian
? dest
-- : dest
++) = buf
;
1609 /* Write the last byte. */
1613 buf
|= *source
<< avail
;
1615 buf
&= (1 << nbits
) - 1;
1616 *dest
= (*dest
& (~0 << nbits
)) | buf
;
1622 namespace selftests
{
1624 /* Helper function for the unit test of copy_bitwise. Convert NBITS bits
1625 out of BITS, starting at OFFS, to the respective '0'/'1'-string. MSB0
1626 specifies whether to assume big endian bit numbering. Store the
1627 resulting (not null-terminated) string at STR. */
1630 bits_to_str (char *str
, const gdb_byte
*bits
, ULONGEST offs
,
1631 ULONGEST nbits
, int msb0
)
1636 for (i
= offs
/ 8, j
= offs
% 8; nbits
; i
++, j
= 0)
1638 unsigned int ch
= bits
[i
];
1639 for (; j
< 8 && nbits
; j
++, nbits
--)
1640 *str
++ = (ch
& (msb0
? (1 << (7 - j
)) : (1 << j
))) ? '1' : '0';
1644 /* Check one invocation of copy_bitwise with the given parameters. */
1647 check_copy_bitwise (const gdb_byte
*dest
, unsigned int dest_offset
,
1648 const gdb_byte
*source
, unsigned int source_offset
,
1649 unsigned int nbits
, int msb0
)
1651 size_t len
= align_up (dest_offset
+ nbits
, 8);
1652 char *expected
= (char *) alloca (len
+ 1);
1653 char *actual
= (char *) alloca (len
+ 1);
1654 gdb_byte
*buf
= (gdb_byte
*) alloca (len
/ 8);
1656 /* Compose a '0'/'1'-string that represents the expected result of
1658 Bits from [0, DEST_OFFSET) are filled from DEST.
1659 Bits from [DEST_OFFSET, DEST_OFFSET + NBITS) are filled from SOURCE.
1660 Bits from [DEST_OFFSET + NBITS, LEN) are filled from DEST.
1669 We should end up with:
1671 DDDDSSDD (D=dest, S=source)
1673 bits_to_str (expected
, dest
, 0, len
, msb0
);
1674 bits_to_str (expected
+ dest_offset
, source
, source_offset
, nbits
, msb0
);
1676 /* Fill BUF with data from DEST, apply copy_bitwise, and convert the
1677 result to a '0'/'1'-string. */
1678 memcpy (buf
, dest
, len
/ 8);
1679 copy_bitwise (buf
, dest_offset
, source
, source_offset
, nbits
, msb0
);
1680 bits_to_str (actual
, buf
, 0, len
, msb0
);
1682 /* Compare the resulting strings. */
1683 expected
[len
] = actual
[len
] = '\0';
1684 if (strcmp (expected
, actual
) != 0)
1685 error (_("copy_bitwise %s != %s (%u+%u -> %u)"),
1686 expected
, actual
, source_offset
, nbits
, dest_offset
);
1689 /* Unit test for copy_bitwise. */
1692 copy_bitwise_tests (void)
1694 /* Data to be used as both source and destination buffers. The two
1695 arrays below represent the lsb0- and msb0- encoded versions of the
1696 following bit string, respectively:
1697 00000000 00011111 11111111 01001000 10100101 11110010
1698 This pattern is chosen such that it contains:
1699 - constant 0- and 1- chunks of more than a full byte;
1700 - 0/1- and 1/0 transitions on all bit positions within a byte;
1701 - several sufficiently asymmetric bytes.
1703 static const gdb_byte data_lsb0
[] = {
1704 0x00, 0xf8, 0xff, 0x12, 0xa5, 0x4f
1706 static const gdb_byte data_msb0
[] = {
1707 0x00, 0x1f, 0xff, 0x48, 0xa5, 0xf2
1710 constexpr size_t data_nbits
= 8 * sizeof (data_lsb0
);
1711 constexpr unsigned max_nbits
= 24;
1713 /* Try all combinations of:
1714 lsb0/msb0 bit order (using the respective data array)
1715 X [0, MAX_NBITS] copy bit width
1716 X feasible source offsets for the given copy bit width
1717 X feasible destination offsets
1719 for (int msb0
= 0; msb0
< 2; msb0
++)
1721 const gdb_byte
*data
= msb0
? data_msb0
: data_lsb0
;
1723 for (unsigned int nbits
= 1; nbits
<= max_nbits
; nbits
++)
1725 const unsigned int max_offset
= data_nbits
- nbits
;
1727 for (unsigned source_offset
= 0;
1728 source_offset
<= max_offset
;
1731 for (unsigned dest_offset
= 0;
1732 dest_offset
<= max_offset
;
1735 check_copy_bitwise (data
+ dest_offset
/ 8,
1737 data
+ source_offset
/ 8,
1744 /* Special cases: copy all, copy nothing. */
1745 check_copy_bitwise (data_lsb0
, 0, data_msb0
, 0, data_nbits
, msb0
);
1746 check_copy_bitwise (data_msb0
, 0, data_lsb0
, 0, data_nbits
, msb0
);
1747 check_copy_bitwise (data
, data_nbits
- 7, data
, 9, 0, msb0
);
1751 } /* namespace selftests */
1753 #endif /* GDB_SELF_TEST */
1756 read_pieced_value (struct value
*v
)
1760 ULONGEST bits_to_skip
;
1762 struct piece_closure
*c
1763 = (struct piece_closure
*) value_computed_closure (v
);
1765 size_t buffer_size
= 0;
1766 std::vector
<gdb_byte
> buffer
;
1768 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1770 if (value_type (v
) != value_enclosing_type (v
))
1771 internal_error (__FILE__
, __LINE__
,
1772 _("Should not be able to create a lazy value with "
1773 "an enclosing type"));
1775 contents
= value_contents_raw (v
);
1776 bits_to_skip
= 8 * value_offset (v
);
1777 if (value_bitsize (v
))
1779 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1780 + value_bitpos (v
));
1781 type_len
= value_bitsize (v
);
1784 type_len
= 8 * TYPE_LENGTH (value_type (v
));
1786 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1788 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1789 size_t this_size
, this_size_bits
;
1790 long dest_offset_bits
, source_offset_bits
, source_offset
;
1791 const gdb_byte
*intermediate_buffer
;
1793 /* Compute size, source, and destination offsets for copying, in
1795 this_size_bits
= p
->size
;
1796 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1798 bits_to_skip
-= this_size_bits
;
1801 if (bits_to_skip
> 0)
1803 dest_offset_bits
= 0;
1804 source_offset_bits
= bits_to_skip
;
1805 this_size_bits
-= bits_to_skip
;
1810 dest_offset_bits
= offset
;
1811 source_offset_bits
= 0;
1813 if (this_size_bits
> type_len
- offset
)
1814 this_size_bits
= type_len
- offset
;
1816 this_size
= (this_size_bits
+ source_offset_bits
% 8 + 7) / 8;
1817 source_offset
= source_offset_bits
/ 8;
1818 if (buffer_size
< this_size
)
1820 buffer_size
= this_size
;
1821 buffer
.reserve (buffer_size
);
1823 intermediate_buffer
= buffer
.data ();
1825 /* Copy from the source to DEST_BUFFER. */
1826 switch (p
->location
)
1828 case DWARF_VALUE_REGISTER
:
1830 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1831 struct gdbarch
*arch
= get_frame_arch (frame
);
1832 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1834 LONGEST reg_offset
= source_offset
;
1836 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1837 && this_size
< register_size (arch
, gdb_regnum
))
1839 /* Big-endian, and we want less than full size. */
1840 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
1841 /* We want the lower-order THIS_SIZE_BITS of the bytes
1842 we extract from the register. */
1843 source_offset_bits
+= 8 * this_size
- this_size_bits
;
1846 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
1847 this_size
, buffer
.data (),
1850 /* Just so garbage doesn't ever shine through. */
1851 memset (buffer
.data (), 0, this_size
);
1854 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1856 mark_value_bits_unavailable (v
, offset
, this_size_bits
);
1859 copy_bitwise (contents
, dest_offset_bits
,
1860 intermediate_buffer
, source_offset_bits
% 8,
1861 this_size_bits
, bits_big_endian
);
1865 case DWARF_VALUE_MEMORY
:
1866 read_value_memory (v
, offset
,
1867 p
->v
.mem
.in_stack_memory
,
1868 p
->v
.mem
.addr
+ source_offset
,
1869 buffer
.data (), this_size
);
1870 copy_bitwise (contents
, dest_offset_bits
,
1871 intermediate_buffer
, source_offset_bits
% 8,
1872 this_size_bits
, bits_big_endian
);
1875 case DWARF_VALUE_STACK
:
1877 struct objfile
*objfile
= dwarf2_per_cu_objfile (c
->per_cu
);
1878 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1879 ULONGEST stack_value_size_bits
1880 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1882 /* Use zeroes if piece reaches beyond stack value. */
1883 if (p
->size
> stack_value_size_bits
)
1886 /* Piece is anchored at least significant bit end. */
1887 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1888 source_offset_bits
+= stack_value_size_bits
- p
->size
;
1890 copy_bitwise (contents
, dest_offset_bits
,
1891 value_contents_all (p
->v
.value
),
1893 this_size_bits
, bits_big_endian
);
1897 case DWARF_VALUE_LITERAL
:
1899 size_t n
= this_size
;
1901 if (n
> p
->v
.literal
.length
- source_offset
)
1902 n
= (p
->v
.literal
.length
>= source_offset
1903 ? p
->v
.literal
.length
- source_offset
1906 intermediate_buffer
= p
->v
.literal
.data
+ source_offset
;
1908 copy_bitwise (contents
, dest_offset_bits
,
1909 intermediate_buffer
, source_offset_bits
% 8,
1910 this_size_bits
, bits_big_endian
);
1914 /* These bits show up as zeros -- but do not cause the value
1915 to be considered optimized-out. */
1916 case DWARF_VALUE_IMPLICIT_POINTER
:
1919 case DWARF_VALUE_OPTIMIZED_OUT
:
1920 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1924 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
1927 offset
+= this_size_bits
;
1932 write_pieced_value (struct value
*to
, struct value
*from
)
1936 ULONGEST bits_to_skip
;
1937 const gdb_byte
*contents
;
1938 struct piece_closure
*c
1939 = (struct piece_closure
*) value_computed_closure (to
);
1941 size_t buffer_size
= 0;
1942 std::vector
<gdb_byte
> buffer
;
1944 = gdbarch_bits_big_endian (get_type_arch (value_type (to
)));
1946 contents
= value_contents (from
);
1947 bits_to_skip
= 8 * value_offset (to
);
1948 if (value_bitsize (to
))
1950 bits_to_skip
+= (8 * value_offset (value_parent (to
))
1951 + value_bitpos (to
));
1952 type_len
= value_bitsize (to
);
1955 type_len
= 8 * TYPE_LENGTH (value_type (to
));
1957 for (i
= 0; i
< c
->n_pieces
&& offset
< type_len
; i
++)
1959 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1960 size_t this_size_bits
, this_size
;
1961 long dest_offset_bits
, source_offset_bits
, dest_offset
, source_offset
;
1963 const gdb_byte
*source_buffer
;
1965 this_size_bits
= p
->size
;
1966 if (bits_to_skip
> 0 && bits_to_skip
>= this_size_bits
)
1968 bits_to_skip
-= this_size_bits
;
1971 if (bits_to_skip
> 0)
1973 dest_offset_bits
= bits_to_skip
;
1974 source_offset_bits
= 0;
1975 this_size_bits
-= bits_to_skip
;
1980 dest_offset_bits
= 0;
1981 source_offset_bits
= offset
;
1983 if (this_size_bits
> type_len
- offset
)
1984 this_size_bits
= type_len
- offset
;
1986 this_size
= (this_size_bits
+ dest_offset_bits
% 8 + 7) / 8;
1987 source_offset
= source_offset_bits
/ 8;
1988 dest_offset
= dest_offset_bits
/ 8;
1989 if (dest_offset_bits
% 8 == 0 && source_offset_bits
% 8 == 0)
1991 source_buffer
= contents
+ source_offset
;
1996 if (buffer_size
< this_size
)
1998 buffer_size
= this_size
;
1999 buffer
.reserve (buffer_size
);
2001 source_buffer
= buffer
.data ();
2005 switch (p
->location
)
2007 case DWARF_VALUE_REGISTER
:
2009 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
2010 struct gdbarch
*arch
= get_frame_arch (frame
);
2011 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
2012 int reg_offset
= dest_offset
;
2014 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
2015 && this_size
<= register_size (arch
, gdb_regnum
))
2017 /* Big-endian, and we want less than full size. */
2018 reg_offset
= register_size (arch
, gdb_regnum
) - this_size
;
2025 if (!get_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
2026 this_size
, buffer
.data (),
2030 throw_error (OPTIMIZED_OUT_ERROR
,
2031 _("Can't do read-modify-write to "
2032 "update bitfield; containing word "
2033 "has been optimized out"));
2035 throw_error (NOT_AVAILABLE_ERROR
,
2036 _("Can't do read-modify-write to update "
2037 "bitfield; containing word "
2040 copy_bitwise (buffer
.data (), dest_offset_bits
,
2041 contents
, source_offset_bits
,
2046 put_frame_register_bytes (frame
, gdb_regnum
, reg_offset
,
2047 this_size
, source_buffer
);
2050 case DWARF_VALUE_MEMORY
:
2053 /* Only the first and last bytes can possibly have any
2055 read_memory (p
->v
.mem
.addr
+ dest_offset
, buffer
.data (), 1);
2056 read_memory (p
->v
.mem
.addr
+ dest_offset
+ this_size
- 1,
2057 &buffer
[this_size
- 1], 1);
2058 copy_bitwise (buffer
.data (), dest_offset_bits
,
2059 contents
, source_offset_bits
,
2064 write_memory (p
->v
.mem
.addr
+ dest_offset
,
2065 source_buffer
, this_size
);
2068 mark_value_bytes_optimized_out (to
, 0, TYPE_LENGTH (value_type (to
)));
2071 offset
+= this_size_bits
;
2075 /* An implementation of an lval_funcs method to see whether a value is
2076 a synthetic pointer. */
2079 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
2082 struct piece_closure
*c
2083 = (struct piece_closure
*) value_computed_closure (value
);
2086 bit_offset
+= 8 * value_offset (value
);
2087 if (value_bitsize (value
))
2088 bit_offset
+= value_bitpos (value
);
2090 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2092 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2093 size_t this_size_bits
= p
->size
;
2097 if (bit_offset
>= this_size_bits
)
2099 bit_offset
-= this_size_bits
;
2103 bit_length
-= this_size_bits
- bit_offset
;
2107 bit_length
-= this_size_bits
;
2109 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2116 /* A wrapper function for get_frame_address_in_block. */
2119 get_frame_address_in_block_wrapper (void *baton
)
2121 return get_frame_address_in_block ((struct frame_info
*) baton
);
2124 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2126 static struct value
*
2127 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2128 struct dwarf2_per_cu_data
*per_cu
,
2131 struct value
*result
= NULL
;
2132 struct obstack temp_obstack
;
2133 struct cleanup
*cleanup
;
2134 const gdb_byte
*bytes
;
2137 obstack_init (&temp_obstack
);
2138 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2139 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
2143 if (byte_offset
>= 0
2144 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2146 bytes
+= byte_offset
;
2147 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2150 invalid_synthetic_pointer ();
2153 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2155 do_cleanups (cleanup
);
2160 /* Fetch the value pointed to by a synthetic pointer. */
2162 static struct value
*
2163 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2164 struct dwarf2_per_cu_data
*per_cu
,
2165 struct frame_info
*frame
, struct type
*type
)
2167 /* Fetch the location expression of the DIE we're pointing to. */
2168 struct dwarf2_locexpr_baton baton
2169 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
2170 get_frame_address_in_block_wrapper
, frame
);
2172 /* Get type of pointed-to DIE. */
2173 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
);
2174 if (orig_type
== NULL
)
2175 invalid_synthetic_pointer ();
2177 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2178 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2179 or it may've been optimized out. */
2180 if (baton
.data
!= NULL
)
2181 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2182 baton
.size
, baton
.per_cu
,
2183 TYPE_TARGET_TYPE (type
),
2186 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2190 /* An implementation of an lval_funcs method to indirect through a
2191 pointer. This handles the synthetic pointer case when needed. */
2193 static struct value
*
2194 indirect_pieced_value (struct value
*value
)
2196 struct piece_closure
*c
2197 = (struct piece_closure
*) value_computed_closure (value
);
2199 struct frame_info
*frame
;
2200 struct dwarf2_locexpr_baton baton
;
2203 struct dwarf_expr_piece
*piece
= NULL
;
2204 LONGEST byte_offset
;
2205 enum bfd_endian byte_order
;
2207 type
= check_typedef (value_type (value
));
2208 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2211 bit_length
= 8 * TYPE_LENGTH (type
);
2212 bit_offset
= 8 * value_offset (value
);
2213 if (value_bitsize (value
))
2214 bit_offset
+= value_bitpos (value
);
2216 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2218 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2219 size_t this_size_bits
= p
->size
;
2223 if (bit_offset
>= this_size_bits
)
2225 bit_offset
-= this_size_bits
;
2229 bit_length
-= this_size_bits
- bit_offset
;
2233 bit_length
-= this_size_bits
;
2235 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2238 if (bit_length
!= 0)
2239 error (_("Invalid use of DW_OP_implicit_pointer"));
2245 gdb_assert (piece
!= NULL
);
2246 frame
= get_selected_frame (_("No frame selected."));
2248 /* This is an offset requested by GDB, such as value subscripts.
2249 However, due to how synthetic pointers are implemented, this is
2250 always presented to us as a pointer type. This means we have to
2251 sign-extend it manually as appropriate. Use raw
2252 extract_signed_integer directly rather than value_as_address and
2253 sign extend afterwards on architectures that would need it
2254 (mostly everywhere except MIPS, which has signed addresses) as
2255 the later would go through gdbarch_pointer_to_address and thus
2256 return a CORE_ADDR with high bits set on architectures that
2257 encode address spaces and other things in CORE_ADDR. */
2258 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2259 byte_offset
= extract_signed_integer (value_contents (value
),
2260 TYPE_LENGTH (type
), byte_order
);
2261 byte_offset
+= piece
->v
.ptr
.offset
;
2263 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2264 byte_offset
, c
->per_cu
,
2268 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2271 static struct value
*
2272 coerce_pieced_ref (const struct value
*value
)
2274 struct type
*type
= check_typedef (value_type (value
));
2276 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2277 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2279 const struct piece_closure
*closure
2280 = (struct piece_closure
*) value_computed_closure (value
);
2281 struct frame_info
*frame
2282 = get_selected_frame (_("No frame selected."));
2284 /* gdb represents synthetic pointers as pieced values with a single
2286 gdb_assert (closure
!= NULL
);
2287 gdb_assert (closure
->n_pieces
== 1);
2289 return indirect_synthetic_pointer (closure
->pieces
->v
.ptr
.die_sect_off
,
2290 closure
->pieces
->v
.ptr
.offset
,
2291 closure
->per_cu
, frame
, type
);
2295 /* Else: not a synthetic reference; do nothing. */
2301 copy_pieced_value_closure (const struct value
*v
)
2303 struct piece_closure
*c
2304 = (struct piece_closure
*) value_computed_closure (v
);
2311 free_pieced_value_closure (struct value
*v
)
2313 struct piece_closure
*c
2314 = (struct piece_closure
*) value_computed_closure (v
);
2321 for (i
= 0; i
< c
->n_pieces
; ++i
)
2322 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2323 value_free (c
->pieces
[i
].v
.value
);
2330 /* Functions for accessing a variable described by DW_OP_piece. */
2331 static const struct lval_funcs pieced_value_funcs
= {
2334 indirect_pieced_value
,
2336 check_pieced_synthetic_pointer
,
2337 copy_pieced_value_closure
,
2338 free_pieced_value_closure
2341 /* Evaluate a location description, starting at DATA and with length
2342 SIZE, to find the current location of variable of TYPE in the
2343 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2344 location of the subobject of type SUBOBJ_TYPE at byte offset
2345 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2347 static struct value
*
2348 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2349 const gdb_byte
*data
, size_t size
,
2350 struct dwarf2_per_cu_data
*per_cu
,
2351 struct type
*subobj_type
,
2352 LONGEST subobj_byte_offset
)
2354 struct value
*retval
;
2355 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2357 if (subobj_type
== NULL
)
2360 subobj_byte_offset
= 0;
2362 else if (subobj_byte_offset
< 0)
2363 invalid_synthetic_pointer ();
2366 return allocate_optimized_out_value (subobj_type
);
2368 dwarf_evaluate_loc_desc ctx
;
2370 ctx
.per_cu
= per_cu
;
2371 ctx
.obj_address
= 0;
2373 scoped_value_mark free_values
;
2375 ctx
.gdbarch
= get_objfile_arch (objfile
);
2376 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2377 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2378 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2382 ctx
.eval (data
, size
);
2384 CATCH (ex
, RETURN_MASK_ERROR
)
2386 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2388 free_values
.free_to_mark ();
2389 retval
= allocate_value (subobj_type
);
2390 mark_value_bytes_unavailable (retval
, 0,
2391 TYPE_LENGTH (subobj_type
));
2394 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2396 if (entry_values_debug
)
2397 exception_print (gdb_stdout
, ex
);
2398 free_values
.free_to_mark ();
2399 return allocate_optimized_out_value (subobj_type
);
2402 throw_exception (ex
);
2406 if (ctx
.num_pieces
> 0)
2408 struct piece_closure
*c
;
2409 ULONGEST bit_size
= 0;
2412 for (i
= 0; i
< ctx
.num_pieces
; ++i
)
2413 bit_size
+= ctx
.pieces
[i
].size
;
2414 if (8 * (subobj_byte_offset
+ TYPE_LENGTH (subobj_type
)) > bit_size
)
2415 invalid_synthetic_pointer ();
2417 c
= allocate_piece_closure (per_cu
, ctx
.num_pieces
, ctx
.pieces
,
2419 /* We must clean up the value chain after creating the piece
2420 closure but before allocating the result. */
2421 free_values
.free_to_mark ();
2422 retval
= allocate_computed_value (subobj_type
,
2423 &pieced_value_funcs
, c
);
2424 set_value_offset (retval
, subobj_byte_offset
);
2428 switch (ctx
.location
)
2430 case DWARF_VALUE_REGISTER
:
2432 struct gdbarch
*arch
= get_frame_arch (frame
);
2434 = longest_to_int (value_as_long (ctx
.fetch (0)));
2435 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2437 if (subobj_byte_offset
!= 0)
2438 error (_("cannot use offset on synthetic pointer to register"));
2439 free_values
.free_to_mark ();
2440 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2441 if (value_optimized_out (retval
))
2445 /* This means the register has undefined value / was
2446 not saved. As we're computing the location of some
2447 variable etc. in the program, not a value for
2448 inspecting a register ($pc, $sp, etc.), return a
2449 generic optimized out value instead, so that we show
2450 <optimized out> instead of <not saved>. */
2451 tmp
= allocate_value (subobj_type
);
2452 value_contents_copy (tmp
, 0, retval
, 0,
2453 TYPE_LENGTH (subobj_type
));
2459 case DWARF_VALUE_MEMORY
:
2461 struct type
*ptr_type
;
2462 CORE_ADDR address
= ctx
.fetch_address (0);
2463 int in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2465 /* DW_OP_deref_size (and possibly other operations too) may
2466 create a pointer instead of an address. Ideally, the
2467 pointer to address conversion would be performed as part
2468 of those operations, but the type of the object to
2469 which the address refers is not known at the time of
2470 the operation. Therefore, we do the conversion here
2471 since the type is readily available. */
2473 switch (TYPE_CODE (subobj_type
))
2475 case TYPE_CODE_FUNC
:
2476 case TYPE_CODE_METHOD
:
2477 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2480 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2483 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2485 free_values
.free_to_mark ();
2486 retval
= value_at_lazy (subobj_type
,
2487 address
+ subobj_byte_offset
);
2488 if (in_stack_memory
)
2489 set_value_stack (retval
, 1);
2493 case DWARF_VALUE_STACK
:
2495 struct value
*value
= ctx
.fetch (0);
2496 size_t n
= TYPE_LENGTH (value_type (value
));
2497 size_t len
= TYPE_LENGTH (subobj_type
);
2498 size_t max
= TYPE_LENGTH (type
);
2499 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2500 struct cleanup
*cleanup
;
2502 if (subobj_byte_offset
+ len
> max
)
2503 invalid_synthetic_pointer ();
2505 /* Preserve VALUE because we are going to free values back
2506 to the mark, but we still need the value contents
2508 value_incref (value
);
2509 free_values
.free_to_mark ();
2510 cleanup
= make_cleanup_value_free (value
);
2512 retval
= allocate_value (subobj_type
);
2514 /* The given offset is relative to the actual object. */
2515 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2516 subobj_byte_offset
+= n
- max
;
2518 memcpy (value_contents_raw (retval
),
2519 value_contents_all (value
) + subobj_byte_offset
, len
);
2521 do_cleanups (cleanup
);
2525 case DWARF_VALUE_LITERAL
:
2528 size_t n
= TYPE_LENGTH (subobj_type
);
2530 if (subobj_byte_offset
+ n
> ctx
.len
)
2531 invalid_synthetic_pointer ();
2533 free_values
.free_to_mark ();
2534 retval
= allocate_value (subobj_type
);
2535 contents
= value_contents_raw (retval
);
2536 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2540 case DWARF_VALUE_OPTIMIZED_OUT
:
2541 free_values
.free_to_mark ();
2542 retval
= allocate_optimized_out_value (subobj_type
);
2545 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2546 operation by execute_stack_op. */
2547 case DWARF_VALUE_IMPLICIT_POINTER
:
2548 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2549 it can only be encountered when making a piece. */
2551 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2555 set_value_initialized (retval
, ctx
.initialized
);
2560 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2561 passes 0 as the byte_offset. */
2564 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2565 const gdb_byte
*data
, size_t size
,
2566 struct dwarf2_per_cu_data
*per_cu
)
2568 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2572 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2573 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2574 frame in which the expression is evaluated. ADDR is a context (location of
2575 a variable) and might be needed to evaluate the location expression.
2576 Returns 1 on success, 0 otherwise. */
2579 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2580 struct frame_info
*frame
,
2584 struct objfile
*objfile
;
2586 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2589 dwarf_evaluate_loc_desc ctx
;
2592 ctx
.per_cu
= dlbaton
->per_cu
;
2593 ctx
.obj_address
= addr
;
2595 objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2597 ctx
.gdbarch
= get_objfile_arch (objfile
);
2598 ctx
.addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2599 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (dlbaton
->per_cu
);
2600 ctx
.offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2602 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2604 switch (ctx
.location
)
2606 case DWARF_VALUE_REGISTER
:
2607 case DWARF_VALUE_MEMORY
:
2608 case DWARF_VALUE_STACK
:
2609 *valp
= ctx
.fetch_address (0);
2610 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2611 *valp
= ctx
.read_addr_from_reg (*valp
);
2613 case DWARF_VALUE_LITERAL
:
2614 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2615 gdbarch_byte_order (ctx
.gdbarch
));
2617 /* Unsupported dwarf values. */
2618 case DWARF_VALUE_OPTIMIZED_OUT
:
2619 case DWARF_VALUE_IMPLICIT_POINTER
:
2626 /* See dwarf2loc.h. */
2629 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2630 struct frame_info
*frame
,
2631 struct property_addr_info
*addr_stack
,
2637 if (frame
== NULL
&& has_stack_frames ())
2638 frame
= get_selected_frame (NULL
);
2644 const struct dwarf2_property_baton
*baton
2645 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2647 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
,
2648 addr_stack
? addr_stack
->addr
: 0,
2651 if (baton
->referenced_type
)
2653 struct value
*val
= value_at (baton
->referenced_type
, *value
);
2655 *value
= value_as_address (val
);
2664 struct dwarf2_property_baton
*baton
2665 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2666 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2667 const gdb_byte
*data
;
2671 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2674 val
= dwarf2_evaluate_loc_desc (baton
->referenced_type
, frame
, data
,
2675 size
, baton
->loclist
.per_cu
);
2676 if (!value_optimized_out (val
))
2678 *value
= value_as_address (val
);
2686 *value
= prop
->data
.const_val
;
2689 case PROP_ADDR_OFFSET
:
2691 struct dwarf2_property_baton
*baton
2692 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2693 struct property_addr_info
*pinfo
;
2696 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2697 if (pinfo
->type
== baton
->referenced_type
)
2700 error (_("cannot find reference address for offset property"));
2701 if (pinfo
->valaddr
!= NULL
)
2702 val
= value_from_contents
2703 (baton
->offset_info
.type
,
2704 pinfo
->valaddr
+ baton
->offset_info
.offset
);
2706 val
= value_at (baton
->offset_info
.type
,
2707 pinfo
->addr
+ baton
->offset_info
.offset
);
2708 *value
= value_as_address (val
);
2716 /* See dwarf2loc.h. */
2719 dwarf2_compile_property_to_c (string_file
&stream
,
2720 const char *result_name
,
2721 struct gdbarch
*gdbarch
,
2722 unsigned char *registers_used
,
2723 const struct dynamic_prop
*prop
,
2727 struct dwarf2_property_baton
*baton
2728 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2729 const gdb_byte
*data
;
2731 struct dwarf2_per_cu_data
*per_cu
;
2733 if (prop
->kind
== PROP_LOCEXPR
)
2735 data
= baton
->locexpr
.data
;
2736 size
= baton
->locexpr
.size
;
2737 per_cu
= baton
->locexpr
.per_cu
;
2741 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2743 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2744 per_cu
= baton
->loclist
.per_cu
;
2747 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2748 gdbarch
, registers_used
,
2749 dwarf2_per_cu_addr_size (per_cu
),
2750 data
, data
+ size
, per_cu
);
2754 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2756 class symbol_needs_eval_context
: public dwarf_expr_context
2760 enum symbol_needs_kind needs
;
2761 struct dwarf2_per_cu_data
*per_cu
;
2763 /* Reads from registers do require a frame. */
2764 CORE_ADDR
read_addr_from_reg (int regnum
) OVERRIDE
2766 needs
= SYMBOL_NEEDS_FRAME
;
2770 /* "get_reg_value" callback: Reads from registers do require a
2773 struct value
*get_reg_value (struct type
*type
, int regnum
) OVERRIDE
2775 needs
= SYMBOL_NEEDS_FRAME
;
2776 return value_zero (type
, not_lval
);
2779 /* Reads from memory do not require a frame. */
2780 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) OVERRIDE
2782 memset (buf
, 0, len
);
2785 /* Frame-relative accesses do require a frame. */
2786 void get_frame_base (const gdb_byte
**start
, size_t *length
) OVERRIDE
2788 static gdb_byte lit0
= DW_OP_lit0
;
2793 needs
= SYMBOL_NEEDS_FRAME
;
2796 /* CFA accesses require a frame. */
2797 CORE_ADDR
get_frame_cfa () OVERRIDE
2799 needs
= SYMBOL_NEEDS_FRAME
;
2803 CORE_ADDR
get_frame_pc () OVERRIDE
2805 needs
= SYMBOL_NEEDS_FRAME
;
2809 /* Thread-local accesses require registers, but not a frame. */
2810 CORE_ADDR
get_tls_address (CORE_ADDR offset
) OVERRIDE
2812 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2813 needs
= SYMBOL_NEEDS_REGISTERS
;
2817 /* Helper interface of per_cu_dwarf_call for
2818 dwarf2_loc_desc_get_symbol_read_needs. */
2820 void dwarf_call (cu_offset die_offset
) OVERRIDE
2822 per_cu_dwarf_call (this, die_offset
, per_cu
);
2825 /* DW_OP_entry_value accesses require a caller, therefore a
2828 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2829 union call_site_parameter_u kind_u
,
2830 int deref_size
) OVERRIDE
2832 needs
= SYMBOL_NEEDS_FRAME
;
2834 /* The expression may require some stub values on DWARF stack. */
2835 push_address (0, 0);
2838 /* DW_OP_GNU_addr_index doesn't require a frame. */
2840 CORE_ADDR
get_addr_index (unsigned int index
) OVERRIDE
2842 /* Nothing to do. */
2846 /* DW_OP_push_object_address has a frame already passed through. */
2848 CORE_ADDR
get_object_address () OVERRIDE
2850 /* Nothing to do. */
2855 /* Compute the correct symbol_needs_kind value for the location
2856 expression at DATA (length SIZE). */
2858 static enum symbol_needs_kind
2859 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2860 struct dwarf2_per_cu_data
*per_cu
)
2863 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2865 scoped_value_mark free_values
;
2867 symbol_needs_eval_context ctx
;
2869 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2870 ctx
.per_cu
= per_cu
;
2871 ctx
.gdbarch
= get_objfile_arch (objfile
);
2872 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2873 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2874 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2876 ctx
.eval (data
, size
);
2878 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2880 if (ctx
.num_pieces
> 0)
2884 /* If the location has several pieces, and any of them are in
2885 registers, then we will need a frame to fetch them from. */
2886 for (i
= 0; i
< ctx
.num_pieces
; i
++)
2887 if (ctx
.pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2892 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2896 /* A helper function that throws an unimplemented error mentioning a
2897 given DWARF operator. */
2900 unimplemented (unsigned int op
)
2902 const char *name
= get_DW_OP_name (op
);
2905 error (_("DWARF operator %s cannot be translated to an agent expression"),
2908 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2909 "to an agent expression"),
2915 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2916 can issue a complaint, which is better than having every target's
2917 implementation of dwarf2_reg_to_regnum do it. */
2920 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2922 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2926 complaint (&symfile_complaints
,
2927 _("bad DWARF register number %d"), dwarf_reg
);
2932 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2933 Throw an error because DWARF_REG is bad. */
2936 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2938 /* Still want to print -1 as "-1".
2939 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2940 but that's overkill for now. */
2941 if ((int) dwarf_reg
== dwarf_reg
)
2942 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2943 error (_("Unable to access DWARF register number %s"),
2944 pulongest (dwarf_reg
));
2947 /* See dwarf2loc.h. */
2950 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2954 if (dwarf_reg
> INT_MAX
)
2955 throw_bad_regnum_error (dwarf_reg
);
2956 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2957 bad, but that's ok. */
2958 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2960 throw_bad_regnum_error (dwarf_reg
);
2964 /* A helper function that emits an access to memory. ARCH is the
2965 target architecture. EXPR is the expression which we are building.
2966 NBITS is the number of bits we want to read. This emits the
2967 opcodes needed to read the memory and then extract the desired
2971 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2973 ULONGEST nbytes
= (nbits
+ 7) / 8;
2975 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2978 ax_trace_quick (expr
, nbytes
);
2981 ax_simple (expr
, aop_ref8
);
2982 else if (nbits
<= 16)
2983 ax_simple (expr
, aop_ref16
);
2984 else if (nbits
<= 32)
2985 ax_simple (expr
, aop_ref32
);
2987 ax_simple (expr
, aop_ref64
);
2989 /* If we read exactly the number of bytes we wanted, we're done. */
2990 if (8 * nbytes
== nbits
)
2993 if (gdbarch_bits_big_endian (arch
))
2995 /* On a bits-big-endian machine, we want the high-order
2997 ax_const_l (expr
, 8 * nbytes
- nbits
);
2998 ax_simple (expr
, aop_rsh_unsigned
);
3002 /* On a bits-little-endian box, we want the low-order NBITS. */
3003 ax_zero_ext (expr
, nbits
);
3007 /* A helper function to return the frame's PC. */
3010 get_ax_pc (void *baton
)
3012 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
3017 /* Compile a DWARF location expression to an agent expression.
3019 EXPR is the agent expression we are building.
3020 LOC is the agent value we modify.
3021 ARCH is the architecture.
3022 ADDR_SIZE is the size of addresses, in bytes.
3023 OP_PTR is the start of the location expression.
3024 OP_END is one past the last byte of the location expression.
3026 This will throw an exception for various kinds of errors -- for
3027 example, if the expression cannot be compiled, or if the expression
3031 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3032 struct gdbarch
*arch
, unsigned int addr_size
,
3033 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
3034 struct dwarf2_per_cu_data
*per_cu
)
3037 std::vector
<int> dw_labels
, patches
;
3038 const gdb_byte
* const base
= op_ptr
;
3039 const gdb_byte
*previous_piece
= op_ptr
;
3040 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3041 ULONGEST bits_collected
= 0;
3042 unsigned int addr_size_bits
= 8 * addr_size
;
3043 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
3045 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3047 /* By default we are making an address. */
3048 loc
->kind
= axs_lvalue_memory
;
3050 while (op_ptr
< op_end
)
3052 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3053 uint64_t uoffset
, reg
;
3057 offsets
[op_ptr
- base
] = expr
->len
;
3060 /* Our basic approach to code generation is to map DWARF
3061 operations directly to AX operations. However, there are
3064 First, DWARF works on address-sized units, but AX always uses
3065 LONGEST. For most operations we simply ignore this
3066 difference; instead we generate sign extensions as needed
3067 before division and comparison operations. It would be nice
3068 to omit the sign extensions, but there is no way to determine
3069 the size of the target's LONGEST. (This code uses the size
3070 of the host LONGEST in some cases -- that is a bug but it is
3073 Second, some DWARF operations cannot be translated to AX.
3074 For these we simply fail. See
3075 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3110 ax_const_l (expr
, op
- DW_OP_lit0
);
3114 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3115 op_ptr
+= addr_size
;
3116 /* Some versions of GCC emit DW_OP_addr before
3117 DW_OP_GNU_push_tls_address. In this case the value is an
3118 index, not an address. We don't support things like
3119 branching between the address and the TLS op. */
3120 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3121 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
3122 ax_const_l (expr
, uoffset
);
3126 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3130 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3134 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3138 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3142 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3146 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3150 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3154 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3158 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3159 ax_const_l (expr
, uoffset
);
3162 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3163 ax_const_l (expr
, offset
);
3198 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3199 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3200 loc
->kind
= axs_lvalue_register
;
3204 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3205 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3206 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3207 loc
->kind
= axs_lvalue_register
;
3210 case DW_OP_implicit_value
:
3214 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3215 if (op_ptr
+ len
> op_end
)
3216 error (_("DW_OP_implicit_value: too few bytes available."));
3217 if (len
> sizeof (ULONGEST
))
3218 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3221 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3224 dwarf_expr_require_composition (op_ptr
, op_end
,
3225 "DW_OP_implicit_value");
3227 loc
->kind
= axs_rvalue
;
3231 case DW_OP_stack_value
:
3232 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3233 loc
->kind
= axs_rvalue
;
3268 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3269 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3273 ax_const_l (expr
, offset
);
3274 ax_simple (expr
, aop_add
);
3279 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3280 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3281 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3285 ax_const_l (expr
, offset
);
3286 ax_simple (expr
, aop_add
);
3292 const gdb_byte
*datastart
;
3294 const struct block
*b
;
3295 struct symbol
*framefunc
;
3297 b
= block_for_pc (expr
->scope
);
3300 error (_("No block found for address"));
3302 framefunc
= block_linkage_function (b
);
3305 error (_("No function found for block"));
3307 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3308 &datastart
, &datalen
);
3310 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3311 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
3312 datastart
+ datalen
, per_cu
);
3313 if (loc
->kind
== axs_lvalue_register
)
3314 require_rvalue (expr
, loc
);
3318 ax_const_l (expr
, offset
);
3319 ax_simple (expr
, aop_add
);
3322 loc
->kind
= axs_lvalue_memory
;
3327 ax_simple (expr
, aop_dup
);
3331 ax_simple (expr
, aop_pop
);
3336 ax_pick (expr
, offset
);
3340 ax_simple (expr
, aop_swap
);
3348 ax_simple (expr
, aop_rot
);
3352 case DW_OP_deref_size
:
3356 if (op
== DW_OP_deref_size
)
3361 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3362 error (_("Unsupported size %d in %s"),
3363 size
, get_DW_OP_name (op
));
3364 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3369 /* Sign extend the operand. */
3370 ax_ext (expr
, addr_size_bits
);
3371 ax_simple (expr
, aop_dup
);
3372 ax_const_l (expr
, 0);
3373 ax_simple (expr
, aop_less_signed
);
3374 ax_simple (expr
, aop_log_not
);
3375 i
= ax_goto (expr
, aop_if_goto
);
3376 /* We have to emit 0 - X. */
3377 ax_const_l (expr
, 0);
3378 ax_simple (expr
, aop_swap
);
3379 ax_simple (expr
, aop_sub
);
3380 ax_label (expr
, i
, expr
->len
);
3384 /* No need to sign extend here. */
3385 ax_const_l (expr
, 0);
3386 ax_simple (expr
, aop_swap
);
3387 ax_simple (expr
, aop_sub
);
3391 /* Sign extend the operand. */
3392 ax_ext (expr
, addr_size_bits
);
3393 ax_simple (expr
, aop_bit_not
);
3396 case DW_OP_plus_uconst
:
3397 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3398 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3399 but we micro-optimize anyhow. */
3402 ax_const_l (expr
, reg
);
3403 ax_simple (expr
, aop_add
);
3408 ax_simple (expr
, aop_bit_and
);
3412 /* Sign extend the operands. */
3413 ax_ext (expr
, addr_size_bits
);
3414 ax_simple (expr
, aop_swap
);
3415 ax_ext (expr
, addr_size_bits
);
3416 ax_simple (expr
, aop_swap
);
3417 ax_simple (expr
, aop_div_signed
);
3421 ax_simple (expr
, aop_sub
);
3425 ax_simple (expr
, aop_rem_unsigned
);
3429 ax_simple (expr
, aop_mul
);
3433 ax_simple (expr
, aop_bit_or
);
3437 ax_simple (expr
, aop_add
);
3441 ax_simple (expr
, aop_lsh
);
3445 ax_simple (expr
, aop_rsh_unsigned
);
3449 ax_simple (expr
, aop_rsh_signed
);
3453 ax_simple (expr
, aop_bit_xor
);
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 /* Note no swap here: A <= B is !(B < A). */
3462 ax_simple (expr
, aop_less_signed
);
3463 ax_simple (expr
, aop_log_not
);
3467 /* Sign extend the operands. */
3468 ax_ext (expr
, addr_size_bits
);
3469 ax_simple (expr
, aop_swap
);
3470 ax_ext (expr
, addr_size_bits
);
3471 ax_simple (expr
, aop_swap
);
3472 /* A >= B is !(A < B). */
3473 ax_simple (expr
, aop_less_signed
);
3474 ax_simple (expr
, aop_log_not
);
3478 /* Sign extend the operands. */
3479 ax_ext (expr
, addr_size_bits
);
3480 ax_simple (expr
, aop_swap
);
3481 ax_ext (expr
, addr_size_bits
);
3482 /* No need for a second swap here. */
3483 ax_simple (expr
, aop_equal
);
3487 /* Sign extend the operands. */
3488 ax_ext (expr
, addr_size_bits
);
3489 ax_simple (expr
, aop_swap
);
3490 ax_ext (expr
, addr_size_bits
);
3491 ax_simple (expr
, aop_swap
);
3492 ax_simple (expr
, aop_less_signed
);
3496 /* Sign extend the operands. */
3497 ax_ext (expr
, addr_size_bits
);
3498 ax_simple (expr
, aop_swap
);
3499 ax_ext (expr
, addr_size_bits
);
3500 /* Note no swap here: A > B is B < A. */
3501 ax_simple (expr
, aop_less_signed
);
3505 /* Sign extend the operands. */
3506 ax_ext (expr
, addr_size_bits
);
3507 ax_simple (expr
, aop_swap
);
3508 ax_ext (expr
, addr_size_bits
);
3509 /* No need for a swap here. */
3510 ax_simple (expr
, aop_equal
);
3511 ax_simple (expr
, aop_log_not
);
3514 case DW_OP_call_frame_cfa
:
3517 CORE_ADDR text_offset
;
3519 const gdb_byte
*cfa_start
, *cfa_end
;
3521 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3523 &text_offset
, &cfa_start
, &cfa_end
))
3526 ax_reg (expr
, regnum
);
3529 ax_const_l (expr
, off
);
3530 ax_simple (expr
, aop_add
);
3535 /* Another expression. */
3536 ax_const_l (expr
, text_offset
);
3537 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3538 cfa_start
, cfa_end
, per_cu
);
3541 loc
->kind
= axs_lvalue_memory
;
3545 case DW_OP_GNU_push_tls_address
:
3546 case DW_OP_form_tls_address
:
3550 case DW_OP_push_object_address
:
3555 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3557 i
= ax_goto (expr
, aop_goto
);
3558 dw_labels
.push_back (op_ptr
+ offset
- base
);
3559 patches
.push_back (i
);
3563 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3565 /* Zero extend the operand. */
3566 ax_zero_ext (expr
, addr_size_bits
);
3567 i
= ax_goto (expr
, aop_if_goto
);
3568 dw_labels
.push_back (op_ptr
+ offset
- base
);
3569 patches
.push_back (i
);
3576 case DW_OP_bit_piece
:
3578 uint64_t size
, offset
;
3580 if (op_ptr
- 1 == previous_piece
)
3581 error (_("Cannot translate empty pieces to agent expressions"));
3582 previous_piece
= op_ptr
- 1;
3584 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3585 if (op
== DW_OP_piece
)
3591 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3593 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3594 error (_("Expression pieces exceed word size"));
3596 /* Access the bits. */
3599 case axs_lvalue_register
:
3600 ax_reg (expr
, loc
->u
.reg
);
3603 case axs_lvalue_memory
:
3604 /* Offset the pointer, if needed. */
3607 ax_const_l (expr
, offset
/ 8);
3608 ax_simple (expr
, aop_add
);
3611 access_memory (arch
, expr
, size
);
3615 /* For a bits-big-endian target, shift up what we already
3616 have. For a bits-little-endian target, shift up the
3617 new data. Note that there is a potential bug here if
3618 the DWARF expression leaves multiple values on the
3620 if (bits_collected
> 0)
3622 if (bits_big_endian
)
3624 ax_simple (expr
, aop_swap
);
3625 ax_const_l (expr
, size
);
3626 ax_simple (expr
, aop_lsh
);
3627 /* We don't need a second swap here, because
3628 aop_bit_or is symmetric. */
3632 ax_const_l (expr
, size
);
3633 ax_simple (expr
, aop_lsh
);
3635 ax_simple (expr
, aop_bit_or
);
3638 bits_collected
+= size
;
3639 loc
->kind
= axs_rvalue
;
3643 case DW_OP_GNU_uninit
:
3649 struct dwarf2_locexpr_baton block
;
3650 int size
= (op
== DW_OP_call2
? 2 : 4);
3652 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3655 cu_offset offset
= (cu_offset
) uoffset
;
3656 block
= dwarf2_fetch_die_loc_cu_off (offset
, per_cu
,
3659 /* DW_OP_call_ref is currently not supported. */
3660 gdb_assert (block
.per_cu
== per_cu
);
3662 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3663 block
.data
, block
.data
+ block
.size
,
3668 case DW_OP_call_ref
:
3676 /* Patch all the branches we emitted. */
3677 for (i
= 0; i
< patches
.size (); ++i
)
3679 int targ
= offsets
[dw_labels
[i
]];
3681 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3682 ax_label (expr
, patches
[i
], targ
);
3687 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3688 evaluator to calculate the location. */
3689 static struct value
*
3690 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3692 struct dwarf2_locexpr_baton
*dlbaton
3693 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3696 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3697 dlbaton
->size
, dlbaton
->per_cu
);
3702 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3703 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3706 static struct value
*
3707 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3709 struct dwarf2_locexpr_baton
*dlbaton
3710 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3712 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3716 /* Implementation of get_symbol_read_needs from
3717 symbol_computed_ops. */
3719 static enum symbol_needs_kind
3720 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3722 struct dwarf2_locexpr_baton
*dlbaton
3723 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3725 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3729 /* Return true if DATA points to the end of a piece. END is one past
3730 the last byte in the expression. */
3733 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3735 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3738 /* Helper for locexpr_describe_location_piece that finds the name of a
3742 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3746 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3747 We'd rather print *something* here than throw an error. */
3748 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3749 /* gdbarch_register_name may just return "", return something more
3750 descriptive for bad register numbers. */
3753 /* The text is output as "$bad_register_number".
3754 That is why we use the underscores. */
3755 return _("bad_register_number");
3757 return gdbarch_register_name (gdbarch
, regnum
);
3760 /* Nicely describe a single piece of a location, returning an updated
3761 position in the bytecode sequence. This function cannot recognize
3762 all locations; if a location is not recognized, it simply returns
3763 DATA. If there is an error during reading, e.g. we run off the end
3764 of the buffer, an error is thrown. */
3766 static const gdb_byte
*
3767 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3768 CORE_ADDR addr
, struct objfile
*objfile
,
3769 struct dwarf2_per_cu_data
*per_cu
,
3770 const gdb_byte
*data
, const gdb_byte
*end
,
3771 unsigned int addr_size
)
3773 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3776 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3778 fprintf_filtered (stream
, _("a variable in $%s"),
3779 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3782 else if (data
[0] == DW_OP_regx
)
3786 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3787 fprintf_filtered (stream
, _("a variable in $%s"),
3788 locexpr_regname (gdbarch
, reg
));
3790 else if (data
[0] == DW_OP_fbreg
)
3792 const struct block
*b
;
3793 struct symbol
*framefunc
;
3795 int64_t frame_offset
;
3796 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3798 int64_t base_offset
= 0;
3800 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3801 if (!piece_end_p (new_data
, end
))
3805 b
= block_for_pc (addr
);
3808 error (_("No block found for address for symbol \"%s\"."),
3809 SYMBOL_PRINT_NAME (symbol
));
3811 framefunc
= block_linkage_function (b
);
3814 error (_("No function found for block for symbol \"%s\"."),
3815 SYMBOL_PRINT_NAME (symbol
));
3817 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3819 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3821 const gdb_byte
*buf_end
;
3823 frame_reg
= base_data
[0] - DW_OP_breg0
;
3824 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3826 if (buf_end
!= base_data
+ base_size
)
3827 error (_("Unexpected opcode after "
3828 "DW_OP_breg%u for symbol \"%s\"."),
3829 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3831 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3833 /* The frame base is just the register, with no offset. */
3834 frame_reg
= base_data
[0] - DW_OP_reg0
;
3839 /* We don't know what to do with the frame base expression,
3840 so we can't trace this variable; give up. */
3844 fprintf_filtered (stream
,
3845 _("a variable at frame base reg $%s offset %s+%s"),
3846 locexpr_regname (gdbarch
, frame_reg
),
3847 plongest (base_offset
), plongest (frame_offset
));
3849 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3850 && piece_end_p (data
, end
))
3854 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3856 fprintf_filtered (stream
,
3857 _("a variable at offset %s from base reg $%s"),
3859 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3862 /* The location expression for a TLS variable looks like this (on a
3865 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3866 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3868 0x3 is the encoding for DW_OP_addr, which has an operand as long
3869 as the size of an address on the target machine (here is 8
3870 bytes). Note that more recent version of GCC emit DW_OP_const4u
3871 or DW_OP_const8u, depending on address size, rather than
3872 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3873 The operand represents the offset at which the variable is within
3874 the thread local storage. */
3876 else if (data
+ 1 + addr_size
< end
3877 && (data
[0] == DW_OP_addr
3878 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3879 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3880 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3881 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3882 && piece_end_p (data
+ 2 + addr_size
, end
))
3885 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3886 gdbarch_byte_order (gdbarch
));
3888 fprintf_filtered (stream
,
3889 _("a thread-local variable at offset 0x%s "
3890 "in the thread-local storage for `%s'"),
3891 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3893 data
+= 1 + addr_size
+ 1;
3896 /* With -gsplit-dwarf a TLS variable can also look like this:
3897 DW_AT_location : 3 byte block: fc 4 e0
3898 (DW_OP_GNU_const_index: 4;
3899 DW_OP_GNU_push_tls_address) */
3900 else if (data
+ 3 <= end
3901 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3902 && data
[0] == DW_OP_GNU_const_index
3904 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3905 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3906 && piece_end_p (data
+ 2 + leb128_size
, end
))
3910 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3911 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3912 fprintf_filtered (stream
,
3913 _("a thread-local variable at offset 0x%s "
3914 "in the thread-local storage for `%s'"),
3915 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3919 else if (data
[0] >= DW_OP_lit0
3920 && data
[0] <= DW_OP_lit31
3922 && data
[1] == DW_OP_stack_value
)
3924 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3931 /* Disassemble an expression, stopping at the end of a piece or at the
3932 end of the expression. Returns a pointer to the next unread byte
3933 in the input expression. If ALL is nonzero, then this function
3934 will keep going until it reaches the end of the expression.
3935 If there is an error during reading, e.g. we run off the end
3936 of the buffer, an error is thrown. */
3938 static const gdb_byte
*
3939 disassemble_dwarf_expression (struct ui_file
*stream
,
3940 struct gdbarch
*arch
, unsigned int addr_size
,
3941 int offset_size
, const gdb_byte
*start
,
3942 const gdb_byte
*data
, const gdb_byte
*end
,
3943 int indent
, int all
,
3944 struct dwarf2_per_cu_data
*per_cu
)
3948 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3950 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3955 name
= get_DW_OP_name (op
);
3958 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3959 op
, (long) (data
- 1 - start
));
3960 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3961 (long) (data
- 1 - start
), name
);
3966 ul
= extract_unsigned_integer (data
, addr_size
,
3967 gdbarch_byte_order (arch
));
3969 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3973 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3975 fprintf_filtered (stream
, " %s", pulongest (ul
));
3978 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3980 fprintf_filtered (stream
, " %s", plongest (l
));
3983 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3985 fprintf_filtered (stream
, " %s", pulongest (ul
));
3988 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3990 fprintf_filtered (stream
, " %s", plongest (l
));
3993 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3995 fprintf_filtered (stream
, " %s", pulongest (ul
));
3998 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
4000 fprintf_filtered (stream
, " %s", plongest (l
));
4003 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
4005 fprintf_filtered (stream
, " %s", pulongest (ul
));
4008 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
4010 fprintf_filtered (stream
, " %s", plongest (l
));
4013 data
= safe_read_uleb128 (data
, end
, &ul
);
4014 fprintf_filtered (stream
, " %s", pulongest (ul
));
4017 data
= safe_read_sleb128 (data
, end
, &l
);
4018 fprintf_filtered (stream
, " %s", plongest (l
));
4053 fprintf_filtered (stream
, " [$%s]",
4054 locexpr_regname (arch
, op
- DW_OP_reg0
));
4058 data
= safe_read_uleb128 (data
, end
, &ul
);
4059 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4060 locexpr_regname (arch
, (int) ul
));
4063 case DW_OP_implicit_value
:
4064 data
= safe_read_uleb128 (data
, end
, &ul
);
4066 fprintf_filtered (stream
, " %s", pulongest (ul
));
4101 data
= safe_read_sleb128 (data
, end
, &l
);
4102 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4103 locexpr_regname (arch
, op
- DW_OP_breg0
));
4107 data
= safe_read_uleb128 (data
, end
, &ul
);
4108 data
= safe_read_sleb128 (data
, end
, &l
);
4109 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4111 locexpr_regname (arch
, (int) ul
),
4116 data
= safe_read_sleb128 (data
, end
, &l
);
4117 fprintf_filtered (stream
, " %s", plongest (l
));
4120 case DW_OP_xderef_size
:
4121 case DW_OP_deref_size
:
4123 fprintf_filtered (stream
, " %d", *data
);
4127 case DW_OP_plus_uconst
:
4128 data
= safe_read_uleb128 (data
, end
, &ul
);
4129 fprintf_filtered (stream
, " %s", pulongest (ul
));
4133 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4135 fprintf_filtered (stream
, " to %ld",
4136 (long) (data
+ l
- start
));
4140 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4142 fprintf_filtered (stream
, " %ld",
4143 (long) (data
+ l
- start
));
4147 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4149 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4153 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4155 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4158 case DW_OP_call_ref
:
4159 ul
= extract_unsigned_integer (data
, offset_size
,
4160 gdbarch_byte_order (arch
));
4161 data
+= offset_size
;
4162 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4166 data
= safe_read_uleb128 (data
, end
, &ul
);
4167 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4170 case DW_OP_bit_piece
:
4174 data
= safe_read_uleb128 (data
, end
, &ul
);
4175 data
= safe_read_uleb128 (data
, end
, &offset
);
4176 fprintf_filtered (stream
, " size %s offset %s (bits)",
4177 pulongest (ul
), pulongest (offset
));
4181 case DW_OP_implicit_pointer
:
4182 case DW_OP_GNU_implicit_pointer
:
4184 ul
= extract_unsigned_integer (data
, offset_size
,
4185 gdbarch_byte_order (arch
));
4186 data
+= offset_size
;
4188 data
= safe_read_sleb128 (data
, end
, &l
);
4190 fprintf_filtered (stream
, " DIE %s offset %s",
4191 phex_nz (ul
, offset_size
),
4196 case DW_OP_deref_type
:
4197 case DW_OP_GNU_deref_type
:
4199 int addr_size
= *data
++;
4202 data
= safe_read_uleb128 (data
, end
, &ul
);
4203 cu_offset offset
= (cu_offset
) ul
;
4204 type
= dwarf2_get_die_type (offset
, per_cu
);
4205 fprintf_filtered (stream
, "<");
4206 type_print (type
, "", stream
, -1);
4207 fprintf_filtered (stream
, " [0x%s]> %d",
4208 phex_nz (to_underlying (offset
), 0),
4213 case DW_OP_const_type
:
4214 case DW_OP_GNU_const_type
:
4218 data
= safe_read_uleb128 (data
, end
, &ul
);
4219 cu_offset type_die
= (cu_offset
) ul
;
4220 type
= dwarf2_get_die_type (type_die
, per_cu
);
4221 fprintf_filtered (stream
, "<");
4222 type_print (type
, "", stream
, -1);
4223 fprintf_filtered (stream
, " [0x%s]>",
4224 phex_nz (to_underlying (type_die
), 0));
4228 case DW_OP_regval_type
:
4229 case DW_OP_GNU_regval_type
:
4234 data
= safe_read_uleb128 (data
, end
, ®
);
4235 data
= safe_read_uleb128 (data
, end
, &ul
);
4236 cu_offset type_die
= (cu_offset
) ul
;
4238 type
= dwarf2_get_die_type (type_die
, per_cu
);
4239 fprintf_filtered (stream
, "<");
4240 type_print (type
, "", stream
, -1);
4241 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4242 phex_nz (to_underlying (type_die
), 0),
4243 locexpr_regname (arch
, reg
));
4248 case DW_OP_GNU_convert
:
4249 case DW_OP_reinterpret
:
4250 case DW_OP_GNU_reinterpret
:
4252 data
= safe_read_uleb128 (data
, end
, &ul
);
4253 cu_offset type_die
= (cu_offset
) ul
;
4255 if (to_underlying (type_die
) == 0)
4256 fprintf_filtered (stream
, "<0>");
4261 type
= dwarf2_get_die_type (type_die
, per_cu
);
4262 fprintf_filtered (stream
, "<");
4263 type_print (type
, "", stream
, -1);
4264 fprintf_filtered (stream
, " [0x%s]>",
4265 phex_nz (to_underlying (type_die
), 0));
4270 case DW_OP_entry_value
:
4271 case DW_OP_GNU_entry_value
:
4272 data
= safe_read_uleb128 (data
, end
, &ul
);
4273 fputc_filtered ('\n', stream
);
4274 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4275 start
, data
, data
+ ul
, indent
+ 2,
4280 case DW_OP_GNU_parameter_ref
:
4281 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4283 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4286 case DW_OP_GNU_addr_index
:
4287 data
= safe_read_uleb128 (data
, end
, &ul
);
4288 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4289 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4291 case DW_OP_GNU_const_index
:
4292 data
= safe_read_uleb128 (data
, end
, &ul
);
4293 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4294 fprintf_filtered (stream
, " %s", pulongest (ul
));
4298 fprintf_filtered (stream
, "\n");
4304 /* Describe a single location, which may in turn consist of multiple
4308 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4309 struct ui_file
*stream
,
4310 const gdb_byte
*data
, size_t size
,
4311 struct objfile
*objfile
, unsigned int addr_size
,
4312 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4314 const gdb_byte
*end
= data
+ size
;
4315 int first_piece
= 1, bad
= 0;
4319 const gdb_byte
*here
= data
;
4320 int disassemble
= 1;
4325 fprintf_filtered (stream
, _(", and "));
4327 if (!dwarf_always_disassemble
)
4329 data
= locexpr_describe_location_piece (symbol
, stream
,
4330 addr
, objfile
, per_cu
,
4331 data
, end
, addr_size
);
4332 /* If we printed anything, or if we have an empty piece,
4333 then don't disassemble. */
4335 || data
[0] == DW_OP_piece
4336 || data
[0] == DW_OP_bit_piece
)
4341 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4342 data
= disassemble_dwarf_expression (stream
,
4343 get_objfile_arch (objfile
),
4344 addr_size
, offset_size
, data
,
4346 dwarf_always_disassemble
,
4352 int empty
= data
== here
;
4355 fprintf_filtered (stream
, " ");
4356 if (data
[0] == DW_OP_piece
)
4360 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4363 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4366 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4369 else if (data
[0] == DW_OP_bit_piece
)
4371 uint64_t bits
, offset
;
4373 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4374 data
= safe_read_uleb128 (data
, end
, &offset
);
4377 fprintf_filtered (stream
,
4378 _("an empty %s-bit piece"),
4381 fprintf_filtered (stream
,
4382 _(" [%s-bit piece, offset %s bits]"),
4383 pulongest (bits
), pulongest (offset
));
4393 if (bad
|| data
> end
)
4394 error (_("Corrupted DWARF2 expression for \"%s\"."),
4395 SYMBOL_PRINT_NAME (symbol
));
4398 /* Print a natural-language description of SYMBOL to STREAM. This
4399 version is for a symbol with a single location. */
4402 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4403 struct ui_file
*stream
)
4405 struct dwarf2_locexpr_baton
*dlbaton
4406 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4407 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4408 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4409 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4411 locexpr_describe_location_1 (symbol
, addr
, stream
,
4412 dlbaton
->data
, dlbaton
->size
,
4413 objfile
, addr_size
, offset_size
,
4417 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4418 any necessary bytecode in AX. */
4421 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4422 struct agent_expr
*ax
, struct axs_value
*value
)
4424 struct dwarf2_locexpr_baton
*dlbaton
4425 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4426 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4428 if (dlbaton
->size
== 0)
4429 value
->optimized_out
= 1;
4431 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
4432 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4436 /* symbol_computed_ops 'generate_c_location' method. */
4439 locexpr_generate_c_location (struct symbol
*sym
, string_file
&stream
,
4440 struct gdbarch
*gdbarch
,
4441 unsigned char *registers_used
,
4442 CORE_ADDR pc
, const char *result_name
)
4444 struct dwarf2_locexpr_baton
*dlbaton
4445 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4446 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4448 if (dlbaton
->size
== 0)
4449 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4451 compile_dwarf_expr_to_c (stream
, result_name
,
4452 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4453 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4457 /* The set of location functions used with the DWARF-2 expression
4459 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4460 locexpr_read_variable
,
4461 locexpr_read_variable_at_entry
,
4462 locexpr_get_symbol_read_needs
,
4463 locexpr_describe_location
,
4464 0, /* location_has_loclist */
4465 locexpr_tracepoint_var_ref
,
4466 locexpr_generate_c_location
4470 /* Wrapper functions for location lists. These generally find
4471 the appropriate location expression and call something above. */
4473 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4474 evaluator to calculate the location. */
4475 static struct value
*
4476 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4478 struct dwarf2_loclist_baton
*dlbaton
4479 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4481 const gdb_byte
*data
;
4483 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4485 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4486 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4492 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4493 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4496 Function always returns non-NULL value, it may be marked optimized out if
4497 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4498 if it cannot resolve the parameter for any reason. */
4500 static struct value
*
4501 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4503 struct dwarf2_loclist_baton
*dlbaton
4504 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4505 const gdb_byte
*data
;
4509 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4510 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4512 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4514 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4516 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4519 /* Implementation of get_symbol_read_needs from
4520 symbol_computed_ops. */
4522 static enum symbol_needs_kind
4523 loclist_symbol_needs (struct symbol
*symbol
)
4525 /* If there's a location list, then assume we need to have a frame
4526 to choose the appropriate location expression. With tracking of
4527 global variables this is not necessarily true, but such tracking
4528 is disabled in GCC at the moment until we figure out how to
4531 return SYMBOL_NEEDS_FRAME
;
4534 /* Print a natural-language description of SYMBOL to STREAM. This
4535 version applies when there is a list of different locations, each
4536 with a specified address range. */
4539 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4540 struct ui_file
*stream
)
4542 struct dwarf2_loclist_baton
*dlbaton
4543 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4544 const gdb_byte
*loc_ptr
, *buf_end
;
4545 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4546 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4547 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4548 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4549 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4550 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4551 /* Adjust base_address for relocatable objects. */
4552 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4553 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4556 loc_ptr
= dlbaton
->data
;
4557 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4559 fprintf_filtered (stream
, _("multi-location:\n"));
4561 /* Iterate through locations until we run out. */
4564 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4566 enum debug_loc_kind kind
;
4567 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4569 if (dlbaton
->from_dwo
)
4570 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4571 loc_ptr
, buf_end
, &new_ptr
,
4572 &low
, &high
, byte_order
);
4574 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4576 byte_order
, addr_size
,
4581 case DEBUG_LOC_END_OF_LIST
:
4584 case DEBUG_LOC_BASE_ADDRESS
:
4585 base_address
= high
+ base_offset
;
4586 fprintf_filtered (stream
, _(" Base address %s"),
4587 paddress (gdbarch
, base_address
));
4589 case DEBUG_LOC_START_END
:
4590 case DEBUG_LOC_START_LENGTH
:
4592 case DEBUG_LOC_BUFFER_OVERFLOW
:
4593 case DEBUG_LOC_INVALID_ENTRY
:
4594 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4595 SYMBOL_PRINT_NAME (symbol
));
4597 gdb_assert_not_reached ("bad debug_loc_kind");
4600 /* Otherwise, a location expression entry. */
4601 low
+= base_address
;
4602 high
+= base_address
;
4604 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4605 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4607 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4610 /* (It would improve readability to print only the minimum
4611 necessary digits of the second number of the range.) */
4612 fprintf_filtered (stream
, _(" Range %s-%s: "),
4613 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4615 /* Now describe this particular location. */
4616 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4617 objfile
, addr_size
, offset_size
,
4620 fprintf_filtered (stream
, "\n");
4626 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4627 any necessary bytecode in AX. */
4629 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4630 struct agent_expr
*ax
, struct axs_value
*value
)
4632 struct dwarf2_loclist_baton
*dlbaton
4633 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4634 const gdb_byte
*data
;
4636 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4638 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4640 value
->optimized_out
= 1;
4642 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4646 /* symbol_computed_ops 'generate_c_location' method. */
4649 loclist_generate_c_location (struct symbol
*sym
, string_file
&stream
,
4650 struct gdbarch
*gdbarch
,
4651 unsigned char *registers_used
,
4652 CORE_ADDR pc
, const char *result_name
)
4654 struct dwarf2_loclist_baton
*dlbaton
4655 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4656 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4657 const gdb_byte
*data
;
4660 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4662 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4664 compile_dwarf_expr_to_c (stream
, result_name
,
4665 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4670 /* The set of location functions used with the DWARF-2 expression
4671 evaluator and location lists. */
4672 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4673 loclist_read_variable
,
4674 loclist_read_variable_at_entry
,
4675 loclist_symbol_needs
,
4676 loclist_describe_location
,
4677 1, /* location_has_loclist */
4678 loclist_tracepoint_var_ref
,
4679 loclist_generate_c_location
4682 /* Provide a prototype to silence -Wmissing-prototypes. */
4683 extern initialize_file_ftype _initialize_dwarf2loc
;
4686 _initialize_dwarf2loc (void)
4688 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4689 &entry_values_debug
,
4690 _("Set entry values and tail call frames "
4692 _("Show entry values and tail call frames "
4694 _("When non-zero, the process of determining "
4695 "parameter values from function entry point "
4696 "and tail call frames will be printed."),
4698 show_entry_values_debug
,
4699 &setdebuglist
, &showdebuglist
);
4702 register_self_test (selftests::copy_bitwise_tests
);