Exemplo n.º 1
0
		public void SyncBookmarks()
		{
			var storage = DebugInformation.CodeMappings;
			if (storage == null || storage.Count == 0)
				return;
			
			// TODO: handle other types of bookmarks
			// remove existing bookmarks and create new ones
			// update of existing bookmarks for new position does not update TextMarker
			// this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed
			List<BreakpointBookmark> newBookmarks = new List<BreakpointBookmark>();
			for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i) {
				var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark;
				if (breakpoint == null)
					continue;
				
				var key = breakpoint.FunctionToken;
				if (!storage.ContainsKey(key))
					continue;
				
				bool isMatch;
				SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(breakpoint.ILRange.From, out isMatch);
				
				if (map != null) {
					BreakpointBookmark newBookmark = new BreakpointBookmark(breakpoint.MemberReference,
					                                                        new TextLocation(map.StartLocation.Line, 0),
					                                                        breakpoint.FunctionToken,
					                                                        map.ILInstructionOffset,
					                                                        BreakpointAction.Break);
					newBookmark.IsEnabled = breakpoint.IsEnabled;
					
					newBookmarks.Add(newBookmark);

					BookmarkManager.RemoveMark(breakpoint);
				}
			}
			newBookmarks.ForEach(m => BookmarkManager.AddMark(m));
			SyncCurrentLineBookmark();
		}
Exemplo n.º 2
0
		void AddBreakpoint(BreakpointBookmark bookmark)
		{
			Breakpoint breakpoint = null;
			
			breakpoint = new ILBreakpoint(
				debugger,
				bookmark.MemberReference.DeclaringType.FullName,
				bookmark.LineNumber,
				bookmark.MemberReference.MetadataToken.ToInt32(),
				bookmark.ILRange.From,
				bookmark.IsEnabled);
			
			debugger.Breakpoints.Add(breakpoint);
//			Action setBookmarkColor = delegate {
//				if (debugger.Processes.Count == 0) {
//					bookmark.IsHealthy = true;
//					bookmark.Tooltip = null;
//				} else if (!breakpoint.IsSet) {
//					bookmark.IsHealthy = false;
//					bookmark.Tooltip = "Breakpoint was not found in any loaded modules";
//				} else if (breakpoint.OriginalLocation.CheckSum == null) {
//					bookmark.IsHealthy = true;
//					bookmark.Tooltip = null;
//				} else {
//					byte[] fileMD5;
//					IEditable file = FileService.GetOpenFile(bookmark.FileName) as IEditable;
//					if (file != null) {
//						byte[] fileContent = Encoding.UTF8.GetBytesWithPreamble(file.Text);
//						fileMD5 = new MD5CryptoServiceProvider().ComputeHash(fileContent);
//					} else {
//						fileMD5 = new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(bookmark.FileName));
//					}
//					if (Compare(fileMD5, breakpoint.OriginalLocation.CheckSum)) {
//						bookmark.IsHealthy = true;
//						bookmark.Tooltip = null;
//					} else {
//						bookmark.IsHealthy = false;
//						bookmark.Tooltip = "Check sum or file does not match to the original";
//					}
//				}
//			};
			
			// event handlers on bookmark and breakpoint don't need deregistration
			bookmark.IsEnabledChanged += delegate {
				breakpoint.Enabled = bookmark.IsEnabled;
			};
			breakpoint.Set += delegate {
				//setBookmarkColor();
			};
			
			//setBookmarkColor();
			
			EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessStarted = (sender, e) => {
				//setBookmarkColor();
				// User can change line number by inserting or deleting lines
				breakpoint.Line = bookmark.LineNumber;
			};
			EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessExited = (sender, e) => {
				//setBookmarkColor();
			};
			
			EventHandler<BreakpointEventArgs> bp_debugger_BreakpointHit =
				new EventHandler<BreakpointEventArgs>(
					delegate(object sender, BreakpointEventArgs e)
					{
						//LoggingService.Debug(bookmark.Action + " " + bookmark.ScriptLanguage + " " + bookmark.Condition);
						
						switch (bookmark.Action) {
							case BreakpointAction.Break:
								break;
							case BreakpointAction.Condition:
//								if (Evaluate(bookmark.Condition, bookmark.ScriptLanguage))
//									DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAtBecause}") + "\n", bookmark.LineNumber, bookmark.FileName, bookmark.Condition));
//								else
//									this.debuggedProcess.AsyncContinue();
								break;
							case BreakpointAction.Trace:
								//DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAt}") + "\n", bookmark.LineNumber, bookmark.FileName));
								break;
						}
					});
			
			BookmarkEventHandler bp_bookmarkManager_Removed = null;
			bp_bookmarkManager_Removed = (sender, e) => {
				if (bookmark == e.Bookmark) {
					debugger.Breakpoints.Remove(breakpoint);
					
					// unregister the events
					debugger.Processes.Added -= bp_debugger_ProcessStarted;
					debugger.Processes.Removed -= bp_debugger_ProcessExited;
					breakpoint.Hit -= bp_debugger_BreakpointHit;
					BookmarkManager.Removed -= bp_bookmarkManager_Removed;
				}
			};
			// register the events
			debugger.Processes.Added += bp_debugger_ProcessStarted;
			debugger.Processes.Removed += bp_debugger_ProcessExited;
			breakpoint.Hit += bp_debugger_BreakpointHit;
			BookmarkManager.Removed += bp_bookmarkManager_Removed;
		}
		public BreakpointBookmarkEventArgs(BreakpointBookmark breakpointBookmark)
		{
			this.breakpointBookmark = breakpointBookmark;
		}
Exemplo n.º 4
0
 public BreakpointBookmarkEventArgs(BreakpointBookmark breakpointBookmark)
 {
     this.breakpointBookmark = breakpointBookmark;
 }
Exemplo n.º 5
0
 public BreakpointBookmarkVM(BreakpointBookmark bpm)
 {
     this.bpm = bpm;
 }
Exemplo n.º 6
0
        void AddBreakpoint(BreakpointBookmark bookmark)
        {
            Breakpoint breakpoint = null;

            breakpoint = new ILBreakpoint(
                debugger,
                bookmark.Location,
                bookmark.EndLocation,
                bookmark.MethodKey,
                bookmark.ILRange.From,
                bookmark.IsEnabled);

            debugger.Breakpoints.Add(breakpoint);

            // event handlers on bookmark and breakpoint don't need deregistration
            bookmark.IsEnabledChanged += delegate {
                breakpoint.Enabled = bookmark.IsEnabled;
            };

            EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessStarted = (sender, e) => {
                // User can change line number by inserting or deleting lines
                breakpoint.Location = bookmark.Location;
                breakpoint.EndLocation = bookmark.EndLocation;
            };
            EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessExited = (sender, e) => {
            };

            BookmarkEventHandler bp_bookmarkManager_Removed = null;
            bp_bookmarkManager_Removed = (sender, e) => {
                if (bookmark == e.Bookmark) {
                    debugger.Breakpoints.Remove(breakpoint);

                    // unregister the events
                    debugger.Processes.Added -= bp_debugger_ProcessStarted;
                    debugger.Processes.Removed -= bp_debugger_ProcessExited;
                    BookmarkManager.Removed -= bp_bookmarkManager_Removed;
                }
            };
            // register the events
            debugger.Processes.Added += bp_debugger_ProcessStarted;
            debugger.Processes.Removed += bp_debugger_ProcessExited;
            BookmarkManager.Removed += bp_bookmarkManager_Removed;
        }
Exemplo n.º 7
0
        public void LoadInternal()
        {
            ILSpySettings settings = ILSpySettings.Load();
            var bpsx = settings["Breakpoints"];
            BookmarkManager.RemoveMarks<BreakpointBookmark>();
            foreach (var bpx in bpsx.Elements("Breakpoint")) {
                int? token = (int?)bpx.Attribute("Token");
                string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
                string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
                uint? from = (uint?)bpx.Attribute("From");
                uint? to = (uint?)bpx.Attribute("To");
                bool? isEnabled = (bool?)bpx.Attribute("IsEnabled");
                int? locationLine = (int?)bpx.Attribute("LocationLine");
                int? locationColumn = (int?)bpx.Attribute("LocationColumn");
                int? endLocationLine = (int?)bpx.Attribute("EndLocationLine");
                int? endLocationColumn = (int?)bpx.Attribute("EndLocationColumn");
                string methodFullName = SessionSettings.Unescape((string)bpx.Attribute("MethodFullName"));

                if (token == null) continue;
                if (string.IsNullOrEmpty(moduleFullPath)) continue;
                if (assemblyFullPath == null) continue;
                if (from == null || to == null || from.Value >= to.Value) continue;
                if (isEnabled == null) continue;
                if (locationLine == null || locationLine.Value < 1) continue;
                if (locationColumn == null || locationColumn.Value < 1) continue;
                if (endLocationLine == null || endLocationLine.Value < 1) continue;
                if (endLocationColumn == null || endLocationColumn.Value < 1) continue;
                var location = new TextLocation(locationLine.Value, locationColumn.Value);
                var endLocation = new TextLocation(endLocationLine.Value, endLocationColumn.Value);
                if (location >= endLocation) continue;

                ModuleDefMD loadedMod;
                try {
                    loadedMod = MainWindow.Instance.LoadAssembly(assemblyFullPath, moduleFullPath).ModuleDefinition as ModuleDefMD;
                }
                catch {
                    continue;
                }
                if (loadedMod == null)
                    continue;

                var method = loadedMod.ResolveToken(token.Value) as MethodDef;
                if (method == null)
                    continue;

                // Add an extra check to make sure that the file hasn't been re-created. This check
                // isn't perfect but should work most of the time unless the file was re-compiled
                // with the same tools and no methods were added or removed.
                if (method.FullName != methodFullName) continue;

                if (MethodKey.Create(method) == null)
                    continue;
                var bpm = new BreakpointBookmark(method, location, endLocation, new ILRange(from.Value, to.Value), isEnabled.Value);
                BookmarkManager.AddMark(bpm);
            }
        }