예제 #1
0
  bool DoExecute(Args &command, CommandReturnObject &result) override {
    Thread *thread = m_exe_ctx.GetThreadPtr();
    StackFrameSP frame_sp = thread->GetSelectedFrame();

    ValueObjectSP valobj_sp;

    if (m_options.address.hasValue()) {
      if (m_options.reg.hasValue() || m_options.offset.hasValue()) {
        result.AppendError(
            "`frame diagnose --address` is incompatible with other arguments.");
        result.SetStatus(eReturnStatusFailed);
        return false;
      }
      valobj_sp = frame_sp->GuessValueForAddress(m_options.address.getValue());
    } else if (m_options.reg.hasValue()) {
      valobj_sp = frame_sp->GuessValueForRegisterAndOffset(
          m_options.reg.getValue(), m_options.offset.getValueOr(0));
    } else {
      StopInfoSP stop_info_sp = thread->GetStopInfo();
      if (!stop_info_sp) {
        result.AppendError("No arguments provided, and no stop info.");
        result.SetStatus(eReturnStatusFailed);
        return false;
      }

      valobj_sp = StopInfo::GetCrashingDereference(stop_info_sp);
    }

    if (!valobj_sp) {
      result.AppendError("No diagnosis available.");
      result.SetStatus(eReturnStatusFailed);
      return false;
    }

    const bool qualify_cxx_base_classes = false;

    DumpValueObjectOptions::DeclPrintingHelper helper =
        [&valobj_sp, qualify_cxx_base_classes](
            ConstString type, ConstString var,
            const DumpValueObjectOptions &opts, Stream &stream) -> bool {
      const ValueObject::GetExpressionPathFormat format = ValueObject::
          GetExpressionPathFormat::eGetExpressionPathFormatHonorPointers;
      valobj_sp->GetExpressionPath(stream, qualify_cxx_base_classes, format);
      stream.PutCString(" =");
      return true;
    };

    DumpValueObjectOptions options;
    options.SetDeclPrintingHelper(helper);
    ValueObjectPrinter printer(valobj_sp.get(), &result.GetOutputStream(),
                               options);
    printer.PrintValueObject();

    return true;
  }
DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
    LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
    lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
  DumpValueObjectOptions options;
  options.SetMaximumPointerDepth(
      {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
  if (use_objc)
    options.SetShowSummary(false);
  else
    options.SetOmitSummaryDepth(no_summary_depth);
  options.SetMaximumDepth(max_depth)
      .SetShowTypes(show_types)
      .SetShowLocation(show_location)
      .SetUseObjectiveC(use_objc)
      .SetUseDynamicType(use_dynamic)
      .SetUseSyntheticValue(use_synth)
      .SetFlatOutput(flat_output)
      .SetIgnoreCap(ignore_cap)
      .SetFormat(format)
      .SetSummary(summary_sp);

  if (lang_descr_verbosity ==
      eLanguageRuntimeDescriptionDisplayVerbosityCompact)
    options.SetHideRootType(use_objc).SetHideName(use_objc).SetHideValue(
        use_objc);

  if (be_raw)
    options.SetRawDisplay();

  options.SetRunValidator(run_validator);

  options.SetElementCount(elem_count);

  return options;
}
예제 #3
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;
}