From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14778 invoked by alias); 9 Feb 2005 10:16:50 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 14206 invoked from network); 9 Feb 2005 10:16:25 -0000 Received: from unknown (HELO mail.codesourcery.com) (65.74.133.9) by sourceware.org with SMTP; 9 Feb 2005 10:16:25 -0000 Received: (qmail 11449 invoked from network); 9 Feb 2005 10:16:24 -0000 Received: from localhost (HELO ?192.168.189.167?) (nathan@127.0.0.1) by mail.codesourcery.com with SMTP; 9 Feb 2005 10:16:24 -0000 Message-ID: <4209E2F1.2000504@codesourcery.com> Date: Wed, 09 Feb 2005 13:37:00 -0000 From: Nathan Sidwell Organization: Codesourcery LLC User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [PATCH] Unary plus Content-Type: multipart/mixed; boundary="------------000605060209000807080902" X-SW-Source: 2005-02/txt/msg00048.txt.bz2 This is a multi-part message in MIME format. --------------000605060209000807080902 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 448 Hi, gdb doesn't parse or evaluate the unary plus operator (but does have one). gdb.trace/collection.exp contains such an expression -- 'a[+b]'. This patch adds the necessary parsing and evaluation machinery. built & tested on i686-px-linux-gnu and an unreleased architecture. ok? nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk --------------000605060209000807080902 Content-Type: text/plain; name="unop_plus.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="unop_plus.patch" Content-length: 4363 2005-02-09 Nathan Sidwell * ax-gdb.c (gen_expr): Add UNOP_PLUS case. * c-exp.y (exp): Add unary plus. * eval.c (evaluate_subexp_standard): Add UNOP_PLUS case. * valarith.c (value_pos): New. * value.h (value_pos): Declare. Index: ax-gdb.c =================================================================== RCS file: /cvs/src/src/gdb/ax-gdb.c,v retrieving revision 1.27 diff -c -3 -p -r1.27 ax-gdb.c *** ax-gdb.c 29 Jan 2005 17:53:25 -0000 1.27 --- ax-gdb.c 9 Feb 2005 09:55:10 -0000 *************** gen_expr (union exp_element **pc, struct *** 1642,1647 **** --- 1642,1654 ---- } break; + case UNOP_PLUS: + (*pc)++; + /* + FOO is equivalent to 0 + FOO, which can be optimized. */ + gen_expr (pc, ax, value); + gen_usual_unary (ax, value); + break; + case UNOP_NEG: (*pc)++; /* -FOO is equivalent to 0 - FOO. */ Index: c-exp.y =================================================================== RCS file: /cvs/src/src/gdb/c-exp.y,v retrieving revision 1.28 diff -c -3 -p -r1.28 c-exp.y *** c-exp.y 7 Aug 2004 19:45:45 -0000 1.28 --- c-exp.y 9 Feb 2005 09:55:11 -0000 *************** exp : '-' exp %prec UNARY *** 256,261 **** --- 256,265 ---- { write_exp_elt_opcode (UNOP_NEG); } ; + exp : '+' exp %prec UNARY + { write_exp_elt_opcode (UNOP_PLUS); } + ; + exp : '!' exp %prec UNARY { write_exp_elt_opcode (UNOP_LOGICAL_NOT); } ; Index: eval.c =================================================================== RCS file: /cvs/src/src/gdb/eval.c,v retrieving revision 1.49 diff -c -3 -p -r1.49 eval.c *** eval.c 7 Feb 2005 00:09:53 -0000 1.49 --- eval.c 9 Feb 2005 09:55:16 -0000 *************** evaluate_subexp_standard (struct type *e *** 1854,1859 **** --- 1854,1868 ---- evaluate_subexp (NULL_TYPE, exp, pos, noside); return evaluate_subexp (NULL_TYPE, exp, pos, noside); + case UNOP_PLUS: + arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); + if (noside == EVAL_SKIP) + goto nosideret; + if (unop_user_defined_p (op, arg1)) + return value_x_unop (arg1, op, noside); + else + return value_pos (arg1); + case UNOP_NEG: arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); if (noside == EVAL_SKIP) Index: valarith.c =================================================================== RCS file: /cvs/src/src/gdb/valarith.c,v retrieving revision 1.35 diff -c -3 -p -r1.35 valarith.c *** valarith.c 7 Feb 2005 15:04:43 -0000 1.35 --- valarith.c 9 Feb 2005 09:55:25 -0000 *************** value_less (struct value *arg1, struct v *** 1313,1319 **** } } ! /* The unary operators - and ~. Both free the argument ARG1. */ struct value * value_neg (struct value *arg1) --- 1313,1349 ---- } } ! /* The unary operators +, - and ~. They free the argument ARG1 ! (unless it is returned). */ ! ! struct value * ! value_pos (struct value *arg1) ! { ! struct type *type; ! ! arg1 = coerce_ref (arg1); ! ! type = check_typedef (value_type (arg1)); ! ! if (TYPE_CODE (type) == TYPE_CODE_FLT) ! return arg1; ! else if (is_integral_type (type)) ! { ! /* Perform integral promotion for ANSI C/C++. FIXME: What about ! FORTRAN and (the deleted) chill ? */ ! if (TYPE_LENGTH (type) >= TYPE_LENGTH (builtin_type_int)) ! return arg1; ! ! type = builtin_type_int; ! ! return value_from_longest (type, value_as_long (arg1)); ! } ! else ! { ! error ("Argument to positive operation not a number."); ! return 0; /* For lint -- never reached */ ! } ! } struct value * value_neg (struct value *arg1) Index: value.h =================================================================== RCS file: /cvs/src/src/gdb/value.h,v retrieving revision 1.72 diff -c -3 -p -r1.72 value.h *** value.h 7 Feb 2005 15:04:43 -0000 1.72 --- value.h 9 Feb 2005 09:55:26 -0000 *************** extern struct value *value_addr (struct *** 332,337 **** --- 332,339 ---- extern struct value *value_assign (struct value *toval, struct value *fromval); + extern struct value *value_pos (struct value *arg1); + extern struct value *value_neg (struct value *arg1); extern struct value *value_complement (struct value *arg1); --------------000605060209000807080902--