[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 28/38] gdbstub: lightly refactor connection to avoid snprintf
From: |
Alex Bennée |
Subject: |
[PATCH v4 28/38] gdbstub: lightly refactor connection to avoid snprintf |
Date: |
Fri, 30 Jun 2023 19:04:13 +0100 |
This may be a bit too much to avoid an snprintf and the slightly dodgy
assign to a const variable. But hopefully not.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- fix checkpatch warning
---
gdbstub/softmmu.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/gdbstub/softmmu.c b/gdbstub/softmmu.c
index 99d994e6bf..f509b7285d 100644
--- a/gdbstub/softmmu.c
+++ b/gdbstub/softmmu.c
@@ -332,11 +332,9 @@ static void create_processes(GDBState *s)
int gdbserver_start(const char *device)
{
- trace_gdbstub_op_start(device);
-
- char gdbstub_device_name[128];
Chardev *chr = NULL;
Chardev *mon_chr;
+ g_autoptr(GString) cs = g_string_new(device);
if (!first_cpu) {
error_report("gdbstub: meaningless to attach gdb to a "
@@ -350,15 +348,16 @@ int gdbserver_start(const char *device)
return -1;
}
- if (!device) {
+ if (cs->len == 0) {
return -1;
}
- if (strcmp(device, "none") != 0) {
- if (strstart(device, "tcp:", NULL)) {
+
+ trace_gdbstub_op_start(cs->str);
+
+ if (g_strcmp0(cs->str, "none") != 0) {
+ if (g_str_has_prefix(cs->str, "tcp:")) {
/* enforce required TCP attributes */
- snprintf(gdbstub_device_name, sizeof(gdbstub_device_name),
- "%s,wait=off,nodelay=on,server=on", device);
- device = gdbstub_device_name;
+ g_string_append_printf(cs, ",wait=off,nodelay=on,server=on");
}
#ifndef _WIN32
else if (strcmp(device, "stdio") == 0) {
@@ -373,7 +372,7 @@ int gdbserver_start(const char *device)
* FIXME: it's a bit weird to allow using a mux chardev here
* and implicitly setup a monitor. We may want to break this.
*/
- chr = qemu_chr_new_noreplay("gdb", device, true, NULL);
+ chr = qemu_chr_new_noreplay("gdb", cs->str, true, NULL);
if (!chr) {
return -1;
}
--
2.39.2
- [PATCH v4 07/38] scripts/oss-fuzz: add a suppression for keymap, (continued)
- [PATCH v4 07/38] scripts/oss-fuzz: add a suppression for keymap, Alex Bennée, 2023/06/30
- [PATCH v4 12/38] tests/lcitool: Bump fedora container versions, Alex Bennée, 2023/06/30
- [PATCH v4 11/38] tests/lcitool: update to latest version, Alex Bennée, 2023/06/30
- [PATCH v4 38/38] tests/tcg: Add a test for info proc mappings, Alex Bennée, 2023/06/30
- [PATCH v4 14/38] tests/lcitool: introduce qemu-minimal, Alex Bennée, 2023/06/30
- [PATCH v4 13/38] tests/lcitool: add an explicit gcc-native package, Alex Bennée, 2023/06/30
- [PATCH v4 30/38] gdbstub: clean-up vcont handling to avoid goto, Alex Bennée, 2023/06/30
- [PATCH v4 32/38] linux-user: Add "safe" parameter to do_guest_openat(), Alex Bennée, 2023/06/30
- [PATCH v4 20/38] plugins: fix memory leak while parsing options, Alex Bennée, 2023/06/30
- [PATCH v4 37/38] docs: Document security implications of debugging, Alex Bennée, 2023/06/30
- [PATCH v4 28/38] gdbstub: lightly refactor connection to avoid snprintf,
Alex Bennée <=
- [PATCH v4 26/38] docs/devel: split qom-api reference into new file, Alex Bennée, 2023/06/30
- [PATCH v4 27/38] docs/devel: introduce some key concepts for QOM development, Alex Bennée, 2023/06/30
- [PATCH v4 21/38] plugins: update lockstep to use g_memdup2, Alex Bennée, 2023/06/30
- [PATCH v4 36/38] gdbstub: Add support for info proc mappings, Alex Bennée, 2023/06/30
- [PATCH v4 33/38] linux-user: Emulate /proc/self/smaps, Alex Bennée, 2023/06/30
- [PATCH v4 34/38] gdbstub: Expose gdb_get_process() and gdb_get_first_cpu_in_process(), Alex Bennée, 2023/06/30
- [PATCH v4 31/38] linux-user: Expose do_guest_openat() and do_guest_readlink(), Alex Bennée, 2023/06/30
- [PATCH v4 16/38] tests/avocado: update firmware to enable sbsa-ref/max, Alex Bennée, 2023/06/30
- [PATCH v4 25/38] docs/devel/qom.rst: Correct code style, Alex Bennée, 2023/06/30
- [PATCH v4 29/38] gdbstub: Permit reverse step/break to provide stop response, Alex Bennée, 2023/06/30