Convert dwarf_expr_context_funcs to methods
[external/binutils.git] / gdb / dwarf2expr.c
1 /* DWARF 2 Expression Evaluator.
2
3    Copyright (C) 2001-2016 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 "symtab.h"
24 #include "gdbtypes.h"
25 #include "value.h"
26 #include "gdbcore.h"
27 #include "dwarf2.h"
28 #include "dwarf2expr.h"
29 #include "dwarf2loc.h"
30
31 /* Cookie for gdbarch data.  */
32
33 static struct gdbarch_data *dwarf_arch_cookie;
34
35 /* This holds gdbarch-specific types used by the DWARF expression
36    evaluator.  See comments in execute_stack_op.  */
37
38 struct dwarf_gdbarch_types
39 {
40   struct type *dw_types[3];
41 };
42
43 /* Allocate and fill in dwarf_gdbarch_types for an arch.  */
44
45 static void *
46 dwarf_gdbarch_types_init (struct gdbarch *gdbarch)
47 {
48   struct dwarf_gdbarch_types *types
49     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf_gdbarch_types);
50
51   /* The types themselves are lazily initialized.  */
52
53   return types;
54 }
55
56 /* Return the type used for DWARF operations where the type is
57    unspecified in the DWARF spec.  Only certain sizes are
58    supported.  */
59
60 struct type *
61 dwarf_expr_context::address_type () const
62 {
63   struct dwarf_gdbarch_types *types
64     = (struct dwarf_gdbarch_types *) gdbarch_data (this->gdbarch,
65                                                    dwarf_arch_cookie);
66   int ndx;
67
68   if (this->addr_size == 2)
69     ndx = 0;
70   else if (this->addr_size == 4)
71     ndx = 1;
72   else if (this->addr_size == 8)
73     ndx = 2;
74   else
75     error (_("Unsupported address size in DWARF expressions: %d bits"),
76            8 * this->addr_size);
77
78   if (types->dw_types[ndx] == NULL)
79     types->dw_types[ndx]
80       = arch_integer_type (this->gdbarch,
81                            8 * this->addr_size,
82                            0, "<signed DWARF address type>");
83
84   return types->dw_types[ndx];
85 }
86
87 /* Create a new context for the expression evaluator.  */
88
89 dwarf_expr_context::dwarf_expr_context ()
90 : stack (NULL),
91   stack_len (0),
92   stack_allocated (10),
93   gdbarch (NULL),
94   addr_size (0),
95   ref_addr_size (0),
96   offset (0),
97   recursion_depth (0),
98   max_recursion_depth (0x100),
99   location (DWARF_VALUE_MEMORY),
100   len (0),
101   data (NULL),
102   initialized (0),
103   num_pieces (0),
104   pieces (NULL)
105 {
106   this->stack = XNEWVEC (struct dwarf_stack_value, this->stack_allocated);
107 }
108
109 /* Clean up a dwarf_expr_context.  */
110
111 dwarf_expr_context::~dwarf_expr_context ()
112 {
113   xfree (this->stack);
114   xfree (this->pieces);
115 }
116
117 /* Expand the memory allocated stack to contain at least
118    NEED more elements than are currently used.  */
119
120 void
121 dwarf_expr_context::grow_stack (size_t need)
122 {
123   if (this->stack_len + need > this->stack_allocated)
124     {
125       size_t newlen = this->stack_len + need + 10;
126
127       this->stack = XRESIZEVEC (struct dwarf_stack_value, this->stack, newlen);
128       this->stack_allocated = newlen;
129     }
130 }
131
132 /* Push VALUE onto the stack.  */
133
134 void
135 dwarf_expr_context::push (struct value *value, int in_stack_memory)
136 {
137   struct dwarf_stack_value *v;
138
139   grow_stack (1);
140   v = &this->stack[this->stack_len++];
141   v->value = value;
142   v->in_stack_memory = in_stack_memory;
143 }
144
145 /* Push VALUE onto the stack.  */
146
147 void
148 dwarf_expr_context::push_address (CORE_ADDR value, int in_stack_memory)
149 {
150   push (value_from_ulongest (address_type (), value), in_stack_memory);
151 }
152
153 /* Pop the top item off of the stack.  */
154
155 void
156 dwarf_expr_context::pop ()
157 {
158   if (this->stack_len <= 0)
159     error (_("dwarf expression stack underflow"));
160   this->stack_len--;
161 }
162
163 /* Retrieve the N'th item on the stack.  */
164
165 struct value *
166 dwarf_expr_context::fetch (int n)
167 {
168   if (this->stack_len <= n)
169      error (_("Asked for position %d of stack, "
170               "stack only has %d elements on it."),
171             n, this->stack_len);
172   return this->stack[this->stack_len - (1 + n)].value;
173 }
174
175 /* Require that TYPE be an integral type; throw an exception if not.  */
176
177 static void
178 dwarf_require_integral (struct type *type)
179 {
180   if (TYPE_CODE (type) != TYPE_CODE_INT
181       && TYPE_CODE (type) != TYPE_CODE_CHAR
182       && TYPE_CODE (type) != TYPE_CODE_BOOL)
183     error (_("integral type expected in DWARF expression"));
184 }
185
186 /* Return the unsigned form of TYPE.  TYPE is necessarily an integral
187    type.  */
188
189 static struct type *
190 get_unsigned_type (struct gdbarch *gdbarch, struct type *type)
191 {
192   switch (TYPE_LENGTH (type))
193     {
194     case 1:
195       return builtin_type (gdbarch)->builtin_uint8;
196     case 2:
197       return builtin_type (gdbarch)->builtin_uint16;
198     case 4:
199       return builtin_type (gdbarch)->builtin_uint32;
200     case 8:
201       return builtin_type (gdbarch)->builtin_uint64;
202     default:
203       error (_("no unsigned variant found for type, while evaluating "
204                "DWARF expression"));
205     }
206 }
207
208 /* Return the signed form of TYPE.  TYPE is necessarily an integral
209    type.  */
210
211 static struct type *
212 get_signed_type (struct gdbarch *gdbarch, struct type *type)
213 {
214   switch (TYPE_LENGTH (type))
215     {
216     case 1:
217       return builtin_type (gdbarch)->builtin_int8;
218     case 2:
219       return builtin_type (gdbarch)->builtin_int16;
220     case 4:
221       return builtin_type (gdbarch)->builtin_int32;
222     case 8:
223       return builtin_type (gdbarch)->builtin_int64;
224     default:
225       error (_("no signed variant found for type, while evaluating "
226                "DWARF expression"));
227     }
228 }
229
230 /* Retrieve the N'th item on the stack, converted to an address.  */
231
232 CORE_ADDR
233 dwarf_expr_context::fetch_address (int n)
234 {
235   struct value *result_val = fetch (n);
236   enum bfd_endian byte_order = gdbarch_byte_order (this->gdbarch);
237   ULONGEST result;
238
239   dwarf_require_integral (value_type (result_val));
240   result = extract_unsigned_integer (value_contents (result_val),
241                                      TYPE_LENGTH (value_type (result_val)),
242                                      byte_order);
243
244   /* For most architectures, calling extract_unsigned_integer() alone
245      is sufficient for extracting an address.  However, some
246      architectures (e.g. MIPS) use signed addresses and using
247      extract_unsigned_integer() will not produce a correct
248      result.  Make sure we invoke gdbarch_integer_to_address()
249      for those architectures which require it.  */
250   if (gdbarch_integer_to_address_p (this->gdbarch))
251     {
252       gdb_byte *buf = (gdb_byte *) alloca (this->addr_size);
253       struct type *int_type = get_unsigned_type (this->gdbarch,
254                                                  value_type (result_val));
255
256       store_unsigned_integer (buf, this->addr_size, byte_order, result);
257       return gdbarch_integer_to_address (this->gdbarch, int_type, buf);
258     }
259
260   return (CORE_ADDR) result;
261 }
262
263 /* Retrieve the in_stack_memory flag of the N'th item on the stack.  */
264
265 int
266 dwarf_expr_context::fetch_in_stack_memory (int n)
267 {
268   if (this->stack_len <= n)
269      error (_("Asked for position %d of stack, "
270               "stack only has %d elements on it."),
271             n, this->stack_len);
272   return this->stack[this->stack_len - (1 + n)].in_stack_memory;
273 }
274
275 /* Return true if the expression stack is empty.  */
276
277 int
278 dwarf_expr_context::stack_empty_p () const
279 {
280   return this->stack_len == 0;
281 }
282
283 /* Add a new piece to the dwarf_expr_context's piece list.  */
284 void
285 dwarf_expr_context::add_piece (ULONGEST size, ULONGEST offset)
286 {
287   struct dwarf_expr_piece *p;
288
289   this->num_pieces++;
290
291   this->pieces
292     = XRESIZEVEC (struct dwarf_expr_piece, this->pieces, this->num_pieces);
293
294   p = &this->pieces[this->num_pieces - 1];
295   p->location = this->location;
296   p->size = size;
297   p->offset = offset;
298
299   if (p->location == DWARF_VALUE_LITERAL)
300     {
301       p->v.literal.data = this->data;
302       p->v.literal.length = this->len;
303     }
304   else if (stack_empty_p ())
305     {
306       p->location = DWARF_VALUE_OPTIMIZED_OUT;
307       /* Also reset the context's location, for our callers.  This is
308          a somewhat strange approach, but this lets us avoid setting
309          the location to DWARF_VALUE_MEMORY in all the individual
310          cases in the evaluator.  */
311       this->location = DWARF_VALUE_OPTIMIZED_OUT;
312     }
313   else if (p->location == DWARF_VALUE_MEMORY)
314     {
315       p->v.mem.addr = fetch_address (0);
316       p->v.mem.in_stack_memory = fetch_in_stack_memory (0);
317     }
318   else if (p->location == DWARF_VALUE_IMPLICIT_POINTER)
319     {
320       p->v.ptr.die.sect_off = this->len;
321       p->v.ptr.offset = value_as_long (fetch (0));
322     }
323   else if (p->location == DWARF_VALUE_REGISTER)
324     p->v.regno = value_as_long (fetch (0));
325   else
326     {
327       p->v.value = fetch (0);
328     }
329 }
330
331 /* Evaluate the expression at ADDR (LEN bytes long).  */
332
333 void
334 dwarf_expr_context::eval (const gdb_byte *addr, size_t len)
335 {
336   int old_recursion_depth = this->recursion_depth;
337
338   execute_stack_op (addr, addr + len);
339
340   /* RECURSION_DEPTH becomes invalid if an exception was thrown here.  */
341
342   gdb_assert (this->recursion_depth == old_recursion_depth);
343 }
344
345 /* Helper to read a uleb128 value or throw an error.  */
346
347 const gdb_byte *
348 safe_read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
349                    uint64_t *r)
350 {
351   buf = gdb_read_uleb128 (buf, buf_end, r);
352   if (buf == NULL)
353     error (_("DWARF expression error: ran off end of buffer reading uleb128 value"));
354   return buf;
355 }
356
357 /* Helper to read a sleb128 value or throw an error.  */
358
359 const gdb_byte *
360 safe_read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end,
361                    int64_t *r)
362 {
363   buf = gdb_read_sleb128 (buf, buf_end, r);
364   if (buf == NULL)
365     error (_("DWARF expression error: ran off end of buffer reading sleb128 value"));
366   return buf;
367 }
368
369 const gdb_byte *
370 safe_skip_leb128 (const gdb_byte *buf, const gdb_byte *buf_end)
371 {
372   buf = gdb_skip_leb128 (buf, buf_end);
373   if (buf == NULL)
374     error (_("DWARF expression error: ran off end of buffer reading leb128 value"));
375   return buf;
376 }
377 \f
378
379 /* Check that the current operator is either at the end of an
380    expression, or that it is followed by a composition operator or by
381    DW_OP_GNU_uninit (which should terminate the expression).  */
382
383 void
384 dwarf_expr_require_composition (const gdb_byte *op_ptr, const gdb_byte *op_end,
385                                 const char *op_name)
386 {
387   if (op_ptr != op_end && *op_ptr != DW_OP_piece && *op_ptr != DW_OP_bit_piece
388       && *op_ptr != DW_OP_GNU_uninit)
389     error (_("DWARF-2 expression error: `%s' operations must be "
390              "used either alone or in conjunction with DW_OP_piece "
391              "or DW_OP_bit_piece."),
392            op_name);
393 }
394
395 /* Return true iff the types T1 and T2 are "the same".  This only does
396    checks that might reasonably be needed to compare DWARF base
397    types.  */
398
399 static int
400 base_types_equal_p (struct type *t1, struct type *t2)
401 {
402   if (TYPE_CODE (t1) != TYPE_CODE (t2))
403     return 0;
404   if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
405     return 0;
406   return TYPE_LENGTH (t1) == TYPE_LENGTH (t2);
407 }
408
409 /* A convenience function to call get_base_type and return the result.
410    DIE is the DIE whose type we need.  SIZE is non-zero if this
411    function should verify that the resulting type has the correct
412    size.  */
413
414 struct type *
415 dwarf_expr_context::get_base_type (cu_offset die, int size)
416 {
417   struct type *result = this->impl_get_base_type (die);
418   if (result == NULL)
419     error (_("Could not find type for DW_OP_GNU_const_type"));
420   if (size != 0 && TYPE_LENGTH (result) != size)
421     error (_("DW_OP_GNU_const_type has different sizes for type and data"));
422   return result;
423 }
424
425 /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_reg* return the
426    DWARF register number.  Otherwise return -1.  */
427
428 int
429 dwarf_block_to_dwarf_reg (const gdb_byte *buf, const gdb_byte *buf_end)
430 {
431   uint64_t dwarf_reg;
432
433   if (buf_end <= buf)
434     return -1;
435   if (*buf >= DW_OP_reg0 && *buf <= DW_OP_reg31)
436     {
437       if (buf_end - buf != 1)
438         return -1;
439       return *buf - DW_OP_reg0;
440     }
441
442   if (*buf == DW_OP_GNU_regval_type)
443     {
444       buf++;
445       buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
446       if (buf == NULL)
447         return -1;
448       buf = gdb_skip_leb128 (buf, buf_end);
449       if (buf == NULL)
450         return -1;
451     }
452   else if (*buf == DW_OP_regx)
453     {
454       buf++;
455       buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
456       if (buf == NULL)
457         return -1;
458     }
459   else
460     return -1;
461   if (buf != buf_end || (int) dwarf_reg != dwarf_reg)
462     return -1;
463   return dwarf_reg;
464 }
465
466 /* If <BUF..BUF_END] contains DW_FORM_block* with just DW_OP_breg*(0) and
467    DW_OP_deref* return the DWARF register number.  Otherwise return -1.
468    DEREF_SIZE_RETURN contains -1 for DW_OP_deref; otherwise it contains the
469    size from DW_OP_deref_size.  */
470
471 int
472 dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf, const gdb_byte *buf_end,
473                                 CORE_ADDR *deref_size_return)
474 {
475   uint64_t dwarf_reg;
476   int64_t offset;
477
478   if (buf_end <= buf)
479     return -1;
480
481   if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
482     {
483       dwarf_reg = *buf - DW_OP_breg0;
484       buf++;
485       if (buf >= buf_end)
486         return -1;
487     }
488   else if (*buf == DW_OP_bregx)
489     {
490       buf++;
491       buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
492       if (buf == NULL)
493         return -1;
494       if ((int) dwarf_reg != dwarf_reg)
495        return -1;
496     }
497   else
498     return -1;
499
500   buf = gdb_read_sleb128 (buf, buf_end, &offset);
501   if (buf == NULL)
502     return -1;
503   if (offset != 0)
504     return -1;
505
506   if (*buf == DW_OP_deref)
507     {
508       buf++;
509       *deref_size_return = -1;
510     }
511   else if (*buf == DW_OP_deref_size)
512     {
513       buf++;
514       if (buf >= buf_end)
515        return -1;
516       *deref_size_return = *buf++;
517     }
518   else
519     return -1;
520
521   if (buf != buf_end)
522     return -1;
523
524   return dwarf_reg;
525 }
526
527 /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_fbreg(X) fill
528    in FB_OFFSET_RETURN with the X offset and return 1.  Otherwise return 0.  */
529
530 int
531 dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
532                           CORE_ADDR *fb_offset_return)
533 {
534   int64_t fb_offset;
535
536   if (buf_end <= buf)
537     return 0;
538
539   if (*buf != DW_OP_fbreg)
540     return 0;
541   buf++;
542
543   buf = gdb_read_sleb128 (buf, buf_end, &fb_offset);
544   if (buf == NULL)
545     return 0;
546   *fb_offset_return = fb_offset;
547   if (buf != buf_end || fb_offset != (LONGEST) *fb_offset_return)
548     return 0;
549
550   return 1;
551 }
552
553 /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
554    in SP_OFFSET_RETURN with the X offset and return 1.  Otherwise return 0.
555    The matched SP register number depends on GDBARCH.  */
556
557 int
558 dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
559                           const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
560 {
561   uint64_t dwarf_reg;
562   int64_t sp_offset;
563
564   if (buf_end <= buf)
565     return 0;
566   if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
567     {
568       dwarf_reg = *buf - DW_OP_breg0;
569       buf++;
570     }
571   else
572     {
573       if (*buf != DW_OP_bregx)
574        return 0;
575       buf++;
576       buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
577       if (buf == NULL)
578         return 0;
579     }
580
581   if (dwarf_reg_to_regnum (gdbarch, dwarf_reg)
582       != gdbarch_sp_regnum (gdbarch))
583     return 0;
584
585   buf = gdb_read_sleb128 (buf, buf_end, &sp_offset);
586   if (buf == NULL)
587     return 0;
588   *sp_offset_return = sp_offset;
589   if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
590     return 0;
591
592   return 1;
593 }
594
595 /* The engine for the expression evaluator.  Using the context in this
596    object, evaluate the expression between OP_PTR and OP_END.  */
597
598 void
599 dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr,
600                                       const gdb_byte *op_end)
601 {
602   enum bfd_endian byte_order = gdbarch_byte_order (this->gdbarch);
603   /* Old-style "untyped" DWARF values need special treatment in a
604      couple of places, specifically DW_OP_mod and DW_OP_shr.  We need
605      a special type for these values so we can distinguish them from
606      values that have an explicit type, because explicitly-typed
607      values do not need special treatment.  This special type must be
608      different (in the `==' sense) from any base type coming from the
609      CU.  */
610   struct type *address_type = this->address_type ();
611
612   this->location = DWARF_VALUE_MEMORY;
613   this->initialized = 1;  /* Default is initialized.  */
614
615   if (this->recursion_depth > this->max_recursion_depth)
616     error (_("DWARF-2 expression error: Loop detected (%d)."),
617            this->recursion_depth);
618   this->recursion_depth++;
619
620   while (op_ptr < op_end)
621     {
622       enum dwarf_location_atom op = (enum dwarf_location_atom) *op_ptr++;
623       ULONGEST result;
624       /* Assume the value is not in stack memory.
625          Code that knows otherwise sets this to 1.
626          Some arithmetic on stack addresses can probably be assumed to still
627          be a stack address, but we skip this complication for now.
628          This is just an optimization, so it's always ok to punt
629          and leave this as 0.  */
630       int in_stack_memory = 0;
631       uint64_t uoffset, reg;
632       int64_t offset;
633       struct value *result_val = NULL;
634
635       /* The DWARF expression might have a bug causing an infinite
636          loop.  In that case, quitting is the only way out.  */
637       QUIT;
638
639       switch (op)
640         {
641         case DW_OP_lit0:
642         case DW_OP_lit1:
643         case DW_OP_lit2:
644         case DW_OP_lit3:
645         case DW_OP_lit4:
646         case DW_OP_lit5:
647         case DW_OP_lit6:
648         case DW_OP_lit7:
649         case DW_OP_lit8:
650         case DW_OP_lit9:
651         case DW_OP_lit10:
652         case DW_OP_lit11:
653         case DW_OP_lit12:
654         case DW_OP_lit13:
655         case DW_OP_lit14:
656         case DW_OP_lit15:
657         case DW_OP_lit16:
658         case DW_OP_lit17:
659         case DW_OP_lit18:
660         case DW_OP_lit19:
661         case DW_OP_lit20:
662         case DW_OP_lit21:
663         case DW_OP_lit22:
664         case DW_OP_lit23:
665         case DW_OP_lit24:
666         case DW_OP_lit25:
667         case DW_OP_lit26:
668         case DW_OP_lit27:
669         case DW_OP_lit28:
670         case DW_OP_lit29:
671         case DW_OP_lit30:
672         case DW_OP_lit31:
673           result = op - DW_OP_lit0;
674           result_val = value_from_ulongest (address_type, result);
675           break;
676
677         case DW_OP_addr:
678           result = extract_unsigned_integer (op_ptr,
679                                              this->addr_size, byte_order);
680           op_ptr += this->addr_size;
681           /* Some versions of GCC emit DW_OP_addr before
682              DW_OP_GNU_push_tls_address.  In this case the value is an
683              index, not an address.  We don't support things like
684              branching between the address and the TLS op.  */
685           if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
686             result += this->offset;
687           result_val = value_from_ulongest (address_type, result);
688           break;
689
690         case DW_OP_GNU_addr_index:
691           op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
692           result = this->get_addr_index (uoffset);
693           result += this->offset;
694           result_val = value_from_ulongest (address_type, result);
695           break;
696         case DW_OP_GNU_const_index:
697           op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
698           result = this->get_addr_index (uoffset);
699           result_val = value_from_ulongest (address_type, result);
700           break;
701
702         case DW_OP_const1u:
703           result = extract_unsigned_integer (op_ptr, 1, byte_order);
704           result_val = value_from_ulongest (address_type, result);
705           op_ptr += 1;
706           break;
707         case DW_OP_const1s:
708           result = extract_signed_integer (op_ptr, 1, byte_order);
709           result_val = value_from_ulongest (address_type, result);
710           op_ptr += 1;
711           break;
712         case DW_OP_const2u:
713           result = extract_unsigned_integer (op_ptr, 2, byte_order);
714           result_val = value_from_ulongest (address_type, result);
715           op_ptr += 2;
716           break;
717         case DW_OP_const2s:
718           result = extract_signed_integer (op_ptr, 2, byte_order);
719           result_val = value_from_ulongest (address_type, result);
720           op_ptr += 2;
721           break;
722         case DW_OP_const4u:
723           result = extract_unsigned_integer (op_ptr, 4, byte_order);
724           result_val = value_from_ulongest (address_type, result);
725           op_ptr += 4;
726           break;
727         case DW_OP_const4s:
728           result = extract_signed_integer (op_ptr, 4, byte_order);
729           result_val = value_from_ulongest (address_type, result);
730           op_ptr += 4;
731           break;
732         case DW_OP_const8u:
733           result = extract_unsigned_integer (op_ptr, 8, byte_order);
734           result_val = value_from_ulongest (address_type, result);
735           op_ptr += 8;
736           break;
737         case DW_OP_const8s:
738           result = extract_signed_integer (op_ptr, 8, byte_order);
739           result_val = value_from_ulongest (address_type, result);
740           op_ptr += 8;
741           break;
742         case DW_OP_constu:
743           op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
744           result = uoffset;
745           result_val = value_from_ulongest (address_type, result);
746           break;
747         case DW_OP_consts:
748           op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
749           result = offset;
750           result_val = value_from_ulongest (address_type, result);
751           break;
752
753         /* The DW_OP_reg operations are required to occur alone in
754            location expressions.  */
755         case DW_OP_reg0:
756         case DW_OP_reg1:
757         case DW_OP_reg2:
758         case DW_OP_reg3:
759         case DW_OP_reg4:
760         case DW_OP_reg5:
761         case DW_OP_reg6:
762         case DW_OP_reg7:
763         case DW_OP_reg8:
764         case DW_OP_reg9:
765         case DW_OP_reg10:
766         case DW_OP_reg11:
767         case DW_OP_reg12:
768         case DW_OP_reg13:
769         case DW_OP_reg14:
770         case DW_OP_reg15:
771         case DW_OP_reg16:
772         case DW_OP_reg17:
773         case DW_OP_reg18:
774         case DW_OP_reg19:
775         case DW_OP_reg20:
776         case DW_OP_reg21:
777         case DW_OP_reg22:
778         case DW_OP_reg23:
779         case DW_OP_reg24:
780         case DW_OP_reg25:
781         case DW_OP_reg26:
782         case DW_OP_reg27:
783         case DW_OP_reg28:
784         case DW_OP_reg29:
785         case DW_OP_reg30:
786         case DW_OP_reg31:
787           dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_reg");
788
789           result = op - DW_OP_reg0;
790           result_val = value_from_ulongest (address_type, result);
791           this->location = DWARF_VALUE_REGISTER;
792           break;
793
794         case DW_OP_regx:
795           op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
796           dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
797
798           result = reg;
799           result_val = value_from_ulongest (address_type, result);
800           this->location = DWARF_VALUE_REGISTER;
801           break;
802
803         case DW_OP_implicit_value:
804           {
805             uint64_t len;
806
807             op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
808             if (op_ptr + len > op_end)
809               error (_("DW_OP_implicit_value: too few bytes available."));
810             this->len = len;
811             this->data = op_ptr;
812             this->location = DWARF_VALUE_LITERAL;
813             op_ptr += len;
814             dwarf_expr_require_composition (op_ptr, op_end,
815                                             "DW_OP_implicit_value");
816           }
817           goto no_push;
818
819         case DW_OP_stack_value:
820           this->location = DWARF_VALUE_STACK;
821           dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
822           goto no_push;
823
824         case DW_OP_GNU_implicit_pointer:
825           {
826             int64_t len;
827
828             if (this->ref_addr_size == -1)
829               error (_("DWARF-2 expression error: DW_OP_GNU_implicit_pointer "
830                        "is not allowed in frame context"));
831
832             /* The referred-to DIE of sect_offset kind.  */
833             this->len = extract_unsigned_integer (op_ptr, this->ref_addr_size,
834                                                  byte_order);
835             op_ptr += this->ref_addr_size;
836
837             /* The byte offset into the data.  */
838             op_ptr = safe_read_sleb128 (op_ptr, op_end, &len);
839             result = (ULONGEST) len;
840             result_val = value_from_ulongest (address_type, result);
841
842             this->location = DWARF_VALUE_IMPLICIT_POINTER;
843             dwarf_expr_require_composition (op_ptr, op_end,
844                                             "DW_OP_GNU_implicit_pointer");
845           }
846           break;
847
848         case DW_OP_breg0:
849         case DW_OP_breg1:
850         case DW_OP_breg2:
851         case DW_OP_breg3:
852         case DW_OP_breg4:
853         case DW_OP_breg5:
854         case DW_OP_breg6:
855         case DW_OP_breg7:
856         case DW_OP_breg8:
857         case DW_OP_breg9:
858         case DW_OP_breg10:
859         case DW_OP_breg11:
860         case DW_OP_breg12:
861         case DW_OP_breg13:
862         case DW_OP_breg14:
863         case DW_OP_breg15:
864         case DW_OP_breg16:
865         case DW_OP_breg17:
866         case DW_OP_breg18:
867         case DW_OP_breg19:
868         case DW_OP_breg20:
869         case DW_OP_breg21:
870         case DW_OP_breg22:
871         case DW_OP_breg23:
872         case DW_OP_breg24:
873         case DW_OP_breg25:
874         case DW_OP_breg26:
875         case DW_OP_breg27:
876         case DW_OP_breg28:
877         case DW_OP_breg29:
878         case DW_OP_breg30:
879         case DW_OP_breg31:
880           {
881             op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
882             result = this->read_addr_from_reg (op - DW_OP_breg0);
883             result += offset;
884             result_val = value_from_ulongest (address_type, result);
885           }
886           break;
887         case DW_OP_bregx:
888           {
889             op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
890             op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
891             result = this->read_addr_from_reg (reg);
892             result += offset;
893             result_val = value_from_ulongest (address_type, result);
894           }
895           break;
896         case DW_OP_fbreg:
897           {
898             const gdb_byte *datastart;
899             size_t datalen;
900             unsigned int before_stack_len;
901
902             op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
903             /* Rather than create a whole new context, we simply
904                record the stack length before execution, then reset it
905                afterwards, effectively erasing whatever the recursive
906                call put there.  */
907             before_stack_len = this->stack_len;
908             /* FIXME: cagney/2003-03-26: This code should be using
909                get_frame_base_address(), and then implement a dwarf2
910                specific this_base method.  */
911             this->get_frame_base (&datastart, &datalen);
912             eval (datastart, datalen);
913             if (this->location == DWARF_VALUE_MEMORY)
914               result = fetch_address (0);
915             else if (this->location == DWARF_VALUE_REGISTER)
916               result = this->read_addr_from_reg (value_as_long (fetch (0)));
917             else
918               error (_("Not implemented: computing frame "
919                        "base using explicit value operator"));
920             result = result + offset;
921             result_val = value_from_ulongest (address_type, result);
922             in_stack_memory = 1;
923             this->stack_len = before_stack_len;
924             this->location = DWARF_VALUE_MEMORY;
925           }
926           break;
927
928         case DW_OP_dup:
929           result_val = fetch (0);
930           in_stack_memory = fetch_in_stack_memory (0);
931           break;
932
933         case DW_OP_drop:
934           pop ();
935           goto no_push;
936
937         case DW_OP_pick:
938           offset = *op_ptr++;
939           result_val = fetch (offset);
940           in_stack_memory = fetch_in_stack_memory (offset);
941           break;
942           
943         case DW_OP_swap:
944           {
945             struct dwarf_stack_value t1, t2;
946
947             if (this->stack_len < 2)
948                error (_("Not enough elements for "
949                         "DW_OP_swap.  Need 2, have %d."),
950                       this->stack_len);
951             t1 = this->stack[this->stack_len - 1];
952             t2 = this->stack[this->stack_len - 2];
953             this->stack[this->stack_len - 1] = t2;
954             this->stack[this->stack_len - 2] = t1;
955             goto no_push;
956           }
957
958         case DW_OP_over:
959           result_val = fetch (1);
960           in_stack_memory = fetch_in_stack_memory (1);
961           break;
962
963         case DW_OP_rot:
964           {
965             struct dwarf_stack_value t1, t2, t3;
966
967             if (this->stack_len < 3)
968                error (_("Not enough elements for "
969                         "DW_OP_rot.  Need 3, have %d."),
970                       this->stack_len);
971             t1 = this->stack[this->stack_len - 1];
972             t2 = this->stack[this->stack_len - 2];
973             t3 = this->stack[this->stack_len - 3];
974             this->stack[this->stack_len - 1] = t2;
975             this->stack[this->stack_len - 2] = t3;
976             this->stack[this->stack_len - 3] = t1;
977             goto no_push;
978           }
979
980         case DW_OP_deref:
981         case DW_OP_deref_size:
982         case DW_OP_GNU_deref_type:
983           {
984             int addr_size = (op == DW_OP_deref ? this->addr_size : *op_ptr++);
985             gdb_byte *buf = (gdb_byte *) alloca (addr_size);
986             CORE_ADDR addr = fetch_address (0);
987             struct type *type;
988
989             pop ();
990
991             if (op == DW_OP_GNU_deref_type)
992               {
993                 cu_offset type_die;
994
995                 op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
996                 type_die.cu_off = uoffset;
997                 type = get_base_type (type_die, 0);
998               }
999             else
1000               type = address_type;
1001
1002             this->read_mem (buf, addr, addr_size);
1003
1004             /* If the size of the object read from memory is different
1005                from the type length, we need to zero-extend it.  */
1006             if (TYPE_LENGTH (type) != addr_size)
1007               {
1008                 ULONGEST result =
1009                   extract_unsigned_integer (buf, addr_size, byte_order);
1010
1011                 buf = (gdb_byte *) alloca (TYPE_LENGTH (type));
1012                 store_unsigned_integer (buf, TYPE_LENGTH (type),
1013                                         byte_order, result);
1014               }
1015
1016             result_val = value_from_contents_and_address (type, buf, addr);
1017             break;
1018           }
1019
1020         case DW_OP_abs:
1021         case DW_OP_neg:
1022         case DW_OP_not:
1023         case DW_OP_plus_uconst:
1024           {
1025             /* Unary operations.  */
1026             result_val = fetch (0);
1027             pop ();
1028
1029             switch (op)
1030               {
1031               case DW_OP_abs:
1032                 if (value_less (result_val,
1033                                 value_zero (value_type (result_val), not_lval)))
1034                   result_val = value_neg (result_val);
1035                 break;
1036               case DW_OP_neg:
1037                 result_val = value_neg (result_val);
1038                 break;
1039               case DW_OP_not:
1040                 dwarf_require_integral (value_type (result_val));
1041                 result_val = value_complement (result_val);
1042                 break;
1043               case DW_OP_plus_uconst:
1044                 dwarf_require_integral (value_type (result_val));
1045                 result = value_as_long (result_val);
1046                 op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
1047                 result += reg;
1048                 result_val = value_from_ulongest (address_type, result);
1049                 break;
1050               }
1051           }
1052           break;
1053
1054         case DW_OP_and:
1055         case DW_OP_div:
1056         case DW_OP_minus:
1057         case DW_OP_mod:
1058         case DW_OP_mul:
1059         case DW_OP_or:
1060         case DW_OP_plus:
1061         case DW_OP_shl:
1062         case DW_OP_shr:
1063         case DW_OP_shra:
1064         case DW_OP_xor:
1065         case DW_OP_le:
1066         case DW_OP_ge:
1067         case DW_OP_eq:
1068         case DW_OP_lt:
1069         case DW_OP_gt:
1070         case DW_OP_ne:
1071           {
1072             /* Binary operations.  */
1073             struct value *first, *second;
1074
1075             second = fetch (0);
1076             pop ();
1077
1078             first = fetch (0);
1079             pop ();
1080
1081             if (! base_types_equal_p (value_type (first), value_type (second)))
1082               error (_("Incompatible types on DWARF stack"));
1083
1084             switch (op)
1085               {
1086               case DW_OP_and:
1087                 dwarf_require_integral (value_type (first));
1088                 dwarf_require_integral (value_type (second));
1089                 result_val = value_binop (first, second, BINOP_BITWISE_AND);
1090                 break;
1091               case DW_OP_div:
1092                 result_val = value_binop (first, second, BINOP_DIV);
1093                 break;
1094               case DW_OP_minus:
1095                 result_val = value_binop (first, second, BINOP_SUB);
1096                 break;
1097               case DW_OP_mod:
1098                 {
1099                   int cast_back = 0;
1100                   struct type *orig_type = value_type (first);
1101
1102                   /* We have to special-case "old-style" untyped values
1103                      -- these must have mod computed using unsigned
1104                      math.  */
1105                   if (orig_type == address_type)
1106                     {
1107                       struct type *utype
1108                         = get_unsigned_type (this->gdbarch, orig_type);
1109
1110                       cast_back = 1;
1111                       first = value_cast (utype, first);
1112                       second = value_cast (utype, second);
1113                     }
1114                   /* Note that value_binop doesn't handle float or
1115                      decimal float here.  This seems unimportant.  */
1116                   result_val = value_binop (first, second, BINOP_MOD);
1117                   if (cast_back)
1118                     result_val = value_cast (orig_type, result_val);
1119                 }
1120                 break;
1121               case DW_OP_mul:
1122                 result_val = value_binop (first, second, BINOP_MUL);
1123                 break;
1124               case DW_OP_or:
1125                 dwarf_require_integral (value_type (first));
1126                 dwarf_require_integral (value_type (second));
1127                 result_val = value_binop (first, second, BINOP_BITWISE_IOR);
1128                 break;
1129               case DW_OP_plus:
1130                 result_val = value_binop (first, second, BINOP_ADD);
1131                 break;
1132               case DW_OP_shl:
1133                 dwarf_require_integral (value_type (first));
1134                 dwarf_require_integral (value_type (second));
1135                 result_val = value_binop (first, second, BINOP_LSH);
1136                 break;
1137               case DW_OP_shr:
1138                 dwarf_require_integral (value_type (first));
1139                 dwarf_require_integral (value_type (second));
1140                 if (!TYPE_UNSIGNED (value_type (first)))
1141                   {
1142                     struct type *utype
1143                       = get_unsigned_type (this->gdbarch, value_type (first));
1144
1145                     first = value_cast (utype, first);
1146                   }
1147
1148                 result_val = value_binop (first, second, BINOP_RSH);
1149                 /* Make sure we wind up with the same type we started
1150                    with.  */
1151                 if (value_type (result_val) != value_type (second))
1152                   result_val = value_cast (value_type (second), result_val);
1153                 break;
1154               case DW_OP_shra:
1155                 dwarf_require_integral (value_type (first));
1156                 dwarf_require_integral (value_type (second));
1157                 if (TYPE_UNSIGNED (value_type (first)))
1158                   {
1159                     struct type *stype
1160                       = get_signed_type (this->gdbarch, value_type (first));
1161
1162                     first = value_cast (stype, first);
1163                   }
1164
1165                 result_val = value_binop (first, second, BINOP_RSH);
1166                 /* Make sure we wind up with the same type we started
1167                    with.  */
1168                 if (value_type (result_val) != value_type (second))
1169                   result_val = value_cast (value_type (second), result_val);
1170                 break;
1171               case DW_OP_xor:
1172                 dwarf_require_integral (value_type (first));
1173                 dwarf_require_integral (value_type (second));
1174                 result_val = value_binop (first, second, BINOP_BITWISE_XOR);
1175                 break;
1176               case DW_OP_le:
1177                 /* A <= B is !(B < A).  */
1178                 result = ! value_less (second, first);
1179                 result_val = value_from_ulongest (address_type, result);
1180                 break;
1181               case DW_OP_ge:
1182                 /* A >= B is !(A < B).  */
1183                 result = ! value_less (first, second);
1184                 result_val = value_from_ulongest (address_type, result);
1185                 break;
1186               case DW_OP_eq:
1187                 result = value_equal (first, second);
1188                 result_val = value_from_ulongest (address_type, result);
1189                 break;
1190               case DW_OP_lt:
1191                 result = value_less (first, second);
1192                 result_val = value_from_ulongest (address_type, result);
1193                 break;
1194               case DW_OP_gt:
1195                 /* A > B is B < A.  */
1196                 result = value_less (second, first);
1197                 result_val = value_from_ulongest (address_type, result);
1198                 break;
1199               case DW_OP_ne:
1200                 result = ! value_equal (first, second);
1201                 result_val = value_from_ulongest (address_type, result);
1202                 break;
1203               default:
1204                 internal_error (__FILE__, __LINE__,
1205                                 _("Can't be reached."));
1206               }
1207           }
1208           break;
1209
1210         case DW_OP_call_frame_cfa:
1211           result = this->get_frame_cfa ();
1212           result_val = value_from_ulongest (address_type, result);
1213           in_stack_memory = 1;
1214           break;
1215
1216         case DW_OP_GNU_push_tls_address:
1217         case DW_OP_form_tls_address:
1218           /* Variable is at a constant offset in the thread-local
1219           storage block into the objfile for the current thread and
1220           the dynamic linker module containing this expression.  Here
1221           we return returns the offset from that base.  The top of the
1222           stack has the offset from the beginning of the thread
1223           control block at which the variable is located.  Nothing
1224           should follow this operator, so the top of stack would be
1225           returned.  */
1226           result = value_as_long (fetch (0));
1227           pop ();
1228           result = this->get_tls_address (result);
1229           result_val = value_from_ulongest (address_type, result);
1230           break;
1231
1232         case DW_OP_skip:
1233           offset = extract_signed_integer (op_ptr, 2, byte_order);
1234           op_ptr += 2;
1235           op_ptr += offset;
1236           goto no_push;
1237
1238         case DW_OP_bra:
1239           {
1240             struct value *val;
1241
1242             offset = extract_signed_integer (op_ptr, 2, byte_order);
1243             op_ptr += 2;
1244             val = fetch (0);
1245             dwarf_require_integral (value_type (val));
1246             if (value_as_long (val) != 0)
1247               op_ptr += offset;
1248             pop ();
1249           }
1250           goto no_push;
1251
1252         case DW_OP_nop:
1253           goto no_push;
1254
1255         case DW_OP_piece:
1256           {
1257             uint64_t size;
1258
1259             /* Record the piece.  */
1260             op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
1261             add_piece (8 * size, 0);
1262
1263             /* Pop off the address/regnum, and reset the location
1264                type.  */
1265             if (this->location != DWARF_VALUE_LITERAL
1266                 && this->location != DWARF_VALUE_OPTIMIZED_OUT)
1267               pop ();
1268             this->location = DWARF_VALUE_MEMORY;
1269           }
1270           goto no_push;
1271
1272         case DW_OP_bit_piece:
1273           {
1274             uint64_t size, offset;
1275
1276             /* Record the piece.  */
1277             op_ptr = safe_read_uleb128 (op_ptr, op_end, &size);
1278             op_ptr = safe_read_uleb128 (op_ptr, op_end, &offset);
1279             add_piece (size, offset);
1280
1281             /* Pop off the address/regnum, and reset the location
1282                type.  */
1283             if (this->location != DWARF_VALUE_LITERAL
1284                 && this->location != DWARF_VALUE_OPTIMIZED_OUT)
1285               pop ();
1286             this->location = DWARF_VALUE_MEMORY;
1287           }
1288           goto no_push;
1289
1290         case DW_OP_GNU_uninit:
1291           if (op_ptr != op_end)
1292             error (_("DWARF-2 expression error: DW_OP_GNU_uninit must always "
1293                    "be the very last op."));
1294
1295           this->initialized = 0;
1296           goto no_push;
1297
1298         case DW_OP_call2:
1299           {
1300             cu_offset offset;
1301
1302             offset.cu_off = extract_unsigned_integer (op_ptr, 2, byte_order);
1303             op_ptr += 2;
1304             this->dwarf_call (offset);
1305           }
1306           goto no_push;
1307
1308         case DW_OP_call4:
1309           {
1310             cu_offset offset;
1311
1312             offset.cu_off = extract_unsigned_integer (op_ptr, 4, byte_order);
1313             op_ptr += 4;
1314             this->dwarf_call (offset);
1315           }
1316           goto no_push;
1317         
1318         case DW_OP_GNU_entry_value:
1319           {
1320             uint64_t len;
1321             CORE_ADDR deref_size;
1322             union call_site_parameter_u kind_u;
1323
1324             op_ptr = safe_read_uleb128 (op_ptr, op_end, &len);
1325             if (op_ptr + len > op_end)
1326               error (_("DW_OP_GNU_entry_value: too few bytes available."));
1327
1328             kind_u.dwarf_reg = dwarf_block_to_dwarf_reg (op_ptr, op_ptr + len);
1329             if (kind_u.dwarf_reg != -1)
1330               {
1331                 op_ptr += len;
1332                 this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_DWARF_REG,
1333                                                   kind_u,
1334                                                   -1 /* deref_size */);
1335                 goto no_push;
1336               }
1337
1338             kind_u.dwarf_reg = dwarf_block_to_dwarf_reg_deref (op_ptr,
1339                                                                op_ptr + len,
1340                                                                &deref_size);
1341             if (kind_u.dwarf_reg != -1)
1342               {
1343                 if (deref_size == -1)
1344                   deref_size = this->addr_size;
1345                 op_ptr += len;
1346                 this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_DWARF_REG,
1347                                                   kind_u, deref_size);
1348                 goto no_push;
1349               }
1350
1351             error (_("DWARF-2 expression error: DW_OP_GNU_entry_value is "
1352                      "supported only for single DW_OP_reg* "
1353                      "or for DW_OP_breg*(0)+DW_OP_deref*"));
1354           }
1355
1356         case DW_OP_GNU_parameter_ref:
1357           {
1358             union call_site_parameter_u kind_u;
1359
1360             kind_u.param_offset.cu_off = extract_unsigned_integer (op_ptr, 4,
1361                                                                    byte_order);
1362             op_ptr += 4;
1363             this->push_dwarf_reg_entry_value (CALL_SITE_PARAMETER_PARAM_OFFSET,
1364                                               kind_u,
1365                                               -1 /* deref_size */);
1366           }
1367           goto no_push;
1368
1369         case DW_OP_GNU_const_type:
1370           {
1371             cu_offset type_die;
1372             int n;
1373             const gdb_byte *data;
1374             struct type *type;
1375
1376             op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1377             type_die.cu_off = uoffset;
1378             n = *op_ptr++;
1379             data = op_ptr;
1380             op_ptr += n;
1381
1382             type = get_base_type (type_die, n);
1383             result_val = value_from_contents (type, data);
1384           }
1385           break;
1386
1387         case DW_OP_GNU_regval_type:
1388           {
1389             cu_offset type_die;
1390             struct type *type;
1391
1392             op_ptr = safe_read_uleb128 (op_ptr, op_end, &reg);
1393             op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1394             type_die.cu_off = uoffset;
1395
1396             type = get_base_type (type_die, 0);
1397             result_val = this->get_reg_value (type, reg);
1398           }
1399           break;
1400
1401         case DW_OP_GNU_convert:
1402         case DW_OP_GNU_reinterpret:
1403           {
1404             cu_offset type_die;
1405             struct type *type;
1406
1407             op_ptr = safe_read_uleb128 (op_ptr, op_end, &uoffset);
1408             type_die.cu_off = uoffset;
1409
1410             if (type_die.cu_off == 0)
1411               type = address_type;
1412             else
1413               type = get_base_type (type_die, 0);
1414
1415             result_val = fetch (0);
1416             pop ();
1417
1418             if (op == DW_OP_GNU_convert)
1419               result_val = value_cast (type, result_val);
1420             else if (type == value_type (result_val))
1421               {
1422                 /* Nothing.  */
1423               }
1424             else if (TYPE_LENGTH (type)
1425                      != TYPE_LENGTH (value_type (result_val)))
1426               error (_("DW_OP_GNU_reinterpret has wrong size"));
1427             else
1428               result_val
1429                 = value_from_contents (type,
1430                                        value_contents_all (result_val));
1431           }
1432           break;
1433
1434         case DW_OP_push_object_address:
1435           /* Return the address of the object we are currently observing.  */
1436           result = this->get_object_address ();
1437           result_val = value_from_ulongest (address_type, result);
1438           break;
1439
1440         default:
1441           error (_("Unhandled dwarf expression opcode 0x%x"), op);
1442         }
1443
1444       /* Most things push a result value.  */
1445       gdb_assert (result_val != NULL);
1446       push (result_val, in_stack_memory);
1447     no_push:
1448       ;
1449     }
1450
1451   /* To simplify our main caller, if the result is an implicit
1452      pointer, then make a pieced value.  This is ok because we can't
1453      have implicit pointers in contexts where pieces are invalid.  */
1454   if (this->location == DWARF_VALUE_IMPLICIT_POINTER)
1455     add_piece (8 * this->addr_size, 0);
1456
1457 abort_expression:
1458   this->recursion_depth--;
1459   gdb_assert (this->recursion_depth >= 0);
1460 }
1461
1462 /* Provide a prototype to silence -Wmissing-prototypes.  */
1463 extern initialize_file_ftype _initialize_dwarf2expr;
1464
1465 void
1466 _initialize_dwarf2expr (void)
1467 {
1468   dwarf_arch_cookie
1469     = gdbarch_data_register_post_init (dwarf_gdbarch_types_init);
1470 }