From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 492123858D20 for ; Wed, 29 May 2024 21:06:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 492123858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 492123858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717016805; cv=none; b=tFKnna/RscLsw2kfkbCSWYUqOPJuj5xUlBQ/nZAJK87FtRkUd8L2wcItENWMP8hNBh77MCgLLTPAjxTQm8MFTse457vz9tA7Bt85+LTlxAaXZjWk8s1p7PvH09Z/8JXtfLfe3EBjsr+YWbWfZTr/VwmMBD5rgZHeeb0cONC6RKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717016805; c=relaxed/simple; bh=lPErX9shyIxbXuS1FjkqcBeJe+Xi/LOQat366XNnDZg=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=wWKcApA7cy48GC9WgNfp5yBNBdmCGPcbEoSxlE6frAWOVQKGhYjydCmC9XxuJQm770tG2rreb6BfQa3Mu4z8Vg9XNPno+XXIpWwcAQhYwFjRiyUbx1GCyGmJT/Nz+QNJ1cMw7diG8Zbc3uHQJ/DjM3J2kjcIsxqq9UBjkD39dQ0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717016802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KybZyQwxu2w9IpoVahgO7RPz9dC8F12jpQOCikbo/Is=; b=XDuywx2A6uJdbN3pdVR4n64/aSJ9iAQS5KBQ5zWwbe2ceg3ezvCcTN1ALGhhkdtwtH1YGC xaDm70Y+G3v4NmqdNGMxkU9ifAd+HB4vklZnZ4QCPL+P92Josf1oQBZWhNggjGaQCX+xSj pcy75+oD9AC7UUQmTJ+eCWp3HKvOq70= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-rpIofn_PM92J7CSdXeoDFg-1; Wed, 29 May 2024 17:06:39 -0400 X-MC-Unique: rpIofn_PM92J7CSdXeoDFg-1 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-5b96a8cbc6aso84255eaf.2 for ; Wed, 29 May 2024 14:06:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717016799; x=1717621599; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KybZyQwxu2w9IpoVahgO7RPz9dC8F12jpQOCikbo/Is=; b=Bfzcsc1gUodx+fSPHTMCBUua5ckK5DHvrEsl51zucU7K7cYy3XjR24QQtduPOO2jMq 0412QxjwpK0qB8tX3UIG3sIK1HTpuujgLctYz5WPnePVgL8s/Utq6w4Dy0YT4Wa1Sggl NSmUMYo5BWCBP6Tc4J/HC4A83aJesRp629sYQ7EuBLjm2r5WF7QQRnDaUPaW5EdOgKX1 gHx1WQCs+RgFoqPyMeERuz9zvq0gnpoLnpq1UhiZmpOB/t8+wUWwsToxmSwYtVU3cqE5 WJR9fAigiV/FyQCPTf/sgWrPZUu3CI3RNcv0P3bxJ5qwJPG6GQqatqvzD+cOrh3gesFy YKEA== X-Gm-Message-State: AOJu0YwjBlcATb4kvqZuRfgy7nitVAofUpTcrWtnvh253eUbruyaFwKm fYbk+ERETQka0mAk+Qf/vaX78O0ZpR4+x45atdBIcsu3NKXfMFz6ou/+4+GvLN4j0xolEiIRkSi qDpt/aeKNQ4NeR6aXu6FQ+NfyQ5iZl043dd/r1b9oBqIXYS/eT+axm3Q= X-Received: by 2002:a05:6358:7285:b0:192:63da:a9ff with SMTP id e5c5f4694b2df-199b95f0ffbmr11299455d.23.1717016799004; Wed, 29 May 2024 14:06:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk6qLN7EBYMthLgjDBPAa/dkLHWrfaCRPuQUE3RkHZCmQONNbPF8d85/DleELulKCftWKBBw== X-Received: by 2002:a05:6358:7285:b0:192:63da:a9ff with SMTP id e5c5f4694b2df-199b95f0ffbmr11296255d.23.1717016798456; Wed, 29 May 2024 14:06:38 -0700 (PDT) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794df26a717sm101040085a.53.2024.05.29.14.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 14:06:37 -0700 (PDT) Message-ID: Subject: Re: PING: Re: [PATCH] selftest: invoke "diff" when ASSERT_STREQ fails From: David Malcolm To: Eric Gallager Cc: gcc-patches@gcc.gnu.org Date: Wed, 29 May 2024 17:06:36 -0400 In-Reply-To: References: <20240517195144.3084069-1-dmalcolm@redhat.com> <7fcde9e48b715db746026c8c3b1e8502dc04080e.camel@redhat.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 Wed, 2024-05-29 at 16:35 -0400, Eric Gallager wrote: > On Tue, May 28, 2024 at 1:21=E2=80=AFPM David Malcolm > wrote: > >=20 > > Ping. > >=20 > > This patch has actually been *very* helpful to me when debugging > > selftest failures involving ASSERT_STREQ. > >=20 > > Thanks > > Dave > >=20 >=20 > Currently `diff` is only listed under the "Tools/packages necessary > for modifying GCC" section of install/prerequisites.html: > https://gcc.gnu.org/install/prerequisites.html > If it's going to become a dependency for actually running GCC, too, > it > should get moved to be documented elsewhere, IMO. All this is selftest code, and is turned off in a release configuration of GCC. The code path that invokes "diff" is when a selftest is failing, which is immediately before a hard failure of the *build* of GCC. So arguably this is just a build-time thing for people packaging/hacking on GCC, and thus not a new dependency for end-usage. BTW I'm a bit hazy on the details of how "pex" is meant to work, so hopefully someone more knowledgable than me can comment on that aspect of the patch. It seems to work though. Dave >=20 > > On Fri, 2024-05-17 at 15:51 -0400, David Malcolm wrote: > > > Currently when ASSERT_STREQ or ASSERT_STREQ_AT fail we print > > > both strings to stderr.=C2=A0 However it can be hard to figure out > > > the problem (e.g. for 1-character differences in long strings). > > >=20 > > > Extend the output by writing out the strings to tempfiles and > > > invoking "diff -up" on them when we have such a selftest failure, > > > to (I hope) simplify debugging. > > >=20 > > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > >=20 > > > OK for trunk? > > >=20 > > > gcc/ChangeLog: > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * selftest.cc (selftest::p= rint_diff): New function. > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (selftest::assert_streq): = Call it when we have non-equal > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 non-null strings. > > >=20 > > > Signed-off-by: David Malcolm > > > --- > > > =C2=A0gcc/selftest.cc | 28 ++++++++++++++++++++++++++-- > > > =C2=A01 file changed, 26 insertions(+), 2 deletions(-) > > >=20 > > > diff --git a/gcc/selftest.cc b/gcc/selftest.cc > > > index 6438d86a6aa0..f58c0631908e 100644 > > > --- a/gcc/selftest.cc > > > +++ b/gcc/selftest.cc > > > @@ -63,6 +63,26 @@ fail_formatted (const location &loc, const > > > char > > > *fmt, ...) > > > =C2=A0=C2=A0 abort (); > > > =C2=A0} > > >=20 > > > +/* Invoke "diff" to print the difference between VAL1 and VAL2 > > > +=C2=A0=C2=A0 on stdout.=C2=A0 */ > > > + > > > +static void > > > +print_diff (const location &loc, const char *val1, const char > > > *val2) > > > +{ > > > +=C2=A0 temp_source_file tmpfile1 (loc, ".txt", val1); > > > +=C2=A0 temp_source_file tmpfile2 (loc, ".txt", val2); > > > +=C2=A0 const char *args[] =3D {"diff", > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "-up", > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tmpfile1= .get_filename (), > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tmpfile2= .get_filename (), > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 NULL}; > > > +=C2=A0 int exit_status =3D 0; > > > +=C2=A0 int err =3D 0; > > > +=C2=A0 pex_one (PEX_SEARCH | PEX_LAST, > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 args[0], CONS= T_CAST (char **, args), > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 NULL, NULL, N= ULL, &exit_status, &err); > > > +} > > > + > > > =C2=A0/* Implementation detail of ASSERT_STREQ. > > > =C2=A0=C2=A0=C2=A0 Compare val1 and val2 with strcmp.=C2=A0 They ough= t > > > =C2=A0=C2=A0=C2=A0 to be non-NULL; fail gracefully if either or both = are NULL.=C2=A0 > > > */ > > > @@ -89,8 +109,12 @@ assert_streq (const location &loc, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (strcmp (val1, val2) = =3D=3D 0) > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pass (loc, "AS= SERT_STREQ"); > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fail_formatted (loc= , "ASSERT_STREQ (%s, %s)\n > > > val1=3D\"%s\"\n > > > val2=3D\"%s\"\n", > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 desc_val1, desc_val2, val1, val2); > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print_d= iff (loc, val1, val2); > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fail_fo= rmatted > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (loc, "ASSERT_STREQ (%s, %s)\n val1=3D\"%s\"\n > > > val2=3D\"%s\"\n", > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 desc_val1, desc_val2, val1, val2); > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > > =C2=A0} > > >=20 > >=20 >=20