From patchwork Tue Jul 28 20:29:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7903 Received: (qmail 116517 invoked by alias); 28 Jul 2015 20:30:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 116500 invoked by uid 89); 28 Jul 2015 20:30:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 28 Jul 2015 20:30:08 +0000 Received: by qgeh16 with SMTP id h16so826828qge.3 for ; Tue, 28 Jul 2015 13:30:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=i/1c56jADqdN0aCE/PRXbNV55RS5mhT6Wlu+CCqput4=; b=dZB+/z9dRClV6upPSyleQK/w+IcOmUhWH5ZfXbqv5z51un2pud+fMw2ifumZe92AyY 7uvK+l8jIwMUY+CaX/YNaOfVgYRGjujTeV3TvNViu5AxFRdbZa9LvP42GDGNM7JAMq7t 0EAcVXMDDXSzruKPU9d5uugYblpkujXFLIaRig5FetE7b79bkur5z1cEB9/AERM/dMJI n2oQMIBC/p60Po+HuzTsBzJMev+YxuX++fampSXoLmUvt+igg6CLWH2IvOnMC5Um3f7T CoUuA/HKZ8oAJi5dEr75JqOq7gm6Z8wfmsbDTqIZ5UJ/ZVFWA+5uV8eKsm0/6A0TA/jF /WCQ== X-Gm-Message-State: ALoCoQkj4o6dhTaDCpJ2Kj95ha4vd1z5FlAG7F/Rnjv5jpTyYEbv+HahAWpP/hDbJa7vwy6U44HQ X-Received: by 10.140.19.203 with SMTP id 69mr52422177qgh.33.1438115405732; Tue, 28 Jul 2015 13:30:05 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id m72sm11953161qkh.26.2015.07.28.13.30.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jul 2015 13:30:04 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Fix assert failure in invocation of "[kill|detach] inferiors 1" Date: Tue, 28 Jul 2015 16:29:56 -0400 Message-Id: <1438115396-7256-1-git-send-email-patrick@parcs.ath.cx> When only the dummy PID 0 inferior exists, invoking either of the above commands triggers the following assert failure: .../binutils-gdb/gdb/thread.c:514: internal-error: any_thread_of_process: Assertion `pid != 0' failed. The fix is straightforward. Tested on x86_64 Debian Stretch. gdb/ChangeLog: * inferior.c (detach_inferior_command): Don't call any_thread_of_process when pid is 0. (kill_inferior_command): Likewise. gdb/testsuite/ChangeLog: * gdb.base/no-inferiors.exp: New test file. --- gdb/inferior.c | 12 ++++++++++-- gdb/testsuite/gdb.base/no-inferiors.exp | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.base/no-inferiors.exp diff --git a/gdb/inferior.c b/gdb/inferior.c index 5e98df5..ff85a1f 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -626,7 +626,11 @@ detach_inferior_command (char *args, int from_tty) pid = gdb_inferior_id_to_pid (num); - tp = any_thread_of_process (pid); + if (pid != 0) + tp = any_thread_of_process (pid); + else + tp = 0; + if (!tp) { warning (_("Inferior ID %d has no threads."), num); @@ -662,7 +666,11 @@ kill_inferior_command (char *args, int from_tty) pid = gdb_inferior_id_to_pid (num); - tp = any_thread_of_process (pid); + if (pid != 0) + tp = any_thread_of_process (pid); + else + tp = 0; + if (!tp) { warning (_("Inferior ID %d has no threads."), num); diff --git a/gdb/testsuite/gdb.base/no-inferiors.exp b/gdb/testsuite/gdb.base/no-inferiors.exp new file mode 100644 index 0000000..2ccf4ce --- /dev/null +++ b/gdb/testsuite/gdb.base/no-inferiors.exp @@ -0,0 +1,24 @@ +# This testcase is part of GDB, the GNU debugger. +# +# Copyright 2015 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 . + +# Check that invoking various commands that take an inferior ID does not cause +# an internal error when only the dummy inferior with PID 0 exists. + +gdb_start + +gdb_test "detach inferiors 1" "warning: Inferior ID 1 has no threads." +gdb_test "kill inferiors 1" "warning: Inferior ID 1 has no threads."