8df655f660ab64e2e16b8fb873619c48ee8b3731
[deliverable/binutils-gdb.git] / gdb / dwarf2 / loc.c
1 /* DWARF 2 location expression support for GDB.
2
3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
4
5 Contributed by Daniel Jacobowitz, MontaVista Software, Inc.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23 #include "ui-out.h"
24 #include "value.h"
25 #include "frame.h"
26 #include "gdbcore.h"
27 #include "target.h"
28 #include "inferior.h"
29 #include "ax.h"
30 #include "ax-gdb.h"
31 #include "regcache.h"
32 #include "objfiles.h"
33 #include "block.h"
34 #include "gdbcmd.h"
35 #include "complaints.h"
36 #include "dwarf2.h"
37 #include "dwarf2/expr.h"
38 #include "dwarf2/loc.h"
39 #include "dwarf2/read.h"
40 #include "dwarf2/frame.h"
41 #include "dwarf2/leb.h"
42 #include "compile/compile.h"
43 #include "gdbsupport/selftest.h"
44 #include <algorithm>
45 #include <vector>
46 #include <unordered_set>
47 #include "gdbsupport/underlying.h"
48 #include "gdbsupport/byte-vector.h"
49
50 static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
51 struct frame_info *frame,
52 const gdb_byte *data,
53 size_t size,
54 struct dwarf2_per_cu_data *per_cu,
55 struct type *subobj_type,
56 LONGEST subobj_byte_offset);
57
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);
63
64 static struct value *indirect_synthetic_pointer
65 (sect_offset die, LONGEST byte_offset,
66 struct dwarf2_per_cu_data *per_cu,
67 struct frame_info *frame,
68 struct type *type, bool resolve_abstract_p = false);
69
70 /* Until these have formal names, we define these here.
71 ref: http://gcc.gnu.org/wiki/DebugFission
72 Each entry in .debug_loc.dwo begins with a byte that describes the entry,
73 and is then followed by data specific to that entry. */
74
75 enum debug_loc_kind
76 {
77 /* Indicates the end of the list of entries. */
78 DEBUG_LOC_END_OF_LIST = 0,
79
80 /* This is followed by an unsigned LEB128 number that is an index into
81 .debug_addr and specifies the base address for all following entries. */
82 DEBUG_LOC_BASE_ADDRESS = 1,
83
84 /* This is followed by two unsigned LEB128 numbers that are indices into
85 .debug_addr and specify the beginning and ending addresses, and then
86 a normal location expression as in .debug_loc. */
87 DEBUG_LOC_START_END = 2,
88
89 /* This is followed by an unsigned LEB128 number that is an index into
90 .debug_addr and specifies the beginning address, and a 4 byte unsigned
91 number that specifies the length, and then a normal location expression
92 as in .debug_loc. */
93 DEBUG_LOC_START_LENGTH = 3,
94
95 /* This is followed by two unsigned LEB128 operands. The values of these
96 operands are the starting and ending offsets, respectively, relative to
97 the applicable base address. */
98 DEBUG_LOC_OFFSET_PAIR = 4,
99
100 /* An internal value indicating there is insufficient data. */
101 DEBUG_LOC_BUFFER_OVERFLOW = -1,
102
103 /* An internal value indicating an invalid kind of entry was found. */
104 DEBUG_LOC_INVALID_ENTRY = -2
105 };
106
107 /* Helper function which throws an error if a synthetic pointer is
108 invalid. */
109
110 static void
111 invalid_synthetic_pointer (void)
112 {
113 error (_("access outside bounds of object "
114 "referenced via synthetic pointer"));
115 }
116
117 /* Decode the addresses in a non-dwo .debug_loc entry.
118 A pointer to the next byte to examine is returned in *NEW_PTR.
119 The encoded low,high addresses are return in *LOW,*HIGH.
120 The result indicates the kind of entry found. */
121
122 static enum debug_loc_kind
123 decode_debug_loc_addresses (const gdb_byte *loc_ptr, const gdb_byte *buf_end,
124 const gdb_byte **new_ptr,
125 CORE_ADDR *low, CORE_ADDR *high,
126 enum bfd_endian byte_order,
127 unsigned int addr_size,
128 int signed_addr_p)
129 {
130 CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
131
132 if (buf_end - loc_ptr < 2 * addr_size)
133 return DEBUG_LOC_BUFFER_OVERFLOW;
134
135 if (signed_addr_p)
136 *low = extract_signed_integer (loc_ptr, addr_size, byte_order);
137 else
138 *low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
139 loc_ptr += addr_size;
140
141 if (signed_addr_p)
142 *high = extract_signed_integer (loc_ptr, addr_size, byte_order);
143 else
144 *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
145 loc_ptr += addr_size;
146
147 *new_ptr = loc_ptr;
148
149 /* A base-address-selection entry. */
150 if ((*low & base_mask) == base_mask)
151 return DEBUG_LOC_BASE_ADDRESS;
152
153 /* An end-of-list entry. */
154 if (*low == 0 && *high == 0)
155 return DEBUG_LOC_END_OF_LIST;
156
157 return DEBUG_LOC_START_END;
158 }
159
160 /* Decode the addresses in .debug_loclists entry.
161 A pointer to the next byte to examine is returned in *NEW_PTR.
162 The encoded low,high addresses are return in *LOW,*HIGH.
163 The result indicates the kind of entry found. */
164
165 static enum debug_loc_kind
166 decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
167 const gdb_byte *loc_ptr,
168 const gdb_byte *buf_end,
169 const gdb_byte **new_ptr,
170 CORE_ADDR *low, CORE_ADDR *high,
171 enum bfd_endian byte_order,
172 unsigned int addr_size,
173 int signed_addr_p)
174 {
175 uint64_t u64;
176
177 if (loc_ptr == buf_end)
178 return DEBUG_LOC_BUFFER_OVERFLOW;
179
180 switch (*loc_ptr++)
181 {
182 case DW_LLE_base_addressx:
183 *low = 0;
184 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
185 if (loc_ptr == NULL)
186 return DEBUG_LOC_BUFFER_OVERFLOW;
187 *high = dwarf2_read_addr_index (per_cu, u64);
188 *new_ptr = loc_ptr;
189 return DEBUG_LOC_BASE_ADDRESS;
190 case DW_LLE_startx_length:
191 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
192 if (loc_ptr == NULL)
193 return DEBUG_LOC_BUFFER_OVERFLOW;
194 *low = dwarf2_read_addr_index (per_cu, u64);
195 *high = *low;
196 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
197 if (loc_ptr == NULL)
198 return DEBUG_LOC_BUFFER_OVERFLOW;
199 *high += u64;
200 *new_ptr = loc_ptr;
201 return DEBUG_LOC_START_LENGTH;
202 case DW_LLE_start_length:
203 if (buf_end - loc_ptr < addr_size)
204 return DEBUG_LOC_BUFFER_OVERFLOW;
205 if (signed_addr_p)
206 *low = extract_signed_integer (loc_ptr, addr_size, byte_order);
207 else
208 *low = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
209 loc_ptr += addr_size;
210 *high = *low;
211 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
212 if (loc_ptr == NULL)
213 return DEBUG_LOC_BUFFER_OVERFLOW;
214 *high += u64;
215 *new_ptr = loc_ptr;
216 return DEBUG_LOC_START_LENGTH;
217 case DW_LLE_end_of_list:
218 *new_ptr = loc_ptr;
219 return DEBUG_LOC_END_OF_LIST;
220 case DW_LLE_base_address:
221 if (loc_ptr + addr_size > buf_end)
222 return DEBUG_LOC_BUFFER_OVERFLOW;
223 if (signed_addr_p)
224 *high = extract_signed_integer (loc_ptr, addr_size, byte_order);
225 else
226 *high = extract_unsigned_integer (loc_ptr, addr_size, byte_order);
227 loc_ptr += addr_size;
228 *new_ptr = loc_ptr;
229 return DEBUG_LOC_BASE_ADDRESS;
230 case DW_LLE_offset_pair:
231 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
232 if (loc_ptr == NULL)
233 return DEBUG_LOC_BUFFER_OVERFLOW;
234 *low = u64;
235 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
236 if (loc_ptr == NULL)
237 return DEBUG_LOC_BUFFER_OVERFLOW;
238 *high = u64;
239 *new_ptr = loc_ptr;
240 return DEBUG_LOC_OFFSET_PAIR;
241 /* Following cases are not supported yet. */
242 case DW_LLE_startx_endx:
243 case DW_LLE_start_end:
244 case DW_LLE_default_location:
245 default:
246 return DEBUG_LOC_INVALID_ENTRY;
247 }
248 }
249
250 /* Decode the addresses in .debug_loc.dwo entry.
251 A pointer to the next byte to examine is returned in *NEW_PTR.
252 The encoded low,high addresses are return in *LOW,*HIGH.
253 The result indicates the kind of entry found. */
254
255 static enum debug_loc_kind
256 decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
257 const gdb_byte *loc_ptr,
258 const gdb_byte *buf_end,
259 const gdb_byte **new_ptr,
260 CORE_ADDR *low, CORE_ADDR *high,
261 enum bfd_endian byte_order)
262 {
263 uint64_t low_index, high_index;
264
265 if (loc_ptr == buf_end)
266 return DEBUG_LOC_BUFFER_OVERFLOW;
267
268 switch (*loc_ptr++)
269 {
270 case DW_LLE_GNU_end_of_list_entry:
271 *new_ptr = loc_ptr;
272 return DEBUG_LOC_END_OF_LIST;
273 case DW_LLE_GNU_base_address_selection_entry:
274 *low = 0;
275 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
276 if (loc_ptr == NULL)
277 return DEBUG_LOC_BUFFER_OVERFLOW;
278 *high = dwarf2_read_addr_index (per_cu, high_index);
279 *new_ptr = loc_ptr;
280 return DEBUG_LOC_BASE_ADDRESS;
281 case DW_LLE_GNU_start_end_entry:
282 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
283 if (loc_ptr == NULL)
284 return DEBUG_LOC_BUFFER_OVERFLOW;
285 *low = dwarf2_read_addr_index (per_cu, low_index);
286 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
287 if (loc_ptr == NULL)
288 return DEBUG_LOC_BUFFER_OVERFLOW;
289 *high = dwarf2_read_addr_index (per_cu, high_index);
290 *new_ptr = loc_ptr;
291 return DEBUG_LOC_START_END;
292 case DW_LLE_GNU_start_length_entry:
293 loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
294 if (loc_ptr == NULL)
295 return DEBUG_LOC_BUFFER_OVERFLOW;
296 *low = dwarf2_read_addr_index (per_cu, low_index);
297 if (loc_ptr + 4 > buf_end)
298 return DEBUG_LOC_BUFFER_OVERFLOW;
299 *high = *low;
300 *high += extract_unsigned_integer (loc_ptr, 4, byte_order);
301 *new_ptr = loc_ptr + 4;
302 return DEBUG_LOC_START_LENGTH;
303 default:
304 return DEBUG_LOC_INVALID_ENTRY;
305 }
306 }
307
308 /* A function for dealing with location lists. Given a
309 symbol baton (BATON) and a pc value (PC), find the appropriate
310 location expression, set *LOCEXPR_LENGTH, and return a pointer
311 to the beginning of the expression. Returns NULL on failure.
312
313 For now, only return the first matching location expression; there
314 can be more than one in the list. */
315
316 const gdb_byte *
317 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
318 size_t *locexpr_length, CORE_ADDR pc)
319 {
320 struct objfile *objfile = baton->per_cu->objfile ();
321 struct gdbarch *gdbarch = objfile->arch ();
322 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
323 unsigned int addr_size = baton->per_cu->addr_size ();
324 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
325 /* Adjust base_address for relocatable objects. */
326 CORE_ADDR base_offset = baton->per_cu->text_offset ();
327 CORE_ADDR base_address = baton->base_address + base_offset;
328 const gdb_byte *loc_ptr, *buf_end;
329
330 loc_ptr = baton->data;
331 buf_end = baton->data + baton->size;
332
333 while (1)
334 {
335 CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */
336 int length;
337 enum debug_loc_kind kind;
338 const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
339
340 if (baton->per_cu->version () < 5 && baton->from_dwo)
341 kind = decode_debug_loc_dwo_addresses (baton->per_cu,
342 loc_ptr, buf_end, &new_ptr,
343 &low, &high, byte_order);
344 else if (baton->per_cu->version () < 5)
345 kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
346 &low, &high,
347 byte_order, addr_size,
348 signed_addr_p);
349 else
350 kind = decode_debug_loclists_addresses (baton->per_cu,
351 loc_ptr, buf_end, &new_ptr,
352 &low, &high, byte_order,
353 addr_size, signed_addr_p);
354
355 loc_ptr = new_ptr;
356 switch (kind)
357 {
358 case DEBUG_LOC_END_OF_LIST:
359 *locexpr_length = 0;
360 return NULL;
361 case DEBUG_LOC_BASE_ADDRESS:
362 base_address = high + base_offset;
363 continue;
364 case DEBUG_LOC_START_END:
365 case DEBUG_LOC_START_LENGTH:
366 case DEBUG_LOC_OFFSET_PAIR:
367 break;
368 case DEBUG_LOC_BUFFER_OVERFLOW:
369 case DEBUG_LOC_INVALID_ENTRY:
370 error (_("dwarf2_find_location_expression: "
371 "Corrupted DWARF expression."));
372 default:
373 gdb_assert_not_reached ("bad debug_loc_kind");
374 }
375
376 /* Otherwise, a location expression entry.
377 If the entry is from a DWO, don't add base address: the entry is from
378 .debug_addr which already has the DWARF "base address". We still add
379 base_offset in case we're debugging a PIE executable. However, if the
380 entry is DW_LLE_offset_pair from a DWO, add the base address as the
381 operands are offsets relative to the applicable base address. */
382 if (baton->from_dwo && kind != DEBUG_LOC_OFFSET_PAIR)
383 {
384 low += base_offset;
385 high += base_offset;
386 }
387 else
388 {
389 low += base_address;
390 high += base_address;
391 }
392
393 if (baton->per_cu->version () < 5)
394 {
395 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
396 loc_ptr += 2;
397 }
398 else
399 {
400 unsigned int bytes_read;
401
402 length = read_unsigned_leb128 (NULL, loc_ptr, &bytes_read);
403 loc_ptr += bytes_read;
404 }
405
406 if (low == high && pc == low)
407 {
408 /* This is entry PC record present only at entry point
409 of a function. Verify it is really the function entry point. */
410
411 const struct block *pc_block = block_for_pc (pc);
412 struct symbol *pc_func = NULL;
413
414 if (pc_block)
415 pc_func = block_linkage_function (pc_block);
416
417 if (pc_func && pc == BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (pc_func)))
418 {
419 *locexpr_length = length;
420 return loc_ptr;
421 }
422 }
423
424 if (pc >= low && pc < high)
425 {
426 *locexpr_length = length;
427 return loc_ptr;
428 }
429
430 loc_ptr += length;
431 }
432 }
433
434 /* Implement find_frame_base_location method for LOC_BLOCK functions using
435 DWARF expression for its DW_AT_frame_base. */
436
437 static void
438 locexpr_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
439 const gdb_byte **start, size_t *length)
440 {
441 struct dwarf2_locexpr_baton *symbaton
442 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (framefunc);
443
444 *length = symbaton->size;
445 *start = symbaton->data;
446 }
447
448 /* Implement the struct symbol_block_ops::get_frame_base method for
449 LOC_BLOCK functions using a DWARF expression as its DW_AT_frame_base. */
450
451 static CORE_ADDR
452 locexpr_get_frame_base (struct symbol *framefunc, struct frame_info *frame)
453 {
454 struct gdbarch *gdbarch;
455 struct type *type;
456 struct dwarf2_locexpr_baton *dlbaton;
457 const gdb_byte *start;
458 size_t length;
459 struct value *result;
460
461 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
462 Thus, it's supposed to provide the find_frame_base_location method as
463 well. */
464 gdb_assert (SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location != NULL);
465
466 gdbarch = get_frame_arch (frame);
467 type = builtin_type (gdbarch)->builtin_data_ptr;
468 dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (framefunc);
469
470 SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
471 (framefunc, get_frame_pc (frame), &start, &length);
472 result = dwarf2_evaluate_loc_desc (type, frame, start, length,
473 dlbaton->per_cu);
474
475 /* The DW_AT_frame_base attribute contains a location description which
476 computes the base address itself. However, the call to
477 dwarf2_evaluate_loc_desc returns a value representing a variable at
478 that address. The frame base address is thus this variable's
479 address. */
480 return value_address (result);
481 }
482
483 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
484 function uses DWARF expression for its DW_AT_frame_base. */
485
486 const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs =
487 {
488 locexpr_find_frame_base_location,
489 locexpr_get_frame_base
490 };
491
492 /* Implement find_frame_base_location method for LOC_BLOCK functions using
493 DWARF location list for its DW_AT_frame_base. */
494
495 static void
496 loclist_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
497 const gdb_byte **start, size_t *length)
498 {
499 struct dwarf2_loclist_baton *symbaton
500 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (framefunc);
501
502 *start = dwarf2_find_location_expression (symbaton, length, pc);
503 }
504
505 /* Implement the struct symbol_block_ops::get_frame_base method for
506 LOC_BLOCK functions using a DWARF location list as its DW_AT_frame_base. */
507
508 static CORE_ADDR
509 loclist_get_frame_base (struct symbol *framefunc, struct frame_info *frame)
510 {
511 struct gdbarch *gdbarch;
512 struct type *type;
513 struct dwarf2_loclist_baton *dlbaton;
514 const gdb_byte *start;
515 size_t length;
516 struct value *result;
517
518 /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
519 Thus, it's supposed to provide the find_frame_base_location method as
520 well. */
521 gdb_assert (SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location != NULL);
522
523 gdbarch = get_frame_arch (frame);
524 type = builtin_type (gdbarch)->builtin_data_ptr;
525 dlbaton = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (framefunc);
526
527 SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
528 (framefunc, get_frame_pc (frame), &start, &length);
529 result = dwarf2_evaluate_loc_desc (type, frame, start, length,
530 dlbaton->per_cu);
531
532 /* The DW_AT_frame_base attribute contains a location description which
533 computes the base address itself. However, the call to
534 dwarf2_evaluate_loc_desc returns a value representing a variable at
535 that address. The frame base address is thus this variable's
536 address. */
537 return value_address (result);
538 }
539
540 /* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
541 function uses DWARF location list for its DW_AT_frame_base. */
542
543 const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs =
544 {
545 loclist_find_frame_base_location,
546 loclist_get_frame_base
547 };
548
549 /* See dwarf2loc.h. */
550
551 void
552 func_get_frame_base_dwarf_block (struct symbol *framefunc, CORE_ADDR pc,
553 const gdb_byte **start, size_t *length)
554 {
555 if (SYMBOL_BLOCK_OPS (framefunc) != NULL)
556 {
557 const struct symbol_block_ops *ops_block = SYMBOL_BLOCK_OPS (framefunc);
558
559 ops_block->find_frame_base_location (framefunc, pc, start, length);
560 }
561 else
562 *length = 0;
563
564 if (*length == 0)
565 error (_("Could not find the frame base for \"%s\"."),
566 framefunc->natural_name ());
567 }
568
569 static CORE_ADDR
570 get_frame_pc_for_per_cu_dwarf_call (void *baton)
571 {
572 dwarf_expr_context *ctx = (dwarf_expr_context *) baton;
573
574 return ctx->get_frame_pc ();
575 }
576
577 static void
578 per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset,
579 struct dwarf2_per_cu_data *per_cu)
580 {
581 struct dwarf2_locexpr_baton block;
582
583 block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu,
584 get_frame_pc_for_per_cu_dwarf_call,
585 ctx);
586
587 /* DW_OP_call_ref is currently not supported. */
588 gdb_assert (block.per_cu == per_cu);
589
590 ctx->eval (block.data, block.size);
591 }
592
593 /* Given context CTX, section offset SECT_OFF, and compilation unit
594 data PER_CU, execute the "variable value" operation on the DIE
595 found at SECT_OFF. */
596
597 static struct value *
598 sect_variable_value (struct dwarf_expr_context *ctx, sect_offset sect_off,
599 struct dwarf2_per_cu_data *per_cu)
600 {
601 struct type *die_type = dwarf2_fetch_die_type_sect_off (sect_off, per_cu);
602
603 if (die_type == NULL)
604 error (_("Bad DW_OP_GNU_variable_value DIE."));
605
606 /* Note: Things still work when the following test is removed. This
607 test and error is here to conform to the proposed specification. */
608 if (TYPE_CODE (die_type) != TYPE_CODE_INT
609 && TYPE_CODE (die_type) != TYPE_CODE_PTR)
610 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
611
612 struct type *type = lookup_pointer_type (die_type);
613 struct frame_info *frame = get_selected_frame (_("No frame selected."));
614 return indirect_synthetic_pointer (sect_off, 0, per_cu, frame, type, true);
615 }
616
617 class dwarf_evaluate_loc_desc : public dwarf_expr_context
618 {
619 public:
620
621 struct frame_info *frame;
622 struct dwarf2_per_cu_data *per_cu;
623 CORE_ADDR obj_address;
624
625 /* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
626 the frame in BATON. */
627
628 CORE_ADDR get_frame_cfa () override
629 {
630 return dwarf2_frame_cfa (frame);
631 }
632
633 /* Helper function for dwarf2_evaluate_loc_desc. Computes the PC for
634 the frame in BATON. */
635
636 CORE_ADDR get_frame_pc () override
637 {
638 return get_frame_address_in_block (frame);
639 }
640
641 /* Using the objfile specified in BATON, find the address for the
642 current thread's thread-local storage with offset OFFSET. */
643 CORE_ADDR get_tls_address (CORE_ADDR offset) override
644 {
645 struct objfile *objfile = per_cu->objfile ();
646
647 return target_translate_tls_address (objfile, offset);
648 }
649
650 /* Helper interface of per_cu_dwarf_call for
651 dwarf2_evaluate_loc_desc. */
652
653 void dwarf_call (cu_offset die_offset) override
654 {
655 per_cu_dwarf_call (this, die_offset, per_cu);
656 }
657
658 /* Helper interface of sect_variable_value for
659 dwarf2_evaluate_loc_desc. */
660
661 struct value *dwarf_variable_value (sect_offset sect_off) override
662 {
663 return sect_variable_value (this, sect_off, per_cu);
664 }
665
666 struct type *get_base_type (cu_offset die_offset, int size) override
667 {
668 struct type *result = dwarf2_get_die_type (die_offset, per_cu);
669 if (result == NULL)
670 error (_("Could not find type for DW_OP_const_type"));
671 if (size != 0 && TYPE_LENGTH (result) != size)
672 error (_("DW_OP_const_type has different sizes for type and data"));
673 return result;
674 }
675
676 /* Callback function for dwarf2_evaluate_loc_desc.
677 Fetch the address indexed by DW_OP_addrx or DW_OP_GNU_addr_index. */
678
679 CORE_ADDR get_addr_index (unsigned int index) override
680 {
681 return dwarf2_read_addr_index (per_cu, index);
682 }
683
684 /* Callback function for get_object_address. Return the address of the VLA
685 object. */
686
687 CORE_ADDR get_object_address () override
688 {
689 if (obj_address == 0)
690 error (_("Location address is not set."));
691 return obj_address;
692 }
693
694 /* Execute DWARF block of call_site_parameter which matches KIND and
695 KIND_U. Choose DEREF_SIZE value of that parameter. Search
696 caller of this objects's frame.
697
698 The caller can be from a different CU - per_cu_dwarf_call
699 implementation can be more simple as it does not support cross-CU
700 DWARF executions. */
701
702 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind,
703 union call_site_parameter_u kind_u,
704 int deref_size) override
705 {
706 struct frame_info *caller_frame;
707 struct dwarf2_per_cu_data *caller_per_cu;
708 struct call_site_parameter *parameter;
709 const gdb_byte *data_src;
710 size_t size;
711
712 caller_frame = get_prev_frame (frame);
713
714 parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
715 &caller_per_cu);
716 data_src = deref_size == -1 ? parameter->value : parameter->data_value;
717 size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
718
719 /* DEREF_SIZE size is not verified here. */
720 if (data_src == NULL)
721 throw_error (NO_ENTRY_VALUE_ERROR,
722 _("Cannot resolve DW_AT_call_data_value"));
723
724 scoped_restore save_frame = make_scoped_restore (&this->frame,
725 caller_frame);
726 scoped_restore save_per_cu = make_scoped_restore (&this->per_cu,
727 caller_per_cu);
728 scoped_restore save_obj_addr = make_scoped_restore (&this->obj_address,
729 (CORE_ADDR) 0);
730
731 scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
732 this->gdbarch = per_cu->objfile ()->arch ();
733 scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
734 this->addr_size = per_cu->addr_size ();
735 scoped_restore save_offset = make_scoped_restore (&this->offset);
736 this->offset = per_cu->text_offset ();
737
738 this->eval (data_src, size);
739 }
740
741 /* Using the frame specified in BATON, find the location expression
742 describing the frame base. Return a pointer to it in START and
743 its length in LENGTH. */
744 void get_frame_base (const gdb_byte **start, size_t * length) override
745 {
746 /* FIXME: cagney/2003-03-26: This code should be using
747 get_frame_base_address(), and then implement a dwarf2 specific
748 this_base method. */
749 struct symbol *framefunc;
750 const struct block *bl = get_frame_block (frame, NULL);
751
752 if (bl == NULL)
753 error (_("frame address is not available."));
754
755 /* Use block_linkage_function, which returns a real (not inlined)
756 function, instead of get_frame_function, which may return an
757 inlined function. */
758 framefunc = block_linkage_function (bl);
759
760 /* If we found a frame-relative symbol then it was certainly within
761 some function associated with a frame. If we can't find the frame,
762 something has gone wrong. */
763 gdb_assert (framefunc != NULL);
764
765 func_get_frame_base_dwarf_block (framefunc,
766 get_frame_address_in_block (frame),
767 start, length);
768 }
769
770 /* Read memory at ADDR (length LEN) into BUF. */
771
772 void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override
773 {
774 read_memory (addr, buf, len);
775 }
776
777 /* Using the frame specified in BATON, return the value of register
778 REGNUM, treated as a pointer. */
779 CORE_ADDR read_addr_from_reg (int dwarf_regnum) override
780 {
781 struct gdbarch *gdbarch = get_frame_arch (frame);
782 int regnum = dwarf_reg_to_regnum_or_error (gdbarch, dwarf_regnum);
783
784 return address_from_register (regnum, frame);
785 }
786
787 /* Implement "get_reg_value" callback. */
788
789 struct value *get_reg_value (struct type *type, int dwarf_regnum) override
790 {
791 struct gdbarch *gdbarch = get_frame_arch (frame);
792 int regnum = dwarf_reg_to_regnum_or_error (gdbarch, dwarf_regnum);
793
794 return value_from_register (type, regnum, frame);
795 }
796 };
797
798 /* See dwarf2loc.h. */
799
800 unsigned int entry_values_debug = 0;
801
802 /* Helper to set entry_values_debug. */
803
804 static void
805 show_entry_values_debug (struct ui_file *file, int from_tty,
806 struct cmd_list_element *c, const char *value)
807 {
808 fprintf_filtered (file,
809 _("Entry values and tail call frames debugging is %s.\n"),
810 value);
811 }
812
813 /* Find DW_TAG_call_site's DW_AT_call_target address.
814 CALLER_FRAME (for registers) can be NULL if it is not known. This function
815 always returns valid address or it throws NO_ENTRY_VALUE_ERROR. */
816
817 static CORE_ADDR
818 call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
819 struct call_site *call_site,
820 struct frame_info *caller_frame)
821 {
822 switch (FIELD_LOC_KIND (call_site->target))
823 {
824 case FIELD_LOC_KIND_DWARF_BLOCK:
825 {
826 struct dwarf2_locexpr_baton *dwarf_block;
827 struct value *val;
828 struct type *caller_core_addr_type;
829 struct gdbarch *caller_arch;
830
831 dwarf_block = FIELD_DWARF_BLOCK (call_site->target);
832 if (dwarf_block == NULL)
833 {
834 struct bound_minimal_symbol msym;
835
836 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
837 throw_error (NO_ENTRY_VALUE_ERROR,
838 _("DW_AT_call_target is not specified at %s in %s"),
839 paddress (call_site_gdbarch, call_site->pc),
840 (msym.minsym == NULL ? "???"
841 : msym.minsym->print_name ()));
842
843 }
844 if (caller_frame == NULL)
845 {
846 struct bound_minimal_symbol msym;
847
848 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
849 throw_error (NO_ENTRY_VALUE_ERROR,
850 _("DW_AT_call_target DWARF block resolving "
851 "requires known frame which is currently not "
852 "available at %s in %s"),
853 paddress (call_site_gdbarch, call_site->pc),
854 (msym.minsym == NULL ? "???"
855 : msym.minsym->print_name ()));
856
857 }
858 caller_arch = get_frame_arch (caller_frame);
859 caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr;
860 val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame,
861 dwarf_block->data, dwarf_block->size,
862 dwarf_block->per_cu);
863 /* DW_AT_call_target is a DWARF expression, not a DWARF location. */
864 if (VALUE_LVAL (val) == lval_memory)
865 return value_address (val);
866 else
867 return value_as_address (val);
868 }
869
870 case FIELD_LOC_KIND_PHYSNAME:
871 {
872 const char *physname;
873 struct bound_minimal_symbol msym;
874
875 physname = FIELD_STATIC_PHYSNAME (call_site->target);
876
877 /* Handle both the mangled and demangled PHYSNAME. */
878 msym = lookup_minimal_symbol (physname, NULL, NULL);
879 if (msym.minsym == NULL)
880 {
881 msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
882 throw_error (NO_ENTRY_VALUE_ERROR,
883 _("Cannot find function \"%s\" for a call site target "
884 "at %s in %s"),
885 physname, paddress (call_site_gdbarch, call_site->pc),
886 (msym.minsym == NULL ? "???"
887 : msym.minsym->print_name ()));
888
889 }
890 return BMSYMBOL_VALUE_ADDRESS (msym);
891 }
892
893 case FIELD_LOC_KIND_PHYSADDR:
894 return FIELD_STATIC_PHYSADDR (call_site->target);
895
896 default:
897 internal_error (__FILE__, __LINE__, _("invalid call site target kind"));
898 }
899 }
900
901 /* Convert function entry point exact address ADDR to the function which is
902 compliant with TAIL_CALL_LIST_COMPLETE condition. Throw
903 NO_ENTRY_VALUE_ERROR otherwise. */
904
905 static struct symbol *
906 func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
907 {
908 struct symbol *sym = find_pc_function (addr);
909 struct type *type;
910
911 if (sym == NULL || BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym)) != addr)
912 throw_error (NO_ENTRY_VALUE_ERROR,
913 _("DW_TAG_call_site resolving failed to find function "
914 "name for address %s"),
915 paddress (gdbarch, addr));
916
917 type = SYMBOL_TYPE (sym);
918 gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC);
919 gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
920
921 return sym;
922 }
923
924 /* Verify function with entry point exact address ADDR can never call itself
925 via its tail calls (incl. transitively). Throw NO_ENTRY_VALUE_ERROR if it
926 can call itself via tail calls.
927
928 If a funtion can tail call itself its entry value based parameters are
929 unreliable. There is no verification whether the value of some/all
930 parameters is unchanged through the self tail call, we expect if there is
931 a self tail call all the parameters can be modified. */
932
933 static void
934 func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
935 {
936 CORE_ADDR addr;
937
938 /* The verification is completely unordered. Track here function addresses
939 which still need to be iterated. */
940 std::vector<CORE_ADDR> todo;
941
942 /* Track here CORE_ADDRs which were already visited. */
943 std::unordered_set<CORE_ADDR> addr_hash;
944
945 todo.push_back (verify_addr);
946 while (!todo.empty ())
947 {
948 struct symbol *func_sym;
949 struct call_site *call_site;
950
951 addr = todo.back ();
952 todo.pop_back ();
953
954 func_sym = func_addr_to_tail_call_list (gdbarch, addr);
955
956 for (call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (func_sym));
957 call_site; call_site = call_site->tail_call_next)
958 {
959 CORE_ADDR target_addr;
960
961 /* CALLER_FRAME with registers is not available for tail-call jumped
962 frames. */
963 target_addr = call_site_to_target_addr (gdbarch, call_site, NULL);
964
965 if (target_addr == verify_addr)
966 {
967 struct bound_minimal_symbol msym;
968
969 msym = lookup_minimal_symbol_by_pc (verify_addr);
970 throw_error (NO_ENTRY_VALUE_ERROR,
971 _("DW_OP_entry_value resolving has found "
972 "function \"%s\" at %s can call itself via tail "
973 "calls"),
974 (msym.minsym == NULL ? "???"
975 : msym.minsym->print_name ()),
976 paddress (gdbarch, verify_addr));
977 }
978
979 if (addr_hash.insert (target_addr).second)
980 todo.push_back (target_addr);
981 }
982 }
983 }
984
985 /* Print user readable form of CALL_SITE->PC to gdb_stdlog. Used only for
986 ENTRY_VALUES_DEBUG. */
987
988 static void
989 tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
990 {
991 CORE_ADDR addr = call_site->pc;
992 struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (addr - 1);
993
994 fprintf_unfiltered (gdb_stdlog, " %s(%s)", paddress (gdbarch, addr),
995 (msym.minsym == NULL ? "???"
996 : msym.minsym->print_name ()));
997
998 }
999
1000 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
1001 only top callers and bottom callees which are present in both. GDBARCH is
1002 used only for ENTRY_VALUES_DEBUG. RESULTP is NULL after return if there are
1003 no remaining possibilities to provide unambiguous non-trivial result.
1004 RESULTP should point to NULL on the first (initialization) call. Caller is
1005 responsible for xfree of any RESULTP data. */
1006
1007 static void
1008 chain_candidate (struct gdbarch *gdbarch,
1009 gdb::unique_xmalloc_ptr<struct call_site_chain> *resultp,
1010 std::vector<struct call_site *> *chain)
1011 {
1012 long length = chain->size ();
1013 int callers, callees, idx;
1014
1015 if (*resultp == NULL)
1016 {
1017 /* Create the initial chain containing all the passed PCs. */
1018
1019 struct call_site_chain *result
1020 = ((struct call_site_chain *)
1021 xmalloc (sizeof (*result)
1022 + sizeof (*result->call_site) * (length - 1)));
1023 result->length = length;
1024 result->callers = result->callees = length;
1025 if (!chain->empty ())
1026 memcpy (result->call_site, chain->data (),
1027 sizeof (*result->call_site) * length);
1028 resultp->reset (result);
1029
1030 if (entry_values_debug)
1031 {
1032 fprintf_unfiltered (gdb_stdlog, "tailcall: initial:");
1033 for (idx = 0; idx < length; idx++)
1034 tailcall_dump (gdbarch, result->call_site[idx]);
1035 fputc_unfiltered ('\n', gdb_stdlog);
1036 }
1037
1038 return;
1039 }
1040
1041 if (entry_values_debug)
1042 {
1043 fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
1044 for (idx = 0; idx < length; idx++)
1045 tailcall_dump (gdbarch, chain->at (idx));
1046 fputc_unfiltered ('\n', gdb_stdlog);
1047 }
1048
1049 /* Intersect callers. */
1050
1051 callers = std::min ((long) (*resultp)->callers, length);
1052 for (idx = 0; idx < callers; idx++)
1053 if ((*resultp)->call_site[idx] != chain->at (idx))
1054 {
1055 (*resultp)->callers = idx;
1056 break;
1057 }
1058
1059 /* Intersect callees. */
1060
1061 callees = std::min ((long) (*resultp)->callees, length);
1062 for (idx = 0; idx < callees; idx++)
1063 if ((*resultp)->call_site[(*resultp)->length - 1 - idx]
1064 != chain->at (length - 1 - idx))
1065 {
1066 (*resultp)->callees = idx;
1067 break;
1068 }
1069
1070 if (entry_values_debug)
1071 {
1072 fprintf_unfiltered (gdb_stdlog, "tailcall: reduced:");
1073 for (idx = 0; idx < (*resultp)->callers; idx++)
1074 tailcall_dump (gdbarch, (*resultp)->call_site[idx]);
1075 fputs_unfiltered (" |", gdb_stdlog);
1076 for (idx = 0; idx < (*resultp)->callees; idx++)
1077 tailcall_dump (gdbarch,
1078 (*resultp)->call_site[(*resultp)->length
1079 - (*resultp)->callees + idx]);
1080 fputc_unfiltered ('\n', gdb_stdlog);
1081 }
1082
1083 if ((*resultp)->callers == 0 && (*resultp)->callees == 0)
1084 {
1085 /* There are no common callers or callees. It could be also a direct
1086 call (which has length 0) with ambiguous possibility of an indirect
1087 call - CALLERS == CALLEES == 0 is valid during the first allocation
1088 but any subsequence processing of such entry means ambiguity. */
1089 resultp->reset (NULL);
1090 return;
1091 }
1092
1093 /* See call_site_find_chain_1 why there is no way to reach the bottom callee
1094 PC again. In such case there must be two different code paths to reach
1095 it. CALLERS + CALLEES equal to LENGTH in the case of self tail-call. */
1096 gdb_assert ((*resultp)->callers + (*resultp)->callees <= (*resultp)->length);
1097 }
1098
1099 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1100 assumed frames between them use GDBARCH. Use depth first search so we can
1101 keep single CHAIN of call_site's back to CALLER_PC. Function recursion
1102 would have needless GDB stack overhead. Any unreliability results
1103 in thrown NO_ENTRY_VALUE_ERROR. */
1104
1105 static gdb::unique_xmalloc_ptr<call_site_chain>
1106 call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
1107 CORE_ADDR callee_pc)
1108 {
1109 CORE_ADDR save_callee_pc = callee_pc;
1110 gdb::unique_xmalloc_ptr<struct call_site_chain> retval;
1111 struct call_site *call_site;
1112
1113 /* CHAIN contains only the intermediate CALL_SITEs. Neither CALLER_PC's
1114 call_site nor any possible call_site at CALLEE_PC's function is there.
1115 Any CALL_SITE in CHAIN will be iterated to its siblings - via
1116 TAIL_CALL_NEXT. This is inappropriate for CALLER_PC's call_site. */
1117 std::vector<struct call_site *> chain;
1118
1119 /* We are not interested in the specific PC inside the callee function. */
1120 callee_pc = get_pc_function_start (callee_pc);
1121 if (callee_pc == 0)
1122 throw_error (NO_ENTRY_VALUE_ERROR, _("Unable to find function for PC %s"),
1123 paddress (gdbarch, save_callee_pc));
1124
1125 /* Mark CALL_SITEs so we do not visit the same ones twice. */
1126 std::unordered_set<CORE_ADDR> addr_hash;
1127
1128 /* Do not push CALL_SITE to CHAIN. Push there only the first tail call site
1129 at the target's function. All the possible tail call sites in the
1130 target's function will get iterated as already pushed into CHAIN via their
1131 TAIL_CALL_NEXT. */
1132 call_site = call_site_for_pc (gdbarch, caller_pc);
1133
1134 while (call_site)
1135 {
1136 CORE_ADDR target_func_addr;
1137 struct call_site *target_call_site;
1138
1139 /* CALLER_FRAME with registers is not available for tail-call jumped
1140 frames. */
1141 target_func_addr = call_site_to_target_addr (gdbarch, call_site, NULL);
1142
1143 if (target_func_addr == callee_pc)
1144 {
1145 chain_candidate (gdbarch, &retval, &chain);
1146 if (retval == NULL)
1147 break;
1148
1149 /* There is no way to reach CALLEE_PC again as we would prevent
1150 entering it twice as being already marked in ADDR_HASH. */
1151 target_call_site = NULL;
1152 }
1153 else
1154 {
1155 struct symbol *target_func;
1156
1157 target_func = func_addr_to_tail_call_list (gdbarch, target_func_addr);
1158 target_call_site = TYPE_TAIL_CALL_LIST (SYMBOL_TYPE (target_func));
1159 }
1160
1161 do
1162 {
1163 /* Attempt to visit TARGET_CALL_SITE. */
1164
1165 if (target_call_site)
1166 {
1167 if (addr_hash.insert (target_call_site->pc).second)
1168 {
1169 /* Successfully entered TARGET_CALL_SITE. */
1170
1171 chain.push_back (target_call_site);
1172 break;
1173 }
1174 }
1175
1176 /* Backtrack (without revisiting the originating call_site). Try the
1177 callers's sibling; if there isn't any try the callers's callers's
1178 sibling etc. */
1179
1180 target_call_site = NULL;
1181 while (!chain.empty ())
1182 {
1183 call_site = chain.back ();
1184 chain.pop_back ();
1185
1186 size_t removed = addr_hash.erase (call_site->pc);
1187 gdb_assert (removed == 1);
1188
1189 target_call_site = call_site->tail_call_next;
1190 if (target_call_site)
1191 break;
1192 }
1193 }
1194 while (target_call_site);
1195
1196 if (chain.empty ())
1197 call_site = NULL;
1198 else
1199 call_site = chain.back ();
1200 }
1201
1202 if (retval == NULL)
1203 {
1204 struct bound_minimal_symbol msym_caller, msym_callee;
1205
1206 msym_caller = lookup_minimal_symbol_by_pc (caller_pc);
1207 msym_callee = lookup_minimal_symbol_by_pc (callee_pc);
1208 throw_error (NO_ENTRY_VALUE_ERROR,
1209 _("There are no unambiguously determinable intermediate "
1210 "callers or callees between caller function \"%s\" at %s "
1211 "and callee function \"%s\" at %s"),
1212 (msym_caller.minsym == NULL
1213 ? "???" : msym_caller.minsym->print_name ()),
1214 paddress (gdbarch, caller_pc),
1215 (msym_callee.minsym == NULL
1216 ? "???" : msym_callee.minsym->print_name ()),
1217 paddress (gdbarch, callee_pc));
1218 }
1219
1220 return retval;
1221 }
1222
1223 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC. All the
1224 assumed frames between them use GDBARCH. If valid call_site_chain cannot be
1225 constructed return NULL. */
1226
1227 gdb::unique_xmalloc_ptr<call_site_chain>
1228 call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
1229 CORE_ADDR callee_pc)
1230 {
1231 gdb::unique_xmalloc_ptr<call_site_chain> retval;
1232
1233 try
1234 {
1235 retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc);
1236 }
1237 catch (const gdb_exception_error &e)
1238 {
1239 if (e.error == NO_ENTRY_VALUE_ERROR)
1240 {
1241 if (entry_values_debug)
1242 exception_print (gdb_stdout, e);
1243
1244 return NULL;
1245 }
1246 else
1247 throw;
1248 }
1249
1250 return retval;
1251 }
1252
1253 /* Return 1 if KIND and KIND_U match PARAMETER. Return 0 otherwise. */
1254
1255 static int
1256 call_site_parameter_matches (struct call_site_parameter *parameter,
1257 enum call_site_parameter_kind kind,
1258 union call_site_parameter_u kind_u)
1259 {
1260 if (kind == parameter->kind)
1261 switch (kind)
1262 {
1263 case CALL_SITE_PARAMETER_DWARF_REG:
1264 return kind_u.dwarf_reg == parameter->u.dwarf_reg;
1265 case CALL_SITE_PARAMETER_FB_OFFSET:
1266 return kind_u.fb_offset == parameter->u.fb_offset;
1267 case CALL_SITE_PARAMETER_PARAM_OFFSET:
1268 return kind_u.param_cu_off == parameter->u.param_cu_off;
1269 }
1270 return 0;
1271 }
1272
1273 /* Fetch call_site_parameter from caller matching KIND and KIND_U.
1274 FRAME is for callee.
1275
1276 Function always returns non-NULL, it throws NO_ENTRY_VALUE_ERROR
1277 otherwise. */
1278
1279 static struct call_site_parameter *
1280 dwarf_expr_reg_to_entry_parameter (struct frame_info *frame,
1281 enum call_site_parameter_kind kind,
1282 union call_site_parameter_u kind_u,
1283 struct dwarf2_per_cu_data **per_cu_return)
1284 {
1285 CORE_ADDR func_addr, caller_pc;
1286 struct gdbarch *gdbarch;
1287 struct frame_info *caller_frame;
1288 struct call_site *call_site;
1289 int iparams;
1290 /* Initialize it just to avoid a GCC false warning. */
1291 struct call_site_parameter *parameter = NULL;
1292 CORE_ADDR target_addr;
1293
1294 while (get_frame_type (frame) == INLINE_FRAME)
1295 {
1296 frame = get_prev_frame (frame);
1297 gdb_assert (frame != NULL);
1298 }
1299
1300 func_addr = get_frame_func (frame);
1301 gdbarch = get_frame_arch (frame);
1302 caller_frame = get_prev_frame (frame);
1303 if (gdbarch != frame_unwind_arch (frame))
1304 {
1305 struct bound_minimal_symbol msym
1306 = lookup_minimal_symbol_by_pc (func_addr);
1307 struct gdbarch *caller_gdbarch = frame_unwind_arch (frame);
1308
1309 throw_error (NO_ENTRY_VALUE_ERROR,
1310 _("DW_OP_entry_value resolving callee gdbarch %s "
1311 "(of %s (%s)) does not match caller gdbarch %s"),
1312 gdbarch_bfd_arch_info (gdbarch)->printable_name,
1313 paddress (gdbarch, func_addr),
1314 (msym.minsym == NULL ? "???"
1315 : msym.minsym->print_name ()),
1316 gdbarch_bfd_arch_info (caller_gdbarch)->printable_name);
1317 }
1318
1319 if (caller_frame == NULL)
1320 {
1321 struct bound_minimal_symbol msym
1322 = lookup_minimal_symbol_by_pc (func_addr);
1323
1324 throw_error (NO_ENTRY_VALUE_ERROR, _("DW_OP_entry_value resolving "
1325 "requires caller of %s (%s)"),
1326 paddress (gdbarch, func_addr),
1327 (msym.minsym == NULL ? "???"
1328 : msym.minsym->print_name ()));
1329 }
1330 caller_pc = get_frame_pc (caller_frame);
1331 call_site = call_site_for_pc (gdbarch, caller_pc);
1332
1333 target_addr = call_site_to_target_addr (gdbarch, call_site, caller_frame);
1334 if (target_addr != func_addr)
1335 {
1336 struct minimal_symbol *target_msym, *func_msym;
1337
1338 target_msym = lookup_minimal_symbol_by_pc (target_addr).minsym;
1339 func_msym = lookup_minimal_symbol_by_pc (func_addr).minsym;
1340 throw_error (NO_ENTRY_VALUE_ERROR,
1341 _("DW_OP_entry_value resolving expects callee %s at %s "
1342 "but the called frame is for %s at %s"),
1343 (target_msym == NULL ? "???"
1344 : target_msym->print_name ()),
1345 paddress (gdbarch, target_addr),
1346 func_msym == NULL ? "???" : func_msym->print_name (),
1347 paddress (gdbarch, func_addr));
1348 }
1349
1350 /* No entry value based parameters would be reliable if this function can
1351 call itself via tail calls. */
1352 func_verify_no_selftailcall (gdbarch, func_addr);
1353
1354 for (iparams = 0; iparams < call_site->parameter_count; iparams++)
1355 {
1356 parameter = &call_site->parameter[iparams];
1357 if (call_site_parameter_matches (parameter, kind, kind_u))
1358 break;
1359 }
1360 if (iparams == call_site->parameter_count)
1361 {
1362 struct minimal_symbol *msym
1363 = lookup_minimal_symbol_by_pc (caller_pc).minsym;
1364
1365 /* DW_TAG_call_site_parameter will be missing just if GCC could not
1366 determine its value. */
1367 throw_error (NO_ENTRY_VALUE_ERROR, _("Cannot find matching parameter "
1368 "at DW_TAG_call_site %s at %s"),
1369 paddress (gdbarch, caller_pc),
1370 msym == NULL ? "???" : msym->print_name ());
1371 }
1372
1373 *per_cu_return = call_site->per_cu;
1374 return parameter;
1375 }
1376
1377 /* Return value for PARAMETER matching DEREF_SIZE. If DEREF_SIZE is -1, return
1378 the normal DW_AT_call_value block. Otherwise return the
1379 DW_AT_call_data_value (dereferenced) block.
1380
1381 TYPE and CALLER_FRAME specify how to evaluate the DWARF block into returned
1382 struct value.
1383
1384 Function always returns non-NULL, non-optimized out value. It throws
1385 NO_ENTRY_VALUE_ERROR if it cannot resolve the value for any reason. */
1386
1387 static struct value *
1388 dwarf_entry_parameter_to_value (struct call_site_parameter *parameter,
1389 CORE_ADDR deref_size, struct type *type,
1390 struct frame_info *caller_frame,
1391 struct dwarf2_per_cu_data *per_cu)
1392 {
1393 const gdb_byte *data_src;
1394 gdb_byte *data;
1395 size_t size;
1396
1397 data_src = deref_size == -1 ? parameter->value : parameter->data_value;
1398 size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
1399
1400 /* DEREF_SIZE size is not verified here. */
1401 if (data_src == NULL)
1402 throw_error (NO_ENTRY_VALUE_ERROR,
1403 _("Cannot resolve DW_AT_call_data_value"));
1404
1405 /* DW_AT_call_value is a DWARF expression, not a DWARF
1406 location. Postprocessing of DWARF_VALUE_MEMORY would lose the type from
1407 DWARF block. */
1408 data = (gdb_byte *) alloca (size + 1);
1409 memcpy (data, data_src, size);
1410 data[size] = DW_OP_stack_value;
1411
1412 return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu);
1413 }
1414
1415 /* VALUE must be of type lval_computed with entry_data_value_funcs. Perform
1416 the indirect method on it, that is use its stored target value, the sole
1417 purpose of entry_data_value_funcs.. */
1418
1419 static struct value *
1420 entry_data_value_coerce_ref (const struct value *value)
1421 {
1422 struct type *checked_type = check_typedef (value_type (value));
1423 struct value *target_val;
1424
1425 if (!TYPE_IS_REFERENCE (checked_type))
1426 return NULL;
1427
1428 target_val = (struct value *) value_computed_closure (value);
1429 value_incref (target_val);
1430 return target_val;
1431 }
1432
1433 /* Implement copy_closure. */
1434
1435 static void *
1436 entry_data_value_copy_closure (const struct value *v)
1437 {
1438 struct value *target_val = (struct value *) value_computed_closure (v);
1439
1440 value_incref (target_val);
1441 return target_val;
1442 }
1443
1444 /* Implement free_closure. */
1445
1446 static void
1447 entry_data_value_free_closure (struct value *v)
1448 {
1449 struct value *target_val = (struct value *) value_computed_closure (v);
1450
1451 value_decref (target_val);
1452 }
1453
1454 /* Vector for methods for an entry value reference where the referenced value
1455 is stored in the caller. On the first dereference use
1456 DW_AT_call_data_value in the caller. */
1457
1458 static const struct lval_funcs entry_data_value_funcs =
1459 {
1460 NULL, /* read */
1461 NULL, /* write */
1462 NULL, /* indirect */
1463 entry_data_value_coerce_ref,
1464 NULL, /* check_synthetic_pointer */
1465 entry_data_value_copy_closure,
1466 entry_data_value_free_closure
1467 };
1468
1469 /* Read parameter of TYPE at (callee) FRAME's function entry. KIND and KIND_U
1470 are used to match DW_AT_location at the caller's
1471 DW_TAG_call_site_parameter.
1472
1473 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1474 cannot resolve the parameter for any reason. */
1475
1476 static struct value *
1477 value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame,
1478 enum call_site_parameter_kind kind,
1479 union call_site_parameter_u kind_u)
1480 {
1481 struct type *checked_type = check_typedef (type);
1482 struct type *target_type = TYPE_TARGET_TYPE (checked_type);
1483 struct frame_info *caller_frame = get_prev_frame (frame);
1484 struct value *outer_val, *target_val, *val;
1485 struct call_site_parameter *parameter;
1486 struct dwarf2_per_cu_data *caller_per_cu;
1487
1488 parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
1489 &caller_per_cu);
1490
1491 outer_val = dwarf_entry_parameter_to_value (parameter, -1 /* deref_size */,
1492 type, caller_frame,
1493 caller_per_cu);
1494
1495 /* Check if DW_AT_call_data_value cannot be used. If it should be
1496 used and it is not available do not fall back to OUTER_VAL - dereferencing
1497 TYPE_CODE_REF with non-entry data value would give current value - not the
1498 entry value. */
1499
1500 if (!TYPE_IS_REFERENCE (checked_type)
1501 || TYPE_TARGET_TYPE (checked_type) == NULL)
1502 return outer_val;
1503
1504 target_val = dwarf_entry_parameter_to_value (parameter,
1505 TYPE_LENGTH (target_type),
1506 target_type, caller_frame,
1507 caller_per_cu);
1508
1509 val = allocate_computed_value (type, &entry_data_value_funcs,
1510 release_value (target_val).release ());
1511
1512 /* Copy the referencing pointer to the new computed value. */
1513 memcpy (value_contents_raw (val), value_contents_raw (outer_val),
1514 TYPE_LENGTH (checked_type));
1515 set_value_lazy (val, 0);
1516
1517 return val;
1518 }
1519
1520 /* Read parameter of TYPE at (callee) FRAME's function entry. DATA and
1521 SIZE are DWARF block used to match DW_AT_location at the caller's
1522 DW_TAG_call_site_parameter.
1523
1524 Function always returns non-NULL value. It throws NO_ENTRY_VALUE_ERROR if it
1525 cannot resolve the parameter for any reason. */
1526
1527 static struct value *
1528 value_of_dwarf_block_entry (struct type *type, struct frame_info *frame,
1529 const gdb_byte *block, size_t block_len)
1530 {
1531 union call_site_parameter_u kind_u;
1532
1533 kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (block, block + block_len);
1534 if (kind_u.dwarf_reg != -1)
1535 return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_DWARF_REG,
1536 kind_u);
1537
1538 if (dwarf_block_to_fb_offset (block, block + block_len, &kind_u.fb_offset))
1539 return value_of_dwarf_reg_entry (type, frame, CALL_SITE_PARAMETER_FB_OFFSET,
1540 kind_u);
1541
1542 /* This can normally happen - throw NO_ENTRY_VALUE_ERROR to get the message
1543 suppressed during normal operation. The expression can be arbitrary if
1544 there is no caller-callee entry value binding expected. */
1545 throw_error (NO_ENTRY_VALUE_ERROR,
1546 _("DWARF-2 expression error: DW_OP_entry_value is supported "
1547 "only for single DW_OP_reg* or for DW_OP_fbreg(*)"));
1548 }
1549
1550 struct piece_closure
1551 {
1552 /* Reference count. */
1553 int refc = 0;
1554
1555 /* The CU from which this closure's expression came. */
1556 struct dwarf2_per_cu_data *per_cu = NULL;
1557
1558 /* The pieces describing this variable. */
1559 std::vector<dwarf_expr_piece> pieces;
1560
1561 /* Frame ID of frame to which a register value is relative, used
1562 only by DWARF_VALUE_REGISTER. */
1563 struct frame_id frame_id;
1564 };
1565
1566 /* Allocate a closure for a value formed from separately-described
1567 PIECES. */
1568
1569 static struct piece_closure *
1570 allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
1571 std::vector<dwarf_expr_piece> &&pieces,
1572 struct frame_info *frame)
1573 {
1574 struct piece_closure *c = new piece_closure;
1575
1576 c->refc = 1;
1577 c->per_cu = per_cu;
1578 c->pieces = std::move (pieces);
1579 if (frame == NULL)
1580 c->frame_id = null_frame_id;
1581 else
1582 c->frame_id = get_frame_id (frame);
1583
1584 for (dwarf_expr_piece &piece : c->pieces)
1585 if (piece.location == DWARF_VALUE_STACK)
1586 value_incref (piece.v.value);
1587
1588 return c;
1589 }
1590
1591 /* Return the number of bytes overlapping a contiguous chunk of N_BITS
1592 bits whose first bit is located at bit offset START. */
1593
1594 static size_t
1595 bits_to_bytes (ULONGEST start, ULONGEST n_bits)
1596 {
1597 return (start % 8 + n_bits + 7) / 8;
1598 }
1599
1600 /* Read or write a pieced value V. If FROM != NULL, operate in "write
1601 mode": copy FROM into the pieces comprising V. If FROM == NULL,
1602 operate in "read mode": fetch the contents of the (lazy) value V by
1603 composing it from its pieces. */
1604
1605 static void
1606 rw_pieced_value (struct value *v, struct value *from)
1607 {
1608 int i;
1609 LONGEST offset = 0, max_offset;
1610 ULONGEST bits_to_skip;
1611 gdb_byte *v_contents;
1612 const gdb_byte *from_contents;
1613 struct piece_closure *c
1614 = (struct piece_closure *) value_computed_closure (v);
1615 gdb::byte_vector buffer;
1616 bool bits_big_endian = type_byte_order (value_type (v)) == BFD_ENDIAN_BIG;
1617
1618 if (from != NULL)
1619 {
1620 from_contents = value_contents (from);
1621 v_contents = NULL;
1622 }
1623 else
1624 {
1625 if (value_type (v) != value_enclosing_type (v))
1626 internal_error (__FILE__, __LINE__,
1627 _("Should not be able to create a lazy value with "
1628 "an enclosing type"));
1629 v_contents = value_contents_raw (v);
1630 from_contents = NULL;
1631 }
1632
1633 bits_to_skip = 8 * value_offset (v);
1634 if (value_bitsize (v))
1635 {
1636 bits_to_skip += (8 * value_offset (value_parent (v))
1637 + value_bitpos (v));
1638 if (from != NULL
1639 && (type_byte_order (value_type (from))
1640 == BFD_ENDIAN_BIG))
1641 {
1642 /* Use the least significant bits of FROM. */
1643 max_offset = 8 * TYPE_LENGTH (value_type (from));
1644 offset = max_offset - value_bitsize (v);
1645 }
1646 else
1647 max_offset = value_bitsize (v);
1648 }
1649 else
1650 max_offset = 8 * TYPE_LENGTH (value_type (v));
1651
1652 /* Advance to the first non-skipped piece. */
1653 for (i = 0; i < c->pieces.size () && bits_to_skip >= c->pieces[i].size; i++)
1654 bits_to_skip -= c->pieces[i].size;
1655
1656 for (; i < c->pieces.size () && offset < max_offset; i++)
1657 {
1658 struct dwarf_expr_piece *p = &c->pieces[i];
1659 size_t this_size_bits, this_size;
1660
1661 this_size_bits = p->size - bits_to_skip;
1662 if (this_size_bits > max_offset - offset)
1663 this_size_bits = max_offset - offset;
1664
1665 switch (p->location)
1666 {
1667 case DWARF_VALUE_REGISTER:
1668 {
1669 struct frame_info *frame = frame_find_by_id (c->frame_id);
1670 struct gdbarch *arch = get_frame_arch (frame);
1671 int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, p->v.regno);
1672 ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
1673 int optim, unavail;
1674
1675 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
1676 && p->offset + p->size < reg_bits)
1677 {
1678 /* Big-endian, and we want less than full size. */
1679 bits_to_skip += reg_bits - (p->offset + p->size);
1680 }
1681 else
1682 bits_to_skip += p->offset;
1683
1684 this_size = bits_to_bytes (bits_to_skip, this_size_bits);
1685 buffer.resize (this_size);
1686
1687 if (from == NULL)
1688 {
1689 /* Read mode. */
1690 if (!get_frame_register_bytes (frame, gdb_regnum,
1691 bits_to_skip / 8,
1692 this_size, buffer.data (),
1693 &optim, &unavail))
1694 {
1695 if (optim)
1696 mark_value_bits_optimized_out (v, offset,
1697 this_size_bits);
1698 if (unavail)
1699 mark_value_bits_unavailable (v, offset,
1700 this_size_bits);
1701 break;
1702 }
1703
1704 copy_bitwise (v_contents, offset,
1705 buffer.data (), bits_to_skip % 8,
1706 this_size_bits, bits_big_endian);
1707 }
1708 else
1709 {
1710 /* Write mode. */
1711 if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
1712 {
1713 /* Data is copied non-byte-aligned into the register.
1714 Need some bits from original register value. */
1715 get_frame_register_bytes (frame, gdb_regnum,
1716 bits_to_skip / 8,
1717 this_size, buffer.data (),
1718 &optim, &unavail);
1719 if (optim)
1720 throw_error (OPTIMIZED_OUT_ERROR,
1721 _("Can't do read-modify-write to "
1722 "update bitfield; containing word "
1723 "has been optimized out"));
1724 if (unavail)
1725 throw_error (NOT_AVAILABLE_ERROR,
1726 _("Can't do read-modify-write to "
1727 "update bitfield; containing word "
1728 "is unavailable"));
1729 }
1730
1731 copy_bitwise (buffer.data (), bits_to_skip % 8,
1732 from_contents, offset,
1733 this_size_bits, bits_big_endian);
1734 put_frame_register_bytes (frame, gdb_regnum,
1735 bits_to_skip / 8,
1736 this_size, buffer.data ());
1737 }
1738 }
1739 break;
1740
1741 case DWARF_VALUE_MEMORY:
1742 {
1743 bits_to_skip += p->offset;
1744
1745 CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8;
1746
1747 if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0
1748 && offset % 8 == 0)
1749 {
1750 /* Everything is byte-aligned; no buffer needed. */
1751 if (from != NULL)
1752 write_memory_with_notification (start_addr,
1753 (from_contents
1754 + offset / 8),
1755 this_size_bits / 8);
1756 else
1757 read_value_memory (v, offset,
1758 p->v.mem.in_stack_memory,
1759 p->v.mem.addr + bits_to_skip / 8,
1760 v_contents + offset / 8,
1761 this_size_bits / 8);
1762 break;
1763 }
1764
1765 this_size = bits_to_bytes (bits_to_skip, this_size_bits);
1766 buffer.resize (this_size);
1767
1768 if (from == NULL)
1769 {
1770 /* Read mode. */
1771 read_value_memory (v, offset,
1772 p->v.mem.in_stack_memory,
1773 p->v.mem.addr + bits_to_skip / 8,
1774 buffer.data (), this_size);
1775 copy_bitwise (v_contents, offset,
1776 buffer.data (), bits_to_skip % 8,
1777 this_size_bits, bits_big_endian);
1778 }
1779 else
1780 {
1781 /* Write mode. */
1782 if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
1783 {
1784 if (this_size <= 8)
1785 {
1786 /* Perform a single read for small sizes. */
1787 read_memory (start_addr, buffer.data (),
1788 this_size);
1789 }
1790 else
1791 {
1792 /* Only the first and last bytes can possibly have
1793 any bits reused. */
1794 read_memory (start_addr, buffer.data (), 1);
1795 read_memory (start_addr + this_size - 1,
1796 &buffer[this_size - 1], 1);
1797 }
1798 }
1799
1800 copy_bitwise (buffer.data (), bits_to_skip % 8,
1801 from_contents, offset,
1802 this_size_bits, bits_big_endian);
1803 write_memory_with_notification (start_addr,
1804 buffer.data (),
1805 this_size);
1806 }
1807 }
1808 break;
1809
1810 case DWARF_VALUE_STACK:
1811 {
1812 if (from != NULL)
1813 {
1814 mark_value_bits_optimized_out (v, offset, this_size_bits);
1815 break;
1816 }
1817
1818 struct objfile *objfile = c->per_cu->objfile ();
1819 struct gdbarch *objfile_gdbarch = objfile->arch ();
1820 ULONGEST stack_value_size_bits
1821 = 8 * TYPE_LENGTH (value_type (p->v.value));
1822
1823 /* Use zeroes if piece reaches beyond stack value. */
1824 if (p->offset + p->size > stack_value_size_bits)
1825 break;
1826
1827 /* Piece is anchored at least significant bit end. */
1828 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
1829 bits_to_skip += stack_value_size_bits - p->offset - p->size;
1830 else
1831 bits_to_skip += p->offset;
1832
1833 copy_bitwise (v_contents, offset,
1834 value_contents_all (p->v.value),
1835 bits_to_skip,
1836 this_size_bits, bits_big_endian);
1837 }
1838 break;
1839
1840 case DWARF_VALUE_LITERAL:
1841 {
1842 if (from != NULL)
1843 {
1844 mark_value_bits_optimized_out (v, offset, this_size_bits);
1845 break;
1846 }
1847
1848 ULONGEST literal_size_bits = 8 * p->v.literal.length;
1849 size_t n = this_size_bits;
1850
1851 /* Cut off at the end of the implicit value. */
1852 bits_to_skip += p->offset;
1853 if (bits_to_skip >= literal_size_bits)
1854 break;
1855 if (n > literal_size_bits - bits_to_skip)
1856 n = literal_size_bits - bits_to_skip;
1857
1858 copy_bitwise (v_contents, offset,
1859 p->v.literal.data, bits_to_skip,
1860 n, bits_big_endian);
1861 }
1862 break;
1863
1864 case DWARF_VALUE_IMPLICIT_POINTER:
1865 if (from != NULL)
1866 {
1867 mark_value_bits_optimized_out (v, offset, this_size_bits);
1868 break;
1869 }
1870
1871 /* These bits show up as zeros -- but do not cause the value to
1872 be considered optimized-out. */
1873 break;
1874
1875 case DWARF_VALUE_OPTIMIZED_OUT:
1876 mark_value_bits_optimized_out (v, offset, this_size_bits);
1877 break;
1878
1879 default:
1880 internal_error (__FILE__, __LINE__, _("invalid location type"));
1881 }
1882
1883 offset += this_size_bits;
1884 bits_to_skip = 0;
1885 }
1886 }
1887
1888
1889 static void
1890 read_pieced_value (struct value *v)
1891 {
1892 rw_pieced_value (v, NULL);
1893 }
1894
1895 static void
1896 write_pieced_value (struct value *to, struct value *from)
1897 {
1898 rw_pieced_value (to, from);
1899 }
1900
1901 /* An implementation of an lval_funcs method to see whether a value is
1902 a synthetic pointer. */
1903
1904 static int
1905 check_pieced_synthetic_pointer (const struct value *value, LONGEST bit_offset,
1906 int bit_length)
1907 {
1908 struct piece_closure *c
1909 = (struct piece_closure *) value_computed_closure (value);
1910 int i;
1911
1912 bit_offset += 8 * value_offset (value);
1913 if (value_bitsize (value))
1914 bit_offset += value_bitpos (value);
1915
1916 for (i = 0; i < c->pieces.size () && bit_length > 0; i++)
1917 {
1918 struct dwarf_expr_piece *p = &c->pieces[i];
1919 size_t this_size_bits = p->size;
1920
1921 if (bit_offset > 0)
1922 {
1923 if (bit_offset >= this_size_bits)
1924 {
1925 bit_offset -= this_size_bits;
1926 continue;
1927 }
1928
1929 bit_length -= this_size_bits - bit_offset;
1930 bit_offset = 0;
1931 }
1932 else
1933 bit_length -= this_size_bits;
1934
1935 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
1936 return 0;
1937 }
1938
1939 return 1;
1940 }
1941
1942 /* A wrapper function for get_frame_address_in_block. */
1943
1944 static CORE_ADDR
1945 get_frame_address_in_block_wrapper (void *baton)
1946 {
1947 return get_frame_address_in_block ((struct frame_info *) baton);
1948 }
1949
1950 /* Fetch a DW_AT_const_value through a synthetic pointer. */
1951
1952 static struct value *
1953 fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
1954 struct dwarf2_per_cu_data *per_cu,
1955 struct type *type)
1956 {
1957 struct value *result = NULL;
1958 const gdb_byte *bytes;
1959 LONGEST len;
1960
1961 auto_obstack temp_obstack;
1962 bytes = dwarf2_fetch_constant_bytes (die, per_cu, &temp_obstack, &len);
1963
1964 if (bytes != NULL)
1965 {
1966 if (byte_offset >= 0
1967 && byte_offset + TYPE_LENGTH (TYPE_TARGET_TYPE (type)) <= len)
1968 {
1969 bytes += byte_offset;
1970 result = value_from_contents (TYPE_TARGET_TYPE (type), bytes);
1971 }
1972 else
1973 invalid_synthetic_pointer ();
1974 }
1975 else
1976 result = allocate_optimized_out_value (TYPE_TARGET_TYPE (type));
1977
1978 return result;
1979 }
1980
1981 /* Fetch the value pointed to by a synthetic pointer. */
1982
1983 static struct value *
1984 indirect_synthetic_pointer (sect_offset die, LONGEST byte_offset,
1985 struct dwarf2_per_cu_data *per_cu,
1986 struct frame_info *frame, struct type *type,
1987 bool resolve_abstract_p)
1988 {
1989 /* Fetch the location expression of the DIE we're pointing to. */
1990 struct dwarf2_locexpr_baton baton
1991 = dwarf2_fetch_die_loc_sect_off (die, per_cu,
1992 get_frame_address_in_block_wrapper, frame,
1993 resolve_abstract_p);
1994
1995 /* Get type of pointed-to DIE. */
1996 struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu);
1997 if (orig_type == NULL)
1998 invalid_synthetic_pointer ();
1999
2000 /* If pointed-to DIE has a DW_AT_location, evaluate it and return the
2001 resulting value. Otherwise, it may have a DW_AT_const_value instead,
2002 or it may've been optimized out. */
2003 if (baton.data != NULL)
2004 return dwarf2_evaluate_loc_desc_full (orig_type, frame, baton.data,
2005 baton.size, baton.per_cu,
2006 TYPE_TARGET_TYPE (type),
2007 byte_offset);
2008 else
2009 return fetch_const_value_from_synthetic_pointer (die, byte_offset, per_cu,
2010 type);
2011 }
2012
2013 /* An implementation of an lval_funcs method to indirect through a
2014 pointer. This handles the synthetic pointer case when needed. */
2015
2016 static struct value *
2017 indirect_pieced_value (struct value *value)
2018 {
2019 struct piece_closure *c
2020 = (struct piece_closure *) value_computed_closure (value);
2021 struct type *type;
2022 struct frame_info *frame;
2023 int i, bit_length;
2024 LONGEST bit_offset;
2025 struct dwarf_expr_piece *piece = NULL;
2026 LONGEST byte_offset;
2027 enum bfd_endian byte_order;
2028
2029 type = check_typedef (value_type (value));
2030 if (TYPE_CODE (type) != TYPE_CODE_PTR)
2031 return NULL;
2032
2033 bit_length = 8 * TYPE_LENGTH (type);
2034 bit_offset = 8 * value_offset (value);
2035 if (value_bitsize (value))
2036 bit_offset += value_bitpos (value);
2037
2038 for (i = 0; i < c->pieces.size () && bit_length > 0; i++)
2039 {
2040 struct dwarf_expr_piece *p = &c->pieces[i];
2041 size_t this_size_bits = p->size;
2042
2043 if (bit_offset > 0)
2044 {
2045 if (bit_offset >= this_size_bits)
2046 {
2047 bit_offset -= this_size_bits;
2048 continue;
2049 }
2050
2051 bit_length -= this_size_bits - bit_offset;
2052 bit_offset = 0;
2053 }
2054 else
2055 bit_length -= this_size_bits;
2056
2057 if (p->location != DWARF_VALUE_IMPLICIT_POINTER)
2058 return NULL;
2059
2060 if (bit_length != 0)
2061 error (_("Invalid use of DW_OP_implicit_pointer"));
2062
2063 piece = p;
2064 break;
2065 }
2066
2067 gdb_assert (piece != NULL);
2068 frame = get_selected_frame (_("No frame selected."));
2069
2070 /* This is an offset requested by GDB, such as value subscripts.
2071 However, due to how synthetic pointers are implemented, this is
2072 always presented to us as a pointer type. This means we have to
2073 sign-extend it manually as appropriate. Use raw
2074 extract_signed_integer directly rather than value_as_address and
2075 sign extend afterwards on architectures that would need it
2076 (mostly everywhere except MIPS, which has signed addresses) as
2077 the later would go through gdbarch_pointer_to_address and thus
2078 return a CORE_ADDR with high bits set on architectures that
2079 encode address spaces and other things in CORE_ADDR. */
2080 byte_order = gdbarch_byte_order (get_frame_arch (frame));
2081 byte_offset = extract_signed_integer (value_contents (value),
2082 TYPE_LENGTH (type), byte_order);
2083 byte_offset += piece->v.ptr.offset;
2084
2085 return indirect_synthetic_pointer (piece->v.ptr.die_sect_off,
2086 byte_offset, c->per_cu,
2087 frame, type);
2088 }
2089
2090 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
2091 references. */
2092
2093 static struct value *
2094 coerce_pieced_ref (const struct value *value)
2095 {
2096 struct type *type = check_typedef (value_type (value));
2097
2098 if (value_bits_synthetic_pointer (value, value_embedded_offset (value),
2099 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
2100 {
2101 const struct piece_closure *closure
2102 = (struct piece_closure *) value_computed_closure (value);
2103 struct frame_info *frame
2104 = get_selected_frame (_("No frame selected."));
2105
2106 /* gdb represents synthetic pointers as pieced values with a single
2107 piece. */
2108 gdb_assert (closure != NULL);
2109 gdb_assert (closure->pieces.size () == 1);
2110
2111 return indirect_synthetic_pointer
2112 (closure->pieces[0].v.ptr.die_sect_off,
2113 closure->pieces[0].v.ptr.offset,
2114 closure->per_cu, frame, type);
2115 }
2116 else
2117 {
2118 /* Else: not a synthetic reference; do nothing. */
2119 return NULL;
2120 }
2121 }
2122
2123 static void *
2124 copy_pieced_value_closure (const struct value *v)
2125 {
2126 struct piece_closure *c
2127 = (struct piece_closure *) value_computed_closure (v);
2128
2129 ++c->refc;
2130 return c;
2131 }
2132
2133 static void
2134 free_pieced_value_closure (struct value *v)
2135 {
2136 struct piece_closure *c
2137 = (struct piece_closure *) value_computed_closure (v);
2138
2139 --c->refc;
2140 if (c->refc == 0)
2141 {
2142 for (dwarf_expr_piece &p : c->pieces)
2143 if (p.location == DWARF_VALUE_STACK)
2144 value_decref (p.v.value);
2145
2146 delete c;
2147 }
2148 }
2149
2150 /* Functions for accessing a variable described by DW_OP_piece. */
2151 static const struct lval_funcs pieced_value_funcs = {
2152 read_pieced_value,
2153 write_pieced_value,
2154 indirect_pieced_value,
2155 coerce_pieced_ref,
2156 check_pieced_synthetic_pointer,
2157 copy_pieced_value_closure,
2158 free_pieced_value_closure
2159 };
2160
2161 /* Evaluate a location description, starting at DATA and with length
2162 SIZE, to find the current location of variable of TYPE in the
2163 context of FRAME. If SUBOBJ_TYPE is non-NULL, return instead the
2164 location of the subobject of type SUBOBJ_TYPE at byte offset
2165 SUBOBJ_BYTE_OFFSET within the variable of type TYPE. */
2166
2167 static struct value *
2168 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
2169 const gdb_byte *data, size_t size,
2170 struct dwarf2_per_cu_data *per_cu,
2171 struct type *subobj_type,
2172 LONGEST subobj_byte_offset)
2173 {
2174 struct value *retval;
2175 struct objfile *objfile = per_cu->objfile ();
2176
2177 if (subobj_type == NULL)
2178 {
2179 subobj_type = type;
2180 subobj_byte_offset = 0;
2181 }
2182 else if (subobj_byte_offset < 0)
2183 invalid_synthetic_pointer ();
2184
2185 if (size == 0)
2186 return allocate_optimized_out_value (subobj_type);
2187
2188 dwarf_evaluate_loc_desc ctx;
2189 ctx.frame = frame;
2190 ctx.per_cu = per_cu;
2191 ctx.obj_address = 0;
2192
2193 scoped_value_mark free_values;
2194
2195 ctx.gdbarch = objfile->arch ();
2196 ctx.addr_size = per_cu->addr_size ();
2197 ctx.ref_addr_size = per_cu->ref_addr_size ();
2198 ctx.offset = per_cu->text_offset ();
2199
2200 try
2201 {
2202 ctx.eval (data, size);
2203 }
2204 catch (const gdb_exception_error &ex)
2205 {
2206 if (ex.error == NOT_AVAILABLE_ERROR)
2207 {
2208 free_values.free_to_mark ();
2209 retval = allocate_value (subobj_type);
2210 mark_value_bytes_unavailable (retval, 0,
2211 TYPE_LENGTH (subobj_type));
2212 return retval;
2213 }
2214 else if (ex.error == NO_ENTRY_VALUE_ERROR)
2215 {
2216 if (entry_values_debug)
2217 exception_print (gdb_stdout, ex);
2218 free_values.free_to_mark ();
2219 return allocate_optimized_out_value (subobj_type);
2220 }
2221 else
2222 throw;
2223 }
2224
2225 if (ctx.pieces.size () > 0)
2226 {
2227 struct piece_closure *c;
2228 ULONGEST bit_size = 0;
2229
2230 for (dwarf_expr_piece &piece : ctx.pieces)
2231 bit_size += piece.size;
2232 /* Complain if the expression is larger than the size of the
2233 outer type. */
2234 if (bit_size > 8 * TYPE_LENGTH (type))
2235 invalid_synthetic_pointer ();
2236
2237 c = allocate_piece_closure (per_cu, std::move (ctx.pieces), frame);
2238 /* We must clean up the value chain after creating the piece
2239 closure but before allocating the result. */
2240 free_values.free_to_mark ();
2241 retval = allocate_computed_value (subobj_type,
2242 &pieced_value_funcs, c);
2243 set_value_offset (retval, subobj_byte_offset);
2244 }
2245 else
2246 {
2247 switch (ctx.location)
2248 {
2249 case DWARF_VALUE_REGISTER:
2250 {
2251 struct gdbarch *arch = get_frame_arch (frame);
2252 int dwarf_regnum
2253 = longest_to_int (value_as_long (ctx.fetch (0)));
2254 int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, dwarf_regnum);
2255
2256 if (subobj_byte_offset != 0)
2257 error (_("cannot use offset on synthetic pointer to register"));
2258 free_values.free_to_mark ();
2259 retval = value_from_register (subobj_type, gdb_regnum, frame);
2260 if (value_optimized_out (retval))
2261 {
2262 struct value *tmp;
2263
2264 /* This means the register has undefined value / was
2265 not saved. As we're computing the location of some
2266 variable etc. in the program, not a value for
2267 inspecting a register ($pc, $sp, etc.), return a
2268 generic optimized out value instead, so that we show
2269 <optimized out> instead of <not saved>. */
2270 tmp = allocate_value (subobj_type);
2271 value_contents_copy (tmp, 0, retval, 0,
2272 TYPE_LENGTH (subobj_type));
2273 retval = tmp;
2274 }
2275 }
2276 break;
2277
2278 case DWARF_VALUE_MEMORY:
2279 {
2280 struct type *ptr_type;
2281 CORE_ADDR address = ctx.fetch_address (0);
2282 bool in_stack_memory = ctx.fetch_in_stack_memory (0);
2283
2284 /* DW_OP_deref_size (and possibly other operations too) may
2285 create a pointer instead of an address. Ideally, the
2286 pointer to address conversion would be performed as part
2287 of those operations, but the type of the object to
2288 which the address refers is not known at the time of
2289 the operation. Therefore, we do the conversion here
2290 since the type is readily available. */
2291
2292 switch (TYPE_CODE (subobj_type))
2293 {
2294 case TYPE_CODE_FUNC:
2295 case TYPE_CODE_METHOD:
2296 ptr_type = builtin_type (ctx.gdbarch)->builtin_func_ptr;
2297 break;
2298 default:
2299 ptr_type = builtin_type (ctx.gdbarch)->builtin_data_ptr;
2300 break;
2301 }
2302 address = value_as_address (value_from_pointer (ptr_type, address));
2303
2304 free_values.free_to_mark ();
2305 retval = value_at_lazy (subobj_type,
2306 address + subobj_byte_offset);
2307 if (in_stack_memory)
2308 set_value_stack (retval, 1);
2309 }
2310 break;
2311
2312 case DWARF_VALUE_STACK:
2313 {
2314 struct value *value = ctx.fetch (0);
2315 size_t n = TYPE_LENGTH (value_type (value));
2316 size_t len = TYPE_LENGTH (subobj_type);
2317 size_t max = TYPE_LENGTH (type);
2318 struct gdbarch *objfile_gdbarch = objfile->arch ();
2319
2320 if (subobj_byte_offset + len > max)
2321 invalid_synthetic_pointer ();
2322
2323 /* Preserve VALUE because we are going to free values back
2324 to the mark, but we still need the value contents
2325 below. */
2326 value_ref_ptr value_holder = value_ref_ptr::new_reference (value);
2327 free_values.free_to_mark ();
2328
2329 retval = allocate_value (subobj_type);
2330
2331 /* The given offset is relative to the actual object. */
2332 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
2333 subobj_byte_offset += n - max;
2334
2335 memcpy (value_contents_raw (retval),
2336 value_contents_all (value) + subobj_byte_offset, len);
2337 }
2338 break;
2339
2340 case DWARF_VALUE_LITERAL:
2341 {
2342 bfd_byte *contents;
2343 size_t n = TYPE_LENGTH (subobj_type);
2344
2345 if (subobj_byte_offset + n > ctx.len)
2346 invalid_synthetic_pointer ();
2347
2348 free_values.free_to_mark ();
2349 retval = allocate_value (subobj_type);
2350 contents = value_contents_raw (retval);
2351 memcpy (contents, ctx.data + subobj_byte_offset, n);
2352 }
2353 break;
2354
2355 case DWARF_VALUE_OPTIMIZED_OUT:
2356 free_values.free_to_mark ();
2357 retval = allocate_optimized_out_value (subobj_type);
2358 break;
2359
2360 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
2361 operation by execute_stack_op. */
2362 case DWARF_VALUE_IMPLICIT_POINTER:
2363 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
2364 it can only be encountered when making a piece. */
2365 default:
2366 internal_error (__FILE__, __LINE__, _("invalid location type"));
2367 }
2368 }
2369
2370 set_value_initialized (retval, ctx.initialized);
2371
2372 return retval;
2373 }
2374
2375 /* The exported interface to dwarf2_evaluate_loc_desc_full; it always
2376 passes 0 as the byte_offset. */
2377
2378 struct value *
2379 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
2380 const gdb_byte *data, size_t size,
2381 struct dwarf2_per_cu_data *per_cu)
2382 {
2383 return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu,
2384 NULL, 0);
2385 }
2386
2387 /* Evaluates a dwarf expression and stores the result in VAL, expecting
2388 that the dwarf expression only produces a single CORE_ADDR. FRAME is the
2389 frame in which the expression is evaluated. ADDR is a context (location of
2390 a variable) and might be needed to evaluate the location expression.
2391 PUSH_INITIAL_VALUE is true if ADDR should be pushed on the stack
2392 before evaluating the expression; this is required by certain
2393 forms of DWARF expression. Returns 1 on success, 0 otherwise. */
2394
2395 static int
2396 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
2397 struct frame_info *frame,
2398 CORE_ADDR addr,
2399 CORE_ADDR *valp,
2400 bool push_initial_value)
2401 {
2402 struct objfile *objfile;
2403
2404 if (dlbaton == NULL || dlbaton->size == 0)
2405 return 0;
2406
2407 dwarf_evaluate_loc_desc ctx;
2408
2409 ctx.frame = frame;
2410 ctx.per_cu = dlbaton->per_cu;
2411 ctx.obj_address = addr;
2412
2413 objfile = dlbaton->per_cu->objfile ();
2414
2415 ctx.gdbarch = objfile->arch ();
2416 ctx.addr_size = dlbaton->per_cu->addr_size ();
2417 ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
2418 ctx.offset = dlbaton->per_cu->text_offset ();
2419
2420 if (push_initial_value)
2421 ctx.push_address (addr, false);
2422
2423 try
2424 {
2425 ctx.eval (dlbaton->data, dlbaton->size);
2426 }
2427 catch (const gdb_exception_error &ex)
2428 {
2429 if (ex.error == NOT_AVAILABLE_ERROR)
2430 {
2431 return 0;
2432 }
2433 else if (ex.error == NO_ENTRY_VALUE_ERROR)
2434 {
2435 if (entry_values_debug)
2436 exception_print (gdb_stdout, ex);
2437 return 0;
2438 }
2439 else
2440 throw;
2441 }
2442
2443 switch (ctx.location)
2444 {
2445 case DWARF_VALUE_REGISTER:
2446 case DWARF_VALUE_MEMORY:
2447 case DWARF_VALUE_STACK:
2448 *valp = ctx.fetch_address (0);
2449 if (ctx.location == DWARF_VALUE_REGISTER)
2450 *valp = ctx.read_addr_from_reg (*valp);
2451 return 1;
2452 case DWARF_VALUE_LITERAL:
2453 *valp = extract_signed_integer (ctx.data, ctx.len,
2454 gdbarch_byte_order (ctx.gdbarch));
2455 return 1;
2456 /* Unsupported dwarf values. */
2457 case DWARF_VALUE_OPTIMIZED_OUT:
2458 case DWARF_VALUE_IMPLICIT_POINTER:
2459 break;
2460 }
2461
2462 return 0;
2463 }
2464
2465 /* See dwarf2loc.h. */
2466
2467 bool
2468 dwarf2_evaluate_property (const struct dynamic_prop *prop,
2469 struct frame_info *frame,
2470 const struct property_addr_info *addr_stack,
2471 CORE_ADDR *value,
2472 bool push_initial_value)
2473 {
2474 if (prop == NULL)
2475 return false;
2476
2477 if (frame == NULL && has_stack_frames ())
2478 frame = get_selected_frame (NULL);
2479
2480 switch (prop->kind)
2481 {
2482 case PROP_LOCEXPR:
2483 {
2484 const struct dwarf2_property_baton *baton
2485 = (const struct dwarf2_property_baton *) prop->data.baton;
2486 gdb_assert (baton->property_type != NULL);
2487
2488 if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame,
2489 addr_stack ? addr_stack->addr : 0,
2490 value, push_initial_value))
2491 {
2492 if (baton->locexpr.is_reference)
2493 {
2494 struct value *val = value_at (baton->property_type, *value);
2495 *value = value_as_address (val);
2496 }
2497 else
2498 {
2499 gdb_assert (baton->property_type != NULL);
2500
2501 struct type *type = check_typedef (baton->property_type);
2502 if (TYPE_LENGTH (type) < sizeof (CORE_ADDR)
2503 && !TYPE_UNSIGNED (type))
2504 {
2505 /* If we have a valid return candidate and it's value
2506 is signed, we have to sign-extend the value because
2507 CORE_ADDR on 64bit machine has 8 bytes but address
2508 size of an 32bit application is bytes. */
2509 const int addr_size
2510 = (baton->locexpr.per_cu->addr_size ()
2511 * TARGET_CHAR_BIT);
2512 const CORE_ADDR neg_mask
2513 = (~((CORE_ADDR) 0) << (addr_size - 1));
2514
2515 /* Check if signed bit is set and sign-extend values. */
2516 if (*value & neg_mask)
2517 *value |= neg_mask;
2518 }
2519 }
2520 return true;
2521 }
2522 }
2523 break;
2524
2525 case PROP_LOCLIST:
2526 {
2527 struct dwarf2_property_baton *baton
2528 = (struct dwarf2_property_baton *) prop->data.baton;
2529 CORE_ADDR pc;
2530 const gdb_byte *data;
2531 struct value *val;
2532 size_t size;
2533
2534 if (frame == NULL
2535 || !get_frame_address_in_block_if_available (frame, &pc))
2536 return false;
2537
2538 data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
2539 if (data != NULL)
2540 {
2541 val = dwarf2_evaluate_loc_desc (baton->property_type, frame, data,
2542 size, baton->loclist.per_cu);
2543 if (!value_optimized_out (val))
2544 {
2545 *value = value_as_address (val);
2546 return true;
2547 }
2548 }
2549 }
2550 break;
2551
2552 case PROP_CONST:
2553 *value = prop->data.const_val;
2554 return true;
2555
2556 case PROP_ADDR_OFFSET:
2557 {
2558 struct dwarf2_property_baton *baton
2559 = (struct dwarf2_property_baton *) prop->data.baton;
2560 const struct property_addr_info *pinfo;
2561 struct value *val;
2562
2563 for (pinfo = addr_stack; pinfo != NULL; pinfo = pinfo->next)
2564 {
2565 /* This approach lets us avoid checking the qualifiers. */
2566 if (TYPE_MAIN_TYPE (pinfo->type)
2567 == TYPE_MAIN_TYPE (baton->property_type))
2568 break;
2569 }
2570 if (pinfo == NULL)
2571 error (_("cannot find reference address for offset property"));
2572 if (pinfo->valaddr != NULL)
2573 val = value_from_contents
2574 (baton->offset_info.type,
2575 pinfo->valaddr + baton->offset_info.offset);
2576 else
2577 val = value_at (baton->offset_info.type,
2578 pinfo->addr + baton->offset_info.offset);
2579 *value = value_as_address (val);
2580 return true;
2581 }
2582 }
2583
2584 return false;
2585 }
2586
2587 /* See dwarf2loc.h. */
2588
2589 void
2590 dwarf2_compile_property_to_c (string_file *stream,
2591 const char *result_name,
2592 struct gdbarch *gdbarch,
2593 unsigned char *registers_used,
2594 const struct dynamic_prop *prop,
2595 CORE_ADDR pc,
2596 struct symbol *sym)
2597 {
2598 struct dwarf2_property_baton *baton
2599 = (struct dwarf2_property_baton *) prop->data.baton;
2600 const gdb_byte *data;
2601 size_t size;
2602 struct dwarf2_per_cu_data *per_cu;
2603
2604 if (prop->kind == PROP_LOCEXPR)
2605 {
2606 data = baton->locexpr.data;
2607 size = baton->locexpr.size;
2608 per_cu = baton->locexpr.per_cu;
2609 }
2610 else
2611 {
2612 gdb_assert (prop->kind == PROP_LOCLIST);
2613
2614 data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
2615 per_cu = baton->loclist.per_cu;
2616 }
2617
2618 compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
2619 gdbarch, registers_used,
2620 per_cu->addr_size (),
2621 data, data + size, per_cu);
2622 }
2623
2624 \f
2625 /* Helper functions and baton for dwarf2_loc_desc_get_symbol_read_needs. */
2626
2627 class symbol_needs_eval_context : public dwarf_expr_context
2628 {
2629 public:
2630
2631 enum symbol_needs_kind needs;
2632 struct dwarf2_per_cu_data *per_cu;
2633
2634 /* Reads from registers do require a frame. */
2635 CORE_ADDR read_addr_from_reg (int regnum) override
2636 {
2637 needs = SYMBOL_NEEDS_FRAME;
2638 return 1;
2639 }
2640
2641 /* "get_reg_value" callback: Reads from registers do require a
2642 frame. */
2643
2644 struct value *get_reg_value (struct type *type, int regnum) override
2645 {
2646 needs = SYMBOL_NEEDS_FRAME;
2647 return value_zero (type, not_lval);
2648 }
2649
2650 /* Reads from memory do not require a frame. */
2651 void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override
2652 {
2653 memset (buf, 0, len);
2654 }
2655
2656 /* Frame-relative accesses do require a frame. */
2657 void get_frame_base (const gdb_byte **start, size_t *length) override
2658 {
2659 static gdb_byte lit0 = DW_OP_lit0;
2660
2661 *start = &lit0;
2662 *length = 1;
2663
2664 needs = SYMBOL_NEEDS_FRAME;
2665 }
2666
2667 /* CFA accesses require a frame. */
2668 CORE_ADDR get_frame_cfa () override
2669 {
2670 needs = SYMBOL_NEEDS_FRAME;
2671 return 1;
2672 }
2673
2674 CORE_ADDR get_frame_pc () override
2675 {
2676 needs = SYMBOL_NEEDS_FRAME;
2677 return 1;
2678 }
2679
2680 /* Thread-local accesses require registers, but not a frame. */
2681 CORE_ADDR get_tls_address (CORE_ADDR offset) override
2682 {
2683 if (needs <= SYMBOL_NEEDS_REGISTERS)
2684 needs = SYMBOL_NEEDS_REGISTERS;
2685 return 1;
2686 }
2687
2688 /* Helper interface of per_cu_dwarf_call for
2689 dwarf2_loc_desc_get_symbol_read_needs. */
2690
2691 void dwarf_call (cu_offset die_offset) override
2692 {
2693 per_cu_dwarf_call (this, die_offset, per_cu);
2694 }
2695
2696 /* Helper interface of sect_variable_value for
2697 dwarf2_loc_desc_get_symbol_read_needs. */
2698
2699 struct value *dwarf_variable_value (sect_offset sect_off) override
2700 {
2701 return sect_variable_value (this, sect_off, per_cu);
2702 }
2703
2704 /* DW_OP_entry_value accesses require a caller, therefore a
2705 frame. */
2706
2707 void push_dwarf_reg_entry_value (enum call_site_parameter_kind kind,
2708 union call_site_parameter_u kind_u,
2709 int deref_size) override
2710 {
2711 needs = SYMBOL_NEEDS_FRAME;
2712
2713 /* The expression may require some stub values on DWARF stack. */
2714 push_address (0, 0);
2715 }
2716
2717 /* DW_OP_addrx and DW_OP_GNU_addr_index doesn't require a frame. */
2718
2719 CORE_ADDR get_addr_index (unsigned int index) override
2720 {
2721 /* Nothing to do. */
2722 return 1;
2723 }
2724
2725 /* DW_OP_push_object_address has a frame already passed through. */
2726
2727 CORE_ADDR get_object_address () override
2728 {
2729 /* Nothing to do. */
2730 return 1;
2731 }
2732 };
2733
2734 /* Compute the correct symbol_needs_kind value for the location
2735 expression at DATA (length SIZE). */
2736
2737 static enum symbol_needs_kind
2738 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
2739 struct dwarf2_per_cu_data *per_cu)
2740 {
2741 int in_reg;
2742 struct objfile *objfile = per_cu->objfile ();
2743
2744 scoped_value_mark free_values;
2745
2746 symbol_needs_eval_context ctx;
2747
2748 ctx.needs = SYMBOL_NEEDS_NONE;
2749 ctx.per_cu = per_cu;
2750 ctx.gdbarch = objfile->arch ();
2751 ctx.addr_size = per_cu->addr_size ();
2752 ctx.ref_addr_size = per_cu->ref_addr_size ();
2753 ctx.offset = per_cu->text_offset ();
2754
2755 ctx.eval (data, size);
2756
2757 in_reg = ctx.location == DWARF_VALUE_REGISTER;
2758
2759 /* If the location has several pieces, and any of them are in
2760 registers, then we will need a frame to fetch them from. */
2761 for (dwarf_expr_piece &p : ctx.pieces)
2762 if (p.location == DWARF_VALUE_REGISTER)
2763 in_reg = 1;
2764
2765 if (in_reg)
2766 ctx.needs = SYMBOL_NEEDS_FRAME;
2767 return ctx.needs;
2768 }
2769
2770 /* A helper function that throws an unimplemented error mentioning a
2771 given DWARF operator. */
2772
2773 static void ATTRIBUTE_NORETURN
2774 unimplemented (unsigned int op)
2775 {
2776 const char *name = get_DW_OP_name (op);
2777
2778 if (name)
2779 error (_("DWARF operator %s cannot be translated to an agent expression"),
2780 name);
2781 else
2782 error (_("Unknown DWARF operator 0x%02x cannot be translated "
2783 "to an agent expression"),
2784 op);
2785 }
2786
2787 /* See dwarf2loc.h.
2788
2789 This is basically a wrapper on gdbarch_dwarf2_reg_to_regnum so that we
2790 can issue a complaint, which is better than having every target's
2791 implementation of dwarf2_reg_to_regnum do it. */
2792
2793 int
2794 dwarf_reg_to_regnum (struct gdbarch *arch, int dwarf_reg)
2795 {
2796 int reg = gdbarch_dwarf2_reg_to_regnum (arch, dwarf_reg);
2797
2798 if (reg == -1)
2799 {
2800 complaint (_("bad DWARF register number %d"), dwarf_reg);
2801 }
2802 return reg;
2803 }
2804
2805 /* Subroutine of dwarf_reg_to_regnum_or_error to simplify it.
2806 Throw an error because DWARF_REG is bad. */
2807
2808 static void
2809 throw_bad_regnum_error (ULONGEST dwarf_reg)
2810 {
2811 /* Still want to print -1 as "-1".
2812 We *could* have int and ULONGEST versions of dwarf2_reg_to_regnum_or_error
2813 but that's overkill for now. */
2814 if ((int) dwarf_reg == dwarf_reg)
2815 error (_("Unable to access DWARF register number %d"), (int) dwarf_reg);
2816 error (_("Unable to access DWARF register number %s"),
2817 pulongest (dwarf_reg));
2818 }
2819
2820 /* See dwarf2loc.h. */
2821
2822 int
2823 dwarf_reg_to_regnum_or_error (struct gdbarch *arch, ULONGEST dwarf_reg)
2824 {
2825 int reg;
2826
2827 if (dwarf_reg > INT_MAX)
2828 throw_bad_regnum_error (dwarf_reg);
2829 /* Yes, we will end up issuing a complaint and an error if DWARF_REG is
2830 bad, but that's ok. */
2831 reg = dwarf_reg_to_regnum (arch, (int) dwarf_reg);
2832 if (reg == -1)
2833 throw_bad_regnum_error (dwarf_reg);
2834 return reg;
2835 }
2836
2837 /* A helper function that emits an access to memory. ARCH is the
2838 target architecture. EXPR is the expression which we are building.
2839 NBITS is the number of bits we want to read. This emits the
2840 opcodes needed to read the memory and then extract the desired
2841 bits. */
2842
2843 static void
2844 access_memory (struct gdbarch *arch, struct agent_expr *expr, ULONGEST nbits)
2845 {
2846 ULONGEST nbytes = (nbits + 7) / 8;
2847
2848 gdb_assert (nbytes > 0 && nbytes <= sizeof (LONGEST));
2849
2850 if (expr->tracing)
2851 ax_trace_quick (expr, nbytes);
2852
2853 if (nbits <= 8)
2854 ax_simple (expr, aop_ref8);
2855 else if (nbits <= 16)
2856 ax_simple (expr, aop_ref16);
2857 else if (nbits <= 32)
2858 ax_simple (expr, aop_ref32);
2859 else
2860 ax_simple (expr, aop_ref64);
2861
2862 /* If we read exactly the number of bytes we wanted, we're done. */
2863 if (8 * nbytes == nbits)
2864 return;
2865
2866 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
2867 {
2868 /* On a bits-big-endian machine, we want the high-order
2869 NBITS. */
2870 ax_const_l (expr, 8 * nbytes - nbits);
2871 ax_simple (expr, aop_rsh_unsigned);
2872 }
2873 else
2874 {
2875 /* On a bits-little-endian box, we want the low-order NBITS. */
2876 ax_zero_ext (expr, nbits);
2877 }
2878 }
2879
2880 /* A helper function to return the frame's PC. */
2881
2882 static CORE_ADDR
2883 get_ax_pc (void *baton)
2884 {
2885 struct agent_expr *expr = (struct agent_expr *) baton;
2886
2887 return expr->scope;
2888 }
2889
2890 /* Compile a DWARF location expression to an agent expression.
2891
2892 EXPR is the agent expression we are building.
2893 LOC is the agent value we modify.
2894 ARCH is the architecture.
2895 ADDR_SIZE is the size of addresses, in bytes.
2896 OP_PTR is the start of the location expression.
2897 OP_END is one past the last byte of the location expression.
2898
2899 This will throw an exception for various kinds of errors -- for
2900 example, if the expression cannot be compiled, or if the expression
2901 is invalid. */
2902
2903 static void
2904 dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
2905 unsigned int addr_size, const gdb_byte *op_ptr,
2906 const gdb_byte *op_end,
2907 struct dwarf2_per_cu_data *per_cu)
2908 {
2909 gdbarch *arch = expr->gdbarch;
2910 std::vector<int> dw_labels, patches;
2911 const gdb_byte * const base = op_ptr;
2912 const gdb_byte *previous_piece = op_ptr;
2913 enum bfd_endian byte_order = gdbarch_byte_order (arch);
2914 ULONGEST bits_collected = 0;
2915 unsigned int addr_size_bits = 8 * addr_size;
2916 bool bits_big_endian = byte_order == BFD_ENDIAN_BIG;
2917
2918 std::vector<int> offsets (op_end - op_ptr, -1);
2919
2920 /* By default we are making an address. */
2921 loc->kind = axs_lvalue_memory;
2922
2923 while (op_ptr < op_end)
2924 {
2925 enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr;
2926 uint64_t uoffset, reg;
2927 int64_t offset;
2928 int i;
2929
2930 offsets[op_ptr - base] = expr->len;
2931 ++op_ptr;
2932
2933 /* Our basic approach to code generation is to map DWARF
2934 operations directly to AX operations. However, there are
2935 some differences.
2936
2937 First, DWARF works on address-sized units, but AX always uses
2938 LONGEST. For most operations we simply ignore this
2939 difference; instead we generate sign extensions as needed
2940 before division and comparison operations. It would be nice
2941 to omit the sign extensions, but there is no way to determine
2942 the size of the target's LONGEST. (This code uses the size
2943 of the host LONGEST in some cases -- that is a bug but it is
2944 difficult to fix.)
2945
2946 Second, some DWARF operations cannot be translated to AX.
2947 For these we simply fail. See
2948 http://sourceware.org/bugzilla/show_bug.cgi?id=11662. */
2949 switch (op)
2950 {
2951 case DW_OP_lit0:
2952 case DW_OP_lit1:
2953 case DW_OP_lit2:
2954 case DW_OP_lit3:
2955 case DW_OP_lit4:
2956 case DW_OP_lit5:
2957 case DW_OP_lit6:
2958 case DW_OP_lit7:
2959 case DW_OP_lit8:
2960 case DW_OP_lit9:
2961 case DW_OP_lit10:
2962 case DW_OP_lit11:
2963 case DW_OP_lit12:
2964 case DW_OP_lit13:
2965 case DW_OP_lit14:
2966 case DW_OP_lit15:
2967 case DW_OP_lit16:
2968 case DW_OP_lit17:
2969 case DW_OP_lit18:
2970 case DW_OP_lit19:
2971 case DW_OP_lit20:
2972 case DW_OP_lit21:
2973 case DW_OP_lit22:
2974 case DW_OP_lit23:
2975 case DW_OP_lit24:
2976 case DW_OP_lit25:
2977 case DW_OP_lit26:
2978 case DW_OP_lit27:
2979 case DW_OP_lit28:
2980 case DW_OP_lit29:
2981 case DW_OP_lit30:
2982 case DW_OP_lit31:
2983 ax_const_l (expr, op - DW_OP_lit0);
2984 break;
2985
2986 case DW_OP_addr:
2987 uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
2988 op_ptr += addr_size;
2989 /* Some versions of GCC emit DW_OP_addr before
2990 DW_OP_GNU_push_tls_address. In this case the value is an
2991 index, not an address. We don't support things like
2992 branching between the address and the TLS op. */
2993 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
2994 uoffset += per_cu->text_offset ();
2995 ax_const_l (expr, uoffset);
2996 break;
2997
2998 case DW_OP_const1u:
2999 ax_const_l (expr, extract_unsigned_integer (op_ptr, 1, byte_order));
3000 op_ptr += 1;
3001 break;
3002 case DW_OP_const1s:
3003 ax_const_l (expr, extract_signed_integer (op_ptr, 1, byte_order));
3004 op_ptr += 1;
3005 break;
3006 case DW_OP_const2u:
3007 ax_const_l (expr, extract_unsigned_integer (op_ptr, 2, byte_order));
3008 op_ptr += 2;
3009 break;
3010 case DW_OP_const2s:
3011 ax_const_l (expr, extract_signed_integer (op_ptr, 2, byte_order));
3012 op_ptr += 2;
3013 break;
3014 case DW_OP_const4u:
3015 ax_const_l (expr, extract_unsigned_integer (op_ptr, 4, byte_order));
3016 op_ptr += 4;
3017 break;
3018 case DW_OP_const4s:
3019 ax_const_l (expr, extract_signed_integer (op_ptr, 4, byte_order));
3020 op_ptr += 4;
3021 break;
3022 case DW_OP_const8u:
3023 ax_const_l (expr, extract_unsigned_integer (op_ptr, 8, byte_order));
3024 op_ptr += 8;
3025 break;
3026 case DW_OP_const8s:
3027 ax_const_l (expr, extract_signed_integer (op_ptr, 8, byte_order));
3028 op_ptr += 8;
3029 break;
3030 case DW_OP_constu:
3031 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
3032 ax_const_l (expr, uoffset);
3033 break;
3034 case DW_OP_consts:
3035 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
3036 ax_const_l (expr, offset);
3037 break;
3038
3039 case DW_OP_reg0:
3040 case DW_OP_reg1:
3041 case DW_OP_reg2:
3042 case DW_OP_reg3:
3043 case DW_OP_reg4:
3044 case DW_OP_reg5:
3045 case DW_OP_reg6:
3046 case DW_OP_reg7:
3047 case DW_OP_reg8:
3048 case DW_OP_reg9:
3049 case DW_OP_reg10:
3050 case DW_OP_reg11:
3051 case DW_OP_reg12:
3052 case DW_OP_reg13:
3053 case DW_OP_reg14:
3054 case DW_OP_reg15:
3055 case DW_OP_reg16:
3056 case DW_OP_reg17:
3057 case DW_OP_reg18:
3058 case DW_OP_reg19:
3059 case DW_OP_reg20:
3060 case DW_OP_reg21:
3061 case DW_OP_reg22:
3062 case DW_OP_reg23:
3063 case DW_OP_reg24:
3064 case DW_OP_reg25:
3065 case DW_OP_reg26:
3066 case DW_OP_reg27:
3067 case DW_OP_reg28:
3068 case DW_OP_reg29:
3069 case DW_OP_reg30:
3070 case DW_OP_reg31:
3071 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
3072 loc->u.reg = dwarf_reg_to_regnum_or_error (arch, op - DW_OP_reg0);
3073 loc->kind = axs_lvalue_register;
3074 break;
3075
3076 case DW_OP_regx:
3077 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
3078 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
3079 loc->u.reg = dwarf_reg_to_regnum_or_error (arch, reg);
3080 loc->kind = axs_lvalue_register;
3081 break;
3082
3083 case DW_OP_implicit_value:
3084 {
3085 uint64_t len;
3086
3087 op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
3088 if (op_ptr + len > op_end)
3089 error (_("DW_OP_implicit_value: too few bytes available."));
3090 if (len > sizeof (ULONGEST))
3091 error (_("Cannot translate DW_OP_implicit_value of %d bytes"),
3092 (int) len);
3093
3094 ax_const_l (expr, extract_unsigned_integer (op_ptr, len,
3095 byte_order));
3096 op_ptr += len;
3097 dwarf_expr_require_composition (op_ptr, op_end,
3098 "DW_OP_implicit_value");
3099
3100 loc->kind = axs_rvalue;
3101 }
3102 break;
3103
3104 case DW_OP_stack_value:
3105 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
3106 loc->kind = axs_rvalue;
3107 break;
3108
3109 case DW_OP_breg0:
3110 case DW_OP_breg1:
3111 case DW_OP_breg2:
3112 case DW_OP_breg3:
3113 case DW_OP_breg4:
3114 case DW_OP_breg5:
3115 case DW_OP_breg6:
3116 case DW_OP_breg7:
3117 case DW_OP_breg8:
3118 case DW_OP_breg9:
3119 case DW_OP_breg10:
3120 case DW_OP_breg11:
3121 case DW_OP_breg12:
3122 case DW_OP_breg13:
3123 case DW_OP_breg14:
3124 case DW_OP_breg15:
3125 case DW_OP_breg16:
3126 case DW_OP_breg17:
3127 case DW_OP_breg18:
3128 case DW_OP_breg19:
3129 case DW_OP_breg20:
3130 case DW_OP_breg21:
3131 case DW_OP_breg22:
3132 case DW_OP_breg23:
3133 case DW_OP_breg24:
3134 case DW_OP_breg25:
3135 case DW_OP_breg26:
3136 case DW_OP_breg27:
3137 case DW_OP_breg28:
3138 case DW_OP_breg29:
3139 case DW_OP_breg30:
3140 case DW_OP_breg31:
3141 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
3142 i = dwarf_reg_to_regnum_or_error (arch, op - DW_OP_breg0);
3143 ax_reg (expr, i);
3144 if (offset != 0)
3145 {
3146 ax_const_l (expr, offset);
3147 ax_simple (expr, aop_add);
3148 }
3149 break;
3150 case DW_OP_bregx:
3151 {
3152 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
3153 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
3154 i = dwarf_reg_to_regnum_or_error (arch, reg);
3155 ax_reg (expr, i);
3156 if (offset != 0)
3157 {
3158 ax_const_l (expr, offset);
3159 ax_simple (expr, aop_add);
3160 }
3161 }
3162 break;
3163 case DW_OP_fbreg:
3164 {
3165 const gdb_byte *datastart;
3166 size_t datalen;
3167 const struct block *b;
3168 struct symbol *framefunc;
3169
3170 b = block_for_pc (expr->scope);
3171
3172 if (!b)
3173 error (_("No block found for address"));
3174
3175 framefunc = block_linkage_function (b);
3176
3177 if (!framefunc)
3178 error (_("No function found for block"));
3179
3180 func_get_frame_base_dwarf_block (framefunc, expr->scope,
3181 &datastart, &datalen);
3182
3183 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
3184 dwarf2_compile_expr_to_ax (expr, loc, addr_size, datastart,
3185 datastart + datalen, per_cu);
3186 if (loc->kind == axs_lvalue_register)
3187 require_rvalue (expr, loc);
3188
3189 if (offset != 0)
3190 {
3191 ax_const_l (expr, offset);
3192 ax_simple (expr, aop_add);
3193 }
3194
3195 loc->kind = axs_lvalue_memory;
3196 }
3197 break;
3198
3199 case DW_OP_dup:
3200 ax_simple (expr, aop_dup);
3201 break;
3202
3203 case DW_OP_drop:
3204 ax_simple (expr, aop_pop);
3205 break;
3206
3207 case DW_OP_pick:
3208 offset = *op_ptr++;
3209 ax_pick (expr, offset);
3210 break;
3211
3212 case DW_OP_swap:
3213 ax_simple (expr, aop_swap);
3214 break;
3215
3216 case DW_OP_over:
3217 ax_pick (expr, 1);
3218 break;
3219
3220 case DW_OP_rot:
3221 ax_simple (expr, aop_rot);
3222 break;
3223
3224 case DW_OP_deref:
3225 case DW_OP_deref_size:
3226 {
3227 int size;
3228
3229 if (op == DW_OP_deref_size)
3230 size = *op_ptr++;
3231 else
3232 size = addr_size;
3233
3234 if (size != 1 && size != 2 && size != 4 && size != 8)
3235 error (_("Unsupported size %d in %s"),
3236 size, get_DW_OP_name (op));
3237 access_memory (arch, expr, size * TARGET_CHAR_BIT);
3238 }
3239 break;
3240
3241 case DW_OP_abs:
3242 /* Sign extend the operand. */
3243 ax_ext (expr, addr_size_bits);
3244 ax_simple (expr, aop_dup);
3245 ax_const_l (expr, 0);
3246 ax_simple (expr, aop_less_signed);
3247 ax_simple (expr, aop_log_not);
3248 i = ax_goto (expr, aop_if_goto);
3249 /* We have to emit 0 - X. */
3250 ax_const_l (expr, 0);
3251 ax_simple (expr, aop_swap);
3252 ax_simple (expr, aop_sub);
3253 ax_label (expr, i, expr->len);
3254 break;
3255
3256 case DW_OP_neg:
3257 /* No need to sign extend here. */
3258 ax_const_l (expr, 0);
3259 ax_simple (expr, aop_swap);
3260 ax_simple (expr, aop_sub);
3261 break;
3262
3263 case DW_OP_not:
3264 /* Sign extend the operand. */
3265 ax_ext (expr, addr_size_bits);
3266 ax_simple (expr, aop_bit_not);
3267 break;
3268
3269 case DW_OP_plus_uconst:
3270 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
3271 /* It would be really weird to emit `DW_OP_plus_uconst 0',
3272 but we micro-optimize anyhow. */
3273 if (reg != 0)
3274 {
3275 ax_const_l (expr, reg);
3276 ax_simple (expr, aop_add);
3277 }
3278 break;
3279
3280 case DW_OP_and:
3281 ax_simple (expr, aop_bit_and);
3282 break;
3283
3284 case DW_OP_div:
3285 /* Sign extend the operands. */
3286 ax_ext (expr, addr_size_bits);
3287 ax_simple (expr, aop_swap);
3288 ax_ext (expr, addr_size_bits);
3289 ax_simple (expr, aop_swap);
3290 ax_simple (expr, aop_div_signed);
3291 break;
3292
3293 case DW_OP_minus:
3294 ax_simple (expr, aop_sub);
3295 break;
3296
3297 case DW_OP_mod:
3298 ax_simple (expr, aop_rem_unsigned);
3299 break;
3300
3301 case DW_OP_mul:
3302 ax_simple (expr, aop_mul);
3303 break;
3304
3305 case DW_OP_or:
3306 ax_simple (expr, aop_bit_or);
3307 break;
3308
3309 case DW_OP_plus:
3310 ax_simple (expr, aop_add);
3311 break;
3312
3313 case DW_OP_shl:
3314 ax_simple (expr, aop_lsh);
3315 break;
3316
3317 case DW_OP_shr:
3318 ax_simple (expr, aop_rsh_unsigned);
3319 break;
3320
3321 case DW_OP_shra:
3322 ax_simple (expr, aop_rsh_signed);
3323 break;
3324
3325 case DW_OP_xor:
3326 ax_simple (expr, aop_bit_xor);
3327 break;
3328
3329 case DW_OP_le:
3330 /* Sign extend the operands. */
3331 ax_ext (expr, addr_size_bits);
3332 ax_simple (expr, aop_swap);
3333 ax_ext (expr, addr_size_bits);
3334 /* Note no swap here: A <= B is !(B < A). */
3335 ax_simple (expr, aop_less_signed);
3336 ax_simple (expr, aop_log_not);
3337 break;
3338
3339 case DW_OP_ge:
3340 /* Sign extend the operands. */
3341 ax_ext (expr, addr_size_bits);
3342 ax_simple (expr, aop_swap);
3343 ax_ext (expr, addr_size_bits);
3344 ax_simple (expr, aop_swap);
3345 /* A >= B is !(A < B). */
3346 ax_simple (expr, aop_less_signed);
3347 ax_simple (expr, aop_log_not);
3348 break;
3349
3350 case DW_OP_eq:
3351 /* Sign extend the operands. */
3352 ax_ext (expr, addr_size_bits);
3353 ax_simple (expr, aop_swap);
3354 ax_ext (expr, addr_size_bits);
3355 /* No need for a second swap here. */
3356 ax_simple (expr, aop_equal);
3357 break;
3358
3359 case DW_OP_lt:
3360 /* Sign extend the operands. */
3361 ax_ext (expr, addr_size_bits);
3362 ax_simple (expr, aop_swap);
3363 ax_ext (expr, addr_size_bits);
3364 ax_simple (expr, aop_swap);
3365 ax_simple (expr, aop_less_signed);
3366 break;
3367
3368 case DW_OP_gt:
3369 /* Sign extend the operands. */
3370 ax_ext (expr, addr_size_bits);
3371 ax_simple (expr, aop_swap);
3372 ax_ext (expr, addr_size_bits);
3373 /* Note no swap here: A > B is B < A. */
3374 ax_simple (expr, aop_less_signed);
3375 break;
3376
3377 case DW_OP_ne:
3378 /* Sign extend the operands. */
3379 ax_ext (expr, addr_size_bits);
3380 ax_simple (expr, aop_swap);
3381 ax_ext (expr, addr_size_bits);
3382 /* No need for a swap here. */
3383 ax_simple (expr, aop_equal);
3384 ax_simple (expr, aop_log_not);
3385 break;
3386
3387 case DW_OP_call_frame_cfa:
3388 {
3389 int regnum;
3390 CORE_ADDR text_offset;
3391 LONGEST off;
3392 const gdb_byte *cfa_start, *cfa_end;
3393
3394 if (dwarf2_fetch_cfa_info (arch, expr->scope, per_cu,
3395 &regnum, &off,
3396 &text_offset, &cfa_start, &cfa_end))
3397 {
3398 /* Register. */
3399 ax_reg (expr, regnum);
3400 if (off != 0)
3401 {
3402 ax_const_l (expr, off);
3403 ax_simple (expr, aop_add);
3404 }
3405 }
3406 else
3407 {
3408 /* Another expression. */
3409 ax_const_l (expr, text_offset);
3410 dwarf2_compile_expr_to_ax (expr, loc, addr_size, cfa_start,
3411 cfa_end, per_cu);
3412 }
3413
3414 loc->kind = axs_lvalue_memory;
3415 }
3416 break;
3417
3418 case DW_OP_GNU_push_tls_address:
3419 case DW_OP_form_tls_address:
3420 unimplemented (op);
3421 break;
3422
3423 case DW_OP_push_object_address:
3424 unimplemented (op);
3425 break;
3426
3427 case DW_OP_skip:
3428 offset = extract_signed_integer (op_ptr, 2, byte_order);
3429 op_ptr += 2;
3430 i = ax_goto (expr, aop_goto);
3431 dw_labels.push_back (op_ptr + offset - base);
3432 patches.push_back (i);
3433 break;
3434
3435 case DW_OP_bra:
3436 offset = extract_signed_integer (op_ptr, 2, byte_order);
3437 op_ptr += 2;
3438 /* Zero extend the operand. */
3439 ax_zero_ext (expr, addr_size_bits);
3440 i = ax_goto (expr, aop_if_goto);
3441 dw_labels.push_back (op_ptr + offset - base);
3442 patches.push_back (i);
3443 break;
3444
3445 case DW_OP_nop:
3446 break;
3447
3448 case DW_OP_piece:
3449 case DW_OP_bit_piece:
3450 {
3451 uint64_t size;
3452
3453 if (op_ptr - 1 == previous_piece)
3454 error (_("Cannot translate empty pieces to agent expressions"));
3455 previous_piece = op_ptr - 1;
3456
3457 op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
3458 if (op == DW_OP_piece)
3459 {
3460 size *= 8;
3461 uoffset = 0;
3462 }
3463 else
3464 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
3465
3466 if (bits_collected + size > 8 * sizeof (LONGEST))
3467 error (_("Expression pieces exceed word size"));
3468
3469 /* Access the bits. */
3470 switch (loc->kind)
3471 {
3472 case axs_lvalue_register:
3473 ax_reg (expr, loc->u.reg);
3474 break;
3475
3476 case axs_lvalue_memory:
3477 /* Offset the pointer, if needed. */
3478 if (uoffset > 8)
3479 {
3480 ax_const_l (expr, uoffset / 8);
3481 ax_simple (expr, aop_add);
3482 uoffset %= 8;
3483 }
3484 access_memory (arch, expr, size);
3485 break;
3486 }
3487
3488 /* For a bits-big-endian target, shift up what we already
3489 have. For a bits-little-endian target, shift up the
3490 new data. Note that there is a potential bug here if
3491 the DWARF expression leaves multiple values on the
3492 stack. */
3493 if (bits_collected > 0)
3494 {
3495 if (bits_big_endian)
3496 {
3497 ax_simple (expr, aop_swap);
3498 ax_const_l (expr, size);
3499 ax_simple (expr, aop_lsh);
3500 /* We don't need a second swap here, because
3501 aop_bit_or is symmetric. */
3502 }
3503 else
3504 {
3505 ax_const_l (expr, size);
3506 ax_simple (expr, aop_lsh);
3507 }
3508 ax_simple (expr, aop_bit_or);
3509 }
3510
3511 bits_collected += size;
3512 loc->kind = axs_rvalue;
3513 }
3514 break;
3515
3516 case DW_OP_GNU_uninit:
3517 unimplemented (op);
3518
3519 case DW_OP_call2:
3520 case DW_OP_call4:
3521 {
3522 struct dwarf2_locexpr_baton block;
3523 int size = (op == DW_OP_call2 ? 2 : 4);
3524
3525 uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
3526 op_ptr += size;
3527
3528 cu_offset cuoffset = (cu_offset) uoffset;
3529 block = dwarf2_fetch_die_loc_cu_off (cuoffset, per_cu,
3530 get_ax_pc, expr);
3531
3532 /* DW_OP_call_ref is currently not supported. */
3533 gdb_assert (block.per_cu == per_cu);
3534
3535 dwarf2_compile_expr_to_ax (expr, loc, addr_size, block.data,
3536 block.data + block.size, per_cu);
3537 }
3538 break;
3539
3540 case DW_OP_call_ref:
3541 unimplemented (op);
3542
3543 case DW_OP_GNU_variable_value:
3544 unimplemented (op);
3545
3546 default:
3547 unimplemented (op);
3548 }
3549 }
3550
3551 /* Patch all the branches we emitted. */
3552 for (int i = 0; i < patches.size (); ++i)
3553 {
3554 int targ = offsets[dw_labels[i]];
3555 if (targ == -1)
3556 internal_error (__FILE__, __LINE__, _("invalid label"));
3557 ax_label (expr, patches[i], targ);
3558 }
3559 }
3560
3561 \f
3562 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
3563 evaluator to calculate the location. */
3564 static struct value *
3565 locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
3566 {
3567 struct dwarf2_locexpr_baton *dlbaton
3568 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
3569 struct value *val;
3570
3571 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
3572 dlbaton->size, dlbaton->per_cu);
3573
3574 return val;
3575 }
3576
3577 /* Return the value of SYMBOL in FRAME at (callee) FRAME's function
3578 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
3579 will be thrown. */
3580
3581 static struct value *
3582 locexpr_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
3583 {
3584 struct dwarf2_locexpr_baton *dlbaton
3585 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
3586
3587 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, dlbaton->data,
3588 dlbaton->size);
3589 }
3590
3591 /* Implementation of get_symbol_read_needs from
3592 symbol_computed_ops. */
3593
3594 static enum symbol_needs_kind
3595 locexpr_get_symbol_read_needs (struct symbol *symbol)
3596 {
3597 struct dwarf2_locexpr_baton *dlbaton
3598 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
3599
3600 return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size,
3601 dlbaton->per_cu);
3602 }
3603
3604 /* Return true if DATA points to the end of a piece. END is one past
3605 the last byte in the expression. */
3606
3607 static int
3608 piece_end_p (const gdb_byte *data, const gdb_byte *end)
3609 {
3610 return data == end || data[0] == DW_OP_piece || data[0] == DW_OP_bit_piece;
3611 }
3612
3613 /* Helper for locexpr_describe_location_piece that finds the name of a
3614 DWARF register. */
3615
3616 static const char *
3617 locexpr_regname (struct gdbarch *gdbarch, int dwarf_regnum)
3618 {
3619 int regnum;
3620
3621 /* This doesn't use dwarf_reg_to_regnum_or_error on purpose.
3622 We'd rather print *something* here than throw an error. */
3623 regnum = dwarf_reg_to_regnum (gdbarch, dwarf_regnum);
3624 /* gdbarch_register_name may just return "", return something more
3625 descriptive for bad register numbers. */
3626 if (regnum == -1)
3627 {
3628 /* The text is output as "$bad_register_number".
3629 That is why we use the underscores. */
3630 return _("bad_register_number");
3631 }
3632 return gdbarch_register_name (gdbarch, regnum);
3633 }
3634
3635 /* Nicely describe a single piece of a location, returning an updated
3636 position in the bytecode sequence. This function cannot recognize
3637 all locations; if a location is not recognized, it simply returns
3638 DATA. If there is an error during reading, e.g. we run off the end
3639 of the buffer, an error is thrown. */
3640
3641 static const gdb_byte *
3642 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
3643 CORE_ADDR addr, struct objfile *objfile,
3644 struct dwarf2_per_cu_data *per_cu,
3645 const gdb_byte *data, const gdb_byte *end,
3646 unsigned int addr_size)
3647 {
3648 struct gdbarch *gdbarch = objfile->arch ();
3649 size_t leb128_size;
3650
3651 if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
3652 {
3653 fprintf_filtered (stream, _("a variable in $%s"),
3654 locexpr_regname (gdbarch, data[0] - DW_OP_reg0));
3655 data += 1;
3656 }
3657 else if (data[0] == DW_OP_regx)
3658 {
3659 uint64_t reg;
3660
3661 data = safe_read_uleb128 (data + 1, end, &reg);
3662 fprintf_filtered (stream, _("a variable in $%s"),
3663 locexpr_regname (gdbarch, reg));
3664 }
3665 else if (data[0] == DW_OP_fbreg)
3666 {
3667 const struct block *b;
3668 struct symbol *framefunc;
3669 int frame_reg = 0;
3670 int64_t frame_offset;
3671 const gdb_byte *base_data, *new_data, *save_data = data;
3672 size_t base_size;
3673 int64_t base_offset = 0;
3674
3675 new_data = safe_read_sleb128 (data + 1, end, &frame_offset);
3676 if (!piece_end_p (new_data, end))
3677 return data;
3678 data = new_data;
3679
3680 b = block_for_pc (addr);
3681
3682 if (!b)
3683 error (_("No block found for address for symbol \"%s\"."),
3684 symbol->print_name ());
3685
3686 framefunc = block_linkage_function (b);
3687
3688 if (!framefunc)
3689 error (_("No function found for block for symbol \"%s\"."),
3690 symbol->print_name ());
3691
3692 func_get_frame_base_dwarf_block (framefunc, addr, &base_data, &base_size);
3693
3694 if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
3695 {
3696 const gdb_byte *buf_end;
3697
3698 frame_reg = base_data[0] - DW_OP_breg0;
3699 buf_end = safe_read_sleb128 (base_data + 1, base_data + base_size,
3700 &base_offset);
3701 if (buf_end != base_data + base_size)
3702 error (_("Unexpected opcode after "
3703 "DW_OP_breg%u for symbol \"%s\"."),
3704 frame_reg, symbol->print_name ());
3705 }
3706 else if (base_data[0] >= DW_OP_reg0 && base_data[0] <= DW_OP_reg31)
3707 {
3708 /* The frame base is just the register, with no offset. */
3709 frame_reg = base_data[0] - DW_OP_reg0;
3710 base_offset = 0;
3711 }
3712 else
3713 {
3714 /* We don't know what to do with the frame base expression,
3715 so we can't trace this variable; give up. */
3716 return save_data;
3717 }
3718
3719 fprintf_filtered (stream,
3720 _("a variable at frame base reg $%s offset %s+%s"),
3721 locexpr_regname (gdbarch, frame_reg),
3722 plongest (base_offset), plongest (frame_offset));
3723 }
3724 else if (data[0] >= DW_OP_breg0 && data[0] <= DW_OP_breg31
3725 && piece_end_p (data, end))
3726 {
3727 int64_t offset;
3728
3729 data = safe_read_sleb128 (data + 1, end, &offset);
3730
3731 fprintf_filtered (stream,
3732 _("a variable at offset %s from base reg $%s"),
3733 plongest (offset),
3734 locexpr_regname (gdbarch, data[0] - DW_OP_breg0));
3735 }
3736
3737 /* The location expression for a TLS variable looks like this (on a
3738 64-bit LE machine):
3739
3740 DW_AT_location : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
3741 (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
3742
3743 0x3 is the encoding for DW_OP_addr, which has an operand as long
3744 as the size of an address on the target machine (here is 8
3745 bytes). Note that more recent version of GCC emit DW_OP_const4u
3746 or DW_OP_const8u, depending on address size, rather than
3747 DW_OP_addr. 0xe0 is the encoding for DW_OP_GNU_push_tls_address.
3748 The operand represents the offset at which the variable is within
3749 the thread local storage. */
3750
3751 else if (data + 1 + addr_size < end
3752 && (data[0] == DW_OP_addr
3753 || (addr_size == 4 && data[0] == DW_OP_const4u)
3754 || (addr_size == 8 && data[0] == DW_OP_const8u))
3755 && (data[1 + addr_size] == DW_OP_GNU_push_tls_address
3756 || data[1 + addr_size] == DW_OP_form_tls_address)
3757 && piece_end_p (data + 2 + addr_size, end))
3758 {
3759 ULONGEST offset;
3760 offset = extract_unsigned_integer (data + 1, addr_size,
3761 gdbarch_byte_order (gdbarch));
3762
3763 fprintf_filtered (stream,
3764 _("a thread-local variable at offset 0x%s "
3765 "in the thread-local storage for `%s'"),
3766 phex_nz (offset, addr_size), objfile_name (objfile));
3767
3768 data += 1 + addr_size + 1;
3769 }
3770
3771 /* With -gsplit-dwarf a TLS variable can also look like this:
3772 DW_AT_location : 3 byte block: fc 4 e0
3773 (DW_OP_GNU_const_index: 4;
3774 DW_OP_GNU_push_tls_address) */
3775 else if (data + 3 <= end
3776 && data + 1 + (leb128_size = skip_leb128 (data + 1, end)) < end
3777 && data[0] == DW_OP_GNU_const_index
3778 && leb128_size > 0
3779 && (data[1 + leb128_size] == DW_OP_GNU_push_tls_address
3780 || data[1 + leb128_size] == DW_OP_form_tls_address)
3781 && piece_end_p (data + 2 + leb128_size, end))
3782 {
3783 uint64_t offset;
3784
3785 data = safe_read_uleb128 (data + 1, end, &offset);
3786 offset = dwarf2_read_addr_index (per_cu, offset);
3787 fprintf_filtered (stream,
3788 _("a thread-local variable at offset 0x%s "
3789 "in the thread-local storage for `%s'"),
3790 phex_nz (offset, addr_size), objfile_name (objfile));
3791 ++data;
3792 }
3793
3794 else if (data[0] >= DW_OP_lit0
3795 && data[0] <= DW_OP_lit31
3796 && data + 1 < end
3797 && data[1] == DW_OP_stack_value)
3798 {
3799 fprintf_filtered (stream, _("the constant %d"), data[0] - DW_OP_lit0);
3800 data += 2;
3801 }
3802
3803 return data;
3804 }
3805
3806 /* Disassemble an expression, stopping at the end of a piece or at the
3807 end of the expression. Returns a pointer to the next unread byte
3808 in the input expression. If ALL is nonzero, then this function
3809 will keep going until it reaches the end of the expression.
3810 If there is an error during reading, e.g. we run off the end
3811 of the buffer, an error is thrown. */
3812
3813 static const gdb_byte *
3814 disassemble_dwarf_expression (struct ui_file *stream,
3815 struct gdbarch *arch, unsigned int addr_size,
3816 int offset_size, const gdb_byte *start,
3817 const gdb_byte *data, const gdb_byte *end,
3818 int indent, int all,
3819 struct dwarf2_per_cu_data *per_cu)
3820 {
3821 while (data < end
3822 && (all
3823 || (data[0] != DW_OP_piece && data[0] != DW_OP_bit_piece)))
3824 {
3825 enum dwarf_location_atom op = (enum dwarf_location_atom) *data++;
3826 uint64_t ul;
3827 int64_t l;
3828 const char *name;
3829
3830 name = get_DW_OP_name (op);
3831
3832 if (!name)
3833 error (_("Unrecognized DWARF opcode 0x%02x at %ld"),
3834 op, (long) (data - 1 - start));
3835 fprintf_filtered (stream, " %*ld: %s", indent + 4,
3836 (long) (data - 1 - start), name);
3837
3838 switch (op)
3839 {
3840 case DW_OP_addr:
3841 ul = extract_unsigned_integer (data, addr_size,
3842 gdbarch_byte_order (arch));
3843 data += addr_size;
3844 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
3845 break;
3846
3847 case DW_OP_const1u:
3848 ul = extract_unsigned_integer (data, 1, gdbarch_byte_order (arch));
3849 data += 1;
3850 fprintf_filtered (stream, " %s", pulongest (ul));
3851 break;
3852 case DW_OP_const1s:
3853 l = extract_signed_integer (data, 1, gdbarch_byte_order (arch));
3854 data += 1;
3855 fprintf_filtered (stream, " %s", plongest (l));
3856 break;
3857 case DW_OP_const2u:
3858 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
3859 data += 2;
3860 fprintf_filtered (stream, " %s", pulongest (ul));
3861 break;
3862 case DW_OP_const2s:
3863 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
3864 data += 2;
3865 fprintf_filtered (stream, " %s", plongest (l));
3866 break;
3867 case DW_OP_const4u:
3868 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
3869 data += 4;
3870 fprintf_filtered (stream, " %s", pulongest (ul));
3871 break;
3872 case DW_OP_const4s:
3873 l = extract_signed_integer (data, 4, gdbarch_byte_order (arch));
3874 data += 4;
3875 fprintf_filtered (stream, " %s", plongest (l));
3876 break;
3877 case DW_OP_const8u:
3878 ul = extract_unsigned_integer (data, 8, gdbarch_byte_order (arch));
3879 data += 8;
3880 fprintf_filtered (stream, " %s", pulongest (ul));
3881 break;
3882 case DW_OP_const8s:
3883 l = extract_signed_integer (data, 8, gdbarch_byte_order (arch));
3884 data += 8;
3885 fprintf_filtered (stream, " %s", plongest (l));
3886 break;
3887 case DW_OP_constu:
3888 data = safe_read_uleb128 (data, end, &ul);
3889 fprintf_filtered (stream, " %s", pulongest (ul));
3890 break;
3891 case DW_OP_consts:
3892 data = safe_read_sleb128 (data, end, &l);
3893 fprintf_filtered (stream, " %s", plongest (l));
3894 break;
3895
3896 case DW_OP_reg0:
3897 case DW_OP_reg1:
3898 case DW_OP_reg2:
3899 case DW_OP_reg3:
3900 case DW_OP_reg4:
3901 case DW_OP_reg5:
3902 case DW_OP_reg6:
3903 case DW_OP_reg7:
3904 case DW_OP_reg8:
3905 case DW_OP_reg9:
3906 case DW_OP_reg10:
3907 case DW_OP_reg11:
3908 case DW_OP_reg12:
3909 case DW_OP_reg13:
3910 case DW_OP_reg14:
3911 case DW_OP_reg15:
3912 case DW_OP_reg16:
3913 case DW_OP_reg17:
3914 case DW_OP_reg18:
3915 case DW_OP_reg19:
3916 case DW_OP_reg20:
3917 case DW_OP_reg21:
3918 case DW_OP_reg22:
3919 case DW_OP_reg23:
3920 case DW_OP_reg24:
3921 case DW_OP_reg25:
3922 case DW_OP_reg26:
3923 case DW_OP_reg27:
3924 case DW_OP_reg28:
3925 case DW_OP_reg29:
3926 case DW_OP_reg30:
3927 case DW_OP_reg31:
3928 fprintf_filtered (stream, " [$%s]",
3929 locexpr_regname (arch, op - DW_OP_reg0));
3930 break;
3931
3932 case DW_OP_regx:
3933 data = safe_read_uleb128 (data, end, &ul);
3934 fprintf_filtered (stream, " %s [$%s]", pulongest (ul),
3935 locexpr_regname (arch, (int) ul));
3936 break;
3937
3938 case DW_OP_implicit_value:
3939 data = safe_read_uleb128 (data, end, &ul);
3940 data += ul;
3941 fprintf_filtered (stream, " %s", pulongest (ul));
3942 break;
3943
3944 case DW_OP_breg0:
3945 case DW_OP_breg1:
3946 case DW_OP_breg2:
3947 case DW_OP_breg3:
3948 case DW_OP_breg4:
3949 case DW_OP_breg5:
3950 case DW_OP_breg6:
3951 case DW_OP_breg7:
3952 case DW_OP_breg8:
3953 case DW_OP_breg9:
3954 case DW_OP_breg10:
3955 case DW_OP_breg11:
3956 case DW_OP_breg12:
3957 case DW_OP_breg13:
3958 case DW_OP_breg14:
3959 case DW_OP_breg15:
3960 case DW_OP_breg16:
3961 case DW_OP_breg17:
3962 case DW_OP_breg18:
3963 case DW_OP_breg19:
3964 case DW_OP_breg20:
3965 case DW_OP_breg21:
3966 case DW_OP_breg22:
3967 case DW_OP_breg23:
3968 case DW_OP_breg24:
3969 case DW_OP_breg25:
3970 case DW_OP_breg26:
3971 case DW_OP_breg27:
3972 case DW_OP_breg28:
3973 case DW_OP_breg29:
3974 case DW_OP_breg30:
3975 case DW_OP_breg31:
3976 data = safe_read_sleb128 (data, end, &l);
3977 fprintf_filtered (stream, " %s [$%s]", plongest (l),
3978 locexpr_regname (arch, op - DW_OP_breg0));
3979 break;
3980
3981 case DW_OP_bregx:
3982 data = safe_read_uleb128 (data, end, &ul);
3983 data = safe_read_sleb128 (data, end, &l);
3984 fprintf_filtered (stream, " register %s [$%s] offset %s",
3985 pulongest (ul),
3986 locexpr_regname (arch, (int) ul),
3987 plongest (l));
3988 break;
3989
3990 case DW_OP_fbreg:
3991 data = safe_read_sleb128 (data, end, &l);
3992 fprintf_filtered (stream, " %s", plongest (l));
3993 break;
3994
3995 case DW_OP_xderef_size:
3996 case DW_OP_deref_size:
3997 case DW_OP_pick:
3998 fprintf_filtered (stream, " %d", *data);
3999 ++data;
4000 break;
4001
4002 case DW_OP_plus_uconst:
4003 data = safe_read_uleb128 (data, end, &ul);
4004 fprintf_filtered (stream, " %s", pulongest (ul));
4005 break;
4006
4007 case DW_OP_skip:
4008 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
4009 data += 2;
4010 fprintf_filtered (stream, " to %ld",
4011 (long) (data + l - start));
4012 break;
4013
4014 case DW_OP_bra:
4015 l = extract_signed_integer (data, 2, gdbarch_byte_order (arch));
4016 data += 2;
4017 fprintf_filtered (stream, " %ld",
4018 (long) (data + l - start));
4019 break;
4020
4021 case DW_OP_call2:
4022 ul = extract_unsigned_integer (data, 2, gdbarch_byte_order (arch));
4023 data += 2;
4024 fprintf_filtered (stream, " offset %s", phex_nz (ul, 2));
4025 break;
4026
4027 case DW_OP_call4:
4028 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
4029 data += 4;
4030 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
4031 break;
4032
4033 case DW_OP_call_ref:
4034 ul = extract_unsigned_integer (data, offset_size,
4035 gdbarch_byte_order (arch));
4036 data += offset_size;
4037 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
4038 break;
4039
4040 case DW_OP_piece:
4041 data = safe_read_uleb128 (data, end, &ul);
4042 fprintf_filtered (stream, " %s (bytes)", pulongest (ul));
4043 break;
4044
4045 case DW_OP_bit_piece:
4046 {
4047 uint64_t offset;
4048
4049 data = safe_read_uleb128 (data, end, &ul);
4050 data = safe_read_uleb128 (data, end, &offset);
4051 fprintf_filtered (stream, " size %s offset %s (bits)",
4052 pulongest (ul), pulongest (offset));
4053 }
4054 break;
4055
4056 case DW_OP_implicit_pointer:
4057 case DW_OP_GNU_implicit_pointer:
4058 {
4059 ul = extract_unsigned_integer (data, offset_size,
4060 gdbarch_byte_order (arch));
4061 data += offset_size;
4062
4063 data = safe_read_sleb128 (data, end, &l);
4064
4065 fprintf_filtered (stream, " DIE %s offset %s",
4066 phex_nz (ul, offset_size),
4067 plongest (l));
4068 }
4069 break;
4070
4071 case DW_OP_deref_type:
4072 case DW_OP_GNU_deref_type:
4073 {
4074 int deref_addr_size = *data++;
4075 struct type *type;
4076
4077 data = safe_read_uleb128 (data, end, &ul);
4078 cu_offset offset = (cu_offset) ul;
4079 type = dwarf2_get_die_type (offset, per_cu);
4080 fprintf_filtered (stream, "<");
4081 type_print (type, "", stream, -1);
4082 fprintf_filtered (stream, " [0x%s]> %d",
4083 phex_nz (to_underlying (offset), 0),
4084 deref_addr_size);
4085 }
4086 break;
4087
4088 case DW_OP_const_type:
4089 case DW_OP_GNU_const_type:
4090 {
4091 struct type *type;
4092
4093 data = safe_read_uleb128 (data, end, &ul);
4094 cu_offset type_die = (cu_offset) ul;
4095 type = dwarf2_get_die_type (type_die, per_cu);
4096 fprintf_filtered (stream, "<");
4097 type_print (type, "", stream, -1);
4098 fprintf_filtered (stream, " [0x%s]>",
4099 phex_nz (to_underlying (type_die), 0));
4100
4101 int n = *data++;
4102 fprintf_filtered (stream, " %d byte block:", n);
4103 for (int i = 0; i < n; ++i)
4104 fprintf_filtered (stream, " %02x", data[i]);
4105 data += n;
4106 }
4107 break;
4108
4109 case DW_OP_regval_type:
4110 case DW_OP_GNU_regval_type:
4111 {
4112 uint64_t reg;
4113 struct type *type;
4114
4115 data = safe_read_uleb128 (data, end, &reg);
4116 data = safe_read_uleb128 (data, end, &ul);
4117 cu_offset type_die = (cu_offset) ul;
4118
4119 type = dwarf2_get_die_type (type_die, per_cu);
4120 fprintf_filtered (stream, "<");
4121 type_print (type, "", stream, -1);
4122 fprintf_filtered (stream, " [0x%s]> [$%s]",
4123 phex_nz (to_underlying (type_die), 0),
4124 locexpr_regname (arch, reg));
4125 }
4126 break;
4127
4128 case DW_OP_convert:
4129 case DW_OP_GNU_convert:
4130 case DW_OP_reinterpret:
4131 case DW_OP_GNU_reinterpret:
4132 {
4133 data = safe_read_uleb128 (data, end, &ul);
4134 cu_offset type_die = (cu_offset) ul;
4135
4136 if (to_underlying (type_die) == 0)
4137 fprintf_filtered (stream, "<0>");
4138 else
4139 {
4140 struct type *type;
4141
4142 type = dwarf2_get_die_type (type_die, per_cu);
4143 fprintf_filtered (stream, "<");
4144 type_print (type, "", stream, -1);
4145 fprintf_filtered (stream, " [0x%s]>",
4146 phex_nz (to_underlying (type_die), 0));
4147 }
4148 }
4149 break;
4150
4151 case DW_OP_entry_value:
4152 case DW_OP_GNU_entry_value:
4153 data = safe_read_uleb128 (data, end, &ul);
4154 fputc_filtered ('\n', stream);
4155 disassemble_dwarf_expression (stream, arch, addr_size, offset_size,
4156 start, data, data + ul, indent + 2,
4157 all, per_cu);
4158 data += ul;
4159 continue;
4160
4161 case DW_OP_GNU_parameter_ref:
4162 ul = extract_unsigned_integer (data, 4, gdbarch_byte_order (arch));
4163 data += 4;
4164 fprintf_filtered (stream, " offset %s", phex_nz (ul, 4));
4165 break;
4166
4167 case DW_OP_addrx:
4168 case DW_OP_GNU_addr_index:
4169 data = safe_read_uleb128 (data, end, &ul);
4170 ul = dwarf2_read_addr_index (per_cu, ul);
4171 fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
4172 break;
4173 case DW_OP_GNU_const_index:
4174 data = safe_read_uleb128 (data, end, &ul);
4175 ul = dwarf2_read_addr_index (per_cu, ul);
4176 fprintf_filtered (stream, " %s", pulongest (ul));
4177 break;
4178
4179 case DW_OP_GNU_variable_value:
4180 ul = extract_unsigned_integer (data, offset_size,
4181 gdbarch_byte_order (arch));
4182 data += offset_size;
4183 fprintf_filtered (stream, " offset %s", phex_nz (ul, offset_size));
4184 break;
4185 }
4186
4187 fprintf_filtered (stream, "\n");
4188 }
4189
4190 return data;
4191 }
4192
4193 static bool dwarf_always_disassemble;
4194
4195 static void
4196 show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
4197 struct cmd_list_element *c, const char *value)
4198 {
4199 fprintf_filtered (file,
4200 _("Whether to always disassemble "
4201 "DWARF expressions is %s.\n"),
4202 value);
4203 }
4204
4205 /* Describe a single location, which may in turn consist of multiple
4206 pieces. */
4207
4208 static void
4209 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
4210 struct ui_file *stream,
4211 const gdb_byte *data, size_t size,
4212 struct objfile *objfile, unsigned int addr_size,
4213 int offset_size, struct dwarf2_per_cu_data *per_cu)
4214 {
4215 const gdb_byte *end = data + size;
4216 int first_piece = 1, bad = 0;
4217
4218 while (data < end)
4219 {
4220 const gdb_byte *here = data;
4221 int disassemble = 1;
4222
4223 if (first_piece)
4224 first_piece = 0;
4225 else
4226 fprintf_filtered (stream, _(", and "));
4227
4228 if (!dwarf_always_disassemble)
4229 {
4230 data = locexpr_describe_location_piece (symbol, stream,
4231 addr, objfile, per_cu,
4232 data, end, addr_size);
4233 /* If we printed anything, or if we have an empty piece,
4234 then don't disassemble. */
4235 if (data != here
4236 || data[0] == DW_OP_piece
4237 || data[0] == DW_OP_bit_piece)
4238 disassemble = 0;
4239 }
4240 if (disassemble)
4241 {
4242 fprintf_filtered (stream, _("a complex DWARF expression:\n"));
4243 data = disassemble_dwarf_expression (stream,
4244 objfile->arch (),
4245 addr_size, offset_size, data,
4246 data, end, 0,
4247 dwarf_always_disassemble,
4248 per_cu);
4249 }
4250
4251 if (data < end)
4252 {
4253 int empty = data == here;
4254
4255 if (disassemble)
4256 fprintf_filtered (stream, " ");
4257 if (data[0] == DW_OP_piece)
4258 {
4259 uint64_t bytes;
4260
4261 data = safe_read_uleb128 (data + 1, end, &bytes);
4262
4263 if (empty)
4264 fprintf_filtered (stream, _("an empty %s-byte piece"),
4265 pulongest (bytes));
4266 else
4267 fprintf_filtered (stream, _(" [%s-byte piece]"),
4268 pulongest (bytes));
4269 }
4270 else if (data[0] == DW_OP_bit_piece)
4271 {
4272 uint64_t bits, offset;
4273
4274 data = safe_read_uleb128 (data + 1, end, &bits);
4275 data = safe_read_uleb128 (data, end, &offset);
4276
4277 if (empty)
4278 fprintf_filtered (stream,
4279 _("an empty %s-bit piece"),
4280 pulongest (bits));
4281 else
4282 fprintf_filtered (stream,
4283 _(" [%s-bit piece, offset %s bits]"),
4284 pulongest (bits), pulongest (offset));
4285 }
4286 else
4287 {
4288 bad = 1;
4289 break;
4290 }
4291 }
4292 }
4293
4294 if (bad || data > end)
4295 error (_("Corrupted DWARF2 expression for \"%s\"."),
4296 symbol->print_name ());
4297 }
4298
4299 /* Print a natural-language description of SYMBOL to STREAM. This
4300 version is for a symbol with a single location. */
4301
4302 static void
4303 locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
4304 struct ui_file *stream)
4305 {
4306 struct dwarf2_locexpr_baton *dlbaton
4307 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
4308 struct objfile *objfile = dlbaton->per_cu->objfile ();
4309 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4310 int offset_size = dlbaton->per_cu->offset_size ();
4311
4312 locexpr_describe_location_1 (symbol, addr, stream,
4313 dlbaton->data, dlbaton->size,
4314 objfile, addr_size, offset_size,
4315 dlbaton->per_cu);
4316 }
4317
4318 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4319 any necessary bytecode in AX. */
4320
4321 static void
4322 locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
4323 struct axs_value *value)
4324 {
4325 struct dwarf2_locexpr_baton *dlbaton
4326 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
4327 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4328
4329 if (dlbaton->size == 0)
4330 value->optimized_out = 1;
4331 else
4332 dwarf2_compile_expr_to_ax (ax, value, addr_size, dlbaton->data,
4333 dlbaton->data + dlbaton->size, dlbaton->per_cu);
4334 }
4335
4336 /* symbol_computed_ops 'generate_c_location' method. */
4337
4338 static void
4339 locexpr_generate_c_location (struct symbol *sym, string_file *stream,
4340 struct gdbarch *gdbarch,
4341 unsigned char *registers_used,
4342 CORE_ADDR pc, const char *result_name)
4343 {
4344 struct dwarf2_locexpr_baton *dlbaton
4345 = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
4346 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4347
4348 if (dlbaton->size == 0)
4349 error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
4350
4351 compile_dwarf_expr_to_c (stream, result_name,
4352 sym, pc, gdbarch, registers_used, addr_size,
4353 dlbaton->data, dlbaton->data + dlbaton->size,
4354 dlbaton->per_cu);
4355 }
4356
4357 /* The set of location functions used with the DWARF-2 expression
4358 evaluator. */
4359 const struct symbol_computed_ops dwarf2_locexpr_funcs = {
4360 locexpr_read_variable,
4361 locexpr_read_variable_at_entry,
4362 locexpr_get_symbol_read_needs,
4363 locexpr_describe_location,
4364 0, /* location_has_loclist */
4365 locexpr_tracepoint_var_ref,
4366 locexpr_generate_c_location
4367 };
4368
4369
4370 /* Wrapper functions for location lists. These generally find
4371 the appropriate location expression and call something above. */
4372
4373 /* Return the value of SYMBOL in FRAME using the DWARF-2 expression
4374 evaluator to calculate the location. */
4375 static struct value *
4376 loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
4377 {
4378 struct dwarf2_loclist_baton *dlbaton
4379 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
4380 struct value *val;
4381 const gdb_byte *data;
4382 size_t size;
4383 CORE_ADDR pc = frame ? get_frame_address_in_block (frame) : 0;
4384
4385 data = dwarf2_find_location_expression (dlbaton, &size, pc);
4386 val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
4387 dlbaton->per_cu);
4388
4389 return val;
4390 }
4391
4392 /* Read variable SYMBOL like loclist_read_variable at (callee) FRAME's function
4393 entry. SYMBOL should be a function parameter, otherwise NO_ENTRY_VALUE_ERROR
4394 will be thrown.
4395
4396 Function always returns non-NULL value, it may be marked optimized out if
4397 inferior frame information is not available. It throws NO_ENTRY_VALUE_ERROR
4398 if it cannot resolve the parameter for any reason. */
4399
4400 static struct value *
4401 loclist_read_variable_at_entry (struct symbol *symbol, struct frame_info *frame)
4402 {
4403 struct dwarf2_loclist_baton *dlbaton
4404 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
4405 const gdb_byte *data;
4406 size_t size;
4407 CORE_ADDR pc;
4408
4409 if (frame == NULL || !get_frame_func_if_available (frame, &pc))
4410 return allocate_optimized_out_value (SYMBOL_TYPE (symbol));
4411
4412 data = dwarf2_find_location_expression (dlbaton, &size, pc);
4413 if (data == NULL)
4414 return allocate_optimized_out_value (SYMBOL_TYPE (symbol));
4415
4416 return value_of_dwarf_block_entry (SYMBOL_TYPE (symbol), frame, data, size);
4417 }
4418
4419 /* Implementation of get_symbol_read_needs from
4420 symbol_computed_ops. */
4421
4422 static enum symbol_needs_kind
4423 loclist_symbol_needs (struct symbol *symbol)
4424 {
4425 /* If there's a location list, then assume we need to have a frame
4426 to choose the appropriate location expression. With tracking of
4427 global variables this is not necessarily true, but such tracking
4428 is disabled in GCC at the moment until we figure out how to
4429 represent it. */
4430
4431 return SYMBOL_NEEDS_FRAME;
4432 }
4433
4434 /* Print a natural-language description of SYMBOL to STREAM. This
4435 version applies when there is a list of different locations, each
4436 with a specified address range. */
4437
4438 static void
4439 loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
4440 struct ui_file *stream)
4441 {
4442 struct dwarf2_loclist_baton *dlbaton
4443 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
4444 const gdb_byte *loc_ptr, *buf_end;
4445 struct objfile *objfile = dlbaton->per_cu->objfile ();
4446 struct gdbarch *gdbarch = objfile->arch ();
4447 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4448 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4449 int offset_size = dlbaton->per_cu->offset_size ();
4450 int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
4451 /* Adjust base_address for relocatable objects. */
4452 CORE_ADDR base_offset = dlbaton->per_cu->text_offset ();
4453 CORE_ADDR base_address = dlbaton->base_address + base_offset;
4454 int done = 0;
4455
4456 loc_ptr = dlbaton->data;
4457 buf_end = dlbaton->data + dlbaton->size;
4458
4459 fprintf_filtered (stream, _("multi-location:\n"));
4460
4461 /* Iterate through locations until we run out. */
4462 while (!done)
4463 {
4464 CORE_ADDR low = 0, high = 0; /* init for gcc -Wall */
4465 int length;
4466 enum debug_loc_kind kind;
4467 const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
4468
4469 if (dlbaton->per_cu->version () < 5 && dlbaton->from_dwo)
4470 kind = decode_debug_loc_dwo_addresses (dlbaton->per_cu,
4471 loc_ptr, buf_end, &new_ptr,
4472 &low, &high, byte_order);
4473 else if (dlbaton->per_cu->version () < 5)
4474 kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
4475 &low, &high,
4476 byte_order, addr_size,
4477 signed_addr_p);
4478 else
4479 kind = decode_debug_loclists_addresses (dlbaton->per_cu,
4480 loc_ptr, buf_end, &new_ptr,
4481 &low, &high, byte_order,
4482 addr_size, signed_addr_p);
4483 loc_ptr = new_ptr;
4484 switch (kind)
4485 {
4486 case DEBUG_LOC_END_OF_LIST:
4487 done = 1;
4488 continue;
4489 case DEBUG_LOC_BASE_ADDRESS:
4490 base_address = high + base_offset;
4491 fprintf_filtered (stream, _(" Base address %s"),
4492 paddress (gdbarch, base_address));
4493 continue;
4494 case DEBUG_LOC_START_END:
4495 case DEBUG_LOC_START_LENGTH:
4496 case DEBUG_LOC_OFFSET_PAIR:
4497 break;
4498 case DEBUG_LOC_BUFFER_OVERFLOW:
4499 case DEBUG_LOC_INVALID_ENTRY:
4500 error (_("Corrupted DWARF expression for symbol \"%s\"."),
4501 symbol->print_name ());
4502 default:
4503 gdb_assert_not_reached ("bad debug_loc_kind");
4504 }
4505
4506 /* Otherwise, a location expression entry. */
4507 low += base_address;
4508 high += base_address;
4509
4510 low = gdbarch_adjust_dwarf2_addr (gdbarch, low);
4511 high = gdbarch_adjust_dwarf2_addr (gdbarch, high);
4512
4513 if (dlbaton->per_cu->version () < 5)
4514 {
4515 length = extract_unsigned_integer (loc_ptr, 2, byte_order);
4516 loc_ptr += 2;
4517 }
4518 else
4519 {
4520 unsigned int bytes_read;
4521 length = read_unsigned_leb128 (NULL, loc_ptr, &bytes_read);
4522 loc_ptr += bytes_read;
4523 }
4524
4525 /* (It would improve readability to print only the minimum
4526 necessary digits of the second number of the range.) */
4527 fprintf_filtered (stream, _(" Range %s-%s: "),
4528 paddress (gdbarch, low), paddress (gdbarch, high));
4529
4530 /* Now describe this particular location. */
4531 locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
4532 objfile, addr_size, offset_size,
4533 dlbaton->per_cu);
4534
4535 fprintf_filtered (stream, "\n");
4536
4537 loc_ptr += length;
4538 }
4539 }
4540
4541 /* Describe the location of SYMBOL as an agent value in VALUE, generating
4542 any necessary bytecode in AX. */
4543 static void
4544 loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
4545 struct axs_value *value)
4546 {
4547 struct dwarf2_loclist_baton *dlbaton
4548 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
4549 const gdb_byte *data;
4550 size_t size;
4551 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4552
4553 data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
4554 if (size == 0)
4555 value->optimized_out = 1;
4556 else
4557 dwarf2_compile_expr_to_ax (ax, value, addr_size, data, data + size,
4558 dlbaton->per_cu);
4559 }
4560
4561 /* symbol_computed_ops 'generate_c_location' method. */
4562
4563 static void
4564 loclist_generate_c_location (struct symbol *sym, string_file *stream,
4565 struct gdbarch *gdbarch,
4566 unsigned char *registers_used,
4567 CORE_ADDR pc, const char *result_name)
4568 {
4569 struct dwarf2_loclist_baton *dlbaton
4570 = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
4571 unsigned int addr_size = dlbaton->per_cu->addr_size ();
4572 const gdb_byte *data;
4573 size_t size;
4574
4575 data = dwarf2_find_location_expression (dlbaton, &size, pc);
4576 if (size == 0)
4577 error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
4578
4579 compile_dwarf_expr_to_c (stream, result_name,
4580 sym, pc, gdbarch, registers_used, addr_size,
4581 data, data + size,
4582 dlbaton->per_cu);
4583 }
4584
4585 /* The set of location functions used with the DWARF-2 expression
4586 evaluator and location lists. */
4587 const struct symbol_computed_ops dwarf2_loclist_funcs = {
4588 loclist_read_variable,
4589 loclist_read_variable_at_entry,
4590 loclist_symbol_needs,
4591 loclist_describe_location,
4592 1, /* location_has_loclist */
4593 loclist_tracepoint_var_ref,
4594 loclist_generate_c_location
4595 };
4596
4597 void _initialize_dwarf2loc ();
4598 void
4599 _initialize_dwarf2loc ()
4600 {
4601 add_setshow_zuinteger_cmd ("entry-values", class_maintenance,
4602 &entry_values_debug,
4603 _("Set entry values and tail call frames "
4604 "debugging."),
4605 _("Show entry values and tail call frames "
4606 "debugging."),
4607 _("When non-zero, the process of determining "
4608 "parameter values from function entry point "
4609 "and tail call frames will be printed."),
4610 NULL,
4611 show_entry_values_debug,
4612 &setdebuglist, &showdebuglist);
4613
4614 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
4615 &dwarf_always_disassemble, _("\
4616 Set whether `info address' always disassembles DWARF expressions."), _("\
4617 Show whether `info address' always disassembles DWARF expressions."), _("\
4618 When enabled, DWARF expressions are always printed in an assembly-like\n\
4619 syntax. When disabled, expressions will be printed in a more\n\
4620 conversational style, when possible."),
4621 NULL,
4622 show_dwarf_always_disassemble,
4623 &set_dwarf_cmdlist,
4624 &show_dwarf_cmdlist);
4625 }
This page took 0.174594 seconds and 3 git commands to generate.