From nobody Sun Oct 5 19:42:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579015306; cv=none; d=zohomail.com; s=zohoarc; b=e/ou/bg1v75Wig/9qz1oKINio3QypUg8HOZBJPxs3svYZ+j/qDCNxnPigzQ7VeTVVDnSCiorgN5hlHJPj+d1ps2r0AeYfvzpMJ8Kaw33T+SR+qss6mZLo0gqfxw2/BiIk4KUhuJt84jLaXO4sTRSMBcUvr9HzO7XhzACgendgkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015306; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=T7eCHdftKhCfpik0hS2DmkJ5F81IP0AK6ft4WhoBYvpE++t1jOvuML1MWRlToO7aAwEACt8hKBd1+ZjbmbZGaKbLK5pS4CEFE9Tmjex/EiWJB01Pi931imVJrX6ziezmZ00ralfUMOL+QIAjBYB8ekSZ+tWIqJC5Fs0zb1e/m50= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157901530638544.62820692682908; Tue, 14 Jan 2020 07:21:46 -0800 (PST) Received: from localhost ([::1]:41908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO0m-0002o2-Pk for importer@patchew.org; Tue, 14 Jan 2020 10:21:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37764) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpW-00055w-Un for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpP-0007Jb-Uc for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:06 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51037) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpP-0007IK-HR for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:09:59 -0500 Received: by mail-wm1-x341.google.com with SMTP id a5so14208974wmb.0 for ; Tue, 14 Jan 2020 07:09:59 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m126sm19466675wmf.7.2020.01.14.07.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:55 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D65131FF8F; Tue, 14 Jan 2020 15:09:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=T0Am0i2kISuKw31xEhz6ngesMBPFzVtWAOeT6ZcizpF1fHj4mI+RqEV5oen9PaAeCS KC30xtXPjlszvMuOZl7qPZM3y74siAcwO4+5WlZ2tKQjsceMiZJ+kzmAYd55GHJ0Uvjs RELZrR7mVZD0anQV5erJXWIzkqP12giNwsbbULONlgd08cIsOy8awRhxcNjf0ddWSHaJ TvZHTEQ9TCDvFNLQVqNiU3y9/2BRtUG0fLvAVOxeisbFyS5cctACmcymHKVqgxmYMwbd FsPWzFepeIscBOCy8yyp3gGkde4vcxLYTD2t6mfz3bFyANnyTpfFsjbqR/D9KlcZJP+k ox9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=jomybdEYz+XaYU+GmTVKsb3GJlZwucENqAmqleyPqjL8bjFl4zgu36+RiIq+uEakYZ BgINIS3GmoczErAfJVWt8SGkJgG6yhKMpbS9rBZ3+hKgRum+h5D2c9JIXh+yDCU67VoR 9/LVk4Nm5q/+C+ebvjyBrpYHXPnUKI7eQnS+h8L5jks22qXnymIeAiBKMrkJsQFq56B2 pnGQamakLQClIGCFeMzugnnnpgObJO189Orm/TmRZf21LQJs6+6wjLRDKc/4lLlfyUlE 5ikvNnvj8ZUKL28cI1/+9Y0kx7qMy08KnODQhgmKX6tJEejOx37pHqRgqXUEn9Fs8kva xYSg== X-Gm-Message-State: APjAAAWsvbkHEgm7TXhEM38XFfIOP2rZWEHl8VuV1EmQlHyaNeXcb7xf HOyS6i8WOzrx7ymMCYF98q9Je95gXws= X-Google-Smtp-Source: APXvYqwYMwGIDzmBA+FZxq/941xVpmX0esWPsbyqgp+38YoiWUD4c+rk0BtTnGYN9D9UKRIcqZ/gCw== X-Received: by 2002:a1c:f30e:: with SMTP id q14mr27635282wmq.65.1579014597695; Tue, 14 Jan 2020 07:09:57 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 02/22] gdbstub: stop passing GDBState * around and use global Date: Tue, 14 Jan 2020 15:09:33 +0000 Message-Id: <20200114150953.27659-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v3 - remove final *s paramters from function calls v4 - a few fixups for coding style --- gdbstub.c | 561 +++++++++++++++++++++++++++--------------------------- 1 file changed, 278 insertions(+), 283 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 3bc90cbde5..99293bb405 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -397,21 +397,21 @@ bool gdb_has_xml; /* XXX: This is not thread safe. Do we care? */ static int gdbserver_fd =3D -1; =20 -static int get_char(GDBState *s) +static int get_char(void) { uint8_t ch; int ret; =20 for(;;) { - ret =3D qemu_recv(s->fd, &ch, 1, 0); + ret =3D qemu_recv(gdbserver_state.fd, &ch, 1, 0); if (ret < 0) { if (errno =3D=3D ECONNRESET) - s->fd =3D -1; + gdbserver_state.fd =3D -1; if (errno !=3D EINTR) return -1; } else if (ret =3D=3D 0) { - close(s->fd); - s->fd =3D -1; + close(gdbserver_state.fd); + gdbserver_state.fd =3D -1; return -1; } else { break; @@ -449,11 +449,11 @@ int use_gdb_syscalls(void) } =20 /* Resume execution. */ -static inline void gdb_continue(GDBState *s) +static inline void gdb_continue(void) { =20 #ifdef CONFIG_USER_ONLY - s->running_state =3D 1; + gdbserver_state.running_state =3D 1; trace_gdbstub_op_continue(); #else if (!runstate_needs_reset()) { @@ -467,7 +467,7 @@ static inline void gdb_continue(GDBState *s) * Resume execution, per CPU actions. For user-mode emulation it's * equivalent to gdb_continue. */ -static int gdb_continue_partial(GDBState *s, char *newstates) +static int gdb_continue_partial(char *newstates) { CPUState *cpu; int res =3D 0; @@ -482,7 +482,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) cpu_single_step(cpu, sstep_flags); } } - s->running_state =3D 1; + gdbserver_state.running_state =3D 1; #else int flag =3D 0; =20 @@ -520,13 +520,13 @@ static int gdb_continue_partial(GDBState *s, char *ne= wstates) return res; } =20 -static void put_buffer(GDBState *s, const uint8_t *buf, int len) +static void put_buffer(const uint8_t *buf, int len) { #ifdef CONFIG_USER_ONLY int ret; =20 while (len > 0) { - ret =3D send(s->fd, buf, len, 0); + ret =3D send(gdbserver_state.fd, buf, len, 0); if (ret < 0) { if (errno !=3D EINTR) return; @@ -538,7 +538,7 @@ static void put_buffer(GDBState *s, const uint8_t *buf,= int len) #else /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, buf, len); + qemu_chr_fe_write_all(&gdbserver_state.chr, buf, len); #endif } =20 @@ -620,17 +620,18 @@ static void hexdump(const char *buf, int len, } =20 /* return -1 if error, 0 if OK */ -static int put_packet_binary(GDBState *s, const char *buf, int len, bool d= ump) +static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; uint8_t *p; + uint8_t *ps =3D &gdbserver_state.last_packet[0]; =20 if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPL= Y)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } =20 for(;;) { - p =3D s->last_packet; + p =3D ps; *(p++) =3D '$'; memcpy(p, buf, len); p +=3D len; @@ -642,11 +643,11 @@ static int put_packet_binary(GDBState *s, const char = *buf, int len, bool dump) *(p++) =3D tohex((csum >> 4) & 0xf); *(p++) =3D tohex((csum) & 0xf); =20 - s->last_packet_len =3D p - s->last_packet; - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + gdbserver_state.last_packet_len =3D p - ps; + put_buffer(ps, gdbserver_state.last_packet_len); =20 #ifdef CONFIG_USER_ONLY - i =3D get_char(s); + i =3D get_char(); if (i < 0) return -1; if (i =3D=3D '+') @@ -659,11 +660,11 @@ static int put_packet_binary(GDBState *s, const char = *buf, int len, bool dump) } =20 /* return -1 if error, 0 if OK */ -static int put_packet(GDBState *s, const char *buf) +static int put_packet(const char *buf) { trace_gdbstub_io_reply(buf); =20 - return put_packet_binary(s, buf, strlen(buf), false); + return put_packet_binary(buf, strlen(buf), false); } =20 /* Encode data using the encoding for 'x' packets. */ @@ -687,37 +688,38 @@ static int memtox(char *buf, const char *mem, int len) return p - buf; } =20 -static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu) +static uint32_t gdb_get_cpu_pid(CPUState *cpu) { /* TODO: In user mode, we should use the task state PID */ if (cpu->cluster_index =3D=3D UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ - return s->processes[s->process_num - 1].pid; + int index =3D gdbserver_state.process_num - 1; + return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; } =20 -static GDBProcess *gdb_get_process(const GDBState *s, uint32_t pid) +static GDBProcess *gdb_get_process(uint32_t pid) { int i; =20 if (!pid) { /* 0 means any process, we take the first one */ - return &s->processes[0]; + return &gdbserver_state.processes[0]; } =20 - for (i =3D 0; i < s->process_num; i++) { - if (s->processes[i].pid =3D=3D pid) { - return &s->processes[i]; + for (i =3D 0; i < gdbserver_state.process_num; i++) { + if (gdbserver_state.processes[i].pid =3D=3D pid) { + return &gdbserver_state.processes[i]; } } =20 return NULL; } =20 -static GDBProcess *gdb_get_cpu_process(const GDBState *s, CPUState *cpu) +static GDBProcess *gdb_get_cpu_process(CPUState *cpu) { - return gdb_get_process(s, gdb_get_cpu_pid(s, cpu)); + return gdb_get_process(gdb_get_cpu_pid(cpu)); } =20 static CPUState *find_cpu(uint32_t thread_id) @@ -733,13 +735,12 @@ static CPUState *find_cpu(uint32_t thread_id) return NULL; } =20 -static CPUState *get_first_cpu_in_process(const GDBState *s, - GDBProcess *process) +static CPUState *get_first_cpu_in_process(GDBProcess *process) { CPUState *cpu; =20 CPU_FOREACH(cpu) { - if (gdb_get_cpu_pid(s, cpu) =3D=3D process->pid) { + if (gdb_get_cpu_pid(cpu) =3D=3D process->pid) { return cpu; } } @@ -747,13 +748,13 @@ static CPUState *get_first_cpu_in_process(const GDBSt= ate *s, return NULL; } =20 -static CPUState *gdb_next_cpu_in_process(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_cpu_in_process(CPUState *cpu) { - uint32_t pid =3D gdb_get_cpu_pid(s, cpu); + uint32_t pid =3D gdb_get_cpu_pid(cpu); cpu =3D CPU_NEXT(cpu); =20 while (cpu) { - if (gdb_get_cpu_pid(s, cpu) =3D=3D pid) { + if (gdb_get_cpu_pid(cpu) =3D=3D pid) { break; } =20 @@ -764,12 +765,12 @@ static CPUState *gdb_next_cpu_in_process(const GDBSta= te *s, CPUState *cpu) } =20 /* Return the cpu following @cpu, while ignoring unattached processes. */ -static CPUState *gdb_next_attached_cpu(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_attached_cpu(CPUState *cpu) { cpu =3D CPU_NEXT(cpu); =20 while (cpu) { - if (gdb_get_cpu_process(s, cpu)->attached) { + if (gdb_get_cpu_process(cpu)->attached) { break; } =20 @@ -780,29 +781,29 @@ static CPUState *gdb_next_attached_cpu(const GDBState= *s, CPUState *cpu) } =20 /* Return the first attached cpu */ -static CPUState *gdb_first_attached_cpu(const GDBState *s) +static CPUState *gdb_first_attached_cpu(void) { CPUState *cpu =3D first_cpu; - GDBProcess *process =3D gdb_get_cpu_process(s, cpu); + GDBProcess *process =3D gdb_get_cpu_process(cpu); =20 if (!process->attached) { - return gdb_next_attached_cpu(s, cpu); + return gdb_next_attached_cpu(cpu); } =20 return cpu; } =20 -static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) +static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) { GDBProcess *process; CPUState *cpu; =20 if (!pid && !tid) { /* 0 means any process/thread, we take the first attached one */ - return gdb_first_attached_cpu(s); + return gdb_first_attached_cpu(); } else if (pid && !tid) { /* any thread in a specific process */ - process =3D gdb_get_process(s, pid); + process =3D gdb_get_process(pid); =20 if (process =3D=3D NULL) { return NULL; @@ -812,7 +813,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_= t pid, uint32_t tid) return NULL; } =20 - return get_first_cpu_in_process(s, process); + return get_first_cpu_in_process(process); } else { /* a specific thread */ cpu =3D find_cpu(tid); @@ -821,7 +822,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_= t pid, uint32_t tid) return NULL; } =20 - process =3D gdb_get_cpu_process(s, cpu); + process =3D gdb_get_cpu_process(cpu); =20 if (pid && process->pid !=3D pid) { return NULL; @@ -835,13 +836,13 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint3= 2_t pid, uint32_t tid) } } =20 -static const char *get_feature_xml(const GDBState *s, const char *p, - const char **newp, GDBProcess *process) +static const char *get_feature_xml(const char *p, const char **newp, + GDBProcess *process) { size_t len; int i; const char *name; - CPUState *cpu =3D get_first_cpu_in_process(s, process); + CPUState *cpu =3D get_first_cpu_in_process(process); CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 len =3D 0; @@ -1076,13 +1077,13 @@ static inline void gdb_cpu_breakpoint_remove_all(CP= UState *cpu) #endif } =20 -static void gdb_process_breakpoint_remove_all(const GDBState *s, GDBProces= s *p) +static void gdb_process_breakpoint_remove_all(GDBProcess *p) { - CPUState *cpu =3D get_first_cpu_in_process(s, p); + CPUState *cpu =3D get_first_cpu_in_process(p); =20 while (cpu) { gdb_cpu_breakpoint_remove_all(cpu); - cpu =3D gdb_next_cpu_in_process(s, cpu); + cpu =3D gdb_next_cpu_in_process(cpu); } } =20 @@ -1100,20 +1101,19 @@ static void gdb_breakpoint_remove_all(void) } } =20 -static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) +static void gdb_set_cpu_pc(target_ulong pc) { - CPUState *cpu =3D s->c_cpu; + CPUState *cpu =3D gdbserver_state.c_cpu; =20 cpu_synchronize_state(cpu); cpu_set_pc(cpu, pc); } =20 -static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, - char *buf, size_t buf_size) +static char *gdb_fmt_thread_id(CPUState *cpu, char *buf, size_t buf_size) { - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { snprintf(buf, buf_size, "p%02x.%02x", - gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu)); + gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); } else { snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); } @@ -1180,7 +1180,7 @@ static GDBThreadIdKind read_thread_id(const char *buf= , const char **end_buf, * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if the= re is * a format error, 0 on success. */ -static int gdb_handle_vcont(GDBState *s, const char *p) +static int gdb_handle_vcont(const char *p) { int res, signal =3D 0; char cur_action; @@ -1255,36 +1255,36 @@ static int gdb_handle_vcont(GDBState *s, const char= *p) goto out; =20 case GDB_ALL_PROCESSES: - cpu =3D gdb_first_attached_cpu(s); + cpu =3D gdb_first_attached_cpu(); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; } =20 - cpu =3D gdb_next_attached_cpu(s, cpu); + cpu =3D gdb_next_attached_cpu(cpu); } break; =20 case GDB_ALL_THREADS: - process =3D gdb_get_process(s, pid); + process =3D gdb_get_process(pid); =20 if (!process->attached) { res =3D -EINVAL; goto out; } =20 - cpu =3D get_first_cpu_in_process(s, process); + cpu =3D get_first_cpu_in_process(process); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; } =20 - cpu =3D gdb_next_cpu_in_process(s, cpu); + cpu =3D gdb_next_cpu_in_process(cpu); } break; =20 case GDB_ONE_THREAD: - cpu =3D gdb_get_cpu(s, pid, tid); + cpu =3D gdb_get_cpu(pid, tid); =20 /* invalid CPU/thread specified */ if (!cpu) { @@ -1299,8 +1299,8 @@ static int gdb_handle_vcont(GDBState *s, const char *= p) break; } } - s->signal =3D signal; - gdb_continue_partial(s, newstates); + gdbserver_state.signal =3D signal; + gdb_continue_partial(newstates); =20 out: g_free(newstates); @@ -1409,7 +1409,6 @@ static int cmd_parse_params(const char *data, const c= har *schema, } =20 typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH]; @@ -1453,7 +1452,7 @@ static inline int startswith(const char *string, cons= t char *pattern) return !strncmp(string, pattern, strlen(pattern)); } =20 -static int process_string_cmd(GDBState *s, void *user_ctx, const char *dat= a, +static int process_string_cmd(void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { int i, schema_len, max_num_params =3D 0; @@ -1490,7 +1489,6 @@ static int process_string_cmd(GDBState *s, void *user= _ctx, const char *data, return -1; } =20 - gdb_ctx.s =3D s; cmd->handler(&gdb_ctx, user_ctx); return 0; } @@ -1498,8 +1496,7 @@ static int process_string_cmd(GDBState *s, void *user= _ctx, const char *data, return -1; } =20 -static void run_cmd_parser(GDBState *s, const char *data, - const GdbCmdParseEntry *cmd) +static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) { if (!data) { return; @@ -1507,44 +1504,43 @@ static void run_cmd_parser(GDBState *s, const char = *data, =20 /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ - if (process_string_cmd(s, NULL, data, cmd, 1)) { - put_packet(s, ""); + if (process_string_cmd(NULL, data, cmd, 1)) { + put_packet(""); } } =20 static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) { GDBProcess *process; - GDBState *s =3D gdb_ctx->s; uint32_t pid =3D 1; =20 - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { if (!gdb_ctx->num_params) { - put_packet(s, "E22"); + put_packet("E22"); return; } =20 pid =3D gdb_ctx->params[0].val_ul; } =20 - process =3D gdb_get_process(s, pid); - gdb_process_breakpoint_remove_all(s, process); + process =3D gdb_get_process(pid); + gdb_process_breakpoint_remove_all(process); process->attached =3D false; =20 - if (pid =3D=3D gdb_get_cpu_pid(s, s->c_cpu)) { - s->c_cpu =3D gdb_first_attached_cpu(s); + if (pid =3D=3D gdb_get_cpu_pid(gdbserver_state.c_cpu)) { + gdbserver_state.c_cpu =3D gdb_first_attached_cpu(); } =20 - if (pid =3D=3D gdb_get_cpu_pid(s, s->g_cpu)) { - s->g_cpu =3D gdb_first_attached_cpu(s); + if (pid =3D=3D gdb_get_cpu_pid(gdbserver_state.g_cpu)) { + gdbserver_state.g_cpu =3D gdb_first_attached_cpu(); } =20 - if (!s->c_cpu) { + if (!gdbserver_state.c_cpu) { /* No more process attached */ gdb_syscall_mode =3D GDB_SYS_DISABLED; - gdb_continue(s); + gdb_continue(); } - put_packet(s, "OK"); + put_packet("OK"); } =20 static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1552,33 +1548,33 @@ static void handle_thread_alive(GdbCmdContext *gdb_= ctx, void *user_ctx) CPUState *cpu; =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_continue(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, gdb_ctx->params[0].val_ull); + gdb_set_cpu_pc(gdb_ctx->params[0].val_ull); } =20 - gdb_ctx->s->signal =3D 0; - gdb_continue(gdb_ctx->s); + gdbserver_state.signal =3D 0; + gdb_continue(); } =20 static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1593,11 +1589,11 @@ static void handle_cont_with_sig(GdbCmdContext *gdb= _ctx, void *user_ctx) signal =3D gdb_ctx->params[0].val_ul; } =20 - gdb_ctx->s->signal =3D gdb_signal_to_target(signal); - if (gdb_ctx->s->signal =3D=3D -1) { - gdb_ctx->s->signal =3D 0; + gdbserver_state.signal =3D gdb_signal_to_target(signal); + if (gdbserver_state.signal =3D=3D -1) { + gdbserver_state.signal =3D 0; } - gdb_continue(gdb_ctx->s); + gdb_continue(); } =20 static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1605,24 +1601,24 @@ static void handle_set_thread(GdbCmdContext *gdb_ct= x, void *user_ctx) CPUState *cpu; =20 if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[1].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[1].thread_id.kind !=3D GDB_ONE_THREAD) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[1].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[1].thread_id.pid, gdb_ctx->params[1].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1632,15 +1628,15 @@ static void handle_set_thread(GdbCmdContext *gdb_ct= x, void *user_ctx) */ switch (gdb_ctx->params[0].opcode) { case 'c': - gdb_ctx->s->c_cpu =3D cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.c_cpu =3D cpu; + put_packet("OK"); break; case 'g': - gdb_ctx->s->g_cpu =3D cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.g_cpu =3D cpu; + put_packet("OK"); break; default: - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); break; } } @@ -1650,7 +1646,7 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, = void *user_ctx) int res; =20 if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1658,14 +1654,14 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >=3D 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res =3D=3D -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } =20 static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1673,7 +1669,7 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, = void *user_ctx) int res; =20 if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1681,14 +1677,14 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >=3D 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res =3D=3D -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } =20 /* @@ -1707,20 +1703,20 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) int reg_size; =20 if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 reg_size =3D strlen(gdb_ctx->params[1].data) / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size); - gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + gdb_write_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1728,73 +1724,73 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) int reg_size; =20 if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 - reg_size =3D gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + reg_size =3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); if (!reg_size) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 /* hextomem() reads 2*len bytes */ if (gdb_ctx->params[1].val_ull > strlen(gdb_ctx->params[2].data) / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 hextomem(gdb_ctx->mem_buf, gdb_ctx->params[2].data, gdb_ctx->params[1].val_ull); - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_u= ll, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, true)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 /* memtohex() doubles the required space */ if (gdb_ctx->params[1].val_ull > MAX_PACKET_LENGTH / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_u= ll, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, false)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ul= l); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1807,37 +1803,37 @@ static void handle_write_all_regs(GdbCmdContext *gd= b_ctx, void *user_ctx) return; } =20 - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); registers =3D gdb_ctx->mem_buf; len =3D strlen(gdb_ctx->params[0].data) / 2; hextomem(registers, gdb_ctx->params[0].data, len); - for (addr =3D 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs && len > 0; + for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len >= 0; addr++) { - reg_size =3D gdb_write_register(gdb_ctx->s->g_cpu, registers, addr= ); + reg_size =3D gdb_write_register(gdbserver_state.g_cpu, registers, = addr); len -=3D reg_size; registers +=3D reg_size; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) { target_ulong addr, len; =20 - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); len =3D 0; - for (addr =3D 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs; addr++) { - len +=3D gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf + l= en, + for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++)= { + len +=3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf= + len, addr); } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { - if (gdb_ctx->num_params >=3D 1 && gdb_ctx->s->current_syscall_cb) { + if (gdb_ctx->num_params >=3D 1 && gdbserver_state.current_syscall_cb) { target_ulong ret, err; =20 ret =3D (target_ulong)gdb_ctx->params[0].val_ull; @@ -1846,31 +1842,31 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, = void *user_ctx) } else { err =3D 0; } - gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); - gdb_ctx->s->current_syscall_cb =3D NULL; + gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err= ); + gdbserver_state.current_syscall_cb =3D NULL; } =20 if (gdb_ctx->num_params >=3D 3 && gdb_ctx->params[2].opcode =3D=3D (ui= nt8_t)'C') { - put_packet(gdb_ctx->s, "T02"); + put_packet("T02"); return; } =20 - gdb_continue(gdb_ctx->s); + gdb_continue(); } =20 static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, (target_ulong)gdb_ctx->params[0].val_ul= l); + gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull); } =20 - cpu_single_step(gdb_ctx->s->c_cpu, sstep_flags); - gdb_continue(gdb_ctx->s); + cpu_single_step(gdbserver_state.c_cpu, sstep_flags); + gdb_continue(); } =20 static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, "vCont;c;C;s;S"); + put_packet("vCont;c;C;s;S"); } =20 static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1881,11 +1877,11 @@ static void handle_v_cont(GdbCmdContext *gdb_ctx, v= oid *user_ctx) return; } =20 - res =3D gdb_handle_vcont(gdb_ctx->s, gdb_ctx->params[0].data); + res =3D gdb_handle_vcont(gdb_ctx->params[0].data); if ((res =3D=3D -EINVAL) || (res =3D=3D -ERANGE)) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } else if (res) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -1900,31 +1896,31 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx,= void *user_ctx) goto cleanup; } =20 - process =3D gdb_get_process(gdb_ctx->s, gdb_ctx->params[0].val_ul); + process =3D gdb_get_process(gdb_ctx->params[0].val_ul); if (!process) { goto cleanup; } =20 - cpu =3D get_first_cpu_in_process(gdb_ctx->s, process); + cpu =3D get_first_cpu_in_process(process); if (!cpu) { goto cleanup; } =20 process->attached =3D true; - gdb_ctx->s->g_cpu =3D cpu; - gdb_ctx->s->c_cpu =3D cpu; + gdbserver_state.g_cpu =3D cpu; + gdbserver_state.c_cpu =3D cpu; =20 - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); cleanup: - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) { /* Kill the target */ - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); error_report("QEMU: Terminated via GDBstub"); exit(0); } @@ -1961,10 +1957,10 @@ static void handle_v_commands(GdbCmdContext *gdb_ct= x, void *user_ctx) return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -1973,7 +1969,7 @@ static void handle_query_qemu_sstepbits(GdbCmdContext= *gdb_ctx, void *user_ctx) snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "ENABLE=3D%x,NOIRQ=3D%x,NOTIMER=3D%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1983,13 +1979,13 @@ static void handle_set_qemu_sstep(GdbCmdContext *gd= b_ctx, void *user_ctx) } =20 sstep_flags =3D gdb_ctx->params[0].val_ul; - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%x", sstep_fla= gs); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2003,33 +1999,32 @@ static void handle_query_curr_tid(GdbCmdContext *gd= b_ctx, void *user_ctx) * the first thread of the current process (gdb returns the * first thread). */ - process =3D gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cpu =3D get_first_cpu_in_process(gdb_ctx->s, process); - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); + cpu =3D get_first_cpu_in_process(process); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "QC%s", thread_id= ); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { char thread_id[16]; =20 - if (!gdb_ctx->s->query_cpu) { - put_packet(gdb_ctx->s, "l"); + if (!gdbserver_state.query_cpu) { + put_packet("l"); return; } =20 - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->query_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.query_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "m%s", thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); - gdb_ctx->s->query_cpu =3D - gdb_next_attached_cpu(gdb_ctx->s, gdb_ctx->s->query_cpu); + put_packet(gdb_ctx->str_buf); + gdbserver_state.query_cpu =3D gdb_next_attached_cpu(gdbserver_state.qu= ery_cpu); } =20 static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_= ctx) { - gdb_ctx->s->query_cpu =3D gdb_first_attached_cpu(gdb_ctx->s); + gdbserver_state.query_cpu =3D gdb_first_attached_cpu(); handle_query_threads(gdb_ctx, user_ctx); } =20 @@ -2040,11 +2035,11 @@ static void handle_query_thread_extra(GdbCmdContext= *gdb_ctx, void *user_ctx) =20 if (!gdb_ctx->num_params || gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { return; @@ -2052,7 +2047,7 @@ static void handle_query_thread_extra(GdbCmdContext *= gdb_ctx, void *user_ctx) =20 cpu_synchronize_state(cpu); =20 - if (gdb_ctx->s->multiprocess && (gdb_ctx->s->process_num > 1)) { + if (gdbserver_state.multiprocess && (gdbserver_state.process_num > 1))= { /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc =3D object_get_class(OBJECT(cpu)); const char *cpu_model =3D object_class_get_name(oc); @@ -2069,7 +2064,7 @@ static void handle_query_thread_extra(GdbCmdContext *= gdb_ctx, void *user_ctx) } trace_gdbstub_op_extra_info((char *)gdb_ctx->mem_buf); memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 #ifdef CONFIG_USER_ONLY @@ -2077,14 +2072,14 @@ static void handle_query_offsets(GdbCmdContext *gdb= _ctx, void *user_ctx) { TaskState *ts; =20 - ts =3D gdb_ctx->s->c_cpu->opaque; + ts =3D gdbserver_state.c_cpu->opaque; snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "Text=3D" TARGET_ABI_FMT_lx ";Data=3D" TARGET_ABI_FMT_lx ";Bss=3D" TARGET_ABI_FMT_lx, ts->info->code_offset, ts->info->data_offset, ts->info->data_offset); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2092,21 +2087,21 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ct= x, void *user_ctx) int len; =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 len =3D strlen(gdb_ctx->params[0].data); if (len % 2) { - put_packet(gdb_ctx->s, "E01"); + put_packet("E01"); return; } =20 len =3D len / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[0].data, len); gdb_ctx->mem_buf[len++] =3D 0; - qemu_chr_be_write(gdb_ctx->s->mon_chr, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, "OK"); + qemu_chr_be_write(gdbserver_state.mon_chr, gdb_ctx->mem_buf, len); + put_packet("OK"); =20 } #endif @@ -2125,11 +2120,11 @@ static void handle_query_supported(GdbCmdContext *g= db_ctx, void *user_ctx) =20 if (gdb_ctx->num_params && strstr(gdb_ctx->params[0].data, "multiprocess+")) { - gdb_ctx->s->multiprocess =3D true; + gdbserver_state.multiprocess =3D true; } =20 pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";multiprocess+"); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_= ctx) @@ -2141,22 +2136,22 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) const char *p; =20 if (gdb_ctx->num_params < 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - process =3D gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cc =3D CPU_GET_CLASS(gdb_ctx->s->g_cpu); + process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); + cc =3D CPU_GET_CLASS(gdbserver_state.g_cpu); if (!cc->gdb_core_xml_file) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 gdb_has_xml =3D true; p =3D gdb_ctx->params[0].data; - xml =3D get_feature_xml(gdb_ctx->s, p, &p, process); + xml =3D get_feature_xml(p, &p, process); if (!xml) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } =20 @@ -2164,7 +2159,7 @@ static void handle_query_xfer_features(GdbCmdContext = *gdb_ctx, void *user_ctx) len =3D gdb_ctx->params[2].val_ul; total_len =3D strlen(xml); if (addr > total_len) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } =20 @@ -2180,12 +2175,12 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) len =3D memtox(gdb_ctx->str_buf + 1, xml + addr, total_len - addr); } =20 - put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true); + put_packet_binary(gdb_ctx->str_buf, len + 1, true); } =20 static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, GDB_ATTACHED); + put_packet(GDB_ATTACHED); } =20 static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user= _ctx) @@ -2194,7 +2189,7 @@ static void handle_query_qemu_supported(GdbCmdContext= *gdb_ctx, void *user_ctx) #ifndef CONFIG_USER_ONLY pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";PhyMemMode"); #endif - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 #ifndef CONFIG_USER_ONLY @@ -2202,13 +2197,13 @@ static void handle_query_qemu_phy_mem_mode(GdbCmdCo= ntext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d", phy_memory_= mode); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *use= r_ctx) { if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -2217,7 +2212,7 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContex= t *gdb_ctx, void *user_ctx) } else { phy_memory_mode =3D 1; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } #endif =20 @@ -2333,16 +2328,16 @@ static void handle_gen_query(GdbCmdContext *gdb_ctx= , void *user_ctx) return; } =20 - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -2352,16 +2347,16 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, = void *user_ctx) return; } =20 - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -2369,11 +2364,11 @@ static void handle_target_halt(GdbCmdContext *gdb_c= tx, void *user_ctx) { char thread_id[16]; =20 - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->c_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.c_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -2382,7 +2377,7 @@ static void handle_target_halt(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_breakpoint_remove_all(); } =20 -static int gdb_handle_packet(GDBState *s, const char *line_buf) +static int gdb_handle_packet(const char *line_buf) { const GdbCmdParseEntry *cmd_parser =3D NULL; =20 @@ -2390,7 +2385,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) =20 switch (line_buf[0]) { case '!': - put_packet(s, "OK"); + put_packet("OK"); break; case '?': { @@ -2605,12 +2600,12 @@ static int gdb_handle_packet(GDBState *s, const cha= r *line_buf) break; default: /* put empty packet */ - put_packet(s, ""); + put_packet(""); break; } =20 if (cmd_parser) { - run_cmd_parser(s, line_buf, cmd_parser); + run_cmd_parser(line_buf, cmd_parser); } =20 return RS_IDLE; @@ -2618,7 +2613,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) =20 void gdb_set_stop_cpu(CPUState *cpu) { - GDBProcess *p =3D gdb_get_cpu_process(&gdbserver_state, cpu); + GDBProcess *p =3D gdb_get_cpu_process(cpu); =20 if (!p->attached) { /* @@ -2635,19 +2630,18 @@ void gdb_set_stop_cpu(CPUState *cpu) #ifndef CONFIG_USER_ONLY static void gdb_vm_state_change(void *opaque, int running, RunState state) { - GDBState *s =3D &gdbserver_state; - CPUState *cpu =3D s->c_cpu; + CPUState *cpu =3D gdbserver_state.c_cpu; char buf[256]; char thread_id[16]; const char *type; int ret; =20 - if (running || s->state =3D=3D RS_INACTIVE) { + if (running || gdbserver_state.state =3D=3D RS_INACTIVE) { return; } /* Is there a GDB syscall waiting to be sent? */ - if (s->current_syscall_cb) { - put_packet(s, s->syscall_buf); + if (gdbserver_state.current_syscall_cb) { + put_packet(gdbserver_state.syscall_buf); return; } =20 @@ -2656,7 +2650,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, RunState state) return; } =20 - gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); =20 switch (state) { case RUN_STATE_DEBUG: @@ -2721,7 +2715,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, RunState state) snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); =20 send_packet: - put_packet(s, buf); + put_packet(buf); =20 /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -2740,8 +2734,9 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, cons= t char *fmt, va_list va) target_ulong addr; uint64_t i64; =20 - if (!gdbserver_state.init) + if (!gdbserver_state.init) { return; + } =20 gdbserver_state.current_syscall_cb =3D cb; #ifndef CONFIG_USER_ONLY @@ -2781,7 +2776,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, cons= t char *fmt, va_list va) } *p =3D 0; #ifdef CONFIG_USER_ONLY - put_packet(&gdbserver_state, gdbserver_state.syscall_buf); + put_packet(gdbserver_state.syscall_buf); /* Return control to gdb for it to process the syscall request. * Since the protocol requires that gdb hands control back to us * using a "here are the results" F packet, we don't need to check @@ -2809,17 +2804,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, con= st char *fmt, ...) va_end(va); } =20 -static void gdb_read_byte(GDBState *s, uint8_t ch) +static void gdb_read_byte(uint8_t ch) { uint8_t reply; =20 #ifndef CONFIG_USER_ONLY - if (s->last_packet_len) { + if (gdbserver_state.last_packet_len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch =3D=3D '-') { trace_gdbstub_err_got_nack(); - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_s= tate.last_packet_len); } else if (ch =3D=3D '+') { trace_gdbstub_io_got_ack(); } else { @@ -2827,7 +2822,7 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } =20 if (ch =3D=3D '+' || ch =3D=3D '$') - s->last_packet_len =3D 0; + gdbserver_state.last_packet_len =3D 0; if (ch !=3D '$') return; } @@ -2838,13 +2833,13 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } else #endif { - switch(s->state) { + switch(gdbserver_state.state) { case RS_IDLE: if (ch =3D=3D '$') { /* start of command packet */ - s->line_buf_index =3D 0; - s->line_sum =3D 0; - s->state =3D RS_GETLINE; + gdbserver_state.line_buf_index =3D 0; + gdbserver_state.line_sum =3D 0; + gdbserver_state.state =3D RS_GETLINE; } else { trace_gdbstub_err_garbage(ch); } @@ -2852,37 +2847,37 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) case RS_GETLINE: if (ch =3D=3D '}') { /* start escape sequence */ - s->state =3D RS_GETLINE_ESC; - s->line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE_ESC; + gdbserver_state.line_sum +=3D ch; } else if (ch =3D=3D '*') { /* start run length encoding sequence */ - s->state =3D RS_GETLINE_RLE; - s->line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE_RLE; + gdbserver_state.line_sum +=3D ch; } else if (ch =3D=3D '#') { /* end of command, start of checksum*/ - s->state =3D RS_CHKSUM1; - } else if (s->line_buf_index >=3D sizeof(s->line_buf) - 1) { + gdbserver_state.state =3D RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >=3D sizeof(gdbserve= r_state.line_buf) - 1) { trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; + gdbserver_state.state =3D RS_IDLE; } else { /* unescaped command character */ - s->line_buf[s->line_buf_index++] =3D ch; - s->line_sum +=3D ch; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++]= =3D ch; + gdbserver_state.line_sum +=3D ch; } break; case RS_GETLINE_ESC: if (ch =3D=3D '#') { /* unexpected end of command in escape sequence */ - s->state =3D RS_CHKSUM1; - } else if (s->line_buf_index >=3D sizeof(s->line_buf) - 1) { + gdbserver_state.state =3D RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >=3D sizeof(gdbserve= r_state.line_buf) - 1) { /* command buffer overrun */ trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; + gdbserver_state.state =3D RS_IDLE; } else { /* parse escaped character and leave escape state */ - s->line_buf[s->line_buf_index++] =3D ch ^ 0x20; - s->line_sum +=3D ch; - s->state =3D RS_GETLINE; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++]= =3D ch ^ 0x20; + gdbserver_state.line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE; } break; case RS_GETLINE_RLE: @@ -2893,25 +2888,25 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) if (ch < ' ' || ch =3D=3D '#' || ch =3D=3D '$' || ch > 126) { /* invalid RLE count encoding */ trace_gdbstub_err_invalid_repeat(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; } else { /* decode repeat length */ int repeat =3D ch - ' ' + 3; - if (s->line_buf_index + repeat >=3D sizeof(s->line_buf) - = 1) { + if (gdbserver_state.line_buf_index + repeat >=3D sizeof(gd= bserver_state.line_buf) - 1) { /* that many repeats would overrun the command buffer = */ trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; - } else if (s->line_buf_index < 1) { + gdbserver_state.state =3D RS_IDLE; + } else if (gdbserver_state.line_buf_index < 1) { /* got a repeat but we have nothing to repeat */ trace_gdbstub_err_invalid_rle(); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; } else { /* repeat the last character */ - memset(s->line_buf + s->line_buf_index, - s->line_buf[s->line_buf_index - 1], repeat); - s->line_buf_index +=3D repeat; - s->line_sum +=3D ch; - s->state =3D RS_GETLINE; + memset(gdbserver_state.line_buf + gdbserver_state.line= _buf_index, + gdbserver_state.line_buf[gdbserver_state.line_b= uf_index - 1], repeat); + gdbserver_state.line_buf_index +=3D repeat; + gdbserver_state.line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE; } } break; @@ -2919,33 +2914,33 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) /* get high hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; break; } - s->line_buf[s->line_buf_index] =3D '\0'; - s->line_csum =3D fromhex(ch) << 4; - s->state =3D RS_CHKSUM2; + gdbserver_state.line_buf[gdbserver_state.line_buf_index] =3D '= \0'; + gdbserver_state.line_csum =3D fromhex(ch) << 4; + gdbserver_state.state =3D RS_CHKSUM2; break; case RS_CHKSUM2: /* get low hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; break; } - s->line_csum |=3D fromhex(ch); + gdbserver_state.line_csum |=3D fromhex(ch); =20 - if (s->line_csum !=3D (s->line_sum & 0xff)) { - trace_gdbstub_err_checksum_incorrect(s->line_sum, s->line_= csum); + if (gdbserver_state.line_csum !=3D (gdbserver_state.line_sum &= 0xff)) { + trace_gdbstub_err_checksum_incorrect(gdbserver_state.line_= sum, gdbserver_state.line_csum); /* send NAK reply */ reply =3D '-'; - put_buffer(s, &reply, 1); - s->state =3D RS_IDLE; + put_buffer(&reply, 1); + gdbserver_state.state =3D RS_IDLE; } else { /* send ACK reply */ reply =3D '+'; - put_buffer(s, &reply, 1); - s->state =3D gdb_handle_packet(s, s->line_buf); + put_buffer(&reply, 1); + gdbserver_state.state =3D gdb_handle_packet(gdbserver_stat= e.line_buf); } break; default: @@ -2971,7 +2966,7 @@ void gdb_exit(CPUArchState *env, int code) trace_gdbstub_op_exiting((uint8_t)code); =20 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - put_packet(&gdbserver_state, buf); + put_packet(buf); =20 #ifndef CONFIG_USER_ONLY qemu_chr_fe_deinit(&gdbserver_state.chr, true); @@ -2988,7 +2983,7 @@ static void create_default_process(GDBState *s) GDBProcess *process; int max_pid =3D 0; =20 - if (s->process_num) { + if (gdbserver_state.process_num) { max_pid =3D s->processes[s->process_num - 1].pid; } =20 @@ -3020,7 +3015,7 @@ gdb_handlesig(CPUState *cpu, int sig) =20 if (sig !=3D 0) { snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } /* put_packet() might have detected that the peer terminated the connection. */ @@ -3037,7 +3032,7 @@ gdb_handlesig(CPUState *cpu, int sig) int i; =20 for (i =3D 0; i < n; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } else { /* XXX: Connection closed. Should probably wait for another @@ -3064,7 +3059,7 @@ void gdb_signalled(CPUArchState *env, int sig) } =20 snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } =20 static bool gdb_accept(void) @@ -3095,7 +3090,7 @@ static bool gdb_accept(void) init_gdbserver_state(); create_default_process(&gdbserver_state); gdbserver_state.processes[0].attached =3D true; - gdbserver_state.c_cpu =3D gdb_first_attached_cpu(&gdbserver_state); + gdbserver_state.c_cpu =3D gdb_first_attached_cpu(); gdbserver_state.g_cpu =3D gdbserver_state.c_cpu; gdbserver_state.fd =3D fd; gdb_has_xml =3D false; @@ -3172,7 +3167,7 @@ static void gdb_chr_receive(void *opaque, const uint8= _t *buf, int size) int i; =20 for (i =3D 0; i < size; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } =20 @@ -3188,7 +3183,7 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent = event) s->processes[i].attached =3D !i; } =20 - s->c_cpu =3D gdb_first_attached_cpu(s); + s->c_cpu =3D gdb_first_attached_cpu(); s->g_cpu =3D s->c_cpu; =20 vm_stop(RUN_STATE_PAUSED); @@ -3199,7 +3194,7 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent = event) } } =20 -static void gdb_monitor_output(GDBState *s, const char *msg, int len) +static void gdb_monitor_output(const char *msg, int len) { char buf[MAX_PACKET_LENGTH]; =20 @@ -3207,7 +3202,7 @@ static void gdb_monitor_output(GDBState *s, const cha= r *msg, int len) if (len > (MAX_PACKET_LENGTH/2) - 1) len =3D (MAX_PACKET_LENGTH/2) - 1; memtohex(buf + 1, (uint8_t *)msg, len); - put_packet(s, buf); + put_packet(buf); } =20 static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) @@ -3218,10 +3213,10 @@ static int gdb_monitor_write(Chardev *chr, const ui= nt8_t *buf, int len) max_sz =3D (sizeof(gdbserver_state.last_packet) - 2) / 2; for (;;) { if (len <=3D max_sz) { - gdb_monitor_output(&gdbserver_state, p, len); + gdb_monitor_output(p, len); break; } - gdb_monitor_output(&gdbserver_state, p, max_sz); + gdb_monitor_output(p, max_sz); p +=3D max_sz; len -=3D max_sz; } @@ -3305,9 +3300,9 @@ static void create_processes(GDBState *s) { object_child_foreach(object_get_root(), find_cpu_clusters, s); =20 - if (s->processes) { + if (gdbserver_state.processes) { /* Sort by PID */ - qsort(s->processes, s->process_num, sizeof(s->processes[0]), pid_o= rder); + qsort(gdbserver_state.processes, gdbserver_state.process_num, size= of(gdbserver_state.processes[0]), pid_order); } =20 create_default_process(s); @@ -3387,7 +3382,7 @@ int gdbserver_start(const char *device) void gdbserver_cleanup(void) { if (gdbserver_state.init) { - put_packet(&gdbserver_state, "W00"); + put_packet("W00"); } } =20 --=20 2.20.1