mirror of https://gitlab.com/qemu-project/qemu
gdbstub: lightly refactor connection to avoid snprintf
This may be a bit too much to avoid an snprintf and the slightly dodgy assign to a const variable. But hopefully not. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20230630180423.558337-29-alex.bennee@linaro.org>
This commit is contained in:
parent
43398409ce
commit
d2fe226467
|
@ -332,11 +332,9 @@ static void create_processes(GDBState *s)
|
||||||
|
|
||||||
int gdbserver_start(const char *device)
|
int gdbserver_start(const char *device)
|
||||||
{
|
{
|
||||||
trace_gdbstub_op_start(device);
|
|
||||||
|
|
||||||
char gdbstub_device_name[128];
|
|
||||||
Chardev *chr = NULL;
|
Chardev *chr = NULL;
|
||||||
Chardev *mon_chr;
|
Chardev *mon_chr;
|
||||||
|
g_autoptr(GString) cs = g_string_new(device);
|
||||||
|
|
||||||
if (!first_cpu) {
|
if (!first_cpu) {
|
||||||
error_report("gdbstub: meaningless to attach gdb to a "
|
error_report("gdbstub: meaningless to attach gdb to a "
|
||||||
|
@ -350,15 +348,16 @@ int gdbserver_start(const char *device)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!device) {
|
if (cs->len == 0) {
|
||||||
return -1;
|
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 */
|
/* enforce required TCP attributes */
|
||||||
snprintf(gdbstub_device_name, sizeof(gdbstub_device_name),
|
g_string_append_printf(cs, ",wait=off,nodelay=on,server=on");
|
||||||
"%s,wait=off,nodelay=on,server=on", device);
|
|
||||||
device = gdbstub_device_name;
|
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
else if (strcmp(device, "stdio") == 0) {
|
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
|
* FIXME: it's a bit weird to allow using a mux chardev here
|
||||||
* and implicitly setup a monitor. We may want to break this.
|
* 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) {
|
if (!chr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue