Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -0,0 +1,4 @@
bin
obj
*.xml
*.user

View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Mdb</RootNamespace>
<AssemblyName>Mono.Cecil.Mdb</AssemblyName>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\mono.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_2_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_2_0_Release\</OutputPath>
<DefineConstants>TRACE;CECIL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_3_5_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_3_5_Release\</OutputPath>
<DefineConstants>TRACE;CECIL;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\net_4_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;CECIL;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\net_4_0_Release\</OutputPath>
<DefineConstants>TRACE;CECIL;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' ">
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Mdb\AssemblyInfo.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbReader.cs" />
<Compile Include="Mono.Cecil.Mdb\MdbWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolFile.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolTable.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\MonoSymbolWriter.cs" />
<Compile Include="Mono.CompilerServices.SymbolWriter\SymbolWriterImpl.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,41 @@
//
// AssemblyInfo.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle ("Mono.Cecil.Mdb")]
[assembly: AssemblyProduct ("Mono.Cecil")]
[assembly: AssemblyCopyright ("Copyright <20> 2008 - 2011 Jb Evain")]
[assembly: CLSCompliant (false)]
[assembly: ComVisible (false)]
[assembly: AssemblyVersion ("0.9.5.0")]
[assembly: AssemblyFileVersion ("0.9.5.0")]

View File

@@ -0,0 +1,222 @@
//
// MdbReader.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
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 class MdbReaderProvider : ISymbolReaderProvider {
public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName)
{
return new MdbReader (module, MonoSymbolFile.ReadSymbolFile (module, fileName));
}
public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream)
{
throw new NotImplementedException ();
}
}
public 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 void Read (MethodBody body, InstructionMapper mapper)
{
var method_token = body.Method.MetadataToken;
var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ());
if (entry == null)
return;
var scopes = ReadScopes (entry, body, mapper);
ReadLineNumbers (entry, mapper);
ReadLocalVariables (entry, body, scopes);
}
static void ReadLocalVariables (MethodEntry entry, MethodBody body, Scope [] scopes)
{
var locals = entry.GetLocals ();
foreach (var local in locals) {
if (local.Index < 0 || local.Index >= body.Variables.Count) // Mono 2.6 emits wrong local infos for iterators
continue;
var variable = body.Variables [local.Index];
variable.Name = 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, InstructionMapper mapper)
{
Document document = null;
var table = entry.GetLineNumberTable ();
foreach (var line in table.LineNumbers) {
var instruction = mapper (line.Offset);
if (instruction == null)
continue;
if (document == null)
document = GetDocument (entry.CompileUnit.SourceFile);
instruction.SequencePoint = new SequencePoint (document) {
StartLine = line.Row,
EndLine = line.Row,
};
}
}
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);
documents.Add (file_name, document);
return document;
}
static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper)
{
var blocks = entry.GetCodeBlocks ();
var scopes = new Scope [blocks.Length];
foreach (var block in blocks) {
if (block.BlockType != CodeBlockEntry.Type.Lexical)
continue;
var scope = new Scope ();
scope.Start = mapper (block.StartOffset);
scope.End = mapper (block.EndOffset);
scopes [block.Index] = scope;
if (body.Scope == null)
body.Scope = scope;
if (!AddScope (body.Scope, scope))
body.Scope = scope;
}
return scopes;
}
static bool AddScope (Scope provider, Scope scope)
{
foreach (var sub_scope in provider.Scopes) {
if (AddScope (sub_scope, 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;
}
public void Read (MethodSymbols symbols)
{
var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ());
if (entry == null)
return;
ReadLineNumbers (entry, symbols);
ReadLocalVariables (entry, symbols);
}
void ReadLineNumbers (MethodEntry entry, MethodSymbols symbols)
{
var table = entry.GetLineNumberTable ();
var lines = table.LineNumbers;
var instructions = symbols.instructions = new Collection<InstructionSymbol> (lines.Length);
for (int i = 0; i < lines.Length; i++) {
var line = lines [i];
instructions.Add (new InstructionSymbol (line.Offset, new SequencePoint (GetDocument (entry.CompileUnit.SourceFile)) {
StartLine = line.Row,
EndLine = line.Row,
}));
}
}
static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols)
{
foreach (var local in entry.GetLocals ()) {
if (local.Index < 0 || local.Index >= symbols.Variables.Count) // Mono 2.6 emits wrong local infos for iterators
continue;
var variable = symbols.Variables [local.Index];
variable.Name = local.Name;
}
}
public void Dispose ()
{
symbol_file.Dispose ();
}
}
}

View File

@@ -0,0 +1,251 @@
//
// MdbWriter.cs
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2011 Jb Evain
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
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 class MdbWriterProvider : ISymbolWriterProvider {
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
return new MdbWriter (module.Mvid, fileName);
}
public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream)
{
throw new NotImplementedException ();
}
}
public 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> ();
}
static Collection<Instruction> GetInstructions (MethodBody body)
{
var instructions = new Collection<Instruction> ();
foreach (var instruction in body.Instructions)
if (instruction.SequencePoint != null)
instructions.Add (instruction);
return instructions;
}
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);
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<Instruction> instructions, int [] offsets,
int [] startRows, int [] startCols, out SourceFile file)
{
SourceFile source_file = null;
for (int i = 0; i < instructions.Count; i++) {
var instruction = instructions [i];
offsets [i] = instruction.Offset;
var sequence_point = instruction.SequencePoint;
if (source_file == null)
source_file = GetSourceFile (sequence_point.Document);
startRows [i] = sequence_point.StartLine;
startCols [i] = sequence_point.StartColumn;
}
file = source_file;
}
public void Write (MethodBody body)
{
var method = new SourceMethod (body.Method);
var instructions = GetInstructions (body);
int count = instructions.Count;
if (count == 0)
return;
var offsets = new int [count];
var start_rows = new int [count];
var start_cols = new int [count];
SourceFile file;
Populate (instructions, offsets, start_rows, start_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],
false);
if (body.HasVariables)
AddVariables (body.Variables);
writer.CloseMethod ();
}
readonly static byte [] empty_header = new byte [0];
public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header)
{
directory = new ImageDebugDirectory ();
header = empty_header;
return false;
}
void AddVariables (IList<VariableDefinition> variables)
{
for (int i = 0; i < variables.Count; i++) {
var variable = variables [i];
writer.DefineLocalVariable (i, variable.Name);
}
}
public void Write (MethodSymbols symbols)
{
var method = new SourceMethodSymbol (symbols);
var file = GetSourceFile (symbols.Instructions [0].SequencePoint.Document);
var builder = writer.OpenMethod (file.CompilationUnit, 0, method);
var count = symbols.Instructions.Count;
for (int i = 0; i < count; i++) {
var instruction = symbols.Instructions [i];
var sequence_point = instruction.SequencePoint;
builder.MarkSequencePoint (
instruction.Offset,
GetSourceFile (sequence_point.Document).CompilationUnit.SourceFile,
sequence_point.StartLine,
sequence_point.EndLine,
false);
}
if (symbols.HasVariables)
AddVariables (symbols.Variables);
writer.CloseMethod ();
}
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 SourceMethodSymbol : IMethodDef {
readonly string name;
readonly int token;
public string Name {
get { return name;}
}
public int Token {
get { return token; }
}
public SourceMethodSymbol (MethodSymbols symbols)
{
name = symbols.MethodName;
token = symbols.MethodToken.ToInt32 ();
}
}
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
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,403 @@
//
// Mono.CSharp.Debugger/MonoSymbolWriter.cs
//
// Author:
// Martin Baulig (martin@ximian.com)
//
// This is the default implementation of the System.Diagnostics.SymbolStore.ISymbolWriter
// interface.
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
namespace Mono.CompilerServices.SymbolWriter
{
public class MonoSymbolWriter
{
List<SourceMethodBuilder> methods;
List<SourceFileEntry> sources;
List<CompileUnitEntry> comp_units;
protected readonly MonoSymbolFile file;
string filename;
private SourceMethodBuilder current_method;
#if NET_2_1
System.Collections.Stack current_method_stack = new System.Collections.Stack ();
#else
Stack<SourceMethodBuilder> current_method_stack = new Stack<SourceMethodBuilder> ();
#endif
public MonoSymbolWriter (string filename)
{
this.methods = new List<SourceMethodBuilder> ();
this.sources = new List<SourceFileEntry> ();
this.comp_units = new List<CompileUnitEntry> ();
this.file = new MonoSymbolFile ();
this.filename = filename + ".mdb";
}
public MonoSymbolFile SymbolFile {
get { return file; }
}
public void CloseNamespace ()
{ }
public void DefineLocalVariable (int index, string name)
{
if (current_method == null)
return;
current_method.AddLocal (index, name);
}
public void DefineCapturedLocal (int scope_id, string name, string captured_name)
{
file.DefineCapturedVariable (scope_id, name, captured_name,
CapturedVariable.CapturedKind.Local);
}
public void DefineCapturedParameter (int scope_id, string name, string captured_name)
{
file.DefineCapturedVariable (scope_id, name, captured_name,
CapturedVariable.CapturedKind.Parameter);
}
public void DefineCapturedThis (int scope_id, string captured_name)
{
file.DefineCapturedVariable (scope_id, "this", captured_name,
CapturedVariable.CapturedKind.This);
}
public void DefineCapturedScope (int scope_id, int id, string captured_name)
{
file.DefineCapturedScope (scope_id, id, captured_name);
}
public void DefineScopeVariable (int scope, int index)
{
if (current_method == null)
return;
current_method.AddScopeVariable (scope, index);
}
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column,
bool is_hidden)
{
if (current_method == null)
return;
current_method.MarkSequencePoint (offset, file, line, column, is_hidden);
}
public SourceMethodBuilder OpenMethod (ICompileUnit file, int ns_id, IMethodDef method)
{
SourceMethodBuilder builder = new SourceMethodBuilder (file, ns_id, method);
current_method_stack.Push (current_method);
current_method = builder;
methods.Add (current_method);
return builder;
}
public void CloseMethod ()
{
current_method = (SourceMethodBuilder) current_method_stack.Pop ();
}
public SourceFileEntry DefineDocument (string url)
{
SourceFileEntry entry = new SourceFileEntry (file, url);
sources.Add (entry);
return entry;
}
public SourceFileEntry DefineDocument (string url, byte[] guid, byte[] checksum)
{
SourceFileEntry entry = new SourceFileEntry (file, url, guid, checksum);
sources.Add (entry);
return entry;
}
public CompileUnitEntry DefineCompilationUnit (SourceFileEntry source)
{
CompileUnitEntry entry = new CompileUnitEntry (file, source);
comp_units.Add (entry);
return entry;
}
public int DefineNamespace (string name, CompileUnitEntry unit,
string[] using_clauses, int parent)
{
if ((unit == null) || (using_clauses == null))
throw new NullReferenceException ();
return unit.DefineNamespace (name, using_clauses, parent);
}
public int OpenScope (int start_offset)
{
if (current_method == null)
return 0;
current_method.StartBlock (CodeBlockEntry.Type.Lexical, start_offset);
return 0;
}
public void CloseScope (int end_offset)
{
if (current_method == null)
return;
current_method.EndBlock (end_offset);
}
public void OpenCompilerGeneratedBlock (int start_offset)
{
if (current_method == null)
return;
current_method.StartBlock (CodeBlockEntry.Type.CompilerGenerated,
start_offset);
}
public void CloseCompilerGeneratedBlock (int end_offset)
{
if (current_method == null)
return;
current_method.EndBlock (end_offset);
}
public void StartIteratorBody (int start_offset)
{
current_method.StartBlock (CodeBlockEntry.Type.IteratorBody,
start_offset);
}
public void EndIteratorBody (int end_offset)
{
current_method.EndBlock (end_offset);
}
public void StartIteratorDispatcher (int start_offset)
{
current_method.StartBlock (CodeBlockEntry.Type.IteratorDispatcher,
start_offset);
}
public void EndIteratorDispatcher (int end_offset)
{
current_method.EndBlock (end_offset);
}
public void DefineAnonymousScope (int id)
{
file.DefineAnonymousScope (id);
}
public void WriteSymbolFile (Guid guid)
{
foreach (SourceMethodBuilder method in methods)
method.DefineMethod (file);
try {
// We mmap the file, so unlink the previous version since it may be in use
File.Delete (filename);
} catch {
// We can safely ignore
}
using (FileStream fs = new FileStream (filename, FileMode.Create, FileAccess.Write)) {
file.CreateSymbolFile (guid, fs);
}
}
}
public class SourceMethodBuilder
{
List<LocalVariableEntry> _locals;
List<CodeBlockEntry> _blocks;
List<ScopeVariable> _scope_vars;
#if NET_2_1
System.Collections.Stack _block_stack;
#else
Stack<CodeBlockEntry> _block_stack;
#endif
string _real_name;
IMethodDef _method;
ICompileUnit _comp_unit;
// MethodEntry.Flags _method_flags;
int _ns_id;
public SourceMethodBuilder (ICompileUnit comp_unit, int ns_id, IMethodDef method)
{
this._comp_unit = comp_unit;
this._method = method;
this._ns_id = ns_id;
method_lines = new LineNumberEntry [32];
}
private LineNumberEntry [] method_lines;
private int method_lines_pos = 0;
public void MarkSequencePoint (int offset, SourceFileEntry file, int line, int column,
bool is_hidden)
{
if (method_lines_pos == method_lines.Length) {
LineNumberEntry [] tmp = method_lines;
method_lines = new LineNumberEntry [method_lines.Length * 2];
Array.Copy (tmp, method_lines, method_lines_pos);
}
int file_idx = file != null ? file.Index : 0;
method_lines [method_lines_pos++] = new LineNumberEntry (
file_idx, line, offset, is_hidden);
}
public void StartBlock (CodeBlockEntry.Type type, int start_offset)
{
if (_block_stack == null) {
#if NET_2_1
_block_stack = new System.Collections.Stack ();
#else
_block_stack = new Stack<CodeBlockEntry> ();
#endif
}
if (_blocks == null)
_blocks = new List<CodeBlockEntry> ();
int parent = CurrentBlock != null ? CurrentBlock.Index : -1;
CodeBlockEntry block = new CodeBlockEntry (
_blocks.Count + 1, parent, type, start_offset);
_block_stack.Push (block);
_blocks.Add (block);
}
public void EndBlock (int end_offset)
{
CodeBlockEntry block = (CodeBlockEntry) _block_stack.Pop ();
block.Close (end_offset);
}
public CodeBlockEntry[] Blocks {
get {
if (_blocks == null)
return new CodeBlockEntry [0];
CodeBlockEntry[] retval = new CodeBlockEntry [_blocks.Count];
_blocks.CopyTo (retval, 0);
return retval;
}
}
public CodeBlockEntry CurrentBlock {
get {
if ((_block_stack != null) && (_block_stack.Count > 0))
return (CodeBlockEntry) _block_stack.Peek ();
else
return null;
}
}
public LocalVariableEntry[] Locals {
get {
if (_locals == null)
return new LocalVariableEntry [0];
else {
LocalVariableEntry[] retval =
new LocalVariableEntry [_locals.Count];
_locals.CopyTo (retval, 0);
return retval;
}
}
}
public void AddLocal (int index, string name)
{
if (_locals == null)
_locals = new List<LocalVariableEntry> ();
int block_idx = CurrentBlock != null ? CurrentBlock.Index : 0;
_locals.Add (new LocalVariableEntry (index, name, block_idx));
}
public ScopeVariable[] ScopeVariables {
get {
if (_scope_vars == null)
return new ScopeVariable [0];
ScopeVariable[] retval = new ScopeVariable [_scope_vars.Count];
_scope_vars.CopyTo (retval);
return retval;
}
}
public void AddScopeVariable (int scope, int index)
{
if (_scope_vars == null)
_scope_vars = new List<ScopeVariable> ();
_scope_vars.Add (
new ScopeVariable (scope, index));
}
public string RealMethodName {
get { return _real_name; }
}
public void SetRealMethodName (string name)
{
_real_name = name;
}
public ICompileUnit SourceFile {
get { return _comp_unit; }
}
public IMethodDef Method {
get { return _method; }
}
public void DefineMethod (MonoSymbolFile file)
{
LineNumberEntry[] lines = new LineNumberEntry [method_lines_pos];
Array.Copy (method_lines, lines, method_lines_pos);
MethodEntry entry = new MethodEntry (
file, _comp_unit.Entry, _method.Token, ScopeVariables,
Locals, lines, Blocks, RealMethodName, 0, //_method_flags,
_ns_id);
file.AddMethod (entry);
}
}
}

View File

@@ -0,0 +1,349 @@
//
// SymbolWriterImpl.cs
//
// Author:
// Lluis Sanchez Gual (lluis@novell.com)
//
// (C) 2005 Novell, Inc. http://www.novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Collections;
using System.IO;
using System.Diagnostics.SymbolStore;
namespace Mono.CompilerServices.SymbolWriter
{
public class SymbolWriterImpl: ISymbolWriter
{
MonoSymbolWriter msw;
int nextLocalIndex;
int currentToken;
string methodName;
Stack namespaceStack = new Stack ();
bool methodOpened;
Hashtable documents = new Hashtable ();
#if !CECIL
ModuleBuilder mb;
delegate Guid GetGuidFunc (ModuleBuilder mb);
GetGuidFunc get_guid_func;
public SymbolWriterImpl (ModuleBuilder mb)
{
this.mb = mb;
}
public void Close ()
{
MethodInfo mi = typeof (ModuleBuilder).GetMethod (
"Mono_GetGuid",
BindingFlags.Static | BindingFlags.NonPublic);
if (mi == null)
return;
get_guid_func = (GetGuidFunc) System.Delegate.CreateDelegate (
typeof (GetGuidFunc), mi);
msw.WriteSymbolFile (get_guid_func (mb));
}
#else
Guid guid;
public SymbolWriterImpl (Guid guid)
{
this.guid = guid;
}
public void Close ()
{
msw.WriteSymbolFile (guid);
}
#endif
public void CloseMethod ()
{
if (methodOpened) {
methodOpened = false;
nextLocalIndex = 0;
msw.CloseMethod ();
}
}
public void CloseNamespace ()
{
namespaceStack.Pop ();
msw.CloseNamespace ();
}
public void CloseScope (int endOffset)
{
msw.CloseScope (endOffset);
}
public ISymbolDocumentWriter DefineDocument (
string url,
Guid language,
Guid languageVendor,
Guid documentType)
{
SymbolDocumentWriterImpl doc = (SymbolDocumentWriterImpl) documents [url];
if (doc == null) {
SourceFileEntry entry = msw.DefineDocument (url);
CompileUnitEntry comp_unit = msw.DefineCompilationUnit (entry);
doc = new SymbolDocumentWriterImpl (comp_unit);
documents [url] = doc;
}
return doc;
}
public void DefineField (
SymbolToken parent,
string name,
FieldAttributes attributes,
byte[] signature,
SymAddressKind addrKind,
int addr1,
int addr2,
int addr3)
{
}
public void DefineGlobalVariable (
string name,
FieldAttributes attributes,
byte[] signature,
SymAddressKind addrKind,
int addr1,
int addr2,
int addr3)
{
}
public void DefineLocalVariable (
string name,
FieldAttributes attributes,
byte[] signature,
SymAddressKind addrKind,
int addr1,
int addr2,
int addr3,
int startOffset,
int endOffset)
{
msw.DefineLocalVariable (nextLocalIndex++, name);
}
public void DefineParameter (
string name,
ParameterAttributes attributes,
int sequence,
SymAddressKind addrKind,
int addr1,
int addr2,
int addr3)
{
}
public void DefineSequencePoints (
ISymbolDocumentWriter document,
int[] offsets,
int[] lines,
int[] columns,
int[] endLines,
int[] endColumns)
{
SymbolDocumentWriterImpl doc = (SymbolDocumentWriterImpl) document;
SourceFileEntry file = doc != null ? doc.Entry.SourceFile : null;
for (int n=0; n<offsets.Length; n++) {
if (n > 0 && offsets[n] == offsets[n-1] && lines[n] == lines[n-1] && columns[n] == columns[n-1])
continue;
msw.MarkSequencePoint (offsets[n], file, lines[n], columns[n], false);
}
}
public void Initialize (IntPtr emitter, string filename, bool fFullBuild)
{
msw = new MonoSymbolWriter (filename);
}
public void OpenMethod (SymbolToken method)
{
currentToken = method.GetToken ();
}
public void OpenNamespace (string name)
{
NamespaceInfo n = new NamespaceInfo ();
n.NamespaceID = -1;
n.Name = name;
namespaceStack.Push (n);
}
public int OpenScope (int startOffset)
{
return msw.OpenScope (startOffset);
}
public void SetMethodSourceRange (
ISymbolDocumentWriter startDoc,
int startLine,
int startColumn,
ISymbolDocumentWriter endDoc,
int endLine,
int endColumn)
{
int nsId = GetCurrentNamespace (startDoc);
SourceMethodImpl sm = new SourceMethodImpl (methodName, currentToken, nsId);
msw.OpenMethod (((ICompileUnit)startDoc).Entry, nsId, sm);
methodOpened = true;
}
public void SetScopeRange (int scopeID, int startOffset, int endOffset)
{
}
public void SetSymAttribute (SymbolToken parent, string name, byte[] data)
{
// This is a hack! but MonoSymbolWriter needs the method name
// and ISymbolWriter does not have any method for providing it
if (name == "__name")
methodName = System.Text.Encoding.UTF8.GetString (data);
}
public void SetUnderlyingWriter (IntPtr underlyingWriter)
{
}
public void SetUserEntryPoint (SymbolToken entryMethod)
{
}
public void UsingNamespace (string fullName)
{
if (namespaceStack.Count == 0) {
OpenNamespace ("");
}
NamespaceInfo ni = (NamespaceInfo) namespaceStack.Peek ();
if (ni.NamespaceID != -1) {
NamespaceInfo old = ni;
CloseNamespace ();
OpenNamespace (old.Name);
ni = (NamespaceInfo) namespaceStack.Peek ();
ni.UsingClauses = old.UsingClauses;
}
ni.UsingClauses.Add (fullName);
}
int GetCurrentNamespace (ISymbolDocumentWriter doc)
{
if (namespaceStack.Count == 0) {
OpenNamespace ("");
}
NamespaceInfo ni = (NamespaceInfo) namespaceStack.Peek ();
if (ni.NamespaceID == -1)
{
string[] usings = (string[]) ni.UsingClauses.ToArray (typeof(string));
int parentId = 0;
if (namespaceStack.Count > 1) {
namespaceStack.Pop ();
parentId = ((NamespaceInfo) namespaceStack.Peek ()).NamespaceID;
namespaceStack.Push (ni);
}
ni.NamespaceID = msw.DefineNamespace (ni.Name, ((ICompileUnit)doc).Entry, usings, parentId);
}
return ni.NamespaceID;
}
}
class SymbolDocumentWriterImpl: ISymbolDocumentWriter, ISourceFile, ICompileUnit
{
CompileUnitEntry comp_unit;
public SymbolDocumentWriterImpl (CompileUnitEntry comp_unit)
{
this.comp_unit = comp_unit;
}
public void SetCheckSum (Guid algorithmId, byte[] checkSum)
{
}
public void SetSource (byte[] source)
{
}
SourceFileEntry ISourceFile.Entry {
get { return comp_unit.SourceFile; }
}
public CompileUnitEntry Entry {
get { return comp_unit; }
}
}
class SourceMethodImpl: IMethodDef
{
string name;
int token;
int namespaceID;
public SourceMethodImpl (string name, int token, int namespaceID)
{
this.name = name;
this.token = token;
this.namespaceID = namespaceID;
}
public string Name {
get { return name; }
}
public int NamespaceID {
get { return namespaceID; }
}
public int Token {
get { return token; }
}
}
class NamespaceInfo
{
public string Name;
public int NamespaceID;
public ArrayList UsingClauses = new ArrayList ();
}
}

View File

@@ -0,0 +1,4 @@
bin
obj
*.xml
*.user

View File

@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">net_4_0_Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AC71DF9C-99FA-4A63-990A-66C8010355A6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mono.Cecil.Mdb.Tests</RootNamespace>
<AssemblyName>Mono.Cecil.Mdb.Tests</AssemblyName>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_2_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_2_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_2_0_Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_3_5_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_3_5_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_3_5_Release\</OutputPath>
<DefineConstants>TRACE;NET_3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net_4_0_Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_0_Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\net_4_0_Release\</OutputPath>
<DefineConstants>TRACE;NET_3_5;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' ">
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Test\Mono.Cecil.Tests.csproj">
<Project>{A47B1F49-A81A-43E8-BE6B-DD28AF2C4055}</Project>
<Name>Mono.Cecil.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil.Mdb.csproj">
<Project>{8559DD7F-A16F-46D0-A05A-9139FAEBA8FD}</Project>
<Name>Mono.Cecil.Mdb</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mono.Cecil.Tests\Addin.cs" />
<Compile Include="Mono.Cecil.Tests\MdbTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\assemblies\hello.exe" />
<Content Include="Resources\assemblies\hello.exe.mdb" />
</ItemGroup>
<ItemGroup>
<Reference Include="nunit.core">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Test\libs\nunit-2.6.2\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,8 @@
using NUnit.Core.Extensibility;
namespace Mono.Cecil.Tests {
[NUnitAddin]
public class CecilMdbAddin : CecilTestAddin {
}
}

View File

@@ -0,0 +1,58 @@
using Mono.Cecil.Mdb;
using NUnit.Framework;
namespace Mono.Cecil.Tests {
[TestFixture]
public class MdbTests : BaseTestFixture {
[TestModule ("hello.exe", SymbolReaderProvider = typeof (MdbReaderProvider), SymbolWriterProvider = typeof (MdbWriterProvider))]
public void Main (ModuleDefinition module)
{
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
AssertCode (@"
.locals init (System.Int32 i)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0000: ldc.i4.0
IL_0001: stloc.0
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0002: br IL_0013
.line 8,8:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldelem.ref
IL_000a: call System.Void Program::Print(System.String)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_000f: ldloc.0
IL_0010: ldc.i4.1
IL_0011: add
IL_0012: stloc.0
IL_0013: ldloc.0
IL_0014: ldarg.0
IL_0015: ldlen
IL_0016: conv.i4
IL_0017: blt IL_0007
.line 10,10:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_001c: ldc.i4.0
IL_001d: ret
", main);
}
static void AssertCode (string expected, MethodDefinition method)
{
Assert.IsTrue (method.HasBody);
Assert.IsNotNull (method.Body);
Assert.AreEqual (Normalize (expected), Normalize (Formatter.FormatMethodBody (method)));
}
static string Normalize (string str)
{
return str.Trim ().Replace ("\r\n", "\n");
}
}
}

View File

@@ -0,0 +1,4 @@
bin
obj
*.xml
*.user

View File

@@ -0,0 +1,255 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Text;
namespace Microsoft.Cci.Pdb {
internal class BitAccess {
internal BitAccess(int capacity) {
this.buffer = new byte[capacity];
}
internal byte[] Buffer {
get { return buffer; }
}
private byte[] buffer;
internal void FillBuffer(Stream stream, int capacity) {
MinCapacity(capacity);
stream.Read(buffer, 0, capacity);
offset = 0;
}
internal void Append(Stream stream, int count) {
int newCapacity = offset + count;
if (buffer.Length < newCapacity) {
byte[] newBuffer = new byte[newCapacity];
Array.Copy(buffer, newBuffer, buffer.Length);
buffer = newBuffer;
}
stream.Read(buffer, offset, count);
offset += count;
}
internal int Position {
get { return offset; }
set { offset = value; }
}
private int offset;
//internal void WriteBuffer(Stream stream, int count) {
// stream.Write(buffer, 0, count);
//}
internal void MinCapacity(int capacity) {
if (buffer.Length < capacity) {
buffer = new byte[capacity];
}
offset = 0;
}
internal void Align(int alignment) {
while ((offset % alignment) != 0) {
offset++;
}
}
//internal void WriteInt32(int value) {
// buffer[offset + 0] = (byte)value;
// buffer[offset + 1] = (byte)(value >> 8);
// buffer[offset + 2] = (byte)(value >> 16);
// buffer[offset + 3] = (byte)(value >> 24);
// offset += 4;
//}
//internal void WriteInt32(int[] values) {
// for (int i = 0; i < values.Length; i++) {
// WriteInt32(values[i]);
// }
//}
//internal void WriteBytes(byte[] bytes) {
// for (int i = 0; i < bytes.Length; i++) {
// buffer[offset++] = bytes[i];
// }
//}
internal void ReadInt16(out short value) {
value = (short)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8));
offset += 2;
}
internal void ReadInt8(out sbyte value) {
value = (sbyte)buffer[offset];
offset += 1;
}
internal void ReadInt32(out int value) {
value = (int)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24));
offset += 4;
}
internal void ReadInt64(out long value) {
value = (long)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
internal void ReadUInt16(out ushort value) {
value = (ushort)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8));
offset += 2;
}
internal void ReadUInt8(out byte value) {
value = (byte)((buffer[offset + 0] & 0xFF));
offset += 1;
}
internal void ReadUInt32(out uint value) {
value = (uint)((buffer[offset + 0] & 0xFF) |
(buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) |
(buffer[offset + 3] << 24));
offset += 4;
}
internal void ReadUInt64(out ulong value) {
value = (ulong)(((ulong)buffer[offset + 0] & 0xFF) |
((ulong)buffer[offset + 1] << 8) |
((ulong)buffer[offset + 2] << 16) |
((ulong)buffer[offset + 3] << 24) |
((ulong)buffer[offset + 4] << 32) |
((ulong)buffer[offset + 5] << 40) |
((ulong)buffer[offset + 6] << 48) |
((ulong)buffer[offset + 7] << 56));
offset += 8;
}
internal void ReadInt32(int[] values) {
for (int i = 0; i < values.Length; i++) {
ReadInt32(out values[i]);
}
}
internal void ReadUInt32(uint[] values) {
for (int i = 0; i < values.Length; i++) {
ReadUInt32(out values[i]);
}
}
internal void ReadBytes(byte[] bytes) {
for (int i = 0; i < bytes.Length; i++) {
bytes[i] = buffer[offset++];
}
}
internal float ReadFloat() {
float result = BitConverter.ToSingle(buffer, offset);
offset += 4;
return result;
}
internal double ReadDouble() {
double result = BitConverter.ToDouble(buffer, offset);
offset += 8;
return result;
}
internal decimal ReadDecimal() {
int[] bits = new int[4];
this.ReadInt32(bits);
return new decimal(bits[2], bits[3], bits[1], bits[0] < 0, (byte)((bits[0] & 0x00FF0000) >> 16));
}
internal void ReadBString(out string value) {
ushort len;
this.ReadUInt16(out len);
value = Encoding.UTF8.GetString(buffer, offset, len);
offset += len;
}
internal string ReadBString(int len) {
var result = Encoding.UTF8.GetString(buffer, offset, len);
offset += len;
return result;
}
internal void ReadCString(out string value) {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len++;
}
value = Encoding.UTF8.GetString(buffer, offset, len);
offset += len + 1;
}
internal void SkipCString(out string value) {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len++;
}
offset += len + 1;
value= null;
}
internal void ReadGuid(out Guid guid) {
uint a;
ushort b;
ushort c;
byte d;
byte e;
byte f;
byte g;
byte h;
byte i;
byte j;
byte k;
ReadUInt32(out a);
ReadUInt16(out b);
ReadUInt16(out c);
ReadUInt8(out d);
ReadUInt8(out e);
ReadUInt8(out f);
ReadUInt8(out g);
ReadUInt8(out h);
ReadUInt8(out i);
ReadUInt8(out j);
ReadUInt8(out k);
guid = new Guid(a, b, c, d, e, f, g, h, i, j, k);
}
internal string ReadString() {
int len = 0;
while (offset + len < buffer.Length && buffer[offset + len] != 0) {
len+=2;
}
string result = Encoding.Unicode.GetString(buffer, offset, len);
offset += len + 2;
return result;
}
}
}

View File

@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct BitSet {
internal BitSet(BitAccess bits) {
bits.ReadInt32(out size); // 0..3 : Number of words
words = new uint[size];
bits.ReadUInt32(words);
}
//internal BitSet(int size) {
// this.size = size;
// words = new uint[size];
//}
internal bool IsSet(int index) {
int word = index / 32;
if (word >= this.size) return false;
return ((words[word] & GetBit(index)) != 0);
}
//internal void Set(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] |= GetBit(index);
//}
//internal void Clear(int index) {
// int word = index / 32;
// if (word >= this.size) return;
// words[word] &= ~GetBit(index);
//}
private static uint GetBit(int index) {
return ((uint)1 << (index % 32));
}
//private static uint ReverseBits(uint value) {
// uint o = 0;
// for (int i = 0; i < 32; i++) {
// o = (o << 1) | (value & 1);
// value >>= 1;
// }
// return o;
//}
internal bool IsEmpty {
get { return size == 0; }
}
//internal bool GetWord(int index, out uint word) {
// if (index < size) {
// word = ReverseBits(words[index]);
// return true;
// }
// word = 0;
// return false;
//}
private int size;
private uint[] words;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
using System.IO;
namespace Microsoft.Cci.Pdb {
internal class DataStream {
internal DataStream() {
}
internal DataStream(int contentSize, BitAccess bits, int count) {
this.contentSize = contentSize;
if (count > 0) {
this.pages = new int[count];
bits.ReadInt32(this.pages);
}
}
internal void Read(PdbReader reader, BitAccess bits) {
bits.MinCapacity(contentSize);
Read(reader, 0, bits.Buffer, 0, contentSize);
}
internal void Read(PdbReader reader, int position,
byte[] bytes, int offset, int data) {
if (position + data > contentSize) {
throw new PdbException("DataStream can't read off end of stream. " +
"(pos={0},siz={1})",
position, data);
}
if (position == contentSize) {
return;
}
int left = data;
int page = position / reader.pageSize;
int rema = position % reader.pageSize;
// First get remained of first page.
if (rema != 0) {
int todo = reader.pageSize - rema;
if (todo > left) {
todo = left;
}
reader.Seek(pages[page], rema);
reader.Read(bytes, offset, todo);
offset += todo;
left -= todo;
page++;
}
// Now get the remaining pages.
while (left > 0) {
int todo = reader.pageSize;
if (todo > left) {
todo = left;
}
reader.Seek(pages[page], 0);
reader.Read(bytes, offset, todo);
offset += todo;
left -= todo;
page++;
}
}
//private void AddPages(int page0, int count) {
// if (pages == null) {
// pages = new int[count];
// for (int i = 0; i < count; i++) {
// pages[i] = page0 + i;
// }
// } else {
// int[] old = pages;
// int used = old.Length;
// pages = new int[used + count];
// Array.Copy(old, pages, used);
// for (int i = 0; i < count; i++) {
// pages[used + i] = page0 + i;
// }
// }
//}
//internal int Pages {
// get { return pages == null ? 0 : pages.Length; }
//}
internal int Length {
get { return contentSize; }
}
//internal int GetPage(int index) {
// return pages[index];
//}
internal int contentSize;
internal int[] pages;
}
}

View File

@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
using System;
namespace Microsoft.Cci.Pdb {
internal struct DbiDbgHdr {
internal DbiDbgHdr(BitAccess bits) {
bits.ReadUInt16(out snFPO);
bits.ReadUInt16(out snException);
bits.ReadUInt16(out snFixup);
bits.ReadUInt16(out snOmapToSrc);
bits.ReadUInt16(out snOmapFromSrc);
bits.ReadUInt16(out snSectionHdr);
bits.ReadUInt16(out snTokenRidMap);
bits.ReadUInt16(out snXdata);
bits.ReadUInt16(out snPdata);
bits.ReadUInt16(out snNewFPO);
bits.ReadUInt16(out snSectionHdrOrig);
}
internal ushort snFPO; // 0..1
internal ushort snException; // 2..3 (deprecated)
internal ushort snFixup; // 4..5
internal ushort snOmapToSrc; // 6..7
internal ushort snOmapFromSrc; // 8..9
internal ushort snSectionHdr; // 10..11
internal ushort snTokenRidMap; // 12..13
internal ushort snXdata; // 14..15
internal ushort snPdata; // 16..17
internal ushort snNewFPO; // 18..19
internal ushort snSectionHdrOrig; // 20..21
}
}

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