Imported Upstream version 5.8.0.88

Former-commit-id: 4b7216ffda08448e562271ce733688e761120fc5
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-11-28 19:36:51 +00:00
parent 7d05485754
commit 6123a772ed
277 changed files with 4817 additions and 941 deletions

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 ();
}
}
@@ -671,8 +682,10 @@ namespace Mono.Cecil.Cil {
var offset_mapping = new Dictionary<int, SequencePoint> (sequence_points.Count);
for (int i = 0; i < sequence_points.Count; i++)
offset_mapping.Add (sequence_points [i].Offset, sequence_points [i]);
for (int i = 0; i < sequence_points.Count; i++) {
if (!offset_mapping.ContainsKey (sequence_points [i].Offset))
offset_mapping.Add (sequence_points [i].Offset, sequence_points [i]);
}
var instructions = method.Body.Instructions;
@@ -782,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.
}
}
@@ -791,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.
}
}