From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16069 invoked by alias); 15 Jul 2011 19:19:46 -0000 Received: (qmail 16060 invoked by uid 22791); 15 Jul 2011 19:19:44 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CX,TW_YY X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Jul 2011 19:19:25 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6FJJPKF025504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 15 Jul 2011 15:19:25 -0400 Received: from host1.jankratochvil.net ([10.3.113.13]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6FJJNDc024637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 15 Jul 2011 15:19:24 -0400 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p6FJJMIA032239 for ; Fri, 15 Jul 2011 21:19:22 +0200 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p6FJJLxM032238 for gdb-patches@sourceware.org; Fri, 15 Jul 2011 21:19:21 +0200 Date: Fri, 15 Jul 2011 20:47:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [rfc] Be in language c more c++ compatible Message-ID: <20110715191920.GA29975@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00402.txt.bz2 Hi, I always see some terrible C++ GDB bug so I fix in some hours and then find out it works in GDB when one has `set language c++'. This usually happens with artificial testcases like the one today: http://sourceware.org/ml/gdb-patches/2011-07/msg00387.html I was told by Keith it also happens to him. echo 'class C { typedef int t; t i; } c;'|g++ -c -o 1.o -g -x c++ - FSF GDB HEAD (gdb) show language The current source language is "auto; currently c". (gdb) whatis C::t type = C::t (gdb) set language c++ (gdb) whatis C::t type = int patched FSF GDB HEAD: (gdb) show language The current source language is "auto; currently c". (gdb) whatis C::t type = int (gdb) set language c++ (gdb) whatis C::t type = int The patch has two parts (two files), each part is sufficient to fix the problem above. The first (c-exp.y) part parses those parts of `language c++' which cannot (I believe - RFC) lead to misinterpretation of any valid C code even in `language c'. The second (valops.c) part is there because with `language c++' parsing "C::t" is straight OP_TYPE handled correctly in evaluate_subexp_standard. But with `language c' it gets parsed as OP_SCOPE and I find there a bug, copied the code there. Sure this patch is not a complete implementation of the idea, just an incremental improvement. No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu. Thanks, Jan gdb/ 2011-07-15 Jan Kratochvil * c-exp.y (tokentab3, tokentab2): Remove the cxx_only field, comment it. (lex_one_token): No longer check them there. (yylex): Do not check for language_cplus. * valops.c (value_maybe_namespace_elt): Dereference LOC_TYPEDEF for EVAL_AVOID_SIDE_EFFECTS. --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1867,38 +1867,40 @@ struct token int cxx_only; }; +/* cxx_only is not used. */ static const struct token tokentab3[] = { - {">>=", ASSIGN_MODIFY, BINOP_RSH, 0}, - {"<<=", ASSIGN_MODIFY, BINOP_LSH, 0}, - {"->*", ARROW_STAR, BINOP_END, 1} + {">>=", ASSIGN_MODIFY, BINOP_RSH}, + {"<<=", ASSIGN_MODIFY, BINOP_LSH}, + {"->*", ARROW_STAR, BINOP_END} }; +/* cxx_only is not used. */ static const struct token tokentab2[] = { - {"+=", ASSIGN_MODIFY, BINOP_ADD, 0}, - {"-=", ASSIGN_MODIFY, BINOP_SUB, 0}, - {"*=", ASSIGN_MODIFY, BINOP_MUL, 0}, - {"/=", ASSIGN_MODIFY, BINOP_DIV, 0}, - {"%=", ASSIGN_MODIFY, BINOP_REM, 0}, - {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR, 0}, - {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND, 0}, - {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR, 0}, - {"++", INCREMENT, BINOP_END, 0}, - {"--", DECREMENT, BINOP_END, 0}, - {"->", ARROW, BINOP_END, 0}, - {"&&", ANDAND, BINOP_END, 0}, - {"||", OROR, BINOP_END, 0}, + {"+=", ASSIGN_MODIFY, BINOP_ADD}, + {"-=", ASSIGN_MODIFY, BINOP_SUB}, + {"*=", ASSIGN_MODIFY, BINOP_MUL}, + {"/=", ASSIGN_MODIFY, BINOP_DIV}, + {"%=", ASSIGN_MODIFY, BINOP_REM}, + {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR}, + {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND}, + {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR}, + {"++", INCREMENT, BINOP_END}, + {"--", DECREMENT, BINOP_END}, + {"->", ARROW, BINOP_END}, + {"&&", ANDAND, BINOP_END}, + {"||", OROR, BINOP_END}, /* "::" is *not* only C++: gdb overrides its meaning in several different ways, e.g., 'filename'::func, function::variable. */ - {"::", COLONCOLON, BINOP_END, 0}, - {"<<", LSH, BINOP_END, 0}, - {">>", RSH, BINOP_END, 0}, - {"==", EQUAL, BINOP_END, 0}, - {"!=", NOTEQUAL, BINOP_END, 0}, - {"<=", LEQ, BINOP_END, 0}, - {">=", GEQ, BINOP_END, 0}, - {".*", DOT_STAR, BINOP_END, 1} + {"::", COLONCOLON, BINOP_END}, + {"<<", LSH, BINOP_END}, + {">>", RSH, BINOP_END}, + {"==", EQUAL, BINOP_END}, + {"!=", NOTEQUAL, BINOP_END}, + {"<=", LEQ, BINOP_END}, + {">=", GEQ, BINOP_END}, + {".*", DOT_STAR, BINOP_END} }; /* Identifier-like tokens. */ @@ -2075,10 +2077,6 @@ lex_one_token (void) for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) if (strncmp (tokstart, tokentab3[i].operator, 3) == 0) { - if (tokentab3[i].cxx_only - && parse_language->la_language != language_cplus) - break; - lexptr += 3; yylval.opcode = tokentab3[i].opcode; return tokentab3[i].token; @@ -2088,10 +2086,6 @@ lex_one_token (void) for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) if (strncmp (tokstart, tokentab2[i].operator, 2) == 0) { - if (tokentab2[i].cxx_only - && parse_language->la_language != language_cplus) - break; - lexptr += 2; yylval.opcode = tokentab2[i].opcode; if (in_parse_field && tokentab2[i].token == ARROW) @@ -2525,8 +2519,7 @@ yylex (void) current.token = lex_one_token (); if (current.token == NAME) current.token = classify_name (expression_context_block); - if (parse_language->la_language != language_cplus - || (current.token != TYPENAME && current.token != COLONCOLON)) + if (current.token != TYPENAME && current.token != COLONCOLON) return current.token; first_was_coloncolon = current.token == COLONCOLON; --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3501,7 +3501,16 @@ value_maybe_namespace_elt (const struct type *curtype, return NULL; else if ((noside == EVAL_AVOID_SIDE_EFFECTS) && (SYMBOL_CLASS (sym) == LOC_TYPEDEF)) - result = allocate_value (SYMBOL_TYPE (sym)); + { + struct type *type = SYMBOL_TYPE (sym); + + /* If this is a typedef, then find its immediate target. We use + check_typedef to resolve stubs, but we ignore its result because we do + not want to dig past all typedefs. */ + check_typedef (type); + type = TYPE_TARGET_TYPE (type); + return allocate_value (type); + } else result = value_of_variable (sym, get_selected_block (0));