public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb.
@ 2013-08-01 15:40 aburgess at broadcom dot com
  2022-08-12 19:41 ` [Bug mi/15811] " tromey at sourceware dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: aburgess at broadcom dot com @ 2013-08-01 15:40 UTC (permalink / raw)
  To: gdb-prs

http://sourceware.org/bugzilla/show_bug.cgi?id=15811

            Bug ID: 15811
           Summary: Using interpreter-exec from a sourced file crashes
                    gdb.
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: mi
          Assignee: unassigned at sourceware dot org
          Reporter: aburgess at broadcom dot com

If I do the following...

## START ##
> cat cmd.gdb
interpreter-exec mi "-gdb-show verbose"
> gdb -q -x cmd.gdb
^done,value="off"
(gdb) 
(gdb) Invalid or non-`poll'able fd 7
error detected on stdin
## END ##

I took a look at this and the issue is something like this:

 - during start up gdb initialises the tui interpreter, at this point the input
stream is stdin, and gdb registers a file event handler against stdin.
 - the '-x' triggers a call to read_command_file, as part of this process gdb
opens the script file and makes this newly opened file the "current" input
stream.
 - When processing the intpereter-exec in the script file the MI interpreter in
started up, this cases a file event handler against the script file descriptor
(I'm not sure this is the correct thing to do...)
 - When the interpreter-exec has finished the MI interpreter is suspended,
de-registering the file event handler previously registered.
 - The TUI interpreter is "re-activated", this triggers the registering of a
file event handler against the open script file.
 - When the script is finished the script file is closed, but the script file
descriptor remains in the list of file descriptors being monitored for events
by gdb.
 - Finally, gdb enters the standard interactive command loop and polls for
events on all monitored file descriptors, including the closed script file
descriptor, this triggers the error.


It's also possible to trigger this bug using "source <script-file>" at an
interactive gdb prompt, or when using the -ex 'source <script-file>' from the
command line.

Here's a patch to add a reproducer to the gdb test suite:

diff --git a/gdb/testsuite/gdb.base/interpreter-exec.gdb
b/gdb/testsuite/gdb.base/interpreter-exec.gdb
new file mode 100644
index 0000000..6afff23
--- /dev/null
+++ b/gdb/testsuite/gdb.base/interpreter-exec.gdb
@@ -0,0 +1,20 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2013 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/>.
+
+# Test GDB's "source" command for scripts containing interpreter-exec.
+
+interpreter-exec mi "-gdb-show verbose"
diff --git a/gdb/testsuite/gdb.base/source.exp
b/gdb/testsuite/gdb.base/source.exp
index 61fd221..dfe0539 100644
--- a/gdb/testsuite/gdb.base/source.exp
+++ b/gdb/testsuite/gdb.base/source.exp
@@ -57,4 +57,10 @@ gdb_test "source -v -s ./source-test.gdb" \
     "echo test source options.*" \
     "source -v -s"

+# There was a case where sourcing a script containing "interpreter-exec"
+# commands would corrupt the interpreter mechanism and crash gdb.
+gdb_test "source ${srcdir}/${subdir}/interpreter-exec.gdb" \
+    "\\^done,value=\"off\"" \
+    "source interpreter-exec"
+
 gdb_exit

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug mi/15811] Using interpreter-exec from a sourced file crashes gdb.
  2013-08-01 15:40 [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb aburgess at broadcom dot com
@ 2022-08-12 19:41 ` tromey at sourceware dot org
  2022-08-12 19:50 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2022-08-12 19:41 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=15811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simark at simark dot ca

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
*** Bug 21388 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug mi/15811] Using interpreter-exec from a sourced file crashes gdb.
  2013-08-01 15:40 [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb aburgess at broadcom dot com
  2022-08-12 19:41 ` [Bug mi/15811] " tromey at sourceware dot org
@ 2022-08-12 19:50 ` tromey at sourceware dot org
  2022-08-31 17:15 ` cvs-commit at gcc dot gnu.org
  2022-08-31 17:15 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2022-08-12 19:50 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=15811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |tromey at sourceware dot org
                 CC|                            |tromey at sourceware dot org

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
I have a patch.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug mi/15811] Using interpreter-exec from a sourced file crashes gdb.
  2013-08-01 15:40 [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb aburgess at broadcom dot com
  2022-08-12 19:41 ` [Bug mi/15811] " tromey at sourceware dot org
  2022-08-12 19:50 ` tromey at sourceware dot org
@ 2022-08-31 17:15 ` cvs-commit at gcc dot gnu.org
  2022-08-31 17:15 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-31 17:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=15811

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1e28eebbbc34ebec69ea4913f7e8d19352e35630

commit 1e28eebbbc34ebec69ea4913f7e8d19352e35630
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Aug 12 13:50:35 2022 -0600

    Fix "source" with interpreter-exec

    PR mi/15811 points out that "source"ing a file that uses
    interpreter-exec will put gdb in a weird state, where the CLI stops
    working.  The bug is that tui_interp::suspend does not unregister the
    event file descriptor.

    The test case is from Andrew Burgess.

    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15811

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug mi/15811] Using interpreter-exec from a sourced file crashes gdb.
  2013-08-01 15:40 [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb aburgess at broadcom dot com
                   ` (2 preceding siblings ...)
  2022-08-31 17:15 ` cvs-commit at gcc dot gnu.org
@ 2022-08-31 17:15 ` tromey at sourceware dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tromey at sourceware dot org @ 2022-08-31 17:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=15811

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.1

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-31 17:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-01 15:40 [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb aburgess at broadcom dot com
2022-08-12 19:41 ` [Bug mi/15811] " tromey at sourceware dot org
2022-08-12 19:50 ` tromey at sourceware dot org
2022-08-31 17:15 ` cvs-commit at gcc dot gnu.org
2022-08-31 17:15 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).