RFA: fix macro expansion bug

Pedro Alves pedro@codesourcery.com
Thu Dec 11 23:51:00 GMT 2008


On Thursday 11 December 2008 23:38:19, Tom Tromey wrote:
> >>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:
> 
> >> +gdb_test "macro expand siginfo.si_addr" \
> >> +  "expands to: siginfo. fields.fault.si_addr" \
> 
> Pedro> Just curious, as it's just a visual annoyance: do you know where
> Pedro> this space comes from?  Do we store the definition with the space for
> Pedro> some reason?  We don't get that extra space if the define came
> Pedro> from the code, instead of from a 'macro define'.
> 
> Here's a patch to fix it.
> 
> This requires a minor tweak to the previous patch's test case, but
> otherwise nothing.
> 
> As with the previous, I'm sending this through the regression tester,
> but I don't expect problems.  Ok if it passes?

Looks obvious enough.  Ok if it passes.


Got curious and confirmed that somehow the trailing end
whitespace is stripped already.

(gdb) macro define foo      bar      
                      ^^^^^^   ^^^^^^
(spaces)

(gdb) macro expand a->foo->b
expands to: a->      bar->b
(gdb) 

> 
> Tom
> 
> 2008-12-11  Tom Tromey  <tromey@redhat.com>
> 
> 	* macrocmd.c (macro_define_command): Skip whitespace after
> 	macro name.
> 	(print_one_macro): Print space after macro name.
> 
> diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
> index 56e9a48..fa639d1 100644
> --- a/gdb/macrocmd.c
> +++ b/gdb/macrocmd.c
> @@ -315,13 +315,17 @@ macro_define_command (char *exp, int from_tty)
>  	}
>        /* Skip the closing paren.  */
>        ++exp;
> +      skip_ws (&exp);
>  
>        macro_define_function (macro_main (macro_user_macros), -1, name,
>  			     new_macro.argc, (const char **) new_macro.argv,
>  			     exp);
>      }
>    else
> -    macro_define_object (macro_main (macro_user_macros), -1, name, exp);
> +    {
> +      skip_ws (&exp);
> +      macro_define_object (macro_main (macro_user_macros), -1, name, exp);
> +    }
>  
>    do_cleanups (cleanup_chain);
>  }
> @@ -358,9 +362,7 @@ print_one_macro (const char *name, const struct macro_definition *macro,
>  			  macro->argv[i]);
>        fprintf_filtered (gdb_stdout, ")");
>      }
> -  /* Note that we don't need a leading space here -- "macro define"
> -     provided it.  */
> -  fprintf_filtered (gdb_stdout, "%s\n", macro->replacement);
> +  fprintf_filtered (gdb_stdout, " %s\n", macro->replacement);
>  }
>  
>  
> 



-- 
Pedro Alves



More information about the Gdb-patches mailing list