How to debug crashed android native library? - android

I am runing junit test for native library(C++), native library process crashed and logcat shows:
I/ActivityManager( 161): Force stopping package xxxxx uid=10043
I/ActivityManager( 161): Start proc xxxxx for added application xxxx: pid=1656 uid=10043 gids={1015}
I/TestRunner( 1656): started: testAddressBook(xxxxx.AddressBookTest)
F//system/bin/app_process( 1656): stack corruption detected: aborted
I/ActivityManager( 161): Process xxxxx (pid 1656) has died.
Where xxxxx is the process name.
I try to follow instruction on http://source.android.com/porting/debugging_native.html , but the instruction is confusing:
If it crashes, connect with aproto and run logcat on the device
What is aproto? I can't find it. Nor "stack" tool.
Any suggestion is appreciated!
-Henry

F//system/bin/app_process( 1656): stack corruption detected: aborted
That sounds like you're trashing a local variable. Here's a really popular way to do that:
char localVar[16];
sprintf(localVar, "And this is why sprintf is the devil");
That's not exactly what you asked for, but I hope it helps anyway.

Related

Android 8 System App update effective only after reboot

TL;DR: When updating system apps on android, the updated app is only started after reboot.
I am developing a custom ROM based on Android 8.1.2 for a custom device based on Rockchip RK3126c. I took the AOSP source from the board manufacturer and only modified the platform key and added two custom apps as system apps; one is privileged (shared system user), and one isn't, i.e. the first is located in /system/priv-app and signed with the platform key, and the second in /system/app and signed with its own key.
Both apps work, but when I try to update any of the two (via adb shell pm install -r ... or via Android Studio) the update doesn't take effect; the old version still runs, even after killing (adb shell kill -9 ... or throwing a null pointer exception) and restarting it. Only after a full reboot is the new version started. I did increment the versionCode. Before the reboot, getPackageManager().getPackageInfo(...).versionCode yields the new version number, while BuildConfig.VERSION_CODE gives the old one. This is both for eng and user builds.
While updating, adb logcat shows:
10-17 15:45:19.706 1048 1048 D AndroidRuntime: Calling main entry com.android.commands.pm.Pm
10-17 15:45:19.725 1058 1058 E asset : setgid: Operation not permitted
10-17 15:45:22.563 336 362 I ActivityManager: Start proc 1062:com.android.defcontainer/u0a11 for service com.android.defcontainer/.DefaultContainerService
10-17 15:45:22.617 1062 1062 I zygote : The ClassLoaderContext is a special shared library.
10-17 15:45:22.739 336 362 I chatty : uid=1000(system) PackageManager expire 1 line
10-17 15:45:22.820 1077 1077 I dex2oat : /system/bin/dex2oat --input-vdex-fd=-1 --output-vdex-fd=14 --compiler-filter=quicken --classpath-dir=/data/app/com.example.myapp-cdF84NESHVxl5UTZHVbRdg== --class-loader-context=PCL[]
10-17 15:45:22.832 1077 1077 W dex2oat : Could not reserve sentinel fault page
10-17 15:45:26.117 1077 1080 W dex2oat : Verification of boolean ao0.a(java.lang.String, long) took 130.568ms
10-17 15:45:28.960 1077 1077 I dex2oat : dex2oat took 6.142s (10.744s cpu) (threads: 4) arena alloc=17KB (17568B) java alloc=4MB (4274432B) native alloc=6MB (6543768B) free=1801KB (1844840B)
10-17 15:45:28.997 336 350 I ActivityManager: Force stopping com.example.myapp appid=1000 user=-1: installPackageLI
10-17 15:45:29.009 336 362 W PackageManager: Trying to update system app code path from /system/priv-app/MyApp to /data/app/MyApp-cdF84NESHVxl5UTZHVbRdg==
10-17 15:45:29.010 336 362 W PackageManager: Code path for com.example.myapp changing from /system/priv-app/MyApp to /data/app/MyApp-cdF84NESHVxl5UTZHVbRdg==
10-17 15:45:29.010 336 362 W PackageManager: Resource path com.example.myapp changing from /system/priv-app/MyApp to /data/app/MyApp-cdF84NESHVxl5UTZHVbRdg==
10-17 15:45:29.205 242 242 E : Couldn't opendir /data/app/vmdl1968223466.tmp: No such file or directory
10-17 15:45:29.205 242 242 E installd: Failed to delete /data/app/vmdl1968223466.tmp: No such file or directory
10-17 15:45:29.213 336 362 I ActivityManager: Force stopping com.example.myapp appid=1000 user=0: pkg removed
10-17 15:45:29.214 1048 1048 I Pm : Package com.example.myapp installed in 9500 ms
10-17 15:45:29.239 1048 1048 I app_process: System.exit called, status: 0
10-17 15:45:29.239 1048 1048 I AndroidRuntime: VM exiting with result code 0.
After the reboot, further updates to the app do work - apparently, the problem only exists when changing the code path from /system/[priv-]app to /data/app, but not when the path is already /data/app.
The same thing worked fine on Android 7.1.2. Deep within the android framework there is probably some cache for the code paths of the apps which doesn't get updated after the app is overwritten. Anyone knows where that is located and how to fix this problem?
After a lot of fiddling, I found it myself: The app was marked as persistent in the manifest, which causes the mentioned behaviour. It only worked on Android 7.1.2 because there was a vendor-specific modification that ignored the persistent flag.

What's the relationship between Dalvik and Zygote process?

I just want to know :
Who created the dalvik_Vm ?
Is the zygote process running in the vm or contrary?
Dalvik VM was authored by Dan Bornstein
Every android application runs in a separate process, has its own Dalvik VM.
Zygote is a daemon with the only mission to launch applications. This means that Zygote is the parent of all App process. When app_process launches Zygote, it creates the first Dalvik VM and calls Zygote’s main () method. Once Zygote starts, it preloads all necessary Java classes and resources, starts System Server and opens a socket /dev/socket/zygote to listen for requests for starting applications.
Add some example to explain that Zygote is the parent of all App process.
zygote PID : 481, my application processes PPID : 481, you can use ps command to check.
UID PID PPID C STIME TTY TIME CMD
root 481 1 0 09:17:54 ? 00:00:03 zygote
u0_a132 28993 481 78 09:07:53 ? 00:23:46 com.languouang.helloworld
u0_a132 29013 481 0 09:07:53 ? 00:00:01 com.languouang.helloworld:countservice
u0_a132 29296 481 1 09:09:04 ? 00:00:09 com.languouang.helloworld:mall
u0_a132 30427 481 1 09:16:42 ? 00:00:15 com.languouang.helloworld:faq
Zygote actually the child of init process which occur as boot process start.
It is responsible of loading Dalvik virtyal machine by which our Dalvik Bytecode get executed. Also, it preload all the necessary resource all shared java classes and resources into memory.
Zygote is one of the first init processes created after the device boots. It initializes the Dalvik virtual machine and tries to create multiple instances to support each Android process. As discussed in earlier sections, the Dalvik virtual machine is the virtual machine that executes Android applications written in Java.
Zygote facilitates using a shared code across the VM, hence, helping to save the memory and reduce the burden on the system. After this, applications can run by requesting new Dalvik virtual machines. Zygote registers a server socket for zygote connections and preloads certain classes and resources. This zygote loading process has been more clearly explained at https://elinux.org/Android_Zygote_Startup ...

About "init: untracked pid xxxx exited" in Genymotion

Sometimes I see the following logcat output such as that below:
<3>[ 283.152845] init: untracked pid 4217 exited
<3>[ 283.162185] init: untracked pid 4078 exited
<3>[ 283.173691] init: untracked pid 1504 exited
<3>[ 283.177018] init: untracked pid 1468 exited
What is the meaning of the log of init: untracked pid xxxx exited?
use logcat and read the huge log carefully. You might find the program that crashes all the time.
There may be many different reasons, one of them is that android init trying to
initialize services specified by init.rc failed.
You can try to bisect the services started from init.rc first, and once you find
the errornous service, then try to fix the specific service start up errors, which
may be the kernel driver error, or android hal driver error, library fault, or
sometimes android framework error.
Technically, this message (modern version of which is "Untracked pid XXX exited with status YY") means that Android init sees a child process exit (that is, receives SIGCHLD signal and then gets its pid with waitpid()), but it can't associate that process with any of configured services (see this question on Android init service configuration).
This in turn opens up a question of what can daemonize itself in Android environment and how to find it. But I don't think that I can answer that, the only suggestion that I have is getting root access and checking processes.

attaching to android native app with gdb closes app on device

I am attempting to debug my native app compiled with ndk-r6. When I attempt to run ndk-gdb to attach the debugger to the process, the app quits on the device. I am stumped. Can anyone shed some light on this for me please?
Here is a log of a run of the gdb process: http://pastebin.com/qTCR7mF2
This is all I get out of logcat:
I/ActivityManager(10006): Process com.gmail.whittock.tom.clockwork (pid 11460) has died.
I/WindowManager(10006): WIN DEATH: Window{4083aa18 com.gmail.whittock.tom.clockwork/com.gmail.whittock.tom.Util.NativeActivity paused=false}
I/WindowManager(10006): WIN DEATH: Window{4085d8d0 SurfaceView paused=false}
I/WindowManager(10006): Setting rotation to 0, animFlags=1
I/ActivityManager(10006): Config changed: { scale=1.0 imsi=234/10 loc=en_GB touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34 uiMode=17 seq=31 themeResource=null}
EDIT:
and this is my gdb.setup file:
$ cat libs/armeabi-v7a/gdb.setup
set solib-search-path C:/Users/Tom/dev/android/Clockwork/obj/local/armeabi-v7a
directory C:/Users/Tom/dev/android/ANDROI~2/platforms/android-5/arch-arm/usr/include C:/Users/Tom/dev/android/ANDROI~2/sources/cxx-stl/stlport/stlport C:/Users/Tom/dev/android/ANDROI~2/sources/cxx-stl/system/include C:/Users/Tom/dev/android/modules/box2d C:/Users/Tom/dev/android/Clockwork/jni
all paths in there look correct to me, but perhaps it's the use of the dos-compatibility versions of filenames that's causing the issue?!
EDIT2: This is the other gdb.setup file:
$ cat obj/local/armeabi-v7a/gdb.setup
file C:/Users/Tom/dev/android/Clockwork/obj/local/armeabi-v7a/app_process
target remote :5039
file C:/Users/Tom/dev/android/Clockwork/obj/local/armeabi-v7a/app_process
target remote :5039
file C:/Users/Tom/dev/android/Clockwork/obj/local/armeabi-v7a/app_process
target remote :5039
I finally found the issue.
ndk-gdb HAS HAS HAS to have NDK_DEBUG=1 environment variable set, otherwise the NDK_APP_GDBSETUP variable gets set to blank due to make believing that the app isn't debuggable (being too damn smart for its own good)
This then causes the gdb.setup file to get corrupted, because a copy command fails and we start appending to the end of anything that is already there. This is why the same command pair is repeated 3 times in obj/local.../gdb.setup.
You have no idea how much pain this has caused me. Hopefully someone else will have an easier time if they read this.
Step by step instructions to setting up GDB on eclipse Your GDB configuration is probably borked. Rather than trying to diagnose the problem, try following those steps and see if that fixes your problem.

App using NDK (native code) falls. How can i find out why?

My app is using NDK (4r-crystax in my case) to proccess images from a camera. Problem is, it falls after few minutes of work. I guess there can be some memory leaks or something like that, but i dont know how to find out where the problem is. This is a log around this error:
04-14 23:07:37.133: INFO/NATIVE CODE(14895): Detection percentage counted.
04-14 23:07:37.163: DEBUG/MDDetectorView(14895): Some debug info
04-14 23:07:37.193: DEBUG/dalvikvm(14895): GC_EXTERNAL_ALLOC freed 19 objects / 872 bytes in 27ms
04-14 23:07:37.283: INFO/NATIVE CODE(14895): Image to proccess loaded.
04-14 23:07:37.493: INFO/ActivityManager(92): Process com.motiondetector (pid 14895) has died.
04-14 23:07:37.493: DEBUG/CameraService(67): Client::~Client E (pid 67, client 0xad08)
04-14 23:07:37.503: INFO/WindowManager(92): WIN DEATH: Window{46590698 com.motiondetector/com.motiondetector.MDMenuActivity paused=false}
04-14 23:07:37.513: ERROR/CameraService(67): getClientFromCookie: client appears to have died
Any ideas? Are there any usefull tools to help me find answer?
Is possible that Android kill on screen activity during proccessing a native code?
If you're using NDK r5 or greater, you can use the ndk-gdb script to run your program and connect to it via GDB. If your native code is crashing, it should drop you into the GDB command line, where you can examine the area of code that's causing the problem.

Categories

Resources