MonoPPDBFile* mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size) { MonoImage *ppdb_image = NULL; const char *filename; char *s, *ppdb_filename; MonoImageOpenStatus status; guint8 pe_guid [16]; gint32 pe_age; gint32 pe_timestamp; MonoPPDBFile *ppdb; if (raw_contents) { if (size > 4 && strncmp ((char*)raw_contents, "BSJB", 4) == 0) ppdb_image = mono_image_open_from_data_internal ((char*)raw_contents, size, TRUE, &status, FALSE, TRUE, NULL); } else { /* ppdb files drop the .exe/.dll extension */ filename = mono_image_get_filename (image); if (strlen (filename) > 4 && (!strcmp (filename + strlen (filename) - 4, ".exe") || !strcmp (filename + strlen (filename) - 4, ".dll"))) { s = g_strdup (filename); s [strlen (filename) - 4] = '\0'; ppdb_filename = g_strdup_printf ("%s.pdb", s); g_free (s); } else { ppdb_filename = g_strdup_printf ("%s.pdb", filename); } ppdb_image = mono_image_open_metadata_only (ppdb_filename, &status); if (!ppdb_image) g_free (ppdb_filename); } if (!ppdb_image) return NULL; /* * Check that the images match. * The same id is stored in the Debug Directory of the PE file, and in the * #Pdb stream in the ppdb file. */ if (get_pe_debug_guid (image, pe_guid, &pe_age, &pe_timestamp)) { PdbStreamHeader *pdb_stream = (PdbStreamHeader*)ppdb_image->heap_pdb.data; g_assert (pdb_stream); /* The pdb id is a concentation of the pe guid and the timestamp */ if (memcmp (pe_guid, pdb_stream->guid, 16) != 0 || memcmp (&pe_timestamp, pdb_stream->guid + 16, 4) != 0) { g_warning ("Symbol file %s doesn't match image %s", ppdb_image->name, image->name); mono_image_close (ppdb_image); return NULL; } } ppdb = g_new0 (MonoPPDBFile, 1); ppdb->image = ppdb_image; ppdb->doc_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) doc_free); ppdb->method_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_free); return ppdb; }
static void output_assembly (MonoAssembly *assembly, MonoAssembly *assembly2, FILE *outfile) { MonoImage *image = mono_assembly_get_image (assembly); fprintf (outfile, "\t<assembly name=\"%s\" guid=\"%s\" filename=\"%s\"/>\n", mono_image_get_name (image), mono_image_get_guid (image), mono_image_get_filename (image)); }
CScriptAssembly *CScriptDomain::TryGetAssembly(MonoImage *pImage) { CRY_ASSERT(pImage); for each(auto assembly in m_assemblies) { if(assembly->GetImage() == pImage) return assembly; } // This assembly was loaded from managed code. CScriptAssembly *pAssembly = new CScriptAssembly(this, pImage, mono_image_get_filename(pImage), false); m_assemblies.push_back(pAssembly); return pAssembly; }
MonoSymbolFile * mono_debug_open_mono_symbols (MonoDebugHandle *handle, const uint8_t *raw_contents, int size, gboolean in_the_debugger) { MonoSymbolFile *symfile; mono_debugger_lock (); symfile = g_new0 (MonoSymbolFile, 1); if (raw_contents != NULL) { unsigned char *p; symfile->raw_contents_size = size; symfile->raw_contents = p = (unsigned char *)g_malloc (size); memcpy (p, raw_contents, size); symfile->filename = g_strdup_printf ("LoadedFromMemory"); symfile->was_loaded_from_memory = TRUE; } else { MonoFileMap *f; symfile->filename = g_strdup_printf ("%s.mdb", mono_image_get_filename (handle->image)); symfile->was_loaded_from_memory = FALSE; if ((f = mono_file_map_open (symfile->filename))) { symfile->raw_contents_size = mono_file_map_size (f); if (symfile->raw_contents_size == 0) { if (!in_the_debugger) g_warning ("stat of %s failed: %s", symfile->filename, g_strerror (errno)); } else { symfile->raw_contents = (const unsigned char *)mono_file_map (symfile->raw_contents_size, MONO_MMAP_READ|MONO_MMAP_PRIVATE, mono_file_map_fd (f), 0, &symfile->raw_contents_handle); } mono_file_map_close (f); } } if (load_symfile (handle, symfile, in_the_debugger)) { mono_debugger_unlock (); return symfile; } else if (!in_the_debugger) { mono_debug_close_mono_symbol_file (symfile); mono_debugger_unlock (); return NULL; } mono_debugger_unlock (); return symfile; }
static int mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc) { MonoError error; MonoAssembly *agent_assembly; MonoImage *image; MonoMethod *method; guint32 entry; MonoArray *main_args; gpointer pa [1]; MonoImageOpenStatus open_status; agent_assembly = mono_assembly_open (agent, &open_status); if (!agent_assembly) { fprintf (stderr, "Cannot open agent assembly '%s': %s.\n", agent, mono_image_strerror (open_status)); g_free (agent); return 2; } /* * Can't use mono_jit_exec (), as it sets things which might confuse the * real Main method. */ image = mono_assembly_get_image (agent_assembly); entry = mono_image_get_entry_point (image); if (!entry) { g_print ("Assembly '%s' doesn't have an entry point.\n", mono_image_get_filename (image)); g_free (agent); return 1; } method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL){ g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error)); mono_error_cleanup (&error); g_free (agent); return 1; } if (args) { main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, 1); mono_array_set (main_args, MonoString*, 0, mono_string_new (domain, args)); } else {
void mono_config_for_assembly (MonoImage *assembly) { ParseState state = {NULL}; int got_it = 0, i; char *aname, *cfg, *cfg_name; const char *bundled_config; const char *home; state.assembly = assembly; bundled_config = mono_config_string_for_assembly_file (assembly->module_name); if (bundled_config) { state.user_data = (gpointer) "<bundled>"; mono_config_parse_xml_with_context (&state, bundled_config, strlen (bundled_config)); } cfg_name = g_strdup_printf ("%s.config", mono_image_get_filename (assembly)); mono_config_parse_file_with_context (&state, cfg_name); g_free (cfg_name); cfg_name = g_strdup_printf ("%s.config", mono_image_get_name (assembly)); home = g_get_home_dir (); for (i = 0; (aname = get_assembly_filename (assembly, i)) != NULL; ++i) { cfg = g_build_filename (mono_get_config_dir (), "mono", "assemblies", aname, cfg_name, NULL); got_it += mono_config_parse_file_with_context (&state, cfg); g_free (cfg); #ifdef TARGET_WIN32 cfg = g_build_filename (home, ".mono", "assemblies", aname, cfg_name, NULL); got_it += mono_config_parse_file_with_context (&state, cfg); g_free (cfg); #endif g_free (aname); if (got_it) break; } g_free (cfg_name); }
static MonoDebugHandle * mono_debug_open_image (MonoImage *image, const guint8 *raw_contents, int size) { MonoDebugHandle *handle; if (mono_image_is_dynamic (image)) return NULL; mono_debugger_lock (); handle = _mono_debug_get_image (image); if (handle != NULL) { mono_debugger_unlock (); return handle; } handle = g_new0 (MonoDebugHandle, 1); handle->index = ++next_symbol_file_id; handle->image = image; mono_image_addref (image); handle->image_file = g_strdup (mono_image_get_filename (image)); handle->type_table = create_data_table (NULL); handle->symfile = mono_debug_open_mono_symbols ( handle, raw_contents, size, _mono_debug_using_mono_debugger); mono_debug_list_add (&mono_symbol_table->symbol_files, handle); g_hash_table_insert (mono_debug_handles, image, handle); if (mono_symbol_table->corlib) mono_debugger_event (MONO_DEBUGGER_EVENT_LOAD_MODULE, (guint64) (gsize) handle, 0); mono_debugger_unlock (); return handle; }
static gboolean collect_coverage_for (MonoProfiler *prof, MonoMethod *method) { int i; char *classname; char *fqn; MonoMethodHeader *header; gboolean has_positive, found; guint32 iflags, flags, code_size; MonoClass *klass; MonoImage *image; flags = mono_method_get_flags (method, &iflags); if ((iflags & 0x1000 /*METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL*/) || (flags & 0x2000 /*METHOD_ATTRIBUTE_PINVOKE_IMPL*/)) return FALSE; //if (method->wrapper_type != MONO_WRAPPER_NONE) // return FALSE; klass = mono_method_get_class (method); image = mono_class_get_image (klass); /* Hacky way of determining the executing assembly */ if (! prof->outfile_name && (strcmp (mono_method_get_name (method), "Main") == 0)) { prof->outfile_name = g_strdup_printf ("%s.cov", mono_image_get_filename (image)); } /* Check filters */ if (prof->filters) { /* Check already filtered classes first */ if (g_hash_table_lookup (prof->filtered_classes, klass)) return FALSE; classname = mono_type_get_name (mono_class_get_type (klass)); fqn = g_strdup_printf ("[%s]%s", mono_image_get_name (image), classname); // Check positive filters first has_positive = FALSE; found = FALSE; for (i = 0; i < prof->filters->len; ++i) { char *filter = g_ptr_array_index (prof->filters_as_str, i); if (filter [0] == '+') { filter = &filter [1]; if (strstr (fqn, filter) != NULL) found = TRUE; has_positive = TRUE; } } if (has_positive && !found) return FALSE; for (i = 0; i < prof->filters->len; ++i) { // Is substring search suffices ??? // GPatternSpec *spec = g_ptr_array_index (filters, i); // if (g_pattern_match_string (spec, classname)) { char *filter = g_ptr_array_index (prof->filters_as_str, i); if (filter [0] == '+') continue; // Skip '-' filter = &filter [1]; if (strstr (fqn, filter) != NULL) { g_hash_table_insert (prof->filtered_classes, klass, klass); return FALSE; } } g_free (fqn); g_free (classname); } header = mono_method_get_header (method); mono_method_header_get_code (header, &code_size, NULL); if (code_size > 20000) { exit (1); g_warning ("Unable to instrument method %s:%s since it is too complex.", mono_class_get_name (klass), mono_method_get_name (method)); return FALSE; } g_hash_table_insert (prof->methods, method, method); g_hash_table_insert (prof->classes, klass, klass); g_hash_table_insert (prof->assemblies, mono_image_get_assembly (image), mono_image_get_assembly (image)); return TRUE; }