Skip to content

Commit f25af34

Browse files
author
Steve Salas
committed
Squashed 'dotnet-symbol-service/' changes from bffd9aa..3db2eb5
3db2eb5 Merges dev/initial-effort into master 4ed597d Supports C# async and yield keywords 292a5a8 Return symbol data for nested types git-subtree-dir: dotnet-symbol-service git-subtree-split: 3db2eb5bb295350f95604adc85076757137a9502
1 parent 494a964 commit f25af34

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

SymbolService/Controllers/MethodsController.cs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.AspNetCore.Http;
2121
using Microsoft.AspNetCore.Mvc;
2222
using System.IO;
23+
using System.Runtime.CompilerServices;
2324
using Mono.Cecil;
2425
using Mono.Cecil.Pdb;
2526
using SymbolService.Model;
@@ -49,8 +50,38 @@ public IActionResult Methods(IFormFile assemblyFile, IFormFile symbolsFile)
4950

5051
using (var module = LoadModule(assemblyPath, symbolsPath))
5152
{
52-
var methodInfos = module.Types.SelectMany(type => type.Methods).Select(GetMethodInfo);
53-
return new JsonResult(methodInfos.ToArray()); // materialize collection prior to module disposal
53+
var methodDefinitions = GetMethodDefinitions(module, out var methodInfoMap);
54+
55+
var stateMachineAttributeTypes = new List<string>(new []
56+
{
57+
typeof(AsyncStateMachineAttribute).FullName,
58+
typeof(IteratorStateMachineAttribute).FullName
59+
});
60+
61+
var stateMachineSupportedMethods =
62+
methodDefinitions.Where(x => !x.DebugInformation.HasSequencePoints &&
63+
x.HasCustomAttributes && x.CustomAttributes.Any(y =>
64+
stateMachineAttributeTypes.Contains(y.AttributeType.FullName))).ToArray();
65+
66+
foreach (var stateMachineSupportedMethod in stateMachineSupportedMethods)
67+
{
68+
var stateMachineTypeDefinition = (TypeDefinition) stateMachineSupportedMethod.CustomAttributes
69+
.Single(x => stateMachineAttributeTypes.Contains(x.AttributeType.FullName))
70+
.ConstructorArguments.Single().Value;
71+
72+
foreach (var stateMachineMethod in stateMachineTypeDefinition.Methods.Where(x => x.DebugInformation.HasSequencePoints))
73+
{
74+
if (!methodInfoMap.TryGetValue(stateMachineSupportedMethod.FullName, out var stateMachineSupportedMethodInfo))
75+
{
76+
stateMachineSupportedMethodInfo = GetMethodInfo(stateMachineSupportedMethod);
77+
methodInfoMap[stateMachineSupportedMethod.FullName] = stateMachineSupportedMethodInfo;
78+
}
79+
80+
methodInfoMap[stateMachineMethod.FullName].SurrogateFor = methodInfoMap[stateMachineSupportedMethod.FullName].Id;
81+
}
82+
}
83+
84+
return new JsonResult(methodInfoMap.Values);
5485
}
5586
}
5687
catch
@@ -92,6 +123,38 @@ private ModuleDefinition LoadModule(string assemblyPath, string symbolsPath)
92123
}
93124
}
94125

126+
private List<MethodDefinition> GetMethodDefinitions(ModuleDefinition module, out Dictionary<string, MethodInfo> methodInfoMap)
127+
{
128+
var allMethodDefinitions = new List<MethodDefinition>();
129+
methodInfoMap = new Dictionary<string, MethodInfo>();
130+
foreach (var type in module.Types)
131+
{
132+
allMethodDefinitions.AddRange(GetMethodDefinitions(type, ref methodInfoMap));
133+
}
134+
return allMethodDefinitions;
135+
}
136+
137+
private IEnumerable<MethodDefinition> GetMethodDefinitions(TypeDefinition typeDefinition, ref Dictionary<string, MethodInfo> methodInfoMap)
138+
{
139+
var definitions = new List<MethodDefinition>();
140+
foreach (var type in typeDefinition.NestedTypes)
141+
{
142+
definitions.AddRange(GetMethodDefinitions(type, ref methodInfoMap));
143+
}
144+
145+
foreach (var method in typeDefinition.Methods)
146+
{
147+
definitions.Add(method);
148+
149+
if (method.DebugInformation.HasSequencePoints)
150+
{
151+
methodInfoMap[method.FullName] = GetMethodInfo(method);
152+
}
153+
}
154+
155+
return definitions;
156+
}
157+
95158
private MethodInfo GetMethodInfo(MethodDefinition method)
96159
{
97160
return new MethodInfo

SymbolService/Model/MethodInfo.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace SymbolService.Model
2121
{
2222
public class MethodInfo
2323
{
24+
public Guid Id { get; }
25+
2426
public String FullyQualifiedName { get; set; }
2527

2628
public String ContainingClass { get; set; }
@@ -32,5 +34,12 @@ public class MethodInfo
3234
public String ReturnType { get; set; }
3335

3436
public int Instructions { get; set; }
37+
38+
public Guid SurrogateFor { get; set; }
39+
40+
public MethodInfo()
41+
{
42+
Id = Guid.NewGuid();
43+
}
3544
}
3645
}

0 commit comments

Comments
 (0)