From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 08BC23858413; Wed, 31 Aug 2022 19:33:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08BC23858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x336.google.com with SMTP id ay12so7881338wmb.1; Wed, 31 Aug 2022 12:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=a63/8d39L9HOZzdPDeqkX+6zdeVmclbvA+5h72Py17c=; b=EcFJrLdG3GNjz6uLfDa1u5Fbu2aPTTCGBQ6wZUh4ZE2b2jS1k+MLtkVJQFcDqg+1FH Hy/pph5YnZQ39jdLYutiZu2HIby6eN2O1JDUrI7BiQ/8moIMM/vC4r+XyWOIOdvlThxX lap1aBEsDxbxulIoPeHk8dUujzgqYmtzEpz+fqbMc742s1FgYPh5acaVveQkR/394v94 MpFSuvAlXnihPPCRwjESUEfvj9p/mp3UsL77tmQRz4GtjjT6Gaf3i8HCB5KoUot/ttUo /OpD3zYp+KF3YCPDcqxVPyeR5uK2Q5gdA1BLqWUG6156f3P8YQKeMu6qU7D7y2eAo3Ro juQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=a63/8d39L9HOZzdPDeqkX+6zdeVmclbvA+5h72Py17c=; b=u1pRM74IynQlD+J72tdgZR9bx6CVoKw/YBt0NFPAtarVuPeduG+iHxYrg1E8A9Am4V ct5TY16sWHfe4kw2YDadt87kuHkCN0MvOdPGrj1OAKdw2tFroiKZHWi7Zx3D9YQ1UxEL dIPj/ogDOJ8SyQyveRL1czigogyS1RPLLY4cv7VLgB/5YcwVudBlLzADGkD3cEnHEmzV YaAyu2lg0022nBU1441pZHtn2qp8LHJnGQXKasikcMbZC/fdY1eaWRV9ByHiva55JSP8 6brxbaUnKp8UVXzalOENTxqR7xP6mk783tTC983LwAhTGfzLj1aVzdJTc7zE63E2Lg78 YZqw== X-Gm-Message-State: ACgBeo3EMqtQ3cwnGwVrx+pp1TW13s7GmYBUGRhkIukMCQ1z2/M7yMKf lbHfYHQjrOa0zD0oeQTPobY= X-Google-Smtp-Source: AA6agR5FaevUN26Vvuq4klvuYGRePM0Zc6BRv+DZvNSftK4/iVCTTJJcYMmw3ebG876tR/jky0zIBg== X-Received: by 2002:a05:600c:2e48:b0:3a5:b600:1a3b with SMTP id q8-20020a05600c2e4800b003a5b6001a3bmr2830396wmf.180.1661974406779; Wed, 31 Aug 2022 12:33:26 -0700 (PDT) Received: from ?IPV6:2a01:e0a:1dc:b1c0:370d:c38f:1313:4f0f? ([2a01:e0a:1dc:b1c0:370d:c38f:1313:4f0f]) by smtp.googlemail.com with ESMTPSA id c4-20020adfef44000000b00220592005edsm13197454wrp.85.2022.08.31.12.33.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Aug 2022 12:33:26 -0700 (PDT) Message-ID: <542e3e43-fc03-a575-7d00-6dd00c28146b@gmail.com> Date: Wed, 31 Aug 2022 21:33:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] Add _GLIBCXX_DEBUG backtrace generation Content-Language: en-US To: Jonathan Wakely Cc: "libstdc++@gcc.gnu.org" , gcc-patches References: From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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 31/08/22 12:11, Jonathan Wakely wrote: > On Wed, 31 Aug 2022 at 06:05, François Dumont wrote: >> After a second thought here is an even cleaner version. No more function >> 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=yes >> >> libstdc++-v3/ChangeLog: >> >> * include/debug/formatter.h >> [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Declare. >> [_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): Declare. >> [_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 test. >> * 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 = -1) > - { > - if (nbc >= 0) > - ctx._M_column += fprintf(stderr, "%.*s", (int)nbc, str); > - else > - ctx._M_column += fprintf(stderr, "%s", str); > - } > - > void > print_word(PrintContext& ctx, const char* word, ptrdiff_t nbc = -1) > { > @@ -643,12 +634,9 @@ namespace > || (ctx._M_column + visual_length < ctx._M_max_length) > || (visual_length >= ctx._M_max_length && ctx._M_column == 1)) > { > - // If this isn't the first line, indent > + // If this isn't the first line, indent. > if (ctx._M_column == 1 && !ctx._M_first_line) > - { > - const char spacing[PrintContext::_S_indent + 1] = " "; > - print_raw(ctx, spacing, PrintContext::_S_indent); > - } > + ctx._M_column += fprintf(stderr, "%*c", PrintContext::_S_indent, ' '); I did not know this syntax, it looks definitely better. > > int written = 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 += fprintf(stderr, "%s", _M_file); > print_literal(ctx, ":"); > go_to_next_line = true; > } > Do you take care or you prefer I do ?