From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31672 invoked by alias); 10 Apr 2009 23:18:24 -0000 Received: (qmail 31664 invoked by uid 22791); 10 Apr 2009 23:18:23 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Apr 2009 23:18:18 +0000 Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by smtp-out.google.com with ESMTP id n3ANIGjt006132 for ; Fri, 10 Apr 2009 16:18:16 -0700 Received: from localhost (ruffy.mtv.corp.google.com [172.18.118.116]) by wpaz5.hot.corp.google.com with ESMTP id n3ANIEeP002276 for ; Fri, 10 Apr 2009 16:18:15 -0700 Received: by localhost (Postfix, from userid 67641) id 40469846AB; Fri, 10 Apr 2009 16:18:14 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [RFA] Don't kill inferior if there's a typo in the specified port. Message-Id: <20090410231814.40469846AB@localhost> Date: Fri, 10 Apr 2009 23:18:00 -0000 From: dje@google.com (Doug Evans) X-System-Of-Record: true 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: 2009-04/txt/msg00198.txt.bz2 Hi. If there's a typo in the port gdbserver will kill the inferior. This fixes that by calling detach_or_kill_inferior_callback instead of kill_inferior_callback. It also moves the status message to the callback; it's only called when exiting gdb (and if that changes one can split the function into silent/verbose versions). An alternative is something like this: - fprintf (stderr, "Killing all inferiors\n"); + fprintf (stderr, "Detaching or killing all inferiors\n"); but will that be confusing? OTOH, if gdbserver ever gets used with 10's or 100's of processes, exiting with one line per process may be a bit much. OTOOH, the user might like to know what got detached and what got killed. I don't know, but I can change the patch to do whatever y'all prefer. Ok to check in? 2009-04-10 Doug Evans Don't kill inferior if there's a typo in the specified port. * server.c (detach_or_kill_inferior_callback): Print whether we're detaching or killing. (main): Don't print "Killing all inferiors", leave message to detach_or_kill_inferior_callback, which we now call instead of kill_inferior_callback. Index: gdbserver/server.c =================================================================== RCS file: /cvs/src/src/gdb/gdbserver/server.c,v retrieving revision 1.95 diff -u -p -u -p -r1.95 server.c] --- gdbserver/server.c 1 Apr 2009 22:50:24 -0000 1.95 +++ gdbserver/server.c 10 Apr 2009 23:07:55 -0000 @@ -1808,6 +1808,11 @@ kill_inferior_callback (struct inferior_ discard_queued_stop_replies (pid); } +/* Callback for for_each_inferior to detach or kill the inferior, + depending on whether we attached to it or not. + We inform the user whether we're detaching or killing the process + as this is only called when gdbserver is about to exit. */ + static void detach_or_kill_inferior_callback (struct inferior_list_entry *entry) { @@ -1815,9 +1820,15 @@ detach_or_kill_inferior_callback (struct int pid = ptid_get_pid (process->head.id); if (process->attached) - detach_inferior (pid); + { + fprintf (stderr, "Detaching from %d\n", pid); + detach_inferior (pid); + } else - kill_inferior (pid); + { + fprintf (stderr, "Killing %d\n", pid); + kill_inferior (pid); + } discard_queued_stop_replies (pid); } @@ -2015,9 +2026,8 @@ main (int argc, char *argv[]) if (setjmp (toplevel)) { - fprintf (stderr, "Killing all inferiors\n"); for_each_inferior (&all_processes, - kill_inferior_callback); + detach_or_kill_inferior_callback); exit (1); }