Imported Upstream version 5.4.0.199

Former-commit-id: f4d318e4b2f128fa9f4d31b37bb3839a3fc0dfb2
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-09-25 16:57:44 +00:00
parent 536cd135cc
commit 5924117973
223 changed files with 3826 additions and 487 deletions

View File

@@ -58,10 +58,12 @@ namespace Mono.Cecil.Mdb {
this.documents = new Dictionary<string, Document> ();
}
#if !READ_ONLY
public ISymbolWriterProvider GetWriterProvider ()
{
return new MdbWriterProvider ();
}
#endif
public bool ProcessDebugHeader (ImageDebugHeader header)
{

View File

@@ -684,6 +684,7 @@ namespace Mono.CompilerServices.SymbolWriter
byte[] hash;
bool creating;
bool auto_generated;
readonly string sourceFile;
public static int Size {
get { return 8; }
@@ -698,11 +699,17 @@ namespace Mono.CompilerServices.SymbolWriter
creating = true;
}
public SourceFileEntry (MonoSymbolFile file, string file_name, byte[] guid, byte[] checksum)
: this (file, file_name)
public SourceFileEntry (MonoSymbolFile file, string sourceFile, byte [] guid, byte [] checksum)
: this (file, sourceFile, sourceFile, guid, checksum)
{
}
public SourceFileEntry (MonoSymbolFile file, string fileName, string sourceFile, byte[] guid, byte[] checksum)
: this (file, fileName)
{
this.guid = guid;
this.hash = checksum;
this.sourceFile = sourceFile;
}
public byte[] Checksum {
@@ -719,29 +726,22 @@ namespace Mono.CompilerServices.SymbolWriter
if (guid == null)
guid = new byte[16];
if (hash == null)
hash = ComputeHash ();
if (hash == null) {
try {
using (FileStream fs = new FileStream (sourceFile, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
hash = md5.ComputeHash (fs);
}
} catch {
hash = new byte [16];
}
}
bw.Write (guid);
bw.Write (hash);
bw.Write ((byte) (auto_generated ? 1 : 0));
}
private byte [] ComputeHash ()
{
if (!File.Exists (file_name))
return new byte [16];
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open, FileAccess.Read)) {
MD5 md5 = MD5.Create ();
return md5.ComputeHash (fs);
}
} catch {
return new byte [16];
}
}
internal void Write (BinaryWriter bw)
{
bw.Write (Index);
@@ -758,7 +758,7 @@ namespace Mono.CompilerServices.SymbolWriter
int old_pos = (int) reader.BaseStream.Position;
reader.BaseStream.Position = DataOffset;
file_name = reader.ReadString ();
sourceFile = file_name = reader.ReadString ();
guid = reader.ReadBytes (16);
hash = reader.ReadBytes (16);
auto_generated = reader.ReadByte () == 1;
@@ -787,7 +787,7 @@ namespace Mono.CompilerServices.SymbolWriter
public bool CheckChecksum ()
{
try {
using (FileStream fs = new FileStream (file_name, FileMode.Open)) {
using (FileStream fs = new FileStream (sourceFile, FileMode.Open)) {
MD5 md5 = MD5.Create ();
byte[] data = md5.ComputeHash (fs);
for (int i = 0; i < 16; i++)

View File

@@ -28,6 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
namespace Mono.CompilerServices.SymbolWriter
@@ -89,6 +90,11 @@ namespace Mono.CompilerServices.SymbolWriter
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset)
{
StartBlock (type, start_offset, _blocks == null ? 1 : _blocks.Count + 1);
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset, int scopeIndex)
{
if (_block_stack == null) {
_block_stack = new Stack<CodeBlockEntry> ();
@@ -100,7 +106,7 @@ namespace Mono.CompilerServices.SymbolWriter
int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
CodeBlockEntry block = new CodeBlockEntry (
_blocks.Count + 1, parent, type, start_offset);
scopeIndex, parent, type, start_offset);
_block_stack.Push (block);
_blocks.Add (block);
@@ -180,9 +186,59 @@ namespace Mono.CompilerServices.SymbolWriter
public void DefineMethod (MonoSymbolFile file, int token)
{
MethodEntry entry = new MethodEntry (
var blocks = Blocks;
if (blocks.Length > 0) {
//
// When index is provided by user it can be inserted in
// any order but mdb format does not store its value. It
// uses stored order as the index instead.
//
var sorted = new List<CodeBlockEntry> (blocks.Length);
int max_index = 0;
for (int i = 0; i < blocks.Length; ++i) {
max_index = System.Math.Max (max_index, blocks [i].Index);
}
for (int i = 0; i < max_index; ++i) {
var scope_index = i + 1;
//
// Common fast path
//
if (i < blocks.Length && blocks [i].Index == scope_index) {
sorted.Add (blocks [i]);
continue;
}
bool found = false;
for (int ii = 0; ii < blocks.Length; ++ii) {
if (blocks [ii].Index == scope_index) {
sorted.Add (blocks [ii]);
found = true;
break;
}
}
if (found)
continue;
//
// Ideally this should never happen but with current design we can
// generate scope index for unreachable code before reachable code
//
sorted.Add (new CodeBlockEntry (scope_index, -1, CodeBlockEntry.Type.CompilerGenerated, 0));
}
blocks = sorted.ToArray ();
//for (int i = 0; i < blocks.Length; ++i) {
// if (blocks [i].Index - 1 != i)
// throw new ArgumentException ("CodeBlocks cannot be converted to mdb format");
//}
}
var entry = new MethodEntry (
file, _comp_unit.Entry, token, ScopeVariables,
Locals, method_lines.ToArray (), Blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
Locals, method_lines.ToArray (), blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);
file.AddMethod (entry);
}

View File

@@ -1,4 +1,4 @@
#if !READ_ONLY
using Mono.Cecil.Mdb;
using NUnit.Framework;
@@ -83,3 +83,4 @@ namespace Mono.Cecil.Tests {
}
}
}
#endif

View File

@@ -35,11 +35,12 @@ namespace Mono.Cecil.Pdb {
this.pdb_file = file;
}
#if !READ_ONLY
public ISymbolWriterProvider GetWriterProvider ()
{
return new NativePdbWriterProvider ();
}
#endif
/*
uint Magic = 0x53445352;
Guid Signature;
@@ -211,6 +212,7 @@ namespace Mono.Cecil.Pdb {
} else {
import = GetImport (scope, info.Method.Module);
imports.Add (scope, import);
parent.import = import;
}
}
@@ -262,6 +264,9 @@ namespace Mono.Cecil.Pdb {
var import = new ImportDebugInformation ();
foreach (var used_namespace in scope.usedNamespaces) {
if (string.IsNullOrEmpty (used_namespace))
continue;
ImportTarget target = null;
var value = used_namespace.Substring (1);
switch (used_namespace [0]) {

View File

@@ -80,6 +80,10 @@ namespace Mono.Cecil.Pdb {
this.metadata = metadata;
}
void IMetadataSymbolWriter.WriteModule ()
{
}
void DefineCustomMetadata (MethodDebugInformation info, MetadataToken import_parent)
{
var metadata = new CustomMetadataWriter (this.writer);

View File

@@ -1,4 +1,4 @@
#if !READ_ONLY
using System.IO;
using System.Linq;
@@ -153,6 +153,13 @@ namespace Mono.Cecil.Tests {
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}
[Test]
public void EmptyRootNamespace ()
{
TestModule ("EmptyRootNamespace.dll", module => {
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
}
[Test]
public void LocalVariables ()
{
@@ -358,6 +365,42 @@ namespace Mono.Cecil.Tests {
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}
[Test]
public void ImportsForFirstMethod ()
{
TestModule ("CecilTest.exe", module => {
var type = module.GetType ("CecilTest.Program");
var method = type.GetMethod ("Main");
var debug = method.DebugInformation;
var scope = debug.Scope;
Assert.IsTrue (scope.End.IsEndOfMethod);
var import = scope.Import;
Assert.IsNotNull (import);
Assert.AreEqual (5, import.Targets.Count);
var ns = new [] {
"System",
"System.Collections.Generic",
"System.Linq",
"System.Text",
"System.Threading.Tasks",
};
for (int i = 0; i < import.Targets.Count; i++) {
var target = import.Targets [i];
Assert.AreEqual (ImportTargetKind.ImportNamespace, target.Kind);
Assert.AreEqual (ns [i], target.Namespace);
}
Assert.AreEqual ("System", import.Targets [0].Namespace);
}, readOnly: Platform.OnMono, symbolReaderProvider: typeof (PdbReaderProvider), symbolWriterProvider: typeof (PdbWriterProvider));
}
[Test]
public void CreateMethodFromScratch ()
{
@@ -412,3 +455,4 @@ namespace Mono.Cecil.Tests {
}
}
}
#endif