27 #ifdef IN_PROCESS_AGENT
38 vsprintf (buf, fmt, ap);
39 fprintf (stderr,
PROG "/ax: %s\n", buf);
43 #define ax_debug_1(level, fmt, args...) \
45 if (level <= debug_threads) \
46 ax_vdebug ((fmt), ##args); \
49 #define ax_debug(FMT, args...) \
50 ax_debug_1 (1, FMT, ##args)
57 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \
58 gdb_agent_op_ ## NAME = VALUE,
67 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) , # NAME
75 #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) , SIZE
87 return gdb_agent_op_names[op];
90 #ifndef IN_PROCESS_AGENT
109 *actparm = act + (xlen * 2);
382 for (i = 0; i < aexpr->
length; i += 1 + gdb_agent_op_sizes[op])
384 op = aexpr->
bytes[i];
386 if (op == gdb_agent_op_goto || op == gdb_agent_op_if_goto)
388 int target = (aexpr->
bytes[i + 1] << 8) + aexpr->
bytes[i + 2];
404 unsigned char op, next_op;
413 ax_debug ("Cannot compile op 0x%x\n", op); \
414 return expr_eval_unhandled_opcode; \
419 ax_debug (
"empty agent expression\n");
429 ax_debug (
"About to compile op 0x%x, pc=%d\n", op, pc);
447 case gdb_agent_op_add:
451 case gdb_agent_op_sub:
455 case gdb_agent_op_mul:
459 case gdb_agent_op_div_signed:
463 case gdb_agent_op_div_unsigned:
467 case gdb_agent_op_rem_signed:
471 case gdb_agent_op_rem_unsigned:
475 case gdb_agent_op_lsh:
479 case gdb_agent_op_rsh_signed:
483 case gdb_agent_op_rsh_unsigned:
487 case gdb_agent_op_trace:
491 case gdb_agent_op_trace_quick:
495 case gdb_agent_op_log_not:
499 case gdb_agent_op_bit_and:
503 case gdb_agent_op_bit_or:
507 case gdb_agent_op_bit_xor:
511 case gdb_agent_op_bit_not:
515 case gdb_agent_op_equal:
517 if (next_op == gdb_agent_op_if_goto
521 ax_debug (
"Combining equal & if_goto");
524 arg = aexpr->
bytes[pc++];
525 arg = (arg << 8) + aexpr->
bytes[pc++];
529 else if (next_op == gdb_agent_op_log_not
530 && (aexpr->
bytes[pc + 1] == gdb_agent_op_if_goto)
534 ax_debug (
"Combining equal & log_not & if_goto");
537 arg = aexpr->
bytes[pc++];
538 arg = (arg << 8) + aexpr->
bytes[pc++];
546 case gdb_agent_op_less_signed:
548 if (next_op == gdb_agent_op_if_goto
551 ax_debug (
"Combining less_signed & if_goto");
554 arg = aexpr->
bytes[pc++];
555 arg = (arg << 8) + aexpr->
bytes[pc++];
559 else if (next_op == gdb_agent_op_log_not
561 && (aexpr->
bytes[pc + 1] == gdb_agent_op_if_goto)
564 ax_debug (
"Combining less_signed & log_not & if_goto");
567 arg = aexpr->
bytes[pc++];
568 arg = (arg << 8) + aexpr->
bytes[pc++];
576 case gdb_agent_op_less_unsigned:
580 case gdb_agent_op_ext:
581 arg = aexpr->
bytes[pc++];
582 if (arg < (
sizeof (
LONGEST) * 8))
586 case gdb_agent_op_ref8:
590 case gdb_agent_op_ref16:
594 case gdb_agent_op_ref32:
598 case gdb_agent_op_ref64:
602 case gdb_agent_op_if_goto:
603 arg = aexpr->
bytes[pc++];
604 arg = (arg << 8) + aexpr->
bytes[pc++];
609 case gdb_agent_op_goto:
610 arg = aexpr->
bytes[pc++];
611 arg = (arg << 8) + aexpr->
bytes[pc++];
616 case gdb_agent_op_const8:
618 top = aexpr->
bytes[pc++];
622 case gdb_agent_op_const16:
624 top = aexpr->
bytes[pc++];
625 top = (top << 8) + aexpr->
bytes[pc++];
629 case gdb_agent_op_const32:
631 top = 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_const64:
640 top = aexpr->
bytes[pc++];
641 top = (top << 8) + aexpr->
bytes[pc++];
642 top = (top << 8) + aexpr->
bytes[pc++];
643 top = (top << 8) + aexpr->
bytes[pc++];
644 top = (top << 8) + aexpr->
bytes[pc++];
645 top = (top << 8) + aexpr->
bytes[pc++];
646 top = (top << 8) + aexpr->
bytes[pc++];
647 top = (top << 8) + aexpr->
bytes[pc++];
651 case gdb_agent_op_reg:
653 arg = aexpr->
bytes[pc++];
654 arg = (arg << 8) + aexpr->
bytes[pc++];
658 case gdb_agent_op_end:
659 ax_debug (
"At end of expression\n");
668 case gdb_agent_op_dup:
673 case gdb_agent_op_pop:
677 case gdb_agent_op_zero_ext:
678 arg = aexpr->
bytes[pc++];
679 if (arg < (
sizeof (
LONGEST) * 8))
683 case gdb_agent_op_swap:
686 if (next_op == gdb_agent_op_less_signed
688 && (aexpr->
bytes[pc + 1] == gdb_agent_op_if_goto)
691 ax_debug (
"Combining swap & less_signed & if_goto");
694 arg = aexpr->
bytes[pc++];
695 arg = (arg << 8) + aexpr->
bytes[pc++];
699 else if (next_op == gdb_agent_op_less_signed
701 && (aexpr->
bytes[pc + 1] == gdb_agent_op_log_not)
703 && (aexpr->
bytes[pc + 2] == gdb_agent_op_if_goto)
706 ax_debug (
"Combining swap & less_signed & log_not & if_goto");
709 arg = aexpr->
bytes[pc++];
710 arg = (arg << 8) + aexpr->
bytes[pc++];
718 case gdb_agent_op_getv:
720 arg = aexpr->
bytes[pc++];
721 arg = (arg << 8) + aexpr->
bytes[pc++];
726 case gdb_agent_op_setv:
727 arg = aexpr->
bytes[pc++];
728 arg = (arg << 8) + aexpr->
bytes[pc++];
733 case gdb_agent_op_tracev:
738 case gdb_agent_op_float:
739 case gdb_agent_op_ref_float:
740 case gdb_agent_op_ref_double:
741 case gdb_agent_op_ref_long_double:
742 case gdb_agent_op_l_to_d:
743 case gdb_agent_op_d_to_l:
744 case gdb_agent_op_trace16:
749 ax_debug (
"Agent expression op 0x%x not recognized\n", op);
758 ax_debug (
"Error %d while emitting code for %s\n",
781 ax_debug (
"Want to jump from %s to %s\n",
794 ax_debug (
"Destination of goto %d not found\n",
816 const char *f = format;
819 char *current_substring;
822 ax_debug (
"Printf of \"%s\" with %d args", format, nargs);
827 for (fp = 0; fpieces[fp].
string != NULL; fp++)
831 if (nargs != nargs_wanted)
832 error (
_(
"Wrong number of arguments for specified format-string"));
835 for (fp = 0; fpieces[fp].
string != NULL; fp++)
837 current_substring = fpieces[fp].
string;
838 ax_debug (
"current substring is '%s', class is %d",
839 current_substring, fpieces[fp].
argclass);
840 switch (fpieces[fp].argclass)
866 printf (current_substring, (
char *) str);
871 #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
873 long long val = args[i];
875 printf (current_substring, val);
879 error (
_(
"long long not supported in agent printf"));
885 printf (current_substring, val);
893 printf (current_substring, val);
906 printf (current_substring, 0);
910 error (
_(
"Format directive in '%s' not supported in agent printf"),
933 #define STACK_MAX 100
947 unsigned char bytes[1];
952 unsigned char bytes[2];
957 unsigned char bytes[4];
962 unsigned char bytes[8];
969 ax_debug (
"empty agent expression");
980 op = aexpr->
bytes[pc++];
982 ax_debug (
"About to interpret byte 0x%x", op);
986 case gdb_agent_op_add:
990 case gdb_agent_op_sub:
991 top = stack[--sp] - top;
994 case gdb_agent_op_mul:
998 case gdb_agent_op_div_signed:
1001 ax_debug (
"Attempted to divide by zero");
1007 case gdb_agent_op_div_unsigned:
1010 ax_debug (
"Attempted to divide by zero");
1013 top = stack[--sp] / top;
1016 case gdb_agent_op_rem_signed:
1019 ax_debug (
"Attempted to divide by zero");
1025 case gdb_agent_op_rem_unsigned:
1028 ax_debug (
"Attempted to divide by zero");
1031 top = stack[--sp] % top;
1034 case gdb_agent_op_lsh:
1035 top = stack[--sp] << top;
1038 case gdb_agent_op_rsh_signed:
1039 top = ((
LONGEST) stack[--sp]) >> top;
1042 case gdb_agent_op_rsh_unsigned:
1043 top = stack[--sp] >> top;
1046 case gdb_agent_op_trace:
1053 case gdb_agent_op_trace_quick:
1054 arg = aexpr->
bytes[pc++];
1058 case gdb_agent_op_log_not:
1062 case gdb_agent_op_bit_and:
1066 case gdb_agent_op_bit_or:
1070 case gdb_agent_op_bit_xor:
1074 case gdb_agent_op_bit_not:
1078 case gdb_agent_op_equal:
1079 top = (stack[--sp] == top);
1082 case gdb_agent_op_less_signed:
1086 case gdb_agent_op_less_unsigned:
1087 top = (stack[--sp] < top);
1090 case gdb_agent_op_ext:
1091 arg = aexpr->
bytes[pc++];
1092 if (arg < (
sizeof (
LONGEST) * 8))
1094 LONGEST mask = 1 << (arg - 1);
1095 top &= ((
LONGEST) 1 << arg) - 1;
1096 top = (top ^ mask) - mask;
1100 case gdb_agent_op_ref8:
1105 case gdb_agent_op_ref16:
1110 case gdb_agent_op_ref32:
1115 case gdb_agent_op_ref64:
1120 case gdb_agent_op_if_goto:
1122 pc = (aexpr->
bytes[pc] << 8) + (aexpr->
bytes[pc + 1]);
1129 case gdb_agent_op_goto:
1130 pc = (aexpr->
bytes[pc] << 8) + (aexpr->
bytes[pc + 1]);
1133 case gdb_agent_op_const8:
1136 top = aexpr->
bytes[pc++];
1139 case gdb_agent_op_const16:
1142 top = aexpr->
bytes[pc++];
1143 top = (top << 8) + aexpr->
bytes[pc++];
1146 case gdb_agent_op_const32:
1149 top = aexpr->
bytes[pc++];
1150 top = (top << 8) + aexpr->
bytes[pc++];
1151 top = (top << 8) + aexpr->
bytes[pc++];
1152 top = (top << 8) + aexpr->
bytes[pc++];
1155 case gdb_agent_op_const64:
1158 top = aexpr->
bytes[pc++];
1159 top = (top << 8) + aexpr->
bytes[pc++];
1160 top = (top << 8) + aexpr->
bytes[pc++];
1161 top = (top << 8) + aexpr->
bytes[pc++];
1162 top = (top << 8) + aexpr->
bytes[pc++];
1163 top = (top << 8) + aexpr->
bytes[pc++];
1164 top = (top << 8) + aexpr->
bytes[pc++];
1165 top = (top << 8) + aexpr->
bytes[pc++];
1168 case gdb_agent_op_reg:
1171 arg = aexpr->
bytes[pc++];
1172 arg = (arg << 8) + aexpr->
bytes[pc++];
1197 "unhandled register size");
1202 case gdb_agent_op_end:
1203 ax_debug (
"At end of expression, sp=%d, stack top cache=0x%s",
1210 ax_debug (
"Stack is empty, nothing to return");
1217 case gdb_agent_op_dup:
1221 case gdb_agent_op_pop:
1226 case gdb_agent_op_pick:
1227 arg = aexpr->
bytes[pc++];
1229 top = stack[sp - arg];
1233 case gdb_agent_op_rot:
1237 stack[sp - 1] = stack[sp - 2];
1238 stack[sp - 2] = top;
1243 case gdb_agent_op_zero_ext:
1244 arg = aexpr->
bytes[pc++];
1245 if (arg < (
sizeof (
LONGEST) * 8))
1246 top &= ((
LONGEST) 1 << arg) - 1;
1249 case gdb_agent_op_swap:
1253 top = stack[sp - 1];
1254 stack[sp - 1] = stack[sp];
1257 case gdb_agent_op_getv:
1260 arg = aexpr->
bytes[pc++];
1261 arg = (arg << 8) + aexpr->
bytes[pc++];
1265 case gdb_agent_op_setv:
1266 arg = aexpr->
bytes[pc++];
1267 arg = (arg << 8) + aexpr->
bytes[pc++];
1273 case gdb_agent_op_tracev:
1274 arg = aexpr->
bytes[pc++];
1275 arg = (arg << 8) + aexpr->
bytes[pc++];
1279 case gdb_agent_op_tracenz:
1286 case gdb_agent_op_printf:
1294 nargs = aexpr->
bytes[pc++];
1295 slen = aexpr->
bytes[pc++];
1296 slen = (slen << 8) + aexpr->
bytes[pc++];
1297 format = (
char *) &(aexpr->
bytes[pc]);
1307 for (i = 0; i < nargs; ++i)
1316 if (format[slen - 1] !=
'\0')
1317 error (
_(
"Unterminated format string in printf bytecode"));
1319 ax_printf (fn, chan, format, nargs, args);
1324 case gdb_agent_op_float:
1325 case gdb_agent_op_ref_float:
1326 case gdb_agent_op_ref_double:
1327 case gdb_agent_op_ref_long_double:
1328 case gdb_agent_op_l_to_d:
1329 case gdb_agent_op_d_to_l:
1330 case gdb_agent_op_trace16:
1331 ax_debug (
"Agent expression op 0x%x valid, but not handled",
1338 ax_debug (
"Agent expression op 0x%x not recognized", op);
1346 ax_debug (
"Expression stack overflow");
1352 ax_debug (
"Expression stack underflow");
1356 ax_debug (
"Op %s -> sp=%d, top=0x%s",
const struct target_desc * tdesc
LONGEST agent_get_trace_state_variable_value(int num)
CORE_ADDR get_set_tsv_func_addr(void)
void collect_register(struct regcache *regcache, int n, void *buf)
static void emit_sub(void)
static void ax_vdebug(const char *,...)
static void emit_ge_goto(int *offset_p, int *size_p)
static void emit_bit_and(void)
#define target_emit_ops()
int bin2hex(const gdb_byte *bin, char *hex, int count)
void internal_error(const char *file, int line, const char *fmt,...)
int agent_mem_read(struct eval_agent_expr_context *ctx, unsigned char *to, CORE_ADDR from, ULONGEST len)
enum eval_result_type compile_bytecodes(struct agent_expr *aexpr)
struct bytecode_address * bytecode_address_table
char * paddress(CORE_ADDR addr)
static void emit_gt_goto(int *offset_p, int *size_p)
static void emit_ne_goto(int *offset_p, int *size_p)
void agent_set_trace_state_variable_value(int num, LONGEST val)
static void ax_printf(CORE_ADDR fn, CORE_ADDR chan, const char *format, int nargs, ULONGEST *args)
static void emit_stack_adjust(int n)
static void emit_log_not(void)
static void emit_less_unsigned(void)
static void emit_less_signed(void)
static void emit_eq_goto(int *offset_p, int *size_p)
static void emit_equal(void)
int agent_tsv_read(struct eval_agent_expr_context *ctx, int n)
static void emit_lsh(void)
static void emit_mul(void)
int agent_mem_read_string(struct eval_agent_expr_context *ctx, unsigned char *to, CORE_ADDR from, ULONGEST len)
static void emit_rsh_unsigned(void)
CORE_ADDR current_insn_ptr
int read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
static void emit_if_goto(int *offset_p, int *size_p)
char * pulongest(ULONGEST u)
static void emit_le_goto(int *offset_p, int *size_p)
int register_size(const struct target_desc *tdesc, int n)
int is_goto_target(struct agent_expr *aexpr, int pc)
static void emit_bit_not(void)
static void emit_int_call_1(CORE_ADDR fn, int arg1)
static void emit_void_call_2(CORE_ADDR fn, int arg1)
enum eval_result_type gdb_eval_agent_expr(struct eval_agent_expr_context *ctx, struct agent_expr *aexpr, ULONGEST *rslt)
static void emit_ext(int arg)
static void emit_bit_xor(void)
char * unpack_varlen_hex(char *buff, ULONGEST *result)
static void emit_add(void)
struct bytecode_address * next
struct agent_expr * gdb_parse_agent_expr(char **actparm)
static void ATTRIBUTE_PRINTF(1, 2)
static void emit_zero_ext(int arg)
static void emit_bit_or(void)
char * phex_nz(ULONGEST l, int sizeof_l)
static void emit_stack_flush(void)
void gdb_free_agent_expr(struct agent_expr *aexpr)
static const char * gdb_agent_op_name(int op)
static void emit_lt_goto(int *offset_p, int *size_p)
static void emit_const(LONGEST num)
static void emit_pop(void)
#define ax_debug(FMT, args...)
unsigned long long ULONGEST
char * gdb_unparse_agent_expr(struct agent_expr *aexpr)
int hex2bin(const char *hex, gdb_byte *bin, int count)
static void emit_reg(int reg)
CORE_ADDR get_get_tsv_func_addr(void)
static void emit_rsh_signed(void)
static void emit_swap(void)
static void emit_ref(int size)
struct regcache * regcache
void error(const char *fmt,...)
static void write_goto_address(CORE_ADDR from, CORE_ADDR to, int size)
static void emit_goto(int *offset_p, int *size_p)