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