Skip to content

Commit

Permalink
Rename files, classes, remove Core from .NET Core
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Nov 11, 2020
1 parent e6221ed commit 45716af
Show file tree
Hide file tree
Showing 65 changed files with 555 additions and 551 deletions.
2 changes: 1 addition & 1 deletion DnSpyCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<Import Project="$(MSBuildThisFileDirectory)Build\ConvertToNetstandardReferences\ConvertToNetstandardReferences.tasks" Condition=" '$(IsDotNet)' == 'true' " />

<!-- .NET Core 3.0 SDK doesn't currently support COMReference: https://github.com/dnSpy/dnSpy/issues/1053 -->
<!-- .NET 5.0 SDK doesn't currently support COMReference: https://github.com/dnSpy/dnSpy/issues/1053 -->
<PropertyGroup>
<HasCOMReference>false</HasCOMReference>
<HasCOMReference Condition=" '$(MSBuildRuntimeType)' != 'Core' ">true</HasCOMReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ You should have received a copy of the GNU General Public License
using dnSpy.Debugger.DotNet.CorDebug.Utilities;

namespace dnSpy.Debugger.DotNet.CorDebug.Dialogs.AttachToProcess {
[ExportAttachProgramOptionsProviderFactory(PredefinedAttachProgramOptionsProviderNames.DotNetCore)]
sealed class DotNetCoreAttachProgramOptionsProviderFactory : AttachProgramOptionsProviderFactory {
public override AttachProgramOptionsProvider? Create(bool allFactories) => new DotNetCoreAttachProgramOptionsProvider();
[ExportAttachProgramOptionsProviderFactory(PredefinedAttachProgramOptionsProviderNames.DotNet)]
sealed class DotNetAttachProgramOptionsProviderFactory : AttachProgramOptionsProviderFactory {
public override AttachProgramOptionsProvider? Create(bool allFactories) => new DotNetAttachProgramOptionsProvider();
}

sealed class DotNetCoreAttachProgramOptionsProvider : AttachProgramOptionsProvider {
sealed class DotNetAttachProgramOptionsProvider : AttachProgramOptionsProvider {
public override IEnumerable<AttachProgramOptions> Create(AttachProgramOptionsProviderContext context) {
foreach (var process in DebuggableProcesses.GetProcesses(context.ProcessIds, context.IsValidProcess, context.CancellationToken)) {
foreach (var info in TryGetCoreCLRInfos(process)) {
Expand All @@ -43,34 +43,34 @@ public override IEnumerable<AttachProgramOptions> Create(AttachProgramOptionsPro
}
}

IEnumerable<DotNetCoreAttachProgramOptions> TryGetCoreCLRInfos(Process process) {
IEnumerable<DotNetAttachProgramOptions> TryGetCoreCLRInfos(Process process) {
// We can only debug processes with the same bitness
int bitness = IntPtr.Size * 8;
var dbgShimFilename = DotNetCoreHelpers.GetDebugShimFilename(bitness);
var dbgShimFilename = DotNetHelpers.GetDebugShimFilename(bitness);
foreach (var ccInfo in CoreCLRHelper.GetCoreCLRInfos(process.Id, null, dbgShimFilename))
yield return new DotNetCoreAttachProgramOptions(process.Id, ccInfo.CoreCLRTypeInfo.Version, ccInfo.CoreCLRTypeInfo.CoreCLRFilename);
yield return new DotNetAttachProgramOptions(process.Id, ccInfo.CoreCLRTypeInfo.Version, ccInfo.CoreCLRTypeInfo.CoreCLRFilename);
}
}

sealed class DotNetCoreAttachProgramOptions : AttachProgramOptions {
sealed class DotNetAttachProgramOptions : AttachProgramOptions {
public override int ProcessId { get; }
public override RuntimeId RuntimeId { get; }
public override string RuntimeName { get; }
public override Guid RuntimeGuid => PredefinedDbgRuntimeGuids.DotNetCore_Guid;
public override Guid RuntimeGuid => PredefinedDbgRuntimeGuids.DotNet_Guid;
public override Guid RuntimeKindGuid => PredefinedDbgRuntimeKindGuids.DotNet_Guid;

readonly string? clrModuleVersion;
readonly string? coreCLRFilename;

public DotNetCoreAttachProgramOptions(int pid, string? clrModuleVersion, string? coreCLRFilename) {
public DotNetAttachProgramOptions(int pid, string? clrModuleVersion, string? coreCLRFilename) {
ProcessId = pid;
RuntimeId = new DotNetCoreRuntimeId(clrModuleVersion);
RuntimeId = new DotNetRuntimeId(clrModuleVersion);
RuntimeName = "CoreCLR " + clrModuleVersion;
this.clrModuleVersion = clrModuleVersion;
this.coreCLRFilename = coreCLRFilename;
}

public override AttachToProgramOptions GetOptions() => new DotNetCoreAttachToProgramOptions {
public override AttachToProgramOptions GetOptions() => new DotNetAttachToProgramOptions {
ProcessId = ProcessId,
ClrModuleVersion = clrModuleVersion,
CoreCLRFilename = coreCLRFilename,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
Copyright (C) 2014-2019 [email protected]
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 <http://www.gnu.org/licenses/>.
*/

using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Input;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.DotNet.CorDebug;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
using dnSpy.Contracts.MVVM;
using dnSpy.Debugger.DotNet.CorDebug.Properties;

namespace dnSpy.Debugger.DotNet.CorDebug.Dialogs.DebugProgram {
abstract class DotNetCommonStartDebuggingOptionsPage : StartDebuggingOptionsPage, IDataErrorInfo {
public override object? UIObject => this;

public string Filename {
get => filename;
set {
if (filename != value) {
filename = value;
OnPropertyChanged(nameof(Filename));
UpdateIsValid();
var path = GetPath(filename);
if (!(path is null))
WorkingDirectory = path;
}
}
}
string filename = string.Empty;

public string CommandLine {
get => commandLine;
set {
if (commandLine != value) {
commandLine = value;
OnPropertyChanged(nameof(CommandLine));
UpdateIsValid();
}
}
}
string commandLine = string.Empty;

public string WorkingDirectory {
get => workingDirectory;
set {
if (workingDirectory != value) {
workingDirectory = value;
OnPropertyChanged(nameof(WorkingDirectory));
UpdateIsValid();
}
}
}
string workingDirectory = string.Empty;

public ICommand PickFilenameCommand => new RelayCommand(a => PickNewFilename());
public ICommand PickWorkingDirectoryCommand => new RelayCommand(a => PickNewWorkingDirectory());

public EnumListVM BreakProcessKindVM => breakProcessKindVM;
readonly EnumListVM breakProcessKindVM = new EnumListVM(BreakProcessKindsUtils.BreakProcessKindList);

public string BreakKind {
get => (string)BreakProcessKindVM.SelectedItem!;
set => BreakProcessKindVM.SelectedItem = value;
}

public override bool IsValid => isValid;
bool isValid;

protected void UpdateIsValid() {
var newIsValid = CalculateIsValid();
if (newIsValid == isValid)
return;
isValid = newIsValid;
OnPropertyChanged(nameof(IsValid));
}

protected abstract bool CalculateIsValid();

protected readonly IPickFilename pickFilename;
readonly IPickDirectory pickDirectory;

protected DotNetCommonStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory) {
this.pickFilename = pickFilename ?? throw new ArgumentNullException(nameof(pickFilename));
this.pickDirectory = pickDirectory ?? throw new ArgumentNullException(nameof(pickDirectory));
}

static string? GetPath(string file) {
try {
return Path.GetDirectoryName(file);
}
catch {
}
return null;
}

protected static void Initialize(string filename, CorDebugStartDebuggingOptions options) {
options.Filename = filename;
options.WorkingDirectory = GetPath(options.Filename);
}

protected abstract void PickNewFilename();

void PickNewWorkingDirectory() {
var newDir = pickDirectory.GetDirectory(WorkingDirectory);
if (newDir is null)
return;

WorkingDirectory = newDir;
}

static string FilterBreakKind(string? breakKind) {
foreach (var info in BreakProcessKindsUtils.BreakProcessKindList) {
if (StringComparer.Ordinal.Equals(breakKind, (string)info.Value))
return breakKind!;
}
return PredefinedBreakKinds.DontBreak;
}

protected void Initialize(CorDebugStartDebuggingOptions options) {
Filename = options.Filename ?? string.Empty;
CommandLine = options.CommandLine ?? string.Empty;
// Must be init'd after Filename since it also overwrites this property
WorkingDirectory = options.WorkingDirectory ?? string.Empty;
BreakKind = FilterBreakKind(options.BreakKind);
}

protected T InitializeDefault<T>(T options, string breakKind) where T : CorDebugStartDebuggingOptions {
options.BreakKind = FilterBreakKind(breakKind);
return options;
}

protected T GetOptions<T>(T options) where T : CorDebugStartDebuggingOptions {
options.Filename = Filename;
options.CommandLine = CommandLine;
options.WorkingDirectory = WorkingDirectory;
options.BreakKind = FilterBreakKind(BreakKind);
return options;
}

string IDataErrorInfo.Error => throw new NotImplementedException();
string IDataErrorInfo.this[string columnName] => Verify(columnName);

protected static string VerifyFilename(string filename) {
if (!File.Exists(filename)) {
if (string.IsNullOrWhiteSpace(filename))
return dnSpy_Debugger_DotNet_CorDebug_Resources.Error_MissingFilename;
return dnSpy_Debugger_DotNet_CorDebug_Resources.Error_FileDoesNotExist;
}
return string.Empty;
}

protected abstract string Verify(string columnName);
}
}
Loading

0 comments on commit 45716af

Please sign in to comment.