Esempio n. 1
0
		void RemoveMarker(ILCodeBreakpoint ilbp) {
			IGlyphTextMethodMarker marker;
			if (toMethodMarkers.TryGetValue(ilbp, out marker)) {
				glyphTextMarkerService.Remove(marker);
				toMethodMarkers.Remove(ilbp);
			}
		}
Esempio n. 2
0
        BreakpointMarkerInfo GetBreakpointMarkerInfo(ILCodeBreakpoint ilbp)
        {
            ImageReference      imgRef;
            string              markerTypeName, selectedMarkerTypeName;
            IClassificationType classificationType;
            int zIndex;

            if (ilbp.IsEnabled)
            {
                imgRef                 = DsImages.BreakpointEnabled;
                markerTypeName         = ThemeClassificationTypeNameKeys.BreakpointStatementMarker;
                selectedMarkerTypeName = ThemeClassificationTypeNameKeys.SelectedBreakpointStatementMarker;
                classificationType     = classificationTypeEnabledBreakpoint;
                zIndex                 = GlyphTextMarkerServiceZIndexes.EnabledBreakpoint;
            }
            else
            {
                imgRef                 = DsImages.BreakpointDisabled;
                markerTypeName         = ThemeClassificationTypeNameKeys.DisabledBreakpointStatementMarker;
                selectedMarkerTypeName = null;
                classificationType     = null;
                zIndex                 = GlyphTextMarkerServiceZIndexes.DisabledBreakpoint;
            }
            return(new BreakpointMarkerInfo(imgRef, markerTypeName, selectedMarkerTypeName, classificationType, zIndex));
        }
Esempio n. 3
0
		void BreakpointAdded(ILCodeBreakpoint ilbp) {
			Debug.Assert(!toMethodMarkers.ContainsKey(ilbp));
			if (toMethodMarkers.ContainsKey(ilbp))
				return;
			ilbp.PropertyChanged += ILCodeBreakpoint_PropertyChanged;
			UpdateMarker(ilbp);
		}
		string GetToolTipContent(ILCodeBreakpoint ilbp, ITextView textView) {
			var documentViewer = textView.TextBuffer.TryGetDocumentViewer();
			Debug.Assert(documentViewer != null);
			var statement = documentViewer?.GetMethodDebugService().FindByCodeOffset(ilbp.MethodToken, ilbp.ILOffset);
			Debug.Assert((documentViewer != null) == (statement != null));
			ITextSnapshotLine snapshotLine = null;
			if (statement != null && statement.Value.Statement.TextSpan.End <= textView.TextSnapshot.Length)
				snapshotLine = textView.TextSnapshot.GetLineFromPosition(statement.Value.Statement.TextSpan.Start);

			var sb = new StringBuilder();
			sb.Append(dnSpy_Debugger_Resources.GlyphToolTip_Location);
			sb.Append(": ");
			if (snapshotLine != null) {
				sb.Append(string.Format(dnSpy_Debugger_Resources.GlyphToolTip_line_0_character_1,
					(snapshotLine.LineNumber + 1).ToString(CultureInfo.CurrentUICulture),
					(statement.Value.Statement.TextSpan.Start - snapshotLine.Start + 1).ToString(CultureInfo.CurrentUICulture)));
				sb.Append(" ");
			}
			sb.Append(string.Format(dnSpy_Debugger_Resources.GlyphToolTip_IL_offset_0, ilbp.ILOffset.ToString("X4")));

			if (statement != null) {
				sb.Append(" ('");
				var decompiler = (documentViewer?.DocumentTab.Content as IDecompilerTabContent)?.Decompiler ?? decompilerService.Decompiler;
				decompiler.Write(new StringBuilderTextColorOutput(sb), statement.Value.Method, SimplePrinterFlags.Default);
				sb.Append("')");
			}

			return sb.ToString();
		}
Esempio n. 5
0
		public void LoadInternal() {
			ILSpySettings settings = ILSpySettings.Load();
			var bpsx = settings["Breakpoints"];
			BreakpointManager.Instance.Clear();
			foreach (var bpx in bpsx.Elements("Breakpoint")) {
				uint? token = (uint?)bpx.Attribute("Token");
				string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
				string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
				bool isDynamic = (bool?)bpx.Attribute("IsDynamic") ?? false;
				bool isInMemory = (bool?)bpx.Attribute("IsInMemory") ?? false;
				uint? ilOffset = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");//TODO: Remove "From" some time after this commit
				bool? isEnabled = (bool?)bpx.Attribute("IsEnabled");

				if (token == null)
					continue;
				if (string.IsNullOrEmpty(moduleFullPath))
					continue;
				if (ilOffset == null)
					continue;
				if (isEnabled == null)
					continue;

				var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory);
				var key = MethodKey.Create(token.Value, snModule);
				var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value);
				BreakpointManager.Instance.Add(bp);
			}
		}
Esempio n. 6
0
        void UpdateMarker(ILCodeBreakpoint ilbp)
        {
            RemoveMarker(ilbp);
            var info   = GetBreakpointMarkerInfo(ilbp);
            var marker = glyphTextMarkerService.AddMarker(ilbp.MethodToken, ilbp.ILOffset, info.ImageReference, info.MarkerTypeName, info.SelectedMarkerTypeName, info.ClassificationType, info.ZIndex, GlyphTextMarkerHelper.GetTag(ilbp), ilCodeBreakpointGlyphTextMarkerHandler, textViewFilter);

            toMethodMarkers.Add(ilbp, marker);
        }
Esempio n. 7
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);
            }
        }
        void LoadInternal()
        {
            var section = settingsService.GetOrCreateSection(SETTINGS_GUID);

            breakpointService.Clear();
            foreach (var bpx in section.SectionsWithName("Breakpoint"))
            {
                uint?  token          = bpx.Attribute <uint?>("Token");
                string asmFullName    = bpx.Attribute <string>("AssemblyFullName");
                string moduleName     = bpx.Attribute <string>("ModuleName");
                bool?  isDynamic      = bpx.Attribute <bool?>("IsDynamic");
                bool?  isInMemory     = bpx.Attribute <bool?>("IsInMemory");
                bool   moduleNameOnly = bpx.Attribute <bool?>("ModuleNameOnly") ?? false;
                uint?  ilOffset       = bpx.Attribute <uint?>("ILOffset");
                bool?  isEnabled      = bpx.Attribute <bool?>("IsEnabled");

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

                var moduleId = ModuleId.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value, moduleNameOnly);
                var key      = new ModuleTokenId(moduleId, token.Value);

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

                var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
                breakpointService.Add(bp);
            }
        }
Esempio n. 9
0
 void BreakpointRemoved(ILCodeBreakpoint ilbp)
 {
     Debug.Assert(toMethodMarkers.ContainsKey(ilbp));
     if (!toMethodMarkers.ContainsKey(ilbp))
     {
         return;
     }
     RemoveMarker(ilbp);
     ilbp.PropertyChanged -= ILCodeBreakpoint_PropertyChanged;
 }
Esempio n. 10
0
 void BreakpointAdded(ILCodeBreakpoint ilbp)
 {
     Debug.Assert(!toMethodMarkers.ContainsKey(ilbp));
     if (toMethodMarkers.ContainsKey(ilbp))
     {
         return;
     }
     ilbp.PropertyChanged += ILCodeBreakpoint_PropertyChanged;
     UpdateMarker(ilbp);
 }
Esempio n. 11
0
        void RemoveMarker(ILCodeBreakpoint ilbp)
        {
            IGlyphTextMethodMarker marker;

            if (toMethodMarkers.TryGetValue(ilbp, out marker))
            {
                glyphTextMarkerService.Remove(marker);
                toMethodMarkers.Remove(ilbp);
            }
        }
Esempio n. 12
0
		static AssemblyDef GetAssembly(ILCodeBreakpoint bp) {
			var asmName = bp.Assembly;
			if (string.IsNullOrEmpty(asmName))
				return null;
			var loadedAsm = MainWindow.Instance.CurrentAssemblyList.FindAssemblyByFileName(asmName);
			if (loadedAsm != null)
				return loadedAsm.AssemblyDefinition;
			if (!File.Exists(asmName))
				return null;
			loadedAsm = MainWindow.Instance.LoadAssembly(asmName);
			return loadedAsm == null ? null : loadedAsm.AssemblyDefinition;
		}
Esempio n. 13
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 assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
                string moduleFullPath   = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
                bool   isDynamic        = (bool?)bpx.Attribute("IsDynamic") ?? false;
                bool   isInMemory       = (bool?)bpx.Attribute("IsInMemory") ?? false;
                uint?  ilOffset         = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");       //TODO: Remove "From" some time after this commit
                bool?  isEnabled        = (bool?)bpx.Attribute("IsEnabled");

                if (token == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleFullPath))
                {
                    continue;
                }
                if (ilOffset == null)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }

                var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory);
                var key      = MethodKey.Create(token.Value, snModule);

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

                var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value);
                BreakpointManager.Instance.Add(bp);
            }
        }
Esempio n. 14
0
        static AssemblyDef GetAssembly(ILCodeBreakpoint bp)
        {
            var asmName = bp.Assembly;

            if (string.IsNullOrEmpty(asmName))
            {
                return(null);
            }
            var loadedAsm = MainWindow.Instance.CurrentAssemblyList.FindAssemblyByFileName(asmName);

            if (loadedAsm != null)
            {
                return(loadedAsm.AssemblyDefinition);
            }
            if (!File.Exists(asmName))
            {
                return(null);
            }
            loadedAsm = MainWindow.Instance.LoadAssembly(asmName);
            return(loadedAsm == null ? null : loadedAsm.AssemblyDefinition);
        }
Esempio n. 15
0
        public void Add(MethodDef method)
        {
            if (method.Body == null)
            {
                return;
            }
            var methodToken         = CreateTokenId(method);
            var existingBreakpoints = GetILCodeBreakpoints(methodToken, 0).ToArray();

            if (existingBreakpoints.Length != 0)
            {
                foreach (var ilbp in existingBreakpoints)
                {
                    ilbp.IsEnabled = true;
                }
            }
            else
            {
                var ilbp = new ILCodeBreakpoint(methodToken, 0);
                Add(ilbp);
            }
        }
        string GetToolTipContent(ILCodeBreakpoint ilbp, ITextView textView)
        {
            var documentViewer = textView.TextBuffer.TryGetDocumentViewer();

            Debug.Assert(documentViewer != null);
            var statement = documentViewer?.GetMethodDebugService().FindByCodeOffset(ilbp.MethodToken, ilbp.ILOffset);

            Debug.Assert((documentViewer != null) == (statement != null));
            ITextSnapshotLine snapshotLine = null;

            if (statement != null && statement.Value.Statement.TextSpan.End <= textView.TextSnapshot.Length)
            {
                snapshotLine = textView.TextSnapshot.GetLineFromPosition(statement.Value.Statement.TextSpan.Start);
            }

            var sb = new StringBuilder();

            sb.Append(dnSpy_Debugger_Resources.GlyphToolTip_Location);
            sb.Append(": ");
            if (snapshotLine != null)
            {
                sb.Append(string.Format(dnSpy_Debugger_Resources.GlyphToolTip_line_0_character_1,
                                        (snapshotLine.LineNumber + 1).ToString(CultureInfo.CurrentUICulture),
                                        (statement.Value.Statement.TextSpan.Start - snapshotLine.Start + 1).ToString(CultureInfo.CurrentUICulture)));
                sb.Append(" ");
            }
            sb.Append(string.Format(dnSpy_Debugger_Resources.GlyphToolTip_IL_offset_0, ilbp.ILOffset.ToString("X4")));

            if (statement != null)
            {
                sb.Append(" ('");
                var decompiler = (documentViewer?.DocumentTab.Content as IDecompilerTabContent)?.Decompiler ?? decompilerService.Decompiler;
                decompiler.Write(new StringBuilderTextColorOutput(sb), statement.Value.Method, SimplePrinterFlags.Default);
                sb.Append("')");
            }

            return(sb.ToString());
        }
Esempio n. 17
0
 public MyMarkedTextLine(ILCodeBreakpoint ilbp, MethodKey methodKey, uint ilOffset)
     : base(methodKey, ilOffset, ilbp)
 {
     this.ilbp = ilbp;
 }
Esempio n. 18
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);
			}
		}
Esempio n. 19
0
        static ModuleDef GetModule(ILCodeBreakpoint bp)
        {
            var loadedAsm = MainWindow.Instance.LoadAssembly(bp.Assembly, bp.MethodKey.Module);

            return(loadedAsm == null ? null : loadedAsm.ModuleDefinition);
        }
Esempio n. 20
0
		void LoadInternal() {
			var section = settingsManager.GetOrCreateSection(SETTINGS_GUID);
			breakpointManager.Clear();
			foreach (var bpx in section.SectionsWithName("Breakpoint")) {
				uint? token = bpx.Attribute<uint?>("Token");
				string asmFullName = bpx.Attribute<string>("AssemblyFullName");
				string moduleName = bpx.Attribute<string>("ModuleName");
				bool? isDynamic = bpx.Attribute<bool?>("IsDynamic");
				bool? isInMemory = bpx.Attribute<bool?>("IsInMemory");
				uint? ilOffset = bpx.Attribute<uint?>("ILOffset");
				bool? isEnabled = bpx.Attribute<bool?>("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 = SerializedDnModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value);
				var key = new SerializedDnToken(snModule, token.Value);

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

				var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
				breakpointManager.Add(bp);
			}
		}
Esempio n. 21
0
			public MyMarkedTextLine(ILCodeBreakpoint ilbp, MethodKey methodKey, uint ilOffset)
				: base(methodKey, ilOffset, ilbp) {
				this.ilbp = ilbp;
			}
Esempio n. 22
0
			public MyMarkedTextLine(ILCodeBreakpoint ilbp, SerializedDnToken methodKey, uint ilOffset)
				: base(methodKey, ilOffset, ilbp) {
				this.ilbp = ilbp;
			}
Esempio n. 23
0
 public MyMarkedTextLine(ILCodeBreakpoint ilbp, SerializedDnSpyToken methodKey, uint ilOffset)
     : base(methodKey, ilOffset, ilbp)
 {
     this.ilbp = ilbp;
 }
Esempio n. 24
0
		public void Add(MethodDef method) {
			if (method.Body == null)
				return;
			var methodToken = CreateTokenId(method);
			var existingBreakpoints = GetILCodeBreakpoints(methodToken, 0).ToArray();
			if (existingBreakpoints.Length != 0) {
				foreach (var ilbp in existingBreakpoints)
					ilbp.IsEnabled = true;
			}
			else {
				var ilbp = new ILCodeBreakpoint(methodToken, 0);
				Add(ilbp);
			}
		}
Esempio n. 25
0
		BreakpointMarkerInfo GetBreakpointMarkerInfo(ILCodeBreakpoint ilbp) {
			ImageReference imgRef;
			string markerTypeName, selectedMarkerTypeName;
			IClassificationType classificationType;
			int zIndex;
			if (ilbp.IsEnabled) {
				imgRef = DsImages.BreakpointEnabled;
				markerTypeName = ThemeClassificationTypeNameKeys.BreakpointStatementMarker;
				selectedMarkerTypeName = ThemeClassificationTypeNameKeys.SelectedBreakpointStatementMarker;
				classificationType = classificationTypeEnabledBreakpoint;
				zIndex = GlyphTextMarkerServiceZIndexes.EnabledBreakpoint;
			}
			else {
				imgRef = DsImages.BreakpointDisabled;
				markerTypeName = ThemeClassificationTypeNameKeys.DisabledBreakpointStatementMarker;
				selectedMarkerTypeName = null;
				classificationType = null;
				zIndex = GlyphTextMarkerServiceZIndexes.DisabledBreakpoint;
			}
			return new BreakpointMarkerInfo(imgRef, markerTypeName, selectedMarkerTypeName, classificationType, zIndex);
		}
Esempio n. 26
0
		void UpdateMarker(ILCodeBreakpoint ilbp) {
			RemoveMarker(ilbp);
			var info = GetBreakpointMarkerInfo(ilbp);
			var marker = glyphTextMarkerService.AddMarker(ilbp.MethodToken, ilbp.ILOffset, info.ImageReference, info.MarkerTypeName, info.SelectedMarkerTypeName, info.ClassificationType, info.ZIndex, GlyphTextMarkerHelper.GetTag(ilbp), ilCodeBreakpointGlyphTextMarkerHandler, textViewFilter);
			toMethodMarkers.Add(ilbp, marker);
		}
Esempio n. 27
0
		static ModuleDef GetModule(ILCodeBreakpoint bp) {
			var loadedAsm = MainWindow.Instance.LoadAssembly(bp.Assembly, bp.MethodKey.Module);
			return loadedAsm == null ? null : loadedAsm.ModuleDefinition;
		}
Esempio n. 28
0
		void BreakpointRemoved(ILCodeBreakpoint ilbp) {
			Debug.Assert(toMethodMarkers.ContainsKey(ilbp));
			if (!toMethodMarkers.ContainsKey(ilbp))
				return;
			RemoveMarker(ilbp);
			ilbp.PropertyChanged -= ILCodeBreakpoint_PropertyChanged;
		}