xref: /dflybsd-src/contrib/gdb-7/gdb/dwarf2expr.c (revision a45ae5f869d9cfcb3e41dbab486e10bfa9e336bf)
15796c8dcSSimon Schubert /* DWARF 2 Expression Evaluator.
25796c8dcSSimon Schubert 
3*a45ae5f8SJohn Marino    Copyright (C) 2001-2003, 2005, 2007-2012 Free Software Foundation,
4*a45ae5f8SJohn Marino    Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    Contributed by Daniel Berlin (dan@dberlin.org)
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This file is part of GDB.
95796c8dcSSimon Schubert 
105796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
115796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
125796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
135796c8dcSSimon Schubert    (at your option) any later version.
145796c8dcSSimon Schubert 
155796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
165796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
175796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185796c8dcSSimon Schubert    GNU General Public License for more details.
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
215796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert #include "defs.h"
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "gdbtypes.h"
265796c8dcSSimon Schubert #include "value.h"
275796c8dcSSimon Schubert #include "gdbcore.h"
285796c8dcSSimon Schubert #include "dwarf2.h"
295796c8dcSSimon Schubert #include "dwarf2expr.h"
305796c8dcSSimon Schubert #include "gdb_assert.h"
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert /* Local prototypes.  */
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert static void execute_stack_op (struct dwarf_expr_context *,
35cf7f2e2dSJohn Marino 			      const gdb_byte *, const gdb_byte *);
365796c8dcSSimon Schubert 
37*a45ae5f8SJohn Marino /* Cookie for gdbarch data.  */
38*a45ae5f8SJohn Marino 
39*a45ae5f8SJohn Marino static struct gdbarch_data *dwarf_arch_cookie;
40*a45ae5f8SJohn Marino 
41*a45ae5f8SJohn Marino /* This holds gdbarch-specific types used by the DWARF expression
42*a45ae5f8SJohn Marino    evaluator.  See comments in execute_stack_op.  */
43*a45ae5f8SJohn Marino 
44*a45ae5f8SJohn Marino struct dwarf_gdbarch_types
45*a45ae5f8SJohn Marino {
46*a45ae5f8SJohn Marino   struct type *dw_types[3];
47*a45ae5f8SJohn Marino };
48*a45ae5f8SJohn Marino 
49*a45ae5f8SJohn Marino /* Allocate and fill in dwarf_gdbarch_types for an arch.  */
50*a45ae5f8SJohn Marino 
51*a45ae5f8SJohn Marino static void *
52*a45ae5f8SJohn Marino dwarf_gdbarch_types_init (struct gdbarch *gdbarch)
53*a45ae5f8SJohn Marino {
54*a45ae5f8SJohn Marino   struct dwarf_gdbarch_types *types
55*a45ae5f8SJohn Marino     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf_gdbarch_types);
56*a45ae5f8SJohn Marino 
57*a45ae5f8SJohn Marino   /* The types themselves are lazily initialized.  */
58*a45ae5f8SJohn Marino 
59*a45ae5f8SJohn Marino   return types;
60*a45ae5f8SJohn Marino }
61*a45ae5f8SJohn Marino 
62*a45ae5f8SJohn Marino /* Return the type used for DWARF operations where the type is
63*a45ae5f8SJohn Marino    unspecified in the DWARF spec.  Only certain sizes are
64*a45ae5f8SJohn Marino    supported.  */
65*a45ae5f8SJohn Marino 
66*a45ae5f8SJohn Marino static struct type *
67*a45ae5f8SJohn Marino dwarf_expr_address_type (struct dwarf_expr_context *ctx)
68*a45ae5f8SJohn Marino {
69*a45ae5f8SJohn Marino   struct dwarf_gdbarch_types *types = gdbarch_data (ctx->gdbarch,
70*a45ae5f8SJohn Marino 						    dwarf_arch_cookie);
71*a45ae5f8SJohn Marino   int ndx;
72*a45ae5f8SJohn Marino 
73*a45ae5f8SJohn Marino   if (ctx->addr_size == 2)
74*a45ae5f8SJohn Marino     ndx = 0;
75*a45ae5f8SJohn Marino   else if (ctx->addr_size == 4)
76*a45ae5f8SJohn Marino     ndx = 1;
77*a45ae5f8SJohn Marino   else if (ctx->addr_size == 8)
78*a45ae5f8SJohn Marino     ndx = 2;
79*a45ae5f8SJohn Marino   else
80*a45ae5f8SJohn Marino     error (_("Unsupported address size in DWARF expressions: %d bits"),
81*a45ae5f8SJohn Marino 	   8 * ctx->addr_size);
82*a45ae5f8SJohn Marino 
83*a45ae5f8SJohn Marino   if (types->dw_types[ndx] == NULL)
84*a45ae5f8SJohn Marino     types->dw_types[ndx]
85*a45ae5f8SJohn Marino       = arch_integer_type (ctx->gdbarch,
86*a45ae5f8SJohn Marino 			   8 * ctx->addr_size,
87*a45ae5f8SJohn Marino 			   0, "<signed DWARF address type>");
88*a45ae5f8SJohn Marino 
89*a45ae5f8SJohn Marino   return types->dw_types[ndx];
90*a45ae5f8SJohn Marino }
91*a45ae5f8SJohn Marino 
925796c8dcSSimon Schubert /* Create a new context for the expression evaluator.  */
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert struct dwarf_expr_context *
955796c8dcSSimon Schubert new_dwarf_expr_context (void)
965796c8dcSSimon Schubert {
975796c8dcSSimon Schubert   struct dwarf_expr_context *retval;
98cf7f2e2dSJohn Marino 
995796c8dcSSimon Schubert   retval = xcalloc (1, sizeof (struct dwarf_expr_context));
1005796c8dcSSimon Schubert   retval->stack_len = 0;
1015796c8dcSSimon Schubert   retval->stack_allocated = 10;
102cf7f2e2dSJohn Marino   retval->stack = xmalloc (retval->stack_allocated
103cf7f2e2dSJohn Marino 			   * sizeof (struct dwarf_stack_value));
1045796c8dcSSimon Schubert   retval->num_pieces = 0;
1055796c8dcSSimon Schubert   retval->pieces = 0;
1065796c8dcSSimon Schubert   retval->max_recursion_depth = 0x100;
1075796c8dcSSimon Schubert   return retval;
1085796c8dcSSimon Schubert }
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert /* Release the memory allocated to CTX.  */
1115796c8dcSSimon Schubert 
1125796c8dcSSimon Schubert void
1135796c8dcSSimon Schubert free_dwarf_expr_context (struct dwarf_expr_context *ctx)
1145796c8dcSSimon Schubert {
1155796c8dcSSimon Schubert   xfree (ctx->stack);
1165796c8dcSSimon Schubert   xfree (ctx->pieces);
1175796c8dcSSimon Schubert   xfree (ctx);
1185796c8dcSSimon Schubert }
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert /* Helper for make_cleanup_free_dwarf_expr_context.  */
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert static void
1235796c8dcSSimon Schubert free_dwarf_expr_context_cleanup (void *arg)
1245796c8dcSSimon Schubert {
1255796c8dcSSimon Schubert   free_dwarf_expr_context (arg);
1265796c8dcSSimon Schubert }
1275796c8dcSSimon Schubert 
1285796c8dcSSimon Schubert /* Return a cleanup that calls free_dwarf_expr_context.  */
1295796c8dcSSimon Schubert 
1305796c8dcSSimon Schubert struct cleanup *
1315796c8dcSSimon Schubert make_cleanup_free_dwarf_expr_context (struct dwarf_expr_context *ctx)
1325796c8dcSSimon Schubert {
1335796c8dcSSimon Schubert   return make_cleanup (free_dwarf_expr_context_cleanup, ctx);
1345796c8dcSSimon Schubert }
1355796c8dcSSimon Schubert 
1365796c8dcSSimon Schubert /* Expand the memory allocated to CTX's stack to contain at least
1375796c8dcSSimon Schubert    NEED more elements than are currently used.  */
1385796c8dcSSimon Schubert 
1395796c8dcSSimon Schubert static void
1405796c8dcSSimon Schubert dwarf_expr_grow_stack (struct dwarf_expr_context *ctx, size_t need)
1415796c8dcSSimon Schubert {
1425796c8dcSSimon Schubert   if (ctx->stack_len + need > ctx->stack_allocated)
1435796c8dcSSimon Schubert     {
1445796c8dcSSimon Schubert       size_t newlen = ctx->stack_len + need + 10;
145cf7f2e2dSJohn Marino 
1465796c8dcSSimon Schubert       ctx->stack = xrealloc (ctx->stack,
1475796c8dcSSimon Schubert 			     newlen * sizeof (struct dwarf_stack_value));
1485796c8dcSSimon Schubert       ctx->stack_allocated = newlen;
1495796c8dcSSimon Schubert     }
1505796c8dcSSimon Schubert }
1515796c8dcSSimon Schubert 
1525796c8dcSSimon Schubert /* Push VALUE onto CTX's stack.  */
1535796c8dcSSimon Schubert 
154*a45ae5f8SJohn Marino static void
155*a45ae5f8SJohn Marino dwarf_expr_push (struct dwarf_expr_context *ctx, struct value *value,
1565796c8dcSSimon Schubert 		 int in_stack_memory)
1575796c8dcSSimon Schubert {
1585796c8dcSSimon Schubert   struct dwarf_stack_value *v;
1595796c8dcSSimon Schubert 
1605796c8dcSSimon Schubert   dwarf_expr_grow_stack (ctx, 1);
1615796c8dcSSimon Schubert   v = &ctx->stack[ctx->stack_len++];
1625796c8dcSSimon Schubert   v->value = value;
1635796c8dcSSimon Schubert   v->in_stack_memory = in_stack_memory;
1645796c8dcSSimon Schubert }
1655796c8dcSSimon Schubert 
166*a45ae5f8SJohn Marino /* Push VALUE onto CTX's stack.  */
1675796c8dcSSimon Schubert 
1685796c8dcSSimon Schubert void
169*a45ae5f8SJohn Marino dwarf_expr_push_address (struct dwarf_expr_context *ctx, CORE_ADDR value,
170*a45ae5f8SJohn Marino 			 int in_stack_memory)
171*a45ae5f8SJohn Marino {
172*a45ae5f8SJohn Marino   dwarf_expr_push (ctx,
173*a45ae5f8SJohn Marino 		   value_from_ulongest (dwarf_expr_address_type (ctx), value),
174*a45ae5f8SJohn Marino 		   in_stack_memory);
175*a45ae5f8SJohn Marino }
176*a45ae5f8SJohn Marino 
177*a45ae5f8SJohn Marino /* Pop the top item off of CTX's stack.  */
178*a45ae5f8SJohn Marino 
179*a45ae5f8SJohn Marino static void
1805796c8dcSSimon Schubert dwarf_expr_pop (struct dwarf_expr_context *ctx)
1815796c8dcSSimon Schubert {
1825796c8dcSSimon Schubert   if (ctx->stack_len <= 0)
1835796c8dcSSimon Schubert     error (_("dwarf expression stack underflow"));
1845796c8dcSSimon Schubert   ctx->stack_len--;
1855796c8dcSSimon Schubert }
1865796c8dcSSimon Schubert 
1875796c8dcSSimon Schubert /* Retrieve the N'th item on CTX's stack.  */
1885796c8dcSSimon Schubert 
189*a45ae5f8SJohn Marino struct value *
1905796c8dcSSimon Schubert dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n)
1915796c8dcSSimon Schubert {
1925796c8dcSSimon Schubert   if (ctx->stack_len <= n)
193c50c785cSJohn Marino      error (_("Asked for position %d of stack, "
194c50c785cSJohn Marino 	      "stack only has %d elements on it."),
1955796c8dcSSimon Schubert 	    n, ctx->stack_len);
1965796c8dcSSimon Schubert   return ctx->stack[ctx->stack_len - (1 + n)].value;
197*a45ae5f8SJohn Marino }
1985796c8dcSSimon Schubert 
199*a45ae5f8SJohn Marino /* Require that TYPE be an integral type; throw an exception if not.  */
200*a45ae5f8SJohn Marino 
201*a45ae5f8SJohn Marino static void
202*a45ae5f8SJohn Marino dwarf_require_integral (struct type *type)
203*a45ae5f8SJohn Marino {
204*a45ae5f8SJohn Marino   if (TYPE_CODE (type) != TYPE_CODE_INT
205*a45ae5f8SJohn Marino       && TYPE_CODE (type) != TYPE_CODE_CHAR
206*a45ae5f8SJohn Marino       && TYPE_CODE (type) != TYPE_CODE_BOOL)
207*a45ae5f8SJohn Marino     error (_("integral type expected in DWARF expression"));
208*a45ae5f8SJohn Marino }
209*a45ae5f8SJohn Marino 
210*a45ae5f8SJohn Marino /* Return the unsigned form of TYPE.  TYPE is necessarily an integral
211*a45ae5f8SJohn Marino    type.  */
212*a45ae5f8SJohn Marino 
213*a45ae5f8SJohn Marino static struct type *
214*a45ae5f8SJohn Marino get_unsigned_type (struct gdbarch *gdbarch, struct type *type)
215*a45ae5f8SJohn Marino {
216*a45ae5f8SJohn Marino   switch (TYPE_LENGTH (type))
217*a45ae5f8SJohn Marino     {
218*a45ae5f8SJohn Marino     case 1:
219*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_uint8;
220*a45ae5f8SJohn Marino     case 2:
221*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_uint16;
222*a45ae5f8SJohn Marino     case 4:
223*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_uint32;
224*a45ae5f8SJohn Marino     case 8:
225*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_uint64;
226*a45ae5f8SJohn Marino     default:
227*a45ae5f8SJohn Marino       error (_("no unsigned variant found for type, while evaluating "
228*a45ae5f8SJohn Marino 	       "DWARF expression"));
229*a45ae5f8SJohn Marino     }
230*a45ae5f8SJohn Marino }
231*a45ae5f8SJohn Marino 
232*a45ae5f8SJohn Marino /* Return the signed form of TYPE.  TYPE is necessarily an integral
233*a45ae5f8SJohn Marino    type.  */
234*a45ae5f8SJohn Marino 
235*a45ae5f8SJohn Marino static struct type *
236*a45ae5f8SJohn Marino get_signed_type (struct gdbarch *gdbarch, struct type *type)
237*a45ae5f8SJohn Marino {
238*a45ae5f8SJohn Marino   switch (TYPE_LENGTH (type))
239*a45ae5f8SJohn Marino     {
240*a45ae5f8SJohn Marino     case 1:
241*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_int8;
242*a45ae5f8SJohn Marino     case 2:
243*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_int16;
244*a45ae5f8SJohn Marino     case 4:
245*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_int32;
246*a45ae5f8SJohn Marino     case 8:
247*a45ae5f8SJohn Marino       return builtin_type (gdbarch)->builtin_int64;
248*a45ae5f8SJohn Marino     default:
249*a45ae5f8SJohn Marino       error (_("no signed variant found for type, while evaluating "
250*a45ae5f8SJohn Marino 	       "DWARF expression"));
251*a45ae5f8SJohn Marino     }
2525796c8dcSSimon Schubert }
2535796c8dcSSimon Schubert 
254cf7f2e2dSJohn Marino /* Retrieve the N'th item on CTX's stack, converted to an address.  */
255cf7f2e2dSJohn Marino 
256cf7f2e2dSJohn Marino CORE_ADDR
257cf7f2e2dSJohn Marino dwarf_expr_fetch_address (struct dwarf_expr_context *ctx, int n)
258cf7f2e2dSJohn Marino {
259*a45ae5f8SJohn Marino   struct value *result_val = dwarf_expr_fetch (ctx, n);
260*a45ae5f8SJohn Marino   enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
261*a45ae5f8SJohn Marino   ULONGEST result;
262*a45ae5f8SJohn Marino 
263*a45ae5f8SJohn Marino   dwarf_require_integral (value_type (result_val));
264*a45ae5f8SJohn Marino   result = extract_unsigned_integer (value_contents (result_val),
265*a45ae5f8SJohn Marino 				     TYPE_LENGTH (value_type (result_val)),
266*a45ae5f8SJohn Marino 				     byte_order);
267cf7f2e2dSJohn Marino 
268cf7f2e2dSJohn Marino   /* For most architectures, calling extract_unsigned_integer() alone
269cf7f2e2dSJohn Marino      is sufficient for extracting an address.  However, some
270cf7f2e2dSJohn Marino      architectures (e.g. MIPS) use signed addresses and using
271cf7f2e2dSJohn Marino      extract_unsigned_integer() will not produce a correct
272cf7f2e2dSJohn Marino      result.  Make sure we invoke gdbarch_integer_to_address()
273cf7f2e2dSJohn Marino      for those architectures which require it.  */
274cf7f2e2dSJohn Marino   if (gdbarch_integer_to_address_p (ctx->gdbarch))
275cf7f2e2dSJohn Marino     {
276cf7f2e2dSJohn Marino       gdb_byte *buf = alloca (ctx->addr_size);
277*a45ae5f8SJohn Marino       struct type *int_type = get_unsigned_type (ctx->gdbarch,
278*a45ae5f8SJohn Marino 						 value_type (result_val));
279cf7f2e2dSJohn Marino 
280cf7f2e2dSJohn Marino       store_unsigned_integer (buf, ctx->addr_size, byte_order, result);
281cf7f2e2dSJohn Marino       return gdbarch_integer_to_address (ctx->gdbarch, int_type, buf);
282cf7f2e2dSJohn Marino     }
283cf7f2e2dSJohn Marino 
284cf7f2e2dSJohn Marino   return (CORE_ADDR) result;
285cf7f2e2dSJohn Marino }
286cf7f2e2dSJohn Marino 
2875796c8dcSSimon Schubert /* Retrieve the in_stack_memory flag of the N'th item on CTX's stack.  */
2885796c8dcSSimon Schubert 
2895796c8dcSSimon Schubert int
2905796c8dcSSimon Schubert dwarf_expr_fetch_in_stack_memory (struct dwarf_expr_context *ctx, int n)
2915796c8dcSSimon Schubert {
2925796c8dcSSimon Schubert   if (ctx->stack_len <= n)
293c50c785cSJohn Marino      error (_("Asked for position %d of stack, "
294c50c785cSJohn Marino 	      "stack only has %d elements on it."),
2955796c8dcSSimon Schubert 	    n, ctx->stack_len);
2965796c8dcSSimon Schubert   return ctx->stack[ctx->stack_len - (1 + n)].in_stack_memory;
2975796c8dcSSimon Schubert }
2985796c8dcSSimon Schubert 
299cf7f2e2dSJohn Marino /* Return true if the expression stack is empty.  */
300cf7f2e2dSJohn Marino 
301cf7f2e2dSJohn Marino static int
302cf7f2e2dSJohn Marino dwarf_expr_stack_empty_p (struct dwarf_expr_context *ctx)
303cf7f2e2dSJohn Marino {
304cf7f2e2dSJohn Marino   return ctx->stack_len == 0;
305cf7f2e2dSJohn Marino }
306cf7f2e2dSJohn Marino 
3075796c8dcSSimon Schubert /* Add a new piece to CTX's piece list.  */
3085796c8dcSSimon Schubert static void
309cf7f2e2dSJohn Marino add_piece (struct dwarf_expr_context *ctx, ULONGEST size, ULONGEST offset)
3105796c8dcSSimon Schubert {
3115796c8dcSSimon Schubert   struct dwarf_expr_piece *p;
3125796c8dcSSimon Schubert 
3135796c8dcSSimon Schubert   ctx->num_pieces++;
3145796c8dcSSimon Schubert 
3155796c8dcSSimon Schubert   ctx->pieces = xrealloc (ctx->pieces,
3165796c8dcSSimon Schubert 			  (ctx->num_pieces
3175796c8dcSSimon Schubert 			   * sizeof (struct dwarf_expr_piece)));
3185796c8dcSSimon Schubert 
3195796c8dcSSimon Schubert   p = &ctx->pieces[ctx->num_pieces - 1];
3205796c8dcSSimon Schubert   p->location = ctx->location;
3215796c8dcSSimon Schubert   p->size = size;
322cf7f2e2dSJohn Marino   p->offset = offset;
323cf7f2e2dSJohn Marino 
3245796c8dcSSimon Schubert   if (p->location == DWARF_VALUE_LITERAL)
3255796c8dcSSimon Schubert     {
3265796c8dcSSimon Schubert       p->v.literal.data = ctx->data;
3275796c8dcSSimon Schubert       p->v.literal.length = ctx->len;
3285796c8dcSSimon Schubert     }
329cf7f2e2dSJohn Marino   else if (dwarf_expr_stack_empty_p (ctx))
330cf7f2e2dSJohn Marino     {
331cf7f2e2dSJohn Marino       p->location = DWARF_VALUE_OPTIMIZED_OUT;
332cf7f2e2dSJohn Marino       /* Also reset the context's location, for our callers.  This is
333cf7f2e2dSJohn Marino 	 a somewhat strange approach, but this lets us avoid setting
334cf7f2e2dSJohn Marino 	 the location to DWARF_VALUE_MEMORY in all the individual
335cf7f2e2dSJohn Marino 	 cases in the evaluator.  */
336cf7f2e2dSJohn Marino       ctx->location = DWARF_VALUE_OPTIMIZED_OUT;
337cf7f2e2dSJohn Marino     }
338cf7f2e2dSJohn Marino   else if (p->location == DWARF_VALUE_MEMORY)
339cf7f2e2dSJohn Marino     {
340cf7f2e2dSJohn Marino       p->v.mem.addr = dwarf_expr_fetch_address (ctx, 0);
341cf7f2e2dSJohn Marino       p->v.mem.in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
342cf7f2e2dSJohn Marino     }
343c50c785cSJohn Marino   else if (p->location == DWARF_VALUE_IMPLICIT_POINTER)
344c50c785cSJohn Marino     {
345c50c785cSJohn Marino       p->v.ptr.die = ctx->len;
346*a45ae5f8SJohn Marino       p->v.ptr.offset = value_as_long (dwarf_expr_fetch (ctx, 0));
347c50c785cSJohn Marino     }
348*a45ae5f8SJohn Marino   else if (p->location == DWARF_VALUE_REGISTER)
349*a45ae5f8SJohn Marino     p->v.regno = value_as_long (dwarf_expr_fetch (ctx, 0));
3505796c8dcSSimon Schubert   else
3515796c8dcSSimon Schubert     {
352cf7f2e2dSJohn Marino       p->v.value = dwarf_expr_fetch (ctx, 0);
3535796c8dcSSimon Schubert     }
3545796c8dcSSimon Schubert }
3555796c8dcSSimon Schubert 
3565796c8dcSSimon Schubert /* Evaluate the expression at ADDR (LEN bytes long) using the context
3575796c8dcSSimon Schubert    CTX.  */
3585796c8dcSSimon Schubert 
3595796c8dcSSimon Schubert void
360cf7f2e2dSJohn Marino dwarf_expr_eval (struct dwarf_expr_context *ctx, const gdb_byte *addr,
361cf7f2e2dSJohn Marino 		 size_t len)
3625796c8dcSSimon Schubert {
3635796c8dcSSimon Schubert   int old_recursion_depth = ctx->recursion_depth;
3645796c8dcSSimon Schubert 
3655796c8dcSSimon Schubert   execute_stack_op (ctx, addr, addr + len);
3665796c8dcSSimon Schubert 
3675796c8dcSSimon Schubert   /* CTX RECURSION_DEPTH becomes invalid if an exception was thrown here.  */
3685796c8dcSSimon Schubert 
3695796c8dcSSimon Schubert   gdb_assert (ctx->recursion_depth == old_recursion_depth);
3705796c8dcSSimon Schubert }
3715796c8dcSSimon Schubert 
3725796c8dcSSimon Schubert /* Decode the unsigned LEB128 constant at BUF into the variable pointed to
3735796c8dcSSimon Schubert    by R, and return the new value of BUF.  Verify that it doesn't extend
374*a45ae5f8SJohn Marino    past BUF_END.  R can be NULL, the constant is then only skipped.  */
3755796c8dcSSimon Schubert 
376cf7f2e2dSJohn Marino const gdb_byte *
377cf7f2e2dSJohn Marino read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end, ULONGEST * r)
3785796c8dcSSimon Schubert {
3795796c8dcSSimon Schubert   unsigned shift = 0;
3805796c8dcSSimon Schubert   ULONGEST result = 0;
3815796c8dcSSimon Schubert   gdb_byte byte;
3825796c8dcSSimon Schubert 
3835796c8dcSSimon Schubert   while (1)
3845796c8dcSSimon Schubert     {
3855796c8dcSSimon Schubert       if (buf >= buf_end)
3865796c8dcSSimon Schubert 	error (_("read_uleb128: Corrupted DWARF expression."));
3875796c8dcSSimon Schubert 
3885796c8dcSSimon Schubert       byte = *buf++;
389c50c785cSJohn Marino       result |= ((ULONGEST) (byte & 0x7f)) << shift;
3905796c8dcSSimon Schubert       if ((byte & 0x80) == 0)
3915796c8dcSSimon Schubert 	break;
3925796c8dcSSimon Schubert       shift += 7;
3935796c8dcSSimon Schubert     }
394*a45ae5f8SJohn Marino   if (r)
3955796c8dcSSimon Schubert     *r = result;
3965796c8dcSSimon Schubert   return buf;
3975796c8dcSSimon Schubert }
3985796c8dcSSimon Schubert 
3995796c8dcSSimon Schubert /* Decode the signed LEB128 constant at BUF into the variable pointed to
4005796c8dcSSimon Schubert    by R, and return the new value of BUF.  Verify that it doesn't extend
401*a45ae5f8SJohn Marino    past BUF_END.  R can be NULL, the constant is then only skipped.  */
4025796c8dcSSimon Schubert 
403cf7f2e2dSJohn Marino const gdb_byte *
404cf7f2e2dSJohn Marino read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end, LONGEST * r)
4055796c8dcSSimon Schubert {
4065796c8dcSSimon Schubert   unsigned shift = 0;
4075796c8dcSSimon Schubert   LONGEST result = 0;
4085796c8dcSSimon Schubert   gdb_byte byte;
4095796c8dcSSimon Schubert 
4105796c8dcSSimon Schubert   while (1)
4115796c8dcSSimon Schubert     {
4125796c8dcSSimon Schubert       if (buf >= buf_end)
4135796c8dcSSimon Schubert 	error (_("read_sleb128: Corrupted DWARF expression."));
4145796c8dcSSimon Schubert 
4155796c8dcSSimon Schubert       byte = *buf++;
416c50c785cSJohn Marino       result |= ((ULONGEST) (byte & 0x7f)) << shift;
4175796c8dcSSimon Schubert       shift += 7;
4185796c8dcSSimon Schubert       if ((byte & 0x80) == 0)
4195796c8dcSSimon Schubert 	break;
4205796c8dcSSimon Schubert     }
4215796c8dcSSimon Schubert   if (shift < (sizeof (*r) * 8) && (byte & 0x40) != 0)
422*a45ae5f8SJohn Marino     result |= -(((LONGEST) 1) << shift);
4235796c8dcSSimon Schubert 
424*a45ae5f8SJohn Marino   if (r)
4255796c8dcSSimon Schubert     *r = result;
4265796c8dcSSimon Schubert   return buf;
4275796c8dcSSimon Schubert }
4285796c8dcSSimon Schubert 
4295796c8dcSSimon Schubert 
4305796c8dcSSimon Schubert /* Check that the current operator is either at the end of an
4315796c8dcSSimon Schubert    expression, or that it is followed by a composition operator.  */
4325796c8dcSSimon Schubert 
433cf7f2e2dSJohn Marino void
434cf7f2e2dSJohn Marino dwarf_expr_require_composition (const gdb_byte *op_ptr, const gdb_byte *op_end,
435cf7f2e2dSJohn Marino 				const char *op_name)
4365796c8dcSSimon Schubert {
4375796c8dcSSimon Schubert   /* It seems like DW_OP_GNU_uninit should be handled here.  However,
4385796c8dcSSimon Schubert      it doesn't seem to make sense for DW_OP_*_value, and it was not
4395796c8dcSSimon Schubert      checked at the other place that this function is called.  */
4405796c8dcSSimon Schubert   if (op_ptr != op_end && *op_ptr != DW_OP_piece && *op_ptr != DW_OP_bit_piece)
4415796c8dcSSimon Schubert     error (_("DWARF-2 expression error: `%s' operations must be "
442*a45ae5f8SJohn Marino 	     "used either alone or in conjunction with DW_OP_piece "
4435796c8dcSSimon Schubert 	     "or DW_OP_bit_piece."),
4445796c8dcSSimon Schubert 	   op_name);
4455796c8dcSSimon Schubert }
4465796c8dcSSimon Schubert 
447*a45ae5f8SJohn Marino /* Return true iff the types T1 and T2 are "the same".  This only does
448*a45ae5f8SJohn Marino    checks that might reasonably be needed to compare DWARF base
449*a45ae5f8SJohn Marino    types.  */
450*a45ae5f8SJohn Marino 
451*a45ae5f8SJohn Marino static int
452*a45ae5f8SJohn Marino base_types_equal_p (struct type *t1, struct type *t2)
453*a45ae5f8SJohn Marino {
454*a45ae5f8SJohn Marino   if (TYPE_CODE (t1) != TYPE_CODE (t2))
455*a45ae5f8SJohn Marino     return 0;
456*a45ae5f8SJohn Marino   if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
457*a45ae5f8SJohn Marino     return 0;
458*a45ae5f8SJohn Marino   return TYPE_LENGTH (t1) == TYPE_LENGTH (t2);
459*a45ae5f8SJohn Marino }
460*a45ae5f8SJohn Marino 
461*a45ae5f8SJohn Marino /* A convenience function to call get_base_type on CTX and return the
462*a45ae5f8SJohn Marino    result.  DIE is the DIE whose type we need.  SIZE is non-zero if
463*a45ae5f8SJohn Marino    this function should verify that the resulting type has the correct
464*a45ae5f8SJohn Marino    size.  */
465*a45ae5f8SJohn Marino 
466*a45ae5f8SJohn Marino static struct type *
467*a45ae5f8SJohn Marino dwarf_get_base_type (struct dwarf_expr_context *ctx, ULONGEST die, int size)
468*a45ae5f8SJohn Marino {
469*a45ae5f8SJohn Marino   struct type *result;
470*a45ae5f8SJohn Marino 
471*a45ae5f8SJohn Marino   if (ctx->funcs->get_base_type)
472*a45ae5f8SJohn Marino     {
473*a45ae5f8SJohn Marino       result = ctx->funcs->get_base_type (ctx, die);
474*a45ae5f8SJohn Marino       if (result == NULL)
475*a45ae5f8SJohn Marino 	error (_("Could not find type for DW_OP_GNU_const_type"));
476*a45ae5f8SJohn Marino       if (size != 0 && TYPE_LENGTH (result) != size)
477*a45ae5f8SJohn Marino 	error (_("DW_OP_GNU_const_type has different sizes for type and data"));
478*a45ae5f8SJohn Marino     }
479*a45ae5f8SJohn Marino   else
480*a45ae5f8SJohn Marino     /* Anything will do.  */
481*a45ae5f8SJohn Marino     result = builtin_type (ctx->gdbarch)->builtin_int;
482*a45ae5f8SJohn Marino 
483*a45ae5f8SJohn Marino   return result;
484*a45ae5f8SJohn Marino }
485*a45ae5f8SJohn Marino 
486*a45ae5f8SJohn Marino /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_reg* return the
487*a45ae5f8SJohn Marino    DWARF register number.  Otherwise return -1.  */
488*a45ae5f8SJohn Marino 
489*a45ae5f8SJohn Marino int
490*a45ae5f8SJohn Marino dwarf_block_to_dwarf_reg (const gdb_byte *buf, const gdb_byte *buf_end)
491*a45ae5f8SJohn Marino {
492*a45ae5f8SJohn Marino   ULONGEST dwarf_reg;
493*a45ae5f8SJohn Marino 
494*a45ae5f8SJohn Marino   if (buf_end <= buf)
495*a45ae5f8SJohn Marino     return -1;
496*a45ae5f8SJohn Marino   if (*buf >= DW_OP_reg0 && *buf <= DW_OP_reg31)
497*a45ae5f8SJohn Marino     {
498*a45ae5f8SJohn Marino       if (buf_end - buf != 1)
499*a45ae5f8SJohn Marino 	return -1;
500*a45ae5f8SJohn Marino       return *buf - DW_OP_reg0;
501*a45ae5f8SJohn Marino     }
502*a45ae5f8SJohn Marino 
503*a45ae5f8SJohn Marino   if (*buf == DW_OP_GNU_regval_type)
504*a45ae5f8SJohn Marino     {
505*a45ae5f8SJohn Marino       buf++;
506*a45ae5f8SJohn Marino       buf = read_uleb128 (buf, buf_end, &dwarf_reg);
507*a45ae5f8SJohn Marino       buf = read_uleb128 (buf, buf_end, NULL);
508*a45ae5f8SJohn Marino     }
509*a45ae5f8SJohn Marino   else if (*buf == DW_OP_regx)
510*a45ae5f8SJohn Marino     {
511*a45ae5f8SJohn Marino       buf++;
512*a45ae5f8SJohn Marino       buf = read_uleb128 (buf, buf_end, &dwarf_reg);
513*a45ae5f8SJohn Marino     }
514*a45ae5f8SJohn Marino   else
515*a45ae5f8SJohn Marino     return -1;
516*a45ae5f8SJohn Marino   if (buf != buf_end || (int) dwarf_reg != dwarf_reg)
517*a45ae5f8SJohn Marino     return -1;
518*a45ae5f8SJohn Marino   return dwarf_reg;
519*a45ae5f8SJohn Marino }
520*a45ae5f8SJohn Marino 
521*a45ae5f8SJohn Marino /* If <BUF..BUF_END] contains DW_FORM_block* with just DW_OP_breg*(0) and
522*a45ae5f8SJohn Marino    DW_OP_deref* return the DWARF register number.  Otherwise return -1.
523*a45ae5f8SJohn Marino    DEREF_SIZE_RETURN contains -1 for DW_OP_deref; otherwise it contains the
524*a45ae5f8SJohn Marino    size from DW_OP_deref_size.  */
525*a45ae5f8SJohn Marino 
526*a45ae5f8SJohn Marino int
527*a45ae5f8SJohn Marino dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf, const gdb_byte *buf_end,
528*a45ae5f8SJohn Marino 				CORE_ADDR *deref_size_return)
529*a45ae5f8SJohn Marino {
530*a45ae5f8SJohn Marino   ULONGEST dwarf_reg;
531*a45ae5f8SJohn Marino   LONGEST offset;
532*a45ae5f8SJohn Marino 
533*a45ae5f8SJohn Marino   if (buf_end <= buf)
534*a45ae5f8SJohn Marino     return -1;
535*a45ae5f8SJohn Marino   if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
536*a45ae5f8SJohn Marino     {
537*a45ae5f8SJohn Marino       dwarf_reg = *buf - DW_OP_breg0;
538*a45ae5f8SJohn Marino       buf++;
539*a45ae5f8SJohn Marino     }
540*a45ae5f8SJohn Marino   else if (*buf == DW_OP_bregx)
541*a45ae5f8SJohn Marino     {
542*a45ae5f8SJohn Marino       buf++;
543*a45ae5f8SJohn Marino       buf = read_uleb128 (buf, buf_end, &dwarf_reg);
544*a45ae5f8SJohn Marino       if ((int) dwarf_reg != dwarf_reg)
545*a45ae5f8SJohn Marino        return -1;
546*a45ae5f8SJohn Marino     }
547*a45ae5f8SJohn Marino   else
548*a45ae5f8SJohn Marino     return -1;
549*a45ae5f8SJohn Marino 
550*a45ae5f8SJohn Marino   buf = read_sleb128 (buf, buf_end, &offset);
551*a45ae5f8SJohn Marino   if (offset != 0)
552*a45ae5f8SJohn Marino     return -1;
553*a45ae5f8SJohn Marino 
554*a45ae5f8SJohn Marino   if (buf >= buf_end)
555*a45ae5f8SJohn Marino     return -1;
556*a45ae5f8SJohn Marino 
557*a45ae5f8SJohn Marino   if (*buf == DW_OP_deref)
558*a45ae5f8SJohn Marino     {
559*a45ae5f8SJohn Marino       buf++;
560*a45ae5f8SJohn Marino       *deref_size_return = -1;
561*a45ae5f8SJohn Marino     }
562*a45ae5f8SJohn Marino   else if (*buf == DW_OP_deref_size)
563*a45ae5f8SJohn Marino     {
564*a45ae5f8SJohn Marino       buf++;
565*a45ae5f8SJohn Marino       if (buf >= buf_end)
566*a45ae5f8SJohn Marino        return -1;
567*a45ae5f8SJohn Marino       *deref_size_return = *buf++;
568*a45ae5f8SJohn Marino     }
569*a45ae5f8SJohn Marino   else
570*a45ae5f8SJohn Marino     return -1;
571*a45ae5f8SJohn Marino 
572*a45ae5f8SJohn Marino   if (buf != buf_end)
573*a45ae5f8SJohn Marino     return -1;
574*a45ae5f8SJohn Marino 
575*a45ae5f8SJohn Marino   return dwarf_reg;
576*a45ae5f8SJohn Marino }
577*a45ae5f8SJohn Marino 
578*a45ae5f8SJohn Marino /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_fbreg(X) fill
579*a45ae5f8SJohn Marino    in FB_OFFSET_RETURN with the X offset and return 1.  Otherwise return 0.  */
580*a45ae5f8SJohn Marino 
581*a45ae5f8SJohn Marino int
582*a45ae5f8SJohn Marino dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
583*a45ae5f8SJohn Marino 			  CORE_ADDR *fb_offset_return)
584*a45ae5f8SJohn Marino {
585*a45ae5f8SJohn Marino   LONGEST fb_offset;
586*a45ae5f8SJohn Marino 
587*a45ae5f8SJohn Marino   if (buf_end <= buf)
588*a45ae5f8SJohn Marino     return 0;
589*a45ae5f8SJohn Marino 
590*a45ae5f8SJohn Marino   if (*buf != DW_OP_fbreg)
591*a45ae5f8SJohn Marino     return 0;
592*a45ae5f8SJohn Marino   buf++;
593*a45ae5f8SJohn Marino 
594*a45ae5f8SJohn Marino   buf = read_sleb128 (buf, buf_end, &fb_offset);
595*a45ae5f8SJohn Marino   *fb_offset_return = fb_offset;
596*a45ae5f8SJohn Marino   if (buf != buf_end || fb_offset != (LONGEST) *fb_offset_return)
597*a45ae5f8SJohn Marino     return 0;
598*a45ae5f8SJohn Marino 
599*a45ae5f8SJohn Marino   return 1;
600*a45ae5f8SJohn Marino }
601*a45ae5f8SJohn Marino 
602*a45ae5f8SJohn Marino /* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
603*a45ae5f8SJohn Marino    in SP_OFFSET_RETURN with the X offset and return 1.  Otherwise return 0.
604*a45ae5f8SJohn Marino    The matched SP register number depends on GDBARCH.  */
605*a45ae5f8SJohn Marino 
606*a45ae5f8SJohn Marino int
607*a45ae5f8SJohn Marino dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
608*a45ae5f8SJohn Marino 			  const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
609*a45ae5f8SJohn Marino {
610*a45ae5f8SJohn Marino   ULONGEST dwarf_reg;
611*a45ae5f8SJohn Marino   LONGEST sp_offset;
612*a45ae5f8SJohn Marino 
613*a45ae5f8SJohn Marino   if (buf_end <= buf)
614*a45ae5f8SJohn Marino     return 0;
615*a45ae5f8SJohn Marino   if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
616*a45ae5f8SJohn Marino     {
617*a45ae5f8SJohn Marino       dwarf_reg = *buf - DW_OP_breg0;
618*a45ae5f8SJohn Marino       buf++;
619*a45ae5f8SJohn Marino     }
620*a45ae5f8SJohn Marino   else
621*a45ae5f8SJohn Marino     {
622*a45ae5f8SJohn Marino       if (*buf != DW_OP_bregx)
623*a45ae5f8SJohn Marino        return 0;
624*a45ae5f8SJohn Marino       buf++;
625*a45ae5f8SJohn Marino       buf = read_uleb128 (buf, buf_end, &dwarf_reg);
626*a45ae5f8SJohn Marino     }
627*a45ae5f8SJohn Marino 
628*a45ae5f8SJohn Marino   if (gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_reg)
629*a45ae5f8SJohn Marino       != gdbarch_sp_regnum (gdbarch))
630*a45ae5f8SJohn Marino     return 0;
631*a45ae5f8SJohn Marino 
632*a45ae5f8SJohn Marino   buf = read_sleb128 (buf, buf_end, &sp_offset);
633*a45ae5f8SJohn Marino   *sp_offset_return = sp_offset;
634*a45ae5f8SJohn Marino   if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
635*a45ae5f8SJohn Marino     return 0;
636*a45ae5f8SJohn Marino 
637*a45ae5f8SJohn Marino   return 1;
638*a45ae5f8SJohn Marino }
639*a45ae5f8SJohn Marino 
6405796c8dcSSimon Schubert /* The engine for the expression evaluator.  Using the context in CTX,
6415796c8dcSSimon Schubert    evaluate the expression between OP_PTR and OP_END.  */
6425796c8dcSSimon Schubert 
6435796c8dcSSimon Schubert static void
6445796c8dcSSimon Schubert execute_stack_op (struct dwarf_expr_context *ctx,
645cf7f2e2dSJohn Marino 		  const gdb_byte *op_ptr, const gdb_byte *op_end)
6465796c8dcSSimon Schubert {
6475796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
648*a45ae5f8SJohn Marino   /* Old-style "untyped" DWARF values need special treatment in a
649*a45ae5f8SJohn Marino      couple of places, specifically DW_OP_mod and DW_OP_shr.  We need
650*a45ae5f8SJohn Marino      a special type for these values so we can distinguish them from
651*a45ae5f8SJohn Marino      values that have an explicit type, because explicitly-typed
652*a45ae5f8SJohn Marino      values do not need special treatment.  This special type must be
653*a45ae5f8SJohn Marino      different (in the `==' sense) from any base type coming from the
654*a45ae5f8SJohn Marino      CU.  */
655*a45ae5f8SJohn Marino   struct type *address_type = dwarf_expr_address_type (ctx);
656cf7f2e2dSJohn Marino 
6575796c8dcSSimon Schubert   ctx->location = DWARF_VALUE_MEMORY;
6585796c8dcSSimon Schubert   ctx->initialized = 1;  /* Default is initialized.  */
6595796c8dcSSimon Schubert 
6605796c8dcSSimon Schubert   if (ctx->recursion_depth > ctx->max_recursion_depth)
6615796c8dcSSimon Schubert     error (_("DWARF-2 expression error: Loop detected (%d)."),
6625796c8dcSSimon Schubert 	   ctx->recursion_depth);
6635796c8dcSSimon Schubert   ctx->recursion_depth++;
6645796c8dcSSimon Schubert 
6655796c8dcSSimon Schubert   while (op_ptr < op_end)
6665796c8dcSSimon Schubert     {
6675796c8dcSSimon Schubert       enum dwarf_location_atom op = *op_ptr++;
668cf7f2e2dSJohn Marino       ULONGEST result;
6695796c8dcSSimon Schubert       /* Assume the value is not in stack memory.
6705796c8dcSSimon Schubert 	 Code that knows otherwise sets this to 1.
6715796c8dcSSimon Schubert 	 Some arithmetic on stack addresses can probably be assumed to still
6725796c8dcSSimon Schubert 	 be a stack address, but we skip this complication for now.
6735796c8dcSSimon Schubert 	 This is just an optimization, so it's always ok to punt
6745796c8dcSSimon Schubert 	 and leave this as 0.  */
6755796c8dcSSimon Schubert       int in_stack_memory = 0;
6765796c8dcSSimon Schubert       ULONGEST uoffset, reg;
6775796c8dcSSimon Schubert       LONGEST offset;
678*a45ae5f8SJohn Marino       struct value *result_val = NULL;
679*a45ae5f8SJohn Marino 
680*a45ae5f8SJohn Marino       /* The DWARF expression might have a bug causing an infinite
681*a45ae5f8SJohn Marino 	 loop.  In that case, quitting is the only way out.  */
682*a45ae5f8SJohn Marino       QUIT;
6835796c8dcSSimon Schubert 
6845796c8dcSSimon Schubert       switch (op)
6855796c8dcSSimon Schubert 	{
6865796c8dcSSimon Schubert 	case DW_OP_lit0:
6875796c8dcSSimon Schubert 	case DW_OP_lit1:
6885796c8dcSSimon Schubert 	case DW_OP_lit2:
6895796c8dcSSimon Schubert 	case DW_OP_lit3:
6905796c8dcSSimon Schubert 	case DW_OP_lit4:
6915796c8dcSSimon Schubert 	case DW_OP_lit5:
6925796c8dcSSimon Schubert 	case DW_OP_lit6:
6935796c8dcSSimon Schubert 	case DW_OP_lit7:
6945796c8dcSSimon Schubert 	case DW_OP_lit8:
6955796c8dcSSimon Schubert 	case DW_OP_lit9:
6965796c8dcSSimon Schubert 	case DW_OP_lit10:
6975796c8dcSSimon Schubert 	case DW_OP_lit11:
6985796c8dcSSimon Schubert 	case DW_OP_lit12:
6995796c8dcSSimon Schubert 	case DW_OP_lit13:
7005796c8dcSSimon Schubert 	case DW_OP_lit14:
7015796c8dcSSimon Schubert 	case DW_OP_lit15:
7025796c8dcSSimon Schubert 	case DW_OP_lit16:
7035796c8dcSSimon Schubert 	case DW_OP_lit17:
7045796c8dcSSimon Schubert 	case DW_OP_lit18:
7055796c8dcSSimon Schubert 	case DW_OP_lit19:
7065796c8dcSSimon Schubert 	case DW_OP_lit20:
7075796c8dcSSimon Schubert 	case DW_OP_lit21:
7085796c8dcSSimon Schubert 	case DW_OP_lit22:
7095796c8dcSSimon Schubert 	case DW_OP_lit23:
7105796c8dcSSimon Schubert 	case DW_OP_lit24:
7115796c8dcSSimon Schubert 	case DW_OP_lit25:
7125796c8dcSSimon Schubert 	case DW_OP_lit26:
7135796c8dcSSimon Schubert 	case DW_OP_lit27:
7145796c8dcSSimon Schubert 	case DW_OP_lit28:
7155796c8dcSSimon Schubert 	case DW_OP_lit29:
7165796c8dcSSimon Schubert 	case DW_OP_lit30:
7175796c8dcSSimon Schubert 	case DW_OP_lit31:
7185796c8dcSSimon Schubert 	  result = op - DW_OP_lit0;
719*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7205796c8dcSSimon Schubert 	  break;
7215796c8dcSSimon Schubert 
7225796c8dcSSimon Schubert 	case DW_OP_addr:
723cf7f2e2dSJohn Marino 	  result = extract_unsigned_integer (op_ptr,
724cf7f2e2dSJohn Marino 					     ctx->addr_size, byte_order);
7255796c8dcSSimon Schubert 	  op_ptr += ctx->addr_size;
726cf7f2e2dSJohn Marino 	  /* Some versions of GCC emit DW_OP_addr before
727cf7f2e2dSJohn Marino 	     DW_OP_GNU_push_tls_address.  In this case the value is an
728cf7f2e2dSJohn Marino 	     index, not an address.  We don't support things like
729cf7f2e2dSJohn Marino 	     branching between the address and the TLS op.  */
730cf7f2e2dSJohn Marino 	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
731cf7f2e2dSJohn Marino 	    result += ctx->offset;
732*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7335796c8dcSSimon Schubert 	  break;
7345796c8dcSSimon Schubert 
7355796c8dcSSimon Schubert 	case DW_OP_const1u:
7365796c8dcSSimon Schubert 	  result = extract_unsigned_integer (op_ptr, 1, byte_order);
737*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7385796c8dcSSimon Schubert 	  op_ptr += 1;
7395796c8dcSSimon Schubert 	  break;
7405796c8dcSSimon Schubert 	case DW_OP_const1s:
7415796c8dcSSimon Schubert 	  result = extract_signed_integer (op_ptr, 1, byte_order);
742*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7435796c8dcSSimon Schubert 	  op_ptr += 1;
7445796c8dcSSimon Schubert 	  break;
7455796c8dcSSimon Schubert 	case DW_OP_const2u:
7465796c8dcSSimon Schubert 	  result = extract_unsigned_integer (op_ptr, 2, byte_order);
747*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7485796c8dcSSimon Schubert 	  op_ptr += 2;
7495796c8dcSSimon Schubert 	  break;
7505796c8dcSSimon Schubert 	case DW_OP_const2s:
7515796c8dcSSimon Schubert 	  result = extract_signed_integer (op_ptr, 2, byte_order);
752*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7535796c8dcSSimon Schubert 	  op_ptr += 2;
7545796c8dcSSimon Schubert 	  break;
7555796c8dcSSimon Schubert 	case DW_OP_const4u:
7565796c8dcSSimon Schubert 	  result = extract_unsigned_integer (op_ptr, 4, byte_order);
757*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7585796c8dcSSimon Schubert 	  op_ptr += 4;
7595796c8dcSSimon Schubert 	  break;
7605796c8dcSSimon Schubert 	case DW_OP_const4s:
7615796c8dcSSimon Schubert 	  result = extract_signed_integer (op_ptr, 4, byte_order);
762*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7635796c8dcSSimon Schubert 	  op_ptr += 4;
7645796c8dcSSimon Schubert 	  break;
7655796c8dcSSimon Schubert 	case DW_OP_const8u:
7665796c8dcSSimon Schubert 	  result = extract_unsigned_integer (op_ptr, 8, byte_order);
767*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7685796c8dcSSimon Schubert 	  op_ptr += 8;
7695796c8dcSSimon Schubert 	  break;
7705796c8dcSSimon Schubert 	case DW_OP_const8s:
7715796c8dcSSimon Schubert 	  result = extract_signed_integer (op_ptr, 8, byte_order);
772*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7735796c8dcSSimon Schubert 	  op_ptr += 8;
7745796c8dcSSimon Schubert 	  break;
7755796c8dcSSimon Schubert 	case DW_OP_constu:
7765796c8dcSSimon Schubert 	  op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
7775796c8dcSSimon Schubert 	  result = uoffset;
778*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7795796c8dcSSimon Schubert 	  break;
7805796c8dcSSimon Schubert 	case DW_OP_consts:
7815796c8dcSSimon Schubert 	  op_ptr = read_sleb128 (op_ptr, op_end, &offset);
7825796c8dcSSimon Schubert 	  result = offset;
783*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
7845796c8dcSSimon Schubert 	  break;
7855796c8dcSSimon Schubert 
7865796c8dcSSimon Schubert 	/* The DW_OP_reg operations are required to occur alone in
7875796c8dcSSimon Schubert 	   location expressions.  */
7885796c8dcSSimon Schubert 	case DW_OP_reg0:
7895796c8dcSSimon Schubert 	case DW_OP_reg1:
7905796c8dcSSimon Schubert 	case DW_OP_reg2:
7915796c8dcSSimon Schubert 	case DW_OP_reg3:
7925796c8dcSSimon Schubert 	case DW_OP_reg4:
7935796c8dcSSimon Schubert 	case DW_OP_reg5:
7945796c8dcSSimon Schubert 	case DW_OP_reg6:
7955796c8dcSSimon Schubert 	case DW_OP_reg7:
7965796c8dcSSimon Schubert 	case DW_OP_reg8:
7975796c8dcSSimon Schubert 	case DW_OP_reg9:
7985796c8dcSSimon Schubert 	case DW_OP_reg10:
7995796c8dcSSimon Schubert 	case DW_OP_reg11:
8005796c8dcSSimon Schubert 	case DW_OP_reg12:
8015796c8dcSSimon Schubert 	case DW_OP_reg13:
8025796c8dcSSimon Schubert 	case DW_OP_reg14:
8035796c8dcSSimon Schubert 	case DW_OP_reg15:
8045796c8dcSSimon Schubert 	case DW_OP_reg16:
8055796c8dcSSimon Schubert 	case DW_OP_reg17:
8065796c8dcSSimon Schubert 	case DW_OP_reg18:
8075796c8dcSSimon Schubert 	case DW_OP_reg19:
8085796c8dcSSimon Schubert 	case DW_OP_reg20:
8095796c8dcSSimon Schubert 	case DW_OP_reg21:
8105796c8dcSSimon Schubert 	case DW_OP_reg22:
8115796c8dcSSimon Schubert 	case DW_OP_reg23:
8125796c8dcSSimon Schubert 	case DW_OP_reg24:
8135796c8dcSSimon Schubert 	case DW_OP_reg25:
8145796c8dcSSimon Schubert 	case DW_OP_reg26:
8155796c8dcSSimon Schubert 	case DW_OP_reg27:
8165796c8dcSSimon Schubert 	case DW_OP_reg28:
8175796c8dcSSimon Schubert 	case DW_OP_reg29:
8185796c8dcSSimon Schubert 	case DW_OP_reg30:
8195796c8dcSSimon Schubert 	case DW_OP_reg31:
8205796c8dcSSimon Schubert 	  if (op_ptr != op_end
8215796c8dcSSimon Schubert 	      && *op_ptr != DW_OP_piece
822cf7f2e2dSJohn Marino 	      && *op_ptr != DW_OP_bit_piece
8235796c8dcSSimon Schubert 	      && *op_ptr != DW_OP_GNU_uninit)
8245796c8dcSSimon Schubert 	    error (_("DWARF-2 expression error: DW_OP_reg operations must be "
825*a45ae5f8SJohn Marino 		     "used either alone or in conjunction with DW_OP_piece "
826cf7f2e2dSJohn Marino 		     "or DW_OP_bit_piece."));
8275796c8dcSSimon Schubert 
8285796c8dcSSimon Schubert 	  result = op - DW_OP_reg0;
829*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
8305796c8dcSSimon Schubert 	  ctx->location = DWARF_VALUE_REGISTER;
8315796c8dcSSimon Schubert 	  break;
8325796c8dcSSimon Schubert 
8335796c8dcSSimon Schubert 	case DW_OP_regx:
8345796c8dcSSimon Schubert 	  op_ptr = read_uleb128 (op_ptr, op_end, &reg);
835cf7f2e2dSJohn Marino 	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
8365796c8dcSSimon Schubert 
8375796c8dcSSimon Schubert 	  result = reg;
838*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
8395796c8dcSSimon Schubert 	  ctx->location = DWARF_VALUE_REGISTER;
8405796c8dcSSimon Schubert 	  break;
8415796c8dcSSimon Schubert 
8425796c8dcSSimon Schubert 	case DW_OP_implicit_value:
8435796c8dcSSimon Schubert 	  {
8445796c8dcSSimon Schubert 	    ULONGEST len;
845cf7f2e2dSJohn Marino 
8465796c8dcSSimon Schubert 	    op_ptr = read_uleb128 (op_ptr, op_end, &len);
8475796c8dcSSimon Schubert 	    if (op_ptr + len > op_end)
8485796c8dcSSimon Schubert 	      error (_("DW_OP_implicit_value: too few bytes available."));
8495796c8dcSSimon Schubert 	    ctx->len = len;
8505796c8dcSSimon Schubert 	    ctx->data = op_ptr;
8515796c8dcSSimon Schubert 	    ctx->location = DWARF_VALUE_LITERAL;
8525796c8dcSSimon Schubert 	    op_ptr += len;
853cf7f2e2dSJohn Marino 	    dwarf_expr_require_composition (op_ptr, op_end,
854cf7f2e2dSJohn Marino 					    "DW_OP_implicit_value");
8555796c8dcSSimon Schubert 	  }
8565796c8dcSSimon Schubert 	  goto no_push;
8575796c8dcSSimon Schubert 
8585796c8dcSSimon Schubert 	case DW_OP_stack_value:
8595796c8dcSSimon Schubert 	  ctx->location = DWARF_VALUE_STACK;
860cf7f2e2dSJohn Marino 	  dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
8615796c8dcSSimon Schubert 	  goto no_push;
8625796c8dcSSimon Schubert 
863c50c785cSJohn Marino 	case DW_OP_GNU_implicit_pointer:
864c50c785cSJohn Marino 	  {
865c50c785cSJohn Marino 	    ULONGEST die;
866c50c785cSJohn Marino 	    LONGEST len;
867c50c785cSJohn Marino 
868*a45ae5f8SJohn Marino 	    if (ctx->ref_addr_size == -1)
869*a45ae5f8SJohn Marino 	      error (_("DWARF-2 expression error: DW_OP_GNU_implicit_pointer "
870*a45ae5f8SJohn Marino 		       "is not allowed in frame context"));
871*a45ae5f8SJohn Marino 
872c50c785cSJohn Marino 	    /* The referred-to DIE.  */
873*a45ae5f8SJohn Marino 	    ctx->len = extract_unsigned_integer (op_ptr, ctx->ref_addr_size,
874c50c785cSJohn Marino 						 byte_order);
875*a45ae5f8SJohn Marino 	    op_ptr += ctx->ref_addr_size;
876c50c785cSJohn Marino 
877c50c785cSJohn Marino 	    /* The byte offset into the data.  */
878c50c785cSJohn Marino 	    op_ptr = read_sleb128 (op_ptr, op_end, &len);
879c50c785cSJohn Marino 	    result = (ULONGEST) len;
880*a45ae5f8SJohn Marino 	    result_val = value_from_ulongest (address_type, result);
881c50c785cSJohn Marino 
882c50c785cSJohn Marino 	    ctx->location = DWARF_VALUE_IMPLICIT_POINTER;
883c50c785cSJohn Marino 	    dwarf_expr_require_composition (op_ptr, op_end,
884c50c785cSJohn Marino 					    "DW_OP_GNU_implicit_pointer");
885c50c785cSJohn Marino 	  }
886c50c785cSJohn Marino 	  break;
887c50c785cSJohn Marino 
8885796c8dcSSimon Schubert 	case DW_OP_breg0:
8895796c8dcSSimon Schubert 	case DW_OP_breg1:
8905796c8dcSSimon Schubert 	case DW_OP_breg2:
8915796c8dcSSimon Schubert 	case DW_OP_breg3:
8925796c8dcSSimon Schubert 	case DW_OP_breg4:
8935796c8dcSSimon Schubert 	case DW_OP_breg5:
8945796c8dcSSimon Schubert 	case DW_OP_breg6:
8955796c8dcSSimon Schubert 	case DW_OP_breg7:
8965796c8dcSSimon Schubert 	case DW_OP_breg8:
8975796c8dcSSimon Schubert 	case DW_OP_breg9:
8985796c8dcSSimon Schubert 	case DW_OP_breg10:
8995796c8dcSSimon Schubert 	case DW_OP_breg11:
9005796c8dcSSimon Schubert 	case DW_OP_breg12:
9015796c8dcSSimon Schubert 	case DW_OP_breg13:
9025796c8dcSSimon Schubert 	case DW_OP_breg14:
9035796c8dcSSimon Schubert 	case DW_OP_breg15:
9045796c8dcSSimon Schubert 	case DW_OP_breg16:
9055796c8dcSSimon Schubert 	case DW_OP_breg17:
9065796c8dcSSimon Schubert 	case DW_OP_breg18:
9075796c8dcSSimon Schubert 	case DW_OP_breg19:
9085796c8dcSSimon Schubert 	case DW_OP_breg20:
9095796c8dcSSimon Schubert 	case DW_OP_breg21:
9105796c8dcSSimon Schubert 	case DW_OP_breg22:
9115796c8dcSSimon Schubert 	case DW_OP_breg23:
9125796c8dcSSimon Schubert 	case DW_OP_breg24:
9135796c8dcSSimon Schubert 	case DW_OP_breg25:
9145796c8dcSSimon Schubert 	case DW_OP_breg26:
9155796c8dcSSimon Schubert 	case DW_OP_breg27:
9165796c8dcSSimon Schubert 	case DW_OP_breg28:
9175796c8dcSSimon Schubert 	case DW_OP_breg29:
9185796c8dcSSimon Schubert 	case DW_OP_breg30:
9195796c8dcSSimon Schubert 	case DW_OP_breg31:
9205796c8dcSSimon Schubert 	  {
9215796c8dcSSimon Schubert 	    op_ptr = read_sleb128 (op_ptr, op_end, &offset);
922*a45ae5f8SJohn Marino 	    result = (ctx->funcs->read_reg) (ctx->baton, op - DW_OP_breg0);
9235796c8dcSSimon Schubert 	    result += offset;
924*a45ae5f8SJohn Marino 	    result_val = value_from_ulongest (address_type, result);
9255796c8dcSSimon Schubert 	  }
9265796c8dcSSimon Schubert 	  break;
9275796c8dcSSimon Schubert 	case DW_OP_bregx:
9285796c8dcSSimon Schubert 	  {
9295796c8dcSSimon Schubert 	    op_ptr = read_uleb128 (op_ptr, op_end, &reg);
9305796c8dcSSimon Schubert 	    op_ptr = read_sleb128 (op_ptr, op_end, &offset);
931*a45ae5f8SJohn Marino 	    result = (ctx->funcs->read_reg) (ctx->baton, reg);
9325796c8dcSSimon Schubert 	    result += offset;
933*a45ae5f8SJohn Marino 	    result_val = value_from_ulongest (address_type, result);
9345796c8dcSSimon Schubert 	  }
9355796c8dcSSimon Schubert 	  break;
9365796c8dcSSimon Schubert 	case DW_OP_fbreg:
9375796c8dcSSimon Schubert 	  {
938cf7f2e2dSJohn Marino 	    const gdb_byte *datastart;
9395796c8dcSSimon Schubert 	    size_t datalen;
9405796c8dcSSimon Schubert 	    unsigned int before_stack_len;
9415796c8dcSSimon Schubert 
9425796c8dcSSimon Schubert 	    op_ptr = read_sleb128 (op_ptr, op_end, &offset);
9435796c8dcSSimon Schubert 	    /* Rather than create a whole new context, we simply
9445796c8dcSSimon Schubert 	       record the stack length before execution, then reset it
9455796c8dcSSimon Schubert 	       afterwards, effectively erasing whatever the recursive
9465796c8dcSSimon Schubert 	       call put there.  */
9475796c8dcSSimon Schubert 	    before_stack_len = ctx->stack_len;
9485796c8dcSSimon Schubert 	    /* FIXME: cagney/2003-03-26: This code should be using
9495796c8dcSSimon Schubert                get_frame_base_address(), and then implement a dwarf2
9505796c8dcSSimon Schubert                specific this_base method.  */
951*a45ae5f8SJohn Marino 	    (ctx->funcs->get_frame_base) (ctx->baton, &datastart, &datalen);
9525796c8dcSSimon Schubert 	    dwarf_expr_eval (ctx, datastart, datalen);
953cf7f2e2dSJohn Marino 	    if (ctx->location == DWARF_VALUE_MEMORY)
954cf7f2e2dSJohn Marino 	      result = dwarf_expr_fetch_address (ctx, 0);
955cf7f2e2dSJohn Marino 	    else if (ctx->location == DWARF_VALUE_REGISTER)
956*a45ae5f8SJohn Marino 	      result = (ctx->funcs->read_reg) (ctx->baton,
957*a45ae5f8SJohn Marino 				     value_as_long (dwarf_expr_fetch (ctx, 0)));
958cf7f2e2dSJohn Marino 	    else
959c50c785cSJohn Marino 	      error (_("Not implemented: computing frame "
960c50c785cSJohn Marino 		       "base using explicit value operator"));
9615796c8dcSSimon Schubert 	    result = result + offset;
962*a45ae5f8SJohn Marino 	    result_val = value_from_ulongest (address_type, result);
9635796c8dcSSimon Schubert 	    in_stack_memory = 1;
9645796c8dcSSimon Schubert 	    ctx->stack_len = before_stack_len;
9655796c8dcSSimon Schubert 	    ctx->location = DWARF_VALUE_MEMORY;
9665796c8dcSSimon Schubert 	  }
9675796c8dcSSimon Schubert 	  break;
9685796c8dcSSimon Schubert 
9695796c8dcSSimon Schubert 	case DW_OP_dup:
970*a45ae5f8SJohn Marino 	  result_val = dwarf_expr_fetch (ctx, 0);
9715796c8dcSSimon Schubert 	  in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
9725796c8dcSSimon Schubert 	  break;
9735796c8dcSSimon Schubert 
9745796c8dcSSimon Schubert 	case DW_OP_drop:
9755796c8dcSSimon Schubert 	  dwarf_expr_pop (ctx);
9765796c8dcSSimon Schubert 	  goto no_push;
9775796c8dcSSimon Schubert 
9785796c8dcSSimon Schubert 	case DW_OP_pick:
9795796c8dcSSimon Schubert 	  offset = *op_ptr++;
980*a45ae5f8SJohn Marino 	  result_val = dwarf_expr_fetch (ctx, offset);
9815796c8dcSSimon Schubert 	  in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, offset);
9825796c8dcSSimon Schubert 	  break;
9835796c8dcSSimon Schubert 
9845796c8dcSSimon Schubert 	case DW_OP_swap:
9855796c8dcSSimon Schubert 	  {
9865796c8dcSSimon Schubert 	    struct dwarf_stack_value t1, t2;
9875796c8dcSSimon Schubert 
9885796c8dcSSimon Schubert 	    if (ctx->stack_len < 2)
989c50c785cSJohn Marino 	       error (_("Not enough elements for "
990c50c785cSJohn Marino 			"DW_OP_swap.  Need 2, have %d."),
9915796c8dcSSimon Schubert 		      ctx->stack_len);
9925796c8dcSSimon Schubert 	    t1 = ctx->stack[ctx->stack_len - 1];
9935796c8dcSSimon Schubert 	    t2 = ctx->stack[ctx->stack_len - 2];
9945796c8dcSSimon Schubert 	    ctx->stack[ctx->stack_len - 1] = t2;
9955796c8dcSSimon Schubert 	    ctx->stack[ctx->stack_len - 2] = t1;
9965796c8dcSSimon Schubert 	    goto no_push;
9975796c8dcSSimon Schubert 	  }
9985796c8dcSSimon Schubert 
9995796c8dcSSimon Schubert 	case DW_OP_over:
1000*a45ae5f8SJohn Marino 	  result_val = dwarf_expr_fetch (ctx, 1);
10015796c8dcSSimon Schubert 	  in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 1);
10025796c8dcSSimon Schubert 	  break;
10035796c8dcSSimon Schubert 
10045796c8dcSSimon Schubert 	case DW_OP_rot:
10055796c8dcSSimon Schubert 	  {
10065796c8dcSSimon Schubert 	    struct dwarf_stack_value t1, t2, t3;
10075796c8dcSSimon Schubert 
10085796c8dcSSimon Schubert 	    if (ctx->stack_len < 3)
1009c50c785cSJohn Marino 	       error (_("Not enough elements for "
1010c50c785cSJohn Marino 			"DW_OP_rot.  Need 3, have %d."),
10115796c8dcSSimon Schubert 		      ctx->stack_len);
10125796c8dcSSimon Schubert 	    t1 = ctx->stack[ctx->stack_len - 1];
10135796c8dcSSimon Schubert 	    t2 = ctx->stack[ctx->stack_len - 2];
10145796c8dcSSimon Schubert 	    t3 = ctx->stack[ctx->stack_len - 3];
10155796c8dcSSimon Schubert 	    ctx->stack[ctx->stack_len - 1] = t2;
10165796c8dcSSimon Schubert 	    ctx->stack[ctx->stack_len - 2] = t3;
10175796c8dcSSimon Schubert 	    ctx->stack[ctx->stack_len - 3] = t1;
10185796c8dcSSimon Schubert 	    goto no_push;
10195796c8dcSSimon Schubert 	  }
10205796c8dcSSimon Schubert 
10215796c8dcSSimon Schubert 	case DW_OP_deref:
10225796c8dcSSimon Schubert 	case DW_OP_deref_size:
1023*a45ae5f8SJohn Marino 	case DW_OP_GNU_deref_type:
1024cf7f2e2dSJohn Marino 	  {
1025cf7f2e2dSJohn Marino 	    int addr_size = (op == DW_OP_deref ? ctx->addr_size : *op_ptr++);
1026cf7f2e2dSJohn Marino 	    gdb_byte *buf = alloca (addr_size);
1027cf7f2e2dSJohn Marino 	    CORE_ADDR addr = dwarf_expr_fetch_address (ctx, 0);
1028*a45ae5f8SJohn Marino 	    struct type *type;
1029*a45ae5f8SJohn Marino 
1030cf7f2e2dSJohn Marino 	    dwarf_expr_pop (ctx);
1031cf7f2e2dSJohn Marino 
1032*a45ae5f8SJohn Marino 	    if (op == DW_OP_GNU_deref_type)
1033*a45ae5f8SJohn Marino 	      {
1034*a45ae5f8SJohn Marino 		ULONGEST type_die;
1035*a45ae5f8SJohn Marino 
1036*a45ae5f8SJohn Marino 		op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1037*a45ae5f8SJohn Marino 		type = dwarf_get_base_type (ctx, type_die, 0);
1038*a45ae5f8SJohn Marino 	      }
1039*a45ae5f8SJohn Marino 	    else
1040*a45ae5f8SJohn Marino 	      type = address_type;
1041*a45ae5f8SJohn Marino 
1042*a45ae5f8SJohn Marino 	    (ctx->funcs->read_mem) (ctx->baton, buf, addr, addr_size);
1043*a45ae5f8SJohn Marino 
1044*a45ae5f8SJohn Marino 	    /* If the size of the object read from memory is different
1045*a45ae5f8SJohn Marino 	       from the type length, we need to zero-extend it.  */
1046*a45ae5f8SJohn Marino 	    if (TYPE_LENGTH (type) != addr_size)
1047*a45ae5f8SJohn Marino 	      {
1048*a45ae5f8SJohn Marino 		ULONGEST result =
1049*a45ae5f8SJohn Marino 		  extract_unsigned_integer (buf, addr_size, byte_order);
1050*a45ae5f8SJohn Marino 
1051*a45ae5f8SJohn Marino 		buf = alloca (TYPE_LENGTH (type));
1052*a45ae5f8SJohn Marino 		store_unsigned_integer (buf, TYPE_LENGTH (type),
1053*a45ae5f8SJohn Marino 					byte_order, result);
1054*a45ae5f8SJohn Marino 	      }
1055*a45ae5f8SJohn Marino 
1056*a45ae5f8SJohn Marino 	    result_val = value_from_contents_and_address (type, buf, addr);
1057cf7f2e2dSJohn Marino 	    break;
1058cf7f2e2dSJohn Marino 	  }
1059cf7f2e2dSJohn Marino 
10605796c8dcSSimon Schubert 	case DW_OP_abs:
10615796c8dcSSimon Schubert 	case DW_OP_neg:
10625796c8dcSSimon Schubert 	case DW_OP_not:
10635796c8dcSSimon Schubert 	case DW_OP_plus_uconst:
1064*a45ae5f8SJohn Marino 	  {
10655796c8dcSSimon Schubert 	    /* Unary operations.  */
1066*a45ae5f8SJohn Marino 	    result_val = dwarf_expr_fetch (ctx, 0);
10675796c8dcSSimon Schubert 	    dwarf_expr_pop (ctx);
10685796c8dcSSimon Schubert 
10695796c8dcSSimon Schubert 	    switch (op)
10705796c8dcSSimon Schubert 	      {
10715796c8dcSSimon Schubert 	      case DW_OP_abs:
1072*a45ae5f8SJohn Marino 		if (value_less (result_val,
1073*a45ae5f8SJohn Marino 				value_zero (value_type (result_val), not_lval)))
1074*a45ae5f8SJohn Marino 		  result_val = value_neg (result_val);
10755796c8dcSSimon Schubert 		break;
10765796c8dcSSimon Schubert 	      case DW_OP_neg:
1077*a45ae5f8SJohn Marino 		result_val = value_neg (result_val);
10785796c8dcSSimon Schubert 		break;
10795796c8dcSSimon Schubert 	      case DW_OP_not:
1080*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (result_val));
1081*a45ae5f8SJohn Marino 		result_val = value_complement (result_val);
10825796c8dcSSimon Schubert 		break;
10835796c8dcSSimon Schubert 	      case DW_OP_plus_uconst:
1084*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (result_val));
1085*a45ae5f8SJohn Marino 		result = value_as_long (result_val);
10865796c8dcSSimon Schubert 		op_ptr = read_uleb128 (op_ptr, op_end, &reg);
10875796c8dcSSimon Schubert 		result += reg;
1088*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
10895796c8dcSSimon Schubert 		break;
10905796c8dcSSimon Schubert 	      }
1091*a45ae5f8SJohn Marino 	  }
10925796c8dcSSimon Schubert 	  break;
10935796c8dcSSimon Schubert 
10945796c8dcSSimon Schubert 	case DW_OP_and:
10955796c8dcSSimon Schubert 	case DW_OP_div:
10965796c8dcSSimon Schubert 	case DW_OP_minus:
10975796c8dcSSimon Schubert 	case DW_OP_mod:
10985796c8dcSSimon Schubert 	case DW_OP_mul:
10995796c8dcSSimon Schubert 	case DW_OP_or:
11005796c8dcSSimon Schubert 	case DW_OP_plus:
11015796c8dcSSimon Schubert 	case DW_OP_shl:
11025796c8dcSSimon Schubert 	case DW_OP_shr:
11035796c8dcSSimon Schubert 	case DW_OP_shra:
11045796c8dcSSimon Schubert 	case DW_OP_xor:
11055796c8dcSSimon Schubert 	case DW_OP_le:
11065796c8dcSSimon Schubert 	case DW_OP_ge:
11075796c8dcSSimon Schubert 	case DW_OP_eq:
11085796c8dcSSimon Schubert 	case DW_OP_lt:
11095796c8dcSSimon Schubert 	case DW_OP_gt:
11105796c8dcSSimon Schubert 	case DW_OP_ne:
11115796c8dcSSimon Schubert 	  {
1112cf7f2e2dSJohn Marino 	    /* Binary operations.  */
1113*a45ae5f8SJohn Marino 	    struct value *first, *second;
11145796c8dcSSimon Schubert 
11155796c8dcSSimon Schubert 	    second = dwarf_expr_fetch (ctx, 0);
11165796c8dcSSimon Schubert 	    dwarf_expr_pop (ctx);
11175796c8dcSSimon Schubert 
11185796c8dcSSimon Schubert 	    first = dwarf_expr_fetch (ctx, 0);
11195796c8dcSSimon Schubert 	    dwarf_expr_pop (ctx);
11205796c8dcSSimon Schubert 
1121*a45ae5f8SJohn Marino 	    if (! base_types_equal_p (value_type (first), value_type (second)))
1122*a45ae5f8SJohn Marino 	      error (_("Incompatible types on DWARF stack"));
1123*a45ae5f8SJohn Marino 
11245796c8dcSSimon Schubert 	    switch (op)
11255796c8dcSSimon Schubert 	      {
11265796c8dcSSimon Schubert 	      case DW_OP_and:
1127*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1128*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1129*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_BITWISE_AND);
11305796c8dcSSimon Schubert 		break;
11315796c8dcSSimon Schubert 	      case DW_OP_div:
1132*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_DIV);
11335796c8dcSSimon Schubert                 break;
11345796c8dcSSimon Schubert 	      case DW_OP_minus:
1135*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_SUB);
11365796c8dcSSimon Schubert 		break;
11375796c8dcSSimon Schubert 	      case DW_OP_mod:
1138*a45ae5f8SJohn Marino 		{
1139*a45ae5f8SJohn Marino 		  int cast_back = 0;
1140*a45ae5f8SJohn Marino 		  struct type *orig_type = value_type (first);
1141*a45ae5f8SJohn Marino 
1142*a45ae5f8SJohn Marino 		  /* We have to special-case "old-style" untyped values
1143*a45ae5f8SJohn Marino 		     -- these must have mod computed using unsigned
1144*a45ae5f8SJohn Marino 		     math.  */
1145*a45ae5f8SJohn Marino 		  if (orig_type == address_type)
1146*a45ae5f8SJohn Marino 		    {
1147*a45ae5f8SJohn Marino 		      struct type *utype
1148*a45ae5f8SJohn Marino 			= get_unsigned_type (ctx->gdbarch, orig_type);
1149*a45ae5f8SJohn Marino 
1150*a45ae5f8SJohn Marino 		      cast_back = 1;
1151*a45ae5f8SJohn Marino 		      first = value_cast (utype, first);
1152*a45ae5f8SJohn Marino 		      second = value_cast (utype, second);
1153*a45ae5f8SJohn Marino 		    }
1154*a45ae5f8SJohn Marino 		  /* Note that value_binop doesn't handle float or
1155*a45ae5f8SJohn Marino 		     decimal float here.  This seems unimportant.  */
1156*a45ae5f8SJohn Marino 		  result_val = value_binop (first, second, BINOP_MOD);
1157*a45ae5f8SJohn Marino 		  if (cast_back)
1158*a45ae5f8SJohn Marino 		    result_val = value_cast (orig_type, result_val);
1159*a45ae5f8SJohn Marino 		}
11605796c8dcSSimon Schubert 		break;
11615796c8dcSSimon Schubert 	      case DW_OP_mul:
1162*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_MUL);
11635796c8dcSSimon Schubert 		break;
11645796c8dcSSimon Schubert 	      case DW_OP_or:
1165*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1166*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1167*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_BITWISE_IOR);
11685796c8dcSSimon Schubert 		break;
11695796c8dcSSimon Schubert 	      case DW_OP_plus:
1170*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_ADD);
11715796c8dcSSimon Schubert 		break;
11725796c8dcSSimon Schubert 	      case DW_OP_shl:
1173*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1174*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1175*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_LSH);
11765796c8dcSSimon Schubert 		break;
11775796c8dcSSimon Schubert 	      case DW_OP_shr:
1178*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1179*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1180*a45ae5f8SJohn Marino 		if (!TYPE_UNSIGNED (value_type (first)))
1181*a45ae5f8SJohn Marino 		  {
1182*a45ae5f8SJohn Marino 		    struct type *utype
1183*a45ae5f8SJohn Marino 		      = get_unsigned_type (ctx->gdbarch, value_type (first));
1184*a45ae5f8SJohn Marino 
1185*a45ae5f8SJohn Marino 		    first = value_cast (utype, first);
1186*a45ae5f8SJohn Marino 		  }
1187*a45ae5f8SJohn Marino 
1188*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_RSH);
1189*a45ae5f8SJohn Marino 		/* Make sure we wind up with the same type we started
1190*a45ae5f8SJohn Marino 		   with.  */
1191*a45ae5f8SJohn Marino 		if (value_type (result_val) != value_type (second))
1192*a45ae5f8SJohn Marino 		  result_val = value_cast (value_type (second), result_val);
11935796c8dcSSimon Schubert                 break;
11945796c8dcSSimon Schubert 	      case DW_OP_shra:
1195*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1196*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1197*a45ae5f8SJohn Marino 		if (TYPE_UNSIGNED (value_type (first)))
1198*a45ae5f8SJohn Marino 		  {
1199*a45ae5f8SJohn Marino 		    struct type *stype
1200*a45ae5f8SJohn Marino 		      = get_signed_type (ctx->gdbarch, value_type (first));
1201*a45ae5f8SJohn Marino 
1202*a45ae5f8SJohn Marino 		    first = value_cast (stype, first);
1203*a45ae5f8SJohn Marino 		  }
1204*a45ae5f8SJohn Marino 
1205*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_RSH);
1206*a45ae5f8SJohn Marino 		/* Make sure we wind up with the same type we started
1207*a45ae5f8SJohn Marino 		   with.  */
1208*a45ae5f8SJohn Marino 		if (value_type (result_val) != value_type (second))
1209*a45ae5f8SJohn Marino 		  result_val = value_cast (value_type (second), result_val);
12105796c8dcSSimon Schubert 		break;
12115796c8dcSSimon Schubert 	      case DW_OP_xor:
1212*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (first));
1213*a45ae5f8SJohn Marino 		dwarf_require_integral (value_type (second));
1214*a45ae5f8SJohn Marino 		result_val = value_binop (first, second, BINOP_BITWISE_XOR);
12155796c8dcSSimon Schubert 		break;
12165796c8dcSSimon Schubert 	      case DW_OP_le:
1217*a45ae5f8SJohn Marino 		/* A <= B is !(B < A).  */
1218*a45ae5f8SJohn Marino 		result = ! value_less (second, first);
1219*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12205796c8dcSSimon Schubert 		break;
12215796c8dcSSimon Schubert 	      case DW_OP_ge:
1222*a45ae5f8SJohn Marino 		/* A >= B is !(A < B).  */
1223*a45ae5f8SJohn Marino 		result = ! value_less (first, second);
1224*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12255796c8dcSSimon Schubert 		break;
12265796c8dcSSimon Schubert 	      case DW_OP_eq:
1227*a45ae5f8SJohn Marino 		result = value_equal (first, second);
1228*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12295796c8dcSSimon Schubert 		break;
12305796c8dcSSimon Schubert 	      case DW_OP_lt:
1231*a45ae5f8SJohn Marino 		result = value_less (first, second);
1232*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12335796c8dcSSimon Schubert 		break;
12345796c8dcSSimon Schubert 	      case DW_OP_gt:
1235*a45ae5f8SJohn Marino 		/* A > B is B < A.  */
1236*a45ae5f8SJohn Marino 		result = value_less (second, first);
1237*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12385796c8dcSSimon Schubert 		break;
12395796c8dcSSimon Schubert 	      case DW_OP_ne:
1240*a45ae5f8SJohn Marino 		result = ! value_equal (first, second);
1241*a45ae5f8SJohn Marino 		result_val = value_from_ulongest (address_type, result);
12425796c8dcSSimon Schubert 		break;
12435796c8dcSSimon Schubert 	      default:
12445796c8dcSSimon Schubert 		internal_error (__FILE__, __LINE__,
12455796c8dcSSimon Schubert 				_("Can't be reached."));
12465796c8dcSSimon Schubert 	      }
12475796c8dcSSimon Schubert 	  }
12485796c8dcSSimon Schubert 	  break;
12495796c8dcSSimon Schubert 
12505796c8dcSSimon Schubert 	case DW_OP_call_frame_cfa:
1251*a45ae5f8SJohn Marino 	  result = (ctx->funcs->get_frame_cfa) (ctx->baton);
1252*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
12535796c8dcSSimon Schubert 	  in_stack_memory = 1;
12545796c8dcSSimon Schubert 	  break;
12555796c8dcSSimon Schubert 
12565796c8dcSSimon Schubert 	case DW_OP_GNU_push_tls_address:
12575796c8dcSSimon Schubert 	  /* Variable is at a constant offset in the thread-local
12585796c8dcSSimon Schubert 	  storage block into the objfile for the current thread and
12595796c8dcSSimon Schubert 	  the dynamic linker module containing this expression.  Here
12605796c8dcSSimon Schubert 	  we return returns the offset from that base.  The top of the
12615796c8dcSSimon Schubert 	  stack has the offset from the beginning of the thread
12625796c8dcSSimon Schubert 	  control block at which the variable is located.  Nothing
12635796c8dcSSimon Schubert 	  should follow this operator, so the top of stack would be
12645796c8dcSSimon Schubert 	  returned.  */
1265*a45ae5f8SJohn Marino 	  result = value_as_long (dwarf_expr_fetch (ctx, 0));
12665796c8dcSSimon Schubert 	  dwarf_expr_pop (ctx);
1267*a45ae5f8SJohn Marino 	  result = (ctx->funcs->get_tls_address) (ctx->baton, result);
1268*a45ae5f8SJohn Marino 	  result_val = value_from_ulongest (address_type, result);
12695796c8dcSSimon Schubert 	  break;
12705796c8dcSSimon Schubert 
12715796c8dcSSimon Schubert 	case DW_OP_skip:
12725796c8dcSSimon Schubert 	  offset = extract_signed_integer (op_ptr, 2, byte_order);
12735796c8dcSSimon Schubert 	  op_ptr += 2;
12745796c8dcSSimon Schubert 	  op_ptr += offset;
12755796c8dcSSimon Schubert 	  goto no_push;
12765796c8dcSSimon Schubert 
12775796c8dcSSimon Schubert 	case DW_OP_bra:
1278*a45ae5f8SJohn Marino 	  {
1279*a45ae5f8SJohn Marino 	    struct value *val;
1280*a45ae5f8SJohn Marino 
12815796c8dcSSimon Schubert 	    offset = extract_signed_integer (op_ptr, 2, byte_order);
12825796c8dcSSimon Schubert 	    op_ptr += 2;
1283*a45ae5f8SJohn Marino 	    val = dwarf_expr_fetch (ctx, 0);
1284*a45ae5f8SJohn Marino 	    dwarf_require_integral (value_type (val));
1285*a45ae5f8SJohn Marino 	    if (value_as_long (val) != 0)
12865796c8dcSSimon Schubert 	      op_ptr += offset;
12875796c8dcSSimon Schubert 	    dwarf_expr_pop (ctx);
1288*a45ae5f8SJohn Marino 	  }
12895796c8dcSSimon Schubert 	  goto no_push;
12905796c8dcSSimon Schubert 
12915796c8dcSSimon Schubert 	case DW_OP_nop:
12925796c8dcSSimon Schubert 	  goto no_push;
12935796c8dcSSimon Schubert 
12945796c8dcSSimon Schubert         case DW_OP_piece:
12955796c8dcSSimon Schubert           {
12965796c8dcSSimon Schubert             ULONGEST size;
12975796c8dcSSimon Schubert 
12985796c8dcSSimon Schubert             /* Record the piece.  */
12995796c8dcSSimon Schubert             op_ptr = read_uleb128 (op_ptr, op_end, &size);
1300cf7f2e2dSJohn Marino 	    add_piece (ctx, 8 * size, 0);
13015796c8dcSSimon Schubert 
13025796c8dcSSimon Schubert             /* Pop off the address/regnum, and reset the location
13035796c8dcSSimon Schubert 	       type.  */
1304cf7f2e2dSJohn Marino 	    if (ctx->location != DWARF_VALUE_LITERAL
1305cf7f2e2dSJohn Marino 		&& ctx->location != DWARF_VALUE_OPTIMIZED_OUT)
1306cf7f2e2dSJohn Marino 	      dwarf_expr_pop (ctx);
1307cf7f2e2dSJohn Marino             ctx->location = DWARF_VALUE_MEMORY;
1308cf7f2e2dSJohn Marino           }
1309cf7f2e2dSJohn Marino           goto no_push;
1310cf7f2e2dSJohn Marino 
1311cf7f2e2dSJohn Marino 	case DW_OP_bit_piece:
1312cf7f2e2dSJohn Marino 	  {
1313cf7f2e2dSJohn Marino 	    ULONGEST size, offset;
1314cf7f2e2dSJohn Marino 
1315cf7f2e2dSJohn Marino             /* Record the piece.  */
1316cf7f2e2dSJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &size);
1317cf7f2e2dSJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &offset);
1318cf7f2e2dSJohn Marino 	    add_piece (ctx, size, offset);
1319cf7f2e2dSJohn Marino 
1320cf7f2e2dSJohn Marino             /* Pop off the address/regnum, and reset the location
1321cf7f2e2dSJohn Marino 	       type.  */
1322cf7f2e2dSJohn Marino 	    if (ctx->location != DWARF_VALUE_LITERAL
1323cf7f2e2dSJohn Marino 		&& ctx->location != DWARF_VALUE_OPTIMIZED_OUT)
13245796c8dcSSimon Schubert 	      dwarf_expr_pop (ctx);
13255796c8dcSSimon Schubert             ctx->location = DWARF_VALUE_MEMORY;
13265796c8dcSSimon Schubert 	  }
13275796c8dcSSimon Schubert 	  goto no_push;
13285796c8dcSSimon Schubert 
13295796c8dcSSimon Schubert 	case DW_OP_GNU_uninit:
13305796c8dcSSimon Schubert 	  if (op_ptr != op_end)
13315796c8dcSSimon Schubert 	    error (_("DWARF-2 expression error: DW_OP_GNU_uninit must always "
13325796c8dcSSimon Schubert 		   "be the very last op."));
13335796c8dcSSimon Schubert 
13345796c8dcSSimon Schubert 	  ctx->initialized = 0;
13355796c8dcSSimon Schubert 	  goto no_push;
13365796c8dcSSimon Schubert 
1337cf7f2e2dSJohn Marino 	case DW_OP_call2:
1338cf7f2e2dSJohn Marino 	  result = extract_unsigned_integer (op_ptr, 2, byte_order);
1339cf7f2e2dSJohn Marino 	  op_ptr += 2;
1340*a45ae5f8SJohn Marino 	  ctx->funcs->dwarf_call (ctx, result);
1341cf7f2e2dSJohn Marino 	  goto no_push;
1342cf7f2e2dSJohn Marino 
1343cf7f2e2dSJohn Marino 	case DW_OP_call4:
1344cf7f2e2dSJohn Marino 	  result = extract_unsigned_integer (op_ptr, 4, byte_order);
1345cf7f2e2dSJohn Marino 	  op_ptr += 4;
1346*a45ae5f8SJohn Marino 	  ctx->funcs->dwarf_call (ctx, result);
1347cf7f2e2dSJohn Marino 	  goto no_push;
1348cf7f2e2dSJohn Marino 
1349c50c785cSJohn Marino 	case DW_OP_GNU_entry_value:
1350*a45ae5f8SJohn Marino 	  {
1351*a45ae5f8SJohn Marino 	    ULONGEST len;
1352*a45ae5f8SJohn Marino 	    int dwarf_reg;
1353*a45ae5f8SJohn Marino 	    CORE_ADDR deref_size;
1354*a45ae5f8SJohn Marino 
1355*a45ae5f8SJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &len);
1356*a45ae5f8SJohn Marino 	    if (op_ptr + len > op_end)
1357*a45ae5f8SJohn Marino 	      error (_("DW_OP_GNU_entry_value: too few bytes available."));
1358*a45ae5f8SJohn Marino 
1359*a45ae5f8SJohn Marino 	    dwarf_reg = dwarf_block_to_dwarf_reg (op_ptr, op_ptr + len);
1360*a45ae5f8SJohn Marino 	    if (dwarf_reg != -1)
1361*a45ae5f8SJohn Marino 	      {
1362*a45ae5f8SJohn Marino 		op_ptr += len;
1363*a45ae5f8SJohn Marino 		ctx->funcs->push_dwarf_reg_entry_value (ctx, dwarf_reg,
1364*a45ae5f8SJohn Marino 							0 /* unused */,
1365*a45ae5f8SJohn Marino 							-1 /* deref_size */);
1366*a45ae5f8SJohn Marino 		goto no_push;
1367*a45ae5f8SJohn Marino 	      }
1368*a45ae5f8SJohn Marino 
1369*a45ae5f8SJohn Marino 	    dwarf_reg = dwarf_block_to_dwarf_reg_deref (op_ptr, op_ptr + len,
1370*a45ae5f8SJohn Marino 							&deref_size);
1371*a45ae5f8SJohn Marino 	    if (dwarf_reg != -1)
1372*a45ae5f8SJohn Marino 	      {
1373*a45ae5f8SJohn Marino 		if (deref_size == -1)
1374*a45ae5f8SJohn Marino 		  deref_size = ctx->addr_size;
1375*a45ae5f8SJohn Marino 		op_ptr += len;
1376*a45ae5f8SJohn Marino 		ctx->funcs->push_dwarf_reg_entry_value (ctx, dwarf_reg,
1377*a45ae5f8SJohn Marino 							0 /* unused */,
1378*a45ae5f8SJohn Marino 							deref_size);
1379*a45ae5f8SJohn Marino 		goto no_push;
1380*a45ae5f8SJohn Marino 	      }
1381*a45ae5f8SJohn Marino 
1382*a45ae5f8SJohn Marino 	    error (_("DWARF-2 expression error: DW_OP_GNU_entry_value is "
1383*a45ae5f8SJohn Marino 		     "supported only for single DW_OP_reg* "
1384*a45ae5f8SJohn Marino 		     "or for DW_OP_breg*(0)+DW_OP_deref*"));
1385*a45ae5f8SJohn Marino 	  }
1386*a45ae5f8SJohn Marino 
1387*a45ae5f8SJohn Marino 	case DW_OP_GNU_const_type:
1388*a45ae5f8SJohn Marino 	  {
1389*a45ae5f8SJohn Marino 	    ULONGEST type_die;
1390*a45ae5f8SJohn Marino 	    int n;
1391*a45ae5f8SJohn Marino 	    const gdb_byte *data;
1392*a45ae5f8SJohn Marino 	    struct type *type;
1393*a45ae5f8SJohn Marino 
1394*a45ae5f8SJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1395*a45ae5f8SJohn Marino 	    n = *op_ptr++;
1396*a45ae5f8SJohn Marino 	    data = op_ptr;
1397*a45ae5f8SJohn Marino 	    op_ptr += n;
1398*a45ae5f8SJohn Marino 
1399*a45ae5f8SJohn Marino 	    type = dwarf_get_base_type (ctx, type_die, n);
1400*a45ae5f8SJohn Marino 	    result_val = value_from_contents (type, data);
1401*a45ae5f8SJohn Marino 	  }
1402*a45ae5f8SJohn Marino 	  break;
1403*a45ae5f8SJohn Marino 
1404*a45ae5f8SJohn Marino 	case DW_OP_GNU_regval_type:
1405*a45ae5f8SJohn Marino 	  {
1406*a45ae5f8SJohn Marino 	    ULONGEST type_die;
1407*a45ae5f8SJohn Marino 	    struct type *type;
1408*a45ae5f8SJohn Marino 
1409*a45ae5f8SJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &reg);
1410*a45ae5f8SJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1411*a45ae5f8SJohn Marino 
1412*a45ae5f8SJohn Marino 	    type = dwarf_get_base_type (ctx, type_die, 0);
1413*a45ae5f8SJohn Marino 	    result = (ctx->funcs->read_reg) (ctx->baton, reg);
1414*a45ae5f8SJohn Marino 	    result_val = value_from_ulongest (address_type, result);
1415*a45ae5f8SJohn Marino 	    result_val = value_from_contents (type,
1416*a45ae5f8SJohn Marino 					      value_contents_all (result_val));
1417*a45ae5f8SJohn Marino 	  }
1418*a45ae5f8SJohn Marino 	  break;
1419*a45ae5f8SJohn Marino 
1420*a45ae5f8SJohn Marino 	case DW_OP_GNU_convert:
1421*a45ae5f8SJohn Marino 	case DW_OP_GNU_reinterpret:
1422*a45ae5f8SJohn Marino 	  {
1423*a45ae5f8SJohn Marino 	    ULONGEST type_die;
1424*a45ae5f8SJohn Marino 	    struct type *type;
1425*a45ae5f8SJohn Marino 
1426*a45ae5f8SJohn Marino 	    op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1427*a45ae5f8SJohn Marino 
1428*a45ae5f8SJohn Marino 	    if (type_die == 0)
1429*a45ae5f8SJohn Marino 	      type = address_type;
1430*a45ae5f8SJohn Marino 	    else
1431*a45ae5f8SJohn Marino 	      type = dwarf_get_base_type (ctx, type_die, 0);
1432*a45ae5f8SJohn Marino 
1433*a45ae5f8SJohn Marino 	    result_val = dwarf_expr_fetch (ctx, 0);
1434*a45ae5f8SJohn Marino 	    dwarf_expr_pop (ctx);
1435*a45ae5f8SJohn Marino 
1436*a45ae5f8SJohn Marino 	    if (op == DW_OP_GNU_convert)
1437*a45ae5f8SJohn Marino 	      result_val = value_cast (type, result_val);
1438*a45ae5f8SJohn Marino 	    else if (type == value_type (result_val))
1439*a45ae5f8SJohn Marino 	      {
1440*a45ae5f8SJohn Marino 		/* Nothing.  */
1441*a45ae5f8SJohn Marino 	      }
1442*a45ae5f8SJohn Marino 	    else if (TYPE_LENGTH (type)
1443*a45ae5f8SJohn Marino 		     != TYPE_LENGTH (value_type (result_val)))
1444*a45ae5f8SJohn Marino 	      error (_("DW_OP_GNU_reinterpret has wrong size"));
1445*a45ae5f8SJohn Marino 	    else
1446*a45ae5f8SJohn Marino 	      result_val
1447*a45ae5f8SJohn Marino 		= value_from_contents (type,
1448*a45ae5f8SJohn Marino 				       value_contents_all (result_val));
1449*a45ae5f8SJohn Marino 	  }
1450*a45ae5f8SJohn Marino 	  break;
1451c50c785cSJohn Marino 
14525796c8dcSSimon Schubert 	default:
14535796c8dcSSimon Schubert 	  error (_("Unhandled dwarf expression opcode 0x%x"), op);
14545796c8dcSSimon Schubert 	}
14555796c8dcSSimon Schubert 
14565796c8dcSSimon Schubert       /* Most things push a result value.  */
1457*a45ae5f8SJohn Marino       gdb_assert (result_val != NULL);
1458*a45ae5f8SJohn Marino       dwarf_expr_push (ctx, result_val, in_stack_memory);
1459c50c785cSJohn Marino     no_push:
1460c50c785cSJohn Marino       ;
14615796c8dcSSimon Schubert     }
14625796c8dcSSimon Schubert 
1463c50c785cSJohn Marino   /* To simplify our main caller, if the result is an implicit
1464c50c785cSJohn Marino      pointer, then make a pieced value.  This is ok because we can't
1465c50c785cSJohn Marino      have implicit pointers in contexts where pieces are invalid.  */
1466c50c785cSJohn Marino   if (ctx->location == DWARF_VALUE_IMPLICIT_POINTER)
1467c50c785cSJohn Marino     add_piece (ctx, 8 * ctx->addr_size, 0);
1468c50c785cSJohn Marino 
1469c50c785cSJohn Marino abort_expression:
14705796c8dcSSimon Schubert   ctx->recursion_depth--;
14715796c8dcSSimon Schubert   gdb_assert (ctx->recursion_depth >= 0);
1472*a45ae5f8SJohn Marino }
1473*a45ae5f8SJohn Marino 
1474*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.get_frame_base implementation.  */
1475*a45ae5f8SJohn Marino 
1476*a45ae5f8SJohn Marino void
1477*a45ae5f8SJohn Marino ctx_no_get_frame_base (void *baton, const gdb_byte **start, size_t *length)
1478*a45ae5f8SJohn Marino {
1479*a45ae5f8SJohn Marino   error (_("%s is invalid in this context"), "DW_OP_fbreg");
1480*a45ae5f8SJohn Marino }
1481*a45ae5f8SJohn Marino 
1482*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.get_frame_cfa implementation.  */
1483*a45ae5f8SJohn Marino 
1484*a45ae5f8SJohn Marino CORE_ADDR
1485*a45ae5f8SJohn Marino ctx_no_get_frame_cfa (void *baton)
1486*a45ae5f8SJohn Marino {
1487*a45ae5f8SJohn Marino   error (_("%s is invalid in this context"), "DW_OP_call_frame_cfa");
1488*a45ae5f8SJohn Marino }
1489*a45ae5f8SJohn Marino 
1490*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.get_frame_pc implementation.  */
1491*a45ae5f8SJohn Marino 
1492*a45ae5f8SJohn Marino CORE_ADDR
1493*a45ae5f8SJohn Marino ctx_no_get_frame_pc (void *baton)
1494*a45ae5f8SJohn Marino {
1495*a45ae5f8SJohn Marino   error (_("%s is invalid in this context"), "DW_OP_GNU_implicit_pointer");
1496*a45ae5f8SJohn Marino }
1497*a45ae5f8SJohn Marino 
1498*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.get_tls_address implementation.  */
1499*a45ae5f8SJohn Marino 
1500*a45ae5f8SJohn Marino CORE_ADDR
1501*a45ae5f8SJohn Marino ctx_no_get_tls_address (void *baton, CORE_ADDR offset)
1502*a45ae5f8SJohn Marino {
1503*a45ae5f8SJohn Marino   error (_("%s is invalid in this context"), "DW_OP_GNU_push_tls_address");
1504*a45ae5f8SJohn Marino }
1505*a45ae5f8SJohn Marino 
1506*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.dwarf_call implementation.  */
1507*a45ae5f8SJohn Marino 
1508*a45ae5f8SJohn Marino void
1509*a45ae5f8SJohn Marino ctx_no_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
1510*a45ae5f8SJohn Marino {
1511*a45ae5f8SJohn Marino   error (_("%s is invalid in this context"), "DW_OP_call*");
1512*a45ae5f8SJohn Marino }
1513*a45ae5f8SJohn Marino 
1514*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.get_base_type implementation.  */
1515*a45ae5f8SJohn Marino 
1516*a45ae5f8SJohn Marino struct type *
1517*a45ae5f8SJohn Marino ctx_no_get_base_type (struct dwarf_expr_context *ctx, size_t die)
1518*a45ae5f8SJohn Marino {
1519*a45ae5f8SJohn Marino   error (_("Support for typed DWARF is not supported in this context"));
1520*a45ae5f8SJohn Marino }
1521*a45ae5f8SJohn Marino 
1522*a45ae5f8SJohn Marino /* Stub dwarf_expr_context_funcs.push_dwarf_block_entry_value
1523*a45ae5f8SJohn Marino    implementation.  */
1524*a45ae5f8SJohn Marino 
1525*a45ae5f8SJohn Marino void
1526*a45ae5f8SJohn Marino ctx_no_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
1527*a45ae5f8SJohn Marino 				   int dwarf_reg, CORE_ADDR fb_offset,
1528*a45ae5f8SJohn Marino 				   int deref_size)
1529*a45ae5f8SJohn Marino {
1530*a45ae5f8SJohn Marino   internal_error (__FILE__, __LINE__,
1531*a45ae5f8SJohn Marino 		  _("Support for DW_OP_GNU_entry_value is unimplemented"));
1532*a45ae5f8SJohn Marino }
1533*a45ae5f8SJohn Marino 
1534*a45ae5f8SJohn Marino void
1535*a45ae5f8SJohn Marino _initialize_dwarf2expr (void)
1536*a45ae5f8SJohn Marino {
1537*a45ae5f8SJohn Marino   dwarf_arch_cookie
1538*a45ae5f8SJohn Marino     = gdbarch_data_register_post_init (dwarf_gdbarch_types_init);
15395796c8dcSSimon Schubert }
1540