public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	Lancelot SIX <lsix@lancelotsix.com>
Cc: Simon Marchi <simon.marchi@efficios.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 5/5] gdbsupport: add path_join function
Date: Mon, 18 Apr 2022 22:07:52 +0100	[thread overview]
Message-ID: <61f1d11c-d7c5-3b60-3e29-cd70a94a824f@palves.net> (raw)
In-Reply-To: <d0305da3-b99c-195d-c84a-20cea43f2220@polymtl.ca>

On 2022-04-18 21:55, Simon Marchi wrote:
>> On 2022-04-18 15:09, Pedro Alves wrote:
>>> On 2022-04-18 19:43, Simon Marchi via Gdb-patches wrote:
>>>>> One implementation could be:
>>>>>
>>>>>     /* The real worker can be compiled in a .cc file if you wish.  */
>>>>>     extern std::string path_join_1 (std::string a, std::string b);
>>>>>
>>>>>     template <typename ...Args)
>>>>>     std::string
>>>>>     path_join (std::string a, std::string b, Args... comps)
>>>>>     {
>>>>>       return path_join (path_join (a, b), comps...);
>>>>>     }
>>>>>
>>>>>     template <>
>>>>>     std::string
>>>>>     path_join (std::string a, std::string b)
>>>>>     {
>>>>>       return path_join_1 (a, b);
>>>>>     }
>>>>>
>>>>> I do not pretend this is optimal (it is not).  In this POC I pass all
>>>>> arguments as std::string and by value, this is probably not what you
>>>>> want to do in a production grade implementation, but this just gives the
>>>>> overall idea.
>>>>>
>>>>> What do you think?
>>>> 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.
>>>
>>> I think it would just work as is you replace std::string with const char *
>>> in Lancelot's snippet above.  FWIW, I had the same thought as Lancelot
>>> about using variable templates instead of varargs.
>>>
>>> OOC, is there any place in GDB that wants to pass more than two components
>>> to path_join?  I skimmed the patch and didn't notice one.
>>
>> I am not aware of one, I'd be happy to make path_join just have two
>> parameters and be done with it.
> 
> Actually, I have one use for it in my upcoming DWARF reader changes,
> where I join the CU's compilation directory, the directory (from the
> line header directory table) and the file name.
> 
> I like Tom's proposal, here:
> 
>   https://sourceware.org/pipermail/gdb-patches/2022-April/188016.html
> 
> It seems efficient (no extraneous string copies) and type-safe.  I
> successfully changed my patch to use it.

Lancelot's approach seems more straightforward (trivially changed to use string_view) and
would also work, and it avoids creating the temporary array, at the expense of being
recursive when you have more than two components to join.  Either approach seems
good to me.  In Tom's approach, I think you could use gdb::array_view in concat.

  reply	other threads:[~2022-04-18 21:07 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 [this message]
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
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=61f1d11c-d7c5-3b60-3e29-cd70a94a824f@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    --cc=simon.marchi@efficios.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).