[Monodevelop-patches-list] r2496 - in trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn: . Gui/Pads

Lluis Sanchez <lluis@ximian.com> lluis at mono-cvs.ximian.com
Sat Apr 30 10:23:09 EDT 2005


Author: lluis
Date: 2005-04-30 10:23:09 -0400 (Sat, 30 Apr 2005)
New Revision: 2496

Removed:
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggerCommands.cs
Modified:
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/ChangeLog
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggingService.cs
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/LocalsPad.cs
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/StackTracePad.cs
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/ThreadPad.cs
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Makefile.am
   trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/MonoDevelopDebugger.addin.xml
Log:
2005-04-30  Lluis Sanchez Gual  <lluis at novell.com>

	* DebuggingService.cs: Made Debugging property public and changed the
	name to IsDebugging for consistency with IsRunning. Implemented
	ClearAllBreakpoints method. Don't dispatch events through the
	GUI thread here. It is the responsibility of the subscriber to handle
	the event in the GUI thread, if it needs to.
	When returning the file and line of the execution location, if the
	current stack frame doesn't have debug info return the first one in
	the stack with info.
	* Gui/Pads/StackTracePad.cs: Make sure debugger events run in the GUI
	thread. Show the complete stack trace, something like what mdb does.
	* Makefile.am:
	* MonoDevelopDebugger.addin.xml:
	* DebuggerCommands.cs: Moved debug commands to MonoDevelop.Base.
	* ThreadPad.cs:
	* LocalsPad.cs:Make sure debugger events run in the GUI thread.



Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/ChangeLog	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/ChangeLog	2005-04-30 14:23:09 UTC (rev 2496)
@@ -1,3 +1,21 @@
+2005-04-30  Lluis Sanchez Gual  <lluis at novell.com>
+
+	* DebuggingService.cs: Made Debugging property public and changed the
+	name to IsDebugging for consistency with IsRunning. Implemented
+	ClearAllBreakpoints method. Don't dispatch events through the
+	GUI thread here. It is the responsibility of the subscriber to handle
+	the event in the GUI thread, if it needs to.
+	When returning the file and line of the execution location, if the
+	current stack frame doesn't have debug info return the first one in
+	the stack with info.
+	* Gui/Pads/StackTracePad.cs: Make sure debugger events run in the GUI
+	thread. Show the complete stack trace, something like what mdb does.
+	* Makefile.am:
+	* MonoDevelopDebugger.addin.xml:
+	* DebuggerCommands.cs: Moved debug commands to MonoDevelop.Base.
+	* ThreadPad.cs:
+	* LocalsPad.cs:Make sure debugger events run in the GUI thread.
+
 2005-04-28  Lluis Sanchez Gual  <lluis at novell.com>
 
 	* Gui/Pads/ThreadPad.cs: Actually remove threads with no target.

Deleted: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggerCommands.cs
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggerCommands.cs	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggerCommands.cs	2005-04-30 14:23:09 UTC (rev 2496)
@@ -1,62 +0,0 @@
-using System;
-
-using MonoDevelop.Core.AddIns.Codons;
-using MonoDevelop.Services;
-using MonoDevelop.Core.Services;
-using MonoDevelop.Commands;
-
-
-namespace MonoDevelop.Debugger
-{
-	public enum DebugCommands
-	{
-		ToggleRunning,
-		StepOver,
-		StepInto
-	}
-}
-
-namespace MonoDevelop.Debugger.Commands
-{
-	public class ToggleRunning : CommandHandler
-	{
-		protected override void Run ()
-		{
-			if (Runtime.DebuggingService.IsRunning)
-				Runtime.DebuggingService.Pause ();
-			else
-				Runtime.DebuggingService.Resume ();
-		}
-		
-		protected override void Update (CommandInfo info)
-		{
-			info.Enabled = ((DebuggingService)Runtime.DebuggingService).Debugging;
-		}
-	}
-
-	public class StepOver : CommandHandler
-	{
-		protected override void Run ()
-		{
-			Runtime.DebuggingService.StepOver();
-		}
-		
-		protected override void Update (CommandInfo info)
-		{
-			info.Enabled = ((DebuggingService)Runtime.DebuggingService).Debugging;
-		}
-	}
-
-	public class StepInto : CommandHandler
-	{
-		protected override void Run ()
-		{
-			Runtime.DebuggingService.StepInto();
-		}
-		
-		protected override void Update (CommandInfo info)
-		{
-			info.Enabled = ((DebuggingService)Runtime.DebuggingService).Debugging;
-		}
-	}
-}

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggingService.cs
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggingService.cs	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/DebuggingService.cs	2005-04-30 14:23:09 UTC (rev 2496)
@@ -30,7 +30,6 @@
 		Hashtable procs = new Hashtable ();
 		Hashtable breakpoints = new Hashtable ();
 		DebuggerBackend backend;
-		Breakpoint point;
 
 		IProgressMonitor current_monitor;
 
@@ -47,7 +46,7 @@
 
 		void Cleanup ()
 		{
-			if (!Debugging)
+			if (!IsDebugging)
 				return;
 
 			if (StoppedEvent != null)
@@ -90,7 +89,7 @@
 								true, true);
 		}
 
-		public bool Debugging {
+		public bool IsDebugging {
 			get {
 				return backend != null && proc != null && proc.HasTarget;
 			}
@@ -98,7 +97,7 @@
 
 		public bool IsRunning {
 			get {
-				return Debugging && !proc.IsStopped;
+				return IsDebugging && !proc.IsStopped;
 			}
 		}
 
@@ -120,7 +119,7 @@
 			if (breakpoints.Contains (key)) return true;
 			
 			BreakpointHandle brkptnum = null;
-			if (Debugging) {
+			if (IsDebugging) {
 				Breakpoint point = CreateBreakpoint (key);
 				SourceLocation loc = backend.FindLocation(filename, linenum);
 				if (loc == null)
@@ -144,17 +143,21 @@
 			string key = filename + ":" + linenum;
 			BreakpointEntry entry = (BreakpointEntry) breakpoints [key];
 			
-			if (entry != null) {
-				if (Debugging)
-					entry.Handle.Remove (proc);
-	
-				breakpoints.Remove (key);
-			
-				if (BreakpointRemoved != null)
-					BreakpointRemoved (this, new BreakpointEventArgs (entry));
-			}
+			if (entry != null)
+				RemoveBreakpoint (entry);
 		}
 
+		void RemoveBreakpoint (BreakpointEntry entry)
+		{
+			if (IsDebugging)
+				entry.Handle.Remove (proc);
+
+			breakpoints.Remove (entry.FileName + ":" + entry.Line);
+		
+			if (BreakpointRemoved != null)
+				BreakpointRemoved (this, new BreakpointEventArgs (entry));
+		}
+
 		public bool ToggleBreakpoint (string filename, int linenum)
 		{
 			if (!breakpoints.ContainsKey (filename + ":" + linenum))
@@ -192,6 +195,14 @@
 			return (IBreakpoint[]) list.ToArray (typeof(IBreakpoint));
 		}
 		
+		public void ClearAllBreakpoints ()
+		{
+			object[] list = new object [breakpoints.Count];
+			breakpoints.Values.CopyTo (list, 0);
+			foreach (BreakpointEntry b in list)
+				RemoveBreakpoint (b);
+		}
+
 		private void thread_created (ThreadManager manager, Process process)
 		{
 			lock (procs) {
@@ -202,7 +213,7 @@
 				process.DebuggerError += new DebuggerErrorHandler (debugger_error);
 			}
 
-			Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (EmitThreadStateEvent), null);
+			EmitThreadStateEvent (null);
 		}
 
 		private void thread_exited (ThreadManager manager, Process process)
@@ -211,7 +222,7 @@
 				procs.Remove (process.ID);
 			}
 
-			Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (EmitThreadStateEvent), null);
+			EmitThreadStateEvent (null);
 		}
 
 		private void initialized_event (ThreadManager manager, Process process)
@@ -223,7 +234,15 @@
 			proc.DebuggerError += new DebuggerErrorHandler (debugger_error);
 			proc.TargetEvent += new TargetEventHandler (target_event);
 
-			Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (EmitStarted), null);
+			insert_breakpoints ();
+
+			if (StartedEvent != null)
+				StartedEvent (this, EventArgs.Empty);
+
+			// This should not be needed, but it hangs if not dispatched in this way
+			// It's prolly a synchronization issue that does not show when the call
+			// is delayed by the dispatcher
+			Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (ChangeState), null);
 		}
 
 		void target_output (bool is_stderr, string line)
@@ -249,11 +268,11 @@
 			switch (args.Type) {
 			case TargetEventType.TargetExited:
 			case TargetEventType.TargetSignaled:
-				Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (KillApplication), null);
+				KillApplication (null);
 				break;
 			case TargetEventType.TargetStopped:
 			case TargetEventType.TargetRunning:
-				Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (ChangeState), null);
+				ChangeState (null);
 				break;
 			case TargetEventType.TargetHitBreakpoint:
 			default:
@@ -287,20 +306,11 @@
 				ThreadStateEvent (this, EventArgs.Empty);
 		}
 
-		void EmitStarted (object obj)
-		{
-			insert_breakpoints ();
-
-			if (StartedEvent != null)
-				StartedEvent (this, EventArgs.Empty);
-
-			ChangeState (obj);
-		}
-
 		void ChangeState (object obj)
 		{
 			if (ThreadStateEvent != null)
 				ThreadStateEvent (this, EventArgs.Empty);
+
 			if (IsRunning) {
 				if (ResumedEvent != null) {
 					ResumedEvent (this, EventArgs.Empty);
@@ -331,7 +341,7 @@
 
 		public void Pause ()
 		{
-			if (!Debugging)
+			if (!IsDebugging)
 				//throw new Exception ("Debugger not running.");
 				return;
 
@@ -343,7 +353,7 @@
 
 		public void Resume ()
 		{
-			if (!Debugging)
+			if (!IsDebugging)
 				//throw new Exception ("Debugger not running.");
 				return;
 
@@ -355,7 +365,7 @@
 
 		public void Run (IProgressMonitor monitor, string[] argv)
 		{
-			if (Debugging)
+			if (IsDebugging)
 				return;
 
 #if NET_2_0
@@ -384,7 +394,7 @@
 
 		public void StepInto ()
 		{
-			if (!Debugging)
+			if (!IsDebugging)
 				//throw new Exception ("Can't step without running debugger.");
 				return;
 
@@ -397,7 +407,7 @@
 
 		public void StepOver ()
 		{
-			if (!Debugging)
+			if (!IsDebugging)
 				//throw new Exception ("Can't step without running debugger.");
 				return;
 
@@ -408,6 +418,17 @@
 			proc.NextLine (false);
 		}
 
+		public void StepOut ()
+		{
+			if (!IsDebugging)
+				return;
+
+			if (IsRunning)
+				return;
+
+			proc.Finish (false);
+		}
+
 		public string[] Backtrace {
 			get {
 				Backtrace trace = proc.GetBacktrace ();
@@ -419,6 +440,11 @@
 				return result;
 			}
 		}
+		
+		public StackFrame[] GetStack ()
+		{
+			return proc.GetBacktrace ().Frames;
+		}
 
 #if NET_2_0
 		public Process MainThread {
@@ -449,11 +475,12 @@
 				if (IsRunning || proc == null)
 					return String.Empty;
 
-				if (proc.CurrentFrame.SourceAddress == null /* there's no source for this frame */
-				      || proc.CurrentFrame.SourceAddress.MethodSource.IsDynamic)
+				StackFrame frame = GetCurrentSourceFrame ();
+				
+				if (frame == null)
 					return String.Empty;
 
-				return proc.CurrentFrame.SourceAddress.MethodSource.SourceFile.FileName;
+				return frame.SourceAddress.MethodSource.SourceFile.FileName;
 			}
 		}
 
@@ -462,12 +489,26 @@
 				if (IsRunning || proc == null)
 					return -1;
 
-				if (proc.CurrentFrame.SourceAddress == null /* there's no source for this frame */)
+				StackFrame frame = GetCurrentSourceFrame ();
+				if (frame == null)
 					return -1;
 
-				return proc.CurrentFrame.SourceAddress.Row;
+				return frame.SourceAddress.Row;
 			}
 		}
+		
+		StackFrame GetCurrentSourceFrame ()
+		{
+			if (proc.CurrentFrame.SourceAddress != null /* there's no source for this frame */
+				  && !proc.CurrentFrame.SourceAddress.MethodSource.IsDynamic)
+				return proc.CurrentFrame;
+			
+			foreach (StackFrame frame in GetStack ()) {
+				if (frame.SourceAddress != null && !frame.SourceAddress.MethodSource.IsDynamic)
+					return frame;
+			}
+			return null;
+		}
 
 		public string LookupValue (string expr)
 		{
@@ -476,13 +517,7 @@
 
 		private void OnBreakpointHit (Breakpoint pointFromDbg, StackFrame frame)
 		{
-			point = pointFromDbg;
-			Runtime.DispatchService.GuiDispatch (new StatefulMessageHandler (MainThreadNotify), null);
-		}
-
-		void MainThreadNotify (object obj)
-		{
-			string[] toks = point.Name.Split (':');
+			string[] toks = pointFromDbg.Name.Split (':');
 			string filename = toks [0];
 			int linenumber = Int32.Parse (toks [1]);
 
@@ -490,7 +525,8 @@
 				return;
 			
 			BreakpointHitArgs args = new BreakpointHitArgs (filename, linenumber);
-			BreakpointHit (this, args);
+			if (BreakpointHit != null)
+				BreakpointHit (this, args);
 		}
 
 		public event DebuggingService.BreakpointHitHandler BreakpointHit;

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/LocalsPad.cs
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/LocalsPad.cs	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/LocalsPad.cs	2005-04-30 14:23:09 UTC (rev 2496)
@@ -91,8 +91,8 @@
 			Add (tree);
 			ShowAll ();
 
-			Runtime.DebuggingService.PausedEvent += new EventHandler (OnPausedEvent);
-			Runtime.DebuggingService.StoppedEvent += new EventHandler (OnStoppedEvent);
+			Runtime.DebuggingService.PausedEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnPausedEvent));
+			Runtime.DebuggingService.StoppedEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnStoppedEvent));
 		}
 
 		bool InsertArrayChildren (TreeIter parent, ITargetArrayObject array)

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/StackTracePad.cs
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/StackTracePad.cs	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/StackTracePad.cs	2005-04-30 14:23:09 UTC (rev 2496)
@@ -45,24 +45,29 @@
 			Add (tree);
 			ShowAll ();
 
-			Runtime.DebuggingService.PausedEvent += new EventHandler (OnPausedEvent);
-			Runtime.DebuggingService.ResumedEvent += new EventHandler (OnResumedEvent);
-			Runtime.DebuggingService.StoppedEvent += new EventHandler (OnStoppedEvent);
+			Runtime.DebuggingService.PausedEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnPausedEvent));
+			Runtime.DebuggingService.ResumedEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnResumedEvent));
+			Runtime.DebuggingService.StoppedEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnStoppedEvent));
 		}
 
 		public void UpdateDisplay ()
 		{
 			TreeIter it;
 
-			if ((current_frame == null) || (current_frame.Method == null)) {
+			if ((current_frame == null) /*|| (current_frame.Method == null)*/) {
 				if (store.GetIterFirst (out it))
 					do { } while (store.Remove (ref it));
 
 				return;
 			}
 
-			string[] trace = Runtime.DebuggingService.Backtrace;
+//			string[] trace = Runtime.DebuggingService.Backtrace;
 
+			StackFrame[] stack = ((DebuggingService)Runtime.DebuggingService).GetStack ();
+			string[] trace = new string [stack.Length];
+			for (int n=0; n<stack.Length; n++)
+				trace [n] = stack [n].ToString ();
+
 			if (!store.GetIterFirst (out it)) {
 				foreach (string frame in trace) {
 					store.Append (out it);

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/ThreadPad.cs
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/ThreadPad.cs	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Gui/Pads/ThreadPad.cs	2005-04-30 14:23:09 UTC (rev 2496)
@@ -79,7 +79,7 @@
 			Add (tree);
 			ShowAll ();
 
-			((DebuggingService)Runtime.DebuggingService).ThreadStateEvent += new EventHandler (OnThreadEvent);
+			((DebuggingService)Runtime.DebuggingService).ThreadStateEvent += (EventHandler) Runtime.DispatchService.GuiDispatch (new EventHandler (OnThreadEvent));
 		}
 
 		void AddThread (Process thread)

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Makefile.am
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Makefile.am	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/Makefile.am	2005-04-30 14:23:09 UTC (rev 2496)
@@ -12,7 +12,6 @@
 
 
 FILES = \
-DebuggerCommands.cs \
 DebuggingService.cs \
 EvaluationContext.cs \
 Expression.cs \

Modified: trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/MonoDevelopDebugger.addin.xml
===================================================================
--- trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/MonoDevelopDebugger.addin.xml	2005-04-30 14:22:53 UTC (rev 2495)
+++ trunk/MonoDevelop/Core/src/AddIns/DebuggerAddIn/MonoDevelopDebugger.addin.xml	2005-04-30 14:23:09 UTC (rev 2496)
@@ -25,31 +25,5 @@
 		<ContextPad id = "MonoDevelop.Debugger.StackTracePad" />
 		<ContextPad id = "MonoDevelop.Debugger.ThreadPad" />
 	</Extension>
-
-	<Extension path = "/SharpDevelop/Commands">
-		<Command id = "MonoDevelop.Debugger.DebugCommands.ToggleRunning"
-				defaultHandler = "MonoDevelop.Debugger.Commands.ToggleRunning"
-				_label = "Pause/Resume"
-				shortcut = "Control|F8" />
-		
-		<Command id = "MonoDevelop.Debugger.DebugCommands.StepOver"
-				defaultHandler = "MonoDevelop.Debugger.Commands.StepOver"
-				_label = "Step Over"
-				shortcut = "F11" />
-		
-		<Command id = "MonoDevelop.Debugger.DebugCommands.StepInto"
-				defaultHandler = "MonoDevelop.Debugger.Commands.StepInto"
-				_label = "Step Into"
-				shortcut = "Control|F11" />
-	</Extension>
-	
-
-
-	<Extension path="/SharpDevelop/Workbench/MainMenu/Run">
-		<CommandItem id = "MonoDevelop.Debugger.DebugCommands.ToggleRunning" insertafter="MonoDevelop.Commands.ProjectCommands.Stop"/>
-		<SeparatorItem id = "DebugSep1" />
-		<CommandItem id = "MonoDevelop.Debugger.DebugCommands.StepOver" />
-		<CommandItem id = "MonoDevelop.Debugger.DebugCommands.StepInto" />
-	</Extension>
 </AddIn>
 




More information about the Monodevelop-patches-list mailing list