From patchwork Tue Feb 21 22:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 655385 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp370518wrb; Tue, 21 Feb 2023 14:54:46 -0800 (PST) X-Google-Smtp-Source: AK7set9d2XmYyD1I4ZlMRm9bixGInls1ZkJMALEno528kmw0IR96hVDPHsPrXVnTGwEUbPMskdIZ X-Received: by 2002:a05:622a:315:b0:3b6:36e1:ed42 with SMTP id q21-20020a05622a031500b003b636e1ed42mr23488723qtw.9.1677020086072; Tue, 21 Feb 2023 14:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677020086; cv=none; d=google.com; s=arc-20160816; b=HE/jLFKZEccB7tz8XG5/OOBf0GX9vtdvDC1HNUbZVd0I+WpabXR1VDqwsIg76Sb8ZF mKkVVuuRQ1btEON0akBNg1uP1AtTwmIxpeQ3+14OfK2YiaWtY1/Ypy09ypwjqrOUTjSp LLQtlNfEUPlkskdJeZfsHF1THbfOJ16mdi+FU9g+/m9wSDLEzdLSMhhplIjIQUAm116l XkJ8VVNFLsDbGYPtXJCI6lOBApGqNv7apcpmmnQg85GFGd6I4nBe473FUTxlhPfEbF6F YU0fcqyC6c9S7m94A9XLrpvFeqMcTIbx2f5XUE1OFwl1WJG6zI6xHaOG9ZjlEEsnFXzh WK+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O9FW5bpnzMlMYArPe7WbUhG+EWllVpppP2M1GYFg3fI=; b=uur3ZWq5XiqRufKk4Vw5SbPUrVp24IYFhs2/vtMwGLXuQRyzcNFQcMnN1Os1GkApfV +Za4Q394R8+mDnK16dj7E9ygMSmBbb7pMzh3Yrp84sLL7mRY23FSNQW84zttOxJzBb8X 7FY/s4c3jYMTNAGOzknfyAjtvHrP+xgrcwMwKLCMd2AQTlWQcSYz8OMafwXzjtZEPu1G +ltNratw6UaMuvgI8Y0QH1KH9ct4l8IvYmQ0x4A7VDm54yUXUBN9/f4dJCERnyeyPLlh Na1fNeSnRk91nGmckiZ5+Oi2M1RpdqE44RnXuoglapnkUUXzEwtMdVc7CpYeM3FcBuwn IeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RvPQSm5P; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b21-20020ac85bd5000000b003b86d51a5e8si273041qtb.647.2023.02.21.14.54.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 14:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RvPQSm5P; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUbV8-0007Pg-9j; Tue, 21 Feb 2023 17:52:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUbV1-0007IV-6C for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:52:39 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUbUu-00044h-Az for qemu-devel@nongnu.org; Tue, 21 Feb 2023 17:52:38 -0500 Received: by mail-wr1-x42a.google.com with SMTP id p8so6158429wrt.12 for ; Tue, 21 Feb 2023 14:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O9FW5bpnzMlMYArPe7WbUhG+EWllVpppP2M1GYFg3fI=; b=RvPQSm5PjO7ZJawqBKNicjvSc+xh8sJWzZF68S/0uRU6WoPFrjDpnPDN4YlM1FTnBG SFIKqMFZpylNRl2quUTL6qp1lFJMB/lNFf7t87LuUq1D7+3N/qpDQ0+MmFEnOcR8EA7O hfAFhbk5Avx3u3o2NwZ0koa/lOoctp6uMEEalcCKkh5M9uNmd1D10bswWAz2y5xV9Gxj CogwAJvM+YPX1Pp7sjFSL7A7PkZmvRYfE5XWEQeBwAjI6NYwS6fbEJ4sgA0sFXKu+OZU d6+JWWv03pZJNf+IBEay6G9iBsY61L1VV9ccPzJ7OFqpWBq+eZC4cJgT77mYPyWXflID kf/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O9FW5bpnzMlMYArPe7WbUhG+EWllVpppP2M1GYFg3fI=; b=7tdqp5BkFEtDmfSBwFdj4EGATfJcEdntrGshJdYrLLpnnEHQ1MjA1swnQmPTCvCdAu Mw+gZDcDFMaTGJzfkf0lMd3zmE6/4Xfkfo/19BDYKn3ytCNfAV40U8txqboZQkAs618t kfoXjEi7zNgRiM9AqnQFFWvQCKYQlRgQ8XjR7zNIEjtoAbVkHU2E5dd75dEiitdQZG7D n5rU6nXkrEF4NEsFB7O6/XbaYyFwW2hSGv7SdlkSDQABrE8rBy/XqPHe7qd4v87WxZ1N SUmy+xJ/aMqhd7+MdQgy9rE4nug29TUn4+HbWf+0jwwPWU8/ghGwwqdi+VMc7oP9SFI3 BVOw== X-Gm-Message-State: AO0yUKWHTXRAkElzPMBHi/KpkzLSnxmCfmQYqU9+jhL4lN9np45JKkpP keK0kZVSe2ONUHA62gESGOFPbw== X-Received: by 2002:a05:6000:103:b0:2c5:4ffa:ba55 with SMTP id o3-20020a056000010300b002c54ffaba55mr5607726wrx.69.1677019950329; Tue, 21 Feb 2023 14:52:30 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id y16-20020a056000109000b002c596e4b3dasm5949966wrw.55.2023.02.21.14.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 14:52:28 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AFA271FFBC; Tue, 21 Feb 2023 22:52:27 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Yoshinori Sato , nicolas.eder@lauterbach.com, Stafford Horne , Daniel Henrique Barboza , Mahmoud Mandour , Taylor Simpson , mads@ynddal.dk, Marek Vasut , Artyom Tarasenko , Alistair Francis , qemu-ppc@nongnu.org, Yanan Wang , Sunil Muthuswamy , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Eduardo Habkost , Bin Meng , Bastian Koppelmann , Palmer Dabbelt , Marcel Apfelbaum , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Rolnik , Aleksandar Rikalo , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno , Xiaojuan Yang , Richard Henderson , Peter Maydell , Alexandre Iooss , Chris Wulff , Jiaxun Yang , David Gibson , "Edgar E. Iglesias" , Greg Kurz , David Hildenbrand , Song Gao , Ilya Leoshkevich , Max Filippov , Mark Cave-Ayland Subject: [PATCH v3 04/24] gdbstub: define separate user/system structures Date: Tue, 21 Feb 2023 22:52:07 +0000 Message-Id: <20230221225227.3735319-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221225227.3735319-1-alex.bennee@linaro.org> References: <20230221225227.3735319-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In preparation for moving user/softmmu specific bits from the main gdbstub file we need to separate the connection details into a user/softmmu state. As these will eventually be defined in their own files we move them out of the common GDBState structure. Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- v3 - split into gdbserver_[user|system]_state now to avoid later hoop jumping --- gdbstub/gdbstub.c | 94 ++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index be88ca0d71..86564adeba 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -342,6 +342,22 @@ enum RSState { RS_CHKSUM1, RS_CHKSUM2, }; + +#ifdef CONFIG_USER_ONLY +typedef struct { + int fd; + char *socket_path; + int running_state; +} GDBUserState; +static GDBUserState gdbserver_user_state; +#else +typedef struct { + CharBackend chr; + Chardev *mon_chr; +} GDBSystemState; +static GDBSystemState gdbserver_system_state; +#endif + typedef struct GDBState { bool init; /* have we been initialised? */ CPUState *c_cpu; /* current CPU for step/continue ops */ @@ -354,14 +370,6 @@ typedef struct GDBState { int line_csum; /* checksum at the end of the packet */ GByteArray *last_packet; int signal; -#ifdef CONFIG_USER_ONLY - int fd; - char *socket_path; - int running_state; -#else - CharBackend chr; - Chardev *mon_chr; -#endif bool multiprocess; GDBProcess *processes; int process_num; @@ -413,15 +421,17 @@ static int get_char(void) int ret; for(;;) { - ret = recv(gdbserver_state.fd, &ch, 1, 0); + ret = recv(gdbserver_user_state.fd, &ch, 1, 0); if (ret < 0) { - if (errno == ECONNRESET) - gdbserver_state.fd = -1; - if (errno != EINTR) + if (errno == ECONNRESET) { + gdbserver_user_state.fd = -1; + } + if (errno != EINTR) { return -1; + } } else if (ret == 0) { - close(gdbserver_state.fd); - gdbserver_state.fd = -1; + close(gdbserver_user_state.fd); + gdbserver_user_state.fd = -1; return -1; } else { break; @@ -480,7 +490,7 @@ static inline void gdb_continue(void) { #ifdef CONFIG_USER_ONLY - gdbserver_state.running_state = 1; + gdbserver_user_state.running_state = 1; trace_gdbstub_op_continue(); #else if (!runstate_needs_reset()) { @@ -509,7 +519,7 @@ static int gdb_continue_partial(char *newstates) cpu_single_step(cpu, gdbserver_state.sstep_flags); } } - gdbserver_state.running_state = 1; + gdbserver_user_state.running_state = 1; #else int flag = 0; @@ -561,7 +571,7 @@ static void put_buffer(const uint8_t *buf, int len) int ret; while (len > 0) { - ret = send(gdbserver_state.fd, buf, len, 0); + ret = send(gdbserver_user_state.fd, buf, len, 0); if (ret < 0) { if (errno != EINTR) return; @@ -573,7 +583,7 @@ static void put_buffer(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(&gdbserver_state.chr, buf, len); + qemu_chr_fe_write_all(&gdbserver_system_state.chr, buf, len); #endif } @@ -2095,7 +2105,8 @@ static void handle_query_rcmd(GArray *params, void *user_ctx) len = len / 2; hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); - qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->data, + qemu_chr_be_write(gdbserver_system_state.mon_chr, + gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len); put_packet("OK"); } @@ -3028,10 +3039,10 @@ void gdb_exit(int code) return; } #ifdef CONFIG_USER_ONLY - if (gdbserver_state.socket_path) { - unlink(gdbserver_state.socket_path); + if (gdbserver_user_state.socket_path) { + unlink(gdbserver_user_state.socket_path); } - if (gdbserver_state.fd < 0) { + if (gdbserver_user_state.fd < 0) { return; } #endif @@ -3042,7 +3053,7 @@ void gdb_exit(int code) put_packet(buf); #ifndef CONFIG_USER_ONLY - qemu_chr_fe_deinit(&gdbserver_state.chr, true); + qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); #endif } @@ -3078,7 +3089,7 @@ gdb_handlesig(CPUState *cpu, int sig) char buf[256]; int n; - if (!gdbserver_state.init || gdbserver_state.fd < 0) { + if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { return sig; } @@ -3096,15 +3107,15 @@ gdb_handlesig(CPUState *cpu, int sig) } /* put_packet() might have detected that the peer terminated the connection. */ - if (gdbserver_state.fd < 0) { + if (gdbserver_user_state.fd < 0) { return sig; } sig = 0; gdbserver_state.state = RS_IDLE; - gdbserver_state.running_state = 0; - while (gdbserver_state.running_state == 0) { - n = read(gdbserver_state.fd, buf, 256); + gdbserver_user_state.running_state = 0; + while (gdbserver_user_state.running_state == 0) { + n = read(gdbserver_user_state.fd, buf, 256); if (n > 0) { int i; @@ -3115,9 +3126,9 @@ gdb_handlesig(CPUState *cpu, int sig) /* XXX: Connection closed. Should probably wait for another connection before continuing. */ if (n == 0) { - close(gdbserver_state.fd); + close(gdbserver_user_state.fd); } - gdbserver_state.fd = -1; + gdbserver_user_state.fd = -1; return sig; } } @@ -3131,7 +3142,7 @@ void gdb_signalled(CPUArchState *env, int sig) { char buf[4]; - if (!gdbserver_state.init || gdbserver_state.fd < 0) { + if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { return; } @@ -3146,7 +3157,7 @@ static void gdb_accept_init(int fd) gdbserver_state.processes[0].attached = true; gdbserver_state.c_cpu = gdb_first_attached_cpu(); gdbserver_state.g_cpu = gdbserver_state.c_cpu; - gdbserver_state.fd = fd; + gdbserver_user_state.fd = fd; gdb_has_xml = false; } @@ -3278,7 +3289,7 @@ int gdbserver_start(const char *port_or_path) if (port > 0 && gdb_accept_tcp(gdb_fd)) { return 0; } else if (gdb_accept_socket(gdb_fd)) { - gdbserver_state.socket_path = g_strdup(port_or_path); + gdbserver_user_state.socket_path = g_strdup(port_or_path); return 0; } @@ -3290,11 +3301,11 @@ int gdbserver_start(const char *port_or_path) /* Disable gdb stub for child processes. */ void gdbserver_fork(CPUState *cpu) { - if (!gdbserver_state.init || gdbserver_state.fd < 0) { + if (!gdbserver_state.init || gdbserver_user_state.fd < 0) { return; } - close(gdbserver_state.fd); - gdbserver_state.fd = -1; + close(gdbserver_user_state.fd); + gdbserver_user_state.fd = -1; cpu_breakpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB); } @@ -3488,21 +3499,22 @@ int gdbserver_start(const char *device) NULL, NULL, &error_abort); monitor_init_hmp(mon_chr, false, &error_abort); } else { - qemu_chr_fe_deinit(&gdbserver_state.chr, true); - mon_chr = gdbserver_state.mon_chr; + qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); + mon_chr = gdbserver_system_state.mon_chr; reset_gdbserver_state(); } create_processes(&gdbserver_state); if (chr) { - qemu_chr_fe_init(&gdbserver_state.chr, chr, &error_abort); - qemu_chr_fe_set_handlers(&gdbserver_state.chr, gdb_chr_can_receive, + qemu_chr_fe_init(&gdbserver_system_state.chr, chr, &error_abort); + qemu_chr_fe_set_handlers(&gdbserver_system_state.chr, + gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event, NULL, &gdbserver_state, NULL, true); } gdbserver_state.state = chr ? RS_IDLE : RS_INACTIVE; - gdbserver_state.mon_chr = mon_chr; + gdbserver_system_state.mon_chr = mon_chr; gdbserver_state.current_syscall_cb = NULL; return 0;