* [PATCH 0/2] Remove one use of struct buffer
@ 2022-12-16 6:01 Simon Marchi
2022-12-16 6:01 ` [PATCH 1/2] gdbsupport: add string_xml_appendf Simon Marchi
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Simon Marchi @ 2022-12-16 6:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Tom mentioned the goal of getting rid of struct buffer, and that made me
remember I had these patches laying around.
Simon Marchi (2):
gdbsupport: add string_xml_appendf
gdb: convert linux-osdata.c from buffer to std::string
gdb/nat/linux-osdata.c | 287 +++++++++++++++++++++-------------------
gdbsupport/xml-utils.cc | 105 +++++++++++++++
gdbsupport/xml-utils.h | 10 ++
3 files changed, 263 insertions(+), 139 deletions(-)
base-commit: de75275fe54c5536c8238f0f3f88bb7ac2222942
--
2.38.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] gdbsupport: add string_xml_appendf
2022-12-16 6:01 [PATCH 0/2] Remove one use of struct buffer Simon Marchi
@ 2022-12-16 6:01 ` Simon Marchi
2022-12-16 6:01 ` [PATCH 2/2] gdb: convert linux-osdata.c from buffer to std::string Simon Marchi
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2022-12-16 6:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Add a version of buffer_xml_printf (defined in gdbsupport/buffer.{c,h})
that appends to an std::string, rather than a struct buffer. Call it
"string" rather than "buffer" since it operates on an std::string rather
than a buffer. And call it "appendf" rather than "printf", since it
appends to and does not replace the string's content. This mirrors
string_appendf.
Place the new version in gdbsupport/xml-utils.h.
The code is a direct copy of buffer_xml_printf. The old version is
going to disappear at some point, which is why I didn't do any effort to
share code.
Change-Id: I30e030627ab4970fd0b9eba3b7e8cec78fa561ba
---
gdbsupport/xml-utils.cc | 105 ++++++++++++++++++++++++++++++++++++++++
gdbsupport/xml-utils.h | 10 ++++
2 files changed, 115 insertions(+)
diff --git a/gdbsupport/xml-utils.cc b/gdbsupport/xml-utils.cc
index e47e23ced590..c74bcdd1155d 100644
--- a/gdbsupport/xml-utils.cc
+++ b/gdbsupport/xml-utils.cc
@@ -61,3 +61,108 @@ xml_escape_text_append (std::string &result, const char *text)
break;
}
}
+
+/* See xml-utils.h. */
+
+void
+string_xml_appendf (std::string &buffer, const char *format, ...)
+{
+ va_list ap;
+ const char *f;
+ const char *prev;
+ int percent = 0;
+
+ va_start (ap, format);
+
+ prev = format;
+ for (f = format; *f; f++)
+ {
+ if (percent)
+ {
+ char buf[32];
+ char *str = buf;
+ const char *f_old = f;
+
+ switch (*f)
+ {
+ case 's':
+ str = va_arg (ap, char *);
+ break;
+ case 'd':
+ sprintf (str, "%d", va_arg (ap, int));
+ break;
+ case 'u':
+ sprintf (str, "%u", va_arg (ap, unsigned int));
+ break;
+ case 'x':
+ sprintf (str, "%x", va_arg (ap, unsigned int));
+ break;
+ case 'o':
+ sprintf (str, "%o", va_arg (ap, unsigned int));
+ break;
+ case 'l':
+ f++;
+ switch (*f)
+ {
+ case 'd':
+ sprintf (str, "%ld", va_arg (ap, long));
+ break;
+ case 'u':
+ sprintf (str, "%lu", va_arg (ap, unsigned long));
+ break;
+ case 'x':
+ sprintf (str, "%lx", va_arg (ap, unsigned long));
+ break;
+ case 'o':
+ sprintf (str, "%lo", va_arg (ap, unsigned long));
+ break;
+ case 'l':
+ f++;
+ switch (*f)
+ {
+ case 'd':
+ sprintf (str, "%" PRId64,
+ (int64_t) va_arg (ap, long long));
+ break;
+ case 'u':
+ sprintf (str, "%" PRIu64,
+ (uint64_t) va_arg (ap, unsigned long long));
+ break;
+ case 'x':
+ sprintf (str, "%" PRIx64,
+ (uint64_t) va_arg (ap, unsigned long long));
+ break;
+ case 'o':
+ sprintf (str, "%" PRIo64,
+ (uint64_t) va_arg (ap, unsigned long long));
+ break;
+ default:
+ str = 0;
+ break;
+ }
+ break;
+ default:
+ str = 0;
+ break;
+ }
+ break;
+ default:
+ str = 0;
+ break;
+ }
+
+ if (str)
+ {
+ buffer.append (prev, f_old - prev - 1);
+ xml_escape_text_append (buffer, str);
+ prev = f + 1;
+ }
+ percent = 0;
+ }
+ else if (*f == '%')
+ percent = 1;
+ }
+
+ buffer.append (prev);
+ va_end (ap);
+}
diff --git a/gdbsupport/xml-utils.h b/gdbsupport/xml-utils.h
index 695263c5b379..09714027030f 100644
--- a/gdbsupport/xml-utils.h
+++ b/gdbsupport/xml-utils.h
@@ -30,4 +30,14 @@ extern std::string xml_escape_text (const char *text);
extern void xml_escape_text_append (std::string &result, const char *text);
+/* Simple printf to string function. Current implemented formatters:
+ %s - append an xml escaped text to BUFFER.
+ %d - append an signed integer to BUFFER.
+ %u - append an unsigned integer to BUFFER.
+ %x - append an unsigned integer formatted in hexadecimal to BUFFER.
+ %o - append an unsigned integer formatted in octal to BUFFER. */
+
+void string_xml_appendf (std::string &buffer, const char *format, ...)
+ ATTRIBUTE_PRINTF (2, 3);
+
#endif /* COMMON_XML_UTILS_H */
--
2.38.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] gdb: convert linux-osdata.c from buffer to std::string
2022-12-16 6:01 [PATCH 0/2] Remove one use of struct buffer Simon Marchi
2022-12-16 6:01 ` [PATCH 1/2] gdbsupport: add string_xml_appendf Simon Marchi
@ 2022-12-16 6:01 ` Simon Marchi
2022-12-16 13:09 ` [PATCH 0/2] Remove one use of struct buffer Pedro Alves
2022-12-16 15:04 ` Tom Tromey
3 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2022-12-16 6:01 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Replace the use of struct buffer in linux-osdata.c with std::string.
There is not change in the logic, so there should be no user-visible
change.
Change-Id: I27f53165d401650bbd0bebe8ed88221e25545b3f
---
gdb/nat/linux-osdata.c | 287 +++++++++++++++++++++--------------------
1 file changed, 148 insertions(+), 139 deletions(-)
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index 8639f090910a..73a052560264 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -333,12 +333,11 @@ get_core_array_size ()
return sysconf (_SC_NPROCESSORS_ONLN);
}
-static void
-linux_xfer_osdata_processes (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_processes ()
{
DIR *dirp;
-
- buffer_grow_str (buffer, "<osdata type=\"processes\">\n");
+ std::string buffer = "<osdata type=\"processes\">\n";
dirp = opendir ("/proc");
if (dirp)
@@ -385,7 +384,7 @@ linux_xfer_osdata_processes (struct buffer *buffer)
xfree (cores);
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"pid\">%lld</column>"
@@ -404,7 +403,9 @@ linux_xfer_osdata_processes (struct buffer *buffer)
closedir (dirp);
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* A simple PID/PGID pair. */
@@ -446,12 +447,11 @@ struct pid_pgid_entry
/* Collect all process groups from /proc in BUFFER. */
-static void
-linux_xfer_osdata_processgroups (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_processgroups ()
{
DIR *dirp;
-
- buffer_grow_str (buffer, "<osdata type=\"process groups\">\n");
+ std::string buffer = "<osdata type=\"process groups\">\n";
dirp = opendir ("/proc");
if (dirp)
@@ -493,7 +493,7 @@ linux_xfer_osdata_processgroups (struct buffer *buffer)
command_from_pid (leader_command, sizeof (leader_command), pgid);
command_line = commandline_from_pid (pid);
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"pgid\">%lld</column>"
@@ -510,18 +510,19 @@ linux_xfer_osdata_processgroups (struct buffer *buffer)
}
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect all the threads in /proc by iterating through processes and
- then tasks within each process in BUFFER. */
+ then tasks within each process. */
-static void
-linux_xfer_osdata_threads (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_threads ()
{
DIR *dirp;
-
- buffer_grow_str (buffer, "<osdata type=\"threads\">\n");
+ std::string buffer = "<osdata type=\"threads\">\n";
dirp = opendir ("/proc");
if (dirp)
@@ -570,7 +571,7 @@ linux_xfer_osdata_threads (struct buffer *buffer)
tid = atoi (dp2->d_name);
core = linux_common_core_of_thread (ptid_t (pid, tid));
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"pid\">%lld</column>"
@@ -592,17 +593,18 @@ linux_xfer_osdata_threads (struct buffer *buffer)
closedir (dirp);
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect data about the cpus/cores on the system in BUFFER. */
-static void
-linux_xfer_osdata_cpus (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_cpus ()
{
int first_item = 1;
-
- buffer_grow_str (buffer, "<osdata type=\"cpus\">\n");
+ std::string buffer = "<osdata type=\"cpus\">\n";
gdb_file_up fp = gdb_fopen_cloexec ("/proc/cpuinfo", "r");
if (fp != NULL)
@@ -639,37 +641,38 @@ linux_xfer_osdata_cpus (struct buffer *buffer)
if (strcmp (key, "processor") == 0)
{
if (first_item)
- buffer_grow_str (buffer, "<item>");
+ buffer += "<item>";
else
- buffer_grow_str (buffer, "</item><item>");
+ buffer += "</item><item>";
first_item = 0;
}
- buffer_xml_printf (buffer,
- "<column name=\"%s\">%s</column>",
- key,
- value);
+ string_xml_appendf (buffer,
+ "<column name=\"%s\">%s</column>",
+ key,
+ value);
}
}
while (!feof (fp.get ()));
if (first_item == 0)
- buffer_grow_str (buffer, "</item>");
+ buffer += "</item>";
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect all the open file descriptors found in /proc and put the details
found about them into BUFFER. */
-static void
-linux_xfer_osdata_fds (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_fds ()
{
DIR *dirp;
-
- buffer_grow_str (buffer, "<osdata type=\"files\">\n");
+ std::string buffer = "<osdata type=\"files\">\n";
dirp = opendir ("/proc");
if (dirp)
@@ -721,7 +724,7 @@ linux_xfer_osdata_fds (struct buffer *buffer)
if (rslt >= 0)
buf[rslt] = '\0';
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"pid\">%s</column>"
@@ -743,7 +746,9 @@ linux_xfer_osdata_fds (struct buffer *buffer)
closedir (dirp);
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Returns the socket state STATE in textual form. */
@@ -808,7 +813,7 @@ union socket_addr
otherwise only UDP sockets are processed. */
static void
-print_sockets (unsigned short family, int tcp, struct buffer *buffer)
+print_sockets (unsigned short family, int tcp, std::string &buffer)
{
const char *proc_file;
@@ -909,26 +914,26 @@ print_sockets (unsigned short family, int tcp, struct buffer *buffer)
user_from_uid (user, sizeof (user), uid);
- buffer_xml_printf (
- buffer,
- "<item>"
- "<column name=\"local address\">%s</column>"
- "<column name=\"local port\">%s</column>"
- "<column name=\"remote address\">%s</column>"
- "<column name=\"remote port\">%s</column>"
- "<column name=\"state\">%s</column>"
- "<column name=\"user\">%s</column>"
- "<column name=\"family\">%s</column>"
- "<column name=\"protocol\">%s</column>"
- "</item>",
- local_address,
- local_service,
- remote_address,
- remote_service,
- format_socket_state (state),
- user,
- (family == AF_INET) ? "INET" : "INET6",
- tcp ? "STREAM" : "DGRAM");
+ string_xml_appendf
+ (buffer,
+ "<item>"
+ "<column name=\"local address\">%s</column>"
+ "<column name=\"local port\">%s</column>"
+ "<column name=\"remote address\">%s</column>"
+ "<column name=\"remote port\">%s</column>"
+ "<column name=\"state\">%s</column>"
+ "<column name=\"user\">%s</column>"
+ "<column name=\"family\">%s</column>"
+ "<column name=\"protocol\">%s</column>"
+ "</item>",
+ local_address,
+ local_service,
+ remote_address,
+ remote_service,
+ format_socket_state (state),
+ user,
+ (family == AF_INET) ? "INET" : "INET6",
+ tcp ? "STREAM" : "DGRAM");
}
}
}
@@ -938,17 +943,19 @@ print_sockets (unsigned short family, int tcp, struct buffer *buffer)
/* Collect data about internet sockets and write it into BUFFER. */
-static void
-linux_xfer_osdata_isockets (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_isockets ()
{
- buffer_grow_str (buffer, "<osdata type=\"I sockets\">\n");
+ std::string buffer = "<osdata type=\"I sockets\">\n";
print_sockets (AF_INET, 1, buffer);
print_sockets (AF_INET, 0, buffer);
print_sockets (AF_INET6, 1, buffer);
print_sockets (AF_INET6, 0, buffer);
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Converts the time SECONDS into textual form and copies it into a
@@ -993,10 +1000,10 @@ group_from_gid (char *group, int maxlen, gid_t gid)
/* Collect data about shared memory recorded in /proc and write it
into BUFFER. */
-static void
-linux_xfer_osdata_shm (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_shm ()
{
- buffer_grow_str (buffer, "<osdata type=\"shared memory\">\n");
+ std::string buffer = "<osdata type=\"shared memory\">\n";
gdb_file_up fp = gdb_fopen_cloexec ("/proc/sysvipc/shm", "r");
if (fp)
@@ -1043,7 +1050,7 @@ linux_xfer_osdata_shm (struct buffer *buffer)
time_from_time_t (dtime_str, sizeof (dtime_str), dtime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"key\">%d</column>"
@@ -1081,16 +1088,18 @@ linux_xfer_osdata_shm (struct buffer *buffer)
while (!feof (fp.get ()));
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect data about semaphores recorded in /proc and write it
into BUFFER. */
-static void
-linux_xfer_osdata_sem (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_sem ()
{
- buffer_grow_str (buffer, "<osdata type=\"semaphores\">\n");
+ std::string buffer = "<osdata type=\"semaphores\">\n";
gdb_file_up fp = gdb_fopen_cloexec ("/proc/sysvipc/sem", "r");
if (fp)
@@ -1129,7 +1138,7 @@ linux_xfer_osdata_sem (struct buffer *buffer)
time_from_time_t (otime_str, sizeof (otime_str), otime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"key\">%d</column>"
@@ -1159,16 +1168,18 @@ linux_xfer_osdata_sem (struct buffer *buffer)
while (!feof (fp.get ()));
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect data about message queues recorded in /proc and write it
into BUFFER. */
-static void
-linux_xfer_osdata_msg (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_msg ()
{
- buffer_grow_str (buffer, "<osdata type=\"message queues\">\n");
+ std::string buffer = "<osdata type=\"message queues\">\n";
gdb_file_up fp = gdb_fopen_cloexec ("/proc/sysvipc/msg", "r");
if (fp)
@@ -1213,7 +1224,7 @@ linux_xfer_osdata_msg (struct buffer *buffer)
time_from_time_t (rtime_str, sizeof (rtime_str), rtime);
time_from_time_t (ctime_str, sizeof (ctime_str), ctime);
- buffer_xml_printf
+ string_xml_appendf
(buffer,
"<item>"
"<column name=\"key\">%d</column>"
@@ -1251,16 +1262,18 @@ linux_xfer_osdata_msg (struct buffer *buffer)
while (!feof (fp.get ()));
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
/* Collect data about loaded kernel modules and write it into
BUFFER. */
-static void
-linux_xfer_osdata_modules (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_modules ()
{
- buffer_grow_str (buffer, "<osdata type=\"modules\">\n");
+ std::string buffer = "<osdata type=\"modules\">\n";
gdb_file_up fp = gdb_fopen_cloexec ("/proc/modules", "r");
if (fp)
@@ -1306,84 +1319,87 @@ linux_xfer_osdata_modules (struct buffer *buffer)
if (sscanf (tmp, "%llx", &address) != 1)
continue;
- buffer_xml_printf (buffer,
- "<item>"
- "<column name=\"name\">%s</column>"
- "<column name=\"size\">%u</column>"
- "<column name=\"num uses\">%d</column>"
- "<column name=\"dependencies\">%s</column>"
- "<column name=\"status\">%s</column>"
- "<column name=\"address\">%llx</column>"
- "</item>",
- name,
- size,
- uses,
- dependencies,
- status,
- address);
+ string_xml_appendf (buffer,
+ "<item>"
+ "<column name=\"name\">%s</column>"
+ "<column name=\"size\">%u</column>"
+ "<column name=\"num uses\">%d</column>"
+ "<column name=\"dependencies\">%s</column>"
+ "<column name=\"status\">%s</column>"
+ "<column name=\"address\">%llx</column>"
+ "</item>",
+ name,
+ size,
+ uses,
+ dependencies,
+ status,
+ address);
}
}
while (!feof (fp.get ()));
}
- buffer_grow_str0 (buffer, "</osdata>\n");
+ buffer += "</osdata>\n";
+
+ return buffer;
}
-static void linux_xfer_osdata_info_os_types (struct buffer *buffer);
+static std::string linux_xfer_osdata_info_os_types ();
static struct osdata_type {
const char *type;
const char *title;
const char *description;
- void (*take_snapshot) (struct buffer *buffer);
- LONGEST len_avail;
- struct buffer buffer;
+ std::string (*take_snapshot) ();
+ std::string buffer;
} osdata_table[] = {
{ "types", "Types", "Listing of info os types you can list",
- linux_xfer_osdata_info_os_types, -1 },
+ linux_xfer_osdata_info_os_types },
{ "cpus", "CPUs", "Listing of all cpus/cores on the system",
- linux_xfer_osdata_cpus, -1 },
+ linux_xfer_osdata_cpus },
{ "files", "File descriptors", "Listing of all file descriptors",
- linux_xfer_osdata_fds, -1 },
+ linux_xfer_osdata_fds },
{ "modules", "Kernel modules", "Listing of all loaded kernel modules",
- linux_xfer_osdata_modules, -1 },
+ linux_xfer_osdata_modules },
{ "msg", "Message queues", "Listing of all message queues",
- linux_xfer_osdata_msg, -1 },
+ linux_xfer_osdata_msg },
{ "processes", "Processes", "Listing of all processes",
- linux_xfer_osdata_processes, -1 },
+ linux_xfer_osdata_processes },
{ "procgroups", "Process groups", "Listing of all process groups",
- linux_xfer_osdata_processgroups, -1 },
+ linux_xfer_osdata_processgroups },
{ "semaphores", "Semaphores", "Listing of all semaphores",
- linux_xfer_osdata_sem, -1 },
+ linux_xfer_osdata_sem },
{ "shm", "Shared-memory regions", "Listing of all shared-memory regions",
- linux_xfer_osdata_shm, -1 },
+ linux_xfer_osdata_shm },
{ "sockets", "Sockets", "Listing of all internet-domain sockets",
- linux_xfer_osdata_isockets, -1 },
+ linux_xfer_osdata_isockets },
{ "threads", "Threads", "Listing of all threads",
- linux_xfer_osdata_threads, -1 },
+ linux_xfer_osdata_threads },
{ NULL, NULL, NULL }
};
/* Collect data about all types info os can show in BUFFER. */
-static void
-linux_xfer_osdata_info_os_types (struct buffer *buffer)
+static std::string
+linux_xfer_osdata_info_os_types ()
{
- buffer_grow_str (buffer, "<osdata type=\"types\">\n");
+ std::string buffer = "<osdata type=\"types\">\n";
/* Start the below loop at 1, as we do not want to list ourselves. */
for (int i = 1; osdata_table[i].type; ++i)
- buffer_xml_printf (buffer,
- "<item>"
- "<column name=\"Type\">%s</column>"
- "<column name=\"Description\">%s</column>"
- "<column name=\"Title\">%s</column>"
- "</item>",
- osdata_table[i].type,
- osdata_table[i].description,
- osdata_table[i].title);
-
- buffer_grow_str0 (buffer, "</osdata>\n");
+ string_xml_appendf (buffer,
+ "<item>"
+ "<column name=\"Type\">%s</column>"
+ "<column name=\"Description\">%s</column>"
+ "<column name=\"Title\">%s</column>"
+ "</item>",
+ osdata_table[i].type,
+ osdata_table[i].description,
+ osdata_table[i].title);
+
+ buffer += "</osdata>\n";
+
+ return buffer;
}
@@ -1397,24 +1413,17 @@ common_getter (struct osdata_type *osd,
gdb_assert (readbuf);
if (offset == 0)
- {
- if (osd->len_avail != -1 && osd->len_avail != 0)
- buffer_free (&osd->buffer);
- osd->len_avail = 0;
- buffer_init (&osd->buffer);
- (osd->take_snapshot) (&osd->buffer);
- osd->len_avail = strlen (osd->buffer.buffer);
- }
- if (offset >= osd->len_avail)
+ osd->buffer = osd->take_snapshot ();
+
+ if (offset >= osd->buffer.size ())
{
/* Done. Get rid of the buffer. */
- buffer_free (&osd->buffer);
- osd->len_avail = 0;
+ osd->buffer.clear ();
return 0;
}
- if (len > osd->len_avail - offset)
- len = osd->len_avail - offset;
- memcpy (readbuf, osd->buffer.buffer + offset, len);
+
+ len = std::min (len, osd->buffer.size () - offset);
+ memcpy (readbuf, &osd->buffer[offset], len);
return len;
--
2.38.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Remove one use of struct buffer
2022-12-16 6:01 [PATCH 0/2] Remove one use of struct buffer Simon Marchi
2022-12-16 6:01 ` [PATCH 1/2] gdbsupport: add string_xml_appendf Simon Marchi
2022-12-16 6:01 ` [PATCH 2/2] gdb: convert linux-osdata.c from buffer to std::string Simon Marchi
@ 2022-12-16 13:09 ` Pedro Alves
2022-12-16 13:32 ` Simon Marchi
2022-12-16 15:04 ` Tom Tromey
3 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2022-12-16 13:09 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 2022-12-16 6:01 a.m., Simon Marchi via Gdb-patches wrote:
> Tom mentioned the goal of getting rid of struct buffer, and that made me
> remember I had these patches laying around.
>
Yeah, IIRC, struct buffer existed avoid obstack in gdbserver I think because
back then gdbserver didn't link with libiberty. There used to be a obstack_xml_printf
function too, which was eliminated too since. Glad to see it all go.
> Simon Marchi (2):
> gdbsupport: add string_xml_appendf
> gdb: convert linux-osdata.c from buffer to std::string
LGTM.
("There is not change" -> "There is no change" in patch 2's commit log.)
>
> gdb/nat/linux-osdata.c | 287 +++++++++++++++++++++-------------------
> gdbsupport/xml-utils.cc | 105 +++++++++++++++
> gdbsupport/xml-utils.h | 10 ++
> 3 files changed, 263 insertions(+), 139 deletions(-)
>
>
> base-commit: de75275fe54c5536c8238f0f3f88bb7ac2222942
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Remove one use of struct buffer
2022-12-16 13:09 ` [PATCH 0/2] Remove one use of struct buffer Pedro Alves
@ 2022-12-16 13:32 ` Simon Marchi
0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2022-12-16 13:32 UTC (permalink / raw)
To: Pedro Alves, gdb-patches
On 12/16/22 08:09, Pedro Alves wrote:
> On 2022-12-16 6:01 a.m., Simon Marchi via Gdb-patches wrote:
>> Tom mentioned the goal of getting rid of struct buffer, and that made me
>> remember I had these patches laying around.
>>
>
> Yeah, IIRC, struct buffer existed avoid obstack in gdbserver I think because
> back then gdbserver didn't link with libiberty. There used to be a obstack_xml_printf
> function too, which was eliminated too since. Glad to see it all go.
>
>> Simon Marchi (2):
>> gdbsupport: add string_xml_appendf
>> gdb: convert linux-osdata.c from buffer to std::string
>
> LGTM.
>
> ("There is not change" -> "There is no change" in patch 2's commit log.)
Fixed and pushed, thanks.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Remove one use of struct buffer
2022-12-16 6:01 [PATCH 0/2] Remove one use of struct buffer Simon Marchi
` (2 preceding siblings ...)
2022-12-16 13:09 ` [PATCH 0/2] Remove one use of struct buffer Pedro Alves
@ 2022-12-16 15:04 ` Tom Tromey
3 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2022-12-16 15:04 UTC (permalink / raw)
To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
Simon> Tom mentioned the goal of getting rid of struct buffer, and that made me
Simon> remember I had these patches laying around.
Thanks for doing this. I have patches to remove all the uses of struct
buffer except the one in event-top.c. I plan to write that one a bit
later though.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-16 15:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-16 6:01 [PATCH 0/2] Remove one use of struct buffer Simon Marchi
2022-12-16 6:01 ` [PATCH 1/2] gdbsupport: add string_xml_appendf Simon Marchi
2022-12-16 6:01 ` [PATCH 2/2] gdb: convert linux-osdata.c from buffer to std::string Simon Marchi
2022-12-16 13:09 ` [PATCH 0/2] Remove one use of struct buffer Pedro Alves
2022-12-16 13:32 ` Simon Marchi
2022-12-16 15:04 ` Tom Tromey
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).