From nobody Wed Oct 23 01:23:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1729179512; cv=none; d=zohomail.com; s=zohoarc; b=XPS2UZO/5mH0YtIaG8V3IWDyAowPtE0MIQ9MjrRrP7TNH1IHx6YiZtkS2x9Jqh7lX4/p1ml7Bp0NTFbkftwiw9K5rPb8Yoyl63lQ7S6CtIiILd58MTWKoqF7Xj9NxMG6QHoG/XLf0IskkFB28OeReSJqdN/EqEp44JFiSbKLluQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729179512; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S+2ZXkQ0LYwfL6luLg/39hG+1Q0aCrDxY1HPUr03Alc=; b=CrXf3Yiqg3MOCcquf+9pAq4HhNYnA6Vf2p7Qh24U4r7ZIt14Z2xmTqyJW6lCtfBasqjtObmiYq7hTJatChtT3yera9qyAeEQLDCfz/GX7s+s0IehhwZjC+bxyYoBlg0vXD253x+s6F0emfPFZ6IFb4hYmVKKREcaJLmQpP01w4Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729179512959213.68650174850382; Thu, 17 Oct 2024 08:38:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1SZf-000186-N1; Thu, 17 Oct 2024 11:38:03 -0400 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 <3WC8RZwYKCjsolnrbedlldib.Zljnbjr-absbiklkdkr.lod@flex--roqueh.bounces.google.com>) id 1t1SZf-00017x-2g for qemu-devel@nongnu.org; Thu, 17 Oct 2024 11:38:03 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3WC8RZwYKCjsolnrbedlldib.Zljnbjr-absbiklkdkr.lod@flex--roqueh.bounces.google.com>) id 1t1SZd-00040x-IT for qemu-devel@nongnu.org; Thu, 17 Oct 2024 11:38:02 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e2974759f5fso1263688276.0 for ; Thu, 17 Oct 2024 08:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729179480; x=1729784280; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S+2ZXkQ0LYwfL6luLg/39hG+1Q0aCrDxY1HPUr03Alc=; b=L8JVvZgkOYsNOVBHzhQQkp0iVAs4d+a+JefKEsLVGrXmJDFqasPSfJ2vL713oaD+Qg +hgaRdMyH5vLLOBDMWKb9OgNpp4K64rtWQlqOnPX/jUoXJG+fybOkzPR/Y4YffNQHbb/ BiDpvEvTc38EdLktAUL0msP/haqWIhTpWBLerNvjrqoCXOi/AFxDlqte2dhuA0Jxi899 LTmxx9yid9CCxGqd8FKlLvEDigCLo/WpXdLcvrBvqzNbvAdvdmsicdne4bZ/HeUuXeSg JuYGKI8HoT7YwTWpggKcRs8lJTg2x+okeE1BtC67LaZBkI+8s8RnnOMLyk3eEKWOLed7 kFFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729179480; x=1729784280; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S+2ZXkQ0LYwfL6luLg/39hG+1Q0aCrDxY1HPUr03Alc=; b=WkFk/a/qVDqQmriS9QIYMwdnk9MzW/qE4slJzbZ7W1jgQSg+NQCX3F15WdewoX1DUU erdkKjQGiFXtfYXWbCFrKtqUgqQtmFQSluk1EPHIauHxqwSAxJDuaRyiclEViLdx+iwQ fF97Mm3gawOhROlZlyNrJTDLqLa5vOBH4ZA4J23XkFWtvpDBRn5U3HJgaR7djJMdhRxk ZC+cVUsj1T5KgdhXt1vW7Tm8XeF8NZcxNZuk0HdwgkZr5dBJVh8RumHHBrZtyfJf6Cnr yqBeanm8EqepHZzpzSLuo0vdOCmhBCWCgOI6dBtQ9TGNqDEJa44aOpLuCw+2tZqPANfT bEXw== X-Gm-Message-State: AOJu0Yw7Ifhk8Mkj+FJFHQZyHFTde2Nt1g888gGCKnGjszmjD0SyEP3d zdG5hD9wDzibANIY+xYy5ZLdhAftFnICNwPc/HBvY5HNfQJ+wT2qFojwJeE95+5UB/Lbya3dRso zJg== X-Google-Smtp-Source: AGHT+IE8ZmIvehVmTdQ6Nn/Yfl5g8brQXze4ezSwqu5inp0XhT1qRKiCMlqrYhM7SSLsirDWuVsRCqTbuyE= X-Received: from roqueh-desktop.svl.corp.google.com ([2a00:79e0:2e5b:9:1adf:42eb:8cf9:56e9]) (user=roqueh job=sendgmr) by 2002:a25:aa84:0:b0:e29:6b0b:5c85 with SMTP id 3f1490d57ef6-e2b9cddf4d3mr7280276.1.1729179480097; Thu, 17 Oct 2024 08:38:00 -0700 (PDT) Date: Thu, 17 Oct 2024 08:37:44 -0700 In-Reply-To: <20241017153745.509978-1-roqueh@google.com> Mime-Version: 1.0 References: <20241017153745.509978-1-roqueh@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241017153745.509978-2-roqueh@google.com> Subject: [PATCH v2 1/2] gdbstub: Fix wrong CPUState pointer in breakpoint functions From: Roque Arcudia Hernandez To: richard.henderson@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org, philmd@linaro.org, slongfield@google.com, komlodi@google.com Cc: qemu-devel@nongnu.org, Roque Arcudia Hernandez 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3WC8RZwYKCjsolnrbedlldib.Zljnbjr-absbiklkdkr.lod@flex--roqueh.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, 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, USER_IN_DEF_DKIM_WL=-7.5 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1729179514477116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the context of using the remote gdb with multiple processes/inferiors (multiple cluster machine) a given breakpoint will target an specific inferior. If needed the remote protocol will use the packet 'H op thread-id' with op =3D 'g' to change focus to the inferior we want to insert/remove the breakpoint to, for instance 'Hgp3.3' and not 'Hcp3.3'. This is supported by the documentation of the H packets: > 'H op thread-id' > Set thread for subsequent operations ('m', 'M', 'g', 'G', > et.al.). Depending on the operation to be performed, op should be > 'c' for step and continue operations (note that this is > deprecated, supporting the 'vCont' command is a better option), > and 'g' for other operations. This can also be verified in the GDB source code file gdb/remote.c. Functions remote_target::insert_breakpoint and remote_target::remove_breakpoint will eventually call remote_target::set_general_thread if it needs to change the process focus and not remote_target::set_continue_thread. This can be seen around a comment that says: /* Make sure the remote is pointing at the right process, if necessary. */ Signed-off-by: Roque Arcudia Hernandez --- gdbstub/gdbstub.c | 4 ++-- gdbstub/internals.h | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index b1def7e71d..64ad81e53f 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1148,7 +1148,7 @@ static void handle_insert_bp(GArray *params, void *us= er_ctx) return; } =20 - res =3D gdb_breakpoint_insert(gdbserver_state.c_cpu, + res =3D gdb_breakpoint_insert(gdbserver_state.g_cpu, gdb_get_cmd_param(params, 0)->val_ul, gdb_get_cmd_param(params, 1)->val_ull, gdb_get_cmd_param(params, 2)->val_ull); @@ -1172,7 +1172,7 @@ static void handle_remove_bp(GArray *params, void *us= er_ctx) return; } =20 - res =3D gdb_breakpoint_remove(gdbserver_state.c_cpu, + res =3D gdb_breakpoint_remove(gdbserver_state.g_cpu, gdb_get_cmd_param(params, 0)->val_ul, gdb_get_cmd_param(params, 1)->val_ull, gdb_get_cmd_param(params, 2)->val_ull); diff --git a/gdbstub/internals.h b/gdbstub/internals.h index bf5a5c6302..e67fb6fe37 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -48,8 +48,17 @@ enum RSState { =20 typedef struct GDBState { bool init; /* have we been initialised? */ - CPUState *c_cpu; /* current CPU for step/continue ops */ - CPUState *g_cpu; /* current CPU for other ops */ + /* + * Current CPU for step/continue ops. Updated by the remote packet + * 'Hc thread-id' + */ + CPUState *c_cpu; + /* + * Current CPU for other ops such as memory accesses ('m'/'M'), general + * register accesses ('g'/'G'), breakpoint management ('z'/'Z'), etc. + * Updated by the remote packet 'Hg thread-id' + */ + CPUState *g_cpu; CPUState *query_cpu; /* for q{f|s}ThreadInfo */ enum RSState state; /* parsing state */ char line_buf[MAX_PACKET_LENGTH]; --=20 2.47.0.rc1.288.g06298d1525-goog