From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20277 invoked by alias); 21 May 2010 13:47:39 -0000 Received: (qmail 20268 invoked by uid 22791); 21 May 2010 13:47:38 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 May 2010 13:47:25 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4LDlM9A023914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 May 2010 09:47:22 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4LDlKrJ014908 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 21 May 2010 09:47:21 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o4LDlJkl017313 for ; Fri, 21 May 2010 15:47:19 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o4LDlJiA017312 for gdb-patches@sourceware.org; Fri, 21 May 2010 15:47:19 +0200 Date: Fri, 21 May 2010 14:47:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Forbid run with a core file loaded Message-ID: <20100521134718.GA17157@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-IsSubscribed: yes 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 X-SW-Source: 2010-05/txt/msg00480.txt.bz2 Hi, there is already a protection against loading a core file when a program is running. But one still can now run a program when a core file is loaded. Moreover GDB then crashes on `quit'. (gdb) file sleep [...] (gdb) start [...] (gdb) core-file core.5841 A program is being debugged already. Kill it? (y or n) y [...] Program terminated with signal 11, Segmentation fault. [...] (gdb) start Starting program: /bin/sleep ^^^^^^^^^^^^^^^^ !!! [...] (gdb) quit A debugging session is active. Inferior 1 [process 13887] will be killed. Quit anyway? (y or n) y inferior.c:362: internal-error: find_inferior_pid: Assertion `pid != 0' failed. Forbid even the latter case. No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu. Thanks, Jan gdb/ 2010-05-21 Jan Kratochvil Forbid run with a core file loaded. * infcmd.c (run_command_1) : New. gdb/testsuite/ 2010-05-21 Jan Kratochvil Forbid run with a core file loaded. * gdb.base/corefile.exp (load core again, start with core) (started with core): New tests. --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -483,6 +483,15 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main) dont_repeat (); + if (core_bfd) + { + if (!from_tty + || query (_("Core file is already loaded. Unload it? "))) + core_file_command (NULL, from_tty); + if (core_bfd) + error (_("Core file not unloaded.")); + } + kill_if_already_running (from_tty); init_wait_for_inferior (); --- a/gdb/testsuite/gdb.base/corefile.exp +++ b/gdb/testsuite/gdb.base/corefile.exp @@ -180,3 +180,15 @@ gdb_load ${binfile} gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)" gdb_test "core" "No core file now." + +# Test a run (start) command will clear any loaded core file. + +gdb_test "core-file $corefile" "Core was generated by .*" "load core again" + +set test "start with core" +gdb_test_multiple "start" $test { + -re {Core file is already loaded. Unload it[?] [(]y or n[)] } { + pass $test + } +} +gdb_test "y" {No core file now\..*reakpoint [0-9]+, main.*} "started with core"