int GetExternalInstructionOffset(ref CurrentMethod info, MethodDef method, Instruction instr) { if (info.Method == method) { return(info.GetOffset(instr)); } var body = method.Body; if (body == null) { Error("Method body is null"); return(0); } var instrs = body.Instructions; int offset = 0; for (int i = 0; i < instrs.Count; i++) { var currInstr = instrs[i]; if (currInstr == instr) { return(offset); } offset += currInstr.GetSize(); } if (instr == null) { return(offset); } Error("Async method instruction has been removed but it's still being referenced by PDB info: BP Instruction: {0}, BP Method: {1} (0x{2:X8}), Current Method: {3} (0x{4:X8})", instr, method, method.MDToken.Raw, info.Method, info.Method.MDToken.Raw); return(0); }
int GetExternalInstructionOffset(ref CurrentMethod info, MethodDef method, Instruction instr) { if (info.Method == method) { return(info.GetOffset(instr)); } var body = method.Body; if (body == null) { Error("Method body is null"); return(0); } var instrs = body.Instructions; int offset = 0; for (int i = 0; i < instrs.Count; i++) { var currInstr = instrs[i]; if (currInstr == instr) { return(offset); } offset += currInstr.GetSize(); } if (instr == null) { return(offset); } Error("Instruction has been removed but it's referenced by PDB info"); return(0); }
void WriteAsyncMethod(ref CurrentMethod info, PdbAsyncMethodCustomDebugInfo asyncMethod) { if (asyncMethod.KickoffMethod == null) { Error("KickoffMethod is null"); return; } uint kickoffMethod = GetMethodToken(asyncMethod.KickoffMethod); writer3.DefineKickoffMethod(kickoffMethod); if (asyncMethod.CatchHandlerInstruction != null) { int catchHandlerILOffset = info.GetOffset(asyncMethod.CatchHandlerInstruction); writer3.DefineCatchHandlerILOffset((uint)catchHandlerILOffset); } var stepInfos = asyncMethod.StepInfos; var yieldOffsets = new uint[stepInfos.Count]; var breakpointOffset = new uint[stepInfos.Count]; var breakpointMethods = new uint[stepInfos.Count]; for (int i = 0; i < yieldOffsets.Length; i++) { var stepInfo = stepInfos[i]; if (stepInfo.YieldInstruction == null) { Error("YieldInstruction is null"); return; } if (stepInfo.BreakpointMethod == null) { Error("BreakpointInstruction is null"); return; } if (stepInfo.BreakpointInstruction == null) { Error("BreakpointInstruction is null"); return; } yieldOffsets[i] = (uint)info.GetOffset(stepInfo.YieldInstruction); breakpointOffset[i] = (uint)GetExternalInstructionOffset(ref info, stepInfo.BreakpointMethod, stepInfo.BreakpointInstruction); breakpointMethods[i] = GetMethodToken(stepInfo.BreakpointMethod); } writer3.DefineAsyncStepInfo(yieldOffsets, breakpointOffset, breakpointMethods); }
void WriteScope(ref CurrentMethod info, PdbScope scope, int recursionCounter) { if (recursionCounter >= 1000) { Error("Too many PdbScopes"); return; } int startOffset = info.GetOffset(scope.Start); int endOffset = info.GetOffset(scope.End); writer.OpenScope(startOffset); AddLocals(info.Method, scope.Variables, (uint)startOffset, (uint)endOffset); if (scope.Constants.Count > 0) { if (writer3 == null) { Error("Symbol writer doesn't implement ISymbolWriter3: no constants can be written to the PDB file"); } else { var constants = scope.Constants; var sig = new FieldSig(); for (int i = 0; i < constants.Count; i++) { var constant = constants[i]; sig.Type = constant.Type; var token = metaData.GetToken(sig); writer3.DefineConstant2(constant.Name, constant.Value ?? 0, token.Raw); } } } foreach (var ns in scope.Namespaces) { writer.UsingNamespace(ns); } foreach (var childScope in scope.Scopes) { WriteScope(ref info, childScope, recursionCounter + 1); } writer.CloseScope(startOffset == 0 && endOffset == info.BodySize ? endOffset : endOffset - localsEndScopeIncValue); }
void WriteScope(ref CurrentMethod info, PdbScope scope, int recursionCounter) { if (recursionCounter >= 1000) { Error("Too many PdbScopes"); return; } int startOffset = info.GetOffset(scope.Start); int endOffset = info.GetOffset(scope.End); writer.OpenScope(startOffset); AddLocals(info.Method, scope.Variables, (uint)startOffset, (uint)endOffset); if (scope.Constants.Count > 0) { var constants = scope.Constants; var sig = new FieldSig(); for (int i = 0; i < constants.Count; i++) { var constant = constants[i]; sig.Type = constant.Type; var token = metadata.GetToken(sig); writer.DefineConstant(constant.Name, constant.Value ?? boxedZeroInt32, token.Raw); } } var scopeNamespaces = scope.Namespaces; int count = scopeNamespaces.Count; for (int i = 0; i < count; i++) { writer.UsingNamespace(scopeNamespaces[i]); } var scopes = scope.Scopes; count = scopes.Count; for (int i = 0; i < count; i++) { WriteScope(ref info, scopes[i], recursionCounter + 1); } writer.CloseScope(startOffset == 0 && endOffset == info.BodySize ? endOffset : endOffset - localsEndScopeIncValue); }