public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: Simon Marchi <simon.marchi@polymtl.ca>,
	GDB Patches <gdb-patches@sourceware.org>,
	Simon Marchi <simon.marchi@ericsson.com>
Subject: Re: [PATCH 2/2] Make gdbserver work with filename-only binaries
Date: Wed, 21 Feb 2018 08:05:00 -0000	[thread overview]
Message-ID: <20180221080536.4kg3avdend5en4ko@adacore.com> (raw)
In-Reply-To: <8737269fxt.fsf@redhat.com>

> Ah, I guess I didn't consider this (obvious) scenario for gdbserver.  I
> was thinking that gdbserver (before the startup-with-shell feature)
> would not work with binaries in PATH...

It would, but it would be at the discretion of each target
implementation. linux-low was doing it by calling execv first,
which doesn't search the PATH, and then calling execvp if
the first execv call failed with a "not found" error.

> > I didn't think this through completely, but maybe we could do
> > something simpler, if the program_name doesn't contain a directory
> > separator and the file exists in the current working directory, we
> > add "./" in front of it when passing it to the shell?  I think all
> > three use cases would work:
> >
> > - gdbserver :1234 foo (foo in current directory)
> > - gdbserver :1234 foo (foo in PATH)
> > - gdbserver :1234 ./foo
> 
> So, what do you think of checking if the file exists in the CWD (and is
> executable), and prefixing it with current_directory, as I'm doing with
> this patch?  I personally prefer to be more verbose, so using the full
> path is better IMHO than just adding "./".

I agree with Simon that we shouldn't (and don't really need to) touch
the file when it contains some directory information in it. As far as
I can tell, it already works as is, both with and without shell startup.

    $ gdbserver --once :4444 simple/simple_main
    Process simple/simple_main created; pid = 15400
    Listening on port 4444

    $ gdbserver --no-startup-with-shell --once :4444 simple/simple_main
    Process simple/simple_main created; pid = 15432
    Listening on port 4444

So, I think the only case that we need to worry about is the case
where exec_file is a basename. For that, I think the following test
should be sufficient:

    if (lbasename (exec_file) == exec_file)

... If it returns anything else than exec file, it's either a full
path, or a relative path with some directory information in it.

I agree with you, Sergio, that I think that expanding to the absolute
path would be cleaner. I'm not sure whether adding "." + SLASH_STRING
is going to work everywhere... I'd rather not ask myself the question,
and just expand to a full path, since you've done the work to do it
anyways.

-- 
Joel

  reply	other threads:[~2018-02-21  8:05 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-10  1:42 [PATCH 0/2] " Sergio Durigan Junior
2018-02-10  1:42 ` [PATCH 1/2] Create new common/pathstuff.[ch] Sergio Durigan Junior
2018-02-11 22:14   ` Simon Marchi
2018-02-12 19:01     ` Sergio Durigan Junior
2018-02-21  7:56   ` Joel Brobecker
2018-02-22 18:43     ` Sergio Durigan Junior
2018-02-10  1:42 ` [PATCH 2/2] Make gdbserver work with filename-only binaries Sergio Durigan Junior
2018-02-12  4:18   ` Simon Marchi
2018-02-12 19:16     ` Sergio Durigan Junior
2018-02-21  8:05       ` Joel Brobecker [this message]
2018-02-12 19:57   ` [PATCH 0/2] " Sergio Durigan Junior
2018-02-12 19:57     ` [PATCH v2 1/2] Create new common/pathstuff.[ch] Sergio Durigan Junior
2018-02-12 19:57     ` [PATCH v2 2/2] Make gdbserver work with filename-only binaries Sergio Durigan Junior
2018-02-13  4:35       ` Simon Marchi
2018-02-22 18:37         ` Sergio Durigan Junior
2018-02-21 12:29       ` Pedro Alves
2018-02-27  0:20         ` Sergio Durigan Junior
2018-02-28  3:32           ` Sergio Durigan Junior
2018-02-28  3:27   ` [PATCH v3 0/2] " Sergio Durigan Junior
2018-02-28  3:27     ` [PATCH v3 1/2] Create new common/pathstuff.[ch] Sergio Durigan Junior
2018-02-28  5:02       ` Simon Marchi
2018-02-28 16:46         ` Sergio Durigan Junior
2018-02-28 16:39       ` Sergio Durigan Junior
2018-02-28  3:27     ` [PATCH v3 2/2] Make gdbserver work with filename-only binaries Sergio Durigan Junior
2018-02-28  3:58       ` Sergio Durigan Junior
2018-02-28  5:33         ` Simon Marchi
2018-02-28  7:09           ` Metzger, Markus T
2018-02-28 16:30             ` Sergio Durigan Junior
2018-02-28  5:46       ` Simon Marchi
2018-02-28 16:29         ` Sergio Durigan Junior
2018-02-28 16:40           ` Sergio Durigan Junior
2018-03-01  2:23     ` [PATCH v3 0/2] " Sergio Durigan Junior
2018-03-01  2:55       ` Joel Brobecker
2018-03-01 13:08         ` Christophe Lyon
2018-03-01 13:18           ` Simon Marchi
2018-03-01 19:50           ` Sergio Durigan Junior
2018-03-01 20:20           ` [PATCH] Conditionally include "<windows.h>" on common/pathstuff.c (and unbreak build on mingw*) Sergio Durigan Junior
2018-03-01 20:47             ` Simon Marchi
2018-03-02 11:46               ` Christophe Lyon
2018-03-02 12:35                 ` Sergio Durigan Junior
2018-03-02 11:11             ` Yao Qi
2018-03-02 12:29               ` Sergio Durigan Junior
2018-03-02 12:37                 ` Sergio Durigan Junior
2018-03-05 12:07                   ` Yao Qi
2018-03-02 13:32             ` Eli Zaretskii
2018-03-02 15:15               ` Simon Marchi
2018-03-02 18:20                 ` Sergio Durigan Junior
2018-03-03  7:36                   ` Eli Zaretskii
2018-03-01 17:37         ` [PATCH v3 0/2] Make gdbserver work with filename-only binaries Sergio Durigan Junior
2018-03-02  3:20           ` Joel Brobecker
2018-02-28 16:47   ` [obvious/pushed] Change order of error message printed when gdbserver can't find CWD Sergio Durigan Junior

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=20180221080536.4kg3avdend5en4ko@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    --cc=simon.marchi@ericsson.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).