Micah Williamson Micah Williamson - 20 days ago 16
iOS Question

SQLite3 iOS Segmentation Fault (Xamarin)

I am having a difficult time diagnosing a segmentation fault thrown inside of sqlite3. I can narrow the entry point down to a single query on my code, after which the stack never returns to my code and blows up in sqlite3.

I understand this may not be an issue with sqlite3 but from the message and stack trace given, I don't know where to begin.

My code-

private Session GetCurrentSession()
{
return Database.Query<Session>("select * from Session").FirstOrDefault();
}


Stack Trace starting at the last call from my code-


Thread 0 name: tid_a0b Dispatch queue: com.apple.main-thread
Thread 0 Crashed:

0 libsystem_kernel.dylib 0x23d86c5c __pthread_kill + 8

1 libsystem_pthread.dylib 0x23e30732 pthread_kill + 62

2 libsystem_c.dylib 0x23d1b0ac abort + 108

3 MyMobileAppiOS 0x0011e834 mono_handle_native_sigsegv (mini-exceptions.c:2420)

4 MyMobileAppiOS 0x0012612c mono_sigsegv_signal_handler (mini-runtime.c:2875)

5 libsystem_platform.dylib 0x23e2a076 _sigtramp + 42

6 libsqlite3.dylib 0x2453cc34 0x2451d000 + 130100

7 libsqlite3.dylib 0x2453cc34 0x2451d000 + 130100

8 libsqlite3.dylib 0x2453cb4a 0x2451d000 + 129866

9 libsqlite3.dylib 0x2452809a 0x2451d000 + 45210

10 libsqlite3.dylib 0x245269e2 0x2451d000 + 39394

11 libsqlite3.dylib 0x24526128 0x2451d000 + 37160

12 libsqlite3.dylib 0x24525aa4 0x2451d000 + 35492

13 libsqlite3.dylib 0x2452583e 0x2451d000 + 34878

14 libsqlite3.dylib 0x24567e50 sqlite3_prepare_v2 + 44

15 MyMobileAppiOS 0x00a2bba0 wrapper_managed_to_native_SQLitePCL_SQLite3Provider_default_NativeMethods_sqlite3_prepare_v2_intptr_byte___int_intptr__intptr_ (/:1)

16 MyMobileAppiOS 0x00a1c754 SQLitePCL_SQLite3Provider_default_SQLitePCL_ISQLite3Provider_sqlite3_prepare_v2_intptr_string_intptr__string_ (/:1)

17 MyMobileAppiOS 0x00a18aa8 SQLitePCL_raw_sqlite3_prepare_v2_SQLitePCL_sqlite3_string_SQLitePCL_sqlite3_stmt__string_ (/:1)

18 MyMobileAppiOS 0x00a189f8 SQLitePCL_raw_sqlite3_prepare_v2_SQLitePCL_sqlite3_string_SQLitePCL_sqlite3_stmt_ (/:1)

19 MyMobileAppiOS 0x009ec278 SQLite_SQLite3_Prepare2_SQLitePCL_sqlite3_string (SQLite.cs:3322)

20 MyMobileAppiOS 0x009e5e00 SQLite_SQLiteCommand_Prepare (SQLite.cs:2289)

21 MyMobileAppiOS 0x009e750c SQLite_SQLiteCommand__ExecuteDeferredQueryc__Iterator0_1_T_REF_MoveNext (SQLite.cs:2201)

22 MyMobileAppiOS 0x002a0db8 System_Collections_Generic_List_1_T_REF__ctor_System_Collections_Generic_IEnumerable_1_T_REF + 596

23 MyMobileAppiOS 0x005b0ae4 System_Linq_Enumerable_ToList_TSource_REF_System_Collections_Generic_IEnumerable_1_TSource_REF (Enumerable.cs:861)

24 MyMobileAppiOS 0x009e58c8 SQLite_SQLiteCommand_ExecuteQuery_T_REF (SQLite.cs:2170)

25 MyMobileAppiOS 0x009debb0 > SQLite_SQLiteConnection_Query_T_REF_string_object__ (SQLite.cs:711)

26 MyMobileAppiOS 0x009c4344 MyMobileAppiOS_SQLiteAccess_Repository_SqlSessionRepository_GetCurrentSession (SqlSessionRepository.cs:35)


This line gets called when the app launches. The app crashes 50% of the time. I understand whats given may not be enough to solve the problem, but I was hoping from the stack trace and call someone could give me direction on what might cause this problem.

EDIT-

Looks like this is not limited to this query and can happen anytime
Database.Query
is called.

Answer

This issue was difficult to find. But maybe this will help someone else who stumbles on this same error.

In one of the queries a column names was incorrect. Instead of getting an error related to an incorrect column name, the error was a seg fault.

To track down this issue, we have to make most of our asynchronous tasks run synchronously before the debugger caught the error. Apparently in iOS, if a thread fails, the entire application fails. In android, it just ignores it and moves on.

Check your queries and make sure you're not referencing columns that don't exist.