* ld-insn.c (print_insn_words): For fields, print conditionals.
[deliverable/binutils-gdb.git] / gdb / dwarf2expr.c
CommitLineData
852483bc
MK
1/* DWARF 2 Expression Evaluator.
2
7b6bb8da 3 Copyright (C) 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
9b254dd1 4 Free Software Foundation, Inc.
852483bc 5
4c2df51b
DJ
6 Contributed by Daniel Berlin (dan@dberlin.org)
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
4c2df51b
DJ
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4c2df51b
DJ
22
23#include "defs.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "value.h"
27#include "gdbcore.h"
fa8f86ff 28#include "dwarf2.h"
4c2df51b 29#include "dwarf2expr.h"
1e3a102a 30#include "gdb_assert.h"
4c2df51b
DJ
31
32/* Local prototypes. */
33
34static void execute_stack_op (struct dwarf_expr_context *,
0d45f56e 35 const gdb_byte *, const gdb_byte *);
4c2df51b 36
8a9b8146
TT
37/* Cookie for gdbarch data. */
38
39static struct gdbarch_data *dwarf_arch_cookie;
40
41/* This holds gdbarch-specific types used by the DWARF expression
42 evaluator. See comments in execute_stack_op. */
43
44struct dwarf_gdbarch_types
45{
46 struct type *dw_types[3];
47};
48
49/* Allocate and fill in dwarf_gdbarch_types for an arch. */
50
51static void *
52dwarf_gdbarch_types_init (struct gdbarch *gdbarch)
53{
54 struct dwarf_gdbarch_types *types
55 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf_gdbarch_types);
56
57 /* The types themselves are lazily initialized. */
58
59 return types;
60}
61
62/* Return the type used for DWARF operations where the type is
63 unspecified in the DWARF spec. Only certain sizes are
64 supported. */
65
66static struct type *
67dwarf_expr_address_type (struct dwarf_expr_context *ctx)
68{
69 struct dwarf_gdbarch_types *types = gdbarch_data (ctx->gdbarch,
70 dwarf_arch_cookie);
71 int ndx;
72
73 if (ctx->addr_size == 2)
74 ndx = 0;
75 else if (ctx->addr_size == 4)
76 ndx = 1;
77 else if (ctx->addr_size == 8)
78 ndx = 2;
79 else
80 error (_("Unsupported address size in DWARF expressions: %d bits"),
81 8 * ctx->addr_size);
82
83 if (types->dw_types[ndx] == NULL)
84 types->dw_types[ndx]
85 = arch_integer_type (ctx->gdbarch,
86 8 * ctx->addr_size,
87 0, "<signed DWARF address type>");
88
89 return types->dw_types[ndx];
90}
91
4c2df51b
DJ
92/* Create a new context for the expression evaluator. */
93
94struct dwarf_expr_context *
e4adbba9 95new_dwarf_expr_context (void)
4c2df51b
DJ
96{
97 struct dwarf_expr_context *retval;
9a619af0 98
4c2df51b 99 retval = xcalloc (1, sizeof (struct dwarf_expr_context));
18ec9831
KB
100 retval->stack_len = 0;
101 retval->stack_allocated = 10;
b966cb8a
TT
102 retval->stack = xmalloc (retval->stack_allocated
103 * sizeof (struct dwarf_stack_value));
87808bd6
JB
104 retval->num_pieces = 0;
105 retval->pieces = 0;
1e3a102a 106 retval->max_recursion_depth = 0x100;
4c2df51b
DJ
107 return retval;
108}
109
110/* Release the memory allocated to CTX. */
111
112void
113free_dwarf_expr_context (struct dwarf_expr_context *ctx)
114{
115 xfree (ctx->stack);
87808bd6 116 xfree (ctx->pieces);
4c2df51b
DJ
117 xfree (ctx);
118}
119
4a227398
TT
120/* Helper for make_cleanup_free_dwarf_expr_context. */
121
122static void
123free_dwarf_expr_context_cleanup (void *arg)
124{
125 free_dwarf_expr_context (arg);
126}
127
128/* Return a cleanup that calls free_dwarf_expr_context. */
129
130struct cleanup *
131make_cleanup_free_dwarf_expr_context (struct dwarf_expr_context *ctx)
132{
133 return make_cleanup (free_dwarf_expr_context_cleanup, ctx);
134}
135
4c2df51b
DJ
136/* Expand the memory allocated to CTX's stack to contain at least
137 NEED more elements than are currently used. */
138
139static void
140dwarf_expr_grow_stack (struct dwarf_expr_context *ctx, size_t need)
141{
142 if (ctx->stack_len + need > ctx->stack_allocated)
143 {
18ec9831 144 size_t newlen = ctx->stack_len + need + 10;
9a619af0 145
4c2df51b 146 ctx->stack = xrealloc (ctx->stack,
44353522 147 newlen * sizeof (struct dwarf_stack_value));
18ec9831 148 ctx->stack_allocated = newlen;
4c2df51b
DJ
149 }
150}
151
152/* Push VALUE onto CTX's stack. */
153
8a9b8146
TT
154static void
155dwarf_expr_push (struct dwarf_expr_context *ctx, struct value *value,
44353522 156 int in_stack_memory)
4c2df51b 157{
44353522
DE
158 struct dwarf_stack_value *v;
159
4c2df51b 160 dwarf_expr_grow_stack (ctx, 1);
44353522
DE
161 v = &ctx->stack[ctx->stack_len++];
162 v->value = value;
163 v->in_stack_memory = in_stack_memory;
4c2df51b
DJ
164}
165
8a9b8146 166/* Push VALUE onto CTX's stack. */
4c2df51b
DJ
167
168void
8a9b8146
TT
169dwarf_expr_push_address (struct dwarf_expr_context *ctx, CORE_ADDR value,
170 int in_stack_memory)
171{
172 dwarf_expr_push (ctx,
173 value_from_ulongest (dwarf_expr_address_type (ctx), value),
174 in_stack_memory);
175}
176
177/* Pop the top item off of CTX's stack. */
178
179static void
4c2df51b
DJ
180dwarf_expr_pop (struct dwarf_expr_context *ctx)
181{
182 if (ctx->stack_len <= 0)
8a3fe4f8 183 error (_("dwarf expression stack underflow"));
4c2df51b
DJ
184 ctx->stack_len--;
185}
186
187/* Retrieve the N'th item on CTX's stack. */
188
8a9b8146 189struct value *
4c2df51b
DJ
190dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n)
191{
ef0fdf07 192 if (ctx->stack_len <= n)
3e43a32a
MS
193 error (_("Asked for position %d of stack, "
194 "stack only has %d elements on it."),
4c2df51b 195 n, ctx->stack_len);
44353522 196 return ctx->stack[ctx->stack_len - (1 + n)].value;
8a9b8146
TT
197}
198
199/* Require that TYPE be an integral type; throw an exception if not. */
44353522 200
8a9b8146
TT
201static void
202dwarf_require_integral (struct type *type)
203{
204 if (TYPE_CODE (type) != TYPE_CODE_INT
205 && TYPE_CODE (type) != TYPE_CODE_CHAR
206 && TYPE_CODE (type) != TYPE_CODE_BOOL)
207 error (_("integral type expected in DWARF expression"));
208}
209
210/* Return the unsigned form of TYPE. TYPE is necessarily an integral
211 type. */
212
213static struct type *
214get_unsigned_type (struct gdbarch *gdbarch, struct type *type)
215{
216 switch (TYPE_LENGTH (type))
217 {
218 case 1:
219 return builtin_type (gdbarch)->builtin_uint8;
220 case 2:
221 return builtin_type (gdbarch)->builtin_uint16;
222 case 4:
223 return builtin_type (gdbarch)->builtin_uint32;
224 case 8:
225 return builtin_type (gdbarch)->builtin_uint64;
226 default:
227 error (_("no unsigned variant found for type, while evaluating "
228 "DWARF expression"));
229 }
44353522
DE
230}
231
8ddd9a20
TT
232/* Return the signed form of TYPE. TYPE is necessarily an integral
233 type. */
234
235static struct type *
236get_signed_type (struct gdbarch *gdbarch, struct type *type)
237{
238 switch (TYPE_LENGTH (type))
239 {
240 case 1:
241 return builtin_type (gdbarch)->builtin_int8;
242 case 2:
243 return builtin_type (gdbarch)->builtin_int16;
244 case 4:
245 return builtin_type (gdbarch)->builtin_int32;
246 case 8:
247 return builtin_type (gdbarch)->builtin_int64;
248 default:
249 error (_("no signed variant found for type, while evaluating "
250 "DWARF expression"));
251 }
252}
253
f2c7657e
UW
254/* Retrieve the N'th item on CTX's stack, converted to an address. */
255
256CORE_ADDR
257dwarf_expr_fetch_address (struct dwarf_expr_context *ctx, int n)
258{
8a9b8146
TT
259 struct value *result_val = dwarf_expr_fetch (ctx, n);
260 enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
261 ULONGEST result;
262
263 dwarf_require_integral (value_type (result_val));
264 result = extract_unsigned_integer (value_contents (result_val),
265 TYPE_LENGTH (value_type (result_val)),
266 byte_order);
f2c7657e
UW
267
268 /* For most architectures, calling extract_unsigned_integer() alone
269 is sufficient for extracting an address. However, some
270 architectures (e.g. MIPS) use signed addresses and using
271 extract_unsigned_integer() will not produce a correct
272 result. Make sure we invoke gdbarch_integer_to_address()
273 for those architectures which require it. */
274 if (gdbarch_integer_to_address_p (ctx->gdbarch))
275 {
f2c7657e 276 gdb_byte *buf = alloca (ctx->addr_size);
8a9b8146
TT
277 struct type *int_type = get_unsigned_type (ctx->gdbarch,
278 value_type (result_val));
f2c7657e
UW
279
280 store_unsigned_integer (buf, ctx->addr_size, byte_order, result);
281 return gdbarch_integer_to_address (ctx->gdbarch, int_type, buf);
282 }
283
284 return (CORE_ADDR) result;
285}
286
44353522
DE
287/* Retrieve the in_stack_memory flag of the N'th item on CTX's stack. */
288
289int
290dwarf_expr_fetch_in_stack_memory (struct dwarf_expr_context *ctx, int n)
291{
292 if (ctx->stack_len <= n)
3e43a32a
MS
293 error (_("Asked for position %d of stack, "
294 "stack only has %d elements on it."),
44353522
DE
295 n, ctx->stack_len);
296 return ctx->stack[ctx->stack_len - (1 + n)].in_stack_memory;
4c2df51b
DJ
297}
298
cb826367
TT
299/* Return true if the expression stack is empty. */
300
301static int
302dwarf_expr_stack_empty_p (struct dwarf_expr_context *ctx)
303{
304 return ctx->stack_len == 0;
305}
306
87808bd6
JB
307/* Add a new piece to CTX's piece list. */
308static void
d3b1e874 309add_piece (struct dwarf_expr_context *ctx, ULONGEST size, ULONGEST offset)
87808bd6
JB
310{
311 struct dwarf_expr_piece *p;
312
313 ctx->num_pieces++;
314
d3b1e874
TT
315 ctx->pieces = xrealloc (ctx->pieces,
316 (ctx->num_pieces
317 * sizeof (struct dwarf_expr_piece)));
87808bd6
JB
318
319 p = &ctx->pieces[ctx->num_pieces - 1];
cec03d70 320 p->location = ctx->location;
87808bd6 321 p->size = size;
d3b1e874
TT
322 p->offset = offset;
323
cec03d70
TT
324 if (p->location == DWARF_VALUE_LITERAL)
325 {
326 p->v.literal.data = ctx->data;
327 p->v.literal.length = ctx->len;
328 }
cb826367
TT
329 else if (dwarf_expr_stack_empty_p (ctx))
330 {
331 p->location = DWARF_VALUE_OPTIMIZED_OUT;
332 /* Also reset the context's location, for our callers. This is
333 a somewhat strange approach, but this lets us avoid setting
334 the location to DWARF_VALUE_MEMORY in all the individual
335 cases in the evaluator. */
336 ctx->location = DWARF_VALUE_OPTIMIZED_OUT;
337 }
f2c7657e
UW
338 else if (p->location == DWARF_VALUE_MEMORY)
339 {
340 p->v.mem.addr = dwarf_expr_fetch_address (ctx, 0);
341 p->v.mem.in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
342 }
8cf6f0b1
TT
343 else if (p->location == DWARF_VALUE_IMPLICIT_POINTER)
344 {
345 p->v.ptr.die = ctx->len;
8a9b8146 346 p->v.ptr.offset = value_as_long (dwarf_expr_fetch (ctx, 0));
8cf6f0b1 347 }
8a9b8146
TT
348 else if (p->location == DWARF_VALUE_REGISTER)
349 p->v.regno = value_as_long (dwarf_expr_fetch (ctx, 0));
cec03d70 350 else
44353522 351 {
f2c7657e 352 p->v.value = dwarf_expr_fetch (ctx, 0);
44353522 353 }
87808bd6
JB
354}
355
4c2df51b
DJ
356/* Evaluate the expression at ADDR (LEN bytes long) using the context
357 CTX. */
358
359void
0d45f56e
TT
360dwarf_expr_eval (struct dwarf_expr_context *ctx, const gdb_byte *addr,
361 size_t len)
4c2df51b 362{
1e3a102a
JK
363 int old_recursion_depth = ctx->recursion_depth;
364
4c2df51b 365 execute_stack_op (ctx, addr, addr + len);
1e3a102a
JK
366
367 /* CTX RECURSION_DEPTH becomes invalid if an exception was thrown here. */
368
369 gdb_assert (ctx->recursion_depth == old_recursion_depth);
4c2df51b
DJ
370}
371
372/* Decode the unsigned LEB128 constant at BUF into the variable pointed to
373 by R, and return the new value of BUF. Verify that it doesn't extend
374 past BUF_END. */
375
0d45f56e
TT
376const gdb_byte *
377read_uleb128 (const gdb_byte *buf, const gdb_byte *buf_end, ULONGEST * r)
4c2df51b
DJ
378{
379 unsigned shift = 0;
380 ULONGEST result = 0;
852483bc 381 gdb_byte byte;
4c2df51b
DJ
382
383 while (1)
384 {
385 if (buf >= buf_end)
8a3fe4f8 386 error (_("read_uleb128: Corrupted DWARF expression."));
4c2df51b
DJ
387
388 byte = *buf++;
9930639c 389 result |= ((ULONGEST) (byte & 0x7f)) << shift;
4c2df51b
DJ
390 if ((byte & 0x80) == 0)
391 break;
392 shift += 7;
393 }
394 *r = result;
395 return buf;
396}
397
398/* Decode the signed LEB128 constant at BUF into the variable pointed to
399 by R, and return the new value of BUF. Verify that it doesn't extend
400 past BUF_END. */
401
0d45f56e
TT
402const gdb_byte *
403read_sleb128 (const gdb_byte *buf, const gdb_byte *buf_end, LONGEST * r)
4c2df51b
DJ
404{
405 unsigned shift = 0;
406 LONGEST result = 0;
852483bc 407 gdb_byte byte;
4c2df51b
DJ
408
409 while (1)
410 {
411 if (buf >= buf_end)
8a3fe4f8 412 error (_("read_sleb128: Corrupted DWARF expression."));
4c2df51b
DJ
413
414 byte = *buf++;
9930639c 415 result |= ((ULONGEST) (byte & 0x7f)) << shift;
4c2df51b
DJ
416 shift += 7;
417 if ((byte & 0x80) == 0)
418 break;
419 }
420 if (shift < (sizeof (*r) * 8) && (byte & 0x40) != 0)
421 result |= -(1 << shift);
422
423 *r = result;
424 return buf;
425}
4c2df51b 426\f
cec03d70
TT
427
428/* Check that the current operator is either at the end of an
429 expression, or that it is followed by a composition operator. */
430
3cf03773
TT
431void
432dwarf_expr_require_composition (const gdb_byte *op_ptr, const gdb_byte *op_end,
433 const char *op_name)
cec03d70
TT
434{
435 /* It seems like DW_OP_GNU_uninit should be handled here. However,
436 it doesn't seem to make sense for DW_OP_*_value, and it was not
437 checked at the other place that this function is called. */
438 if (op_ptr != op_end && *op_ptr != DW_OP_piece && *op_ptr != DW_OP_bit_piece)
439 error (_("DWARF-2 expression error: `%s' operations must be "
64b9b334 440 "used either alone or in conjunction with DW_OP_piece "
cec03d70
TT
441 "or DW_OP_bit_piece."),
442 op_name);
443}
444
8a9b8146
TT
445/* Return true iff the types T1 and T2 are "the same". This only does
446 checks that might reasonably be needed to compare DWARF base
447 types. */
448
449static int
450base_types_equal_p (struct type *t1, struct type *t2)
451{
452 if (TYPE_CODE (t1) != TYPE_CODE (t2))
453 return 0;
454 if (TYPE_UNSIGNED (t1) != TYPE_UNSIGNED (t2))
455 return 0;
456 return TYPE_LENGTH (t1) == TYPE_LENGTH (t2);
457}
458
459/* A convenience function to call get_base_type on CTX and return the
460 result. DIE is the DIE whose type we need. SIZE is non-zero if
461 this function should verify that the resulting type has the correct
462 size. */
463
464static struct type *
465dwarf_get_base_type (struct dwarf_expr_context *ctx, ULONGEST die, int size)
466{
467 struct type *result;
468
469 if (ctx->get_base_type)
470 {
471 result = ctx->get_base_type (ctx, die);
9ff3b74f
TT
472 if (result == NULL)
473 error (_("Could not find type for DW_OP_GNU_const_type"));
8a9b8146
TT
474 if (size != 0 && TYPE_LENGTH (result) != size)
475 error (_("DW_OP_GNU_const_type has different sizes for type and data"));
476 }
477 else
478 /* Anything will do. */
479 result = builtin_type (ctx->gdbarch)->builtin_int;
480
481 return result;
482}
483
4c2df51b
DJ
484/* The engine for the expression evaluator. Using the context in CTX,
485 evaluate the expression between OP_PTR and OP_END. */
486
487static void
852483bc 488execute_stack_op (struct dwarf_expr_context *ctx,
0d45f56e 489 const gdb_byte *op_ptr, const gdb_byte *op_end)
4c2df51b 490{
e17a4113 491 enum bfd_endian byte_order = gdbarch_byte_order (ctx->gdbarch);
8a9b8146
TT
492 /* Old-style "untyped" DWARF values need special treatment in a
493 couple of places, specifically DW_OP_mod and DW_OP_shr. We need
494 a special type for these values so we can distinguish them from
495 values that have an explicit type, because explicitly-typed
496 values do not need special treatment. This special type must be
497 different (in the `==' sense) from any base type coming from the
498 CU. */
499 struct type *address_type = dwarf_expr_address_type (ctx);
9a619af0 500
cec03d70 501 ctx->location = DWARF_VALUE_MEMORY;
42be36b3 502 ctx->initialized = 1; /* Default is initialized. */
18ec9831 503
1e3a102a
JK
504 if (ctx->recursion_depth > ctx->max_recursion_depth)
505 error (_("DWARF-2 expression error: Loop detected (%d)."),
506 ctx->recursion_depth);
507 ctx->recursion_depth++;
508
4c2df51b
DJ
509 while (op_ptr < op_end)
510 {
511 enum dwarf_location_atom op = *op_ptr++;
f2c7657e 512 ULONGEST result;
44353522
DE
513 /* Assume the value is not in stack memory.
514 Code that knows otherwise sets this to 1.
515 Some arithmetic on stack addresses can probably be assumed to still
516 be a stack address, but we skip this complication for now.
517 This is just an optimization, so it's always ok to punt
518 and leave this as 0. */
519 int in_stack_memory = 0;
4c2df51b
DJ
520 ULONGEST uoffset, reg;
521 LONGEST offset;
8a9b8146 522 struct value *result_val = NULL;
4c2df51b 523
4c2df51b
DJ
524 switch (op)
525 {
526 case DW_OP_lit0:
527 case DW_OP_lit1:
528 case DW_OP_lit2:
529 case DW_OP_lit3:
530 case DW_OP_lit4:
531 case DW_OP_lit5:
532 case DW_OP_lit6:
533 case DW_OP_lit7:
534 case DW_OP_lit8:
535 case DW_OP_lit9:
536 case DW_OP_lit10:
537 case DW_OP_lit11:
538 case DW_OP_lit12:
539 case DW_OP_lit13:
540 case DW_OP_lit14:
541 case DW_OP_lit15:
542 case DW_OP_lit16:
543 case DW_OP_lit17:
544 case DW_OP_lit18:
545 case DW_OP_lit19:
546 case DW_OP_lit20:
547 case DW_OP_lit21:
548 case DW_OP_lit22:
549 case DW_OP_lit23:
550 case DW_OP_lit24:
551 case DW_OP_lit25:
552 case DW_OP_lit26:
553 case DW_OP_lit27:
554 case DW_OP_lit28:
555 case DW_OP_lit29:
556 case DW_OP_lit30:
557 case DW_OP_lit31:
558 result = op - DW_OP_lit0;
8a9b8146 559 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
560 break;
561
562 case DW_OP_addr:
f2c7657e
UW
563 result = extract_unsigned_integer (op_ptr,
564 ctx->addr_size, byte_order);
ae0d2f24 565 op_ptr += ctx->addr_size;
ac56253d
TT
566 /* Some versions of GCC emit DW_OP_addr before
567 DW_OP_GNU_push_tls_address. In this case the value is an
568 index, not an address. We don't support things like
569 branching between the address and the TLS op. */
570 if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
571 result += ctx->offset;
8a9b8146 572 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
573 break;
574
575 case DW_OP_const1u:
e17a4113 576 result = extract_unsigned_integer (op_ptr, 1, byte_order);
8a9b8146 577 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
578 op_ptr += 1;
579 break;
580 case DW_OP_const1s:
e17a4113 581 result = extract_signed_integer (op_ptr, 1, byte_order);
8a9b8146 582 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
583 op_ptr += 1;
584 break;
585 case DW_OP_const2u:
e17a4113 586 result = extract_unsigned_integer (op_ptr, 2, byte_order);
8a9b8146 587 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
588 op_ptr += 2;
589 break;
590 case DW_OP_const2s:
e17a4113 591 result = extract_signed_integer (op_ptr, 2, byte_order);
8a9b8146 592 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
593 op_ptr += 2;
594 break;
595 case DW_OP_const4u:
e17a4113 596 result = extract_unsigned_integer (op_ptr, 4, byte_order);
8a9b8146 597 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
598 op_ptr += 4;
599 break;
600 case DW_OP_const4s:
e17a4113 601 result = extract_signed_integer (op_ptr, 4, byte_order);
8a9b8146 602 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
603 op_ptr += 4;
604 break;
605 case DW_OP_const8u:
e17a4113 606 result = extract_unsigned_integer (op_ptr, 8, byte_order);
8a9b8146 607 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
608 op_ptr += 8;
609 break;
610 case DW_OP_const8s:
e17a4113 611 result = extract_signed_integer (op_ptr, 8, byte_order);
8a9b8146 612 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
613 op_ptr += 8;
614 break;
615 case DW_OP_constu:
616 op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
617 result = uoffset;
8a9b8146 618 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
619 break;
620 case DW_OP_consts:
621 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
622 result = offset;
8a9b8146 623 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
624 break;
625
626 /* The DW_OP_reg operations are required to occur alone in
627 location expressions. */
628 case DW_OP_reg0:
629 case DW_OP_reg1:
630 case DW_OP_reg2:
631 case DW_OP_reg3:
632 case DW_OP_reg4:
633 case DW_OP_reg5:
634 case DW_OP_reg6:
635 case DW_OP_reg7:
636 case DW_OP_reg8:
637 case DW_OP_reg9:
638 case DW_OP_reg10:
639 case DW_OP_reg11:
640 case DW_OP_reg12:
641 case DW_OP_reg13:
642 case DW_OP_reg14:
643 case DW_OP_reg15:
644 case DW_OP_reg16:
645 case DW_OP_reg17:
646 case DW_OP_reg18:
647 case DW_OP_reg19:
648 case DW_OP_reg20:
649 case DW_OP_reg21:
650 case DW_OP_reg22:
651 case DW_OP_reg23:
652 case DW_OP_reg24:
653 case DW_OP_reg25:
654 case DW_OP_reg26:
655 case DW_OP_reg27:
656 case DW_OP_reg28:
657 case DW_OP_reg29:
658 case DW_OP_reg30:
659 case DW_OP_reg31:
42be36b3
CT
660 if (op_ptr != op_end
661 && *op_ptr != DW_OP_piece
d3b1e874 662 && *op_ptr != DW_OP_bit_piece
42be36b3 663 && *op_ptr != DW_OP_GNU_uninit)
8a3fe4f8 664 error (_("DWARF-2 expression error: DW_OP_reg operations must be "
64b9b334 665 "used either alone or in conjunction with DW_OP_piece "
d3b1e874 666 "or DW_OP_bit_piece."));
4c2df51b 667
61fbb938 668 result = op - DW_OP_reg0;
8a9b8146 669 result_val = value_from_ulongest (address_type, result);
cec03d70 670 ctx->location = DWARF_VALUE_REGISTER;
4c2df51b
DJ
671 break;
672
673 case DW_OP_regx:
674 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
3cf03773 675 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_regx");
4c2df51b 676
61fbb938 677 result = reg;
8a9b8146 678 result_val = value_from_ulongest (address_type, result);
cec03d70 679 ctx->location = DWARF_VALUE_REGISTER;
4c2df51b
DJ
680 break;
681
cec03d70
TT
682 case DW_OP_implicit_value:
683 {
684 ULONGEST len;
9a619af0 685
cec03d70
TT
686 op_ptr = read_uleb128 (op_ptr, op_end, &len);
687 if (op_ptr + len > op_end)
688 error (_("DW_OP_implicit_value: too few bytes available."));
689 ctx->len = len;
690 ctx->data = op_ptr;
691 ctx->location = DWARF_VALUE_LITERAL;
692 op_ptr += len;
3cf03773
TT
693 dwarf_expr_require_composition (op_ptr, op_end,
694 "DW_OP_implicit_value");
cec03d70
TT
695 }
696 goto no_push;
697
698 case DW_OP_stack_value:
699 ctx->location = DWARF_VALUE_STACK;
3cf03773 700 dwarf_expr_require_composition (op_ptr, op_end, "DW_OP_stack_value");
cec03d70
TT
701 goto no_push;
702
8cf6f0b1
TT
703 case DW_OP_GNU_implicit_pointer:
704 {
705 ULONGEST die;
706 LONGEST len;
707
708 /* The referred-to DIE. */
709 ctx->len = extract_unsigned_integer (op_ptr, ctx->addr_size,
710 byte_order);
711 op_ptr += ctx->addr_size;
712
713 /* The byte offset into the data. */
714 op_ptr = read_sleb128 (op_ptr, op_end, &len);
715 result = (ULONGEST) len;
8a9b8146 716 result_val = value_from_ulongest (address_type, result);
8cf6f0b1
TT
717
718 ctx->location = DWARF_VALUE_IMPLICIT_POINTER;
719 dwarf_expr_require_composition (op_ptr, op_end,
720 "DW_OP_GNU_implicit_pointer");
721 }
722 break;
723
4c2df51b
DJ
724 case DW_OP_breg0:
725 case DW_OP_breg1:
726 case DW_OP_breg2:
727 case DW_OP_breg3:
728 case DW_OP_breg4:
729 case DW_OP_breg5:
730 case DW_OP_breg6:
731 case DW_OP_breg7:
732 case DW_OP_breg8:
733 case DW_OP_breg9:
734 case DW_OP_breg10:
735 case DW_OP_breg11:
736 case DW_OP_breg12:
737 case DW_OP_breg13:
738 case DW_OP_breg14:
739 case DW_OP_breg15:
740 case DW_OP_breg16:
741 case DW_OP_breg17:
742 case DW_OP_breg18:
743 case DW_OP_breg19:
744 case DW_OP_breg20:
745 case DW_OP_breg21:
746 case DW_OP_breg22:
747 case DW_OP_breg23:
748 case DW_OP_breg24:
749 case DW_OP_breg25:
750 case DW_OP_breg26:
751 case DW_OP_breg27:
752 case DW_OP_breg28:
753 case DW_OP_breg29:
754 case DW_OP_breg30:
755 case DW_OP_breg31:
756 {
757 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
61fbb938 758 result = (ctx->read_reg) (ctx->baton, op - DW_OP_breg0);
4c2df51b 759 result += offset;
8a9b8146 760 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
761 }
762 break;
763 case DW_OP_bregx:
764 {
765 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
766 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
61fbb938 767 result = (ctx->read_reg) (ctx->baton, reg);
4c2df51b 768 result += offset;
8a9b8146 769 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
770 }
771 break;
772 case DW_OP_fbreg:
773 {
0d45f56e 774 const gdb_byte *datastart;
4c2df51b
DJ
775 size_t datalen;
776 unsigned int before_stack_len;
777
778 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
779 /* Rather than create a whole new context, we simply
780 record the stack length before execution, then reset it
781 afterwards, effectively erasing whatever the recursive
782 call put there. */
783 before_stack_len = ctx->stack_len;
da62e633
AC
784 /* FIXME: cagney/2003-03-26: This code should be using
785 get_frame_base_address(), and then implement a dwarf2
786 specific this_base method. */
4c2df51b
DJ
787 (ctx->get_frame_base) (ctx->baton, &datastart, &datalen);
788 dwarf_expr_eval (ctx, datastart, datalen);
f2c7657e
UW
789 if (ctx->location == DWARF_VALUE_MEMORY)
790 result = dwarf_expr_fetch_address (ctx, 0);
791 else if (ctx->location == DWARF_VALUE_REGISTER)
8a9b8146
TT
792 result
793 = (ctx->read_reg) (ctx->baton,
794 value_as_long (dwarf_expr_fetch (ctx, 0)));
f2c7657e 795 else
3e43a32a
MS
796 error (_("Not implemented: computing frame "
797 "base using explicit value operator"));
4c2df51b 798 result = result + offset;
8a9b8146 799 result_val = value_from_ulongest (address_type, result);
44353522 800 in_stack_memory = 1;
4c2df51b 801 ctx->stack_len = before_stack_len;
cec03d70 802 ctx->location = DWARF_VALUE_MEMORY;
4c2df51b
DJ
803 }
804 break;
44353522 805
4c2df51b 806 case DW_OP_dup:
8a9b8146 807 result_val = dwarf_expr_fetch (ctx, 0);
44353522 808 in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
4c2df51b
DJ
809 break;
810
811 case DW_OP_drop:
812 dwarf_expr_pop (ctx);
813 goto no_push;
814
815 case DW_OP_pick:
816 offset = *op_ptr++;
8a9b8146 817 result_val = dwarf_expr_fetch (ctx, offset);
44353522 818 in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, offset);
4c2df51b 819 break;
9f3fe11c
TG
820
821 case DW_OP_swap:
822 {
44353522 823 struct dwarf_stack_value t1, t2;
9f3fe11c
TG
824
825 if (ctx->stack_len < 2)
3e43a32a 826 error (_("Not enough elements for "
0963b4bd 827 "DW_OP_swap. Need 2, have %d."),
9f3fe11c
TG
828 ctx->stack_len);
829 t1 = ctx->stack[ctx->stack_len - 1];
830 t2 = ctx->stack[ctx->stack_len - 2];
831 ctx->stack[ctx->stack_len - 1] = t2;
832 ctx->stack[ctx->stack_len - 2] = t1;
833 goto no_push;
834 }
4c2df51b
DJ
835
836 case DW_OP_over:
8a9b8146 837 result_val = dwarf_expr_fetch (ctx, 1);
44353522 838 in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 1);
4c2df51b
DJ
839 break;
840
841 case DW_OP_rot:
842 {
44353522 843 struct dwarf_stack_value t1, t2, t3;
4c2df51b
DJ
844
845 if (ctx->stack_len < 3)
0963b4bd
MS
846 error (_("Not enough elements for "
847 "DW_OP_rot. Need 3, have %d."),
4c2df51b
DJ
848 ctx->stack_len);
849 t1 = ctx->stack[ctx->stack_len - 1];
850 t2 = ctx->stack[ctx->stack_len - 2];
851 t3 = ctx->stack[ctx->stack_len - 3];
852 ctx->stack[ctx->stack_len - 1] = t2;
853 ctx->stack[ctx->stack_len - 2] = t3;
854 ctx->stack[ctx->stack_len - 3] = t1;
855 goto no_push;
856 }
857
858 case DW_OP_deref:
859 case DW_OP_deref_size:
8a9b8146 860 case DW_OP_GNU_deref_type:
f2c7657e
UW
861 {
862 int addr_size = (op == DW_OP_deref ? ctx->addr_size : *op_ptr++);
863 gdb_byte *buf = alloca (addr_size);
864 CORE_ADDR addr = dwarf_expr_fetch_address (ctx, 0);
8a9b8146
TT
865 struct type *type;
866
f2c7657e
UW
867 dwarf_expr_pop (ctx);
868
8a9b8146
TT
869 if (op == DW_OP_GNU_deref_type)
870 {
871 ULONGEST type_die;
872
873 op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
874 type = dwarf_get_base_type (ctx, type_die, 0);
875 }
876 else
877 type = address_type;
878
f2c7657e 879 (ctx->read_mem) (ctx->baton, buf, addr, addr_size);
325663dc
JB
880
881 /* If the size of the object read from memory is different
882 from the type length, we need to zero-extend it. */
883 if (TYPE_LENGTH (type) != addr_size)
884 {
885 ULONGEST result =
886 extract_unsigned_integer (buf, addr_size, byte_order);
887
888 buf = alloca (TYPE_LENGTH (type));
889 store_unsigned_integer (buf, TYPE_LENGTH (type),
890 byte_order, result);
891 }
892
8a9b8146 893 result_val = value_from_contents_and_address (type, buf, addr);
f2c7657e
UW
894 break;
895 }
896
4c2df51b
DJ
897 case DW_OP_abs:
898 case DW_OP_neg:
899 case DW_OP_not:
900 case DW_OP_plus_uconst:
8a9b8146
TT
901 {
902 /* Unary operations. */
903 result_val = dwarf_expr_fetch (ctx, 0);
904 dwarf_expr_pop (ctx);
4c2df51b 905
8a9b8146
TT
906 switch (op)
907 {
908 case DW_OP_abs:
909 if (value_less (result_val,
910 value_zero (value_type (result_val), not_lval)))
911 result_val = value_neg (result_val);
912 break;
913 case DW_OP_neg:
914 result_val = value_neg (result_val);
915 break;
916 case DW_OP_not:
917 dwarf_require_integral (value_type (result_val));
918 result_val = value_complement (result_val);
919 break;
920 case DW_OP_plus_uconst:
921 dwarf_require_integral (value_type (result_val));
922 result = value_as_long (result_val);
923 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
924 result += reg;
925 result_val = value_from_ulongest (address_type, result);
926 break;
927 }
928 }
4c2df51b
DJ
929 break;
930
931 case DW_OP_and:
932 case DW_OP_div:
933 case DW_OP_minus:
934 case DW_OP_mod:
935 case DW_OP_mul:
936 case DW_OP_or:
937 case DW_OP_plus:
938 case DW_OP_shl:
939 case DW_OP_shr:
940 case DW_OP_shra:
941 case DW_OP_xor:
942 case DW_OP_le:
943 case DW_OP_ge:
944 case DW_OP_eq:
945 case DW_OP_lt:
946 case DW_OP_gt:
947 case DW_OP_ne:
948 {
f2c7657e 949 /* Binary operations. */
8a9b8146 950 struct value *first, *second;
4c2df51b
DJ
951
952 second = dwarf_expr_fetch (ctx, 0);
953 dwarf_expr_pop (ctx);
954
b263358a 955 first = dwarf_expr_fetch (ctx, 0);
4c2df51b
DJ
956 dwarf_expr_pop (ctx);
957
8a9b8146
TT
958 if (! base_types_equal_p (value_type (first), value_type (second)))
959 error (_("Incompatible types on DWARF stack"));
960
4c2df51b
DJ
961 switch (op)
962 {
963 case DW_OP_and:
8a9b8146
TT
964 dwarf_require_integral (value_type (first));
965 dwarf_require_integral (value_type (second));
966 result_val = value_binop (first, second, BINOP_BITWISE_AND);
4c2df51b
DJ
967 break;
968 case DW_OP_div:
8a9b8146 969 result_val = value_binop (first, second, BINOP_DIV);
99c87dab 970 break;
4c2df51b 971 case DW_OP_minus:
8a9b8146 972 result_val = value_binop (first, second, BINOP_SUB);
4c2df51b
DJ
973 break;
974 case DW_OP_mod:
8a9b8146
TT
975 {
976 int cast_back = 0;
977 struct type *orig_type = value_type (first);
978
979 /* We have to special-case "old-style" untyped values
980 -- these must have mod computed using unsigned
981 math. */
982 if (orig_type == address_type)
983 {
984 struct type *utype
985 = get_unsigned_type (ctx->gdbarch, orig_type);
986
987 cast_back = 1;
988 first = value_cast (utype, first);
989 second = value_cast (utype, second);
990 }
991 /* Note that value_binop doesn't handle float or
992 decimal float here. This seems unimportant. */
993 result_val = value_binop (first, second, BINOP_MOD);
994 if (cast_back)
995 result_val = value_cast (orig_type, result_val);
996 }
4c2df51b
DJ
997 break;
998 case DW_OP_mul:
8a9b8146 999 result_val = value_binop (first, second, BINOP_MUL);
4c2df51b
DJ
1000 break;
1001 case DW_OP_or:
8a9b8146
TT
1002 dwarf_require_integral (value_type (first));
1003 dwarf_require_integral (value_type (second));
1004 result_val = value_binop (first, second, BINOP_BITWISE_IOR);
4c2df51b
DJ
1005 break;
1006 case DW_OP_plus:
8a9b8146 1007 result_val = value_binop (first, second, BINOP_ADD);
4c2df51b
DJ
1008 break;
1009 case DW_OP_shl:
8a9b8146
TT
1010 dwarf_require_integral (value_type (first));
1011 dwarf_require_integral (value_type (second));
1012 result_val = value_binop (first, second, BINOP_LSH);
4c2df51b
DJ
1013 break;
1014 case DW_OP_shr:
8a9b8146
TT
1015 dwarf_require_integral (value_type (first));
1016 dwarf_require_integral (value_type (second));
b087e0ed 1017 if (!TYPE_UNSIGNED (value_type (first)))
8a9b8146
TT
1018 {
1019 struct type *utype
1020 = get_unsigned_type (ctx->gdbarch, value_type (first));
1021
1022 first = value_cast (utype, first);
1023 }
1024
1025 result_val = value_binop (first, second, BINOP_RSH);
1026 /* Make sure we wind up with the same type we started
1027 with. */
1028 if (value_type (result_val) != value_type (second))
1029 result_val = value_cast (value_type (second), result_val);
99c87dab 1030 break;
4c2df51b 1031 case DW_OP_shra:
8a9b8146
TT
1032 dwarf_require_integral (value_type (first));
1033 dwarf_require_integral (value_type (second));
8ddd9a20
TT
1034 if (TYPE_UNSIGNED (value_type (first)))
1035 {
1036 struct type *stype
1037 = get_signed_type (ctx->gdbarch, value_type (first));
1038
1039 first = value_cast (stype, first);
1040 }
1041
8a9b8146 1042 result_val = value_binop (first, second, BINOP_RSH);
8ddd9a20
TT
1043 /* Make sure we wind up with the same type we started
1044 with. */
1045 if (value_type (result_val) != value_type (second))
1046 result_val = value_cast (value_type (second), result_val);
4c2df51b
DJ
1047 break;
1048 case DW_OP_xor:
8a9b8146
TT
1049 dwarf_require_integral (value_type (first));
1050 dwarf_require_integral (value_type (second));
1051 result_val = value_binop (first, second, BINOP_BITWISE_XOR);
4c2df51b
DJ
1052 break;
1053 case DW_OP_le:
8a9b8146
TT
1054 /* A <= B is !(B < A). */
1055 result = ! value_less (second, first);
1056 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1057 break;
1058 case DW_OP_ge:
8a9b8146
TT
1059 /* A >= B is !(A < B). */
1060 result = ! value_less (first, second);
1061 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1062 break;
1063 case DW_OP_eq:
8a9b8146
TT
1064 result = value_equal (first, second);
1065 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1066 break;
1067 case DW_OP_lt:
8a9b8146
TT
1068 result = value_less (first, second);
1069 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1070 break;
1071 case DW_OP_gt:
8a9b8146
TT
1072 /* A > B is B < A. */
1073 result = value_less (second, first);
1074 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1075 break;
1076 case DW_OP_ne:
8a9b8146
TT
1077 result = ! value_equal (first, second);
1078 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1079 break;
1080 default:
1081 internal_error (__FILE__, __LINE__,
e2e0b3e5 1082 _("Can't be reached."));
4c2df51b 1083 }
4c2df51b
DJ
1084 }
1085 break;
1086
e7802207
TT
1087 case DW_OP_call_frame_cfa:
1088 result = (ctx->get_frame_cfa) (ctx->baton);
8a9b8146 1089 result_val = value_from_ulongest (address_type, result);
44353522 1090 in_stack_memory = 1;
e7802207
TT
1091 break;
1092
4c2df51b 1093 case DW_OP_GNU_push_tls_address:
c3228f12
EZ
1094 /* Variable is at a constant offset in the thread-local
1095 storage block into the objfile for the current thread and
0963b4bd 1096 the dynamic linker module containing this expression. Here
c3228f12
EZ
1097 we return returns the offset from that base. The top of the
1098 stack has the offset from the beginning of the thread
1099 control block at which the variable is located. Nothing
1100 should follow this operator, so the top of stack would be
1101 returned. */
8a9b8146 1102 result = value_as_long (dwarf_expr_fetch (ctx, 0));
4c2df51b
DJ
1103 dwarf_expr_pop (ctx);
1104 result = (ctx->get_tls_address) (ctx->baton, result);
8a9b8146 1105 result_val = value_from_ulongest (address_type, result);
4c2df51b
DJ
1106 break;
1107
1108 case DW_OP_skip:
e17a4113 1109 offset = extract_signed_integer (op_ptr, 2, byte_order);
4c2df51b
DJ
1110 op_ptr += 2;
1111 op_ptr += offset;
1112 goto no_push;
1113
1114 case DW_OP_bra:
8a9b8146
TT
1115 {
1116 struct value *val;
1117
1118 offset = extract_signed_integer (op_ptr, 2, byte_order);
1119 op_ptr += 2;
1120 val = dwarf_expr_fetch (ctx, 0);
1121 dwarf_require_integral (value_type (val));
1122 if (value_as_long (val) != 0)
1123 op_ptr += offset;
1124 dwarf_expr_pop (ctx);
1125 }
4c2df51b
DJ
1126 goto no_push;
1127
1128 case DW_OP_nop:
1129 goto no_push;
1130
87808bd6
JB
1131 case DW_OP_piece:
1132 {
1133 ULONGEST size;
87808bd6
JB
1134
1135 /* Record the piece. */
1136 op_ptr = read_uleb128 (op_ptr, op_end, &size);
d3b1e874 1137 add_piece (ctx, 8 * size, 0);
87808bd6 1138
cec03d70
TT
1139 /* Pop off the address/regnum, and reset the location
1140 type. */
cb826367
TT
1141 if (ctx->location != DWARF_VALUE_LITERAL
1142 && ctx->location != DWARF_VALUE_OPTIMIZED_OUT)
cec03d70
TT
1143 dwarf_expr_pop (ctx);
1144 ctx->location = DWARF_VALUE_MEMORY;
87808bd6
JB
1145 }
1146 goto no_push;
1147
d3b1e874
TT
1148 case DW_OP_bit_piece:
1149 {
1150 ULONGEST size, offset;
1151
1152 /* Record the piece. */
1153 op_ptr = read_uleb128 (op_ptr, op_end, &size);
1154 op_ptr = read_uleb128 (op_ptr, op_end, &offset);
1155 add_piece (ctx, size, offset);
1156
1157 /* Pop off the address/regnum, and reset the location
1158 type. */
1159 if (ctx->location != DWARF_VALUE_LITERAL
1160 && ctx->location != DWARF_VALUE_OPTIMIZED_OUT)
1161 dwarf_expr_pop (ctx);
1162 ctx->location = DWARF_VALUE_MEMORY;
1163 }
1164 goto no_push;
1165
42be36b3
CT
1166 case DW_OP_GNU_uninit:
1167 if (op_ptr != op_end)
9c482037 1168 error (_("DWARF-2 expression error: DW_OP_GNU_uninit must always "
42be36b3
CT
1169 "be the very last op."));
1170
1171 ctx->initialized = 0;
1172 goto no_push;
1173
5c631832
JK
1174 case DW_OP_call2:
1175 result = extract_unsigned_integer (op_ptr, 2, byte_order);
1176 op_ptr += 2;
1177 ctx->dwarf_call (ctx, result);
1178 goto no_push;
1179
1180 case DW_OP_call4:
1181 result = extract_unsigned_integer (op_ptr, 4, byte_order);
1182 op_ptr += 4;
1183 ctx->dwarf_call (ctx, result);
1184 goto no_push;
dd90784c
JK
1185
1186 case DW_OP_GNU_entry_value:
1187 /* This operation is not yet supported by GDB. */
1188 ctx->location = DWARF_VALUE_OPTIMIZED_OUT;
1189 ctx->stack_len = 0;
1190 ctx->num_pieces = 0;
1191 goto abort_expression;
5c631832 1192
8a9b8146
TT
1193 case DW_OP_GNU_const_type:
1194 {
1195 ULONGEST type_die;
1196 int n;
1197 const gdb_byte *data;
1198 struct type *type;
1199
1200 op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1201 n = *op_ptr++;
1202 data = op_ptr;
1203 op_ptr += n;
1204
1205 type = dwarf_get_base_type (ctx, type_die, n);
1206 result_val = value_from_contents (type, data);
1207 }
1208 break;
1209
1210 case DW_OP_GNU_regval_type:
1211 {
1212 ULONGEST type_die;
1213 struct type *type;
1214
1215 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
1216 op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1217
1218 type = dwarf_get_base_type (ctx, type_die, 0);
1219 result = (ctx->read_reg) (ctx->baton, reg);
1220 result_val = value_from_ulongest (type, result);
1221 }
1222 break;
1223
1224 case DW_OP_GNU_convert:
1225 case DW_OP_GNU_reinterpret:
1226 {
1227 ULONGEST type_die;
1228 struct type *type;
1229
1230 op_ptr = read_uleb128 (op_ptr, op_end, &type_die);
1231
c38c4bc5
TT
1232 if (type_die == 0)
1233 type = address_type;
1234 else
1235 type = dwarf_get_base_type (ctx, type_die, 0);
8a9b8146
TT
1236
1237 result_val = dwarf_expr_fetch (ctx, 0);
1238 dwarf_expr_pop (ctx);
1239
1240 if (op == DW_OP_GNU_convert)
1241 result_val = value_cast (type, result_val);
1242 else if (type == value_type (result_val))
1243 {
1244 /* Nothing. */
1245 }
1246 else if (TYPE_LENGTH (type)
1247 != TYPE_LENGTH (value_type (result_val)))
1248 error (_("DW_OP_GNU_reinterpret has wrong size"));
1249 else
1250 result_val
1251 = value_from_contents (type,
1252 value_contents_all (result_val));
1253 }
1254 break;
1255
4c2df51b 1256 default:
8a3fe4f8 1257 error (_("Unhandled dwarf expression opcode 0x%x"), op);
4c2df51b
DJ
1258 }
1259
1260 /* Most things push a result value. */
8a9b8146
TT
1261 gdb_assert (result_val != NULL);
1262 dwarf_expr_push (ctx, result_val, in_stack_memory);
82ae4854 1263 no_push:
b27cf2b3 1264 ;
4c2df51b 1265 }
1e3a102a 1266
8cf6f0b1
TT
1267 /* To simplify our main caller, if the result is an implicit
1268 pointer, then make a pieced value. This is ok because we can't
1269 have implicit pointers in contexts where pieces are invalid. */
1270 if (ctx->location == DWARF_VALUE_IMPLICIT_POINTER)
1271 add_piece (ctx, 8 * ctx->addr_size, 0);
1272
dd90784c 1273abort_expression:
1e3a102a
JK
1274 ctx->recursion_depth--;
1275 gdb_assert (ctx->recursion_depth >= 0);
8a9b8146
TT
1276}
1277
1278void
1279_initialize_dwarf2expr (void)
1280{
1281 dwarf_arch_cookie
1282 = gdbarch_data_register_post_init (dwarf_gdbarch_types_init);
4c2df51b 1283}
This page took 0.645798 seconds and 4 git commands to generate.