From patchwork Mon Dec 17 22:13:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Marechal X-Patchwork-Id: 30708 Received: (qmail 67641 invoked by alias); 17 Dec 2018 22:13:25 -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 67618 invoked by uid 89); 17 Dec 2018 22:13:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.2 spammy=2201, msg, H*RU:sk:ESESBMR, H*M:ericsson X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Dec 2018 22:13:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1545084801; x=1547676801; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OOdlKJNuP64j4KsszReBlKI0i6vEBfJoanKuUVDIko8=; b=CPdgocWTd37XAZpW35ft+BChAvBQTlP7hIFC36t3GeNzyeS86RwzIFaS9yBsNejt PhhxCehEA56KMwHURhi9DkKoOUAlANb6EPX/bfqdm3UqcowGfxSE1xHdRHT9tb5R +W6jOavpL342F7PUqTxnXkElzn4tHanH7ILyKd2+V48=; Received: from ESESBMB502.ericsson.se (Unknown_Domain [153.88.183.115]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id 72.92.01583.08F181C5; Mon, 17 Dec 2018 23:13:20 +0100 (CET) Received: from ESESBMR502.ericsson.se (153.88.183.134) by ESESBMB502.ericsson.se (153.88.183.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Mon, 17 Dec 2018 23:13:20 +0100 Received: from ESESBMB504.ericsson.se (153.88.183.171) by ESESBMR502.ericsson.se (153.88.183.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Mon, 17 Dec 2018 23:13:20 +0100 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Mon, 17 Dec 2018 23:13:20 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rxcEGFYhiY/+B8ODX9HOe2Vi1RkAdpy4CzVQa+CGTWs=; b=dg1OwLKAKztQhOj4E1h0uN/jc4TaIv4QU+T2GNJDpmF02JeGPric0khhc9w/dUsO3KCTYRXvIl2A487ifJLJ4zo54qi/XikNYnAHklp7OV6rx/ih8aEy7G20+Vd6zfjLW7zrypqCfa4bm8y4ARrOaY8S7B+TuUEME+qlvGKRo4I= Received: from DM5PR15MB1690.namprd15.prod.outlook.com (10.175.112.18) by DM5PR15MB1643.namprd15.prod.outlook.com (10.175.106.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.18; Mon, 17 Dec 2018 22:13:17 +0000 Received: from DM5PR15MB1690.namprd15.prod.outlook.com ([fe80::a5e9:4d3c:c16b:95c3]) by DM5PR15MB1690.namprd15.prod.outlook.com ([fe80::a5e9:4d3c:c16b:95c3%5]) with mapi id 15.20.1425.021; Mon, 17 Dec 2018 22:13:17 +0000 From: Paul Marechal To: "gdb-patches@sourceware.org" CC: Paul Marechal Subject: [PATCH] gdb: Fix "info os " command Date: Mon, 17 Dec 2018 22:13:16 +0000 Message-ID: <20181217221253.13314-1-paul.marechal@ericsson.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=paul.marechal@ericsson.com; received-spf: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) MIME-Version: 1.0 Return-Path: paul.marechal@ericsson.com Running `info os someUnknownOsType` is crashing when gdb is built with -D_GLIBCXX_DEBUG: /usr/include/c++/5/debug/vector:439:error: attempt to access an element in an empty container. In target_read_stralloc from target.c, the call to target_read_alloc_1 can return an empty vector, we then call vector::back on this vector, which is invalid. This commit adds a check for emptiness before trying to call vector::back on it. It also adds test to check for `info os ` to return the proper error message. This is a regression in gdb 8.2 and this patch restores the behavior of previous versions. gdb/ChangeLog: PR gdb/23974 * target.c (target_read_stralloc): Check for empty vector. gdb/testsuite/ChangeLog: PR gdb/23974 * gdb.base/info-os.exp: Check return for unknown "info os" type. --- gdb/target.c | 2 +- gdb/testsuite/gdb.base/info-os.exp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/target.c b/gdb/target.c index 80b8453176..6c63255d03 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -1793,7 +1793,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object, if (!buf) return {}; - if (buf->back () != '\0') + if (buf->empty () || buf->back () != '\0') buf->push_back ('\0'); /* Check for embedded NUL bytes; but allow trailing NULs. */ diff --git a/gdb/testsuite/gdb.base/info-os.exp b/gdb/testsuite/gdb.base/info-os.exp index 8d7eab9c53..c44e6b27c3 100644 --- a/gdb/testsuite/gdb.base/info-os.exp +++ b/gdb/testsuite/gdb.base/info-os.exp @@ -175,6 +175,9 @@ expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphor # key msqid perm num used bytes num messages last msgsnd() command last msgrcv() command user group creator user creator group last msgsnd() time last msgrcv() time last msgctl() time expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues" +gdb_test "info os unknown_entry" [multi_line \ + "warning: Empty data returned by target. Wrong osdata type\\\?" \ + "Can not fetch data now."] # The SysV IPC primitives linger on after the creating process is killed # unless they are destroyed explicitly, so allow the test program to tidy