airpaulg
airpaulg

Reputation: 565

Xamarin.iOS- Debugging native crash in a bound library using GDB

I have a third-party library on which I did bindings and that I built for archiving using XCode. I use it in my C# Xamarin app. Nevertheless, I had a native crash that I have no way of debugging through Xamarin Studio. I tried attaching gdb to the process but I get the following warnings:

warning: Could not find object file "/var/folders/mf/w59_1t797k3cfrp7hdmncvt40000gn/T/tmp42fc77da.tmp/libCouchCocoa.a(CouchEmbeddedServer.o)" - no debug information available for "CouchEmbeddedServer.m".


warning: Could not find object file "/var/folders/mf/w59_1t797k3cfrp7hdmncvt40000gn/T/tmp42fc77da.tmp/libCouchCocoa.a(CouchTouchDBDatabase.o)" - no debug information available for "CouchTouchDBDatabase.m".

[...]

Then, when the SIGSEGV occurs, I use the bt function and I have no information on what happened in the library. I presume this is related with the warnings.

(gdb) continue
Continuing.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008
[Switching to process 98604 thread 0x28403]
0x0438509b in objc_msgSend ()
(gdb) bt
#0  0x0438509b in objc_msgSend ()
#1  0x112924f0 in ?? ()
#2  0x1714fdb0 in ?? ()
#3  0x17555a9c in ?? ()
#4  0x175557f6 in ?? ()
#5  0x17555200 in ?? ()
#6  0x17554c48 in ?? ()
#7  0x17554b4c in ?? ()
#8  0x17554af0 in ?? ()
#9  0x17554aac in ?? ()
#10 0x1718fb1c in ?? ()
#11 0x1718f6dc in ?? ()
#12 0x1718f5d8 in ?? ()
#13 0x0b6c0c8e in ?? ()
#14 0x000a3172 in mono_jit_runtime_invoke (method=0xca60dac, obj=0x10ec7490, params=0xb0974eec, exc=0xb0974ef4) at mini.c:5804
#15 0x0020840e in mono_runtime_invoke (method=0xca60dac, obj=0x10ec7490, params=0xb0974eec, exc=0xb0974ef4) at object.c:2790
#16 0x0020857c in mono_runtime_delegate_invoke (delegate=0x10ec7490, params=0xb0974eec, exc=0xb0974ef4) at object.c:3462
#17 0x002629b4 in mono_async_invoke [inlined] () at :626
#18 0x002629b4 in async_invoke_thread (data=0xc71f870) at threadpool.c:1443
#19 0x00268756 in start_wrapper_internal [inlined] () at :784
#20 0x00268756 in start_wrapper (data=0x1128e680) at threads.c:832
#21 0x0029a69a in thread_start_routine (args=0xfa46204) at wthreads.c:287
#22 0x00245540 in gc_start_thread (arg=0x112922a0) at sgen-gc.c:6280
#23 0x98a89ed9 in _pthread_start ()
#24 0x98a8d6de in thread_start ()
(gdb) 

How should I build my third-party libraries so that gdb manages to find debug information about them?

EDIT: Using p mono_pmip, I managed to get the desymbolicated method name, but is there a way not having to do this and having the debug symbols?

Upvotes: 1

Views: 1130

Answers (1)

Rolf Bjarne Kvinge
Rolf Bjarne Kvinge

Reputation: 19345

You might have more luck if you use gdb on device.

This can be done using fruitstrap (note that fruitstrap is not officially supported by Xamarin - all I can say is that I've been able to use it myself occasionally).

The reason it's harder in the simulator is because we use a JIT there - this means that the mapping between memory addresses and function names / line numbers is only present in-memory, which gdb doesn't understand. When building for device we AOT everything into ARM assembly and we create proper debug information that gdb understands.

Upvotes: 3

Related Questions