forked from Imagelibrary/binutils-gdb
gdb: remove use of a static buffer for building error strings
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. Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
27
gdb/procfs.c
27
gdb/procfs.c
@@ -255,8 +255,6 @@ typedef struct procinfo {
|
|||||||
int threads_valid: 1;
|
int threads_valid: 1;
|
||||||
} procinfo;
|
} procinfo;
|
||||||
|
|
||||||
static char errmsg[128]; /* shared error msg buffer */
|
|
||||||
|
|
||||||
/* Function prototypes for procinfo module: */
|
/* Function prototypes for procinfo module: */
|
||||||
|
|
||||||
static procinfo *find_procinfo_or_die (int pid, int tid);
|
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
|
static void
|
||||||
proc_warn (procinfo *pi, const char *func, int line)
|
proc_warn (procinfo *pi, const char *func, int line)
|
||||||
{
|
{
|
||||||
xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
|
int saved_errno = errno;
|
||||||
func, line, pi->pathname);
|
std::string errmsg
|
||||||
print_sys_errmsg (errmsg, errno);
|
= string_printf ("procfs: %s line %d, %s", func, line, pi->pathname);
|
||||||
|
print_sys_errmsg (errmsg.c_str (), saved_errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
proc_error (procinfo *pi, const char *func, int line)
|
proc_error (procinfo *pi, const char *func, int line)
|
||||||
{
|
{
|
||||||
xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
|
int saved_errno = errno;
|
||||||
func, line, pi->pathname);
|
std::string errmsg
|
||||||
perror_with_name (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'
|
/* 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))
|
if (!open_procinfo_files (pi, FD_CTL))
|
||||||
{
|
{
|
||||||
gdb_printf (gdb_stderr, "procfs:%d -- ", __LINE__);
|
int saved_errno = errno;
|
||||||
xsnprintf (errmsg, sizeof (errmsg),
|
std::string errmsg
|
||||||
"do_attach: couldn't open /proc file for process %d",
|
= string_printf ("procfs:%d -- do_attach: couldn't open /proc "
|
||||||
ptid.pid ());
|
"file for process %d", __LINE__, ptid.pid ());
|
||||||
dead_procinfo (pi, errmsg, NOKILL);
|
errno = saved_errno;
|
||||||
|
dead_procinfo (pi, errmsg.c_str (), NOKILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop the process (if it isn't already stopped). */
|
/* Stop the process (if it isn't already stopped). */
|
||||||
|
|||||||
Reference in New Issue
Block a user