Exemplo n.º 1
0
static void
process_image (MonoImage *image, gboolean all) {
	int i;
	const MonoTableInfo *t;
	MonoClass *klass;
	MonoMethod *entry;
	guint32 eptoken;

	if (verbose)
		g_print ("#processing image: %s\n", mono_image_get_name (image));
	eptoken =  mono_image_get_entry_point (image);
	if (eptoken) {
		entry = mono_get_method (image, eptoken, NULL);
		add_types_from_method (entry);
	}
	/* we always add the <Module> type */
	klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | 1);
	handle_type (klass, all? TYPE_ALL: TYPE_BASIC);
	if (all) {
		t = mono_image_get_table_info (image, MONO_TABLE_TYPEDEF);
		for (i = 1; i < mono_table_info_get_rows (t); ++i) {
			klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | (i + 1));
			handle_type (klass, all? TYPE_ALL: TYPE_BASIC);
		}
	}
}
Exemplo n.º 2
0
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));
}
Exemplo n.º 3
0
void CPipeServer::GetImageName()
{
	void *image=(void *)ReadQword();
	char *s=mono_image_get_name(image);

	WriteWord(strlen(s));
	Write(s, strlen(s));
}
Exemplo n.º 4
0
void
mono_error_set_bad_image (MonoError *oerror, MonoImage *image, const char *msg_format, ...)
{
	MonoErrorInternal *error = (MonoErrorInternal*)oerror;
	mono_error_prepare (error);

	error->error_code = MONO_ERROR_BAD_IMAGE;
	error->assembly_name = image ? mono_image_get_name (image) : "<no_image>";
	set_error_message ();
}
Exemplo n.º 5
0
void
mono_error_set_bad_image (MonoError *error, MonoImage *image, const char *msg_format, ...)
{
	char *str;
	SET_ERROR_MSG (str, msg_format);

	mono_error_set_specific (error, MONO_ERROR_BAD_IMAGE, str);
	if (image)
		mono_error_set_first_argument (error, mono_image_get_name (image));
}
Exemplo n.º 6
0
static void
foreach_image (const gpointer key, const gpointer val, gpointer user_data)
{
	MonoImage *image = key;
	const char* aname;
	aname = mono_image_get_name (image);
	/* later print the guid as well to prevent mismatches */
	fprintf (outf, "[%s]\n", aname);
	g_hash_table_foreach (type_table, foreach_type, image);
}
Exemplo n.º 7
0
/* 
 * use the equivalent lookup code from the GAC when available.
 * Depending on state, this should give something like:
 * 	aname/version-pubtoken/
 * 	aname/version/
 * 	aname
 */
static char*
get_assembly_filename (MonoImage *image, int state)
{
	switch (state) {
	case 0:
		return g_strdup (mono_image_get_name (image));
	default:
		return NULL;
	}
}
Exemplo n.º 8
0
static void
output_image (gpointer key, gpointer value, gpointer user_data)
{
	MonoImage *image = (MonoImage*)key;
	PerImageData *image_data = (PerImageData*)value;
	MonoProfiler *prof = (MonoProfiler*)user_data;
	char *tmp, *outfile_name;
	FILE *outfile;
	int i, err;
	ForeachData data;

	tmp = g_strdup_printf ("%s/.mono/aot-profile-data", g_get_home_dir ());

	if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) {
#ifdef PLATFORM_WIN32
		err = mkdir (tmp);
#else
		err = mkdir (tmp, 0777);
#endif
		if (err) {
			fprintf (stderr, "mono-profiler-aot: Unable to create output directory '%s': %s\n", tmp, g_strerror (errno));
			exit (1);
		}
	}

	i = 0;
	while (TRUE) {
		outfile_name = g_strdup_printf ("%s/%s-%d", tmp, mono_image_get_name (image), i);

		if (!g_file_test (outfile_name, G_FILE_TEST_IS_REGULAR))
			break;

		i ++;
	}

	printf ("Creating output file: %s\n", outfile_name);

	outfile = fopen (outfile_name, "w+");
	g_assert (outfile);

	fprintf (outfile, "#VER:%d\n", 2);

	data.prof = prof;
	data.outfile = outfile;
	data.image = image;

	g_list_foreach (image_data->methods, foreach_method, &data);
}
Exemplo n.º 9
0
Arquivo: trace.c Projeto: RavenB/mono
gboolean
mono_trace_eval (MonoMethod *method)
{
	int include = 0;
	int i;

	for (i = 0; i < trace_spec.len; i++){
		MonoTraceOperation *op = &trace_spec.ops [i];
		int inc = 0;
		
		switch (op->op){
		case MONO_TRACEOP_ALL:
			inc = 1; break;
		case MONO_TRACEOP_PROGRAM:
			if (trace_spec.assembly && (method->klass->image == mono_assembly_get_image (trace_spec.assembly)))
				inc = 1; break;
		case MONO_TRACEOP_WRAPPER:
			if ((method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) ||
				(method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE))
				inc = 1; break;
		case MONO_TRACEOP_METHOD:
			if (mono_method_desc_full_match ((MonoMethodDesc *) op->data, method))
				inc = 1; break;
		case MONO_TRACEOP_CLASS:
			if (strcmp (method->klass->name_space, op->data) == 0)
				if (strcmp (method->klass->name, op->data2) == 0)
					inc = 1;
			break;
		case MONO_TRACEOP_ASSEMBLY:
			if (strcmp (mono_image_get_name (method->klass->image), op->data) == 0)
				inc = 1; break;
		case MONO_TRACEOP_NAMESPACE:
			if (strcmp (method->klass->name_space, op->data) == 0)
				inc = 1;
		case MONO_TRACEOP_EXCEPTION:
			break;
		}
		if (op->exclude){
			if (inc)
				include = 0;
		} else if (inc)
			include = 1;
	}
	return include;
}
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
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");
}
Exemplo n.º 12
0
//#####################################################################
// Function listAssembliesHelper
//#####################################################################
static void listAssembliesHelper(MonoAssembly* assembly, MonoSystem* this_ptr) {
    MonoImage* image = mono_assembly_get_image(assembly);
    printf("Assembly Image: %s\n", mono_image_get_name(image));
}
Exemplo n.º 13
0
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;
}