You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
16
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs
vendored
Normal file
16
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle ("Mono.Cecil.Mdb")]
|
||||
|
||||
[assembly: CLSCompliant (false)]
|
||||
204
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs
vendored
Normal file
204
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Collections.Generic;
|
||||
using Mono.CompilerServices.SymbolWriter;
|
||||
|
||||
namespace Mono.Cecil.Mdb {
|
||||
|
||||
public sealed class MdbReaderProvider : ISymbolReaderProvider {
|
||||
|
||||
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
|
||||
{
|
||||
Mixin.CheckModule (module);
|
||||
Mixin.CheckFileName (fileName);
|
||||
|
||||
return new MdbReader (module, MonoSymbolFile.ReadSymbolFile (Mixin.GetMdbFileName (fileName), module.Mvid));
|
||||
}
|
||||
|
||||
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
|
||||
{
|
||||
Mixin.CheckModule (module);
|
||||
Mixin.CheckStream (symbolStream);
|
||||
|
||||
var file = MonoSymbolFile.ReadSymbolFile (symbolStream);
|
||||
if (module.Mvid != file.Guid) {
|
||||
var file_stream = symbolStream as FileStream;
|
||||
if (file_stream != null)
|
||||
throw new MonoSymbolFileException ("Symbol file `{0}' does not match assembly", file_stream.Name);
|
||||
|
||||
throw new MonoSymbolFileException ("Symbol file from stream does not match assembly");
|
||||
}
|
||||
return new MdbReader (module, file);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MdbReader : ISymbolReader {
|
||||
|
||||
readonly ModuleDefinition module;
|
||||
readonly MonoSymbolFile symbol_file;
|
||||
readonly Dictionary<string, Document> documents;
|
||||
|
||||
public MdbReader (ModuleDefinition module, MonoSymbolFile symFile)
|
||||
{
|
||||
this.module = module;
|
||||
this.symbol_file = symFile;
|
||||
this.documents = new Dictionary<string, Document> ();
|
||||
}
|
||||
|
||||
public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header)
|
||||
{
|
||||
return symbol_file.Guid == module.Mvid;
|
||||
}
|
||||
|
||||
public MethodDebugInformation Read (MethodDefinition method)
|
||||
{
|
||||
var method_token = method.MetadataToken;
|
||||
var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ());
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
var info = new MethodDebugInformation (method);
|
||||
|
||||
var scopes = ReadScopes (entry, info);
|
||||
ReadLineNumbers (entry, info);
|
||||
ReadLocalVariables (entry, scopes);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static void ReadLocalVariables (MethodEntry entry, ScopeDebugInformation [] scopes)
|
||||
{
|
||||
var locals = entry.GetLocals ();
|
||||
|
||||
foreach (var local in locals) {
|
||||
var variable = new VariableDebugInformation (local.Index, local.Name);
|
||||
|
||||
var index = local.BlockIndex;
|
||||
if (index < 0 || index >= scopes.Length)
|
||||
continue;
|
||||
|
||||
var scope = scopes [index];
|
||||
if (scope == null)
|
||||
continue;
|
||||
|
||||
scope.Variables.Add (variable);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadLineNumbers (MethodEntry entry, MethodDebugInformation info)
|
||||
{
|
||||
var table = entry.GetLineNumberTable ();
|
||||
|
||||
info.sequence_points = new Collection<SequencePoint> (table.LineNumbers.Length);
|
||||
|
||||
for (var i = 0; i < table.LineNumbers.Length; i++) {
|
||||
var line = table.LineNumbers [i];
|
||||
if (i > 0 && table.LineNumbers [i - 1].Offset == line.Offset)
|
||||
continue;
|
||||
|
||||
info.sequence_points.Add (LineToSequencePoint (line));
|
||||
}
|
||||
}
|
||||
|
||||
Document GetDocument (SourceFileEntry file)
|
||||
{
|
||||
var file_name = file.FileName;
|
||||
|
||||
Document document;
|
||||
if (documents.TryGetValue (file_name, out document))
|
||||
return document;
|
||||
|
||||
document = new Document (file_name) {
|
||||
Hash = file.Checksum,
|
||||
};
|
||||
|
||||
documents.Add (file_name, document);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
static ScopeDebugInformation [] ReadScopes (MethodEntry entry, MethodDebugInformation info)
|
||||
{
|
||||
var blocks = entry.GetCodeBlocks ();
|
||||
var scopes = new ScopeDebugInformation [blocks.Length + 1];
|
||||
|
||||
info.scope = scopes [0] = new ScopeDebugInformation {
|
||||
Start = new InstructionOffset (0),
|
||||
End = new InstructionOffset (info.code_size),
|
||||
};
|
||||
|
||||
foreach (var block in blocks) {
|
||||
if (block.BlockType != CodeBlockEntry.Type.Lexical && block.BlockType != CodeBlockEntry.Type.CompilerGenerated)
|
||||
continue;
|
||||
|
||||
var scope = new ScopeDebugInformation ();
|
||||
scope.Start = new InstructionOffset (block.StartOffset);
|
||||
scope.End = new InstructionOffset (block.EndOffset);
|
||||
|
||||
scopes [block.Index + 1] = scope;
|
||||
|
||||
if (!AddScope (info.scope.Scopes, scope))
|
||||
info.scope.Scopes.Add (scope);
|
||||
}
|
||||
|
||||
return scopes;
|
||||
}
|
||||
|
||||
static bool AddScope (Collection<ScopeDebugInformation> scopes, ScopeDebugInformation scope)
|
||||
{
|
||||
foreach (var sub_scope in scopes) {
|
||||
if (sub_scope.HasScopes && AddScope (sub_scope.Scopes, scope))
|
||||
return true;
|
||||
|
||||
if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) {
|
||||
sub_scope.Scopes.Add (scope);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SequencePoint LineToSequencePoint (LineNumberEntry line)
|
||||
{
|
||||
var source = symbol_file.GetSourceFile (line.File);
|
||||
return new SequencePoint (line.Offset, GetDocument (source)) {
|
||||
StartLine = line.Row,
|
||||
EndLine = line.EndRow,
|
||||
StartColumn = line.Column,
|
||||
EndColumn = line.EndColumn,
|
||||
};
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
symbol_file.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
static class MethodEntryExtensions {
|
||||
|
||||
public static bool HasColumnInfo (this MethodEntry entry)
|
||||
{
|
||||
return (entry.MethodFlags & MethodEntry.Flags.ColumnsInfoIncluded) != 0;
|
||||
}
|
||||
|
||||
public static bool HasEndInfo (this MethodEntry entry)
|
||||
{
|
||||
return (entry.MethodFlags & MethodEntry.Flags.EndInfoIncluded) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
212
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs
vendored
Normal file
212
external/linker/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// Author:
|
||||
// Jb Evain (jbevain@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2008 - 2015 Jb Evain
|
||||
// Copyright (c) 2008 - 2011 Novell, Inc.
|
||||
//
|
||||
// Licensed under the MIT/X11 license.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Collections.Generic;
|
||||
using Mono.CompilerServices.SymbolWriter;
|
||||
|
||||
namespace Mono.Cecil.Mdb {
|
||||
|
||||
#if !READ_ONLY
|
||||
public sealed class MdbWriterProvider : ISymbolWriterProvider {
|
||||
|
||||
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
|
||||
{
|
||||
Mixin.CheckModule (module);
|
||||
Mixin.CheckFileName (fileName);
|
||||
|
||||
return new MdbWriter (module.Mvid, fileName);
|
||||
}
|
||||
|
||||
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MdbWriter : ISymbolWriter {
|
||||
|
||||
readonly Guid mvid;
|
||||
readonly MonoSymbolWriter writer;
|
||||
readonly Dictionary<string, SourceFile> source_files;
|
||||
|
||||
public MdbWriter (Guid mvid, string assembly)
|
||||
{
|
||||
this.mvid = mvid;
|
||||
this.writer = new MonoSymbolWriter (assembly);
|
||||
this.source_files = new Dictionary<string, SourceFile> ();
|
||||
}
|
||||
|
||||
SourceFile GetSourceFile (Document document)
|
||||
{
|
||||
var url = document.Url;
|
||||
|
||||
SourceFile source_file;
|
||||
if (source_files.TryGetValue (url, out source_file))
|
||||
return source_file;
|
||||
|
||||
var entry = writer.DefineDocument (url, null, document.Hash != null && document.Hash.Length == 16 ? document.Hash : null);
|
||||
var compile_unit = writer.DefineCompilationUnit (entry);
|
||||
|
||||
source_file = new SourceFile (compile_unit, entry);
|
||||
source_files.Add (url, source_file);
|
||||
return source_file;
|
||||
}
|
||||
|
||||
void Populate (Collection<SequencePoint> sequencePoints, int [] offsets,
|
||||
int [] startRows, int [] endRows, int [] startCols, int [] endCols, out SourceFile file)
|
||||
{
|
||||
SourceFile source_file = null;
|
||||
|
||||
for (int i = 0; i < sequencePoints.Count; i++) {
|
||||
var sequence_point = sequencePoints [i];
|
||||
offsets [i] = sequence_point.Offset;
|
||||
|
||||
if (source_file == null)
|
||||
source_file = GetSourceFile (sequence_point.Document);
|
||||
|
||||
startRows [i] = sequence_point.StartLine;
|
||||
endRows [i] = sequence_point.EndLine;
|
||||
startCols [i] = sequence_point.StartColumn;
|
||||
endCols [i] = sequence_point.EndColumn;
|
||||
}
|
||||
|
||||
file = source_file;
|
||||
}
|
||||
|
||||
public void Write (MethodDebugInformation info)
|
||||
{
|
||||
var method = new SourceMethod (info.method);
|
||||
|
||||
var sequence_points = info.SequencePoints;
|
||||
int count = sequence_points.Count;
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
var offsets = new int [count];
|
||||
var start_rows = new int [count];
|
||||
var end_rows = new int [count];
|
||||
var start_cols = new int [count];
|
||||
var end_cols = new int [count];
|
||||
|
||||
SourceFile file;
|
||||
Populate (sequence_points, offsets, start_rows, end_rows, start_cols, end_cols, out file);
|
||||
|
||||
var builder = writer.OpenMethod (file.CompilationUnit, 0, method);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
builder.MarkSequencePoint (
|
||||
offsets [i],
|
||||
file.CompilationUnit.SourceFile,
|
||||
start_rows [i],
|
||||
start_cols [i],
|
||||
end_rows [i],
|
||||
end_cols [i],
|
||||
false);
|
||||
}
|
||||
|
||||
if (info.scope != null)
|
||||
WriteRootScope (info.scope, info);
|
||||
|
||||
writer.CloseMethod ();
|
||||
}
|
||||
|
||||
void WriteRootScope (ScopeDebugInformation scope, MethodDebugInformation info)
|
||||
{
|
||||
WriteScopeVariables (scope);
|
||||
|
||||
if (scope.HasScopes)
|
||||
WriteScopes (scope.Scopes, info);
|
||||
}
|
||||
|
||||
void WriteScope (ScopeDebugInformation scope, MethodDebugInformation info)
|
||||
{
|
||||
writer.OpenScope (scope.Start.Offset);
|
||||
|
||||
WriteScopeVariables (scope);
|
||||
|
||||
if (scope.HasScopes)
|
||||
WriteScopes (scope.Scopes, info);
|
||||
|
||||
writer.CloseScope (scope.End.IsEndOfMethod ? info.code_size : scope.End.Offset);
|
||||
}
|
||||
|
||||
void WriteScopes (Collection<ScopeDebugInformation> scopes, MethodDebugInformation info)
|
||||
{
|
||||
for (int i = 0; i < scopes.Count; i++)
|
||||
WriteScope (scopes [i], info);
|
||||
}
|
||||
|
||||
void WriteScopeVariables (ScopeDebugInformation scope)
|
||||
{
|
||||
if (!scope.HasVariables)
|
||||
return;
|
||||
|
||||
foreach (var variable in scope.variables)
|
||||
if (!string.IsNullOrEmpty (variable.Name))
|
||||
writer.DefineLocalVariable (variable.Index, variable.Name);
|
||||
}
|
||||
|
||||
public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header)
|
||||
{
|
||||
directory = new ImageDebugDirectory ();
|
||||
header = Empty<byte>.Array;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
writer.WriteSymbolFile (mvid);
|
||||
}
|
||||
|
||||
class SourceFile : ISourceFile {
|
||||
|
||||
readonly CompileUnitEntry compilation_unit;
|
||||
readonly SourceFileEntry entry;
|
||||
|
||||
public SourceFileEntry Entry {
|
||||
get { return entry; }
|
||||
}
|
||||
|
||||
public CompileUnitEntry CompilationUnit {
|
||||
get { return compilation_unit; }
|
||||
}
|
||||
|
||||
public SourceFile (CompileUnitEntry comp_unit, SourceFileEntry entry)
|
||||
{
|
||||
this.compilation_unit = comp_unit;
|
||||
this.entry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
class SourceMethod : IMethodDef {
|
||||
|
||||
readonly MethodDefinition method;
|
||||
|
||||
public string Name {
|
||||
get { return method.Name; }
|
||||
}
|
||||
|
||||
public int Token {
|
||||
get { return method.MetadataToken.ToInt32 (); }
|
||||
}
|
||||
|
||||
public SourceMethod (MethodDefinition method)
|
||||
{
|
||||
this.method = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user