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"
46 #include "common/byte-vector.h"
48 extern int dwarf_always_disassemble
;
50 static struct value
*dwarf2_evaluate_loc_desc_full (struct type
*type
,
51 struct frame_info
*frame
,
54 struct dwarf2_per_cu_data
*per_cu
,
55 struct type
*subobj_type
,
56 LONGEST subobj_byte_offset
);
58 static struct call_site_parameter
*dwarf_expr_reg_to_entry_parameter
59 (struct frame_info
*frame
,
60 enum call_site_parameter_kind kind
,
61 union call_site_parameter_u kind_u
,
62 struct dwarf2_per_cu_data
**per_cu_return
);
64 /* Until these have formal names, we define these here.
65 ref: http://gcc.gnu.org/wiki/DebugFission
66 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
67 and is then followed by data specific to that entry. */
71 /* Indicates the end of the list of entries. */
72 DEBUG_LOC_END_OF_LIST
= 0,
74 /* This is followed by an unsigned LEB128 number that is an index into
75 .debug_addr and specifies the base address for all following entries. */
76 DEBUG_LOC_BASE_ADDRESS
= 1,
78 /* This is followed by two unsigned LEB128 numbers that are indices into
79 .debug_addr and specify the beginning and ending addresses, and then
80 a normal location expression as in .debug_loc. */
81 DEBUG_LOC_START_END
= 2,
83 /* This is followed by an unsigned LEB128 number that is an index into
84 .debug_addr and specifies the beginning address, and a 4 byte unsigned
85 number that specifies the length, and then a normal location expression
87 DEBUG_LOC_START_LENGTH
= 3,
89 /* An internal value indicating there is insufficient data. */
90 DEBUG_LOC_BUFFER_OVERFLOW
= -1,
92 /* An internal value indicating an invalid kind of entry was found. */
93 DEBUG_LOC_INVALID_ENTRY
= -2
96 /* Helper function which throws an error if a synthetic pointer is
100 invalid_synthetic_pointer (void)
102 error (_("access outside bounds of object "
103 "referenced via synthetic pointer"));
106 /* Decode the addresses in a non-dwo .debug_loc entry.
107 A pointer to the next byte to examine is returned in *NEW_PTR.
108 The encoded low,high addresses are return in *LOW,*HIGH.
109 The result indicates the kind of entry found. */
111 static enum debug_loc_kind
112 decode_debug_loc_addresses (const gdb_byte
*loc_ptr
, const gdb_byte
*buf_end
,
113 const gdb_byte
**new_ptr
,
114 CORE_ADDR
*low
, CORE_ADDR
*high
,
115 enum bfd_endian byte_order
,
116 unsigned int addr_size
,
119 CORE_ADDR base_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
121 if (buf_end
- loc_ptr
< 2 * addr_size
)
122 return DEBUG_LOC_BUFFER_OVERFLOW
;
125 *low
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
127 *low
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
128 loc_ptr
+= addr_size
;
131 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
133 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
134 loc_ptr
+= addr_size
;
138 /* A base-address-selection entry. */
139 if ((*low
& base_mask
) == base_mask
)
140 return DEBUG_LOC_BASE_ADDRESS
;
142 /* An end-of-list entry. */
143 if (*low
== 0 && *high
== 0)
144 return DEBUG_LOC_END_OF_LIST
;
146 return DEBUG_LOC_START_END
;
149 /* Decode the addresses in .debug_loclists entry.
150 A pointer to the next byte to examine is returned in *NEW_PTR.
151 The encoded low,high addresses are return in *LOW,*HIGH.
152 The result indicates the kind of entry found. */
154 static enum debug_loc_kind
155 decode_debug_loclists_addresses (struct dwarf2_per_cu_data
*per_cu
,
156 const gdb_byte
*loc_ptr
,
157 const gdb_byte
*buf_end
,
158 const gdb_byte
**new_ptr
,
159 CORE_ADDR
*low
, CORE_ADDR
*high
,
160 enum bfd_endian byte_order
,
161 unsigned int addr_size
,
166 if (loc_ptr
== buf_end
)
167 return DEBUG_LOC_BUFFER_OVERFLOW
;
171 case DW_LLE_end_of_list
:
173 return DEBUG_LOC_END_OF_LIST
;
174 case DW_LLE_base_address
:
175 if (loc_ptr
+ addr_size
> buf_end
)
176 return DEBUG_LOC_BUFFER_OVERFLOW
;
178 *high
= extract_signed_integer (loc_ptr
, addr_size
, byte_order
);
180 *high
= extract_unsigned_integer (loc_ptr
, addr_size
, byte_order
);
181 loc_ptr
+= addr_size
;
183 return DEBUG_LOC_BASE_ADDRESS
;
184 case DW_LLE_offset_pair
:
185 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
187 return DEBUG_LOC_BUFFER_OVERFLOW
;
189 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &u64
);
191 return DEBUG_LOC_BUFFER_OVERFLOW
;
194 return DEBUG_LOC_START_END
;
196 return DEBUG_LOC_INVALID_ENTRY
;
200 /* Decode the addresses in .debug_loc.dwo entry.
201 A pointer to the next byte to examine is returned in *NEW_PTR.
202 The encoded low,high addresses are return in *LOW,*HIGH.
203 The result indicates the kind of entry found. */
205 static enum debug_loc_kind
206 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data
*per_cu
,
207 const gdb_byte
*loc_ptr
,
208 const gdb_byte
*buf_end
,
209 const gdb_byte
**new_ptr
,
210 CORE_ADDR
*low
, CORE_ADDR
*high
,
211 enum bfd_endian byte_order
)
213 uint64_t low_index
, high_index
;
215 if (loc_ptr
== buf_end
)
216 return DEBUG_LOC_BUFFER_OVERFLOW
;
220 case DW_LLE_GNU_end_of_list_entry
:
222 return DEBUG_LOC_END_OF_LIST
;
223 case DW_LLE_GNU_base_address_selection_entry
:
225 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
227 return DEBUG_LOC_BUFFER_OVERFLOW
;
228 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
230 return DEBUG_LOC_BASE_ADDRESS
;
231 case DW_LLE_GNU_start_end_entry
:
232 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
234 return DEBUG_LOC_BUFFER_OVERFLOW
;
235 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
236 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &high_index
);
238 return DEBUG_LOC_BUFFER_OVERFLOW
;
239 *high
= dwarf2_read_addr_index (per_cu
, high_index
);
241 return DEBUG_LOC_START_END
;
242 case DW_LLE_GNU_start_length_entry
:
243 loc_ptr
= gdb_read_uleb128 (loc_ptr
, buf_end
, &low_index
);
245 return DEBUG_LOC_BUFFER_OVERFLOW
;
246 *low
= dwarf2_read_addr_index (per_cu
, low_index
);
247 if (loc_ptr
+ 4 > buf_end
)
248 return DEBUG_LOC_BUFFER_OVERFLOW
;
250 *high
+= extract_unsigned_integer (loc_ptr
, 4, byte_order
);
251 *new_ptr
= loc_ptr
+ 4;
252 return DEBUG_LOC_START_LENGTH
;
254 return DEBUG_LOC_INVALID_ENTRY
;
258 /* A function for dealing with location lists. Given a
259 symbol baton (BATON) and a pc value (PC), find the appropriate
260 location expression, set *LOCEXPR_LENGTH, and return a pointer
261 to the beginning of the expression. Returns NULL on failure.
263 For now, only return the first matching location expression; there
264 can be more than one in the list. */
267 dwarf2_find_location_expression (struct dwarf2_loclist_baton
*baton
,
268 size_t *locexpr_length
, CORE_ADDR pc
)
270 struct objfile
*objfile
= dwarf2_per_cu_objfile (baton
->per_cu
);
271 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
272 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
273 unsigned int addr_size
= dwarf2_per_cu_addr_size (baton
->per_cu
);
274 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
275 /* Adjust base_address for relocatable objects. */
276 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (baton
->per_cu
);
277 CORE_ADDR base_address
= baton
->base_address
+ base_offset
;
278 const gdb_byte
*loc_ptr
, *buf_end
;
280 loc_ptr
= baton
->data
;
281 buf_end
= baton
->data
+ baton
->size
;
285 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
287 enum debug_loc_kind kind
;
288 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
291 kind
= decode_debug_loc_dwo_addresses (baton
->per_cu
,
292 loc_ptr
, buf_end
, &new_ptr
,
293 &low
, &high
, byte_order
);
294 else if (dwarf2_version (baton
->per_cu
) < 5)
295 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
297 byte_order
, addr_size
,
300 kind
= decode_debug_loclists_addresses (baton
->per_cu
,
301 loc_ptr
, buf_end
, &new_ptr
,
302 &low
, &high
, byte_order
,
303 addr_size
, signed_addr_p
);
308 case DEBUG_LOC_END_OF_LIST
:
311 case DEBUG_LOC_BASE_ADDRESS
:
312 base_address
= high
+ base_offset
;
314 case DEBUG_LOC_START_END
:
315 case DEBUG_LOC_START_LENGTH
:
317 case DEBUG_LOC_BUFFER_OVERFLOW
:
318 case DEBUG_LOC_INVALID_ENTRY
:
319 error (_("dwarf2_find_location_expression: "
320 "Corrupted DWARF expression."));
322 gdb_assert_not_reached ("bad debug_loc_kind");
325 /* Otherwise, a location expression entry.
326 If the entry is from a DWO, don't add base address: the entry is from
327 .debug_addr which already has the DWARF "base address". We still add
328 base_offset in case we're debugging a PIE executable. */
337 high
+= base_address
;
340 if (dwarf2_version (baton
->per_cu
) < 5)
342 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
347 unsigned int bytes_read
;
349 length
= read_unsigned_leb128 (NULL
, loc_ptr
, &bytes_read
);
350 loc_ptr
+= bytes_read
;
353 if (low
== high
&& pc
== low
)
355 /* This is entry PC record present only at entry point
356 of a function. Verify it is really the function entry point. */
358 const struct block
*pc_block
= block_for_pc (pc
);
359 struct symbol
*pc_func
= NULL
;
362 pc_func
= block_linkage_function (pc_block
);
364 if (pc_func
&& pc
== BLOCK_START (SYMBOL_BLOCK_VALUE (pc_func
)))
366 *locexpr_length
= length
;
371 if (pc
>= low
&& pc
< high
)
373 *locexpr_length
= length
;
381 /* This is the baton used when performing dwarf2 expression
383 struct dwarf_expr_baton
385 struct frame_info
*frame
;
386 struct dwarf2_per_cu_data
*per_cu
;
387 CORE_ADDR obj_address
;
390 /* Implement find_frame_base_location method for LOC_BLOCK functions using
391 DWARF expression for its DW_AT_frame_base. */
394 locexpr_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
395 const gdb_byte
**start
, size_t *length
)
397 struct dwarf2_locexpr_baton
*symbaton
398 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
400 *length
= symbaton
->size
;
401 *start
= symbaton
->data
;
404 /* Implement the struct symbol_block_ops::get_frame_base method for
405 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
408 locexpr_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
410 struct gdbarch
*gdbarch
;
412 struct dwarf2_locexpr_baton
*dlbaton
;
413 const gdb_byte
*start
;
415 struct value
*result
;
417 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
418 Thus, it's supposed to provide the find_frame_base_location method as
420 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
422 gdbarch
= get_frame_arch (frame
);
423 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
424 dlbaton
= (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
426 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
427 (framefunc
, get_frame_pc (frame
), &start
, &length
);
428 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
431 /* The DW_AT_frame_base attribute contains a location description which
432 computes the base address itself. However, the call to
433 dwarf2_evaluate_loc_desc returns a value representing a variable at
434 that address. The frame base address is thus this variable's
436 return value_address (result
);
439 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
440 function uses DWARF expression for its DW_AT_frame_base. */
442 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs
=
444 locexpr_find_frame_base_location
,
445 locexpr_get_frame_base
448 /* Implement find_frame_base_location method for LOC_BLOCK functions using
449 DWARF location list for its DW_AT_frame_base. */
452 loclist_find_frame_base_location (struct symbol
*framefunc
, CORE_ADDR pc
,
453 const gdb_byte
**start
, size_t *length
)
455 struct dwarf2_loclist_baton
*symbaton
456 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
458 *start
= dwarf2_find_location_expression (symbaton
, length
, pc
);
461 /* Implement the struct symbol_block_ops::get_frame_base method for
462 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
465 loclist_get_frame_base (struct symbol
*framefunc
, struct frame_info
*frame
)
467 struct gdbarch
*gdbarch
;
469 struct dwarf2_loclist_baton
*dlbaton
;
470 const gdb_byte
*start
;
472 struct value
*result
;
474 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
475 Thus, it's supposed to provide the find_frame_base_location method as
477 gdb_assert (SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
!= NULL
);
479 gdbarch
= get_frame_arch (frame
);
480 type
= builtin_type (gdbarch
)->builtin_data_ptr
;
481 dlbaton
= (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (framefunc
);
483 SYMBOL_BLOCK_OPS (framefunc
)->find_frame_base_location
484 (framefunc
, get_frame_pc (frame
), &start
, &length
);
485 result
= dwarf2_evaluate_loc_desc (type
, frame
, start
, length
,
488 /* The DW_AT_frame_base attribute contains a location description which
489 computes the base address itself. However, the call to
490 dwarf2_evaluate_loc_desc returns a value representing a variable at
491 that address. The frame base address is thus this variable's
493 return value_address (result
);
496 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
497 function uses DWARF location list for its DW_AT_frame_base. */
499 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs
=
501 loclist_find_frame_base_location
,
502 loclist_get_frame_base
505 /* See dwarf2loc.h. */
508 func_get_frame_base_dwarf_block (struct symbol
*framefunc
, CORE_ADDR pc
,
509 const gdb_byte
**start
, size_t *length
)
511 if (SYMBOL_BLOCK_OPS (framefunc
) != NULL
)
513 const struct symbol_block_ops
*ops_block
= SYMBOL_BLOCK_OPS (framefunc
);
515 ops_block
->find_frame_base_location (framefunc
, pc
, start
, length
);
521 error (_("Could not find the frame base for \"%s\"."),
522 SYMBOL_NATURAL_NAME (framefunc
));
526 get_frame_pc_for_per_cu_dwarf_call (void *baton
)
528 dwarf_expr_context
*ctx
= (dwarf_expr_context
*) baton
;
530 return ctx
->get_frame_pc ();
534 per_cu_dwarf_call (struct dwarf_expr_context
*ctx
, cu_offset die_offset
,
535 struct dwarf2_per_cu_data
*per_cu
)
537 struct dwarf2_locexpr_baton block
;
539 block
= dwarf2_fetch_die_loc_cu_off (die_offset
, per_cu
,
540 get_frame_pc_for_per_cu_dwarf_call
,
543 /* DW_OP_call_ref is currently not supported. */
544 gdb_assert (block
.per_cu
== per_cu
);
546 ctx
->eval (block
.data
, block
.size
);
549 class dwarf_evaluate_loc_desc
: public dwarf_expr_context
553 struct frame_info
*frame
;
554 struct dwarf2_per_cu_data
*per_cu
;
555 CORE_ADDR obj_address
;
557 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
558 the frame in BATON. */
560 CORE_ADDR
get_frame_cfa () OVERRIDE
562 return dwarf2_frame_cfa (frame
);
565 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
566 the frame in BATON. */
568 CORE_ADDR
get_frame_pc () OVERRIDE
570 return get_frame_address_in_block (frame
);
573 /* Using the objfile specified in BATON, find the address for the
574 current thread's thread-local storage with offset OFFSET. */
575 CORE_ADDR
get_tls_address (CORE_ADDR offset
) OVERRIDE
577 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
579 return target_translate_tls_address (objfile
, offset
);
582 /* Helper interface of per_cu_dwarf_call for
583 dwarf2_evaluate_loc_desc. */
585 void dwarf_call (cu_offset die_offset
) OVERRIDE
587 per_cu_dwarf_call (this, die_offset
, per_cu
);
590 struct type
*get_base_type (cu_offset die_offset
, int size
) OVERRIDE
592 struct type
*result
= dwarf2_get_die_type (die_offset
, per_cu
);
594 error (_("Could not find type for DW_OP_const_type"));
595 if (size
!= 0 && TYPE_LENGTH (result
) != size
)
596 error (_("DW_OP_const_type has different sizes for type and data"));
600 /* Callback function for dwarf2_evaluate_loc_desc.
601 Fetch the address indexed by DW_OP_GNU_addr_index. */
603 CORE_ADDR
get_addr_index (unsigned int index
) OVERRIDE
605 return dwarf2_read_addr_index (per_cu
, index
);
608 /* Callback function for get_object_address. Return the address of the VLA
611 CORE_ADDR
get_object_address () OVERRIDE
613 if (obj_address
== 0)
614 error (_("Location address is not set."));
618 /* Execute DWARF block of call_site_parameter which matches KIND and
619 KIND_U. Choose DEREF_SIZE value of that parameter. Search
620 caller of this objects's frame.
622 The caller can be from a different CU - per_cu_dwarf_call
623 implementation can be more simple as it does not support cross-CU
626 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
627 union call_site_parameter_u kind_u
,
628 int deref_size
) OVERRIDE
630 struct frame_info
*caller_frame
;
631 struct dwarf2_per_cu_data
*caller_per_cu
;
632 struct call_site_parameter
*parameter
;
633 const gdb_byte
*data_src
;
636 caller_frame
= get_prev_frame (frame
);
638 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
640 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
641 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
643 /* DEREF_SIZE size is not verified here. */
644 if (data_src
== NULL
)
645 throw_error (NO_ENTRY_VALUE_ERROR
,
646 _("Cannot resolve DW_AT_call_data_value"));
648 scoped_restore save_frame
= make_scoped_restore (&this->frame
,
650 scoped_restore save_per_cu
= make_scoped_restore (&this->per_cu
,
652 scoped_restore save_obj_addr
= make_scoped_restore (&this->obj_address
,
655 scoped_restore save_arch
= make_scoped_restore (&this->gdbarch
);
657 = get_objfile_arch (dwarf2_per_cu_objfile (per_cu
));
658 scoped_restore save_addr_size
= make_scoped_restore (&this->addr_size
);
659 this->addr_size
= dwarf2_per_cu_addr_size (per_cu
);
660 scoped_restore save_offset
= make_scoped_restore (&this->offset
);
661 this->offset
= dwarf2_per_cu_text_offset (per_cu
);
663 this->eval (data_src
, size
);
666 /* Using the frame specified in BATON, find the location expression
667 describing the frame base. Return a pointer to it in START and
668 its length in LENGTH. */
669 void get_frame_base (const gdb_byte
**start
, size_t * length
) OVERRIDE
671 /* FIXME: cagney/2003-03-26: This code should be using
672 get_frame_base_address(), and then implement a dwarf2 specific
674 struct symbol
*framefunc
;
675 const struct block
*bl
= get_frame_block (frame
, NULL
);
678 error (_("frame address is not available."));
680 /* Use block_linkage_function, which returns a real (not inlined)
681 function, instead of get_frame_function, which may return an
683 framefunc
= block_linkage_function (bl
);
685 /* If we found a frame-relative symbol then it was certainly within
686 some function associated with a frame. If we can't find the frame,
687 something has gone wrong. */
688 gdb_assert (framefunc
!= NULL
);
690 func_get_frame_base_dwarf_block (framefunc
,
691 get_frame_address_in_block (frame
),
695 /* Read memory at ADDR (length LEN) into BUF. */
697 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) OVERRIDE
699 read_memory (addr
, buf
, len
);
702 /* Using the frame specified in BATON, return the value of register
703 REGNUM, treated as a pointer. */
704 CORE_ADDR
read_addr_from_reg (int dwarf_regnum
) OVERRIDE
706 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
707 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
709 return address_from_register (regnum
, frame
);
712 /* Implement "get_reg_value" callback. */
714 struct value
*get_reg_value (struct type
*type
, int dwarf_regnum
) OVERRIDE
716 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
717 int regnum
= dwarf_reg_to_regnum_or_error (gdbarch
, dwarf_regnum
);
719 return value_from_register (type
, regnum
, frame
);
723 /* See dwarf2loc.h. */
725 unsigned int entry_values_debug
= 0;
727 /* Helper to set entry_values_debug. */
730 show_entry_values_debug (struct ui_file
*file
, int from_tty
,
731 struct cmd_list_element
*c
, const char *value
)
733 fprintf_filtered (file
,
734 _("Entry values and tail call frames debugging is %s.\n"),
738 /* Find DW_TAG_call_site's DW_AT_call_target address.
739 CALLER_FRAME (for registers) can be NULL if it is not known. This function
740 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
743 call_site_to_target_addr (struct gdbarch
*call_site_gdbarch
,
744 struct call_site
*call_site
,
745 struct frame_info
*caller_frame
)
747 switch (FIELD_LOC_KIND (call_site
->target
))
749 case FIELD_LOC_KIND_DWARF_BLOCK
:
751 struct dwarf2_locexpr_baton
*dwarf_block
;
753 struct type
*caller_core_addr_type
;
754 struct gdbarch
*caller_arch
;
756 dwarf_block
= FIELD_DWARF_BLOCK (call_site
->target
);
757 if (dwarf_block
== NULL
)
759 struct bound_minimal_symbol msym
;
761 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
762 throw_error (NO_ENTRY_VALUE_ERROR
,
763 _("DW_AT_call_target is not specified at %s in %s"),
764 paddress (call_site_gdbarch
, call_site
->pc
),
765 (msym
.minsym
== NULL
? "???"
766 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
769 if (caller_frame
== NULL
)
771 struct bound_minimal_symbol msym
;
773 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
774 throw_error (NO_ENTRY_VALUE_ERROR
,
775 _("DW_AT_call_target DWARF block resolving "
776 "requires known frame which is currently not "
777 "available at %s in %s"),
778 paddress (call_site_gdbarch
, call_site
->pc
),
779 (msym
.minsym
== NULL
? "???"
780 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
783 caller_arch
= get_frame_arch (caller_frame
);
784 caller_core_addr_type
= builtin_type (caller_arch
)->builtin_func_ptr
;
785 val
= dwarf2_evaluate_loc_desc (caller_core_addr_type
, caller_frame
,
786 dwarf_block
->data
, dwarf_block
->size
,
787 dwarf_block
->per_cu
);
788 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
789 if (VALUE_LVAL (val
) == lval_memory
)
790 return value_address (val
);
792 return value_as_address (val
);
795 case FIELD_LOC_KIND_PHYSNAME
:
797 const char *physname
;
798 struct bound_minimal_symbol msym
;
800 physname
= FIELD_STATIC_PHYSNAME (call_site
->target
);
802 /* Handle both the mangled and demangled PHYSNAME. */
803 msym
= lookup_minimal_symbol (physname
, NULL
, NULL
);
804 if (msym
.minsym
== NULL
)
806 msym
= lookup_minimal_symbol_by_pc (call_site
->pc
- 1);
807 throw_error (NO_ENTRY_VALUE_ERROR
,
808 _("Cannot find function \"%s\" for a call site target "
810 physname
, paddress (call_site_gdbarch
, call_site
->pc
),
811 (msym
.minsym
== NULL
? "???"
812 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
815 return BMSYMBOL_VALUE_ADDRESS (msym
);
818 case FIELD_LOC_KIND_PHYSADDR
:
819 return FIELD_STATIC_PHYSADDR (call_site
->target
);
822 internal_error (__FILE__
, __LINE__
, _("invalid call site target kind"));
826 /* Convert function entry point exact address ADDR to the function which is
827 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
828 NO_ENTRY_VALUE_ERROR otherwise. */
830 static struct symbol
*
831 func_addr_to_tail_call_list (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
833 struct symbol
*sym
= find_pc_function (addr
);
836 if (sym
== NULL
|| BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) != addr
)
837 throw_error (NO_ENTRY_VALUE_ERROR
,
838 _("DW_TAG_call_site resolving failed to find function "
839 "name for address %s"),
840 paddress (gdbarch
, addr
));
842 type
= SYMBOL_TYPE (sym
);
843 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FUNC
);
844 gdb_assert (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FUNC
);
849 /* Verify function with entry point exact address ADDR can never call itself
850 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
851 can call itself via tail calls.
853 If a funtion can tail call itself its entry value based parameters are
854 unreliable. There is no verification whether the value of some/all
855 parameters is unchanged through the self tail call, we expect if there is
856 a self tail call all the parameters can be modified. */
859 func_verify_no_selftailcall (struct gdbarch
*gdbarch
, CORE_ADDR verify_addr
)
863 /* The verification is completely unordered. Track here function addresses
864 which still need to be iterated. */
865 std::vector
<CORE_ADDR
> todo
;
867 /* Track here CORE_ADDRs which were already visited. */
868 std::unordered_set
<CORE_ADDR
> addr_hash
;
870 todo
.push_back (verify_addr
);
871 while (!todo
.empty ())
873 struct symbol
*func_sym
;
874 struct call_site
*call_site
;
879 func_sym
= func_addr_to_tail_call_list (gdbarch
, addr
);
881 for (call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym
));
882 call_site
; call_site
= call_site
->tail_call_next
)
884 CORE_ADDR target_addr
;
886 /* CALLER_FRAME with registers is not available for tail-call jumped
888 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
890 if (target_addr
== verify_addr
)
892 struct bound_minimal_symbol msym
;
894 msym
= lookup_minimal_symbol_by_pc (verify_addr
);
895 throw_error (NO_ENTRY_VALUE_ERROR
,
896 _("DW_OP_entry_value resolving has found "
897 "function \"%s\" at %s can call itself via tail "
899 (msym
.minsym
== NULL
? "???"
900 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
901 paddress (gdbarch
, verify_addr
));
904 if (addr_hash
.insert (target_addr
).second
)
905 todo
.push_back (target_addr
);
910 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
911 ENTRY_VALUES_DEBUG. */
914 tailcall_dump (struct gdbarch
*gdbarch
, const struct call_site
*call_site
)
916 CORE_ADDR addr
= call_site
->pc
;
917 struct bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (addr
- 1);
919 fprintf_unfiltered (gdb_stdlog
, " %s(%s)", paddress (gdbarch
, addr
),
920 (msym
.minsym
== NULL
? "???"
921 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
925 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
926 only top callers and bottom callees which are present in both. GDBARCH is
927 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
928 no remaining possibilities to provide unambiguous non-trivial result.
929 RESULTP should point to NULL on the first (initialization) call. Caller is
930 responsible for xfree of any RESULTP data. */
933 chain_candidate (struct gdbarch
*gdbarch
,
934 gdb::unique_xmalloc_ptr
<struct call_site_chain
> *resultp
,
935 std::vector
<struct call_site
*> *chain
)
937 long length
= chain
->size ();
938 int callers
, callees
, idx
;
940 if (*resultp
== NULL
)
942 /* Create the initial chain containing all the passed PCs. */
944 struct call_site_chain
*result
945 = ((struct call_site_chain
*)
946 xmalloc (sizeof (*result
)
947 + sizeof (*result
->call_site
) * (length
- 1)));
948 result
->length
= length
;
949 result
->callers
= result
->callees
= length
;
950 if (!chain
->empty ())
951 memcpy (result
->call_site
, chain
->data (),
952 sizeof (*result
->call_site
) * length
);
953 resultp
->reset (result
);
955 if (entry_values_debug
)
957 fprintf_unfiltered (gdb_stdlog
, "tailcall: initial:");
958 for (idx
= 0; idx
< length
; idx
++)
959 tailcall_dump (gdbarch
, result
->call_site
[idx
]);
960 fputc_unfiltered ('\n', gdb_stdlog
);
966 if (entry_values_debug
)
968 fprintf_unfiltered (gdb_stdlog
, "tailcall: compare:");
969 for (idx
= 0; idx
< length
; idx
++)
970 tailcall_dump (gdbarch
, chain
->at (idx
));
971 fputc_unfiltered ('\n', gdb_stdlog
);
974 /* Intersect callers. */
976 callers
= std::min ((long) (*resultp
)->callers
, length
);
977 for (idx
= 0; idx
< callers
; idx
++)
978 if ((*resultp
)->call_site
[idx
] != chain
->at (idx
))
980 (*resultp
)->callers
= idx
;
984 /* Intersect callees. */
986 callees
= std::min ((long) (*resultp
)->callees
, length
);
987 for (idx
= 0; idx
< callees
; idx
++)
988 if ((*resultp
)->call_site
[(*resultp
)->length
- 1 - idx
]
989 != chain
->at (length
- 1 - idx
))
991 (*resultp
)->callees
= idx
;
995 if (entry_values_debug
)
997 fprintf_unfiltered (gdb_stdlog
, "tailcall: reduced:");
998 for (idx
= 0; idx
< (*resultp
)->callers
; idx
++)
999 tailcall_dump (gdbarch
, (*resultp
)->call_site
[idx
]);
1000 fputs_unfiltered (" |", gdb_stdlog
);
1001 for (idx
= 0; idx
< (*resultp
)->callees
; idx
++)
1002 tailcall_dump (gdbarch
,
1003 (*resultp
)->call_site
[(*resultp
)->length
1004 - (*resultp
)->callees
+ idx
]);
1005 fputc_unfiltered ('\n', gdb_stdlog
);
1008 if ((*resultp
)->callers
== 0 && (*resultp
)->callees
== 0)
1010 /* There are no common callers or callees. It could be also a direct
1011 call (which has length 0) with ambiguous possibility of an indirect
1012 call - CALLERS == CALLEES == 0 is valid during the first allocation
1013 but any subsequence processing of such entry means ambiguity. */
1014 resultp
->reset (NULL
);
1018 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1019 PC again. In such case there must be two different code paths to reach
1020 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1021 gdb_assert ((*resultp
)->callers
+ (*resultp
)->callees
<= (*resultp
)->length
);
1024 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1025 assumed frames between them use GDBARCH. Use depth first search so we can
1026 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1027 would have needless GDB stack overhead. Caller is responsible for xfree of
1028 the returned result. Any unreliability results in thrown
1029 NO_ENTRY_VALUE_ERROR. */
1031 static struct call_site_chain
*
1032 call_site_find_chain_1 (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1033 CORE_ADDR callee_pc
)
1035 CORE_ADDR save_callee_pc
= callee_pc
;
1036 gdb::unique_xmalloc_ptr
<struct call_site_chain
> retval
;
1037 struct call_site
*call_site
;
1039 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1040 call_site nor any possible call_site at CALLEE_PC's function is there.
1041 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1042 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1043 std::vector
<struct call_site
*> chain
;
1045 /* We are not interested in the specific PC inside the callee function. */
1046 callee_pc
= get_pc_function_start (callee_pc
);
1048 throw_error (NO_ENTRY_VALUE_ERROR
, _("Unable to find function for PC %s"),
1049 paddress (gdbarch
, save_callee_pc
));
1051 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1052 std::unordered_set
<CORE_ADDR
> addr_hash
;
1054 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1055 at the target's function. All the possible tail call sites in the
1056 target's function will get iterated as already pushed into CHAIN via their
1058 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1062 CORE_ADDR target_func_addr
;
1063 struct call_site
*target_call_site
;
1065 /* CALLER_FRAME with registers is not available for tail-call jumped
1067 target_func_addr
= call_site_to_target_addr (gdbarch
, call_site
, NULL
);
1069 if (target_func_addr
== callee_pc
)
1071 chain_candidate (gdbarch
, &retval
, &chain
);
1075 /* There is no way to reach CALLEE_PC again as we would prevent
1076 entering it twice as being already marked in ADDR_HASH. */
1077 target_call_site
= NULL
;
1081 struct symbol
*target_func
;
1083 target_func
= func_addr_to_tail_call_list (gdbarch
, target_func_addr
);
1084 target_call_site
= TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func
));
1089 /* Attempt to visit TARGET_CALL_SITE. */
1091 if (target_call_site
)
1093 if (addr_hash
.insert (target_call_site
->pc
).second
)
1095 /* Successfully entered TARGET_CALL_SITE. */
1097 chain
.push_back (target_call_site
);
1102 /* Backtrack (without revisiting the originating call_site). Try the
1103 callers's sibling; if there isn't any try the callers's callers's
1106 target_call_site
= NULL
;
1107 while (!chain
.empty ())
1109 call_site
= chain
.back ();
1112 size_t removed
= addr_hash
.erase (call_site
->pc
);
1113 gdb_assert (removed
== 1);
1115 target_call_site
= call_site
->tail_call_next
;
1116 if (target_call_site
)
1120 while (target_call_site
);
1125 call_site
= chain
.back ();
1130 struct bound_minimal_symbol msym_caller
, msym_callee
;
1132 msym_caller
= lookup_minimal_symbol_by_pc (caller_pc
);
1133 msym_callee
= lookup_minimal_symbol_by_pc (callee_pc
);
1134 throw_error (NO_ENTRY_VALUE_ERROR
,
1135 _("There are no unambiguously determinable intermediate "
1136 "callers or callees between caller function \"%s\" at %s "
1137 "and callee function \"%s\" at %s"),
1138 (msym_caller
.minsym
== NULL
1139 ? "???" : MSYMBOL_PRINT_NAME (msym_caller
.minsym
)),
1140 paddress (gdbarch
, caller_pc
),
1141 (msym_callee
.minsym
== NULL
1142 ? "???" : MSYMBOL_PRINT_NAME (msym_callee
.minsym
)),
1143 paddress (gdbarch
, callee_pc
));
1146 return retval
.release ();
1149 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1150 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1151 constructed return NULL. Caller is responsible for xfree of the returned
1154 struct call_site_chain
*
1155 call_site_find_chain (struct gdbarch
*gdbarch
, CORE_ADDR caller_pc
,
1156 CORE_ADDR callee_pc
)
1158 struct call_site_chain
*retval
= NULL
;
1162 retval
= call_site_find_chain_1 (gdbarch
, caller_pc
, callee_pc
);
1164 CATCH (e
, RETURN_MASK_ERROR
)
1166 if (e
.error
== NO_ENTRY_VALUE_ERROR
)
1168 if (entry_values_debug
)
1169 exception_print (gdb_stdout
, e
);
1174 throw_exception (e
);
1181 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1184 call_site_parameter_matches (struct call_site_parameter
*parameter
,
1185 enum call_site_parameter_kind kind
,
1186 union call_site_parameter_u kind_u
)
1188 if (kind
== parameter
->kind
)
1191 case CALL_SITE_PARAMETER_DWARF_REG
:
1192 return kind_u
.dwarf_reg
== parameter
->u
.dwarf_reg
;
1193 case CALL_SITE_PARAMETER_FB_OFFSET
:
1194 return kind_u
.fb_offset
== parameter
->u
.fb_offset
;
1195 case CALL_SITE_PARAMETER_PARAM_OFFSET
:
1196 return kind_u
.param_cu_off
== parameter
->u
.param_cu_off
;
1201 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1202 FRAME is for callee.
1204 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1207 static struct call_site_parameter
*
1208 dwarf_expr_reg_to_entry_parameter (struct frame_info
*frame
,
1209 enum call_site_parameter_kind kind
,
1210 union call_site_parameter_u kind_u
,
1211 struct dwarf2_per_cu_data
**per_cu_return
)
1213 CORE_ADDR func_addr
, caller_pc
;
1214 struct gdbarch
*gdbarch
;
1215 struct frame_info
*caller_frame
;
1216 struct call_site
*call_site
;
1218 /* Initialize it just to avoid a GCC false warning. */
1219 struct call_site_parameter
*parameter
= NULL
;
1220 CORE_ADDR target_addr
;
1222 while (get_frame_type (frame
) == INLINE_FRAME
)
1224 frame
= get_prev_frame (frame
);
1225 gdb_assert (frame
!= NULL
);
1228 func_addr
= get_frame_func (frame
);
1229 gdbarch
= get_frame_arch (frame
);
1230 caller_frame
= get_prev_frame (frame
);
1231 if (gdbarch
!= frame_unwind_arch (frame
))
1233 struct bound_minimal_symbol msym
1234 = lookup_minimal_symbol_by_pc (func_addr
);
1235 struct gdbarch
*caller_gdbarch
= frame_unwind_arch (frame
);
1237 throw_error (NO_ENTRY_VALUE_ERROR
,
1238 _("DW_OP_entry_value resolving callee gdbarch %s "
1239 "(of %s (%s)) does not match caller gdbarch %s"),
1240 gdbarch_bfd_arch_info (gdbarch
)->printable_name
,
1241 paddress (gdbarch
, func_addr
),
1242 (msym
.minsym
== NULL
? "???"
1243 : MSYMBOL_PRINT_NAME (msym
.minsym
)),
1244 gdbarch_bfd_arch_info (caller_gdbarch
)->printable_name
);
1247 if (caller_frame
== NULL
)
1249 struct bound_minimal_symbol msym
1250 = lookup_minimal_symbol_by_pc (func_addr
);
1252 throw_error (NO_ENTRY_VALUE_ERROR
, _("DW_OP_entry_value resolving "
1253 "requires caller of %s (%s)"),
1254 paddress (gdbarch
, func_addr
),
1255 (msym
.minsym
== NULL
? "???"
1256 : MSYMBOL_PRINT_NAME (msym
.minsym
)));
1258 caller_pc
= get_frame_pc (caller_frame
);
1259 call_site
= call_site_for_pc (gdbarch
, caller_pc
);
1261 target_addr
= call_site_to_target_addr (gdbarch
, call_site
, caller_frame
);
1262 if (target_addr
!= func_addr
)
1264 struct minimal_symbol
*target_msym
, *func_msym
;
1266 target_msym
= lookup_minimal_symbol_by_pc (target_addr
).minsym
;
1267 func_msym
= lookup_minimal_symbol_by_pc (func_addr
).minsym
;
1268 throw_error (NO_ENTRY_VALUE_ERROR
,
1269 _("DW_OP_entry_value resolving expects callee %s at %s "
1270 "but the called frame is for %s at %s"),
1271 (target_msym
== NULL
? "???"
1272 : MSYMBOL_PRINT_NAME (target_msym
)),
1273 paddress (gdbarch
, target_addr
),
1274 func_msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (func_msym
),
1275 paddress (gdbarch
, func_addr
));
1278 /* No entry value based parameters would be reliable if this function can
1279 call itself via tail calls. */
1280 func_verify_no_selftailcall (gdbarch
, func_addr
);
1282 for (iparams
= 0; iparams
< call_site
->parameter_count
; iparams
++)
1284 parameter
= &call_site
->parameter
[iparams
];
1285 if (call_site_parameter_matches (parameter
, kind
, kind_u
))
1288 if (iparams
== call_site
->parameter_count
)
1290 struct minimal_symbol
*msym
1291 = lookup_minimal_symbol_by_pc (caller_pc
).minsym
;
1293 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1294 determine its value. */
1295 throw_error (NO_ENTRY_VALUE_ERROR
, _("Cannot find matching parameter "
1296 "at DW_TAG_call_site %s at %s"),
1297 paddress (gdbarch
, caller_pc
),
1298 msym
== NULL
? "???" : MSYMBOL_PRINT_NAME (msym
));
1301 *per_cu_return
= call_site
->per_cu
;
1305 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1306 the normal DW_AT_call_value block. Otherwise return the
1307 DW_AT_call_data_value (dereferenced) block.
1309 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1312 Function always returns non-NULL, non-optimized out value. It throws
1313 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1315 static struct value
*
1316 dwarf_entry_parameter_to_value (struct call_site_parameter
*parameter
,
1317 CORE_ADDR deref_size
, struct type
*type
,
1318 struct frame_info
*caller_frame
,
1319 struct dwarf2_per_cu_data
*per_cu
)
1321 const gdb_byte
*data_src
;
1325 data_src
= deref_size
== -1 ? parameter
->value
: parameter
->data_value
;
1326 size
= deref_size
== -1 ? parameter
->value_size
: parameter
->data_value_size
;
1328 /* DEREF_SIZE size is not verified here. */
1329 if (data_src
== NULL
)
1330 throw_error (NO_ENTRY_VALUE_ERROR
,
1331 _("Cannot resolve DW_AT_call_data_value"));
1333 /* DW_AT_call_value is a DWARF expression, not a DWARF
1334 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1336 data
= (gdb_byte
*) alloca (size
+ 1);
1337 memcpy (data
, data_src
, size
);
1338 data
[size
] = DW_OP_stack_value
;
1340 return dwarf2_evaluate_loc_desc (type
, caller_frame
, data
, size
+ 1, per_cu
);
1343 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1344 the indirect method on it, that is use its stored target value, the sole
1345 purpose of entry_data_value_funcs.. */
1347 static struct value
*
1348 entry_data_value_coerce_ref (const struct value
*value
)
1350 struct type
*checked_type
= check_typedef (value_type (value
));
1351 struct value
*target_val
;
1353 if (!TYPE_IS_REFERENCE (checked_type
))
1356 target_val
= (struct value
*) value_computed_closure (value
);
1357 value_incref (target_val
);
1361 /* Implement copy_closure. */
1364 entry_data_value_copy_closure (const struct value
*v
)
1366 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1368 value_incref (target_val
);
1372 /* Implement free_closure. */
1375 entry_data_value_free_closure (struct value
*v
)
1377 struct value
*target_val
= (struct value
*) value_computed_closure (v
);
1379 value_free (target_val
);
1382 /* Vector for methods for an entry value reference where the referenced value
1383 is stored in the caller. On the first dereference use
1384 DW_AT_call_data_value in the caller. */
1386 static const struct lval_funcs entry_data_value_funcs
=
1390 NULL
, /* indirect */
1391 entry_data_value_coerce_ref
,
1392 NULL
, /* check_synthetic_pointer */
1393 entry_data_value_copy_closure
,
1394 entry_data_value_free_closure
1397 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1398 are used to match DW_AT_location at the caller's
1399 DW_TAG_call_site_parameter.
1401 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1402 cannot resolve the parameter for any reason. */
1404 static struct value
*
1405 value_of_dwarf_reg_entry (struct type
*type
, struct frame_info
*frame
,
1406 enum call_site_parameter_kind kind
,
1407 union call_site_parameter_u kind_u
)
1409 struct type
*checked_type
= check_typedef (type
);
1410 struct type
*target_type
= TYPE_TARGET_TYPE (checked_type
);
1411 struct frame_info
*caller_frame
= get_prev_frame (frame
);
1412 struct value
*outer_val
, *target_val
, *val
;
1413 struct call_site_parameter
*parameter
;
1414 struct dwarf2_per_cu_data
*caller_per_cu
;
1416 parameter
= dwarf_expr_reg_to_entry_parameter (frame
, kind
, kind_u
,
1419 outer_val
= dwarf_entry_parameter_to_value (parameter
, -1 /* deref_size */,
1423 /* Check if DW_AT_call_data_value cannot be used. If it should be
1424 used and it is not available do not fall back to OUTER_VAL - dereferencing
1425 TYPE_CODE_REF with non-entry data value would give current value - not the
1428 if (!TYPE_IS_REFERENCE (checked_type
)
1429 || TYPE_TARGET_TYPE (checked_type
) == NULL
)
1432 target_val
= dwarf_entry_parameter_to_value (parameter
,
1433 TYPE_LENGTH (target_type
),
1434 target_type
, caller_frame
,
1437 release_value (target_val
);
1438 val
= allocate_computed_value (type
, &entry_data_value_funcs
,
1439 target_val
/* closure */);
1441 /* Copy the referencing pointer to the new computed value. */
1442 memcpy (value_contents_raw (val
), value_contents_raw (outer_val
),
1443 TYPE_LENGTH (checked_type
));
1444 set_value_lazy (val
, 0);
1449 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1450 SIZE are DWARF block used to match DW_AT_location at the caller's
1451 DW_TAG_call_site_parameter.
1453 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1454 cannot resolve the parameter for any reason. */
1456 static struct value
*
1457 value_of_dwarf_block_entry (struct type
*type
, struct frame_info
*frame
,
1458 const gdb_byte
*block
, size_t block_len
)
1460 union call_site_parameter_u kind_u
;
1462 kind_u
.dwarf_reg
= dwarf_block_to_dwarf_reg (block
, block
+ block_len
);
1463 if (kind_u
.dwarf_reg
!= -1)
1464 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_DWARF_REG
,
1467 if (dwarf_block_to_fb_offset (block
, block
+ block_len
, &kind_u
.fb_offset
))
1468 return value_of_dwarf_reg_entry (type
, frame
, CALL_SITE_PARAMETER_FB_OFFSET
,
1471 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1472 suppressed during normal operation. The expression can be arbitrary if
1473 there is no caller-callee entry value binding expected. */
1474 throw_error (NO_ENTRY_VALUE_ERROR
,
1475 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1476 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1479 struct piece_closure
1481 /* Reference count. */
1484 /* The CU from which this closure's expression came. */
1485 struct dwarf2_per_cu_data
*per_cu
;
1487 /* The number of pieces used to describe this variable. */
1490 /* The pieces themselves. */
1491 struct dwarf_expr_piece
*pieces
;
1493 /* Frame ID of frame to which a register value is relative, used
1494 only by DWARF_VALUE_REGISTER. */
1495 struct frame_id frame_id
;
1498 /* Allocate a closure for a value formed from separately-described
1501 static struct piece_closure
*
1502 allocate_piece_closure (struct dwarf2_per_cu_data
*per_cu
,
1503 int n_pieces
, struct dwarf_expr_piece
*pieces
,
1504 struct frame_info
*frame
)
1506 struct piece_closure
*c
= XCNEW (struct piece_closure
);
1511 c
->n_pieces
= n_pieces
;
1512 c
->pieces
= XCNEWVEC (struct dwarf_expr_piece
, n_pieces
);
1514 c
->frame_id
= null_frame_id
;
1516 c
->frame_id
= get_frame_id (frame
);
1518 memcpy (c
->pieces
, pieces
, n_pieces
* sizeof (struct dwarf_expr_piece
));
1519 for (i
= 0; i
< n_pieces
; ++i
)
1520 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
1521 value_incref (c
->pieces
[i
].v
.value
);
1526 /* Copy NBITS bits from SOURCE to DEST starting at the given bit
1527 offsets. Use the bit order as specified by BITS_BIG_ENDIAN.
1528 Source and destination buffers must not overlap. */
1531 copy_bitwise (gdb_byte
*dest
, ULONGEST dest_offset
,
1532 const gdb_byte
*source
, ULONGEST source_offset
,
1533 ULONGEST nbits
, int bits_big_endian
)
1535 unsigned int buf
, avail
;
1540 if (bits_big_endian
)
1542 /* Start from the end, then work backwards. */
1543 dest_offset
+= nbits
- 1;
1544 dest
+= dest_offset
/ 8;
1545 dest_offset
= 7 - dest_offset
% 8;
1546 source_offset
+= nbits
- 1;
1547 source
+= source_offset
/ 8;
1548 source_offset
= 7 - source_offset
% 8;
1552 dest
+= dest_offset
/ 8;
1554 source
+= source_offset
/ 8;
1558 /* Fill BUF with DEST_OFFSET bits from the destination and 8 -
1559 SOURCE_OFFSET bits from the source. */
1560 buf
= *(bits_big_endian
? source
-- : source
++) >> source_offset
;
1561 buf
<<= dest_offset
;
1562 buf
|= *dest
& ((1 << dest_offset
) - 1);
1564 /* NBITS: bits yet to be written; AVAIL: BUF's fill level. */
1565 nbits
+= dest_offset
;
1566 avail
= dest_offset
+ 8 - source_offset
;
1568 /* Flush 8 bits from BUF, if appropriate. */
1569 if (nbits
>= 8 && avail
>= 8)
1571 *(bits_big_endian
? dest
-- : dest
++) = buf
;
1577 /* Copy the middle part. */
1580 size_t len
= nbits
/ 8;
1582 /* Use a faster method for byte-aligned copies. */
1585 if (bits_big_endian
)
1589 memcpy (dest
+ 1, source
+ 1, len
);
1593 memcpy (dest
, source
, len
);
1602 buf
|= *(bits_big_endian
? source
-- : source
++) << avail
;
1603 *(bits_big_endian
? dest
-- : dest
++) = buf
;
1610 /* Write the last byte. */
1614 buf
|= *source
<< avail
;
1616 buf
&= (1 << nbits
) - 1;
1617 *dest
= (*dest
& (~0 << nbits
)) | buf
;
1623 namespace selftests
{
1625 /* Helper function for the unit test of copy_bitwise. Convert NBITS bits
1626 out of BITS, starting at OFFS, to the respective '0'/'1'-string. MSB0
1627 specifies whether to assume big endian bit numbering. Store the
1628 resulting (not null-terminated) string at STR. */
1631 bits_to_str (char *str
, const gdb_byte
*bits
, ULONGEST offs
,
1632 ULONGEST nbits
, int msb0
)
1637 for (i
= offs
/ 8, j
= offs
% 8; nbits
; i
++, j
= 0)
1639 unsigned int ch
= bits
[i
];
1640 for (; j
< 8 && nbits
; j
++, nbits
--)
1641 *str
++ = (ch
& (msb0
? (1 << (7 - j
)) : (1 << j
))) ? '1' : '0';
1645 /* Check one invocation of copy_bitwise with the given parameters. */
1648 check_copy_bitwise (const gdb_byte
*dest
, unsigned int dest_offset
,
1649 const gdb_byte
*source
, unsigned int source_offset
,
1650 unsigned int nbits
, int msb0
)
1652 size_t len
= align_up (dest_offset
+ nbits
, 8);
1653 char *expected
= (char *) alloca (len
+ 1);
1654 char *actual
= (char *) alloca (len
+ 1);
1655 gdb_byte
*buf
= (gdb_byte
*) alloca (len
/ 8);
1657 /* Compose a '0'/'1'-string that represents the expected result of
1659 Bits from [0, DEST_OFFSET) are filled from DEST.
1660 Bits from [DEST_OFFSET, DEST_OFFSET + NBITS) are filled from SOURCE.
1661 Bits from [DEST_OFFSET + NBITS, LEN) are filled from DEST.
1670 We should end up with:
1672 DDDDSSDD (D=dest, S=source)
1674 bits_to_str (expected
, dest
, 0, len
, msb0
);
1675 bits_to_str (expected
+ dest_offset
, source
, source_offset
, nbits
, msb0
);
1677 /* Fill BUF with data from DEST, apply copy_bitwise, and convert the
1678 result to a '0'/'1'-string. */
1679 memcpy (buf
, dest
, len
/ 8);
1680 copy_bitwise (buf
, dest_offset
, source
, source_offset
, nbits
, msb0
);
1681 bits_to_str (actual
, buf
, 0, len
, msb0
);
1683 /* Compare the resulting strings. */
1684 expected
[len
] = actual
[len
] = '\0';
1685 if (strcmp (expected
, actual
) != 0)
1686 error (_("copy_bitwise %s != %s (%u+%u -> %u)"),
1687 expected
, actual
, source_offset
, nbits
, dest_offset
);
1690 /* Unit test for copy_bitwise. */
1693 copy_bitwise_tests (void)
1695 /* Data to be used as both source and destination buffers. The two
1696 arrays below represent the lsb0- and msb0- encoded versions of the
1697 following bit string, respectively:
1698 00000000 00011111 11111111 01001000 10100101 11110010
1699 This pattern is chosen such that it contains:
1700 - constant 0- and 1- chunks of more than a full byte;
1701 - 0/1- and 1/0 transitions on all bit positions within a byte;
1702 - several sufficiently asymmetric bytes.
1704 static const gdb_byte data_lsb0
[] = {
1705 0x00, 0xf8, 0xff, 0x12, 0xa5, 0x4f
1707 static const gdb_byte data_msb0
[] = {
1708 0x00, 0x1f, 0xff, 0x48, 0xa5, 0xf2
1711 constexpr size_t data_nbits
= 8 * sizeof (data_lsb0
);
1712 constexpr unsigned max_nbits
= 24;
1714 /* Try all combinations of:
1715 lsb0/msb0 bit order (using the respective data array)
1716 X [0, MAX_NBITS] copy bit width
1717 X feasible source offsets for the given copy bit width
1718 X feasible destination offsets
1720 for (int msb0
= 0; msb0
< 2; msb0
++)
1722 const gdb_byte
*data
= msb0
? data_msb0
: data_lsb0
;
1724 for (unsigned int nbits
= 1; nbits
<= max_nbits
; nbits
++)
1726 const unsigned int max_offset
= data_nbits
- nbits
;
1728 for (unsigned source_offset
= 0;
1729 source_offset
<= max_offset
;
1732 for (unsigned dest_offset
= 0;
1733 dest_offset
<= max_offset
;
1736 check_copy_bitwise (data
+ dest_offset
/ 8,
1738 data
+ source_offset
/ 8,
1745 /* Special cases: copy all, copy nothing. */
1746 check_copy_bitwise (data_lsb0
, 0, data_msb0
, 0, data_nbits
, msb0
);
1747 check_copy_bitwise (data_msb0
, 0, data_lsb0
, 0, data_nbits
, msb0
);
1748 check_copy_bitwise (data
, data_nbits
- 7, data
, 9, 0, msb0
);
1752 } /* namespace selftests */
1754 #endif /* GDB_SELF_TEST */
1756 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1757 bits whose first bit is located at bit offset START. */
1760 bits_to_bytes (ULONGEST start
, ULONGEST n_bits
)
1762 return (start
% 8 + n_bits
+ 7) / 8;
1765 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1766 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1767 operate in "read mode": fetch the contents of the (lazy) value V by
1768 composing it from its pieces. */
1771 rw_pieced_value (struct value
*v
, struct value
*from
)
1774 LONGEST offset
= 0, max_offset
;
1775 ULONGEST bits_to_skip
;
1776 gdb_byte
*v_contents
;
1777 const gdb_byte
*from_contents
;
1778 struct piece_closure
*c
1779 = (struct piece_closure
*) value_computed_closure (v
);
1780 gdb::byte_vector buffer
;
1782 = gdbarch_bits_big_endian (get_type_arch (value_type (v
)));
1786 from_contents
= value_contents (from
);
1791 if (value_type (v
) != value_enclosing_type (v
))
1792 internal_error (__FILE__
, __LINE__
,
1793 _("Should not be able to create a lazy value with "
1794 "an enclosing type"));
1795 v_contents
= value_contents_raw (v
);
1796 from_contents
= NULL
;
1799 bits_to_skip
= 8 * value_offset (v
);
1800 if (value_bitsize (v
))
1802 bits_to_skip
+= (8 * value_offset (value_parent (v
))
1803 + value_bitpos (v
));
1805 && (gdbarch_byte_order (get_type_arch (value_type (from
)))
1808 /* Use the least significant bits of FROM. */
1809 max_offset
= 8 * TYPE_LENGTH (value_type (from
));
1810 offset
= max_offset
- value_bitsize (v
);
1813 max_offset
= value_bitsize (v
);
1816 max_offset
= 8 * TYPE_LENGTH (value_type (v
));
1818 /* Advance to the first non-skipped piece. */
1819 for (i
= 0; i
< c
->n_pieces
&& bits_to_skip
>= c
->pieces
[i
].size
; i
++)
1820 bits_to_skip
-= c
->pieces
[i
].size
;
1822 for (; i
< c
->n_pieces
&& offset
< max_offset
; i
++)
1824 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
1825 size_t this_size_bits
, this_size
;
1827 this_size_bits
= p
->size
- bits_to_skip
;
1828 if (this_size_bits
> max_offset
- offset
)
1829 this_size_bits
= max_offset
- offset
;
1831 switch (p
->location
)
1833 case DWARF_VALUE_REGISTER
:
1835 struct frame_info
*frame
= frame_find_by_id (c
->frame_id
);
1836 struct gdbarch
*arch
= get_frame_arch (frame
);
1837 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, p
->v
.regno
);
1838 ULONGEST reg_bits
= 8 * register_size (arch
, gdb_regnum
);
1841 if (gdbarch_byte_order (arch
) == BFD_ENDIAN_BIG
1842 && p
->offset
+ p
->size
< reg_bits
)
1844 /* Big-endian, and we want less than full size. */
1845 bits_to_skip
+= reg_bits
- (p
->offset
+ p
->size
);
1848 bits_to_skip
+= p
->offset
;
1850 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1851 buffer
.resize (this_size
);
1856 if (!get_frame_register_bytes (frame
, gdb_regnum
,
1858 this_size
, buffer
.data (),
1862 mark_value_bits_optimized_out (v
, offset
,
1865 mark_value_bits_unavailable (v
, offset
,
1870 copy_bitwise (v_contents
, offset
,
1871 buffer
.data (), bits_to_skip
% 8,
1872 this_size_bits
, bits_big_endian
);
1877 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1879 /* Data is copied non-byte-aligned into the register.
1880 Need some bits from original register value. */
1881 get_frame_register_bytes (frame
, gdb_regnum
,
1883 this_size
, buffer
.data (),
1886 throw_error (OPTIMIZED_OUT_ERROR
,
1887 _("Can't do read-modify-write to "
1888 "update bitfield; containing word "
1889 "has been optimized out"));
1891 throw_error (NOT_AVAILABLE_ERROR
,
1892 _("Can't do read-modify-write to "
1893 "update bitfield; containing word "
1897 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1898 from_contents
, offset
,
1899 this_size_bits
, bits_big_endian
);
1900 put_frame_register_bytes (frame
, gdb_regnum
,
1902 this_size
, buffer
.data ());
1907 case DWARF_VALUE_MEMORY
:
1909 bits_to_skip
+= p
->offset
;
1911 CORE_ADDR start_addr
= p
->v
.mem
.addr
+ bits_to_skip
/ 8;
1913 if (bits_to_skip
% 8 == 0 && this_size_bits
% 8 == 0
1916 /* Everything is byte-aligned; no buffer needed. */
1918 write_memory_with_notification (start_addr
,
1921 this_size_bits
/ 8);
1923 read_value_memory (v
, offset
,
1924 p
->v
.mem
.in_stack_memory
,
1925 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1926 v_contents
+ offset
/ 8,
1927 this_size_bits
/ 8);
1931 this_size
= bits_to_bytes (bits_to_skip
, this_size_bits
);
1932 buffer
.resize (this_size
);
1937 read_value_memory (v
, offset
,
1938 p
->v
.mem
.in_stack_memory
,
1939 p
->v
.mem
.addr
+ bits_to_skip
/ 8,
1940 buffer
.data (), this_size
);
1941 copy_bitwise (v_contents
, offset
,
1942 buffer
.data (), bits_to_skip
% 8,
1943 this_size_bits
, bits_big_endian
);
1948 if (bits_to_skip
% 8 != 0 || this_size_bits
% 8 != 0)
1952 /* Perform a single read for small sizes. */
1953 read_memory (start_addr
, buffer
.data (),
1958 /* Only the first and last bytes can possibly have
1960 read_memory (start_addr
, buffer
.data (), 1);
1961 read_memory (start_addr
+ this_size
- 1,
1962 &buffer
[this_size
- 1], 1);
1966 copy_bitwise (buffer
.data (), bits_to_skip
% 8,
1967 from_contents
, offset
,
1968 this_size_bits
, bits_big_endian
);
1969 write_memory_with_notification (start_addr
,
1976 case DWARF_VALUE_STACK
:
1980 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
1984 struct objfile
*objfile
= dwarf2_per_cu_objfile (c
->per_cu
);
1985 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
1986 ULONGEST stack_value_size_bits
1987 = 8 * TYPE_LENGTH (value_type (p
->v
.value
));
1989 /* Use zeroes if piece reaches beyond stack value. */
1990 if (p
->offset
+ p
->size
> stack_value_size_bits
)
1993 /* Piece is anchored at least significant bit end. */
1994 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
1995 bits_to_skip
+= stack_value_size_bits
- p
->offset
- p
->size
;
1997 bits_to_skip
+= p
->offset
;
1999 copy_bitwise (v_contents
, offset
,
2000 value_contents_all (p
->v
.value
),
2002 this_size_bits
, bits_big_endian
);
2006 case DWARF_VALUE_LITERAL
:
2010 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
2014 ULONGEST literal_size_bits
= 8 * p
->v
.literal
.length
;
2015 size_t n
= this_size_bits
;
2017 /* Cut off at the end of the implicit value. */
2018 bits_to_skip
+= p
->offset
;
2019 if (bits_to_skip
>= literal_size_bits
)
2021 if (n
> literal_size_bits
- bits_to_skip
)
2022 n
= literal_size_bits
- bits_to_skip
;
2024 copy_bitwise (v_contents
, offset
,
2025 p
->v
.literal
.data
, bits_to_skip
,
2026 n
, bits_big_endian
);
2030 case DWARF_VALUE_IMPLICIT_POINTER
:
2033 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
2037 /* These bits show up as zeros -- but do not cause the value to
2038 be considered optimized-out. */
2041 case DWARF_VALUE_OPTIMIZED_OUT
:
2042 mark_value_bits_optimized_out (v
, offset
, this_size_bits
);
2046 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2049 offset
+= this_size_bits
;
2056 read_pieced_value (struct value
*v
)
2058 rw_pieced_value (v
, NULL
);
2062 write_pieced_value (struct value
*to
, struct value
*from
)
2064 rw_pieced_value (to
, from
);
2067 /* An implementation of an lval_funcs method to see whether a value is
2068 a synthetic pointer. */
2071 check_pieced_synthetic_pointer (const struct value
*value
, LONGEST bit_offset
,
2074 struct piece_closure
*c
2075 = (struct piece_closure
*) value_computed_closure (value
);
2078 bit_offset
+= 8 * value_offset (value
);
2079 if (value_bitsize (value
))
2080 bit_offset
+= value_bitpos (value
);
2082 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2084 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2085 size_t this_size_bits
= p
->size
;
2089 if (bit_offset
>= this_size_bits
)
2091 bit_offset
-= this_size_bits
;
2095 bit_length
-= this_size_bits
- bit_offset
;
2099 bit_length
-= this_size_bits
;
2101 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2108 /* A wrapper function for get_frame_address_in_block. */
2111 get_frame_address_in_block_wrapper (void *baton
)
2113 return get_frame_address_in_block ((struct frame_info
*) baton
);
2116 /* Fetch a DW_AT_const_value through a synthetic pointer. */
2118 static struct value
*
2119 fetch_const_value_from_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2120 struct dwarf2_per_cu_data
*per_cu
,
2123 struct value
*result
= NULL
;
2124 const gdb_byte
*bytes
;
2127 auto_obstack temp_obstack
;
2128 bytes
= dwarf2_fetch_constant_bytes (die
, per_cu
, &temp_obstack
, &len
);
2132 if (byte_offset
>= 0
2133 && byte_offset
+ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) <= len
)
2135 bytes
+= byte_offset
;
2136 result
= value_from_contents (TYPE_TARGET_TYPE (type
), bytes
);
2139 invalid_synthetic_pointer ();
2142 result
= allocate_optimized_out_value (TYPE_TARGET_TYPE (type
));
2147 /* Fetch the value pointed to by a synthetic pointer. */
2149 static struct value
*
2150 indirect_synthetic_pointer (sect_offset die
, LONGEST byte_offset
,
2151 struct dwarf2_per_cu_data
*per_cu
,
2152 struct frame_info
*frame
, struct type
*type
)
2154 /* Fetch the location expression of the DIE we're pointing to. */
2155 struct dwarf2_locexpr_baton baton
2156 = dwarf2_fetch_die_loc_sect_off (die
, per_cu
,
2157 get_frame_address_in_block_wrapper
, frame
);
2159 /* Get type of pointed-to DIE. */
2160 struct type
*orig_type
= dwarf2_fetch_die_type_sect_off (die
, per_cu
);
2161 if (orig_type
== NULL
)
2162 invalid_synthetic_pointer ();
2164 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2165 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2166 or it may've been optimized out. */
2167 if (baton
.data
!= NULL
)
2168 return dwarf2_evaluate_loc_desc_full (orig_type
, frame
, baton
.data
,
2169 baton
.size
, baton
.per_cu
,
2170 TYPE_TARGET_TYPE (type
),
2173 return fetch_const_value_from_synthetic_pointer (die
, byte_offset
, per_cu
,
2177 /* An implementation of an lval_funcs method to indirect through a
2178 pointer. This handles the synthetic pointer case when needed. */
2180 static struct value
*
2181 indirect_pieced_value (struct value
*value
)
2183 struct piece_closure
*c
2184 = (struct piece_closure
*) value_computed_closure (value
);
2186 struct frame_info
*frame
;
2187 struct dwarf2_locexpr_baton baton
;
2190 struct dwarf_expr_piece
*piece
= NULL
;
2191 LONGEST byte_offset
;
2192 enum bfd_endian byte_order
;
2194 type
= check_typedef (value_type (value
));
2195 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
2198 bit_length
= 8 * TYPE_LENGTH (type
);
2199 bit_offset
= 8 * value_offset (value
);
2200 if (value_bitsize (value
))
2201 bit_offset
+= value_bitpos (value
);
2203 for (i
= 0; i
< c
->n_pieces
&& bit_length
> 0; i
++)
2205 struct dwarf_expr_piece
*p
= &c
->pieces
[i
];
2206 size_t this_size_bits
= p
->size
;
2210 if (bit_offset
>= this_size_bits
)
2212 bit_offset
-= this_size_bits
;
2216 bit_length
-= this_size_bits
- bit_offset
;
2220 bit_length
-= this_size_bits
;
2222 if (p
->location
!= DWARF_VALUE_IMPLICIT_POINTER
)
2225 if (bit_length
!= 0)
2226 error (_("Invalid use of DW_OP_implicit_pointer"));
2232 gdb_assert (piece
!= NULL
);
2233 frame
= get_selected_frame (_("No frame selected."));
2235 /* This is an offset requested by GDB, such as value subscripts.
2236 However, due to how synthetic pointers are implemented, this is
2237 always presented to us as a pointer type. This means we have to
2238 sign-extend it manually as appropriate. Use raw
2239 extract_signed_integer directly rather than value_as_address and
2240 sign extend afterwards on architectures that would need it
2241 (mostly everywhere except MIPS, which has signed addresses) as
2242 the later would go through gdbarch_pointer_to_address and thus
2243 return a CORE_ADDR with high bits set on architectures that
2244 encode address spaces and other things in CORE_ADDR. */
2245 byte_order
= gdbarch_byte_order (get_frame_arch (frame
));
2246 byte_offset
= extract_signed_integer (value_contents (value
),
2247 TYPE_LENGTH (type
), byte_order
);
2248 byte_offset
+= piece
->v
.ptr
.offset
;
2250 return indirect_synthetic_pointer (piece
->v
.ptr
.die_sect_off
,
2251 byte_offset
, c
->per_cu
,
2255 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2258 static struct value
*
2259 coerce_pieced_ref (const struct value
*value
)
2261 struct type
*type
= check_typedef (value_type (value
));
2263 if (value_bits_synthetic_pointer (value
, value_embedded_offset (value
),
2264 TARGET_CHAR_BIT
* TYPE_LENGTH (type
)))
2266 const struct piece_closure
*closure
2267 = (struct piece_closure
*) value_computed_closure (value
);
2268 struct frame_info
*frame
2269 = get_selected_frame (_("No frame selected."));
2271 /* gdb represents synthetic pointers as pieced values with a single
2273 gdb_assert (closure
!= NULL
);
2274 gdb_assert (closure
->n_pieces
== 1);
2276 return indirect_synthetic_pointer (closure
->pieces
->v
.ptr
.die_sect_off
,
2277 closure
->pieces
->v
.ptr
.offset
,
2278 closure
->per_cu
, frame
, type
);
2282 /* Else: not a synthetic reference; do nothing. */
2288 copy_pieced_value_closure (const struct value
*v
)
2290 struct piece_closure
*c
2291 = (struct piece_closure
*) value_computed_closure (v
);
2298 free_pieced_value_closure (struct value
*v
)
2300 struct piece_closure
*c
2301 = (struct piece_closure
*) value_computed_closure (v
);
2308 for (i
= 0; i
< c
->n_pieces
; ++i
)
2309 if (c
->pieces
[i
].location
== DWARF_VALUE_STACK
)
2310 value_free (c
->pieces
[i
].v
.value
);
2317 /* Functions for accessing a variable described by DW_OP_piece. */
2318 static const struct lval_funcs pieced_value_funcs
= {
2321 indirect_pieced_value
,
2323 check_pieced_synthetic_pointer
,
2324 copy_pieced_value_closure
,
2325 free_pieced_value_closure
2328 /* Evaluate a location description, starting at DATA and with length
2329 SIZE, to find the current location of variable of TYPE in the
2330 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2331 location of the subobject of type SUBOBJ_TYPE at byte offset
2332 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2334 static struct value
*
2335 dwarf2_evaluate_loc_desc_full (struct type
*type
, struct frame_info
*frame
,
2336 const gdb_byte
*data
, size_t size
,
2337 struct dwarf2_per_cu_data
*per_cu
,
2338 struct type
*subobj_type
,
2339 LONGEST subobj_byte_offset
)
2341 struct value
*retval
;
2342 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2344 if (subobj_type
== NULL
)
2347 subobj_byte_offset
= 0;
2349 else if (subobj_byte_offset
< 0)
2350 invalid_synthetic_pointer ();
2353 return allocate_optimized_out_value (subobj_type
);
2355 dwarf_evaluate_loc_desc ctx
;
2357 ctx
.per_cu
= per_cu
;
2358 ctx
.obj_address
= 0;
2360 scoped_value_mark free_values
;
2362 ctx
.gdbarch
= get_objfile_arch (objfile
);
2363 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2364 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2365 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2369 ctx
.eval (data
, size
);
2371 CATCH (ex
, RETURN_MASK_ERROR
)
2373 if (ex
.error
== NOT_AVAILABLE_ERROR
)
2375 free_values
.free_to_mark ();
2376 retval
= allocate_value (subobj_type
);
2377 mark_value_bytes_unavailable (retval
, 0,
2378 TYPE_LENGTH (subobj_type
));
2381 else if (ex
.error
== NO_ENTRY_VALUE_ERROR
)
2383 if (entry_values_debug
)
2384 exception_print (gdb_stdout
, ex
);
2385 free_values
.free_to_mark ();
2386 return allocate_optimized_out_value (subobj_type
);
2389 throw_exception (ex
);
2393 if (ctx
.num_pieces
> 0)
2395 struct piece_closure
*c
;
2396 ULONGEST bit_size
= 0;
2399 for (i
= 0; i
< ctx
.num_pieces
; ++i
)
2400 bit_size
+= ctx
.pieces
[i
].size
;
2401 if (8 * (subobj_byte_offset
+ TYPE_LENGTH (subobj_type
)) > bit_size
)
2402 invalid_synthetic_pointer ();
2404 c
= allocate_piece_closure (per_cu
, ctx
.num_pieces
, ctx
.pieces
,
2406 /* We must clean up the value chain after creating the piece
2407 closure but before allocating the result. */
2408 free_values
.free_to_mark ();
2409 retval
= allocate_computed_value (subobj_type
,
2410 &pieced_value_funcs
, c
);
2411 set_value_offset (retval
, subobj_byte_offset
);
2415 switch (ctx
.location
)
2417 case DWARF_VALUE_REGISTER
:
2419 struct gdbarch
*arch
= get_frame_arch (frame
);
2421 = longest_to_int (value_as_long (ctx
.fetch (0)));
2422 int gdb_regnum
= dwarf_reg_to_regnum_or_error (arch
, dwarf_regnum
);
2424 if (subobj_byte_offset
!= 0)
2425 error (_("cannot use offset on synthetic pointer to register"));
2426 free_values
.free_to_mark ();
2427 retval
= value_from_register (subobj_type
, gdb_regnum
, frame
);
2428 if (value_optimized_out (retval
))
2432 /* This means the register has undefined value / was
2433 not saved. As we're computing the location of some
2434 variable etc. in the program, not a value for
2435 inspecting a register ($pc, $sp, etc.), return a
2436 generic optimized out value instead, so that we show
2437 <optimized out> instead of <not saved>. */
2438 tmp
= allocate_value (subobj_type
);
2439 value_contents_copy (tmp
, 0, retval
, 0,
2440 TYPE_LENGTH (subobj_type
));
2446 case DWARF_VALUE_MEMORY
:
2448 struct type
*ptr_type
;
2449 CORE_ADDR address
= ctx
.fetch_address (0);
2450 int in_stack_memory
= ctx
.fetch_in_stack_memory (0);
2452 /* DW_OP_deref_size (and possibly other operations too) may
2453 create a pointer instead of an address. Ideally, the
2454 pointer to address conversion would be performed as part
2455 of those operations, but the type of the object to
2456 which the address refers is not known at the time of
2457 the operation. Therefore, we do the conversion here
2458 since the type is readily available. */
2460 switch (TYPE_CODE (subobj_type
))
2462 case TYPE_CODE_FUNC
:
2463 case TYPE_CODE_METHOD
:
2464 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_func_ptr
;
2467 ptr_type
= builtin_type (ctx
.gdbarch
)->builtin_data_ptr
;
2470 address
= value_as_address (value_from_pointer (ptr_type
, address
));
2472 free_values
.free_to_mark ();
2473 retval
= value_at_lazy (subobj_type
,
2474 address
+ subobj_byte_offset
);
2475 if (in_stack_memory
)
2476 set_value_stack (retval
, 1);
2480 case DWARF_VALUE_STACK
:
2482 struct value
*value
= ctx
.fetch (0);
2483 size_t n
= TYPE_LENGTH (value_type (value
));
2484 size_t len
= TYPE_LENGTH (subobj_type
);
2485 size_t max
= TYPE_LENGTH (type
);
2486 struct gdbarch
*objfile_gdbarch
= get_objfile_arch (objfile
);
2487 struct cleanup
*cleanup
;
2489 if (subobj_byte_offset
+ len
> max
)
2490 invalid_synthetic_pointer ();
2492 /* Preserve VALUE because we are going to free values back
2493 to the mark, but we still need the value contents
2495 value_incref (value
);
2496 free_values
.free_to_mark ();
2497 cleanup
= make_cleanup_value_free (value
);
2499 retval
= allocate_value (subobj_type
);
2501 /* The given offset is relative to the actual object. */
2502 if (gdbarch_byte_order (objfile_gdbarch
) == BFD_ENDIAN_BIG
)
2503 subobj_byte_offset
+= n
- max
;
2505 memcpy (value_contents_raw (retval
),
2506 value_contents_all (value
) + subobj_byte_offset
, len
);
2508 do_cleanups (cleanup
);
2512 case DWARF_VALUE_LITERAL
:
2515 size_t n
= TYPE_LENGTH (subobj_type
);
2517 if (subobj_byte_offset
+ n
> ctx
.len
)
2518 invalid_synthetic_pointer ();
2520 free_values
.free_to_mark ();
2521 retval
= allocate_value (subobj_type
);
2522 contents
= value_contents_raw (retval
);
2523 memcpy (contents
, ctx
.data
+ subobj_byte_offset
, n
);
2527 case DWARF_VALUE_OPTIMIZED_OUT
:
2528 free_values
.free_to_mark ();
2529 retval
= allocate_optimized_out_value (subobj_type
);
2532 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2533 operation by execute_stack_op. */
2534 case DWARF_VALUE_IMPLICIT_POINTER
:
2535 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2536 it can only be encountered when making a piece. */
2538 internal_error (__FILE__
, __LINE__
, _("invalid location type"));
2542 set_value_initialized (retval
, ctx
.initialized
);
2547 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2548 passes 0 as the byte_offset. */
2551 dwarf2_evaluate_loc_desc (struct type
*type
, struct frame_info
*frame
,
2552 const gdb_byte
*data
, size_t size
,
2553 struct dwarf2_per_cu_data
*per_cu
)
2555 return dwarf2_evaluate_loc_desc_full (type
, frame
, data
, size
, per_cu
,
2559 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2560 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2561 frame in which the expression is evaluated. ADDR is a context (location of
2562 a variable) and might be needed to evaluate the location expression.
2563 Returns 1 on success, 0 otherwise. */
2566 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton
*dlbaton
,
2567 struct frame_info
*frame
,
2571 struct objfile
*objfile
;
2573 if (dlbaton
== NULL
|| dlbaton
->size
== 0)
2576 dwarf_evaluate_loc_desc ctx
;
2579 ctx
.per_cu
= dlbaton
->per_cu
;
2580 ctx
.obj_address
= addr
;
2582 objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
2584 ctx
.gdbarch
= get_objfile_arch (objfile
);
2585 ctx
.addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
2586 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (dlbaton
->per_cu
);
2587 ctx
.offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
2589 ctx
.eval (dlbaton
->data
, dlbaton
->size
);
2591 switch (ctx
.location
)
2593 case DWARF_VALUE_REGISTER
:
2594 case DWARF_VALUE_MEMORY
:
2595 case DWARF_VALUE_STACK
:
2596 *valp
= ctx
.fetch_address (0);
2597 if (ctx
.location
== DWARF_VALUE_REGISTER
)
2598 *valp
= ctx
.read_addr_from_reg (*valp
);
2600 case DWARF_VALUE_LITERAL
:
2601 *valp
= extract_signed_integer (ctx
.data
, ctx
.len
,
2602 gdbarch_byte_order (ctx
.gdbarch
));
2604 /* Unsupported dwarf values. */
2605 case DWARF_VALUE_OPTIMIZED_OUT
:
2606 case DWARF_VALUE_IMPLICIT_POINTER
:
2613 /* See dwarf2loc.h. */
2616 dwarf2_evaluate_property (const struct dynamic_prop
*prop
,
2617 struct frame_info
*frame
,
2618 struct property_addr_info
*addr_stack
,
2624 if (frame
== NULL
&& has_stack_frames ())
2625 frame
= get_selected_frame (NULL
);
2631 const struct dwarf2_property_baton
*baton
2632 = (const struct dwarf2_property_baton
*) prop
->data
.baton
;
2634 if (dwarf2_locexpr_baton_eval (&baton
->locexpr
, frame
,
2635 addr_stack
? addr_stack
->addr
: 0,
2638 if (baton
->referenced_type
)
2640 struct value
*val
= value_at (baton
->referenced_type
, *value
);
2642 *value
= value_as_address (val
);
2651 struct dwarf2_property_baton
*baton
2652 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2653 CORE_ADDR pc
= get_frame_address_in_block (frame
);
2654 const gdb_byte
*data
;
2658 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2661 val
= dwarf2_evaluate_loc_desc (baton
->referenced_type
, frame
, data
,
2662 size
, baton
->loclist
.per_cu
);
2663 if (!value_optimized_out (val
))
2665 *value
= value_as_address (val
);
2673 *value
= prop
->data
.const_val
;
2676 case PROP_ADDR_OFFSET
:
2678 struct dwarf2_property_baton
*baton
2679 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2680 struct property_addr_info
*pinfo
;
2683 for (pinfo
= addr_stack
; pinfo
!= NULL
; pinfo
= pinfo
->next
)
2684 if (pinfo
->type
== baton
->referenced_type
)
2687 error (_("cannot find reference address for offset property"));
2688 if (pinfo
->valaddr
!= NULL
)
2689 val
= value_from_contents
2690 (baton
->offset_info
.type
,
2691 pinfo
->valaddr
+ baton
->offset_info
.offset
);
2693 val
= value_at (baton
->offset_info
.type
,
2694 pinfo
->addr
+ baton
->offset_info
.offset
);
2695 *value
= value_as_address (val
);
2703 /* See dwarf2loc.h. */
2706 dwarf2_compile_property_to_c (string_file
&stream
,
2707 const char *result_name
,
2708 struct gdbarch
*gdbarch
,
2709 unsigned char *registers_used
,
2710 const struct dynamic_prop
*prop
,
2714 struct dwarf2_property_baton
*baton
2715 = (struct dwarf2_property_baton
*) prop
->data
.baton
;
2716 const gdb_byte
*data
;
2718 struct dwarf2_per_cu_data
*per_cu
;
2720 if (prop
->kind
== PROP_LOCEXPR
)
2722 data
= baton
->locexpr
.data
;
2723 size
= baton
->locexpr
.size
;
2724 per_cu
= baton
->locexpr
.per_cu
;
2728 gdb_assert (prop
->kind
== PROP_LOCLIST
);
2730 data
= dwarf2_find_location_expression (&baton
->loclist
, &size
, pc
);
2731 per_cu
= baton
->loclist
.per_cu
;
2734 compile_dwarf_bounds_to_c (stream
, result_name
, prop
, sym
, pc
,
2735 gdbarch
, registers_used
,
2736 dwarf2_per_cu_addr_size (per_cu
),
2737 data
, data
+ size
, per_cu
);
2741 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2743 class symbol_needs_eval_context
: public dwarf_expr_context
2747 enum symbol_needs_kind needs
;
2748 struct dwarf2_per_cu_data
*per_cu
;
2750 /* Reads from registers do require a frame. */
2751 CORE_ADDR
read_addr_from_reg (int regnum
) OVERRIDE
2753 needs
= SYMBOL_NEEDS_FRAME
;
2757 /* "get_reg_value" callback: Reads from registers do require a
2760 struct value
*get_reg_value (struct type
*type
, int regnum
) OVERRIDE
2762 needs
= SYMBOL_NEEDS_FRAME
;
2763 return value_zero (type
, not_lval
);
2766 /* Reads from memory do not require a frame. */
2767 void read_mem (gdb_byte
*buf
, CORE_ADDR addr
, size_t len
) OVERRIDE
2769 memset (buf
, 0, len
);
2772 /* Frame-relative accesses do require a frame. */
2773 void get_frame_base (const gdb_byte
**start
, size_t *length
) OVERRIDE
2775 static gdb_byte lit0
= DW_OP_lit0
;
2780 needs
= SYMBOL_NEEDS_FRAME
;
2783 /* CFA accesses require a frame. */
2784 CORE_ADDR
get_frame_cfa () OVERRIDE
2786 needs
= SYMBOL_NEEDS_FRAME
;
2790 CORE_ADDR
get_frame_pc () OVERRIDE
2792 needs
= SYMBOL_NEEDS_FRAME
;
2796 /* Thread-local accesses require registers, but not a frame. */
2797 CORE_ADDR
get_tls_address (CORE_ADDR offset
) OVERRIDE
2799 if (needs
<= SYMBOL_NEEDS_REGISTERS
)
2800 needs
= SYMBOL_NEEDS_REGISTERS
;
2804 /* Helper interface of per_cu_dwarf_call for
2805 dwarf2_loc_desc_get_symbol_read_needs. */
2807 void dwarf_call (cu_offset die_offset
) OVERRIDE
2809 per_cu_dwarf_call (this, die_offset
, per_cu
);
2812 /* DW_OP_entry_value accesses require a caller, therefore a
2815 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind
,
2816 union call_site_parameter_u kind_u
,
2817 int deref_size
) OVERRIDE
2819 needs
= SYMBOL_NEEDS_FRAME
;
2821 /* The expression may require some stub values on DWARF stack. */
2822 push_address (0, 0);
2825 /* DW_OP_GNU_addr_index doesn't require a frame. */
2827 CORE_ADDR
get_addr_index (unsigned int index
) OVERRIDE
2829 /* Nothing to do. */
2833 /* DW_OP_push_object_address has a frame already passed through. */
2835 CORE_ADDR
get_object_address () OVERRIDE
2837 /* Nothing to do. */
2842 /* Compute the correct symbol_needs_kind value for the location
2843 expression at DATA (length SIZE). */
2845 static enum symbol_needs_kind
2846 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte
*data
, size_t size
,
2847 struct dwarf2_per_cu_data
*per_cu
)
2850 struct objfile
*objfile
= dwarf2_per_cu_objfile (per_cu
);
2852 scoped_value_mark free_values
;
2854 symbol_needs_eval_context ctx
;
2856 ctx
.needs
= SYMBOL_NEEDS_NONE
;
2857 ctx
.per_cu
= per_cu
;
2858 ctx
.gdbarch
= get_objfile_arch (objfile
);
2859 ctx
.addr_size
= dwarf2_per_cu_addr_size (per_cu
);
2860 ctx
.ref_addr_size
= dwarf2_per_cu_ref_addr_size (per_cu
);
2861 ctx
.offset
= dwarf2_per_cu_text_offset (per_cu
);
2863 ctx
.eval (data
, size
);
2865 in_reg
= ctx
.location
== DWARF_VALUE_REGISTER
;
2867 if (ctx
.num_pieces
> 0)
2871 /* If the location has several pieces, and any of them are in
2872 registers, then we will need a frame to fetch them from. */
2873 for (i
= 0; i
< ctx
.num_pieces
; i
++)
2874 if (ctx
.pieces
[i
].location
== DWARF_VALUE_REGISTER
)
2879 ctx
.needs
= SYMBOL_NEEDS_FRAME
;
2883 /* A helper function that throws an unimplemented error mentioning a
2884 given DWARF operator. */
2887 unimplemented (unsigned int op
)
2889 const char *name
= get_DW_OP_name (op
);
2892 error (_("DWARF operator %s cannot be translated to an agent expression"),
2895 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2896 "to an agent expression"),
2902 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2903 can issue a complaint, which is better than having every target's
2904 implementation of dwarf2_reg_to_regnum do it. */
2907 dwarf_reg_to_regnum (struct gdbarch
*arch
, int dwarf_reg
)
2909 int reg
= gdbarch_dwarf2_reg_to_regnum (arch
, dwarf_reg
);
2913 complaint (&symfile_complaints
,
2914 _("bad DWARF register number %d"), dwarf_reg
);
2919 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2920 Throw an error because DWARF_REG is bad. */
2923 throw_bad_regnum_error (ULONGEST dwarf_reg
)
2925 /* Still want to print -1 as "-1".
2926 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2927 but that's overkill for now. */
2928 if ((int) dwarf_reg
== dwarf_reg
)
2929 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg
);
2930 error (_("Unable to access DWARF register number %s"),
2931 pulongest (dwarf_reg
));
2934 /* See dwarf2loc.h. */
2937 dwarf_reg_to_regnum_or_error (struct gdbarch
*arch
, ULONGEST dwarf_reg
)
2941 if (dwarf_reg
> INT_MAX
)
2942 throw_bad_regnum_error (dwarf_reg
);
2943 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2944 bad, but that's ok. */
2945 reg
= dwarf_reg_to_regnum (arch
, (int) dwarf_reg
);
2947 throw_bad_regnum_error (dwarf_reg
);
2951 /* A helper function that emits an access to memory. ARCH is the
2952 target architecture. EXPR is the expression which we are building.
2953 NBITS is the number of bits we want to read. This emits the
2954 opcodes needed to read the memory and then extract the desired
2958 access_memory (struct gdbarch
*arch
, struct agent_expr
*expr
, ULONGEST nbits
)
2960 ULONGEST nbytes
= (nbits
+ 7) / 8;
2962 gdb_assert (nbytes
> 0 && nbytes
<= sizeof (LONGEST
));
2965 ax_trace_quick (expr
, nbytes
);
2968 ax_simple (expr
, aop_ref8
);
2969 else if (nbits
<= 16)
2970 ax_simple (expr
, aop_ref16
);
2971 else if (nbits
<= 32)
2972 ax_simple (expr
, aop_ref32
);
2974 ax_simple (expr
, aop_ref64
);
2976 /* If we read exactly the number of bytes we wanted, we're done. */
2977 if (8 * nbytes
== nbits
)
2980 if (gdbarch_bits_big_endian (arch
))
2982 /* On a bits-big-endian machine, we want the high-order
2984 ax_const_l (expr
, 8 * nbytes
- nbits
);
2985 ax_simple (expr
, aop_rsh_unsigned
);
2989 /* On a bits-little-endian box, we want the low-order NBITS. */
2990 ax_zero_ext (expr
, nbits
);
2994 /* A helper function to return the frame's PC. */
2997 get_ax_pc (void *baton
)
2999 struct agent_expr
*expr
= (struct agent_expr
*) baton
;
3004 /* Compile a DWARF location expression to an agent expression.
3006 EXPR is the agent expression we are building.
3007 LOC is the agent value we modify.
3008 ARCH is the architecture.
3009 ADDR_SIZE is the size of addresses, in bytes.
3010 OP_PTR is the start of the location expression.
3011 OP_END is one past the last byte of the location expression.
3013 This will throw an exception for various kinds of errors -- for
3014 example, if the expression cannot be compiled, or if the expression
3018 dwarf2_compile_expr_to_ax (struct agent_expr
*expr
, struct axs_value
*loc
,
3019 struct gdbarch
*arch
, unsigned int addr_size
,
3020 const gdb_byte
*op_ptr
, const gdb_byte
*op_end
,
3021 struct dwarf2_per_cu_data
*per_cu
)
3024 std::vector
<int> dw_labels
, patches
;
3025 const gdb_byte
* const base
= op_ptr
;
3026 const gdb_byte
*previous_piece
= op_ptr
;
3027 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
3028 ULONGEST bits_collected
= 0;
3029 unsigned int addr_size_bits
= 8 * addr_size
;
3030 int bits_big_endian
= gdbarch_bits_big_endian (arch
);
3032 std::vector
<int> offsets (op_end
- op_ptr
, -1);
3034 /* By default we are making an address. */
3035 loc
->kind
= axs_lvalue_memory
;
3037 while (op_ptr
< op_end
)
3039 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *op_ptr
;
3040 uint64_t uoffset
, reg
;
3044 offsets
[op_ptr
- base
] = expr
->len
;
3047 /* Our basic approach to code generation is to map DWARF
3048 operations directly to AX operations. However, there are
3051 First, DWARF works on address-sized units, but AX always uses
3052 LONGEST. For most operations we simply ignore this
3053 difference; instead we generate sign extensions as needed
3054 before division and comparison operations. It would be nice
3055 to omit the sign extensions, but there is no way to determine
3056 the size of the target's LONGEST. (This code uses the size
3057 of the host LONGEST in some cases -- that is a bug but it is
3060 Second, some DWARF operations cannot be translated to AX.
3061 For these we simply fail. See
3062 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
3097 ax_const_l (expr
, op
- DW_OP_lit0
);
3101 uoffset
= extract_unsigned_integer (op_ptr
, addr_size
, byte_order
);
3102 op_ptr
+= addr_size
;
3103 /* Some versions of GCC emit DW_OP_addr before
3104 DW_OP_GNU_push_tls_address. In this case the value is an
3105 index, not an address. We don't support things like
3106 branching between the address and the TLS op. */
3107 if (op_ptr
>= op_end
|| *op_ptr
!= DW_OP_GNU_push_tls_address
)
3108 uoffset
+= dwarf2_per_cu_text_offset (per_cu
);
3109 ax_const_l (expr
, uoffset
);
3113 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 1, byte_order
));
3117 ax_const_l (expr
, extract_signed_integer (op_ptr
, 1, byte_order
));
3121 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 2, byte_order
));
3125 ax_const_l (expr
, extract_signed_integer (op_ptr
, 2, byte_order
));
3129 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 4, byte_order
));
3133 ax_const_l (expr
, extract_signed_integer (op_ptr
, 4, byte_order
));
3137 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, 8, byte_order
));
3141 ax_const_l (expr
, extract_signed_integer (op_ptr
, 8, byte_order
));
3145 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &uoffset
);
3146 ax_const_l (expr
, uoffset
);
3149 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3150 ax_const_l (expr
, offset
);
3185 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3186 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_reg0
);
3187 loc
->kind
= axs_lvalue_register
;
3191 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3192 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_regx");
3193 loc
->u
.reg
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3194 loc
->kind
= axs_lvalue_register
;
3197 case DW_OP_implicit_value
:
3201 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &len
);
3202 if (op_ptr
+ len
> op_end
)
3203 error (_("DW_OP_implicit_value: too few bytes available."));
3204 if (len
> sizeof (ULONGEST
))
3205 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3208 ax_const_l (expr
, extract_unsigned_integer (op_ptr
, len
,
3211 dwarf_expr_require_composition (op_ptr
, op_end
,
3212 "DW_OP_implicit_value");
3214 loc
->kind
= axs_rvalue
;
3218 case DW_OP_stack_value
:
3219 dwarf_expr_require_composition (op_ptr
, op_end
, "DW_OP_stack_value");
3220 loc
->kind
= axs_rvalue
;
3255 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3256 i
= dwarf_reg_to_regnum_or_error (arch
, op
- DW_OP_breg0
);
3260 ax_const_l (expr
, offset
);
3261 ax_simple (expr
, aop_add
);
3266 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3267 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3268 i
= dwarf_reg_to_regnum_or_error (arch
, reg
);
3272 ax_const_l (expr
, offset
);
3273 ax_simple (expr
, aop_add
);
3279 const gdb_byte
*datastart
;
3281 const struct block
*b
;
3282 struct symbol
*framefunc
;
3284 b
= block_for_pc (expr
->scope
);
3287 error (_("No block found for address"));
3289 framefunc
= block_linkage_function (b
);
3292 error (_("No function found for block"));
3294 func_get_frame_base_dwarf_block (framefunc
, expr
->scope
,
3295 &datastart
, &datalen
);
3297 op_ptr
= safe_read_sleb128 (op_ptr
, op_end
, &offset
);
3298 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
, datastart
,
3299 datastart
+ datalen
, per_cu
);
3300 if (loc
->kind
== axs_lvalue_register
)
3301 require_rvalue (expr
, loc
);
3305 ax_const_l (expr
, offset
);
3306 ax_simple (expr
, aop_add
);
3309 loc
->kind
= axs_lvalue_memory
;
3314 ax_simple (expr
, aop_dup
);
3318 ax_simple (expr
, aop_pop
);
3323 ax_pick (expr
, offset
);
3327 ax_simple (expr
, aop_swap
);
3335 ax_simple (expr
, aop_rot
);
3339 case DW_OP_deref_size
:
3343 if (op
== DW_OP_deref_size
)
3348 if (size
!= 1 && size
!= 2 && size
!= 4 && size
!= 8)
3349 error (_("Unsupported size %d in %s"),
3350 size
, get_DW_OP_name (op
));
3351 access_memory (arch
, expr
, size
* TARGET_CHAR_BIT
);
3356 /* Sign extend the operand. */
3357 ax_ext (expr
, addr_size_bits
);
3358 ax_simple (expr
, aop_dup
);
3359 ax_const_l (expr
, 0);
3360 ax_simple (expr
, aop_less_signed
);
3361 ax_simple (expr
, aop_log_not
);
3362 i
= ax_goto (expr
, aop_if_goto
);
3363 /* We have to emit 0 - X. */
3364 ax_const_l (expr
, 0);
3365 ax_simple (expr
, aop_swap
);
3366 ax_simple (expr
, aop_sub
);
3367 ax_label (expr
, i
, expr
->len
);
3371 /* No need to sign extend here. */
3372 ax_const_l (expr
, 0);
3373 ax_simple (expr
, aop_swap
);
3374 ax_simple (expr
, aop_sub
);
3378 /* Sign extend the operand. */
3379 ax_ext (expr
, addr_size_bits
);
3380 ax_simple (expr
, aop_bit_not
);
3383 case DW_OP_plus_uconst
:
3384 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, ®
);
3385 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3386 but we micro-optimize anyhow. */
3389 ax_const_l (expr
, reg
);
3390 ax_simple (expr
, aop_add
);
3395 ax_simple (expr
, aop_bit_and
);
3399 /* Sign extend the operands. */
3400 ax_ext (expr
, addr_size_bits
);
3401 ax_simple (expr
, aop_swap
);
3402 ax_ext (expr
, addr_size_bits
);
3403 ax_simple (expr
, aop_swap
);
3404 ax_simple (expr
, aop_div_signed
);
3408 ax_simple (expr
, aop_sub
);
3412 ax_simple (expr
, aop_rem_unsigned
);
3416 ax_simple (expr
, aop_mul
);
3420 ax_simple (expr
, aop_bit_or
);
3424 ax_simple (expr
, aop_add
);
3428 ax_simple (expr
, aop_lsh
);
3432 ax_simple (expr
, aop_rsh_unsigned
);
3436 ax_simple (expr
, aop_rsh_signed
);
3440 ax_simple (expr
, aop_bit_xor
);
3444 /* Sign extend the operands. */
3445 ax_ext (expr
, addr_size_bits
);
3446 ax_simple (expr
, aop_swap
);
3447 ax_ext (expr
, addr_size_bits
);
3448 /* Note no swap here: A <= B is !(B < A). */
3449 ax_simple (expr
, aop_less_signed
);
3450 ax_simple (expr
, aop_log_not
);
3454 /* Sign extend the operands. */
3455 ax_ext (expr
, addr_size_bits
);
3456 ax_simple (expr
, aop_swap
);
3457 ax_ext (expr
, addr_size_bits
);
3458 ax_simple (expr
, aop_swap
);
3459 /* A >= B is !(A < B). */
3460 ax_simple (expr
, aop_less_signed
);
3461 ax_simple (expr
, aop_log_not
);
3465 /* Sign extend the operands. */
3466 ax_ext (expr
, addr_size_bits
);
3467 ax_simple (expr
, aop_swap
);
3468 ax_ext (expr
, addr_size_bits
);
3469 /* No need for a second swap here. */
3470 ax_simple (expr
, aop_equal
);
3474 /* Sign extend the operands. */
3475 ax_ext (expr
, addr_size_bits
);
3476 ax_simple (expr
, aop_swap
);
3477 ax_ext (expr
, addr_size_bits
);
3478 ax_simple (expr
, aop_swap
);
3479 ax_simple (expr
, aop_less_signed
);
3483 /* Sign extend the operands. */
3484 ax_ext (expr
, addr_size_bits
);
3485 ax_simple (expr
, aop_swap
);
3486 ax_ext (expr
, addr_size_bits
);
3487 /* Note no swap here: A > B is B < A. */
3488 ax_simple (expr
, aop_less_signed
);
3492 /* Sign extend the operands. */
3493 ax_ext (expr
, addr_size_bits
);
3494 ax_simple (expr
, aop_swap
);
3495 ax_ext (expr
, addr_size_bits
);
3496 /* No need for a swap here. */
3497 ax_simple (expr
, aop_equal
);
3498 ax_simple (expr
, aop_log_not
);
3501 case DW_OP_call_frame_cfa
:
3504 CORE_ADDR text_offset
;
3506 const gdb_byte
*cfa_start
, *cfa_end
;
3508 if (dwarf2_fetch_cfa_info (arch
, expr
->scope
, per_cu
,
3510 &text_offset
, &cfa_start
, &cfa_end
))
3513 ax_reg (expr
, regnum
);
3516 ax_const_l (expr
, off
);
3517 ax_simple (expr
, aop_add
);
3522 /* Another expression. */
3523 ax_const_l (expr
, text_offset
);
3524 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3525 cfa_start
, cfa_end
, per_cu
);
3528 loc
->kind
= axs_lvalue_memory
;
3532 case DW_OP_GNU_push_tls_address
:
3533 case DW_OP_form_tls_address
:
3537 case DW_OP_push_object_address
:
3542 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3544 i
= ax_goto (expr
, aop_goto
);
3545 dw_labels
.push_back (op_ptr
+ offset
- base
);
3546 patches
.push_back (i
);
3550 offset
= extract_signed_integer (op_ptr
, 2, byte_order
);
3552 /* Zero extend the operand. */
3553 ax_zero_ext (expr
, addr_size_bits
);
3554 i
= ax_goto (expr
, aop_if_goto
);
3555 dw_labels
.push_back (op_ptr
+ offset
- base
);
3556 patches
.push_back (i
);
3563 case DW_OP_bit_piece
:
3565 uint64_t size
, offset
;
3567 if (op_ptr
- 1 == previous_piece
)
3568 error (_("Cannot translate empty pieces to agent expressions"));
3569 previous_piece
= op_ptr
- 1;
3571 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &size
);
3572 if (op
== DW_OP_piece
)
3578 op_ptr
= safe_read_uleb128 (op_ptr
, op_end
, &offset
);
3580 if (bits_collected
+ size
> 8 * sizeof (LONGEST
))
3581 error (_("Expression pieces exceed word size"));
3583 /* Access the bits. */
3586 case axs_lvalue_register
:
3587 ax_reg (expr
, loc
->u
.reg
);
3590 case axs_lvalue_memory
:
3591 /* Offset the pointer, if needed. */
3594 ax_const_l (expr
, offset
/ 8);
3595 ax_simple (expr
, aop_add
);
3598 access_memory (arch
, expr
, size
);
3602 /* For a bits-big-endian target, shift up what we already
3603 have. For a bits-little-endian target, shift up the
3604 new data. Note that there is a potential bug here if
3605 the DWARF expression leaves multiple values on the
3607 if (bits_collected
> 0)
3609 if (bits_big_endian
)
3611 ax_simple (expr
, aop_swap
);
3612 ax_const_l (expr
, size
);
3613 ax_simple (expr
, aop_lsh
);
3614 /* We don't need a second swap here, because
3615 aop_bit_or is symmetric. */
3619 ax_const_l (expr
, size
);
3620 ax_simple (expr
, aop_lsh
);
3622 ax_simple (expr
, aop_bit_or
);
3625 bits_collected
+= size
;
3626 loc
->kind
= axs_rvalue
;
3630 case DW_OP_GNU_uninit
:
3636 struct dwarf2_locexpr_baton block
;
3637 int size
= (op
== DW_OP_call2
? 2 : 4);
3639 uoffset
= extract_unsigned_integer (op_ptr
, size
, byte_order
);
3642 cu_offset offset
= (cu_offset
) uoffset
;
3643 block
= dwarf2_fetch_die_loc_cu_off (offset
, per_cu
,
3646 /* DW_OP_call_ref is currently not supported. */
3647 gdb_assert (block
.per_cu
== per_cu
);
3649 dwarf2_compile_expr_to_ax (expr
, loc
, arch
, addr_size
,
3650 block
.data
, block
.data
+ block
.size
,
3655 case DW_OP_call_ref
:
3663 /* Patch all the branches we emitted. */
3664 for (i
= 0; i
< patches
.size (); ++i
)
3666 int targ
= offsets
[dw_labels
[i
]];
3668 internal_error (__FILE__
, __LINE__
, _("invalid label"));
3669 ax_label (expr
, patches
[i
], targ
);
3674 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3675 evaluator to calculate the location. */
3676 static struct value
*
3677 locexpr_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
3679 struct dwarf2_locexpr_baton
*dlbaton
3680 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3683 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3684 dlbaton
->size
, dlbaton
->per_cu
);
3689 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3690 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3693 static struct value
*
3694 locexpr_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
3696 struct dwarf2_locexpr_baton
*dlbaton
3697 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3699 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, dlbaton
->data
,
3703 /* Implementation of get_symbol_read_needs from
3704 symbol_computed_ops. */
3706 static enum symbol_needs_kind
3707 locexpr_get_symbol_read_needs (struct symbol
*symbol
)
3709 struct dwarf2_locexpr_baton
*dlbaton
3710 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
3712 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton
->data
, dlbaton
->size
,
3716 /* Return true if DATA points to the end of a piece. END is one past
3717 the last byte in the expression. */
3720 piece_end_p (const gdb_byte
*data
, const gdb_byte
*end
)
3722 return data
== end
|| data
[0] == DW_OP_piece
|| data
[0] == DW_OP_bit_piece
;
3725 /* Helper for locexpr_describe_location_piece that finds the name of a
3729 locexpr_regname (struct gdbarch
*gdbarch
, int dwarf_regnum
)
3733 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3734 We'd rather print *something* here than throw an error. */
3735 regnum
= dwarf_reg_to_regnum (gdbarch
, dwarf_regnum
);
3736 /* gdbarch_register_name may just return "", return something more
3737 descriptive for bad register numbers. */
3740 /* The text is output as "$bad_register_number".
3741 That is why we use the underscores. */
3742 return _("bad_register_number");
3744 return gdbarch_register_name (gdbarch
, regnum
);
3747 /* Nicely describe a single piece of a location, returning an updated
3748 position in the bytecode sequence. This function cannot recognize
3749 all locations; if a location is not recognized, it simply returns
3750 DATA. If there is an error during reading, e.g. we run off the end
3751 of the buffer, an error is thrown. */
3753 static const gdb_byte
*
3754 locexpr_describe_location_piece (struct symbol
*symbol
, struct ui_file
*stream
,
3755 CORE_ADDR addr
, struct objfile
*objfile
,
3756 struct dwarf2_per_cu_data
*per_cu
,
3757 const gdb_byte
*data
, const gdb_byte
*end
,
3758 unsigned int addr_size
)
3760 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3763 if (data
[0] >= DW_OP_reg0
&& data
[0] <= DW_OP_reg31
)
3765 fprintf_filtered (stream
, _("a variable in $%s"),
3766 locexpr_regname (gdbarch
, data
[0] - DW_OP_reg0
));
3769 else if (data
[0] == DW_OP_regx
)
3773 data
= safe_read_uleb128 (data
+ 1, end
, ®
);
3774 fprintf_filtered (stream
, _("a variable in $%s"),
3775 locexpr_regname (gdbarch
, reg
));
3777 else if (data
[0] == DW_OP_fbreg
)
3779 const struct block
*b
;
3780 struct symbol
*framefunc
;
3782 int64_t frame_offset
;
3783 const gdb_byte
*base_data
, *new_data
, *save_data
= data
;
3785 int64_t base_offset
= 0;
3787 new_data
= safe_read_sleb128 (data
+ 1, end
, &frame_offset
);
3788 if (!piece_end_p (new_data
, end
))
3792 b
= block_for_pc (addr
);
3795 error (_("No block found for address for symbol \"%s\"."),
3796 SYMBOL_PRINT_NAME (symbol
));
3798 framefunc
= block_linkage_function (b
);
3801 error (_("No function found for block for symbol \"%s\"."),
3802 SYMBOL_PRINT_NAME (symbol
));
3804 func_get_frame_base_dwarf_block (framefunc
, addr
, &base_data
, &base_size
);
3806 if (base_data
[0] >= DW_OP_breg0
&& base_data
[0] <= DW_OP_breg31
)
3808 const gdb_byte
*buf_end
;
3810 frame_reg
= base_data
[0] - DW_OP_breg0
;
3811 buf_end
= safe_read_sleb128 (base_data
+ 1, base_data
+ base_size
,
3813 if (buf_end
!= base_data
+ base_size
)
3814 error (_("Unexpected opcode after "
3815 "DW_OP_breg%u for symbol \"%s\"."),
3816 frame_reg
, SYMBOL_PRINT_NAME (symbol
));
3818 else if (base_data
[0] >= DW_OP_reg0
&& base_data
[0] <= DW_OP_reg31
)
3820 /* The frame base is just the register, with no offset. */
3821 frame_reg
= base_data
[0] - DW_OP_reg0
;
3826 /* We don't know what to do with the frame base expression,
3827 so we can't trace this variable; give up. */
3831 fprintf_filtered (stream
,
3832 _("a variable at frame base reg $%s offset %s+%s"),
3833 locexpr_regname (gdbarch
, frame_reg
),
3834 plongest (base_offset
), plongest (frame_offset
));
3836 else if (data
[0] >= DW_OP_breg0
&& data
[0] <= DW_OP_breg31
3837 && piece_end_p (data
, end
))
3841 data
= safe_read_sleb128 (data
+ 1, end
, &offset
);
3843 fprintf_filtered (stream
,
3844 _("a variable at offset %s from base reg $%s"),
3846 locexpr_regname (gdbarch
, data
[0] - DW_OP_breg0
));
3849 /* The location expression for a TLS variable looks like this (on a
3852 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3853 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3855 0x3 is the encoding for DW_OP_addr, which has an operand as long
3856 as the size of an address on the target machine (here is 8
3857 bytes). Note that more recent version of GCC emit DW_OP_const4u
3858 or DW_OP_const8u, depending on address size, rather than
3859 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3860 The operand represents the offset at which the variable is within
3861 the thread local storage. */
3863 else if (data
+ 1 + addr_size
< end
3864 && (data
[0] == DW_OP_addr
3865 || (addr_size
== 4 && data
[0] == DW_OP_const4u
)
3866 || (addr_size
== 8 && data
[0] == DW_OP_const8u
))
3867 && (data
[1 + addr_size
] == DW_OP_GNU_push_tls_address
3868 || data
[1 + addr_size
] == DW_OP_form_tls_address
)
3869 && piece_end_p (data
+ 2 + addr_size
, end
))
3872 offset
= extract_unsigned_integer (data
+ 1, addr_size
,
3873 gdbarch_byte_order (gdbarch
));
3875 fprintf_filtered (stream
,
3876 _("a thread-local variable at offset 0x%s "
3877 "in the thread-local storage for `%s'"),
3878 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3880 data
+= 1 + addr_size
+ 1;
3883 /* With -gsplit-dwarf a TLS variable can also look like this:
3884 DW_AT_location : 3 byte block: fc 4 e0
3885 (DW_OP_GNU_const_index: 4;
3886 DW_OP_GNU_push_tls_address) */
3887 else if (data
+ 3 <= end
3888 && data
+ 1 + (leb128_size
= skip_leb128 (data
+ 1, end
)) < end
3889 && data
[0] == DW_OP_GNU_const_index
3891 && (data
[1 + leb128_size
] == DW_OP_GNU_push_tls_address
3892 || data
[1 + leb128_size
] == DW_OP_form_tls_address
)
3893 && piece_end_p (data
+ 2 + leb128_size
, end
))
3897 data
= safe_read_uleb128 (data
+ 1, end
, &offset
);
3898 offset
= dwarf2_read_addr_index (per_cu
, offset
);
3899 fprintf_filtered (stream
,
3900 _("a thread-local variable at offset 0x%s "
3901 "in the thread-local storage for `%s'"),
3902 phex_nz (offset
, addr_size
), objfile_name (objfile
));
3906 else if (data
[0] >= DW_OP_lit0
3907 && data
[0] <= DW_OP_lit31
3909 && data
[1] == DW_OP_stack_value
)
3911 fprintf_filtered (stream
, _("the constant %d"), data
[0] - DW_OP_lit0
);
3918 /* Disassemble an expression, stopping at the end of a piece or at the
3919 end of the expression. Returns a pointer to the next unread byte
3920 in the input expression. If ALL is nonzero, then this function
3921 will keep going until it reaches the end of the expression.
3922 If there is an error during reading, e.g. we run off the end
3923 of the buffer, an error is thrown. */
3925 static const gdb_byte
*
3926 disassemble_dwarf_expression (struct ui_file
*stream
,
3927 struct gdbarch
*arch
, unsigned int addr_size
,
3928 int offset_size
, const gdb_byte
*start
,
3929 const gdb_byte
*data
, const gdb_byte
*end
,
3930 int indent
, int all
,
3931 struct dwarf2_per_cu_data
*per_cu
)
3935 || (data
[0] != DW_OP_piece
&& data
[0] != DW_OP_bit_piece
)))
3937 enum dwarf_location_atom op
= (enum dwarf_location_atom
) *data
++;
3942 name
= get_DW_OP_name (op
);
3945 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3946 op
, (long) (data
- 1 - start
));
3947 fprintf_filtered (stream
, " %*ld: %s", indent
+ 4,
3948 (long) (data
- 1 - start
), name
);
3953 ul
= extract_unsigned_integer (data
, addr_size
,
3954 gdbarch_byte_order (arch
));
3956 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
3960 ul
= extract_unsigned_integer (data
, 1, gdbarch_byte_order (arch
));
3962 fprintf_filtered (stream
, " %s", pulongest (ul
));
3965 l
= extract_signed_integer (data
, 1, gdbarch_byte_order (arch
));
3967 fprintf_filtered (stream
, " %s", plongest (l
));
3970 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
3972 fprintf_filtered (stream
, " %s", pulongest (ul
));
3975 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
3977 fprintf_filtered (stream
, " %s", plongest (l
));
3980 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
3982 fprintf_filtered (stream
, " %s", pulongest (ul
));
3985 l
= extract_signed_integer (data
, 4, gdbarch_byte_order (arch
));
3987 fprintf_filtered (stream
, " %s", plongest (l
));
3990 ul
= extract_unsigned_integer (data
, 8, gdbarch_byte_order (arch
));
3992 fprintf_filtered (stream
, " %s", pulongest (ul
));
3995 l
= extract_signed_integer (data
, 8, gdbarch_byte_order (arch
));
3997 fprintf_filtered (stream
, " %s", plongest (l
));
4000 data
= safe_read_uleb128 (data
, end
, &ul
);
4001 fprintf_filtered (stream
, " %s", pulongest (ul
));
4004 data
= safe_read_sleb128 (data
, end
, &l
);
4005 fprintf_filtered (stream
, " %s", plongest (l
));
4040 fprintf_filtered (stream
, " [$%s]",
4041 locexpr_regname (arch
, op
- DW_OP_reg0
));
4045 data
= safe_read_uleb128 (data
, end
, &ul
);
4046 fprintf_filtered (stream
, " %s [$%s]", pulongest (ul
),
4047 locexpr_regname (arch
, (int) ul
));
4050 case DW_OP_implicit_value
:
4051 data
= safe_read_uleb128 (data
, end
, &ul
);
4053 fprintf_filtered (stream
, " %s", pulongest (ul
));
4088 data
= safe_read_sleb128 (data
, end
, &l
);
4089 fprintf_filtered (stream
, " %s [$%s]", plongest (l
),
4090 locexpr_regname (arch
, op
- DW_OP_breg0
));
4094 data
= safe_read_uleb128 (data
, end
, &ul
);
4095 data
= safe_read_sleb128 (data
, end
, &l
);
4096 fprintf_filtered (stream
, " register %s [$%s] offset %s",
4098 locexpr_regname (arch
, (int) ul
),
4103 data
= safe_read_sleb128 (data
, end
, &l
);
4104 fprintf_filtered (stream
, " %s", plongest (l
));
4107 case DW_OP_xderef_size
:
4108 case DW_OP_deref_size
:
4110 fprintf_filtered (stream
, " %d", *data
);
4114 case DW_OP_plus_uconst
:
4115 data
= safe_read_uleb128 (data
, end
, &ul
);
4116 fprintf_filtered (stream
, " %s", pulongest (ul
));
4120 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4122 fprintf_filtered (stream
, " to %ld",
4123 (long) (data
+ l
- start
));
4127 l
= extract_signed_integer (data
, 2, gdbarch_byte_order (arch
));
4129 fprintf_filtered (stream
, " %ld",
4130 (long) (data
+ l
- start
));
4134 ul
= extract_unsigned_integer (data
, 2, gdbarch_byte_order (arch
));
4136 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 2));
4140 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4142 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4145 case DW_OP_call_ref
:
4146 ul
= extract_unsigned_integer (data
, offset_size
,
4147 gdbarch_byte_order (arch
));
4148 data
+= offset_size
;
4149 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, offset_size
));
4153 data
= safe_read_uleb128 (data
, end
, &ul
);
4154 fprintf_filtered (stream
, " %s (bytes)", pulongest (ul
));
4157 case DW_OP_bit_piece
:
4161 data
= safe_read_uleb128 (data
, end
, &ul
);
4162 data
= safe_read_uleb128 (data
, end
, &offset
);
4163 fprintf_filtered (stream
, " size %s offset %s (bits)",
4164 pulongest (ul
), pulongest (offset
));
4168 case DW_OP_implicit_pointer
:
4169 case DW_OP_GNU_implicit_pointer
:
4171 ul
= extract_unsigned_integer (data
, offset_size
,
4172 gdbarch_byte_order (arch
));
4173 data
+= offset_size
;
4175 data
= safe_read_sleb128 (data
, end
, &l
);
4177 fprintf_filtered (stream
, " DIE %s offset %s",
4178 phex_nz (ul
, offset_size
),
4183 case DW_OP_deref_type
:
4184 case DW_OP_GNU_deref_type
:
4186 int addr_size
= *data
++;
4189 data
= safe_read_uleb128 (data
, end
, &ul
);
4190 cu_offset offset
= (cu_offset
) ul
;
4191 type
= dwarf2_get_die_type (offset
, per_cu
);
4192 fprintf_filtered (stream
, "<");
4193 type_print (type
, "", stream
, -1);
4194 fprintf_filtered (stream
, " [0x%s]> %d",
4195 phex_nz (to_underlying (offset
), 0),
4200 case DW_OP_const_type
:
4201 case DW_OP_GNU_const_type
:
4205 data
= safe_read_uleb128 (data
, end
, &ul
);
4206 cu_offset type_die
= (cu_offset
) ul
;
4207 type
= dwarf2_get_die_type (type_die
, per_cu
);
4208 fprintf_filtered (stream
, "<");
4209 type_print (type
, "", stream
, -1);
4210 fprintf_filtered (stream
, " [0x%s]>",
4211 phex_nz (to_underlying (type_die
), 0));
4215 case DW_OP_regval_type
:
4216 case DW_OP_GNU_regval_type
:
4221 data
= safe_read_uleb128 (data
, end
, ®
);
4222 data
= safe_read_uleb128 (data
, end
, &ul
);
4223 cu_offset type_die
= (cu_offset
) ul
;
4225 type
= dwarf2_get_die_type (type_die
, per_cu
);
4226 fprintf_filtered (stream
, "<");
4227 type_print (type
, "", stream
, -1);
4228 fprintf_filtered (stream
, " [0x%s]> [$%s]",
4229 phex_nz (to_underlying (type_die
), 0),
4230 locexpr_regname (arch
, reg
));
4235 case DW_OP_GNU_convert
:
4236 case DW_OP_reinterpret
:
4237 case DW_OP_GNU_reinterpret
:
4239 data
= safe_read_uleb128 (data
, end
, &ul
);
4240 cu_offset type_die
= (cu_offset
) ul
;
4242 if (to_underlying (type_die
) == 0)
4243 fprintf_filtered (stream
, "<0>");
4248 type
= dwarf2_get_die_type (type_die
, per_cu
);
4249 fprintf_filtered (stream
, "<");
4250 type_print (type
, "", stream
, -1);
4251 fprintf_filtered (stream
, " [0x%s]>",
4252 phex_nz (to_underlying (type_die
), 0));
4257 case DW_OP_entry_value
:
4258 case DW_OP_GNU_entry_value
:
4259 data
= safe_read_uleb128 (data
, end
, &ul
);
4260 fputc_filtered ('\n', stream
);
4261 disassemble_dwarf_expression (stream
, arch
, addr_size
, offset_size
,
4262 start
, data
, data
+ ul
, indent
+ 2,
4267 case DW_OP_GNU_parameter_ref
:
4268 ul
= extract_unsigned_integer (data
, 4, gdbarch_byte_order (arch
));
4270 fprintf_filtered (stream
, " offset %s", phex_nz (ul
, 4));
4273 case DW_OP_GNU_addr_index
:
4274 data
= safe_read_uleb128 (data
, end
, &ul
);
4275 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4276 fprintf_filtered (stream
, " 0x%s", phex_nz (ul
, addr_size
));
4278 case DW_OP_GNU_const_index
:
4279 data
= safe_read_uleb128 (data
, end
, &ul
);
4280 ul
= dwarf2_read_addr_index (per_cu
, ul
);
4281 fprintf_filtered (stream
, " %s", pulongest (ul
));
4285 fprintf_filtered (stream
, "\n");
4291 /* Describe a single location, which may in turn consist of multiple
4295 locexpr_describe_location_1 (struct symbol
*symbol
, CORE_ADDR addr
,
4296 struct ui_file
*stream
,
4297 const gdb_byte
*data
, size_t size
,
4298 struct objfile
*objfile
, unsigned int addr_size
,
4299 int offset_size
, struct dwarf2_per_cu_data
*per_cu
)
4301 const gdb_byte
*end
= data
+ size
;
4302 int first_piece
= 1, bad
= 0;
4306 const gdb_byte
*here
= data
;
4307 int disassemble
= 1;
4312 fprintf_filtered (stream
, _(", and "));
4314 if (!dwarf_always_disassemble
)
4316 data
= locexpr_describe_location_piece (symbol
, stream
,
4317 addr
, objfile
, per_cu
,
4318 data
, end
, addr_size
);
4319 /* If we printed anything, or if we have an empty piece,
4320 then don't disassemble. */
4322 || data
[0] == DW_OP_piece
4323 || data
[0] == DW_OP_bit_piece
)
4328 fprintf_filtered (stream
, _("a complex DWARF expression:\n"));
4329 data
= disassemble_dwarf_expression (stream
,
4330 get_objfile_arch (objfile
),
4331 addr_size
, offset_size
, data
,
4333 dwarf_always_disassemble
,
4339 int empty
= data
== here
;
4342 fprintf_filtered (stream
, " ");
4343 if (data
[0] == DW_OP_piece
)
4347 data
= safe_read_uleb128 (data
+ 1, end
, &bytes
);
4350 fprintf_filtered (stream
, _("an empty %s-byte piece"),
4353 fprintf_filtered (stream
, _(" [%s-byte piece]"),
4356 else if (data
[0] == DW_OP_bit_piece
)
4358 uint64_t bits
, offset
;
4360 data
= safe_read_uleb128 (data
+ 1, end
, &bits
);
4361 data
= safe_read_uleb128 (data
, end
, &offset
);
4364 fprintf_filtered (stream
,
4365 _("an empty %s-bit piece"),
4368 fprintf_filtered (stream
,
4369 _(" [%s-bit piece, offset %s bits]"),
4370 pulongest (bits
), pulongest (offset
));
4380 if (bad
|| data
> end
)
4381 error (_("Corrupted DWARF2 expression for \"%s\"."),
4382 SYMBOL_PRINT_NAME (symbol
));
4385 /* Print a natural-language description of SYMBOL to STREAM. This
4386 version is for a symbol with a single location. */
4389 locexpr_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4390 struct ui_file
*stream
)
4392 struct dwarf2_locexpr_baton
*dlbaton
4393 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4394 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4395 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4396 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4398 locexpr_describe_location_1 (symbol
, addr
, stream
,
4399 dlbaton
->data
, dlbaton
->size
,
4400 objfile
, addr_size
, offset_size
,
4404 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4405 any necessary bytecode in AX. */
4408 locexpr_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4409 struct agent_expr
*ax
, struct axs_value
*value
)
4411 struct dwarf2_locexpr_baton
*dlbaton
4412 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4413 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4415 if (dlbaton
->size
== 0)
4416 value
->optimized_out
= 1;
4418 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
,
4419 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4423 /* symbol_computed_ops 'generate_c_location' method. */
4426 locexpr_generate_c_location (struct symbol
*sym
, string_file
&stream
,
4427 struct gdbarch
*gdbarch
,
4428 unsigned char *registers_used
,
4429 CORE_ADDR pc
, const char *result_name
)
4431 struct dwarf2_locexpr_baton
*dlbaton
4432 = (struct dwarf2_locexpr_baton
*) SYMBOL_LOCATION_BATON (sym
);
4433 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4435 if (dlbaton
->size
== 0)
4436 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4438 compile_dwarf_expr_to_c (stream
, result_name
,
4439 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4440 dlbaton
->data
, dlbaton
->data
+ dlbaton
->size
,
4444 /* The set of location functions used with the DWARF-2 expression
4446 const struct symbol_computed_ops dwarf2_locexpr_funcs
= {
4447 locexpr_read_variable
,
4448 locexpr_read_variable_at_entry
,
4449 locexpr_get_symbol_read_needs
,
4450 locexpr_describe_location
,
4451 0, /* location_has_loclist */
4452 locexpr_tracepoint_var_ref
,
4453 locexpr_generate_c_location
4457 /* Wrapper functions for location lists. These generally find
4458 the appropriate location expression and call something above. */
4460 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4461 evaluator to calculate the location. */
4462 static struct value
*
4463 loclist_read_variable (struct symbol
*symbol
, struct frame_info
*frame
)
4465 struct dwarf2_loclist_baton
*dlbaton
4466 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4468 const gdb_byte
*data
;
4470 CORE_ADDR pc
= frame
? get_frame_address_in_block (frame
) : 0;
4472 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4473 val
= dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol
), frame
, data
, size
,
4479 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4480 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4483 Function always returns non-NULL value, it may be marked optimized out if
4484 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4485 if it cannot resolve the parameter for any reason. */
4487 static struct value
*
4488 loclist_read_variable_at_entry (struct symbol
*symbol
, struct frame_info
*frame
)
4490 struct dwarf2_loclist_baton
*dlbaton
4491 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4492 const gdb_byte
*data
;
4496 if (frame
== NULL
|| !get_frame_func_if_available (frame
, &pc
))
4497 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4499 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4501 return allocate_optimized_out_value (SYMBOL_TYPE (symbol
));
4503 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol
), frame
, data
, size
);
4506 /* Implementation of get_symbol_read_needs from
4507 symbol_computed_ops. */
4509 static enum symbol_needs_kind
4510 loclist_symbol_needs (struct symbol
*symbol
)
4512 /* If there's a location list, then assume we need to have a frame
4513 to choose the appropriate location expression. With tracking of
4514 global variables this is not necessarily true, but such tracking
4515 is disabled in GCC at the moment until we figure out how to
4518 return SYMBOL_NEEDS_FRAME
;
4521 /* Print a natural-language description of SYMBOL to STREAM. This
4522 version applies when there is a list of different locations, each
4523 with a specified address range. */
4526 loclist_describe_location (struct symbol
*symbol
, CORE_ADDR addr
,
4527 struct ui_file
*stream
)
4529 struct dwarf2_loclist_baton
*dlbaton
4530 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4531 const gdb_byte
*loc_ptr
, *buf_end
;
4532 struct objfile
*objfile
= dwarf2_per_cu_objfile (dlbaton
->per_cu
);
4533 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4534 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4535 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4536 int offset_size
= dwarf2_per_cu_offset_size (dlbaton
->per_cu
);
4537 int signed_addr_p
= bfd_get_sign_extend_vma (objfile
->obfd
);
4538 /* Adjust base_address for relocatable objects. */
4539 CORE_ADDR base_offset
= dwarf2_per_cu_text_offset (dlbaton
->per_cu
);
4540 CORE_ADDR base_address
= dlbaton
->base_address
+ base_offset
;
4543 loc_ptr
= dlbaton
->data
;
4544 buf_end
= dlbaton
->data
+ dlbaton
->size
;
4546 fprintf_filtered (stream
, _("multi-location:\n"));
4548 /* Iterate through locations until we run out. */
4551 CORE_ADDR low
= 0, high
= 0; /* init for gcc -Wall */
4553 enum debug_loc_kind kind
;
4554 const gdb_byte
*new_ptr
= NULL
; /* init for gcc -Wall */
4556 if (dlbaton
->from_dwo
)
4557 kind
= decode_debug_loc_dwo_addresses (dlbaton
->per_cu
,
4558 loc_ptr
, buf_end
, &new_ptr
,
4559 &low
, &high
, byte_order
);
4561 kind
= decode_debug_loc_addresses (loc_ptr
, buf_end
, &new_ptr
,
4563 byte_order
, addr_size
,
4568 case DEBUG_LOC_END_OF_LIST
:
4571 case DEBUG_LOC_BASE_ADDRESS
:
4572 base_address
= high
+ base_offset
;
4573 fprintf_filtered (stream
, _(" Base address %s"),
4574 paddress (gdbarch
, base_address
));
4576 case DEBUG_LOC_START_END
:
4577 case DEBUG_LOC_START_LENGTH
:
4579 case DEBUG_LOC_BUFFER_OVERFLOW
:
4580 case DEBUG_LOC_INVALID_ENTRY
:
4581 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4582 SYMBOL_PRINT_NAME (symbol
));
4584 gdb_assert_not_reached ("bad debug_loc_kind");
4587 /* Otherwise, a location expression entry. */
4588 low
+= base_address
;
4589 high
+= base_address
;
4591 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
);
4592 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
);
4594 length
= extract_unsigned_integer (loc_ptr
, 2, byte_order
);
4597 /* (It would improve readability to print only the minimum
4598 necessary digits of the second number of the range.) */
4599 fprintf_filtered (stream
, _(" Range %s-%s: "),
4600 paddress (gdbarch
, low
), paddress (gdbarch
, high
));
4602 /* Now describe this particular location. */
4603 locexpr_describe_location_1 (symbol
, low
, stream
, loc_ptr
, length
,
4604 objfile
, addr_size
, offset_size
,
4607 fprintf_filtered (stream
, "\n");
4613 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4614 any necessary bytecode in AX. */
4616 loclist_tracepoint_var_ref (struct symbol
*symbol
, struct gdbarch
*gdbarch
,
4617 struct agent_expr
*ax
, struct axs_value
*value
)
4619 struct dwarf2_loclist_baton
*dlbaton
4620 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (symbol
);
4621 const gdb_byte
*data
;
4623 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4625 data
= dwarf2_find_location_expression (dlbaton
, &size
, ax
->scope
);
4627 value
->optimized_out
= 1;
4629 dwarf2_compile_expr_to_ax (ax
, value
, gdbarch
, addr_size
, data
, data
+ size
,
4633 /* symbol_computed_ops 'generate_c_location' method. */
4636 loclist_generate_c_location (struct symbol
*sym
, string_file
&stream
,
4637 struct gdbarch
*gdbarch
,
4638 unsigned char *registers_used
,
4639 CORE_ADDR pc
, const char *result_name
)
4641 struct dwarf2_loclist_baton
*dlbaton
4642 = (struct dwarf2_loclist_baton
*) SYMBOL_LOCATION_BATON (sym
);
4643 unsigned int addr_size
= dwarf2_per_cu_addr_size (dlbaton
->per_cu
);
4644 const gdb_byte
*data
;
4647 data
= dwarf2_find_location_expression (dlbaton
, &size
, pc
);
4649 error (_("symbol \"%s\" is optimized out"), SYMBOL_NATURAL_NAME (sym
));
4651 compile_dwarf_expr_to_c (stream
, result_name
,
4652 sym
, pc
, gdbarch
, registers_used
, addr_size
,
4657 /* The set of location functions used with the DWARF-2 expression
4658 evaluator and location lists. */
4659 const struct symbol_computed_ops dwarf2_loclist_funcs
= {
4660 loclist_read_variable
,
4661 loclist_read_variable_at_entry
,
4662 loclist_symbol_needs
,
4663 loclist_describe_location
,
4664 1, /* location_has_loclist */
4665 loclist_tracepoint_var_ref
,
4666 loclist_generate_c_location
4669 /* Provide a prototype to silence -Wmissing-prototypes. */
4670 extern initialize_file_ftype _initialize_dwarf2loc
;
4673 _initialize_dwarf2loc (void)
4675 add_setshow_zuinteger_cmd ("entry-values", class_maintenance
,
4676 &entry_values_debug
,
4677 _("Set entry values and tail call frames "
4679 _("Show entry values and tail call frames "
4681 _("When non-zero, the process of determining "
4682 "parameter values from function entry point "
4683 "and tail call frames will be printed."),
4685 show_entry_values_debug
,
4686 &setdebuglist
, &showdebuglist
);
4689 register_self_test (selftests::copy_bitwise_tests
);