From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6A4483858408; Wed, 7 Feb 2024 13:50:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4483858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1707313834; bh=eo6wTegKH6P/JkRyVOnS8IVtHsmY4WU4L16GPI5Vn9M=; h=From:To:Subject:Date:From; b=IyF5OaPmPg+20LczszkEQvQaPCeH3C+oFz+75wgskrScITFcrxBpoMGTxj9wziiG8 iNnKcIJBYCGF1MO7qn09dPs7yv5KiZ6gWy6g0gzApBOgEmAxHhSCaxdccM35FSaAJj dkBV8FDesJq9w1+5yC/00vAE/OMe7GklAzp9Doz8= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug cli/31352] New: [gdb/cli, recursive internal problem] sig_write uses gdb_stderr->write_async_safe, which may be a string_file Date: Wed, 07 Feb 2024 13:50:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: cli X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31352 Bug ID: 31352 Summary: [gdb/cli, recursive internal problem] sig_write uses gdb_stderr->write_async_safe, which may be a string_file Product: gdb Version: HEAD Status: NEW Severity: normal Priority: P2 Component: cli Assignee: unassigned at sourceware dot org Reporter: vries at gcc dot gnu.org Target Milestone: --- I tried debugging a dap test-case (gdb.dap/pause.exp), by replacing: ... @@ -661,13 +661,16 @@ quit (void) #else if (job_control /* If there is no terminal switching for this target, then we can't possibly get screwed by the lack of job control. */ || !target_supports_terminal_ours ()) - throw_quit ("Quit"); + __builtin_abort (); else throw_quit ("Quit (expect signal SIGINT when the program is resumed)"); #endif ... to try to produce a corefile. I noticed this didn't produce a core file, but it did mention recursive internal problems, so I decided to try a bit harder: ... @@ -347,7 +347,7 @@ internal_vproblem (struct internal_problem *problem, /* Don't allow infinite error/warning recursion. */ { static const char msg[] =3D "Recursive internal problem.\n"; - + __builtin_abort (); switch (dejavu) { case 0: ... and managed to produce a core file, due to a segfault. The segfault is due to running out of stack, and the stack loop looks like: ... gdb)=20 #16321 0x00000000014f89f5 in internal_error_loc (file=3D0x160fac0 "/data/vries/gdb/src/gdb/ui-file.h", line=3D72,=20 fmt=3D0x160faa4 "%s: write_async_safe") at /data/vries/gdb/src/gdbsupport/errors.cc:58 58 internal_verror (file, line, fmt, ap); (gdb) down #16320 0x0000000000d2433d in internal_verror (file=3D0x160fac0 "/data/vries/gdb/src/gdb/ui-file.h", line=3D72,=20 fmt=3D0x160faa4 "%s: write_async_safe", ap=3D0x7ffc703be958) at /data/vries/gdb/src/gdb/utils.c:495 495 internal_vproblem (&internal_error_problem, file, line, fmt, ap); (gdb)=20 #16319 0x0000000000d24307 in internal_vproblem(internal_problem *, const ch= ar *, int, const char *, typedef __va_list_tag __va_list_tag *) (problem=3D0x2= 76b5e0 ,=20 file=3D0x160fac0 "/data/vries/gdb/src/gdb/ui-file.h", line=3D72, fmt=3D= 0x160faa4 "%s: write_async_safe",=20 ap=3D0x7ffc703be958) at /data/vries/gdb/src/gdb/utils.c:350 350 __builtin_abort (); (gdb)=20 #16318 0x00007f1a9e6553e5 in abort () from /lib64/libc.so.6 (gdb)=20 #16317 0x00007f1a9e653d2b in raise () from /lib64/libc.so.6 (gdb)=20 #16316 (gdb)=20 #16315 0x00000000007a35eb in handle_fatal_signal (sig=3D6) at /data/vries/gdb/src/gdb/event-top.c:898 898 sig_write ("\n\n"); (gdb)=20 #16314 0x00000000007a35b1 in ::operator()(const char *) const (__closure=3D0x7ffc703bd8af,=20 msg=3D0x15ed81c "\n\n") at /data/vries/gdb/src/gdb/event-top.c:893 893 gdb_stderr->write_async_safe (msg, strlen (msg)); (gdb)=20 #16313 0x000000000082e644 in ui_file::write_async_safe (this=3D0x7ffc703c19= 70, buf=3D0x15ed81c "\n\n", length_buf=3D2) at /data/vries/gdb/src/gdb/ui-file.h:72 72 { gdb_assert_not_reached ("write_async_safe"); } (gdb)=20 #16312 0x00000000014f89f5 in internal_error_loc (file=3D0x160fac0 "/data/vries/gdb/src/gdb/ui-file.h", line=3D72,=20 fmt=3D0x160faa4 "%s: write_async_safe") at /data/vries/gdb/src/gdbsupport/errors.cc:58 58 internal_verror (file, line, fmt, ap); (gdb)=20 ... AFAICT, what happens is: - abort is raised - abort is caught - attempt to write backtrace using sig_write - sigwrite does gdb_stderr->write_async_safe - since gdb_stderr is set to a string_file, which doesn't have write_async_safe an internal_error is thrown - the internal_error ends up calling the abort I added in internal_vproblem, and another abort is raised This can easily be avoided by printing to stderr instead: ... diff --git a/gdb/bt-utils.c b/gdb/bt-utils.c index 6f68e269c51..f93e45688e8 100644 --- a/gdb/bt-utils.c +++ b/gdb/bt-utils.c @@ -56,7 +56,7 @@ libbacktrace_error (void *data, const char *errmsg, int errnum) const auto sig_write =3D [] (const char *msg) -> void { - gdb_stderr->write_async_safe (msg, strlen (msg)); + fprintf (stderr, "%s", msg); }; sig_write ("error creating backtrace: "); @@ -80,7 +80,7 @@ libbacktrace_print (void *data, uintptr_t pc, const char *filename, { const auto sig_write =3D [] (const char *msg) -> void { - gdb_stderr->write_async_safe (msg, strlen (msg)); + fprintf (stderr,"%s", msg); }; /* Buffer to print addresses and line numbers into. An 8-byte address @@ -131,7 +131,7 @@ gdb_internal_backtrace_1 () { const auto sig_write =3D [] (const char *msg) -> void { - gdb_stderr->write_async_safe (msg, strlen (msg)); + fprintf (stderr, msg); };e-- /* Allow up to 25 frames of backtrace. */ @@ -159,7 +159,7 @@ gdb_internal_backtrace () #ifdef GDB_PRINT_INTERNAL_BACKTRACE const auto sig_write =3D [] (const char *msg) -> void { - gdb_stderr->write_async_safe (msg, strlen (msg)); + fprintf (stderr, "%s", msg); }; sig_write (_("----- Backtrace -----\n")); diff --git a/gdb/event-top.c b/gdb/event-top.c index 33aef7d7cc5..b3d16ecd710 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -890,7 +890,7 @@ handle_fatal_signal (int sig) #ifdef GDB_PRINT_INTERNAL_BACKTRACE const auto sig_write =3D [] (const char *msg) -> void { - gdb_stderr->write_async_safe (msg, strlen (msg)); + fprintf (stderr, "%s", msg); }; if (bt_on_fatal_signal) ... With this patch, I can get rid of the abort in internal_vproblem and still = get my core dump. I don't know what is a proper fix for this. --=20 You are receiving this mail because: You are on the CC list for the bug.=