Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

11
external/linker/.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,11 @@
#
# Reference: https://help.github.com/articles/about-codeowners
#
# the default owners for everything in the repo.
* @marek-safar
/analyzer @radekdoulik
/corebuild @sbomer
netci.groovy @sbomer

73
external/linker/.github/CONTRIBUTING.md vendored Normal file
View File

@@ -0,0 +1,73 @@
Guidelines
==========
When contributing to the Mono project, please follow the [Mono Coding
Guidelines][1]. We have been using a coding style for many years,
please make your patches conform to these guidelines.
[1]: http://www.mono-project.com/community/contributing/coding-guidelines/
Etiquette
=========
In general, we do not accept patches that merely shuffle code around,
split classes in multiple files, reindent the code or are the result
of running a refactoring tool on the source code. This is done for
three reasons: (a) we have our own coding guidelines; (b) Some modules
are imported from upstream sources and we want to respect their coding
guidelines and (c) it destroys valuable history that is often used to
investigate bugs, regressions and problems.
License
=======
The Mono runtime, compilers, and tools and most of the class libraries
are licensed under the MIT license. But include some bits of code
licensed under different licenses. The exact list is [available here] (https://github.com/mono/mono/blob/master/LICENSE).
Different parts of Mono use different licenses. The actual details of
which licenses are used for which parts are detailed on the LICENSE
file in this directory.
CLA
=======
Contributions are now taken under the [.NET Foundation CLA] (https://cla2.dotnetfoundation.org/).
Testing
=======
Pull requests go through testing on our [Jenkins server][2]. We will
usually only merge a pull request if it causes no regressions in a
test run there.
When you submit a pull request, one of two things happens:
* If you are a new contributor, Jenkins will ask for permissions (on
the pull request) to test it. A maintainer will reply to approve
the test run if they find the patch appropriate. After you have
submitted a few patches, a maintainer will whitelist you so that
all of your future pull requests are tested automatically.
* If you are a well-known, whitelisted contributor, Jenkins will go
ahead and test your pull request as soon as a test machine is
available.
When your pull request has been built, Jenkins will update the build
status of your pull request. If it succeeded and we like the changes,
a maintainer will likely merge it. Otherwise, you can amend your pull
request to fix build breakage and Jenkins will test it again.
[2]: http://jenkins.mono-project.com/
# Inactivity
Occasionally, a pull request sits for several months without any
response from the author. This isn't necessarily an issue, but we may
sometimes decide to close pull requests that have not seen any
progress for a long time. This is in interest of keeping the pull
request list clean so that other pull requests don't get lost in the
clutter.
If we do close your pull request due to inactivity, you're more than
welcome to submit it anew after you address any comments or issues that
were brought up on the original pull request.

View File

@@ -29,3 +29,4 @@ bin/
corebuild/Tools
corebuild/bootstrap.log
/corebuild/global.json

View File

@@ -0,0 +1,176 @@
//
// ConsoleDependencyGraph.cs: text output related code for dependency graph
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using LinkerAnalyzer.Core;
namespace LinkerAnalyzer
{
public class ConsoleDependencyGraph : DependencyGraph
{
public bool Tree = false;
public bool FlatDeps;
public void ShowDependencies (string raw, List<VertexData> verticesList, string searchString)
{
VertexData vertex = Vertex (raw);
if (vertex == null) {
Regex regex = new Regex (searchString);
int count = 0;
foreach (var v in verticesList) {
if (regex.Match (v.value) != Match.Empty) {
ShowDependencies (v);
count++;
}
}
if (count == 0)
Console.WriteLine ("\nUnable to find vertex: {0}", raw);
else
Console.WriteLine ("\nFound {0} matches", count);
} else
ShowDependencies (vertex);
}
void ShowFlatDependencies (VertexData vertex)
{
bool first = true;
var flatDeps = GetAllDependencies (vertex);
Console.WriteLine ();
foreach (var d in flatDeps) {
if (first) {
Console.WriteLine ($"Distance | {d.Item1.value} [total deps: {flatDeps.Count}]");
Line ();
first = false;
continue;
}
Console.WriteLine ($"{string.Format ("{0,8}", d.Item2)} | {d.Item1.value}");
}
}
public void ShowDependencies (VertexData vertex)
{
if (FlatDeps) {
ShowFlatDependencies (vertex);
return;
}
Header ("{0} dependencies", vertex.value);
if (vertex.parentIndexes == null) {
Console.WriteLine ("Root dependency");
} else {
int i = 0;
foreach (int index in vertex.parentIndexes) {
Console.WriteLine ("Dependency #{0}", ++i);
Console.WriteLine ("\t{0}", vertex.value);
var childVertex = Vertex (index);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
while (childVertex.parentIndexes != null) {
childVertex = Vertex (childVertex.parentIndexes [0]);
Console.WriteLine ("\t| {0}{1}", childVertex.value, childVertex.DepsCount);
}
if (Tree)
break;
}
}
}
public void ShowAllDependencies ()
{
Header ("All dependencies");
Console.WriteLine ("Types count: {0}", vertices.Count);
foreach (var vertex in vertices)
ShowDependencies (vertex);
}
public void ShowTypesDependencies ()
{
Header ("All types dependencies");
Console.WriteLine ("Deps count: {0}", Types.Count);
foreach (var type in Types)
ShowDependencies (type);
}
string Tabs (string key)
{
int count = Math.Max (1, 2 - key.Length / 8);
if (count == 1)
return "\t";
else
return "\t\t";
}
public void ShowStat (bool verbose = false)
{
Header ("Statistics");
if (verbose) {
foreach (var key in counts.Keys)
Console.WriteLine ("Vertex type:\t{0}{1}count:{2}", key, Tabs (key), counts [key]);
} else {
Console.WriteLine ("Assemblies:\t{0}", counts ["Assembly"]);
Console.WriteLine ("Modules:\t{0}", counts ["Module"]);
Console.WriteLine ("Types:\t\t{0}", counts ["TypeDef"]);
Console.WriteLine ("Fields:\t\t{0}", counts ["Field"]);
Console.WriteLine ("Methods:\t{0}", counts ["Method"]);
}
Console.WriteLine ();
Console.WriteLine ("Total vertices: {0}", vertices.Count);
}
public void ShowRoots ()
{
Header ("Root vertices");
int count = 0;
foreach (var vertex in vertices) {
if (vertex.parentIndexes == null) {
Console.WriteLine ("{0}", vertex.value);
count++;
}
}
Console.WriteLine ();
Console.WriteLine ("Total root vertices: {0}", count);
}
public void ShowRawDependencies (string raw)
{
Header ("Raw dependencies: '{0}'", raw);
ShowDependencies (raw, vertices, raw);
}
public void ShowTypeDependencies (string raw)
{
Header ("Type dependencies: '{0}'", raw);
ShowDependencies ("TypeDef:" + raw, Types, raw);
}
static readonly string line = new string ('-', 72);
void Line ()
{
Console.Write (line);
Console.WriteLine ();
}
void Header (string header, params object[] values)
{
string formatted = string.Format (header, values);
Console.WriteLine ();
Console.WriteLine ($"--- {formatted} {new string ('-', Math.Max (3, 67 - formatted.Length))}");
}
}
}

View File

@@ -0,0 +1,141 @@
//
// DependencyGraph.cs: linker dependencies graph
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Xml;
namespace LinkerAnalyzer.Core
{
public class VertexData {
public string value;
public List<int> parentIndexes;
public int index;
public string DepsCount {
get {
if (parentIndexes == null || parentIndexes.Count < 1)
return "";
return string.Format (" [{0} deps]", parentIndexes.Count);
}
}
};
public class DependencyGraph
{
protected List<VertexData> vertices = new List<VertexData> ();
public List<VertexData> Types = new List<VertexData> ();
Dictionary<string, int> indexes = new Dictionary<string, int> ();
protected Dictionary<string, int> counts = new Dictionary<string, int> ();
public void Load (string filename)
{
Console.WriteLine ("Loading dependency tree from: {0}", filename);
try {
using (var fileStream = File.OpenRead (filename))
using (var zipStream = new GZipStream (fileStream, CompressionMode.Decompress)) {
Load (zipStream);
}
} catch (Exception) {
Console.WriteLine ("Unable to open and read the dependecies.");
Environment.Exit (1);
}
}
void Load (GZipStream zipStream) {
using (XmlReader reader = XmlReader.Create (zipStream)) {
while (reader.Read ()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
//Console.WriteLine (reader.Name);
if (reader.Name == "edge" && reader.IsStartElement ()) {
string b = reader.GetAttribute ("b");
string e = reader.GetAttribute ("e");
//Console.WriteLine ("edge value " + b + " --> " + e);
if (e != b) {
VertexData begin = Vertex (b, true);
VertexData end = Vertex (e, true);
if (end.parentIndexes == null)
end.parentIndexes = new List<int> ();
if (!end.parentIndexes.Contains (begin.index)) {
end.parentIndexes.Add (begin.index);
//Console.WriteLine (" end parent index: {0}", end.parentIndexes);
}
}
}
break;
default:
//Console.WriteLine ("node: " + reader.NodeType);
break;
}
}
}
}
public VertexData Vertex (string vertexName, bool create = false)
{
VertexData vertex;
try {
vertex = vertices [indexes [vertexName]];
} catch (KeyNotFoundException) {
if (create) {
int index = vertices.Count;
vertex = new VertexData () { value = vertexName, index = index };
vertices.Add (vertex);
indexes.Add (vertexName, index);
string prefix = vertexName.Substring (0, vertexName.IndexOf (':'));
if (counts.ContainsKey (prefix))
counts [prefix]++;
else
counts [prefix] = 1;
//Console.WriteLine ("prefix " + prefix + " count " + counts[prefix]);
if (prefix == "TypeDef") {
Types.Add (vertex);
}
} else
return null;
}
return vertex;
}
public VertexData Vertex (int index)
{
return vertices [index];
}
IEnumerable<Tuple<VertexData, int>> AddDependencies (VertexData vertex, HashSet<int> reachedVertices, int depth)
{
reachedVertices.Add (vertex.index);
yield return new Tuple<VertexData, int> (vertex, depth);
if (vertex.parentIndexes == null)
yield break;
foreach (var pi in vertex.parentIndexes) {
var parent = Vertex (pi);
if (reachedVertices.Contains (parent.index))
continue;
foreach (var d in AddDependencies (parent, reachedVertices, depth + 1))
yield return d;
}
}
public List<Tuple<VertexData, int>> GetAllDependencies (VertexData vertex)
{
return new List<Tuple<VertexData, int>> (AddDependencies (vertex, new HashSet<int> (), 0));
}
}
}

88
external/linker/analyzer/Main.cs vendored Normal file
View File

@@ -0,0 +1,88 @@
//
// Main.cs: Main program file of command line utility.
//
// Author:
// Radek Doulik (rodo@xamarin.com)
//
// Copyright 2015 Xamarin Inc (http://www.xamarin.com).
//
using System;
using Mono.Options;
using LinkerAnalyzer.Core;
namespace LinkerAnalyzer
{
static class MainClass
{
static void Main (string[] args)
{
bool showUsage = true;
bool showAllDeps = false;
bool showTypeDeps = false;
string typeName = null;
bool showRawDeps = false;
string rawName = null;
bool showRoots = false;
bool showSpaceUsage = false;
bool showStat = false;
bool showTypes = false;
bool reduceToTree = false;
bool verbose = false;
bool flatDeps = false;
var optionsParser = new OptionSet () {
{ "a|alldeps", "show all dependencies", v => { showAllDeps = v != null; } },
{ "h|help", "show this message and exit.", v => showUsage = v != null },
{ "r|rawdeps=", "show raw vertex dependencies. Raw vertex VALUE is in the raw format written by linker to the dependency XML file. VALUE can be regular expression", v => { showRawDeps = v != null; rawName = v; } },
{ "roots", "show root dependencies.", v => showRoots = v != null },
{ "stat", "show statistic of loaded dependencies.", v => showStat = v != null },
{ "tree", "reduce the dependency graph to the tree.", v => reduceToTree = v != null },
{ "types", "show all types dependencies.", v => showTypes = v != null },
{ "t|typedeps=", "show type dependencies. The VALUE can be regular expression", v => { showTypeDeps = v != null; typeName = v; } },
//{ "u|spaceusage", "show space analysis.", v => showSpaceUsage = v != null },
{ "f|flat", "show all dependencies per vertex and their distance", v => flatDeps = v != null },
{ "v|verbose", "be more verbose. Enables stat and roots options.", v => verbose = v != null },
};
if (args.Length > 0) {
showUsage = false;
optionsParser.Parse (args);
}
if (showUsage) {
Console.WriteLine ("Usage:\n\n\tillinkanalyzer [Options] <linker-dependency-file.xml.gz>\n\nOptions:\n");
optionsParser.WriteOptionDescriptions (Console.Out);
Console.WriteLine ();
return;
}
string dependencyFile = args [args.Length - 1];
ConsoleDependencyGraph deps = new ConsoleDependencyGraph () { Tree = reduceToTree, FlatDeps = flatDeps };
deps.Load (dependencyFile);
if (showSpaceUsage) {
// SpaceAnalyzer sa = new SpaceAnalyzer (System.IO.Path.GetDirectoryName (dependencyFile));
// sa.LoadAssemblies (verbose);
}
if (verbose) {
showStat = true;
showRoots = true;
}
if (showStat)
deps.ShowStat (verbose);
if (showRoots)
deps.ShowRoots ();
if (showRawDeps)
deps.ShowRawDependencies (rawName);
if (showTypeDeps)
deps.ShowTypeDependencies (typeName);
if (showAllDeps)
deps.ShowAllDependencies ();
else if (showTypes)
deps.ShowTypesDependencies ();
}
}
}

126
external/linker/analyzer/README.md vendored Normal file
View File

@@ -0,0 +1,126 @@
Linker analyzer is a command line tool to analyze dependencies, which
were recorded during linker processing, and led linker to mark an item
to keep it in the resulting linked assembly.
It works on an oriented graph of dependencies, which are collected and
dumped during the linker run. The vertices of this graph are the items
of interest like assemblies, types, methods, fields, linker steps,
etc. The edges represent the dependencies.
How to dump dependencies
------------------------
The linker analyzer needs a linker dependencies file as an input. It
can be retrieved by enabling dependencies dumping during linking of a
Xamarin.Android or a Xamarin.iOS project.
That can be done on the command line by setting
`LinkerDumpDependencies` property to `true` and building the
project. (make sure the LinkAssemblies task is called, it might
require cleaning the project sometimes) Usually it is enough to build
the project like this:
```msbuild /p:LinkerDumpDependencies=true /p:Configuration=Release YourAppProject.csproj```
After a successful build, there will be a linker-dependencies.xml.gz
file created, containing the information for the analyzer.
How to use the analyzer
-----------------------
Let say you would like to know, why a type, Android.App.Activity for
example, was marked by the linker. So run the analyzer like this:
```illinkanalyzer -t Android.App.Activity linker-dependencies.xml.gz```
Output:
```
Loading dependency tree from: linker-dependencies.xml.gz
--- Type dependencies: 'Android.App.Activity' -----------------------
--- TypeDef:Android.App.Activity dependencies -----------------------
Dependency #1
TypeDef:Android.App.Activity
| TypeDef:XA.App.MainActivity [2 deps]
| Assembly:XA.App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [3 deps]
| Other:Mono.Linker.Steps.ResolveFromAssemblyStep
```
The output contains dependencies string(s), starting with the type and
continuing with the item of interest, which depends on the type. The
dependency could be result of multiple reasons. For example the type
was referenced from a method, or the type was listed in the linker xml
file to be protected.
In our example there is only one dependency string called `Dependency
#1`. It shows us that the type `Android.App.Activity` was marked
during processing of type `XA.App.MainActivity` by the linker. In this
case because the `MainActivity` type is based on the `Activity` type
and thus the linker marked it and kept it in the linked assembly. We
can also see that there are 2 dependencies for the `MainActivity`
class. Note that in the string (above) we see only 1st dependency of
the 2, the dependency on the assembly `XA.App`. And finally the
assembly vertex depends on the `ResolveFromAssemblyStep` vertex. So we
see that the assembly was processed in the `ResolveFromAssembly`
linker step.
Now we might want to see the `MainActivity` dependencies. That could
be done by the following analyzer run:
```illinkanalyzer -r TypeDef:XA.App.MainActivity linker-dependencies.xml.gz```
Output:
```
Loading dependency tree from: linker-dependencies.xml.gz
--- Raw dependencies: 'TypeDef:XA.App.MainActivity' -----------------
--- TypeDef:XA.App.MainActivity dependencies ------------------------
Dependency #1
TypeDef:XA.App.MainActivity
| Assembly:XA.App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [3 deps]
| Other:Mono.Linker.Steps.ResolveFromAssemblyStep
Dependency #2
TypeDef:XA.App.MainActivity
| TypeDef:XA.App.MainActivity/<>c__DisplayClass1_0 [2 deps]
| TypeDef:XA.App.MainActivity [2 deps]
| Assembly:XA.App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null [3 deps]
| Other:Mono.Linker.Steps.ResolveFromAssemblyStep
```
Known issues
------------
Sometimes the linker processing is not straight forward and the
marking is postponed, like processing of some of the methods. They are
queued to be processed later. In such case the dependencies are
"interrupted" and the dependecy string for the method usually shows
just dependency on the Mark step.
Command line help
-----------------
```
Usage:
illinkanalyzer [Options] <linker-dependency-file.xml.gz>
Options:
-a, --alldeps show all dependencies
-h, --help show this message and exit.
-r, --rawdeps=VALUE show raw vertex dependencies. Raw vertex VALUE is
in the raw format written by linker to the
dependency XML file. VALUE can be regular
expression
--roots show root dependencies.
--stat show statistic of loaded dependencies.
--tree reduce the dependency graph to the tree.
--types show all types dependencies.
-t, --typedeps=VALUE show type dependencies. The VALUE can be regular
expression
-f, --flat show all dependencies per vertex and their distance
-v, --verbose be more verbose. Enables stat and roots options.
```

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{4F328B3E-39C1-4E48-8093-F24390C58A5E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>LinkerAnalyzer</RootNamespace>
<AssemblyName>illinkanalyzer</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleDependencyGraph.cs" />
<Compile Include="Main.cs" />
<Compile Include="LinkerAnalyzerCore\DependencyGraph.cs" />
<Compile Include="..\common\Mono.Options\Options.cs">
<Link>Options.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -45,7 +45,7 @@ namespace Mono.Cecil.Cil {
return position;
}
void MoveBackTo (int position)
public void MoveBackTo (int position)
{
this.reader.context = null;
this.Position = position;
@@ -62,6 +62,30 @@ namespace Mono.Cecil.Cil {
return this.body;
}
public int ReadCodeSize (MethodDefinition method)
{
var position = MoveTo (method);
var code_size = ReadCodeSize ();
MoveBackTo (position);
return code_size;
}
int ReadCodeSize ()
{
var flags = ReadByte ();
switch (flags & 0x3) {
case 0x2: // tiny
return flags >> 2;
case 0x3: // fat
Advance (-1 + 2 + 2); // go back, 2 bytes flags, 2 bytes stack size
return (int) ReadUInt32 ();
default:
throw new InvalidOperationException ();
}
}
void ReadMethodBody ()
{
var flags = ReadByte ();
@@ -88,99 +112,6 @@ namespace Mono.Cecil.Cil {
ReadDebugInfo ();
}
void ReadDebugInfo ()
{
if (method.debug_info.sequence_points != null)
ReadSequencePoints ();
if (method.debug_info.scope != null)
ReadScope (method.debug_info.scope);
if (method.custom_infos != null)
ReadCustomDebugInformations (method);
}
void ReadCustomDebugInformations (MethodDefinition method)
{
var custom_infos = method.custom_infos;
for (int i = 0; i < custom_infos.Count; i++) {
var state_machine_scope = custom_infos [i] as StateMachineScopeDebugInformation;
if (state_machine_scope != null)
ReadStateMachineScope (state_machine_scope);
var async_method = custom_infos [i] as AsyncMethodBodyDebugInformation;
if (async_method != null)
ReadAsyncMethodBody (async_method);
}
}
void ReadAsyncMethodBody (AsyncMethodBodyDebugInformation async_method)
{
if (async_method.catch_handler.Offset > -1)
async_method.catch_handler = new InstructionOffset (GetInstruction (async_method.catch_handler.Offset));
if (!async_method.yields.IsNullOrEmpty ())
for (int i = 0; i < async_method.yields.Count; i++)
async_method.yields [i] = new InstructionOffset (GetInstruction (async_method.yields [i].Offset));
if (!async_method.resumes.IsNullOrEmpty ())
for (int i = 0; i < async_method.resumes.Count; i++)
async_method.resumes [i] = new InstructionOffset (GetInstruction (async_method.resumes [i].Offset));
}
void ReadStateMachineScope (StateMachineScopeDebugInformation state_machine_scope)
{
state_machine_scope.start = new InstructionOffset (GetInstruction (state_machine_scope.start.Offset));
var end_instruction = GetInstruction (state_machine_scope.end.Offset);
state_machine_scope.end = end_instruction == null
? new InstructionOffset ()
: new InstructionOffset (end_instruction);
}
void ReadSequencePoints ()
{
var symbol = method.debug_info;
for (int i = 0; i < symbol.sequence_points.Count; i++) {
var sequence_point = symbol.sequence_points [i];
var instruction = GetInstruction (sequence_point.Offset);
if (instruction != null)
sequence_point.offset = new InstructionOffset (instruction);
}
}
void ReadScopes (Collection<ScopeDebugInformation> scopes)
{
for (int i = 0; i < scopes.Count; i++)
ReadScope (scopes [i]);
}
void ReadScope (ScopeDebugInformation scope)
{
var start_instruction = GetInstruction (scope.Start.Offset);
if (start_instruction != null)
scope.Start = new InstructionOffset (start_instruction);
var end_instruction = GetInstruction (scope.End.Offset);
scope.End = end_instruction != null
? new InstructionOffset (end_instruction)
: new InstructionOffset ();
if (!scope.variables.IsNullOrEmpty ()) {
for (int i = 0; i < scope.variables.Count; i++) {
var variable_info = scope.variables [i];
var variable = GetVariable (variable_info.Index);
if (variable != null)
variable_info.index = new VariableIndex (variable);
}
}
if (!scope.scopes.IsNullOrEmpty ())
ReadScopes (scope.scopes);
}
void ReadFatMethod ()
{
var flags = ReadUInt16 ();
@@ -442,6 +373,104 @@ namespace Mono.Cecil.Cil {
return new MetadataToken (ReadUInt32 ());
}
void ReadDebugInfo ()
{
if (method.debug_info.sequence_points != null)
ReadSequencePoints ();
if (method.debug_info.scope != null)
ReadScope (method.debug_info.scope);
if (method.custom_infos != null)
ReadCustomDebugInformations (method);
}
void ReadCustomDebugInformations (MethodDefinition method)
{
var custom_infos = method.custom_infos;
for (int i = 0; i < custom_infos.Count; i++) {
var state_machine_scope = custom_infos [i] as StateMachineScopeDebugInformation;
if (state_machine_scope != null)
ReadStateMachineScope (state_machine_scope);
var async_method = custom_infos [i] as AsyncMethodBodyDebugInformation;
if (async_method != null)
ReadAsyncMethodBody (async_method);
}
}
void ReadAsyncMethodBody (AsyncMethodBodyDebugInformation async_method)
{
if (async_method.catch_handler.Offset > -1)
async_method.catch_handler = new InstructionOffset (GetInstruction (async_method.catch_handler.Offset));
if (!async_method.yields.IsNullOrEmpty ())
for (int i = 0; i < async_method.yields.Count; i++)
async_method.yields [i] = new InstructionOffset (GetInstruction (async_method.yields [i].Offset));
if (!async_method.resumes.IsNullOrEmpty ())
for (int i = 0; i < async_method.resumes.Count; i++)
async_method.resumes [i] = new InstructionOffset (GetInstruction (async_method.resumes [i].Offset));
}
void ReadStateMachineScope (StateMachineScopeDebugInformation state_machine_scope)
{
if (state_machine_scope.scopes.IsNullOrEmpty ())
return;
foreach (var scope in state_machine_scope.scopes) {
scope.start = new InstructionOffset (GetInstruction (scope.start.Offset));
var end_instruction = GetInstruction (scope.end.Offset);
scope.end = end_instruction == null
? new InstructionOffset ()
: new InstructionOffset (end_instruction);
}
}
void ReadSequencePoints ()
{
var symbol = method.debug_info;
for (int i = 0; i < symbol.sequence_points.Count; i++) {
var sequence_point = symbol.sequence_points [i];
var instruction = GetInstruction (sequence_point.Offset);
if (instruction != null)
sequence_point.offset = new InstructionOffset (instruction);
}
}
void ReadScopes (Collection<ScopeDebugInformation> scopes)
{
for (int i = 0; i < scopes.Count; i++)
ReadScope (scopes [i]);
}
void ReadScope (ScopeDebugInformation scope)
{
var start_instruction = GetInstruction (scope.Start.Offset);
if (start_instruction != null)
scope.Start = new InstructionOffset (start_instruction);
var end_instruction = GetInstruction (scope.End.Offset);
scope.End = end_instruction != null
? new InstructionOffset (end_instruction)
: new InstructionOffset ();
if (!scope.variables.IsNullOrEmpty ()) {
for (int i = 0; i < scope.variables.Count; i++) {
var variable_info = scope.variables [i];
var variable = GetVariable (variable_info.Index);
if (variable != null)
variable_info.index = new VariableIndex (variable);
}
}
if (!scope.scopes.IsNullOrEmpty ())
ReadScopes (scope.scopes);
}
#if !READ_ONLY
public ByteBuffer PatchRawMethodBody (MethodDefinition method, CodeWriter writer, out int code_size, out MetadataToken local_var_token)

View File

@@ -479,7 +479,7 @@ namespace Mono.Cecil.Cil {
internal InstructionOffset catch_handler;
internal Collection<InstructionOffset> yields;
internal Collection<InstructionOffset> resumes;
internal MethodDefinition move_next;
internal Collection<MethodDefinition> resume_methods;
public InstructionOffset CatchHandler {
get { return catch_handler; }
@@ -494,9 +494,8 @@ namespace Mono.Cecil.Cil {
get { return resumes ?? (resumes = new Collection<InstructionOffset> ()); }
}
public MethodDefinition MoveNextMethod {
get { return move_next; }
set { move_next = value; }
public Collection<MethodDefinition> ResumeMethods {
get { return resume_methods ?? (resume_methods = new Collection<MethodDefinition> ()); }
}
public override CustomDebugInformationKind Kind {
@@ -524,7 +523,7 @@ namespace Mono.Cecil.Cil {
}
}
public sealed class StateMachineScopeDebugInformation : CustomDebugInformation {
public sealed class StateMachineScope {
internal InstructionOffset start;
internal InstructionOffset end;
@@ -539,24 +538,36 @@ namespace Mono.Cecil.Cil {
set { end = value; }
}
internal StateMachineScope (int start, int end)
{
this.start = new InstructionOffset (start);
this.end = new InstructionOffset (end);
}
public StateMachineScope (Instruction start, Instruction end)
{
this.start = new InstructionOffset (start);
this.end = end != null ? new InstructionOffset (end) : new InstructionOffset ();
}
}
public sealed class StateMachineScopeDebugInformation : CustomDebugInformation {
internal Collection<StateMachineScope> scopes;
public Collection<StateMachineScope> Scopes {
get { return scopes ?? (scopes = new Collection<StateMachineScope> ()); }
}
public override CustomDebugInformationKind Kind {
get { return CustomDebugInformationKind.StateMachineScope; }
}
public static Guid KindIdentifier = new Guid ("{6DA9A61E-F8C7-4874-BE62-68BC5630DF71}");
internal StateMachineScopeDebugInformation (int start, int end)
public StateMachineScopeDebugInformation ()
: base (KindIdentifier)
{
this.start = new InstructionOffset (start);
this.end = new InstructionOffset (end);
}
public StateMachineScopeDebugInformation (Instruction start, Instruction end)
: base (KindIdentifier)
{
this.start = new InstructionOffset (start);
this.end = end != null ? new InstructionOffset (end) : new InstructionOffset ();
}
}
@@ -784,7 +795,7 @@ namespace Mono.Cecil.Cil {
try {
return SymbolProvider.GetReaderProvider (SymbolKind.NativePdb).GetSymbolReader (module, fileName);
} catch (TypeLoadException) {
} catch (Exception) {
// We might not include support for native pdbs.
}
}
@@ -793,7 +804,7 @@ namespace Mono.Cecil.Cil {
if (File.Exists (mdb_file_name)) {
try {
return SymbolProvider.GetReaderProvider (SymbolKind.Mdb).GetSymbolReader (module, fileName);
} catch (TypeLoadException) {
} catch (Exception) {
// We might not include support for mdbs.
}
}

View File

@@ -2,9 +2,27 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDirectory>$(MSBuildProjectDirectory)</BuildDirectory>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<Import Project="Mono.Cecil.props" />
<ItemGroup>
<PropertyGroup Condition="$(NetStandard)">
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition="!$(NetStandard)">
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup Condition="$(NetStandard)">
<PackageReference Include="NUnit">
<Version>3.7.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.3.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.8.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="!$(NetStandard)">
<Reference Include="nunit.core">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(MSBuildThisFileDirectory)\Test\libs\nunit-2.6.2\nunit.core.dll</HintPath>
@@ -18,4 +36,14 @@
<HintPath>$(MSBuildThisFileDirectory)\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<!-- Workaround for https://github.com/Microsoft/msbuild/issues/1310 -->
<Target Name="ForceGenerationOfBindingRedirects"
AfterTargets="ResolveAssemblyReferences"
BeforeTargets="GenerateBindingRedirects"
Condition="$(AutoGenerateBindingRedirects)">
<PropertyGroup>
<!-- Needs to be set in a target because it has to be set after the initial evaluation in the common targets -->
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
</Target>
</Project>

View File

@@ -2,7 +2,7 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Mono.Cecil</id>
<version>0.10.0.0-beta6</version>
<version>0.10.0.0-beta7</version>
<title>Mono.Cecil</title>
<authors>Jb Evain</authors>
<owners>Jb Evain</owners>

View File

@@ -14,6 +14,7 @@
<MSBuildCSharpTargets>$(MSBuildToolsPath)\Microsoft.CSharp.targets</MSBuildCSharpTargets>
<NetStandard Condition=" $(Configuration.StartsWith('netstandard')) Or '$(NuGetRestoreTargets)' != '' ">true</NetStandard>
<NetStandard Condition=" '$(NetStandard)' == '' ">false</NetStandard>
<IsTestProject Condition=" '$(IsTestProject)' == '' ">false</IsTestProject>
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.Contains('Debug')) ">
<DebugSymbols>true</DebugSymbols>
@@ -36,18 +37,19 @@
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.StartsWith('net_3_5')) ">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);</DefineConstants>
<DefineConstants>$(DefineConstants);NET_3_5;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" $(Configuration.StartsWith('net_4_0')) ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);NET_4_0;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" $(NetStandard) ">
<TargetFramework>netstandard1.3</TargetFramework>
<PropertyGroup Condition="$(NetStandard)">
<TargetFramework Condition="$(IsTestProject)">netcoreapp2.0</TargetFramework>
<TargetFramework Condition="!$(IsTestProject)">netstandard1.3</TargetFramework>
</PropertyGroup>
<Import Project="NetStandard.props" Condition=" $(NetStandard) " />
<Import Project="NetStandard.props" Condition="$(NetStandard)" />
<!-- Shared References -->
<ItemGroup Condition=" ! $(NetStandard) ">
<ItemGroup Condition="!$(NetStandard)">
<Reference Include="System.Core" />
<Reference Include="System" />
</ItemGroup>

View File

@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26927.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{74E5ECE0-06B4-401C-AEBA-E8DD53E17943}"
EndProject
@@ -22,6 +22,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks.Tests", "r
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Rocks", "rocks\Mono.Cecil.Rocks.csproj", "{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E0893F44-CB9F-49C5-B38C-70082EFC5072}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
net_3_5_Debug_ReadOnly|Any CPU = net_3_5_Debug_ReadOnly|Any CPU
@@ -81,9 +86,11 @@ Global
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Debug|Any CPU.Build.0 = netstandard_Debug|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}.netstandard_Release|Any CPU.Build.0 = netstandard_Release|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}.net_3_5_Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
@@ -125,10 +132,8 @@ Global
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{AC71DF9C-99FA-4A63-990A-66C8010355A6}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{63E6915C-7EA4-4D76-AB28-0D7191EEA626}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -171,10 +176,8 @@ Global
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -193,10 +196,8 @@ Global
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.net_4_0_Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug_ReadOnly|Any CPU.ActiveCfg = netstandard_Debug_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug_ReadOnly|Any CPU.Build.0 = netstandard_Debug_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Debug|Any CPU.ActiveCfg = netstandard_Debug|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release_ReadOnly|Any CPU.ActiveCfg = netstandard_Release_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release_ReadOnly|Any CPU.Build.0 = netstandard_Release_ReadOnly|Any CPU
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52}.netstandard_Release|Any CPU.ActiveCfg = netstandard_Release|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug_ReadOnly|Any CPU.ActiveCfg = net_3_5_Debug_ReadOnly|Any CPU
{FBC6DD59-D09D-499C-B03C-99C1C78FF2AC}.net_3_5_Debug_ReadOnly|Any CPU.Build.0 = net_3_5_Debug_ReadOnly|Any CPU
@@ -234,4 +235,7 @@ Global
{29300103-CB76-4A1D-B6FD-FFD91C1EC8AA} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943}
{C6CFD7E1-B855-44DC-B4CE-9CD72984AF52} = {74E5ECE0-06B4-401C-AEBA-E8DD53E17943}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D75C0801-AFCB-4B1F-90AD-2B7852A74E6A}
EndGlobalSection
EndGlobal

View File

@@ -156,7 +156,6 @@ namespace Mono.Cecil {
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
ReadModule (module, resolve_attributes: true);
return module;
});
}
@@ -422,10 +421,7 @@ namespace Mono.Cecil {
protected override void ReadModule ()
{
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
return module;
});
this.module.Read (this.module, (_, reader) => ReadModuleManifest (reader));
}
public override void ReadSymbols (ModuleDefinition module)
@@ -1680,23 +1676,19 @@ namespace Mono.Cecil {
}
}
public PropertyDefinition ReadMethods (PropertyDefinition property)
public void ReadMethods (PropertyDefinition property)
{
ReadAllSemantics (property.DeclaringType);
return property;
}
public EventDefinition ReadMethods (EventDefinition @event)
public void ReadMethods (EventDefinition @event)
{
ReadAllSemantics (@event.DeclaringType);
return @event;
}
public MethodSemanticsAttributes ReadAllSemantics (MethodDefinition method)
public void ReadAllSemantics (MethodDefinition method)
{
ReadAllSemantics (method.DeclaringType);
return method.SemanticsAttributes;
}
void ReadAllSemantics (TypeDefinition type)
@@ -2099,6 +2091,11 @@ namespace Mono.Cecil {
return code.ReadMethodBody (method);
}
public int ReadCodeSize (MethodDefinition method)
{
return code.ReadCodeSize (method);
}
public CallSite ReadCallSite (MetadataToken token)
{
if (!MoveTo (Table.StandAloneSig, token.RID))
@@ -2365,8 +2362,8 @@ namespace Mono.Cecil {
var type_system = module.TypeSystem;
var context = new MethodReference (string.Empty, type_system.Void);
context.DeclaringType = new TypeReference (string.Empty, string.Empty, module, type_system.CoreLibrary);
var context = new MethodDefinition (string.Empty, MethodAttributes.Static, type_system.Void);
context.DeclaringType = new TypeDefinition (string.Empty, string.Empty, TypeAttributes.Public);
var member_references = new MemberReference [length];
@@ -3161,25 +3158,36 @@ namespace Mono.Cecil {
for (int i = 0; i < rows.Length; i++) {
if (rows [i].Col1 == StateMachineScopeDebugInformation.KindIdentifier) {
var signature = ReadSignature (rows [i].Col2);
infos.Add (new StateMachineScopeDebugInformation (signature.ReadInt32 (), signature.ReadInt32 ()));
var scopes = new Collection<StateMachineScope> ();
while (signature.CanReadMore ()) {
var start = signature.ReadInt32 ();
var end = start + signature.ReadInt32 ();
scopes.Add (new StateMachineScope (start, end));
}
var state_machine = new StateMachineScopeDebugInformation ();
state_machine.scopes = scopes;
infos.Add (state_machine);
} else if (rows [i].Col1 == AsyncMethodBodyDebugInformation.KindIdentifier) {
var signature = ReadSignature (rows [i].Col2);
var catch_offset = signature.ReadInt32 () - 1;
var yields = new Collection<InstructionOffset> ();
var resumes = new Collection<InstructionOffset> ();
uint move_next_rid = 0;
var resume_methods = new Collection<MethodDefinition> ();
while (signature.CanReadMore ()) {
yields.Add (new InstructionOffset (signature.ReadInt32 ()));
resumes.Add (new InstructionOffset (signature.ReadInt32 ()));
move_next_rid = signature.ReadCompressedUInt32 ();
resume_methods.Add (GetMethodDefinition (signature.ReadCompressedUInt32 ()));
}
var async_body = new AsyncMethodBodyDebugInformation (catch_offset);
async_body.yields = yields;
async_body.resumes = resumes;
async_body.move_next = GetMethodDefinition (move_next_rid);
async_body.resume_methods = resume_methods;
infos.Add (async_body);
} else if (rows [i].Col1 == EmbeddedSourceDebugInformation.KindIdentifier) {
@@ -3348,7 +3356,7 @@ namespace Mono.Cecil {
switch (etype) {
case ElementType.ValueType: {
var value_type = GetTypeDefOrRef (ReadTypeTokenSignature ());
value_type.IsValueType = true;
value_type.KnownValueType ();
return value_type;
}
case ElementType.Class:
@@ -3388,8 +3396,8 @@ namespace Mono.Cecil {
ReadGenericInstanceSignature (element_type, generic_instance);
if (is_value_type) {
generic_instance.IsValueType = true;
element_type.GetElementType ().IsValueType = true;
generic_instance.KnownValueType ();
element_type.GetElementType ().KnownValueType ();
}
return generic_instance;

View File

@@ -2392,13 +2392,19 @@ namespace Mono.Cecil {
var method_info = ((MethodDefinition) provider).DebugInformation;
var signature = CreateSignatureWriter ();
signature.WriteUInt32 ((uint) state_machine_scope.Start.Offset);
var end_offset = state_machine_scope.End.IsEndOfMethod
? method_info.code_size
: state_machine_scope.End.Offset;
var scopes = state_machine_scope.Scopes;
signature.WriteUInt32 ((uint) (end_offset - state_machine_scope.Start.Offset));
for (int i = 0; i < scopes.Count; i++) {
var scope = scopes [i];
signature.WriteUInt32 ((uint) scope.Start.Offset);
var end_offset = scope.End.IsEndOfMethod
? method_info.code_size
: scope.End.Offset;
signature.WriteUInt32 ((uint) (end_offset - scope.Start.Offset));
}
AddCustomDebugInformation (provider, state_machine_scope, signature);
}
@@ -2411,7 +2417,7 @@ namespace Mono.Cecil {
for (int i = 0; i < async_method.yields.Count; i++) {
signature.WriteUInt32 ((uint) async_method.yields [i].Offset);
signature.WriteUInt32 ((uint) async_method.resumes [i].Offset);
signature.WriteCompressedUInt32 (async_method.move_next.MetadataToken.RID);
signature.WriteCompressedUInt32 (async_method.resume_methods [i].MetadataToken.RID);
}
AddCustomDebugInformation (provider, async_method, signature);

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Mono.Collections.Generic;
@@ -65,14 +66,19 @@ namespace Mono.Cecil {
#endif
}
#if !NET_CORE
public abstract class BaseAssemblyResolver : IAssemblyResolver {
static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null;
readonly Collection<string> directories;
#if NET_CORE
// Maps file names of available trusted platform assemblies to their full paths.
// Internal for testing.
internal static readonly Lazy<Dictionary<string, string>> TrustedPlatformAssemblies = new Lazy<Dictionary<string, string>> (CreateTrustedPlatformAssemblyMap);
#else
Collection<string> gac_paths;
#endif
public void AddSearchDirectory (string directory)
{
@@ -127,6 +133,11 @@ namespace Mono.Cecil {
};
}
#if NET_CORE
assembly = SearchTrustedPlatformAssemblies (name, parameters);
if (assembly != null)
return assembly;
#else
var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);
var framework_dirs = on_mono
? new [] { framework_dir, Path.Combine (framework_dir, "Facades") }
@@ -151,7 +162,7 @@ namespace Mono.Cecil {
assembly = SearchDirectory (name, framework_dirs, parameters);
if (assembly != null)
return assembly;
#endif
if (ResolveFailure != null) {
assembly = ResolveFailure (this, name);
if (assembly != null)
@@ -161,7 +172,45 @@ namespace Mono.Cecil {
throw new AssemblyResolutionException (name);
}
AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
#if NET_CORE
AssemblyDefinition SearchTrustedPlatformAssemblies (AssemblyNameReference name, ReaderParameters parameters)
{
if (name.IsWindowsRuntime)
return null;
if (TrustedPlatformAssemblies.Value.TryGetValue (name.Name, out string path))
return GetAssembly (path, parameters);
return null;
}
static Dictionary<string, string> CreateTrustedPlatformAssemblyMap ()
{
var result = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
string paths;
try {
// AppContext is only available on platforms that implement .NET Standard 1.6
var appContextType = Type.GetType ("System.AppContext, System.AppContext, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
var getData = appContextType?.GetTypeInfo ().GetDeclaredMethod ("GetData");
paths = (string) getData?.Invoke (null, new [] { "TRUSTED_PLATFORM_ASSEMBLIES" });
} catch {
paths = null;
}
if (paths == null)
return result;
foreach (var path in paths.Split (Path.PathSeparator))
if (string.Equals (Path.GetExtension (path), ".dll", StringComparison.OrdinalIgnoreCase))
result [Path.GetFileNameWithoutExtension (path)] = path;
return result;
}
#endif
protected virtual AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
{
var extensions = name.IsWindowsRuntime ? new [] { ".winmd", ".dll" } : new [] { ".exe", ".dll" };
foreach (var directory in directories) {
@@ -185,11 +234,11 @@ namespace Mono.Cecil {
return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
}
#if !NET_CORE
AssemblyDefinition GetCorlib (AssemblyNameReference reference, ReaderParameters parameters)
{
var version = reference.Version;
var corlib = typeof (object).Assembly.GetName ();
if (corlib.Version == version || IsZero (version))
return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters);
@@ -325,7 +374,7 @@ namespace Mono.Cecil {
return null;
}
#endif
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
@@ -352,5 +401,4 @@ namespace Mono.Cecil {
{
}
}
#endif
}

View File

@@ -62,8 +62,10 @@ namespace Mono.Cecil {
bool HasFields { get; }
bool HasProperties { get; }
bool HasConstructorArguments { get; }
Collection<CustomAttributeNamedArgument> Fields { get; }
Collection<CustomAttributeNamedArgument> Properties { get; }
Collection<CustomAttributeArgument> ConstructorArguments { get; }
}
public sealed class CustomAttribute : ICustomAttribute {
@@ -196,7 +198,6 @@ namespace Mono.Cecil {
resolved = false;
}
return this;
});
}
}

View File

@@ -8,8 +8,6 @@
// Licensed under the MIT/X11 license.
//
#if !NET_CORE
using System;
using System.Collections.Generic;
@@ -61,5 +59,3 @@ namespace Mono.Cecil {
}
}
}
#endif

View File

@@ -143,9 +143,9 @@ namespace Mono.Cecil {
public MethodBody Body {
get {
MethodBody localBody = this.body;
if (localBody != null)
return localBody;
var local = this.body;
if (local != null)
return local;
if (!HasBody)
return null;

Some files were not shown because too many files have changed in this diff Show More