// ISymUnmanagedScope public static ISymUnmanagedScope[] GetChildren(this ISymUnmanagedScope symScope) { uint count; symScope.GetChildren(0, out count, new ISymUnmanagedScope[0]); ISymUnmanagedScope[] children = new ISymUnmanagedScope[count]; symScope.GetChildren(count, out count, children); return(children); }
public static ISymUnmanagedScope[] GetAndValidateChildScopes(ISymUnmanagedScope scope, int expectedCount) { int count, count2; Assert.Equal(HResult.S_OK, scope.GetChildren(0, out count, null)); Assert.Equal(expectedCount, count); var children = new ISymUnmanagedScope[count]; Assert.Equal(HResult.S_OK, scope.GetChildren(count, out count2, children)); Assert.Equal(count, count2); return(children); }
private static void ForEachLocalVariableRecursive( ISymUnmanagedScope scope, int offset, ref ISymUnmanagedVariable[] localsBuffer, Action <ISymUnmanagedVariable> action) { Debug.Assert((offset < 0) || scope.IsInScope(offset)); // apply action on locals of the current scope: int localCount; scope.GetLocalCount(out localCount); if (localCount > 0) { EnsureBufferSize(ref localsBuffer, localCount); scope.GetLocals(localCount, out localCount, localsBuffer); for (int i = 0; i < localCount; i++) { action(localsBuffer[i]); } } // recurse: int childCount; scope.GetChildren(0, out childCount, null); if (childCount > 0) { var children = new ISymUnmanagedScope[childCount]; scope.GetChildren(childCount, out childCount, children); foreach (var child in children) { if ((offset < 0) || child.IsInScope(offset)) { ForEachLocalVariableRecursive(child, offset, ref localsBuffer, action); if (offset >= 0) { return; } } } } }
/// <summary> /// Returns the child lexical scopes of the current lexical scope. /// </summary> /// <returns></returns> public ISymbolScope[] GetChildren() { int chNum; private_scope.GetChildren(0, out chNum, null); ISymUnmanagedScope[] unScps = new ISymUnmanagedScope[chNum]; ISymbolScope[] manScps = new ISymbolScope[chNum]; private_scope.GetChildren(chNum, out chNum, unScps); for (int i = 0; i < chNum; i++) { manScps[i] = new SymbolScope(unScps[i]); } return(manScps); }
public ISymbolScope[] GetChildren() { m_target.GetChildren(0, out var count, null); ISymUnmanagedScope[] uScopes = new ISymUnmanagedScope[count]; m_target.GetChildren(count, out count, uScopes); int i; ISymbolScope[] scopes = new ISymbolScope[count]; for (i = 0; i < count; i++) { scopes[i] = new SymScope(uScopes[i]); } return(scopes); }
public ISymbolScope[] GetChildren() { uint numScopes; scope.GetChildren(0, out numScopes, null); var unScopes = new ISymUnmanagedScope[numScopes]; scope.GetChildren((uint)unScopes.Length, out numScopes, unScopes); var scopes = new ISymbolScope[numScopes]; for (uint i = 0; i < numScopes; i++) { scopes[i] = new SymbolScope(unScopes[i]); } return(scopes); }
private static void ForEachLocalVariableRecursive( ISymUnmanagedScope scope, int offset, bool isScopeEndInclusive, Action<ISymUnmanagedVariable> action) { Debug.Assert(offset < 0 || scope.IsInScope(offset, isScopeEndInclusive)); // apply action on locals of the current scope: foreach (var local in scope.GetLocals()) { action(local); } // recurse: foreach (var child in scope.GetChildren()) { if (offset < 0 || child.IsInScope(offset, isScopeEndInclusive)) { ForEachLocalVariableRecursive(child, offset, isScopeEndInclusive, action); if (offset >= 0) { return; } } } }
private static void ForEachLocalVariableRecursive( ISymUnmanagedScope scope, int offset, bool isScopeEndInclusive, Action <ISymUnmanagedVariable> action) { Debug.Assert(offset < 0 || scope.IsInScope(offset, isScopeEndInclusive)); // apply action on locals of the current scope: foreach (var local in scope.GetLocals()) { action(local); } // recurse: foreach (var child in scope.GetChildren()) { if (offset < 0 || child.IsInScope(offset, isScopeEndInclusive)) { ForEachLocalVariableRecursive(child, offset, isScopeEndInclusive, action); if (offset >= 0) { return; } } } }
// // Gather the local details in a scope and then recurse to child scopes // private void ProbeScopeForLocals(List <LocalVariable> variables, ISymUnmanagedScope scope) { int localCount; ThrowExceptionForHR(scope.GetLocalCount(out localCount)); ISymUnmanagedVariable[] locals = new ISymUnmanagedVariable[localCount]; ThrowExceptionForHR(scope.GetLocals(localCount, out localCount, locals)); for (int i = 0; i < localCount; i++) { var local = locals[i]; int slot; ThrowExceptionForHR(local.GetAddressField1(out slot)); int nameLength; ThrowExceptionForHR(local.GetName(0, out nameLength, null)); // nameLength includes terminating '\0' char[] nameBuffer = new char[nameLength]; ThrowExceptionForHR(local.GetName(nameLength, out nameLength, nameBuffer)); int attributes; ThrowExceptionForHR(local.GetAttributes(out attributes)); variables.Add(new LocalVariable() { Slot = slot, Name = new String(nameBuffer, 0, nameLength - 1), CompilerGenerated = (attributes & 0x1) != 0 }); } int childrenCount; ThrowExceptionForHR(scope.GetChildren(0, out childrenCount, null)); ISymUnmanagedScope[] children = new ISymUnmanagedScope[childrenCount]; ThrowExceptionForHR(scope.GetChildren(childrenCount, out childrenCount, children)); for (int i = 0; i < childrenCount; i++) { ProbeScopeForLocals(variables, children[i]); } }
public ISymbolScope[] GetChildren() { int size; HRESULT.ThrowOnFailure(_unmanaged.GetChildren(0, out size, null)); var unmanagedScopes = new ISymUnmanagedScope[size]; HRESULT.ThrowOnFailure(_unmanaged.GetChildren(unmanagedScopes.Length, out size, unmanagedScopes)); var scopes = new ISymbolScope[size]; for (int i = 0; i < size; i++) { scopes[i] = new SymbolScope(unmanagedScopes[i]); } return(scopes); }
private List <DebugLocalVariableInfo> GetLocalVariablesInScope(ISymUnmanagedScope symScope) { List <DebugLocalVariableInfo> vars = new List <DebugLocalVariableInfo>(); foreach (ISymUnmanagedVariable symVar in symScope.GetLocals()) { ISymUnmanagedVariable symVarCopy = symVar; int start; SignatureReader sigReader = new SignatureReader(symVar.GetSignature()); LocalVarSig.LocalVariable locVarSig = sigReader.ReadLocalVariable(sigReader.Blob, 0, out start); DebugType locVarType = DebugType.CreateFromSignature(this.DebugModule, locVarSig.Type, declaringType); // Compiler generated? // NB: Display class does not have the compiler-generated flag if ((symVar.GetAttributes() & 1) == 1 || symVar.GetName().StartsWith("CS$")) { // Get display class from local variable if (locVarType.IsDisplayClass) { AddCapturedLocalVariables( vars, (int)symScope.GetStartOffset(), (int)symScope.GetEndOffset(), delegate(StackFrame context) { return(GetLocalVariableValue(context, symVarCopy)); }, locVarType ); } } else { DebugLocalVariableInfo locVar = new DebugLocalVariableInfo( symVar.GetName(), (int)symVar.GetAddressField1(), // symVar also has Get*Offset methods, but the are not implemented (int)symScope.GetStartOffset(), (int)symScope.GetEndOffset(), locVarType, delegate(StackFrame context) { return(GetLocalVariableValue(context, symVarCopy)); } ); vars.Add(locVar); } } foreach (ISymUnmanagedScope childScope in symScope.GetChildren()) { vars.AddRange(GetLocalVariablesInScope(childScope)); } return(vars); }
public static ImmutableArray <ISymUnmanagedScope> GetScopes(this ISymUnmanagedScope scope) { int numAvailable; scope.GetChildren(0, out numAvailable, null); if (numAvailable == 0) { return(ImmutableArray <ISymUnmanagedScope> .Empty); } int numRead; var scopes = new ISymUnmanagedScope[numAvailable]; scope.GetChildren(numAvailable, out numRead, scopes); if (numRead != numAvailable) { throw new InvalidOperationException(string.Format("Read only {0} of {1} child scopes.", numRead, numAvailable)); } return(ImmutableArray.Create(scopes)); }
public int GetChildren(int cChildren, out int pcChildren, ISymUnmanagedScope[] children) { _scope.GetChildren(cChildren, out pcChildren, children); if (children != null) { for (int i = 0; i < pcChildren; i++) { children[i] = new SymScope(_reader, children[i]); } } return(SymUnmanagedReaderExtensions.S_OK); }
private static ISymUnmanagedScope[] GetScopesInternal(ISymUnmanagedScope scope) { int numAvailable; scope.GetChildren(0, out numAvailable, null); if (numAvailable == 0) { return(null); } int numRead; var scopes = new ISymUnmanagedScope[numAvailable]; scope.GetChildren(numAvailable, out numRead, scopes); if (numRead != numAvailable) { throw new InvalidOperationException(string.Format("Read only {0} of {1} child scopes.", numRead, numAvailable)); } return(scopes); }
/// <summary> /// Get definitions of local variables in scope. /// </summary> /// <param name="scope">Interface refering to desired scope.</param> /// <param name="index">Index pointing to the last read variable.</param> /// <param name="definitions">List of definitions, where found variable definition are placed.</param> private void getDefinitionsForScope(ISymUnmanagedScope scope, ref int index, List <LocalVarDefinition> definitions) { ISymUnmanagedVariable[] variables = scope.GetLocals(); foreach (ISymUnmanagedVariable var in variables) { LocalVarDefinition def = new LocalVarDefinition(); def.ilStart = scope.GetStartOffset(); def.ilEnd = scope.GetEndOffset(); def.name = var.GetName(); def.signature = var.GetSignature(); definitions.Add(def); ++index; } foreach (ISymUnmanagedScope cScope in scope.GetChildren()) { getDefinitionsForScope(cScope, ref index, definitions); } }
/// <summary> /// Get the (unprocessed) import strings for a given method. /// </summary> /// <remarks> /// Doesn't consider forwarding. /// /// CONSIDER: Dev12 doesn't just check the root scope - it digs around to find the best /// match based on the IL offset and then walks up to the root scope (see PdbUtil::GetScopeFromOffset). /// However, it's not clear that this matters, since imports can't be scoped in VB. This is probably /// just based on the way they were extracting locals and constants based on a specific scope. /// /// Returns empty array if there are no import strings for the specified method. /// </remarks> private static ImmutableArray <string> GetImportStrings(ISymUnmanagedReader reader, int methodToken, int methodVersion) { var method = reader.GetMethodByVersion(methodToken, methodVersion); if (method == null) { // In rare circumstances (only bad PDBs?) GetMethodByVersion can return null. // If there's no debug info for the method, then no import strings are available. return(ImmutableArray <string> .Empty); } ISymUnmanagedScope rootScope = method.GetRootScope(); if (rootScope == null) { Debug.Assert(false, "Expected a root scope."); return(ImmutableArray <string> .Empty); } var childScopes = rootScope.GetChildren(); if (childScopes.Length == 0) { // It seems like there should always be at least one child scope, but we've // seen PDBs where that is not the case. return(ImmutableArray <string> .Empty); } // As in NamespaceListWrapper::Init, we only consider namespaces in the first // child of the root scope. ISymUnmanagedScope firstChildScope = childScopes[0]; var namespaces = firstChildScope.GetNamespaces(); if (namespaces.Length == 0) { // It seems like there should always be at least one namespace (i.e. the global // namespace), but we've seen PDBs where that is not the case. return(ImmutableArray <string> .Empty); } return(ImmutableArray.CreateRange(namespaces.Select(n => n.GetName()))); }
public IEnumerable <ILLocalVariable> GetLocalVariables(IMethod method) { List <ILLocalVariable> vars = new List <ILLocalVariable>(); var symMethod = method.GetSymMethod(); if (symMethod == null) { return(vars); } Stack <ISymUnmanagedScope> scopes = new Stack <ISymUnmanagedScope>(); scopes.Push(symMethod.GetRootScope()); while (scopes.Count > 0) { ISymUnmanagedScope scope = scopes.Pop(); foreach (ISymUnmanagedVariable symVar in scope.GetLocals()) { int index = (int)symVar.GetAddressField1(); vars.Add(new ILLocalVariable() { Index = index, Type = method.GetLocalVariableType(index), Name = symVar.GetName(), IsCompilerGenerated = (symVar.GetAttributes() & 1) == 1, // symVar also has Get*Offset methods, but the are not implemented ILRanges = new [] { new ILRange() { From = (int)scope.GetStartOffset(), To = (int)scope.GetEndOffset() } } }); } foreach (ISymUnmanagedScope childScope in scope.GetChildren()) { scopes.Push(childScope); } } return(vars); }
private static void SerializeScope( MetadataBuilder metadataBuilder, MetadataModel metadataModel, MethodDefinitionHandle methodHandle, ImportScopeHandle importScopeHandle, ISymUnmanagedScope symScope, Dictionary <int, DynamicLocalInfo> dynamicSlots, Dictionary <string, DynamicLocalInfo> dynamicNames, bool vbSemantics, ref LocalVariableHandle lastLocalVariableHandle, ref LocalConstantHandle lastLocalConstantHandle) { // VB Windows PDB encode the range as end-inclusive, // all Portable PDBs use end-exclusive encoding. int start = symScope.GetStartOffset(); int end = symScope.GetEndOffset() + (vbSemantics ? 1 : 0); metadataBuilder.AddLocalScope( method: methodHandle, importScope: importScopeHandle, variableList: NextHandle(lastLocalVariableHandle), constantList: NextHandle(lastLocalConstantHandle), startOffset: start, length: end - start); foreach (var symLocal in symScope.GetLocals()) { int slot = symLocal.GetSlot(); string name = symLocal.GetName(); lastLocalVariableHandle = metadataBuilder.AddLocalVariable( attributes: (LocalVariableAttributes)symLocal.GetAttributes(), index: slot, name: metadataBuilder.GetOrAddString(name)); DynamicLocalInfo dynamicInfo; if (slot > 0 && dynamicSlots.TryGetValue(slot, out dynamicInfo) || slot == 0 && dynamicNames.TryGetValue(name, out dynamicInfo)) { metadataBuilder.AddCustomDebugInformation( parent: lastLocalVariableHandle, kind: metadataBuilder.GetOrAddGuid(PortableCustomDebugInfoKinds.DynamicLocalVariables), value: SerializeDynamicLocalBlob(metadataBuilder, dynamicInfo)); } } foreach (var symConstant in symScope.GetConstants()) { string name = symConstant.GetName(); object value = symConstant.GetValue(); lastLocalConstantHandle = metadataBuilder.AddLocalConstant( name: metadataBuilder.GetOrAddString(name), signature: SerializeConstantSignature(metadataBuilder, metadataModel, symConstant.GetSignature(), value)); DynamicLocalInfo dynamicInfo; if (dynamicNames.TryGetValue(name, out dynamicInfo)) { metadataBuilder.AddCustomDebugInformation( parent: lastLocalConstantHandle, kind: metadataBuilder.GetOrAddGuid(PortableCustomDebugInfoKinds.DynamicLocalVariables), value: SerializeDynamicLocalBlob(metadataBuilder, dynamicInfo)); } } int previousChildScopeEnd = start; foreach (ISymUnmanagedScope child in symScope.GetChildren()) { int childScopeStart = child.GetStartOffset(); int childScopeEnd = child.GetEndOffset(); // scopes are properly nested: if (childScopeStart < previousChildScopeEnd || childScopeEnd > end) { // TODO: loc/warning throw new BadImageFormatException($"Invalid scope IL offset range: [{childScopeStart}, {childScopeEnd}), method 0x{MetadataTokens.GetToken(methodHandle):x}."); } previousChildScopeEnd = childScopeEnd; SerializeScope(metadataBuilder, metadataModel, methodHandle, importScopeHandle, child, dynamicSlots, dynamicNames, vbSemantics, ref lastLocalVariableHandle, ref lastLocalConstantHandle); } }
List<DebugLocalVariableInfo> GetLocalVariablesInScope(ISymUnmanagedScope symScope) { List<DebugLocalVariableInfo> vars = new List<DebugLocalVariableInfo>(); foreach (ISymUnmanagedVariable symVar in symScope.GetLocals()) { ISymUnmanagedVariable symVarCopy = symVar; var locVarSig = new DebugSignatureReader().ReadTypeSignature(symVar.GetSignature()); DebugType locVarType = DebugType.CreateFromSignature(this.DebugModule, locVarSig, declaringType); // Compiler generated? // NB: Display class does not have the compiler-generated flag if ((symVar.GetAttributes() & 1) == 1 || symVar.GetName().StartsWith("CS$")) { // Get display class from local variable if (locVarType.IsDisplayClass) { AddCapturedLocalVariables( vars, (int)symScope.GetStartOffset(), (int)symScope.GetEndOffset(), delegate(StackFrame context) { return GetLocalVariableValue(context, symVarCopy); }, locVarType ); } } else { DebugLocalVariableInfo locVar = new DebugLocalVariableInfo( symVar.GetName(), (int)symVar.GetAddressField1(), // symVar also has Get*Offset methods, but the are not implemented (int)symScope.GetStartOffset(), (int)symScope.GetEndOffset(), locVarType, delegate(StackFrame context) { return GetLocalVariableValue(context, symVarCopy); } ); vars.Add(locVar); } } foreach(ISymUnmanagedScope childScope in symScope.GetChildren()) { vars.AddRange(GetLocalVariablesInScope(childScope)); } return vars; }
/// <summary> /// Emits scope debugging symbols based on <c>ISymUnmanagedScope</c> insatnce, representing /// scope from new assembly. /// </summary> /// <param name="smScope">Scope from new version of changed assembly.</param> /// <param name="placeholder">Placeholder translation for local variables.</param> public void EmitScope(ISymUnmanagedScope smScope, Dictionary <int, int> placeholder) { if (State != WriterState.Building) { throw new TranslatingException("ISym* interfaces were not initialized."); } uint scStartOffset = smScope.__GetStartOffset(); uint scEndOffset = smScope.__GetEndOffset(); mWriter.OpenScope(scStartOffset); uint localsCount = smScope.__GetLocalCount(); if (localsCount > 0) { uint read; ISymUnmanagedVariable[] variables = new ISymUnmanagedVariable[localsCount]; smScope.__GetLocals(localsCount, out read, variables); for (int i = 0; i < localsCount; i++) { byte[] signature = variables[i].GetSignature(); Signature sig = new Signature(signature); sig.Migrate(translator); signature = sig.Compress(); string name = variables[i].GetName(); uint addr1 = 0; //variables[i].GetAddressField1(); uint addr2 = 0; //variables[i].GetAddressField2(); uint addr3 = 0; //variables[i].GetAddressField3(); uint addrKind = variables[i].GetAddressKind(); //variables[i].GetAddressKind(); if ((variables[i].GetAttributes() & 1) != 1) { addr1 = variables[i].GetAddressField1(); addrKind = variables[i].GetAddressKind(); if (placeholder != null && placeholder.ContainsKey((int)addr1)) { addr1 = (uint)placeholder[(int)addr1]; } } uint varStartOffset = scStartOffset; uint varEndOffset = scEndOffset; uint attributes = variables[i].GetAttributes(); IntPtr pName = Marshal.StringToCoTaskMemUni(name); IntPtr pSig = Marshal.AllocCoTaskMem(signature.Length); Marshal.Copy(signature, 0, pSig, signature.Length); try{ mWriter.DefineLocalVariable(pName, attributes, (uint)signature.Length, pSig, addrKind, addr1, addr2, addr3, varStartOffset, varEndOffset); } finally { Marshal.FreeCoTaskMem(pSig); Marshal.FreeCoTaskMem(pName); } } } ISymUnmanagedScope[] subScopes = smScope.GetChildren(); foreach (ISymUnmanagedScope subScope in subScopes) { EmitScope(subScope, placeholder); } mWriter.CloseScope(scEndOffset); }
static void _PrintLocals(ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip, System.IO.TextWriter writer) { int varcount; unmScope.GetLocalCount(out varcount); ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount]; unmScope.GetLocals(varcount, out varcount, vars); for (int iv = 0; iv < varcount; iv++) { ISymUnmanagedVariable var = vars[iv]; string varname; { int namelen; var.GetName(0, out namelen, null); StringBuilder sbName = new StringBuilder(namelen); var.GetName(sbName.Capacity, out namelen, sbName); namelen--; // Remove nul. sbName.Length = namelen; varname = sbName.ToString(); } string valstr; { int field1; var.GetAddressField1(out field1); ICorDebugValue pvalue; ilframe.GetLocalVariable((uint)field1, out pvalue); valstr = ToString(pvalue); } writer.WriteLine("{0}={1}", varname, valstr); } int cChildren; unmScope.GetChildren(0, out cChildren, null); ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren]; unmScope.GetChildren(children.Length, out cChildren, children); for (int ic = 0; ic < cChildren; ic++) { _PrintLocals(ilframe, children[ic], ip, writer); } }
static ICorDebugValue _FindLocal(string name, ICorDebugILFrame ilframe, ISymUnmanagedScope unmScope, uint ip) { int varcount; unmScope.GetLocalCount(out varcount); ISymUnmanagedVariable[] vars = new ISymUnmanagedVariable[varcount]; unmScope.GetLocals(varcount, out varcount, vars); for (int iv = 0; iv < varcount; iv++) { ISymUnmanagedVariable var = vars[iv]; string varname; { int namelen; var.GetName(0, out namelen, null); StringBuilder sbName = new StringBuilder(namelen); var.GetName(sbName.Capacity, out namelen, sbName); namelen--; // Remove nul. sbName.Length = namelen; varname = sbName.ToString(); } if (name == varname) { int field1; var.GetAddressField1(out field1); ICorDebugValue pvalue; ilframe.GetLocalVariable((uint)field1, out pvalue); return pvalue; } } int cChildren; unmScope.GetChildren(0, out cChildren, null); ISymUnmanagedScope[] children = new ISymUnmanagedScope[cChildren]; unmScope.GetChildren(children.Length, out cChildren, children); for (int ic = 0; ic < cChildren; ic++) { ICorDebugValue pvalue = _FindLocal(name, ilframe, children[ic], ip); if (null != pvalue) { return pvalue; } } return null; }
/// <summary> /// Get definitions of local variables in scope. /// </summary> /// <param name="scope">Interface refering to desired scope.</param> /// <param name="index">Index pointing to the last read variable.</param> /// <param name="definitions">List of definitions, where found variable definition are placed.</param> private void getDefinitionsForScope(ISymUnmanagedScope scope, ref int index, List<LocalVarDefinition> definitions) { ISymUnmanagedVariable[] variables = scope.GetLocals(); foreach (ISymUnmanagedVariable var in variables) { LocalVarDefinition def = new LocalVarDefinition(); def.ilStart = scope.GetStartOffset(); def.ilEnd = scope.GetEndOffset(); def.name = var.GetName(); def.signature = var.GetSignature(); definitions.Add(def); ++index; } foreach (ISymUnmanagedScope cScope in scope.GetChildren()) { getDefinitionsForScope(cScope, ref index, definitions); } }
internal void GetLocalSourceNames(ISymUnmanagedScope/*!*/ scope, Hashtable/*!*/ localSourceNames) { uint numLocals = scope.GetLocalCount(); IntPtr[] localPtrs = new IntPtr[numLocals]; scope.GetLocals((uint)localPtrs.Length, out numLocals, localPtrs); char[] nameBuffer = new char[100]; uint nameLen; for (int i = 0; i < numLocals; i++) { ISymUnmanagedVariable local = (ISymUnmanagedVariable)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(localPtrs[i], typeof(ISymUnmanagedVariable)); if (local != null) { local.GetName((uint)nameBuffer.Length, out nameLen, nameBuffer); int localIndex = (int)local.GetAddressField1(); localSourceNames[localIndex] = new String(nameBuffer, 0, (int)nameLen - 1); System.Runtime.InteropServices.Marshal.ReleaseComObject(local); } System.Runtime.InteropServices.Marshal.Release(localPtrs[i]); } IntPtr[] subscopes = new IntPtr[100]; uint numScopes; scope.GetChildren((uint)subscopes.Length, out numScopes, subscopes); for (int i = 0; i < numScopes; i++) { ISymUnmanagedScope subscope = (ISymUnmanagedScope)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(subscopes[i], typeof(ISymUnmanagedScope)); if (subscope != null) { this.GetLocalSourceNames(subscope, localSourceNames); System.Runtime.InteropServices.Marshal.ReleaseComObject(subscope); } System.Runtime.InteropServices.Marshal.Release(subscopes[i]); //TODO: need to figure out how map these scope to blocks and set HasLocals on those blocks } }
/// <summary> /// Emits scope debugging symbols based on <c>ISymUnmanagedScope</c> insatnce, representing /// scope from new assembly. /// </summary> /// <param name="smScope">Scope from new version of changed assembly.</param> /// <param name="placeholder">Placeholder translation for local variables.</param> public void EmitScope(ISymUnmanagedScope smScope, Dictionary<int, int> placeholder) { if(State != WriterState.Building){ throw new TranslatingException("ISym* interfaces were not initialized."); } uint scStartOffset = smScope.__GetStartOffset(); uint scEndOffset = smScope.__GetEndOffset(); mWriter.OpenScope(scStartOffset); uint localsCount = smScope.__GetLocalCount(); if(localsCount > 0){ uint read; ISymUnmanagedVariable[] variables = new ISymUnmanagedVariable[localsCount]; smScope.__GetLocals(localsCount,out read,variables); for (int i = 0; i < localsCount; i++) { byte[] signature = variables[i].GetSignature(); Signature sig = new Signature(signature); sig.Migrate(translator); signature = sig.Compress(); string name = variables[i].GetName(); uint addr1 = 0;//variables[i].GetAddressField1(); uint addr2 = 0;//variables[i].GetAddressField2(); uint addr3 = 0;//variables[i].GetAddressField3(); uint addrKind = variables[i].GetAddressKind();//variables[i].GetAddressKind(); if((variables[i].GetAttributes() & 1) != 1) { addr1 = variables[i].GetAddressField1(); addrKind = variables[i].GetAddressKind(); if (placeholder != null && placeholder.ContainsKey((int)addr1)) { addr1 = (uint)placeholder[(int)addr1]; } } uint varStartOffset = scStartOffset; uint varEndOffset = scEndOffset; uint attributes = variables[i].GetAttributes(); IntPtr pName = Marshal.StringToCoTaskMemUni(name); IntPtr pSig = Marshal.AllocCoTaskMem(signature.Length); Marshal.Copy(signature,0,pSig,signature.Length); try{ mWriter.DefineLocalVariable(pName,attributes,(uint)signature.Length,pSig,addrKind, addr1,addr2,addr3,varStartOffset,varEndOffset); } finally { Marshal.FreeCoTaskMem(pSig); Marshal.FreeCoTaskMem(pName); } } } ISymUnmanagedScope[] subScopes = smScope.GetChildren(); foreach(ISymUnmanagedScope subScope in subScopes){ EmitScope(subScope,placeholder); } mWriter.CloseScope(scEndOffset); }
// // Gather the local details in a scope and then recurse to child scopes // private void ProbeScopeForLocals(List<ILLocalVariable> variables, ISymUnmanagedScope scope) { int localCount; ThrowExceptionForHR(scope.GetLocalCount(out localCount)); ISymUnmanagedVariable[] locals = new ISymUnmanagedVariable[localCount]; ThrowExceptionForHR(scope.GetLocals(localCount, out localCount, locals)); for (int i = 0; i < localCount; i++) { var local = locals[i]; int slot; ThrowExceptionForHR(local.GetAddressField1(out slot)); int nameLength; ThrowExceptionForHR(local.GetName(0, out nameLength, null)); // nameLength includes terminating '\0' char[] nameBuffer = new char[nameLength]; ThrowExceptionForHR(local.GetName(nameLength, out nameLength, nameBuffer)); int attributes; ThrowExceptionForHR(local.GetAttributes(out attributes)); variables.Add(new ILLocalVariable() { Slot = slot, Name = new String(nameBuffer, 0, nameLength - 1), CompilerGenerated = (attributes & 0x1) != 0 }); } int childrenCount; ThrowExceptionForHR(scope.GetChildren(0, out childrenCount, null)); ISymUnmanagedScope[] children = new ISymUnmanagedScope[childrenCount]; ThrowExceptionForHR(scope.GetChildren(childrenCount, out childrenCount, children)); for (int i = 0; i < childrenCount; i++) { ProbeScopeForLocals(variables, children[i]); } }
public static ISymUnmanagedScope[] GetAndValidateChildScopes(ISymUnmanagedScope scope, int expectedCount) { int count, count2; Assert.Equal(HResult.S_OK, scope.GetChildren(0, out count, null)); Assert.Equal(expectedCount, count); var children = new ISymUnmanagedScope[count]; Assert.Equal(HResult.S_OK, scope.GetChildren(count, out count2, children)); Assert.Equal(count, count2); return children; }