From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 04/19] Remove find_inferior_id
Date: Mon, 20 Nov 2017 16:35:00 -0000 [thread overview]
Message-ID: <1511195683-2055-5-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1511195683-2055-1-git-send-email-simon.marchi@ericsson.com>
From: Simon Marchi <simon.marchi@polymtl.ca>
Remove find_inferior_id, replacing its usages with find_thread_ptid.
find_thread_ptid was implemented using find_inferior_id, so move the
implementation there instead.
gdb/gdbserver/ChangeLog:
* inferiors.c (find_inferior_id): Remove.
(find_thread_ptid): Move implemention from find_inferior_id to
here.
* inferiors.h (find_inferior_id): Remove.
* server.c (handle_status): Use find_thread_ptid.
(process_serial_event): Likewise.
* thread-db.c (find_one_thread): Likewise.
(thread_db_thread_handle): Likewise.
* win32-low.c (thread_rec): Likewise.
(child_delete_thread): Likewise.
(win32_thread_alive): Likewise.
(get_child_debug_event): Likewise.
---
gdb/gdbserver/inferiors.c | 14 +++-----------
gdb/gdbserver/inferiors.h | 2 --
gdb/gdbserver/server.c | 6 ++----
gdb/gdbserver/thread-db.c | 8 +++-----
gdb/gdbserver/win32-low.c | 23 +++++------------------
5 files changed, 13 insertions(+), 40 deletions(-)
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index f4101c7..be3f3ef 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -43,16 +43,6 @@ find_inferior (std::list<thread_info *> *thread_list,
}
thread_info *
-find_inferior_id (std::list<thread_info *> *thread_list, ptid_t id)
-{
- gdb_assert (thread_list == &all_threads);
-
- return find_thread ([&] (thread_info *thread) {
- return thread->id == id;
- });
-}
-
-thread_info *
find_inferior_in_random (std::list<thread_info *> *thread_list,
int (*func) (thread_info *, void *),
void *arg)
@@ -120,7 +110,9 @@ get_first_thread (void)
struct thread_info *
find_thread_ptid (ptid_t ptid)
{
- return (struct thread_info *) find_inferior_id (&all_threads, ptid);
+ return find_thread ([&] (thread_info *thread) {
+ return thread->id == ptid;
+ });
}
/* Find a thread associated with the given PROCESS, or NULL if no
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 4c66a74..a8a374e 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -142,8 +142,6 @@ void clear_inferiors (void);
thread_info *find_inferior (std::list<thread_info *> *thread_list,
int (*func) (thread_info *, void *), void *arg);
-thread_info *find_inferior_id (std::list<thread_info *> *thread_list,
- ptid_t id);
thread_info *find_inferior_in_random (std::list<thread_info *> *thread_list,
int (*func) (thread_info *, void *),
void *arg);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index f0dac95..26c4a01 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3355,7 +3355,7 @@ handle_status (char *own_buf)
if (last_status.kind != TARGET_WAITKIND_IGNORE
&& last_status.kind != TARGET_WAITKIND_EXITED
&& last_status.kind != TARGET_WAITKIND_SIGNALLED)
- thread = find_inferior_id (&all_threads, last_ptid);
+ thread = find_thread_ptid (last_ptid);
/* If the last event thread is not found for some reason, look
for some other thread that might have an event to report. */
@@ -4081,9 +4081,7 @@ process_serial_event (void)
/* GDB is telling us to choose any thread. Check if
the currently selected thread is still valid. If
it is not, select the first available. */
- struct thread_info *thread =
- (struct thread_info *) find_inferior_id (&all_threads,
- general_thread);
+ thread_info *thread = find_thread_ptid (general_thread);
if (thread == NULL)
thread = get_first_thread ();
thread_id = thread->id;
diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index 67970f4..537758c 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -165,13 +165,12 @@ find_one_thread (ptid_t ptid)
td_thrhandle_t th;
td_thrinfo_t ti;
td_err_e err;
- struct thread_info *inferior;
struct lwp_info *lwp;
struct thread_db *thread_db = current_process ()->priv->thread_db;
int lwpid = ptid_get_lwp (ptid);
- inferior = (struct thread_info *) find_inferior_id (&all_threads, ptid);
- lwp = get_thread_lwp (inferior);
+ thread_info *thread = find_thread_ptid (ptid);
+ lwp = get_thread_lwp (thread);
if (lwp->thread_known)
return 1;
@@ -452,8 +451,7 @@ thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len)
{
struct thread_db *thread_db;
struct lwp_info *lwp;
- struct thread_info *thread
- = (struct thread_info *) find_inferior_id (&all_threads, ptid);
+ thread_info *thread = find_thread_ptid (ptid);
if (thread == NULL)
return false;
diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index c7684b7..fecab84 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -193,14 +193,11 @@ win32_require_context (win32_thread_info *th)
static win32_thread_info *
thread_rec (ptid_t ptid, int get_context)
{
- struct thread_info *thread;
- win32_thread_info *th;
-
- thread = (struct thread_info *) find_inferior_id (&all_threads, ptid);
+ thread_info *thread = find_thread_ptid (ptid);
if (thread == NULL)
return NULL;
- th = (win32_thread_info *) thread_target_data (thread);
+ win32_thread_info *th = (win32_thread_info *) thread_target_data (thread);
if (get_context)
win32_require_context (th);
return th;
@@ -244,14 +241,11 @@ delete_thread_info (thread_info *thread)
static void
child_delete_thread (DWORD pid, DWORD tid)
{
- ptid_t ptid;
-
/* If the last thread is exiting, just return. */
if (all_threads.size () == 1)
return;
- ptid = ptid_build (pid, tid, 0);
- thread_info *thread = find_inferior_id (&all_threads, ptid);
+ thread_info *thread = find_thread_ptid (ptid_t (pid, tid));
if (thread == NULL)
return;
@@ -892,15 +886,9 @@ win32_join (int pid)
static int
win32_thread_alive (ptid_t ptid)
{
- int res;
-
/* Our thread list is reliable; don't bother to poll target
threads. */
- if (find_inferior_id (&all_threads, ptid) != NULL)
- res = 1;
- else
- res = 0;
- return res;
+ return find_thread_ptid (ptid) != NULL;
}
/* Resume the inferior process. RESUME_INFO describes how we want
@@ -1582,8 +1570,7 @@ get_child_debug_event (struct target_waitstatus *ourstatus)
}
ptid = debug_event_ptid (¤t_event);
- current_thread =
- (struct thread_info *) find_inferior_id (&all_threads, ptid);
+ current_thread = find_thread_ptid (ptid);
return 1;
}
--
2.7.4
next prev parent reply other threads:[~2017-11-20 16:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 16:35 [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
2017-11-20 16:35 ` [PATCH 16/19] Update comments Simon Marchi
2017-11-20 16:35 ` [PATCH 19/19] Remove for_each_inferior_with_data Simon Marchi
2017-11-20 16:35 ` Simon Marchi [this message]
2017-11-20 16:35 ` [PATCH 10/19] Remove usages of find_inferior calling not_stopped_callback Simon Marchi
2017-11-20 16:35 ` [PATCH 14/19] Remove usage of find_inferior in linux_resume Simon Marchi
2017-11-20 16:35 ` [PATCH 09/19] Remove usage of find_inferior in find_lwp_pid Simon Marchi
2017-11-20 16:35 ` [PATCH 05/19] Remove find_inferior_in_random Simon Marchi
2017-11-20 16:35 ` [PATCH 01/19] Remove usage of find_inferior in regcache_invalidate_pid Simon Marchi
2017-11-20 16:35 ` [PATCH 13/19] Remove usages of find_inferior in stop_all_lwps Simon Marchi
2017-11-20 16:35 ` [PATCH 12/19] Remove usage of find_inferior in linux_stabilize_threads Simon Marchi
2017-11-20 16:35 ` [PATCH 18/19] Remove for_each_inferior Simon Marchi
2017-11-20 16:35 ` [PATCH 02/19] Remove usage of find_inferior in lynx_mourn Simon Marchi
2017-11-20 16:35 ` [PATCH 17/19] Remove find_inferior Simon Marchi
2017-11-20 16:35 ` [PATCH 11/19] Remove usages of find_inferior in select_event_lwp Simon Marchi
2017-11-20 16:35 ` [PATCH 08/19] Remove usage of find_inferior in linux_mourn Simon Marchi
2017-11-20 16:35 ` [PATCH 07/19] Remove usage of find_inferior in linux_detach Simon Marchi
2017-11-20 16:35 ` [PATCH 03/19] Remove usages of find_inferior in linux-mips-low.c Simon Marchi
2017-11-20 16:35 ` [PATCH 06/19] Remove usage of find_inferior in last_thread_of_process_p Simon Marchi
2017-11-20 16:35 ` [PATCH 15/19] Remove usages of find_inferior that call proceed_one_lwp Simon Marchi
2017-12-03 1:48 ` [PATCH 00/19] Remove find_inferior* and for_each_inferior* Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511195683-2055-5-git-send-email-simon.marchi@ericsson.com \
--to=simon.marchi@ericsson.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).