GDB (xrefs)
Loading...
Searching...
No Matches
expr.c
Go to the documentation of this file.
1/* DWARF 2 Expression Evaluator.
2
3 Copyright (C) 2001-2023 Free Software Foundation, Inc.
4
5 Contributed by Daniel Berlin (dan@dberlin.org)
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 "block.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "value.h"
27#include "gdbcore.h"
28#include "dwarf2.h"
29#include "dwarf2/expr.h"
30#include "dwarf2/loc.h"
31#include "dwarf2/read.h"
32#include "frame.h"
33#include "gdbsupport/underlying.h"
34#include "gdbarch.h"
35#include "objfiles.h"
36
37/* This holds gdbarch-specific types used by the DWARF expression
38 evaluator. See comments in execute_stack_op. */
39
41{
42 struct type *dw_types[3] {};
43};
44
45/* Cookie for gdbarch data. */
46
48
49/* Ensure that a FRAME is defined, throw an exception otherwise. */
50
51static void
52ensure_have_frame (frame_info_ptr frame, const char *op_name)
53{
54 if (frame == nullptr)
55 throw_error (GENERIC_ERROR,
56 _("%s evaluation requires a frame."), op_name);
57}
58
59/* Ensure that a PER_CU is defined and throw an exception otherwise. */
60
61static void
62ensure_have_per_cu (dwarf2_per_cu_data *per_cu, const char* op_name)
63{
64 if (per_cu == nullptr)
65 throw_error (GENERIC_ERROR,
66 _("%s evaluation requires a compilation unit."), op_name);
67}
68
69/* Return the number of bytes overlapping a contiguous chunk of N_BITS
70 bits whose first bit is located at bit offset START. */
71
72static size_t
73bits_to_bytes (ULONGEST start, ULONGEST n_bits)
74{
75 return (start % HOST_CHAR_BIT + n_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
76}
77
78/* See expr.h. */
79
80CORE_ADDR
82{
83 struct gdbarch *gdbarch = get_frame_arch (frame);
85
86 return address_from_register (regnum, frame);
87}
88
90{
91 /* Reference count. */
92 int refc = 0;
93
94 /* The objfile from which this closure's expression came. */
96
97 /* The CU from which this closure's expression came. */
99
100 /* The pieces describing this variable. */
101 std::vector<dwarf_expr_piece> pieces;
102
103 /* Frame ID of frame to which a register value is relative, used
104 only by DWARF_VALUE_REGISTER. */
106};
107
108/* Allocate a closure for a value formed from separately-described
109 PIECES. */
110
111static piece_closure *
113 dwarf2_per_objfile *per_objfile,
114 std::vector<dwarf_expr_piece> &&pieces,
115 frame_info_ptr frame)
116{
118
119 c->refc = 1;
120 /* We must capture this here due to sharing of DWARF state. */
121 c->per_objfile = per_objfile;
122 c->per_cu = per_cu;
123 c->pieces = std::move (pieces);
124 if (frame == nullptr)
126 else
127 c->frame_id = get_frame_id (frame);
128
129 for (dwarf_expr_piece &piece : c->pieces)
130 if (piece.location == DWARF_VALUE_STACK)
131 piece.v.value->incref ();
132
133 return c;
134}
135
136/* Read or write a pieced value V. If FROM != NULL, operate in "write
137 mode": copy FROM into the pieces comprising V. If FROM == NULL,
138 operate in "read mode": fetch the contents of the (lazy) value V by
139 composing it from its pieces. If CHECK_OPTIMIZED is true, then no
140 reading or writing is done; instead the return value of this
141 function is true if any piece is optimized out. When
142 CHECK_OPTIMIZED is true, FROM must be nullptr. */
143
144static bool
145rw_pieced_value (value *v, value *from, bool check_optimized)
146{
147 int i;
148 LONGEST offset = 0, max_offset;
149 gdb_byte *v_contents;
150 const gdb_byte *from_contents;
153 gdb::byte_vector buffer;
154 bool bits_big_endian = type_byte_order (v->type ()) == BFD_ENDIAN_BIG;
155
156 gdb_assert (!check_optimized || from == nullptr);
157 if (from != nullptr)
158 {
159 from_contents = from->contents ().data ();
160 v_contents = nullptr;
161 }
162 else
163 {
164 if (check_optimized)
165 v_contents = nullptr;
166 else
167 v_contents = v->contents_raw ().data ();
168 from_contents = nullptr;
169 }
170
171 ULONGEST bits_to_skip = 8 * v->offset ();
172 if (v->bitsize ())
173 {
174 bits_to_skip += (8 * v->parent ()->offset ()
175 + v->bitpos ());
176 if (from != nullptr
177 && (type_byte_order (from->type ())
178 == BFD_ENDIAN_BIG))
179 {
180 /* Use the least significant bits of FROM. */
181 max_offset = 8 * from->type ()->length ();
182 offset = max_offset - v->bitsize ();
183 }
184 else
185 max_offset = v->bitsize ();
186 }
187 else
188 max_offset = 8 * v->type ()->length ();
189
190 /* Advance to the first non-skipped piece. */
191 for (i = 0; i < c->pieces.size () && bits_to_skip >= c->pieces[i].size; i++)
192 bits_to_skip -= c->pieces[i].size;
193
194 for (; i < c->pieces.size () && offset < max_offset; i++)
195 {
196 dwarf_expr_piece *p = &c->pieces[i];
197 size_t this_size_bits, this_size;
198
199 this_size_bits = p->size - bits_to_skip;
200 if (this_size_bits > max_offset - offset)
201 this_size_bits = max_offset - offset;
202
203 switch (p->location)
204 {
206 {
208 gdbarch *arch = get_frame_arch (frame);
210 ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum);
211 int optim, unavail;
212
213 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG
214 && p->offset + p->size < reg_bits)
215 {
216 /* Big-endian, and we want less than full size. */
217 bits_to_skip += reg_bits - (p->offset + p->size);
218 }
219 else
220 bits_to_skip += p->offset;
221
222 this_size = bits_to_bytes (bits_to_skip, this_size_bits);
223 buffer.resize (this_size);
224
225 if (from == nullptr)
226 {
227 /* Read mode. */
229 bits_to_skip / 8,
230 buffer, &optim, &unavail))
231 {
232 if (optim)
233 {
234 if (check_optimized)
235 return true;
236 v->mark_bits_optimized_out (offset,
237 this_size_bits);
238 }
239 if (unavail && !check_optimized)
240 v->mark_bits_unavailable (offset,
241 this_size_bits);
242 break;
243 }
244
245 if (!check_optimized)
246 copy_bitwise (v_contents, offset,
247 buffer.data (), bits_to_skip % 8,
248 this_size_bits, bits_big_endian);
249 }
250 else
251 {
252 /* Write mode. */
253 if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
254 {
255 /* Data is copied non-byte-aligned into the register.
256 Need some bits from original register value. */
258 bits_to_skip / 8,
259 buffer, &optim, &unavail);
260 if (optim)
261 throw_error (OPTIMIZED_OUT_ERROR,
262 _("Can't do read-modify-write to "
263 "update bitfield; containing word "
264 "has been optimized out"));
265 if (unavail)
266 throw_error (NOT_AVAILABLE_ERROR,
267 _("Can't do read-modify-write to "
268 "update bitfield; containing word "
269 "is unavailable"));
270 }
271
272 copy_bitwise (buffer.data (), bits_to_skip % 8,
273 from_contents, offset,
274 this_size_bits, bits_big_endian);
276 bits_to_skip / 8,
277 buffer);
278 }
279 }
280 break;
281
283 {
284 if (check_optimized)
285 break;
286
287 bits_to_skip += p->offset;
288
289 CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8;
290
291 if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0
292 && offset % 8 == 0)
293 {
294 /* Everything is byte-aligned; no buffer needed. */
295 if (from != nullptr)
297 (from_contents
298 + offset / 8),
299 this_size_bits / 8);
300 else
301 read_value_memory (v, offset,
303 p->v.mem.addr + bits_to_skip / 8,
304 v_contents + offset / 8,
305 this_size_bits / 8);
306 break;
307 }
308
309 this_size = bits_to_bytes (bits_to_skip, this_size_bits);
310 buffer.resize (this_size);
311
312 if (from == nullptr)
313 {
314 /* Read mode. */
315 read_value_memory (v, offset,
317 p->v.mem.addr + bits_to_skip / 8,
318 buffer.data (), this_size);
319 copy_bitwise (v_contents, offset,
320 buffer.data (), bits_to_skip % 8,
321 this_size_bits, bits_big_endian);
322 }
323 else
324 {
325 /* Write mode. */
326 if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0)
327 {
328 if (this_size <= 8)
329 {
330 /* Perform a single read for small sizes. */
331 read_memory (start_addr, buffer.data (),
332 this_size);
333 }
334 else
335 {
336 /* Only the first and last bytes can possibly have
337 any bits reused. */
338 read_memory (start_addr, buffer.data (), 1);
339 read_memory (start_addr + this_size - 1,
340 &buffer[this_size - 1], 1);
341 }
342 }
343
344 copy_bitwise (buffer.data (), bits_to_skip % 8,
345 from_contents, offset,
346 this_size_bits, bits_big_endian);
348 buffer.data (),
349 this_size);
350 }
351 }
352 break;
353
355 {
356 if (check_optimized)
357 break;
358
359 if (from != nullptr)
360 {
361 v->mark_bits_optimized_out (offset, this_size_bits);
362 break;
363 }
364
365 gdbarch *objfile_gdbarch = c->per_objfile->objfile->arch ();
366 ULONGEST stack_value_size_bits
367 = 8 * p->v.value->type ()->length ();
368
369 /* Use zeroes if piece reaches beyond stack value. */
370 if (p->offset + p->size > stack_value_size_bits)
371 break;
372
373 /* Piece is anchored at least significant bit end. */
374 if (gdbarch_byte_order (objfile_gdbarch) == BFD_ENDIAN_BIG)
375 bits_to_skip += stack_value_size_bits - p->offset - p->size;
376 else
377 bits_to_skip += p->offset;
378
379 copy_bitwise (v_contents, offset,
380 p->v.value->contents_all ().data (),
381 bits_to_skip,
382 this_size_bits, bits_big_endian);
383 }
384 break;
385
387 {
388 if (check_optimized)
389 break;
390
391 if (from != nullptr)
392 {
393 v->mark_bits_optimized_out (offset, this_size_bits);
394 break;
395 }
396
397 ULONGEST literal_size_bits = 8 * p->v.literal.length;
398 size_t n = this_size_bits;
399
400 /* Cut off at the end of the implicit value. */
401 bits_to_skip += p->offset;
402 if (bits_to_skip >= literal_size_bits)
403 break;
404 if (n > literal_size_bits - bits_to_skip)
405 n = literal_size_bits - bits_to_skip;
406
407 copy_bitwise (v_contents, offset,
408 p->v.literal.data, bits_to_skip,
409 n, bits_big_endian);
410 }
411 break;
412
414 if (from != nullptr)
415 {
416 v->mark_bits_optimized_out (offset, this_size_bits);
417 break;
418 }
419
420 /* These bits show up as zeros -- but do not cause the value to
421 be considered optimized-out. */
422 break;
423
425 if (check_optimized)
426 return true;
427 v->mark_bits_optimized_out (offset, this_size_bits);
428 break;
429
430 default:
431 internal_error (_("invalid location type"));
432 }
433
434 offset += this_size_bits;
435 bits_to_skip = 0;
436 }
437
438 if (offset < max_offset)
439 {
440 if (check_optimized)
441 return true;
442 v->mark_bits_optimized_out (offset, max_offset - offset);
443 }
444
445 return false;
446}
447
448static void
450{
451 rw_pieced_value (v, nullptr, false);
452}
453
454static void
456{
457 rw_pieced_value (to, from, false);
458}
459
460static bool
462{
463 return rw_pieced_value (v, nullptr, true);
464}
465
466/* An implementation of an lval_funcs method to see whether a value is
467 a synthetic pointer. */
468
469static bool
470check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset,
471 int bit_length)
472{
474 int i;
475
476 bit_offset += 8 * value->offset ();
477 if (value->bitsize ())
478 bit_offset += value->bitpos ();
479
480 for (i = 0; i < c->pieces.size () && bit_length > 0; i++)
481 {
482 dwarf_expr_piece *p = &c->pieces[i];
483 size_t this_size_bits = p->size;
484
485 if (bit_offset > 0)
486 {
487 if (bit_offset >= this_size_bits)
488 {
489 bit_offset -= this_size_bits;
490 continue;
491 }
492
493 bit_length -= this_size_bits - bit_offset;
494 bit_offset = 0;
495 }
496 else
497 bit_length -= this_size_bits;
498
500 return false;
501 }
502
503 return bit_length == 0;
504}
505
506/* An implementation of an lval_funcs method to indirect through a
507 pointer. This handles the synthetic pointer case when needed. */
508
509static value *
511{
514 int i;
515 dwarf_expr_piece *piece = NULL;
516
517 struct type *type = check_typedef (value->type ());
518 if (type->code () != TYPE_CODE_PTR)
519 return NULL;
520
521 int bit_length = 8 * type->length ();
522 LONGEST bit_offset = 8 * value->offset ();
523 if (value->bitsize ())
524 bit_offset += value->bitpos ();
525
526 for (i = 0; i < c->pieces.size () && bit_length > 0; i++)
527 {
528 dwarf_expr_piece *p = &c->pieces[i];
529 size_t this_size_bits = p->size;
530
531 if (bit_offset > 0)
532 {
533 if (bit_offset >= this_size_bits)
534 {
535 bit_offset -= this_size_bits;
536 continue;
537 }
538
539 bit_length -= this_size_bits - bit_offset;
540 bit_offset = 0;
541 }
542 else
543 bit_length -= this_size_bits;
544
546 return NULL;
547
548 if (bit_length != 0)
549 error (_("Invalid use of DW_OP_implicit_pointer"));
550
551 piece = p;
552 break;
553 }
554
555 gdb_assert (piece != NULL && c->per_cu != nullptr);
556 frame_info_ptr frame = get_selected_frame (_("No frame selected."));
557
558 /* This is an offset requested by GDB, such as value subscripts.
559 However, due to how synthetic pointers are implemented, this is
560 always presented to us as a pointer type. This means we have to
561 sign-extend it manually as appropriate. Use raw
562 extract_signed_integer directly rather than value_as_address and
563 sign extend afterwards on architectures that would need it
564 (mostly everywhere except MIPS, which has signed addresses) as
565 the later would go through gdbarch_pointer_to_address and thus
566 return a CORE_ADDR with high bits set on architectures that
567 encode address spaces and other things in CORE_ADDR. */
568 bfd_endian byte_order = gdbarch_byte_order (get_frame_arch (frame));
569 LONGEST byte_offset
570 = extract_signed_integer (value->contents (), byte_order);
571 byte_offset += piece->v.ptr.offset;
572
574 byte_offset, c->per_cu,
575 c->per_objfile, frame, type);
576}
577
578/* Implementation of the coerce_ref method of lval_funcs for synthetic C++
579 references. */
580
581static value *
583{
584 struct type *type = check_typedef (value->type ());
585
587 TARGET_CHAR_BIT * type->length ()))
588 {
589 const piece_closure *closure
591 frame_info_ptr frame
592 = get_selected_frame (_("No frame selected."));
593
594 /* gdb represents synthetic pointers as pieced values with a single
595 piece. */
596 gdb_assert (closure != NULL);
597 gdb_assert (closure->pieces.size () == 1);
598
600 (closure->pieces[0].v.ptr.die_sect_off,
601 closure->pieces[0].v.ptr.offset,
602 closure->per_cu, closure->per_objfile, frame, type);
603 }
604 else
605 {
606 /* Else: not a synthetic reference; do nothing. */
607 return NULL;
608 }
609}
610
611static void *
613{
615
616 ++c->refc;
617 return c;
618}
619
620static void
622{
624
625 --c->refc;
626 if (c->refc == 0)
627 {
628 for (dwarf_expr_piece &p : c->pieces)
629 if (p.location == DWARF_VALUE_STACK)
630 p.v.value->decref ();
631
632 delete c;
633 }
634}
635
636/* Functions for accessing a variable described by DW_OP_piece. */
647
648/* Given context CTX, section offset SECT_OFF, and compilation unit
649 data PER_CU, execute the "variable value" operation on the DIE
650 found at SECT_OFF. */
651
652static value *
653sect_variable_value (sect_offset sect_off,
654 dwarf2_per_cu_data *per_cu,
655 dwarf2_per_objfile *per_objfile)
656{
657 const char *var_name = nullptr;
658 struct type *die_type
659 = dwarf2_fetch_die_type_sect_off (sect_off, per_cu, per_objfile,
660 &var_name);
661
662 if (die_type == NULL)
663 error (_("Bad DW_OP_GNU_variable_value DIE."));
664
665 /* Note: Things still work when the following test is removed. This
666 test and error is here to conform to the proposed specification. */
667 if (die_type->code () != TYPE_CODE_INT
668 && die_type->code () != TYPE_CODE_ENUM
669 && die_type->code () != TYPE_CODE_RANGE
670 && die_type->code () != TYPE_CODE_PTR)
671 error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
672
673 if (var_name != nullptr)
674 {
675 value *result = compute_var_value (var_name);
676 if (result != nullptr)
677 return result;
678 }
679
681 frame_info_ptr frame = get_selected_frame (_("No frame selected."));
682 return indirect_synthetic_pointer (sect_off, 0, per_cu, per_objfile, frame,
683 type, true);
684}
685
686/* Return the type used for DWARF operations where the type is
687 unspecified in the DWARF spec. Only certain sizes are
688 supported. */
689
690struct type *
692{
693 gdbarch *arch = this->m_per_objfile->objfile->arch ();
695 if (types == nullptr)
696 types = dwarf_arch_cookie.emplace (arch);
697 int ndx;
698
699 if (this->m_addr_size == 2)
700 ndx = 0;
701 else if (this->m_addr_size == 4)
702 ndx = 1;
703 else if (this->m_addr_size == 8)
704 ndx = 2;
705 else
706 error (_("Unsupported address size in DWARF expressions: %d bits"),
707 8 * this->m_addr_size);
708
709 if (types->dw_types[ndx] == NULL)
710 {
711 type_allocator alloc (arch);
712 types->dw_types[ndx]
713 = init_integer_type (alloc, 8 * this->m_addr_size,
714 0, "<signed DWARF address type>");
715 }
716
717 return types->dw_types[ndx];
718}
719
720/* Create a new context for the expression evaluator. */
721
723 int addr_size)
724: m_addr_size (addr_size),
725 m_per_objfile (per_objfile)
726{
727}
728
729/* Push VALUE onto the stack. */
730
731void
732dwarf_expr_context::push (struct value *value, bool in_stack_memory)
733{
734 this->m_stack.emplace_back (value, in_stack_memory);
735}
736
737/* Push VALUE onto the stack. */
738
739void
740dwarf_expr_context::push_address (CORE_ADDR value, bool in_stack_memory)
741{
742 push (value_from_ulongest (address_type (), value), in_stack_memory);
743}
744
745/* Pop the top item off of the stack. */
746
747void
749{
750 if (this->m_stack.empty ())
751 error (_("dwarf expression stack underflow"));
752
753 this->m_stack.pop_back ();
754}
755
756/* Retrieve the N'th item on the stack. */
757
758struct value *
760{
761 if (this->m_stack.size () <= n)
762 error (_("Asked for position %d of stack, "
763 "stack only has %zu elements on it."),
764 n, this->m_stack.size ());
765 return this->m_stack[this->m_stack.size () - (1 + n)].value;
766}
767
768/* See expr.h. */
769
770void
772 size_t * length)
773{
774 ensure_have_frame (this->m_frame, "DW_OP_fbreg");
775
776 const block *bl = get_frame_block (this->m_frame, NULL);
777
778 if (bl == NULL)
779 error (_("frame address is not available."));
780
781 /* Use block_linkage_function, which returns a real (not inlined)
782 function, instead of get_frame_function, which may return an
783 inlined function. */
784 symbol *framefunc = bl->linkage_function ();
785
786 /* If we found a frame-relative symbol then it was certainly within
787 some function associated with a frame. If we can't find the frame,
788 something has gone wrong. */
789 gdb_assert (framefunc != NULL);
790
793 start, length);
794}
795
796/* See expr.h. */
797
798struct type *
800{
801 if (this->m_per_cu == nullptr)
803
804 struct type *result = dwarf2_get_die_type (die_cu_off, this->m_per_cu,
805 this->m_per_objfile);
806
807 if (result == nullptr)
808 error (_("Could not find type for operation"));
809
810 return result;
811}
812
813/* See expr.h. */
814
815void
816dwarf_expr_context::dwarf_call (cu_offset die_cu_off)
817{
818 ensure_have_per_cu (this->m_per_cu, "DW_OP_call");
819
820 frame_info_ptr frame = this->m_frame;
821
822 auto get_pc_from_frame = [frame] ()
823 {
824 ensure_have_frame (frame, "DW_OP_call");
825 return get_frame_address_in_block (frame);
826 };
827
829 = dwarf2_fetch_die_loc_cu_off (die_cu_off, this->m_per_cu,
830 this->m_per_objfile, get_pc_from_frame);
831
832 /* DW_OP_call_ref is currently not supported. */
833 gdb_assert (block.per_cu == this->m_per_cu);
834
835 this->eval (block.data, block.size);
836}
837
838/* See expr.h. */
839
840void
841dwarf_expr_context::read_mem (gdb_byte *buf, CORE_ADDR addr,
842 size_t length)
843{
844 if (length == 0)
845 return;
846
847 /* Prefer the passed-in memory, if it exists. */
848 if (this->m_addr_info != nullptr)
849 {
850 CORE_ADDR offset = addr - this->m_addr_info->addr;
851
852 if (offset < this->m_addr_info->valaddr.size ()
853 && offset + length <= this->m_addr_info->valaddr.size ())
854 {
855 memcpy (buf, this->m_addr_info->valaddr.data (), length);
856 return;
857 }
858 }
859
860 read_memory (addr, buf, length);
861}
862
863/* See expr.h. */
864
865void
868 int deref_size)
869{
870 ensure_have_per_cu (this->m_per_cu, "DW_OP_entry_value");
871 ensure_have_frame (this->m_frame, "DW_OP_entry_value");
872
873 dwarf2_per_cu_data *caller_per_cu;
874 dwarf2_per_objfile *caller_per_objfile;
875 frame_info_ptr caller_frame = get_prev_frame (this->m_frame);
876 call_site_parameter *parameter
877 = dwarf_expr_reg_to_entry_parameter (this->m_frame, kind, kind_u,
878 &caller_per_cu,
879 &caller_per_objfile);
880 const gdb_byte *data_src
881 = deref_size == -1 ? parameter->value : parameter->data_value;
882 size_t size
883 = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
884
885 /* DEREF_SIZE size is not verified here. */
886 if (data_src == nullptr)
887 throw_error (NO_ENTRY_VALUE_ERROR,
888 _("Cannot resolve DW_AT_call_data_value"));
889
890 /* We are about to evaluate an expression in the context of the caller
891 of the current frame. This evaluation context may be different from
892 the current (callee's) context), so temporarily set the caller's context.
893
894 It is possible for the caller to be from a different objfile from the
895 callee if the call is made through a function pointer. */
896 scoped_restore save_frame = make_scoped_restore (&this->m_frame,
897 caller_frame);
898 scoped_restore save_per_cu = make_scoped_restore (&this->m_per_cu,
899 caller_per_cu);
900 scoped_restore save_addr_info = make_scoped_restore (&this->m_addr_info,
901 nullptr);
902 scoped_restore save_per_objfile = make_scoped_restore (&this->m_per_objfile,
903 caller_per_objfile);
904
905 scoped_restore save_addr_size = make_scoped_restore (&this->m_addr_size);
906 this->m_addr_size = this->m_per_cu->addr_size ();
907
908 this->eval (data_src, size);
909}
910
911/* See expr.h. */
912
913value *
914dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type,
915 LONGEST subobj_offset, bool as_lval)
916{
917 value *retval = nullptr;
918 gdbarch *arch = this->m_per_objfile->objfile->arch ();
919
920 if (type == nullptr)
921 type = address_type ();
922
923 if (subobj_type == nullptr)
924 subobj_type = type;
925
926 /* Ensure that, if TYPE or SUBOBJ_TYPE are typedefs, their length is filled
927 in instead of being zero. */
929 check_typedef (subobj_type);
930
931 if (this->m_pieces.size () > 0)
932 {
933 ULONGEST bit_size = 0;
934
935 for (dwarf_expr_piece &piece : this->m_pieces)
936 bit_size += piece.size;
937 /* Complain if the expression is larger than the size of the
938 outer type. */
939 if (bit_size > 8 * type->length ())
941
944 std::move (this->m_pieces), this->m_frame);
945 retval = value::allocate_computed (subobj_type,
947 retval->set_offset (subobj_offset);
948 }
949 else
950 {
951 /* If AS_LVAL is false, means that the implicit conversion
952 from a location description to value is expected. */
953 if (!as_lval)
955
956 switch (this->m_location)
957 {
959 {
960 gdbarch *f_arch = get_frame_arch (this->m_frame);
961 int dwarf_regnum
962 = longest_to_int (value_as_long (this->fetch (0)));
964 dwarf_regnum);
965
966 if (subobj_offset != 0)
967 error (_("cannot use offset on synthetic pointer to register"));
968
969 gdb_assert (this->m_frame != NULL);
970
971 retval = value_from_register (subobj_type, gdb_regnum,
972 this->m_frame);
973 if (retval->optimized_out ())
974 {
975 /* This means the register has undefined value / was
976 not saved. As we're computing the location of some
977 variable etc. in the program, not a value for
978 inspecting a register ($pc, $sp, etc.), return a
979 generic optimized out value instead, so that we show
980 <optimized out> instead of <not saved>. */
981 value *tmp = value::allocate (subobj_type);
982 retval->contents_copy (tmp, 0, 0,
983 subobj_type->length ());
984 retval = tmp;
985 }
986 }
987 break;
988
990 {
991 struct type *ptr_type;
992 CORE_ADDR address = this->fetch_address (0);
993 bool in_stack_memory = this->fetch_in_stack_memory (0);
994
995 /* DW_OP_deref_size (and possibly other operations too) may
996 create a pointer instead of an address. Ideally, the
997 pointer to address conversion would be performed as part
998 of those operations, but the type of the object to
999 which the address refers is not known at the time of
1000 the operation. Therefore, we do the conversion here
1001 since the type is readily available. */
1002
1003 switch (subobj_type->code ())
1004 {
1005 case TYPE_CODE_FUNC:
1006 case TYPE_CODE_METHOD:
1007 ptr_type = builtin_type (arch)->builtin_func_ptr;
1008 break;
1009 default:
1010 ptr_type = builtin_type (arch)->builtin_data_ptr;
1011 break;
1012 }
1013 address = value_as_address (value_from_pointer (ptr_type, address));
1014
1015 retval = value_at_lazy (subobj_type, address + subobj_offset,
1016 m_frame);
1017 if (in_stack_memory)
1018 retval->set_stack (true);
1019 }
1020 break;
1021
1022 case DWARF_VALUE_STACK:
1023 {
1024 value *val = this->fetch (0);
1025 size_t n = val->type ()->length ();
1026 size_t len = subobj_type->length ();
1027 size_t max = type->length ();
1028
1029 if (subobj_offset + len > max)
1031
1032 retval = value::allocate (subobj_type);
1033
1034 /* The given offset is relative to the actual object. */
1035 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
1036 subobj_offset += n - max;
1037
1038 copy (val->contents_all ().slice (subobj_offset, len),
1039 retval->contents_raw ());
1040 }
1041 break;
1042
1044 {
1045 size_t n = subobj_type->length ();
1046
1047 if (subobj_offset + n > this->m_len)
1049
1050 retval = value::allocate (subobj_type);
1051 bfd_byte *contents = retval->contents_raw ().data ();
1052 memcpy (contents, this->m_data + subobj_offset, n);
1053 }
1054 break;
1055
1057 retval = value::allocate_optimized_out (subobj_type);
1058 break;
1059
1060 /* DWARF_VALUE_IMPLICIT_POINTER was converted to a pieced
1061 operation by execute_stack_op. */
1063 /* DWARF_VALUE_OPTIMIZED_OUT can't occur in this context --
1064 it can only be encountered when making a piece. */
1065 default:
1066 internal_error (_("invalid location type"));
1067 }
1068 }
1069
1070 retval->set_initialized (this->m_initialized);
1071
1072 return retval;
1073}
1074
1075/* See expr.h. */
1076
1077value *
1078dwarf_expr_context::evaluate (const gdb_byte *addr, size_t len, bool as_lval,
1079 dwarf2_per_cu_data *per_cu, frame_info_ptr frame,
1080 const struct property_addr_info *addr_info,
1081 struct type *type, struct type *subobj_type,
1082 LONGEST subobj_offset)
1083{
1084 this->m_per_cu = per_cu;
1085 this->m_frame = frame;
1086 this->m_addr_info = addr_info;
1087
1088 eval (addr, len);
1089 return fetch_result (type, subobj_type, subobj_offset, as_lval);
1090}
1091
1092/* Require that TYPE be an integral type; throw an exception if not. */
1093
1094static void
1096{
1097 if (type->code () != TYPE_CODE_INT
1098 && type->code () != TYPE_CODE_CHAR
1099 && type->code () != TYPE_CODE_BOOL)
1100 error (_("integral type expected in DWARF expression"));
1101}
1102
1103/* Return the unsigned form of TYPE. TYPE is necessarily an integral
1104 type. */
1105
1106static struct type *
1108{
1109 switch (type->length ())
1110 {
1111 case 1:
1113 case 2:
1115 case 4:
1117 case 8:
1119 default:
1120 error (_("no unsigned variant found for type, while evaluating "
1121 "DWARF expression"));
1122 }
1123}
1124
1125/* Return the signed form of TYPE. TYPE is necessarily an integral
1126 type. */
1127
1128static struct type *
1130{
1131 switch (type->length ())
1132 {
1133 case 1:
1135 case 2:
1137 case 4:
1139 case 8:
1141 default:
1142 error (_("no signed variant found for type, while evaluating "
1143 "DWARF expression"));
1144 }
1145}
1146
1147/* Retrieve the N'th item on the stack, converted to an address. */
1148
1149CORE_ADDR
1151{
1152 gdbarch *arch = this->m_per_objfile->objfile->arch ();
1153 value *result_val = fetch (n);
1154 bfd_endian byte_order = gdbarch_byte_order (arch);
1155 ULONGEST result;
1156
1157 dwarf_require_integral (result_val->type ());
1158 result = extract_unsigned_integer (result_val->contents (), byte_order);
1159
1160 /* For most architectures, calling extract_unsigned_integer() alone
1161 is sufficient for extracting an address. However, some
1162 architectures (e.g. MIPS) use signed addresses and using
1163 extract_unsigned_integer() will not produce a correct
1164 result. Make sure we invoke gdbarch_integer_to_address()
1165 for those architectures which require it. */
1167 {
1168 gdb_byte *buf = (gdb_byte *) alloca (this->m_addr_size);
1169 type *int_type = get_unsigned_type (arch,
1170 result_val->type ());
1171
1172 store_unsigned_integer (buf, this->m_addr_size, byte_order, result);
1173 return gdbarch_integer_to_address (arch, int_type, buf);
1174 }
1175
1176 return (CORE_ADDR) result;
1177}
1178
1179/* Retrieve the in_stack_memory flag of the N'th item on the stack. */
1180
1181bool
1183{
1184 if (this->m_stack.size () <= n)
1185 error (_("Asked for position %d of stack, "
1186 "stack only has %zu elements on it."),
1187 n, this->m_stack.size ());
1188 return this->m_stack[this->m_stack.size () - (1 + n)].in_stack_memory;
1189}
1190
1191/* Return true if the expression stack is empty. */
1192
1193bool
1195{
1196 return m_stack.empty ();
1197}
1198
1199/* Add a new piece to the dwarf_expr_context's piece list. */
1200void
1201dwarf_expr_context::add_piece (ULONGEST size, ULONGEST offset)
1202{
1203 this->m_pieces.emplace_back ();
1204 dwarf_expr_piece &p = this->m_pieces.back ();
1205
1206 p.location = this->m_location;
1207 p.size = size;
1208 p.offset = offset;
1209
1211 {
1212 p.v.literal.data = this->m_data;
1213 p.v.literal.length = this->m_len;
1214 }
1215 else if (stack_empty_p ())
1216 {
1218 /* Also reset the context's location, for our callers. This is
1219 a somewhat strange approach, but this lets us avoid setting
1220 the location to DWARF_VALUE_MEMORY in all the individual
1221 cases in the evaluator. */
1223 }
1224 else if (p.location == DWARF_VALUE_MEMORY)
1225 {
1226 p.v.mem.addr = fetch_address (0);
1228 }
1230 {
1231 p.v.ptr.die_sect_off = (sect_offset) this->m_len;
1232 p.v.ptr.offset = value_as_long (fetch (0));
1233 }
1234 else if (p.location == DWARF_VALUE_REGISTER)
1235 p.v.regno = value_as_long (fetch (0));
1236 else
1237 {
1238 p.v.value = fetch (0);
1239 }
1240}
1241
1242/* Evaluate the expression at ADDR (LEN bytes long). */
1243
1244void
1245dwarf_expr_context::eval (const gdb_byte *addr, size_t len)
1246{
1247 int old_recursion_depth = this->m_recursion_depth;
1248
1249 execute_stack_op (addr, addr + len);
1250
1251 /* RECURSION_DEPTH becomes invalid if an exception was thrown here. */
1252
1253 gdb_assert (this->m_recursion_depth == old_recursion_depth);
1254}
1255
1256/* Helper to read a uleb128 value or throw an error. */
1257
1258const gdb_byte *
1259safe_read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
1260 uint64_t *r)
1261{
1262 buf = gdb_read_uleb128 (buf, buf_end, r);
1263 if (buf == NULL)
1264 error (_("DWARF expression error: ran off end of buffer reading uleb128 value"));
1265 return buf;
1266}
1267
1268/* Helper to read a sleb128 value or throw an error. */
1269
1270const gdb_byte *
1271safe_read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
1272 int64_t *r)
1273{
1274 buf = gdb_read_sleb128 (buf, buf_end, r);
1275 if (buf == NULL)
1276 error (_("DWARF expression error: ran off end of buffer reading sleb128 value"));
1277 return buf;
1278}
1279
1280const gdb_byte *
1281safe_skip_leb128 (const gdb_byte *buf, const gdb_byte *buf_end)
1282{
1283 buf = gdb_skip_leb128 (buf, buf_end);
1284 if (buf == NULL)
1285 error (_("DWARF expression error: ran off end of buffer reading leb128 value"));
1286 return buf;
1287}
1288
1289
1290/* Check that the current operator is either at the end of an
1291 expression, or that it is followed by a composition operator or by
1292 DW_OP_GNU_uninit (which should terminate the expression). */
1293
1294void
1295dwarf_expr_require_composition (const gdb_byte *op_ptr, const gdb_byte *op_end,
1296 const char *op_name)
1297{
1298 if (op_ptr != op_end && *op_ptr != DW_OP_piece && *op_ptr != DW_OP_bit_piece
1299 && *op_ptr != DW_OP_GNU_uninit)
1300 error (_("DWARF-2 expression error: `%s' operations must be "
1301 "used either alone or in conjunction with DW_OP_piece "
1302 "or DW_OP_bit_piece."),
1303 op_name);
1304}
1305
1306/* Return true iff the types T1 and T2 are "the same". This only does
1307 checks that might reasonably be needed to compare DWARF base
1308 types. */
1309
1310static int
1311base_types_equal_p (struct type *t1, struct type *t2)
1312{
1313 if (t1->code () != t2->code ())
1314 return 0;
1315 if (t1->is_unsigned () != t2->is_unsigned ())
1316 return 0;
1317 return t1->length () == t2->length ();
1318}
1319
1320/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_reg* return the
1321 DWARF register number. Otherwise return -1. */
1322
1323int
1324dwarf_block_to_dwarf_reg (const gdb_byte *buf, const gdb_byte *buf_end)
1325{
1326 uint64_t dwarf_reg;
1327
1328 if (buf_end <= buf)
1329 return -1;
1330 if (*buf >= DW_OP_reg0 && *buf <= DW_OP_reg31)
1331 {
1332 if (buf_end - buf != 1)
1333 return -1;
1334 return *buf - DW_OP_reg0;
1335 }
1336
1337 if (*buf == DW_OP_regval_type || *buf == DW_OP_GNU_regval_type)
1338 {
1339 buf++;
1340 buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
1341 if (buf == NULL)
1342 return -1;
1343 buf = gdb_skip_leb128 (buf, buf_end);
1344 if (buf == NULL)
1345 return -1;
1346 }
1347 else if (*buf == DW_OP_regx)
1348 {
1349 buf++;
1350 buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
1351 if (buf == NULL)
1352 return -1;
1353 }
1354 else
1355 return -1;
1356 if (buf != buf_end || (int) dwarf_reg != dwarf_reg)
1357 return -1;
1358 return dwarf_reg;
1359}
1360
1361/* If <BUF..BUF_END] contains DW_FORM_block* with just DW_OP_breg*(0) and
1362 DW_OP_deref* return the DWARF register number. Otherwise return -1.
1363 DEREF_SIZE_RETURN contains -1 for DW_OP_deref; otherwise it contains the
1364 size from DW_OP_deref_size. */
1365
1366int
1367dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf, const gdb_byte *buf_end,
1368 CORE_ADDR *deref_size_return)
1369{
1370 uint64_t dwarf_reg;
1371 int64_t offset;
1372
1373 if (buf_end <= buf)
1374 return -1;
1375
1376 if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
1377 {
1378 dwarf_reg = *buf - DW_OP_breg0;
1379 buf++;
1380 if (buf >= buf_end)
1381 return -1;
1382 }
1383 else if (*buf == DW_OP_bregx)
1384 {
1385 buf++;
1386 buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
1387 if (buf == NULL)
1388 return -1;
1389 if ((int) dwarf_reg != dwarf_reg)
1390 return -1;
1391 }
1392 else
1393 return -1;
1394
1395 buf = gdb_read_sleb128 (buf, buf_end, &offset);
1396 if (buf == NULL)
1397 return -1;
1398 if (offset != 0)
1399 return -1;
1400
1401 if (*buf == DW_OP_deref)
1402 {
1403 buf++;
1404 *deref_size_return = -1;
1405 }
1406 else if (*buf == DW_OP_deref_size)
1407 {
1408 buf++;
1409 if (buf >= buf_end)
1410 return -1;
1411 *deref_size_return = *buf++;
1412 }
1413 else
1414 return -1;
1415
1416 if (buf != buf_end)
1417 return -1;
1418
1419 return dwarf_reg;
1420}
1421
1422/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_fbreg(X) fill
1423 in FB_OFFSET_RETURN with the X offset and return 1. Otherwise return 0. */
1424
1425int
1426dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
1427 CORE_ADDR *fb_offset_return)
1428{
1429 int64_t fb_offset;
1430
1431 if (buf_end <= buf)
1432 return 0;
1433
1434 if (*buf != DW_OP_fbreg)
1435 return 0;
1436 buf++;
1437
1438 buf = gdb_read_sleb128 (buf, buf_end, &fb_offset);
1439 if (buf == NULL)
1440 return 0;
1441 *fb_offset_return = fb_offset;
1442 if (buf != buf_end || fb_offset != (LONGEST) *fb_offset_return)
1443 return 0;
1444
1445 return 1;
1446}
1447
1448/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
1449 in SP_OFFSET_RETURN with the X offset and return 1. Otherwise return 0.
1450 The matched SP register number depends on GDBARCH. */
1451
1452int
1453dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
1454 const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
1455{
1456 uint64_t dwarf_reg;
1457 int64_t sp_offset;
1458
1459 if (buf_end <= buf)
1460 return 0;
1461 if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
1462 {
1463 dwarf_reg = *buf - DW_OP_breg0;
1464 buf++;
1465 }
1466 else
1467 {
1468 if (*buf != DW_OP_bregx)
1469 return 0;
1470 buf++;
1471 buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
1472 if (buf == NULL)
1473 return 0;
1474 }
1475
1476 if (dwarf_reg_to_regnum (gdbarch, dwarf_reg)
1478 return 0;
1479
1480 buf = gdb_read_sleb128 (buf, buf_end, &sp_offset);
1481 if (buf == NULL)
1482 return 0;
1483 *sp_offset_return = sp_offset;
1484 if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
1485 return 0;
1486
1487 return 1;
1488}
1489
1490/* The engine for the expression evaluator. Using the context in this
1491 object, evaluate the expression between OP_PTR and OP_END. */
1492
1493void
1495 const gdb_byte *op_end)
1496{
1497 gdbarch *arch = this->m_per_objfile->objfile->arch ();
1498 bfd_endian byte_order = gdbarch_byte_order (arch);
1499 /* Old-style "untyped" DWARF values need special treatment in a
1500 couple of places, specifically DW_OP_mod and DW_OP_shr. We need
1501 a special type for these values so we can distinguish them from
1502 values that have an explicit type, because explicitly-typed
1503 values do not need special treatment. This special type must be
1504 different (in the `==' sense) from any base type coming from the
1505 CU. */
1506 type *address_type = this->address_type ();
1507
1509 this->m_initialized = true; /* Default is initialized. */
1510
1511 if (this->m_recursion_depth > this->m_max_recursion_depth)
1512 error (_("DWARF-2 expression error: Loop detected (%d)."),
1513 this->m_recursion_depth);
1514 this->m_recursion_depth++;
1515
1516 while (op_ptr < op_end)
1517 {
1518 dwarf_location_atom op = (dwarf_location_atom) *op_ptr++;
1519 ULONGEST result;
1520 /* Assume the value is not in stack memory.
1521 Code that knows otherwise sets this to true.
1522 Some arithmetic on stack addresses can probably be assumed to still
1523 be a stack address, but we skip this complication for now.
1524 This is just an optimization, so it's always ok to punt
1525 and leave this as false. */
1526 bool in_stack_memory = false;
1527 uint64_t uoffset, reg;
1528 int64_t offset;
1529 value *result_val = NULL;
1530
1531 /* The DWARF expression might have a bug causing an infinite
1532 loop. In that case, quitting is the only way out. */
1533 QUIT;
1534
1535 switch (op)
1536 {
1537 case DW_OP_lit0:
1538 case DW_OP_lit1:
1539 case DW_OP_lit2:
1540 case DW_OP_lit3:
1541 case DW_OP_lit4:
1542 case DW_OP_lit5:
1543 case DW_OP_lit6:
1544 case DW_OP_lit7:
1545 case DW_OP_lit8:
1546 case DW_OP_lit9:
1547 case DW_OP_lit10:
1548 case DW_OP_lit11:
1549 case DW_OP_lit12:
1550 case DW_OP_lit13:
1551 case DW_OP_lit14:
1552 case DW_OP_lit15:
1553 case DW_OP_lit16:
1554 case DW_OP_lit17:
1555 case DW_OP_lit18:
1556 case DW_OP_lit19:
1557 case DW_OP_lit20:
1558 case DW_OP_lit21:
1559 case DW_OP_lit22:
1560 case DW_OP_lit23:
1561 case DW_OP_lit24:
1562 case DW_OP_lit25:
1563 case DW_OP_lit26:
1564 case DW_OP_lit27:
1565 case DW_OP_lit28:
1566 case DW_OP_lit29:
1567 case DW_OP_lit30:
1568 case DW_OP_lit31:
1569 result = op - DW_OP_lit0;
1570 result_val = value_from_ulongest (address_type, result);
1571 break;
1572
1573 case DW_OP_addr:
1574 result = extract_unsigned_integer (op_ptr,
1575 this->m_addr_size, byte_order);
1576 op_ptr += this->m_addr_size;
1577 /* Some versions of GCC emit DW_OP_addr before
1578 DW_OP_GNU_push_tls_address. In this case the value is an
1579 index, not an address. We don't support things like
1580 branching between the address and the TLS op. */
1581 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
1582 result += this->m_per_objfile->objfile->text_section_offset ();
1583 result_val = value_from_ulongest (address_type, result);
1584 break;
1585
1586 case DW_OP_addrx:
1587 case DW_OP_GNU_addr_index:
1588 ensure_have_per_cu (this->m_per_cu, "DW_OP_addrx");
1589
1590 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1591 result = (m_per_objfile->relocate
1593 this->m_per_objfile,
1594 uoffset)));
1595 result_val = value_from_ulongest (address_type, result);
1596 break;
1597 case DW_OP_GNU_const_index:
1598 ensure_have_per_cu (this->m_per_cu, "DW_OP_GNU_const_index");
1599
1600 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1601 result = (ULONGEST) dwarf2_read_addr_index (this->m_per_cu,
1602 this->m_per_objfile,
1603 uoffset);
1604 result_val = value_from_ulongest (address_type, result);
1605 break;
1606
1607 case DW_OP_const1u:
1608 result = extract_unsigned_integer (op_ptr, 1, byte_order);
1609 result_val = value_from_ulongest (address_type, result);
1610 op_ptr += 1;
1611 break;
1612 case DW_OP_const1s:
1613 result = extract_signed_integer (op_ptr, 1, byte_order);
1614 result_val = value_from_ulongest (address_type, result);
1615 op_ptr += 1;
1616 break;
1617 case DW_OP_const2u:
1618 result = extract_unsigned_integer (op_ptr, 2, byte_order);
1619 result_val = value_from_ulongest (address_type, result);
1620 op_ptr += 2;
1621 break;
1622 case DW_OP_const2s:
1623 result = extract_signed_integer (op_ptr, 2, byte_order);
1624 result_val = value_from_ulongest (address_type, result);
1625 op_ptr += 2;
1626 break;
1627 case DW_OP_const4u:
1628 result = extract_unsigned_integer (op_ptr, 4, byte_order);
1629 result_val = value_from_ulongest (address_type, result);
1630 op_ptr += 4;
1631 break;
1632 case DW_OP_const4s:
1633 result = extract_signed_integer (op_ptr, 4, byte_order);
1634 result_val = value_from_ulongest (address_type, result);
1635 op_ptr += 4;
1636 break;
1637 case DW_OP_const8u:
1638 result = extract_unsigned_integer (op_ptr, 8, byte_order);
1639 result_val = value_from_ulongest (address_type, result);
1640 op_ptr += 8;
1641 break;
1642 case DW_OP_const8s:
1643 result = extract_signed_integer (op_ptr, 8, byte_order);
1644 result_val = value_from_ulongest (address_type, result);
1645 op_ptr += 8;
1646 break;
1647 case DW_OP_constu:
1648 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1649 result = uoffset;
1650 result_val = value_from_ulongest (address_type, result);
1651 break;
1652 case DW_OP_consts:
1653 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
1654 result = offset;
1655 result_val = value_from_ulongest (address_type, result);
1656 break;
1657
1658 /* The DW_OP_reg operations are required to occur alone in
1659 location expressions. */
1660 case DW_OP_reg0:
1661 case DW_OP_reg1:
1662 case DW_OP_reg2:
1663 case DW_OP_reg3:
1664 case DW_OP_reg4:
1665 case DW_OP_reg5:
1666 case DW_OP_reg6:
1667 case DW_OP_reg7:
1668 case DW_OP_reg8:
1669 case DW_OP_reg9:
1670 case DW_OP_reg10:
1671 case DW_OP_reg11:
1672 case DW_OP_reg12:
1673 case DW_OP_reg13:
1674 case DW_OP_reg14:
1675 case DW_OP_reg15:
1676 case DW_OP_reg16:
1677 case DW_OP_reg17:
1678 case DW_OP_reg18:
1679 case DW_OP_reg19:
1680 case DW_OP_reg20:
1681 case DW_OP_reg21:
1682 case DW_OP_reg22:
1683 case DW_OP_reg23:
1684 case DW_OP_reg24:
1685 case DW_OP_reg25:
1686 case DW_OP_reg26:
1687 case DW_OP_reg27:
1688 case DW_OP_reg28:
1689 case DW_OP_reg29:
1690 case DW_OP_reg30:
1691 case DW_OP_reg31:
1692 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_reg");
1693
1694 result = op - DW_OP_reg0;
1695 result_val = value_from_ulongest (address_type, result);
1697 break;
1698
1699 case DW_OP_regx:
1700 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
1701 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
1702
1703 result = reg;
1704 result_val = value_from_ulongest (address_type, result);
1706 break;
1707
1708 case DW_OP_implicit_value:
1709 {
1710 uint64_t len;
1711
1712 op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
1713 if (op_ptr + len > op_end)
1714 error (_("DW_OP_implicit_value: too few bytes available."));
1715 this->m_len = len;
1716 this->m_data = op_ptr;
1718 op_ptr += len;
1719 dwarf_expr_require_composition (op_ptr, op_end,
1720 "DW_OP_implicit_value");
1721 }
1722 goto no_push;
1723
1724 case DW_OP_stack_value:
1726 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
1727 goto no_push;
1728
1729 case DW_OP_implicit_pointer:
1730 case DW_OP_GNU_implicit_pointer:
1731 {
1732 int64_t len;
1733 ensure_have_per_cu (this->m_per_cu, "DW_OP_implicit_pointer");
1734
1735 int ref_addr_size = this->m_per_cu->ref_addr_size ();
1736
1737 /* The referred-to DIE of sect_offset kind. */
1738 this->m_len = extract_unsigned_integer (op_ptr, ref_addr_size,
1739 byte_order);
1740 op_ptr += ref_addr_size;
1741
1742 /* The byte offset into the data. */
1743 op_ptr = safe_read_sleb128 (op_ptr, op_end, &len);
1744 result = (ULONGEST) len;
1745 result_val = value_from_ulongest (address_type, result);
1746
1748 dwarf_expr_require_composition (op_ptr, op_end,
1749 "DW_OP_implicit_pointer");
1750 }
1751 break;
1752
1753 case DW_OP_breg0:
1754 case DW_OP_breg1:
1755 case DW_OP_breg2:
1756 case DW_OP_breg3:
1757 case DW_OP_breg4:
1758 case DW_OP_breg5:
1759 case DW_OP_breg6:
1760 case DW_OP_breg7:
1761 case DW_OP_breg8:
1762 case DW_OP_breg9:
1763 case DW_OP_breg10:
1764 case DW_OP_breg11:
1765 case DW_OP_breg12:
1766 case DW_OP_breg13:
1767 case DW_OP_breg14:
1768 case DW_OP_breg15:
1769 case DW_OP_breg16:
1770 case DW_OP_breg17:
1771 case DW_OP_breg18:
1772 case DW_OP_breg19:
1773 case DW_OP_breg20:
1774 case DW_OP_breg21:
1775 case DW_OP_breg22:
1776 case DW_OP_breg23:
1777 case DW_OP_breg24:
1778 case DW_OP_breg25:
1779 case DW_OP_breg26:
1780 case DW_OP_breg27:
1781 case DW_OP_breg28:
1782 case DW_OP_breg29:
1783 case DW_OP_breg30:
1784 case DW_OP_breg31:
1785 {
1786 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
1787 ensure_have_frame (this->m_frame, "DW_OP_breg");
1788
1789 result = read_addr_from_reg (this->m_frame, op - DW_OP_breg0);
1790 result += offset;
1791 result_val = value_from_ulongest (address_type, result);
1792 }
1793 break;
1794 case DW_OP_bregx:
1795 {
1796 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
1797 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
1798 ensure_have_frame (this->m_frame, "DW_OP_bregx");
1799
1800 result = read_addr_from_reg (this->m_frame, reg);
1801 result += offset;
1802 result_val = value_from_ulongest (address_type, result);
1803 }
1804 break;
1805 case DW_OP_fbreg:
1806 {
1807 const gdb_byte *datastart;
1808 size_t datalen;
1809
1810 op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
1811
1812 /* Rather than create a whole new context, we simply
1813 backup the current stack locally and install a new empty stack,
1814 then reset it afterwards, effectively erasing whatever the
1815 recursive call put there. */
1816 std::vector<dwarf_stack_value> saved_stack = std::move (this->m_stack);
1817 this->m_stack.clear ();
1818
1819 /* FIXME: cagney/2003-03-26: This code should be using
1820 get_frame_base_address(), and then implement a dwarf2
1821 specific this_base method. */
1822 this->get_frame_base (&datastart, &datalen);
1823 eval (datastart, datalen);
1824 if (this->m_location == DWARF_VALUE_MEMORY)
1825 result = fetch_address (0);
1826 else if (this->m_location == DWARF_VALUE_REGISTER)
1827 result
1829 else
1830 error (_("Not implemented: computing frame "
1831 "base using explicit value operator"));
1832 result = result + offset;
1833 result_val = value_from_ulongest (address_type, result);
1834 in_stack_memory = true;
1835
1836 /* Restore the content of the original stack. */
1837 this->m_stack = std::move (saved_stack);
1838
1840 }
1841 break;
1842
1843 case DW_OP_dup:
1844 result_val = fetch (0);
1845 in_stack_memory = fetch_in_stack_memory (0);
1846 break;
1847
1848 case DW_OP_drop:
1849 pop ();
1850 goto no_push;
1851
1852 case DW_OP_pick:
1853 offset = *op_ptr++;
1854 result_val = fetch (offset);
1855 in_stack_memory = fetch_in_stack_memory (offset);
1856 break;
1857
1858 case DW_OP_swap:
1859 {
1860 if (this->m_stack.size () < 2)
1861 error (_("Not enough elements for "
1862 "DW_OP_swap. Need 2, have %zu."),
1863 this->m_stack.size ());
1864
1865 dwarf_stack_value &t1 = this->m_stack[this->m_stack.size () - 1];
1866 dwarf_stack_value &t2 = this->m_stack[this->m_stack.size () - 2];
1867 std::swap (t1, t2);
1868 goto no_push;
1869 }
1870
1871 case DW_OP_over:
1872 result_val = fetch (1);
1873 in_stack_memory = fetch_in_stack_memory (1);
1874 break;
1875
1876 case DW_OP_rot:
1877 {
1878 if (this->m_stack.size () < 3)
1879 error (_("Not enough elements for "
1880 "DW_OP_rot. Need 3, have %zu."),
1881 this->m_stack.size ());
1882
1883 dwarf_stack_value temp = this->m_stack[this->m_stack.size () - 1];
1884 this->m_stack[this->m_stack.size () - 1]
1885 = this->m_stack[this->m_stack.size () - 2];
1886 this->m_stack[this->m_stack.size () - 2]
1887 = this->m_stack[this->m_stack.size () - 3];
1888 this->m_stack[this->m_stack.size () - 3] = temp;
1889 goto no_push;
1890 }
1891
1892 case DW_OP_deref:
1893 case DW_OP_deref_size:
1894 case DW_OP_deref_type:
1895 case DW_OP_GNU_deref_type:
1896 {
1897 int addr_size = (op == DW_OP_deref ? this->m_addr_size : *op_ptr++);
1898 gdb_byte *buf = (gdb_byte *) alloca (addr_size);
1899 CORE_ADDR addr = fetch_address (0);
1900 struct type *type;
1901
1902 pop ();
1903
1904 if (op == DW_OP_deref_type || op == DW_OP_GNU_deref_type)
1905 {
1906 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1907 cu_offset type_die_cu_off = (cu_offset) uoffset;
1908 type = get_base_type (type_die_cu_off);
1909 }
1910 else
1912
1913 this->read_mem (buf, addr, addr_size);
1914
1915 /* If the size of the object read from memory is different
1916 from the type length, we need to zero-extend it. */
1917 if (type->length () != addr_size)
1918 {
1919 ULONGEST datum =
1920 extract_unsigned_integer (buf, addr_size, byte_order);
1921
1922 buf = (gdb_byte *) alloca (type->length ());
1924 byte_order, datum);
1925 }
1926
1927 result_val = value_from_contents_and_address (type, buf, addr);
1928 break;
1929 }
1930
1931 case DW_OP_abs:
1932 case DW_OP_neg:
1933 case DW_OP_not:
1934 case DW_OP_plus_uconst:
1935 {
1936 /* Unary operations. */
1937 result_val = fetch (0);
1938 pop ();
1939
1940 switch (op)
1941 {
1942 case DW_OP_abs:
1943 if (value_less (result_val,
1944 value::zero (result_val->type (), not_lval)))
1945 result_val = value_neg (result_val);
1946 break;
1947 case DW_OP_neg:
1948 result_val = value_neg (result_val);
1949 break;
1950 case DW_OP_not:
1951 dwarf_require_integral (result_val->type ());
1952 result_val = value_complement (result_val);
1953 break;
1954 case DW_OP_plus_uconst:
1955 dwarf_require_integral (result_val->type ());
1956 result = value_as_long (result_val);
1957 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
1958 result += reg;
1959 result_val = value_from_ulongest (address_type, result);
1960 break;
1961 }
1962 }
1963 break;
1964
1965 case DW_OP_and:
1966 case DW_OP_div:
1967 case DW_OP_minus:
1968 case DW_OP_mod:
1969 case DW_OP_mul:
1970 case DW_OP_or:
1971 case DW_OP_plus:
1972 case DW_OP_shl:
1973 case DW_OP_shr:
1974 case DW_OP_shra:
1975 case DW_OP_xor:
1976 case DW_OP_le:
1977 case DW_OP_ge:
1978 case DW_OP_eq:
1979 case DW_OP_lt:
1980 case DW_OP_gt:
1981 case DW_OP_ne:
1982 {
1983 /* Binary operations. */
1984 struct value *first, *second;
1985
1986 second = fetch (0);
1987 pop ();
1988
1989 first = fetch (0);
1990 pop ();
1991
1992 if (! base_types_equal_p (first->type (), second->type ()))
1993 error (_("Incompatible types on DWARF stack"));
1994
1995 switch (op)
1996 {
1997 case DW_OP_and:
1998 dwarf_require_integral (first->type ());
1999 dwarf_require_integral (second->type ());
2000 result_val = value_binop (first, second, BINOP_BITWISE_AND);
2001 break;
2002 case DW_OP_div:
2003 result_val = value_binop (first, second, BINOP_DIV);
2004 break;
2005 case DW_OP_minus:
2006 result_val = value_binop (first, second, BINOP_SUB);
2007 break;
2008 case DW_OP_mod:
2009 {
2010 int cast_back = 0;
2011 struct type *orig_type = first->type ();
2012
2013 /* We have to special-case "old-style" untyped values
2014 -- these must have mod computed using unsigned
2015 math. */
2016 if (orig_type == address_type)
2017 {
2018 struct type *utype = get_unsigned_type (arch, orig_type);
2019
2020 cast_back = 1;
2021 first = value_cast (utype, first);
2022 second = value_cast (utype, second);
2023 }
2024 /* Note that value_binop doesn't handle float or
2025 decimal float here. This seems unimportant. */
2026 result_val = value_binop (first, second, BINOP_MOD);
2027 if (cast_back)
2028 result_val = value_cast (orig_type, result_val);
2029 }
2030 break;
2031 case DW_OP_mul:
2032 result_val = value_binop (first, second, BINOP_MUL);
2033 break;
2034 case DW_OP_or:
2035 dwarf_require_integral (first->type ());
2036 dwarf_require_integral (second->type ());
2037 result_val = value_binop (first, second, BINOP_BITWISE_IOR);
2038 break;
2039 case DW_OP_plus:
2040 result_val = value_binop (first, second, BINOP_ADD);
2041 break;
2042 case DW_OP_shl:
2043 dwarf_require_integral (first->type ());
2044 dwarf_require_integral (second->type ());
2045 result_val = value_binop (first, second, BINOP_LSH);
2046 break;
2047 case DW_OP_shr:
2048 dwarf_require_integral (first->type ());
2049 dwarf_require_integral (second->type ());
2050 if (!first->type ()->is_unsigned ())
2051 {
2052 struct type *utype
2053 = get_unsigned_type (arch, first->type ());
2054
2055 first = value_cast (utype, first);
2056 }
2057
2058 result_val = value_binop (first, second, BINOP_RSH);
2059 /* Make sure we wind up with the same type we started
2060 with. */
2061 if (result_val->type () != second->type ())
2062 result_val = value_cast (second->type (), result_val);
2063 break;
2064 case DW_OP_shra:
2065 dwarf_require_integral (first->type ());
2066 dwarf_require_integral (second->type ());
2067 if (first->type ()->is_unsigned ())
2068 {
2069 struct type *stype
2070 = get_signed_type (arch, first->type ());
2071
2072 first = value_cast (stype, first);
2073 }
2074
2075 result_val = value_binop (first, second, BINOP_RSH);
2076 /* Make sure we wind up with the same type we started
2077 with. */
2078 if (result_val->type () != second->type ())
2079 result_val = value_cast (second->type (), result_val);
2080 break;
2081 case DW_OP_xor:
2082 dwarf_require_integral (first->type ());
2083 dwarf_require_integral (second->type ());
2084 result_val = value_binop (first, second, BINOP_BITWISE_XOR);
2085 break;
2086 case DW_OP_le:
2087 /* A <= B is !(B < A). */
2088 result = ! value_less (second, first);
2089 result_val = value_from_ulongest (address_type, result);
2090 break;
2091 case DW_OP_ge:
2092 /* A >= B is !(A < B). */
2093 result = ! value_less (first, second);
2094 result_val = value_from_ulongest (address_type, result);
2095 break;
2096 case DW_OP_eq:
2097 result = value_equal (first, second);
2098 result_val = value_from_ulongest (address_type, result);
2099 break;
2100 case DW_OP_lt:
2101 result = value_less (first, second);
2102 result_val = value_from_ulongest (address_type, result);
2103 break;
2104 case DW_OP_gt:
2105 /* A > B is B < A. */
2106 result = value_less (second, first);
2107 result_val = value_from_ulongest (address_type, result);
2108 break;
2109 case DW_OP_ne:
2110 result = ! value_equal (first, second);
2111 result_val = value_from_ulongest (address_type, result);
2112 break;
2113 default:
2114 internal_error (_("Can't be reached."));
2115 }
2116 }
2117 break;
2118
2119 case DW_OP_call_frame_cfa:
2120 ensure_have_frame (this->m_frame, "DW_OP_call_frame_cfa");
2121
2122 result = dwarf2_frame_cfa (this->m_frame);
2123 result_val = value_from_ulongest (address_type, result);
2124 in_stack_memory = true;
2125 break;
2126
2127 case DW_OP_GNU_push_tls_address:
2128 case DW_OP_form_tls_address:
2129 /* Variable is at a constant offset in the thread-local
2130 storage block into the objfile for the current thread and
2131 the dynamic linker module containing this expression. Here
2132 we return returns the offset from that base. The top of the
2133 stack has the offset from the beginning of the thread
2134 control block at which the variable is located. Nothing
2135 should follow this operator, so the top of stack would be
2136 returned. */
2137 result = value_as_long (fetch (0));
2138 pop ();
2140 result);
2141 result_val = value_from_ulongest (address_type, result);
2142 break;
2143
2144 case DW_OP_skip:
2145 offset = extract_signed_integer (op_ptr, 2, byte_order);
2146 op_ptr += 2;
2147 op_ptr += offset;
2148 goto no_push;
2149
2150 case DW_OP_bra:
2151 {
2152 struct value *val;
2153
2154 offset = extract_signed_integer (op_ptr, 2, byte_order);
2155 op_ptr += 2;
2156 val = fetch (0);
2157 dwarf_require_integral (val->type ());
2158 if (value_as_long (val) != 0)
2159 op_ptr += offset;
2160 pop ();
2161 }
2162 goto no_push;
2163
2164 case DW_OP_nop:
2165 goto no_push;
2166
2167 case DW_OP_piece:
2168 {
2169 uint64_t size;
2170
2171 /* Record the piece. */
2172 op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
2173 add_piece (8 * size, 0);
2174
2175 /* Pop off the address/regnum, and reset the location
2176 type. */
2177 if (this->m_location != DWARF_VALUE_LITERAL
2179 pop ();
2181 }
2182 goto no_push;
2183
2184 case DW_OP_bit_piece:
2185 {
2186 uint64_t size, uleb_offset;
2187
2188 /* Record the piece. */
2189 op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
2190 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uleb_offset);
2191 add_piece (size, uleb_offset);
2192
2193 /* Pop off the address/regnum, and reset the location
2194 type. */
2195 if (this->m_location != DWARF_VALUE_LITERAL
2197 pop ();
2199 }
2200 goto no_push;
2201
2202 case DW_OP_GNU_uninit:
2203 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_GNU_uninit");
2204 this->m_initialized = false;
2205 goto no_push;
2206
2207 case DW_OP_call2:
2208 {
2209 cu_offset cu_off
2210 = (cu_offset) extract_unsigned_integer (op_ptr, 2, byte_order);
2211 op_ptr += 2;
2212 this->dwarf_call (cu_off);
2213 }
2214 goto no_push;
2215
2216 case DW_OP_call4:
2217 {
2218 cu_offset cu_off
2219 = (cu_offset) extract_unsigned_integer (op_ptr, 4, byte_order);
2220 op_ptr += 4;
2221 this->dwarf_call (cu_off);
2222 }
2223 goto no_push;
2224
2225 case DW_OP_GNU_variable_value:
2226 {
2227 ensure_have_per_cu (this->m_per_cu, "DW_OP_GNU_variable_value");
2228 int ref_addr_size = this->m_per_cu->ref_addr_size ();
2229
2230 sect_offset sect_off
2231 = (sect_offset) extract_unsigned_integer (op_ptr,
2232 ref_addr_size,
2233 byte_order);
2234 op_ptr += ref_addr_size;
2235 result_val = sect_variable_value (sect_off, this->m_per_cu,
2236 this->m_per_objfile);
2237 result_val = value_cast (address_type, result_val);
2238 }
2239 break;
2240
2241 case DW_OP_entry_value:
2242 case DW_OP_GNU_entry_value:
2243 {
2244 uint64_t len;
2245 CORE_ADDR deref_size;
2246 union call_site_parameter_u kind_u;
2247
2248 op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
2249 if (op_ptr + len > op_end)
2250 error (_("DW_OP_entry_value: too few bytes available."));
2251
2252 kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (op_ptr, op_ptr + len);
2253 if (kind_u.dwarf_reg != -1)
2254 {
2255 op_ptr += len;
2257 kind_u,
2258 -1 /* deref_size */);
2259 goto no_push;
2260 }
2261
2263 op_ptr + len,
2264 &deref_size);
2265 if (kind_u.dwarf_reg != -1)
2266 {
2267 if (deref_size == -1)
2268 deref_size = this->m_addr_size;
2269 op_ptr += len;
2271 kind_u, deref_size);
2272 goto no_push;
2273 }
2274
2275 error (_("DWARF-2 expression error: DW_OP_entry_value is "
2276 "supported only for single DW_OP_reg* "
2277 "or for DW_OP_breg*(0)+DW_OP_deref*"));
2278 }
2279
2280 case DW_OP_GNU_parameter_ref:
2281 {
2282 union call_site_parameter_u kind_u;
2283
2284 kind_u.param_cu_off
2285 = (cu_offset) extract_unsigned_integer (op_ptr, 4, byte_order);
2286 op_ptr += 4;
2288 kind_u,
2289 -1 /* deref_size */);
2290 }
2291 goto no_push;
2292
2293 case DW_OP_const_type:
2294 case DW_OP_GNU_const_type:
2295 {
2296 int n;
2297 const gdb_byte *data;
2298 struct type *type;
2299
2300 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
2301 cu_offset type_die_cu_off = (cu_offset) uoffset;
2302
2303 n = *op_ptr++;
2304 data = op_ptr;
2305 op_ptr += n;
2306
2307 type = get_base_type (type_die_cu_off);
2308
2309 if (type->length () != n)
2310 error (_("DW_OP_const_type has different sizes for type and data"));
2311
2312 result_val = value_from_contents (type, data);
2313 }
2314 break;
2315
2316 case DW_OP_regval_type:
2317 case DW_OP_GNU_regval_type:
2318 {
2319 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
2320 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
2321 cu_offset type_die_cu_off = (cu_offset) uoffset;
2322
2323 ensure_have_frame (this->m_frame, "DW_OP_regval_type");
2324
2325 struct type *type = get_base_type (type_die_cu_off);
2326 int regnum
2328 reg);
2329 result_val = value_from_register (type, regnum, this->m_frame);
2330 }
2331 break;
2332
2333 case DW_OP_convert:
2334 case DW_OP_GNU_convert:
2335 case DW_OP_reinterpret:
2336 case DW_OP_GNU_reinterpret:
2337 {
2338 struct type *type;
2339
2340 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
2341 cu_offset type_die_cu_off = (cu_offset) uoffset;
2342
2343 if (to_underlying (type_die_cu_off) == 0)
2345 else
2346 type = get_base_type (type_die_cu_off);
2347
2348 result_val = fetch (0);
2349 pop ();
2350
2351 if (op == DW_OP_convert || op == DW_OP_GNU_convert)
2352 result_val = value_cast (type, result_val);
2353 else if (type == result_val->type ())
2354 {
2355 /* Nothing. */
2356 }
2357 else if (type->length ()
2358 != result_val->type ()->length ())
2359 error (_("DW_OP_reinterpret has wrong size"));
2360 else
2361 result_val
2363 result_val->contents_all ().data ());
2364 }
2365 break;
2366
2367 case DW_OP_push_object_address:
2368 /* Return the address of the object we are currently observing. */
2369 if (this->m_addr_info == nullptr
2370 || (this->m_addr_info->valaddr.data () == nullptr
2371 && this->m_addr_info->addr == 0))
2372 error (_("Location address is not set."));
2373
2374 result_val
2376 break;
2377
2378 default:
2379 error (_("Unhandled dwarf expression opcode 0x%x"), op);
2380 }
2381
2382 /* Most things push a result value. */
2383 gdb_assert (result_val != NULL);
2384 push (result_val, in_stack_memory);
2385 no_push:
2386 ;
2387 }
2388
2389 /* To simplify our main caller, if the result is an implicit
2390 pointer, then make a pieced value. This is ok because we can't
2391 have implicit pointers in contexts where pieces are invalid. */
2393 add_piece (8 * this->m_addr_size, 0);
2394
2395 this->m_recursion_depth--;
2396 gdb_assert (this->m_recursion_depth >= 0);
2397}
int regnum
gdb_regnum
Definition arm.h:39
const struct block * get_frame_block(frame_info_ptr frame, CORE_ADDR *addr_in_block)
Definition blockframe.c:55
call_site_parameter_kind
Definition call-site.h:36
@ CALL_SITE_PARAMETER_DWARF_REG
Definition call-site.h:38
@ CALL_SITE_PARAMETER_PARAM_OFFSET
Definition call-site.h:44
void * get(unsigned key)
Definition registry.h:211
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition corefile.c:238
void write_memory_with_notification(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition corefile.c:370
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
int longest_to_int(LONGEST)
Definition valprint.c:1372
@ not_lval
Definition defs.h:361
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:465
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
#define QUIT
Definition defs.h:187
CORE_ADDR dwarf2_frame_cfa(frame_info_ptr this_frame)
Definition frame.c:1415
static value * indirect_pieced_value(value *value)
Definition expr.c:510
const gdb_byte * safe_skip_leb128(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1281
static void dwarf_require_integral(struct type *type)
Definition expr.c:1095
static void read_pieced_value(value *v)
Definition expr.c:449
static void ensure_have_per_cu(dwarf2_per_cu_data *per_cu, const char *op_name)
Definition expr.c:62
static void write_pieced_value(value *to, value *from)
Definition expr.c:455
static size_t bits_to_bytes(ULONGEST start, ULONGEST n_bits)
Definition expr.c:73
static void * copy_pieced_value_closure(const value *v)
Definition expr.c:612
static void free_pieced_value_closure(value *v)
Definition expr.c:621
static const registry< gdbarch >::key< dwarf_gdbarch_types > dwarf_arch_cookie
Definition expr.c:47
static struct type * get_unsigned_type(struct gdbarch *gdbarch, struct type *type)
Definition expr.c:1107
static bool rw_pieced_value(value *v, value *from, bool check_optimized)
Definition expr.c:145
void dwarf_expr_require_composition(const gdb_byte *op_ptr, const gdb_byte *op_end, const char *op_name)
Definition expr.c:1295
int dwarf_block_to_dwarf_reg_deref(const gdb_byte *buf, const gdb_byte *buf_end, CORE_ADDR *deref_size_return)
Definition expr.c:1367
const gdb_byte * safe_read_sleb128(const gdb_byte *buf, const gdb_byte *buf_end, int64_t *r)
Definition expr.c:1271
static piece_closure * allocate_piece_closure(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, std::vector< dwarf_expr_piece > &&pieces, frame_info_ptr frame)
Definition expr.c:112
static value * coerce_pieced_ref(const value *value)
Definition expr.c:582
static int base_types_equal_p(struct type *t1, struct type *t2)
Definition expr.c:1311
static void ensure_have_frame(frame_info_ptr frame, const char *op_name)
Definition expr.c:52
static const struct lval_funcs pieced_value_funcs
Definition expr.c:637
static bool is_optimized_out_pieced_value(value *v)
Definition expr.c:461
int dwarf_block_to_sp_offset(struct gdbarch *gdbarch, const gdb_byte *buf, const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
Definition expr.c:1453
CORE_ADDR read_addr_from_reg(frame_info_ptr frame, int reg)
Definition expr.c:81
const gdb_byte * safe_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.c:1259
int dwarf_block_to_fb_offset(const gdb_byte *buf, const gdb_byte *buf_end, CORE_ADDR *fb_offset_return)
Definition expr.c:1426
static struct type * get_signed_type(struct gdbarch *gdbarch, struct type *type)
Definition expr.c:1129
static bool check_pieced_synthetic_pointer(const value *value, LONGEST bit_offset, int bit_length)
Definition expr.c:470
int dwarf_block_to_dwarf_reg(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1324
static value * sect_variable_value(sect_offset sect_off, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition expr.c:653
static const gdb_byte * gdb_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.h:281
@ DWARF_VALUE_STACK
Definition expr.h:42
@ DWARF_VALUE_LITERAL
Definition expr.h:45
@ DWARF_VALUE_IMPLICIT_POINTER
Definition expr.h:51
@ DWARF_VALUE_REGISTER
Definition expr.h:39
@ DWARF_VALUE_OPTIMIZED_OUT
Definition expr.h:48
@ DWARF_VALUE_MEMORY
Definition expr.h:35
void dwarf_expr_require_composition(const gdb_byte *, const gdb_byte *, const char *)
Definition expr.c:1295
static const gdb_byte * gdb_read_sleb128(const gdb_byte *buf, const gdb_byte *buf_end, int64_t *r)
Definition expr.h:292
int dwarf_block_to_dwarf_reg_deref(const gdb_byte *buf, const gdb_byte *buf_end, CORE_ADDR *deref_size_return)
Definition expr.c:1367
const gdb_byte * safe_read_sleb128(const gdb_byte *buf, const gdb_byte *buf_end, int64_t *r)
Definition expr.c:1271
static const gdb_byte * gdb_skip_leb128(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.h:303
CORE_ADDR read_addr_from_reg(frame_info_ptr frame, int reg)
Definition expr.c:81
const gdb_byte * safe_read_uleb128(const gdb_byte *buf, const gdb_byte *buf_end, uint64_t *r)
Definition expr.c:1259
int dwarf_block_to_dwarf_reg(const gdb_byte *buf, const gdb_byte *buf_end)
Definition expr.c:1324
struct value * value_from_register(struct type *type, int regnum, frame_info_ptr frame)
Definition findvar.c:833
CORE_ADDR address_from_register(int regnum, frame_info_ptr frame)
Definition findvar.c:883
const struct frame_id null_frame_id
Definition frame.c:688
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
void put_frame_register_bytes(frame_info_ptr frame, int regnum, CORE_ADDR offset, gdb::array_view< const gdb_byte > buffer)
Definition frame.c:1569
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
frame_info_ptr frame_find_by_id(struct frame_id id)
Definition frame.c:916
bool get_frame_register_bytes(frame_info_ptr frame, int regnum, CORE_ADDR offset, gdb::array_view< gdb_byte > buffer, int *optimizedp, int *unavailablep)
Definition frame.c:1480
CORE_ADDR get_frame_address_in_block(frame_info_ptr this_frame)
Definition frame.c:2742
struct frame_id get_frame_id(frame_info_ptr fi)
Definition frame.c:631
frame_info_ptr get_prev_frame(frame_info_ptr this_frame)
Definition frame.c:2614
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
CORE_ADDR gdbarch_integer_to_address(struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf)
Definition gdbarch.c:2586
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2037
bool gdbarch_integer_to_address_p(struct gdbarch *gdbarch)
Definition gdbarch.c:2579
enum bfd_endian type_byte_order(const struct type *type)
Definition gdbtypes.c:3900
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
struct type * init_integer_type(type_allocator &alloc, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:3355
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
size_t size
Definition go32-nat.c:239
unsigned stype
Definition go32-nat.c:3
void invalid_synthetic_pointer(void)
Definition loc.c:96
struct call_site_parameter * dwarf_expr_reg_to_entry_parameter(frame_info_ptr frame, enum call_site_parameter_kind kind, union call_site_parameter_u kind_u, dwarf2_per_cu_data **per_cu_return, dwarf2_per_objfile **per_objfile_return)
Definition loc.c:1141
struct value * indirect_synthetic_pointer(sect_offset die, LONGEST byte_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, frame_info_ptr frame, struct type *type, bool resolve_abstract_p)
Definition loc.c:1456
int dwarf_reg_to_regnum(struct gdbarch *arch, int dwarf_reg)
Definition loc.c:2275
int dwarf_reg_to_regnum_or_error(struct gdbarch *arch, ULONGEST dwarf_reg)
Definition loc.c:2304
value * compute_var_value(const char *name)
Definition loc.c:625
void func_get_frame_base_dwarf_block(struct symbol *framefunc, CORE_ADDR pc, const gdb_byte **start, size_t *length)
Definition loc.c:605
static struct type * die_type(struct die_info *, struct dwarf2_cu *)
Definition read.c:19619
struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off(cu_offset offset_in_cu, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< CORE_ADDR()> get_frame_pc)
Definition read.c:20666
unrelocated_addr dwarf2_read_addr_index(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, unsigned int addr_index)
Definition read.c:17615
struct type * dwarf2_get_die_type(cu_offset die_offset, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
Definition read.c:20863
struct type * dwarf2_fetch_die_type_sect_off(sect_offset sect_off, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, const char **var_name)
Definition read.c:20837
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
enum var_types type
Definition scm-param.c:142
Definition block.h:109
struct symbol * linkage_function() const
Definition block.c:91
struct type * builtin_uint16
Definition gdbtypes.h:2116
struct type * builtin_int8
Definition gdbtypes.h:2113
struct type * builtin_func_ptr
Definition gdbtypes.h:2146
struct type * builtin_data_ptr
Definition gdbtypes.h:2135
struct type * builtin_uint32
Definition gdbtypes.h:2120
struct type * builtin_uint64
Definition gdbtypes.h:2122
struct type * builtin_int64
Definition gdbtypes.h:2121
struct type * builtin_int
Definition gdbtypes.h:2080
struct type * builtin_int32
Definition gdbtypes.h:2119
struct type * builtin_uint8
Definition gdbtypes.h:2114
struct type * builtin_int16
Definition gdbtypes.h:2115
const gdb_byte * value
Definition call-site.h:151
const gdb_byte * data_value
Definition call-site.h:157
const gdb_byte * data
Definition loc.h:159
int addr_size() const
Definition read.c:21567
int ref_addr_size() const
Definition read.c:21583
struct objfile * objfile
Definition read.h:724
CORE_ADDR relocate(unrelocated_addr addr)
Definition read.c:1219
void execute_stack_op(const gdb_byte *op_ptr, const gdb_byte *op_end)
Definition expr.c:1494
std::vector< dwarf_stack_value > m_stack
Definition expr.h:148
const struct property_addr_info * m_addr_info
Definition expr.h:205
void eval(const gdb_byte *addr, size_t len)
Definition expr.c:1245
struct value * fetch(int n)
Definition expr.c:759
const gdb_byte * m_data
Definition expr.h:165
ULONGEST m_len
Definition expr.h:164
void push_address(CORE_ADDR value, bool in_stack_memory)
Definition expr.c:740
std::vector< dwarf_expr_piece > m_pieces
Definition expr.h:193
bool stack_empty_p() const
Definition expr.c:1194
dwarf_expr_context(dwarf2_per_objfile *per_objfile, int addr_size)
Definition expr.c:722
frame_info_ptr m_frame
Definition expr.h:199
struct type * address_type() const
Definition expr.c:691
value * evaluate(const gdb_byte *addr, size_t len, bool as_lval, dwarf2_per_cu_data *per_cu, frame_info_ptr frame, const struct property_addr_info *addr_info=nullptr, struct type *type=nullptr, struct type *subobj_type=nullptr, LONGEST subobj_offset=0)
Definition expr.c:1078
CORE_ADDR fetch_address(int n)
Definition expr.c:1150
struct type * get_base_type(cu_offset die_cu_off)
Definition expr.c:799
void push(struct value *value, bool in_stack_memory)
Definition expr.c:732
void dwarf_call(cu_offset die_cu_off)
Definition expr.c:816
int m_recursion_depth
Definition expr.h:156
int m_max_recursion_depth
Definition expr.h:156
dwarf_value_location m_location
Definition expr.h:159
dwarf2_per_cu_data * m_per_cu
Definition expr.h:202
bool fetch_in_stack_memory(int n)
Definition expr.c:1182
void push_dwarf_reg_entry_value(call_site_parameter_kind kind, call_site_parameter_u kind_u, int deref_size)
Definition expr.c:866
dwarf2_per_objfile * m_per_objfile
Definition expr.h:196
value * fetch_result(struct type *type, struct type *subobj_type, LONGEST subobj_offset, bool as_lval)
Definition expr.c:914
bool m_initialized
Definition expr.h:169
void get_frame_base(const gdb_byte **start, size_t *length)
Definition expr.c:771
void read_mem(gdb_byte *buf, CORE_ADDR addr, size_t length)
Definition expr.c:841
void add_piece(ULONGEST size, ULONGEST offset)
Definition expr.c:1201
struct dwarf_expr_piece::@42::@43 mem
enum dwarf_value_location location
Definition expr.h:57
ULONGEST length
Definition expr.h:82
const gdb_byte * data
Definition expr.h:80
struct dwarf_expr_piece::@42::@45 ptr
bool in_stack_memory
Definition expr.h:67
struct value * value
Definition expr.h:74
sect_offset die_sect_off
Definition expr.h:89
union dwarf_expr_piece::@42 v
ULONGEST size
Definition expr.h:96
struct dwarf_expr_piece::@42::@44 literal
LONGEST offset
Definition expr.h:91
CORE_ADDR addr
Definition expr.h:64
struct type * dw_types[3]
Definition expr.c:42
struct gdbarch * arch() const
Definition objfiles.h:507
CORE_ADDR text_section_offset() const
Definition objfiles.h:482
dwarf2_per_objfile * per_objfile
Definition expr.c:95
struct frame_id frame_id
Definition expr.c:105
dwarf2_per_cu_data * per_cu
Definition expr.c:98
int refc
Definition expr.c:92
std::vector< dwarf_expr_piece > pieces
Definition expr.c:101
gdb::array_view< const gdb_byte > valaddr
Definition loc.h:96
CORE_ADDR addr
Definition loc.h:99
type_code code() const
Definition gdbtypes.h:956
ULONGEST length() const
Definition gdbtypes.h:983
bool is_unsigned() const
Definition gdbtypes.h:1100
unsigned short bit_offset() const
Definition gdbtypes.h:1424
Definition value.h:130
static struct value * zero(struct type *type, enum lval_type lv)
Definition value.c:3426
void set_initialized(bool value)
Definition value.h:345
static struct value * allocate_optimized_out(struct type *type)
Definition value.c:997
gdb::array_view< const gdb_byte > contents_all()
Definition value.c:1119
void contents_copy(struct value *dst, LONGEST dst_offset, LONGEST src_offset, LONGEST length)
Definition value.c:1252
LONGEST bitsize() const
Definition value.h:193
void mark_bits_optimized_out(LONGEST offset, LONGEST length)
Definition value.c:1333
static struct value * allocate_computed(struct type *type, const struct lval_funcs *funcs, void *closure)
Definition value.c:981
static struct value * allocate(struct type *type)
Definition value.c:957
void set_stack(bool val)
Definition value.h:320
LONGEST bitpos() const
Definition value.h:202
LONGEST embedded_offset() const
Definition value.h:244
gdb::array_view< const gdb_byte > contents()
Definition value.c:1262
gdb::array_view< gdb_byte > contents_raw()
Definition value.c:1009
struct type * type() const
Definition value.h:180
value * parent() const
Definition value.h:211
void set_offset(LONGEST offset)
Definition value.h:225
void * computed_closure() const
Definition value.c:1357
void mark_bits_unavailable(LONGEST offset, ULONGEST length)
Definition value.c:413
LONGEST offset() const
Definition value.h:222
bool optimized_out()
Definition value.c:1279
bool bits_synthetic_pointer(LONGEST offset, LONGEST length) const
Definition value.c:1339
CORE_ADDR target_translate_tls_address(struct objfile *objfile, CORE_ADDR offset)
Definition target.c:1280
void copy_bitwise(gdb_byte *dest, ULONGEST dest_offset, const gdb_byte *source, ULONGEST source_offset, ULONGEST nbits, int bits_big_endian)
Definition utils.c:3588
struct value * value_neg(struct value *arg1)
Definition valarith.c:1722
struct value * value_complement(struct value *arg1)
Definition valarith.c:1770
int value_equal(struct value *arg1, struct value *arg2)
Definition valarith.c:1559
int value_less(struct value *arg1, struct value *arg2)
Definition valarith.c:1648
struct value * value_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
Definition valarith.c:1464
void read_value_memory(struct value *val, LONGEST bit_offset, bool stack, CORE_ADDR memaddr, gdb_byte *buffer, size_t length)
Definition valops.c:1042
struct value * value_at_lazy(struct type *type, CORE_ADDR addr, frame_info_ptr frame)
Definition valops.c:1036
struct value * value_cast(struct type *type, struct value *arg2)
Definition valops.c:403
CORE_ADDR value_as_address(struct value *val)
Definition value.c:2636
struct value * value_from_ulongest(struct type *type, ULONGEST num)
Definition value.c:3450
struct value * value_from_contents(struct type *type, const gdb_byte *contents)
Definition value.c:3581
LONGEST value_as_long(struct value *val)
Definition value.c:2554
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
Definition value.c:3500
struct value * value_from_contents_and_address(struct type *type, const gdb_byte *valaddr, CORE_ADDR address, frame_info_ptr frame)
Definition value.c:3552