1 /* Agent expression code for remote server.
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 static void ax_vdebug (const char *, ...) ATTR_FORMAT (printf
, 1, 2);
24 #ifdef IN_PROCESS_AGENT
29 ax_vdebug (const char *fmt
, ...)
35 vsprintf (buf
, fmt
, ap
);
36 fprintf (stderr
, PROG
"/ax: %s\n", buf
);
40 #define ax_debug_1(level, fmt, args...) \
42 if (level <= debug_threads) \
43 ax_vdebug ((fmt), ##args); \
46 #define ax_debug(FMT, args...) \
47 ax_debug_1 (1, FMT, ##args)
49 /* This enum must exactly match what is documented in
50 gdb/doc/agentexpr.texi, including all the numerical values. */
54 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \
55 gdb_agent_op_ ## NAME = VALUE,
61 static const char *gdb_agent_op_names
[gdb_agent_op_last
] =
64 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) , # NAME
69 static const unsigned char gdb_agent_op_sizes
[gdb_agent_op_last
] =
72 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) , SIZE
77 /* A wrapper for gdb_agent_op_names that does some bounds-checking. */
80 gdb_agent_op_name (int op
)
82 if (op
< 0 || op
>= gdb_agent_op_last
|| gdb_agent_op_names
[op
] == NULL
)
84 return gdb_agent_op_names
[op
];
87 #ifndef IN_PROCESS_AGENT
89 /* The packet form of an agent expression consists of an 'X', number
90 of bytes in expression, a comma, and then the bytes. */
93 gdb_parse_agent_expr (char **actparm
)
97 struct agent_expr
*aexpr
;
99 ++act
; /* skip the X */
100 act
= unpack_varlen_hex (act
, &xlen
);
101 ++act
; /* skip a comma */
102 aexpr
= xmalloc (sizeof (struct agent_expr
));
103 aexpr
->length
= xlen
;
104 aexpr
->bytes
= xmalloc (xlen
);
105 convert_ascii_to_int (act
, aexpr
->bytes
, xlen
);
106 *actparm
= act
+ (xlen
* 2);
110 /* Convert the bytes of an agent expression back into hex digits, so
111 they can be printed or uploaded. This allocates the buffer,
112 callers should free when they are done with it. */
115 gdb_unparse_agent_expr (struct agent_expr
*aexpr
)
119 rslt
= xmalloc (2 * aexpr
->length
+ 1);
120 convert_int_to_ascii (aexpr
->bytes
, rslt
, aexpr
->length
);
124 /* Bytecode compilation. */
126 CORE_ADDR current_insn_ptr
;
130 struct bytecode_address
135 /* Offset and size of field to be modified in the goto block. */
136 int from_offset
, from_size
;
137 struct bytecode_address
*next
;
138 } *bytecode_address_table
;
143 target_emit_ops ()->emit_prologue ();
149 target_emit_ops ()->emit_epilogue ();
155 target_emit_ops ()->emit_add ();
161 target_emit_ops ()->emit_sub ();
167 target_emit_ops ()->emit_mul ();
173 target_emit_ops ()->emit_lsh ();
177 emit_rsh_signed (void)
179 target_emit_ops ()->emit_rsh_signed ();
183 emit_rsh_unsigned (void)
185 target_emit_ops ()->emit_rsh_unsigned ();
191 target_emit_ops ()->emit_ext (arg
);
197 target_emit_ops ()->emit_log_not ();
203 target_emit_ops ()->emit_bit_and ();
209 target_emit_ops ()->emit_bit_or ();
215 target_emit_ops ()->emit_bit_xor ();
221 target_emit_ops ()->emit_bit_not ();
227 target_emit_ops ()->emit_equal ();
231 emit_less_signed (void)
233 target_emit_ops ()->emit_less_signed ();
237 emit_less_unsigned (void)
239 target_emit_ops ()->emit_less_unsigned ();
245 target_emit_ops ()->emit_ref (size
);
249 emit_if_goto (int *offset_p
, int *size_p
)
251 target_emit_ops ()->emit_if_goto (offset_p
, size_p
);
255 emit_goto (int *offset_p
, int *size_p
)
257 target_emit_ops ()->emit_goto (offset_p
, size_p
);
261 write_goto_address (CORE_ADDR from
, CORE_ADDR to
, int size
)
263 target_emit_ops ()->write_goto_address (from
, to
, size
);
267 emit_const (LONGEST num
)
269 target_emit_ops ()->emit_const (num
);
275 target_emit_ops ()->emit_reg (reg
);
281 target_emit_ops ()->emit_pop ();
285 emit_stack_flush (void)
287 target_emit_ops ()->emit_stack_flush ();
291 emit_zero_ext (int arg
)
293 target_emit_ops ()->emit_zero_ext (arg
);
299 target_emit_ops ()->emit_swap ();
303 emit_stack_adjust (int n
)
305 target_emit_ops ()->emit_stack_adjust (n
);
308 /* FN's prototype is `LONGEST(*fn)(int)'. */
311 emit_int_call_1 (CORE_ADDR fn
, int arg1
)
313 target_emit_ops ()->emit_int_call_1 (fn
, arg1
);
316 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
319 emit_void_call_2 (CORE_ADDR fn
, int arg1
)
321 target_emit_ops ()->emit_void_call_2 (fn
, arg1
);
325 emit_eq_goto (int *offset_p
, int *size_p
)
327 target_emit_ops ()->emit_eq_goto (offset_p
, size_p
);
331 emit_ne_goto (int *offset_p
, int *size_p
)
333 target_emit_ops ()->emit_ne_goto (offset_p
, size_p
);
337 emit_lt_goto (int *offset_p
, int *size_p
)
339 target_emit_ops ()->emit_lt_goto (offset_p
, size_p
);
343 emit_ge_goto (int *offset_p
, int *size_p
)
345 target_emit_ops ()->emit_ge_goto (offset_p
, size_p
);
349 emit_gt_goto (int *offset_p
, int *size_p
)
351 target_emit_ops ()->emit_gt_goto (offset_p
, size_p
);
355 emit_le_goto (int *offset_p
, int *size_p
)
357 target_emit_ops ()->emit_le_goto (offset_p
, size_p
);
360 /* Scan an agent expression for any evidence that the given PC is the
361 target of a jump bytecode in the expression. */
364 is_goto_target (struct agent_expr
*aexpr
, int pc
)
369 for (i
= 0; i
< aexpr
->length
; i
+= 1 + gdb_agent_op_sizes
[op
])
371 op
= aexpr
->bytes
[i
];
373 if (op
== gdb_agent_op_goto
|| op
== gdb_agent_op_if_goto
)
375 int target
= (aexpr
->bytes
[i
+ 1] << 8) + aexpr
->bytes
[i
+ 2];
384 /* Given an agent expression, turn it into native code. */
386 enum eval_result_type
387 compile_bytecodes (struct agent_expr
*aexpr
)
391 unsigned char op
, next_op
;
393 /* This is only used to build 64-bit value for constants. */
395 struct bytecode_address
*aentry
, *aentry2
;
400 ax_debug ("Cannot compile op 0x%x\n", op); \
401 return expr_eval_unhandled_opcode; \
404 if (aexpr
->length
== 0)
406 ax_debug ("empty agent expression\n");
407 return expr_eval_empty_expression
;
410 bytecode_address_table
= NULL
;
414 op
= aexpr
->bytes
[pc
];
416 ax_debug ("About to compile op 0x%x, pc=%d\n", op
, pc
);
418 /* Record the compiled-code address of the bytecode, for use by
419 jump instructions. */
420 aentry
= xmalloc (sizeof (struct bytecode_address
));
422 aentry
->address
= current_insn_ptr
;
423 aentry
->goto_pc
= -1;
424 aentry
->from_offset
= aentry
->from_size
= 0;
425 aentry
->next
= bytecode_address_table
;
426 bytecode_address_table
= aentry
;
434 case gdb_agent_op_add
:
438 case gdb_agent_op_sub
:
442 case gdb_agent_op_mul
:
446 case gdb_agent_op_div_signed
:
450 case gdb_agent_op_div_unsigned
:
454 case gdb_agent_op_rem_signed
:
458 case gdb_agent_op_rem_unsigned
:
462 case gdb_agent_op_lsh
:
466 case gdb_agent_op_rsh_signed
:
470 case gdb_agent_op_rsh_unsigned
:
471 emit_rsh_unsigned ();
474 case gdb_agent_op_trace
:
478 case gdb_agent_op_trace_quick
:
482 case gdb_agent_op_log_not
:
486 case gdb_agent_op_bit_and
:
490 case gdb_agent_op_bit_or
:
494 case gdb_agent_op_bit_xor
:
498 case gdb_agent_op_bit_not
:
502 case gdb_agent_op_equal
:
503 next_op
= aexpr
->bytes
[pc
];
504 if (next_op
== gdb_agent_op_if_goto
505 && !is_goto_target (aexpr
, pc
)
506 && target_emit_ops ()->emit_eq_goto
)
508 ax_debug ("Combining equal & if_goto");
511 arg
= aexpr
->bytes
[pc
++];
512 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
513 aentry
->goto_pc
= arg
;
514 emit_eq_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
516 else if (next_op
== gdb_agent_op_log_not
517 && (aexpr
->bytes
[pc
+ 1] == gdb_agent_op_if_goto
)
518 && !is_goto_target (aexpr
, pc
+ 1)
519 && target_emit_ops ()->emit_ne_goto
)
521 ax_debug ("Combining equal & log_not & if_goto");
524 arg
= aexpr
->bytes
[pc
++];
525 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
526 aentry
->goto_pc
= arg
;
527 emit_ne_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
533 case gdb_agent_op_less_signed
:
534 next_op
= aexpr
->bytes
[pc
];
535 if (next_op
== gdb_agent_op_if_goto
536 && !is_goto_target (aexpr
, pc
))
538 ax_debug ("Combining less_signed & if_goto");
541 arg
= aexpr
->bytes
[pc
++];
542 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
543 aentry
->goto_pc
= arg
;
544 emit_lt_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
546 else if (next_op
== gdb_agent_op_log_not
547 && !is_goto_target (aexpr
, pc
)
548 && (aexpr
->bytes
[pc
+ 1] == gdb_agent_op_if_goto
)
549 && !is_goto_target (aexpr
, pc
+ 1))
551 ax_debug ("Combining less_signed & log_not & if_goto");
554 arg
= aexpr
->bytes
[pc
++];
555 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
556 aentry
->goto_pc
= arg
;
557 emit_ge_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
563 case gdb_agent_op_less_unsigned
:
564 emit_less_unsigned ();
567 case gdb_agent_op_ext
:
568 arg
= aexpr
->bytes
[pc
++];
569 if (arg
< (sizeof (LONGEST
) * 8))
573 case gdb_agent_op_ref8
:
577 case gdb_agent_op_ref16
:
581 case gdb_agent_op_ref32
:
585 case gdb_agent_op_ref64
:
589 case gdb_agent_op_if_goto
:
590 arg
= aexpr
->bytes
[pc
++];
591 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
592 aentry
->goto_pc
= arg
;
593 emit_if_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
596 case gdb_agent_op_goto
:
597 arg
= aexpr
->bytes
[pc
++];
598 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
599 aentry
->goto_pc
= arg
;
600 emit_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
603 case gdb_agent_op_const8
:
605 top
= aexpr
->bytes
[pc
++];
609 case gdb_agent_op_const16
:
611 top
= aexpr
->bytes
[pc
++];
612 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
616 case gdb_agent_op_const32
:
618 top
= aexpr
->bytes
[pc
++];
619 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
620 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
621 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
625 case gdb_agent_op_const64
:
627 top
= aexpr
->bytes
[pc
++];
628 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
629 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
630 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
631 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
632 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
633 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
634 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
638 case gdb_agent_op_reg
:
640 arg
= aexpr
->bytes
[pc
++];
641 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
645 case gdb_agent_op_end
:
646 ax_debug ("At end of expression\n");
648 /* Assume there is one stack element left, and that it is
649 cached in "top" where emit_epilogue can get to it. */
650 emit_stack_adjust (1);
655 case gdb_agent_op_dup
:
656 /* In our design, dup is equivalent to stack flushing. */
660 case gdb_agent_op_pop
:
664 case gdb_agent_op_zero_ext
:
665 arg
= aexpr
->bytes
[pc
++];
666 if (arg
< (sizeof (LONGEST
) * 8))
670 case gdb_agent_op_swap
:
671 next_op
= aexpr
->bytes
[pc
];
672 /* Detect greater-than comparison sequences. */
673 if (next_op
== gdb_agent_op_less_signed
674 && !is_goto_target (aexpr
, pc
)
675 && (aexpr
->bytes
[pc
+ 1] == gdb_agent_op_if_goto
)
676 && !is_goto_target (aexpr
, pc
+ 1))
678 ax_debug ("Combining swap & less_signed & if_goto");
681 arg
= aexpr
->bytes
[pc
++];
682 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
683 aentry
->goto_pc
= arg
;
684 emit_gt_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
686 else if (next_op
== gdb_agent_op_less_signed
687 && !is_goto_target (aexpr
, pc
)
688 && (aexpr
->bytes
[pc
+ 1] == gdb_agent_op_log_not
)
689 && !is_goto_target (aexpr
, pc
+ 1)
690 && (aexpr
->bytes
[pc
+ 2] == gdb_agent_op_if_goto
)
691 && !is_goto_target (aexpr
, pc
+ 2))
693 ax_debug ("Combining swap & less_signed & log_not & if_goto");
696 arg
= aexpr
->bytes
[pc
++];
697 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
698 aentry
->goto_pc
= arg
;
699 emit_le_goto (&(aentry
->from_offset
), &(aentry
->from_size
));
705 case gdb_agent_op_getv
:
707 arg
= aexpr
->bytes
[pc
++];
708 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
709 emit_int_call_1 (get_get_tsv_func_addr (),
713 case gdb_agent_op_setv
:
714 arg
= aexpr
->bytes
[pc
++];
715 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
716 emit_void_call_2 (get_set_tsv_func_addr (),
720 case gdb_agent_op_tracev
:
724 /* GDB never (currently) generates any of these ops. */
725 case gdb_agent_op_float
:
726 case gdb_agent_op_ref_float
:
727 case gdb_agent_op_ref_double
:
728 case gdb_agent_op_ref_long_double
:
729 case gdb_agent_op_l_to_d
:
730 case gdb_agent_op_d_to_l
:
731 case gdb_agent_op_trace16
:
736 ax_debug ("Agent expression op 0x%x not recognized\n", op
);
737 /* Don't struggle on, things will just get worse. */
738 return expr_eval_unrecognized_opcode
;
741 /* This catches errors that occur in target-specific code
745 ax_debug ("Error %d while emitting code for %s\n",
746 emit_error
, gdb_agent_op_name (op
));
747 return expr_eval_unhandled_opcode
;
750 ax_debug ("Op %s compiled\n", gdb_agent_op_name (op
));
753 /* Now fill in real addresses as goto destinations. */
754 for (aentry
= bytecode_address_table
; aentry
; aentry
= aentry
->next
)
758 if (aentry
->goto_pc
< 0)
761 /* Find the location that we are going to, and call back into
762 target-specific code to write the actual address or
764 for (aentry2
= bytecode_address_table
; aentry2
; aentry2
= aentry2
->next
)
766 if (aentry2
->pc
== aentry
->goto_pc
)
768 ax_debug ("Want to jump from %s to %s\n",
769 paddress (aentry
->address
),
770 paddress (aentry2
->address
));
771 write_goto_address (aentry
->address
+ aentry
->from_offset
,
772 aentry2
->address
, aentry
->from_size
);
778 /* Error out if we didn't find a destination. */
781 ax_debug ("Destination of goto %d not found\n",
783 return expr_eval_invalid_goto
;
787 return expr_eval_no_error
;
792 /* The agent expression evaluator, as specified by the GDB docs. It
793 returns 0 if everything went OK, and a nonzero error code
796 enum eval_result_type
797 gdb_eval_agent_expr (struct regcache
*regcache
,
798 struct traceframe
*tframe
,
799 struct agent_expr
*aexpr
,
803 #define STACK_MAX 100
804 ULONGEST stack
[STACK_MAX
], top
;
809 /* This union is a convenient way to convert representations. For
810 now, assume a standard architecture where the hardware integer
811 types have 8, 16, 32, 64 bit types. A more robust solution would
812 be to import stdint.h from gnulib. */
817 unsigned char bytes
[1];
822 unsigned char bytes
[2];
827 unsigned char bytes
[4];
832 unsigned char bytes
[8];
837 if (aexpr
->length
== 0)
839 ax_debug ("empty agent expression");
840 return expr_eval_empty_expression
;
843 /* Cache the stack top in its own variable. Much of the time we can
844 operate on this variable, rather than dinking with the stack. It
845 needs to be copied to the stack when sp changes. */
850 op
= aexpr
->bytes
[pc
++];
852 ax_debug ("About to interpret byte 0x%x", op
);
856 case gdb_agent_op_add
:
860 case gdb_agent_op_sub
:
861 top
= stack
[--sp
] - top
;
864 case gdb_agent_op_mul
:
868 case gdb_agent_op_div_signed
:
871 ax_debug ("Attempted to divide by zero");
872 return expr_eval_divide_by_zero
;
874 top
= ((LONGEST
) stack
[--sp
]) / ((LONGEST
) top
);
877 case gdb_agent_op_div_unsigned
:
880 ax_debug ("Attempted to divide by zero");
881 return expr_eval_divide_by_zero
;
883 top
= stack
[--sp
] / top
;
886 case gdb_agent_op_rem_signed
:
889 ax_debug ("Attempted to divide by zero");
890 return expr_eval_divide_by_zero
;
892 top
= ((LONGEST
) stack
[--sp
]) % ((LONGEST
) top
);
895 case gdb_agent_op_rem_unsigned
:
898 ax_debug ("Attempted to divide by zero");
899 return expr_eval_divide_by_zero
;
901 top
= stack
[--sp
] % top
;
904 case gdb_agent_op_lsh
:
905 top
= stack
[--sp
] << top
;
908 case gdb_agent_op_rsh_signed
:
909 top
= ((LONGEST
) stack
[--sp
]) >> top
;
912 case gdb_agent_op_rsh_unsigned
:
913 top
= stack
[--sp
] >> top
;
916 case gdb_agent_op_trace
:
917 agent_mem_read (tframe
,
918 NULL
, (CORE_ADDR
) stack
[--sp
], (ULONGEST
) top
);
923 case gdb_agent_op_trace_quick
:
924 arg
= aexpr
->bytes
[pc
++];
925 agent_mem_read (tframe
, NULL
, (CORE_ADDR
) top
, (ULONGEST
) arg
);
928 case gdb_agent_op_log_not
:
932 case gdb_agent_op_bit_and
:
936 case gdb_agent_op_bit_or
:
940 case gdb_agent_op_bit_xor
:
944 case gdb_agent_op_bit_not
:
948 case gdb_agent_op_equal
:
949 top
= (stack
[--sp
] == top
);
952 case gdb_agent_op_less_signed
:
953 top
= (((LONGEST
) stack
[--sp
]) < ((LONGEST
) top
));
956 case gdb_agent_op_less_unsigned
:
957 top
= (stack
[--sp
] < top
);
960 case gdb_agent_op_ext
:
961 arg
= aexpr
->bytes
[pc
++];
962 if (arg
< (sizeof (LONGEST
) * 8))
964 LONGEST mask
= 1 << (arg
- 1);
965 top
&= ((LONGEST
) 1 << arg
) - 1;
966 top
= (top
^ mask
) - mask
;
970 case gdb_agent_op_ref8
:
971 agent_mem_read (tframe
, cnv
.u8
.bytes
, (CORE_ADDR
) top
, 1);
975 case gdb_agent_op_ref16
:
976 agent_mem_read (tframe
, cnv
.u16
.bytes
, (CORE_ADDR
) top
, 2);
980 case gdb_agent_op_ref32
:
981 agent_mem_read (tframe
, cnv
.u32
.bytes
, (CORE_ADDR
) top
, 4);
985 case gdb_agent_op_ref64
:
986 agent_mem_read (tframe
, cnv
.u64
.bytes
, (CORE_ADDR
) top
, 8);
990 case gdb_agent_op_if_goto
:
992 pc
= (aexpr
->bytes
[pc
] << 8) + (aexpr
->bytes
[pc
+ 1]);
999 case gdb_agent_op_goto
:
1000 pc
= (aexpr
->bytes
[pc
] << 8) + (aexpr
->bytes
[pc
+ 1]);
1003 case gdb_agent_op_const8
:
1004 /* Flush the cached stack top. */
1006 top
= aexpr
->bytes
[pc
++];
1009 case gdb_agent_op_const16
:
1010 /* Flush the cached stack top. */
1012 top
= aexpr
->bytes
[pc
++];
1013 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1016 case gdb_agent_op_const32
:
1017 /* Flush the cached stack top. */
1019 top
= aexpr
->bytes
[pc
++];
1020 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1021 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1022 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1025 case gdb_agent_op_const64
:
1026 /* Flush the cached stack top. */
1028 top
= aexpr
->bytes
[pc
++];
1029 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1030 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1031 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1032 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1033 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1034 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1035 top
= (top
<< 8) + aexpr
->bytes
[pc
++];
1038 case gdb_agent_op_reg
:
1039 /* Flush the cached stack top. */
1041 arg
= aexpr
->bytes
[pc
++];
1042 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
1046 switch (register_size (regnum
))
1049 collect_register (regcache
, regnum
, cnv
.u64
.bytes
);
1053 collect_register (regcache
, regnum
, cnv
.u32
.bytes
);
1057 collect_register (regcache
, regnum
, cnv
.u16
.bytes
);
1061 collect_register (regcache
, regnum
, cnv
.u8
.bytes
);
1065 internal_error (__FILE__
, __LINE__
,
1066 "unhandled register size");
1071 case gdb_agent_op_end
:
1072 ax_debug ("At end of expression, sp=%d, stack top cache=0x%s",
1073 sp
, pulongest (top
));
1078 /* This should be an error */
1079 ax_debug ("Stack is empty, nothing to return");
1080 return expr_eval_empty_stack
;
1084 return expr_eval_no_error
;
1086 case gdb_agent_op_dup
:
1090 case gdb_agent_op_pop
:
1095 case gdb_agent_op_pick
:
1096 arg
= aexpr
->bytes
[pc
++];
1098 top
= stack
[sp
- arg
];
1102 case gdb_agent_op_rot
:
1104 ULONGEST tem
= stack
[sp
- 1];
1106 stack
[sp
- 1] = stack
[sp
- 2];
1107 stack
[sp
- 2] = top
;
1112 case gdb_agent_op_zero_ext
:
1113 arg
= aexpr
->bytes
[pc
++];
1114 if (arg
< (sizeof (LONGEST
) * 8))
1115 top
&= ((LONGEST
) 1 << arg
) - 1;
1118 case gdb_agent_op_swap
:
1119 /* Interchange top two stack elements, making sure top gets
1120 copied back onto stack. */
1122 top
= stack
[sp
- 1];
1123 stack
[sp
- 1] = stack
[sp
];
1126 case gdb_agent_op_getv
:
1127 /* Flush the cached stack top. */
1129 arg
= aexpr
->bytes
[pc
++];
1130 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
1131 top
= agent_get_trace_state_variable_value (arg
);
1134 case gdb_agent_op_setv
:
1135 arg
= aexpr
->bytes
[pc
++];
1136 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
1137 agent_set_trace_state_variable_value (arg
, top
);
1138 /* Note that we leave the value on the stack, for the
1139 benefit of later/enclosing expressions. */
1142 case gdb_agent_op_tracev
:
1143 arg
= aexpr
->bytes
[pc
++];
1144 arg
= (arg
<< 8) + aexpr
->bytes
[pc
++];
1145 agent_tsv_read (tframe
, arg
);
1148 case gdb_agent_op_tracenz
:
1149 agent_mem_read_string (tframe
, NULL
, (CORE_ADDR
) stack
[--sp
],
1155 /* GDB never (currently) generates any of these ops. */
1156 case gdb_agent_op_float
:
1157 case gdb_agent_op_ref_float
:
1158 case gdb_agent_op_ref_double
:
1159 case gdb_agent_op_ref_long_double
:
1160 case gdb_agent_op_l_to_d
:
1161 case gdb_agent_op_d_to_l
:
1162 case gdb_agent_op_trace16
:
1163 ax_debug ("Agent expression op 0x%x valid, but not handled",
1165 /* If ever GDB generates any of these, we don't have the
1166 option of ignoring. */
1170 ax_debug ("Agent expression op 0x%x not recognized", op
);
1171 /* Don't struggle on, things will just get worse. */
1172 return expr_eval_unrecognized_opcode
;
1175 /* Check for stack badness. */
1176 if (sp
>= (STACK_MAX
- 1))
1178 ax_debug ("Expression stack overflow");
1179 return expr_eval_stack_overflow
;
1184 ax_debug ("Expression stack underflow");
1185 return expr_eval_stack_underflow
;
1188 ax_debug ("Op %s -> sp=%d, top=0x%s",
1189 gdb_agent_op_name (op
), sp
, pulongest (top
));