/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.DotNet.Evaluation;
using dnSpy.Contracts.Debugger.DotNet.Evaluation.ValueNodes;
using dnSpy.Contracts.Debugger.DotNet.Text;
using dnSpy.Contracts.Debugger.Engine.Evaluation;
using dnSpy.Contracts.Debugger.Evaluation;
using dnSpy.Contracts.Debugger.Text;
using dnSpy.Debugger.DotNet.Metadata;
using dnSpy.Roslyn.Properties;
namespace dnSpy.Roslyn.Debugger.ValueNodes {
sealed class ResultsViewMembersValueNodeProvider : MembersValueNodeProvider {
public override string ImageName => PredefinedDbgValueNodeImageNames.ResultsView;
public override DbgDotNetText ValueText => valueText;
static readonly DbgDotNetText valueText = new DbgDotNetText(new DbgDotNetTextPart(DbgTextColor.Text, dnSpy_Roslyn_Resources.DebuggerVarsWindow_ExpandResultsViewMessage));
static readonly DbgDotNetText resultsViewName = new DbgDotNetText(new DbgDotNetTextPart(DbgTextColor.Text, dnSpy_Roslyn_Resources.DebuggerVarsWindow_ResultsView));
readonly DbgDotNetValueNodeProviderFactory valueNodeProviderFactory;
readonly DmdType enumerableType;
readonly DbgDotNetValue instanceValue;
readonly DmdType expectedType;
readonly string valueExpression;
string resultsViewProxyExpression;
DbgDotNetValue? getResultsViewValue;
public ResultsViewMembersValueNodeProvider(DbgDotNetValueNodeProviderFactory valueNodeProviderFactory, LanguageValueNodeFactory valueNodeFactory, DmdType enumerableType, DbgDotNetValue instanceValue, DmdType expectedType, string valueExpression, DbgValueNodeEvaluationOptions evalOptions)
: base(valueNodeFactory, resultsViewName, valueExpression + ", " + PredefinedFormatSpecifiers.ResultsView, default, evalOptions) {
this.valueNodeProviderFactory = valueNodeProviderFactory;
this.enumerableType = enumerableType;
this.instanceValue = instanceValue;
this.expectedType = expectedType;
this.valueExpression = valueExpression;
resultsViewProxyExpression = string.Empty;
}
sealed class ForceLoadAssemblyState {
public volatile int Counter;
}
protected override string? InitializeCore(DbgEvaluationInfo evalInfo) {
if ((evalOptions & DbgValueNodeEvaluationOptions.NoFuncEval) != 0)
return PredefinedEvaluationErrorMessages.FuncEvalDisabled;
var errorMessage = InitializeEnumerableDebugView(evalInfo);
if (errorMessage is not null) {
if (InitializeListDebugView(evalInfo))
errorMessage = null;
}
return errorMessage;
}
bool InitializeListDebugView(DbgEvaluationInfo evalInfo) {
var info = EnumerableDebugViewHelper.GetListEnumerableMethods(instanceValue.Type, enumerableType);
if (info.ctor is null)
return false;
DbgDotNetValueResult collTypeResult = default;
DbgDotNetValueResult toArrayResult = default;
bool error = true;
try {
var runtime = evalInfo.Runtime.GetDotNetRuntime();
collTypeResult = runtime.CreateInstance(evalInfo, info.ctor, new[] { instanceValue }, DbgDotNetInvokeOptions.None);
if (!collTypeResult.IsNormalResult)
return false;
var expr = valueNodeProviderFactory.GetNewObjectExpression(info.ctor, valueExpression, expectedType);
toArrayResult = runtime.Call(evalInfo, collTypeResult.Value, info.toArrayMethod, Array.Empty