From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 35F193858C41 for ; Tue, 5 Mar 2024 03:07:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35F193858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 35F193858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709608031; cv=none; b=sj8wx5w/9jouCemvLnlnQHS/Y8+TxfMNYNTaVqPuEJT9jXuray/ejyN1pGRhFqy3sISN4uhteB2C12MVDiNMSa95N2yoq8YdQp4vtGSMmsP++amJ2MaN8xbRFPMNOQtgZJ5fS1mphcqVHbClSAfexF8ZlGegiw8QDsvfuhJs7cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709608031; c=relaxed/simple; bh=XV+gg5BxlDSiYlc26Bv5DgB/xcCRRfktDbx6jtJ8IAI=; h=DKIM-Signature:Mime-Version:Date:Message-Id:From:To:Subject; b=f1q2HicqvxeMgd/C4eC5VTsw1Tam+oAPvYNunfoKJDXzVyHg7spwJ2arM+US5Q4bp4K3J0ofRI2PaNjYul4KuCAEqKrDYtWKFzLMjD722qBd+Ir5wnOL+MHN4dk8/uIwmKpw9a7mcHe4oJSr4q8R7QI1WvnyK+tvwJsWWdXye+E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dd1d9daf02so9141895ad.1 for ; Mon, 04 Mar 2024 19:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709608027; x=1710212827; darn=sourceware.org; h=in-reply-to:references:subject:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jed1Yxo//XGgf0439V+R3x+BrXKw4eqsKfgzO5a/Et0=; b=J7mJL2ghRLP3TvByPEarG6HQIi6mhWCvU01tGArYB/3qZodv5duK9OkfdDPUelG9S8 DOOHDPeUEAQEwyR23nNW1IAE4kumjkhNk4zWNb0x12JbqFgQMVc+r1Q1vE/C9i3yMnx2 WCuv66v3CYCTD33t4v3y3XBbN31xk3MhayDHRoA09kHuRH9jeVLrqITjxGq/YrMcbWo3 FNMrMeWRc7bIfuqX4nPDVnxl5I9kbY4RZdmh2sLZ61L3GbFS/98tkayvEXYo9inpCUUV SCghErglEoUhAoaaSlVC6HcNyqYmSWStypwxeGoY/CnJB1kCVyHLwFLiZotmx8RTJChT awYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709608027; x=1710212827; h=in-reply-to:references:subject:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=jed1Yxo//XGgf0439V+R3x+BrXKw4eqsKfgzO5a/Et0=; b=p1av70/npDKm51IA0gqJtuv/aOLdlBYwzq1kuMCHKreIvzzE8Tg6t7nw58S+QgGR2T TPvNn2ICGBLzlQ5kjGmgurSR7US0lJP9UVAuhXZZ+d2UCEg8MQ9p9CE9qwVQzZtVurGq /nvJtDtPXLMhRs5BbCALvV+8nDaePHMVQj8mHj/fEjMZC3eD42BG4KMDjT4MQ7pBY9Wv 60UPT6BIlwuB0Q59rNYGDN1WEoDbJt7kYIsj+fds1aAZmesK8F9FdALIOVl263IU5BXR yfwzVYXPtRy8E0pAkN7maT15f6cUNQTr9vZ4FH7isVJn6myBsJbnhWp+V96drHd+yA7a uoUg== X-Forwarded-Encrypted: i=1; AJvYcCUVj59o6yZvJxuQjsMSmzCqElOtLIO5vmZ8f60tYBn5lTXCaoRQTI9z90q5HJOB/g5O5uFwZBPLOjRLJ7hO0Rv480k= X-Gm-Message-State: AOJu0YzeJGBlQAe7pOxIkPlIopoJmMNa3hXKXBzSh2011HtfLWG+ot6v OHNt6ycAJlUVRMGqcz9pOynMVhiBSOgKtkdPCt1NRYMaOUaf97lc1YQlPrLE X-Google-Smtp-Source: AGHT+IE/N4d2q3Nt0ibIXr4pPPm5kn3KNXtYsgIt4YdHLiMeflg5UPj1kF/ANwtVoMyomntmDWb48w== X-Received: by 2002:a17:903:11d2:b0:1dc:f360:7537 with SMTP id q18-20020a17090311d200b001dcf3607537mr698138plh.54.1709608027111; Mon, 04 Mar 2024 19:07:07 -0800 (PST) Received: from localhost (220-235-220-130.tpgi.com.au. [220.235.220.130]) by smtp.gmail.com with ESMTPSA id e5-20020a170902784500b001dcdf24e32csm8757267pln.111.2024.03.04.19.07.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 19:07:06 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 05 Mar 2024 13:07:03 +1000 Message-Id: From: "Nicholas Piggin" To: "Luis Machado" , Subject: Re: [RFC PATCH] gdb: powerpc: Provide an option to disable single step atomic heuristic X-Mailer: aerc 0.15.2 References: <20240222055246.879454-1-npiggin@gmail.com> <8073df5c-d0fd-49ac-bf07-ad4313bc6746@arm.com> In-Reply-To: <8073df5c-d0fd-49ac-bf07-ad4313bc6746@arm.com> X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue Mar 5, 2024 at 1:41 AM AEST, Luis Machado wrote: > Hi, > > On 2/22/24 05:52, Nicholas Piggin via Gdb wrote: > > gdb tries to step over atomic (larx/stcx.) sequences because stepping > > through them tends to clear the reservation and prevent forward > > progress. > >=20 > > More specialised targets like an emulator or hardware debug interface > > can support single stepping without clearing reservation. It would be > > nice to permit atomic sequences to be stepped into as an option. QEMU > > can do this, for example. > >=20 > > Other targets not just powerpc could have the same issue, so not sure > > whether it would make sense to be a generic option, or if it's such a > > niche case that it's not worthwhile. > >=20 > > Also, would there be a way to describe this capability to a gdb client > > in the protocol? > >=20 > > I think you'd need some way to tell gdb that it can skip registering the = atomic-stepping hook. > > While that is easy for a remote target to do, I don't know how though :) I assume add some xml description for it? > it may be a bit more complex to convey that information if, say, > gdb is running within a system QEMU instance and you want QEMU to handle = the atomic sequence and tell gdb it > doesn't need to bother with additional atomic-stepping logic. Yeah it was more for remote targets -- attaching to the QEMU machine from the outside. I think gdb running inside QEMU would have problems with single stepping, because the single step interrupts may clear the reservation explicitly (in QEMU and/or the OS). It is an interesting idea, possibly something we could look into further, but might not be feasible and likely requires some OS and QEMU changes. Remote only for now would be enough I think, and the option could always be changed manually. > > So it needs to be something that works both for remote targets and for na= tive targets, like a flag in /proc//* > , some register value and so on. > > I don't have a strong opinion on whether this should be a generic setting= or not. If QEMU can do it for multiple architectures, > then it may make sense to make it generic. Otherwise a ppc-specific optio= n would work OK. Okay. That can be decided after the mechanism is agreed upon. Thanks, Nick > > > Thanks, > > Nick > > --- > > gdb/rs6000-tdep.c | 36 ++++++++++++++++++++++++++++++++++-- > > 1 file changed, 34 insertions(+), 2 deletions(-) > >=20 > > diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c > > index c8450345be2..e911abc7604 100644 > > --- a/gdb/rs6000-tdep.c > > +++ b/gdb/rs6000-tdep.c > > @@ -153,6 +153,9 @@ static const char *const powerpc_vector_strings[] = =3D > > static enum powerpc_vector_abi powerpc_vector_abi_global =3D POWERPC_V= EC_AUTO; > > static const char *powerpc_vector_abi_string =3D "auto"; > > =20 > > +/* Single-step tries to step over entire larx/stcx. atomic sequence */ > > +static bool powerpc_step_over_atomic =3D true; > > + > > /* PowerPC-related per-inferior data. */ > > =20 > > static const registry::key ppc_inferior_d= ata_key; > > @@ -1132,7 +1135,7 @@ ppc_displaced_step_hw_singlestep (struct gdbarch = *gdbarch) > > =20 > > /* Checks for an atomic sequence of instructions beginning with a > > Load And Reserve instruction and ending with a Store Conditional > > - instruction. If such a sequence is found, attempt to step through = it. > > + instruction. If such a sequence is found, attempt to step over it. > > A breakpoint is placed at the end of the sequence. */ > > std::vector > > ppc_deal_with_atomic_sequence (struct regcache *regcache) > > @@ -1143,13 +1146,19 @@ ppc_deal_with_atomic_sequence (struct regcache = *regcache) > > CORE_ADDR breaks[2] =3D {CORE_ADDR_MAX, CORE_ADDR_MAX}; > > CORE_ADDR loc =3D pc; > > CORE_ADDR closing_insn; /* Instruction that closes the atomic sequen= ce. */ > > - int insn =3D read_memory_integer (loc, PPC_INSN_SIZE, byte_order); > > + int insn; > > int insn_count; > > int index; > > int last_breakpoint =3D 0; /* Defaults to 0 (no breakpoints placed).= */ =20 > > const int atomic_sequence_length =3D 16; /* Instruction sequence len= gth. */ > > int bc_insn_count =3D 0; /* Conditional branch instruction count. *= / > > =20 > > + /* global enable option for atomic sequence single step heuristic */ > > + if (!powerpc_step_over_atomic) > > + return {}; > > + > > + insn =3D read_memory_integer (loc, PPC_INSN_SIZE, byte_order); > > + > > /* Assume all atomic sequences start with a Load And Reserve instruc= tion. */ > > if (!IS_LOAD_AND_RESERVE_INSN (insn)) > > return {}; > > @@ -8644,6 +8653,14 @@ show_powerpc_exact_watchpoints (struct ui_file *= file, int from_tty, > > gdb_printf (file, _("Use of exact watchpoints is %s.\n"), value); > > } > > =20 > > +static void > > +show_powerpc_step_over_atomic (struct ui_file *file, int from_tty, > > + struct cmd_list_element *c, > > + const char *value) > > +{ > > + gdb_printf (file, _("Single-step over atomic (larx/stcx.) sequences = %s.\n"), value); > > +} > > + > > /* Read a PPC instruction from memory. */ > > =20 > > static unsigned int > > @@ -8787,4 +8804,19 @@ scalar type, thus assuming that the variable is = accessed through the address\n\ > > of its first byte."), > > NULL, show_powerpc_exact_watchpoints, > > &setpowerpccmdlist, &showpowerpccmdlist); > > + > > + add_setshow_boolean_cmd ("step-over-atomic", class_support, > > + &powerpc_step_over_atomic, > > + _("\ > > +Set whether single-step tries to step over atomics."), > > + _("\ > > +Show whether single-step tries to step over atomics."), > > + _("\ > > +If true, when GDB single-steps a larx instruction, it will try to find= the\n\ > > +the matching stcx. instruction and step over the entire atomic sequenc= e.\n\ > > +This can be required for forward-progress because single-stepping may = clear\n\ > > +the reservation. Special environments like emulators and low level har= dware\n\ > > +debug interfaces may not have this restriction, so this could be disab= led."), > > + NULL, show_powerpc_step_over_atomic, > > + &setpowerpccmdlist, &showpowerpccmdlist); > > }