2019-12-18 Anthony Green <green@moxielogic.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / tracepoint.c
index 0f41ff4c42efe7318f6dc8fbf6d37f8e43380a2b..9f8a49174c47fc51adbe574a07480e9e48519da7 100644 (file)
@@ -1,5 +1,5 @@
 /* Tracepoint code for remote server for GDB.
-   Copyright (C) 2009-2017 Free Software Foundation, Inc.
+   Copyright (C) 2009-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -19,8 +19,7 @@
 #include "server.h"
 #include "tracepoint.h"
 #include "gdbthread.h"
-#include "agent.h"
-#include "rsp-low.h"
+#include "gdbsupport/rsp-low.h"
 
 #include <ctype.h>
 #include <fcntl.h>
@@ -30,6 +29,9 @@
 #include "ax.h"
 #include "tdesc.h"
 
+#define IPA_SYM_STRUCT_NAME ipa_sym_addresses
+#include "gdbsupport/agent.h"
+
 #define DEFAULT_TRACE_BUFFER_SIZE 5242880 /* 5*1024*1024 */
 
 /* This file is built for both GDBserver, and the in-process
@@ -438,26 +440,26 @@ static int
 write_inferior_data_pointer (CORE_ADDR symaddr, CORE_ADDR val)
 {
   void *pval = (void *) (uintptr_t) val;
-  return write_inferior_memory (symaddr,
+  return target_write_memory (symaddr,
                                (unsigned char *) &pval, sizeof (pval));
 }
 
 static int
 write_inferior_integer (CORE_ADDR symaddr, int val)
 {
-  return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
+  return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
 }
 
 static int
 write_inferior_int8 (CORE_ADDR symaddr, int8_t val)
 {
-  return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
+  return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
 }
 
 static int
 write_inferior_uinteger (CORE_ADDR symaddr, unsigned int val)
 {
-  return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
+  return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
 }
 
 static CORE_ADDR target_malloc (ULONGEST size);
@@ -515,7 +517,7 @@ m_tracepoint_action_download (const struct tracepoint_action *action)
 {
   CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_memory_action));
 
-  write_inferior_memory (ipa_action, (unsigned char *) action,
+  target_write_memory (ipa_action, (unsigned char *) action,
                         sizeof (struct collect_memory_action));
 
   return ipa_action;
@@ -538,7 +540,7 @@ r_tracepoint_action_download (const struct tracepoint_action *action)
 {
   CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_registers_action));
 
-  write_inferior_memory (ipa_action, (unsigned char *) action,
+  target_write_memory (ipa_action, (unsigned char *) action,
                         sizeof (struct collect_registers_action));
 
   return ipa_action;
@@ -558,7 +560,7 @@ x_tracepoint_action_download (const struct tracepoint_action *action)
   CORE_ADDR ipa_action = target_malloc (sizeof (struct eval_expr_action));
   CORE_ADDR expr;
 
-  write_inferior_memory (ipa_action, (unsigned char *) action,
+  target_write_memory (ipa_action, (unsigned char *) action,
                         sizeof (struct eval_expr_action));
   expr = download_agent_expr (((struct eval_expr_action *) action)->expr);
   write_inferior_data_pointer (ipa_action
@@ -606,7 +608,7 @@ l_tracepoint_action_download (const struct tracepoint_action *action)
   CORE_ADDR ipa_action
     = target_malloc (sizeof (struct collect_static_trace_data_action));
 
-  write_inferior_memory (ipa_action, (unsigned char *) action,
+  target_write_memory (ipa_action, (unsigned char *) action,
                         sizeof (struct collect_static_trace_data_action));
 
   return ipa_action;
@@ -973,11 +975,6 @@ struct traceframe
    fields (and no data) marks the end of trace data.  */
 #define TRACEFRAME_EOB_MARKER_SIZE offsetof (struct traceframe, data)
 
-/* The traceframe to be used as the source of data to send back to
-   GDB.  A value of -1 means to get data from the live program.  */
-
-int current_traceframe = -1;
-
 /* This flag is true if the trace buffer is circular, meaning that
    when it fills, the oldest trace frames are discarded in order to
    make room.  */
@@ -1005,7 +1002,7 @@ EXTERN_C_POP
 
 /* Control structure holding the read/write/etc. pointers into the
    trace buffer.  We need more than one of these to implement a
-   transaction-like mechanism to garantees that both GDBserver and the
+   transaction-like mechanism to guarantees that both GDBserver and the
    in-process agent can try to change the trace buffer
    simultaneously.  */
 
@@ -1461,14 +1458,14 @@ clear_inferior_trace_buffer (void)
   ipa_trace_buffer_ctrl.wrap = ipa_trace_buffer_hi;
 
   /* A traceframe with zeroed fields marks the end of trace data.  */
-  write_inferior_memory (ipa_sym_addrs.addr_trace_buffer_ctrl,
+  target_write_memory (ipa_sym_addrs.addr_trace_buffer_ctrl,
                         (unsigned char *) &ipa_trace_buffer_ctrl,
                         sizeof (ipa_trace_buffer_ctrl));
 
   write_inferior_uinteger (ipa_sym_addrs.addr_trace_buffer_ctrl_curr, 0);
 
   /* A traceframe with zeroed fields marks the end of trace data.  */
-  write_inferior_memory (ipa_trace_buffer_lo,
+  target_write_memory (ipa_trace_buffer_lo,
                         (unsigned char *) &ipa_traceframe,
                         sizeof (ipa_traceframe));
 
@@ -1910,9 +1907,9 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num)
 /* Append another action to perform when the tracepoint triggers.  */
 
 static void
-add_tracepoint_action (struct tracepoint *tpoint, char *packet)
+add_tracepoint_action (struct tracepoint *tpoint, const char *packet)
 {
-  char *act;
+  const char *act;
 
   if (*packet == 'S')
     {
@@ -1924,7 +1921,7 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet)
 
   while (*act)
     {
-      char *act_start = act;
+      const char *act_start = act;
       struct tracepoint_action *action = NULL;
 
       switch (*act)
@@ -2279,10 +2276,11 @@ static struct traceframe *
 find_next_traceframe_in_range (CORE_ADDR lo, CORE_ADDR hi, int inside_p,
                               int *tfnump)
 {
+  client_state &cs = get_client_state ();
   struct traceframe *tframe;
   CORE_ADDR tfaddr;
 
-  *tfnump = current_traceframe + 1;
+  *tfnump = cs.current_traceframe + 1;
   tframe = find_traceframe (*tfnump);
   /* The search is not supposed to wrap around.  */
   if (!tframe)
@@ -2312,9 +2310,10 @@ find_next_traceframe_in_range (CORE_ADDR lo, CORE_ADDR hi, int inside_p,
 static struct traceframe *
 find_next_traceframe_by_tracepoint (int num, int *tfnump)
 {
+  client_state &cs = get_client_state ();
   struct traceframe *tframe;
 
-  *tfnump = current_traceframe + 1;
+  *tfnump = cs.current_traceframe + 1;
   tframe = find_traceframe (*tfnump);
   /* The search is not supposed to wrap around.  */
   if (!tframe)
@@ -2343,6 +2342,7 @@ find_next_traceframe_by_tracepoint (int num, int *tfnump)
 static void
 cmd_qtinit (char *packet)
 {
+  client_state &cs = get_client_state ();
   struct trace_state_variable *tsv, *prev, *next;
 
   /* Can't do this command without a pid attached.  */
@@ -2353,7 +2353,7 @@ cmd_qtinit (char *packet)
     }
 
   /* Make sure we don't try to read from a trace frame.  */
-  current_traceframe = -1;
+  cs.current_traceframe = -1;
 
   stop_tracing ();
 
@@ -2485,8 +2485,7 @@ cmd_qtdp (char *own_buf)
   ULONGEST addr;
   ULONGEST count;
   struct tracepoint *tpoint;
-  char *actparm;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   packet += strlen ("QTDP:");
 
@@ -2546,9 +2545,7 @@ cmd_qtdp (char *own_buf)
            }
          else if (*packet == 'X')
            {
-             actparm = (char *) packet;
-             tpoint->cond = gdb_parse_agent_expr (&actparm);
-             packet = actparm;
+             tpoint->cond = gdb_parse_agent_expr (&packet);
            }
          else if (*packet == '-')
            break;
@@ -2657,8 +2654,9 @@ cmd_qtdpsrc (char *own_buf)
 {
   ULONGEST num, addr, start, slen;
   struct tracepoint *tpoint;
-  char *packet = own_buf;
-  char *saved, *srctype, *src;
+  const char *packet = own_buf;
+  const char *saved;
+  char *srctype, *src;
   size_t nbytes;
   struct source_string *last, *newlast;
 
@@ -2720,7 +2718,7 @@ cmd_qtdv (char *own_buf)
   char *varname;
   size_t nbytes;
   struct trace_state_variable *tsv;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   packet += strlen ("QTDV:");
 
@@ -2748,7 +2746,7 @@ cmd_qtdv (char *own_buf)
 static void
 cmd_qtenable_disable (char *own_buf, int enable)
 {
-  char *packet = own_buf;
+  const char *packet = own_buf;
   ULONGEST num, addr;
   struct tracepoint *tp;
 
@@ -2815,6 +2813,7 @@ cmd_qtenable_disable (char *own_buf, int enable)
 static void
 cmd_qtv (char *own_buf)
 {
+  client_state &cs = get_client_state ();
   ULONGEST num;
   LONGEST val = 0;
   int err;
@@ -2823,7 +2822,7 @@ cmd_qtv (char *own_buf)
   packet += strlen ("qTV:");
   unpack_varlen_hex (packet, &num);
 
-  if (current_traceframe >= 0)
+  if (cs.current_traceframe >= 0)
     {
       err = traceframe_read_tsv ((int) num, &val);
       if (err)
@@ -2870,7 +2869,7 @@ cmd_qtro (char *own_buf)
 {
   ULONGEST start, end;
   struct readonly_region *roreg;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   trace_debug ("Want to mark readonly regions");
 
@@ -3554,10 +3553,11 @@ cmd_qtdisconnected (char *own_buf)
 static void
 cmd_qtframe (char *own_buf)
 {
+  client_state &cs = get_client_state ();
   ULONGEST frame, pc, lo, hi, num;
   int tfnum, tpnum;
   struct traceframe *tframe;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   packet += strlen ("QTFrame:");
 
@@ -3604,7 +3604,7 @@ cmd_qtframe (char *own_buf)
       if (tfnum == -1)
        {
          trace_debug ("Want to stop looking at traceframes");
-         current_traceframe = -1;
+         cs.current_traceframe = -1;
          write_ok (own_buf);
          return;
        }
@@ -3614,7 +3614,7 @@ cmd_qtframe (char *own_buf)
 
   if (tframe)
     {
-      current_traceframe = tfnum;
+      cs.current_traceframe = tfnum;
       sprintf (own_buf, "F%xT%x", tfnum, tframe->tpnum);
     }
   else
@@ -3712,7 +3712,7 @@ cmd_qtp (char *own_buf)
 {
   ULONGEST num, addr;
   struct tracepoint *tpoint;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   packet += strlen ("qTP:");
 
@@ -4005,7 +4005,7 @@ cmd_qtbuffer (char *own_buf)
 {
   ULONGEST offset, num, tot;
   unsigned char *tbp;
-  char *packet = own_buf;
+  const char *packet = own_buf;
 
   packet += strlen ("qTBuffer:");
 
@@ -4398,7 +4398,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc)
   wstep_link = &tinfo->while_stepping;
 
   trace_debug ("Thread %s finished a single-step for tracepoint %d at 0x%s",
-              target_pid_to_str (tinfo->entry.id),
+              target_pid_to_str (tinfo->id),
               wstep->tp_number, paddress (wstep->tp_address));
 
   ctx.base.type = trap_tracepoint;
@@ -4411,7 +4411,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc)
        {
          trace_debug ("NO TRACEPOINT %d at 0x%s FOR THREAD %s!",
                       wstep->tp_number, paddress (wstep->tp_address),
-                      target_pid_to_str (tinfo->entry.id));
+                      target_pid_to_str (tinfo->id));
 
          /* Unlink.  */
          *wstep_link = wstep->next;
@@ -4431,7 +4431,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc)
        {
          /* The requested numbers of steps have occurred.  */
          trace_debug ("Thread %s done stepping for tracepoint %d at 0x%s",
-                      target_pid_to_str (tinfo->entry.id),
+                      target_pid_to_str (tinfo->id),
                       wstep->tp_number, paddress (wstep->tp_address));
 
          /* Unlink the wstep.  */
@@ -4578,7 +4578,7 @@ tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc)
          && tpoint->type != static_tracepoint)
        {
          trace_debug ("Thread %s at address of tracepoint %d at 0x%s",
-                      target_pid_to_str (tinfo->entry.id),
+                      target_pid_to_str (tinfo->id),
                       tpoint->number, paddress (tpoint->address));
 
          /* Test the condition if present, and collect if true.  */
@@ -5154,7 +5154,7 @@ traceframe_walk_blocks (unsigned char *database, unsigned int datasize,
   return NULL;
 }
 
-/* Look for the block of type TYPE_WANTED in the trameframe starting
+/* Look for the block of type TYPE_WANTED in the traceframe starting
    at DATABASE of DATASIZE bytes long.  TFNUM is the traceframe
    number.  */
 
@@ -5299,6 +5299,7 @@ traceframe_read_mem (int tfnum, CORE_ADDR addr,
 static int
 traceframe_read_tsv (int tsvnum, LONGEST *val)
 {
+  client_state &cs = get_client_state ();
   int tfnum;
   struct traceframe *tframe;
   unsigned char *database, *dataptr;
@@ -5308,7 +5309,7 @@ traceframe_read_tsv (int tsvnum, LONGEST *val)
 
   trace_debug ("traceframe_read_tsv");
 
-  tfnum = current_traceframe;
+  tfnum = cs.current_traceframe;
 
   if (tfnum < 0)
     {
@@ -6008,12 +6009,12 @@ download_agent_expr (struct agent_expr *expr)
   CORE_ADDR expr_bytes;
 
   expr_addr = target_malloc (sizeof (*expr));
-  write_inferior_memory (expr_addr, (unsigned char *) expr, sizeof (*expr));
+  target_write_memory (expr_addr, (unsigned char *) expr, sizeof (*expr));
 
   expr_bytes = target_malloc (expr->length);
   write_inferior_data_pointer (expr_addr + offsetof (struct agent_expr, bytes),
                               expr_bytes);
-  write_inferior_memory (expr_bytes, expr->bytes, expr->length);
+  target_write_memory (expr_bytes, expr->bytes, expr->length);
 
   return expr_addr;
 }
@@ -6066,7 +6067,7 @@ download_tracepoint_1 (struct tracepoint *tpoint)
      tracepoints before clearing our own copy.  */
   target_tracepoint.hit_count = 0;
 
-  write_inferior_memory (tpptr, (unsigned char *) &target_tracepoint,
+  target_write_memory (tpptr, (unsigned char *) &target_tracepoint,
                         sizeof (target_tracepoint));
 
   if (tpoint->cond)
@@ -6278,14 +6279,14 @@ download_trace_state_variables (void)
         Assume no next, fixup when needed.  */
       target_tsv.next = NULL;
 
-      write_inferior_memory (ptr, (unsigned char *) &target_tsv,
+      target_write_memory (ptr, (unsigned char *) &target_tsv,
                             sizeof (target_tsv));
 
       if (tsv->name != NULL)
        {
          size_t size = strlen (tsv->name) + 1;
          CORE_ADDR name_addr = target_malloc (size);
-         write_inferior_memory (name_addr,
+         target_write_memory (name_addr,
                                 (unsigned char *) tsv->name, size);
          write_inferior_data_pointer (ptr
                                       + offsetof (struct trace_state_variable,
@@ -6309,7 +6310,7 @@ download_trace_state_variables (void)
    into GDBserver's trace buffer.  This always uploads either all or
    no trace frames.  This is the counter part of
    `trace_alloc_trace_buffer'.  See its description of the atomic
-   synching mechanism.  */
+   syncing mechanism.  */
 
 static void
 upload_fast_traceframes (void)
@@ -6547,7 +6548,7 @@ upload_fast_traceframes (void)
                   (int) (ipa_trace_buffer_hi - ipa_trace_buffer_lo));
     }
 
-  if (write_inferior_memory (ipa_trace_buffer_ctrl_addr,
+  if (target_write_memory (ipa_trace_buffer_ctrl_addr,
                             (unsigned char *) &ipa_trace_buffer_ctrl,
                             sizeof (struct ipa_trace_buffer_control)))
     return;
@@ -6836,7 +6837,7 @@ static int
 run_inferior_command (char *cmd, int len)
 {
   int err = -1;
-  int pid = ptid_get_pid (current_ptid);
+  int pid = current_ptid.pid ();
 
   trace_debug ("run_inferior_command: running: %s", cmd);
 
@@ -6878,7 +6879,7 @@ init_named_socket (const char *name)
   result = fd = socket (PF_UNIX, SOCK_STREAM, 0);
   if (result == -1)
     {
-      warning ("socket creation failed: %s", strerror (errno));
+      warning ("socket creation failed: %s", safe_strerror (errno));
       return -1;
     }
 
@@ -6894,7 +6895,7 @@ init_named_socket (const char *name)
       result = unlink (name);
       if (result == -1)
        {
-         warning ("unlink failed: %s", strerror (errno));
+         warning ("unlink failed: %s", safe_strerror (errno));
          close (fd);
          return -1;
        }
@@ -6904,7 +6905,7 @@ init_named_socket (const char *name)
   result = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
   if (result == -1)
     {
-      warning ("bind failed: %s", strerror (errno));
+      warning ("bind failed: %s", safe_strerror (errno));
       close (fd);
       return -1;
     }
@@ -6912,7 +6913,7 @@ init_named_socket (const char *name)
   result = listen (fd, 1);
   if (result == -1)
     {
-      warning ("listen: %s", strerror (errno));
+      warning ("listen: %s", safe_strerror (errno));
       close (fd);
       return -1;
     }
@@ -7193,7 +7194,7 @@ gdb_agent_helper_thread (void *arg)
 
       if (listen_fd == -1)
        {
-         warning ("could not create sync socket\n");
+         warning ("could not create sync socket");
          break;
        }
 
@@ -7217,8 +7218,8 @@ gdb_agent_helper_thread (void *arg)
 
          if (fd < 0)
            {
-             warning ("Accept returned %d, error: %s\n",
-                      fd, strerror (errno));
+             warning ("Accept returned %d, error: %s",
+                      fd, safe_strerror (errno));
              break;
            }
 
@@ -7230,7 +7231,7 @@ gdb_agent_helper_thread (void *arg)
          if (ret == -1)
            {
              warning ("reading socket (fd=%d) failed with %s",
-                      fd, strerror (errno));
+                      fd, safe_strerror (errno));
              close (fd);
              break;
            }
@@ -7329,7 +7330,6 @@ gdb_agent_init (void)
 }
 
 #include <sys/mman.h>
-#include <fcntl.h>
 
 IP_AGENT_EXPORT_VAR char *gdb_tp_heap_buffer;
 IP_AGENT_EXPORT_VAR char *gdb_jump_pad_buffer;
This page took 0.036261 seconds and 4 git commands to generate.