Ejemplo n.º 1
0
        public MonoClassType(MonoSymbolFile file, Cecil.TypeDefinition type)
            : base(file.MonoLanguage, TargetObjectKind.Class)
        {
            this.type = type;
            this.file = file;

            struct_type = new MonoStructType (file, this, type);

            if (type.GenericParameters.Count > 0) {
                StringBuilder sb = new StringBuilder (type.FullName);
                sb.Append ('<');
                for (int i = 0; i < type.GenericParameters.Count; i++) {
                    if (i > 0)
                        sb.Append (',');
                    sb.Append (type.GenericParameters [i].Name);
                }
                sb.Append ('>');
                full_name = sb.ToString ();
            } else
                full_name = type.FullName;

            DebuggerBrowsableState? browsable_state;
            MonoSymbolFile.CheckCustomAttributes (type,
                                  out browsable_state,
                                  out debugger_display,
                                  out type_proxy,
                                  out is_compiler_generated);
        }
Ejemplo n.º 2
0
        public MonoEnumType(MonoSymbolFile file, Cecil.TypeDefinition type)
            : base(file.MonoLanguage)
        {
            this.type = type;
            this.file = file;

            class_type = new MonoClassType (file, type);
        }
Ejemplo n.º 3
0
        public static void DumpLineNumberTable(TextWriter writer, MonoSymbolFile file,
							Cecil.MethodDefinition mdef, C.MethodEntry entry)
        {
            try {
                DumpLineNumberTable_internal (writer, file, mdef, entry);
            } catch (Exception ex) {
                writer.WriteLine ("DUMP LNT EX: {0}", ex);
            }
        }
Ejemplo n.º 4
0
 void close_symfile(MonoSymbolFile symfile)
 {
     symfile_by_image_addr.Remove (symfile.MonoImage);
     assembly_hash.Remove (symfile.Assembly);
     assembly_by_name.Remove (symfile.Assembly.Name.FullName);
     symfile_by_index.Remove (symfile.Index);
 }
Ejemplo n.º 5
0
        public MonoClassType(MonoSymbolFile file, Cecil.TypeDefinition typedef,
				      MonoClassInfo class_info)
            : this(file, typedef)
        {
            this.class_info = class_info;
        }
Ejemplo n.º 6
0
            private RangeEntry(MonoSymbolFile file, int domain, int index,
					    WrapperEntry wrapper, TargetAddress method,
					    TargetAddress start_address, TargetAddress end_address,
					    byte[] contents)
                : base(start_address, end_address)
            {
                this.File = file;
                this.Index = index;
                this.Hash = new MethodHashEntry (method, domain);
                this.Wrapper = wrapper;
                this.Contents = contents;
            }
Ejemplo n.º 7
0
 public WrapperMethod(MonoSymbolFile file, int domain, WrapperEntry entry)
     : base(entry.Name, file.ImageFile, file.Module)
 {
     this.File = file;
     this.Entry = entry;
     this.domain = domain;
     source = new WrapperMethodSource (this);
     SetWrapperType (entry.WrapperType);
 }
Ejemplo n.º 8
0
            protected MonoTypeTable(MonoSymbolFile file, TargetAddress ptr,
						 TargetAddress first_chunk)
                : base(ptr, first_chunk)
            {
                this.SymbolFile = file;
            }
Ejemplo n.º 9
0
            public MonoMethodLineNumberTable(MonoSymbolFile file, MonoMethod method,
							  MethodSource source, C.MethodEntry entry,
							  JitLineNumberEntry[] jit_lnt)
                : base(file, method)
            {
                this.method = method;
                this.entry = entry;
                this.line_numbers = jit_lnt;
            }
Ejemplo n.º 10
0
 public MonoStructType(MonoSymbolFile file, TargetClassType type, Cecil.TypeDefinition typedef)
 {
     this.File    = file;
     this.Type    = type;
     this.TypeDef = typedef;
 }
Ejemplo n.º 11
0
        public virtual void Emit()
        {
            if (Compiler.Settings.Target == Target.Module)
            {
                module_target_attrs = new AssemblyAttributesPlaceholder(module, name);
                module_target_attrs.CreateContainer();
                module_target_attrs.DefineContainer();
                module_target_attrs.Define();
                module.AddCompilerGeneratedClass(module_target_attrs);
            }
            else if (added_modules != null)
            {
                ReadModulesAssemblyAttributes();
            }

            if (Compiler.Settings.GenerateDebugInfo)
            {
                symbol_writer = new MonoSymbolFile();
            }

            module.EmitContainer();

            if (module.HasExtensionMethod)
            {
                var pa = module.PredefinedAttributes.Extension;
                if (pa.IsDefined)
                {
                    SetCustomAttribute(pa.Constructor, AttributeEncoder.Empty);
                }
            }

            if (!IsSatelliteAssembly)
            {
                if (!wrap_non_exception_throws_custom)
                {
                    PredefinedAttribute pa = module.PredefinedAttributes.RuntimeCompatibility;
                    if (pa.IsDefined && pa.ResolveBuilder())
                    {
                        var prop = module.PredefinedMembers.RuntimeCompatibilityWrapNonExceptionThrows.Get();
                        if (prop != null)
                        {
                            AttributeEncoder encoder = new AttributeEncoder();
                            encoder.EncodeNamedPropertyArgument(prop, new BoolLiteral(Compiler.BuiltinTypes, true, Location.Null));
                            SetCustomAttribute(pa.Constructor, encoder.ToArray());
                        }
                    }
                }

                if (declarative_security != null)
                {
#if STATIC
                    foreach (var entry in declarative_security)
                    {
                        Builder.__AddDeclarativeSecurity(entry);
                    }
#else
                    throw new NotSupportedException("Assembly-level security");
#endif
                }
            }

            CheckReferencesPublicToken();

            SetEntryPoint();
        }
Ejemplo n.º 12
0
        static void DumpLineNumberTable_internal(TextWriter writer, MonoSymbolFile file,
							  Cecil.MethodDefinition mdef, C.MethodEntry entry)
        {
            string full_name = MonoSymbolFile.GetMethodName (mdef);
            if (mdef.MetadataToken.TokenType != Cecil.Metadata.TokenType.Method) {
                writer.WriteLine ("UNKNOWN METHOD: {0}", full_name);
                return;
            }

            writer.WriteLine ();
            writer.WriteLine ("Symfile Line Numbers (file / row / offset):");
            writer.WriteLine ("-------------------------------------------");

            C.LineNumberEntry[] lnt;
            lnt = entry.GetLineNumberTable ().LineNumbers;
            for (int i = 0; i < lnt.Length; i++) {
                C.LineNumberEntry lne = lnt [i];

                writer.WriteLine ("{0,4} {1,4} {2,4} {3,4:x}{4}", i,
                          lne.File, lne.Row, lne.Offset,
                          lne.IsHidden ? " (hidden)" : "");
            }

            writer.WriteLine ("-------------------------------------------");
            writer.WriteLine ();

            List<string> lines;
            Dictionary<int,int> offsets;

            if (!DisassembleMethod_internal (file.ImageFile, (int) mdef.MetadataToken.RID, out lines, out offsets)) {
                writer.WriteLine ("Cannot disassemble method: {0}", full_name);
                return;
            }

            writer.WriteLine ("Disassembling {0}:\n\n{1}\n", full_name, String.Join ("\n", lines.ToArray ()));
        }
Ejemplo n.º 13
0
 public MdbModuleEntry(ModuleDefinition module, Stream symbolStream)
 {
     this.module = module;
     mdbReader   = new MdbReader(module, MonoSymbolFile.ReadSymbolFile(symbolStream));
 }
Ejemplo n.º 14
0
 protected MonoVoidType(MonoSymbolFile file, Cecil.TypeDefinition typedef)
     : base(file.MonoLanguage, TargetObjectKind.Unknown)
 {
     this.file    = file;
     this.typedef = typedef;
 }
Ejemplo n.º 15
0
        MonoSymbolFile load_symfile(TargetMemoryAccess memory, TargetAddress address)
        {
            MonoSymbolFile symfile = null;

            if (symfile_hash.Contains (address))
                return (MonoSymbolFile) symfile_hash [address];

            try {
                symfile = new MonoSymbolFile (this, process, memory, address);
            } catch (C.MonoSymbolFileException ex) {
                Console.WriteLine (ex.Message);
            } catch (SymbolTableException ex) {
                Console.WriteLine (ex.Message);
            } catch (Exception ex) {
                Console.WriteLine (ex);
            }

            symfile_hash.Add (address, symfile);

            if (symfile == null)
                return null;

            if (!assembly_by_name.Contains (symfile.Assembly.Name.FullName)) {
                assembly_hash.Add (symfile.Assembly, symfile);
                assembly_by_name.Add (symfile.Assembly.Name.FullName, symfile);
            }

            symfile_by_image_addr.Add (symfile.MonoImage, symfile);
            symfile_by_index.Add (symfile.Index, symfile);

            return symfile;
        }
Ejemplo n.º 16
0
        internal MonoClassType CreateCoreType(MonoSymbolFile file, Cecil.TypeDefinition typedef,
						       TargetMemoryAccess memory, TargetAddress klass)
        {
            MonoClassType type;
            MonoClassInfo info = MonoClassInfo.ReadCoreType (
                file, typedef, memory, klass, out type);
            class_info_by_addr.Add (klass, info);

            return type;
        }
Ejemplo n.º 17
0
        public void AddAssembly(string assemblyPath)
        {
            assemblyPath = Path.GetFullPath(assemblyPath);
            if (assemblies.ContainsKey(assemblyPath))
            {
                return;
            }

            if (!File.Exists(assemblyPath))
            {
                throw new ArgumentException("assemblyPath does not exist: " + assemblyPath);
            }

            var            assembly   = AssemblyDefinition.ReadAssembly(assemblyPath);
            MonoSymbolFile symbolFile = null;

            var symbolPath = assemblyPath + ".mdb";

            if (!File.Exists(symbolPath))
            {
                Debug.WriteLine(".mdb file was not found for " + assemblyPath);
            }
            else
            {
                symbolFile = MonoSymbolFile.ReadSymbolFile(assemblyPath + ".mdb");
            }

            var seqPointDataPath = assemblyPath + ".msym";

            if (!File.Exists(seqPointDataPath))
            {
                seqPointDataPath = null;
            }

            assemblies.Add(assemblyPath, new AssemblyLocationProvider(assembly, symbolFile, seqPointDataPath));

            directories.Add(Path.GetDirectoryName(assemblyPath));

            foreach (var assemblyRef in assembly.MainModule.AssemblyReferences)
            {
                string refPath = null;
                foreach (var dir in directories)
                {
                    refPath = Path.Combine(dir, assemblyRef.Name);
                    if (File.Exists(refPath))
                    {
                        break;
                    }
                    refPath = Path.Combine(dir, assemblyRef.Name + ".dll");
                    if (File.Exists(refPath))
                    {
                        break;
                    }
                    refPath = Path.Combine(dir, assemblyRef.Name + ".exe");
                    if (File.Exists(refPath))
                    {
                        break;
                    }
                    refPath = null;
                }
                if (refPath != null)
                {
                    AddAssembly(refPath);
                }
            }
        }
Ejemplo n.º 18
0
            public MonoMethod(MonoSymbolFile file, MethodSource source, int domain,
					   C.MethodEntry method, Cecil.MethodDefinition mdef)
                : base(source.Name, file.ImageFile, file.Module)
            {
                this.file = file;
                this.source = source;
                this.domain = domain;
                this.method = method;
                this.mdef = mdef;

                foreach (Cecil.CustomAttribute cattr in mdef.CustomAttributes) {
                    string cname = cattr.Constructor.DeclaringType.FullName;
                    if ((cname == "System.Diagnostics.DebuggerHiddenAttribute") ||
                        (cname == "System.Runtime.CompilerServices.CompilerGeneratedAttribute"))
                        is_compiler_generated = true;
                }
            }
Ejemplo n.º 19
0
 public AssemblyLocationProvider(AssemblyDefinition assembly, MonoSymbolFile symbolFile, string seqPointDataPath)
 {
     this.assembly         = assembly;
     this.symbolFile       = symbolFile;
     this.seqPointDataPath = seqPointDataPath;
 }
Ejemplo n.º 20
0
            public MonoMethodSource(MonoSymbolFile file, SourceFile source_file,
						 C.MethodEntry method, Cecil.MethodDefinition mdef,
						 MonoClassType klass, MonoFunctionType function)
            {
                this.file = file;
                this.source_file = source_file;
                this.method = method;
                this.mdef = mdef;
                this.function = function;
                this.klass = klass;

                full_name = method.GetRealName ();
                if (full_name == null)
                    full_name = MonoSymbolFile.GetMethodName (mdef);

                C.LineNumberEntry start, end;
                C.LineNumberTable lnt = method.GetLineNumberTable ();
                if (lnt.GetMethodBounds (out start, out end))
                    start_row = start.Row; end_row = end.Row;
            }
Ejemplo n.º 21
0
 public MdbReader(MonoSymbolFile symFile)
 {
     m_symFile   = symFile;
     m_documents = new Hashtable();
     m_scopes    = new Hashtable();
 }
Ejemplo n.º 22
0
            public static MonoTypeTable CreateTypeTable(MonoSymbolFile file,
								     TargetMemoryAccess memory,
								     TargetAddress ptr)
            {
                TargetAddress first_chunk = memory.ReadAddress (ptr + 8);
                return new MonoTypeTable (file, ptr, first_chunk);
            }
Ejemplo n.º 23
0
 public MdbReader(ModuleDefinition module, MonoSymbolFile symFile)
 {
     this.module      = module;
     this.symbol_file = symFile;
     this.documents   = new Dictionary <string, Document> ();
 }
Ejemplo n.º 24
0
 public MonoSymbolTable(MonoSymbolFile file)
 {
     this.file = file;
 }
Ejemplo n.º 25
0
 public virtual void WriteDebugSymbol(MonoSymbolFile file)
 {
 }
Ejemplo n.º 26
0
            public static RangeEntry Create(MonoSymbolFile file, TargetMemoryAccess memory,
							 TargetReader reader, byte[] contents)
            {
                int domain = reader.BinaryReader.ReadInt32 ();
                int index = reader.BinaryReader.ReadInt32 ();

                TargetAddress wrapper_data = reader.ReadAddress ();
                TargetAddress method = reader.ReadAddress ();
                reader.ReadAddress (); /* address_list */
                TargetAddress code_start = reader.ReadAddress ();
                TargetAddress wrapper_addr = reader.ReadAddress ();
                int code_size = reader.BinaryReader.ReadInt32 ();

                WrapperEntry wrapper = null;

                if (!wrapper_data.IsNull) {
                    int wrapper_size = 4 + 3 * memory.TargetMemoryInfo.TargetAddressSize;

                    TargetReader wrapper_reader = new TargetReader (
                        memory.ReadMemory (wrapper_data, wrapper_size));

                    TargetAddress name_address = wrapper_reader.ReadAddress ();
                    TargetAddress cil_address = wrapper_reader.ReadAddress ();
                    int wrapper_type = wrapper_reader.BinaryReader.ReadInt32 ();

                    string name = "<" + memory.ReadString (name_address) + ">";
                    string cil_code = memory.ReadString (cil_address);

                    wrapper = new WrapperEntry (
                        wrapper_addr, (WrapperType) wrapper_type, name, cil_code);
                }

                return new RangeEntry (
                    file, domain, index, wrapper, method,
                    code_start, code_start + code_size, contents);
            }
Ejemplo n.º 27
0
 public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName)
 {
     return(new MdbReader(MonoSymbolFile.ReadSymbolFile(fileName)));
 }
Ejemplo n.º 28
0
 public MdbReader(MonoSymbolFile symFile)
 {
     symbol_file = symFile;
     documents   = new Dictionary <string, Document> ();
 }
Ejemplo n.º 29
0
        public void ReadFromFile(string fileName)
        {
            dataFileName = fileName;
            namespaces   = new Hashtable();
            classes      = new Hashtable();

            long begin = DateTime.Now.Ticks / 10000;
            long msec  = DateTime.Now.Ticks / 10000;
            long msec2;

            loadedAssemblies = new Hashtable();
            symbolFiles      = new Hashtable();

            XmlDocument dom = new XmlDocument();

            Progress("XML reading", 0);
            Console.Write("Loading " + fileName + "...");
            dom.Load(new XmlTextReader(new FileStream(fileName, FileMode.Open)));
            Console.WriteLine(" Done.");

            msec2 = DateTime.Now.Ticks / 10000;
            Console.WriteLine("XML Reading: " + (msec2 - msec) + " msec");
            msec = msec2;

            Progress("Load assemblies", 0.2);
            LoadAssemblies(dom);

            LoadFilters(dom);

            msec2 = DateTime.Now.Ticks / 10000;
            Console.WriteLine("Load assemblies: " + (msec2 - msec) + " msec");
            msec = msec2;

            Progress("Load methods", 0.4);
            foreach (XmlNode n in dom.GetElementsByTagName("method"))
            {
                string assemblyName = n.Attributes ["assembly"].Value;
                string className    = n.Attributes ["class"].Value;
                string methodName   = n.Attributes ["name"].Value;
                string token        = n.Attributes ["token"].Value;
                if (n.FirstChild == null)
                {
                    continue;
                }
                string cov_info = n.FirstChild.Value;
                int    itok     = int.Parse(token);

#if USE_REFLECTION
                Assembly       assembly   = (Assembly)loadedAssemblies [assemblyName];
                MonoSymbolFile symbolFile = (MonoSymbolFile)symbolFiles [assembly];

                if (symbolFile == null)
                {
                    continue;
                }

                Type t = LoadType(assembly, className);
                if (t == null)
                {
                    Console.WriteLine("ERROR: Unable to resolve type " + className + " in " + assembly);
                    continue;
                }

                ClassCoverageItem klass = ProcessClass(t);

                MethodEntry entry = symbolFile.GetMethodByToken(Int32.Parse(token));

                Module[] modules = assembly.GetModules();

                if (modules.Length > 1)
                {
                    Console.WriteLine("WARNING: Assembly had more than one module. Using the first.");
                }

                Module module = modules[0];

                MethodBase monoMethod = module.ResolveMethod(Int32.Parse(token));

                ProcessMethod(monoMethod, entry, klass, methodName, cov_info);
#else
                if ((TokenType)(itok & 0xff000000) != TokenType.Method)
                {
                    continue;
                }
                AssemblyDefinition assembly   = (AssemblyDefinition)loadedAssemblies [assemblyName];
                MonoSymbolFile     symbolFile = (MonoSymbolFile)symbolFiles [assembly];

                if (symbolFile == null)
                {
                    continue;
                }

                TypeDefinition t = LoadType(assembly, className);
                if (t == null)
                {
                    Console.WriteLine("ERROR: Unable to resolve type " + className + " in " + assembly);
                    continue;
                }

                ClassCoverageItem klass = ProcessClass(t);

                MethodEntry entry = symbolFile.GetMethodByToken(itok);

                MethodDefinition monoMethod = assembly.MainModule.LookupToken(
                    new MetadataToken((TokenType)(itok & 0xff000000), (uint)(itok & 0xffffff)))
                                              as MethodDefinition;
                //Console.WriteLine (monoMethod);
                ProcessMethod(monoMethod, entry, klass, methodName, cov_info);
#endif
            }

            msec2 = DateTime.Now.Ticks / 10000;
            Console.WriteLine("Process methods: " + (msec2 - msec) + " msec");
            msec = msec2;

            // Add info for klasses for which we have no coverage

#if USE_REFLECTION
            foreach (Assembly assembly in loadedAssemblies.Values)
            {
                foreach (Type t in assembly.GetTypes())
                {
                    ProcessClass(t);
                }
            }

            // Add info for methods for which we have no coverage

            foreach (ClassCoverageItem klass in classes.Values)
            {
                foreach (MethodInfo mb in klass.type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    MonoSymbolFile symbolFile = (MonoSymbolFile)symbolFiles [klass.type.Assembly];
                    if (symbolFile == null)
                    {
                        continue;
                    }

                    if (!klass.methodsByMethod.ContainsKey(mb))
                    {
                        MethodEntry entry = symbolFile.GetMethod(mb);
                        ProcessMethod(mb, entry, klass, mb.Name, null);
                    }
                }
            }
#else
            Progress("Not covered classes", 0.6);
            foreach (AssemblyDefinition assembly in loadedAssemblies.Values)
            {
                foreach (TypeDefinition t in assembly.MainModule.Types)
                {
                    ProcessClass(t);
                }
            }

            Progress("Not covered methods", 0.7);
            // Add info for methods for which we have no coverage
            foreach (ClassCoverageItem klass in classes.Values)
            {
                foreach (MethodDefinition mb in klass.type.Methods)
                {
                    MonoSymbolFile symbolFile = (MonoSymbolFile)symbolFiles [klass.type.Module.Assembly];
                    if (symbolFile == null)
                    {
                        continue;
                    }

                    if (!klass.methodsByMethod.ContainsKey(mb))
                    {
                        MethodEntry entry = symbolFile.GetMethodByToken((int)mb.MetadataToken.ToUInt32());
                        ProcessMethod(mb, entry, klass, mb.Name, null);
                    }
                }
            }
#endif

            msec2 = DateTime.Now.Ticks / 10000;
            Console.WriteLine("Additional classes: " + (msec2 - msec) + " msec");
            msec = msec2;

            Progress("Compute coverage", 0.9);
            // Compute coverage for all items

            computeCoverage(true);

            msec2 = DateTime.Now.Ticks / 10000;
            Console.WriteLine("Compute coverage: " + (msec2 - msec) + " msec");
            msec = msec2;

            Console.WriteLine("All: " + (msec2 - begin) + " msec");
            Progress("Done loading", 0.9);

            // Free memory
            symbolFiles = null;
        }
Ejemplo n.º 30
0
        // This method reads the MonoDebuggerSymbolTable structure
        // (struct definition is in mono-debug-debugger.h)
        void do_read_symbol_table(TargetMemoryAccess memory)
        {
            TargetAddress symtab_address = memory.ReadAddress (info.SymbolTable);
            if (symtab_address.IsNull)
                throw new SymbolTableException ("Symbol table is null.");

            TargetReader header = new TargetReader (
                memory.ReadMemory (symtab_address, info.SymbolTableSize));

            long magic = header.BinaryReader.ReadInt64 ();
            if (magic != MonoDebuggerInfo.DynamicMagic)
                throw new SymbolTableException (
                    "Debugger symbol table has unknown magic {0:x}.", magic);

            int version = header.ReadInteger ();
            if (version < MonoDebuggerInfo.MinDynamicVersion)
                throw new SymbolTableException (
                    "Debugger symbol table has version {0}, but " +
                    "expected at least {1}.", version,
                    MonoDebuggerInfo.MinDynamicVersion);
            if (version > MonoDebuggerInfo.MaxDynamicVersion)
                throw new SymbolTableException (
                    "Debugger symbol table has version {0}, but " +
                    "expected at most {1}.", version,
                    MonoDebuggerInfo.MaxDynamicVersion);

            int total_size = header.ReadInteger ();
            if (total_size != info.SymbolTableSize)
                throw new SymbolTableException (
                    "Debugger symbol table has size {0}, but " +
                    "expected {1}.", total_size, info.SymbolTableSize);

            TargetAddress corlib_address = header.ReadAddress ();
            TargetAddress global_data_table_ptr = header.ReadAddress ();
            TargetAddress data_table_list = header.ReadAddress ();

            TargetAddress symfile_by_index = header.ReadAddress ();

            if (corlib_address.IsNull)
                throw new SymbolTableException ("Corlib address is null.");
            corlib = load_symfile (memory, corlib_address);
            if (corlib == null)
                throw new SymbolTableException ("Cannot read corlib!");

            TargetAddress ptr = symfile_by_index;
            while (!ptr.IsNull) {
                TargetAddress next_ptr = memory.ReadAddress (ptr);
                TargetAddress address = memory.ReadAddress (
                    ptr + memory.TargetMemoryInfo.TargetAddressSize);

                ptr = next_ptr;
                load_symfile (memory, address);
            }

            ptr = data_table_list;
            while (!ptr.IsNull) {
                TargetAddress next_ptr = memory.ReadAddress (ptr);
                TargetAddress address = memory.ReadAddress (
                    ptr + memory.TargetMemoryInfo.TargetAddressSize);

                ptr = next_ptr;
                add_data_table (memory, address);
            }

            global_data_table = new GlobalDataTable (this, global_data_table_ptr);
        }
Ejemplo n.º 31
0
        private void LoadAssemblies(XmlDocument dom)
        {
            foreach (XmlNode n in dom.GetElementsByTagName("assembly"))
            {
                string         assemblyName = n.Attributes ["name"].Value;
                string         guid         = n.Attributes ["guid"].Value;
                string         filename     = n.Attributes ["filename"].Value;
                MonoSymbolFile symbolFile;

                if (!File.Exists(filename))
                {
                    string newFilename = Path.Combine(Path.GetDirectoryName(dataFileName), Path.GetFileName(filename));
                    if (File.Exists(newFilename))
                    {
                        filename = newFilename;
                    }
                }

#if USE_REFLECTION
                Assembly assembly = Assembly.Load(assemblyName);

                MethodInfo getguid = typeof(Module).GetMethod(
                    "Mono_GetGuid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                    null, CallingConventions.Any, new Type [0], null);

                if (getguid != null)
                {
                    Guid assembly_guid = (Guid)getguid.Invoke(assembly.GetLoadedModules()[0], new object [0]);
                    Console.WriteLine(assembly_guid);
                    if (assembly_guid != new Guid(guid))
                    {
                        Console.WriteLine("WARNING: Loaded version of assembly " + assembly + " is different from the version used to collect coverage data.");
                    }
                }
                else
                {
                    Console.WriteLine("WARNING: Can't verify the guid of " + assembly);
                }

                loadedAssemblies [assemblyName] = assembly;

                Console.Write("Reading symbols for " + assembly + " ...");
                symbolFile = MonoSymbolFile.ReadSymbolFile(assembly);
                if (symbolFile == null)
                {
                    Console.WriteLine(" (No symbols found)");
                }
                else
                {
                    symbolFiles [assembly] = symbolFile;
                    Console.WriteLine(" (" + symbolFile.SourceCount + " files, " + symbolFile.MethodCount + " methods)");
                }
#else
                AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(filename);
                ModuleDefinition   module   = assembly.MainModule;
                if (module.Mvid != new Guid(guid))
                {
                    Console.WriteLine("WARNING: Loaded version of assembly " + assembly + " is different from the version used to collect coverage data.");
                }
                loadedAssemblies [assemblyName] = assembly;

                Console.Write("Reading symbols for " + assemblyName + " ...");
                symbolFile = MonoSymbolFile.ReadSymbolFile(filename + ".mdb");
                if (symbolFile == null)
                {
                    Console.WriteLine(" (No symbols found)");
                }
                else
                {
                    symbolFiles [assembly] = symbolFile;
                    Console.WriteLine(" (" + symbolFile.SourceCount + " files, " + symbolFile.MethodCount + " methods)");
                }
#endif
            }
        }
Ejemplo n.º 32
0
        public MonoBuiltinTypeInfo(MonoSymbolFile corlib, TargetMemoryAccess memory)
        {
            this.Corlib = corlib;

            MonoLanguageBackend mono = corlib.MonoLanguage;

            ObjectType = MonoObjectType.Create (corlib, memory);
            VoidType = MonoVoidType.Create (corlib, memory);

            StringType = MonoStringType.Create (corlib, memory);

            BooleanType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Boolean);
            CharType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Char);
            ByteType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Byte);
            SByteType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.SByte);
            Int16Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Int16);
            UInt16Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.UInt16);
            Int32Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Int32);
            UInt32Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.UInt32);
            Int64Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Int64);
            UInt64Type = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.UInt64);
            SingleType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Single);
            DoubleType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Double);

            IntType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.IntPtr);
            UIntType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.UIntPtr);

            DecimalType = MonoFundamentalType.Create (
                corlib, memory, FundamentalKind.Decimal);
            Cecil.TypeDefinition decimal_type = corlib.ModuleDefinition.GetType ("System.Decimal");
            corlib.AddType (decimal_type, DecimalType);

            TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetArrayClass (memory);
            Cecil.TypeDefinition array_type = corlib.ModuleDefinition.GetType ("System.Array");
            ArrayType = mono.CreateCoreType (corlib, array_type, memory, klass);
            mono.AddCoreType (array_type, ArrayType, ArrayType, klass);

            klass = corlib.MonoLanguage.MetadataHelper.GetDelegateClass (memory);
            Cecil.TypeDefinition delegate_type = corlib.ModuleDefinition.GetType ("System.Delegate");
            DelegateType = new MonoClassType (corlib, delegate_type);
            mono.AddCoreType (delegate_type, DelegateType, DelegateType, klass);

            klass = corlib.MonoLanguage.MetadataHelper.GetExceptionClass (memory);
            Cecil.TypeDefinition exception_type = corlib.ModuleDefinition.GetType ("System.Exception");
            ExceptionType = mono.CreateCoreType (corlib, exception_type, memory, klass);
            mono.AddCoreType (exception_type, ExceptionType, ExceptionType, klass);
        }
Ejemplo n.º 33
0
            protected MonoLineNumberTable(MonoSymbolFile file, Method method)
            {
                this.File = file;
                this.Method = method;

                this.start = method.StartAddress;
                this.end = method.EndAddress;
            }
Ejemplo n.º 34
0
 public MonoStructType(MonoSymbolFile file, TargetClassType type, Cecil.TypeDefinition typedef)
 {
     this.File = file;
     this.Type = type;
     this.TypeDef = typedef;
 }
Ejemplo n.º 35
0
    static void DumpSymbolFile(AssemblyDefinition assembly, MonoSymbolFile symbolFile, TextWriter output)
    {
        using (XmlTextWriter writer = new XmlTextWriter(output)) {
            writer.Formatting = Formatting.Indented;

            writer.WriteStartDocument();

            writer.WriteStartElement("symbols");

            writer.WriteStartElement("files");
            foreach (var file in symbolFile.Sources)
            {
                writer.WriteStartElement("file");
                writer.WriteAttributeString("id", file.Index.ToString());
                writer.WriteAttributeString("name", Path.GetFileName(file.FileName));
                var checksum = file.Checksum;
                if (checksum != null)
                {
                    writer.WriteAttributeString("checksum", ChecksumToString(checksum));
                }

                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteStartElement("methods");
            foreach (var method in symbolFile.Methods)
            {
                writer.WriteStartElement("method");
                writer.WriteAttributeString("token", IntToHex(method.Token));
                writer.WriteAttributeString("signature", assembly.MainModule.LookupToken(method.Token).ToString());

                var il_entries = method.GetLineNumberTable();
                writer.WriteStartElement("sequencepoints");
                foreach (var entry in il_entries.LineNumbers)
                {
                    writer.WriteStartElement("entry");
                    writer.WriteAttributeString("il", IntToHex(entry.Offset));
                    writer.WriteAttributeString("row", entry.Row.ToString());
                    writer.WriteAttributeString("col", entry.Column.ToString());
                    if (entry.EndRow != -1 || entry.EndColumn != -1)
                    {
                        writer.WriteAttributeString("end_row", entry.EndRow.ToString());
                        writer.WriteAttributeString("end_col", entry.EndColumn.ToString());
                    }
                    writer.WriteAttributeString("file_ref", entry.File.ToString());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteStartElement("locals");
                foreach (var local in method.GetLocals())
                {
                    writer.WriteStartElement("entry");
                    writer.WriteAttributeString("name", local.Name);
                    writer.WriteAttributeString("il_index", local.Index.ToString());
                    writer.WriteAttributeString("scope_ref", local.BlockIndex.ToString());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteStartElement("scopes");
                foreach (var scope in method.GetCodeBlocks())
                {
                    writer.WriteStartElement("entry");
                    writer.WriteAttributeString("index", scope.Index.ToString());
                    writer.WriteAttributeString("start", IntToHex(scope.StartOffset));
                    writer.WriteAttributeString("end", IntToHex(scope.EndOffset));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
    }