From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16237 invoked by alias); 25 Jul 2013 05:10:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 16101 invoked by uid 89); 25 Jul 2013 05:10:19 -0000 X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_50,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RDNS_NONE,TW_DB,TW_GJ autolearn=no version=3.3.1 Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 25 Jul 2013 05:10:18 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1V2DoY-000381-Fz from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Wed, 24 Jul 2013 22:10:10 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 24 Jul 2013 22:10:10 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Wed, 24 Jul 2013 22:10:09 -0700 From: Yao Qi To: Subject: [PATCH 1/3] New option --cygwin-tty. Date: Thu, 25 Jul 2013 05:10:00 -0000 Message-ID: <1374728963-25187-2-git-send-email-yao@codesourcery.com> In-Reply-To: <1374728963-25187-1-git-send-email-yao@codesourcery.com> References: <1374728963-25187-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-07/txt/msg00592.txt.bz2 Hi, This patch is to add a new GDB option '--cygwin-tty', which is useful when running/testing mingw32 native GDB in cygwin. Due the odd TTY in Cygwin, the output of mingw32 native GDB behaves differently, which causes the testsuite result unusable. I tried different approaches to detect whether GDB is running in cygwin tty, but failed. Finally, we decide to add this option in GDB, and let the testsuite to launch GDB with this option if GDB is running cygwin. This patch was written by Pedro in 2008, and used in CS tree for a while. gdb: 2013-07-25 Pedro Alves Yao Qi * NEWS: Mention new option '--cygwin-tty'. * defs.h [__MINGW32__] (cygwin_tty): Declare. * main.c [__MINGW32__] (cygwin_tty): New global variable. (long_options) [__MINGW32__]: Add an element for "cygwin-tty". (print_gdb_help) [__MINGW32__]: Print "--cygwin-tty" in help. gdb/testsuite: 2013-07-25 Pedro Alves * lib/gdb.exp (GDB_USING_CYGWIN_TTY): New global. (gdb_using_cygwin_tty): New proc. (default_gdb_start): Use gdb_using_cygwin_tty. * lib/mi-support.exp (mi_gdb_start): Use gdb_using_cygwin_tty. * gdb.base/dbx.exp (dbx_gdb_start): Use gdb_using_cygwin_tty. --- gdb/NEWS | 4 ++++ gdb/defs.h | 4 ++++ gdb/main.c | 16 ++++++++++++++++ gdb/testsuite/gdb.base/dbx.exp | 3 ++- gdb/testsuite/lib/gdb.exp | 35 +++++++++++++++++++++++++++++++++-- gdb/testsuite/lib/mi-support.exp | 3 ++- 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index a4238d0..407b715 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -61,6 +61,10 @@ show range-stepping --configuration Display the details of GDB configure-time options. +--cygwin-tty + Tells GDB that it is running in Cygwin's TTY. This is mostly for + testing purposes. + * The command 'tsave' can now support new option '-ctf' to save trace buffer in Common Trace Format. diff --git a/gdb/defs.h b/gdb/defs.h index 014d7d4..90bfe0f 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -156,6 +156,10 @@ extern char *python_libdir; /* Search path for separate debug files. */ extern char *debug_file_directory; +#ifdef __MINGW32__ +extern int cygwin_tty; +#endif + /* GDB has two methods for handling SIGINT. When immediate_quit is nonzero, a SIGINT results in an immediate longjmp out of the signal handler. Otherwise, SIGINT simply sets a flag; code that might diff --git a/gdb/main.c b/gdb/main.c index 440094e..029f365 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -98,6 +98,12 @@ int return_child_result_value = -1; /* GDB as it has been invoked from the command line (i.e. argv[0]). */ static char *gdb_program_name; +#ifdef __MINGW32__ +/* Support for --cygwin-tty. If non-zero, pipes seen on + std{in,out,err} are understood as being Cygwin ttys. */ +int cygwin_tty = 0; +#endif + static void print_gdb_help (struct ui_file *); /* Relocate a file or directory. PROGNAME is the name by which gdb @@ -517,6 +523,9 @@ captured_main (void *data) {"args", no_argument, &set_args, 1}, {"l", required_argument, 0, 'l'}, {"return-child-result", no_argument, &return_child_result, 1}, +#ifdef __MINGW32__ + {"cygwin-tty", no_argument, &cygwin_tty, 1}, +#endif {0, no_argument, 0, 0} }; @@ -1123,6 +1132,13 @@ Output and user interface control:\n\n\ --interpreter=INTERP\n\ Select a specific interpreter / user interface\n\ --tty=TTY Use TTY for input/output by the program being debugged.\n\ +"), stream); +#ifdef __MINGW32__ + fputs_unfiltered (_("\ + --cygwin-tty Tells GDB that it is running in Cygwin's TTY.\n\ +"), stream); +#endif + fputs_unfiltered (_("\ -w Use the GUI interface.\n\ --nw Do not use the GUI interface.\n\ "), stream); diff --git a/gdb/testsuite/gdb.base/dbx.exp b/gdb/testsuite/gdb.base/dbx.exp index 7d89b81..a460971 100644 --- a/gdb/testsuite/gdb.base/dbx.exp +++ b/gdb/testsuite/gdb.base/dbx.exp @@ -41,7 +41,8 @@ proc dbx_gdb_start { } { set oldtimeout $timeout set timeout [expr "$timeout + 60"] - eval "spawn $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS" + set cygwin_tty [gdb_using_cygwin_tty]; + eval "spawn $GDB -dbx $cygwin_tty $INTERNAL_GDBFLAGS $GDBFLAGS" gdb_expect { -re ".*\r\n$gdb_prompt $" { verbose "GDB initialized." diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 77fa359..e769b7f 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -52,6 +52,9 @@ if ![info exists GDBFLAGS] { } verbose "using GDBFLAGS = $GDBFLAGS" 2 +global GDB_USING_CYGWIN_TTY +set GDB_USING_CYGWIN_TTY "" + # Make the build data directory available to tests. set BUILD_DATA_DIRECTORY "[pwd]/../data-directory" @@ -126,6 +129,31 @@ proc gdb_version { } { return [default_gdb_version] } +# Return "--cygwin-tty" and save it in $GDB_USING_CYGWIN_TTY if GDB is +# running in cygwin. + +proc gdb_using_cygwin_tty { } { + global GDB_USING_CYGWIN_TTY + + if ![string compare $GDB_USING_CYGWIN_TTY ""] { + + set GDB_USING_CYGWIN_TTY "" + if { [ishost "*-*-mingw*"] } { + set output [remote_exec host "uname -o"] + set osname [lindex $output 1]; + verbose "Remote host OS name: $osname" 2 + if [string match "Cygwin*" $osname] { + # Tell GDB that the pipes seen attached to + # std{in|out|err} are really Cygwin TTYs. + set GDB_USING_CYGWIN_TTY "--cygwin-tty" + } + } + + verbose "using GDB_USING_CYGWIN_TTY = $GDB_USING_CYGWIN_TTY" 2 + } + return $GDB_USING_CYGWIN_TTY +} + # # gdb_unload -- unload a file if one is loaded # Return 0 on success, -1 on error. @@ -1415,7 +1443,8 @@ proc default_gdb_start { } { # a specific different target protocol itself. set use_gdb_stub [target_info exists use_gdb_stub] - verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS" + set cygwin_tty [gdb_using_cygwin_tty] + verbose "Spawning $GDB $cygwin_tty $INTERNAL_GDBFLAGS $GDBFLAGS" if [info exists gdb_spawn_id] { return 0 @@ -1427,7 +1456,9 @@ proc default_gdb_start { } { exit 1 } } - set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"] + + set res [remote_spawn host \ + "$GDB $cygwin_tty $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"] if { $res < 0 || $res == "" } { perror "Spawning $GDB failed." return 1 diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index 86a0fd6..061735d 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -145,7 +145,8 @@ proc default_mi_gdb_start { args } { set mi_inferior_tty_name $spawn_out(slave,name) } - set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS [host_info gdb_opts]"] + set cygwin_tty [gdb_using_cygwin_tty]; + set res [remote_spawn host "$GDB $cygwin_tty $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS [host_info gdb_opts]"] if { $res < 0 || $res == "" } { perror "Spawning $GDB failed." return 1 -- 1.7.7.6