293 lines
12 KiB
C#
293 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace System.Diagnostics
|
|
{
|
|
/// <summary>Represents a stack trace, which is an ordered collection of one or more stack frames.</summary>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x02000166 RID: 358
|
|
[MonoTODO("Serialized objects are not compatible with .NET")]
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public class StackTrace
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class from the caller's frame.</summary>
|
|
// Token: 0x06001169 RID: 4457 RVA: 0x00045658 File Offset: 0x00043858
|
|
public StackTrace()
|
|
{
|
|
this.init_frames(0, false);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class from the caller's frame, optionally capturing source information.</summary>
|
|
/// <param name="fNeedFileInfo">true to capture the file name, line number, and column number; otherwise, false. </param>
|
|
// Token: 0x0600116A RID: 4458 RVA: 0x00045668 File Offset: 0x00043868
|
|
public StackTrace(bool fNeedFileInfo)
|
|
{
|
|
this.init_frames(0, fNeedFileInfo);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class from the caller's frame, skipping the specified number of frames.</summary>
|
|
/// <param name="skipFrames">The number of frames up the stack from which to start the trace. </param>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="skipFrames" /> parameter is negative. </exception>
|
|
// Token: 0x0600116B RID: 4459 RVA: 0x00045678 File Offset: 0x00043878
|
|
public StackTrace(int skipFrames)
|
|
{
|
|
this.init_frames(skipFrames, false);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class from the caller's frame, skipping the specified number of frames and optionally capturing source information.</summary>
|
|
/// <param name="skipFrames">The number of frames up the stack from which to start the trace. </param>
|
|
/// <param name="fNeedFileInfo">true to capture the file name, line number, and column number; otherwise, false. </param>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="skipFrames" /> parameter is negative. </exception>
|
|
// Token: 0x0600116C RID: 4460 RVA: 0x00045688 File Offset: 0x00043888
|
|
public StackTrace(int skipFrames, bool fNeedFileInfo)
|
|
{
|
|
this.init_frames(skipFrames, fNeedFileInfo);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class using the provided exception object.</summary>
|
|
/// <param name="e">The exception object from which to construct the stack trace. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The parameter <paramref name="e" /> is null. </exception>
|
|
// Token: 0x0600116D RID: 4461 RVA: 0x00045698 File Offset: 0x00043898
|
|
public StackTrace(Exception e)
|
|
: this(e, 0, false)
|
|
{
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class, using the provided exception object and optionally capturing source information.</summary>
|
|
/// <param name="e">The exception object from which to construct the stack trace. </param>
|
|
/// <param name="fNeedFileInfo">true to capture the file name, line number, and column number; otherwise, false. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The parameter <paramref name="e" /> is null. </exception>
|
|
// Token: 0x0600116E RID: 4462 RVA: 0x000456A4 File Offset: 0x000438A4
|
|
public StackTrace(Exception e, bool fNeedFileInfo)
|
|
: this(e, 0, fNeedFileInfo)
|
|
{
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class using the provided exception object and skipping the specified number of frames.</summary>
|
|
/// <param name="e">The exception object from which to construct the stack trace. </param>
|
|
/// <param name="skipFrames">The number of frames up the stack from which to start the trace. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The parameter <paramref name="e" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="skipFrames" /> parameter is negative. </exception>
|
|
// Token: 0x0600116F RID: 4463 RVA: 0x000456B0 File Offset: 0x000438B0
|
|
public StackTrace(Exception e, int skipFrames)
|
|
: this(e, skipFrames, false)
|
|
{
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class using the provided exception object, skipping the specified number of frames and optionally capturing source information.</summary>
|
|
/// <param name="e">The exception object from which to construct the stack trace. </param>
|
|
/// <param name="skipFrames">The number of frames up the stack from which to start the trace. </param>
|
|
/// <param name="fNeedFileInfo">true to capture the file name, line number, and column number; otherwise, false. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The parameter <paramref name="e" /> is null. </exception>
|
|
/// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="skipFrames" /> parameter is negative. </exception>
|
|
// Token: 0x06001170 RID: 4464 RVA: 0x000456BC File Offset: 0x000438BC
|
|
public StackTrace(Exception e, int skipFrames, bool fNeedFileInfo)
|
|
: this(e, skipFrames, fNeedFileInfo, false)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06001171 RID: 4465 RVA: 0x000456C8 File Offset: 0x000438C8
|
|
internal StackTrace(Exception e, int skipFrames, bool fNeedFileInfo, bool returnNativeFrames)
|
|
{
|
|
if (e == null)
|
|
{
|
|
throw new ArgumentNullException("e");
|
|
}
|
|
if (skipFrames < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException("< 0", "skipFrames");
|
|
}
|
|
this.frames = StackTrace.get_trace(e, skipFrames, fNeedFileInfo);
|
|
if (!returnNativeFrames)
|
|
{
|
|
bool flag = false;
|
|
for (int i = 0; i < this.frames.Length; i++)
|
|
{
|
|
if (this.frames[i].GetMethod() == null)
|
|
{
|
|
flag = true;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
ArrayList arrayList = new ArrayList();
|
|
for (int j = 0; j < this.frames.Length; j++)
|
|
{
|
|
if (this.frames[j].GetMethod() != null)
|
|
{
|
|
arrayList.Add(this.frames[j]);
|
|
}
|
|
}
|
|
this.frames = (StackFrame[])arrayList.ToArray(typeof(StackFrame));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class that contains a single frame.</summary>
|
|
/// <param name="frame">The frame that the <see cref="T:System.Diagnostics.StackTrace" /> object should contain. </param>
|
|
// Token: 0x06001172 RID: 4466 RVA: 0x000457A8 File Offset: 0x000439A8
|
|
public StackTrace(StackFrame frame)
|
|
{
|
|
this.frames = new StackFrame[1];
|
|
this.frames[0] = frame;
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.StackTrace" /> class for a specific thread, optionally capturing source information.</summary>
|
|
/// <param name="targetThread">The thread whose stack trace is requested. </param>
|
|
/// <param name="needFileInfo">true to capture the file name, line number, and column number; otherwise, false. </param>
|
|
/// <exception cref="T:System.Threading.ThreadStateException">The thread <paramref name="targetThread" /> is not suspended. </exception>
|
|
// Token: 0x06001173 RID: 4467 RVA: 0x000457C8 File Offset: 0x000439C8
|
|
[MonoTODO("Not possible to create StackTraces from other threads")]
|
|
public StackTrace(Thread targetThread, bool needFileInfo)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
// Token: 0x06001174 RID: 4468 RVA: 0x000457D8 File Offset: 0x000439D8
|
|
private void init_frames(int skipFrames, bool fNeedFileInfo)
|
|
{
|
|
if (skipFrames < 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException("< 0", "skipFrames");
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
skipFrames += 2;
|
|
StackFrame stackFrame;
|
|
while ((stackFrame = new StackFrame(skipFrames, fNeedFileInfo)) != null && stackFrame.GetMethod() != null)
|
|
{
|
|
arrayList.Add(stackFrame);
|
|
skipFrames++;
|
|
}
|
|
this.debug_info = fNeedFileInfo;
|
|
this.frames = (StackFrame[])arrayList.ToArray(typeof(StackFrame));
|
|
}
|
|
|
|
// Token: 0x06001175 RID: 4469
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern StackFrame[] get_trace(Exception e, int skipFrames, bool fNeedFileInfo);
|
|
|
|
/// <summary>Gets the number of frames in the stack trace.</summary>
|
|
/// <returns>The number of frames in the stack trace. </returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x170002FA RID: 762
|
|
// (get) Token: 0x06001176 RID: 4470 RVA: 0x00045854 File Offset: 0x00043A54
|
|
public virtual int FrameCount
|
|
{
|
|
get
|
|
{
|
|
return (this.frames != null) ? this.frames.Length : 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the specified stack frame.</summary>
|
|
/// <returns>The specified stack frame.</returns>
|
|
/// <param name="index">The index of the stack frame requested. </param>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x06001177 RID: 4471 RVA: 0x00045870 File Offset: 0x00043A70
|
|
public virtual StackFrame GetFrame(int index)
|
|
{
|
|
if (index < 0 || index >= this.FrameCount)
|
|
{
|
|
return null;
|
|
}
|
|
return this.frames[index];
|
|
}
|
|
|
|
/// <summary>Returns a copy of all stack frames in the current stack trace.</summary>
|
|
/// <returns>An array of type <see cref="T:System.Diagnostics.StackFrame" /> representing the function calls in the stack trace.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x06001178 RID: 4472 RVA: 0x00045890 File Offset: 0x00043A90
|
|
[ComVisible(false)]
|
|
public virtual StackFrame[] GetFrames()
|
|
{
|
|
return this.frames;
|
|
}
|
|
|
|
/// <summary>Builds a readable representation of the stack trace.</summary>
|
|
/// <returns>A readable representation of the stack trace.</returns>
|
|
/// <filterpriority>2</filterpriority>
|
|
// Token: 0x06001179 RID: 4473 RVA: 0x00045898 File Offset: 0x00043A98
|
|
public override string ToString()
|
|
{
|
|
string text = string.Format("{0} {1} ", Environment.NewLine, Locale.GetText("at"));
|
|
string text2 = Locale.GetText("<unknown method>");
|
|
string text3 = Locale.GetText(" in {0}:line {1}");
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
for (int i = 0; i < this.FrameCount; i++)
|
|
{
|
|
StackFrame frame = this.GetFrame(i);
|
|
if (i > 0)
|
|
{
|
|
stringBuilder.Append(text);
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.AppendFormat(" {0} ", Locale.GetText("at"));
|
|
}
|
|
MethodBase method = frame.GetMethod();
|
|
if (method != null)
|
|
{
|
|
stringBuilder.AppendFormat("{0}.{1}", method.DeclaringType.FullName, method.Name);
|
|
stringBuilder.Append("(");
|
|
ParameterInfo[] parameters = method.GetParameters();
|
|
for (int j = 0; j < parameters.Length; j++)
|
|
{
|
|
if (j > 0)
|
|
{
|
|
stringBuilder.Append(", ");
|
|
}
|
|
Type type = parameters[j].ParameterType;
|
|
bool isByRef = type.IsByRef;
|
|
if (isByRef)
|
|
{
|
|
type = type.GetElementType();
|
|
}
|
|
if (type.IsClass && type.Namespace != string.Empty)
|
|
{
|
|
stringBuilder.Append(type.Namespace);
|
|
stringBuilder.Append(".");
|
|
}
|
|
stringBuilder.Append(type.Name);
|
|
if (isByRef)
|
|
{
|
|
stringBuilder.Append(" ByRef");
|
|
}
|
|
stringBuilder.AppendFormat(" {0}", parameters[j].Name);
|
|
}
|
|
stringBuilder.Append(")");
|
|
}
|
|
else
|
|
{
|
|
stringBuilder.Append(text2);
|
|
}
|
|
if (this.debug_info)
|
|
{
|
|
string secureFileName = frame.GetSecureFileName();
|
|
if (secureFileName != "<filename unknown>")
|
|
{
|
|
stringBuilder.AppendFormat(text3, secureFileName, frame.GetFileLineNumber());
|
|
}
|
|
}
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
/// <summary>Defines the default for the number of methods to omit from the stack trace. This field is constant.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x0400045C RID: 1116
|
|
public const int METHODS_TO_SKIP = 0;
|
|
|
|
// Token: 0x0400045D RID: 1117
|
|
private StackFrame[] frames;
|
|
|
|
// Token: 0x0400045E RID: 1118
|
|
private bool debug_info;
|
|
}
|
|
}
|