This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Improve handling of Fortran keywords


Nope, this is not going to work. If the identifier being printed is shorter than the keyword, they will match. You really have to check the length as well.

If you want to use namelen, then I think this is the minimum required change.

Greg

*** f-exp.y.orig	2010-12-14 10:28:34.542834692 -0500
--- f-exp.y	2010-12-15 13:49:51.189819361 -0500
***************
*** 1150,1157 ****
    /* Catch specific keywords.  */
    
    for (i = 0; f77_keywords[i].operator != NULL; i++)
!     if (strncmp (tokstart, f77_keywords[i].operator,
! 		 strlen(f77_keywords[i].operator)) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;
--- 1150,1157 ----
    /* Catch specific keywords.  */
    
    for (i = 0; f77_keywords[i].operator != NULL; i++)
!     if (strlen(f77_keywords[i].operator) == namelen &&
!             strncmp (tokstart, f77_keywords[i].operator, namelen) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;


On Dec 14, 2010, at 12:41 PM, Tom Tromey wrote:

>>>>>> "Greg" == Greg Watson <g.watson@computer.org> writes:
> 
> Greg> Currently, gdb 7.2 will not allow me to use identifier names such
> Greg> as "integer_var" as it treats the first "integer" part as a
> Greg> keyword without checking that the identifier is actually longer
> Greg> than the keyword. Here's a simple patch to fix this (and make
> Greg> Fortran debugging more useful).
> 
> Could you try this patch instead?
> 
> I think it should have the same effect, but it is simpler.
> 
> Tom
> 
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index 415819a..487b00d 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1150,8 +1150,7 @@ yylex ()
>   /* Catch specific keywords.  */
> 
>   for (i = 0; f77_keywords[i].operator != NULL; i++)
> -    if (strncmp (tokstart, f77_keywords[i].operator,
> -		 strlen(f77_keywords[i].operator)) == 0)
> +    if (strncmp (tokstart, f77_keywords[i].operator, namelen)) == 0)
>       {
> 	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
> 	yylval.opcode = f77_keywords[i].opcode;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]