-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathDumpTargetFactory.cs
More file actions
58 lines (53 loc) · 2.23 KB
/
DumpTargetFactory.cs
File metadata and controls
58 lines (53 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Diagnostics.Runtime;
namespace Microsoft.Diagnostics.DebugServices.Implementation
{
public sealed class DumpTargetFactory(IHost host) : IDumpTargetFactory
{
private readonly IHost _host = host;
public ITarget OpenDump(string fileName)
{
DataTarget dataTarget;
OSPlatform targetPlatform;
try
{
fileName = Path.GetFullPath(fileName);
dataTarget = DataTarget.LoadDump(fileName);
targetPlatform = dataTarget.DataReader.TargetPlatform;
}
catch (Exception ex)
{
throw new DiagnosticsException(ex.Message, ex);
}
try
{
// Cross-platform dump analysis is allowed when using cDAC-only mode (ForceUseContractReader)
// because the cDAC is a host-native NativeAOT binary that can analyze dumps from any platform.
ISettingsService settingsService = _host.Services.GetService<ISettingsService>();
bool allowCrossPlatform = settingsService?.ForceUseContractReader == true;
if (!allowCrossPlatform)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && (targetPlatform != OSPlatform.OSX))
{
throw new NotSupportedException("Analyzing Windows or Linux dumps not supported when running on MacOS");
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && (targetPlatform != OSPlatform.Linux))
{
throw new NotSupportedException("Analyzing Windows or MacOS dumps not supported when running on Linux");
}
}
return new TargetFromDataReader(dataTarget, targetPlatform, _host, fileName);
}
catch (Exception)
{
dataTarget.Dispose();
throw;
}
}
}
}