diff options
author | Tom de Vries <tdevries@suse.de> | 2025-04-29 17:01:55 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2025-04-29 17:01:55 +0200 |
commit | 27ff35ce34d89687feb2584d0eb9102218ee9e74 (patch) | |
tree | 42e8f9e93ea326005361cde4729ee0fe0a06756e | |
parent | 5e247da8afb8b764cb111ce1a05e8cb8862a7f98 (diff) | |
download | binutils-27ff35ce34d89687feb2584d0eb9102218ee9e74.zip binutils-27ff35ce34d89687feb2584d0eb9102218ee9e74.tar.gz binutils-27ff35ce34d89687feb2584d0eb9102218ee9e74.tar.bz2 |
[gdb] Factor out sig_write
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>
-rw-r--r-- | gdb/bt-utils.c | 28 | ||||
-rw-r--r-- | gdb/bt-utils.h | 5 | ||||
-rw-r--r-- | gdb/event-top.c | 5 |
3 files changed, 13 insertions, 25 deletions
diff --git a/gdb/bt-utils.c b/gdb/bt-utils.c index 8e78245..98726e7 100644 --- a/gdb/bt-utils.c +++ b/gdb/bt-utils.c @@ -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) diff --git a/gdb/bt-utils.h b/gdb/bt-utils.h index ed381d8..c2fbe97 100644 --- a/gdb/bt-utils.h +++ b/gdb/bt-utils.h @@ -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 */ diff --git a/gdb/event-top.c b/gdb/event-top.c index c533e74..ad9459e 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -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"); |