[Mono-dev] Unable to call methods on managed objects while running Mono on the iPhone

mobbe peter.moberg at gmail.com
Sun Feb 22 23:17:58 EST 2009


Over the past couple of weeks I have been working with getting the Mono
framework up and running on the iPhone and I am darn close to have it all
working.. .I have been able to get the AOT compilation to work and was able
this morning to startup Mono in full aot mode on the device. Big thanks to
Zoltan Varga for helping me through all the roadblocks I ran into.  I have
been working with a SVN HEAD version that I updated last week sometime.

Next step I took was to try to invoke some methods on classes in the msorlib
assembly to see if I could execute managed code and this is where I ran into
a new road block..

It looks like I am only able to execute .ctor methods!? During the startup
of Mono it creates a few exceptions (OutOfMemoryException etc..) and it
invokes its constructor method and passes in parameters. This works just
fine...and here it is executing managed code.

However, I tried to execute the ToString() method on an instance of the
Exception class and then the program is interrupted and stopped in the
prolog for the function mono_get_lmf_addr.. if I continue to run the
program
I get a BAD_INSTRUCTION message and the whole thing shuts down...

Here is the code I am trying to execute... 

MonoDomain * domain = mono_jit_init(""); 
MonoAssembly* msCorlib = mono_domain_assembly_open (domain,"mscorlib"); 
MonoImage* image = mono_assembly_get_image(msCorlib);
	
MonoClass *klass = mono_class_from_name (image, "System", "Exception");
MonoObject* o = mono_object_new (domain, klass);

MonoMethodDesc* methodDesc = mono_method_desc_new("System.Object:ToString",
TRUE);
MonoMethod* toStringMethod = mono_method_desc_search_in_class(methodDesc,
klass);
MonoObject* result = mono_runtime_invoke(toStringMethod, o, NULL, NULL);


I don't know if it would help you but here is the assembly where it all
stops... 
mono_get_lmf_addr
0x001d5bdc  <+0000>  push {r4, r5, r7, lr}
0x001d5bde  <+0002>  add r7, sp, #8
0x001d5be0  <+0004>  sub sp, #12 <-- stops here
0x001d5be2  <+0006>  ldr r3, [pc, #76] (0x1d5c30
<mono_get_lmf_addr+84>)
0x001d5be4  <+0008>  add r3, pc
0x001d5be6  <+0010>  ldr r3, [r3, #0]
0x001d5be8  <+0012>  adds r0, r3, #0
0x001d5bea  <+0014>  bl 0x3e640 <TlsGetValue>

I get the same problem if I try to run other methods on other objects or
static methods as well...Only constructor methods seems to work.

It looks to me that the stack isn't setup properly since it always throws
the EXC_BAD_INSTRUCTION when trying to access the stack pointer. 

I have been banging my head against this problem for two days and right now
I am not able to figure out how to troubleshoot this. If there is anyone out
there that have any suggestion on how I should go about troubleshooting this
I would really appreciate it. It stings a bit to come this close and not be
able to cross the finish line... 


Thanks,

-- 
View this message in context: http://www.nabble.com/Unable-to-call-methods-on-managed-objects-while-running-Mono-on-the-iPhone-tp22155202p22155202.html
Sent from the Mono - Dev mailing list archive at Nabble.com.



More information about the Mono-devel-list mailing list