Inheritance: Mono.Debugger.DebuggerMarshalByRefObject, IDisposable
示例#1
0
        public NativeLanguage(Process process, OperatingSystemBackend os, TargetInfo info)
        {
            this.process = process;
            this.os = os;
            this.info = info;

            this.type_hash = Hashtable.Synchronized (new Hashtable ());

            integer_type = new NativeFundamentalType (this, "int", FundamentalKind.Int32, 4);
            unsigned_type = new NativeFundamentalType (this, "unsigned int", FundamentalKind.UInt32, 4);
            long_type = new NativeFundamentalType (this, "long", FundamentalKind.Int64, 8);
            ulong_type = new NativeFundamentalType (this, "unsigned long", FundamentalKind.UInt64, 8);
            pointer_type = new NativePointerType (this, "void *", info.TargetAddressSize);
            void_type = new NativeOpaqueType (this, "void", 0);
            string_type = new NativeStringType (this, info.TargetAddressSize);
        }
示例#2
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);
        }
示例#3
0
        internal Process(ThreadManager manager, ProcessStart start)
            : this(manager, start.Session)
        {
            this.start = start;

            is_attached = start.PID != 0;

            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);

            session.OnProcessCreated (this);
        }
示例#4
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);
        }
示例#5
0
        private Process(Process parent, int pid)
            : this(parent.manager, parent.session)
        {
            this.start = new ProcessStart (parent.ProcessStart, pid);

            this.is_forked = true;
            this.initialized = true;

            this.parent = parent;

            breakpoint_manager = new BreakpointManager (parent.breakpoint_manager);

            exception_handlers = new Dictionary<int,ExceptionCatchPoint> ();
            foreach (KeyValuePair<int,ExceptionCatchPoint> catchpoint in parent.exception_handlers)
                exception_handlers.Add (catchpoint.Key, catchpoint.Value);

            symtab_manager = parent.symtab_manager;

            native_language = parent.native_language;
            os = parent.os;
        }
示例#6
0
        public Bfd(OperatingSystemBackend os, TargetMemoryInfo info, string filename,
                   TargetAddress base_address, bool is_loaded)
        {
            this.os           = os;
            this.info         = info;
            this.filename     = filename;
            this.base_address = base_address;
            this.is_loaded    = is_loaded;

            this.symfile = new BfdSymbolFile(this);

            bfd = bfd_glue_openr(filename, null);
            if (bfd == IntPtr.Zero)
            {
                throw new SymbolTableException("Can't read symbol file: {0}", filename);
            }

            if (bfd_glue_check_format_archive(bfd))
            {
                IntPtr archive = bfd;
                bfd = IntPtr.Zero;

                while (true)
                {
                    bfd = bfd_glue_openr_next_archived_file(archive, bfd);
                    if (bfd == IntPtr.Zero)
                    {
                        throw new SymbolTableException("Can't read symbol file: {0}", filename);
                    }

                    if (bfd_glue_check_format_object(bfd))
                    {
                        /*
                         * At this point, just check for mach-o-le (OS X X86 binary).
                         * When we want to support other architctures in fat binarys,
                         * we need to somehow get the correct target string for the
                         * process, and chech against that.
                         */
                        if (bfd_glue_get_target_name(bfd) == "mach-o-le")
                        {
                            break;
                        }
                    }
                }
            }

            if (bfd_glue_check_format_object(bfd))
            {
                is_coredump = false;
            }
            else if (bfd_glue_check_format_core(bfd))
            {
                is_coredump = true;
            }
            else
            {
                throw new SymbolTableException("Not an object file: {0}", filename);
            }

            target = bfd_glue_get_target_name(bfd);
            if ((target == "elf32-i386") || (target == "elf64-x86-64"))
            {
                if (!is_coredump)
                {
                    Section text = GetSectionByName(".text", false);
                    Section bss  = GetSectionByName(".bss", false);

                    if ((text != null) && (bss != null))
                    {
                        if (!base_address.IsNull)
                        {
                            start_address = new TargetAddress(
                                info.AddressDomain,
                                base_address.Address + text.vma);
                        }
                        else
                        {
                            start_address = new TargetAddress(
                                info.AddressDomain, text.vma);
                        }

                        if (!base_address.IsNull)
                        {
                            end_address = new TargetAddress(
                                info.AddressDomain,
                                base_address.Address + bss.vma + bss.size);
                        }
                        else
                        {
                            end_address = new TargetAddress(
                                info.AddressDomain, bss.vma + bss.size);
                        }
                    }
                }

                read_bfd_symbols();

                if (DwarfReader.IsSupported(this))
                {
                    has_debugging_info = true;
                }

                Section plt_section = GetSectionByName(".plt", false);
                Section got_section = GetSectionByName(".got", false);
                if ((plt_section != null) && (got_section != null))
                {
                    plt_start = new TargetAddress(
                        info.AddressDomain,
                        base_address.Address + plt_section.vma);
                    plt_end = plt_start + plt_section.size;

                    got_start = new TargetAddress(
                        info.AddressDomain,
                        base_address.Address + got_section.vma);
                    has_got = true;
                }
            }
            else if (target == "mach-o-le")
            {
                if (!is_coredump)
                {
                    read_sections();
                    long start = 0xffffffff;
                    long end   = 0;
                    foreach (Section section in sections)
                    {
                        long relocated = base_address.Address + section.vma;

                        if (relocated < start)
                        {
                            start = relocated;
                        }
                        if (relocated + section.size > end)
                        {
                            end = relocated + section.size;
                        }
                    }

                    start_address = new TargetAddress(info.AddressDomain, start);
                    end_address   = new TargetAddress(info.AddressDomain, end);
                }

                read_bfd_symbols();

                if (DwarfReader.IsSupported(this))
                {
                    has_debugging_info = true;
                }

                has_got = false;
            }
            else
            {
                throw new SymbolTableException(
                          "Symbol file {0} has unknown target architecture {1}",
                          filename, target);
            }

            long entry_point_addr = bfd_glue_get_start_address(bfd);

            entry_point = entry_point_addr != 0 ? new TargetAddress(info.AddressDomain, entry_point_addr) : TargetAddress.Null;

            module = os.Process.Session.GetModule(filename);
            if (module == null)
            {
                module = os.Process.Session.CreateModule(filename, symfile);
                OnModuleChanged();
            }
            else
            {
                module.LoadModule(symfile);
            }

            os.Process.SymbolTableManager.AddSymbolFile(symfile);
        }
示例#7
0
文件: Bfd.cs 项目: baulig/debugger
        public Bfd(OperatingSystemBackend os, TargetMemoryInfo info, string filename,
			    TargetAddress base_address, bool is_loaded)
        {
            this.os = os;
            this.info = info;
            this.filename = filename;
            this.base_address = base_address;
            this.is_loaded = is_loaded;

            this.symfile = new BfdSymbolFile (this);

            bfd = bfd_glue_openr (filename, null);
            if (bfd == IntPtr.Zero)
                throw new SymbolTableException ("Can't read symbol file: {0}", filename);

            if (bfd_glue_check_format_archive (bfd))
            {
                IntPtr archive = bfd;
                bfd = IntPtr.Zero;

                while (true) {
                    bfd = bfd_glue_openr_next_archived_file (archive, bfd);
                    if(bfd == IntPtr.Zero)
                        throw new SymbolTableException ("Can't read symbol file: {0}", filename);

                    if (bfd_glue_check_format_object(bfd))
                    {
                        /*
                         * At this point, just check for mach-o-le (OS X X86 binary).
                         * When we want to support other architctures in fat binarys,
                         * we need to somehow get the correct target string for the
                         * process, and chech against that.
                         */
                        if (bfd_glue_get_target_name(bfd) == "mach-o-le")
                            break;
                    }
                }
            }

            if (bfd_glue_check_format_object (bfd))
                is_coredump = false;
            else if (bfd_glue_check_format_core (bfd))
                is_coredump = true;
            else
                throw new SymbolTableException ("Not an object file: {0}", filename);

            target = bfd_glue_get_target_name (bfd);
            if ((target == "elf32-i386") || (target == "elf64-x86-64")) {
                if (!is_coredump) {
                    Section text = GetSectionByName (".text", false);
                    Section bss = GetSectionByName (".bss", false);

                    if ((text != null) && (bss != null)) {
                        if (!base_address.IsNull)
                            start_address = new TargetAddress (
                                info.AddressDomain,
                                base_address.Address + text.vma);
                        else
                            start_address = new TargetAddress (
                                info.AddressDomain, text.vma);

                        if (!base_address.IsNull)
                            end_address = new TargetAddress (
                                info.AddressDomain,
                                base_address.Address + bss.vma + bss.size);
                        else
                            end_address = new TargetAddress (
                                info.AddressDomain, bss.vma + bss.size);
                    }
                }

                read_bfd_symbols ();

                if (DwarfReader.IsSupported (this))
                    has_debugging_info = true;

                Section plt_section = GetSectionByName (".plt", false);
                Section got_section = GetSectionByName (".got", false);
                if ((plt_section != null) && (got_section != null)) {
                    plt_start = new TargetAddress (
                        info.AddressDomain,
                        base_address.Address + plt_section.vma);
                    plt_end = plt_start + plt_section.size;

                    got_start = new TargetAddress (
                        info.AddressDomain,
                        base_address.Address + got_section.vma);
                    has_got = true;
                }
            } else if (target == "mach-o-le") {
                if (!is_coredump) {
                    read_sections ();
                    long start = 0xffffffff;
                    long end = 0;
                    foreach (Section section in sections) {
                        long relocated = base_address.Address + section.vma;

                        if (relocated < start)
                            start = relocated;
                        if (relocated + section.size > end)
                            end = relocated + section.size;
                    }

                    start_address = new TargetAddress (info.AddressDomain, start);
                    end_address = new TargetAddress (info.AddressDomain, end);
                }

                read_bfd_symbols ();

                if (DwarfReader.IsSupported (this))
                    has_debugging_info = true;

                has_got = false;
            } else
                throw new SymbolTableException (
                    "Symbol file {0} has unknown target architecture {1}",
                    filename, target);

            long entry_point_addr = bfd_glue_get_start_address (bfd);
            entry_point = entry_point_addr != 0 ? new TargetAddress (info.AddressDomain, entry_point_addr) : TargetAddress.Null;

            module = os.Process.Session.GetModule (filename);
            if (module == null) {
                module = os.Process.Session.CreateModule (filename, symfile);
                OnModuleChanged ();
            } else {
                module.LoadModule (symfile);
            }

            os.Process.SymbolTableManager.AddSymbolFile (symfile);
        }