This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]