Skip to content

Commit

Permalink
Fix build breaks
Browse files Browse the repository at this point in the history
- Add Exception._remoteStackTrace
  • Loading branch information
jkotas committed Apr 1, 2021
1 parent ad56f5d commit a6e006f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public partial class Exception : ISerializable
{
partial void RestoreRemoteStackTrace(SerializationInfo info, StreamingContext context)
{
_remoteStackTraceString = info.GetString("RemoteStackTraceString"); // Do not rename (binary serialization)

// Get the WatsonBuckets that were serialized - this is particularly
// done to support exceptions going across AD transitions.
//
Expand Down Expand Up @@ -245,8 +243,6 @@ internal void RestoreDispatchState(in DispatchState dispatchState)
// See src\inc\corexcep.h's EXCEPTION_COMPLUS definition:
private const int _COMPlusExceptionCode = unchecked((int)0xe0434352); // Win32 exception code for COM+ exceptions

private string? SerializationRemoteStackTraceString => _remoteStackTraceString;

private object? SerializationWatsonBuckets => _watsonBuckets;

private string? SerializationStackTraceString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,9 @@
<data name="Exception_EndOfInnerExceptionStack" xml:space="preserve">
<value>--- End of inner exception stack trace ---</value>
</data>
<data name="Exception_EndStackTraceFromPreviousThrow" xml:space="preserve">
<value>--- End of stack trace from previous location ---</value>
</data>
<data name="Exception_WasThrown" xml:space="preserve">
<value>Exception of type '{0}' was thrown.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,20 @@ private void InitializeForIpAddressArray(IntPtr[] ipAddresses, int skipFrames, i
}

#if !TARGET_WASM
internal string ToString(TraceFormat traceFormat)
internal void ToString(TraceFormat traceFormat, StringBuilder builder)
{
if (_stackFrames == null)
{
return "";
return;
}

StringBuilder builder = new StringBuilder();
foreach (StackFrame frame in _stackFrames)
{
frame.AppendToStackTrace(builder);
}

if (traceFormat == TraceFormat.Normal && builder.Length >= Environment.NewLine.Length)
builder.Length -= Environment.NewLine.Length;

return builder.ToString();
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public MethodBase TargetSite
private IDictionary CreateDataContainer() => new ListDictionaryInternal();

private string SerializationStackTraceString => StackTrace;
private string SerializationRemoteStackTraceString => null;
private string SerializationWatsonBuckets => null;

private string CreateSourceName() => HasBeenThrown ? "<unknown>" : null;
Expand All @@ -46,21 +45,29 @@ public MethodBase TargetSite
private int _HResult; // HResult

// To maintain compatibility across runtimes, if this object was deserialized, it will store its stack trace as a string
private string _stackTraceString;
private string? _stackTraceString;
private string? _remoteStackTraceString;

// Returns the stack trace as a string. If no stack trace is
// available, null is returned.
public virtual string StackTrace
public virtual string? StackTrace
{
get
{
if (_stackTraceString != null)
return _stackTraceString;
string? stackTraceString = _stackTraceString;
string? remoteStackTraceString = _remoteStackTraceString;

// if no stack trace, try to get one
if (stackTraceString != null)
{
return remoteStackTraceString + stackTraceString;
}
if (!HasBeenThrown)
return null;
{
return remoteStackTraceString;
}

return StackTraceHelper.FormatStackTrace(GetStackIPs(), true);
return remoteStackTraceString + StackTraceHelper.FormatStackTrace(GetStackIPs(), true);
}
}

Expand Down Expand Up @@ -232,12 +239,6 @@ public DispatchState(IntPtr[] stackTrace)
}
}

[StackTraceHidden]
internal void SetCurrentStackTrace()
{
// TODO: Exception.SetCurrentStackTrace
}

// This is the object against which a lock will be taken
// when attempt to restore the EDI. Since its static, its possible
// that unrelated exception object restorations could get blocked
Expand Down Expand Up @@ -289,5 +290,19 @@ internal unsafe byte[] SerializeForDump()
return buffer;
}
}

// Returns true if setting the _remoteStackTraceString field is legal, false if not (immutable exception).
// A false return value means the caller should early-exit the operation.
// Can also throw InvalidOperationException if a stack trace is already set or if object has been thrown.
private bool CanSetRemoteStackTrace()
{
// Check to see if the exception already has a stack set in it.
if (HasBeenThrown || _stackTraceString != null || _remoteStackTraceString != null)
{
ThrowHelper.ThrowInvalidOperationException();
}

return true; // CoreRT runtime doesn't have immutable agile exceptions, always return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\ModuleDesc.cs">
<Link>Internal\TypeSystem\ModuleDesc.cs</Link>
</Compile>
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\NotFoundBehavior.cs">
<Link>TypeSystem\Common\NotFoundBehavior.cs</Link>
</Compile>
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\ParameterizedType.cs">
<Link>Internal\TypeSystem\ParameterizedType.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ internal enum TraceFormat
TrailingNewLine, // include a trailing new line character
}

#if !CORERT
/// <summary>
/// Builds a readable representation of the stack trace, specifying
/// the format for backwards compatibility.
Expand All @@ -199,6 +198,7 @@ internal string ToString(TraceFormat traceFormat)
return sb.ToString();
}

#if !CORERT
internal void ToString(TraceFormat traceFormat, StringBuilder sb)
{
// Passing a default string for "at" in case SR.UsingResourceKeys() is true
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Private.CoreLib/src/System/Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected Exception(SerializationInfo info, StreamingContext context)
_innerException = (Exception?)(info.GetValue("InnerException", typeof(Exception))); // Do not rename (binary serialization)
_helpURL = info.GetString("HelpURL"); // Do not rename (binary serialization)
_stackTraceString = info.GetString("StackTraceString"); // Do not rename (binary serialization)
_remoteStackTraceString = info.GetString("RemoteStackTraceString"); // Do not rename (binary serialization)
_HResult = info.GetInt32("HResult"); // Do not rename (binary serialization)
_source = info.GetString("Source"); // Do not rename (binary serialization)

Expand Down Expand Up @@ -110,7 +111,7 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
info.AddValue("InnerException", _innerException, typeof(Exception)); // Do not rename (binary serialization)
info.AddValue("HelpURL", _helpURL, typeof(string)); // Do not rename (binary serialization)
info.AddValue("StackTraceString", SerializationStackTraceString, typeof(string)); // Do not rename (binary serialization)
info.AddValue("RemoteStackTraceString", SerializationRemoteStackTraceString, typeof(string)); // Do not rename (binary serialization)
info.AddValue("RemoteStackTraceString", _remoteStackTraceString, typeof(string)); // Do not rename (binary serialization)
info.AddValue("RemoteStackIndex", 0, typeof(int)); // Do not rename (binary serialization)
info.AddValue("ExceptionMethod", null, typeof(string)); // Do not rename (binary serialization)
info.AddValue("HResult", _HResult); // Do not rename (binary serialization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private bool CanSetRemoteStackTrace()
private static IDictionary CreateDataContainer() => new ListDictionaryInternal();

private static string? SerializationWatsonBuckets => null;
private string? SerializationRemoteStackTraceString => _remoteStackTraceString;
private string? SerializationStackTraceString => GetStackTrace(true);
}
}

0 comments on commit a6e006f

Please sign in to comment.