From: Simon Marchi <simark@simark.ca>
To: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix re-runs of a second inferior (PR gdb/25410)
Date: Fri, 24 Jan 2020 07:00:00 -0000 [thread overview]
Message-ID: <50431f58-94c4-88ce-f59a-54c16a36475c@simark.ca> (raw)
In-Reply-To: <20200124030222.13854-1-palves@redhat.com>
On 2020-01-23 10:02 p.m., Pedro Alves wrote:
> This fixes a latent bug exposed by the multi-target patch (5b6d1e4fa
> "Multi-target support).
>
> The symptom described in the bug is that starting a first inferior,
> then trying to run a second (multi-threaded) inferior twice, causes
> libthread_db to fail to load, along with other erratic behavior:
>
> (gdb) run
> Starting program: /tmp/foo
> warning: td_ta_new failed: generic error
>
> Going a bit deeply, I found that if the two inferiors have different
> symbols, we can see that just after inferior 2 exits, we are left with
> inferior 2 selected, which is correct, but the symbols in scope belong
> to inferior 1, which is obviously incorrect...
>
> This problem is that there's a path in
> scoped_restore_current_thread::restore() that switches to no thread
> selected, and switches the current inferior, but leaves the current
> program space as is, resulting in leaving the program space pointing
> to the wrong program space (the one of the other inferior). This was
> happening after handling TARGET_WAITKIND_NO_RESUMED, which is an event
> that triggers after TARGET_WAITKIND_EXITED for the previous inferior
> exit. Subsequent symbol lookups find the symbols of the wrong
> inferior.
>
> The fix is to use switch_to_inferior_no_thread in that problem spot.
> This function was recently added along with the multi-target work
> exactly for these situations.
>
> As for testing, this patch adds a new testcase that tests symbol
> printing just after inferior exit, which exercises the root cause of
> the problem more directly. And then, to cover the use case described
> in the bug too, it also exercises the lithread_db.so mis-loading, by
> using TLS printing as a proxy for being sure that threaded debugging
> was activated sucessfully. The testcase fails without the fix like
> this, for the "print symbol just after exit" bits:
>
> ...
> [Inferior 1 (process 8719) exited normally]
> (gdb) PASS: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: continue until exit
> print re_run_var_1
> No symbol "re_run_var_1" in current context.
> (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=1: print re_run_var_1
> ...
>
> And like this for the "libthread_db.so loading" bits:
>
> (gdb) run
> Starting program: /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run
> warning: td_ta_new failed: generic error
> [New LWP 27001]
>
> Thread 1.1 "multi-re-run" hit Breakpoint 3, all_started () at /home/pedro/gdb/binutils-gdb/build/../src/gdb/testsuite/gdb.multi/multi-re-run.c:44
> 44 }
> (gdb) PASS: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=2: running to all_started in runto
> print tls_var
> Cannot find thread-local storage for LWP 27000, executable file /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.multi/multi-re-run/multi-re-run:
> Cannot find thread-local variables on this target
> (gdb) FAIL: gdb.multi/multi-re-run.exp: re_run_inf=1: iter=2: print tls_var
Thanks, that fixes it for me (and LGTM).
Simon
next prev parent reply other threads:[~2020-01-24 3:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-24 3:32 Pedro Alves
2020-01-24 7:00 ` Simon Marchi [this message]
[not found] ` <DM6PR11MB303390E9124B6ECD67E1740AC40E0@DM6PR11MB3033.namprd11.prod.outlook.com>
2020-01-24 15:02 ` Simon Marchi
2020-01-24 15:23 ` Pedro Alves
2020-01-24 17:15 ` 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=50431f58-94c4-88ce-f59a-54c16a36475c@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/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