diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-25 14:33:55 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-25 14:33:55 -0400 |
commit | 61d7f128e6ea37af805be4e365f5879b0d42bb93 (patch) | |
tree | c581803312ce6dcb9b37ef348c37367090ea293e /gdbserver/target.cc | |
parent | b3a9fe6f51fd3922ce7978b6ba5ce0cbdf33885e (diff) | |
download | gdb-61d7f128e6ea37af805be4e365f5879b0d42bb93.zip gdb-61d7f128e6ea37af805be4e365f5879b0d42bb93.tar.gz gdb-61d7f128e6ea37af805be4e365f5879b0d42bb93.tar.bz2 |
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
Diffstat (limited to 'gdbserver/target.cc')
-rw-r--r-- | gdbserver/target.cc | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/gdbserver/target.cc b/gdbserver/target.cc index b6a1cb2..bfa8605 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -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 |