/* Main code for remote server for GDB.
- Copyright (C) 1989-2018 Free Software Foundation, Inc.
+ Copyright (C) 1989-2019 Free Software Foundation, Inc.
This file is part of GDB.
handle_detach (char *own_buf)
{
client_state &cs = get_client_state ();
- require_running_or_return (own_buf);
- int pid;
+ process_info *process;
if (cs.multi_process)
{
/* skip 'D;' */
- pid = strtol (&own_buf[2], NULL, 16);
+ int pid = strtol (&own_buf[2], NULL, 16);
+
+ process = find_process_pid (pid);
}
else
- pid = current_ptid.pid ();
-
- if ((tracing && disconnected_tracing) || any_persistent_commands ())
{
- struct process_info *process = find_process_pid (pid);
+ process = (current_thread != nullptr
+ ? get_thread_process (current_thread)
+ : nullptr);
+ }
- if (process == NULL)
- {
- write_enn (own_buf);
- return;
- }
+ if (process == NULL)
+ {
+ write_enn (own_buf);
+ return;
+ }
+ if ((tracing && disconnected_tracing) || any_persistent_commands (process))
+ {
if (tracing && disconnected_tracing)
fprintf (stderr,
"Disconnected tracing in effect, "
"leaving gdbserver attached to the process\n");
- if (any_persistent_commands ())
+ if (any_persistent_commands (process))
fprintf (stderr,
"Persistent commands are present, "
"leaving gdbserver attached to the process\n");
return;
}
- fprintf (stderr, "Detaching from process %d\n", pid);
+ fprintf (stderr, "Detaching from process %d\n", process->pid);
stop_tracing ();
- if (detach_inferior (pid) != 0)
+
+ /* We'll need this after PROCESS has been destroyed. */
+ int pid = process->pid;
+
+ if (detach_inferior (process) != 0)
write_enn (own_buf);
else
{
pid = strtol (p, NULL, 16);
else
pid = signal_pid;
- if (pid != 0 && kill_inferior (pid) == 0)
+
+ process_info *proc = find_process_pid (pid);
+
+ if (proc != nullptr && kill_inferior (proc) == 0)
{
cs.last_status.kind = TARGET_WAITKIND_SIGNALLED;
cs.last_status.value.sig = GDB_SIGNAL_KILL;
/* If the last event thread is not found for some reason, look
for some other thread that might have an event to report. */
if (thread == NULL)
- thread = find_thread ([] (thread_info *thread)
+ thread = find_thread ([] (thread_info *thr_arg)
{
- return thread->status_pending_p;
+ return thr_arg->status_pending_p;
});
/* If we're still out of luck, simply pick the first thread in
static void
kill_inferior_callback (process_info *process)
{
- int pid = process->pid;
-
- kill_inferior (pid);
- discard_queued_stop_replies (ptid_t (pid));
+ kill_inferior (process);
+ discard_queued_stop_replies (ptid_t (process->pid));
}
/* Call this when exiting gdbserver with possible inferiors that need
int pid = process->pid;
if (process->attached)
- detach_inferior (pid);
+ detach_inferior (process);
else
- kill_inferior (pid);
+ kill_inferior (process);
discard_queued_stop_replies (ptid_t (pid));
});
#if GDB_SELF_TEST
selftests::run_tests (selftest_filter);
#else
- printf (_("Selftests are not available in a non-development build.\n"));
+ printf (_("Selftests have been disabled for this build.\n"));
#endif
throw_quit ("Quit");
}
client_state &cs = get_client_state ();
int signal;
unsigned int len;
- int res;
CORE_ADDR mem_addr;
unsigned char sig;
int packet_len;
}
break;
case 'm':
- require_running_or_break (cs.own_buf);
- decode_m_packet (&cs.own_buf[1], &mem_addr, &len);
- res = gdb_read_memory (mem_addr, mem_buf, len);
- if (res < 0)
- write_enn (cs.own_buf);
- else
- bin2hex (mem_buf, cs.own_buf, res);
+ {
+ require_running_or_break (cs.own_buf);
+ decode_m_packet (&cs.own_buf[1], &mem_addr, &len);
+ int res = gdb_read_memory (mem_addr, mem_buf, len);
+ if (res < 0)
+ write_enn (cs.own_buf);
+ else
+ bin2hex (mem_buf, cs.own_buf, res);
+ }
break;
case 'M':
require_running_or_break (cs.own_buf);