2007-06-13 Markus Deuling <deuling@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / dwarf2expr.c
CommitLineData
852483bc
MK
1/* DWARF 2 Expression Evaluator.
2
6aba47ca 3 Copyright (C) 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
852483bc 4
4c2df51b
DJ
5 Contributed by Daniel Berlin (dan@dberlin.org)
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
197e01b6
EZ
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
4c2df51b
DJ
23
24#include "defs.h"
25#include "symtab.h"
26#include "gdbtypes.h"
27#include "value.h"
28#include "gdbcore.h"
29#include "elf/dwarf2.h"
30#include "dwarf2expr.h"
31
32/* Local prototypes. */
33
34static void execute_stack_op (struct dwarf_expr_context *,
852483bc 35 gdb_byte *, gdb_byte *);
ace186d4 36static struct type *unsigned_address_type (void);
4c2df51b
DJ
37
38/* Create a new context for the expression evaluator. */
39
40struct dwarf_expr_context *
e4adbba9 41new_dwarf_expr_context (void)
4c2df51b
DJ
42{
43 struct dwarf_expr_context *retval;
44 retval = xcalloc (1, sizeof (struct dwarf_expr_context));
18ec9831
KB
45 retval->stack_len = 0;
46 retval->stack_allocated = 10;
47 retval->stack = xmalloc (retval->stack_allocated * sizeof (CORE_ADDR));
87808bd6
JB
48 retval->num_pieces = 0;
49 retval->pieces = 0;
4c2df51b
DJ
50 return retval;
51}
52
53/* Release the memory allocated to CTX. */
54
55void
56free_dwarf_expr_context (struct dwarf_expr_context *ctx)
57{
58 xfree (ctx->stack);
87808bd6 59 xfree (ctx->pieces);
4c2df51b
DJ
60 xfree (ctx);
61}
62
63/* Expand the memory allocated to CTX's stack to contain at least
64 NEED more elements than are currently used. */
65
66static void
67dwarf_expr_grow_stack (struct dwarf_expr_context *ctx, size_t need)
68{
69 if (ctx->stack_len + need > ctx->stack_allocated)
70 {
18ec9831 71 size_t newlen = ctx->stack_len + need + 10;
4c2df51b 72 ctx->stack = xrealloc (ctx->stack,
18ec9831
KB
73 newlen * sizeof (CORE_ADDR));
74 ctx->stack_allocated = newlen;
4c2df51b
DJ
75 }
76}
77
78/* Push VALUE onto CTX's stack. */
79
80void
81dwarf_expr_push (struct dwarf_expr_context *ctx, CORE_ADDR value)
82{
83 dwarf_expr_grow_stack (ctx, 1);
84 ctx->stack[ctx->stack_len++] = value;
85}
86
87/* Pop the top item off of CTX's stack. */
88
89void
90dwarf_expr_pop (struct dwarf_expr_context *ctx)
91{
92 if (ctx->stack_len <= 0)
8a3fe4f8 93 error (_("dwarf expression stack underflow"));
4c2df51b
DJ
94 ctx->stack_len--;
95}
96
97/* Retrieve the N'th item on CTX's stack. */
98
99CORE_ADDR
100dwarf_expr_fetch (struct dwarf_expr_context *ctx, int n)
101{
ef0fdf07 102 if (ctx->stack_len <= n)
8a3fe4f8 103 error (_("Asked for position %d of stack, stack only has %d elements on it."),
4c2df51b
DJ
104 n, ctx->stack_len);
105 return ctx->stack[ctx->stack_len - (1 + n)];
106
107}
108
87808bd6
JB
109/* Add a new piece to CTX's piece list. */
110static void
111add_piece (struct dwarf_expr_context *ctx,
112 int in_reg, CORE_ADDR value, ULONGEST size)
113{
114 struct dwarf_expr_piece *p;
115
116 ctx->num_pieces++;
117
118 if (ctx->pieces)
119 ctx->pieces = xrealloc (ctx->pieces,
120 (ctx->num_pieces
121 * sizeof (struct dwarf_expr_piece)));
122 else
123 ctx->pieces = xmalloc (ctx->num_pieces
124 * sizeof (struct dwarf_expr_piece));
125
126 p = &ctx->pieces[ctx->num_pieces - 1];
127 p->in_reg = in_reg;
128 p->value = value;
129 p->size = size;
130}
131
4c2df51b
DJ
132/* Evaluate the expression at ADDR (LEN bytes long) using the context
133 CTX. */
134
135void
852483bc 136dwarf_expr_eval (struct dwarf_expr_context *ctx, gdb_byte *addr, size_t len)
4c2df51b
DJ
137{
138 execute_stack_op (ctx, addr, addr + len);
139}
140
141/* Decode the unsigned LEB128 constant at BUF into the variable pointed to
142 by R, and return the new value of BUF. Verify that it doesn't extend
143 past BUF_END. */
144
852483bc
MK
145gdb_byte *
146read_uleb128 (gdb_byte *buf, gdb_byte *buf_end, ULONGEST * r)
4c2df51b
DJ
147{
148 unsigned shift = 0;
149 ULONGEST result = 0;
852483bc 150 gdb_byte byte;
4c2df51b
DJ
151
152 while (1)
153 {
154 if (buf >= buf_end)
8a3fe4f8 155 error (_("read_uleb128: Corrupted DWARF expression."));
4c2df51b
DJ
156
157 byte = *buf++;
158 result |= (byte & 0x7f) << shift;
159 if ((byte & 0x80) == 0)
160 break;
161 shift += 7;
162 }
163 *r = result;
164 return buf;
165}
166
167/* Decode the signed LEB128 constant at BUF into the variable pointed to
168 by R, and return the new value of BUF. Verify that it doesn't extend
169 past BUF_END. */
170
852483bc
MK
171gdb_byte *
172read_sleb128 (gdb_byte *buf, gdb_byte *buf_end, LONGEST * r)
4c2df51b
DJ
173{
174 unsigned shift = 0;
175 LONGEST result = 0;
852483bc 176 gdb_byte byte;
4c2df51b
DJ
177
178 while (1)
179 {
180 if (buf >= buf_end)
8a3fe4f8 181 error (_("read_sleb128: Corrupted DWARF expression."));
4c2df51b
DJ
182
183 byte = *buf++;
184 result |= (byte & 0x7f) << shift;
185 shift += 7;
186 if ((byte & 0x80) == 0)
187 break;
188 }
189 if (shift < (sizeof (*r) * 8) && (byte & 0x40) != 0)
190 result |= -(1 << shift);
191
192 *r = result;
193 return buf;
194}
195
196/* Read an address from BUF, and verify that it doesn't extend past
197 BUF_END. The address is returned, and *BYTES_READ is set to the
198 number of bytes read from BUF. */
199
0d53c4c4 200CORE_ADDR
852483bc 201dwarf2_read_address (gdb_byte *buf, gdb_byte *buf_end, int *bytes_read)
4c2df51b
DJ
202{
203 CORE_ADDR result;
204
17a912b6 205 if (buf_end - buf < gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT)
8a3fe4f8 206 error (_("dwarf2_read_address: Corrupted DWARF expression."));
4c2df51b 207
17a912b6 208 *bytes_read = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
ace186d4
KB
209
210 /* For most architectures, calling extract_unsigned_integer() alone
211 is sufficient for extracting an address. However, some
212 architectures (e.g. MIPS) use signed addresses and using
213 extract_unsigned_integer() will not produce a correct
214 result. Turning the unsigned integer into a value and then
215 decomposing that value as an address will cause
216 gdbarch_integer_to_address() to be invoked for those
217 architectures which require it. Thus, using value_as_address()
218 will produce the correct result for both types of architectures.
219
220 One concern regarding the use of values for this purpose is
221 efficiency. Obviously, these extra calls will take more time to
222 execute and creating a value takes more space, space which will
223 have to be garbage collected at a later time. If constructing
224 and then decomposing a value for this purpose proves to be too
225 inefficient, then gdbarch_integer_to_address() can be called
226 directly.
227
228 The use of `unsigned_address_type' in the code below refers to
229 the type of buf and has no bearing on the signedness of the
230 address being returned. */
231
232 result = value_as_address (value_from_longest
233 (unsigned_address_type (),
234 extract_unsigned_integer
235 (buf,
17a912b6
UW
236 gdbarch_addr_bit (current_gdbarch)
237 / TARGET_CHAR_BIT)));
ace186d4 238
4c2df51b
DJ
239 return result;
240}
241
242/* Return the type of an address, for unsigned arithmetic. */
243
244static struct type *
245unsigned_address_type (void)
246{
17a912b6 247 switch (gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT)
4c2df51b
DJ
248 {
249 case 2:
250 return builtin_type_uint16;
251 case 4:
252 return builtin_type_uint32;
253 case 8:
254 return builtin_type_uint64;
255 default:
256 internal_error (__FILE__, __LINE__,
e2e0b3e5 257 _("Unsupported address size.\n"));
4c2df51b
DJ
258 }
259}
260
261/* Return the type of an address, for signed arithmetic. */
262
263static struct type *
264signed_address_type (void)
265{
17a912b6 266 switch (gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT)
4c2df51b
DJ
267 {
268 case 2:
269 return builtin_type_int16;
270 case 4:
271 return builtin_type_int32;
272 case 8:
273 return builtin_type_int64;
274 default:
275 internal_error (__FILE__, __LINE__,
e2e0b3e5 276 _("Unsupported address size.\n"));
4c2df51b
DJ
277 }
278}
279\f
280/* The engine for the expression evaluator. Using the context in CTX,
281 evaluate the expression between OP_PTR and OP_END. */
282
283static void
852483bc
MK
284execute_stack_op (struct dwarf_expr_context *ctx,
285 gdb_byte *op_ptr, gdb_byte *op_end)
4c2df51b 286{
18ec9831 287 ctx->in_reg = 0;
42be36b3 288 ctx->initialized = 1; /* Default is initialized. */
18ec9831 289
4c2df51b
DJ
290 while (op_ptr < op_end)
291 {
292 enum dwarf_location_atom op = *op_ptr++;
61fbb938 293 CORE_ADDR result;
4c2df51b
DJ
294 ULONGEST uoffset, reg;
295 LONGEST offset;
296 int bytes_read;
4c2df51b 297
4c2df51b
DJ
298 switch (op)
299 {
300 case DW_OP_lit0:
301 case DW_OP_lit1:
302 case DW_OP_lit2:
303 case DW_OP_lit3:
304 case DW_OP_lit4:
305 case DW_OP_lit5:
306 case DW_OP_lit6:
307 case DW_OP_lit7:
308 case DW_OP_lit8:
309 case DW_OP_lit9:
310 case DW_OP_lit10:
311 case DW_OP_lit11:
312 case DW_OP_lit12:
313 case DW_OP_lit13:
314 case DW_OP_lit14:
315 case DW_OP_lit15:
316 case DW_OP_lit16:
317 case DW_OP_lit17:
318 case DW_OP_lit18:
319 case DW_OP_lit19:
320 case DW_OP_lit20:
321 case DW_OP_lit21:
322 case DW_OP_lit22:
323 case DW_OP_lit23:
324 case DW_OP_lit24:
325 case DW_OP_lit25:
326 case DW_OP_lit26:
327 case DW_OP_lit27:
328 case DW_OP_lit28:
329 case DW_OP_lit29:
330 case DW_OP_lit30:
331 case DW_OP_lit31:
332 result = op - DW_OP_lit0;
333 break;
334
335 case DW_OP_addr:
0d53c4c4 336 result = dwarf2_read_address (op_ptr, op_end, &bytes_read);
4c2df51b
DJ
337 op_ptr += bytes_read;
338 break;
339
340 case DW_OP_const1u:
341 result = extract_unsigned_integer (op_ptr, 1);
342 op_ptr += 1;
343 break;
344 case DW_OP_const1s:
345 result = extract_signed_integer (op_ptr, 1);
346 op_ptr += 1;
347 break;
348 case DW_OP_const2u:
349 result = extract_unsigned_integer (op_ptr, 2);
350 op_ptr += 2;
351 break;
352 case DW_OP_const2s:
353 result = extract_signed_integer (op_ptr, 2);
354 op_ptr += 2;
355 break;
356 case DW_OP_const4u:
357 result = extract_unsigned_integer (op_ptr, 4);
358 op_ptr += 4;
359 break;
360 case DW_OP_const4s:
361 result = extract_signed_integer (op_ptr, 4);
362 op_ptr += 4;
363 break;
364 case DW_OP_const8u:
365 result = extract_unsigned_integer (op_ptr, 8);
366 op_ptr += 8;
367 break;
368 case DW_OP_const8s:
369 result = extract_signed_integer (op_ptr, 8);
370 op_ptr += 8;
371 break;
372 case DW_OP_constu:
373 op_ptr = read_uleb128 (op_ptr, op_end, &uoffset);
374 result = uoffset;
375 break;
376 case DW_OP_consts:
377 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
378 result = offset;
379 break;
380
381 /* The DW_OP_reg operations are required to occur alone in
382 location expressions. */
383 case DW_OP_reg0:
384 case DW_OP_reg1:
385 case DW_OP_reg2:
386 case DW_OP_reg3:
387 case DW_OP_reg4:
388 case DW_OP_reg5:
389 case DW_OP_reg6:
390 case DW_OP_reg7:
391 case DW_OP_reg8:
392 case DW_OP_reg9:
393 case DW_OP_reg10:
394 case DW_OP_reg11:
395 case DW_OP_reg12:
396 case DW_OP_reg13:
397 case DW_OP_reg14:
398 case DW_OP_reg15:
399 case DW_OP_reg16:
400 case DW_OP_reg17:
401 case DW_OP_reg18:
402 case DW_OP_reg19:
403 case DW_OP_reg20:
404 case DW_OP_reg21:
405 case DW_OP_reg22:
406 case DW_OP_reg23:
407 case DW_OP_reg24:
408 case DW_OP_reg25:
409 case DW_OP_reg26:
410 case DW_OP_reg27:
411 case DW_OP_reg28:
412 case DW_OP_reg29:
413 case DW_OP_reg30:
414 case DW_OP_reg31:
42be36b3
CT
415 if (op_ptr != op_end
416 && *op_ptr != DW_OP_piece
417 && *op_ptr != DW_OP_GNU_uninit)
8a3fe4f8
AC
418 error (_("DWARF-2 expression error: DW_OP_reg operations must be "
419 "used either alone or in conjuction with DW_OP_piece."));
4c2df51b 420
61fbb938
DJ
421 result = op - DW_OP_reg0;
422 ctx->in_reg = 1;
4c2df51b
DJ
423
424 break;
425
426 case DW_OP_regx:
427 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
18ec9831 428 if (op_ptr != op_end && *op_ptr != DW_OP_piece)
8a3fe4f8
AC
429 error (_("DWARF-2 expression error: DW_OP_reg operations must be "
430 "used either alone or in conjuction with DW_OP_piece."));
4c2df51b 431
61fbb938
DJ
432 result = reg;
433 ctx->in_reg = 1;
4c2df51b
DJ
434 break;
435
436 case DW_OP_breg0:
437 case DW_OP_breg1:
438 case DW_OP_breg2:
439 case DW_OP_breg3:
440 case DW_OP_breg4:
441 case DW_OP_breg5:
442 case DW_OP_breg6:
443 case DW_OP_breg7:
444 case DW_OP_breg8:
445 case DW_OP_breg9:
446 case DW_OP_breg10:
447 case DW_OP_breg11:
448 case DW_OP_breg12:
449 case DW_OP_breg13:
450 case DW_OP_breg14:
451 case DW_OP_breg15:
452 case DW_OP_breg16:
453 case DW_OP_breg17:
454 case DW_OP_breg18:
455 case DW_OP_breg19:
456 case DW_OP_breg20:
457 case DW_OP_breg21:
458 case DW_OP_breg22:
459 case DW_OP_breg23:
460 case DW_OP_breg24:
461 case DW_OP_breg25:
462 case DW_OP_breg26:
463 case DW_OP_breg27:
464 case DW_OP_breg28:
465 case DW_OP_breg29:
466 case DW_OP_breg30:
467 case DW_OP_breg31:
468 {
469 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
61fbb938 470 result = (ctx->read_reg) (ctx->baton, op - DW_OP_breg0);
4c2df51b
DJ
471 result += offset;
472 }
473 break;
474 case DW_OP_bregx:
475 {
476 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
477 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
61fbb938 478 result = (ctx->read_reg) (ctx->baton, reg);
4c2df51b
DJ
479 result += offset;
480 }
481 break;
482 case DW_OP_fbreg:
483 {
852483bc 484 gdb_byte *datastart;
4c2df51b
DJ
485 size_t datalen;
486 unsigned int before_stack_len;
487
488 op_ptr = read_sleb128 (op_ptr, op_end, &offset);
489 /* Rather than create a whole new context, we simply
490 record the stack length before execution, then reset it
491 afterwards, effectively erasing whatever the recursive
492 call put there. */
493 before_stack_len = ctx->stack_len;
da62e633
AC
494 /* FIXME: cagney/2003-03-26: This code should be using
495 get_frame_base_address(), and then implement a dwarf2
496 specific this_base method. */
4c2df51b
DJ
497 (ctx->get_frame_base) (ctx->baton, &datastart, &datalen);
498 dwarf_expr_eval (ctx, datastart, datalen);
499 result = dwarf_expr_fetch (ctx, 0);
61fbb938
DJ
500 if (ctx->in_reg)
501 result = (ctx->read_reg) (ctx->baton, result);
4c2df51b
DJ
502 result = result + offset;
503 ctx->stack_len = before_stack_len;
504 ctx->in_reg = 0;
505 }
506 break;
507 case DW_OP_dup:
508 result = dwarf_expr_fetch (ctx, 0);
509 break;
510
511 case DW_OP_drop:
512 dwarf_expr_pop (ctx);
513 goto no_push;
514
515 case DW_OP_pick:
516 offset = *op_ptr++;
517 result = dwarf_expr_fetch (ctx, offset);
518 break;
519
520 case DW_OP_over:
521 result = dwarf_expr_fetch (ctx, 1);
522 break;
523
524 case DW_OP_rot:
525 {
526 CORE_ADDR t1, t2, t3;
527
528 if (ctx->stack_len < 3)
8a3fe4f8 529 error (_("Not enough elements for DW_OP_rot. Need 3, have %d."),
4c2df51b
DJ
530 ctx->stack_len);
531 t1 = ctx->stack[ctx->stack_len - 1];
532 t2 = ctx->stack[ctx->stack_len - 2];
533 t3 = ctx->stack[ctx->stack_len - 3];
534 ctx->stack[ctx->stack_len - 1] = t2;
535 ctx->stack[ctx->stack_len - 2] = t3;
536 ctx->stack[ctx->stack_len - 3] = t1;
537 goto no_push;
538 }
539
540 case DW_OP_deref:
541 case DW_OP_deref_size:
542 case DW_OP_abs:
543 case DW_OP_neg:
544 case DW_OP_not:
545 case DW_OP_plus_uconst:
546 /* Unary operations. */
547 result = dwarf_expr_fetch (ctx, 0);
548 dwarf_expr_pop (ctx);
549
550 switch (op)
551 {
552 case DW_OP_deref:
553 {
17a912b6
UW
554 gdb_byte *buf = alloca (gdbarch_addr_bit (current_gdbarch)
555 / TARGET_CHAR_BIT);
4c2df51b
DJ
556 int bytes_read;
557
558 (ctx->read_mem) (ctx->baton, buf, result,
17a912b6
UW
559 gdbarch_addr_bit (current_gdbarch)
560 / TARGET_CHAR_BIT);
0d53c4c4 561 result = dwarf2_read_address (buf,
17a912b6
UW
562 buf + (gdbarch_addr_bit
563 (current_gdbarch)
0d53c4c4
DJ
564 / TARGET_CHAR_BIT),
565 &bytes_read);
4c2df51b
DJ
566 }
567 break;
568
569 case DW_OP_deref_size:
570 {
17a912b6
UW
571 gdb_byte *buf
572 = alloca (gdbarch_addr_bit (current_gdbarch)
573 / TARGET_CHAR_BIT);
4c2df51b
DJ
574 int bytes_read;
575
576 (ctx->read_mem) (ctx->baton, buf, result, *op_ptr++);
0d53c4c4 577 result = dwarf2_read_address (buf,
17a912b6
UW
578 buf + (gdbarch_addr_bit
579 (current_gdbarch)
0d53c4c4
DJ
580 / TARGET_CHAR_BIT),
581 &bytes_read);
4c2df51b
DJ
582 }
583 break;
584
585 case DW_OP_abs:
586 if ((signed int) result < 0)
587 result = -result;
588 break;
589 case DW_OP_neg:
590 result = -result;
591 break;
592 case DW_OP_not:
593 result = ~result;
594 break;
595 case DW_OP_plus_uconst:
596 op_ptr = read_uleb128 (op_ptr, op_end, &reg);
597 result += reg;
598 break;
599 }
600 break;
601
602 case DW_OP_and:
603 case DW_OP_div:
604 case DW_OP_minus:
605 case DW_OP_mod:
606 case DW_OP_mul:
607 case DW_OP_or:
608 case DW_OP_plus:
609 case DW_OP_shl:
610 case DW_OP_shr:
611 case DW_OP_shra:
612 case DW_OP_xor:
613 case DW_OP_le:
614 case DW_OP_ge:
615 case DW_OP_eq:
616 case DW_OP_lt:
617 case DW_OP_gt:
618 case DW_OP_ne:
619 {
620 /* Binary operations. Use the value engine to do computations in
621 the right width. */
622 CORE_ADDR first, second;
623 enum exp_opcode binop;
624 struct value *val1, *val2;
625
626 second = dwarf_expr_fetch (ctx, 0);
627 dwarf_expr_pop (ctx);
628
b263358a 629 first = dwarf_expr_fetch (ctx, 0);
4c2df51b
DJ
630 dwarf_expr_pop (ctx);
631
632 val1 = value_from_longest (unsigned_address_type (), first);
633 val2 = value_from_longest (unsigned_address_type (), second);
634
635 switch (op)
636 {
637 case DW_OP_and:
638 binop = BINOP_BITWISE_AND;
639 break;
640 case DW_OP_div:
641 binop = BINOP_DIV;
99c87dab 642 break;
4c2df51b
DJ
643 case DW_OP_minus:
644 binop = BINOP_SUB;
645 break;
646 case DW_OP_mod:
647 binop = BINOP_MOD;
648 break;
649 case DW_OP_mul:
650 binop = BINOP_MUL;
651 break;
652 case DW_OP_or:
653 binop = BINOP_BITWISE_IOR;
654 break;
655 case DW_OP_plus:
656 binop = BINOP_ADD;
657 break;
658 case DW_OP_shl:
659 binop = BINOP_LSH;
660 break;
661 case DW_OP_shr:
662 binop = BINOP_RSH;
99c87dab 663 break;
4c2df51b
DJ
664 case DW_OP_shra:
665 binop = BINOP_RSH;
666 val1 = value_from_longest (signed_address_type (), first);
667 break;
668 case DW_OP_xor:
669 binop = BINOP_BITWISE_XOR;
670 break;
671 case DW_OP_le:
672 binop = BINOP_LEQ;
673 break;
674 case DW_OP_ge:
675 binop = BINOP_GEQ;
676 break;
677 case DW_OP_eq:
678 binop = BINOP_EQUAL;
679 break;
680 case DW_OP_lt:
681 binop = BINOP_LESS;
682 break;
683 case DW_OP_gt:
684 binop = BINOP_GTR;
685 break;
686 case DW_OP_ne:
687 binop = BINOP_NOTEQUAL;
688 break;
689 default:
690 internal_error (__FILE__, __LINE__,
e2e0b3e5 691 _("Can't be reached."));
4c2df51b
DJ
692 }
693 result = value_as_long (value_binop (val1, val2, binop));
694 }
695 break;
696
697 case DW_OP_GNU_push_tls_address:
c3228f12
EZ
698 /* Variable is at a constant offset in the thread-local
699 storage block into the objfile for the current thread and
700 the dynamic linker module containing this expression. Here
701 we return returns the offset from that base. The top of the
702 stack has the offset from the beginning of the thread
703 control block at which the variable is located. Nothing
704 should follow this operator, so the top of stack would be
705 returned. */
4c2df51b
DJ
706 result = dwarf_expr_fetch (ctx, 0);
707 dwarf_expr_pop (ctx);
708 result = (ctx->get_tls_address) (ctx->baton, result);
709 break;
710
711 case DW_OP_skip:
712 offset = extract_signed_integer (op_ptr, 2);
713 op_ptr += 2;
714 op_ptr += offset;
715 goto no_push;
716
717 case DW_OP_bra:
718 offset = extract_signed_integer (op_ptr, 2);
719 op_ptr += 2;
720 if (dwarf_expr_fetch (ctx, 0) != 0)
721 op_ptr += offset;
722 dwarf_expr_pop (ctx);
723 goto no_push;
724
725 case DW_OP_nop:
726 goto no_push;
727
87808bd6
JB
728 case DW_OP_piece:
729 {
730 ULONGEST size;
731 CORE_ADDR addr_or_regnum;
732
733 /* Record the piece. */
734 op_ptr = read_uleb128 (op_ptr, op_end, &size);
735 addr_or_regnum = dwarf_expr_fetch (ctx, 0);
736 add_piece (ctx, ctx->in_reg, addr_or_regnum, size);
737
738 /* Pop off the address/regnum, and clear the in_reg flag. */
739 dwarf_expr_pop (ctx);
740 ctx->in_reg = 0;
741 }
742 goto no_push;
743
42be36b3
CT
744 case DW_OP_GNU_uninit:
745 if (op_ptr != op_end)
746 error (_("DWARF-2 expression error: DW_OP_GNU_unint must always "
747 "be the very last op."));
748
749 ctx->initialized = 0;
750 goto no_push;
751
4c2df51b 752 default:
8a3fe4f8 753 error (_("Unhandled dwarf expression opcode 0x%x"), op);
4c2df51b
DJ
754 }
755
756 /* Most things push a result value. */
757 dwarf_expr_push (ctx, result);
758 no_push:;
759 }
760}
This page took 0.423996 seconds and 4 git commands to generate.