Inheritance: DebuggerMarshalByRefObject, IOperationHost
示例#1
0
        private void OnInitialized(MD.Debugger debugger, Process process)
        {
            Console.WriteLine(">> OnInitialized");

            this.process  = process;
            this.debugger = debugger;

            mdbAdaptor.Process = process;

            guiManager = process.StartGUIManager();

            //FIXME: conditionally add event handlers
            process.TargetOutputEvent += OnTargetOutput;

            debugger.ProcessCreatedEvent += OnProcessCreatedEvent;
            debugger.ProcessExecdEvent   += OnProcessExecdEvent;
            debugger.ProcessExitedEvent  += OnProcessExitedEvent;

            debugger.ThreadCreatedEvent += OnThreadCreatedEvent;
            debugger.ThreadExitedEvent  += OnThreadExitedEvent;

            debugger.TargetExitedEvent += OnTargetExitedEvent;
            guiManager.TargetEvent     += OnTargetEvent;

            // Not supported
            //guiManager.BreakpointHitHandler = BreakEventCheck;

            activeThread = process.MainThread;
            running      = true;

            Console.WriteLine("<< OnInitialized");
        }
示例#2
0
        void NotifyTargetEvent(MD.Thread thread, MD.TargetEventArgs args)
        {
            if (args.Frame != null)
            {
                activeThread = args.Frame.Thread;
            }

            try {
                if (args.Type == MD.TargetEventType.TargetStopped && ((int)args.Data) != 0)
                {
                    DispatchEvent(delegate {
                        controller.OnDebuggerOutput(false, string.Format("Thread {0:x} received signal {1}.\n", args.Frame.Thread.ID, args.Data));
                    });
                }

                DL.TargetEventType type;

                switch (args.Type)
                {
                case MD.TargetEventType.Exception: type = DL.TargetEventType.ExceptionThrown; break;

                case MD.TargetEventType.TargetHitBreakpoint: type = DL.TargetEventType.TargetHitBreakpoint; break;

                case MD.TargetEventType.TargetInterrupted: type = DL.TargetEventType.TargetInterrupted; break;

                case MD.TargetEventType.TargetSignaled: type = DL.TargetEventType.TargetSignaled; break;

                case MD.TargetEventType.TargetStopped: type = DL.TargetEventType.TargetStopped; break;

                case MD.TargetEventType.UnhandledException: type = DL.TargetEventType.UnhandledException; break;

                default:
                    return;
                }

                OnCleanFrameData();

                DL.TargetEventArgs targetArgs = new DL.TargetEventArgs(type);

                if (args.Type != MD.TargetEventType.TargetExited)
                {
                    ML.TargetObject exception = null;
                    if (args.Type == MD.TargetEventType.UnhandledException || args.Type == MD.TargetEventType.Exception)
                    {
                        exception = args.Frame.ExceptionObject;
                    }
                    targetArgs.Backtrace = CreateBacktrace(thread, exception);
                    targetArgs.Thread    = CreateThreadInfo(activeThread);
                }


                running = false;

                DispatchEvent(delegate {
                    controller.OnTargetEvent(targetArgs);
                });
            } catch (Exception e) {
                Console.WriteLine("*** DS.OnTargetEvent2, exception : {0}", e.ToString());
            }
        }
示例#3
0
        private void OnTargetEvent(MD.Thread thread, MD.TargetEventArgs args)
        {
            try {
                if (!running)
                {
                    LogEvent(args);
                    return;
                }

                bool notifyToClient = args.IsStopped || args.Type == MD.TargetEventType.UnhandledException || args.Type == MD.TargetEventType.Exception || args.Type == MD.TargetEventType.TargetInterrupted;

                LogEvent(args);

                bool isStop = args.Type != MD.TargetEventType.FrameChanged &&
                              args.Type != MD.TargetEventType.TargetExited &&
                              args.Type != MD.TargetEventType.TargetRunning;

                if (isStop)
                {
                    lock (debugger) {
                        if (stoppedWorkQueue.Count > 0)
                        {
                            // Execute queued work in another thread with a small delay
                            // since it is not safe to execute it here
                            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                                System.Threading.Thread.Sleep(50);
                                bool resume = false;
                                lock (debugger) {
                                    foreach (ST.WaitCallback cb in stoppedWorkQueue)
                                    {
                                        cb(null);
                                    }
                                    stoppedWorkQueue.Clear();
                                }
                                if (resume)
                                {
                                    guiManager.Continue(process.MainThread);
                                }
                                else if (notifyToClient)
                                {
                                    NotifyTargetEvent(thread, args);
                                }
                            });
                            return;
                        }
                    }
                }

                if (notifyToClient)
                {
                    NotifyTargetEvent(thread, args);
                }
            } catch (Exception e) {
                Console.WriteLine("*** DS.OnTargetEvent1, exception : {0}", e.ToString());
            }
        }
示例#4
0
 public DL.Backtrace GetThreadBacktrace(long processId, long threadId)
 {
     MD.Thread t = GetThread(processId, threadId);
     if (t != null && t.IsStopped)
     {
         return(CreateBacktrace(t, null));
     }
     else
     {
         return(null);
     }
 }
示例#5
0
        protected override void OnThreadCreated(Mono.Debugger.Thread thread)
        {
            eventData newEvent = new eventData();

            newEvent.eventType = "OnThreadCreated";
            newEvent.arg1      = 0;
            newEvent.arg2      = 0;
            newEvent.arg3      = "";

            eventList.Add(newEvent);

            base.OnThreadCreated(thread);
        }
示例#6
0
        ThreadInfo CreateThreadInfo(MD.Thread t)
        {
            string loc;

            if (t.CurrentFrame != null && t.CurrentFrame.SourceLocation != null)
            {
                loc = t.CurrentFrame.ToString();
            }
            else
            {
                loc = "<Unknown>";
            }

            return(new ThreadInfo(t.Process.ID, t.ID, t.Name, loc));
        }
示例#7
0
        protected override void OnThreadExited(Mono.Debugger.Thread thread)
        {
            if (thread != thread.Process.MainThread)
            {
                eventData newEvent = new eventData();
                newEvent.eventType = "OnThreadExited";
                newEvent.arg1      = 0;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
            }

            base.OnThreadExited(thread);
        }
示例#8
0
        DL.Backtrace CreateBacktrace(MD.Thread thread, ML.TargetObject exception)
        {
            List <MD.StackFrame> frames = new List <MD.StackFrame> ();
            DateTime             t      = DateTime.Now;

            if (!thread.CurrentFrame.Language.IsManaged)
            {
                MD.Backtrace bt = thread.GetBacktrace(MD.Backtrace.Mode.Native, max_frames);
                if (bt != null)
                {
                    Console.WriteLine("GetBacktrace native time: {0} ms n:{1}", (DateTime.Now - t).TotalMilliseconds, bt.Count);
                    frames.AddRange(bt.Frames);
                }
            }
            else
            {
                t = DateTime.Now;
                MD.Backtrace backtrace = thread.GetBacktrace(MD.Backtrace.Mode.Managed, max_frames);
                if (backtrace != null)
                {
                    Console.WriteLine("GetBacktrace managed time: {0} ms n:{1}", (DateTime.Now - t).TotalMilliseconds, backtrace.Count);
                    frames.AddRange(backtrace.Frames);
                }
            }
            if (frames.Count > 0)
            {
                BacktraceWrapper wrapper = new BacktraceWrapper(frames.ToArray(), exception);
                return(new DL.Backtrace(wrapper));
            }
            else if (thread.CurrentBacktrace != null)
            {
                BacktraceWrapper wrapper = new BacktraceWrapper(thread.CurrentBacktrace.Frames, exception);
                return(new DL.Backtrace(wrapper));
            }
            return(null);
        }
示例#9
0
 public void SetActiveThread(long processId, long threadId)
 {
     activeThread = GetThread(processId, threadId);
 }
		private void OnInitialized (MD.Debugger debugger, Process process)
		{
			Console.WriteLine (">> OnInitialized");
			
			this.process = process;
			this.debugger = debugger;
			
			mdbAdaptor.Process = process;
			
			guiManager = process.StartGUIManager ();

			//FIXME: conditionally add event handlers
			process.TargetOutputEvent += OnTargetOutput;
			
			debugger.ProcessCreatedEvent += OnProcessCreatedEvent;
			debugger.ProcessExecdEvent += OnProcessExecdEvent;
			debugger.ProcessExitedEvent += OnProcessExitedEvent;
			
			debugger.ThreadCreatedEvent += OnThreadCreatedEvent;
			debugger.ThreadExitedEvent += OnThreadExitedEvent;
			
			debugger.TargetExitedEvent += OnTargetExitedEvent;
			guiManager.TargetEvent += OnTargetEvent;

			// Not supported
			//guiManager.BreakpointHitHandler = BreakEventCheck;
			
			activeThread = process.MainThread;
			running = true;
			
			Console.WriteLine ("<< OnInitialized");
		}
示例#11
0
 private void OnThreadCreatedEvent(MD.Debugger debugger, MD.Thread thread)
 {
     WriteDebuggerOutput(string.Format("Thread {0} created.\n", thread.ID));
 }
示例#12
0
 public abstract void AbortThread(MDB.Thread thread, MDB.RuntimeInvokeResult result);
示例#13
0
        protected override bool DoResolve(ScriptingContext context)
        {
            // set whole method in a try-catch block: if anything goes wrong, an invalid breakpoint
            // number is set and the semaphore is released.
            try {
                if (global)
                {
                    if (local)
                    {
                        throw new ScriptingException(
                                  "Cannot use both -local and -global.");
                    }

                    if (Group != null)
                    {
                        throw new ScriptingException(
                                  "Cannot use both -group and -global.");
                    }

                    tgroup = ThreadGroup.Global;
                }
                else if (local)
                {
                    if (Group != null)
                    {
                        throw new ScriptingException(
                                  "Cannot use both -group and -local.");
                    }

                    tgroup = context.Interpreter.GetThreadGroup(Group, false);
                }
                else if (Group != null)
                {
                    tgroup = context.Interpreter.GetThreadGroup(Group, false);
                }
                else
                {
                    tgroup = ThreadGroup.Global;
                }

                if (context.Interpreter.HasTarget)
                {
                    context.CurrentProcess = context.Interpreter.GetProcess(p_index);
                    context.CurrentThread  = context.Interpreter.GetThread(t_index);

                    Mono.Debugger.Thread thread = context.CurrentThread;
                    if (!thread.IsStopped)
                    {
                        throw new Mono.Debugger.TargetException(TargetError.NotStopped);
                    }

                    Backtrace backtrace = thread.GetBacktrace();

                    StackFrame frame;
                    if (f_index == -1)
                    {
                        frame = backtrace.CurrentFrame;
                    }
                    else
                    {
                        if (f_index >= backtrace.Count)
                        {
                            throw new ScriptingException(
                                      "No such frame: {0}", f_index);
                        }

                        frame = backtrace [f_index];
                    }

                    context.CurrentFrame = frame;

                    if (ExpressionParser.ParseLocation(
                            thread, thread.CurrentFrame, Argument, out location))
                    {
                        return(true);
                    }
                }

                if (Argument.IndexOf(':') > 0)
                {
                    return(true);
                }

                try {
                    UInt32.Parse(Argument);
                    return(true);
                } catch {
                }

                Expression expr = context.Interpreter.ExpressionParser.Parse(Argument);
                if (expr == null)
                {
                    throw new ScriptingException("Cannot resolve expression `{0}'.", Argument);
                }

                if (expr is PointerExpression)
                {
                    address = ((PointerExpression)expr).EvaluateAddress(context);
                    return(true);
                }

                if (!context.Interpreter.HasTarget)
                {
                    return(true);
                }

                MethodExpression mexpr;
                try {
                    mexpr = expr.ResolveMethod(context, type);
                } catch {
                    if (lazy)
                    {
                        return(true);
                    }
                    throw new ScriptingException("No such method: `{0}'.", Argument);
                }

                if (mexpr != null)
                {
                    location = mexpr.EvaluateSource(context);
                }
                else
                {
                    location = context.FindMethod(Argument);
                }

                if (lazy)
                {
                    return(true);
                }

                if (location == null)
                {
                    throw new ScriptingException("No such method: `{0}'.", Argument);
                }

                return(true);
            } catch {
                EmonicInterpreter.breakpointNumber = -1;
                EmonicInterpreter.breakpointSem.Release();
                throw;
            }
        }
示例#14
0
        protected override string Execute(ScriptingContext context,
                                          Expression expression, DisplayFormat format)
        {
            try {
                if (expression is TypeExpression)
                {
                    throw new ScriptingException(
                              "`{0}' is a type, not a variable.", expression.Name);
                }
                object retval = expression.Evaluate(context);

                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";

                if (retval != null)
                {
                    output.type = ((TargetObject)retval).TypeName;
                    if (output.type == null)
                    {
                        output.type = "";
                    }

                    switch (((TargetObject)retval).Kind)
                    {
                    case TargetObjectKind.Fundamental:
                        // we send the value of the fundamental type
                        TargetFundamentalObject tfo = retval as TargetFundamentalObject;
                        if (tfo == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        output.varValue = tfo.GetObject(context.CurrentThread).ToString();
                        if (output.varValue == null)
                        {
                            output.varValue = "";
                        }
                        break;

                    case TargetObjectKind.Array:
                        // we send back the number of array elements
                        TargetArrayObject tao = retval as TargetArrayObject;
                        if (tao == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        int lower = tao.GetLowerBound(context.CurrentThread, 0);
                        int upper = tao.GetUpperBound(context.CurrentThread, 0);
                        output.varNames = (upper - lower).ToString();
                        break;

                    // same for struct and class
                    case TargetObjectKind.Struct:
                    case TargetObjectKind.Class:
                        // we send back the member's names
                        // NOTE! we also show static and constant fields
                        TargetObject obj = retval as TargetObject;
                        if (obj.HasAddress && obj.GetAddress(context.CurrentThread).IsNull)
                        {
                            output.varValue = "<null>";
                            break;
                        }
                        Mono.Debugger.Thread thread = context.CurrentThread;
                        TargetClass          tc     = ((TargetClassObject)retval).Type.GetClass(thread);
                        if (tc == null)
                        {
                            break;
                        }
                        TargetFieldInfo[] tfi = tc.GetFields(thread);
                        if (tfi == null)
                        {
                            break;
                        }
                        output.varNames = "";
                        for (int i = 0; i < tfi.Length; i++)
                        {
                            if (tfi[i].IsStatic)                             // do not show static fields, they're not accessible via the instance!
                            {
                                continue;
                            }
                            output.varNames += tfi[i].Name;
                            output.varNames += " ";
                        }
                        output.varNames = output.varNames.Trim();
                        break;

                    case TargetObjectKind.Object:
                    case TargetObjectKind.Pointer:
                    case TargetObjectKind.Unknown:
                    case TargetObjectKind.Function:
                    case TargetObjectKind.Alias:
                    case TargetObjectKind.Enum:
                        context.Print("ERROR: Print Command will return no values because of an implementation error");
                        break;
                    }
                }
                string text = context.FormatObject(retval, format);
                context.Print(text);

                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();

                return(text);
            } catch {
                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";
                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();
                throw;
            }
        }
		public MdbDissassemblyBuffer (MD.Thread thread, MD.TargetAddress addr): base (addr.Address)
		{
			this.thread = thread;
			this.baseAddr = addr;
		}
		void NotifyTargetEvent (MD.Thread thread, MD.TargetEventArgs args)
		{
			if (args.Frame != null)
				activeThread = args.Frame.Thread;
	
			try {
				if (args.Type == MD.TargetEventType.TargetStopped && ((int)args.Data) != 0) {
					DispatchEvent (delegate {
						controller.OnDebuggerOutput (false, string.Format ("Thread {0:x} received signal {1}.\n", args.Frame.Thread.ID, args.Data));
					});
				}

				DL.TargetEventType type;
				
				switch (args.Type) {
					case MD.TargetEventType.Exception: type = DL.TargetEventType.ExceptionThrown; break;
					case MD.TargetEventType.TargetHitBreakpoint: type = DL.TargetEventType.TargetHitBreakpoint; break;
					case MD.TargetEventType.TargetInterrupted: type = DL.TargetEventType.TargetInterrupted; break;
					case MD.TargetEventType.TargetSignaled: type = DL.TargetEventType.TargetSignaled; break;
					case MD.TargetEventType.TargetStopped: type = DL.TargetEventType.TargetStopped; break;
					case MD.TargetEventType.UnhandledException: type = DL.TargetEventType.UnhandledException; break;
					default:
						return;
				}

				OnCleanFrameData ();
				
				DL.TargetEventArgs targetArgs = new DL.TargetEventArgs (type);

				if (args.Type != MD.TargetEventType.TargetExited) {
					ML.TargetObject exception = null;
					if (args.Type == MD.TargetEventType.UnhandledException || args.Type == MD.TargetEventType.Exception)
						exception = args.Frame.ExceptionObject;
					targetArgs.Backtrace = CreateBacktrace (thread, exception);
					targetArgs.Thread = CreateThreadInfo (activeThread);
				}


				running = false;

				DispatchEvent (delegate {
					controller.OnTargetEvent (targetArgs);
				});
			} catch (Exception e) {
				Console.WriteLine ("*** DS.OnTargetEvent2, exception : {0}", e.ToString ());
			}
		}
示例#17
0
        protected override void OnTargetEvent(Mono.Debugger.Thread thread, TargetEventArgs args)
        {
            switch (args.Type)
            {
            case TargetEventType.TargetStopped: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetStopped";
                newEvent.arg1      = thread.ID;
                newEvent.arg3      = "";

                newEvent.arg2 = (int)args.Data;

                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.TargetRunning: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetRunning";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";
                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.TargetInterrupted: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetInterrupted";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";
                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.FrameChanged: {
                eventData newEvent = new eventData();
                newEvent.eventType = "FrameChanged";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";
                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.TargetHitBreakpoint: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetHitBreakpoint";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = (int)args.Data;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.TargetSignaled: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetSignaled";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = (int)args.Data;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.TargetExited: {
                eventData newEvent = new eventData();
                newEvent.eventType = "TargetExited";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = (int)args.Data;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.Exception: {
                eventData newEvent = new eventData();
                newEvent.eventType = "Exception";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
                break;
            }

            case TargetEventType.UnhandledException: {
                eventData newEvent = new eventData();
                newEvent.eventType = "UnhandledException";
                newEvent.arg1      = thread.ID;
                newEvent.arg2      = 0;
                newEvent.arg3      = "";

                eventList.Add(newEvent);
                break;
            }
            }

            base.OnTargetEvent(thread, args);
        }
示例#18
0
 public MdbDissassemblyBuffer(MD.Thread thread, MD.TargetAddress addr) : base(addr.Address)
 {
     this.thread   = thread;
     this.baseAddr = addr;
 }
示例#19
0
 public override void AbortThread(MDB.Thread thread, MDB.RuntimeInvokeResult result)
 {
     result.Abort();
 }
		public void SetActiveThread (long processId, long threadId)
		{
			activeThread = GetThread (processId, threadId);
		}