Ejemplo n.º 1
0
bool
JavaLanguageRuntime::GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic,
                                              TypeAndOrName &class_type_or_name, Address &dynamic_address,
                                              Value::ValueType &value_type)
{
    class_type_or_name.Clear();

    // null references don't have a dynamic type
    if (in_value.IsNilReference())
        return false;

    ExecutionContext exe_ctx(in_value.GetExecutionContextRef());
    Target *target = exe_ctx.GetTargetPtr();
    if (!target)
        return false;

    ConstString linkage_name;
    CompilerType in_type = in_value.GetCompilerType();
    if (in_type.IsPossibleDynamicType(nullptr, false, false))
        linkage_name = GetDynamicTypeId(&exe_ctx, target, in_value);
    else
        linkage_name = JavaASTContext::GetLinkageName(in_type);

    if (!linkage_name)
        return false;

    class_type_or_name.SetName(in_type.GetNonReferenceType().GetTypeName());

    SymbolContext sc;
    TypeList class_types;
    llvm::DenseSet<SymbolFile *> searched_symbol_files;
    size_t num_matches = target->GetImages().FindTypes(sc, linkage_name,
                                                       true, // name_is_fully_qualified
                                                       UINT32_MAX, searched_symbol_files, class_types);

    for (size_t i = 0; i < num_matches; ++i)
    {
        TypeSP type_sp = class_types.GetTypeAtIndex(i);
        CompilerType compiler_type = type_sp->GetFullCompilerType();

        if (compiler_type.GetMinimumLanguage() != eLanguageTypeJava)
            continue;

        if (compiler_type.GetCompleteType() && compiler_type.IsCompleteType())
        {
            class_type_or_name.SetTypeSP(type_sp);

            Value &value = in_value.GetValue();
            value_type = value.GetValueType();
            dynamic_address.SetRawAddress(value.GetScalar().ULongLong(0));
            return true;
        }
    }
    return false;
}