コード例 #1
0
        static string GetMethodAsString(SerializedDnSpyToken key)
        {
            var file   = ModuleLoader.Instance.LoadModule(key.Module, true, true);
            var method = file == null ? null : file.ModuleDef.ResolveToken(key.Token) as MethodDef;

            return(method == null ? null : method.ToString());
        }
コード例 #2
0
ファイル: LocalsControl.xaml.cs プロジェクト: arkanoid1/dnSpy
			public void GetMethodInfo(SerializedDnSpyToken key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals) {
				parameters = null;
				locals = null;
				decLocals = null;

				foreach (var textView in MainWindow.Instance.AllTextViews) {
					if (parameters != null && decLocals != null)
						break;

					var cm = textView.CodeMappings;
					if (cm == null)
						continue;
					MemberMapping mapping;
					if (!cm.TryGetValue(key, out mapping))
						continue;
					var method = mapping.MethodDef;
					if (mapping.LocalVariables != null && method.Body != null) {
						locals = method.Body.Variables.ToArray();
						decLocals = new ILVariable[method.Body.Variables.Count];
						foreach (var v in mapping.LocalVariables) {
							if (v.IsGenerated)
								continue;
							if (v.OriginalVariable == null)
								continue;
							if ((uint)v.OriginalVariable.Index >= decLocals.Length)
								continue;
							decLocals[v.OriginalVariable.Index] = v;
						}
					}

					parameters = method.Parameters.ToArray();
				}
			}
コード例 #3
0
ファイル: DebugUtils.cs プロジェクト: arkanoid1/dnSpy
		static bool JumpToStatement(MethodDef method, uint ilOffset, DecompilerTextView textView) {
			if (method == null)
				return false;
			var serMod = method.Module.ToSerializedDnSpyModule();
			var key = new SerializedDnSpyToken(serMod, method.MDToken);
			if (textView == null)
				textView = MainWindow.Instance.SafeActiveTextView;

			bool found = MainWindow.Instance.DnSpyFileListTreeNode.FindModuleNode(method.Module) != null;
			if (found) {
				return MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
					if (success)
						return MoveCaretTo(textView, key, ilOffset);
					return false;
				});
			}

			MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
				MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
					if (success)
						return MoveCaretTo(textView, key, ilOffset);
					return false;
				});
			}));
			return true;
		}
コード例 #4
0
ファイル: BreakpointManager.cs プロジェクト: xornand/dnSpy
            public static void Toggle(DecompilerTextView textView, int line, int column)
            {
                var bps   = SourceCodeMappingUtils.Find(textView, line, column);
                var ilbps = GetILCodeBreakpoints(textView, bps);

                if (ilbps.Count > 0)
                {
                    if (IsEnabled(ilbps))
                    {
                        foreach (var ilbp in ilbps)
                        {
                            BreakpointManager.Instance.Remove(ilbp);
                        }
                    }
                    else
                    {
                        foreach (var bpm in ilbps)
                        {
                            bpm.IsEnabled = true;
                        }
                    }
                }
                else if (bps.Count > 0)
                {
                    foreach (var bp in bps)
                    {
                        var md     = bp.MemberMapping.MethodDef;
                        var serMod = md.Module.ToSerializedDnSpyModule();
                        var key    = new SerializedDnSpyToken(serMod, md.MDToken);
                        BreakpointManager.Instance.Add(new ILCodeBreakpoint(key, bp.ILInstructionOffset.From));
                    }
                    textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
                }
            }
コード例 #5
0
        void LoadInternal()
        {
            DNSpySettings settings = DNSpySettings.Load();
            var           bpsx     = settings[SETTINGS_NAME];

            BreakpointManager.Instance.Clear();
            foreach (var bpx in bpsx.Elements("Breakpoint"))
            {
                uint?  token       = (uint?)bpx.Attribute("Token");
                string asmFullName = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullName"));
                string moduleName  = SessionSettings.Unescape((string)bpx.Attribute("ModuleName"));
                bool?  isDynamic   = (bool?)bpx.Attribute("IsDynamic");
                bool?  isInMemory  = (bool?)bpx.Attribute("IsInMemory");
                uint?  ilOffset    = (uint?)bpx.Attribute("ILOffset");
                bool?  isEnabled   = (bool?)bpx.Attribute("IsEnabled");

                if (token == null)
                {
                    continue;
                }
                if (isDynamic == null || isInMemory == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(asmFullName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleName))
                {
                    continue;
                }
                if (ilOffset == null)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }

                var snModule = SerializedDnSpyModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value);
                var key      = new SerializedDnSpyToken(snModule, token.Value);

                if (!isInMemory.Value && !isDynamic.Value)
                {
                    var s = SessionSettings.Unescape((string)bpx.Attribute("Method"));
                    if (s == null || s != GetMethodAsString(key))
                    {
                        continue;
                    }
                }

                var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
                BreakpointManager.Instance.Add(bp);
            }
        }
コード例 #6
0
ファイル: LocalsControl.xaml.cs プロジェクト: xornand/dnSpy
            public void GetMethodInfo(SerializedDnSpyToken key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals)
            {
                parameters = null;
                locals     = null;
                decLocals  = null;

                foreach (var textView in MainWindow.Instance.AllTextViews)
                {
                    if (parameters != null && decLocals != null)
                    {
                        break;
                    }

                    var cm = textView.CodeMappings;
                    if (cm == null)
                    {
                        continue;
                    }
                    MemberMapping mapping;
                    if (!cm.TryGetValue(key, out mapping))
                    {
                        continue;
                    }
                    var method = mapping.MethodDef;
                    if (mapping.LocalVariables != null && method.Body != null)
                    {
                        locals    = method.Body.Variables.ToArray();
                        decLocals = new ILVariable[method.Body.Variables.Count];
                        foreach (var v in mapping.LocalVariables)
                        {
                            if (v.IsGenerated)
                            {
                                continue;
                            }
                            if (v.OriginalVariable == null)
                            {
                                continue;
                            }
                            if ((uint)v.OriginalVariable.Index >= decLocals.Length)
                            {
                                continue;
                            }
                            decLocals[v.OriginalVariable.Index] = v;
                        }
                    }

                    parameters = method.Parameters.ToArray();
                }
            }
コード例 #7
0
ファイル: DebugUtils.cs プロジェクト: arkanoid1/dnSpy
		public static bool MoveCaretTo(DecompilerTextView textView, SerializedDnSpyToken key, uint ilOffset) {
			if (textView == null)
				return false;

			Dictionary<SerializedDnSpyToken, MemberMapping> cm;
			if (!VerifyAndGetCurrentDebuggedMethod(textView, key, out cm))
				return false;

			TextLocation location, endLocation;
			if (!cm[key].GetInstructionByTokenAndOffset(ilOffset, out location, out endLocation))
				return false;

			textView.ScrollAndMoveCaretTo(location.Line, location.Column);
			return true;
		}
コード例 #8
0
        static bool JumpToStatement(MethodDef method, uint ilOffset, DecompilerTextView textView)
        {
            if (method == null)
            {
                return(false);
            }
            var serMod = method.Module.ToSerializedDnSpyModule();
            var key    = new SerializedDnSpyToken(serMod, method.MDToken);

            if (textView == null)
            {
                textView = MainWindow.Instance.SafeActiveTextView;
            }

            bool found = MainWindow.Instance.DnSpyFileListTreeNode.FindModuleNode(method.Module) != null;

            if (found)
            {
                return(MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
                    if (success)
                    {
                        return MoveCaretTo(textView, key, ilOffset);
                    }
                    return false;
                }));
            }

            MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
                MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
                    if (success)
                    {
                        return(MoveCaretTo(textView, key, ilOffset));
                    }
                    return(false);
                });
            }));
            return(true);
        }
コード例 #9
0
        public static bool MoveCaretTo(DecompilerTextView textView, SerializedDnSpyToken key, uint ilOffset)
        {
            if (textView == null)
            {
                return(false);
            }

            Dictionary <SerializedDnSpyToken, MemberMapping> cm;

            if (!VerifyAndGetCurrentDebuggedMethod(textView, key, out cm))
            {
                return(false);
            }

            TextLocation location, endLocation;

            if (!cm[key].GetInstructionByTokenAndOffset(ilOffset, out location, out endLocation))
            {
                return(false);
            }

            textView.ScrollAndMoveCaretTo(location.Line, location.Column);
            return(true);
        }
コード例 #10
0
ファイル: DebugUtils.cs プロジェクト: arkanoid1/dnSpy
		public static bool VerifyAndGetCurrentDebuggedMethod(DecompilerTextView textView, SerializedDnSpyToken serToken, out Dictionary<SerializedDnSpyToken, MemberMapping> codeMappings) {
			codeMappings = textView == null ? null : textView.CodeMappings;
			if (codeMappings == null || !codeMappings.ContainsKey(serToken))
				return false;

			return true;
		}
コード例 #11
0
		static string GetMethodAsString(SerializedDnSpyToken key) {
			var file = ModuleLoader.Instance.LoadModule(key.Module, true, true);
			var method = file == null ? null : file.ModuleDef.ResolveToken(key.Token) as MethodDef;
			return method == null ? null : method.ToString();
		}
コード例 #12
0
ファイル: BreakpointManager.cs プロジェクト: arkanoid1/dnSpy
			public static void Toggle(DecompilerTextView textView, int line, int column) {
				var bps = SourceCodeMappingUtils.Find(textView, line, column);
				var ilbps = GetILCodeBreakpoints(textView, bps);
				if (ilbps.Count > 0) {
					if (IsEnabled(ilbps)) {
						foreach (var ilbp in ilbps)
							BreakpointManager.Instance.Remove(ilbp);
					}
					else {
						foreach (var bpm in ilbps)
							bpm.IsEnabled = true;
					}
				}
				else if (bps.Count > 0) {
					foreach (var bp in bps) {
						var md = bp.MemberMapping.MethodDef;
						var serMod = md.Module.ToSerializedDnSpyModule();
						var key = new SerializedDnSpyToken(serMod, md.MDToken);
						BreakpointManager.Instance.Add(new ILCodeBreakpoint(key, bp.ILInstructionOffset.From));
					}
					textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
				}
			}
コード例 #13
0
ファイル: StackFrameLine.cs プロジェクト: arkanoid1/dnSpy
		public StackFrameLine(StackFrameLineType type, DecompilerTextView decompilerTextView, SerializedDnSpyToken methodKey, uint ilOffset)
			: base(methodKey, ilOffset) {
			this.type = type;
			this.decompilerTextView = decompilerTextView;
		}
コード例 #14
0
 public StackFrameLine(StackFrameLineType type, DecompilerTextView decompilerTextView, SerializedDnSpyToken methodKey, uint ilOffset)
     : base(methodKey, ilOffset)
 {
     this.type = type;
     this.decompilerTextView = decompilerTextView;
 }
コード例 #15
0
ファイル: MarkedTextLine.cs プロジェクト: arkanoid1/dnSpy
		protected MarkedTextLine(SerializedDnSpyToken methodKey, uint ilOffset, IMarkedTextLine senderObj = null) {
			this.methodKey = methodKey;
			this.ilOffset = ilOffset;
			this.senderObj = senderObj ?? this;
		}
コード例 #16
0
 protected MarkedTextLine(SerializedDnSpyToken methodKey, uint ilOffset, IMarkedTextLine senderObj = null)
 {
     this.methodKey = methodKey;
     this.ilOffset  = ilOffset;
     this.senderObj = senderObj ?? this;
 }
コード例 #17
0
        /// <summary>
        /// Should be called each time the IL offset has been updated
        /// </summary>
        bool UpdateStackFrameLines(DecompilerTextView decompilerTextView, bool moveCaret = false)
        {
            Remove(decompilerTextView);
            bool movedCaret             = false;
            var  cm                     = decompilerTextView == null ? null : decompilerTextView.CodeMappings;
            bool updateReturnStatements = cm != null && DebugManager.Instance.ProcessState == DebuggerProcessState.Stopped;

            if (updateReturnStatements)
            {
                int  frameNo = -1;
                bool tooManyFrames;
                foreach (var frame in GetFrames(MAX_STACKFRAME_LINES, out tooManyFrames))
                {
                    frameNo++;
                    if (!frame.IsILFrame)
                    {
                        continue;
                    }
                    var ip = frame.ILFrameIP;
                    if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog)
                    {
                        continue;
                    }
                    uint token = frame.Token;
                    if (token == 0)
                    {
                        continue;
                    }
                    var serAsm = frame.SerializedDnModule;
                    if (serAsm == null)
                    {
                        continue;
                    }

                    StackFrameLineType type;
                    if (frameNo == 0)
                    {
                        type = StackFrameLineType.CurrentStatement;
                    }
                    else
                    {
                        type = currentState.FrameNumber == frameNo ? StackFrameLineType.SelectedReturnStatement : StackFrameLineType.ReturnStatement;
                    }
                    var          key    = new SerializedDnSpyToken(serAsm.Value.ToSerializedDnSpyModule(), token);
                    uint         offset = frame.GetILOffset();
                    MethodDef    methodDef;
                    TextLocation location, endLocation;
                    if (cm != null && cm.ContainsKey(key) &&
                        cm[key].GetInstructionByTokenAndOffset(offset, out methodDef, out location, out endLocation))
                    {
                        var rs = new StackFrameLine(type, decompilerTextView, key, offset);
                        stackFrameLines.Add(rs);
                        TextLineObjectManager.Instance.Add(rs);

                        if (moveCaret && frameNo == currentState.FrameNumber)
                        {
                            decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column);
                            movedCaret = true;
                        }
                    }
                }
            }
            return(movedCaret);
        }
コード例 #18
0
ファイル: ILCodeBreakpoint.cs プロジェクト: xornand/dnSpy
 public MyMarkedTextLine(ILCodeBreakpoint ilbp, SerializedDnSpyToken methodKey, uint ilOffset)
     : base(methodKey, ilOffset, ilbp)
 {
     this.ilbp = ilbp;
 }
コード例 #19
0
ファイル: ILCodeBreakpoint.cs プロジェクト: arkanoid1/dnSpy
			public MyMarkedTextLine(ILCodeBreakpoint ilbp, SerializedDnSpyToken methodKey, uint ilOffset)
				: base(methodKey, ilOffset, ilbp) {
				this.ilbp = ilbp;
			}
コード例 #20
0
		void LoadInternal() {
			DNSpySettings settings = DNSpySettings.Load();
			var bpsx = settings[SETTINGS_NAME];
			BreakpointManager.Instance.Clear();
			foreach (var bpx in bpsx.Elements("Breakpoint")) {
				uint? token = (uint?)bpx.Attribute("Token");
				string asmFullName = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullName"));
				string moduleName = SessionSettings.Unescape((string)bpx.Attribute("ModuleName"));
				bool? isDynamic = (bool?)bpx.Attribute("IsDynamic");
				bool? isInMemory = (bool?)bpx.Attribute("IsInMemory");
				uint? ilOffset = (uint?)bpx.Attribute("ILOffset");
				bool? isEnabled = (bool?)bpx.Attribute("IsEnabled");

				if (token == null)
					continue;
				if (isDynamic == null || isInMemory == null)
					continue;
				if (string.IsNullOrEmpty(asmFullName))
					continue;
				if (string.IsNullOrEmpty(moduleName))
					continue;
				if (ilOffset == null)
					continue;
				if (isEnabled == null)
					continue;

				var snModule = SerializedDnSpyModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value);
				var key = new SerializedDnSpyToken(snModule, token.Value);

				if (!isInMemory.Value && !isDynamic.Value) {
					var s = SessionSettings.Unescape((string)bpx.Attribute("Method"));
					if (s == null || s != GetMethodAsString(key))
						continue;
				}

				var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
				BreakpointManager.Instance.Add(bp);
			}
		}
コード例 #21
0
ファイル: StackFrameManager.cs プロジェクト: arkanoid1/dnSpy
		/// <summary>
		/// Should be called each time the IL offset has been updated
		/// </summary>
		bool UpdateStackFrameLines(DecompilerTextView decompilerTextView, bool moveCaret = false) {
			Remove(decompilerTextView);
			bool movedCaret = false;
			var cm = decompilerTextView == null ? null : decompilerTextView.CodeMappings;
			bool updateReturnStatements = cm != null && DebugManager.Instance.ProcessState == DebuggerProcessState.Stopped;
			if (updateReturnStatements) {
				int frameNo = -1;
				bool tooManyFrames;
				foreach (var frame in GetFrames(MAX_STACKFRAME_LINES, out tooManyFrames)) {
					frameNo++;
					if (!frame.IsILFrame)
						continue;
					var ip = frame.ILFrameIP;
					if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog)
						continue;
					uint token = frame.Token;
					if (token == 0)
						continue;
					var serAsm = frame.SerializedDnModule;
					if (serAsm == null)
						continue;

					StackFrameLineType type;
					if (frameNo == 0)
						type = StackFrameLineType.CurrentStatement;
					else
						type = currentState.FrameNumber == frameNo ? StackFrameLineType.SelectedReturnStatement : StackFrameLineType.ReturnStatement;
					var key = new SerializedDnSpyToken(serAsm.Value.ToSerializedDnSpyModule(), token);
					uint offset = frame.GetILOffset();
					MethodDef methodDef;
					TextLocation location, endLocation;
					if (cm != null && cm.ContainsKey(key) &&
						cm[key].GetInstructionByTokenAndOffset(offset, out methodDef, out location, out endLocation)) {
						var rs = new StackFrameLine(type, decompilerTextView, key, offset);
						stackFrameLines.Add(rs);
						TextLineObjectManager.Instance.Add(rs);

						if (moveCaret && frameNo == currentState.FrameNumber) {
							decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column);
							movedCaret = true;
						}
					}
				}
			}
			return movedCaret;
		}
コード例 #22
0
        public static bool VerifyAndGetCurrentDebuggedMethod(DecompilerTextView textView, SerializedDnSpyToken serToken, out Dictionary <SerializedDnSpyToken, MemberMapping> codeMappings)
        {
            codeMappings = textView == null ? null : textView.CodeMappings;
            if (codeMappings == null || !codeMappings.ContainsKey(serToken))
            {
                return(false);
            }

            return(true);
        }
コード例 #23
0
ファイル: ILCodeBreakpoint.cs プロジェクト: xornand/dnSpy
 public ILCodeBreakpoint(SerializedDnSpyToken methodKey, uint ilOffset, bool isEnabled = true)
     : base(isEnabled)
 {
     this.myMarkedTextLine = new MyMarkedTextLine(this, methodKey, ilOffset);
 }
コード例 #24
0
ファイル: ILCodeBreakpoint.cs プロジェクト: arkanoid1/dnSpy
		public ILCodeBreakpoint(SerializedDnSpyToken methodKey, uint ilOffset, bool isEnabled = true)
			: base(isEnabled) {
			this.myMarkedTextLine = new MyMarkedTextLine(this, methodKey, ilOffset);
		}