From: Simon Marchi Date: Thu, 7 Nov 2024 16:22:20 +0000 (+0000) Subject: gdbserver: remove get_thread_process X-Git-Tag: gdb-16-branchpoint~498 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=907f8c0cf39e1f6e3455dfad03b99a8700c81922;p=thirdparty%2Fbinutils-gdb.git gdbserver: remove get_thread_process Remove the `get_thread_process` function, use `thread_info::process` instead. In `server.cc`, use `current_process ()` instead of going through the current thread. Change-Id: Ifc61d65852e392d154b854a45d45df584ab3922e Reviewed-By: Tankut Baris Aktemur --- diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc index 8ca6d643264..7657ddbda2a 100644 --- a/gdbserver/inferiors.cc +++ b/gdbserver/inferiors.cc @@ -213,12 +213,6 @@ have_attached_inferiors_p (void) }) != NULL; } -struct process_info * -get_thread_process (const struct thread_info *thread) -{ - return find_process_pid (thread->id.pid ()); -} - struct process_info * current_process (void) { @@ -422,7 +416,7 @@ void switch_to_thread (thread_info *thread) { if (thread != nullptr) - current_process_ = get_thread_process (thread); + current_process_ = thread->process (); else current_process_ = nullptr; current_thread = thread; diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h index 002dd2a4ed6..c282a7bf188 100644 --- a/gdbserver/inferiors.h +++ b/gdbserver/inferiors.h @@ -134,7 +134,6 @@ pid_of (const process_info *proc) is null. */ struct process_info *current_process (void); -struct process_info *get_thread_process (const struct thread_info *); extern owning_intrusive_list all_processes; diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 924536c34fa..e364114c7d2 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -604,7 +604,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, the client side will access registers. */ gdb_assert (child_proc != NULL); - process_info *parent_proc = get_thread_process (event_thr); + process_info *parent_proc = event_thr->process (); child_proc->attached = parent_proc->attached; clone_all_breakpoints (child_thr, event_thr); @@ -723,7 +723,6 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, } else if (event == PTRACE_EVENT_EXEC && cs.report_exec_events) { - struct process_info *proc; std::vector syscalls_to_catch; ptid_t event_ptid; pid_t event_pid; @@ -736,7 +735,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, event_pid = event_ptid.pid (); /* Save the syscall list from the execing process. */ - proc = get_thread_process (event_thr); + process_info *proc = event_thr->process (); syscalls_to_catch = std::move (proc->syscalls_to_catch); /* Delete the execing process and all its threads. */ @@ -781,7 +780,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, CORE_ADDR linux_process_target::get_pc (lwp_info *lwp) { - process_info *proc = get_thread_process (get_lwp_thread (lwp)); + process_info *proc = get_lwp_thread (lwp)->process (); gdb_assert (!proc->starting_up); if (!low_supports_breakpoints ()) @@ -829,7 +828,7 @@ linux_process_target::save_stop_reason (lwp_info *lwp) if (!low_supports_breakpoints ()) return false; - process_info *proc = get_thread_process (get_lwp_thread (lwp)); + process_info *proc = get_lwp_thread (lwp)->process (); if (proc->starting_up) { /* Claim we have the stop PC so that the caller doesn't try to @@ -2938,10 +2937,7 @@ linux_process_target::filter_exit_event (lwp_info *event_child, static int gdb_catching_syscalls_p (struct lwp_info *event_child) { - struct thread_info *thread = get_lwp_thread (event_child); - struct process_info *proc = get_thread_process (thread); - - return !proc->syscalls_to_catch.empty (); + return !get_lwp_thread (event_child)->process ()->syscalls_to_catch.empty (); } bool @@ -2949,7 +2945,7 @@ linux_process_target::gdb_catch_this_syscall (lwp_info *event_child) { int sysno; struct thread_info *thread = get_lwp_thread (event_child); - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); if (proc->syscalls_to_catch.empty ()) return false; @@ -4016,7 +4012,6 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step, { struct thread_info *thread = get_lwp_thread (lwp); int ptrace_request; - struct process_info *proc = get_thread_process (thread); /* Note that target description may not be initialised (proc->tdesc == NULL) at this point because the program hasn't @@ -4139,7 +4134,7 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step, step = single_step (lwp); } - if (proc->tdesc != NULL && low_supports_breakpoints ()) + if (thread->process ()->tdesc != nullptr && low_supports_breakpoints ()) { struct regcache *regcache = get_thread_regcache (current_thread, 1); @@ -4393,11 +4388,10 @@ linux_process_target::thread_needs_step_over (thread_info *thread) { struct lwp_info *lwp = get_thread_lwp (thread); CORE_ADDR pc; - struct process_info *proc = get_thread_process (thread); /* GDBserver is skipping the extra traps from the wrapper program, don't have to do step over. */ - if (proc->tdesc == NULL) + if (thread->process ()->tdesc == nullptr) return false; /* LWPs which will not be resumed are not interesting, because we diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc index eebf999c223..1f7af7138cf 100644 --- a/gdbserver/mem-break.cc +++ b/gdbserver/mem-break.cc @@ -1412,7 +1412,7 @@ set_single_step_breakpoint (CORE_ADDR stop_at, ptid_t ptid) void delete_single_step_breakpoints (struct thread_info *thread) { - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); struct breakpoint *bp, **bp_link; bp = proc->breakpoints; @@ -1507,7 +1507,7 @@ uninsert_all_breakpoints (void) void uninsert_single_step_breakpoints (struct thread_info *thread) { - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); struct breakpoint *bp; for (bp = proc->breakpoints; bp != NULL; bp = bp->next) @@ -1576,7 +1576,7 @@ reinsert_breakpoints_at (CORE_ADDR pc) int has_single_step_breakpoints (struct thread_info *thread) { - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); struct breakpoint *bp, **bp_link; bp = proc->breakpoints; @@ -1613,7 +1613,7 @@ reinsert_all_breakpoints (void) void reinsert_single_step_breakpoints (struct thread_info *thread) { - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); struct breakpoint *bp; for (bp = proc->breakpoints; bp != NULL; bp = bp->next) @@ -2138,8 +2138,8 @@ clone_all_breakpoints (struct thread_info *child_thread, struct breakpoint *new_bkpt; struct breakpoint *bkpt_tail = NULL; struct raw_breakpoint *raw_bkpt_tail = NULL; - struct process_info *child_proc = get_thread_process (child_thread); - struct process_info *parent_proc = get_thread_process (parent_thread); + process_info *child_proc = child_thread->process (); + process_info *parent_proc = parent_thread->process (); struct breakpoint **new_list = &child_proc->breakpoints; struct raw_breakpoint **new_raw_list = &child_proc->raw_breakpoints; diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 64b6e317618..a37a985dd30 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -40,7 +40,7 @@ get_thread_regcache (struct thread_info *thread, int fetch) have. */ if (regcache == NULL) { - struct process_info *proc = get_thread_process (thread); + process_info *proc = thread->process (); gdb_assert (proc->tdesc != NULL); diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 291d62a61f1..138a8acc953 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1296,11 +1296,7 @@ handle_detach (char *own_buf) process = find_process_pid (pid); } else - { - process = (current_thread != nullptr - ? get_thread_process (current_thread) - : nullptr); - } + process = current_process (); if (process == NULL) { @@ -1363,9 +1359,7 @@ handle_detach (char *own_buf) if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED) continue; - process_info *fork_child_process = get_thread_process (child); - gdb_assert (fork_child_process != nullptr); - + process_info *fork_child_process = child->process (); int fork_child_pid = fork_child_process->pid; if (detach_inferior (fork_child_process) != 0) diff --git a/gdbserver/thread-db.cc b/gdbserver/thread-db.cc index 8cef84206b8..96a9ced19ec 100644 --- a/gdbserver/thread-db.cc +++ b/gdbserver/thread-db.cc @@ -388,10 +388,9 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset, psaddr_t addr; td_err_e err; struct lwp_info *lwp; - struct process_info *proc; struct thread_db *thread_db; + process_info *proc = thread->process (); - proc = get_thread_process (thread); thread_db = proc->priv->thread_db; /* If the thread layer is not (yet) initialized, fail. */ @@ -448,14 +447,13 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset, bool thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len) { - struct thread_db *thread_db; struct lwp_info *lwp; thread_info *thread = find_thread_ptid (ptid); if (thread == NULL) return false; - thread_db = get_thread_process (thread)->priv->thread_db; + thread_db *thread_db = thread->process ()->priv->thread_db; if (thread_db == NULL) return false; @@ -873,8 +871,7 @@ thread_db_handle_monitor_command (char *mon) void thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid) { - process_info *parent_proc = get_thread_process (parent_thr); - struct thread_db *thread_db = parent_proc->priv->thread_db; + thread_db *thread_db = parent_thr->process ()->priv->thread_db; /* If the thread layer isn't initialized, return. It may just be that the program uses clone, but does not use libthread_db. */