gdbserver:prepare_access_memory: pick another thread
[deliverable/binutils-gdb.git] / gdb / gdbserver / tracepoint.c
index 27fcf032479d786c7d913ded36c6b0fbb1f8df56..9006a2ed1f2a8e2e332217191d67c38fb47c2596 100644 (file)
 #include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <sys/time.h>
+#include "gdb_sys_time.h"
 #include <inttypes.h>
-#include <stdint.h>
-
 #include "ax.h"
 #include "tdesc.h"
 
@@ -179,7 +177,6 @@ static struct
 {
   const char *name;
   int offset;
-  int required;
 } symbol_list[] = {
   IPA_SYM(gdb_tp_heap_buffer),
   IPA_SYM(gdb_jump_pad_buffer),
@@ -698,7 +695,7 @@ enum tracepoint_type
 
 struct tracepoint_hit_ctx;
 
-typedef enum eval_result_type (*condfn) (struct tracepoint_hit_ctx *,
+typedef enum eval_result_type (*condfn) (unsigned char *,
                                         ULONGEST *);
 
 /* The definition of a tracepoint.  */
@@ -851,7 +848,10 @@ IP_AGENT_EXPORT_VAR int trace_buffer_is_full;
 
 /* The first error that occurred during expression evaluation.  */
 
-IP_AGENT_EXPORT_VAR enum eval_result_type expr_eval_result = expr_eval_no_error;
+/* Stored as an int to avoid the IPA ABI being dependent on whatever
+   the compiler decides to use for the enum's underlying type.  Holds
+   enum eval_result_type values.  */
+IP_AGENT_EXPORT_VAR int expr_eval_result = expr_eval_no_error;
 
 EXTERN_C_POP
 
@@ -1497,7 +1497,7 @@ init_trace_buffer (LONGEST bufsize)
      marker.  */
   alloc_size = (bufsize < TRACEFRAME_EOB_MARKER_SIZE
                ? TRACEFRAME_EOB_MARKER_SIZE : bufsize);
-  trace_buffer_lo = xrealloc (trace_buffer_lo, alloc_size);
+  trace_buffer_lo = (unsigned char *) xrealloc (trace_buffer_lo, alloc_size);
 
   trace_buffer_hi = trace_buffer_lo + trace_buffer_size;
 
@@ -1803,7 +1803,7 @@ add_tracepoint (int num, CORE_ADDR addr)
 {
   struct tracepoint *tpoint, **tp_next;
 
-  tpoint = xmalloc (sizeof (struct tracepoint));
+  tpoint = XNEW (struct tracepoint);
   tpoint->number = num;
   tpoint->address = addr;
   tpoint->numactions = 0;
@@ -1938,11 +1938,11 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
        {
        case 'M':
          {
-           struct collect_memory_action *maction;
+           struct collect_memory_action *maction =
+             XNEW (struct collect_memory_action);
            ULONGEST basereg;
            int is_neg;
 
-           maction = xmalloc (sizeof *maction);
            maction->base.type = *act;
            maction->base.ops = &m_tracepoint_action_ops;
            action = &maction->base;
@@ -1966,9 +1966,9 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
          }
        case 'R':
          {
-           struct collect_registers_action *raction;
+           struct collect_registers_action *raction =
+             XNEW (struct collect_registers_action);
 
-           raction = xmalloc (sizeof *raction);
            raction->base.type = *act;
            raction->base.ops = &r_tracepoint_action_ops;
            action = &raction->base;
@@ -1982,9 +1982,9 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
          }
        case 'L':
          {
-           struct collect_static_trace_data_action *raction;
+           struct collect_static_trace_data_action *raction =
+             XNEW (struct collect_static_trace_data_action);
 
-           raction = xmalloc (sizeof *raction);
            raction->base.type = *act;
            raction->base.ops = &l_tracepoint_action_ops;
            action = &raction->base;
@@ -1999,9 +1999,8 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
          break;
        case 'X':
          {
-           struct eval_expr_action *xaction;
+           struct eval_expr_action *xaction = XNEW (struct eval_expr_action);
 
-           xaction = xmalloc (sizeof (*xaction));
            xaction->base.type = *act;
            xaction->base.ops = &x_tracepoint_action_ops;
            action = &xaction->base;
@@ -2025,13 +2024,11 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
          tpoint->num_step_actions++;
 
          tpoint->step_actions
-           = xrealloc (tpoint->step_actions,
-                       (sizeof (*tpoint->step_actions)
-                        * tpoint->num_step_actions));
+           = XRESIZEVEC (struct tracepoint_action *, tpoint->step_actions,
+                         tpoint->num_step_actions);
          tpoint->step_actions_str
-           = xrealloc (tpoint->step_actions_str,
-                       (sizeof (*tpoint->step_actions_str)
-                        * tpoint->num_step_actions));
+           = XRESIZEVEC (char *, tpoint->step_actions_str,
+                         tpoint->num_step_actions);
          tpoint->step_actions[tpoint->num_step_actions - 1] = action;
          tpoint->step_actions_str[tpoint->num_step_actions - 1]
            = savestring (act_start, act - act_start);
@@ -2040,11 +2037,10 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
        {
          tpoint->numactions++;
          tpoint->actions
-           = xrealloc (tpoint->actions,
-                       sizeof (*tpoint->actions) * tpoint->numactions);
+           = XRESIZEVEC (struct tracepoint_action *, tpoint->actions,
+                         tpoint->numactions);
          tpoint->actions_str
-           = xrealloc (tpoint->actions_str,
-                       sizeof (*tpoint->actions_str) * tpoint->numactions);
+           = XRESIZEVEC (char *, tpoint->actions_str, tpoint->numactions);
          tpoint->actions[tpoint->numactions - 1] = action;
          tpoint->actions_str[tpoint->numactions - 1]
            = savestring (act_start, act - act_start);
@@ -2088,7 +2084,7 @@ create_trace_state_variable (int num, int gdb)
     return tsv;
 
   /* Create a new variable.  */
-  tsv = xmalloc (sizeof (struct trace_state_variable));
+  tsv = XNEW (struct trace_state_variable);
   tsv->number = num;
   tsv->initial_value = 0;
   tsv->value = 0;
@@ -2202,7 +2198,8 @@ add_traceframe (struct tracepoint *tpoint)
 {
   struct traceframe *tframe;
 
-  tframe = trace_buffer_alloc (sizeof (struct traceframe));
+  tframe
+    = (struct traceframe *) trace_buffer_alloc (sizeof (struct traceframe));
 
   if (tframe == NULL)
     return NULL;
@@ -2224,7 +2221,7 @@ add_traceframe_block (struct traceframe *tframe,
   if (!tframe)
     return NULL;
 
-  block = trace_buffer_alloc (amt);
+  block = (unsigned char *) trace_buffer_alloc (amt);
 
   if (!block)
     return NULL;
@@ -2451,10 +2448,20 @@ clear_installed_tracepoints (void)
       switch (tpoint->type)
        {
        case trap_tracepoint:
-         delete_breakpoint (tpoint->handle);
+         {
+           struct breakpoint *bp
+             = (struct breakpoint *) tpoint->handle;
+
+           delete_breakpoint (bp);
+         }
          break;
        case fast_tracepoint:
-         delete_fast_tracepoint_jump (tpoint->handle);
+         {
+           struct fast_tracepoint_jump *jump
+             = (struct fast_tracepoint_jump *) tpoint->handle;
+
+           delete_fast_tracepoint_jump (jump);
+         }
          break;
        case static_tracepoint:
          if (prev_stpoint != NULL
@@ -2686,7 +2693,7 @@ cmd_qtdpsrc (char *own_buf)
 
   saved = packet;
   packet = strchr (packet, ':');
-  srctype = xmalloc (packet - saved + 1);
+  srctype = (char *) xmalloc (packet - saved + 1);
   memcpy (srctype, saved, packet - saved);
   srctype[packet - saved] = '\0';
   ++packet;
@@ -2694,11 +2701,11 @@ cmd_qtdpsrc (char *own_buf)
   ++packet; /* skip a colon */
   packet = unpack_varlen_hex (packet, &slen);
   ++packet; /* skip a colon */
-  src = xmalloc (slen + 1);
+  src = (char *) xmalloc (slen + 1);
   nbytes = hex2bin (packet, (gdb_byte *) src, strlen (packet) / 2);
   src[nbytes] = '\0';
 
-  newlast = xmalloc (sizeof (struct source_string));
+  newlast = XNEW (struct source_string);
   newlast->type = srctype;
   newlast->str = src;
   newlast->next = NULL;
@@ -2736,7 +2743,7 @@ cmd_qtdv (char *own_buf)
   ++packet; /* skip a colon */
 
   nbytes = strlen (packet) / 2;
-  varname = xmalloc (nbytes + 1);
+  varname = (char *) xmalloc (nbytes + 1);
   nbytes = hex2bin (packet, (gdb_byte *) varname, nbytes);
   varname[nbytes] = '\0';
 
@@ -2888,7 +2895,8 @@ cmd_qtro (char *own_buf)
       packet = unpack_varlen_hex (packet, &start);
       ++packet;  /* skip a comma */
       packet = unpack_varlen_hex (packet, &end);
-      roreg = xmalloc (sizeof (struct readonly_region));
+
+      roreg = XNEW (struct readonly_region);
       roreg->start = start;
       roreg->end = end;
       roreg->next = readonly_regions;
@@ -2916,9 +2924,6 @@ in_readonly_region (CORE_ADDR addr, ULONGEST length)
   return 0;
 }
 
-/* The maximum size of a jump pad entry.  */
-static const int max_jump_pad_size = 0x100;
-
 static CORE_ADDR gdb_jump_pad_head;
 
 /* Return the address of the next free jump space.  */
@@ -3615,7 +3620,8 @@ static void
 cmd_qtstatus (char *packet)
 {
   char *stop_reason_rsp = NULL;
-  char *buf1, *buf2, *buf3, *str;
+  char *buf1, *buf2, *buf3;
+  const char *str;
   int slen;
 
   /* Translate the plain text of the notes back into hex for
@@ -3661,7 +3667,8 @@ cmd_qtstatus (char *packet)
 
       result_name = stop_reason_rsp + strlen ("terror:");
       hexstr_len = strlen (result_name) * 2;
-      p = stop_reason_rsp = alloca (strlen ("terror:") + hexstr_len + 1);
+      p = stop_reason_rsp
+       = (char *) alloca (strlen ("terror:") + hexstr_len + 1);
       strcpy (p, "terror:");
       p += strlen (p);
       bin2hex ((gdb_byte *) result_name, p, strlen (result_name));
@@ -3670,7 +3677,7 @@ cmd_qtstatus (char *packet)
   /* If this was a forced stop, include any stop note that was supplied.  */
   if (strcmp (stop_reason_rsp, "tstop") == 0)
     {
-      stop_reason_rsp = alloca (strlen ("tstop:") + strlen (buf3) + 1);
+      stop_reason_rsp = (char *) alloca (strlen ("tstop:") + strlen (buf3) + 1);
       strcpy (stop_reason_rsp, "tstop:");
       strcat (stop_reason_rsp, buf3);
     }
@@ -3782,7 +3789,7 @@ response_source (char *packet,
   int len;
 
   len = strlen (src->str);
-  buf = alloca (len * 2 + 1);
+  buf = (char *) alloca (len * 2 + 1);
   bin2hex ((gdb_byte *) src->str, buf, len);
 
   sprintf (packet, "Z%x:%s:%s:%x:%x:%s",
@@ -3871,7 +3878,7 @@ response_tsv (char *packet, struct trace_state_variable *tsv)
   if (tsv->name)
     {
       namelen = strlen (tsv->name);
-      buf = alloca (namelen * 2 + 1);
+      buf = (char *) alloca (namelen * 2 + 1);
       bin2hex ((gdb_byte *) tsv->name, buf, namelen);
     }
 
@@ -3950,7 +3957,7 @@ cmd_qtstmat (char *packet)
 static int
 same_process_p (struct inferior_list_entry *entry, void *data)
 {
-  int *pid = data;
+  int *pid = (int *) data;
 
   return ptid_get_pid (entry->id) == *pid;
 }
@@ -4112,7 +4119,7 @@ cmd_qtnotes (char *own_buf)
          saved = packet;
          packet = strchr (packet, ';');
          nbytes = (packet - saved) / 2;
-         user = xmalloc (nbytes + 1);
+         user = (char *) xmalloc (nbytes + 1);
          nbytes = hex2bin (saved, (gdb_byte *) user, nbytes);
          user[nbytes] = '\0';
          ++packet; /* skip the semicolon */
@@ -4126,7 +4133,7 @@ cmd_qtnotes (char *own_buf)
          saved = packet;
          packet = strchr (packet, ';');
          nbytes = (packet - saved) / 2;
-         notes = xmalloc (nbytes + 1);
+         notes = (char *) xmalloc (nbytes + 1);
          nbytes = hex2bin (saved, (gdb_byte *) notes, nbytes);
          notes[nbytes] = '\0';
          ++packet; /* skip the semicolon */
@@ -4140,7 +4147,7 @@ cmd_qtnotes (char *own_buf)
          saved = packet;
          packet = strchr (packet, ';');
          nbytes = (packet - saved) / 2;
-         stopnote = xmalloc (nbytes + 1);
+         stopnote = (char *) xmalloc (nbytes + 1);
          nbytes = hex2bin (saved, (gdb_byte *) stopnote, nbytes);
          stopnote[nbytes] = '\0';
          ++packet; /* skip the semicolon */
@@ -4325,9 +4332,8 @@ static void
 add_while_stepping_state (struct thread_info *tinfo,
                          int tp_number, CORE_ADDR tp_address)
 {
-  struct wstep_state *wstep;
+  struct wstep_state *wstep = XNEW (struct wstep_state);
 
-  wstep = xmalloc (sizeof (*wstep));
   wstep->next = tinfo->while_stepping;
 
   wstep->tp_number = tp_number;
@@ -4907,7 +4913,10 @@ condition_true_at_tracepoint (struct tracepoint_hit_ctx *ctx,
      used.  */
 #ifdef IN_PROCESS_AGENT
   if (tpoint->compiled_cond)
-    err = ((condfn) (uintptr_t) (tpoint->compiled_cond)) (ctx, &value);
+    {
+      struct fast_tracepoint_ctx *fctx = (struct fast_tracepoint_ctx *) ctx;
+      err = ((condfn) (uintptr_t) (tpoint->compiled_cond)) (fctx->regs, &value);
+    }
   else
 #endif
     {
@@ -5067,7 +5076,7 @@ agent_tsv_read (struct eval_agent_expr_context *ctx, int n)
 static int
 match_blocktype (char blocktype, unsigned char *dataptr, void *data)
 {
-  char *wantedp = data;
+  char *wantedp = (char *) data;
 
   if (*wantedp == blocktype)
     return 1;
@@ -5413,7 +5422,7 @@ traceframe_read_sdata (int tfnum, ULONGEST offset,
 static int
 build_traceframe_info_xml (char blocktype, unsigned char *dataptr, void *data)
 {
-  struct buffer *buffer = data;
+  struct buffer *buffer = (struct buffer *) data;
 
   switch (blocktype)
     {
@@ -5800,7 +5809,7 @@ gdb_collect (struct tracepoint *tpoint, unsigned char *regs)
   ctx.regcache_initted = 0;
   /* Wrap the regblock in a register cache (in the stack, we don't
      want to malloc here).  */
-  ctx.regspace = alloca (ipa_tdesc->registers_size);
+  ctx.regspace = (unsigned char *) alloca (ipa_tdesc->registers_size);
   if (ctx.regspace == NULL)
     {
       trace_debug ("Trace buffer block allocation failed, skipping");
@@ -7174,7 +7183,7 @@ gdb_agent_helper_thread (void *arg)
 
          do
            {
-             fd = accept (listen_fd, &sockaddr, &tmp);
+             fd = accept (listen_fd, (struct sockaddr *) &sockaddr, &tmp);
            }
          /* It seems an ERESTARTSYS can escape out of accept.  */
          while (fd == -512 || (fd == -1 && errno == EINTR));
@@ -7365,7 +7374,7 @@ initialize_tracepoint (void)
     if (pagesize == -1)
       perror_with_name ("sysconf");
 
-    gdb_tp_heap_buffer = xmalloc (5 * 1024 * 1024);
+    gdb_tp_heap_buffer = (char *) xmalloc (5 * 1024 * 1024);
 
 #define SCRATCH_BUFFER_NPAGES 20
 
@@ -7373,10 +7382,12 @@ initialize_tracepoint (void)
        address (close to the main executable's code).  */
     for (addr = pagesize; addr != 0; addr += pagesize)
       {
-       gdb_jump_pad_buffer = mmap ((void *) addr, pagesize * SCRATCH_BUFFER_NPAGES,
-                                   PROT_READ | PROT_WRITE | PROT_EXEC,
-                                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
-                                   -1, 0);
+       gdb_jump_pad_buffer
+         = (char *) mmap ((void *) addr,
+                          pagesize * SCRATCH_BUFFER_NPAGES,
+                          PROT_READ | PROT_WRITE | PROT_EXEC,
+                          MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+                          -1, 0);
        if (gdb_jump_pad_buffer != MAP_FAILED)
          break;
       }
@@ -7393,7 +7404,7 @@ initialize_tracepoint (void)
      buffer setup, but it can be mysterious, so create a channel to
      report back on what went wrong, using a fixed size since we may
      not be able to allocate space later when the problem occurs.  */
-  gdb_trampoline_buffer_error = xmalloc (IPA_BUFSIZ);
+  gdb_trampoline_buffer_error = (char *) xmalloc (IPA_BUFSIZ);
 
   strcpy (gdb_trampoline_buffer_error, "No errors reported");
 
This page took 0.029293 seconds and 4 git commands to generate.