aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2021-11-22 11:27:30 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2021-11-22 13:57:49 -0500
commit06de25b7af21eb1173d7b86c5c0f37aae5ec2674 (patch)
tree257ca777e7e7c96de2844956bb61256f1ed5e111 /gdbsupport
parent7dca2ea7ff4c2c786119e13e81a5e6b0c1bf1d2d (diff)
downloadgdb-06de25b7af21eb1173d7b86c5c0f37aae5ec2674.zip
gdb-06de25b7af21eb1173d7b86c5c0f37aae5ec2674.tar.gz
gdb-06de25b7af21eb1173d7b86c5c0f37aae5ec2674.tar.bz2
gdb: introduce target_waitkind_str, use it in target_waitstatus::to_string
I would like to print target_waitkind values in debug messages, so I think that a target_waitkind-to-string function would be useful. While at it, use it in target_waitstatus::to_string. This changes the output of target_waitstatus::to_string a bit, but I think it is for the better. The debug messages will show a string matching exactly the target_waitkind enumerator (minus the TARGET_WAITKIND prefix). As a convenience, make string_appendf return the same reference to string it got as a parameter. This allows doing this: return string_appendf (str, "foo"); ... keeping the code concise. Change-Id: I383dffc9c78614e7d0668b1516073905e798eef7
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/common-utils.cc8
-rw-r--r--gdbsupport/common-utils.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/gdbsupport/common-utils.cc b/gdbsupport/common-utils.cc
index 42bce36..b591537 100644
--- a/gdbsupport/common-utils.cc
+++ b/gdbsupport/common-utils.cc
@@ -119,7 +119,7 @@ string_vprintf (const char* fmt, va_list args)
/* See documentation in common-utils.h. */
-void
+std::string &
string_appendf (std::string &str, const char *fmt, ...)
{
va_list vp;
@@ -127,12 +127,14 @@ string_appendf (std::string &str, const char *fmt, ...)
va_start (vp, fmt);
string_vappendf (str, fmt, vp);
va_end (vp);
+
+ return str;
}
/* See documentation in common-utils.h. */
-void
+std::string &
string_vappendf (std::string &str, const char *fmt, va_list args)
{
va_list vp;
@@ -148,6 +150,8 @@ string_vappendf (std::string &str, const char *fmt, va_list args)
/* C++11 and later guarantee std::string uses contiguous memory and
always includes the terminating '\0'. */
vsprintf (&str[curr_size], fmt, args); /* ARI: vsprintf */
+
+ return str;
}
char *
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index af07847..98a9dc7 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -54,11 +54,11 @@ std::string string_vprintf (const char* fmt, va_list args)
/* Like string_printf, but appends to DEST instead of returning a new
std::string. */
-void string_appendf (std::string &dest, const char* fmt, ...)
+std::string &string_appendf (std::string &dest, const char* fmt, ...)
ATTRIBUTE_PRINTF (2, 3);
/* Like string_appendf, but takes a va_list. */
-void string_vappendf (std::string &dest, const char* fmt, va_list args)
+std::string &string_vappendf (std::string &dest, const char* fmt, va_list args)
ATTRIBUTE_PRINTF (2, 0);
/* Make a copy of the string at PTR with LEN characters