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