From patchwork Wed Jan 24 16:51:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 25497 Received: (qmail 87756 invoked by alias); 24 Jan 2018 16:51:18 -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 87734 invoked by uid 89); 24 Jan 2018 16:51:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-34.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, T_RP_MATCHES_RCVD, USER_IN_DEF_SPF_WL autolearn=ham version=3.3.2 spammy= X-HELO: mail-ua0-f201.google.com Received: from mail-ua0-f201.google.com (HELO mail-ua0-f201.google.com) (209.85.217.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 Jan 2018 16:51:15 +0000 Received: by mail-ua0-f201.google.com with SMTP id e8so2722051uam.22 for ; Wed, 24 Jan 2018 08:51:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=8f07N3VCtP1vRy5Ia8w3Ur6gh0CK1C69ZmvHE6hr8zk=; b=bqnvEowksFz6Haj3x6yujcWz/oLOX+K4C/voJLfcqGKSC9I9yMuujkyXnarZGQAzQB NliXwTqe0GahAUkZcUqgpMzBRlcdKnh+7cilLcNxOrUyquuBIEOSZHxlsqzoGs7cBkzs ktnN6w7gCuOGgm+KCVHkX6HYcdqj/gB26E4yG8/Vqz0Edmsevrf1coj+bd+ZdkwlKbhx 30g9EjYne85mQcS8snecltPCWunNGjFAtsZJKMkviZFfPtqcjqa11DazSduVjHShD4Cg 6OKBBCwDLrnmmXiQPB6Pa0rbTdTxfMT/mFU1elvOcQSFyj5O0ZUqud46DVuiODeXuXp3 MPig== X-Gm-Message-State: AKwxytcflbFO47ewWHogB9Y+fqJ7piljVZvTIRomMjnPDwfzw0E3/FcP ZJTM/LNwr1GOYh2/FVYA6yZReq81clGLpGdF9pUM6F18yjSn1g63olnWfN2EdzGZ8MXmzk5zLCT IYh3+iEYD0LIZnWo/53qq0ONIGUwAfZmUowVEFjEVTjl54RuvTrkvc47b0/qGOlS9cFyjkA== X-Google-Smtp-Source: AH8x226NtkoVmsRK7D/WYTIGErSu8DoBXKkIbIX6M8E1SLA3TJ9MTK4NnvfPzHL1855ntewi3+l/G4fqaDGx MIME-Version: 1.0 X-Received: by 10.31.2.65 with SMTP id 62mr3465145vkc.114.1516812673676; Wed, 24 Jan 2018 08:51:13 -0800 (PST) Date: Wed, 24 Jan 2018 16:51:07 +0000 Message-Id: <20180124165107.186980-1-leszeks@google.com> Subject: [PATCH v2] Do not classify C struct members as a filename X-Patchwork-Original-From: "Leszek Swirski via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Leszek Swirski To: gdb-patches@sourceware.org Cc: Leszek Swirski There is existing logic in C/C++ expression parsing to avoid classifying names as a filename when they are a field on the this object. This change extends this logic to also avoid classifying names after a struct-op (-> or .) as a filename, which otherwise causes a syntax error. Thus, it is now possible in the file #include struct D { void map(); } D d; to call (gdb) print d.map() where previously this would have been a syntax error. Tested on gdb.cp/*.exp gdb/ChangeLog: * c-exp.y (lex_one_token, classify_name, yylex): Don't classify names after a structop as a filename gdb/testsuite/ChangeLog: * gdb.cp/filename.cc, gdb.cp/filename.exp: Test that member functions with the same name as an include file are parsed correctly. --- Removed an accidental unrelated change in varobj.c gdb/ChangeLog | 5 +++++ gdb/c-exp.y | 24 +++++++++++++----------- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.cp/filename.cc | 15 ++++++++++++++- gdb/testsuite/gdb.cp/filename.exp | 10 ++++++++-- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2b6d1d6d6b..17a5a84b0c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-01-24 Leszek Swirski + + * c-exp.y (lex_one_token, classify_name, yylex): Don't classify + names after a structop as a filename + 2018-01-23 Philipp Rudo * s390-linux-tdep.c (s390_record_address_mask) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 0482e85ce8..f8c5529551 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2447,8 +2447,7 @@ static struct macro_scope *expression_macro_scope; static int saw_name_at_eof; /* This is set if the previously-returned token was a structure - operator -- either '.' or ARROW. This is used only when parsing to - do field name completion. */ + operator -- either '.' or ARROW. */ static int last_was_structop; /* Read one token, getting characters through lexptr. */ @@ -2505,7 +2504,7 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name) lexptr += 2; yylval.opcode = tokentab2[i].opcode; - if (parse_completion && tokentab2[i].token == ARROW) + if (tokentab2[i].token == ARROW) last_was_structop = 1; return tokentab2[i].token; } @@ -2569,8 +2568,7 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name) /* Might be a floating point number. */ if (lexptr[1] < '0' || lexptr[1] > '9') { - if (parse_completion) - last_was_structop = 1; + last_was_structop = 1; goto symbol; /* Nope, must be a symbol. */ } /* FALL THRU into number case. */ @@ -2863,7 +2861,7 @@ auto_obstack name_obstack; static int classify_name (struct parser_state *par_state, const struct block *block, - int is_quoted_name) + int is_quoted_name, int is_after_structop) { struct block_symbol bsym; char *copy; @@ -2907,11 +2905,13 @@ classify_name (struct parser_state *par_state, const struct block *block, } } - /* If we found a field, then we want to prefer it over a + /* If we found a field on the "this" object, or we are looking + up a field on a struct, then we want to prefer it over a filename. However, if the name was quoted, then it is better to check for a filename or a block, since this is the only way the user has of requiring the extension to be used. */ - if (is_a_field_of_this.type == NULL || is_quoted_name) + if ((is_a_field_of_this.type == NULL && !is_after_structop) + || is_quoted_name) { /* See if it's a file name. */ struct symtab *symtab; @@ -2992,7 +2992,7 @@ classify_inner_name (struct parser_state *par_state, char *copy; if (context == NULL) - return classify_name (par_state, block, 0); + return classify_name (par_state, block, 0, 0); type = check_typedef (context); if (!type_aggregate_p (type)) @@ -3062,7 +3062,7 @@ static int yylex (void) { token_and_value current; - int first_was_coloncolon, last_was_coloncolon; + int first_was_coloncolon, last_was_coloncolon, last_lex_was_structop; struct type *context_type = NULL; int last_to_examine, next_to_examine, checkpoint; const struct block *search_block; @@ -3072,13 +3072,15 @@ yylex (void) goto do_pop; popping = 0; + last_lex_was_structop = last_was_structop; + /* Read the first token and decide what to do. Most of the subsequent code is C++-only; but also depends on seeing a "::" or name-like token. */ current.token = lex_one_token (pstate, &is_quoted_name); if (current.token == NAME) current.token = classify_name (pstate, expression_context_block, - is_quoted_name); + is_quoted_name, last_lex_was_structop); if (parse_language (pstate)->la_language != language_cplus || (current.token != TYPENAME && current.token != COLONCOLON && current.token != FILENAME)) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0f02f4a97f..903d9f4cb6 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-01-24 Leszek Swirski + + * gdb.cp/filename.cc, gdb.cp/filename.exp: Test that member + functions with the same name as an include file are parsed + correctly. + 2018-01-22 Pedro Alves Sergio Durigan Junior diff --git a/gdb/testsuite/gdb.cp/filename.cc b/gdb/testsuite/gdb.cp/filename.cc index 45edf4efe9..0600c67a75 100644 --- a/gdb/testsuite/gdb.cp/filename.cc +++ b/gdb/testsuite/gdb.cp/filename.cc @@ -26,11 +26,24 @@ public: } void m() { - /* stop here */ + /* stop here 1 */ } }; +class D { +public: + int includefile(); +}; + +int D::includefile() { + return 24; +} + int main() { C c; c.m(); + + D d; + D* pd = &d; + /* stop here 2 */ } diff --git a/gdb/testsuite/gdb.cp/filename.exp b/gdb/testsuite/gdb.cp/filename.exp index 971ffe715f..67583cc67c 100644 --- a/gdb/testsuite/gdb.cp/filename.exp +++ b/gdb/testsuite/gdb.cp/filename.exp @@ -26,8 +26,14 @@ if ![runto_main] then { continue } -gdb_breakpoint [gdb_get_line_number "stop here"] -gdb_continue_to_breakpoint "stop here" +gdb_breakpoint [gdb_get_line_number "stop here 1"] +gdb_continue_to_breakpoint "stop here 1" gdb_test "print includefile\[0\]" " = 23" gdb_test "print 'includefile'::some_global" " = 27" + +gdb_breakpoint [gdb_get_line_number "stop here 2"] +gdb_continue_to_breakpoint "stop here 2" + +gdb_test "print d.includefile()" " = 24" +gdb_test "print pd->includefile()" " = 24"