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 8AEE93858011 for ; Wed, 31 Aug 2022 20:08:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AEE93858011 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976490; 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=2s9PqddX71pEpLAQ6Oxu9vH0oMSiJEAHGmrY35G8nV8=; b=M3qwRj1vZI3rtUilc3CjsBO7h7pBepSCWmeqLPWXXn2fvCEbvSJs8brQOQLY4UL4Nt3Vb5 /368OiQY8G/Q7bvQiD1a/xeRH0H9uqcsLrOWpVGzNY5QSFTuh5CMBd3BiPByDCaWI0CZ5E im+CsYOy9LsMNYlqALFurcR50K/UiXU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-659-Iefl5SSVNaiOUSFCWbWnOA-1; Wed, 31 Aug 2022 16:08:08 -0400 X-MC-Unique: Iefl5SSVNaiOUSFCWbWnOA-1 Received: by mail-qk1-f200.google.com with SMTP id s9-20020a05620a254900b006b54dd4d6deso12519763qko.3 for ; Wed, 31 Aug 2022 13:08:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=2s9PqddX71pEpLAQ6Oxu9vH0oMSiJEAHGmrY35G8nV8=; b=t2Xf+pSb15PDxtu4rOF8mH8Kil/DGKECWi//hNLwYD/HGk4LYAMiG299prN2RNlxHo EOCQWilWcP5TGFomixEDF/nFuSilI9ZwYRoJPTJ2RWW0cRgZAYpD8wd0kB+ZnXnyHf0v oXFLKcmZzEHlNoe4yxPJiZMgoURwY74wV22RqcDk5foJBGgZIXaipEBqHC/pc2zh5A1j KLwIZAgPTw3EHHVU2CjiSm5cg5WQ7J+3G2i2iJX/lwOa7cc92Vv5Rt6eQ+Opt2BVjgmj +JV7SrtaXArmDknjsFBfUG/7BQqL5zLV4db7ZkvQ30cOMs7emCQx0Ddby+b1ITto6IVD NY7Q== X-Gm-Message-State: ACgBeo3R4XBKzGKr1HkbyOqS0XXi6Xs9pCp4XwtJ+kBInSWmSAs6Qm+E Dyw2RLnE0LFrc/Zb0cNR5QZxHdil7uqK/4QsuQHL1vdS2hNCJdLrBwUzpNIT76+dzbsFVUQFze0 jgkaIW6JXJuPOIcQeBAR7t9P7p6H82J0= X-Received: by 2002:a05:6214:2a84:b0:476:feb2:f436 with SMTP id jr4-20020a0562142a8400b00476feb2f436mr21295457qvb.43.1661976488356; Wed, 31 Aug 2022 13:08:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR5E8PuuBZLvO20xx/Zid8PVVYJ69HTL7nE1m9zgs0tinJ3Z33C9WqFrcbtTN/KeRxBV2o062nll8nUwFk9bvUI= X-Received: by 2002:a05:6214:2a84:b0:476:feb2:f436 with SMTP id jr4-20020a0562142a8400b00476feb2f436mr21295441qvb.43.1661976488080; Wed, 31 Aug 2022 13:08:08 -0700 (PDT) MIME-Version: 1.0 References: <542e3e43-fc03-a575-7d00-6dd00c28146b@gmail.com> In-Reply-To: <542e3e43-fc03-a575-7d00-6dd00c28146b@gmail.com> From: Jonathan Wakely Date: Wed, 31 Aug 2022 21:07:57 +0100 Message-ID: Subject: Re: [PATCH] Add _GLIBCXX_DEBUG backtrace generation To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++@gcc.gnu.org" , gcc-patches 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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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, 31 Aug 2022 at 20:33, Fran=C3=A7ois Dumont w= rote: > > On 31/08/22 12:11, Jonathan Wakely wrote: > > On Wed, 31 Aug 2022 at 06:05, Fran=C3=A7ois Dumont wrote: > >> After a second thought here is an even cleaner version. No more functi= on > >> rename, current pretty_print is fine. > >> > >> libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demand > >> > >> Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace > >> generation on > >> _GLIBCXX_DEBUG assertions. Prerequisite is to have configure the > >> lib with: > >> > >> --enable-libstdcxx-backtrace=3Dyes > >> > >> libstdc++-v3/ChangeLog: > >> > >> * include/debug/formatter.h > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): D= eclare. > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_create_state): Declare. > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_callback): Define. > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_error_callback): Define= . > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_func): Define. > >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full): De= clare. > >> [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_state): New. > >> [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_full): New. > >> * src/c++11/debug.cc > >> [_GLIBCXX_HAVE_STACKTRACE](print_backtrace): New. > >> (_Error_formatter::_M_error()): Adapt. > >> * src/libbacktrace/Makefile.am: Add backtrace.c. > >> * src/libbacktrace/Makefile.in: Regenerate. > >> * src/libbacktrace/backtrace-rename.h (backtrace_full): = New. > >> * > >> testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc: New tes= t. > >> * doc/xml/manual/debug_mode.xml: Document > >> _GLIBCXX_DEBUG_BACKTRACE. > >> * doc/xml/manual/using.xml: Likewise. > >> Ok to commit ? > > OK for trunk, thanks. > > > > The small change to print_raw in this patch makes me wonder whether > > that function is actually useful. > > > > It supports two modes, print with max precision, and print without. > > The only time we use it to print with max precision we pass a string > > of exactly the right length, so the precision is not needed (but the > > caller has to get the string length correct: if we increase _S_indent > > and do not increase the " " literal passed to print_raw, the > > effects would be wrong). > > > > Wouldn't it be better to just use fprintf directly when we want to > > print without precision, and use a minimum field width instead of > > precision for indenting? i.e. ... > > > > --- a/libstdc++-v3/src/c++11/debug.cc > > +++ b/libstdc++-v3/src/c++11/debug.cc > > @@ -608,15 +608,6 @@ namespace > > print_literal(PrintContext& ctx, const char(&word)[Length]) > > { print_word(ctx, word, Length - 1); } > > > > - void > > - print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc =3D -1) > > - { > > - if (nbc >=3D 0) > > - ctx._M_column +=3D fprintf(stderr, "%.*s", (int)nbc, str); > > - else > > - ctx._M_column +=3D fprintf(stderr, "%s", str); > > - } > > - > > void > > print_word(PrintContext& ctx, const char* word, ptrdiff_t nbc =3D -1= ) > > { > > @@ -643,12 +634,9 @@ namespace > > || (ctx._M_column + visual_length < ctx._M_max_length) > > || (visual_length >=3D ctx._M_max_length && ctx._M_column =3D= =3D 1)) > > { > > - // If this isn't the first line, indent > > + // If this isn't the first line, indent. > > if (ctx._M_column =3D=3D 1 && !ctx._M_first_line) > > - { > > - const char spacing[PrintContext::_S_indent + 1] =3D " "; > > - print_raw(ctx, spacing, PrintContext::_S_indent); > > - } > > + ctx._M_column +=3D fprintf(stderr, "%*c", PrintContext::_S_in= dent, ' '); > I did not know this syntax, it looks definitely better. > > > > int written =3D fprintf(stderr, "%.*s", (int)length, word); > > > > @@ -1112,7 +1100,7 @@ namespace __gnu_debug > > PrintContext ctx; > > if (_M_file) > > { > > - print_raw(ctx, _M_file); > > + ctx._M_column +=3D fprintf(stderr, "%s", _M_file); > > print_literal(ctx, ":"); > > go_to_next_line =3D true; > > } > > > Do you take care or you prefer I do ? I can do it.