Merge pull request #2819 from BrzVlad/fix-major-log
[mono.git] / mcs / class / corlib / System.Diagnostics / StackFrame.cs
index e254347d1fb3b2dde8670b16877160e77e251f44..702cd540d976d92e34dbce66fc2e116a679f2603 100644 (file)
@@ -34,18 +34,14 @@ using System.Runtime.CompilerServices;
 using System.Security;
 using System.Security.Permissions;
 using System.Text;
-
-#if NET_2_0
 using System.Runtime.InteropServices;
-#endif
 
 namespace System.Diagnostics {
 
        [Serializable]
-#if NET_2_0
        [ComVisible (true)]
-#endif
        [MonoTODO ("Serialized objects are not compatible with MS.NET")]
+       [StructLayout (LayoutKind.Sequential)]
         public class StackFrame {
 
                 public const int OFFSET_UNKNOWN = -1;
@@ -53,6 +49,8 @@ namespace System.Diagnostics {
                #region Keep in sync with object-internals.h
                private int ilOffset = OFFSET_UNKNOWN;
                private int nativeOffset = OFFSET_UNKNOWN;
+               private long methodAddress;
+               private uint methodIndex;
                private MethodBase methodBase;
                private string fileName;
                private int lineNumber;
@@ -131,7 +129,7 @@ namespace System.Diagnostics {
                 
                 public virtual string GetFileName()
                 {
-#if NET_2_0
+#if !NET_2_1
                        if (SecurityManager.SecurityEnabled && (fileName != null) && (fileName.Length > 0)) {
                                string fn = Path.GetFullPath (fileName);
                                new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fn).Demand ();
@@ -139,15 +137,26 @@ namespace System.Diagnostics {
 #endif
                         return fileName;
                 }
+
+               internal string GetSecureFileName ()
+               {
+                       string filename = "<filename unknown>";
+                       if (fileName == null)
+                               return filename;
+                       try {
+                               filename = GetFileName ();
+                       }
+                       catch (SecurityException) {
+                               // CAS check failure
+                       }
+                       return filename;
+               }
                 
                 public virtual int GetILOffset()
                 {
                         return ilOffset;
                 }
                 
-#if ONLY_1_1
-               [ReflectionPermission (SecurityAction.Demand, TypeInformation = true)]
-#endif
                public virtual MethodBase GetMethod ()
                 {
                         return methodBase;
@@ -158,6 +167,16 @@ namespace System.Diagnostics {
                         return nativeOffset;                        
                 }
 
+               internal long GetMethodAddress ()
+               {
+                       return methodAddress;
+               }
+
+               internal uint GetMethodIndex ()
+               {
+                       return methodIndex;
+               }
+
                internal string GetInternalMethodName ()
                {
                        return internalMethodName;
@@ -183,18 +202,7 @@ namespace System.Diagnostics {
                        }
 
                        sb.Append (Locale.GetText (" in file:line:column "));
-
-                       if (fileName == null) {
-                               sb.Append (Locale.GetText ("<filename unknown>"));
-                       } else {
-                               try {
-                                       sb.Append (GetFileName ());
-                               }
-                               catch (SecurityException) {
-                                       sb.Append (Locale.GetText ("<filename unknown>"));
-                               }
-                       }
-
+                       sb.Append (GetSecureFileName ());
                        sb.AppendFormat (":{0}:{1}", lineNumber, columnNumber);
                        return sb.ToString ();
                }