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 5D3B03839DCD for ; Wed, 31 Aug 2022 10:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D3B03839DCD 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=1661940686; 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=IBoSXDQNS2apk0nwX0W3d3WPb65s0j1q/OAQWL5lwCo=; b=PWk8Plgk20Z4SM13pqZ5fEL7r+B3qHCyH2KYjN3ulc8zK4XPvKEf5LtC5c8Qw1iyqNRg7S TAGqomsD6OVzDWdw2Y+krKIqiDYoyuzXkfatBodaoCz1TQnBRJxCIKJgMLJ3aOouWHRhl7 F1NxCSqZ/UY5K97v5FlQtrQW5BFRORo= 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-279-afNTzLnIPv6pNEiUDIvFxQ-1; Wed, 31 Aug 2022 06:11:23 -0400 X-MC-Unique: afNTzLnIPv6pNEiUDIvFxQ-1 Received: by mail-qk1-f200.google.com with SMTP id h20-20020a05620a245400b006bb0c6074baso11285976qkn.6 for ; Wed, 31 Aug 2022 03:11:23 -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=IBoSXDQNS2apk0nwX0W3d3WPb65s0j1q/OAQWL5lwCo=; b=OBXMFt7ZXdgJaIzQGtAl8fnOoK88SWpAAY4k5moFB4d5L/SXLZAh/Bin6AVBiLee2x 3rpuOKSYzbIqSI004Mmy+Bo/zlmq6XUXr0SROcAZUR/iwoqXtQ1B1a1U/Kk19ZK0Lmd8 FrlnGXELzTrYtJp74dWb3rGEUAqZKpElDz4+qJeglNpQrxp/Z7Uw0QevxEn2mnpywd4F Wg8+QVTXJPuwWIb75qWo3TYsMT81QGGOPwNG2rJhktiYEk0wStnSPJJG9NZwmQnrcj2f cka0UsrhzVc/nebp58NFjey915AhNsYCwrfah2v30Yeq+b6aMI8khk6JkQFu2IDy0WjK MSoA== X-Gm-Message-State: ACgBeo1SYg1wYMHgXkvYDYmcWRnI+yh76CEeHtONUC+2U30cr04MYbQ0 uCpUGiyxrS3J0W81tz/8Ah7vXSPhhmfb+/ZXOD50LQ5mHjEbRqTQBPZWB55l8RE8t0bdHPGjgBc n/moZpmdHERqnzjIUI8smHT1Ib+uWe5A= X-Received: by 2002:ae9:e312:0:b0:6bb:b0c9:a41d with SMTP id v18-20020ae9e312000000b006bbb0c9a41dmr15403834qkf.436.1661940683196; Wed, 31 Aug 2022 03:11:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR6e+/qOFL2lwf4kZ3Hvz9xSuOLLa4zX7shurrqFaQPPaUdiSJ7fH7Weu8NNUyWtGSzL9ZYXPfchPL0n+BdKxVI= X-Received: by 2002:ae9:e312:0:b0:6bb:b0c9:a41d with SMTP id v18-20020ae9e312000000b006bbb0c9a41dmr15403819qkf.436.1661940682969; Wed, 31 Aug 2022 03:11:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 31 Aug 2022 11:11:12 +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.2 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=unavailable 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 06:05, Fran=C3=A7ois Dumont w= rote: > > 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=3Dyes > > libstdc++-v3/ChangeLog: > > * include/debug/formatter.h > [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Decla= re. > [_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): Declar= e. > [_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 =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_indent= , ' '); 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; }