public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "Björn Schäpers" <gcc@hazardy.de>,
	gcc-patches@gc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Add error handler for <stacktrace>
Date: Wed, 30 Nov 2022 11:54:17 +0000	[thread overview]
Message-ID: <CACb0b4nR8Rx9=vpaTh48EkrL+osj8o7FTaBchPW8AUaQVxf0SA@mail.gmail.com> (raw)
In-Reply-To: <ee866216-8828-6b88-764d-9de8264108d5@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 655 bytes --]

On Wed, 30 Nov 2022 at 06:04, François Dumont via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> Good catch, then we also need this patch.
>

Is it worth printing an error? If we can't show the backtrace because of an
error, we can just print nothing there.

We also need to pass an error handler to the
__glibcxx_backtrace_create_state call in formatter.h.

Now that I look at this code again, why do we need the _M_backtrace_full
member? It's always set to the same thing, why can't we just call that
function directly?

And I think we should use threaded=1 for the
__glibcxx_backtrace_create_state call.

So like the attached patch.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3797 bytes --]

commit b1ab3ca54c58e9e5505929b58bd311aca4458cda
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Nov 30 11:48:35 2022

    libstdc++: Pass error handler to libbacktrace functions
    
    Also remove a redundant data member, which also allows removing several
    namespace scope declarations.
    
    libstdc++-v3/ChangeLog:
    
            * include/debug/formatter.h [_GLIBCXX_DEBUG_BACKTRACE]
            (_Error_formatter::_Error_formatter): Pass error handler to
            __glibcxx_backtrace_create_state.
            (_Error_formatter::_M_backtrace_full): Remove data member.
            (_Error_formatter::_S_err): Define empty function.
            * src/c++11/debug.cc (_Error_formatter::_M_error): Call
            __glibcxx_backtrace_full directly.

diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h
index f120163c6d4..2dd90bdf23b 100644
--- a/libstdc++-v3/include/debug/formatter.h
+++ b/libstdc++-v3/include/debug/formatter.h
@@ -32,34 +32,11 @@
 #include <bits/c++config.h>
 
 #if _GLIBCXX_HAVE_STACKTRACE
-struct __glibcxx_backtrace_state;
-
 extern "C"
-{
-  __glibcxx_backtrace_state*
-  __glibcxx_backtrace_create_state(const char*, int,
-				   void(*)(void*, const char*, int),
-				   void*);
-
-  typedef int (*__glibcxx_backtrace_full_callback) (
-    void*, __UINTPTR_TYPE__, const char *, int, const char*);
-
-  typedef void (*__glibcxx_backtrace_error_callback) (
-    void*, const char*, int);
-
-  typedef int (*__glibcxx_backtrace_full_func) (
-    __glibcxx_backtrace_state*, int,
-    __glibcxx_backtrace_full_callback,
-    __glibcxx_backtrace_error_callback,
-    void*);
-
-  int
-  __glibcxx_backtrace_full(
-    __glibcxx_backtrace_state*, int,
-    __glibcxx_backtrace_full_callback,
-    __glibcxx_backtrace_error_callback,
-    void*);
-}
+struct __glibcxx_backtrace_state*
+__glibcxx_backtrace_create_state(const char*, int,
+				 void(*)(void*, const char*, int),
+				 void*);
 #endif
 
 #if __cpp_rtti
@@ -609,8 +586,7 @@ namespace __gnu_debug
     , _M_function(__function)
 #if _GLIBCXX_HAVE_STACKTRACE
 # ifdef _GLIBCXX_DEBUG_BACKTRACE
-    , _M_backtrace_state(__glibcxx_backtrace_create_state(0, 0, 0, 0))
-    , _M_backtrace_full(&__glibcxx_backtrace_full)
+    , _M_backtrace_state(__glibcxx_backtrace_create_state(0, 1, _S_err, 0))
 # else
     , _M_backtrace_state()
 # endif
@@ -632,7 +608,8 @@ namespace __gnu_debug
     const char*		_M_function;
 #if _GLIBCXX_HAVE_STACKTRACE
     __glibcxx_backtrace_state*		_M_backtrace_state;
-    __glibcxx_backtrace_full_func	_M_backtrace_full;
+
+    static void _S_err(void*, const char*, int) { }
 #endif
 
   public:
diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 9eda38023f7..2f273ec2c93 100644
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -1084,6 +1084,20 @@ namespace
   { print_string(ctx, str, nbc, nullptr, 0); }
 
 #if _GLIBCXX_HAVE_STACKTRACE
+extern "C"
+{
+  using __glibcxx_backtrace_full_callback
+    = int (*)(void*, __UINTPTR_TYPE__, const char *, int, const char*);
+
+  using __glibcxx_backtrace_error_callback = void (*)(void*, const char*, int);
+
+  int
+  __glibcxx_backtrace_full(__glibcxx_backtrace_state*, int,
+			   __glibcxx_backtrace_full_callback,
+			   __glibcxx_backtrace_error_callback,
+			   void*);
+}
+
   void
   print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc)
   {
@@ -1192,8 +1206,8 @@ namespace __gnu_debug
     if (_M_backtrace_state)
       {
 	print_literal(ctx, "Backtrace:\n");
-	_M_backtrace_full(
-	  _M_backtrace_state, 1, print_backtrace, nullptr, &ctx);
+	__glibcxx_backtrace_full(
+	  _M_backtrace_state, 1, print_backtrace, _S_err, &ctx);
 	ctx._M_first_line = true;
 	print_literal(ctx, "\n");
       }

  reply	other threads:[~2022-11-30 11:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 21:41 Björn Schäpers
2022-11-30  6:04 ` François Dumont
2022-11-30 11:54   ` Jonathan Wakely [this message]
2022-11-30 11:57     ` Jonathan Wakely
2022-11-30 13:07       ` Jonathan Wakely
2022-11-30 18:00         ` François Dumont
2022-12-06 21:44           ` Jonathan Wakely
2022-12-07 17:58             ` François Dumont
2022-12-07 20:06               ` Jonathan Wakely
2022-11-30 18:17         ` François Dumont
2022-11-30 19:20   ` Björn Schäpers
2022-11-30 12:31 ` Jonathan Wakely
2022-11-30 13:05   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACb0b4nR8Rx9=vpaTh48EkrL+osj8o7FTaBchPW8AUaQVxf0SA@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gc.gnu.org \
    --cc=gcc@hazardy.de \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).