From patchwork Tue Jan 24 09:39:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 9534785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E482D6042D for ; Tue, 24 Jan 2017 10:18:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4D9225D99 for ; Tue, 24 Jan 2017 10:18:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9CA126AE3; Tue, 24 Jan 2017 10:18:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5C77425D99 for ; Tue, 24 Jan 2017 10:18:27 +0000 (UTC) Received: from localhost ([::1]:47420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVyBG-0005FK-Bi for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Jan 2017 05:18:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVxem-00021K-Ja for qemu-devel@nongnu.org; Tue, 24 Jan 2017 04:44:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVxei-0002co-Kc for qemu-devel@nongnu.org; Tue, 24 Jan 2017 04:44:52 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:35057) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVxei-0002cP-D3; Tue, 24 Jan 2017 04:44:48 -0500 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 384D842104; Tue, 24 Jan 2017 12:44:48 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id 5F63D58B; Tue, 24 Jan 2017 12:39:44 +0300 (MSK) Received: (nullmailer pid 12665 invoked by uid 1000); Tue, 24 Jan 2017 09:39:41 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Tue, 24 Jan 2017 12:39:32 +0300 Message-Id: <8c171da885807f7b534bdcde6757cd35b2969816.1485250702.git.mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 28/31] gdbstub.c: fix GDB connection segfault caused by empty machines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Ziyue Yang , Michael Tokarev , Ziyue Yang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Ziyue Yang This patch is to fix the segmentation fault caused by attaching GDB to a QEMU instance initialized with "-M none" option. The bug can be reproduced by > ./qemu-system-x86_64 -M none -nographic -S -s and attach a GDB to it by > gdb -ex 'target remote :1234 The segmentation fault was originally caused by trying to read the information about CPU when communicating with GDB. However, it's impossible for any control flow to exist on an empty machine, nor can CPU's be hot plugged to an empty machine later by QOM commands. So I think simply disabling GDB connections on empty machines makes sense. Signed-off-by: Ziyue Yang Reviewed-by: Thomas Huth Signed-off-by: Michael Tokarev --- gdbstub.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index de9b62b..27e0923 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/cutils.h" #include "cpu.h" #ifdef CONFIG_USER_ONLY @@ -1732,6 +1733,12 @@ int gdbserver_start(const char *device) CharDriverState *mon_chr; ChardevCommon common = { 0 }; + if (!first_cpu) { + error_report("gdbstub: meaningless to attach gdb to a " + "machine without any CPU."); + return -1; + } + if (!device) return -1; if (strcmp(device, "none") != 0) {