From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 3/5] gdb: remove use of a static buffer for building error strings
Date: Thu, 28 Sep 2023 15:00:42 +0100 [thread overview]
Message-ID: <a2349003d8f47575c5fe99630ecdef6814d885a9.1695909469.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1695909469.git.aburgess@redhat.com>
I noticed in procfs.c that we use a static buffer for building error
strings when we could easily use std::string and string_printf to
achieve the same result, this commit does that.
I ran into this while performing a further refactor/cleanup that will
be presented in a later patch in this series, and thought this was
worth splitting out into its own patch.
As far as I can tell, only Solaris uses procfs.c, so I did a test
build on a Solaris machine, and I don't believe that I've broken
anything.
There should be no user visible changes after this commit.
---
gdb/procfs.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/gdb/procfs.c b/gdb/procfs.c
index 9443b074483..706ccf0965c 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -255,8 +255,6 @@ typedef struct procinfo {
int threads_valid: 1;
} procinfo;
-static char errmsg[128]; /* shared error msg buffer */
-
/* Function prototypes for procinfo module: */
static procinfo *find_procinfo_or_die (int pid, int tid);
@@ -595,17 +593,19 @@ static void proc_resume (procinfo *pi, ptid_t scope_ptid,
static void
proc_warn (procinfo *pi, const char *func, int line)
{
- xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
- func, line, pi->pathname);
- print_sys_errmsg (errmsg, errno);
+ int saved_errno = errno;
+ std::string errmsg
+ = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname);
+ print_sys_errmsg (errmsg.c_str (), saved_errno);
}
static void
proc_error (procinfo *pi, const char *func, int line)
{
- xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
- func, line, pi->pathname);
- perror_with_name (errmsg);
+ int saved_errno = errno;
+ std::string errmsg
+ = string_printf ("procfs: %s line %d, %s", func, line, pi->pathname);
+ perror_with_name (errmsg.c_str (), saved_errno);
}
/* Updates the status struct in the procinfo. There is a 'valid'
@@ -1805,11 +1805,12 @@ do_attach (ptid_t ptid)
if (!open_procinfo_files (pi, FD_CTL))
{
- gdb_printf (gdb_stderr, "procfs:%d -- ", __LINE__);
- xsnprintf (errmsg, sizeof (errmsg),
- "do_attach: couldn't open /proc file for process %d",
- ptid.pid ());
- dead_procinfo (pi, errmsg, NOKILL);
+ int saved_errno = errno;
+ std::string errmsg
+ = string_printf ("procfs:%d -- do_attach: couldn't open /proc "
+ "file for process %d", __LINE__, ptid.pid ());
+ errno = saved_errno;
+ dead_procinfo (pi, errmsg.c_str (), NOKILL);
}
/* Stop the process (if it isn't already stopped). */
--
2.25.4
next prev parent reply other threads:[~2023-09-28 14:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 14:22 [PATCH 0/5] Fix using an exec file with target: prefix Andrew Burgess
2023-09-27 14:22 ` [PATCH 1/5] gdb: some additional filename styling Andrew Burgess
2023-09-27 14:22 ` [PATCH 2/5] gdb: use archive name in warning when appropriate Andrew Burgess
2023-09-27 14:22 ` [PATCH 3/5] gdb: remove use of a static buffer for building error strings Andrew Burgess
2023-09-27 14:22 ` [PATCH 4/5] gdb: remove print_sys_errmsg Andrew Burgess
2023-09-28 12:06 ` Andrew Burgess
2023-09-27 14:22 ` [PATCH 5/5] gdb: fix reread_symbols when an objfile has target: prefix Andrew Burgess
2023-09-28 14:00 ` [PATCHv2 0/5] Fix using an exec file with " Andrew Burgess
2023-09-28 14:00 ` [PATCHv2 1/5] gdb: some additional filename styling Andrew Burgess
2023-09-28 14:00 ` [PATCHv2 2/5] gdb: use archive name in warning when appropriate Andrew Burgess
2023-09-28 14:00 ` Andrew Burgess [this message]
2023-09-28 14:00 ` [PATCHv2 4/5] gdb: remove print_sys_errmsg Andrew Burgess
2023-09-28 14:00 ` [PATCHv2 5/5] gdb: fix reread_symbols when an objfile has target: prefix Andrew Burgess
2023-09-28 18:17 ` Tom Tromey
2023-09-29 10:20 ` Andrew Burgess
2023-10-02 14:19 ` Tom Tromey
2023-10-02 16:05 ` Andrew Burgess
2023-10-02 17:00 ` Tom Tromey
2023-10-02 19:13 ` [PATCHv2 0/5] Fix using an exec file with " 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=a2349003d8f47575c5fe99630ecdef6814d885a9.1695909469.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/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).