+ offset += retcode;
+ }
+
+ discard_cleanups (close_cleanup);
+ if (remote_hostio_close (fd, &remote_errno))
+ remote_hostio_error (remote_errno);
+
+ if (from_tty)
+ printf_filtered (_("Successfully sent file \"%s\".\n"), local_file);
+ do_cleanups (back_to);
+}
+
+void
+remote_file_get (const char *remote_file, const char *local_file, int from_tty)
+{
+ struct cleanup *back_to, *close_cleanup;
+ int fd, remote_errno, bytes, io_size;
+ FILE *file;
+ gdb_byte *buffer;
+ ULONGEST offset;
+
+ if (!remote_desc)
+ error (_("command can only be used with remote target"));
+
+ fd = remote_hostio_open (remote_file, FILEIO_O_RDONLY, 0, &remote_errno);
+ if (fd == -1)
+ remote_hostio_error (remote_errno);
+
+ file = fopen (local_file, "wb");
+ if (file == NULL)
+ perror_with_name (local_file);
+ back_to = make_cleanup_fclose (file);
+
+ /* Send up to this many bytes at once. They won't all fit in the
+ remote packet limit, so we'll transfer slightly fewer. */
+ io_size = get_remote_packet_size ();
+ buffer = xmalloc (io_size);
+ make_cleanup (xfree, buffer);
+
+ close_cleanup = make_cleanup (remote_hostio_close_cleanup, &fd);
+
+ offset = 0;
+ while (1)
+ {
+ bytes = remote_hostio_pread (fd, buffer, io_size, offset, &remote_errno);
+ if (bytes == 0)
+ /* Success, but no bytes, means end-of-file. */
+ break;
+ if (bytes == -1)
+ remote_hostio_error (remote_errno);
+
+ offset += bytes;
+
+ bytes = fwrite (buffer, 1, bytes, file);
+ if (bytes == 0)
+ perror_with_name (local_file);
+ }
+
+ discard_cleanups (close_cleanup);
+ if (remote_hostio_close (fd, &remote_errno))
+ remote_hostio_error (remote_errno);
+
+ if (from_tty)
+ printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file);
+ do_cleanups (back_to);
+}
+
+void
+remote_file_delete (const char *remote_file, int from_tty)
+{
+ int retcode, remote_errno;
+
+ if (!remote_desc)
+ error (_("command can only be used with remote target"));
+
+ retcode = remote_hostio_unlink (remote_file, &remote_errno);
+ if (retcode == -1)
+ remote_hostio_error (remote_errno);
+
+ if (from_tty)
+ printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file);
+}
+
+static void
+remote_put_command (char *args, int from_tty)
+{
+ struct cleanup *back_to;
+ char **argv;
+
+ if (args == NULL)
+ error_no_arg (_("file to put"));
+
+ argv = gdb_buildargv (args);
+ back_to = make_cleanup_freeargv (argv);
+ if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
+ error (_("Invalid parameters to remote put"));
+
+ remote_file_put (argv[0], argv[1], from_tty);
+
+ do_cleanups (back_to);
+}
+
+static void
+remote_get_command (char *args, int from_tty)
+{
+ struct cleanup *back_to;
+ char **argv;
+
+ if (args == NULL)
+ error_no_arg (_("file to get"));
+
+ argv = gdb_buildargv (args);
+ back_to = make_cleanup_freeargv (argv);
+ if (argv[0] == NULL || argv[1] == NULL || argv[2] != NULL)
+ error (_("Invalid parameters to remote get"));
+
+ remote_file_get (argv[0], argv[1], from_tty);
+
+ do_cleanups (back_to);
+}
+
+static void
+remote_delete_command (char *args, int from_tty)
+{
+ struct cleanup *back_to;
+ char **argv;
+
+ if (args == NULL)
+ error_no_arg (_("file to delete"));
+
+ argv = gdb_buildargv (args);
+ back_to = make_cleanup_freeargv (argv);
+ if (argv[0] == NULL || argv[1] != NULL)
+ error (_("Invalid parameters to remote delete"));
+
+ remote_file_delete (argv[0], from_tty);
+
+ do_cleanups (back_to);
+}
+
+static void
+remote_command (char *args, int from_tty)
+{
+ help_list (remote_cmdlist, "remote ", -1, gdb_stdout);
+}
+
+static int
+remote_can_execute_reverse (void)
+{
+ if (remote_protocol_packets[PACKET_bs].support == PACKET_ENABLE
+ || remote_protocol_packets[PACKET_bc].support == PACKET_ENABLE)
+ return 1;
+ else
+ return 0;
+}
+
+static int
+remote_supports_non_stop (void)
+{
+ return 1;
+}
+
+static int
+remote_supports_multi_process (void)
+{
+ struct remote_state *rs = get_remote_state ();
+
+ return remote_multi_process_p (rs);
+}
+
+int
+remote_supports_cond_tracepoints (void)
+{
+ struct remote_state *rs = get_remote_state ();
+
+ return rs->cond_tracepoints;
+}
+
+int
+remote_supports_fast_tracepoints (void)
+{
+ struct remote_state *rs = get_remote_state ();
+
+ return rs->fast_tracepoints;
+}
+
+static int
+remote_supports_static_tracepoints (void)
+{
+ struct remote_state *rs = get_remote_state ();
+
+ return rs->static_tracepoints;
+}
+
+static int
+remote_supports_enable_disable_tracepoint (void)
+{
+ struct remote_state *rs = get_remote_state ();
+
+ return rs->enable_disable_tracepoints;
+}
+
+static void
+remote_trace_init (void)
+{
+ putpkt ("QTinit");
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK") != 0)
+ error (_("Target does not support this command."));
+}
+
+static void free_actions_list (char **actions_list);
+static void free_actions_list_cleanup_wrapper (void *);
+static void
+free_actions_list_cleanup_wrapper (void *al)
+{
+ free_actions_list (al);
+}
+
+static void
+free_actions_list (char **actions_list)
+{
+ int ndx;
+
+ if (actions_list == 0)
+ return;
+
+ for (ndx = 0; actions_list[ndx]; ndx++)
+ xfree (actions_list[ndx]);
+
+ xfree (actions_list);
+}
+
+/* Recursive routine to walk through command list including loops, and
+ download packets for each command. */
+
+static void
+remote_download_command_source (int num, ULONGEST addr,
+ struct command_line *cmds)
+{
+ struct remote_state *rs = get_remote_state ();
+ struct command_line *cmd;
+
+ for (cmd = cmds; cmd; cmd = cmd->next)
+ {
+ QUIT; /* Allow user to bail out with ^C. */
+ strcpy (rs->buf, "QTDPsrc:");
+ encode_source_string (num, addr, "cmd", cmd->line,
+ rs->buf + strlen (rs->buf),
+ rs->buf_size - strlen (rs->buf));
+ putpkt (rs->buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ warning (_("Target does not support source download."));
+
+ if (cmd->control_type == while_control
+ || cmd->control_type == while_stepping_control)
+ {
+ remote_download_command_source (num, addr, *cmd->body_list);
+
+ QUIT; /* Allow user to bail out with ^C. */
+ strcpy (rs->buf, "QTDPsrc:");
+ encode_source_string (num, addr, "cmd", "end",
+ rs->buf + strlen (rs->buf),
+ rs->buf_size - strlen (rs->buf));
+ putpkt (rs->buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ warning (_("Target does not support source download."));
+ }
+ }
+}
+
+static void
+remote_download_tracepoint (struct breakpoint *t)
+{
+ struct bp_location *loc;
+ CORE_ADDR tpaddr;
+ char addrbuf[40];
+ char buf[2048];
+ char **tdp_actions;
+ char **stepping_actions;
+ int ndx;
+ struct cleanup *old_chain = NULL;
+ struct agent_expr *aexpr;
+ struct cleanup *aexpr_chain = NULL;
+ char *pkt;
+
+ /* Iterate over all the tracepoint locations. It's up to the target to
+ notice multiple tracepoint packets with the same number but different
+ addresses, and treat them as multiple locations. */
+ for (loc = t->loc; loc; loc = loc->next)
+ {
+ encode_actions (t, loc, &tdp_actions, &stepping_actions);
+ old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
+ tdp_actions);
+ (void) make_cleanup (free_actions_list_cleanup_wrapper,
+ stepping_actions);
+
+ tpaddr = loc->address;
+ sprintf_vma (addrbuf, tpaddr);
+ sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number,
+ addrbuf, /* address */
+ (t->enable_state == bp_enabled ? 'E' : 'D'),
+ t->step_count, t->pass_count);
+ /* Fast tracepoints are mostly handled by the target, but we can
+ tell the target how big of an instruction block should be moved
+ around. */
+ if (t->type == bp_fast_tracepoint)
+ {
+ /* Only test for support at download time; we may not know
+ target capabilities at definition time. */
+ if (remote_supports_fast_tracepoints ())
+ {
+ int isize;
+
+ if (gdbarch_fast_tracepoint_valid_at (target_gdbarch,
+ tpaddr, &isize, NULL))
+ sprintf (buf + strlen (buf), ":F%x", isize);
+ else
+ /* If it passed validation at definition but fails now,
+ something is very wrong. */
+ internal_error (__FILE__, __LINE__,
+ _("Fast tracepoint not "
+ "valid during download"));
+ }
+ else
+ /* Fast tracepoints are functionally identical to regular
+ tracepoints, so don't take lack of support as a reason to
+ give up on the trace run. */
+ warning (_("Target does not support fast tracepoints, "
+ "downloading %d as regular tracepoint"), t->number);
+ }
+ else if (t->type == bp_static_tracepoint)
+ {
+ /* Only test for support at download time; we may not know
+ target capabilities at definition time. */
+ if (remote_supports_static_tracepoints ())
+ {
+ struct static_tracepoint_marker marker;
+
+ if (target_static_tracepoint_marker_at (tpaddr, &marker))
+ strcat (buf, ":S");
+ else
+ error (_("Static tracepoint not valid during download"));
+ }
+ else
+ /* Fast tracepoints are functionally identical to regular
+ tracepoints, so don't take lack of support as a reason
+ to give up on the trace run. */
+ error (_("Target does not support static tracepoints"));
+ }
+ /* If the tracepoint has a conditional, make it into an agent
+ expression and append to the definition. */
+ if (loc->cond)
+ {
+ /* Only test support at download time, we may not know target
+ capabilities at definition time. */
+ if (remote_supports_cond_tracepoints ())
+ {
+ aexpr = gen_eval_for_expr (tpaddr, loc->cond);
+ aexpr_chain = make_cleanup_free_agent_expr (aexpr);
+ sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
+ pkt = buf + strlen (buf);
+ for (ndx = 0; ndx < aexpr->len; ++ndx)
+ pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
+ *pkt = '\0';
+ do_cleanups (aexpr_chain);
+ }
+ else
+ warning (_("Target does not support conditional tracepoints, "
+ "ignoring tp %d cond"), t->number);
+ }
+
+ if (t->commands || *default_collect)
+ strcat (buf, "-");
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ error (_("Target does not support tracepoints."));
+
+ /* do_single_steps (t); */
+ if (tdp_actions)
+ {
+ for (ndx = 0; tdp_actions[ndx]; ndx++)
+ {
+ QUIT; /* Allow user to bail out with ^C. */
+ sprintf (buf, "QTDP:-%x:%s:%s%c",
+ t->number, addrbuf, /* address */
+ tdp_actions[ndx],
+ ((tdp_actions[ndx + 1] || stepping_actions)
+ ? '-' : 0));
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf,
+ &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ error (_("Error on target while setting tracepoints."));
+ }
+ }
+ if (stepping_actions)
+ {
+ for (ndx = 0; stepping_actions[ndx]; ndx++)
+ {
+ QUIT; /* Allow user to bail out with ^C. */
+ sprintf (buf, "QTDP:-%x:%s:%s%s%s",
+ t->number, addrbuf, /* address */
+ ((ndx == 0) ? "S" : ""),
+ stepping_actions[ndx],
+ (stepping_actions[ndx + 1] ? "-" : ""));
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf,
+ &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ error (_("Error on target while setting tracepoints."));
+ }
+ }
+
+ if (remote_protocol_packets[PACKET_TracepointSource].support
+ == PACKET_ENABLE)
+ {
+ if (t->addr_string)
+ {
+ strcpy (buf, "QTDPsrc:");
+ encode_source_string (t->number, loc->address,
+ "at", t->addr_string, buf + strlen (buf),
+ 2048 - strlen (buf));
+
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ warning (_("Target does not support source download."));
+ }
+ if (t->cond_string)
+ {
+ strcpy (buf, "QTDPsrc:");
+ encode_source_string (t->number, loc->address,
+ "cond", t->cond_string, buf + strlen (buf),
+ 2048 - strlen (buf));
+ putpkt (buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (strcmp (target_buf, "OK"))
+ warning (_("Target does not support source download."));
+ }
+ remote_download_command_source (t->number, loc->address,
+ breakpoint_commands (t));
+ }
+
+ do_cleanups (old_chain);
+ }
+}
+
+static void
+remote_download_trace_state_variable (struct trace_state_variable *tsv)
+{
+ struct remote_state *rs = get_remote_state ();
+ char *p;
+
+ sprintf (rs->buf, "QTDV:%x:%s:%x:",
+ tsv->number, phex ((ULONGEST) tsv->initial_value, 8), tsv->builtin);
+ p = rs->buf + strlen (rs->buf);
+ if ((p - rs->buf) + strlen (tsv->name) * 2 >= get_remote_packet_size ())
+ error (_("Trace state variable name too long for tsv definition packet"));
+ p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, 0);
+ *p++ = '\0';
+ putpkt (rs->buf);
+ remote_get_noisy_reply (&target_buf, &target_buf_size);
+ if (*target_buf == '\0')
+ error (_("Target does not support this command."));
+ if (strcmp (target_buf, "OK") != 0)
+ error (_("Error on target while downloading trace state variable."));
+}
+
+static void
+remote_enable_tracepoint (struct bp_location *location)
+{
+ struct remote_state *rs = get_remote_state ();
+ char addr_buf[40];
+
+ sprintf_vma (addr_buf, location->address);
+ sprintf (rs->buf, "QTEnable:%x:%s", location->owner->number, addr_buf);
+ putpkt (rs->buf);
+ remote_get_noisy_reply (&rs->buf, &rs->buf_size);
+ if (*rs->buf == '\0')
+ error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
+ if (strcmp (rs->buf, "OK") != 0)
+ error (_("Error on target while enabling tracepoint."));
+}
+
+static void
+remote_disable_tracepoint (struct bp_location *location)
+{
+ struct remote_state *rs = get_remote_state ();
+ char addr_buf[40];
+
+ sprintf_vma (addr_buf, location->address);
+ sprintf (rs->buf, "QTDisable:%x:%s", location->owner->number, addr_buf);
+ putpkt (rs->buf);
+ remote_get_noisy_reply (&rs->buf, &rs->buf_size);
+ if (*rs->buf == '\0')
+ error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
+ if (strcmp (rs->buf, "OK") != 0)
+ error (_("Error on target while disabling tracepoint."));
+}
+
+static void
+remote_trace_set_readonly_regions (void)
+{
+ asection *s;
+ bfd_size_type size;
+ bfd_vma vma;
+ int anysecs = 0;