From: Luis Machado <lgustavo@codesourcery.com>
To: Sandra Loosemore <sandra@codesourcery.com>, <gdb-patches@sourceware.org>
Subject: Re: [rfc] PR 20569, segv in follow_exec
Date: Tue, 18 Oct 2016 18:11:00 -0000 [thread overview]
Message-ID: <50f4c7d8-44e3-4351-0b54-9cbaef64717a@codesourcery.com> (raw)
In-Reply-To: <57F6D57D.8070603@codesourcery.com>
On 10/06/2016 05:51 PM, Sandra Loosemore wrote:
> As I noted in PR20569, several exec-related tests cause GDB to segv when
> sysroot translation fails on the executable pathname reported by
> gdbserver. The immediate cause of the segv is that follow_exec is
> passing a NULL argument (the result of exec_file_find) to strlen, but as
> I looked at the code in more detail it seemed like follow_exec simply
> isn't prepared for the case where sysroot translation fails to locate
> the new executable, and there is no obvious recovery strategy.
>
> I thought I could copy logic from the other caller of exec_file_find,
> exec_file_locate_attach, but I think it's doing the wrong thing there as
> well. Plus, from reading the code I found other bugs in both callers of
> exec_file_find due to confusion between host and target pathnames.
>
> The attached patch attempts to fix all the bugs. In terms of the
> testcases that were formerly segv'ing, GDB now prints a warning but
> continues execution of the new program, so that the tests now mostly
> FAIL instead. You could argue the FAILs are due to a legitimate problem
> with the test environment setting up the sysroot translation
> incorrectly, but I'm not sure continuing execution rather than leaving
> the target stopped is the most user-friendly fallback behavior, either.
> E.g. the GDB manual suggests that you can set a breakpoint on main and
> GDB will stop on main of the newly exec'ed program, too, but it can't do
> that if it can't find the symbol information, and there's no way for the
> user to specify the executable file to GDB explicitly before it resumes
> execution. But, seemed better not to complicate this
> already-too-complicated patch further by trying to address that in the
> first cut.
>
> Comments? Suggestions? Etc.
>
> -Sandra
>
>
> gdb-segv2.log
>
>
> 2016-10-06 Sandra Loosemore <sandra@codesourcery.com>
>
> PR gdb/20569
> gdb/
> * exceptions.c (exception_print_same): Moved here from exec.c.
> Fixed message comparison.
> * exceptions.h (exception_print_same): Declare.
> * exec_file_locate_attach (exception_print_same): Delete copy here.
> (exec_file_locate_attach): Rename exec_file and full_exec_path
> variables to avoid confusion between target and host pathnames.
> Move pathname processing logic to exec_file_find. Do not return
> early if pathname lookup fails; guard symbol_file_add_main call
> instead.
> * infrun.c (follow_exec): Split and rename execd_pathname variable
> to avoid confusion between target and host pathnames. Replace
> brokenpathname copy with cleanup to free malloc'ed string. Warn
> if pathname lookup fails. Pass target pathname to
> target_follow_exec, not hostpathname. Borrow exception-handling
> logic from exec_file_locate_attach.
> * solib.c (exec_file_find): Incorporate fallback logic for relative
> pathnames formerly in exec_file_locate_attach.
>
>
> gdb-segv2.patch
>
>
I went through the patch and, although this code as a whole is a bit on
the convoluted side, it looks reasonable to me.
Segfaults are not supposed to happen, so allowing the session to
continue is a good thing IMO.
Sounds like a good candidate for master and even stable branches.
next prev parent reply other threads:[~2016-10-18 18:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-06 22:51 Sandra Loosemore
2016-10-18 18:11 ` Luis Machado [this message]
2016-10-19 13:37 ` Pedro Alves
2016-10-19 16:14 ` Luis Machado
2016-10-19 20:19 ` Luis Machado
2016-10-20 23:27 ` Pedro Alves
2016-10-21 18:30 ` Luis Machado
2016-10-21 18:33 ` Pedro Alves
2016-10-21 18:34 ` Luis Machado
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=50f4c7d8-44e3-4351-0b54-9cbaef64717a@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=sandra@codesourcery.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).