diff options
author | Marek Safar <marek.safar@gmail.com> | 2017-08-04 17:38:12 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-08-04 17:38:12 +0300 |
commit | 14e17dfbebf5651b5ce70c7fb317e388f8a3a271 (patch) | |
tree | 1b09ca46c332c133bd10aee9fec2209fcc3b4d12 | |
parent | c76ba7b410447fa37093150cb7bc772cba28a0ae (diff) | |
parent | c5c135a8a255883fa8ec2e7ff0b1a437e8bebaa8 (diff) |
Merge remote-tracking branch 'upstream/master'
6 files changed, 92 insertions, 31 deletions
diff --git a/Mono.Cecil.Cil/CodeReader.cs b/Mono.Cecil.Cil/CodeReader.cs index 11cc7e9..17376d4 100644 --- a/Mono.Cecil.Cil/CodeReader.cs +++ b/Mono.Cecil.Cil/CodeReader.cs @@ -160,7 +160,8 @@ namespace Mono.Cecil.Cil { void ReadScope (ScopeDebugInformation scope) { var start_instruction = GetInstruction (scope.Start.Offset); - scope.Start = new InstructionOffset (start_instruction); + if (start_instruction != null) + scope.Start = new InstructionOffset (start_instruction); var end_instruction = GetInstruction (scope.End.Offset); scope.End = end_instruction != null diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs index e5003b8..5496cac 100644 --- a/Mono.Cecil/AssemblyWriter.cs +++ b/Mono.Cecil/AssemblyWriter.cs @@ -775,7 +775,7 @@ namespace Mono.Cecil { } } - sealed class CustomDebugInformationTable : MetadataTable<CustomDebugInformationRow> { + sealed class CustomDebugInformationTable : SortedTable<CustomDebugInformationRow> { public override void Write (TableHeapBuffer buffer) { @@ -785,6 +785,11 @@ namespace Mono.Cecil { buffer.WriteBlob (rows [i].Col3); // Value } } + + public override int Compare (CustomDebugInformationRow x, CustomDebugInformationRow y) + { + return Compare(x.Col1, y.Col1); + } } sealed class MetadataBuilder { diff --git a/Test/Mono.Cecil.Tests/CompilationService.cs b/Test/Mono.Cecil.Tests/CompilationService.cs index 54fef5f..877ed24 100644 --- a/Test/Mono.Cecil.Tests/CompilationService.cs +++ b/Test/Mono.Cecil.Tests/CompilationService.cs @@ -251,6 +251,10 @@ namespace Mono.Cecil.Tests { static string WinSdkTool (string tool) { var sdks = new [] { + @"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools", + @"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools", + @"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools", + @"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools", @"Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools", @"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools", @"Microsoft SDKs\Windows\v7.0A\Bin", diff --git a/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs b/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs index 6598df7..0c2c125 100644 --- a/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs +++ b/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs @@ -58,10 +58,5 @@ namespace Mono.Cecil.Tests { Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ())); }); } - - static string Normalize (string s) - { - return s.Replace ("\n", "").Replace ("\r", ""); - } } } diff --git a/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs b/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs index fab5eff..0eec10f 100644 --- a/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs +++ b/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs @@ -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++) diff --git a/symbols/mdb/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs b/symbols/mdb/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs index 88363e7..094425c 100644 --- a/symbols/mdb/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs +++ b/symbols/mdb/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs @@ -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 @@ -90,6 +91,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); } |