|
| 1 | +// Copyright (c) Ben A Adams. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Reflection; |
| 5 | + |
| 6 | +namespace System.Diagnostics |
| 7 | +{ |
| 8 | + public class EnhancedStackFrame : StackFrame |
| 9 | + { |
| 10 | + private string _fileName; |
| 11 | + private int _lineNumber; |
| 12 | + private int _colNumber; |
| 13 | + |
| 14 | + public StackFrame StackFrame { get; } |
| 15 | + |
| 16 | + public ResolvedMethod MethodInfo { get; } |
| 17 | + |
| 18 | + internal EnhancedStackFrame(StackFrame stackFrame, ResolvedMethod methodInfo, string fileName, int lineNumber, int colNumber) |
| 19 | + : base(fileName, lineNumber, colNumber) |
| 20 | + { |
| 21 | + StackFrame = stackFrame; |
| 22 | + MethodInfo = methodInfo; |
| 23 | + |
| 24 | + _fileName = fileName; |
| 25 | + _lineNumber = lineNumber; |
| 26 | + _colNumber = colNumber; |
| 27 | + } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Gets the column number in the file that contains the code that is executing. |
| 31 | + /// This information is typically extracted from the debugging symbols for the executable. |
| 32 | + /// </summary> |
| 33 | + /// <returns>The file column number, or 0 (zero) if the file column number cannot be determined.</returns> |
| 34 | + public override int GetFileColumnNumber() => _colNumber; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Gets the line number in the file that contains the code that is executing. |
| 38 | + /// This information is typically extracted from the debugging symbols for the executable. |
| 39 | + /// </summary> |
| 40 | + /// <returns>The file line number, or 0 (zero) if the file line number cannot be determined.</returns> |
| 41 | + public override int GetFileLineNumber() => _lineNumber; |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Gets the file name that contains the code that is executing. |
| 45 | + /// This information is typically extracted from the debugging symbols for the executable. |
| 46 | + /// </summary> |
| 47 | + /// <returns>The file name, or null if the file name cannot be determined.</returns> |
| 48 | + public override string GetFileName() => _fileName; |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Gets the offset from the start of the Microsoft intermediate language (MSIL) |
| 52 | + /// code for the method that is executing. This offset might be an approximation |
| 53 | + /// depending on whether or not the just-in-time (JIT) compiler is generating debugging |
| 54 | + /// code. The generation of this debugging information is controlled by the System.Diagnostics.DebuggableAttribute. |
| 55 | + /// </summary> |
| 56 | + /// <returns>The offset from the start of the MSIL code for the method that is executing.</returns> |
| 57 | + public override int GetILOffset() => StackFrame.GetILOffset(); |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Gets the method in which the frame is executing. |
| 61 | + /// </summary> |
| 62 | + /// <returns>The method in which the frame is executing.</returns> |
| 63 | + public override MethodBase GetMethod() => StackFrame.GetMethod(); |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Gets the offset from the start of the native just-in-time (JIT)-compiled code |
| 67 | + /// for the method that is being executed. The generation of this debugging information |
| 68 | + /// is controlled by the System.Diagnostics.DebuggableAttribute class. |
| 69 | + /// </summary> |
| 70 | + /// <returns>The offset from the start of the JIT-compiled code for the method that is being executed.</returns> |
| 71 | + public override int GetNativeOffset() => StackFrame.GetNativeOffset(); |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Builds a readable representation of the stack trace. |
| 75 | + /// </summary> |
| 76 | + /// <returns>A readable representation of the stack trace.</returns> |
| 77 | + public override string ToString() => MethodInfo.ToString(); |
| 78 | + } |
| 79 | +} |
0 commit comments