From patchwork Sat Jan 4 21:46:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37200 Received: (qmail 77988 invoked by alias); 4 Jan 2020 21:47:01 -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 77979 invoked by uid 89); 4 Jan 2020 21:47:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=wild X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.162) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 21:46:59 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3063A946D for ; Sat, 4 Jan 2020 15:46:58 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id nrG6is7DkHunhnrG6i2uOI; Sat, 04 Jan 2020 15:46:58 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: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=ASLlWVFFcIYUGBA6w6kE0PQG/t7R6vaKTcr0eghjUM0=; b=MpjvqyfSgRBupq2HuIkg2wRgQp p28IkgH9MDnegAQoD7potwmqbjzKP6vb/uzCObaWgpEwWwKdU1S2NMe5zV0O3/btvn//+LmtnKT/J 3o52Y+qK/yWcsrAxmDouAajsV; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:50602 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1inrG6-003DZV-0I; Sat, 04 Jan 2020 14:46:58 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix valgrind error from gdb.decode_line Date: Sat, 4 Jan 2020 14:46:56 -0700 Message-Id: <20200104214656.15488-1-tom@tromey.com> PR symtab/12535 points out that gdb.decode_line("") will cause a valgrind report. I think the empty linespec does not really make sense. So, this patch changes gdb.decode_line to treat a whitespace-only linespec the same as a non-existing argument. gdb/ChangeLog 2020-01-04 Tom Tromey PR symtab/12535: * python/python.c (gdbpy_decode_line): Treat empty string the same as no argument. gdb/testsuite/ChangeLog 2020-01-04 Tom Tromey PR symtab/12535: * gdb.python/python.exp: Test decode_line with empty string argument. Change-Id: I1d95812b4b7a21d69a3e9afd05b9e3141a931897 --- gdb/ChangeLog | 6 ++++++ gdb/python/python.c | 9 +++++++++ gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/python.exp | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/gdb/python/python.c b/gdb/python/python.c index bf214fae6e2..74d11b570ac 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -810,6 +810,15 @@ gdbpy_decode_line (PyObject *self, PyObject *args) if (! PyArg_ParseTuple (args, "|s", &arg)) return NULL; + /* Treat a string consisting of just whitespace the same as + NULL. */ + if (arg != NULL) + { + arg = skip_spaces (arg); + if (*arg == '\0') + arg = NULL; + } + if (arg != NULL) location = string_to_event_location_basic (&arg, python_language, symbol_name_match_type::WILD); diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index f002497e9d0..a50a7b43e2c 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -234,6 +234,10 @@ gdb_test "python print (len(symtab))" "2" "test decode_line current location" gdb_test "python print (symtab\[0\])" "None" "test decode_line expression parse" gdb_test "python print (len(symtab\[1\]))" "1" "test decode_line current location" +# Test that decode_line with an empty string argument does not crash. +gdb_py_test_silent_cmd "python symtab2 = gdb.decode_line('')" \ + "test decode_line with empty string" 1 + if { [is_remote host] } { set python_c [string_to_regexp "python.c"] } else {