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: [PATCH v2 2/2] Fix gdb.base/completion.exp with --target_board=dwarf4-gdb-index


Pedro Alves <palves@redhat.com> writes:

> -  /* Find the symtab for SRCFILE (this loads it if it was not yet read
> -     in).  */
> -  s = lookup_symtab (srcfile);
> -  if (s == NULL)
> +  /* Go through symtabs for SRCFILE and check the externs and statics
> +     for symbols which match.  */
> +  iterate_over_symtabs (srcfile, [&] (symtab *s)
>      {
> -      /* Maybe they typed the file with leading directories, while the
> -	 symbol tables record only its basename.  */
> -      const char *tail = lbasename (srcfile);
> -
> -      if (tail > srcfile)
> -	s = lookup_symtab (tail);
> -    }
> -
> -  /* If we have no symtab for that file, return an empty list.  */
> -  if (s == NULL)
> -    return (return_val);

In the original code, lookup_symtab is called twice, and if we inline
lookup_symtab here, the change in this patch is more readable.

Let us inline lookup_symtab first, the code becomes,

  s = NULL;
  iterate_over_symtabs (srcfile, [&] (symtab *symtab)
    {
      s = symtab;

      add_symtab_completions (SYMTAB_COMPUNIT (s),
			      sym_text, sym_text_len,
			      text, word, TYPE_CODE_UNDEF);
      return true;
    });

  if (s == NULL)
    {
      /* Maybe they typed the file with leading directories, while the
	 symbol tables record only its basename.  */
      const char *tail = lbasename (srcfile);

      if (tail > srcfile)
	iterate_over_symtabs (tail, [&] (symtab *symtab)
			      {
				s = symtab;

				add_symtab_completions (SYMTAB_COMPUNIT (s),
							sym_text, sym_text_len,
							text, word, TYPE_CODE_UNDEF);
				return true;
			      });
    }


then, as you described in commit log, we have to iterate all symtabs
rather than stop on the first matched symtab.  We need to replace
"return true;" with "return false;" above.  Presumably, this replacement
will fix the fails in completion.exp.

Then, it turns out that the whole block "if (s == NULL) {...}" is
removed by this patch.  I'll dig deep to see this block is still needed
or not.

-- 
Yao (齐尧)


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