Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/4] [gdb] Add logging_file::fd
Date: Wed, 21 Oct 2026 10:01:17 +0200	[thread overview]
Message-ID: <20261021080120.349861-2-tdevries@suse.de> (raw)
In-Reply-To: <20261021080120.349861-1-tdevries@suse.de>

Logging_file is derived from ui_file, which defines a virtual fd member
function:
...
  /* If this object has an underlying file descriptor, then return it.
     Otherwise, return -1.  */
  virtual int fd () const
  { return -1; }
...

Logging_file doesn't define its own fd, so it defaults to -1.

Consequently, when logging is enabled and we do "maint internal-error", the
backtrace is printed but not recorded in the log file.

Fix this by adding logging_file::fd that defers to the wrapped file, like
other logging_file member functions.

Add a new test-case gdb.base/logging-internal-error.exp.
---
 gdb/logging-file.h                            |  6 ++
 .../gdb.base/logging-internal-error.exp       | 75 +++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/logging-internal-error.exp

diff --git a/gdb/logging-file.h b/gdb/logging-file.h
index 5dfe1118494..95ff421d485 100644
--- a/gdb/logging-file.h
+++ b/gdb/logging-file.h
@@ -66,6 +66,12 @@ class logging_file : public ui_file
     return m_out->can_emit_style_escape ();
   }
 
+  int fd () const override
+  {
+    /* Defer to the wrapped file.  */
+    return m_out->fd ();
+  }
+
 private:
   /* A helper function that returns true if output should go to
      M_OUT.  */
diff --git a/gdb/testsuite/gdb.base/logging-internal-error.exp b/gdb/testsuite/gdb.base/logging-internal-error.exp
new file mode 100644
index 00000000000..b121ca42612
--- /dev/null
+++ b/gdb/testsuite/gdb.base/logging-internal-error.exp
@@ -0,0 +1,75 @@
+# Copyright 2026 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that the backtrace generated by "maint internal-error", if any, also
+# ends up in the log file.
+
+require {!isremote host}
+
+# Do not run if gdb debug is enabled as it will interfere with logging.
+require !gdb_debug_enabled
+
+clean_restart
+
+# Don't quit, don't produce a core file.
+gdb_test_no_output "maint set internal-error corefile no"
+gdb_test_no_output "maint set internal-error quit no"
+
+set log_name [standard_output_file log.txt]
+gdb_test_no_output "set logging file $log_name" \
+    "set logging filename"
+gdb_test_no_output "set logging overwrite on"
+gdb_test "set logging enabled on" "Copying output to .*"
+
+set seen_bt 0
+set re_bt [string_to_regexp "----- Backtrace -----"]
+
+set cmd "maint internal-error"
+send_gdb "$cmd\n"
+set re \
+    [multi_line \
+	 [string_to_regexp "Command aborted."] \
+	 "$gdb_prompt $"]
+gdb_expect {
+    -re $re_bt {
+	set seen_bt 1
+	exp_continue
+    }
+    -re $re {
+	pass $cmd
+    }
+    -re "$gdb_prompt $" {
+	fail $cmd
+    }
+    timeout {
+	fail "$cmd (timeout)"
+    }
+    eof {
+	fail "$cmd (eof)"
+    }
+}
+
+gdb_test "set logging enabled off" "Done logging to .*"
+
+set fd [open $log_name]
+set data [read -nonewline $fd]
+close $fd
+
+set test "Logged backtrace"
+if {$seen_bt} {
+    gdb_assert {[regexp $re_bt $data]} $test
+} else {
+    unsupported $test
+}
-- 
2.51.0


  reply	other threads:[~2026-10-21  8:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  8:01 [PATCH 0/4] [gdb/tui] Fix hang in tui_disable in handle_fatal_signal Tom de Vries
2026-10-21  8:01 ` Tom de Vries [this message]
2026-10-21 16:54   ` [PATCH 1/4] [gdb] Add logging_file::fd Tom Tromey
2026-10-23  8:02     ` Tom de Vries
2026-10-23 17:41       ` Tom Tromey
2026-10-23 18:25         ` Tom de Vries
2026-10-21  8:01 ` [PATCH 2/4] [gdb/testsuite] Check internal-error in gdb.tui/new-ui.exp Tom de Vries
2026-10-21  8:01 ` [PATCH 3/4] [gdb/tui] Switch to main UI before disabling TUI Tom de Vries
2026-10-21  8:01 ` [PATCH 4/4] [gdb/tui] Fix hang in tui_disable in handle_fatal_signal Tom de Vries

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=20261021080120.349861-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.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