From 38f3c9a0616d410e2105f0cd8e430d7ffa79c948 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Thu, 11 Jan 2024 16:27:25 +0100 Subject: [PATCH] Avoid internal recursive error ... ... by implementing gdbtk_file::write_async_safe() writing directly to stderr. Also introduce a dirty hack to dump internal error message to stderr. --- gdbtk/generic/gdbtk-hooks.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/gdbtk/generic/gdbtk-hooks.c b/gdbtk/generic/gdbtk-hooks.c index 75e89e7..40b106d 100644 --- a/gdbtk/generic/gdbtk-hooks.c +++ b/gdbtk/generic/gdbtk-hooks.c @@ -1,6 +1,6 @@ /* Startup code for Insight. - Copyright (C) 1994-2023 Free Software Foundation, Inc. + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by Stu Grossman of Cygnus Support. @@ -110,6 +110,7 @@ class gdbtk_file : public ui_file public: virtual long read (char *buf, long length_buf) override; virtual void write (const char *buf, long length_buf) override; + virtual void write_async_safe (const char *buf, long length_buf) override; }; static int gdbtk_load_hash (const char *, unsigned long); @@ -288,6 +289,9 @@ gdbtk_file::read (char *buf, long sizeof_buf) * UNLESS it was coming to gdb_stderr. Then we place it in the result_ptr * anyway, so it can be dealt with. * + * If output goes to gdb_stderr and seems to come from an internal error, + * send it to stderr too. + * * This method only supports text output, so null bytes cannot appear in * output data. * @@ -342,9 +346,26 @@ gdbtk_file::write (const char *buf, long length_buf) gdbtk_two_elem_cmd ("gdbtk_tcl_fputs", ptr); } + if (this == gdb_stderr && + strstr (ptr, "A problem internal to GDB has been detected")) + write_async_safe (buf, length_buf); + gdbtk_in_write = false; } +/* This is only called in extreme situations thus we write to the standard + * error stream to keep a track of the written data. + */ + +void +gdbtk_file::write_async_safe (const char *buf, long length_buf) +{ + if (::write (2, buf, length_buf)) + { + /* Nothing. */ + } +} + /* * This gets the current process id in a portable way. */ -- 2.43.5