From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9860 invoked by alias); 12 Feb 2013 16:59:46 -0000 Received: (qmail 9832 invoked by uid 22791); 12 Feb 2013 16:59:43 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Feb 2013 16:59:36 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1U5JCh-00060F-7N from Hafiz_Abid@mentor.com ; Tue, 12 Feb 2013 08:59:35 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 12 Feb 2013 08:59:34 -0800 Received: from abidh-ubunto1104 (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server (TLS) id 14.1.289.1; Tue, 12 Feb 2013 16:59:32 +0000 Date: Tue, 12 Feb 2013 16:59:00 -0000 From: Hafiz Abid Qadeer Subject: [patch[ Improve the error messages of tvariable command To: , Message-ID: <1360688372.8583.1@abidh-ubunto1104> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-KDZxDFNQfBAWiisDXGgm" 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: 2013-02/txt/msg00277.txt.bz2 --=-KDZxDFNQfBAWiisDXGgm Content-Type: text/plain; charset="us-ascii"; delsp=Yes; format=Flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1819 Hi All, This patch improves the error message of tvariable command. The=20=20 difference in error messages in various cases is shown below. This=20=20 patch was originally written by Pedro. I have updated it to latest code=20= =20 and regtested. Is it ok? Regards, Abid Before the patch: (gdb) start Temporary breakpoint 1 at 0x80483ba: file test.c, line 3. Starting program: /home/abidh/test Temporary breakpoint 1, main () at test.c:3 3 int x =3D 1; (gdb) list 1 int main() 2 { 3 int x =3D 1; 4 return 0; 5 } (gdb) tvar x Syntax must be $NAME [ =3D EXPR ] (gdb) tvar y No symbol "y" in current context. (gdb) tvar $ Syntax must be $NAME [ =3D EXPR ] (gdb) tvar $1234 Syntax must be $NAME [ =3D EXPR ] After the patch: (gdb) start Temporary breakpoint 1 at 0x80483ba: file test.c, line 3. Starting program: /home/abidh/test Temporary breakpoint 1, main () at test.c:3 3 int x =3D 1; (gdb) list 1 int main() 2 { 3 int x =3D 1; 4 return 0; 5 } (gdb) tvar x Name of trace variable should start with '$' (gdb) tvar y Name of trace variable should start with '$' (gdb) tvar $ Must supply a non-empty variable name (gdb) tvar $1234 $1234 is not a valid trace state variable name (gdb) tvar $asdf=3D1=3D1 Left operand of assignment is not an lvalue. 2013-02-12 Pedro Alves Hafiz Abid Qadeer gdb/ * tracepoint.h (validate_trace_state_variable_name): Declare. * tracepoint.c (validate_trace_state_variable_name): New. (trace_variable_command): Parse the trace state variable's name without using parse_expression. Do several validations. * mi/mi-main.c (mi_cmd_trace_define_variable): Don't parse the trace state variable's name with parse_expression. Validate it. gdb/testsuite/ * gdb.trace/tsv.exp: Adjust tests, and add a few more. --=-KDZxDFNQfBAWiisDXGgm Content-Type: text/x-patch; charset="us-ascii"; name="tvar.patch" Content-Disposition: attachment; filename="tvar.patch" Content-Transfer-Encoding: quoted-printable Content-length: 6699 diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 28de126aa..37294e0 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2357,7 +2357,6 @@ void mi_cmd_trace_define_variable (char *command, char **argv, int argc) { struct expression *expr; - struct cleanup *back_to; LONGEST initval =3D 0; struct trace_state_variable *tsv; char *name =3D 0; @@ -2365,19 +2364,11 @@ mi_cmd_trace_define_variable (char *command, char *= *argv, int argc) if (argc !=3D 1 && argc !=3D 2) error (_("Usage: -trace-define-variable VARIABLE [VALUE]")); =20 - expr =3D parse_expression (argv[0]); - back_to =3D make_cleanup (xfree, expr); - - if (expr->nelts =3D=3D 3 && expr->elts[0].opcode =3D=3D OP_INTERNALVAR) - { - struct internalvar *intvar =3D expr->elts[1].internalvar; - - if (intvar) - name =3D internalvar_name (intvar); - } + name =3D argv[0]; + if (*name++ !=3D '$') + error (_("Name of trace variable should start with '$'")); =20 - if (!name || *name =3D=3D '\0') - error (_("Invalid name of trace variable")); + validate_trace_state_variable_name (name); =20 tsv =3D find_trace_state_variable (name); if (!tsv) @@ -2387,8 +2378,6 @@ mi_cmd_trace_define_variable (char *command, char **a= rgv, int argc) initval =3D value_as_long (parse_and_eval (argv[1])); =20 tsv->initial_value =3D initval; - - do_cleanups (back_to); } =20 void diff --git a/gdb/testsuite/gdb.trace/tsv.exp b/gdb/testsuite/gdb.trace/tsv.= exp index 4ea930f..47d66ad 100644 --- a/gdb/testsuite/gdb.trace/tsv.exp +++ b/gdb/testsuite/gdb.trace/tsv.exp @@ -46,14 +46,30 @@ gdb_test "tvariable \$tvar3 =3D 1234567000000" \ "Trace state variable \\\$tvar3 now has initial value 1234567000000." \ "Init trace state variable to a 64-bit value" =20 +gdb_test "tvariable $" \ + "Must supply a non-empty variable name" \ + "tvariable syntax error, not empty variable name" + gdb_test "tvariable main" \ - "Syntax must be \\\$NAME \\\[ =3D EXPR \\\]" \ + "Name of trace variable should start with '\\\$'" \ "tvariable syntax error, bad name" =20 +gdb_test "tvariable \$\$" \ + "Syntax must be \\\$NAME \\\[ =3D EXPR \\\]" \ + "tvariable syntax error, bad name 2" + +gdb_test "tvariable \$123" \ + "\\\$123 is not a valid trace state variable name" \ + "tvariable syntax error, bad name 3" + gdb_test "tvariable \$tvar1 - 93" \ "Syntax must be \\\$NAME \\\[ =3D EXPR \\\]" \ "tvariable syntax error, not an assignment" =20 +gdb_test "tvariable \$tvar0 =3D 1 =3D 1" \ + "Left operand of assignment is not an lvalue\." \ + "tvariable creation fails with invalid expression" + gdb_test "info tvariables" \ "Name\[\t \]+Initial\[\t \]+Current.* \\\$tvar1\[\t \]+0\[\t \]+.* diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index b45863e..540665d 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -362,50 +362,67 @@ delete_trace_state_variable (const char *name) warning (_("No trace variable named \"$%s\", not deleting"), name); } =20 +/* Throws an error if NAME is not valid syntax for a trace state + variable's name. */ + +void +validate_trace_state_variable_name (const char *name) +{ + const char *p; + + if (*name =3D=3D '\0') + error (_("Must supply a non-empty variable name")); + + /* All digits in the name is reserved for value history + references. */ + for (p =3D name; isdigit (*p); p++) + ; + if (*p =3D=3D '\0') + error (_("$%s is not a valid trace state variable name"), name); + + for (p =3D name; isalnum (*p) || *p =3D=3D '_'; p++) + ; + if (*p !=3D '\0') + error (_("$%s is not a valid trace state variable name"), name); +} + /* The 'tvariable' command collects a name and optional expression to evaluate into an initial value. */ =20 static void trace_variable_command (char *args, int from_tty) { - struct expression *expr; struct cleanup *old_chain; - struct internalvar *intvar =3D NULL; LONGEST initval =3D 0; struct trace_state_variable *tsv; + char *name, *p; =20 if (!args || !*args) - error_no_arg (_("trace state variable name")); + error_no_arg (_("Syntax is $NAME [ =3D EXPR ]")); =20 - /* All the possible valid arguments are expressions. */ - expr =3D parse_expression (args); - old_chain =3D make_cleanup (free_current_contents, &expr); + /* Only allow two syntaxes; "$name" and "$name=3Dvalue". */ + p =3D skip_spaces (args); =20 - if (expr->nelts =3D=3D 0) - error (_("No expression?")); + if (*p++ !=3D '$') + error (_("Name of trace variable should start with '$'")); =20 - /* Only allow two syntaxes; "$name" and "$name=3Dvalue". */ - if (expr->elts[0].opcode =3D=3D OP_INTERNALVAR) - { - intvar =3D expr->elts[1].internalvar; - } - else if (expr->elts[0].opcode =3D=3D BINOP_ASSIGN - && expr->elts[1].opcode =3D=3D OP_INTERNALVAR) - { - intvar =3D expr->elts[2].internalvar; - initval =3D value_as_long (evaluate_subexpression_type (expr, 4)); - } - else + name =3D p; + while (isalnum (*p) || *p =3D=3D '_') + p++; + name =3D savestring (name, p - name); + old_chain =3D make_cleanup (xfree, name); + + p =3D skip_spaces (p); + if (*p !=3D '=3D' && *p !=3D '\0') error (_("Syntax must be $NAME [ =3D EXPR ]")); =20 - if (!intvar) - error (_("No name given")); + validate_trace_state_variable_name (name); =20 - if (strlen (internalvar_name (intvar)) <=3D 0) - error (_("Must supply a non-empty variable name")); + if (*p =3D=3D '=3D') + initval =3D value_as_long (parse_and_eval (++p)); =20 /* If the variable already exists, just change its initial value. */ - tsv =3D find_trace_state_variable (internalvar_name (intvar)); + tsv =3D find_trace_state_variable (name); if (tsv) { if (tsv->initial_value !=3D initval) @@ -421,7 +438,7 @@ trace_variable_command (char *args, int from_tty) } =20 /* Create a new variable. */ - tsv =3D create_trace_state_variable (internalvar_name (intvar)); + tsv =3D create_trace_state_variable (name); tsv->initial_value =3D initval; =20 observer_notify_tsv_created (tsv); diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index 2e1d83a..61c7212 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -246,6 +246,7 @@ extern void validate_actionline (char **, struct breakp= oint *); =20 extern void end_actions_pseudocommand (char *args, int from_tty); extern void while_stepping_pseudocommand (char *args, int from_tty); +extern void validate_trace_state_variable_name (const char *name); =20 extern struct trace_state_variable *find_trace_state_variable (const char = *name); extern struct trace_state_variable *create_trace_state_variable (const cha= r *name); --=-KDZxDFNQfBAWiisDXGgm--