This repository was archived by the owner on Jun 5, 2024. It is now read-only.
forked from benaadams/Ben.Demystifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnhancedStackFrame.cs
114 lines (94 loc) · 4.7 KB
/
EnhancedStackFrame.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Ben A Adams. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Reflection;
namespace Apkd.Internal
{
sealed class EnhancedStackFrame : StackFrame
{
string _fileName;
int _lineNumber;
int _colNumber;
internal StackFrame StackFrame { get; }
internal ResolvedMethod MethodInfo { get; }
internal EnhancedStackFrame(StackFrame stackFrame, ResolvedMethod methodInfo, string fileName, int lineNumber, int colNumber)
: base(fileName, lineNumber, colNumber)
{
StackFrame = stackFrame;
MethodInfo = methodInfo;
_fileName = fileName;
_lineNumber = lineNumber;
_colNumber = colNumber;
}
/// <summary>
/// Gets the column number in the file that contains the code that is executing.
/// This information is typically extracted from the debugging symbols for the executable.
/// </summary>
/// <returns>The file column number, or 0 (zero) if the file column number cannot be determined.</returns>
public override int GetFileColumnNumber() => _colNumber;
/// <summary>
/// Gets the line number in the file that contains the code that is executing.
/// This information is typically extracted from the debugging symbols for the executable.
/// </summary>
/// <returns>The file line number, or 0 (zero) if the file line number cannot be determined.</returns>
public override int GetFileLineNumber() => _lineNumber;
/// <summary>
/// Gets the file name that contains the code that is executing.
/// This information is typically extracted from the debugging symbols for the executable.
/// </summary>
/// <returns>The file name, or null if the file name cannot be determined.</returns>
public override string GetFileName()
{
if (string.IsNullOrWhiteSpace(_fileName))
return null;
return !_fileName.StartsWith(@"C:\buildslave\unity", StringComparison.Ordinal)
? System.IO.Path.GetFileName(_fileName)
: null;
}
internal string GetFullFilename()
{
if (string.IsNullOrWhiteSpace(_fileName))
return null;
int index = _fileName.IndexOf("\\Assets\\", StringComparison.Ordinal);
return index >= 0
? _fileName.Substring(index + 1)
: _fileName;
}
internal StringBuilder AppendFullFilename(StringBuilder sb)
{
if (string.IsNullOrWhiteSpace(_fileName))
return sb;
int index = _fileName.IndexOf("\\Assets\\", StringComparison.Ordinal);
return index >= 0
? sb.Append(_fileName, index + 1)
: sb.Append(_fileName);
}
internal bool IsEmpty => MethodInfo == null;
/// <summary>
/// Gets the offset from the start of the Microsoft intermediate language (MSIL)
/// code for the method that is executing. This offset might be an approximation
/// depending on whether or not the just-in-time (JIT) compiler is generating debugging
/// code. The generation of this debugging information is controlled by the System.Diagnostics.DebuggableAttribute.
/// </summary>
/// <returns>The offset from the start of the MSIL code for the method that is executing.</returns>
public override int GetILOffset() => StackFrame.GetILOffset();
/// <summary>
/// Gets the method in which the frame is executing.
/// </summary>
/// <returns>The method in which the frame is executing.</returns>
public override MethodBase GetMethod() => StackFrame.GetMethod();
/// <summary>
/// Gets the offset from the start of the native just-in-time (JIT)-compiled code
/// for the method that is being executed. The generation of this debugging information
/// is controlled by the System.Diagnostics.DebuggableAttribute class.
/// </summary>
/// <returns>The offset from the start of the JIT-compiled code for the method that is being executed.</returns>
public override int GetNativeOffset() => StackFrame.GetNativeOffset();
/// <summary>
/// Builds a readable representation of the stack trace.
/// </summary>
/// <returns>A readable representation of the stack trace.</returns>
public override string ToString() => MethodInfo.ToString();
}
}