static MonoObject * mono_jit_exec_virt (MonoAssembly *assembly, char *mtd_name, MonoArray *v_args) { MonoImage *image = mono_assembly_get_image (assembly); MonoMethod *method; MonoClass *class; MonoMethodDesc *desc; MonoObject *exc = NULL, *ret; class = mono_class_from_name (image, "", "VInvoke"); desc = mono_method_desc_new (mtd_name, 1); method = mono_method_desc_search_in_image (desc, image); mono_assembly_set_main ( mono_image_get_assembly ( mono_class_get_image ( mono_method_get_class (method)))); /*mono_start_method = mono_marshal_get_runtime_invoke (method);*/ ret = virt_mono_runtime_exec_main (method, v_args, &exc); if (exc) virt_mono_throw_unhandled_exception (exc); return ret; }
MonoDebugMethodInfo * mono_ppdb_lookup_method (MonoDebugHandle *handle, MonoMethod *method) { MonoDebugMethodInfo *minfo; MonoPPDBFile *ppdb = handle->ppdb; if (handle->image != mono_class_get_image (mono_method_get_class (method))) return NULL; mono_debugger_lock (); minfo = (MonoDebugMethodInfo *)g_hash_table_lookup (ppdb->method_hash, method); if (minfo) { mono_debugger_unlock (); return minfo; } minfo = g_new0 (MonoDebugMethodInfo, 1); minfo->index = 0; minfo->method = method; minfo->handle = handle; g_hash_table_insert (ppdb->method_hash, method, minfo); mono_debugger_unlock (); return minfo; }
static void foreach_method (gpointer data, gpointer user_data) { ForeachData *udata = (ForeachData*)user_data; MonoMethod *method = (MonoMethod*)data; char *name; if (!mono_method_get_token (method) || mono_class_get_image (mono_method_get_class (method)) != udata->image) return; name = mono_method_full_name (method, TRUE); fprintf (udata->outfile, "%s\n", name); g_free (name); }
static void prof_jit_leave (MonoProfiler *prof, MonoMethod *method, int result) { MonoImage *image = mono_class_get_image (mono_method_get_class (method)); PerImageData *data; data = g_hash_table_lookup (prof->images, image); if (!data) { data = g_new0 (PerImageData, 1); g_hash_table_insert (prof->images, image, data); } data->methods = g_list_append (data->methods, method); }
MonoDebugMethodInfo * mono_debug_symfile_lookup_method (MonoDebugHandle *handle, MonoMethod *method) { MonoSymbolFileMethodEntry *first_ie, *ie; MonoDebugMethodInfo *minfo; MonoSymbolFile *symfile = handle->symfile; if (!symfile->method_hash) return NULL; if (handle->image != mono_class_get_image (mono_method_get_class (method))) return NULL; mono_debugger_lock (); minfo = g_hash_table_lookup (symfile->method_hash, method); if (minfo) { mono_debugger_unlock (); return minfo; } first_ie = (MonoSymbolFileMethodEntry *) (symfile->raw_contents + read32(&(symfile->offset_table->_method_table_offset))); ie = bsearch (GUINT_TO_POINTER (mono_method_get_token (method)), first_ie, read32(&(symfile->offset_table->_method_count)), sizeof (MonoSymbolFileMethodEntry), compare_method); if (!ie) { mono_debugger_unlock (); return NULL; } minfo = g_new0 (MonoDebugMethodInfo, 1); minfo->index = (ie - first_ie) + 1; minfo->method = method; minfo->handle = handle; minfo->data_offset = read32 (&(ie->_data_offset)); minfo->lnt_offset = read32 (&(ie->_line_number_table)); g_hash_table_insert (symfile->method_hash, method, minfo); mono_debugger_unlock (); return minfo; }
static void output_method (MonoMethod *method, gpointer dummy, MonoProfiler *prof) { MonoMethodHeader *header; char *classname; char *tmpsig; char *tmpname; FILE *outfile; MonoClass *klass; MonoImage *image; outfile = prof->outfile; header = mono_method_get_header (method); tmpsig = mono_signature_get_desc (mono_method_signature (method), TRUE); tmpsig = g_markup_escape_text (tmpsig, strlen (tmpsig)); klass = mono_method_get_class (method); classname = mono_type_get_name (mono_class_get_type (klass)); image = mono_class_get_image (klass); tmpname = mono_method_get_name (method); tmpname = g_markup_escape_text (tmpname, strlen (tmpname)); fprintf (outfile, "\t<method assembly=\"%s\" class=\"%s\" name=\"%s (%s)\" token=\"%d\">\n", mono_image_get_name (image), classname, tmpname, tmpsig, mono_method_get_token (method)); g_free (tmpsig); g_free (tmpname); fprintf (outfile, "\t\t"); count = 0; prev_offset = 0; mono_profiler_coverage_get (prof, method, output_entry); fprintf (outfile, "\n"); fprintf (outfile, "\t</method>\n"); }
GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { MonoImage *image = mono_class_get_image(p_raw_class); if (image == corlib_assembly->get_image()) return corlib_assembly->get_class(p_raw_class); uint32_t domain_id = mono_domain_get_id(mono_domain_get()); HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies[domain_id]; const String *k = NULL; while ((k = domain_assemblies.next(k))) { GDMonoAssembly *assembly = domain_assemblies.get(*k); if (assembly->get_image() == image) { GDMonoClass *klass = assembly->get_class(p_raw_class); if (klass) return klass; } } return NULL; }
static MonoObject * virt_mono_runtime_exec_main (MonoMethod *method, MonoArray *args, MonoObject **exc) { MonoDomain *domain; MonoObject *obj, *ret; g_assert (args); domain = mono_object_get_domain ((MonoObject *) args); mono_runtime_ensure_entry_assembly (domain, mono_image_get_assembly ( mono_class_get_image ( mono_method_get_class (method)))); #if 0 #ifndef MONO_AGENT mono_new_thread_init (get_mono_thread(), &ret); #endif #endif obj = mono_object_new (domain, mono_method_get_class (method)); ret = mono_runtime_invoke_array (method, obj, args, exc); return ret; /* FIXME: check signature of method if (method->signature->ret->type == MONO_TYPE_I4) { res = mono_runtime_invoke (method, NULL, pa, exc); if (!exc || !*exc) rval = *(guint32 *)((char *)res + sizeof (MonoObject)); else rval = -1; fprintf (stderr, "[INT:%i]\n", rval); } else if (method->signature->ret->type == MONO_TYPE_SZARRAY) { MonoObject *res; int len; res = mono_runtime_invoke (method, NULL, pa, exc); rval = mono_array_length ((MonoArrayType *)res); len = mono_array_length ((MonoArray*)res); for (i = 0; i < len; ++i) { MonoObject *s; // = (MonoString *)mono_array_get ((MonoArray*)res, gpointer, i); fprintf (stderr, "[STRING:%s]\n", mono_string_to_utf8 ((MonoString *)s)); } if (!exc || !*exc) rval = *(guint32 *)((char *)res + sizeof (MonoObject)); else rval = -1; fprintf (stderr, "[INT:%i]\n", rval); } else { MonoObject *ress; ress = mono_runtime_invoke (method, NULL, pa, exc); fprintf (stderr, "[STRING:%s]\n", mono_string_to_utf8 ((MonoString *)ress)); } // return rval;*/ }
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; }