diff options
Diffstat (limited to 'gdbserver')
-rw-r--r-- | gdbserver/gdbthread.h | 4 | ||||
-rw-r--r-- | gdbserver/linux-low.cc | 132 | ||||
-rw-r--r-- | gdbserver/linux-low.h | 5 | ||||
-rw-r--r-- | gdbserver/netbsd-low.cc | 50 | ||||
-rw-r--r-- | gdbserver/remote-utils.cc | 44 | ||||
-rw-r--r-- | gdbserver/server.cc | 90 | ||||
-rw-r--r-- | gdbserver/target.cc | 14 | ||||
-rw-r--r-- | gdbserver/win32-low.cc | 40 |
8 files changed, 171 insertions, 208 deletions
diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h index fc9b4d2..7c293b1 100644 --- a/gdbserver/gdbthread.h +++ b/gdbserver/gdbthread.h @@ -31,9 +31,7 @@ struct thread_info { thread_info (ptid_t id, void *target_data) : id (id), target_data (target_data) - { - this->last_status.kind = TARGET_WAITKIND_IGNORE; - } + {} ~thread_info () { diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 6ea517e..b6820ad 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -450,7 +450,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, struct thread_info *event_thr = get_lwp_thread (event_lwp); struct lwp_info *new_lwp; - gdb_assert (event_lwp->waitstatus.kind == TARGET_WAITKIND_IGNORE); + gdb_assert (event_lwp->waitstatus.kind () == TARGET_WAITKIND_IGNORE); /* All extended events we currently use are mid-syscall. Only PTRACE_EVENT_STOP is delivered more like a signal-stop, but @@ -515,7 +515,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, child_lwp->status_pending_p = 0; child_thr = get_lwp_thread (child_lwp); child_thr->last_resume_kind = resume_stop; - child_thr->last_status.kind = TARGET_WAITKIND_STOPPED; + child_thr->last_status.set_stopped (GDB_SIGNAL_0); /* If we're suspending all threads, leave this one suspended too. If the fork/clone parent is stepping over a breakpoint, @@ -554,11 +554,9 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, /* Save fork info in the parent thread. */ if (event == PTRACE_EVENT_FORK) - event_lwp->waitstatus.kind = TARGET_WAITKIND_FORKED; + event_lwp->waitstatus.set_forked (ptid); else if (event == PTRACE_EVENT_VFORK) - event_lwp->waitstatus.kind = TARGET_WAITKIND_VFORKED; - - event_lwp->waitstatus.value.related_pid = ptid; + event_lwp->waitstatus.set_vforked (ptid); /* The status_pending field contains bits denoting the extended event, so when the pending event is handled, @@ -625,7 +623,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, } else if (cs.report_thread_events) { - new_lwp->waitstatus.kind = TARGET_WAITKIND_THREAD_CREATED; + new_lwp->waitstatus.set_thread_created (); new_lwp->status_pending_p = 1; new_lwp->status_pending = status; } @@ -639,7 +637,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, } else if (event == PTRACE_EVENT_VFORK_DONE) { - event_lwp->waitstatus.kind = TARGET_WAITKIND_VFORK_DONE; + event_lwp->waitstatus.set_vfork_done (); if (event_lwp->bp_reinsert != 0 && supports_software_single_step ()) { @@ -684,16 +682,16 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, arch_setup_thread (event_thr); /* Set the event status. */ - event_lwp->waitstatus.kind = TARGET_WAITKIND_EXECD; - event_lwp->waitstatus.value.execd_pathname - = xstrdup (linux_proc_pid_to_exec_file (lwpid_of (event_thr))); + event_lwp->waitstatus.set_execd + (make_unique_xstrdup + (linux_proc_pid_to_exec_file (lwpid_of (event_thr)))); /* Mark the exec status as pending. */ event_lwp->stopped = 1; event_lwp->status_pending_p = 1; event_lwp->status_pending = wstat; event_thr->last_resume_kind = resume_continue; - event_thr->last_status.kind = TARGET_WAITKIND_IGNORE; + event_thr->last_status.set_ignore (); /* Update syscall state in the new lwp, effectively mid-syscall too. */ event_lwp->syscall_state = TARGET_WAITKIND_SYSCALL_ENTRY; @@ -1388,8 +1386,8 @@ get_detach_signal (struct thread_info *thread) /* If the thread had been suspended by gdbserver, and it stopped cleanly, then it'll have stopped with SIGSTOP. But we don't want to deliver that SIGSTOP. */ - if (thread->last_status.kind != TARGET_WAITKIND_STOPPED - || thread->last_status.value.sig == GDB_SIGNAL_0) + if (thread->last_status.kind () != TARGET_WAITKIND_STOPPED + || thread->last_status.sig () == GDB_SIGNAL_0) return 0; /* Otherwise, we may need to deliver the signal we @@ -1712,7 +1710,7 @@ lwp_resumed (struct lwp_info *lwp) corresponding stop to gdb yet? If so, the thread is still resumed/running from gdb's perspective. */ if (thread->last_resume_kind == resume_stop - && thread->last_status.kind == TARGET_WAITKIND_IGNORE) + && thread->last_status.kind () == TARGET_WAITKIND_IGNORE) return 1; return 0; @@ -2464,7 +2462,7 @@ linux_process_target::resume_stopped_resumed_lwps (thread_info *thread) if (lp->stopped && !lp->suspended && !lp->status_pending_p - && thread->last_status.kind == TARGET_WAITKIND_IGNORE) + && thread->last_status.kind () == TARGET_WAITKIND_IGNORE) { int step = 0; @@ -2710,7 +2708,7 @@ select_event_lwp (struct lwp_info **orig_lp) { lwp_info *lp = get_thread_lwp (thread); - return (thread->last_status.kind == TARGET_WAITKIND_IGNORE + return (thread->last_status.kind () == TARGET_WAITKIND_IGNORE && thread->last_resume_kind == resume_step && lp->status_pending_p); }); @@ -2732,7 +2730,7 @@ select_event_lwp (struct lwp_info **orig_lp) lwp_info *lp = get_thread_lwp (thread); /* Only resumed LWPs that have an event pending. */ - return (thread->last_status.kind == TARGET_WAITKIND_IGNORE + return (thread->last_status.kind () == TARGET_WAITKIND_IGNORE && lp->status_pending_p); }); } @@ -2831,17 +2829,17 @@ linux_process_target::stabilize_threads () over internal breakpoints and such. */ wait_1 (minus_one_ptid, &ourstatus, 0); - if (ourstatus.kind == TARGET_WAITKIND_STOPPED) + if (ourstatus.kind () == TARGET_WAITKIND_STOPPED) { lwp = get_thread_lwp (current_thread); /* Lock it. */ lwp_suspended_inc (lwp); - if (ourstatus.value.sig != GDB_SIGNAL_0 + if (ourstatus.sig () != GDB_SIGNAL_0 || current_thread->last_resume_kind == resume_stop) { - wstat = W_STOPCODE (gdb_signal_to_host (ourstatus.value.sig)); + wstat = W_STOPCODE (gdb_signal_to_host (ourstatus.sig ())); enqueue_one_deferred_signal (lwp, &wstat); } } @@ -2877,7 +2875,7 @@ ignore_event (struct target_waitstatus *ourstatus) another target_wait call. */ async_file_mark (); - ourstatus->kind = TARGET_WAITKIND_IGNORE; + ourstatus->set_ignore (); return null_ptid; } @@ -2892,9 +2890,9 @@ linux_process_target::filter_exit_event (lwp_info *event_child, if (!last_thread_of_process_p (pid_of (thread))) { if (cs.report_thread_events) - ourstatus->kind = TARGET_WAITKIND_THREAD_EXITED; + ourstatus->set_thread_exited (0); else - ourstatus->kind = TARGET_WAITKIND_IGNORE; + ourstatus->set_ignore (); delete_lwp (event_child); } @@ -2965,7 +2963,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, bp_explains_trap = 0; trace_event = 0; in_step_range = 0; - ourstatus->kind = TARGET_WAITKIND_IGNORE; + ourstatus->set_ignore (); auto status_pending_p_any = [&] (thread_info *thread) { @@ -3006,7 +3004,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, debug_exit (); } - ourstatus->kind = TARGET_WAITKIND_IGNORE; + ourstatus->set_ignore (); return null_ptid; } else if (pid == -1) @@ -3018,7 +3016,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, debug_exit (); } - ourstatus->kind = TARGET_WAITKIND_NO_RESUMED; + ourstatus->set_no_resumed (); return null_ptid; } @@ -3030,8 +3028,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, { if (WIFEXITED (w)) { - ourstatus->kind = TARGET_WAITKIND_EXITED; - ourstatus->value.integer = WEXITSTATUS (w); + ourstatus->set_exited (WEXITSTATUS (w)); if (debug_threads) { @@ -3044,8 +3041,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, } else { - ourstatus->kind = TARGET_WAITKIND_SIGNALLED; - ourstatus->value.sig = gdb_signal_from_host (WTERMSIG (w)); + ourstatus->set_signalled (gdb_signal_from_host (WTERMSIG (w))); if (debug_threads) { @@ -3057,7 +3053,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, } } - if (ourstatus->kind == TARGET_WAITKIND_EXITED) + if (ourstatus->kind () == TARGET_WAITKIND_EXITED) return filter_exit_event (event_child, ourstatus); return ptid_of (current_thread); @@ -3252,8 +3248,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, if (stabilizing_threads) { - ourstatus->kind = TARGET_WAITKIND_STOPPED; - ourstatus->value.sig = GDB_SIGNAL_0; + ourstatus->set_stopped (GDB_SIGNAL_0); if (debug_threads) { @@ -3378,7 +3373,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, || (gdb_breakpoint_here (event_child->stop_pc) && gdb_condition_true_at_breakpoint (event_child->stop_pc) && gdb_no_commands_at_breakpoint (event_child->stop_pc)) - || event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE); + || event_child->waitstatus.kind () != TARGET_WAITKIND_IGNORE); run_breakpoint_commands (event_child->stop_pc); @@ -3448,7 +3443,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, if (debug_threads) { - if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE) + if (event_child->waitstatus.kind () != TARGET_WAITKIND_IGNORE) { std::string str = target_waitstatus_to_string (&event_child->waitstatus); @@ -3589,14 +3584,14 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, unstop_all_lwps (1, event_child); } - if (event_child->waitstatus.kind != TARGET_WAITKIND_IGNORE) + if (event_child->waitstatus.kind () != TARGET_WAITKIND_IGNORE) { /* If the reported event is an exit, fork, vfork or exec, let GDB know. */ /* Break the unreported fork relationship chain. */ - if (event_child->waitstatus.kind == TARGET_WAITKIND_FORKED - || event_child->waitstatus.kind == TARGET_WAITKIND_VFORKED) + if (event_child->waitstatus.kind () == TARGET_WAITKIND_FORKED + || event_child->waitstatus.kind () == TARGET_WAITKIND_VFORKED) { event_child->fork_relative->fork_relative = NULL; event_child->fork_relative = NULL; @@ -3604,10 +3599,13 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, *ourstatus = event_child->waitstatus; /* Clear the event lwp's waitstatus since we handled it already. */ - event_child->waitstatus.kind = TARGET_WAITKIND_IGNORE; + event_child->waitstatus.set_ignore (); } else - ourstatus->kind = TARGET_WAITKIND_STOPPED; + { + /* The actual stop signal is overwritten below. */ + ourstatus->set_stopped (GDB_SIGNAL_0); + } /* Now that we've selected our final event LWP, un-adjust its PC if it was a software breakpoint, and the client doesn't know we can @@ -3627,9 +3625,15 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, if (WSTOPSIG (w) == SYSCALL_SIGTRAP) { - get_syscall_trapinfo (event_child, - &ourstatus->value.syscall_number); - ourstatus->kind = event_child->syscall_state; + int syscall_number; + + get_syscall_trapinfo (event_child, &syscall_number); + if (event_child->syscall_state == TARGET_WAITKIND_SYSCALL_ENTRY) + ourstatus->set_syscall_entry (syscall_number); + else if (event_child->syscall_state == TARGET_WAITKIND_SYSCALL_RETURN) + ourstatus->set_syscall_return (syscall_number); + else + gdb_assert_not_reached ("unexpected syscall state"); } else if (current_thread->last_resume_kind == resume_stop && WSTOPSIG (w) == SIGSTOP) @@ -3637,19 +3641,17 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, /* A thread that has been requested to stop by GDB with vCont;t, and it stopped cleanly, so report as SIG0. The use of SIGSTOP is an implementation detail. */ - ourstatus->value.sig = GDB_SIGNAL_0; + ourstatus->set_stopped (GDB_SIGNAL_0); } else if (current_thread->last_resume_kind == resume_stop && WSTOPSIG (w) != SIGSTOP) { /* A thread that has been requested to stop by GDB with vCont;t, but, it stopped for other reasons. */ - ourstatus->value.sig = gdb_signal_from_host (WSTOPSIG (w)); - } - else if (ourstatus->kind == TARGET_WAITKIND_STOPPED) - { - ourstatus->value.sig = gdb_signal_from_host (WSTOPSIG (w)); + ourstatus->set_stopped (gdb_signal_from_host (WSTOPSIG (w))); } + else if (ourstatus->kind () == TARGET_WAITKIND_STOPPED) + ourstatus->set_stopped (gdb_signal_from_host (WSTOPSIG (w))); gdb_assert (step_over_bkpt == null_ptid); @@ -3657,11 +3659,11 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, { debug_printf ("wait_1 ret = %s, %d, %d\n", target_pid_to_str (ptid_of (current_thread)), - ourstatus->kind, ourstatus->value.sig); + ourstatus->kind (), ourstatus->sig ()); debug_exit (); } - if (ourstatus->kind == TARGET_WAITKIND_EXITED) + if (ourstatus->kind () == TARGET_WAITKIND_EXITED) return filter_exit_event (event_child, ourstatus); return ptid_of (current_thread); @@ -3712,7 +3714,7 @@ linux_process_target::wait (ptid_t ptid, } while ((target_options & TARGET_WNOHANG) == 0 && event_ptid == null_ptid - && ourstatus->kind == TARGET_WAITKIND_IGNORE); + && ourstatus->kind () == TARGET_WAITKIND_IGNORE); /* If at least one stop was reported, there may be more. A single SIGCHLD can signal more than one child stop. */ @@ -3813,15 +3815,9 @@ mark_lwp_dead (struct lwp_info *lwp, int wstat) /* Store in waitstatus as well, as there's nothing else to process for this event. */ if (WIFEXITED (wstat)) - { - lwp->waitstatus.kind = TARGET_WAITKIND_EXITED; - lwp->waitstatus.value.integer = WEXITSTATUS (wstat); - } + lwp->waitstatus.set_exited (WEXITSTATUS (wstat)); else if (WIFSIGNALED (wstat)) - { - lwp->waitstatus.kind = TARGET_WAITKIND_SIGNALLED; - lwp->waitstatus.value.sig = gdb_signal_from_host (WTERMSIG (wstat)); - } + lwp->waitstatus.set_signalled (gdb_signal_from_host (WTERMSIG (wstat))); /* Prevent trying to stop it. */ lwp->stopped = 1; @@ -4087,7 +4083,7 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step, if (lwp->stopped == 0) return; - gdb_assert (lwp->waitstatus.kind == TARGET_WAITKIND_IGNORE); + gdb_assert (lwp->waitstatus.kind () == TARGET_WAITKIND_IGNORE); fast_tpoint_collect_result fast_tp_collecting = lwp->collecting_fast_tracepoint; @@ -4351,7 +4347,7 @@ linux_set_resume_request (thread_info *thread, thread_resume *resume, size_t n) { if (debug_threads) debug_printf ("already %s LWP %ld at GDB's request\n", - (thread->last_status.kind + (thread->last_status.kind () == TARGET_WAITKIND_STOPPED) ? "stopped" : "stopping", @@ -4382,8 +4378,8 @@ linux_set_resume_request (thread_info *thread, thread_resume *resume, size_t n) struct lwp_info *rel = lwp->fork_relative; if (rel->status_pending_p - && (rel->waitstatus.kind == TARGET_WAITKIND_FORKED - || rel->waitstatus.kind == TARGET_WAITKIND_VFORKED)) + && (rel->waitstatus.kind () == TARGET_WAITKIND_FORKED + || rel->waitstatus.kind () == TARGET_WAITKIND_VFORKED)) { if (debug_threads) debug_printf ("not resuming LWP %ld: has queued stop reply\n", @@ -4771,7 +4767,7 @@ linux_process_target::resume_one_thread (thread_info *thread, /* For stop requests, we're done. */ lwp->resume = NULL; - thread->last_status.kind = TARGET_WAITKIND_IGNORE; + thread->last_status.set_ignore (); return; } @@ -4818,7 +4814,7 @@ linux_process_target::resume_one_thread (thread_info *thread, debug_printf ("leaving LWP %ld stopped\n", lwpid_of (thread)); } - thread->last_status.kind = TARGET_WAITKIND_IGNORE; + thread->last_status.set_ignore (); lwp->resume = NULL; } @@ -4918,7 +4914,7 @@ linux_process_target::proceed_one_lwp (thread_info *thread, lwp_info *except) } if (thread->last_resume_kind == resume_stop - && thread->last_status.kind != TARGET_WAITKIND_IGNORE) + && thread->last_status.kind () != TARGET_WAITKIND_IGNORE) { if (debug_threads) debug_printf (" client wants LWP to remain %ld stopped\n", diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index c6a17a4..05067ff 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -721,11 +721,6 @@ struct pending_signal struct lwp_info { - lwp_info () - { - this->waitstatus.kind = TARGET_WAITKIND_IGNORE; - } - /* Backlink to the parent object. */ struct thread_info *thread = nullptr; diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc index 84e34d0..ada92c1 100644 --- a/gdbserver/netbsd-low.cc +++ b/gdbserver/netbsd-low.cc @@ -206,20 +206,11 @@ static void netbsd_store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) { if (WIFEXITED (hoststatus)) - { - ourstatus->kind = TARGET_WAITKIND_EXITED; - ourstatus->value.integer = WEXITSTATUS (hoststatus); - } + ourstatus->set_exited (WEXITSTATUS (hoststatus)); else if (!WIFSTOPPED (hoststatus)) - { - ourstatus->kind = TARGET_WAITKIND_SIGNALLED; - ourstatus->value.sig = gdb_signal_from_host (WTERMSIG (hoststatus)); - } + ourstatus->set_signalled (gdb_signal_from_host (WTERMSIG (hoststatus))); else - { - ourstatus->kind = TARGET_WAITKIND_STOPPED; - ourstatus->value.sig = gdb_signal_from_host (WSTOPSIG (hoststatus)); - } + ourstatus->set_stopped (gdb_signal_from_host (WSTOPSIG (hoststatus))); } /* Implement a safe wrapper around waitpid(). */ @@ -258,14 +249,14 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, if (pid == 0) { gdb_assert (target_options & TARGET_WNOHANG); - ourstatus->kind = TARGET_WAITKIND_IGNORE; + ourstatus->set_ignore (); return null_ptid; } gdb_assert (pid != -1); /* If the child stopped, keep investigating its status. */ - if (ourstatus->kind != TARGET_WAITKIND_STOPPED) + if (ourstatus->kind () != TARGET_WAITKIND_STOPPED) return wptid; /* Extract the event and thread that received a signal. */ @@ -307,12 +298,11 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, Ignore exited events for an unknown LWP. */ thread_info *thr = find_thread_ptid (wptid); if (thr == nullptr) - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); else { - ourstatus->kind = TARGET_WAITKIND_THREAD_EXITED; /* NetBSD does not store an LWP exit status. */ - ourstatus->value.integer = 0; + ourstatus->set_thread_exited (0); remove_thread (thr); } @@ -329,20 +319,19 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, not yet reported their PTRACE_LWP_CREATE event. Ignore born events for an already-known LWP. */ if (find_thread_ptid (wptid)) - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); else { add_thread (wptid, NULL); - ourstatus->kind = TARGET_WAITKIND_THREAD_CREATED; + ourstatus->set_thread_created (); } return wptid; } if (code == TRAP_EXEC) { - ourstatus->kind = TARGET_WAITKIND_EXECD; - ourstatus->value.execd_pathname - = xstrdup (netbsd_nat::pid_to_exec_file (pid)); + ourstatus->set_execd + (make_unique_xstrdup (netbsd_nat::pid_to_exec_file (pid))); return wptid; } @@ -356,14 +345,15 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, if (!netbsd_catch_this_syscall(sysnum)) { /* If the core isn't interested in this event, ignore it. */ - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); return wptid; } - ourstatus->kind - = ((code == TRAP_SCE) ? TARGET_WAITKIND_SYSCALL_ENTRY : - TARGET_WAITKIND_SYSCALL_RETURN); - ourstatus->value.syscall_number = sysnum; + if (code == TRAP_SCE) + ourstatus->set_syscall_entry (sysnum); + else + ourstatus->set_syscall_return (sysnum); + return wptid; } @@ -381,7 +371,7 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus, } /* Unclassified SIGTRAP event. */ - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); return wptid; } @@ -401,10 +391,10 @@ netbsd_process_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, This may also happen on attach, when an event is registered on a thread that was not fully initialized during the attach stage. */ if (wptid.lwp () != 0 && !find_thread_ptid (wptid) - && ourstatus->kind != TARGET_WAITKIND_THREAD_EXITED) + && ourstatus->kind () != TARGET_WAITKIND_THREAD_EXITED) add_thread (wptid, nullptr); - switch (ourstatus->kind) + switch (ourstatus->kind ()) { case TARGET_WAITKIND_EXITED: case TARGET_WAITKIND_STOPPED: diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index b79c2aa..a4cc326 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1087,9 +1087,9 @@ prepare_resume_reply (char *buf, ptid_t ptid, client_state &cs = get_client_state (); if (debug_threads) debug_printf ("Writing resume reply for %s:%d\n", - target_pid_to_str (ptid), status->kind); + target_pid_to_str (ptid), status->kind ()); - switch (status->kind) + switch (status->kind ()) { case TARGET_WAITKIND_STOPPED: case TARGET_WAITKIND_FORKED: @@ -1104,27 +1104,27 @@ prepare_resume_reply (char *buf, ptid_t ptid, const char **regp; struct regcache *regcache; - if ((status->kind == TARGET_WAITKIND_FORKED && cs.report_fork_events) - || (status->kind == TARGET_WAITKIND_VFORKED + if ((status->kind () == TARGET_WAITKIND_FORKED && cs.report_fork_events) + || (status->kind () == TARGET_WAITKIND_VFORKED && cs.report_vfork_events)) { enum gdb_signal signal = GDB_SIGNAL_TRAP; - const char *event = (status->kind == TARGET_WAITKIND_FORKED + const char *event = (status->kind () == TARGET_WAITKIND_FORKED ? "fork" : "vfork"); sprintf (buf, "T%02x%s:", signal, event); buf += strlen (buf); - buf = write_ptid (buf, status->value.related_pid); + buf = write_ptid (buf, status->child_ptid ()); strcat (buf, ";"); } - else if (status->kind == TARGET_WAITKIND_VFORK_DONE + else if (status->kind () == TARGET_WAITKIND_VFORK_DONE && cs.report_vfork_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; sprintf (buf, "T%02xvforkdone:;", signal); } - else if (status->kind == TARGET_WAITKIND_EXECD && cs.report_exec_events) + else if (status->kind () == TARGET_WAITKIND_EXECD && cs.report_exec_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; const char *event = "exec"; @@ -1134,34 +1134,32 @@ prepare_resume_reply (char *buf, ptid_t ptid, buf += strlen (buf); /* Encode pathname to hexified format. */ - bin2hex ((const gdb_byte *) status->value.execd_pathname, + bin2hex ((const gdb_byte *) status->execd_pathname (), hexified_pathname, - strlen (status->value.execd_pathname)); + strlen (status->execd_pathname ())); sprintf (buf, "%s;", hexified_pathname); - xfree (status->value.execd_pathname); - status->value.execd_pathname = NULL; buf += strlen (buf); } - else if (status->kind == TARGET_WAITKIND_THREAD_CREATED + else if (status->kind () == TARGET_WAITKIND_THREAD_CREATED && cs.report_thread_events) { enum gdb_signal signal = GDB_SIGNAL_TRAP; sprintf (buf, "T%02xcreate:;", signal); } - else if (status->kind == TARGET_WAITKIND_SYSCALL_ENTRY - || status->kind == TARGET_WAITKIND_SYSCALL_RETURN) + else if (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY + || status->kind () == TARGET_WAITKIND_SYSCALL_RETURN) { enum gdb_signal signal = GDB_SIGNAL_TRAP; - const char *event = (status->kind == TARGET_WAITKIND_SYSCALL_ENTRY + const char *event = (status->kind () == TARGET_WAITKIND_SYSCALL_ENTRY ? "syscall_entry" : "syscall_return"); sprintf (buf, "T%02x%s:%x;", signal, event, - status->value.syscall_number); + status->syscall_number ()); } else - sprintf (buf, "T%02x", status->value.sig); + sprintf (buf, "T%02x", status->sig ()); if (disable_packet_T) { @@ -1283,19 +1281,19 @@ prepare_resume_reply (char *buf, ptid_t ptid, case TARGET_WAITKIND_EXITED: if (cs.multi_process) sprintf (buf, "W%x;process:%x", - status->value.integer, ptid.pid ()); + status->exit_status (), ptid.pid ()); else - sprintf (buf, "W%02x", status->value.integer); + sprintf (buf, "W%02x", status->exit_status ()); break; case TARGET_WAITKIND_SIGNALLED: if (cs.multi_process) sprintf (buf, "X%x;process:%x", - status->value.sig, ptid.pid ()); + status->sig (), ptid.pid ()); else - sprintf (buf, "X%02x", status->value.sig); + sprintf (buf, "X%02x", status->sig ()); break; case TARGET_WAITKIND_THREAD_EXITED: - sprintf (buf, "w%x;", status->value.integer); + sprintf (buf, "w%x;", status->exit_status ()); buf += strlen (buf); buf = write_ptid (buf, ptid); break; diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 193c3d9..2cb378c 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -239,9 +239,9 @@ in_queued_stop_replies_ptid (struct notif_event *event, ptid_t filter_ptid) return true; /* Don't resume fork children that GDB does not know about yet. */ - if ((vstop_event->status.kind == TARGET_WAITKIND_FORKED - || vstop_event->status.kind == TARGET_WAITKIND_VFORKED) - && vstop_event->status.value.related_pid.matches (filter_ptid)) + if ((vstop_event->status.kind () == TARGET_WAITKIND_FORKED + || vstop_event->status.kind () == TARGET_WAITKIND_VFORKED) + && vstop_event->status.child_ptid ().matches (filter_ptid)) return true; return false; @@ -327,9 +327,9 @@ attach_inferior (int pid) /* GDB knows to ignore the first SIGSTOP after attaching to a running process using the "attach" command, but this is different; it's just using "target remote". Pretend it's just starting up. */ - if (cs.last_status.kind == TARGET_WAITKIND_STOPPED - && cs.last_status.value.sig == GDB_SIGNAL_STOP) - cs.last_status.value.sig = GDB_SIGNAL_TRAP; + if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED + && cs.last_status.sig () == GDB_SIGNAL_STOP) + cs.last_status.set_stopped (GDB_SIGNAL_TRAP); current_thread->last_resume_kind = resume_stop; current_thread->last_status = cs.last_status; @@ -1262,8 +1262,7 @@ handle_detach (char *own_buf) /* There is still at least one inferior remaining or we are in extended mode, so don't terminate gdbserver, and instead treat this like a normal program exit. */ - cs.last_status.kind = TARGET_WAITKIND_EXITED; - cs.last_status.value.integer = 0; + cs.last_status.set_exited (0); cs.last_ptid = ptid_t (pid); current_thread = NULL; @@ -2944,7 +2943,7 @@ resume (struct thread_resume *actions, size_t num_actions) { cs.last_ptid = mywait (minus_one_ptid, &cs.last_status, 0, 1); - if (cs.last_status.kind == TARGET_WAITKIND_NO_RESUMED + if (cs.last_status.kind () == TARGET_WAITKIND_NO_RESUMED && !report_no_resumed) { /* The client does not support this stop reply. At least @@ -2954,9 +2953,9 @@ resume (struct thread_resume *actions, size_t num_actions) return; } - if (cs.last_status.kind != TARGET_WAITKIND_EXITED - && cs.last_status.kind != TARGET_WAITKIND_SIGNALLED - && cs.last_status.kind != TARGET_WAITKIND_NO_RESUMED) + if (cs.last_status.kind () != TARGET_WAITKIND_EXITED + && cs.last_status.kind () != TARGET_WAITKIND_SIGNALLED + && cs.last_status.kind () != TARGET_WAITKIND_NO_RESUMED) current_thread->last_status = cs.last_status; /* From the client's perspective, all-stop mode always stops all @@ -2967,8 +2966,8 @@ resume (struct thread_resume *actions, size_t num_actions) prepare_resume_reply (cs.own_buf, cs.last_ptid, &cs.last_status); disable_async_io (); - if (cs.last_status.kind == TARGET_WAITKIND_EXITED - || cs.last_status.kind == TARGET_WAITKIND_SIGNALLED) + if (cs.last_status.kind () == TARGET_WAITKIND_EXITED + || cs.last_status.kind () == TARGET_WAITKIND_SIGNALLED) target_mourn_inferior (cs.last_ptid); } } @@ -3113,7 +3112,7 @@ handle_v_run (char *own_buf) target_create_inferior (program_path.get (), program_args); - if (cs.last_status.kind == TARGET_WAITKIND_STOPPED) + if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED) { prepare_resume_reply (own_buf, cs.last_ptid, &cs.last_status); @@ -3143,8 +3142,7 @@ handle_v_kill (char *own_buf) if (proc != nullptr && kill_inferior (proc) == 0) { - cs.last_status.kind = TARGET_WAITKIND_SIGNALLED; - cs.last_status.value.sig = GDB_SIGNAL_KILL; + cs.last_status.set_signalled (GDB_SIGNAL_KILL); cs.last_ptid = ptid_t (pid); discard_queued_stop_replies (cs.last_ptid); write_ok (own_buf); @@ -3316,7 +3314,7 @@ queue_stop_reply_callback (thread_info *thread) status_string.c_str ()); } - gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE); + gdb_assert (thread->last_status.kind () != TARGET_WAITKIND_IGNORE); /* Pass the last stop reply back to GDB, but don't notify yet. */ @@ -3334,12 +3332,11 @@ gdb_wants_thread_stopped (thread_info *thread) { thread->last_resume_kind = resume_stop; - if (thread->last_status.kind == TARGET_WAITKIND_IGNORE) + if (thread->last_status.kind () == TARGET_WAITKIND_IGNORE) { /* Most threads are stopped implicitly (all-stop); tag that with signal 0. */ - thread->last_status.kind = TARGET_WAITKIND_STOPPED; - thread->last_status.value.sig = GDB_SIGNAL_0; + thread->last_status.set_stopped (GDB_SIGNAL_0); } } @@ -3357,15 +3354,15 @@ gdb_wants_all_threads_stopped (void) static void set_pending_status_callback (thread_info *thread) { - if (thread->last_status.kind != TARGET_WAITKIND_STOPPED - || (thread->last_status.value.sig != GDB_SIGNAL_0 + if (thread->last_status.kind () != TARGET_WAITKIND_STOPPED + || (thread->last_status.sig () != GDB_SIGNAL_0 /* A breakpoint, watchpoint or finished step from a previous GDB run isn't considered interesting for a new GDB run. If we left those pending, the new GDB could consider them random SIGTRAPs. This leaves out real async traps. We'd have to peek into the (target-specific) siginfo to distinguish those. */ - && thread->last_status.value.sig != GDB_SIGNAL_TRAP)) + && thread->last_status.sig () != GDB_SIGNAL_TRAP)) thread->status_pending_p = 1; } @@ -3412,9 +3409,9 @@ handle_status (char *own_buf) /* Prefer the last thread that reported an event to GDB (even if that was a GDB_SIGNAL_TRAP). */ - if (cs.last_status.kind != TARGET_WAITKIND_IGNORE - && cs.last_status.kind != TARGET_WAITKIND_EXITED - && cs.last_status.kind != TARGET_WAITKIND_SIGNALLED) + if (cs.last_status.kind () != TARGET_WAITKIND_IGNORE + && cs.last_status.kind () != TARGET_WAITKIND_EXITED + && cs.last_status.kind () != TARGET_WAITKIND_SIGNALLED) thread = find_thread_ptid (cs.last_ptid); /* If the last event thread is not found for some reason, look @@ -3443,7 +3440,7 @@ handle_status (char *own_buf) cs.general_thread = thread->id; set_desired_thread (); - gdb_assert (tp->last_status.kind != TARGET_WAITKIND_IGNORE); + gdb_assert (tp->last_status.kind () != TARGET_WAITKIND_IGNORE); prepare_resume_reply (own_buf, tp->id, &tp->last_status); } else @@ -3989,8 +3986,7 @@ captured_main (int argc, char *argv[]) } else { - cs.last_status.kind = TARGET_WAITKIND_EXITED; - cs.last_status.value.integer = 0; + cs.last_status.set_exited (0); cs.last_ptid = minus_one_ptid; } @@ -4002,8 +3998,8 @@ captured_main (int argc, char *argv[]) if (current_thread != nullptr) current_process ()->dlls_changed = false; - if (cs.last_status.kind == TARGET_WAITKIND_EXITED - || cs.last_status.kind == TARGET_WAITKIND_SIGNALLED) + if (cs.last_status.kind () == TARGET_WAITKIND_EXITED + || cs.last_status.kind () == TARGET_WAITKIND_SIGNALLED) was_running = 0; else was_running = 1; @@ -4456,8 +4452,7 @@ process_serial_event (void) running. The traditional protocol will exit instead. */ if (extended_protocol) { - cs.last_status.kind = TARGET_WAITKIND_EXITED; - cs.last_status.value.sig = GDB_SIGNAL_KILL; + cs.last_status.set_exited (GDB_SIGNAL_KILL); return 0; } else @@ -4497,7 +4492,7 @@ process_serial_event (void) { target_create_inferior (program_path.get (), program_args); - if (cs.last_status.kind == TARGET_WAITKIND_STOPPED) + if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED) { /* Stopped at the first instruction of the target process. */ @@ -4511,8 +4506,7 @@ process_serial_event (void) } else { - cs.last_status.kind = TARGET_WAITKIND_EXITED; - cs.last_status.value.sig = GDB_SIGNAL_KILL; + cs.last_status.set_exited (GDB_SIGNAL_KILL); } return 0; } @@ -4595,24 +4589,24 @@ handle_target_event (int err, gdb_client_data client_data) cs.last_ptid = mywait (minus_one_ptid, &cs.last_status, TARGET_WNOHANG, 1); - if (cs.last_status.kind == TARGET_WAITKIND_NO_RESUMED) + if (cs.last_status.kind () == TARGET_WAITKIND_NO_RESUMED) { if (gdb_connected () && report_no_resumed) push_stop_notification (null_ptid, &cs.last_status); } - else if (cs.last_status.kind != TARGET_WAITKIND_IGNORE) + else if (cs.last_status.kind () != TARGET_WAITKIND_IGNORE) { int pid = cs.last_ptid.pid (); struct process_info *process = find_process_pid (pid); int forward_event = !gdb_connected () || process->gdb_detached; - if (cs.last_status.kind == TARGET_WAITKIND_EXITED - || cs.last_status.kind == TARGET_WAITKIND_SIGNALLED) + if (cs.last_status.kind () == TARGET_WAITKIND_EXITED + || cs.last_status.kind () == TARGET_WAITKIND_SIGNALLED) { mark_breakpoints_out (process); target_mourn_inferior (cs.last_ptid); } - else if (cs.last_status.kind == TARGET_WAITKIND_THREAD_EXITED) + else if (cs.last_status.kind () == TARGET_WAITKIND_THREAD_EXITED) ; else { @@ -4631,9 +4625,9 @@ handle_target_event (int err, gdb_client_data client_data) exit (0); } - if (cs.last_status.kind == TARGET_WAITKIND_EXITED - || cs.last_status.kind == TARGET_WAITKIND_SIGNALLED - || cs.last_status.kind == TARGET_WAITKIND_THREAD_EXITED) + if (cs.last_status.kind () == TARGET_WAITKIND_EXITED + || cs.last_status.kind () == TARGET_WAITKIND_SIGNALLED + || cs.last_status.kind () == TARGET_WAITKIND_THREAD_EXITED) ; else { @@ -4645,11 +4639,11 @@ handle_target_event (int err, gdb_client_data client_data) if (debug_threads) debug_printf ("GDB not connected; forwarding event %d for" " [%s]\n", - (int) cs.last_status.kind, + (int) cs.last_status.kind (), target_pid_to_str (cs.last_ptid)); - if (cs.last_status.kind == TARGET_WAITKIND_STOPPED) - signal = cs.last_status.value.sig; + if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED) + signal = cs.last_status.sig (); else signal = GDB_SIGNAL_0; target_continue (cs.last_ptid, signal); diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 988c6d5..b6a1cb2 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -172,8 +172,8 @@ mywait (ptid_t ptid, struct target_waitstatus *ourstatus, /* We don't expose _LOADED events to gdbserver core. See the `dlls_changed' global. */ - if (ourstatus->kind == TARGET_WAITKIND_LOADED) - ourstatus->kind = TARGET_WAITKIND_STOPPED; + if (ourstatus->kind () == TARGET_WAITKIND_LOADED) + ourstatus->set_stopped (GDB_SIGNAL_0); /* If GDB is connected through TCP/serial, then GDBserver will most probably be running on its own terminal/console, so it's nice to @@ -183,13 +183,13 @@ mywait (ptid_t ptid, struct target_waitstatus *ourstatus, regular GDB output, in that same terminal. */ if (!remote_connection_is_stdio ()) { - if (ourstatus->kind == TARGET_WAITKIND_EXITED) + if (ourstatus->kind () == TARGET_WAITKIND_EXITED) fprintf (stderr, - "\nChild exited with status %d\n", ourstatus->value.integer); - else if (ourstatus->kind == TARGET_WAITKIND_SIGNALLED) + "\nChild exited with status %d\n", ourstatus->exit_status ()); + else if (ourstatus->kind () == TARGET_WAITKIND_SIGNALLED) fprintf (stderr, "\nChild terminated with signal = 0x%x (%s)\n", - gdb_signal_to_host (ourstatus->value.sig), - gdb_signal_to_name (ourstatus->value.sig)); + gdb_signal_to_host (ourstatus->sig ()), + gdb_signal_to_name (ourstatus->sig ())); } if (connected_wait) diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 1e97f91..cc981d3 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -374,7 +374,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached) if (the_low_target.initial_stuff != NULL) (*the_low_target.initial_stuff) (); - cached_status.kind = TARGET_WAITKIND_IGNORE; + cached_status.set_ignore (); /* Flush all currently pending debug events (thread and dll list) up to the initial breakpoint. */ @@ -385,7 +385,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached) the_target->wait (minus_one_ptid, &status, 0); /* Note win32_wait doesn't return thread events. */ - if (status.kind != TARGET_WAITKIND_LOADED) + if (status.kind () != TARGET_WAITKIND_LOADED) { cached_status = status; break; @@ -1081,7 +1081,7 @@ get_child_debug_event (DWORD *continue_status, ptid_t ptid; last_sig = GDB_SIGNAL_0; - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); *continue_status = DBG_CONTINUE; /* Check if GDB sent us an interrupt request. */ @@ -1119,8 +1119,7 @@ get_child_debug_event (DWORD *continue_status, load the application, e.g., if the main executable tries to pull in a non-existing export from a DLL. */ - ourstatus->kind = TARGET_WAITKIND_EXITED; - ourstatus->value.integer = 1; + ourstatus->set_exited (1); return 1; } @@ -1192,15 +1191,9 @@ get_child_debug_event (DWORD *continue_status, int exit_signal = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1; if (exit_signal == -1) - { - ourstatus->kind = TARGET_WAITKIND_EXITED; - ourstatus->value.integer = exit_status; - } + ourstatus->set_exited (exit_status); else - { - ourstatus->kind = TARGET_WAITKIND_SIGNALLED; - ourstatus->value.sig = gdb_signal_from_host (exit_signal); - } + ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); } child_continue (DBG_CONTINUE, desired_stop_thread_id); break; @@ -1215,8 +1208,7 @@ get_child_debug_event (DWORD *continue_status, break; dll_loaded_event (); - ourstatus->kind = TARGET_WAITKIND_LOADED; - ourstatus->value.sig = GDB_SIGNAL_TRAP; + ourstatus->set_loaded (); break; case UNLOAD_DLL_DEBUG_EVENT: @@ -1227,8 +1219,7 @@ get_child_debug_event (DWORD *continue_status, if (! child_initialization_done) break; handle_unload_dll (); - ourstatus->kind = TARGET_WAITKIND_LOADED; - ourstatus->value.sig = GDB_SIGNAL_TRAP; + ourstatus->set_loaded (); break; case EXCEPTION_DEBUG_EVENT: @@ -1270,7 +1261,7 @@ get_child_debug_event (DWORD *continue_status, ptid.lwp (), desired_stop_thread_id)); maybe_adjust_pc (); pending_stops.push_back ({(DWORD) ptid.lwp (), *ourstatus, current_event}); - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; + ourstatus->set_spurious (); } else current_thread = find_thread_ptid (ptid); @@ -1285,14 +1276,14 @@ ptid_t win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus, target_wait_flags options) { - if (cached_status.kind != TARGET_WAITKIND_IGNORE) + if (cached_status.kind () != TARGET_WAITKIND_IGNORE) { /* The core always does a wait after creating the inferior, and do_initial_child_stuff already ran the inferior to the initial breakpoint (or an exit, if creating the process fails). Report it now. */ *ourstatus = cached_status; - cached_status.kind = TARGET_WAITKIND_IGNORE; + cached_status.set_ignore (); return debug_event_ptid (¤t_event); } @@ -1302,11 +1293,11 @@ win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus, if (!get_child_debug_event (&continue_status, ourstatus)) continue; - switch (ourstatus->kind) + switch (ourstatus->kind ()) { case TARGET_WAITKIND_EXITED: OUTMSG2 (("Child exited with retcode = %x\n", - ourstatus->value.integer)); + ourstatus->exit_status ())); win32_clear_inferiors (); return ptid_t (current_event.dwProcessId); case TARGET_WAITKIND_STOPPED: @@ -1314,12 +1305,13 @@ win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus, case TARGET_WAITKIND_LOADED: { OUTMSG2 (("Child Stopped with signal = %d \n", - ourstatus->value.sig)); + ourstatus->sig ())); maybe_adjust_pc (); return debug_event_ptid (¤t_event); } default: - OUTMSG (("Ignoring unknown internal event, %d\n", ourstatus->kind)); + OUTMSG (("Ignoring unknown internal event, %d\n", + ourstatus->kind ())); /* fall-through */ case TARGET_WAITKIND_SPURIOUS: /* do nothing, just continue */ |