forked from Imagelibrary/binutils-gdb
gdbserver: make target_pid_to_str return std::string
I wanted to write a warning that included two target_pid_to_str calls,
like this:
warning (_("Blabla %s, blabla %s"),
target_pid_to_str (ptid1),
target_pid_to_str (ptid2));
This doesn't work, because target_pid_to_str stores its result in a
static buffer, so my message would show twice the same ptid. Change
target_pid_to_str to return an std::string to avoid this. I don't think
we save much by using a static buffer, but it is more error-prone.
Change-Id: Ie3f649627686b84930529cc5c7c691ccf5d36dc2
This commit is contained in:
@@ -276,26 +276,23 @@ set_target_ops (process_stratum_target *target)
|
||||
|
||||
/* Convert pid to printable format. */
|
||||
|
||||
const char *
|
||||
std::string
|
||||
target_pid_to_str (ptid_t ptid)
|
||||
{
|
||||
static char buf[80];
|
||||
|
||||
if (ptid == minus_one_ptid)
|
||||
xsnprintf (buf, sizeof (buf), "<all threads>");
|
||||
return string_printf("<all threads>");
|
||||
else if (ptid == null_ptid)
|
||||
xsnprintf (buf, sizeof (buf), "<null thread>");
|
||||
return string_printf("<null thread>");
|
||||
else if (ptid.tid () != 0)
|
||||
xsnprintf (buf, sizeof (buf), "Thread %d.0x%s",
|
||||
ptid.pid (), phex_nz (ptid.tid (), sizeof (ULONGEST)));
|
||||
return string_printf("Thread %d.0x%s",
|
||||
ptid.pid (),
|
||||
phex_nz (ptid.tid (), sizeof (ULONGEST)));
|
||||
else if (ptid.lwp () != 0)
|
||||
xsnprintf (buf, sizeof (buf), "LWP %d.%ld",
|
||||
ptid.pid (), ptid.lwp ());
|
||||
return string_printf("LWP %d.%ld",
|
||||
ptid.pid (), ptid.lwp ());
|
||||
else
|
||||
xsnprintf (buf, sizeof (buf), "Process %d",
|
||||
ptid.pid ());
|
||||
|
||||
return buf;
|
||||
return string_printf("Process %d",
|
||||
ptid.pid ());
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user