[lldb-dev] lock() fails on my lldb::Type

Nat! via lldb-dev lldb-dev at lists.llvm.org
Sat Jul 9 11:10:24 PDT 2016


 From the looks of it, lldb uses 
`ObjCLanguageRuntime::LookupInCompleteClassCache` to create a lldb::Type 
for an Objective C class, by looking through the modules. In my 
circumstances (one being on Linux), it doesn't find a symbol for the 
class and puts my classname into `m_negative_complete_class_cache`. 
Which is no good for me.

I try to fix this by looking through my DeclVendor, check if a class is 
defined in the runtime, and if yes I create a substitute lldb::Type.

``
        DeclVendor *vendor = GetDeclVendor();
        if( vendor)
        {
          std::vector<clang::NamedDecl*> decls;
          uint32_t  count = vendor->FindDecls( name, false, 1, decls);

          if( count)
          {
              if (clang::ObjCInterfaceDecl *interface_decl = 
llvm::dyn_cast<clang::ObjCInterfaceDecl>( decls[ 0]))
              {
                 CompilerType compiler_type = 
ClangASTContext::GetTypeForDecl(interface_decl);
                 Declaration whatever;
                 Type   *type = new Type(  LLDB_INVALID_UID,
                                           NULL,
                                           name,
                                           1024, // just ... 
 

                                           NULL,
                                           LLDB_INVALID_UID,
                                           Type::eEncodingIsUID,
                                           whatever,
                                           compiler_type,
                                           Type::eResolveStateFull);
                  TypeSP  p_type( type);

                  p_type->SetIsCompleteObjCClass( true);
                  m_complete_class_cache[ name] = p_type;

                  return( p_type);
               }
            }
        }
     }
     m_negative_complete_class_cache.insert(name);
     return TypeSP();
}
```

This doesn't fail outright, but the next time LookupInCompleteClassCache 
is called, the codes does this `lock()` with my cached type and fails:

```
        TypeSP complete_type_sp (complete_class_iter->second.lock());

         if (complete_type_sp)
             return complete_type_sp;
```

Then the code will create a duplicate type. So what do I have to do, so 
that my lldb::Type doesn't return NULL when lock() is called ?

Nat!



More information about the lldb-dev mailing list