From patchwork Thu Jan 5 16:43:04 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: 639267 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp320447pvb; Thu, 5 Jan 2023 08:43:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDtqDUGvGmelhL1496TMMyRAW0W4OEhtFyFdUJRY7/0G1dT08DUpfsafQj59f164VlQ+Yd X-Received: by 2002:a05:622a:4d47:b0:3a8:18fb:d2b4 with SMTP id fe7-20020a05622a4d4700b003a818fbd2b4mr80610268qtb.22.1672937030452; Thu, 05 Jan 2023 08:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672937030; cv=none; d=google.com; s=arc-20160816; b=E2A+rxuiu0RVwLzDpMqNcr9osUWB32MG6Mo9ihhY70ZBPjAVL5P++1H8QpLzBNEjoE gWnIWstOtj+zF70GXLDOcMjuU8QYyS+CAYXdXj3AFKhHqKsSTXvsrRRuF+tQimYoxvGG Png6/qMHtT6TSNf/lT6/hLp2FwNe6lHsS6ve5I/Zv/R3bX1XMyVNxko98He5G73ogHHc 59PoE+0kjIRQo/HJLwDFf/k/StaJ56Xc8iARAh4TSYoP9FtbcDO7vx9jUdMDapNVxDZT fsro3LKbD9Hw2XIJrR71VSyck4dco9HnKy8Su0yYKHFhMVwR7wzihRuF5lYNd72a+ZkV aDsg== 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=9rGtAM1a6TiNs1+FB6TlBWh3o6cb+GfZm+A8LFRsD5w=; b=syZRvJ9UTtVIzmxtB0CGOaHfOJ+u9jYUkldpskjn6tK/0pIidkH7p/iyD8EM4PwaI3 ft4Vtums5NZsc21GPlm/YYdZeCaLYK5tU8iSTnO0aeBBiP/x3EKm3qVW0ujSBFkNlmBy xuGrYf9nKiPmfuRtJcByclUk1FH5vBfnciA5YB23+si7jpPpA6COfyqlCNJxwsvC1ZmD TeFDdmBw4PR8nnQzCVSGQ01a0HEP3cJpLOkUt/le3LBKq4qk9/PRdiKwsJwZm5rYdSZR dUBBhIdtzM7FGAcmO7i1s12Yuz406c7YO9eYYAN15gRGd8UBHjR6CEKLs5DGcdHc19CZ Ap/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g6AdrS6E; 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 bw13-20020a05622a098d00b003a6a5866c2esi20791952qtb.171.2023.01.05.08.43.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Jan 2023 08:43:50 -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=g6AdrS6E; 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 1pDTL8-00074s-5J; Thu, 05 Jan 2023 11:43:38 -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 1pDTL7-000734-4a for qemu-devel@nongnu.org; Thu, 05 Jan 2023 11:43:37 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDTKw-0006xf-D6 for qemu-devel@nongnu.org; Thu, 05 Jan 2023 11:43:36 -0500 Received: by mail-wm1-x334.google.com with SMTP id m3so19553322wmq.0 for ; Thu, 05 Jan 2023 08:43:25 -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=9rGtAM1a6TiNs1+FB6TlBWh3o6cb+GfZm+A8LFRsD5w=; b=g6AdrS6EW+5PHWDPLvZgk/ErxplEW+fXOIf4osHQtf9IbOMCP9xT1G11ZoyavkieNG jky6elPdESA0UwxSfH1/q0nIrRCd/Jqs1TPD/BQJ9pP3q8cSvlmQ00mZEQoTKSpA1sIi BTzlOgnIK9buT/PGmvNRd2maO1G+GzkOUC8VAGWzrG26ZNKHzCydcyU2rHdBSkzERJ1B d6sj0kmZYawBrBnkafp1GdGV3WK4hDMnCkNuWDaRLna/9einXGWqMtD1VQ4nCh2F9iel JdmsTrhIv7PS0FMJSfl0bF3T79mqgyLS8/nLbnoMdGVRK6Cb0q/0aQEfw4tT03z2qQ9C qPDQ== 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=9rGtAM1a6TiNs1+FB6TlBWh3o6cb+GfZm+A8LFRsD5w=; b=qWQuq2yoKB+RK90S8T6XQLElXbpRcsh6a4qKKy/8X6KrvFbRP9sQpANfojuHPFvDCS 8tRcm7Xnb7b9ZzngMN9ljCIAdmd0fSh10qU84+zEU2EKYgTtxwvkXWHv/8a18yscXP7r MurxuhWE3tYedh/EUD3dBYrWhMKBtX4KQ1c98r0A3e4wuiRfoC4CAIehVvLyAIcOLKJ9 Be0BtbY/ey9MXOKoZu8s0F6JP9rXIrCeLm0vX8Iin5yfVr1hh370Z/TkMhr+HNp9eXl8 N5MSWaRKplJrKerDO8E8Eppl8do+j7YYQIjveJIKXoVRiFuGsRgKmPrUk4rqnloQn6R0 I1XQ== X-Gm-Message-State: AFqh2koPbbS4mKvmQj95o9nzdHH5kYrfdnX7ks6XuxUeyPXRBjb+SbjH NrN+nERdDmowMbVntbh+0hhtiQ== X-Received: by 2002:a05:600c:1ca3:b0:3d3:591a:bfda with SMTP id k35-20020a05600c1ca300b003d3591abfdamr40202142wms.27.1672937003746; Thu, 05 Jan 2023 08:43:23 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id g19-20020a05600c4ed300b003d978f8f255sm4625941wmq.27.2023.01.05.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 08:43:22 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A9E101FFBD; Thu, 5 Jan 2023 16:43:20 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org, alex.bennee@gmail.com Cc: David Hildenbrand , Sunil Muthuswamy , Aurelien Jarno , Michael Rolnik , Aleksandar Rikalo , Greg Kurz , Ilya Leoshkevich , Thomas Huth , qemu-ppc@nongnu.org, Laurent Vivier , Max Filippov , Yanan Wang , Marek Vasut , Stafford Horne , Peter Maydell , Daniel Henrique Barboza , Palmer Dabbelt , =?utf-8?q?Alex_Benn=C3=A9e?= , Taylor Simpson , Marcel Apfelbaum , Alexandre Iooss , Chris Wulff , Richard Henderson , Eduardo Habkost , Song Gao , Mark Cave-Ayland , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Artyom Tarasenko , Paolo Bonzini , qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , "Edgar E. Iglesias" , Bastian Koppelmann , Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Bin Meng , Mahmoud Mandour , David Gibson , Yoshinori Sato , Xiaojuan Yang , qemu-arm@nongnu.org Subject: [PATCH v2 05/21] gdbstub: define separate user/system structures Date: Thu, 5 Jan 2023 16:43:04 +0000 Message-Id: <20230105164320.2164095-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230105164320.2164095-1-alex.bennee@linaro.org> References: <20230105164320.2164095-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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=unavailable 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. These will eventually be defined in their own files. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- gdbstub/gdbstub.c | 91 +++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index be88ca0d71..42ae13b344 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -342,6 +342,20 @@ enum RSState { RS_CHKSUM1, RS_CHKSUM2, }; + +#ifdef CONFIG_USER_ONLY +typedef struct { + int fd; + char *socket_path; + int running_state; +} GDBUserState; +#else +typedef struct { + CharBackend chr; + Chardev *mon_chr; +} GDBSystemState; +#endif + typedef struct GDBState { bool init; /* have we been initialised? */ CPUState *c_cpu; /* current CPU for step/continue ops */ @@ -355,12 +369,9 @@ typedef struct GDBState { GByteArray *last_packet; int signal; #ifdef CONFIG_USER_ONLY - int fd; - char *socket_path; - int running_state; + GDBUserState user; #else - CharBackend chr; - Chardev *mon_chr; + GDBSystemState system; #endif bool multiprocess; GDBProcess *processes; @@ -413,15 +424,17 @@ static int get_char(void) int ret; for(;;) { - ret = recv(gdbserver_state.fd, &ch, 1, 0); + ret = recv(gdbserver_state.user.fd, &ch, 1, 0); if (ret < 0) { - if (errno == ECONNRESET) - gdbserver_state.fd = -1; - if (errno != EINTR) + if (errno == ECONNRESET) { + gdbserver_state.user.fd = -1; + } + if (errno != EINTR) { return -1; + } } else if (ret == 0) { - close(gdbserver_state.fd); - gdbserver_state.fd = -1; + close(gdbserver_state.user.fd); + gdbserver_state.user.fd = -1; return -1; } else { break; @@ -480,7 +493,7 @@ static inline void gdb_continue(void) { #ifdef CONFIG_USER_ONLY - gdbserver_state.running_state = 1; + gdbserver_state.user.running_state = 1; trace_gdbstub_op_continue(); #else if (!runstate_needs_reset()) { @@ -509,7 +522,7 @@ static int gdb_continue_partial(char *newstates) cpu_single_step(cpu, gdbserver_state.sstep_flags); } } - gdbserver_state.running_state = 1; + gdbserver_state.user.running_state = 1; #else int flag = 0; @@ -561,7 +574,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_state.user.fd, buf, len, 0); if (ret < 0) { if (errno != EINTR) return; @@ -573,7 +586,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_state.system.chr, buf, len); #endif } @@ -2095,7 +2108,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_state.system.mon_chr, + gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len); put_packet("OK"); } @@ -3028,10 +3042,10 @@ void gdb_exit(int code) return; } #ifdef CONFIG_USER_ONLY - if (gdbserver_state.socket_path) { - unlink(gdbserver_state.socket_path); + if (gdbserver_state.user.socket_path) { + unlink(gdbserver_state.user.socket_path); } - if (gdbserver_state.fd < 0) { + if (gdbserver_state.user.fd < 0) { return; } #endif @@ -3042,7 +3056,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_state.system.chr, true); #endif } @@ -3078,7 +3092,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_state.user.fd < 0) { return sig; } @@ -3096,15 +3110,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_state.user.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_state.user.running_state = 0; + while (gdbserver_state.user.running_state == 0) { + n = read(gdbserver_state.user.fd, buf, 256); if (n > 0) { int i; @@ -3115,9 +3129,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_state.user.fd); } - gdbserver_state.fd = -1; + gdbserver_state.user.fd = -1; return sig; } } @@ -3131,7 +3145,7 @@ void gdb_signalled(CPUArchState *env, int sig) { char buf[4]; - if (!gdbserver_state.init || gdbserver_state.fd < 0) { + if (!gdbserver_state.init || gdbserver_state.user.fd < 0) { return; } @@ -3146,7 +3160,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_state.user.fd = fd; gdb_has_xml = false; } @@ -3278,7 +3292,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_state.user.socket_path = g_strdup(port_or_path); return 0; } @@ -3290,11 +3304,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_state.user.fd < 0) { return; } - close(gdbserver_state.fd); - gdbserver_state.fd = -1; + close(gdbserver_state.user.fd); + gdbserver_state.user.fd = -1; cpu_breakpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB); } @@ -3488,21 +3502,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_state.system.chr, true); + mon_chr = gdbserver_state.system.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_state.system.chr, chr, &error_abort); + qemu_chr_fe_set_handlers(&gdbserver_state.system.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_state.system.mon_chr = mon_chr; gdbserver_state.current_syscall_cb = NULL; return 0;