- case 'g':
- require_running (own_buf);
- set_desired_inferior (1);
- registers_to_string (own_buf);
- break;
- case 'G':
- require_running (own_buf);
- set_desired_inferior (1);
- registers_from_string (&own_buf[1]);
- write_ok (own_buf);
- break;
- case 'm':
- require_running (own_buf);
- decode_m_packet (&own_buf[1], &mem_addr, &len);
- if (read_inferior_memory (mem_addr, mem_buf, len) == 0)
- convert_int_to_ascii (mem_buf, own_buf, len);
- else
- write_enn (own_buf);
- break;
- case 'M':
- require_running (own_buf);
- decode_M_packet (&own_buf[1], &mem_addr, &len, mem_buf);
- if (write_inferior_memory (mem_addr, mem_buf, len) == 0)
- write_ok (own_buf);
- else
- write_enn (own_buf);
- break;
- case 'X':
- require_running (own_buf);
- if (decode_X_packet (&own_buf[1], packet_len - 1,
- &mem_addr, &len, mem_buf) < 0
- || write_inferior_memory (mem_addr, mem_buf, len) != 0)
- write_enn (own_buf);
- else
- write_ok (own_buf);
- break;
- case 'C':
- require_running (own_buf);
- convert_ascii_to_int (own_buf + 1, &sig, 1);
- if (target_signal_to_host_p (sig))
- signal = target_signal_to_host (sig);
- else
- signal = 0;
- myresume (own_buf, 0, signal);
- break;
- case 'S':
- require_running (own_buf);
- convert_ascii_to_int (own_buf + 1, &sig, 1);
- if (target_signal_to_host_p (sig))
- signal = target_signal_to_host (sig);
- else
- signal = 0;
- myresume (own_buf, 1, signal);
- break;
- case 'c':
- require_running (own_buf);
- signal = 0;
- myresume (own_buf, 0, signal);
- break;
- case 's':
- require_running (own_buf);
- signal = 0;
- myresume (own_buf, 1, signal);
- break;
- case 'Z':
- {
- char *lenptr;
- char *dataptr;
- CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
- int len = strtol (lenptr + 1, &dataptr, 16);
- char type = own_buf[1];
-
- if (the_target->insert_watchpoint == NULL
- || (type < '2' || type > '4'))
- {
- /* No watchpoint support or not a watchpoint command;
- unrecognized either way. */
- own_buf[0] = '\0';
- }
- else
- {
- int res;
-
- require_running (own_buf);
- res = (*the_target->insert_watchpoint) (type, addr, len);
- if (res == 0)
- write_ok (own_buf);
- else if (res == 1)
- /* Unsupported. */
- own_buf[0] = '\0';
- else
- write_enn (own_buf);
- }
- break;
- }
- case 'z':
- {
- char *lenptr;
- char *dataptr;
- CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
- int len = strtol (lenptr + 1, &dataptr, 16);
- char type = own_buf[1];
-
- if (the_target->remove_watchpoint == NULL
- || (type < '2' || type > '4'))
- {
- /* No watchpoint support or not a watchpoint command;
- unrecognized either way. */
- own_buf[0] = '\0';
- }
- else
- {
- int res;
-
- require_running (own_buf);
- res = (*the_target->remove_watchpoint) (type, addr, len);
- if (res == 0)
- write_ok (own_buf);
- else if (res == 1)
- /* Unsupported. */
- own_buf[0] = '\0';
- else
- write_enn (own_buf);
- }
- break;
- }
- case 'k':
- response_needed = 0;
- if (!target_running ())
- /* The packet we received doesn't make sense - but we
- can't reply to it, either. */
- goto restart;
-
- fprintf (stderr, "Killing inferior\n");
- kill_inferior ();
-
- /* When using the extended protocol, we wait with no
- program running. The traditional protocol will exit
- instead. */
- if (extended_protocol)
- {
- last_status.kind = TARGET_WAITKIND_EXITED;
- last_status.value.sig = TARGET_SIGNAL_KILL;
- was_running = 0;
- goto restart;
- }
- else
+ }
+
+ fprintf (stderr,
+ "Disconnected tracing in effect, "
+ "leaving gdbserver attached to the process\n");
+
+ /* Make sure we're in non-stop/async mode, so we we can both
+ wait for an async socket accept, and handle async target
+ events simultaneously. There's also no point either in
+ having the target stop all threads, when we're going to
+ pass signals down without informing GDB. */
+ if (!non_stop)
+ {
+ if (debug_threads)
+ fprintf (stderr, "Forcing non-stop mode\n");
+
+ non_stop = 1;
+ start_non_stop (1);
+ }
+
+ process->gdb_detached = 1;
+
+ /* Detaching implicitly resumes all threads. */
+ resume_info.thread = minus_one_ptid;
+ resume_info.kind = resume_continue;
+ resume_info.sig = 0;
+ (*the_target->resume) (&resume_info, 1);
+
+ write_ok (own_buf);
+ break; /* from switch/case */
+ }
+
+ fprintf (stderr, "Detaching from process %d\n", pid);
+ stop_tracing ();
+ if (detach_inferior (pid) != 0)
+ write_enn (own_buf);
+ else
+ {
+ discard_queued_stop_replies (pid);
+ write_ok (own_buf);
+
+ if (extended_protocol)
+ {
+ /* Treat this like a normal program exit. */
+ last_status.kind = TARGET_WAITKIND_EXITED;
+ last_status.value.integer = 0;
+ last_ptid = pid_to_ptid (pid);
+
+ current_inferior = NULL;
+ }
+ else
+ {
+ putpkt (own_buf);
+ remote_close ();
+
+ /* If we are attached, then we can exit. Otherwise, we
+ need to hang around doing nothing, until the child is
+ gone. */
+ for_each_inferior (&all_processes,
+ join_inferiors_callback);
+ exit (0);
+ }
+ }
+ break;
+ case '!':
+ extended_protocol = 1;
+ write_ok (own_buf);
+ break;
+ case '?':
+ handle_status (own_buf);
+ break;
+ case 'H':
+ if (own_buf[1] == 'c' || own_buf[1] == 'g' || own_buf[1] == 's')
+ {
+ ptid_t gdb_id, thread_id;
+ int pid;
+
+ require_running (own_buf);
+
+ gdb_id = read_ptid (&own_buf[2], NULL);
+
+ pid = ptid_get_pid (gdb_id);
+
+ if (ptid_equal (gdb_id, null_ptid)
+ || ptid_equal (gdb_id, minus_one_ptid))
+ thread_id = null_ptid;
+ else if (pid != 0
+ && ptid_equal (pid_to_ptid (pid),
+ gdb_id))
+ {
+ struct thread_info *thread =
+ (struct thread_info *) find_inferior (&all_threads,
+ first_thread_of,
+ &pid);
+ if (!thread)