From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Libor Bukata <libor.bukata@oracle.com>
Subject: [PATCH 2/2] gdb: add asserts in thread code
Date: Sun, 21 Feb 2021 10:56:30 -0500 [thread overview]
Message-ID: <20210221155630.3026942-2-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210221155630.3026942-1-simon.marchi@polymtl.ca>
Unlike the previous patch, I don't propose that we take this patch into
gdb-10-branch.
This patch adds two asserts, prompted by investigating and fixing the
bug fixed by the previous patch.
The assert in find_thread_ptid would have caught the original issue
before the segfault (I think it's slightly more use friendly).
The assert in add_thread_silent would have made it clear that the
solution proposed in [1] isn't the right one. The solution ended up
passing nullptr as a target to add_thread. We don't want that, because
add_thread_silent uses it to look up the inferior to which to add the
thread. If the target is nullptr, we could find an inferior with the
same pid, but belonging to an unrelated target. So we always want a
non-nullptr target in add_thread_silent.
gdb/ChangeLog:
* thread.c (add_thread_silent): Add assert.
(find_thread_ptid): Add assert.
[1] https://sourceware.org/pipermail/gdb-patches/2021-February/176202.html
Change-Id: Ie593ee45c5eb02235e8e9fbcda612d48ce883852
---
gdb/thread.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gdb/thread.c b/gdb/thread.c
index 821070672171..3e7d6e14bf74 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -246,6 +246,8 @@ new_thread (struct inferior *inf, ptid_t ptid)
struct thread_info *
add_thread_silent (process_stratum_target *targ, ptid_t ptid)
{
+ gdb_assert (targ != nullptr);
+
inferior *inf = find_inferior_ptid (targ, ptid);
/* We may have an old thread with the same id in the thread list.
@@ -535,6 +537,8 @@ find_thread_ptid (process_stratum_target *targ, ptid_t ptid)
struct thread_info *
find_thread_ptid (inferior *inf, ptid_t ptid)
{
+ gdb_assert (inf != nullptr);
+
for (thread_info *tp : inf->non_exited_threads ())
if (tp->ptid == ptid)
return tp;
--
2.30.1
next prev parent reply other threads:[~2021-02-21 15:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-21 15:56 [PATCH 1/2] gdb: push target earlier in procfs_target::attach (PR 27435) Simon Marchi via Gdb-patches
2021-02-21 15:56 ` Simon Marchi via Gdb-patches [this message]
2021-02-21 21:04 ` Tom Tromey
2021-02-21 21:18 ` Simon Marchi via Gdb-patches
2021-02-22 11:03 ` Libor Bukata via Gdb-patches
2021-02-22 16:51 ` Simon Marchi via Gdb-patches
2021-02-23 6:35 ` Libor Bukata via Gdb-patches
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=20210221155630.3026942-2-simon.marchi@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=libor.bukata@oracle.com \
--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