예제 #1
0
ValueObjectSP
GoUserExpression::GoInterpreter::VisitIndexExpr(const lldb_private::GoASTIndexExpr *e)
{
    ValueObjectSP target = EvaluateExpr(e->GetX());
    if (!target)
        return nullptr;
    ValueObjectSP index = EvaluateExpr(e->GetIndex());
    if (!index)
        return nullptr;
    bool is_signed;
    if (!index->GetCompilerType().IsIntegerType(is_signed))
    {
        m_error.SetErrorString("Unsupported index");
        return nullptr;
    }
    size_t idx;
    if (is_signed)
        idx = index->GetValueAsSigned(0);
    else
        idx = index->GetValueAsUnsigned(0);
    if (GoASTContext::IsGoSlice(target->GetCompilerType()))
    {
        target = target->GetStaticValue();
        ValueObjectSP cap = target->GetChildMemberWithName(ConstString("cap"), true);
        if (cap)
        {
            uint64_t capval = cap->GetValueAsUnsigned(0);
            if (idx >= capval)
            {
                m_error.SetErrorStringWithFormat("Invalid index %" PRIu64 " , cap = %" PRIu64, uint64_t(idx), capval);
                return nullptr;
            }
        }
        target = target->GetChildMemberWithName(ConstString("array"), true);
        if (target && m_use_dynamic != eNoDynamicValues)
        {
            ValueObjectSP dynamic = target->GetDynamicValue(m_use_dynamic);
            if (dynamic)
                target = dynamic;
        }
        if (!target)
            return nullptr;
        return target->GetSyntheticArrayMember(idx, true);
    }
    return target->GetChildAtIndex(idx, true);
}
예제 #2
0
bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
  static ConstString g___value_("__value_");
  static ConstString g_tree_("__tree_");
  static ConstString g_pair3("__pair3_");

  if (m_element_type.GetOpaqueQualType() && m_element_type.GetTypeSystem())
    return true;
  m_element_type.Clear();
  ValueObjectSP deref;
  Status error;
  deref = m_root_node->Dereference(error);
  if (!deref || error.Fail())
    return false;
  deref = deref->GetChildMemberWithName(g___value_, true);
  if (deref) {
    m_element_type = deref->GetCompilerType();
    return true;
  }
  deref = m_backend.GetChildAtNamePath({g_tree_, g_pair3});
  if (!deref)
    return false;
  m_element_type = deref->GetCompilerType()
                       .GetTypeTemplateArgument(1)
                       .GetTypeTemplateArgument(1);
  if (m_element_type) {
    std::string name;
    uint64_t bit_offset_ptr;
    uint32_t bitfield_bit_size_ptr;
    bool is_bitfield_ptr;
    m_element_type = m_element_type.GetFieldAtIndex(
        0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
    m_element_type = m_element_type.GetTypedefedType();
    return m_element_type.IsValid();
  } else {
    m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0);
    return m_element_type.IsValid();
  }
}
예제 #3
0
ValueObjectSP
GoUserExpression::GoInterpreter::VisitSelectorExpr(const lldb_private::GoASTSelectorExpr *e)
{
    ValueObjectSP target = EvaluateExpr(e->GetX());
    if (target)
    {
        if (target->GetCompilerType().IsPointerType())
        {
            target = target->Dereference(m_error);
            if (m_error.Fail())
                return nullptr;
        }
        ConstString field(e->GetSel()->GetName().m_value);
        ValueObjectSP result = target->GetChildMemberWithName(field, true);
        if (!result)
            m_error.SetErrorStringWithFormat("Unknown child %s", field.AsCString());
        return result;
    }
    if (const GoASTIdent *package = llvm::dyn_cast<GoASTIdent>(e->GetX()))
    {
        if (VariableSP global = FindGlobalVariable(m_exe_ctx.GetTargetSP(),
                                                   package->GetName().m_value + "." + e->GetSel()->GetName().m_value))
        {
            if (m_frame)
            {
                m_error.Clear();
                return m_frame->GetValueObjectForFrameVariable(global, m_use_dynamic);
            }
        }
    }
    if (const GoASTBasicLit *packageLit = llvm::dyn_cast<GoASTBasicLit>(e->GetX()))
    {
        if (packageLit->GetValue().m_type == GoLexer::LIT_STRING)
        {
            std::string value = packageLit->GetValue().m_value.str();
            value = value.substr(1, value.size() - 2);
            if (VariableSP global =
                    FindGlobalVariable(m_exe_ctx.GetTargetSP(), value + "." + e->GetSel()->GetName().m_value))
            {
                if (m_frame)
                {
                    m_error.Clear();
                    return m_frame->TrackGlobalVariable(global, m_use_dynamic);
                }
            }
        }
    }
    // EvaluateExpr should have already set m_error.
    return target;
}
예제 #4
0
파일: LibCxxMap.cpp 프로젝트: Arhzi/lldb
bool
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType()
{
    if (m_element_type.GetOpaqueQualType() && m_element_type.GetTypeSystem())
        return true;
    m_element_type.Clear();
    ValueObjectSP deref;
    Error error;
    deref = m_root_node->Dereference(error);
    if (!deref || error.Fail())
        return false;
    deref = deref->GetChildMemberWithName(ConstString("__value_"), true);
    if (!deref)
        return false;
    m_element_type = deref->GetCompilerType();
    return true;
}
예제 #5
0
ValueObjectSP
GoUserExpression::GoInterpreter::VisitUnaryExpr(const GoASTUnaryExpr *e) {
  ValueObjectSP x = EvaluateExpr(e->GetX());
  if (!x)
    return nullptr;
  switch (e->GetOp()) {
  case GoLexer::OP_AMP: {
    CompilerType type = x->GetCompilerType().GetPointerType();
    uint64_t address = x->GetAddressOf();
    return ValueObject::CreateValueObjectFromAddress(nullptr, address,
                                                     m_exe_ctx, type);
  }
  case GoLexer::OP_PLUS:
    return x;
  default:
    m_error.SetErrorStringWithFormat(
        "Operator %s not supported",
        GoLexer::LookupToken(e->GetOp()).str().c_str());
    return nullptr;
  }
}
예제 #6
0
bool
SwiftREPL::PrintOneVariable (Debugger &debugger,
                             StreamFileSP &output_sp,
                             ValueObjectSP &valobj_sp,
                             ExpressionVariable *var)
{
    bool is_computed = false;
    
    if (var)
    {
        if (lldb::ValueObjectSP valobj_sp = var->GetValueObject())
        {
            Flags valobj_type_flags(valobj_sp->GetCompilerType().GetTypeInfo());
            const bool is_swift(valobj_type_flags.AllSet(eTypeIsSwift));
            if ((var->GetName().AsCString("anonymous")[0] != '$') &&
                is_swift)
            {
                is_computed = llvm::cast<SwiftExpressionVariable>(var)->GetIsComputed();
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
        
    const bool colorize_out = output_sp->GetFile().GetIsTerminalWithColors();

    bool handled = false;
    
    Format format = m_format_options.GetFormat();
    
    bool treat_as_void = (format == eFormatVoid);
    // if we are asked to suppress void, check if this is the empty tuple type, and if so suppress it
    if (!treat_as_void && !debugger.GetNotifyVoid())
    {
        const CompilerType &expr_type(valobj_sp->GetCompilerType());
        Flags expr_type_flags(expr_type.GetTypeInfo());
        if (expr_type_flags.AllSet(eTypeIsSwift | eTypeIsTuple))
        {
            treat_as_void = (expr_type.GetNumFields() == 0);
        }
    }
    
    if (!treat_as_void)
    {
        if (format != eFormatDefault)
            valobj_sp->SetFormat (format);
        
        DumpValueObjectOptions options;
        options.SetUseDynamicType(lldb::eDynamicCanRunTarget);
        options.SetMaximumPointerDepth( {DumpValueObjectOptions::PointerDepth::Mode::Formatters,1} );
        options.SetUseSyntheticValue(true);
        options.SetRevealEmptyAggregates(false);
        options.SetHidePointerValue(true);
        options.SetVariableFormatDisplayLanguage(lldb::eLanguageTypeSwift);
	options.SetDeclPrintingHelper ([] (ConstString type_name,
               ConstString var_name,
               const DumpValueObjectOptions &options,
               Stream &stream) -> bool {
      		   if (!type_name || !var_name)
			return false;

		   std::string type_name_str(type_name ? type_name.GetCString() : "");
                   for(auto iter = type_name_str.find(" *");
                       iter != std::string::npos;
                       iter = type_name_str.find(" *"))
                   {
                       type_name_str.erase(iter, 2);
                   }
                   if (!type_name_str.empty())
                   {
		       stream.Printf("%s: %s =", var_name.GetCString(), type_name_str.c_str());	
		       return true;
		   }
                       
                   return false;
               });
        
        if (is_computed)
        {
            StringSummaryFormat::Flags flags;
            flags.SetDontShowChildren(true);
            flags.SetDontShowValue(true);
            flags.SetHideItemNames(true);
            flags.SetShowMembersOneLiner(false);
            flags.SetSkipPointers(false);
            flags.SetSkipReferences(false);
            options.SetHideValue(true);
            options.SetShowSummary(true);
            options.SetSummary(lldb::TypeSummaryImplSP(new StringSummaryFormat(flags,"<computed property>")));
        }
        
        if (colorize_out)
        {
            const char *color = isThrownError(valobj_sp) ?
                ANSI_ESCAPE1(ANSI_FG_COLOR_RED) : ANSI_ESCAPE1(ANSI_FG_COLOR_CYAN);
            fprintf(output_sp->GetFile().GetStream(), "%s", color);
        }
        
        valobj_sp->Dump(*output_sp, options);
        
        if (colorize_out)
            fprintf(output_sp->GetFile().GetStream(), ANSI_ESCAPE1(ANSI_CTRL_NORMAL));
        
        handled = true;
    }
    
    return handled;
}