Inheritance: NativeExecutableReader, ISymbolContainer
Exemplo n.º 1
0
 protected void check_loaded_library(Inferior inferior, Bfd bfd)
 {
     if (!Process.MonoRuntimeFound)
     {
         check_for_mono_runtime(inferior, bfd);
     }
 }
Exemplo n.º 2
0
        public Bfd OpenCoreFile(string core_file)
        {
            Bfd core = new Bfd(os, info, core_file, TargetAddress.Null, true);

            core.is_coredump = true;
            return(core);
        }
        void check_for_mono_runtime(Inferior inferior, Bfd bfd)
        {
            TargetAddress info = bfd.GetSectionAddress(".mdb_debug_info");

            if (info.IsNull)
            {
                return;
            }

            TargetAddress data = inferior.ReadAddress(info);

            if (data.IsNull)
            {
                //
                // See CheckForPendingMonoInit() below - this should only happen when
                // the Mono runtime is embedded - for instance Moonlight inside Firefox.
                //
                // Note that we have to do a symbol lookup for it because we do not know
                // whether the mono runtime is recent enough to have this variable.
                //
                data = bfd.LookupSymbol("MONO_DEBUGGER__using_debugger");
                if (data.IsNull)
                {
                    Report.Error("Failed to initialize the Mono runtime!");
                    return;
                }

                inferior.WriteInteger(data, 1);
                pending_mono_init = info;
                return;
            }

            Process.InitializeMono(inferior, data);
        }
        void check_nptl_setxid(Inferior inferior, Bfd bfd)
        {
            if (setxid_breakpoint != null)
            {
                return;
            }

            TargetAddress vtable = bfd.LookupSymbol("__libc_pthread_functions");

            if (vtable.IsNull)
            {
                return;
            }

            /*
             * Big big hack to allow debugging gnome-vfs:
             * We intercept any calls to __nptl_setxid() and make it
             * return 0.  This is safe to do since we do not allow
             * debugging setuid programs or running as root, so setxid()
             * will always be a no-op anyways.
             */

            TargetAddress nptl_setxid = inferior.ReadAddress(vtable + 51 * inferior.TargetAddressSize);

            if (!nptl_setxid.IsNull)
            {
                setxid_breakpoint = new SetXidBreakpoint(this, nptl_setxid);
                setxid_breakpoint.Insert(inferior);
            }
        }
Exemplo n.º 5
0
        protected CoreFile(ThreadManager manager, ProcessStart start)
            : base(manager, start)
        {
            info = Inferior.GetTargetMemoryInfo(manager.AddressDomain);

            bfd = (Bfd)NativeLanguage.OperatingSystem.LoadExecutable(
                info, start.TargetApplication, true);

            core_file = start.CoreFile;

            core_bfd = bfd.OpenCoreFile(core_file);

#if FIXME
            string   crash_program      = core_bfd.CrashProgram;
            string[] crash_program_args = crash_program.Split(' ');

            if (crash_program_args [0] != application)
            {
                throw new TargetException(
                          TargetError.CannotStartTarget,
                          "Core file (generated from {0}) doesn't match executable {1}.",
                          crash_program, application);
            }

            bool ok;
            try {
                DateTime core_date = Directory.GetLastWriteTime(core_file);
                DateTime app_date  = Directory.GetLastWriteTime(application);

                ok = app_date < core_date;
            } catch {
                ok = false;
            }

            if (!ok)
            {
                throw new TargetException(
                          TargetError.CannotStartTarget,
                          "Executable {0} is more recent than core file {1}.",
                          application, core_file);
            }
#endif

            read_note_section();
            main_thread = (CoreFileThread)threads [0];

            TargetMemoryAccess target_access = ((CoreFileThread)threads [0]).TargetAccess;
            // bfd.UpdateSharedLibraryInfo (null, target_access);

            TargetAddress mdb_debug_info = bfd.GetSectionAddress(".mdb_debug_info");
            if (!mdb_debug_info.IsNull)
            {
                mdb_debug_info = main_thread.ReadAddress(mdb_debug_info);
                debugger_info  = MonoDebuggerInfo.Create(target_access, mdb_debug_info);
                read_thread_table();
                CreateMonoLanguage(debugger_info);
                mono_language.InitializeCoreFile(target_access);
                mono_language.Update(target_access);
            }
        }
Exemplo n.º 6
0
 public DwarfFrameReader(Bfd bfd, TargetBlob blob, long vma,
                         bool is_ehframe)
 {
     this.bfd        = bfd;
     this.blob       = blob;
     this.vma        = vma;
     this.is_ehframe = is_ehframe;
 }
Exemplo n.º 7
0
        public DwarfFrameReader(Bfd bfd, TargetBlob blob, long vma,
					 bool is_ehframe)
        {
            this.bfd = bfd;
            this.blob = blob;
            this.vma = vma;
            this.is_ehframe = is_ehframe;
        }
Exemplo n.º 8
0
        public void CloseBfd(Bfd bfd)
        {
            if (bfd == null)
            {
                return;
            }

            bfd_hash.Remove(bfd.FileName);
            bfd.Dispose();
        }
Exemplo n.º 9
0
        protected CoreFile(ThreadManager manager, ProcessStart start)
            : base(manager, start)
        {
            info = Inferior.GetTargetMemoryInfo (manager.AddressDomain);

            bfd = (Bfd) NativeLanguage.OperatingSystem.LoadExecutable (
                info, start.TargetApplication, true);

            core_file = start.CoreFile;

            core_bfd = bfd.OpenCoreFile (core_file);

            #if FIXME
            string crash_program = core_bfd.CrashProgram;
            string[] crash_program_args = crash_program.Split (' ');

            if (crash_program_args [0] != application)
                throw new TargetException (
                    TargetError.CannotStartTarget,
                    "Core file (generated from {0}) doesn't match executable {1}.",
                    crash_program, application);

            bool ok;
            try {
                DateTime core_date = Directory.GetLastWriteTime (core_file);
                DateTime app_date = Directory.GetLastWriteTime (application);

                ok = app_date < core_date;
            } catch {
                ok = false;
            }

            if (!ok)
                throw new TargetException (
                    TargetError.CannotStartTarget,
                    "Executable {0} is more recent than core file {1}.",
                    application, core_file);
            #endif

            read_note_section ();
            main_thread = (CoreFileThread) threads [0];

            TargetMemoryAccess target_access = ((CoreFileThread) threads [0]).TargetAccess;
            // bfd.UpdateSharedLibraryInfo (null, target_access);

            TargetAddress mdb_debug_info = bfd.GetSectionAddress (".mdb_debug_info");
            if (!mdb_debug_info.IsNull) {
                mdb_debug_info = main_thread.ReadAddress (mdb_debug_info);
                debugger_info = MonoDebuggerInfo.Create (target_access, mdb_debug_info);
                read_thread_table ();
                CreateMonoLanguage (debugger_info);
                mono_language.InitializeCoreFile (target_access);
                mono_language.Update (target_access);
            }
        }
Exemplo n.º 10
0
            internal Section(Bfd bfd, IntPtr section)
            {
                this.bfd     = bfd;
                this.section = section;

                this.name  = bfd_glue_get_section_name(section);
                this.vma   = bfd_glue_get_section_vma(section);
                this.size  = bfd_glue_get_section_size(section);
                this.flags = bfd_glue_get_section_flags(section);

                contents = new ObjectCache(
                    new ObjectCacheFunc(get_section_contents), section, 5);
            }
Exemplo n.º 11
0
        public override NativeExecutableReader LoadExecutable(TargetMemoryInfo memory, string filename,
								       bool load_native_symtabs)
        {
            check_disposed ();
            Bfd bfd = (Bfd) bfd_hash [filename];
            if (bfd != null)
                return bfd;

            bfd = new Bfd (this, memory, filename, TargetAddress.Null, true);
            bfd_hash.Add (filename, bfd);
            main_bfd = bfd;
            return bfd;
        }
Exemplo n.º 12
0
        void check_for_mono_runtime(Inferior inferior, Bfd bfd)
        {
            TargetAddress info = bfd.LookupSymbol("MONO_DEBUGGER__debugger_info_ptr");

            if (info.IsNull)
            {
                return;
            }

            TargetAddress data = inferior.ReadAddress(info);

            if (data.IsNull)
            {
                //
                // See CheckForPendingMonoInit() below - this should only happen when
                // the Mono runtime is embedded - for instance Moonlight inside Firefox.
                //
                // Note that we have to do a symbol lookup for it because we do not know
                // whether the mono runtime is recent enough to have this variable.
                //
                data = bfd.LookupSymbol("MONO_DEBUGGER__using_debugger");
                if (data.IsNull)
                {
                    Report.Error("Failed to initialize the Mono runtime!");
                    return;
                }

                inferior.WriteInteger(data, 1);
                pending_mono_init = info;

                // Add a breakpoint in mini_debugger_init, to make sure that InitializeMono()
                // gets called in time to set the breakpoint at debugger_initialize, needed to
                // initialize the notifications.
                TargetAddress mini_debugger_init = bfd.LookupSymbol("mini_debugger_init");
                if (!mini_debugger_init.IsNull)
                {
                    Instruction insn = inferior.Architecture.ReadInstruction(inferior, mini_debugger_init);
                    if ((insn == null) || !insn.CanInterpretInstruction)
                    {
                        throw new InternalError("Unknown dynlink breakpoint: {0}", mini_debugger_init);
                    }

                    DynlinkBreakpoint init_breakpoint = new DynlinkBreakpoint(this, insn);
                    init_breakpoint.Insert(inferior);
                }
                return;
            }

            Process.InitializeMono(inferior, data);
        }
Exemplo n.º 13
0
        public override NativeExecutableReader AddExecutableFile(Inferior inferior, string filename,
									  TargetAddress base_address, bool step_into,
									  bool is_loaded)
        {
            check_disposed ();
            Bfd bfd = (Bfd) bfd_hash [filename];
            if (bfd != null)
                return bfd;

            bfd = new Bfd (this, inferior.TargetMemoryInfo, filename, base_address, is_loaded);
            bfd_hash.Add (filename, bfd);
            check_loaded_library (inferior, bfd);
            return bfd;
        }
Exemplo n.º 14
0
        public override NativeExecutableReader LoadExecutable(TargetMemoryInfo memory, string filename,
                                                              bool load_native_symtabs)
        {
            check_disposed();
            Bfd bfd = (Bfd)bfd_hash [filename];

            if (bfd != null)
            {
                return(bfd);
            }

            bfd = new Bfd(this, memory, filename, TargetAddress.Null, true);
            bfd_hash.Add(filename, bfd);
            main_bfd = bfd;
            return(bfd);
        }
Exemplo n.º 15
0
        public override NativeExecutableReader AddExecutableFile(Inferior inferior, string filename,
                                                                 TargetAddress base_address, bool step_into,
                                                                 bool is_loaded)
        {
            check_disposed();
            Bfd bfd = (Bfd)bfd_hash [filename];

            if (bfd != null)
            {
                return(bfd);
            }

            bfd = new Bfd(this, inferior.TargetMemoryInfo, filename, base_address, is_loaded);
            bfd_hash.Add(filename, bfd);
            check_loaded_library(inferior, bfd);
            return(bfd);
        }
Exemplo n.º 16
0
        void read_dynamic_info(Inferior inferior)
        {
            if (has_dynlink_info)
            {
                if (!dyld_all_image_infos.IsNull)
                {
                    do_update_shlib_info(inferior);
                }
                return;
            }

            TargetMemoryInfo info = Inferior.GetTargetMemoryInfo(AddressDomain.Global);
            Bfd dyld_image        = new Bfd(this, info, "/usr/lib/dyld", TargetAddress.Null, true);

            dyld_all_image_infos = dyld_image.LookupSymbol("dyld_all_image_infos");
            if (dyld_all_image_infos.IsNull)
            {
                return;
            }


            int          size   = 2 * inferior.TargetLongIntegerSize + 2 * inferior.TargetAddressSize;
            TargetReader reader = new TargetReader(inferior.ReadMemory(dyld_all_image_infos, size));

            reader.ReadLongInteger();          // version
            reader.ReadLongInteger();          // infoArrayCount
            reader.ReadAddress();              // infoArray
            TargetAddress dyld_image_notifier = reader.ReadAddress();

            has_dynlink_info = true;

            Instruction insn = inferior.Architecture.ReadInstruction(inferior, dyld_image_notifier);

            if ((insn == null) || !insn.CanInterpretInstruction)
            {
                throw new InternalError("Unknown dynlink breakpoint: {0}", dyld_image_notifier);
            }

            dynlink_breakpoint = new DynlinkBreakpoint(this, insn);
            dynlink_breakpoint.Insert(inferior);

            do_update_shlib_info(inferior);

            check_loaded_library(inferior, main_bfd);
        }
Exemplo n.º 17
0
        public DwarfException(Bfd bfd, string message, params object[] args)
            : base(String.Format ("{0}: {1}", bfd.FileName,
					       String.Format (message, args)))
        {
        }
Exemplo n.º 18
0
 public BfdSymbolFile(Bfd bfd)
 {
     this.Bfd = bfd;
 }
Exemplo n.º 19
0
 public Bfd OpenCoreFile(string core_file)
 {
     Bfd core = new Bfd (os, info, core_file, TargetAddress.Null, true);
     core.is_coredump = true;
     return core;
 }
Exemplo n.º 20
0
 public BfdSymbolTable(Bfd bfd)
 {
     this.bfd = bfd;
 }
Exemplo n.º 21
0
 protected void check_loaded_library(Inferior inferior, Bfd bfd)
 {
     if (!Process.MonoRuntimeFound)
         check_for_mono_runtime (inferior, bfd);
 }
Exemplo n.º 22
0
            internal Section(Bfd bfd, IntPtr section)
            {
                this.bfd = bfd;
                this.section = section;

                this.name = bfd_glue_get_section_name (section);
                this.vma = bfd_glue_get_section_vma (section);
                this.size = bfd_glue_get_section_size (section);
                this.flags = bfd_glue_get_section_flags (section);

                contents = new ObjectCache (
                    new ObjectCacheFunc (get_section_contents), section, 5);
            }
Exemplo n.º 23
0
 public BfdSymbolTable(Bfd bfd)
 {
     this.bfd = bfd;
 }
Exemplo n.º 24
0
        void check_for_mono_runtime(Inferior inferior, Bfd bfd)
        {
            TargetAddress info = bfd.LookupSymbol ("MONO_DEBUGGER__debugger_info_ptr");
            if (info.IsNull)
                return;

            TargetAddress data = inferior.ReadAddress (info);
            if (data.IsNull) {
                //
                // See CheckForPendingMonoInit() below - this should only happen when
                // the Mono runtime is embedded - for instance Moonlight inside Firefox.
                //
                // Note that we have to do a symbol lookup for it because we do not know
                // whether the mono runtime is recent enough to have this variable.
                //
                data = bfd.LookupSymbol ("MONO_DEBUGGER__using_debugger");
                if (data.IsNull) {
                    Report.Error ("Failed to initialize the Mono runtime!");
                    return;
                }

                inferior.WriteInteger (data, 1);
                pending_mono_init = info;

                // Add a breakpoint in mini_debugger_init, to make sure that InitializeMono()
                // gets called in time to set the breakpoint at debugger_initialize, needed to
                // initialize the notifications.
                TargetAddress mini_debugger_init = bfd.LookupSymbol ("mini_debugger_init");
                if (!mini_debugger_init.IsNull)
                {
                    Instruction insn = inferior.Architecture.ReadInstruction (inferior, mini_debugger_init);
                    if ((insn == null) || !insn.CanInterpretInstruction)
                        throw new InternalError ("Unknown dynlink breakpoint: {0}", mini_debugger_init);

                    DynlinkBreakpoint init_breakpoint = new DynlinkBreakpoint (this, insn);
                    init_breakpoint.Insert (inferior);
                }
                return;
            }

            Process.InitializeMono (inferior, data);
        }
Exemplo n.º 25
0
        void read_dynamic_info(Inferior inferior)
        {
            if (has_dynlink_info) {
                if (!dyld_all_image_infos.IsNull)
                    do_update_shlib_info (inferior);
                return;
            }

            TargetMemoryInfo info = Inferior.GetTargetMemoryInfo (AddressDomain.Global);
			Bfd dyld_image = new Bfd (this, info, "/usr/lib/dyld", TargetAddress.Null, true);

            dyld_all_image_infos = dyld_image.LookupSymbol("dyld_all_image_infos");
            if (dyld_all_image_infos.IsNull)
                return;

            int size = 2 * inferior.TargetLongIntegerSize + 2 * inferior.TargetAddressSize;
            TargetReader reader = new TargetReader (inferior.ReadMemory (dyld_all_image_infos, size));

            reader.ReadLongInteger (); // version
            reader.ReadLongInteger (); // infoArrayCount
            reader.ReadAddress (); // infoArray
            TargetAddress dyld_image_notifier = reader.ReadAddress ();

            has_dynlink_info = true;

            Instruction insn = inferior.Architecture.ReadInstruction (inferior, dyld_image_notifier);
            if ((insn == null) || !insn.CanInterpretInstruction)
                throw new InternalError ("Unknown dynlink breakpoint: {0}", dyld_image_notifier);

            dynlink_breakpoint = new DynlinkBreakpoint (this, insn);
            dynlink_breakpoint.Insert (inferior);

            do_update_shlib_info (inferior);

            check_loaded_library (inferior, main_bfd);
Exemplo n.º 26
0
 public BfdSymbolFile(Bfd bfd)
 {
     this.Bfd = bfd;
 }
Exemplo n.º 27
0
 public static bool IsSupported(Bfd bfd)
 {
     if ((bfd.Target == "elf32-i386") || (bfd.Target == "elf64-x86-64"))
         return bfd.HasSection (".debug_info");
     else
         return false;
 }
Exemplo n.º 28
0
 public DwarfBinaryReader(Bfd bfd, TargetBlob blob, bool is64bit)
     : base(blob)
 {
     this.bfd = bfd;
     this.is64bit = is64bit;
 }
Exemplo n.º 29
0
        public DwarfReader(Bfd bfd, Module module)
        {
            this.bfd = bfd;
            this.module = module;
            this.filename = bfd.FileName;
            this.target_info = bfd.TargetMemoryInfo;

            debug_info_reader = create_reader (".debug_info", false);

            DwarfBinaryReader reader = DebugInfoReader;

            reader.ReadInitialLength (out is64bit);
            int version = reader.ReadInt16 ();
            if (version < 2)
                throw new DwarfException (
                    bfd, "Wrong DWARF version: {0}", version);

            reader.ReadOffset ();
            address_size = reader.ReadByte ();

            if ((address_size != 4) && (address_size != 8))
                throw new DwarfException (
                    bfd, "Unknown address size: {0}", address_size);

            debug_abbrev_reader = create_reader (".debug_abbrev", false);
            debug_line_reader = create_reader (".debug_line", false);
            debug_aranges_reader = create_reader (".debug_aranges", true);
            debug_pubnames_reader = create_reader (".debug_pubnames", true);
            debug_pubtypes_reader = create_reader (".debug_pubtypes", true);
            debug_str_reader = create_reader (".debug_str", true);
            debug_loc_reader = create_reader (".debug_loc", false);
            debug_ranges_reader = create_reader (".debug_ranges", true);

            compile_unit_hash = Hashtable.Synchronized (new Hashtable ());
            method_source_hash = Hashtable.Synchronized (new Hashtable ());
            method_hash = Hashtable.Synchronized (new Hashtable ());
            source_file_hash = Hashtable.Synchronized (new Hashtable ());

            if (bfd.IsLoaded) {
                aranges = ArrayList.Synchronized (read_aranges ());
                symtab = new DwarfSymbolTable (this, aranges);
                pubnames = read_pubnames ();
                // pubtypes = read_pubtypes ();
            }

            long offset = 0;
            while (offset < reader.Size) {
                CompileUnitBlock block = new CompileUnitBlock (this, offset);
                compile_unit_hash.Add (offset, block);
                offset += block.length;
            }
        }
Exemplo n.º 30
0
        void check_nptl_setxid(Inferior inferior, Bfd bfd)
        {
            if (setxid_breakpoint != null)
                return;

            TargetAddress vtable = bfd.LookupSymbol ("__libc_pthread_functions");
            if (vtable.IsNull)
                return;

            /*
             * Big big hack to allow debugging gnome-vfs:
             * We intercept any calls to __nptl_setxid() and make it
             * return 0.  This is safe to do since we do not allow
             * debugging setuid programs or running as root, so setxid()
             * will always be a no-op anyways.
             */

            TargetAddress nptl_setxid = inferior.ReadAddress (vtable + 51 * inferior.TargetAddressSize);

            if (!nptl_setxid.IsNull) {
                setxid_breakpoint = new SetXidBreakpoint (this, nptl_setxid);
                setxid_breakpoint.Insert (inferior);
            }
        }
Exemplo n.º 31
0
        public void CloseBfd(Bfd bfd)
        {
            if (bfd == null)
                return;

            bfd_hash.Remove (bfd.FileName);
            bfd.Dispose ();
Exemplo n.º 32
0
 public DwarfException(Bfd bfd, string message, Exception inner)
     : base(String.Format ("{0}: {1}", bfd.FileName, message), inner)
 {
 }
Exemplo n.º 33
0
        void check_for_mono_runtime(Inferior inferior, Bfd bfd)
        {
            TargetAddress info = bfd.GetSectionAddress (".mdb_debug_info");
            if (info.IsNull)
                return;

            TargetAddress data = inferior.ReadAddress (info);
            if (data.IsNull) {
                //
                // See CheckForPendingMonoInit() below - this should only happen when
                // the Mono runtime is embedded - for instance Moonlight inside Firefox.
                //
                // Note that we have to do a symbol lookup for it because we do not know
                // whether the mono runtime is recent enough to have this variable.
                //
                data = bfd.LookupSymbol ("MONO_DEBUGGER__using_debugger");
                if (data.IsNull) {
                    Report.Error ("Failed to initialize the Mono runtime!");
                    return;
                }

                inferior.WriteInteger (data, 1);
                pending_mono_init = info;
                return;
            }

            Process.InitializeMono (inferior, data);
        }