Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@ -28,6 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
@ -180,7 +181,15 @@ namespace System.Diagnostics {
[ComVisibleAttribute (false)]
public virtual StackFrame[] GetFrames ()
{
return frames;
if (captured_traces == null)
return frames;
var accum = new List<StackFrame> ();
foreach (var t in captured_traces)
accum.AddRange(t.GetFrames ());
accum.AddRange (frames);
return accum.ToArray ();
}
static bool isAotidSet;
@ -197,15 +206,16 @@ namespace System.Diagnostics {
return aotid;
}
bool AddFrames (StringBuilder sb)
bool AddFrames (StringBuilder sb, bool separator, out bool isAsync)
{
isAsync = false;
bool any_frame = false;
for (int i = 0; i < FrameCount; i++) {
StackFrame frame = GetFrame (i);
if (frame.GetMethod () == null) {
if (any_frame)
if (any_frame || separator)
sb.Append (Environment.NewLine);
sb.Append (prefix);
@ -215,7 +225,7 @@ namespace System.Diagnostics {
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);
GetFullNameForStackTrace (sb, frame.GetMethod (), any_frame || separator, out var skipped, out isAsync);
if (skipped)
continue;
@ -247,9 +257,9 @@ namespace System.Diagnostics {
return any_frame;
}
void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi, bool needsNewLine, out bool skipped)
void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi, bool needsNewLine, out bool skipped, out bool isAsync)
{
var declaringType = mi.DeclaringType;
Type declaringType = mi.DeclaringType;
// Get generic definition
if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition) {
@ -265,10 +275,15 @@ namespace System.Diagnostics {
}
}
skipped = mi.IsDefined (typeof(StackTraceHiddenAttribute)) || declaringType.IsDefined (typeof(StackTraceHiddenAttribute));
isAsync = typeof (IAsyncStateMachine).IsAssignableFrom (declaringType);
skipped = mi.IsDefined (typeof (StackTraceHiddenAttribute)) || declaringType.IsDefined (typeof (StackTraceHiddenAttribute));
if (skipped)
return;
if (isAsync) {
ConvertAsyncStateMachineMethod (ref mi, ref declaringType);
}
if (needsNewLine)
sb.Append (Environment.NewLine);
sb.Append (prefix);
@ -310,6 +325,31 @@ namespace System.Diagnostics {
}
sb.Append (")");
}
static void ConvertAsyncStateMachineMethod (ref MethodBase method, ref Type declaringType)
{
Type parentType = declaringType.DeclaringType;
if (parentType == null)
return;
MethodInfo[] methods = parentType.GetMethods (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (methods == null)
return;
foreach (MethodInfo candidateMethod in methods) {
var attributes = candidateMethod.GetCustomAttributes<AsyncStateMachineAttribute> ();
if (attributes == null)
continue;
foreach (var attr in attributes) {
if (attr.StateMachineType == declaringType) {
method = candidateMethod;
declaringType = candidateMethod.DeclaringType;
return;
}
}
}
}
public override string ToString ()
{
@ -318,18 +358,22 @@ namespace System.Diagnostics {
//
// Add traces captured using ExceptionDispatchInfo
//
bool has_frames = false;
if (captured_traces != null) {
foreach (var t in captured_traces) {
if (!t.AddFrames (sb))
has_frames = t.AddFrames (sb, has_frames, out var isAsync);
if (!has_frames)
continue;
sb.Append (Environment.NewLine);
sb.Append ("--- End of stack trace from previous location where exception was thrown ---");
sb.Append (Environment.NewLine);
if (!isAsync) {
sb.Append (Environment.NewLine);
sb.Append ("--- End of stack trace from previous location where exception was thrown ---");
sb.Append (Environment.NewLine);
}
}
}
AddFrames (sb);
AddFrames (sb, has_frames, out _);
return sb.ToString ();
}