From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>,
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 1/2] gdbsupport, gdb: add read_text_file_to_string, use it in linux_common_core_of_thread
Date: Tue, 8 Nov 2022 15:36:02 -0500 [thread overview]
Message-ID: <142c4e64-d0ce-6fef-7354-6ed98bf298f4@simark.ca> (raw)
In-Reply-To: <87edud5pzm.fsf@tromey.com>
On 11/8/22 12:13, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> I would like to add more code to nat/linux-osdata.c that reads an entire
> Simon> file from /proc or /sys and processes it as a string afterwards. I
> Simon> would like to avoid duplicating the somewhat error-prone code that reads
> Simon> an entire file to a buffer. I think we should have a utility function
> Simon> that does that.
>
> Makes sense. source_cache::get_plain_source_lines could use this btw,
> though it would need some change for error reporting.
Ok, although it would need a bit of refactoring, because that uses
open_source_file, which returns a scoped_fd.
I also spotted xml_fetch_content_from_file. The problem here is that it
returns a gdb::char_vector, not an std::string. To change it, we would
have to change to std::string all the way to target_read_stralloc. I
think it would be nice (it's nicer to use std::string for strings than
gdb::char_vector), but a bit too much just for this patch.
>
> Simon> +
> Simon> +gdb::optional<std::string>
> Simon> +read_text_file_to_string (const char *path)
>
> Should have a comment.
>
>
> Simon> +extern gdb::optional<std::string> read_text_file_to_string (const char *path);
>
> Here too.
Oops, forgot. Does that look good to you?
diff --git a/gdbsupport/filestuff.cc b/gdbsupport/filestuff.cc
index d003a7f39c4..cf5fb13bd0c 100644
--- a/gdbsupport/filestuff.cc
+++ b/gdbsupport/filestuff.cc
@@ -502,6 +502,8 @@ mkdir_recursive (const char *dir)
}
}
+/* See gdbsupport/filestuff.h. */
+
gdb::optional<std::string>
read_text_file_to_string (const char *path)
{
diff --git a/gdbsupport/filestuff.h b/gdbsupport/filestuff.h
index 3932710b5dc..33362901ab8 100644
--- a/gdbsupport/filestuff.h
+++ b/gdbsupport/filestuff.h
@@ -129,6 +129,8 @@ extern bool is_regular_file (const char *name, int *errno_ptr);
extern bool mkdir_recursive (const char *dir);
+/* Read the entire content of file PATH into an std::string. */
+
extern gdb::optional<std::string> read_text_file_to_string (const char *path);
#endif /* COMMON_FILESTUFF_H */
Simon
next prev parent reply other threads:[~2022-11-08 20:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 15:51 Simon Marchi
2022-11-04 15:51 ` [PATCH 2/2] gdb/linux-nat: get core count using /sys/devices/system/cpu/possible Simon Marchi
2022-11-08 17:17 ` Tom Tromey
2022-11-08 17:13 ` [PATCH 1/2] gdbsupport, gdb: add read_text_file_to_string, use it in linux_common_core_of_thread Tom Tromey
2022-11-08 20:36 ` Simon Marchi [this message]
2022-11-08 21:48 ` Tom Tromey
2022-11-08 21:52 ` Simon Marchi
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=142c4e64-d0ce-6fef-7354-6ed98bf298f4@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).