Skip to main content

Debugging a crash in a python native library on Android (ex, kivy)

I'm trying to debug a crash in a python extension (cythonized) from pyjnius. The crash signature is as follows:


06-05 18:41:46.111 3631-3631/com.jventura.pyapp I/System.out: + java:invoke(, public abstract void android.text.TextWatcher.beforeTextChanged(java.lang.CharSequence,int,int,int), [Ljava.lang.Object;@c30cd5c)
06-05 18:41:46.113 3631-3631/com.jventura.pyapp I/pybridge: beforeTextChanged called
06-05 18:41:46.114 3631-3631/com.jventura.pyapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 3631 (.jventura.pyapp)
                                                        
                                                        [ 06-05 18:41:46.114   151:  151 W/         ]
                                                        debuggerd: handling request: pid=3631 uid=10103 gid=10103 tid=3631
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1696): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1697): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1698): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1699): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1700): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1701): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1702): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.112 4374-4374/? W/debuggerd: type=1400 audit(0.0:1703): avc: denied { search } for name="com.jventura.pyapp" dev="dm-0" ino=130503 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
06-05 18:41:46.193 4374-4374/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-05 18:41:46.193 4374-4374/? A/DEBUG: LineageOS Version: '14.1-20170502-NIGHTLY-hammerhead'
06-05 18:41:46.193 4374-4374/? A/DEBUG: Build fingerprint: 'google/hammerhead/hammerhead:6.0.1/M4B30Z/3437181:user/release-keys'
06-05 18:41:46.193 4374-4374/? A/DEBUG: Revision: '11'
06-05 18:41:46.193 4374-4374/? A/DEBUG: ABI: 'arm'
06-05 18:41:46.194 4374-4374/? A/DEBUG: pid: 3631, tid: 3631, name: .jventura.pyapp  >>> com.jventura.pyapp <<<
06-05 18:41:46.194 4374-4374/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
06-05 18:41:46.194 4374-4374/? A/DEBUG:     r0 00000000  r1 3fffffff  r2 b516737c  r3 98bed684
06-05 18:41:46.194 4374-4374/? A/DEBUG:     r4 00000000  r5 00000000  r6 00000000  r7 b2c17770
06-05 18:41:46.194 4374-4374/? A/DEBUG:     r8 96fb22d0  r9 b42a3230  sl 989d0db4  fp 98d85d30
06-05 18:41:46.194 4374-4374/? A/DEBUG:     ip 98ba2c88  sp beef7148  lr 989fdd3f  pc b50f2b68  cpsr 600f0030
06-05 18:41:46.199 4374-4374/? A/DEBUG: backtrace:
06-05 18:41:46.199 4374-4374/? A/DEBUG:     #00 pc 0001db68  /system/lib/libc.so (sem_post+11)
06-05 18:41:46.199 4374-4374/? A/DEBUG:     #01 pc 00028d3b  /data/app/com.jventura.pyapp-2/lib/arm/libpython2.7.so (PyThread_release_lock+2)
06-05 18:41:46.199 4374-4374/? A/DEBUG:     #02 pc 0003b48d  /data/data/com.jventura.pyapp/assets/python/site-packages/jnius/jnius.so
                                        
                                        
                                        [ 06-05 18:41:46.621   151:  151 W/         ]
                                        debuggerd: resuming target 3631

It occurs any time after callback is invoked when using a PythonJavaClass.  In order to figure out where in jnius.so this is occuring I had to use the following command:


~/Android/Crystax/crystax-ndk/toolchains/arm-linux-androideabi-5/prebuilt/linux-x86_64/bin/arm-linux-androideabi-addr2line -f -e ~/.local/share/python-for-android/build/other_builds/pyjnius-genericndkbuild-python2crystax/armeabi-v7a/pyjnius/build/lib.linux-x86_64-2.7/jnius/jnius.so 0003a9bd
__pyx_f_5jnius_invoke0
~/.local/share/python-for-android/build/other_builds/pyjnius-genericndkbuild-python2crystax/armeabi-v7a/pyjnius/jnius/jnius.c:32226


Which shows how to use addr2line to get the source line of the cythonized file that was leading to the crash.  Nice!

Note, if using p4a, you must make sure that the debug symbols are NOT stripped (in recipes.py) as it is done by default.

Comments

Popular posts from this blog

Kivy vs React-Native for building cross platform mobile apps

I've built three apps now using Kivy and one with React-Native, just wanted to share my thoughts on both.

Just a warning, I am strongly biased towards python and this is all based on opinion and experience and is thus worth what you pay for it. I don't claim to be an expert in either of these, just have worked with each for several months.  If something is incorrect I'd love to hear advice.

Kivy
Demo of one of the apps



Pros:
Nice to be able to run natively on the desktop WITHOUT a simulatorPython is easy to work withUse (almost) any python libraryVery easy to create custom widgetsKivy properties and data binding just work. Way nicer than React's "state" / flux / redux whatever you want to call it (stupid?). Native interfaces (pyjnius) and (pyobjc)Runs and feels pretty smooth Cons:Default widget toolkit looks like Android 4.4. Requiring you use your own widgets or a theming kit like KivyMD if styling bothers youCreating dynamic widgets declaratively is not yet s…

Control Systems in Python - Part 1 - Bode and Step Response

I hate matlab with passion, yet sadly, nearly everyone uses it.  I'm a fan of Python and open source stuff so here's a simple article on how to do some common control systems stuff in Python.

First we need to make sure the environment is setup.
Install IPython (or you can use any other python shell, but a unicode supported shell is preferred)Install python-control (numpy, scipy)Install sympy
These should do if your on Ubuntu/debian:

sudo apt-get install python-sympy python-numpy python-scipy python-matplotlib ipython
Then you need to install python control, see How to download and install python-control
Intro to using SympyOpen ipython and run the following:

import sympy from sympy import * sympy.init_printing() s = Symbol('s')

Now we can do things like define transfer functions using the symbolic variable s.


We can expand the bottom using the .simplify() method

and we can do something more complex like...
which is really nice because it does all the multiplication for us... and it’…