From patchwork Tue Mar 7 21:21:14 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: 659846 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2605912wrb; Tue, 7 Mar 2023 13:23:21 -0800 (PST) X-Google-Smtp-Source: AK7set+ShswvCDgmlsR/G1BaQ5KLHX6a8iFX/L6RiT0IqqCiIPrWmN7oEbyta4oxh2zwtEpIpJcc X-Received: by 2002:a05:6214:2627:b0:53a:151:b650 with SMTP id gv7-20020a056214262700b0053a0151b650mr27763583qvb.35.1678224201320; Tue, 07 Mar 2023 13:23:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678224201; cv=none; d=google.com; s=arc-20160816; b=xmn4ELU5bd/HxGWvqppo6OpMtV0lqkD+wLUndLQVXJYhBXodAH+FB5mX647U5wehjD e8YqBUoD0vTvSed3uG+PmOhhO+4iL9Bvq2TEj74Pd6mOjRsOoHpZA6lJXatj0S7AQJ2i RyGb1lHMcH42sVSIADo/J2FsBct/unjANUhI/OLEl3E25h53mVoyp09CElsZ9DyQ7eSm j2+wL50zPWTK7mPcjW4KmemxO2lIH5Dk0h4dGaC4uuN6eW9LqvHxsml2Kzsk3yIJpheU PIRenocgtq+cnwGHGMA5n+0d46/OVLrUKI5z+g/BZK9+SM0XN5HDjvYKc4/IB4l5ahrt 1nPw== 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=kV3VwBQc2zc0YwDkPCS/8fY1JZ2IvGW167JZgbKQuxQ=; b=TTO0wQU2SDsNIyTDoaOJjpUOWZ9Ave6dKED/WDZ0jVNYygIMiguV7NSRh/gbuV9RxE BYRE639ELcz0fwbfF61T2jFkY1PCWkA/hGwIa8X15X7a1ckB0NLf1xN2b/ClKb7aWJkM fjU3Qrz5N1k8Dsbq27abNeE9PfUR9cjk/mP5bx69BYS+ocDohW3VP/km6gfwQf1eP4PX KbWCGiZdDIwt4Fug0ZeFCepPXahhJQTIwOq0fXjRT+os25XhIVapuiJlIx2k4MtdzwOi pn3vzqYm4yZyw0nCy2zN4BY1lP6JBc9vy2jtsDC0veDkonwj87x19L+8xg4UaY98uj+c vhAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=khL1K1j+; 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 t18-20020a0ce2d2000000b0056eaa387bd8si10215676qvl.147.2023.03.07.13.23.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Mar 2023 13:23:21 -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=khL1K1j+; 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 1pZekm-0001fh-Qo; Tue, 07 Mar 2023 16:21:48 -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 1pZekj-0001Xq-Ut for qemu-devel@nongnu.org; Tue, 07 Mar 2023 16:21:45 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZekh-00081e-Ns for qemu-devel@nongnu.org; Tue, 07 Mar 2023 16:21:45 -0500 Received: by mail-wm1-x32f.google.com with SMTP id bg16-20020a05600c3c9000b003eb34e21bdfso24049wmb.0 for ; Tue, 07 Mar 2023 13:21:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678224102; 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=kV3VwBQc2zc0YwDkPCS/8fY1JZ2IvGW167JZgbKQuxQ=; b=khL1K1j+l+WLSGQWXDIP0u89wiaGP/29yYG1Oj1kwi/1xiVsUUc2US9cxIkDt/Lo67 yEb1dLWLxh8+IqSj1sh4v0tthbM8ffKkqA9ua0yMs/SIHbTbyN4bFStjpp0yl2Hf39tI D8wC8Y85+c3Mcm2DelJrBJ807dNoEl5V4y3GkFFvg7OIP4lbJv8eVWN70HUg+eTqk5R4 0ryXPJpI4C5Dr8oo8JZGDwrbM/mjEz6A+GajTIpDj+8LhH2cjsK4GL8vuV6ZCOtpFV/G 9DEhTptem5t+BjZ90NTEbTB39Dv39I7i3ZiGOPxc0An+WoPN6IkJGNiKpt69hfVgftn4 x1Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678224102; 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=kV3VwBQc2zc0YwDkPCS/8fY1JZ2IvGW167JZgbKQuxQ=; b=SG6kI2VYDrzZXrqb5DEZdG69qf3Brfwl2PgfCFi7BcUoE5vH77BDAEjUjg4jnUb7PT F4adGw0+blvX7SQ/PFRGNZvaYdS4YvK1dwhaEVozgtVXl4YbJxDV+EwHW49W+1igjq9N oesFlMAJjX3pefv671gnCR7ogb+S+4mQlNsP21GmPiQSPM1WP/wVxqUBbAddHYpkSoa2 Sk0ofo58NwNRmCDpd73ah0RGHCPtWM2QHKiGvkXy+i1Of2j/4XO+GtWz0ykh1dC/yssO F/FnWVtanxflq9qiyZun18cd/EVhHOQg+Xk6w5vbSn8HEo8kYGIP+EJjZcPYm0ldXVY6 ygEg== X-Gm-Message-State: AO0yUKWRoEzk2nawpxpJ/LqO9+33iF39S5T1DivboU2CciT0Ak0ewaMV I2XB2Nl4aDoO2ICl18wGWK1wgWv5wV0XNDMHgD8= X-Received: by 2002:a05:600c:190b:b0:3eb:38e6:f64f with SMTP id j11-20020a05600c190b00b003eb38e6f64fmr13904239wmq.8.1678224102289; Tue, 07 Mar 2023 13:21:42 -0800 (PST) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t17-20020a05600c41d100b003dc4fd6e624sm13503156wmh.19.2023.03.07.13.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 13:21:41 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ADE191FFBD; Tue, 7 Mar 2023 21:21:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Subject: [PULL 05/30] gdbstub: define separate user/system structures Date: Tue, 7 Mar 2023 21:21:14 +0000 Message-Id: <20230307212139.883112-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307212139.883112-1-alex.bennee@linaro.org> References: <20230307212139.883112-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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 Message-Id: <20230302190846.2593720-6-alex.bennee@linaro.org> Message-Id: <20230303025805.625589-6-richard.henderson@linaro.org> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 63b56f0027..1e6f8978b5 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -341,6 +341,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 */ @@ -353,14 +369,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; @@ -412,15 +420,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; @@ -479,7 +489,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()) { @@ -508,7 +518,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; @@ -560,7 +570,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; @@ -572,7 +582,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 } @@ -2094,7 +2104,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"); } @@ -3027,10 +3038,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 @@ -3041,7 +3052,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 } @@ -3077,7 +3088,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; } @@ -3095,15 +3106,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; @@ -3114,9 +3125,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; } } @@ -3130,7 +3141,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; } @@ -3145,7 +3156,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; } @@ -3277,7 +3288,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; } @@ -3289,11 +3300,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); } @@ -3487,21 +3498,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;