From patchwork Thu Dec 7 21:20:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 24787 Received: (qmail 61355 invoked by alias); 7 Dec 2017 21:20:49 -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 61328 invoked by uid 89); 7 Dec 2017 21:20:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=innocent X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Dec 2017 21:20:47 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 820C7883A4 for ; Thu, 7 Dec 2017 21:20:46 +0000 (UTC) Received: from theo.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F077612A2 for ; Thu, 7 Dec 2017 21:20:46 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] Validate explicit locations with early termination Date: Thu, 7 Dec 2017 13:20:46 -0800 Message-Id: <20171207212046.13452-1-keiths@redhat.com> X-IsSubscribed: yes breakpoints/22569 involves an internal error generated by the rather innocent looking command: (gdb) break -source test.cpp main .../linespec.c:3302: internal-error: void decode_line_full(...): Assertion `result.size () == 1 || canonical->pre_expanded' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) The input string is tokenized into "-source", "test.cpp", and "main" (input parsing breaks on whitespace). create_breakpoint is then called with the explicit location (containing only the source file name) and "main" as the extra_string argument. No SaLs are created for this underspecified explicit location, and the "result.size () == 1" evaluates false (as does the pre_expanded condition). This triggers the assertion. Normally string_to_explicit_location validates the input string. However, the presence of the string "main" causes the parser to exit early: 802 else 803 { 804 /* End of the explicit location specification. 805 Stop parsing and return whatever explicit location was 806 parsed. */ 807 *argp = start; 808 return location; 809 } This bypasses the validation that is done a few lines down in this function which would have emitted the expected error. This patch fixes that. Additionally, this patch also fixes an inconsistency with error reporting in this use case: (gdb) b -source foo Source filename requires function, label, or line offset. (gdb) b -source foo main No source file named foo. These two commands should have elicited the same error message. gdb/ChangeLog: PR breakpoints/22569 * location.c (string_to_explicit_location): When terminating parsing early, break out of enclosing loop instead of returning. gdb/testsuite/ChangeLog: PR breakpoints/22569 * gdb.linespec/ls-errs.exp: Change expected result of "break -source this file has spaces.c -line 3". Check that an explicit source file followed by whitespace is identified as an invalid explicit location. --- gdb/location.c | 2 +- gdb/testsuite/gdb.linespec/ls-errs.exp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/location.c b/gdb/location.c index 6752462bcf..69b7aa4c85 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -843,7 +843,7 @@ string_to_explicit_location (const char **argp, Stop parsing and return whatever explicit location was parsed. */ *argp = start; - return location; + break; } *argp = skip_spaces (*argp); diff --git a/gdb/testsuite/gdb.linespec/ls-errs.exp b/gdb/testsuite/gdb.linespec/ls-errs.exp index ee8bb087f0..a0bcc528f8 100644 --- a/gdb/testsuite/gdb.linespec/ls-errs.exp +++ b/gdb/testsuite/gdb.linespec/ls-errs.exp @@ -175,7 +175,7 @@ proc do_test {lang} { # Test that option lexing stops at whitespace boundaries, except # when lexing function names, where we want to handle setting # breakpoints on e.g., "int template_function()". - test_break "-source this file has spaces.c -line 3" invalid_file "this" + test_break "-source this file has spaces.c -line 3" source_incomplete test_break "-function ret_type tmpl_function" \ invalid_function "ret_type tmpl_function" test_break "-source $srcfile -function ret_type tmpl_function" \ @@ -267,6 +267,7 @@ proc do_test {lang} { # Explicit linespec-specific tests test_break "-source $srcfile" source_incomplete + test_break "-source $srcfile main" source_incomplete } foreach_with_prefix lang {"C" "C++"} {