[PATCH] call cp_lookup_symbol_namespace recursively to search symbols in C++ base classes

Pedro Alves pedro@codesourcery.com
Wed Nov 3 00:10:00 GMT 2010


Hi!

I'm looking at this exact problem as well.  :-)

> 2010-11-02  Lei Liu <lei.liu2@windriver.com>
> 
>      * cp-namespace.c (cp_lookup_symbol_namespace): Recursively call
>      itself to search C++ base classes.

> @@ -513,6 +513,8 @@ cp_lookup_symbol_namespace (const char *scope,
>                               const domain_enum domain)
>   {
...
> @@ -530,6 +532,31 @@ cp_lookup_symbol_namespace (const char *scope,
>         block = BLOCK_SUPERBLOCK (block);
>       }
> 
> +  /* If scope is a C++ class, we need to search all its base classes.  */
> +  if (scope == NULL || scope[0] == '\0')
> +    return NULL;

Your testcase is not hitting this empty scope check, due to your
"#include <cstdio>", which does namespace things, and
ends up emitting DW_TAG_namespace in the debug info, and
so dwarf2read.c sets the processing_has_namespace_info
global, and so a "namespace" for you test's class
is installed by:

  /* For C++, set the block's scope.  */
  if (cu->language == language_cplus || cu->language == language_fortran)
    cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
			determine_prefix (die, cu),
			processing_has_namespace_info);

If I remove that include from your test (and the printf), then
the patch no longer works.  We need to do something here.

A related issue that should be addressed as well, I think, is:

 class A {
 public:
   enum E { X, Y, Z };
 };

 A a;

Both "print a.X" and "ptype a.X" should work.  I've got a
patch that fixes this part, and a dejagnuified testcase,
but haven't sorted out the processing_has_namespace_info
part yet.

-- 
Pedro Alves



More information about the Gdb-patches mailing list