From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130843 invoked by alias); 15 Jan 2020 04:41:31 -0000 Mailing-List: contact gdb-testers-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-testers-owner@sourceware.org Received: (qmail 130821 invoked by uid 89); 15 Jan 2020 04:41:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=2346 X-HELO: kwanyin.sergiodj.net Received: from kwanyin.sergiodj.net (HELO kwanyin.sergiodj.net) (158.69.185.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 04:39:55 +0000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] Fix valgrind error from gdb.decode_line From: gdb-buildbot@sergiodj.net To: gdb-testers@sourceware.org Message-Id: Date: Wed, 15 Jan 2020 04:55:00 -0000 X-SW-Source: 2020-q1/txt/msg01432.txt *** TEST RESULTS FOR COMMIT ff47f4f06d296b672337e2c7363a745cd2725f58 *** commit ff47f4f06d296b672337e2c7363a745cd2725f58 Author: Tom Tromey AuthorDate: Sat Dec 21 09:51:05 2019 -0700 Commit: Tom Tromey CommitDate: Tue Jan 14 17:57:52 2020 -0700 Fix valgrind error from gdb.decode_line 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-14 Tom Tromey PR symtab/12535: * python/python.c (gdbpy_decode_line): Treat empty string the same as no argument. gdb/testsuite/ChangeLog 2020-01-14 Tom Tromey PR symtab/12535: * gdb.python/python.exp: Test decode_line with empty string argument. Change-Id: I1d95812b4b7a21d69a3e9afd05b9e3141a931897 diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 213f2d0395..d348abbf58 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-01-14 Tom Tromey + + PR symtab/12535: + * python/python.c (gdbpy_decode_line): Treat empty string the same + as no argument. + 2020-01-14 Tom Tromey * Makefile.in (CLIBS): Remove second use of $(LIBIBERTY). diff --git a/gdb/python/python.c b/gdb/python/python.c index e0c05f1d06..d6f7f99c45 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/ChangeLog b/gdb/testsuite/ChangeLog index 4c1e6040d6..fd9ba7ea61 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-01-14 Tom Tromey + + PR symtab/12535: + * gdb.python/python.exp: Test decode_line with empty string + argument. + 2020-01-14 Bernd Edlinger * gdb.base/skip-inline.exp: Extend test. diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index f002497e9d..a50a7b43e2 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 {