]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Factor out sig_write
authorTom de Vries <tdevries@suse.de>
Tue, 29 Apr 2025 15:01:55 +0000 (17:01 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 29 Apr 2025 15:01:55 +0000 (17:01 +0200)
Lambda function sig_write:
...
  const auto sig_write = [] (const char *msg) -> void
  {
    gdb_stderr->write_async_safe (msg, strlen (msg));
  }
...
is defined a few times.

Factor this out into a regular function.

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/bt-utils.c
gdb/bt-utils.h
gdb/event-top.c

index 8e782450ae98b1e2f0978d23c18c5841afc622ee..98726e78f545861d79107be52e13b2b0c08a2235 100644 (file)
@@ -40,6 +40,14 @@ gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
 #endif
 }
 
+/* See bt-utils.h.  */
+
+void
+sig_write (const char *msg)
+{
+  gdb_stderr->write_async_safe (msg, strlen (msg));
+}
+
 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
 #ifdef GDB_PRINT_INTERNAL_BACKTRACE_USING_LIBBACKTRACE
 
@@ -53,11 +61,6 @@ libbacktrace_error (void *data, const char *errmsg, int errnum)
   if (errnum < 0)
     return;
 
-  const auto sig_write = [] (const char *msg) -> void
-  {
-    gdb_stderr->write_async_safe (msg, strlen (msg));
-  };
-
   sig_write ("error creating backtrace: ");
   sig_write (errmsg);
   if (errnum > 0)
@@ -77,11 +80,6 @@ static int
 libbacktrace_print (void *data, uintptr_t pc, const char *filename,
                    int lineno, const char *function)
 {
-  const auto sig_write = [] (const char *msg) -> void
-  {
-    gdb_stderr->write_async_safe (msg, strlen (msg));
-  };
-
   /* Buffer to print addresses and line numbers into.  An 8-byte address
      with '0x' prefix and a null terminator requires 20 characters.  This
      also feels like it should be enough to represent line numbers in most
@@ -128,11 +126,6 @@ gdb_internal_backtrace_1 ()
 static void
 gdb_internal_backtrace_1 ()
 {
-  const auto sig_write = [] (const char *msg) -> void
-  {
-    gdb_stderr->write_async_safe (msg, strlen (msg));
-  };
-
   /* Allow up to 25 frames of backtrace.  */
   void *buffer[25];
   int frames = backtrace (buffer, ARRAY_SIZE (buffer));
@@ -171,11 +164,6 @@ gdb_internal_backtrace ()
     return;
 
 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
-  const auto sig_write = [] (const char *msg) -> void
-  {
-    gdb_stderr->write_async_safe (msg, strlen (msg));
-  };
-
   sig_write (str_backtrace);
 
   if (gdb_stderr->fd () > -1)
index ed381d8770789247ffe6caf5e0cd37ca4c3a684d..c2fbe9797386c5378ca527f9536e8dcce51ee58b 100644 (file)
@@ -75,4 +75,9 @@ extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty,
 
 extern void gdb_internal_backtrace_init_str ();
 
+/* Print MSG to gdb_stderr or stderr in a way that is safe to do from an
+   interrupt handler.  */
+
+extern void sig_write (const char *msg);
+
 #endif /* GDB_BT_UTILS_H */
index c533e74811d4e7fb9fbfa6f9f704b6e200e44090..ad9459e3cbf058d8271ed9a3079b36288f8b6bb2 100644 (file)
@@ -980,11 +980,6 @@ handle_fatal_signal (int sig)
 #endif
 
 #ifdef GDB_PRINT_INTERNAL_BACKTRACE
-  const auto sig_write = [] (const char *msg) -> void
-  {
-    gdb_stderr->write_async_safe (msg, strlen (msg));
-  };
-
   if (bt_on_fatal_signal)
     {
       sig_write ("\n\n");