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>,
	Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	Christina Joos <christina.joos@intel.com>
Subject: Re: [PATCH v3 6/8] gdb: introduce helper class target_file_reader
Date: Wed, 11 Nov 2026 11:24:56 +0000	[thread overview]
Message-ID: <39e3c1ff-7476-4c25-bda1-78c2e065e71a@arm.com> (raw)
In-Reply-To: <87se1fvv0j.fsf@tromey.com>

On 05/11/2026 21:16, Tom Tromey wrote:
>>>>>> Matthieu Longo <matthieu.longo@arm.com> writes:
> 
>> Wrap all the boilerplate code required to read a file in a new helper
>> class: target_file_reader. The class owns the file contents together with
>> the file path, and provides convenient accessors for the data, size and
>> typed views. It supports both null-terminated text files and binary files.
> 
>> This helper eliminates repeated calls to target_fileio_read_stralloc
>> and target_fileio_read_alloc, removes explicit memory management with
>> gdb::unique_xmalloc_ptr, and simplifies the casting logic when working
>> with binary data.
> 
>> The patch converts some of the existing Linux, AMD64, and SPARC code that
>> reads files from /proc to use target_file_reader. As a side effect,
>> amd64_linux_lam_untag_mask and linux_process_address_in_memtag_page
>> may now return earlier in case the file is empty.
> 
> Thanks.
> 
>> +  target_file_reader<char> proc_status
>> +    (string_printf ("/proc/%d/status", inf->pid));
> 
>> +public:
>> +  /* Read the content of the file associated to PATH from the filesystem as
>> +     seen by INF.  If INF is NULL, use the filesystem seen by the debugger
>> +     (GDB or, for remote targets, the remote stub).  */
>> +  target_file_reader (const std::string &path, struct inferior *inf = nullptr)
>> +    : m_path (path)
>> +    , m_size (0)
>> +  {
> 
> Two notes here.
> 
> The ", m_size" thing isn't really gdb style.  (I like this style but
> haven't pushed for it at all.)  But it's moot here because in gdb it's
> more normal to inline-initialize a member like this.
> 

Fixed.

> Also, accepting a "std::string &&" here and moving it into place would
> avoid copying.
> 

There are some places where we want to keep the argument still valid in the calling context, so
rvalue is not always wanted.
I think it would make sense to add a second constructor taking an rvalue.

> I think this patch explains why you used array_view previously.
> 
> Tom

Matthieu

  reply	other threads:[~2026-11-11 11:26 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
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 [this message]
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=39e3c1ff-7476-4c25-bda1-78c2e065e71a@arm.com \
    --to=matthieu.longo@arm.com \
    --cc=aburgess@redhat.com \
    --cc=christina.joos@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=thiago.bauermann@linaro.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