From patchwork Tue Oct 17 22:12:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 23655 Received: (qmail 91363 invoked by alias); 17 Oct 2017 22:12:21 -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 91352 invoked by uid 89); 17 Oct 2017 22:12:20 -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, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=spelled, his 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; Tue, 17 Oct 2017 22:12:18 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 597A5A467C for ; Tue, 17 Oct 2017 22:12:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 597A5A467C Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=keiths@redhat.com Received: from valrhona.Home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33D9618EE3 for ; Tue, 17 Oct 2017 22:12:17 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH] Canonicalize conversion operators Date: Tue, 17 Oct 2017 15:12:16 -0700 Message-Id: <1508278336-8655-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes Consider a conversion operator such as: operator foo const* const* (); There are two small parser problems, highlighted by this test: (gdb) p operator foo const* const* There is no field named operatorfoo const* const * GDB is looking up the symbol "operatorfoo const* const*" -- it is missing a space between the keyword "operator" and the type name "foo const* const*". Pedro also discovered this problem and has a patch for it pending on his cxx-breakpoint-improvements branch. However, something not address by Pedro's patch is that this input of the user-defined type needs to be canonicalized so that different "spellings" of the type are recognized: (gdb) p operator const foo* const * There is no field named operator const foo* const * gdb/ChangeLog: * c-exp.y (oper): Canonicalize conversion operators of user-defined types. Add whitespace to front of type name. gdb/testsuite/ChangeLog: * gdb.cp/cpexprs.cc (base) : New method. (main): Call it. * gdb.cp/cpexprs.exp: Add new conversion operator to test matrix. Add additional user-defined conversion operator tests. --- gdb/c-exp.y | 10 ++++++++-- gdb/testsuite/gdb.cp/cpexprs.cc | 2 ++ gdb/testsuite/gdb.cp/cpexprs.exp | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 7c050b4..dbb88fb 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1554,7 +1554,7 @@ oper: OPERATOR NEW | OPERATOR '>' { $$ = operator_stoken (">"); } | OPERATOR ASSIGN_MODIFY - { const char *op = "unknown"; + { const char *op = " unknown"; switch ($2) { case BINOP_RSH: @@ -1630,7 +1630,13 @@ oper: OPERATOR NEW c_print_type ($2, NULL, &buf, -1, 0, &type_print_raw_options); - $$ = operator_stoken (buf.c_str ()); + + /* This also needs canonicalization. */ + std::string canon + = " " + cp_canonicalize_string (buf.c_str ()); + if (canon.length () == 1) + canon = " " + buf.string (); + $$ = operator_stoken (canon.c_str ()); } ; diff --git a/gdb/testsuite/gdb.cp/cpexprs.cc b/gdb/testsuite/gdb.cp/cpexprs.cc index f70fd51..a2364eb 100644 --- a/gdb/testsuite/gdb.cp/cpexprs.cc +++ b/gdb/testsuite/gdb.cp/cpexprs.cc @@ -270,6 +270,7 @@ public: operator int () const { return 21; } // base::operator int operator fluff* () const { return new fluff (); } // base::operator fluff* operator fluff** () const { return &g_fluff; } // base::operator fluff** + operator fluff const* const* () const { return &g_fluff; } // base::operator fluff const* const* }; class base1 : public virtual base @@ -448,6 +449,7 @@ test_function (int argc, char* argv[]) // test_function char* str = a; fluff* flp = a; fluff** flpp = a; + fluff const* const* flcpcp = a; CV_f(CV::i); diff --git a/gdb/testsuite/gdb.cp/cpexprs.exp b/gdb/testsuite/gdb.cp/cpexprs.exp index d0f41b2..463e89c 100644 --- a/gdb/testsuite/gdb.cp/cpexprs.exp +++ b/gdb/testsuite/gdb.cp/cpexprs.exp @@ -407,6 +407,10 @@ add {base::operator int} \ {int (const base * const)} \ - \ - +add {base::operator fluff const* const*} \ + {const fluff * const *(const base * const)} \ + - \ + - # Templates add {tclass::do_something} \ @@ -746,5 +750,17 @@ gdb_test "p CV_f(CV::i)" " = 43" gdb_test "p CV_f('cpexprs.cc'::CV::t)" \ { = {int \(int\)} 0x[0-9a-f]+ } +# Make sure conversion operator names are canonicalized and properly +# "spelled." +gdb_test "p base::operator const fluff * const *" \ + [get "base::operator fluff const* const*" print] \ + "canonicalized conversion operator name 1" +gdb_test "p base::operator const fluff* const*" \ + [get "base::operator fluff const* const*" print] \ + "canonicalized conversion operator name 2" +gdb_test "p base::operator derived*" \ + "There is no field named operator derived\\*" \ + "undefined conversion operator" + gdb_exit return 0