gdbserver crash if gdb attaches too fast
[deliverable/binutils-gdb.git] / gdb / gdbserver / ax.c
index 386df3ded0c6cbc5a31ea0c6de0ac11ba4009f18..4c9dadc4440fdb37a201b50a09058f4b3521c749 100644 (file)
@@ -1,5 +1,5 @@
 /* Agent expression code for remote server.
-   Copyright (C) 2009-2013 Free Software Foundation, Inc.
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -19,6 +19,8 @@
 #include "server.h"
 #include "ax.h"
 #include "format.h"
+#include "tracepoint.h"
+#include "rsp-low.h"
 
 static void ax_vdebug (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
 
@@ -67,6 +69,7 @@ static const char *gdb_agent_op_names [gdb_agent_op_last] =
 #undef DEFOP
   };
 
+#ifndef IN_PROCESS_AGENT
 static const unsigned char gdb_agent_op_sizes [gdb_agent_op_last] =
   {
     0
@@ -74,6 +77,7 @@ static const unsigned char gdb_agent_op_sizes [gdb_agent_op_last] =
 #include "ax.def"
 #undef DEFOP
   };
+#endif
 
 /* A wrapper for gdb_agent_op_names that does some bounds-checking.  */
 
@@ -100,14 +104,24 @@ gdb_parse_agent_expr (char **actparm)
   ++act;  /* skip the X */
   act = unpack_varlen_hex (act, &xlen);
   ++act;  /* skip a comma */
-  aexpr = xmalloc (sizeof (struct agent_expr));
+  aexpr = XNEW (struct agent_expr);
   aexpr->length = xlen;
-  aexpr->bytes = xmalloc (xlen);
-  convert_ascii_to_int (act, aexpr->bytes, xlen);
+  aexpr->bytes = (unsigned char *) xmalloc (xlen);
+  hex2bin (act, aexpr->bytes, xlen);
   *actparm = act + (xlen * 2);
   return aexpr;
 }
 
+void
+gdb_free_agent_expr (struct agent_expr *aexpr)
+{
+  if (aexpr != NULL)
+    {
+      free (aexpr->bytes);
+      free (aexpr);
+    }
+}
+
 /* Convert the bytes of an agent expression back into hex digits, so
    they can be printed or uploaded.  This allocates the buffer,
    callers should free when they are done with it.  */
@@ -117,8 +131,8 @@ gdb_unparse_agent_expr (struct agent_expr *aexpr)
 {
   char *rslt;
 
-  rslt = xmalloc (2 * aexpr->length + 1);
-  convert_int_to_ascii (aexpr->bytes, rslt, aexpr->length);
+  rslt = (char *) xmalloc (2 * aexpr->length + 1);
+  bin2hex (aexpr->bytes, rslt, aexpr->length);
   return rslt;
 }
 
@@ -418,7 +432,7 @@ compile_bytecodes (struct agent_expr *aexpr)
 
       /* Record the compiled-code address of the bytecode, for use by
         jump instructions.  */
-      aentry = xmalloc (sizeof (struct bytecode_address));
+      aentry = XNEW (struct bytecode_address);
       aentry->pc = pc;
       aentry->address = current_insn_ptr;
       aentry->goto_pc = -1;
@@ -798,10 +812,10 @@ compile_bytecodes (struct agent_expr *aexpr)
    in.  */
 
 static void
-ax_printf (CORE_ADDR fn, CORE_ADDR chan, char *format,
+ax_printf (CORE_ADDR fn, CORE_ADDR chan, const char *format,
           int nargs, ULONGEST *args)
 {
-  char *f = format;
+  const char *f = format;
   struct format_piece *fpieces;
   int i, fp;
   char *current_substring;
@@ -905,6 +919,7 @@ ax_printf (CORE_ADDR fn, CORE_ADDR chan, char *format,
     }
 
   free_format_pieces (fpieces);
+  fflush (stdout);
 }
 
 /* The agent expression evaluator, as specified by the GDB docs. It
@@ -1161,7 +1176,7 @@ gdb_eval_agent_expr (struct eval_agent_expr_context *ctx,
            int regnum = arg;
            struct regcache *regcache = ctx->regcache;
 
-           switch (register_size (regnum))
+           switch (register_size (regcache->tdesc, regnum))
              {
              case 8:
                collect_register (regcache, regnum, cnv.u64.bytes);
@@ -1319,7 +1334,7 @@ gdb_eval_agent_expr (struct eval_agent_expr_context *ctx,
                    op);
          /* If ever GDB generates any of these, we don't have the
             option of ignoring.  */
-         return 1;
+         return expr_eval_unhandled_opcode;
 
        default:
          ax_debug ("Agent expression op 0x%x not recognized", op);
This page took 0.025122 seconds and 4 git commands to generate.