public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: Gary Benson <gbenson@redhat.com>
Cc: <gdb-patches@sourceware.org>, Pedro Alves <palves@redhat.com>
Subject: Re: [PATCH v2] Fix logic in exec_file_locate_attach
Date: Mon, 22 Feb 2016 22:00:00 -0000	[thread overview]
Message-ID: <56CB8506.3010602@codesourcery.com> (raw)
In-Reply-To: <20160222135109.GA2256@blade.nx>

On 02/22/2016 10:51 AM, Gary Benson wrote:
> Luis Machado wrote:
>> On 02/22/2016 07:40 AM, Gary Benson wrote:
>>> Luis Machado wrote:
>>>> On 02/19/2016 09:21 AM, Gary Benson wrote:
>>>>> This is an updated version of the patch I posted yesterday.
>>>>> It fails silently rather than throwing if the executable is
>>>>> not in the sysroot, which both fixes the sysroot-escape issue
>>>>> and results in a better GDB session for the user.
>>>>>
>>>>> Built and regtested on RHEL 6.6 x86_64.
>>>>>
>>>>> Luis, I think this patch will fix your connection drop without
>>>>> any further changes.  Could you test it please?
>>>>
>>>> Unfortunately it doesn't completely solve the problem i saw, as
>>>> exec_file_find will still potentially throw errors and will
>>>> disrupt the connection attempt or stop execution of a custom
>>>> sequence of commands (as Pedro noted) when "attach" is part of
>>>> the sequence.
>>>>
>>>> define foo
>>>> attach <pid>
>>>>>>>> execution stops here if an error is thrown
>>>> info threads
>>>> info registers
>>>> end
>>>>
>>>> It still looks like a TRY/CATCH block is needed around at least
>>>> exec_file_find.
>>>
>>> What is throwing in exec_file_find?  I'm just seeing lots of calls
>>> to gdb_open_cloexec and openp, and I don't think either of those
>>> should throw except for assertion failures or running out of
>>> memory.
>>
>> Not sure why i had exec_file_find in my mind. I meant to say
>> exec_file_attach still throws errors, when openp fails and
>> scratch_chan < 0. Sorry.
>
> You shouldn't get that now, the "if (full_exec_path == NULL) return"
> should have caught it.  Are you still seeing thrown errors with your
> setup?
>

Yes. With your patch applied, i still see a case where we error out. 
Suppose we have a test binary gdb/test, then:

- chmod -r gdb/test
- Fire up gdbserver with a test binary: ./gdb/gdbserver/gdbserver :2345 
gdb/test
- Fire up GDB: ./gdb/gdb -ex "set sysroot" -ex "tar rem :2345"

You will see something similar to the following:

Sending packet: $qXfer:exec-file:read:3486:0,fff#5f...Packet received: 
l/proc/13446/exe
/proc/13446/exe: Permission denied.
(gdb) i r
The program has no registers now.
(gdb)

This was the testcase suggested by Pedro and it proved to be a good one.

>> There is a symbol_file_add_main call right after calling
>> exec_file_attach in exec_file_locate_attach, but i didn't see any
>> errors being thrown from that one.
>
> You could probably race it (e.g. by deleting the file between the
> calls) but generally symbol_file_add_main won't fail because
> exec_file_attach would have failed if the file was missing or
> inaccessible.

My idea was to guard both exec_file_attach and symbol_file_add_main. We 
can't have anything in that function throwing an error that won't be 
caught, otherwise the above connection attempt will fail.

Luis

  reply	other threads:[~2016-02-22 22:00 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 14:19 [PATCH] Remote debugging without a binary (regression) Luis Machado
2016-02-11 16:35 ` Gary Benson
2016-02-11 17:06   ` Luis Machado
2016-02-11 17:31     ` Pedro Alves
2016-02-11 17:42       ` Luis Machado
2016-02-12 10:31     ` Gary Benson
2016-02-12 10:59       ` Luis Machado
2016-02-12 15:24       ` Pedro Alves
2016-02-17 13:53         ` Gary Benson
2016-02-17 14:40           ` Pedro Alves
2016-02-17 17:02           ` [OB PATCH] Add missing cleanup in exec_file_locate_attach Gary Benson
2016-02-17 17:05             ` Gary Benson
2016-02-17 18:11             ` Luis Machado
2016-02-18  9:54               ` Gary Benson
2016-02-18 17:05         ` [PATCH] Fix logic " Gary Benson
2016-02-18 17:28           ` Pedro Alves
2016-02-19 10:24             ` Gary Benson
2016-02-19 10:33               ` Luis Machado
2016-02-19 11:21               ` [PATCH v2] " Gary Benson
2016-02-19 15:38                 ` Luis Machado
2016-02-22 10:40                   ` Gary Benson
2016-02-22 11:37                     ` Luis Machado
2016-02-22 13:51                       ` Gary Benson
2016-02-22 22:00                         ` Luis Machado [this message]
2016-02-22 22:50                           ` Luis Machado
2016-02-22 23:00                             ` Pedro Alves
2016-02-23  0:04                               ` Luis Machado
2016-02-23  0:13                                 ` Pedro Alves
2016-02-23  0:16                                   ` Luis Machado
2016-02-23 11:27                                     ` Gary Benson
2016-02-23 11:43                                       ` Pedro Alves
2016-02-23 12:15                                         ` Gary Benson
2016-02-23 12:20                                           ` Pedro Alves
2016-02-23 11:55                 ` Pedro Alves
2016-02-24 11:56                   ` Gary Benson
2016-02-12 15:29 ` [PATCH] Remote debugging without a binary (regression) Pedro Alves
2016-02-12 16:08   ` Luis Machado
2016-02-12 16:36     ` Pedro Alves
2016-02-12 17:31       ` Luis Machado
2016-02-17 11:46         ` Pedro Alves
2016-02-18 12:30 ` Gary Benson
2016-02-18 12:40   ` 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=56CB8506.3010602@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=gbenson@redhat.com \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).