public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Lancelot SIX <lsix@lancelotsix.com>
Cc: gdb-patches@sourceware.org, Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 5/5] gdbsupport: add path_join function
Date: Tue, 19 Apr 2022 20:22:37 -0400	[thread overview]
Message-ID: <7c4c5b28-843a-f434-35e2-d42f51f18321@polymtl.ca> (raw)
In-Reply-To: <20220418231116.qhpo34hnaxpjwzcs@ubuntu.lan>

>>> Is this different semantics made on purpose?
>>
>> I indeed noticed how os.path.join handled ("/foo", "/bar").
>>
>> I went with the behavior in my patch mostly because there are cases in
>> GDB where we really need to append absolute paths to another path.  For
>> example, looking up files in sysroots.  If the sysroot is set to
>> "/the/sysroot/" (with or without the trailing slash) and we want to load
>> the target library /usr/lib/libfoo.so, it would be nice if
>>
>>     path_join (sysroot_path, lib_path)
>>
>> gave
>>
>>     /the/sysroot/usr/lib/libfoo.so
>>
>> without a double-slash.  Same when we are looking up files in the
>> debug-file-directory (/usr/lib/debug).
>>
>> When changing those implementations that currently use concat(...) or
>> string_printf("%s/%s"), we would need to be careful: if the right hand
>> side is an absolute path, then we would have to skip the leading
>> directory separator before passing it to path_join, to get the desired
>> result.  And then we're back at having some special path handling
>> details everywhere.
> 
> Fair enough.  This is a good enough reason to have a special semantics
> (we could have a path_join and a  sysroot_path_join, but not sure it is
> worth it having 2 functions).

Well, I've been thinking about it, and perhaps that appending an
absolute path to another path (either absolute or non-absolute),
sysroot-style, is indeed a distinct use case that a regular path_join is
not meant to solve.  The code that Pedro pointed to, in solib_find_1,
convinced me.  It tries different things when dealing with a Windows
paths that contains a drive letter.

And compatibility-wise, being a drop-in replacement for
std::filesystem::operator/ is interesting.

> 
>> If you can make it work using gdb::string_view or const char *, I think
>> it would be ok.  I'll give it a try.  But otherwise, I am personally
>> fine with the sentinel nullptr, given that the compiler gives you a
>> warning if you forget it.
>>
> 
> Something like this avoids copying some std::string around (which my
> initial implementation did), and can work with a string view (would be
> the same architecture with const char*).  The compiler should optimize
> almost all the function calls away easily enough.  I saw that Tom gave
> another approach which would work fine as well.
> 
>     namespace impl {
>     
>     template<typename ...Args>
>     inline void
>     path_join_1 (std::string &l, gdb::string_view r, Args... comps)
>     {
>       path_join_1 (l, r);
>       path_join_1 (l, ...comps);
>     }
>     
>     template<>
>     inline void
>     path_join_1 (std::string &l, gdb::string_view r)
>     {
>       /* The real logic here  */
>     }
>     
>     } /* namespace impl  */
>     
>     template<typename ...Args>
>     inline std::string
>     path_join (Args... comps)
>     {
>       std::string res;
>       impl::path_join_1 (res, comps...);
>       return res;
>     }

Thanks for the suggestion, I ended up using Tom's proposal.

Simon

  reply	other threads:[~2022-04-20  0:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14 20:01 [PATCH 1/5] gdb: call gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search Simon Marchi
2022-04-14 20:01 ` [PATCH 2/5] gdbsupport: make gdb_abspath return an std::string Simon Marchi
2022-04-18 19:41   ` Tom Tromey
2022-04-18 20:09     ` Pedro Alves
2022-04-18 20:11     ` Simon Marchi
2022-04-14 20:01 ` [PATCH 3/5] gdbsupport: make gdb_realpath_keepfile " Simon Marchi
2022-04-18 19:44   ` Tom Tromey
2022-04-14 20:01 ` [PATCH 4/5] gdb: use gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search Simon Marchi
2022-04-18 19:44   ` Tom Tromey
2022-04-18 20:12     ` Simon Marchi
2022-04-14 20:01 ` [PATCH 5/5] gdbsupport: add path_join function Simon Marchi
2022-04-15  5:59   ` Eli Zaretskii
2022-04-18 18:11     ` Simon Marchi
2022-04-18 18:30       ` Eli Zaretskii
2022-04-18 19:24       ` Pedro Alves
2022-04-15 14:38   ` Lancelot SIX
2022-04-15 16:55     ` Lancelot SIX
2022-04-18 18:43     ` Simon Marchi
2022-04-18 19:09       ` Pedro Alves
2022-04-18 19:12         ` Simon Marchi
2022-04-18 20:55           ` Simon Marchi
2022-04-18 21:07             ` Pedro Alves
2022-04-19  0:19               ` Simon Marchi
2022-04-18 19:22       ` Pedro Alves
2022-04-18 20:01       ` Tom Tromey
2022-04-18 23:11       ` Lancelot SIX
2022-04-20  0:22         ` Simon Marchi [this message]
2022-04-18 19:36 ` [PATCH 1/5] gdb: call gdb_tilde_expand instead of gdb_tilde_expand_up in source_script_with_search Tom Tromey

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=7c4c5b28-843a-f434-35e2-d42f51f18321@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    --cc=simon.marchi@efficios.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).