Ejemplo n.º 1
0
        internal override BreakpointHandle Resolve(Thread target, StackFrame frame)
        {
            if (handle != null)
            {
                return(handle);
            }

            if (frame.Thread.Process.IsManaged)
            {
                MonoLanguageBackend mono = frame.Thread.Process.MonoLanguage;
                MonoFunctionType    main = mono.MainMethod;
                if (main == null)
                {
                    return(null);
                }

                handle = main.GetBreakpointHandle(this, -1, -1);
            }
            else
            {
                OperatingSystemBackend os   = frame.Thread.Process.OperatingSystem;
                TargetAddress          main = os.LookupSymbol("main");
                if (main.IsNull)
                {
                    return(null);
                }

                handle = new AddressBreakpointHandle(this, main);
            }

            return(handle);
        }
Ejemplo n.º 2
0
        public override TargetMethodSignature GetSignature(Thread thread)
        {
            if (signature != null)
            {
                return(signature);
            }

            if (!ContainsGenericParameters)
            {
                return(new MonoMethodSignature(return_type, parameter_types));
            }

            if (!thread.CurrentFrame.Language.IsManaged)
            {
                throw new TargetException(TargetError.InvalidContext);
            }

            TargetAddress addr = (TargetAddress)thread.ThreadServant.DoTargetAccess(
                delegate(TargetMemoryAccess target)  {
                MonoClassInfo class_info = ResolveClass(target, true);
                return(class_info.GetMethodAddress(target, token));
            });

            MonoLanguageBackend mono = klass.File.MonoLanguage;

            TargetAddress sig = thread.CallMethod(
                mono.MonoDebuggerInfo.GetMethodSignature, addr, 0);

            signature = (MonoMethodSignature)thread.ThreadServant.DoTargetAccess(
                delegate(TargetMemoryAccess target)  {
                return(mono.MetadataHelper.GetMethodSignature(mono, target, sig));
            });

            return(signature);
        }
Ejemplo n.º 3
0
        public MonoMethodSignature GetMethodSignature(MonoLanguageBackend mono,
                                                      TargetMemoryAccess memory,
                                                      TargetAddress signature)
        {
            int count = memory.ReadInteger(signature + 4) & 0x0000ffff;

            int           offset = memory.TargetAddressSize == 8 ? 16 : 12;
            TargetAddress ret    = memory.ReadAddress(signature + offset);

            TargetType ret_type = mono.ReadType(memory, ret);

            if (count == 0)
            {
                return(new MonoMethodSignature(ret_type, new TargetType [0]));
            }

            offset += memory.TargetAddressSize;
            TargetReader reader = new TargetReader(
                memory.ReadMemory(signature + offset, count * memory.TargetAddressSize));

            TargetType[] param_types = new TargetType [count];
            for (int i = 0; i < count; i++)
            {
                param_types [i] = mono.ReadType(memory, reader.ReadAddress());
            }

            return(new MonoMethodSignature(ret_type, param_types));
        }
Ejemplo n.º 4
0
        public AppDomainInfo GetAppDomainInfo(MonoLanguageBackend mono, TargetMemoryAccess memory,
                                              TargetAddress address)
        {
            int          addr_size = memory.TargetMemoryInfo.TargetAddressSize;
            TargetReader reader    = new TargetReader(memory.ReadMemory(address, 12 * addr_size));

            return(new AppDomainInfo(mono, memory, reader));
        }
Ejemplo n.º 5
0
        void DoDispose()
        {
            if (!is_forked)
            {
                if (architecture != null)
                {
                    architecture.Dispose();
                    architecture = null;
                }

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

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

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

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

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

            if (thread_db != null)
            {
                thread_db.Dispose();
                thread_db = null;
            }

            if (thread_lock_mutex != null)
            {
                thread_lock_mutex.Dispose();
                thread_lock_mutex = null;
            }

            exception_handlers = null;

            manager.RemoveProcess(this);
        }
Ejemplo n.º 6
0
		protected FunctionBreakpointHandle (Breakpoint bpt, TargetFunctionType function,
						    int line, int column)
			: base (bpt)
		{
			this.function = function;
			this.line = line;
			this.column = column;

			this.Index = MonoLanguageBackend.GetUniqueID ();
		}
Ejemplo n.º 7
0
        internal static string ReadString(MonoLanguageBackend mono, TargetMemoryAccess target,
                                          TargetAddress address)
        {
            if (address.IsNull)
            {
                return(null);
            }

            TargetLocation   location = new AbsoluteTargetLocation(address);
            MonoStringObject so       = new MonoStringObject(mono.BuiltinTypes.StringType, location);

            return((string)so.DoGetObject(target));
        }
Ejemplo n.º 8
0
            public AppDomainInfo(MonoLanguageBackend mono, TargetMemoryAccess memory, TargetReader reader)
            {
                int addr_size = memory.TargetMemoryInfo.TargetAddressSize;

                reader.Offset         = 2 * addr_size;
                ApplicationBase       = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                ApplicationName       = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                CachePath             = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                ConfigFile            = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                DynamicBase           = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                reader.Offset        += 3 * addr_size;
                ShadowCopyDirectories = MonoStringObject.ReadString(mono, memory, reader.ReadAddress());
                ShadowCopyFiles       = MonoStringObject.ReadString(mono, memory, reader.ReadAddress()) == "true";
            }
Ejemplo n.º 9
0
        internal bool CheckException(MonoLanguageBackend mono, TargetMemoryAccess target,
                                     TargetAddress address)
        {
            TargetClassObject exc = mono.CreateObject(target, address) as TargetClassObject;

            if (exc == null)
            {
                return(false);                // OOOPS
            }
            if (exception == null)
            {
                exception = mono.LookupType(Name);
            }
            if (exception == null)
            {
                return(false);
            }

            return(IsSubclassOf(target, exc.Type, exception));
        }
Ejemplo n.º 10
0
 internal MonoGenericParameterType(MonoLanguageBackend mono, string name)
     : base(mono)
 {
     this.name = name;
 }
Ejemplo n.º 11
0
        public static MonoClassInfo ReadClassInfo(MonoLanguageBackend mono,
                                                  TargetMemoryAccess target,
                                                  TargetAddress klass)
        {
            TargetAddress  image = mono.MetadataHelper.MonoClassGetMonoImage(target, klass);
            MonoSymbolFile file  = mono.GetImage(image);

            if (file == null)
            {
                throw new InternalError();
            }

            int token = mono.MetadataHelper.MonoClassGetToken(target, klass);

            if ((token & 0xff000000) != 0x02000000)
            {
                throw new InternalError();
            }

            Cecil.TypeDefinition typedef;
            typedef = (Cecil.TypeDefinition)file.ModuleDefinition.LookupToken(
                new Cecil.MetadataToken(Cecil.TokenType.TypeDef, token & 0x00ffffff));
            if (typedef == null)
            {
                throw new InternalError();
            }

            MonoClassInfo info = new MonoClassInfo(file, typedef, target, klass);

            if ((file == mono.BuiltinTypes.Corlib) &&
                (typedef.FullName == "System.Decimal"))
            {
                MonoFundamentalType ftype = mono.BuiltinTypes.DecimalType;

                if (ftype.ClassType == null)
                {
                    MonoClassType ctype = new MonoClassType(file, typedef, info);
                    ((IMonoStructType)ctype).ClassInfo = info;
                    ftype.SetClass(ctype);
                }

                info.struct_type = (IMonoStructType)ftype.ClassType;
                info.type        = ftype;
            }
            else if (info.IsGenericClass)
            {
                info.struct_type = (IMonoStructType)
                                   file.MonoLanguage.ReadGenericClass(
                    target, info.GenericClass, false);
                info.type = info.struct_type.Type;
            }
            else
            {
                info.type = file.LookupMonoType(typedef);
                if (info.type is TargetClassType)
                {
                    info.struct_type = (IMonoStructType)info.type;
                }
                else
                {
                    info.struct_type = (IMonoStructType)info.type.ClassType;
                }
            }
            info.struct_type.ClassInfo = info;
            return(info);
        }
Ejemplo n.º 12
0
 internal MonoLanguageBackend CreateMonoLanguage(MonoDebuggerInfo info)
 {
     mono_language = new MonoLanguageBackend(this, info);
     return(mono_language);
 }
Ejemplo n.º 13
0
        internal bool HandleChildEvent(SingleSteppingEngine engine, Inferior inferior,
                                       ref Inferior.ChildEvent cevent, out bool resume_target)
        {
            if (cevent.Type == Inferior.ChildEventType.CHILD_NOTIFICATION)
            {
                NotificationType type = (NotificationType)cevent.Argument;

                Report.Debug(DebugFlags.EventLoop,
                             "{0} received notification {1}: {2}",
                             engine, type, cevent);

                switch (type)
                {
                case NotificationType.AcquireGlobalThreadLock:
                    Report.Debug(DebugFlags.Threads,
                                 "{0} received notification {1}", engine, type);
                    engine.Process.AcquireGlobalThreadLock(engine);
                    break;

                case NotificationType.ReleaseGlobalThreadLock:
                    Report.Debug(DebugFlags.Threads,
                                 "{0} received notification {1}", engine, type);
                    engine.Process.ReleaseGlobalThreadLock(engine);
                    break;

                case NotificationType.ThreadCreated: {
                    TargetAddress data = new TargetAddress(
                        inferior.AddressDomain, cevent.Data2);

                    TargetAddress lmf = inferior.ReadAddress(data + 8);
                    engine.SetManagedThreadData(lmf, data + 24);

                    if (MonoDebuggerInfo.CheckRuntimeVersion(81, 3))
                    {
                        int         flags_offset = 56 + inferior.TargetAddressSize;
                        ThreadFlags flags        = (ThreadFlags)inferior.ReadInteger(data + flags_offset);
                        check_thread_flags(engine, flags);
                    }

                    Report.Debug(DebugFlags.Threads,
                                 "{0} managed thread created: {1:x} {2} {3} - {4}",
                                 engine, cevent.Data1, data, lmf, engine.LMFAddress);
                    break;
                }

                case NotificationType.ThreadCleanup: {
                    TargetAddress data = new TargetAddress(
                        inferior.AddressDomain, cevent.Data1);

                    Report.Debug(DebugFlags.Threads,
                                 "{0} managed thread cleanup: {1:x} {2}",
                                 engine, cevent.Data2, data);
                    break;
                }

                case NotificationType.GcThreadCreated: {
                    TargetAddress data = new TargetAddress(
                        inferior.AddressDomain, cevent.Data1);
                    long tid = cevent.Data2;

                    Report.Debug(DebugFlags.Threads,
                                 "{0} created gc thread: {1:x} {2}",
                                 engine, tid, data);

                    engine = engine.Process.GetEngineByTID(inferior, tid);
                    if (engine == null)
                    {
                        throw new InternalError();
                    }

                    engine.OnManagedThreadCreated(data);
                    break;
                }

                case NotificationType.GcThreadExited:
                    Report.Debug(DebugFlags.Threads, "{0} gc thread exited", engine);
                    engine.OnManagedThreadExited();
                    try {
                        inferior.Continue();
                    } catch {
                        // Ignore errors; for some reason, the thread may have died
                        // already by the time get this notification.
                    }
                    resume_target = false;
                    return(true);

                case NotificationType.InitializeThreadManager:
                    csharp_language = inferior.Process.CreateMonoLanguage(
                        debugger_info);
                    if (engine.Process.IsAttached)
                    {
                        csharp_language.InitializeAttach(inferior);
                    }
                    else
                    {
                        csharp_language.Initialize(inferior);
                    }

                    break;

                case NotificationType.ReachedMain: {
                    Inferior.StackFrame iframe = inferior.GetCurrentFrame(false);
                    engine.SetMainReturnAddress(iframe.StackPointer);
                    engine.Process.OnProcessReachedMainEvent();
                    resume_target = !engine.InitializeBreakpoints();
                    return(true);
                }

                case NotificationType.WrapperMain:
                    break;

                case NotificationType.MainExited:
                    engine.SetMainReturnAddress(TargetAddress.Null);
                    break;

                case NotificationType.UnhandledException:
                    cevent = new Inferior.ChildEvent(
                        Inferior.ChildEventType.UNHANDLED_EXCEPTION,
                        0, cevent.Data1, cevent.Data2);
                    resume_target = false;
                    return(false);

                case NotificationType.HandleException:
                    cevent = new Inferior.ChildEvent(
                        Inferior.ChildEventType.HANDLE_EXCEPTION,
                        0, cevent.Data1, cevent.Data2);
                    resume_target = false;
                    return(false);

                case NotificationType.ThrowException:
                    cevent = new Inferior.ChildEvent(
                        Inferior.ChildEventType.THROW_EXCEPTION,
                        0, cevent.Data1, cevent.Data2);
                    resume_target = false;
                    return(false);

                case NotificationType.FinalizeManagedCode:
                    mono_debugger_server_finalize_mono_runtime(mono_runtime_info);
                    mono_runtime_info = IntPtr.Zero;
                    csharp_language   = null;
                    break;

                case NotificationType.OldTrampoline:
                case NotificationType.Trampoline:
                    resume_target = false;
                    return(false);

                case NotificationType.ClassInitialized:
                    break;

                case NotificationType.InterruptionRequest:
                    inferior.WriteInteger(MonoDebuggerInfo.InterruptionRequest, 0);
                    var callbacks = managed_callbacks;
                    managed_callbacks = new Queue <ManagedCallbackData> ();
                    resume_target     = !engine.OnManagedCallback(callbacks);
                    return(true);

                default: {
                    TargetAddress data = new TargetAddress(
                        inferior.AddressDomain, cevent.Data1);

                    resume_target = csharp_language.Notification(
                        engine, inferior, type, data, cevent.Data2);
                    return(true);
                }
                }

                resume_target = true;
                return(true);
            }

            if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) &&
                (cevent.Argument == thread_abort_signal))
            {
                resume_target = true;
                return(true);
            }

            if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) && (cevent.Argument != 0) && !
                engine.Process.Session.Config.StopOnManagedSignals)
            {
                if (inferior.IsManagedSignal((int)cevent.Argument))
                {
                    resume_target = true;
                    return(true);
                }
            }

            resume_target = false;
            return(false);
        }