mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-28 20:43:45 +08:00
8336d594d5
* linux-low.c (linux_remove_process): Delete. (add_lwp): Don't set last_resume_kind here. (linux_kill): Use `mourn'. (linux_detach): Use `thread_db_detach', and `mourn'. (linux_mourn): New. (linux_attach_lwp_1): Adjust comment. (linux_attach): last_resume_kind moved the thread_info; adjust. (status_pending_p_callback): Adjust. (linux_wait_for_event_1): Adjust. (count_events_callback, select_singlestep_lwp_callback) (select_event_lwp_callback, cancel_breakpoints_callback) (db_wants_lwp_stopped, linux_wait_1, need_step_over_p) (proceed_one_lwp): Adjust. (linux_async): Add debug output. (linux_thread_stopped): New. (linux_pause_all): New. (linux_target_ops): Install linux_mourn, linux_thread_stopped and linux_pause_all. * linux-low.h (struct lwp_info): Delete last_resume_kind field. (thread_db_free): Delete declaration. (thread_db_detach, thread_db_mourn): Declare. * thread-db.c (thread_db_init): Use thread_db_mourn. (thread_db_free): Delete, split in two. (disable_thread_event_reporting): New. (thread_db_detach): New. (thread_db_mourn): New. * server.h (struct thread_info) <last_resume_kind>: New field. <attached>: Add comment. <gdb_detached>: New field. (handler_func): Change return type to int. (handle_serial_event, handle_target_event): Ditto. (gdb_connected): Declare. (tracing): Delete. (disconnected_tracing): Declare. (stop_tracing): Declare. * server.c (handle_query) <qSupported>: Report support for disconnected tracing. (queue_stop_reply_callback): Account for running threads. (gdb_wants_thread_stopped): New. (gdb_wants_all_threads_stopped): New. (gdb_reattached_process): New. (handle_status): Clear the `gdb_detached' flag of all processes. In all-stop, stop all threads. (main): Be sure to leave tfind mode. Handle disconnected tracing. (process_serial_event): If the remote connection breaks, or if an exit was forced with "monitor exit", force an event loop exit. Handle disconnected tracing on detach. (handle_serial_event): Adjust. (handle_target_event): If GDB isn't connected, forward events back to the inferior, unless the last process exited, in which case, exit gdbserver. Adjust interface. * remote-utils.c (remote_open): Don't block in accept. Instead register an event loop source on the listen socket file descriptor. Refactor bits into ... (listen_desc): ... this new global. (gdb_connected): ... this new function. (enable_async_notification): ... this new function. (handle_accept_event): ... this new function. (remote_close): Clear remote_desc. * inferiors.c (add_thread): Set the new thread's last_resume_kind. * target.h (struct target_ops) <mourn, thread_stopped, pause_all>: New fields. (mourn_inferior): Define. (target_process_qsupported): Avoid the dangling else problem. (thread_stopped): Define. (pause_all): Define. (target_waitstatus_to_string): Declare. * target.c (target_waitstatus_to_string): New. * tracepoint.c (tracing): Make extern. (disconnected_tracing): New. (stop_tracing): Make extern. Handle tracing stops due to GDB disconnecting. (cmd_qtdisconnected): New. (cmd_qtstatus): Report disconnected tracing status in trace reply. (handle_tracepoint_general_set): Handle QTDisconnected. * event-loop.c (event_handler_func): Change return type to int. (process_event): Bail out if the event handler wants the event loop to stop. (handle_file_event): Ditto. (start_event_loop): Bail out if the event handler wants the event loop to stop. * nto-low.c (nto_target_ops): Adjust. * spu-low.c (spu_wait): Don't remove the process here. (spu_target_ops): Adjust. * win32-low.c (win32_wait): Don't remove the process here. (win32_target_ops): Adjust.
199 lines
5.2 KiB
C
199 lines
5.2 KiB
C
/* Target operations for the remote server for GDB.
|
|
Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009, 2010
|
|
Free Software Foundation, Inc.
|
|
|
|
Contributed by MontaVista Software.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "server.h"
|
|
|
|
struct target_ops *the_target;
|
|
|
|
void
|
|
set_desired_inferior (int use_general)
|
|
{
|
|
struct thread_info *found;
|
|
|
|
if (use_general == 1)
|
|
found = find_thread_ptid (general_thread);
|
|
else
|
|
{
|
|
found = NULL;
|
|
|
|
/* If we are continuing any (all) thread(s), use step_thread
|
|
to decide which thread to step and/or send the specified
|
|
signal to. */
|
|
if ((!ptid_equal (step_thread, null_ptid)
|
|
&& !ptid_equal (step_thread, minus_one_ptid))
|
|
&& (ptid_equal (cont_thread, null_ptid)
|
|
|| ptid_equal (cont_thread, minus_one_ptid)))
|
|
found = find_thread_ptid (step_thread);
|
|
|
|
if (found == NULL)
|
|
found = find_thread_ptid (cont_thread);
|
|
}
|
|
|
|
if (found == NULL)
|
|
current_inferior = (struct thread_info *) all_threads.head;
|
|
else
|
|
current_inferior = found;
|
|
}
|
|
|
|
int
|
|
read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
|
|
{
|
|
int res;
|
|
res = (*the_target->read_memory) (memaddr, myaddr, len);
|
|
check_mem_read (memaddr, myaddr, len);
|
|
return res;
|
|
}
|
|
|
|
int
|
|
write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
|
|
int len)
|
|
{
|
|
/* Lacking cleanups, there is some potential for a memory leak if the
|
|
write fails and we go through error(). Make sure that no more than
|
|
one buffer is ever pending by making BUFFER static. */
|
|
static unsigned char *buffer = 0;
|
|
int res;
|
|
|
|
if (buffer != NULL)
|
|
free (buffer);
|
|
|
|
buffer = xmalloc (len);
|
|
memcpy (buffer, myaddr, len);
|
|
check_mem_write (memaddr, buffer, len);
|
|
res = (*the_target->write_memory) (memaddr, buffer, len);
|
|
free (buffer);
|
|
buffer = NULL;
|
|
|
|
return res;
|
|
}
|
|
|
|
ptid_t
|
|
mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
|
|
int connected_wait)
|
|
{
|
|
ptid_t ret;
|
|
|
|
if (connected_wait)
|
|
server_waiting = 1;
|
|
|
|
ret = (*the_target->wait) (ptid, ourstatus, options);
|
|
|
|
if (ourstatus->kind == TARGET_WAITKIND_EXITED)
|
|
fprintf (stderr,
|
|
"\nChild exited with status %d\n", ourstatus->value.sig);
|
|
else if (ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
|
|
fprintf (stderr, "\nChild terminated with signal = 0x%x (%s)\n",
|
|
target_signal_to_host (ourstatus->value.sig),
|
|
target_signal_to_name (ourstatus->value.sig));
|
|
|
|
if (connected_wait)
|
|
server_waiting = 0;
|
|
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
start_non_stop (int nonstop)
|
|
{
|
|
if (the_target->start_non_stop == NULL)
|
|
{
|
|
if (nonstop)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
return (*the_target->start_non_stop) (nonstop);
|
|
}
|
|
|
|
void
|
|
set_target_ops (struct target_ops *target)
|
|
{
|
|
the_target = (struct target_ops *) xmalloc (sizeof (*the_target));
|
|
memcpy (the_target, target, sizeof (*the_target));
|
|
}
|
|
|
|
/* Convert pid to printable format. */
|
|
|
|
const char *
|
|
target_pid_to_str (ptid_t ptid)
|
|
{
|
|
static char buf[80];
|
|
|
|
if (ptid_equal (ptid, minus_one_ptid))
|
|
snprintf (buf, sizeof (buf), "<all threads>");
|
|
else if (ptid_equal (ptid, null_ptid))
|
|
snprintf (buf, sizeof (buf), "<null thread>");
|
|
else if (ptid_get_tid (ptid) != 0)
|
|
snprintf (buf, sizeof (buf), "Thread %d.0x%lx",
|
|
ptid_get_pid (ptid), ptid_get_tid (ptid));
|
|
else if (ptid_get_lwp (ptid) != 0)
|
|
snprintf (buf, sizeof (buf), "LWP %d.%ld",
|
|
ptid_get_pid (ptid), ptid_get_lwp (ptid));
|
|
else
|
|
snprintf (buf, sizeof (buf), "Process %d",
|
|
ptid_get_pid (ptid));
|
|
|
|
return buf;
|
|
}
|
|
|
|
/* Return a pretty printed form of target_waitstatus. */
|
|
|
|
const char *
|
|
target_waitstatus_to_string (const struct target_waitstatus *ws)
|
|
{
|
|
static char buf[200];
|
|
const char *kind_str = "status->kind = ";
|
|
|
|
switch (ws->kind)
|
|
{
|
|
case TARGET_WAITKIND_EXITED:
|
|
sprintf (buf, "%sexited, status = %d",
|
|
kind_str, ws->value.integer);
|
|
break;
|
|
case TARGET_WAITKIND_STOPPED:
|
|
sprintf (buf, "%sstopped, signal = %s",
|
|
kind_str, target_signal_to_name (ws->value.sig));
|
|
break;
|
|
case TARGET_WAITKIND_SIGNALLED:
|
|
sprintf (buf, "%ssignalled, signal = %s",
|
|
kind_str, target_signal_to_name (ws->value.sig));
|
|
break;
|
|
case TARGET_WAITKIND_LOADED:
|
|
sprintf (buf, "%sloaded", kind_str);
|
|
break;
|
|
case TARGET_WAITKIND_EXECD:
|
|
sprintf (buf, "%sexecd", kind_str);
|
|
break;
|
|
case TARGET_WAITKIND_SPURIOUS:
|
|
sprintf (buf, "%sspurious", kind_str);
|
|
break;
|
|
case TARGET_WAITKIND_IGNORE:
|
|
sprintf (buf, "%signore", kind_str);
|
|
break;
|
|
default:
|
|
sprintf (buf, "%sunknown???", kind_str);
|
|
break;
|
|
}
|
|
|
|
return buf;
|
|
}
|