#include "gdbsupport/scoped_restore.h"
#include "gdbsupport/environ.h"
#include "gdbsupport/byte-vector.h"
+#include "gdbsupport/search.h"
#include <algorithm>
#include <unordered_map>
#include "async-event.h"
void commit_resume () override;
void resume (ptid_t, int, enum gdb_signal) override;
- ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
+ ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
void fetch_registers (struct regcache *, int) override;
void store_registers (struct regcache *, int) override;
void add_current_inferior_and_thread (char *wait_status);
ptid_t wait_ns (ptid_t ptid, struct target_waitstatus *status,
- int options);
+ target_wait_flags options);
ptid_t wait_as (ptid_t ptid, target_waitstatus *status,
- int options);
+ target_wait_flags options);
ptid_t process_stop_reply (struct stop_reply *stop_reply,
target_waitstatus *status);
thread_change_ptid (this, inferior_ptid, currthread);
else
{
- remote_add_thread (currthread, running, executing);
- inferior_ptid = currthread;
+ thread_info *thr
+ = remote_add_thread (currthread, running, executing);
+ switch_to_thread (thr);
}
return;
}
struct remote_state *rs = get_remote_state ();
bool fake_pid_p = false;
- inferior_ptid = null_ptid;
+ switch_to_no_thread ();
- /* Now, if we have thread information, update inferior_ptid. */
+ /* Now, if we have thread information, update the current thread's
+ ptid. */
ptid_t curr_ptid = get_current_thread (wait_status);
if (curr_ptid != null_ptid)
}
/* If we connected to a live target, do some additional setup. */
- if (target_has_execution)
+ if (target_has_execution ())
{
if (symfile_objfile) /* No use without a symbol-file. */
remote_check_symbols ();
but our current inferior is not running, we should not invite the
remote target to request symbol lookups related to its
(unrelated) current process. */
- if (!target_has_execution)
+ if (!target_has_execution ())
return;
if (packet_support (PACKET_qSymbol) == PACKET_DISABLE)
/* If we're connected to a running target, target_preopen will kill it.
Ask this question first, before target_preopen has a chance to kill
anything. */
- if (curr_remote != NULL && !target_has_execution)
+ if (curr_remote != NULL && !target_has_execution ())
{
if (from_tty
&& !query (_("Already connected to a remote target. Disconnect? ")))
/* Register extra event sources in the event loop. */
rs->remote_async_inferior_event_token
- = create_async_event_handler (remote_async_inferior_event_handler,
- remote);
+ = create_async_event_handler (remote_async_inferior_event_handler, remote,
+ "remote");
rs->notif_state = remote_notif_state_allocate (remote);
/* Reset the target state; these things will be queried either by
struct remote_state *rs = get_remote_state ();
int is_fork_parent;
- if (!target_has_execution)
+ if (!target_has_execution ())
error (_("No process to detach from."));
target_announce_detach (from_tty);
}
else
{
- inferior_ptid = null_ptid;
+ switch_to_no_thread ();
detach_inferior (current_inferior ());
}
}
target_pid_to_str (ptid_t (pid)).c_str ());
}
- set_current_inferior (remote_add_inferior (false, pid, 1, 0));
+ switch_to_inferior_no_thread (remote_add_inferior (false, pid, 1, 0));
inferior_ptid = ptid_t (pid);
if (target_is_non_stop_p ())
{
- struct thread_info *thread;
-
/* Get list of threads. */
update_thread_list ();
- thread = first_thread_of_inferior (current_inferior ());
- if (thread)
- inferior_ptid = thread->ptid;
- else
- inferior_ptid = ptid_t (pid);
+ thread_info *thread = first_thread_of_inferior (current_inferior ());
+ if (thread != nullptr)
+ switch_to_thread (thread);
/* Invalidate our notion of the remote current thread. */
record_currthread (rs, minus_one_ptid);
}
else
{
- /* Now, if we have thread information, update inferior_ptid. */
- inferior_ptid = remote_current_thread (inferior_ptid);
+ /* Now, if we have thread information, update the main thread's
+ ptid. */
+ ptid_t curr_ptid = remote_current_thread (ptid_t (pid));
/* Add the main thread to the thread list. */
- thread_info *thr = add_thread_silent (this, inferior_ptid);
+ thread_info *thr = add_thread_silent (this, curr_ptid);
+
+ switch_to_thread (thr);
+
/* Don't consider the thread stopped until we've processed the
saved stop reply. */
set_executing (this, thr->ptid, true);
/* The non-stop mode version of target_wait. */
ptid_t
-remote_target::wait_ns (ptid_t ptid, struct target_waitstatus *status, int options)
+remote_target::wait_ns (ptid_t ptid, struct target_waitstatus *status,
+ target_wait_flags options)
{
struct remote_state *rs = get_remote_state ();
struct stop_reply *stop_reply;
STATUS just as `wait' would. */
ptid_t
-remote_target::wait_as (ptid_t ptid, target_waitstatus *status, int options)
+remote_target::wait_as (ptid_t ptid, target_waitstatus *status,
+ target_wait_flags options)
{
struct remote_state *rs = get_remote_state ();
ptid_t event_ptid = null_ptid;
STATUS just as `wait' would. */
ptid_t
-remote_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
+remote_target::wait (ptid_t ptid, struct target_waitstatus *status,
+ target_wait_flags options)
{
ptid_t event_ptid;
ULONGEST *xfered_len)
{
struct target_section *secp;
- struct target_section_table *table;
secp = target_section_by_addr (this, memaddr);
if (secp != NULL
&& (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
{
- struct target_section *p;
ULONGEST memend = memaddr + len;
- table = target_get_section_table (this);
-
- for (p = table->sections; p < table->sections_end; p++)
+ target_section_table *table = target_get_section_table (this);
+ for (target_section &p : *table)
{
- if (memaddr >= p->addr)
+ if (memaddr >= p.addr)
{
- if (memend <= p->endaddr)
+ if (memend <= p.endaddr)
{
/* Entire transfer is within this section. */
return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
xfered_len);
}
- else if (memaddr >= p->endaddr)
+ else if (memaddr >= p.endaddr)
{
/* This section ends before the transfer starts. */
continue;
else
{
/* This section overlaps the transfer. Just do half. */
- len = p->endaddr - memaddr;
+ len = p.endaddr - memaddr;
return remote_read_bytes_1 (memaddr, readbuf, len, unit_size,
xfered_len);
}
/* It doesn't make sense to use qCRC if the remote target is
connected but not running. */
- if (target_has_execution && packet_support (PACKET_qCRC) != PACKET_DISABLE)
+ if (target_has_execution ()
+ && packet_support (PACKET_qCRC) != PACKET_DISABLE)
{
enum packet_result result;
/* If the remote target is connected but not running, we should
pass this request down to a lower stratum (e.g. the executable
file). */
- if (!target_has_execution)
+ if (!target_has_execution ())
return TARGET_XFER_EOF;
if (writebuf != NULL)
int found;
ULONGEST found_addr;
+ auto read_memory = [=] (CORE_ADDR addr, gdb_byte *result, size_t len)
+ {
+ return (target_read (this, TARGET_OBJECT_MEMORY, NULL, result, addr, len)
+ == len);
+ };
+
/* Don't go to the target if we don't have to. This is done before
checking packet_config_support to avoid the possibility that a
success for this edge case means the facility works in
{
/* Target doesn't provided special support, fall back and use the
standard support (copy memory and do the search here). */
- return simple_search_memory (this, start_addr, search_space_len,
+ return simple_search_memory (read_memory, start_addr, search_space_len,
pattern, pattern_len, found_addrp);
}
supported. If so, fall back to the simple way. */
if (packet_config_support (packet) == PACKET_DISABLE)
{
- return simple_search_memory (this, start_addr, search_space_len,
+ return simple_search_memory (read_memory, start_addr, search_space_len,
pattern, pattern_len, found_addrp);
}
return -1;
/* Do not try this during initial connection, when we do not know
whether there is a running but stopped thread. */
- if (!target_has_execution || inferior_ptid == null_ptid)
+ if (!target_has_execution () || inferior_ptid == null_ptid)
return beneath ()->read_description ();
if (!data->guesses.empty ())
/* If we're not debugging a process yet, the IPA can't be
loaded. */
- if (!target_has_execution)
+ if (!target_has_execution ())
return 0;
/* Make sure the remote is pointing at the right process. */
{
/* Don't propogate error information up to the client. Instead let
the client find out about the error by querying the target. */
- inferior_event_handler (INF_REG_EVENT, NULL);
+ inferior_event_handler (INF_REG_EVENT);
}
static void
remote_async_inferior_event_handler (gdb_client_data data)
{
- inferior_event_handler (INF_REG_EVENT, data);
+ inferior_event_handler (INF_REG_EVENT);
+
+ remote_target *remote = (remote_target *) data;
+ remote_state *rs = remote->get_remote_state ();
+
+ /* inferior_event_handler may have consumed an event pending on the
+ infrun side without calling target_wait on the REMOTE target, or
+ may have pulled an event out of a different target. Keep trying
+ for this remote target as long it still has either pending events
+ or unacknowledged notifications. */
+
+ if (rs->notif_state->pending_event[notif_client_stop.id] != NULL
+ || !rs->stop_reply_queue.empty ())
+ mark_async_event_handler (rs->remote_async_inferior_event_token);
}
int
set_remotebreak, show_remotebreak,
&setlist, &showlist);
cmd_name = "remotebreak";
- cmd = lookup_cmd (&cmd_name, setlist, "", -1, 1);
+ cmd = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
deprecate_cmd (cmd, "set remote interrupt-sequence");
cmd_name = "remotebreak"; /* needed because lookup_cmd updates the pointer */
- cmd = lookup_cmd (&cmd_name, showlist, "", -1, 1);
+ cmd = lookup_cmd (&cmd_name, showlist, "", NULL, -1, 1);
deprecate_cmd (cmd, "show remote interrupt-sequence");
add_setshow_enum_cmd ("interrupt-sequence", class_support,