예제 #1
0
파일: PdbWriter.cs 프로젝트: atykhyy/cecil
        public void Write(MethodBody body)
        {
            var method_token = body.Method.MetadataToken;
            var sym_token = new SymbolToken (method_token.ToInt32 ());

            var instructions = CollectInstructions (body);
            if (instructions.Count == 0 && !body.HasVariables)
                return;

            writer.OpenMethod (sym_token);

            DefineSequencePoints (instructions);

            if (body.Scope != null)
                WriteScope (body, body.Scope);
            else
            if (body.HasVariables)
            {
                var start_offset = 0;
                var end_offset = body.CodeSize;

                writer.OpenScope  (start_offset);
                DefineVariables   (body, body.Variables, start_offset, end_offset);
                writer.CloseScope (end_offset);
            }

            if (body.IteratorType != null)
                DefineIteratorType   (sym_token, body.IteratorType.Name);

            if (body.iterator_scopes != null)
                DefineIteratorScopes (sym_token, body.IteratorScopes, body.CodeSize);

            writer.CloseMethod ();
        }
예제 #2
0
		void CreateScopes (MethodBody body, ScopeCollection scopes, SymbolToken localVarToken)
		{
			foreach (Scope s in scopes) {
				int startOffset = s.Start.Offset;
				int endOffset = s.End == body.Instructions.Outside ?
					body.Instructions[body.Instructions.Count - 1].Offset + 1 :
					s.End.Offset;

				m_writer.OpenScope (startOffset);
				m_writer.UsingNamespace (body.Method.DeclaringType.Namespace);
				m_writer.OpenNamespace (body.Method.DeclaringType.Namespace);

				int start = body.Instructions.IndexOf (s.Start);
				int end = s.End == body.Instructions.Outside ?
					body.Instructions.Count - 1 :
					body.Instructions.IndexOf (s.End);

				ArrayList instructions = CollectSequencePoints (body, start, end);
				DefineSequencePoints (instructions);

				CreateLocalVariable (s, startOffset, endOffset, localVarToken);

				CreateScopes (body, s.Scopes, localVarToken);
				m_writer.CloseNamespace ();

				m_writer.CloseScope (endOffset);
			}
		}
예제 #3
0
		public ISymbolMethod GetMethod(SymbolToken method, int version) {
			ISymUnmanagedMethod unMethod;
			int hr = reader.GetMethodByVersion((uint)method.GetToken(), version, out unMethod);
			if (hr == E_FAIL)
				return null;
			Marshal.ThrowExceptionForHR(hr);
			return unMethod == null ? null : new SymbolMethod(unMethod);
		}
예제 #4
0
	public virtual void DefineField
				(SymbolToken parent, String name,
				 FieldAttributes attributes, 
				 byte[] signature, 
				 SymAddressKind addrKind, 
				 int addr1, int addr2, int addr3)
			{
				throw new NotSupportedException();
			}
예제 #5
0
 public int GetMethodByVersion(SymbolToken methodToken, int version, out ISymUnmanagedMethod retVal)
 {
     var hr = _reader.GetMethodByVersion(methodToken, version, out retVal);
     if (retVal != null)
     {
         retVal = new SymMethod(this, retVal);
     }
     return hr;
 }
예제 #6
0
        public void Write(MethodBody body)
        {
            var method_token = body.Method.MetadataToken;
            var sym_token = new SymbolToken (method_token.ToInt32 ());

            writer.OpenMethod (sym_token);
            DefineSequencePoints (body);
            DefineVariables (body);
            writer.CloseMethod ();
        }
 private ISymUnmanagedMethod GetSymMethod(SymbolToken token)
 {
     try
     {
         return _comReader.GetMethod(token);
     }
     catch
     {
         return null;
     }
 }
		public void DefineLocalVariable2 (string name,
										  FieldAttributes attributes,
										  SymbolToken sigToken,
										  SymAddressKind addrKind,
										  int addr1,
										  int addr2,
										  int addr3,
										  int startOffset,
										  int endOffset)
		{
			((ISymUnmanagedWriter2)m_writer).DefineLocalVariable2 (name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset);
		}
예제 #9
0
파일: PdbWriter.cs 프로젝트: jbevain/cecil
 void CreateLocalVariable(VariableDebugInformation variable, SymbolToken local_var_token, int start_offset, int end_offset)
 {
     writer.DefineLocalVariable2 (
         variable.Name,
         variable.Attributes,
         local_var_token,
         SymAddressKind.ILOffset,
         variable.Index,
         0,
         0,
         start_offset,
         end_offset);
 }
예제 #10
0
 public static ISymbolMethod GetSymReader(this MethodBase method)
 {
     var reader = method.Module.GetSymReader();
     if (reader == null)
     {
         return null;
     }
     else
     {
         var token = new SymbolToken(method.MetadataToken);
         return reader.GetMethod(token);
     }
 }
예제 #11
0
		void DefineVariables (MethodBody body, int start_offset, int end_offset)
		{
			if (!body.HasVariables)
				return;

			var sym_token = new SymbolToken (body.LocalVarToken.ToInt32 ());

			var variables = body.Variables;
			for (int i = 0; i < variables.Count; i++) {
				var variable = variables [i];
				CreateLocalVariable (variable, sym_token, start_offset, end_offset);
			}
		}
예제 #12
0
파일: PdbWriter.cs 프로젝트: jbevain/cecil
        public void Write(MethodDebugInformation info)
        {
            var method_token = info.method.MetadataToken;
            var sym_token = new SymbolToken (method_token.ToInt32 ());

            writer.OpenMethod (sym_token);

            if (!info.sequence_points.IsNullOrEmpty ())
                DefineSequencePoints (info.sequence_points);

            if (info.scope != null)
                DefineScope (info.scope, info);

            writer.CloseMethod ();
        }
예제 #13
0
        public virtual ISymbolMethod GetMethod(SymbolToken method, int version)
        {
            ISymbolMethod meth;

            if (methodCache == null)
            {
                methodCache = new Hashtable();
            }
            else if ((meth = (ISymbolMethod)methodCache
                             [method.GetToken()]) != null)
            {
                return(meth);
            }
            meth = new SymMethod(this, method.GetToken());
            methodCache[method.GetToken()] = meth;
            return(meth);
        }
예제 #14
0
		public void Write (MethodBody body)
		{
			var method_token = body.Method.MetadataToken;
			var sym_token = new SymbolToken (method_token.ToInt32 ());

			var instructions = CollectInstructions (body);
			if (instructions.Count == 0)
				return;

			var start_offset = 0;
			var end_offset = body.CodeSize;

			writer.OpenMethod (sym_token);
			writer.OpenScope (start_offset);

			DefineSequencePoints (instructions);
			DefineVariables (body, start_offset, end_offset);

			writer.CloseScope (end_offset);
			writer.CloseMethod ();
		}
        public bool TryGetFunctionByLocation(SourceLocation location, out SymbolToken token)
        {
            token = default(SymbolToken);

            try
            {
                var document = _comReader.GetDocument(location.FilePath.FullPath, default(Guid), default(Guid), default(Guid));
                if (document == null)
                    return false;

                var method = _comReader.GetMethodFromDocumentPosition(document, location.Line, location.Column);
                if (method == null)
                    return false;

                token = method.GetToken();
                return true;
            }
            catch (COMException)
            {
                return false;
            }
        }
예제 #16
0
		public ISymbolVariable[] GetVariables(SymbolToken parent) {
			uint numVars;
			reader.GetVariables((uint)parent.GetToken(), 0, out numVars, null);
			var unVars = new ISymUnmanagedVariable[numVars];
			reader.GetVariables((uint)parent.GetToken(), (uint)unVars.Length, out numVars, unVars);
			var vars = new ISymbolVariable[numVars];
			for (uint i = 0; i < numVars; i++)
				vars[i] = new SymbolVariable(unVars[i]);
			return vars;
		}
예제 #17
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.DefineLocalVariable1"]/*' />
 public void DefineLocalVariable([MarshalAs(UnmanagedType.LPWStr)] String name,
                                 int attributes,
                                 SymbolToken sigToken,
                                 int addressKind,
                                 int addr1,
                                 int addr2,
                                 int addr3,
                                 int startOffset,
                                 int endOffset)
 {
     ((ISymUnmanagedWriter2)m_target).DefineLocalVariable2(name, attributes, sigToken,
                                  addressKind, addr1, addr2, addr3, startOffset, endOffset);
 }
예제 #18
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.RemapToken"]/*' />
 public void RemapToken(SymbolToken oldToken,
                     SymbolToken newToken)
 {
     m_target.RemapToken(oldToken, newToken);
 }
예제 #19
0
		public void OpenMethod (SymbolToken method)
		{
			m_writer.OpenMethod (method);
		}
예제 #20
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.DefineConstant1"]/*' />
 public void DefineConstant([MarshalAs(UnmanagedType.LPWStr)] String name,
                           Object value,
                           SymbolToken sigToken)
 {
     ((ISymUnmanagedWriter2)m_target).DefineConstant2(name, value, sigToken);
 }
예제 #21
0
파일: SymWriter.cs 프로젝트: ForNeVeR/pnet
 public virtual void OpenMethod(SymbolToken method)
 {
     // Nothing to do here.
 }
예제 #22
0
 public bool Equals(SymbolToken obj) // Method.
 {
     return(obj.m_token == this.m_token);
 }
예제 #23
0
 public virtual byte[] GetSymAttribute(SymbolToken parent, String name)
 {
     throw new NotSupportedException();
 }
예제 #24
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.SetUserEntryPoint"]/*' />
 public void SetUserEntryPoint(SymbolToken entryMethod)
 {
     m_target.SetUserEntryPoint(entryMethod);
 }
예제 #25
0
 public virtual ISymbolVariable[] GetVariables(SymbolToken parent)
 {
     throw new NotSupportedException();
 }
예제 #26
0
파일: Token.cs 프로젝트: alisci01/cs2cpp
 public bool Equals(SymbolToken obj)
 {
     return(obj.m_token == m_token);
 }
예제 #27
0
 public bool Equals(SymbolToken obj)
 {
     return(obj.GetToken() == _val);
 }
예제 #28
0
파일: SymWriter.cs 프로젝트: ForNeVeR/pnet
 public virtual void SetUserEntryPoint(SymbolToken entryMethod)
 {
     // Nothing to do here.
 }
예제 #29
0
파일: PdbWriter.cs 프로젝트: atykhyy/cecil
        void DefineIteratorType(SymbolToken method_token, string name)
        {
            var buffer = new PE.ByteBuffer ();
            buffer.WriteByte (4);
            buffer.WriteByte (1);
            buffer.Align     (4);
            buffer.WriteByte (4);
            buffer.WriteByte (4);
            buffer.Align	 (4);

            var length = 10 + (uint) name.Length * 2;
            while (length % 4 > 0)
                length++;

            buffer.WriteUInt32 (length);
            buffer.WriteBytes (System.Text.Encoding.Unicode.GetBytes (name));
            buffer.WriteByte (0);
            buffer.Align	 (4);

            writer.SetSymAttribute (method_token, "MD2", buffer.length, buffer.buffer);
        }
예제 #30
0
		internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
		{
			if (ilgen != null && ilgen.HasDebugInfo) {
				SymbolToken token = new SymbolToken (GetToken().Token);
				symbolWriter.OpenMethod (token);
				symbolWriter.SetSymAttribute (token, "__name", System.Text.Encoding.UTF8.GetBytes (Name));
				ilgen.GenerateDebugInfo (symbolWriter);
				symbolWriter.CloseMethod ();
			}
		}
예제 #31
0
파일: PdbWriter.cs 프로젝트: atykhyy/cecil
        void DefineVariables(MethodSymbols symbols, Collection<VariableDefinition> variables, int start_offset, int end_offset)
        {
            var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ());

            for (int i = 0; i < variables.Count; i++) {
                var variable = variables [i];
                CreateLocalVariable (variable, sym_token, start_offset, end_offset);
            }
        }
예제 #32
0
파일: SymWriter.cs 프로젝트: ttRevan/cecil
 public void SetUserEntryPoint(SymbolToken method)
 {
     m_writer.SetUserEntryPoint (method);
 }
예제 #33
0
 public virtual ISymbolMethod GetMethod(SymbolToken method)
 {
     return(GetMethod(method, 0));
 }
예제 #34
0
파일: SymWriter.cs 프로젝트: ForNeVeR/pnet
 public virtual void SetSymAttribute
     (SymbolToken parent, String name, byte[] data)
 {
     // Nothing to do here.
 }
예제 #35
0
		void CreateLocalVariable (IVariableDefinitionProvider provider, int startOffset, int endOffset, SymbolToken localVarToken)
		{
			for (int i = 0; i < provider.Variables.Count; i++) {
				VariableDefinition var = provider.Variables [i];
 				m_writer.DefineLocalVariable2(
  					var.Name,
  					0,
 					localVarToken,
  					SymAddressKind.ILOffset,
 					var.Index,
  					0,
  					0,
  					startOffset,
					endOffset);
			}
		}
예제 #36
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.DefineField"]/*' />
 public void DefineField(SymbolToken parent,
                         String name,
                         FieldAttributes attributes,
                         byte[] signature,
                         SymAddressKind addressKind,
                         int addr1,
                         int addr2,
                         int addr3)
 {
     m_target.DefineField(parent, name, (int)attributes, signature.Length, signature,
                          (int)addressKind, addr1, addr2, addr3);
 }
 //
 // Summary:
 //     Determines whether obj is equal to this instance.
 //
 // Parameters:
 //   obj:
 //     The System.Diagnostics.SymbolStore.SymbolToken to check.
 //
 // Returns:
 //     true if obj is equal to this instance; otherwise, false.
 public bool Equals(SymbolToken obj);
예제 #38
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.OpenMethod"]/*' />
 public void OpenMethod(SymbolToken method)
 {
     m_target.OpenMethod(method);
 }
예제 #39
0
		public byte[] GetSymAttribute(SymbolToken parent, string name) {
			uint bufSize;
			reader.GetSymAttribute((uint)parent.GetToken(), name, 0, out bufSize, null);
			var buffer = new byte[bufSize];
			reader.GetSymAttribute((uint)parent.GetToken(), name, (uint)buffer.Length, out bufSize, buffer);
			return buffer;
		}
예제 #40
0
 /// <include file='doc\SymWriter.uex' path='docs/doc[@for="SymbolWriter.SetSymAttribute"]/*' />
 public void SetSymAttribute(SymbolToken parent, String name, byte[] data)
 {
     m_target.SetSymAttribute(parent, name, data.Length, data);
 }
예제 #41
0
 /// <summary>Determines whether <paramref name="obj" /> is equal to this instance.</summary><returns>true if <paramref name="obj" /> is equal to this instance; otherwise, false.</returns><param name="obj">The <see cref="T:System.Diagnostics.SymbolStore.SymbolToken" /> to check.</param>
 public bool Equals(SymbolToken obj)
 {
     throw new NotImplementedException();
 }
예제 #42
0
        [System.Security.SecurityCritical]  // auto-generated
        private void SetUserEntryPointNoLock(MethodInfo entryPoint)
        {
            // Set the user entry point. Compiler may generate startup stub before calling user main.
            // The startup stub will be the entry point. While the user "main" will be the user entry
            // point so that debugger will not step into the compiler entry point.

            if (entryPoint == null)
            {
                throw new ArgumentNullException("entryPoint");
            }
            Contract.EndContractBlock();
        
            if (m_iSymWriter == null)
            {
                // Cannot set entry point when it is not a debug module
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
            }

            if (entryPoint.DeclaringType != null)
            {
                if (!entryPoint.Module.Equals(this))
                {
                    // you cannot pass in a MethodInfo that is not contained by this ModuleBuilder
                    throw new InvalidOperationException(Environment.GetResourceString("Argument_NotInTheSameModuleBuilder"));
                }
            }
            else
            {
                // unfortunately this check is missing for global function passed in as RuntimeMethodInfo. 
                // The problem is that Reflection does not 
                // allow us to get the containing module giving a global function
                MethodBuilder mb = entryPoint as MethodBuilder;
                if (mb != null && mb.GetModuleBuilder() != this)
                {
                    // you cannot pass in a MethodInfo that is not contained by this ModuleBuilder
                    throw new InvalidOperationException(Environment.GetResourceString("Argument_NotInTheSameModuleBuilder"));                    
                }                    
            }
                
            // get the metadata token value and create the SymbolStore's token value class
            SymbolToken       tkMethod = new SymbolToken(GetMethodTokenInternal(entryPoint).Token);

            // set the UserEntryPoint
            m_iSymWriter.SetUserEntryPoint(tkMethod);
        }
예제 #43
0
 public bool Equals(SymbolToken obj) => obj._token == _token;