[Mono-dev] Debugging Embedded Mono in Python C extension

Cronan ivan.cronyn at gmail.com
Wed Jan 25 11:19:20 UTC 2017


FYI I built a version without python and get the same issue:

#include <mono/jit/jit.h> 
#include <mono/metadata/object.h> 
#include <mono/metadata/environment.h> 
#include <mono/metadata/assembly.h> 
#include <mono/metadata/debug-helpers.h> 
#include <stdbool.h>
#include <string.h>
#include <stdio.h>

static MonoMethod *getMethod(char* methodName)
{
	static MonoImage *img;
	
	if(img == NULL) 
	{
		MonoDomain *domain = mono_jit_init("my.dll");
		
		if(domain == NULL)
		{
			return NULL;
		}
		
		MonoAssembly *assembly = mono_domain_assembly_open(domain, "my.dll"); 
		
		if(assembly == NULL)
		{
			return NULL;
		}
		
		img = mono_assembly_get_image(assembly);
		
		if(img == NULL)
		{
			return NULL;
		}
	}
	
	MonoMethodDesc *desc = mono_method_desc_new(methodName, true); 
	
	if(desc == NULL)
		return NULL;
	
    return mono_method_desc_search_in_image(desc, img); 
}

int main(void)
{
	MonoMethod *method = getMethod("MyNs.MyClass:MyFunc()"); 

	if(method == NULL)
	{
		puts("Method was null");
		return 1;
	}
	
	MonoObject* ex = NULL;
	MonoObject *res = mono_runtime_invoke(method, NULL, NULL, &ex);
	
	if(ex != NULL)
	{
		char *s = mono_string_to_utf8(mono_object_to_string(ex, NULL));
		puts(s);
		return 2;
	}
	
	if(res == NULL)
	{
		puts("No result");
		return 3;
	}
	
	char *rv = mono_string_to_utf8(mono_object_to_string(res, NULL));
	puts(rv);
	return 0;
}



--
View this message in context: http://mono.1490590.n4.nabble.com/Debugging-Embedded-Mono-in-Python-C-extension-tp4669812p4669820.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list