#include "remote-notif.h"
#include "regcache.h"
#include "value.h"
-#include "observer.h"
+#include "observable.h"
#include "solib.h"
#include "cli/cli-decode.h"
#include "cli/cli-setshow.h"
#if defined(HAVE_LIBEXPAT)
if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
{
- gdb::unique_xmalloc_ptr<char> xml
+ gdb::optional<gdb::char_vector> xml
= target_read_stralloc (ops, TARGET_OBJECT_THREADS, NULL);
- if (xml != NULL && *xml != '\0')
+ if (xml && (*xml)[0] != '\0')
{
gdb_xml_parse_quick (_("threads"), "threads.dtd",
- threads_elements, xml.get (), context);
+ threads_elements, xml->data (), context);
}
return 1;
}
\f
-static int
+static bool
remote_static_tracepoint_marker_at (struct target_ops *self, CORE_ADDR addr,
struct static_tracepoint_marker *marker)
{
if (*p++ == 'm')
{
parse_static_tracepoint_marker_definition (p, NULL, marker);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
-static VEC(static_tracepoint_marker_p) *
+static std::vector<static_tracepoint_marker>
remote_static_tracepoint_markers_by_strid (struct target_ops *self,
const char *strid)
{
struct remote_state *rs = get_remote_state ();
- VEC(static_tracepoint_marker_p) *markers = NULL;
- struct static_tracepoint_marker *marker = NULL;
- struct cleanup *old_chain;
+ std::vector<static_tracepoint_marker> markers;
const char *p;
+ static_tracepoint_marker marker;
/* Ask for a first packet of static tracepoint marker
definition. */
if (*p == 'E')
error (_("Remote failure reply: %s"), p);
- old_chain = make_cleanup (free_current_marker, &marker);
-
while (*p++ == 'm')
{
- if (marker == NULL)
- marker = XCNEW (struct static_tracepoint_marker);
-
do
{
- parse_static_tracepoint_marker_definition (p, &p, marker);
+ parse_static_tracepoint_marker_definition (p, &p, &marker);
- if (strid == NULL || strcmp (strid, marker->str_id) == 0)
- {
- VEC_safe_push (static_tracepoint_marker_p,
- markers, marker);
- marker = NULL;
- }
- else
- {
- release_static_tracepoint_marker (marker);
- memset (marker, 0, sizeof (*marker));
- }
+ if (strid == NULL || marker.str_id == strid)
+ markers.push_back (std::move (marker));
}
while (*p++ == ','); /* comma-separated list */
/* Ask for another packet of static tracepoint definition. */
p = rs->buf;
}
- do_cleanups (old_chain);
return markers;
}
enum gdb_signal sig = ws->value.sig;
if (signal_print_state (sig))
- observer_notify_signal_received (sig);
+ gdb::observers::signal_received.notify (sig);
}
- observer_notify_normal_stop (NULL, 1);
+ gdb::observers::normal_stop.notify (NULL, 1);
}
/* Process all initial stop replies the remote side sent in response
/* All-stop protocol, and blocked waiting for stop reply. Send
an interrupt request. */
else if (!target_terminal::is_ours () && rs->waiting_for_stop_reply)
- target_interrupt (inferior_ptid);
+ target_interrupt ();
else
rs->got_ctrlc_during_io = 1;
}
one. */
static void
-remote_detach_1 (int from_tty)
+remote_detach_1 (int from_tty, inferior *inf)
{
int pid = ptid_get_pid (inferior_ptid);
struct remote_state *rs = get_remote_state ();
}
static void
-remote_detach (struct target_ops *ops, int from_tty)
+remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty);
+ remote_detach_1 (from_tty, inf);
}
static void
-extended_remote_detach (struct target_ops *ops, int from_tty)
+extended_remote_detach (struct target_ops *ops, inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty);
+ remote_detach_1 (from_tty, inf);
}
/* Target follow-fork function for remote targets. On entry, and
child_pid = ptid_get_pid (child_ptid);
remote_detach_pid (child_pid);
- detach_inferior (child_pid);
}
}
return 0;
inferior_ptid = remote_current_thread (inferior_ptid);
/* Add the main thread to the thread list. */
- add_thread_silent (inferior_ptid);
+ thread_info *thr = add_thread_silent (inferior_ptid);
+ /* Don't consider the thread stopped until we've processed the
+ saved stop reply. */
+ set_executing (thr->ptid, true);
}
/* Next, if the target can specify a description, read it. We do
/* Implement the to_interrupt function for the remote targets. */
static void
-remote_interrupt (struct target_ops *self, ptid_t ptid)
+remote_interrupt (struct target_ops *self)
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
else if (rs->ctrlc_pending_p)
interrupt_query ();
else
- target_interrupt (inferior_ptid);
+ target_interrupt ();
}
/* Ask the user what to do when an interrupt is received. */
fprintf_unfiltered (gdb_stdlog, "Sending packet: %s", str.c_str ());
- if (str.length () > REMOTE_DEBUG_MAX_CHAR)
- {
- fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
- str.length () - REMOTE_DEBUG_MAX_CHAR);
- }
+ if (len > REMOTE_DEBUG_MAX_CHAR)
+ fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
+ len - REMOTE_DEBUG_MAX_CHAR);
fprintf_unfiltered (gdb_stdlog, "...");
fprintf_unfiltered (gdb_stdlog, "Packet received: %s",
str.c_str ());
- if (str.length () > REMOTE_DEBUG_MAX_CHAR)
- {
- fprintf_unfiltered (gdb_stdlog, "[%zu bytes omitted]",
- str.length () - REMOTE_DEBUG_MAX_CHAR);
- }
+ if (val > REMOTE_DEBUG_MAX_CHAR)
+ fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
+ val - REMOTE_DEBUG_MAX_CHAR);
fprintf_unfiltered (gdb_stdlog, "\n");
}
remote_memory_map (struct target_ops *ops)
{
std::vector<mem_region> result;
- gdb::unique_xmalloc_ptr<char> text
+ gdb::optional<gdb::char_vector> text
= target_read_stralloc (¤t_target, TARGET_OBJECT_MEMORY_MAP, NULL);
if (text)
- result = parse_memory_map (text.get ());
+ result = parse_memory_map (text->data ());
return result;
}
int ret, bytes_read;
char *attachment_tmp;
- if (!rs->remote_desc
- || packet_support (which_packet) == PACKET_DISABLE)
+ if (packet_support (which_packet) == PACKET_DISABLE)
{
*remote_errno = FILEIO_ENOSYS;
return -1;
/* Implementation of to_fileio_readlink. */
-static char *
+static gdb::optional<std::string>
remote_hostio_readlink (struct target_ops *self,
struct inferior *inf, const char *filename,
int *remote_errno)
int left = get_remote_packet_size ();
int len, attachment_len;
int read_len;
- char *ret;
if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
- return NULL;
+ return {};
remote_buffer_add_string (&p, &left, "vFile:readlink:");
&attachment_len);
if (len < 0)
- return NULL;
+ return {};
- ret = (char *) xmalloc (len + 1);
+ std::string ret (len, '\0');
read_len = remote_unescape_input ((gdb_byte *) attachment, attachment_len,
- (gdb_byte *) ret, len);
+ (gdb_byte *) &ret[0], len);
if (read_len != len)
error (_("Readlink returned %d, but %d bytes."), len, read_len);
- ret[len] = '\0';
return ret;
}
static void
remote_download_trace_state_variable (struct target_ops *self,
- struct trace_state_variable *tsv)
+ const trace_state_variable &tsv)
{
struct remote_state *rs = get_remote_state ();
char *p;
xsnprintf (rs->buf, get_remote_packet_size (), "QTDV:%x:%s:%x:",
- tsv->number, phex ((ULONGEST) tsv->initial_value, 8),
- tsv->builtin);
+ 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 ())
+ if ((p - rs->buf) + tsv.name.length () * 2 >= get_remote_packet_size ())
error (_("Trace state variable name too long for tsv definition packet"));
- p += 2 * bin2hex ((gdb_byte *) (tsv->name), p, strlen (tsv->name));
+ p += 2 * bin2hex ((gdb_byte *) (tsv.name.data ()), p, tsv.name.length ());
*p++ = '\0';
putpkt (rs->buf);
remote_get_noisy_reply ();
static traceframe_info_up
remote_traceframe_info (struct target_ops *self)
{
- gdb::unique_xmalloc_ptr<char> text
+ gdb::optional<gdb::char_vector> text
= target_read_stralloc (¤t_target, TARGET_OBJECT_TRACEFRAME_INFO,
NULL);
- if (text != NULL)
- return parse_traceframe_info (text.get ());
+ if (text)
+ return parse_traceframe_info (text->data ());
return NULL;
}
memset (&rs->btrace_config, 0, sizeof (rs->btrace_config));
}
-/* Check whether the target supports branch tracing. */
-
-static int
-remote_supports_btrace (struct target_ops *self, enum btrace_format format)
-{
- if (packet_support (PACKET_Qbtrace_off) != PACKET_ENABLE)
- return 0;
- if (packet_support (PACKET_qXfer_btrace) != PACKET_ENABLE)
- return 0;
-
- switch (format)
- {
- case BTRACE_FORMAT_NONE:
- return 0;
-
- case BTRACE_FORMAT_BTS:
- return (packet_support (PACKET_Qbtrace_bts) == PACKET_ENABLE);
-
- case BTRACE_FORMAT_PT:
- /* The trace is decoded on the host. Even if our target supports it,
- we still need to have libipt to decode the trace. */
-#if defined (HAVE_LIBIPT)
- return (packet_support (PACKET_Qbtrace_pt) == PACKET_ENABLE);
-#else /* !defined (HAVE_LIBIPT) */
- return 0;
-#endif /* !defined (HAVE_LIBIPT) */
- }
-
- internal_error (__FILE__, __LINE__, _("Unknown branch trace format"));
-}
-
/* Synchronize the configuration with the target. */
static void
static void
btrace_read_config (struct btrace_config *conf)
{
- gdb::unique_xmalloc_ptr<char> xml
+ gdb::optional<gdb::char_vector> xml
= target_read_stralloc (¤t_target, TARGET_OBJECT_BTRACE_CONF, "");
- if (xml != NULL)
- parse_xml_btrace_conf (conf, xml.get ());
+ if (xml)
+ parse_xml_btrace_conf (conf, xml->data ());
}
/* Maybe reopen target btrace. */
if (!warned)
{
warned = 1;
- warning (_("GDB does not support Intel Processor Trace. "
- "\"record\" will not work in this session."));
+ warning (_("Target is recording using Intel Processor Trace "
+ "but support was disabled at compile time."));
}
continue;
(unsigned int) type);
}
- gdb::unique_xmalloc_ptr<char> xml
+ gdb::optional<gdb::char_vector> xml
= target_read_stralloc (¤t_target, TARGET_OBJECT_BTRACE, annex);
- if (xml == NULL)
+ if (!xml)
return BTRACE_ERR_UNKNOWN;
- parse_xml_btrace (btrace, xml.get ());
+ parse_xml_btrace (btrace, xml->data ());
return BTRACE_ERR_NONE;
}
static char *
remote_pid_to_exec_file (struct target_ops *self, int pid)
{
- static gdb::unique_xmalloc_ptr<char> filename;
+ static gdb::optional<gdb::char_vector> filename;
struct inferior *inf;
char *annex = NULL;
filename = target_read_stralloc (¤t_target,
TARGET_OBJECT_EXEC_FILE, annex);
- return filename.get ();
+ return filename ? filename->data () : nullptr;
}
/* Implement the to_can_do_single_step target_ops method. */
remote_ops.to_traceframe_info = remote_traceframe_info;
remote_ops.to_use_agent = remote_use_agent;
remote_ops.to_can_use_agent = remote_can_use_agent;
- remote_ops.to_supports_btrace = remote_supports_btrace;
remote_ops.to_enable_btrace = remote_enable_btrace;
remote_ops.to_disable_btrace = remote_disable_btrace;
remote_ops.to_teardown_btrace = remote_teardown_btrace;
add_target (&extended_remote_ops);
/* Hook into new objfile notification. */
- observer_attach_new_objfile (remote_new_objfile);
+ gdb::observers::new_objfile.attach (remote_new_objfile);
/* We're no longer interested in notification events of an inferior
when it exits. */
- observer_attach_inferior_exit (discard_pending_stop_replies);
+ gdb::observers::inferior_exit.attach (discard_pending_stop_replies);
#if 0
init_remote_threadtests ();