GetNativeOffset() public method

public GetNativeOffset ( ) : int
return int
Example #1
0
		public void Default ()
		{
			StackFrame sf = new StackFrame ();
			Assert.AreEqual (0, sf.GetFileLineNumber (), "GetFileLineNumber");
			Assert.AreEqual (0, sf.GetFileColumnNumber (), "GetFileColumnNumber");
			Assert.IsTrue (sf.GetILOffset () >= 0, "GetILOffset");
			Assert.IsTrue (sf.GetNativeOffset () >= 0, "GetNativeOffset");
			Assert.AreEqual ("Default", sf.GetMethod ().Name, "GetMethod");
		}
Example #2
0
		public void FileName_LineNumber_ColumnNumber ()
		{
			StackFrame sf = new StackFrame (String.Empty, Int32.MinValue, Int32.MaxValue);
			Assert.AreEqual (Int32.MinValue, sf.GetFileLineNumber (), "GetFileLineNumber");
			Assert.AreEqual (Int32.MaxValue, sf.GetFileColumnNumber (), "GetFileColumnNumber");
			Assert.IsTrue (sf.GetILOffset () >= 0, "GetILOffset");
			Assert.IsTrue (sf.GetNativeOffset () > 0, "GetNativeOffset");
			Assert.AreEqual ("FileName_LineNumber_ColumnNumber", sf.GetMethod ().Name, "GetMethod");
		}
 /// <summary>
 /// Creates a new instance of the <see cref="WcfRawJson.ErrorHandling.FaultStackFrame"/> 
 /// class from an existing <see cref="System.Diagnostics.StackFrame"/>.
 /// </summary>
 /// <param name="frame">
 /// The <see cref="System.Diagnostics.StackFrame"/> object from which to derive this
 /// <see cref="WcfRawJson.ErrorHandling.StackFrame"/>
 /// </param>
 public FaultStackFrame(StackFrame frame)
 {
     this.FileColumnNumber = frame.GetFileColumnNumber();
     this.FileLineNumber = frame.GetFileLineNumber();
     this.FileName = frame.GetFileName();
     this.ILOffset = frame.GetILOffset();
     this.Method = frame.GetMethod().ToString();
     this.NativeOffset = frame.GetNativeOffset();
     this.Description = frame.ToString();
 }
Example #4
0
		// avoid replication of tests on all constructors (this is no 
		// problem because the stack is already set correctly). The 
		// goal is to call every property and methods to see if they
		// have any* security requirements (*except for LinkDemand and
		// InheritanceDemand).
		private void Check (StackFrame sf, bool checkFile)
		{
			int cn = sf.GetFileColumnNumber ();
			int ln = sf.GetFileLineNumber ();
			int il = sf.GetILOffset ();
			int no = sf.GetNativeOffset ();

			Assert.IsNotNull (sf.GetMethod (), "GetMethod");

			if (checkFile) {
				string fn = sf.GetFileName ();
			}
		}
Example #5
0
        public static string FormatLocation(StackFrame frame)
        {
            StringBuilder location = new StringBuilder();

            location.Append(frame.GetMethod().DeclaringType.ToString());
            location.Append("=>");
            location.Append(frame.GetMethod().ToString());
            location.Append(" [");
            location.Append(frame.GetILOffset());
            location.Append(":");
            location.Append(frame.GetNativeOffset());
            location.Append("]");

            return location.ToString();
        }
 public static string StackFrameToString(StackFrame stackFrame)
 {
     StringBuilder sb = new StringBuilder();
     int intParam; MemberInfo mi = stackFrame.GetMethod();
     sb.Append("   ");
     sb.Append(mi.DeclaringType.Namespace);
     sb.Append(".");
     sb.Append(mi.DeclaringType.Name);
     sb.Append(".");
     sb.Append(mi.Name);
     // -- build method params           
     sb.Append("(");
     intParam = 0;
     foreach (ParameterInfo param in stackFrame.GetMethod().GetParameters())
     {
         intParam += 1;
         sb.Append(param.Name);
         sb.Append(" As ");
         sb.Append(param.ParameterType.Name);
     }
     sb.Append(")");
     sb.Append(Environment.NewLine);
     // -- if source code is available, append location info           
     sb.Append("       ");
     if (string.IsNullOrEmpty(stackFrame.GetFileName()))
     {
         sb.Append("(unknown file)");
         //-- native code offset is always available               
         sb.Append(": N ");
         sb.Append(string.Format("{0:#00000}", stackFrame.GetNativeOffset()));
     }
     else
     {
         sb.Append(Path.GetFileName(stackFrame.GetFileName()));
         sb.Append(": line ");
         sb.Append(string.Format("{0:#0000}", stackFrame.GetFileLineNumber()));
         sb.Append(", col ");
         sb.Append(string.Format("{0:#00}", stackFrame.GetFileColumnNumber()));
         if (stackFrame.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
         {
             sb.Append(", IL ");
             sb.Append(string.Format("{0:#0000}", stackFrame.GetILOffset()));
         }
     }
     sb.Append(Environment.NewLine);
     return sb.ToString();
 }
Example #7
0
        public static StackFrame Create(System.Diagnostics.StackFrame frame)
        {
            if (frame == null)
            {
                return(null);
            }

            string      fileName      = null;
            bool        isTaskAwaiter = false;
            ITypeMember member        = null;

            try {
                fileName = frame.GetFileName();
            } catch (SecurityException) {
                // CAS check failure
            }

            var method = frame.GetMethod();

            if (method != null)
            {
                isTaskAwaiter = method.DeclaringType.IsTaskAwaiter() ||
                                method.DeclaringType.DeclaringType.IsTaskAwaiter();

                var property = GetPropertyForMethodAccessor(method);
                if (property != null)
                {
                    member = Property.Create(property);
                }
                else
                {
                    member = Method.Create(method);
                }
            }

            return(new StackFrame(
                       fileName,
                       frame.GetFileLineNumber(),
                       frame.GetFileColumnNumber(),
                       frame.GetILOffset(),
                       frame.GetNativeOffset(),
                       frame.GetMethodAddress(),
                       frame.GetMethodIndex(),
                       isTaskAwaiter,
                       ParseInternalMethodName(frame.GetInternalMethodName()),
                       member));
        }
Example #8
0
        public override bool Equals(Object obj)
        {
            if ((obj == null) || (!(obj is StackFrame)))
            {
                return(false);
            }

            StackFrame rhs = (StackFrame)obj;

            if (!ObjectsEqual(GetMethod(), rhs.GetMethod()))
            {
                return(false);
            }

            if (!ObjectsEqual(GetFileName(), rhs.GetFileName()))
            {
                return(false);
            }

            if (GetFileLineNumber() != rhs.GetFileLineNumber())
            {
                return(false);
            }

            if (GetFileColumnNumber() != rhs.GetFileColumnNumber())
            {
                return(false);
            }

            if (GetILOffset() != rhs.GetILOffset())
            {
                return(false);
            }

            if (GetNativeOffset() != rhs.GetNativeOffset())
            {
                return(false);
            }

            return(true);
        }
Example #9
0
        bool AddFrames(StringBuilder sb)
        {
            bool   printOffset;
            string debugInfo, indentation;
            string unknown = Locale.GetText("<unknown method>");

            indentation = "  ";
            debugInfo   = Locale.GetText(" in {0}:{1} ");

            var newline = String.Format("{0}{1}{2} ", Environment.NewLine, indentation,
                                        Locale.GetText("at"));

            int i;

            for (i = 0; i < FrameCount; i++)
            {
                StackFrame frame = GetFrame(i);
                if (i == 0)
                {
                    sb.AppendFormat("{0}{1} ", indentation, Locale.GetText("at"));
                }
                else
                {
                    sb.Append(newline);
                }

                if (frame.GetMethod() == null)
                {
                    string internal_name = frame.GetInternalMethodName();
                    if (internal_name != null)
                    {
                        sb.Append(internal_name);
                    }
                    else
                    {
                        sb.AppendFormat("<0x{0:x5} + 0x{1:x5}> {2}", frame.GetMethodAddress(), frame.GetNativeOffset(), unknown);
                    }
                }
                else
                {
                    GetFullNameForStackTrace(sb, frame.GetMethod());

                    if (frame.GetILOffset() == -1)
                    {
                        sb.AppendFormat(" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress(), frame.GetNativeOffset());
                        if (frame.GetMethodIndex() != 0xffffff)
                        {
                            sb.AppendFormat(" {0}", frame.GetMethodIndex());
                        }
                    }
                    else
                    {
                        sb.AppendFormat(" [0x{0:x5}]", frame.GetILOffset());
                    }

                    sb.AppendFormat(debugInfo, frame.GetSecureFileName(),
                                    frame.GetFileLineNumber());
                }
            }

            return(i != 0);
        }
        //--
        //-- turns a single stack frame object into an informative string
        //--
        private static string StackFrameToString(StackFrame sf)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int intParam = 0;
            MemberInfo mi = sf.GetMethod();

            var _with1 = sb;
            //-- build method name
            _with1.Append("   ");
            _with1.Append(mi.DeclaringType.Namespace);
            _with1.Append(".");
            _with1.Append(mi.DeclaringType.Name);
            _with1.Append(".");
            _with1.Append(mi.Name);

            //-- build method params
            ParameterInfo[] objParameters = sf.GetMethod().GetParameters();
            ParameterInfo objParameter = null;
            _with1.Append("(");
            intParam = 0;
            foreach (ParameterInfo objParameter_loopVariable in objParameters)
            {
                objParameter = objParameter_loopVariable;
                intParam += 1;
                if (intParam > 1)
                    _with1.Append(", ");
                _with1.Append(objParameter.Name);
                _with1.Append(" As ");
                _with1.Append(objParameter.ParameterType.Name);
            }
            _with1.Append(")");
            _with1.Append(Environment.NewLine);

            //-- if source code is available, append location info
            _with1.Append("       ");
            if (sf.GetFileName() == null || sf.GetFileName().Length == 0)
            {
                _with1.Append(System.IO.Path.GetFileName(ParentAssembly().CodeBase));
                //-- native code offset is always available
                _with1.Append(": N ");
                _with1.Append(string.Format("{0:#00000}", sf.GetNativeOffset()));
            }
            else
            {
                _with1.Append(System.IO.Path.GetFileName(sf.GetFileName()));
                _with1.Append(": line ");
                _with1.Append(string.Format("{0:#0000}", sf.GetFileLineNumber()));
                _with1.Append(", col ");
                _with1.Append(string.Format("{0:#00}", sf.GetFileColumnNumber()));
                //-- if IL is available, append IL location info
                if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
                {
                    _with1.Append(", IL ");
                    _with1.Append(string.Format("{0:#0000}", sf.GetILOffset()));
                }
            }
            _with1.Append(Environment.NewLine);
            return sb.ToString();
        }
 /// <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();
        private static string StackFrameToString(StackFrame sf)
        {
            var sb = new StringBuilder();
            MemberInfo mi = sf.GetMethod();

            sb.Append("   ");
            sb.Append(mi.DeclaringType.Namespace);
            sb.Append(".");
            sb.Append(mi.DeclaringType.Name);
            sb.Append(".");
            sb.Append(mi.Name);
            
            var objParameters = sf.GetMethod().GetParameters();
            sb.Append("(");
            
            var intParam = 0;
            
            foreach (var objParameter in objParameters)
            {
                intParam++;
                if (intParam > 1)
                {
                    sb.Append(", ");
                }
                sb.Append(objParameter.Name);
                sb.Append(" As ");
                sb.Append(objParameter.ParameterType.Name);
            }
            sb.Append(")");
            sb.Append(Environment.NewLine);
            sb.Append("       ");
            if ((sf.GetFileName() == null) || (sf.GetFileName().Length == 0))
            {
                sb.Append(Path.GetFileName(ParentAssembly().CodeBase));
                sb.Append(": N ");
                sb.Append(string.Format("{0:#00000}", sf.GetNativeOffset()));
            }
            else
            {
                sb.Append(Path.GetFileName(sf.GetFileName()));
                sb.Append(": line ");
                sb.Append(string.Format("{0:#0000}", sf.GetFileLineNumber()));
                sb.Append(", col ");
                sb.Append(string.Format("{0:#00}", sf.GetFileColumnNumber()));
                if (sf.GetILOffset() != -1)
                {
                    sb.Append(", IL ");
                    sb.Append(string.Format("{0:#0000}", sf.GetILOffset()));
                }
            }
            sb.Append(Environment.NewLine);
            
            return sb.ToString();
        }
 /// <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()
 {
     return(StackFrame.GetNativeOffset());
 }
Example #14
0
 private static string StackFrameToString(StackFrame sf, ref string errorFrom)
 {
     StringBuilder sb = new StringBuilder();
     int intParam;
     MemberInfo mi = sf.GetMethod();
     Type type = mi.DeclaringType;
     string namspace = type.Namespace ?? string.Empty;
     if (namspace.Equals("ExamineSystem.utility.eslog"))
     {
         return sb.ToString();
     }
     if (string.IsNullOrEmpty(errorFrom))
     {
         try
         {
             if (type.IsSubclassOf(typeof(System.Web.UI.Page)))
             {
                 errorFrom = type.FullName;
             }
             else if (type.IsSubclassOf(typeof(System.Web.UI.Control)))
             {
                 errorFrom = type.FullName;
             }
             else if (type.GetInterface("System.Web.IHttpHandler") != null)
             {
                 errorFrom = type.FullName;
             }
             else if (type.GetInterface("System.Web.IHttpAsyncHandler") != null)
             {
                 errorFrom = type.FullName;
             }
             else if (type.GetInterface("System.Web.IHttpModule") != null)
             {
                 errorFrom = type.FullName;
             }
             else if (type.GetInterface("System.Web.IHttpHandlerFactory") != null)
             {
                 errorFrom = type.FullName;
             }
         }
         catch (Exception)
         {
             errorFrom = string.Empty;
         }
     }
     sb.Append("   ");
     sb.Append(namspace);
     sb.Append(".");
     sb.Append(type.Name);
     sb.Append(".");
     sb.Append(mi.Name);
     // -- build method params
     sb.Append("(");
     intParam = 0;
     foreach (ParameterInfo param in sf.GetMethod().GetParameters())
     {
         if (intParam > 0)
             sb.Append(" , ");
         sb.Append(param.Name);
         sb.Append(" As ");
         sb.Append(param.ParameterType.Name);
         intParam += 1;
     }
     sb.Append(")");
     sb.Append(Environment.NewLine);
     // -- if source code is available, append location info
     sb.Append("       ");
     if (string.IsNullOrEmpty(sf.GetFileName()))
     {
         sb.Append("(unknown file)");
         //-- native code offset is always available
         sb.Append(": N ");
         sb.Append(String.Format("{0:#00000}", sf.GetNativeOffset()));
     }
     else
     {
         sb.Append(System.IO.Path.GetFileName(sf.GetFileName()));
         sb.Append(": line ");
         sb.Append(String.Format("{0:#0000}", sf.GetFileLineNumber()));
         sb.Append(", col ");
         sb.Append(String.Format("{0:#00}", sf.GetFileColumnNumber()));
         if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
         {
             sb.Append(", IL ");
             sb.Append(String.Format("{0:#0000}", sf.GetILOffset()));
         }
     }
     sb.Append(Environment.NewLine);
     return sb.ToString();
 }
        private static string StackFrameToString(StackFrame sf)
        {
            int intParam = 0;
            var sb = new StringBuilder();

            MemberInfo mi = sf.GetMethod();
            {
                //-- build method name
                sb.Append(" ");
                sb.Append(mi.DeclaringType.Namespace);
                sb.Append(".");
                sb.Append(mi.DeclaringType.Name);
                sb.Append(".");
                sb.Append(mi.Name);

                //-- build method params
                ParameterInfo[] objParameters = sf.GetMethod().GetParameters();
                sb.Append("(");
                intParam = 0;
                foreach (var objParameter in objParameters)
                {
                    intParam += 1;
                    if (intParam > 1) sb.Append(", ");
                    sb.Append(objParameter.Name);
                    sb.Append(" As ");
                    sb.Append(objParameter.ParameterType.Name);
                }
                sb.Append(")");
                sb.Append(Environment.NewLine);

                //-- if source code is available, append location info
                sb.Append(" ");

                if (string.IsNullOrEmpty(sf.GetFileName()))
                {
                    sb.Append(Path.GetFileName(GetParentAssembly().CodeBase));

                    //-- native code offset is always available
                    sb.Append(": N ");
                    sb.Append(string.Format("{0:#00000}", sf.GetNativeOffset()));
                }
                else
                {
                    sb.Append(Path.GetFileName(sf.GetFileName()));
                    sb.Append(": line ");
                    sb.Append(string.Format("{0:#0000}", sf.GetFileLineNumber()));
                    sb.Append(", col ");
                    sb.Append(string.Format("{0:#00}", sf.GetFileColumnNumber()));

                    //-- if IL is available, append IL location info
                    if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
                    {
                        sb.Append(", IL ");
                        sb.Append(string.Format("{0:#0000}", sf.GetILOffset()));
                    }
                }

                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }
        private static string StackFrameToString(StackFrame sf)
        {
            var sb = new StringBuilder();
            MemberInfo mi = sf.GetMethod();

            sb.AppendFormat("   {0}.{1}.{2}",
                mi.DeclaringType.Namespace,
                mi.DeclaringType.Name,
                mi.Name);

            ParameterInfo[] parameters = sf.GetMethod().GetParameters();
            sb.Append("(");
            sb.Append(String.Join(", ", parameters.Select(p => String.Format("{0} {1}", p.ParameterType.Name, p.Name)).ToArray()));
            sb.Append(")");
            sb.AppendLine();

            sb.Append("       ");
            if (String.IsNullOrEmpty(sf.GetFileName()))
            {
                sb.Append(Path.GetFileName(ParentAssembly.CodeBase));
                sb.Append(": N ");
                sb.AppendFormat("{0:#00000}", sf.GetNativeOffset());
            }
            else
            {
                sb.Append(Path.GetFileName(sf.GetFileName()));
                sb.AppendFormat(": line {0:#0000}, col {1:#00}", sf.GetFileLineNumber(), sf.GetFileColumnNumber());
                if (sf.GetILOffset() != StackFrame.OFFSET_UNKNOWN)
                {
                    sb.AppendFormat(", IL {0:#0000}", sf.GetILOffset());
                }
            }
            sb.AppendLine();

            return sb.ToString();
        }
        bool AddFrames(StringBuilder sb)
        {
            bool any_frame = false;

            for (int i = 0; i < FrameCount; i++)
            {
                StackFrame frame = GetFrame(i);

                if (frame.GetMethod() == null)
                {
                    if (any_frame)
                    {
                        sb.Append(Environment.NewLine);
                    }
                    sb.Append(prefix);

                    string internal_name = frame.GetInternalMethodName();
                    if (internal_name != null)
                    {
                        sb.Append(internal_name);
                    }
                    else
                    {
                        sb.AppendFormat("<0x{0:x5} + 0x{1:x5}> <unknown method>", frame.GetMethodAddress(), frame.GetNativeOffset());
                    }
                }
                else
                {
                    GetFullNameForStackTrace(sb, frame.GetMethod(), any_frame, out var skipped);
                    if (skipped)
                    {
                        continue;
                    }

                    if (frame.GetILOffset() == -1)
                    {
                        sb.AppendFormat(" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress(), frame.GetNativeOffset());
                        if (frame.GetMethodIndex() != 0xffffff)
                        {
                            sb.AppendFormat(" {0}", frame.GetMethodIndex());
                        }
                    }
                    else
                    {
                        sb.AppendFormat(" [0x{0:x5}]", frame.GetILOffset());
                    }

                    var filename = frame.GetSecureFileName();
                    if (filename[0] == '<')
                    {
                        var mvid  = frame.GetMethod().Module.ModuleVersionId.ToString("N");
                        var aotid = GetAotId();
                        if (frame.GetILOffset() != -1 || aotid == null)
                        {
                            filename = string.Format("<{0}>", mvid);
                        }
                        else
                        {
                            filename = string.Format("<{0}#{1}>", mvid, aotid);
                        }
                    }

                    sb.AppendFormat(" in {0}:{1} ", filename, frame.GetFileLineNumber());
                }

                any_frame = true;
            }

            return(any_frame);
        }
Example #18
0
 private string SourceCodeInformation(StackFrame frame)
 {
     if (String.IsNullOrEmpty(frame.GetFileName()))
         return Path.GetFileName(_assemblyInfo.CodeBase) + ": N " + frame.GetNativeOffset();
     return Path.GetFileName(frame.GetFileName()) + ": line " + frame.GetFileLineNumber()
        + ", col " + frame.GetFileColumnNumber() + ", IL " + frame.GetILOffset();
 }