From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8059 invoked by alias); 1 Aug 2013 15:40:03 -0000 Mailing-List: contact gdb-prs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-prs-owner@sourceware.org Received: (qmail 8033 invoked by uid 48); 1 Aug 2013 15:40:03 -0000 From: "aburgess at broadcom dot com" To: gdb-prs@sourceware.org Subject: [Bug mi/15811] New: Using interpreter-exec from a sourced file crashes gdb. Date: Thu, 01 Aug 2013 15:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: mi X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aburgess at broadcom dot com X-Bugzilla-Status: NEW 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 Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-q3/txt/msg00149.txt.bz2 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 " at an interactive gdb prompt, or when using the -ex 'source ' 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 . + +# 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.