Inheritance: DebuggerMarshalByRefObject
Beispiel #1
0
        internal void ChildExecd(SingleSteppingEngine engine, Inferior inferior)
        {
            is_execed = true;

            if (!is_forked) {
                if (mono_language != null)
                    mono_language.Dispose();

                if (native_language != null)
                    native_language.Dispose ();

                if (os != null)
                    os.Dispose ();

                if (symtab_manager != null)
                    symtab_manager.Dispose ();
            }

            if (breakpoint_manager != null)
                breakpoint_manager.Dispose ();

            session.OnProcessExecd (this);

            breakpoint_manager = new BreakpointManager ();

            exception_handlers = new Dictionary<int,ExceptionCatchPoint> ();

            symtab_manager = new SymbolTableManager (session);

            os = Inferior.CreateOperatingSystemBackend (this);
            native_language = new NativeLanguage (this, os, target_info);

            Inferior new_inferior = Inferior.CreateInferior (manager, this, start);
            try {
                new_inferior.InitializeAfterExec (inferior.PID);
            } catch (Exception ex) {
                if ((ex is TargetException) && (((TargetException) ex).Type == TargetError.PermissionDenied)) {
                    Report.Error ("Permission denied when trying to debug exec()ed child {0}, detaching!",
                              inferior.PID);
                } else {
                    Report.Error ("InitializeAfterExec() failed on pid {0}: {1}", inferior.PID, ex);
                }
                new_inferior.DetachAfterFork ();
                return;
            }

            SingleSteppingEngine new_thread = new SingleSteppingEngine (
                manager, this, new_inferior, inferior.PID);

            ThreadServant[] threads;
            lock (thread_hash.SyncRoot) {
                threads = new ThreadServant [thread_hash.Count];
                thread_hash.Values.CopyTo (threads, 0);
            }

            for (int i = 0; i < threads.Length; i++) {
                if (threads [i].PID != inferior.PID)
                    threads [i].Kill ();
            }

            thread_hash [inferior.PID] = new_thread;

            inferior.Dispose ();
            inferior = null;

            manager.Debugger.OnProcessExecdEvent (this);
            manager.Debugger.OnThreadCreatedEvent (new_thread.Thread);
            initialized = is_forked = false;
            main_thread = new_thread;

            if ((engine.Thread.ThreadFlags & Thread.Flags.StopOnExit) != 0)
                new_thread.Thread.ThreadFlags |= Thread.Flags.StopOnExit;

            CommandResult result = engine.OnExecd (new_thread);
            new_thread.StartExecedChild (result);
        }
Beispiel #2
0
 internal void OnManagedThreadExitedEvent(ThreadServant thread)
 {
     thread_hash.Remove (thread.PID);
 }
Beispiel #3
0
 void OnThreadCreatedEvent(ThreadServant thread)
 {
     thread_hash.Add (thread.PID, thread);
     manager.Debugger.OnThreadCreatedEvent (thread.Client);
 }
Beispiel #4
0
 public Thread[] GetThreads()
 {
     lock (thread_hash.SyncRoot) {
         int count = thread_hash.Count;
         Thread[] threads = new Thread [count];
         ThreadServant[] servants = new ThreadServant [count];
         thread_hash.Values.CopyTo (servants, 0);
         for (int i = 0; i < count; i++)
             threads [i] = servants [i].Client;
         return threads;
     }
 }
Beispiel #5
0
        internal override StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess memory, ref TargetAddress lmf_address)
        {
            TargetAddress lmf = lmf_address;
            TargetBinaryReader reader = memory.ReadMemory (lmf_address, 88).GetReader ();

            lmf_address = reader.ReadTargetAddress (); // prev
            reader.ReadTargetAddress ();
            reader.ReadTargetAddress (); // method
            TargetAddress rip = reader.ReadTargetAddress ();

            if (lmf_address.IsNull)
                return null;

            TargetAddress rbx = reader.ReadTargetAddress ();
            TargetAddress rbp = reader.ReadTargetAddress ();
            TargetAddress rsp = reader.ReadTargetAddress ();
            TargetAddress r12 = reader.ReadTargetAddress ();
            TargetAddress r13 = reader.ReadTargetAddress ();
            TargetAddress r14 = reader.ReadTargetAddress ();
            TargetAddress r15 = reader.ReadTargetAddress ();

            Registers regs = new Registers (this);

            if ((lmf_address.Address & 1) == 0) {
                rip = memory.ReadAddress (rsp - 8);
                regs [(int) X86_Register.RIP].SetValue (rsp - 8, rip);
                regs [(int) X86_Register.RBP].SetValue (lmf + 40, rbp);
            } else {
                TargetAddress new_rbp = memory.ReadAddress (rbp);
                regs [(int) X86_Register.RIP].SetValue (lmf + 24, rip);
                regs [(int) X86_Register.RBP].SetValue (rbp, new_rbp);
                rbp = new_rbp;
                lmf_address--;
            }

            regs [(int) X86_Register.RBX].SetValue (lmf + 32, rbx);
            regs [(int) X86_Register.RSP].SetValue (lmf + 48, rsp);
            regs [(int) X86_Register.R12].SetValue (lmf + 56, r12);
            regs [(int) X86_Register.R13].SetValue (lmf + 64, r13);
            regs [(int) X86_Register.R14].SetValue (lmf + 72, r14);
            regs [(int) X86_Register.R15].SetValue (lmf + 80, r15);

            return CreateFrame (thread.Client, FrameType.LMF, memory, rip, rsp, rbp, regs);
        }
Beispiel #6
0
 internal abstract StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess target,
                                     ref TargetAddress lmf_address);
Beispiel #7
0
        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) {
                if (servant != null) {
                    servant.Dispose ();
                    servant = null;
                }
            }
        }
Beispiel #8
0
        internal override StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess memory,
						     ref TargetAddress lmf_address)
        {
            TargetAddress lmf = lmf_address;

            TargetBinaryReader reader = memory.ReadMemory (lmf, 36).GetReader ();
            lmf_address = reader.ReadTargetAddress (); // prev

            reader.Position = 16;

            TargetAddress ebx = reader.ReadTargetAddress ();
            TargetAddress edi = reader.ReadTargetAddress ();
            TargetAddress esi = reader.ReadTargetAddress ();
            TargetAddress ebp = reader.ReadTargetAddress ();
            TargetAddress eip = reader.ReadTargetAddress ();

            Registers regs = new Registers (this);
            regs [(int) X86_Register.RBX].SetValue (lmf + 16, ebx);
            regs [(int) X86_Register.RDI].SetValue (lmf + 20, edi);
            regs [(int) X86_Register.RSI].SetValue (lmf + 24, esi);
            regs [(int) X86_Register.RBP].SetValue (lmf + 28, ebp);
            regs [(int) X86_Register.RIP].SetValue (lmf + 32, eip);

            TargetAddress new_ebp = memory.ReadAddress (ebp);
            regs [(int) X86_Register.RBP].SetValue (ebp, new_ebp);

            TargetAddress new_esp = ebp + 8;
            regs [(int) X86_Register.RSP].SetValue (ebp, new_esp);

            return CreateFrame (thread.Client, FrameType.LMF, memory, eip, new_esp, new_ebp, regs);
        }
Beispiel #9
0
        private StackFrame TryLMF(ThreadServant thread, TargetMemoryAccess memory)
        {
            try {
                if (lmf_address.IsNull)
                    return null;

                StackFrame new_frame = thread.Architecture.GetLMF (thread, memory, ref lmf_address);
                if (new_frame == null)
                    return null;

                // Sanity check; don't loop.
                if (new_frame.StackPointer <= last_frame.StackPointer)
                    return null;

                return new_frame;
            } catch (TargetException) {
                return null;
            }
        }
Beispiel #10
0
 internal Thread(ThreadServant servant, int id)
 {
     this.id = id;
     this.servant = servant;
     this.flags = Flags.AutoRun;
 }
Beispiel #11
0
        private bool TryCallback(ThreadServant thread, TargetMemoryAccess memory,
					  ref StackFrame frame, bool exact_match)
        {
            try {
                if (frame == null)
                    return false;

                Inferior.CallbackFrame callback = thread.GetCallbackFrame (
                    frame.StackPointer, exact_match);
                if (callback == null)
                    return false;

                frame = thread.Architecture.CreateFrame (
                    thread.Client, FrameType.Normal, memory, callback.Registers);

                FrameType callback_type;
                string frame_name = "<method called from mdb>";

                if (callback.IsRuntimeInvokeFrame) {
                    callback_type = FrameType.RuntimeInvoke;
                    TargetFunctionType func = thread.GetRuntimeInvokedFunction (callback.ID);
                    if (func != null)
                        frame_name = String.Format ("<Invocation of: {0}>", func.FullName);
                } else {
                    callback_type = FrameType.Callback;
                }

                AddFrame (new StackFrame (
                    thread.Client, callback_type, callback.CallAddress, callback.StackPointer,
                    TargetAddress.Null, callback.Registers, thread.NativeLanguage,
                    new Symbol (frame_name, callback.CallAddress, 0)));
                return true;
            } catch (TargetException) {
                return false;
            }
        }
Beispiel #12
0
        internal bool TryUnwind(ThreadServant thread, TargetMemoryAccess memory,
					 Mode mode, TargetAddress until)
        {
            StackFrame new_frame = null;
            try {
                new_frame = last_frame.UnwindStack (memory);
            } catch (TargetException) {
            }

            if (!TryCallback (thread, memory, ref new_frame, true)) {
                if ((new_frame == null) || !IsFrameOkForMode (new_frame, mode)) {
                    if (!tried_lmf) {
                        tried_lmf = true;
                        if (thread.LMFAddress.IsNull)
                            return false;
                        lmf_address = memory.ReadAddress (thread.LMFAddress);
                    }

                    if (!lmf_address.IsNull)
                        new_frame = TryLMF (thread, memory);
                    else
                        return false;
                }
            }

            if (new_frame == null)
                return false;

            // Sanity check; don't loop.
            if (new_frame.StackPointer <= last_frame.StackPointer)
                return false;

            if (!until.IsNull && (new_frame.StackPointer >= until))
                return false;

            AddFrame (new_frame);
            return true;
        }
Beispiel #13
0
        internal void GetBacktrace(ThreadServant thread, TargetMemoryAccess memory,
					    Mode mode, TargetAddress until, int max_frames)
        {
            while (TryUnwind (thread, memory, mode, until)) {
                if ((max_frames != -1) && (frames.Count > max_frames))
                    break;
            }

            // Ugly hack: in Mode == Mode.Default, we accept wrappers but not as the
            //            last frame.
            if ((mode == Mode.Default) && (frames.Count > 1)) {
                StackFrame last = this [frames.Count - 1];
                if (!IsFrameOkForMode (last, Mode.Managed))
                    frames.Remove (last);
            }
        }
Beispiel #14
0
        internal void OnThreadExitedEvent(ThreadServant thread)
        {
            thread_hash.Remove (thread.PID);
            thread.ThreadGroup.RemoveThread (thread.ID);
            session.DeleteThreadGroup (thread.ThreadGroup.Name);
            manager.Debugger.OnThreadExitedEvent (thread.Client);

            if (thread_hash.Count == 0)
                OnProcessExitedEvent ();
        }
Beispiel #15
0
        internal abstract StackFrame GetLMF(ThreadServant thread, TargetMemoryAccess target,
						     ref TargetAddress lmf_address);
Beispiel #16
0
        internal CommandResult StartApplication()
        {
            SingleSteppingEngine engine = new SingleSteppingEngine (manager, this, start);

            initialized = true;

            this.main_thread = engine;
            engine.Thread.ThreadFlags |= Thread.Flags.StopOnExit;

            if (thread_hash.Contains (engine.PID))
                thread_hash [engine.PID] = engine;
            else
                thread_hash.Add (engine.PID, engine);
            session.MainThreadGroup.AddThread (engine.Thread.ID);

            session.OnMainProcessCreated (this);
            manager.Debugger.OnMainProcessCreatedEvent (this);

            CommandResult result = Debugger.StartOperation (start.Session.Config.ThreadingModel, engine);
            return engine.StartApplication (result);
        }
Beispiel #17
0
 internal Thread CreateThread(ThreadServant servant, int id)
 {
     return new Thread (servant, id);
 }