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

@@ -25,13 +25,15 @@ namespace Mono
assemblyFullPath = assemblyPath;
}
public bool TryResolveLocation (StackFrameData sfData, SeqPointInfo seqPointInfo)
public bool TryResolveLocation (StackFrameData sfData, SeqPointInfo seqPointInfo, out Location location)
{
var readerParameters = new ReaderParameters { ReadSymbols = true };
using (var assembly = AssemblyDefinition.ReadAssembly (assemblyFullPath, readerParameters)) {
if (!assembly.MainModule.HasSymbols)
if (!assembly.MainModule.HasSymbols) {
location = default;
return false;
}
TypeDefinition type = null;
string[] nested;
@@ -51,6 +53,7 @@ namespace Mono
if (type == null) {
logger.LogWarning ("Could not find type: {0}", ntype);
location = default;
return false;
}
@@ -63,10 +66,12 @@ namespace Mono
var methods = type.Methods.Where (m => CompareName (m, methodName) && CompareParameters (m.Parameters, methodParameters)).ToArray ();
if (methods.Length == 0) {
logger.LogWarning ("Could not find method: {0}", methodName);
location = default;
return false;
}
if (methods.Length > 1) {
logger.LogWarning ("Ambiguous match for method: {0}", sfData.MethodSignature);
location = default;
return false;
}
var method = methods [0];
@@ -75,22 +80,34 @@ namespace Mono
if (sfData.IsILOffset) {
ilOffset = sfData.Offset;
} else {
if (seqPointInfo == null)
if (seqPointInfo == null) {
location = default;
return false;
}
ilOffset = seqPointInfo.GetILOffset (method.MetadataToken.ToInt32 (), sfData.MethodIndex, sfData.Offset);
}
if (ilOffset < 0)
if (ilOffset < 0) {
location = default;
return false;
}
if (!method.DebugInformation.HasSequencePoints)
if (!method.DebugInformation.HasSequencePoints) {
var async_method = GetAsyncStateMachine (method);
if (async_method?.ConstructorArguments?.Count == 1) {
string state_machine = ((TypeReference)async_method.ConstructorArguments [0].Value).FullName;
return TryResolveLocation (sfData.Relocate (state_machine, "MoveNext ()"), seqPointInfo, out location);
}
location = default;
return false;
}
SequencePoint prev = null;
foreach (var sp in method.DebugInformation.SequencePoints.OrderBy (l => l.Offset)) {
if (sp.Offset >= ilOffset) {
sfData.SetLocation (sp.Document.Url, sp.StartLine);
location = new Location (sp.Document.Url, sp.StartLine);
return true;
}
@@ -98,14 +115,24 @@ namespace Mono
}
if (prev != null) {
sfData.SetLocation (prev.Document.Url, prev.StartLine);
location = new Location (prev.Document.Url, prev.StartLine);
return true;
}
location = default;
return false;
}
}
static CustomAttribute GetAsyncStateMachine (MethodDefinition method)
{
if (!method.HasCustomAttributes)
return null;
return method.CustomAttributes.FirstOrDefault (l =>
l.AttributeType.Name == "AsyncStateMachineAttribute" && l.AttributeType.Namespace == "System.Runtime.CompilerServices");
}
static bool CompareName (MethodDefinition candidate, string expected)
{
if (candidate.Name == expected)

View File

@@ -45,7 +45,7 @@ PREPARE_OUTDIR = @\
mkdir -p $(MSYM_DIR);
COMPILE = \
$(CSCOMPILE) $(TEST_CS) -r:$(LIB_PATH)/mscorlib.dll -out:$(TEST_EXE); \
$(CSCOMPILE) $(TEST_CS) -r:$(LIB_PATH)/mscorlib.dll -r:$(LIB_PATH)/System.Core.dll -warn:0 -out:$(TEST_EXE); \
$(MONO) $(LIB_PATH)/$(PROGRAM) store-symbols $(MSYM_DIR) $(OUT_DIR); \
$(MONO) $(LIB_PATH)/$(PROGRAM) store-symbols $(MSYM_DIR) $(LIB_PATH);

View File

@@ -17,13 +17,8 @@ namespace Mono
public readonly string Mvid;
public readonly string Aotid;
public string File { get; private set; }
public int LineNumber { get; private set; }
private StackFrameData (string line, string typeFullName, string methodSig, int offset, bool isILOffset, uint methodIndex, string mvid, string aotid)
{
LineNumber = -1;
Line = line;
TypeFullName = typeFullName;
MethodSignature = methodSig;
@@ -34,6 +29,11 @@ namespace Mono
Aotid = aotid;
}
public StackFrameData Relocate (string typeName, string methodName)
{
return new StackFrameData (Line, typeName, methodName, Offset, IsILOffset, MethodIndex, Mvid, Aotid);
}
public static bool TryParse (string line, out StackFrameData stackFrame)
{
stackFrame = null;
@@ -91,16 +91,5 @@ namespace Mono
return true;
}
internal void SetLocation (string file, int lineNumber)
{
File = file;
LineNumber = lineNumber;
}
public override string ToString ()
{
return string.Format ("{0} in {1}:{2} ", Line.Substring (0, Line.IndexOf(" in <", StringComparison.Ordinal)), File, LineNumber);
}
}
}

View File

@@ -9,6 +9,19 @@ using Mono.Collections.Generic;
namespace Mono
{
// Should be (string File, int Line) but need to bump monodroid_tools to 4.7
readonly struct Location
{
public readonly string File;
public readonly int Line;
public Location (string file, int line)
{
File = file;
Line = line;
}
}
public class SymbolManager
{
string msymDir;
@@ -19,20 +32,25 @@ namespace Mono
this.logger = logger;
}
internal bool TryResolveLocation (StackFrameData sfData)
internal bool TryResolveLocation (StackFrameData sfData, out Location location)
{
if (sfData.Mvid == null)
if (sfData.Mvid == null) {
location = default;
return false;
}
var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (sfData.Mvid);
if (assemblyLocProvider == null)
if (assemblyLocProvider == null) {
location = default;
return false;
}
SeqPointInfo seqPointInfo = null;
if (!sfData.IsILOffset && sfData.Aotid != null)
seqPointInfo = GetOrCreateSeqPointInfo (sfData.Aotid);
return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo);
return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo, out location);
}
Dictionary<string, AssemblyLocationProvider> assemblies = new Dictionary<string, AssemblyLocationProvider> ();

View File

@@ -81,11 +81,9 @@ namespace Mono
using (StreamReader r = new StreamReader (inputFile)) {
for (var line = r.ReadLine (); line != null; line = r.ReadLine ()) {
StackFrameData sfData;
if (StackFrameData.TryParse (line, out sfData) &&
symbolManager.TryResolveLocation (sfData)) {
Console.WriteLine (sfData.ToString ());
continue;
if (StackFrameData.TryParse (line, out var sfData) && symbolManager.TryResolveLocation (sfData, out var location)) {
var sign = sfData.Line.Substring (0, sfData.Line.IndexOf (" in <", StringComparison.Ordinal));
line = $"{sign} in {location.File}:{location.Line}";
}
Console.WriteLine (line);