Author: martin
Date: 2006-04-18 12:50:21 -0400 (Tue, 18 Apr 2006)
New Revision: 59600
Added:
trunk/debugger/classes/Debugger.cs
trunk/debugger/classes/Process.cs
trunk/debugger/classes/Thread.cs
Removed:
trunk/debugger/backends/Debugger.cs
trunk/debugger/backends/Process.cs
trunk/debugger/backends/Thread.cs
Modified:
trunk/debugger/ChangeLog
Log:
2006-04-18 Martin Baulig <[EMAIL PROTECTED]>
* backends/Debugger.cs: Moved to ../classes/
* backends/Process.cs: Moved to ../classes/
* backends/Thread.cs: Moved to ../classes/
Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog 2006-04-18 16:38:24 UTC (rev 59599)
+++ trunk/debugger/ChangeLog 2006-04-18 16:50:21 UTC (rev 59600)
@@ -1,5 +1,11 @@
2006-04-18 Martin Baulig <[EMAIL PROTECTED]>
+ * backends/Debugger.cs: Moved to ../classes/
+ * backends/Process.cs: Moved to ../classes/
+ * backends/Thread.cs: Moved to ../classes/
+
+2006-04-18 Martin Baulig <[EMAIL PROTECTED]>
+
* classes/SymbolTableManager.cs: Moved to ../backends/
* classes/ModuleManager.cs: Moved to ../backends/
Deleted: trunk/debugger/backends/Debugger.cs
===================================================================
--- trunk/debugger/backends/Debugger.cs 2006-04-18 16:38:24 UTC (rev 59599)
+++ trunk/debugger/backends/Debugger.cs 2006-04-18 16:50:21 UTC (rev 59600)
@@ -1,227 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Configuration;
-using System.Globalization;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Specialized;
-using System.Runtime.InteropServices;
-using System.Runtime.Remoting;
-
-using Mono.Debugger.Backends;
-using Mono.Debugger.Languages;
-using Mono.Debugger.Languages.Mono;
-
-namespace Mono.Debugger
-{
- public delegate void DebuggerEventHandler (Debugger debugger);
- public delegate void ThreadEventHandler (Debugger debugger, Thread
thread);
- public delegate void ProcessEventHandler (Debugger debugger, Process
process);
-
- public class Debugger : MarshalByRefObject, IDisposable
- {
- ThreadManager thread_manager;
- Hashtable process_hash;
- Process main_process;
-
- public Debugger ()
- {
- thread_manager = new ThreadManager (this);
- process_hash = Hashtable.Synchronized (new Hashtable
());
- }
-
- internal ThreadManager ThreadManager {
- get {
- return thread_manager;
- }
- }
-
- public event TargetOutputHandler TargetOutputEvent;
- public event ThreadEventHandler ThreadCreatedEvent;
- public event ThreadEventHandler ThreadExitedEvent;
- public event ProcessEventHandler ProcessCreatedEvent;
- public event ProcessEventHandler ProcessExitedEvent;
- public event ProcessEventHandler ProcessExecdEvent;
- public event DebuggerEventHandler TargetExitedEvent;
- public event TargetEventHandler TargetEvent;
- public event SymbolTableChangedHandler SymbolTableChanged;
-
- internal void OnProcessCreatedEvent (Process process)
- {
- process_hash.Add (process, process);
- if (ProcessCreatedEvent != null)
- ProcessCreatedEvent (this, process);
- }
-
- protected void OnTargetExitedEvent ()
- {
- if (TargetExitedEvent != null)
- TargetExitedEvent (this);
- }
-
- internal void OnProcessExitedEvent (Process process)
- {
- process_hash.Remove (process);
- if (ProcessExitedEvent != null)
- ProcessExitedEvent (this, process);
-
- if (process == main_process) {
- Kill ();
- }
- }
-
- internal void OnProcessExecdEvent (Process process)
- {
- if (ProcessExecdEvent != null)
- ProcessExecdEvent (this, process);
- }
-
- public void Kill ()
- {
- main_process = null;
-
- Process[] procs;
- lock (process_hash.SyncRoot) {
- procs = new Process [process_hash.Count];
- process_hash.Values.CopyTo (procs, 0);
- }
-
- foreach (Process proc in procs) {
- proc.Kill ();
- }
-
- OnTargetExitedEvent ();
- }
-
- public Process Run (DebuggerOptions options)
- {
- check_disposed ();
-
- if (main_process != null)
- throw new TargetException
(TargetError.AlreadyHaveTarget);
-
- ProcessStart start = new ProcessStart (options);
- main_process = thread_manager.StartApplication (start);
- process_hash.Add (main_process, main_process);
- return main_process;
- }
-
- public Process Attach (DebuggerOptions options, int pid)
- {
- check_disposed ();
-
- if (main_process != null)
- throw new TargetException
(TargetError.AlreadyHaveTarget);
-
- ProcessStart start = new ProcessStart (options, pid);
- main_process = thread_manager.StartApplication (start);
- process_hash.Add (main_process, main_process);
- return main_process;
- }
-
- public Process OpenCoreFile (DebuggerOptions options, string
core_file,
- out Thread[] threads)
- {
- check_disposed ();
-
- if (main_process != null)
- throw new TargetException
(TargetError.AlreadyHaveTarget);
-
- ProcessStart start = new ProcessStart (options,
core_file);
- main_process = thread_manager.OpenCoreFile (start, out
threads);
- process_hash.Add (main_process, main_process);
- return main_process;
- }
-
- internal void OnThreadCreatedEvent (Thread new_process)
- {
- if (ThreadCreatedEvent != null)
- ThreadCreatedEvent (this, new_process);
- }
-
- internal void OnThreadExitedEvent (Thread thread)
- {
- if (ThreadExitedEvent != null)
- ThreadExitedEvent (this, thread);
- }
-
- internal void OnInferiorOutput (bool is_stderr, string line)
- {
- if (TargetOutputEvent != null)
- TargetOutputEvent (is_stderr, line);
- }
-
- internal void SendTargetEvent (SingleSteppingEngine sse,
TargetEventArgs args)
- {
- try {
- if (TargetEvent != null)
- TargetEvent (sse.Thread, args);
- } catch (Exception ex) {
- Error ("{0} caught exception while sending
{1}:\n{2}",
- sse, args, ex);
- }
- }
-
- public Process[] Processes {
- get {
- lock (process_hash.SyncRoot) {
- Process[] procs = new Process
[process_hash.Count];
- process_hash.Values.CopyTo (procs, 0);
- return procs;
- }
- }
- }
-
- public void Error (string message, params object[] args)
- {
- Console.WriteLine ("ERROR: " + String.Format (message,
args));
- }
-
- //
- // IDisposable
- //
-
- private bool disposed = false;
-
- private void check_disposed ()
- {
- if (disposed)
- throw new ObjectDisposedException ("Debugger");
- }
-
- protected virtual void Dispose (bool disposing)
- {
- // Check to see if Dispose has already been called.
- lock (this) {
- if (disposed)
- return;
-
- disposed = true;
- }
-
- // If this is a call to Dispose, dispose all managed
resources.
- if (disposing) {
- if (thread_manager != null) {
- thread_manager.Dispose ();
- thread_manager = null;
- }
-
- ObjectCache.Shutdown ();
- }
- }
-
- public void Dispose ()
- {
- Dispose (true);
- // Take yourself off the Finalization queue
- GC.SuppressFinalize (this);
- }
-
- ~Debugger ()
- {
- Dispose (false);
- }
- }
-}
Deleted: trunk/debugger/backends/Process.cs
===================================================================
--- trunk/debugger/backends/Process.cs 2006-04-18 16:38:24 UTC (rev 59599)
+++ trunk/debugger/backends/Process.cs 2006-04-18 16:50:21 UTC (rev 59600)
@@ -1,759 +0,0 @@
-using System;
-using System.IO;
-using System.Collections;
-using ST = System.Threading;
-using System.Runtime.Serialization;
-using System.Runtime.Serialization.Formatters.Binary;
-
-using Mono.Debugger.Backends;
-using Mono.Debugger.Languages;
-using Mono.Debugger.Languages.Mono;
-
-namespace Mono.Debugger
-{
- public class Process : MarshalByRefObject
- {
- ThreadManager manager;
- BfdContainer bfd_container;
- SymbolTableManager symtab_manager;
- ModuleManager module_manager;
- SourceFileFactory source_factory;
- MonoLanguageBackend mono_language;
- MonoThreadManager mono_manager;
- BreakpointManager breakpoint_manager;
- ProcessStart start;
- protected Thread main_thread;
- SingleSteppingEngine main_engine;
- ArrayList languages;
- Hashtable thread_hash;
- Hashtable events;
- ArrayList attach_results;
-
- bool is_forked;
- bool initialized;
- ST.ManualResetEvent initialized_event;
- DebuggerMutex thread_lock_mutex;
- bool has_thread_lock;
-
- Hashtable thread_groups;
- ThreadGroup main_thread_group;
-
- int id = ++next_id;
- static int next_id = 0;
-
- private Process (ThreadManager manager)
- {
- this.manager = manager;
-
- thread_lock_mutex = new DebuggerMutex
("thread_lock_mutex");
-
- thread_groups = Hashtable.Synchronized (new Hashtable
());
- main_thread_group = CreateThreadGroup ("main");
-
- events = Hashtable.Synchronized (new Hashtable ());
- thread_hash = Hashtable.Synchronized (new Hashtable ());
- initialized_event = new ST.ManualResetEvent (false);
- }
-
- internal Process (ThreadManager manager, ProcessStart start)
- : this (manager)
- {
- this.start = start;
-
- breakpoint_manager = new BreakpointManager ();
- module_manager = new ModuleManager ();
- source_factory = new SourceFileFactory ();
-
- module_manager.ModulesChanged += modules_changed;
- module_manager.BreakpointsChanged +=
breakpoints_changed;
-
- symtab_manager = new SymbolTableManager ();
- symtab_manager.ModulesChangedEvent += modules_reloaded;
-
- languages = new ArrayList ();
- bfd_container = new BfdContainer (this);
- }
-
- private Process (Process parent, int pid)
- : this (parent.manager)
- {
- this.start = new ProcessStart (parent.ProcessStart,
pid);
-
- this.is_forked = true;
- this.initialized = true;
-
- breakpoint_manager = new BreakpointManager
(parent.breakpoint_manager);
- module_manager = parent.module_manager;
- source_factory = parent.source_factory;
-
- module_manager.ModulesChanged += modules_changed;
- module_manager.BreakpointsChanged +=
breakpoints_changed;
-
- symtab_manager = parent.symtab_manager;
- symtab_manager.ModulesChangedEvent += modules_reloaded;
-
- languages = parent.languages;
- bfd_container = parent.bfd_container;
- }
-
- public int ID {
- get { return id; }
- }
-
- internal ThreadManager ThreadManager {
- get { return manager; }
- }
-
- internal BfdContainer BfdContainer {
- get {
- return bfd_container;
- }
- }
-
- internal BreakpointManager BreakpointManager {
- get { return breakpoint_manager; }
- }
-
- internal ModuleManager ModuleManager {
- get {
- return module_manager;
- }
- }
-
- internal SymbolTableManager SymbolTableManager {
- get {
- return symtab_manager;
- }
- }
-
- public SourceFileFactory SourceFileFactory {
- get {
- return source_factory;
- }
- }
-
- public Language NativeLanguage {
- get {
- return bfd_container.NativeLanguage;
- }
- }
-
- public Thread MainThread {
- get { return main_thread; }
- }
-
- public Debugger Debugger {
- get { return manager.Debugger; }
- }
-
- internal ProcessStart ProcessStart {
- get { return start; }
- }
-
- internal void AddLanguage (ILanguageBackend language)
- {
- languages.Add (language);
- }
-
- internal ArrayList Languages {
- get { return languages; }
- }
-
- internal MonoThreadManager MonoManager {
- get { return mono_manager; }
- }
-
- public bool IsManaged {
- get { return mono_manager != null; }
- }
-
- public string TargetApplication {
- get { return start.TargetApplication; }
- }
-
- public string[] CommandLineArguments {
- get { return start.CommandLineArguments; }
- }
-
- public event ModulesChangedHandler ModulesChangedEvent;
- public event BreakpointsChangedHandler BreakpointsChangedEvent;
-
- void modules_changed ()
- {
- check_disposed ();
- symtab_manager.SetModules (module_manager.Modules);
- }
-
- Module[] current_modules = null;
-
- void breakpoints_changed ()
- {
- if (BreakpointsChangedEvent != null)
- BreakpointsChangedEvent ();
- }
-
- void modules_reloaded (object sender, Module[] modules)
- {
- current_modules = modules;
-
- if (ModulesChangedEvent != null)
- ModulesChangedEvent ();
- }
-
- internal void ReachedMain ()
- {
- module_manager.UnLock ();
- symtab_manager.Wait ();
- }
-
- internal void ThreadCreated (Inferior inferior, int pid, bool
do_attach)
- {
- Inferior new_inferior = inferior.CreateThread ();
-
- SingleSteppingEngine new_thread = new
SingleSteppingEngine (
- manager, this, new_inferior, pid, do_attach,
false);
-
- Report.Debug (DebugFlags.Threads, "Thread created: {0}
{1}", pid, new_thread);
-
- manager.AddEngine (new_thread);
-
- if ((mono_manager != null) && !do_attach)
- mono_manager.ThreadCreated (new_thread,
new_inferior);
-
- OnThreadCreatedEvent (new_thread.Thread);
-
- if (!do_attach)
- new_thread.Start (TargetAddress.Null);
- }
-
- internal void ChildForked (Inferior inferior, int pid)
- {
- Process new_process = new Process (this, pid);
-
- Inferior new_inferior = Inferior.CreateInferior (
- manager, new_process, new_process.ProcessStart);
-
- SingleSteppingEngine new_thread = new
SingleSteppingEngine (
- manager, new_process, new_inferior, pid, false,
false);
-
- new_inferior.InitializeAfterFork ();
-
- Report.Debug (DebugFlags.Threads, "Child forked: {0}
{1}", pid, new_thread);
-
- new_process.main_thread = new_thread.Thread;
- new_process.main_engine = new_thread;
-
- manager.AddEngine (new_thread);
-
- manager.Debugger.OnProcessCreatedEvent (new_process);
- new_process.OnThreadCreatedEvent (new_thread.Thread);
-
- new_thread.Start (TargetAddress.Null);
- }
-
- internal void ChildExecd (Inferior inferior)
- {
- if (!is_forked) {
- if (bfd_container != null)
- bfd_container.Dispose ();
-
- if (languages != null)
- foreach (ILanguageBackend lang in
languages)
- lang.Dispose();
-
- if (symtab_manager != null)
- symtab_manager.Dispose ();
- }
-
- module_manager.ModulesChanged -= modules_changed;
- module_manager.BreakpointsChanged -=
breakpoints_changed;
-
- if (breakpoint_manager != null)
- breakpoint_manager.Dispose ();
-
- breakpoint_manager = new BreakpointManager ();
- module_manager = new ModuleManager ();
- source_factory = new SourceFileFactory ();
-
- module_manager.ModulesChanged += modules_changed;
- module_manager.BreakpointsChanged +=
breakpoints_changed;
-
- symtab_manager = new SymbolTableManager ();
- symtab_manager.ModulesChangedEvent += modules_reloaded;
-
- languages = new ArrayList ();
- bfd_container = new BfdContainer (this);
-
- Inferior new_inferior = Inferior.CreateInferior
(manager, this, start);
-
- SingleSteppingEngine new_thread = new
SingleSteppingEngine (
- manager, this, new_inferior, inferior.PID,
false, false);
-
- Thread[] threads;
- lock (thread_hash.SyncRoot) {
- threads = new Thread [thread_hash.Count];
- thread_hash.Values.CopyTo (threads, 0);
- }
-
- for (int i = 0; i < threads.Length; i++) {
- if (threads [i].TID != inferior.TID)
- threads [i].Kill ();
- }
-
- thread_hash [inferior.PID] = new_thread.Thread;
-
- manager.ProcessExecd (new_thread);
- manager.Debugger.OnProcessExecdEvent (this);
- manager.Debugger.OnThreadCreatedEvent
(new_thread.Thread);
- initialized = is_forked = false;
-
- inferior.Dispose ();
-
- Initialize (new_thread, new_inferior, true);
- }
-
- protected void OnThreadCreatedEvent (Thread thread)
- {
- thread_hash.Add (thread.PID, thread);
- manager.Debugger.OnThreadCreatedEvent (thread);
- }
-
- internal void OnThreadExitedEvent (Thread thread)
- {
- manager.Debugger.OnThreadExitedEvent (thread);
- thread.Kill ();
- }
-
- internal void WaitForApplication ()
- {
- initialized_event.WaitOne ();
- }
-
- internal bool Initialize (SingleSteppingEngine engine, Inferior
inferior,
- bool is_exec)
- {
- if (initialized)
- return true;
-
- initialized = true;
- if (!is_forked || is_exec)
- mono_manager = MonoThreadManager.Initialize (
- manager, inferior, (start.PID != 0) &&
!is_exec,
- !is_exec);
-
- this.main_thread = engine.Thread;
- this.main_engine = engine;
-
- if (thread_hash.Contains (engine.PID))
- thread_hash [engine.PID] = engine.Thread;
- else
- thread_hash.Add (engine.PID, engine.Thread);
- main_thread_group.AddThread (engine.Thread.ID);
-
- if ((start.PID != 0) && !is_exec) {
- int[] threads = inferior.GetThreads ();
- foreach (int thread in threads) {
- if (thread_hash.Contains (thread))
- continue;
- ThreadCreated (inferior, thread, true);
- }
-
- if (mono_manager == null)
- goto done;
-
- attach_results = new ArrayList ();
- foreach (Thread thread in thread_hash.Values)
- attach_results.Add
(mono_manager.GetThreadID (thread));
- }
-
- if (mono_manager != null) {
- inferior.Continue ();
- goto done;
- }
-
- if (is_exec)
- engine.Start (TargetAddress.Null);
- else
- engine.Start (inferior.MainMethodAddress);
-
- done:
- initialized_event.Set ();
- return false;
- }
-
- public void Kill ()
- {
- Thread[] threads;
- lock (thread_hash.SyncRoot) {
- threads = new Thread [thread_hash.Count];
- thread_hash.Values.CopyTo (threads, 0);
- }
-
- for (int i = 0; i < threads.Length; i++)
- threads [i].Kill ();
-
- Dispose ();
- }
-
- internal void KillThread (SingleSteppingEngine engine)
- {
- if (engine == main_engine) {
- manager.Debugger.OnProcessExitedEvent
(main_engine.Process);
- Kill ();
- } else {
- thread_hash.Remove (engine.PID);
- OnThreadExitedEvent (engine.Thread);
- engine.Thread.Kill ();
- }
-
- if (mono_manager != null)
- mono_manager.ThreadExited (engine);
- }
-
- // XXX This desperately needs to be renamed.
- internal ILanguageBackend CreateDebuggerHandler
(MonoDebuggerInfo info)
- {
- mono_language = new MonoLanguageBackend (this, info);
- languages.Add (mono_language);
-
- return mono_language;
- }
-
- internal void UpdateSymbolTable (TargetMemoryAccess target)
- {
- if (mono_language != null)
- mono_language.Update (target);
- }
-
- public void LoadLibrary (Thread thread, string filename)
- {
- if (mono_language == null)
- throw new SymbolTableException (
- "Cannot load .NET assembly {0}
while " +
- "debugging an unmanaged
application",
- filename);
-
- if (!mono_language.TryFindImage (thread, filename))
- bfd_container.AddFile (thread.TargetInfo,
filename,
- TargetAddress.Null,
true, false);
- }
-
- internal MonoLanguageBackend MonoLanguage {
- get {
- if (mono_language == null)
- throw new InvalidOperationException ();
-
- return mono_language;
- }
- }
-
- internal bool IsManagedApplication {
- get { return mono_language != null; }
- }
-
- public Module[] Modules {
- get {
- if (current_modules != null)
- return current_modules;
-
- return new Module [0];
- }
- }
-
- public SourceLocation FindLocation (string file, int line)
- {
- foreach (Module module in Modules) {
- SourceLocation location = module.FindLocation
(file, line);
-
- if (location != null)
- return location;
- }
-
- return null;
- }
-
- public SourceLocation FindMethod (string name)
- {
- foreach (Module module in Modules) {
- SourceMethod method = module.FindMethod (name);
-
- if (method != null)
- return new SourceLocation (method);
- }
-
- return null;
- }
-
- public Thread[] Threads {
- get {
- lock (thread_hash.SyncRoot) {
- Thread[] threads = new Thread
[thread_hash.Count];
- thread_hash.Values.CopyTo (threads, 0);
- return threads;
- }
- }
- }
-
- // <summary>
- // Stop all currently running threads without sending any
notifications.
- // The threads are automatically resumed to their previos
state when
- // ReleaseGlobalThreadLock() is called.
- // </summary>
- internal void AcquireGlobalThreadLock (SingleSteppingEngine
caller)
- {
- thread_lock_mutex.Lock ();
- Report.Debug (DebugFlags.Threads,
- "Acquiring global thread lock: {0}",
caller);
- has_thread_lock = true;
- foreach (Thread thread in thread_hash.Values) {
- if (thread.Engine == caller)
- continue;
- thread.Engine.AcquireThreadLock ();
- }
- Report.Debug (DebugFlags.Threads,
- "Done acquiring global thread lock: {0}",
- caller);
- }
-
- internal void ReleaseGlobalThreadLock (SingleSteppingEngine
caller)
- {
- Report.Debug (DebugFlags.Threads,
- "Releasing global thread lock: {0}",
caller);
-
- foreach (Thread thread in thread_hash.Values) {
- if (thread.Engine == caller)
- continue;
- thread.Engine.ReleaseThreadLock ();
- }
- has_thread_lock = false;
- thread_lock_mutex.Unlock ();
- Report.Debug (DebugFlags.Threads,
- "Released global thread lock: {0}",
caller);
- }
-
- //
- // Thread Groups
- //
-
- public ThreadGroup CreateThreadGroup (string name)
- {
- lock (thread_groups) {
- ThreadGroup group = (ThreadGroup) thread_groups
[name];
- if (group != null)
- return group;
-
- group = ThreadGroup.CreateThreadGroup (name);
- thread_groups.Add (name, group);
- return group;
- }
- }
-
- public void DeleteThreadGroup (string name)
- {
- thread_groups.Remove (name);
- }
-
- public bool ThreadGroupExists (string name)
- {
- return thread_groups.Contains (name);
- }
-
- public ThreadGroup[] ThreadGroups {
- get {
- lock (thread_groups) {
- ThreadGroup[] retval = new ThreadGroup
[thread_groups.Values.Count];
- thread_groups.Values.CopyTo (retval, 0);
- return retval;
- }
- }
- }
-
- public ThreadGroup ThreadGroupByName (string name)
- {
- return (ThreadGroup) thread_groups [name];
- }
-
- public ThreadGroup MainThreadGroup {
- get { return main_thread_group; }
- }
-
- //
- // Events
- //
-
- public Event[] Events {
- get {
- Event[] handles = new Event [events.Count];
- events.Values.CopyTo (handles, 0);
- return handles;
- }
- }
-
- public Event GetEvent (int index)
- {
- return (Event) events [index];
- }
-
- internal void AddEvent (Event handle)
- {
- events.Add (handle.Index, handle);
- }
-
- public void DeleteEvent (Thread thread, Event handle)
- {
- handle.Remove (thread);
- events.Remove (handle.Index);
- }
-
- public Event InsertBreakpoint (Thread target, ThreadGroup
group, int domain,
- SourceLocation location)
- {
- Event handle = new Breakpoint (group, location);
- events.Add (handle.Index, handle);
- return handle;
- }
-
- public Event InsertBreakpoint (Thread target, ThreadGroup group,
- TargetFunctionType func)
- {
- Event handle = new Breakpoint (group, new
SourceLocation (func));
- events.Add (handle.Index, handle);
- return handle;
- }
-
- public Event InsertExceptionCatchPoint (Thread target,
ThreadGroup group,
- TargetType exception)
- {
- Event handle = new ExceptionCatchPoint (group,
exception);
- events.Add (handle.Index, handle);
- return handle;
- }
-
- //
- // Session management.
- //
-
- public void SaveSession (Stream stream, StreamingContextStates
states )
- {
- StreamingContext context = new StreamingContext (
- states, this);
-
- ISurrogateSelector ss =
DebuggerSession.CreateSurrogateSelector (context);
- BinaryFormatter formatter = new BinaryFormatter (ss,
context);
-
- SessionInfo info = new SessionInfo (this);
- formatter.Serialize (stream, info);
- }
-
- public void LoadSession (Stream stream, StreamingContextStates
states)
- {
- StreamingContext context = new StreamingContext (
- StreamingContextStates.Persistence, this);
-
- ISurrogateSelector ss =
DebuggerSession.CreateSurrogateSelector (context);
- BinaryFormatter formatter = new BinaryFormatter (ss,
context);
-
- SessionInfo info = (SessionInfo) formatter.Deserialize
(stream);
-
- foreach (Event handle in info.Events) {
- events.Add (handle.Index, handle);
- handle.Enable (main_thread);
- }
- }
-
- [Serializable]
- private class SessionInfo : ISerializable,
IDeserializationCallback
- {
- public readonly Module[] Modules;
- public readonly Event[] Events;
-
- public SessionInfo (Process process)
- {
- this.Modules = process.Modules;
- this.Events = process.Events;
- }
-
- public void GetObjectData (SerializationInfo info,
StreamingContext context)
- {
- info.AddValue ("modules", Modules);
- info.AddValue ("events", Events);
- }
-
- void IDeserializationCallback.OnDeserialization (object
obj)
- { }
-
- private SessionInfo (SerializationInfo info,
StreamingContext context)
- {
- Modules = (Module []) info.GetValue (
- "modules", typeof (Module []));
- Events = (Event []) info.GetValue (
- "events", typeof (Event []));
- }
- }
-
- //
- // IDisposable
- //
-
- private bool disposed = false;
-
- private void check_disposed ()
- {
- if (disposed)
- throw new ObjectDisposedException ("Process");
- }
-
- protected virtual void DoDispose ()
- {
- if (!is_forked) {
- if (bfd_container != null) {
- bfd_container.Dispose ();
- bfd_container = null;
- }
-
- if (languages != null) {
- foreach (ILanguageBackend lang in
languages)
- lang.Dispose();
- languages = null;
- }
-
- if (symtab_manager != null) {
- symtab_manager.Dispose ();
- symtab_manager = null;
- }
- }
-
- if (breakpoint_manager != null)
- breakpoint_manager.Dispose ();
-
- manager.RemoveProcess (this);
- }
-
- private void Dispose (bool disposing)
- {
- // Check to see if Dispose has already been called.
- lock (this) {
- if (disposed)
- return;
-
- disposed = true;
- }
-
- // If this is a call to Dispose, dispose all managed
resources.
- if (disposing)
- DoDispose ();
- }
-
- public void Dispose ()
- {
- Dispose (true);
- // Take yourself off the Finalization queue
- GC.SuppressFinalize (this);
- }
-
- ~Process ()
- {
- Dispose (false);
- }
- }
-}
Deleted: trunk/debugger/backends/Thread.cs
===================================================================
--- trunk/debugger/backends/Thread.cs 2006-04-18 16:38:24 UTC (rev 59599)
+++ trunk/debugger/backends/Thread.cs 2006-04-18 16:50:21 UTC (rev 59600)
@@ -1,837 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-using ST = System.Threading;
-using System.Configuration;
-using System.Globalization;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Specialized;
-using System.Runtime.InteropServices;
-using System.Runtime.Remoting.Messaging;
-
-using Mono.Debugger.Backends;
-using Mono.Debugger.Languages;
-
-namespace Mono.Debugger
-{
- using SSE = SingleSteppingEngine;
-
- [Serializable]
- internal delegate object TargetAccessDelegate (Thread target, object
user_data);
-
- public class Thread : TargetAccess
- {
- internal Thread (SingleSteppingEngine engine)
- {
- this.engine = engine;
- this.target = engine;
- this.id = engine.ThreadManager.NextThreadID;
-
- this.manager = engine.ThreadManager;
- this.process = engine.Process;
-
- this.symtab_manager = process.SymbolTableManager;
-
- this.pid = engine.PID;
- this.tid = engine.TID;
-
- tgroup = process.CreateThreadGroup ("@" + ID);
- tgroup.AddThread (ID);
-
- operation_completed_event = new ST.ManualResetEvent
(false);
-
- this.target_info = engine.TargetInfo;
- }
-
- internal Thread (TargetAccess target, int pid)
- {
- this.target = target;
- this.id = target.ThreadManager.NextThreadID;
- this.pid = pid;
-
- this.manager = target.ThreadManager;
- this.process = target.Process;
-
- this.symtab_manager = process.SymbolTableManager;
-
- tgroup = process.CreateThreadGroup ("@" + ID);
- tgroup.AddThread (ID);
-
- operation_completed_event = new ST.ManualResetEvent
(false);
-
- this.target_info = target.TargetInfo;
- }
-
- bool is_daemon;
- int id, pid;
- long tid;
- ThreadGroup tgroup;
- TargetAccess target;
- SingleSteppingEngine engine;
- Process process;
- ThreadManager manager;
- SymbolTableManager symtab_manager;
- ST.ManualResetEvent operation_completed_event;
- TargetInfo target_info;
-
- public ST.WaitHandle WaitHandle {
- get { return operation_completed_event; }
- }
-
- protected internal Language NativeLanguage {
- get {
- check_target ();
- return process.BfdContainer.NativeLanguage;
- }
- }
-
- public override string ToString ()
- {
- return Name;
- }
-
- // <summary>
- // The single-stepping engine's target state. This will be
- // TargetState.RUNNING while the engine is stepping.
- // </summary>
- public override TargetState State {
- get {
- if (target == null)
- return TargetState.NO_TARGET;
- else
- return target.State;
- }
- }
-
- public int ID {
- get {
- return id;
- }
- }
-
- public string Name {
- get {
- if (IsDaemon)
- return String.Format ("Daemon thread
@{0}", id);
- else
- return String.Format ("Thread @{0}",
id);
- }
- }
-
- public int PID {
- get {
- return pid;
- }
- }
-
- public long TID {
- get {
- return tid;
- }
- }
-
- internal override Architecture Architecture {
- get {
- check_target ();
- return target.Architecture;
- }
- }
-
- public override Process Process {
- get {
- check_target ();
- return process;
- }
- }
-
- internal override ThreadManager ThreadManager {
- get {
- check_target ();
- return manager;
- }
- }
-
- internal SingleSteppingEngine Engine {
- get {
- check_engine ();
- return engine;
- }
- }
-
- public bool IsDaemon {
- get {
- return is_daemon;
- }
- }
-
- public ThreadGroup ThreadGroup {
- get { return tgroup; }
- }
-
- internal void SetDaemon ()
- {
- is_daemon = true;
- }
-
- internal void SetTID (long tid)
- {
- this.tid = tid;
- }
-
- void check_engine ()
- {
- if (engine == null)
- throw new TargetException
(TargetError.NoTarget);
- }
-
- void check_target ()
- {
- if (target == null)
- throw new TargetException
(TargetError.NoTarget);
- }
-
- // <summary>
- // The current stack frame. May only be used when the engine
is stopped
- // (State == TargetState.STOPPED). The single stepping engine
- // automatically computes the current frame and current
method each time
- // a stepping operation is completed. This ensures that we
do not
- // unnecessarily compute this several times if more than one
client
- // accesses this property.
- // </summary>
- public override StackFrame CurrentFrame {
- get {
- check_target ();
- return target.CurrentFrame;
- }
- }
-
- public override TargetAddress CurrentFrameAddress {
- get {
- check_target ();
- return target.CurrentFrameAddress;
- }
- }
-
- // <summary>
- // The current stack frame. May only be used when the engine
is stopped
- // (State == TargetState.STOPPED). The backtrace is
generated on
- // demand, when this function is called. However, the single
stepping
- // engine will compute this only once each time a stepping
operation is
- // completed. This means that if you call this function
several times
- // without doing any stepping operations in the meantime,
you'll always
- // get the same backtrace.
- // </summary>
- public override Backtrace GetBacktrace (int max_frames)
- {
- check_target ();
- return target.GetBacktrace (max_frames);
- }
-
- public Backtrace GetBacktrace ()
- {
- check_target ();
- Backtrace bt = target.CurrentBacktrace;
- if (bt != null)
- return bt;
-
- return GetBacktrace (-1);
- }
-
- public override Backtrace CurrentBacktrace {
- get {
- check_target ();
- return target.CurrentBacktrace;
- }
- }
-
- public override Registers GetRegisters ()
- {
- check_target ();
- return target.GetRegisters ();
- }
-
- public override void SetRegisters (Registers registers)
- {
- check_engine ();
- engine.SetRegisters (registers);
- }
-
- public TargetMemoryArea[] GetMemoryMaps ()
- {
- check_engine ();
- return engine.GetMemoryMaps ();
- }
-
- public Method Lookup (TargetAddress address)
- {
- check_engine ();
- return symtab_manager.Lookup (address);
- }
-
- public Symbol SimpleLookup (TargetAddress address, bool
exact_match)
- {
- check_engine ();
- return symtab_manager.SimpleLookup (address,
exact_match);
- }
-
- // <summary>
- // The current method May only be used when the engine is
stopped
- // (State == TargetState.STOPPED). The single stepping engine
- // automatically computes the current frame and current
method each time
- // a stepping operation is completed. This ensures that we
do not
- // unnecessarily compute this several times if more than one
client
- // accesses this property.
- // </summary>
- public Method CurrentMethod {
- get {
- check_engine ();
- return engine.CurrentMethod;
- }
- }
-
- // <summary>
- // Step one machine instruction, but don't step into
trampolines.
- // </summary>
- public void StepInstruction ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.StepInstruction (new StepCommandResult
(this));
- }
- }
-
- // <summary>
- // Step one machine instruction, always step into method
calls.
- // </summary>
- public void StepNativeInstruction ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.StepNativeInstruction (new
StepCommandResult (this));
- }
- }
-
- // <summary>
- // Step one machine instruction, but step over method calls.
- // </summary>
- public void NextInstruction ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.NextInstruction (new StepCommandResult
(this));
- }
- }
-
- // <summary>
- // Step one source line.
- // </summary>
- public void StepLine ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.StepLine (new StepCommandResult (this));
- }
- }
-
- // <summary>
- // Step one source line, but step over method calls.
- // </summary>
- public void NextLine ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.NextLine (new StepCommandResult (this));
- }
- }
-
- // <summary>
- // Continue until leaving the current method.
- // </summary>
- public void Finish ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.Finish (new StepCommandResult (this));
- }
- }
-
- // <summary>
- // Continue until leaving the current method.
- // </summary>
- public void FinishNative ()
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.FinishNative (new StepCommandResult
(this));
- }
- }
-
- public void Continue ()
- {
- Continue (TargetAddress.Null, false);
- }
-
- public void Continue (TargetAddress until)
- {
- Continue (until, false);
- }
-
- public void Continue (bool in_background)
- {
- Continue (TargetAddress.Null, in_background);
- }
-
- public void Continue (TargetAddress until, bool in_background)
- {
- lock (this) {
- check_engine ();
- operation_completed_event.Reset ();
- engine.Continue (until, in_background, new
StepCommandResult (this));
- }
- }
-
- internal void Kill ()
- {
- operation_completed_event.Set ();
- if (engine != null)
- engine.Kill ();
- Dispose ();
- }
-
- public void Stop ()
- {
- check_engine ();
- engine.Stop ();
- }
-
- public void Wait ()
- {
- Report.Debug (DebugFlags.Wait, "{0} waiting", this);
- operation_completed_event.WaitOne ();
- Report.Debug (DebugFlags.Wait, "{0} done waiting",
this);
- }
-
- // <summary>
- // Insert a breakpoint at address @address.
- //
- // Returns a number which may be passed to RemoveBreakpoint()
to remove
- // the breakpoint.
- // </summary>
- public override int InsertBreakpoint (Breakpoint breakpoint,
TargetAddress address)
- {
- check_engine ();
- return engine.InsertBreakpoint (breakpoint, address);
- }
-
- // <summary>
- // Remove breakpoint @index. @index is the breakpoint number
which has
- // been returned by InsertBreakpoint().
- // </summary>
- public void RemoveBreakpoint (int index)
- {
- check_disposed ();
- if (engine != null)
- engine.RemoveBreakpoint (index);
- }
-
- // <summary>
- // Insert a breakpoint at function @func.
- //
- // Returns a number which may be passed to RemoveBreakpoint()
to remove
- // the breakpoint.
- // </summary>
- public int InsertBreakpoint (Breakpoint breakpoint,
TargetFunctionType func)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.InsertBreakpoint (breakpoint,
func);
- }
-
- result.Wait ();
-
- return (int) result.Result;
- }
-
- // <summary>
- // Add an event handler.
- //
- // Returns a number which may be passed to
RemoveEventHandler() to remove
- // the event handler.
- // </summary>
- public int AddEventHandler (EventType type, Event handle)
- {
- check_engine ();
- return engine.AddEventHandler (type, handle);
- }
-
- // <summary>
- // Remove event handler @index. @index is the event handler
number which has
- // been returned by AddEventHandler().
- // </summary>
- public void RemoveEventHandler (int index)
- {
- check_disposed ();
- if (engine != null)
- engine.RemoveEventHandler (index);
- }
-
- public string PrintObject (Style style, TargetObject obj,
DisplayFormat format)
- {
- check_engine ();
- return engine.PrintObject (style, obj, format);
- }
-
- public string PrintType (Style style, TargetType type)
- {
- check_engine ();
- return engine.PrintType (style, type);
- }
-
- //
- // Disassembling.
- //
-
- public override int GetInstructionSize (TargetAddress address)
- {
- check_target ();
- return target.GetInstructionSize (address);
- }
-
- public override AssemblerLine DisassembleInstruction (Method
method, TargetAddress address)
- {
- check_target ();
- return target.DisassembleInstruction (method, address);
- }
-
- public override AssemblerMethod DisassembleMethod (Method
method)
- {
- check_target ();
- return target.DisassembleMethod (method);
- }
-
- public void RuntimeInvoke (TargetFunctionType function,
- TargetClassObject object_argument,
- TargetObject[] param_objects,
- bool is_virtual)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.RuntimeInvoke (
- function, object_argument,
param_objects, is_virtual, true);
- }
-
- result.Wait ();
- }
-
- public TargetObject RuntimeInvoke (TargetFunctionType function,
- TargetClassObject
object_argument,
- TargetObject[] param_objects,
- bool is_virtual, out string
exc_message)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.RuntimeInvoke (
- function, object_argument,
param_objects, is_virtual, false);
- }
-
- result.Wait ();
-
- RuntimeInvokeResult res = (RuntimeInvokeResult)
result.Result;
- if (res == null) {
- exc_message = null;
- return null;
- }
- exc_message = res.ExceptionMessage;
- return res.ReturnObject;
- }
-
- public TargetAddress CallMethod (TargetAddress method,
TargetAddress arg1,
- TargetAddress arg2)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.CallMethod (method, arg1, arg2);
- }
-
- result.Wait ();
-
- if (result.Result == null)
- throw new TargetException
(TargetError.UnknownError);
-
- return (TargetAddress) result.Result;
- }
-
- public TargetAddress CallMethod (TargetAddress method, long
method_arg,
- string string_arg)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.CallMethod (method, method_arg,
string_arg);
- }
-
- result.Wait ();
-
- if (result.Result == null)
- throw new TargetException
(TargetError.UnknownError);
-
- return (TargetAddress) result.Result;
- }
-
- internal object Invoke (TargetAccessDelegate func, object data)
- {
- if (engine.ThreadManager.InBackgroundThread)
- return func (this, data);
- else
- return engine.ThreadManager.SendCommand
(engine, func, data);
- }
-
- public void Return (bool run_finally)
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.Return (run_finally);
- if (result == null)
- return;
- }
-
- result.Wait ();
- }
-
- public void AbortInvocation ()
- {
- CommandResult result;
-
- lock (this) {
- check_engine ();
- result = engine.AbortInvocation ();
- }
-
- result.Wait ();
- }
-
- internal CommandResult GetThreadID (MonoThreadManager
mono_manager,
- MonoDebuggerInfo
debugger_info)
- {
- check_engine ();
- return engine.GetThreadID (mono_manager, debugger_info);
- }
-
- public string PrintRegisters (StackFrame frame)
- {
- return Architecture.PrintRegisters (frame);
- }
-
- public bool HasTarget {
- get { return engine != null; }
- }
-
- public bool CanRun {
- get { return true; }
- }
-
- public bool CanStep {
- get { return true; }
- }
-
- public bool IsStopped {
- get { return State == TargetState.STOPPED; }
- }
-
- public override TargetInfo TargetInfo {
- get { return target_info; }
- }
-
-#region ITargetInfo implementation
- public override int TargetAddressSize {
- get { return target_info.TargetAddressSize; }
- }
-
- public override int TargetIntegerSize {
- get { return target_info.TargetIntegerSize; }
- }
-
- public override int TargetLongIntegerSize {
- get { return target_info.TargetLongIntegerSize; }
- }
-
- public override bool IsBigEndian {
- get { return target_info.IsBigEndian; }
- }
-#endregion
-
-#region TargetMemoryAccess implementation
- void write_memory (TargetAddress address, byte[] buffer)
- {
- check_target ();
- target.WriteBuffer (address, buffer);
- }
-
- public override AddressDomain AddressDomain {
- get {
- return target_info.AddressDomain;
- }
- }
-
- public override byte ReadByte (TargetAddress address)
- {
- check_target ();
- return target.ReadByte (address);
- }
-
- public override int ReadInteger (TargetAddress address)
- {
- check_target ();
- return target.ReadInteger (address);
- }
-
- public override long ReadLongInteger (TargetAddress address)
- {
- check_target ();
- return target.ReadLongInteger (address);
- }
-
- public override TargetAddress ReadAddress (TargetAddress
address)
- {
- check_target ();
- return target.ReadAddress (address);
- }
-
- public override string ReadString (TargetAddress address)
- {
- check_target ();
- return target.ReadString (address);
- }
-
- public override TargetBlob ReadMemory (TargetAddress address,
int size)
- {
- check_target ();
- byte[] buffer = target.ReadBuffer (address, size);
- return new TargetBlob (buffer, target_info);
- }
-
- public override byte[] ReadBuffer (TargetAddress address, int
size)
- {
- check_target ();
- return target.ReadBuffer (address, size);
- }
-
- public override bool CanWrite {
- get { return false; }
- }
-
- public override void WriteBuffer (TargetAddress address, byte[]
buffer)
- {
- write_memory (address, buffer);
- }
-
- public override void WriteByte (TargetAddress address, byte
value)
- {
- throw new InvalidOperationException ();
- }
-
- public override void WriteInteger (TargetAddress address, int
value)
- {
- throw new InvalidOperationException ();
- }
-
- public override void WriteLongInteger (TargetAddress address,
long value)
- {
- throw new InvalidOperationException ();
- }
-
- public override void WriteAddress (TargetAddress address,
TargetAddress value)
- {
- check_target ();
- TargetBinaryWriter writer = new TargetBinaryWriter (
- target_info.TargetAddressSize, target_info);
- writer.WriteAddress (value);
- write_memory (address, writer.Contents);
- }
-#endregion
-
- internal class StepCommandResult : CommandResult
- {
- Thread thread;
-
- public StepCommandResult (Thread thread)
- {
- this.thread = thread;
- }
-
- public override ST.WaitHandle CompletedEvent {
- get { return thread.WaitHandle; }
- }
-
- public override void Completed ()
- {
- thread.operation_completed_event.Set ();
- }
- }
-
-#region IDisposable implementation
- private bool disposed = false;
-
- protected void check_disposed ()
- {
- if (disposed)
- throw new ObjectDisposedException ("Thread");
- }
-
- protected virtual void DoDispose ()
- {
- if (engine != null) {
- engine.Dispose ();
- engine = null;
-
- operation_completed_event.Set ();
- }
- }
-
- protected virtual void Dispose (bool disposing)
- {
- // Check to see if Dispose has already been called.
- if (disposed)
- return;
-
- disposed = true;
-
- // If this is a call to Dispose, dispose all managed
resources.
- if (disposing) {
- DoDispose ();
- }
- }
-
- public void Dispose ()
- {
- Dispose (true);
- // Take yourself off the Finalization queue
- GC.SuppressFinalize (this);
- }
-#endregion
-
- ~Thread ()
- {
- Dispose (false);
- }
- }
-}
Copied: trunk/debugger/classes/Debugger.cs (from rev 59571,
trunk/debugger/backends/Debugger.cs)
Copied: trunk/debugger/classes/Process.cs (from rev 59573,
trunk/debugger/backends/Process.cs)
Copied: trunk/debugger/classes/Thread.cs (from rev 59571,
trunk/debugger/backends/Thread.cs)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches