From patchwork Mon May 7 20:20:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 909909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477323-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Ta2AkCBy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40fvC61FMnz9ry1 for ; Tue, 8 May 2018 06:21:05 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=cK+/uP8VryOXKLQevpyO86Hs+vqf/TvtwqwZIngdIpsOhLI91mKf6 XZAN0PRekhs+aY3DGUKIzw1ImmN5OpP4iZE3oI6F3vLV5WP01xWPRZ/Lql765qNT Oyo25eP0LXIofWk5l3YlxtSVamFpwzgVN/+ggWxgGnEvOCsSwoBeLw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=H5Xrnn9YznPj71PyDgccv/Dc7EU=; b=Ta2AkCByKV3foRK6eWff ExAhkLirZ/kduhrdAYToz7jovmaStk0fu8B9bEzSnFmHjb3eMNpNFYmQQGnyoBMC NtY/FKlG0b/ER0rv3s9t6nUvhbAK8C8iY4fRZVM2N5j1hWTu0loWXhjVtgQ3ahIx Rr1YNexn/PlLoiIVf2Vm/PM= Received: (qmail 30207 invoked by alias); 7 May 2018 20:20:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 30180 invoked by uid 89); 7 May 2018 20:20:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=__gnu_cxx, sk:random_, sk:templat X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wr0-f179.google.com Received: from mail-wr0-f179.google.com (HELO mail-wr0-f179.google.com) (209.85.128.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 May 2018 20:20:39 +0000 Received: by mail-wr0-f179.google.com with SMTP id o2-v6so27104013wrj.13; Mon, 07 May 2018 13:20:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language; bh=SlwGB9FNzIEpOHGKpWNksq7u8evqnGcsMZL9F5zYRcA=; b=mYuB2A60inKBGQTJAa6AQU3AtkSxPSbhrlB758s5YYrnkUFDbkLlh2uh0ln2oWYgAB hzbhrCt/JkY2+JmQNV5oqEsCWgv/nqZdLzaRCWUa9dSU1E+dZJPetzkw5+y+ikD5IOat 3Wg12GOmJYIy0hOscM7NsAW5MudGU94KQPJqyQAn4/GyfLGYlihtzyglEzpfe3doR1wB OyTQ1UB853f82F3d0NKPUxpHNAAFCq+R7UMw/C9gtz4XHJFBnGcYvkYKXa0gbHYYrdcL cEYaw2p9cl/+6tmeyjnGojVBcOGxmVSjaEbpkP8bYcPgmOd64I4YYbpJCf14jifZWT7s 7vnw== X-Gm-Message-State: ALQs6tCx7vZqQcNwiaMpv8AhWwVpCYEf6/AnJmzjSxT3/0MRrFhwyU/d vP2xEsiSm3g55EBR3LMqilGflw== X-Google-Smtp-Source: AB8JxZquTCdQ/i1aDzDQgYY9UIPhLrjS6XbxtyOohj2e7A6l/ssZPOAJjE1h5DvbTHAe5qoutsAgcg== X-Received: by 2002:adf:d1cc:: with SMTP id m12-v6mr22694136wri.214.1525724437075; Mon, 07 May 2018 13:20:37 -0700 (PDT) Received: from [192.168.0.23] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id q16-v6sm29888418wrn.81.2018.05.07.13.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 13:20:36 -0700 (PDT) From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: Debug Mode ENH 3/4: Add backtrace To: "libstdc++@gcc.gnu.org" , gcc-patches Message-ID: <0dd654b0-6299-766d-e218-d3a5d4f1a886@gmail.com> Date: Mon, 7 May 2018 22:20:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Hi     Here is the patch to add backtrace info to debug assertion failure output. Example: /home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/vector:188: In function:     std::__debug::vector<_Tp, _Allocator>::vector(_InputIterator,     _InputIterator, const _Allocator&) [with _InputIterator = std::reverse_iterator<__gnu_debug::_Safe_tagged_iterator<__gnu_cxx::__normal_iterator >, std::__debug::vector,     std::random_access_iterator_tag> >; = void; _Tp     = int; _Allocator = std::allocator] Backtrace:     ./debug_neg.exe() [0x4020c1]     ./debug_neg.exe() [0x400e59]     /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f13fc56e830]     ./debug_neg.exe() [0x400eb9] I tried to use add2line on the output address and it worked fine. Tested under Linux x86_64. I'll commit tomorrow if not told otherwise.     * src/c++11/debug.cc [_GLIBCXX_HAVE_EXECINFO_H]: Include execinfo.h.     [_GLIBCXX_HAVE_EXECINFO_H](_Error_formatter::_M_error): Render backtrace. François diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index 3a1558b..cd1b43d 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -40,6 +40,10 @@ #include // for __cxa_demangle +#if defined _GLIBCXX_HAVE_EXECINFO_H +# include // for backtrace +#endif + #include "mutex_pool.h" using namespace std; @@ -1048,6 +1052,29 @@ namespace __gnu_debug print_literal(ctx, "\n"); } +#if defined _GLIBCXX_HAVE_EXECINFO_H + { + void* stack[32]; + int nb = backtrace(stack, 32); + + // Note that we skip current method symbol. + if (nb > 1) + { + print_literal(ctx, "Backtrace:\n"); + auto symbols = backtrace_symbols(stack, nb); + for (int i = 1; i < nb; ++i) + { + print_word(ctx, symbols[i]); + print_literal(ctx, "\n"); + } + + free(symbols); + ctx._M_first_line = true; + print_literal(ctx, "\n"); + } + } +#endif + print_literal(ctx, "Error: "); // Print the error message