Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Matthieu Longo <matthieu.longo@arm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org, Andrew Burgess <aburgess@redhat.com>
Subject: Re: [PATCH v3 4/8] gdbsupport: add extract_next_field helper
Date: Tue, 10 Nov 2026 12:51:59 +0000	[thread overview]
Message-ID: <7c22c0e1-8c0f-47f3-bac8-90ffbacc021c@arm.com> (raw)
In-Reply-To: <871p8zxaqz.fsf@tromey.com>

On 05/11/2026 20:51, Tom Tromey wrote:
>>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:
> 
>> Add extract_next_field, a helper for extracting a view from a buffer
>> up to a given separator. The helper also returns an iterator to the
>> beginning of the next entry, skipping consecutive separators.
> 
>> The helper supports views whose value type is 'char', such as
>> gdb::array_view<char> and std::string_view (from c++20).
> 
> Thanks for the patch.
> 
> I think this looks essentially ok but I have some nits.
> 
>> diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
>> index de83a715ac4..a4042b24644 100644
>> --- a/gdbsupport/common-utils.h
>> +++ b/gdbsupport/common-utils.h
> 
> I think we should normally not add more stuff to the various "utils"
> files.  These end up just being random grab bags of stuff.
> 
> I think adding a new header file in gdbsupport should be pretty easy.
> You don't even have to patch the build.
> 

How would you name the header ? common-string.h ?
I am really not inspired this morning... :/

>> +  /* Skip leading occurrences of the separator.  */
>> +  while (start != buffer.end () && *start == separator)
>> +    ++start;
> 
> This uses ++, which seems fine.
> 
>> +  /* If no separator is found, the remainder of BUFFER is the final string.  */
>> +  if (it != buffer.end ())
>> +    {
>> +      /* Otherwise, skip successive separators so that NEXT_START points to
>> +	 the beginning of the next string, if any.  */
>> +      for (next_start = std::next (it);
>> +	   next_start != buffer.end () && *next_start == separator;
>> +	   next_start = std::next (next_start));
> 
> ... but this uses std::next -- which is also fine, but made me wonder if
> there's a reason for the difference.
> 

No reason. Just a lack of consistency on my side.
I can change it to ++ instead.

> Also, is this second separator-skipping loop even needed?  Because it
> seems like it would be fine to just end here and let the next call to
> extract_next_field skip these now-leading separators.
> 
> Maybe it's important to the callers that these be skipped.  I haven't
> looked.
> 
> Tom

If I were to change the code to:

  auto it = std::find (start, buffer.end (), separator);

  /* If a separator is found, update next_start to the position of the
     found separator.  */
  if (it != buffer.end ())
    next_start = it;

  return {ViewT (start, it), next_start};

Without the second loop, trailing separators would cause an extra empty string to be returned.
For example, "\n1234\nabc\n\ndef\n\n" would produce:
  {"1234", "abc", "def", ""}
instead of:
  {"1234", "abc", "def"}.

I think skipping the trailing separators keeps the behavior consistent and avoids having callers to
handle this edge case.

Matthieu

  reply	other threads:[~2026-11-10 12:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 13:50 [PATCH v3 0/8] gdb: introduce file_reader_t to read procfs files Matthieu Longo
2026-09-22 13:50 ` [PATCH v3 1/8] gdb support: add gdb::ranges::replace algorithm Matthieu Longo
2026-11-05 20:39   ` Tom Tromey
2026-09-22 13:50 ` [PATCH v3 2/8] gdb/linux: remove redundant struct prefixes from smaps_data Matthieu Longo
2026-11-05 20:40   ` Tom Tromey
2026-09-22 13:50 ` [PATCH v3 3/8] gdb/linux: style filenames in /proc warning messages Matthieu Longo
2026-11-05 20:41   ` Tom Tromey
2026-09-22 13:50 ` [PATCH v3 4/8] gdbsupport: add extract_next_field helper Matthieu Longo
2026-11-05 20:51   ` Tom Tromey
2026-11-10 12:51     ` Matthieu Longo [this message]
2026-11-13 18:20       ` Tom Tromey
2026-11-16 11:11         ` Matthieu Longo
2026-09-22 13:50 ` [PATCH v3 5/8] gdb/linux: refactor /proc mapping parsing to use array_view Matthieu Longo
2026-11-05 21:04   ` Tom Tromey
2026-11-11 10:41     ` Matthieu Longo
2026-11-13 18:23       ` Tom Tromey
2026-11-11 10:56     ` Matthieu Longo
2026-09-22 13:50 ` [PATCH v3 6/8] gdb: introduce helper class target_file_reader Matthieu Longo
2026-11-05 21:16   ` Tom Tromey
2026-11-11 11:24     ` Matthieu Longo
2026-09-22 13:50 ` [PATCH v3 7/8] gdb/linux-tdep: use target_file_reader for procfs parsing Matthieu Longo
2026-11-05 21:27   ` Tom Tromey
2026-11-11 12:08     ` Matthieu Longo
2026-09-22 13:50 ` [PATCH v3 8/8] gdb/linux-tdep: remove legacy parse_smaps_data overload Matthieu Longo
2026-11-05 21:28   ` Tom Tromey
2026-10-09 14:59 ` [PATCH v3 0/8] gdb: introduce file_reader_t to read procfs files Matthieu Longo
2026-10-26 10:18   ` Matthieu Longo

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=7c22c0e1-8c0f-47f3-bac8-90ffbacc021c@arm.com \
    --to=matthieu.longo@arm.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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