Git Product home page Git Product logo

coffeecatch's People

Contributors

afathman avatar ehrenkret avatar ghazel avatar xroche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coffeecatch's Issues

Architecture is not supported on Android Studio 1.5.1 with NDK

I put cofficecatch folder in jni and make project but get these errors:

In cofficecatch.c
Error:(211, 2) error: #error "Architecture is not supported (unknown ucontext layout)"
Error:(1141, 2) error: #error "Architecture is unknown, please report me!"

Any suggestion? Thanks you.

Do not work with old NDK.

I have tried to catch a native exception under NDK r9d on Android 7.0 device with an error generated by the code

    char str[10];
    for( int i = 0; i < 1000; i++ )
    str[i] = 'X';

This is my logcat:

2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0x9e449a00 allocspace main rosalloc space live-bitmap 3[begin=0x12c00000,end=0x22c00000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0x9e449a20 allocspace main rosalloc space mark-bitmap 3[begin=0x12c00000,end=0x22c00000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b340 SpaceTypeImageSpace begin=0x6f6ca000,end=0x6fae6340,size=4MB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5980 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 0[begin=0x6f6ca000,end=0x6fae6400]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5980 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 0[begin=0x6f6ca000,end=0x6fae6400]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b400 SpaceTypeImageSpace begin=0x6fc1a000,end=0x6fc5cc28,size=267KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc59c0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 1[begin=0x6fc1a000,end=0x6fc5cd00]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc59c0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 1[begin=0x6fc1a000,end=0x6fc5cd00]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b540 SpaceTypeImageSpace begin=0x6fcfd000,end=0x6fd05220,size=32KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ae0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 2[begin=0x6fcfd000,end=0x6fd05300]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ae0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 2[begin=0x6fcfd000,end=0x6fd05300]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b580 SpaceTypeImageSpace begin=0x6fd18000,end=0x6fd23090,size=44KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5b00 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 3[begin=0x6fd18000,end=0x6fd23100]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5b00 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 3[begin=0x6fd18000,end=0x6fd23100]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b5c0 SpaceTypeImageSpace begin=0x6fd3d000,end=0x6fd3d110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5b20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 4[begin=0x6fd3d000,end=0x6fd3d200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5b20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 4[begin=0x6fd3d000,end=0x6fd3d200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b700 SpaceTypeImageSpace begin=0x6fd3e000,end=0x6fd46c08,size=35KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5cc0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 5[begin=0x6fd3e000,end=0x6fd46d00]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5cc0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 5[begin=0x6fd3e000,end=0x6fd46d00]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b840 SpaceTypeImageSpace begin=0x6fd62000,end=0x6fd65408,size=13KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5d00 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 6[begin=0x6fd62000,end=0x6fd65500]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5d00 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 6[begin=0x6fd62000,end=0x6fd65500]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8b980 SpaceTypeImageSpace begin=0x6fd7f000,end=0x6fe80250,size=1028KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5d40 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 7[begin=0x6fd7f000,end=0x6fe80300]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5d40 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 7[begin=0x6fd7f000,end=0x6fe80300]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8bac0 SpaceTypeImageSpace begin=0x70205000,end=0x70205110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5de0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 8[begin=0x70205000,end=0x70205200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5de0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 8[begin=0x70205000,end=0x70205200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8bf40 SpaceTypeImageSpace begin=0x7025d000,end=0x7025d110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5c20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 9[begin=0x7025d000,end=0x7025d200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5c20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 9[begin=0x7025d000,end=0x7025d200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8bf80 SpaceTypeImageSpace begin=0x70261000,end=0x70261110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5c60 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 10[begin=0x70261000,end=0x70261200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5c60 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 10[begin=0x70261000,end=0x70261200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c8bfc0 SpaceTypeImageSpace begin=0x70265000,end=0x70265110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ca0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 11[begin=0x70265000,end=0x70265200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ca0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 11[begin=0x70265000,end=0x70265200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4ce4000 SpaceTypeImageSpace begin=0x7027d000,end=0x7027f400,size=9KB,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ea0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 12[begin=0x7027d000,end=0x7027f400]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ea0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 12[begin=0x7027d000,end=0x7027f400]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4ce4140 SpaceTypeImageSpace begin=0x7028e000,end=0x7028e110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ee0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 13[begin=0x7028e000,end=0x7028e200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5ee0 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 13[begin=0x7028e000,end=0x7028e200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4ce43c0 SpaceTypeImageSpace begin=0x7029c000,end=0x7029c110,size=272B,name="/data/dalvik-cache/arm/system@[email protected]"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5f20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 14[begin=0x7029c000,end=0x7029c200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5f20 imagespace /data/dalvik-cache/arm/system@[email protected] live-bitmap 14[begin=0x7029c000,end=0x7029c200]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4c9cb50 SpaceTypeZygoteSpace begin=0x74a1a000,end=0x74bac000,size=1608KB,name="Zygote space"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5960 allocspace zygote / non moving space live-bitmap 0[begin=0x74a1a000,end=0x74bac000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4cc5940 allocspace zygote / non moving space mark-bitmap 0[begin=0x74a1a000,end=0x74bac000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0x9e420e00 SpaceTypeMallocSpace begin=0x74bac000,end=0x74bde000,limit=0x78a1a000,size=200KB,capacity=62MB,non_growth_limit_capacity=62MB,name="non moving space"]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0x9510aea0 allocspace non moving space live-bitmap 4[begin=0x74bac000,end=0x78a1a000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0x95133c20 allocspace non moving space mark-bitmap 4[begin=0x74bac000,end=0x78a1a000]
2019-05-20 17:20:40.339 19308-19445/com.xxx.yyy E/art: 0xa4ccda00 mem map large object space:GcRetentionPolicyAlwaysCollect
2019-05-20 17:20:40.341 19308-19445/com.xxx.yyy A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x58585864 in tid 19445 (AsyncTask #4)

No too informative... Why?

JNA support

JNA (https://github.com/twall/jna) is a handy supplement to JNI. However, this places the exact moment of the C call out of the control of the application. It would be neat if there were still some way to use coffeecatch in that situation.

Are the COFFEE_* macros something which can be called individually as C functions? Then, through JNA, in Java you might have coffeeTry()/coffeeCatch()/coffeeEnd().

Another way is to modify JNA to wrap all C calls, but that probably requires more effort.

can't compile on mips

[mips] Compile        : NativeSampler <= coffeecatch.c
jni/coffeecatch/coffeecatch.c:79:58: error: 'SIGSTKFLT' undeclared here (not in a function)
jni/coffeecatch/coffeecatch.c: In function 'coffeecatch_get_pc_from_ucontext':
jni/coffeecatch/coffeecatch.c:1011:2: error: #error "Architecture is unknown, please report me!"
make.exe: *** [obj/local/mips/objs/NativeSampler/coffeecatch/coffeecatch.o] Error 1

armeabi works perfectly, but when it comes to the mips part, it won't compile.
Using android-ndk-r9d-windows-x86_64

Question: Would this allow me to catch SIG- errors on dependencies ?

Sorry if this is a naive question, just came across this library, and haven't had time to research too thoroughly yet.

I have a handful of libraries that access the NDK, but I don't have access to the source code, just the Java wrappers that call the native functions.

Would CoffeeCatch also catch and SIGILL or SIGSEGV throws from those libraries too, or do I have to have access to the point where the NDK is called explicitly ?

memoryleak

I am not sure if this is caused by me using this library in a wrong way, but I get a memory leak that keeps growing on every usage of the COFFEE_TRY_JNI().
I have 260 allocations after a while which seem to correlate to the number of times the protected jni method is called, and the mem usage is 120kb already. Since I use it in a synth, each played note will increase the mem usage.

Is there anything I can do to fix this?

It seems to be caused by:

format_pc_address_cb --- C:\Users\Peter\git\native-sampler\NativeSampler/jni/coffeecatch/coffeecatch.c:1050

My code:

extern long play(JNIEnv * env, jclass clazz, jlong samplerPointer, jint fd,
        jlong offset, jlong length) {
    if (samplerPointer == 0) {
        return 0;
    }
    NativeSampler* sampler = (NativeSampler*) samplerPointer;
    long channelID = sampler->playFileUsingFD(fd, offset, length);
    return channelID;
}

#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT long JNICALL
Java_nativesampler_NativeSampler_play(JNIEnv * env, jclass clazz,
jlong samplerPointer,jint fd, jlong offset, jlong length) {
long returnValue = 0;

COFFEE_TRY_JNI(env, returnValue = play(env, clazz, samplerPointer,fd,offset,length));
return returnValue;
}
#ifdef __cplusplus
}
#endif
Allocations: 260
Size: 512
TotalSize: 133120
BeginStacktrace:
    415808e2    /system/lib/libc_malloc_debug_leak.so --- 415808e2 --- 
    41580aea    /system/lib/libc_malloc_debug_leak.so --- 41580aea --- 
    40176b62    /system/lib/libc.so --- 40176b62 --- 
    66911b60    /data/app-lib/umito.android.minipiano_pro-1/libcoffeedJNI.so --- format_pc_address_cb --- C:\Users\Peter\git\native-sampler\NativeSampler/jni/coffeecatch/coffeecatch.c:1050
    66912980    /data/app-lib/umito.android.minipiano_pro-1/libcoffeedJNI.so --- resume(_JNIEnv*, _jclass*, long long) --- C:\Users\Peter\git\native-sampler\NativeSampler/jni/JNI.cpp:127 //I think this is a error in the native heap tracker, since I only resume 3/4 times, and all the play calls are not registered anywhere.
    4093cb0c    /system/lib/libdvm.so --- 4093cb0c --- 
    4096d576    /system/lib/libdvm.so --- 4096d576 --- 
    40945fa0    /system/lib/libdvm.so --- 40945fa0 --- 
    4094a9e4    /system/lib/libdvm.so --- 4094a9e4 --- 
    4097f5b4    /system/lib/libdvm.so --- 4097f5b4 --- 
    4097f5de    /system/lib/libdvm.so --- 4097f5de --- 
    40974366    /system/lib/libdvm.so --- 40974366 --- 
    40175b48    /system/lib/libc.so --- 40175b48 --- 
    40175cc4    /system/lib/libc.so --- 40175cc4 --- 
EndStacktrace

Not working at all

I dont know if I did something wrong, but the library is just not doing anything for me.

jboolean real_vpxGetFrame(JNIEnv *env, struct vpx_wrapper *wrapper, jobject bitmap, jint pixel_skip) {
  char *x = 0;
  *x = 10;

  // other code which is not even ran because of the error above
}

 __attribute__ ((noinline))
 void protected_vpxGetFrame(JNIEnv *env, struct vpx_wrapper *wrapper, jobject bitmap, jint pixel_skip, jboolean *result) {
  COFFEE_TRY_JNI(env, *result=real_vpxGetFrame(env, wrapper, bitmap, pixel_skip));
}

JNIEXPORT jboolean JNICALL
Java_com_pr0gramm_app_vpx_VpxWrapper_vpxGetFrame(JNIEnv *env, jlong wrapper_addr, jobject bitmap, jint pixel_skip) {
  struct vpx_wrapper *wrapper = (struct vpx_wrapper*) wrapper_addr;

  jboolean result = false;
  protected_vpxGetFrame(env, wrapper, bitmap, pixel_skip, &result);
  return result;
}

Calling this code just produces this on Android 4.0:

07-20 18:44:24.813  27913-28056/com.pr0gramm.app A/libc﹕ Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)

I compiled it as a static library and linked it against my shared library. I use APP_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries in my Application.mk... Any Ideas?

Edit: Compiled for armabi-v7a on the sdk emulator.

Doesnt catch my assert

JNIEXPORT jobject JNICALL Java_com_ircm_controller_MPCController_getInfusion(JNIEnv *env, jobject thiz, jobject object) {

COFFEE_TRY_JNI(env, return Java_com_ircm_controller_MPCController_getInfusion_notProtected(env, thiz, object));

}

JNIEXPORT jobject JNICALL Java_com_ircm_controller_MPCController_getInfusion_notProtected(JNIEnv *env, jobject thiz, jobject object) {

DBLOG("getInfusion Called");

jobject jInfusion;
Measurements& measurements = ircm::Measurements::instance();
SensorMeasurement* measurement = JNIFactory::make_sensor_measurement(env, object);
Infusion infusion = mpc_contr(measurement);
measurements.clearBolusInfusion();
jInfusion = JNIFactory::make_infusion(env, infusion);

DBLOG("getInfusion end");

return jInfusion;

}

Logcat:
07-28 11:25:45.087: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:getInfusion Called
07-28 11:25:45.157: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:make_sensor_measurement Called
07-28 11:25:45.217: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:make_sensor_measurement Called
07-28 11:25:45.267: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:make_sensor_measurement End
07-28 11:25:45.307: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:make_sensor_measurement End
07-28 11:25:45.337: I/com.ircm.utils.DBUtils(31297): addMessageToDiagnostic:mpc_contr Called
07-28 11:25:45.407: I/TAG(31297): print mat
07-28 11:25:45.407: I/TAG(31297): After the begin x0 11 1
07-28 11:25:45.407: I/TAG(31297): NaN
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.407: I/TAG(31297): 0.00000
07-28 11:25:45.537: I/TAG(31297): ClpSimplex
07-28 11:25:45.567: A/libc(31297): jni/clp/ClpSimplex.cpp:3519: bool ClpSimplex::createRim(int, bool, int): assertion "fabs(obj[i]) < 1.0e25" failed
07-28 11:25:45.617: A/libc(31297): FATAL ERROR occurring at line: 4858
07-28 11:25:45.617: A/libc(31297): least_addr: 0x40039000, mchunkptr: 0x62eaa808. Segment Infomation:
07-28 11:25:45.617: A/libc(31297): base : size
07-28 11:25:45.617: A/libc(31297): 000 62f47000: 65536
07-28 11:25:45.617: A/libc(31297): 001 62e9a000: 77824
07-28 11:25:45.617: A/libc(31297): 002 62e8c000: 28672
07-28 11:25:45.617: A/libc(31297): 003 62f38000: 32768
07-28 11:25:45.617: A/libc(31297): 004 63025000: 180224
07-28 11:25:45.617: A/libc(31297): 005 62e73000: 36864
07-28 11:25:45.617: A/libc(31297): 006 6538a000: 20480
07-28 11:25:45.617: A/libc(31297): 007 6538f000: 16384
07-28 11:25:45.617: A/libc(31297): 008 63974000: 16384
07-28 11:25:45.617: A/libc(31297): 009 63941000: 24576
07-28 11:25:45.617: A/libc(31297): 010 63948000: 180224
07-28 11:25:45.617: A/libc(31297): 011 6393d000: 16384
07-28 11:25:45.617: A/libc(31297): 012 638e5000: 360448
07-28 11:25:45.617: A/libc(31297): 013 638aa000: 32768
07-28 11:25:45.617: A/libc(31297): 014 63893000: 65536
07-28 11:25:45.617: A/libc(31297): 015 63875000: 106496
07-28 11:25:45.617: A/libc(31297): 016 63978000: 77824
07-28 11:25:45.617: A/libc(31297): 017 68989000: 12288
07-28 11:25:45.617: A/libc(31297): 018 68990000: 69632
07-28 11:25:45.617: A/libc(31297): 019 68978000: 69632
07-28 11:25:45.617: A/libc(31297): 020 68a7d000: 28672
07-28 11:25:45.617: A/libc(31297): 021 68974000: 16384
07-28 11:25:45.617: A/libc(31297): 022 65795000: 81920
07-28 11:25:45.617: A/libc(31297): 023 6575a000: 98304
07-28 11:25:45.617: A/libc(31297): 024 62e70000: 8192
07-28 11:25:45.617: A/libc(31297): 025 6573b000: 126976
07-28 11:25:45.617: A/libc(31297): 026 630b7000: 16384
07-28 11:25:45.617: A/libc(31297): 027 6573a000: 4096
07-28 11:25:45.617: A/libc(31297): 028 657bb000: 286720
07-28 11:25:45.617: A/libc(31297): 029 63641000: 86016
07-28 11:25:45.617: A/libc(31297): 030 6361e000: 8192
07-28 11:25:45.617: A/libc(31297): 031 635da000: 81920
07-28 11:25:45.617: A/libc(31297): 032 635b5000: 8192
07-28 11:25:45.617: A/libc(31297): 033 635ca000: 65536
07-28 11:25:45.617: A/libc(31297): 034 635c1000: 36864
07-28 11:25:45.617: A/libc(31297): 035 635b8000: 36864
07-28 11:25:45.617: A/libc(31297): 036 635aa000: 45056
07-28 11:25:45.617: A/libc(31297): 037 635a4000: 20480
07-28 11:25:45.617: A/libc(31297): 038 63597000: 28672
07-28 11:25:45.617: A/libc(31297): 039 63656000: 122880
07-28 11:25:45.617: A/libc(31297): 040 6358f000: 32768
07-28 11:25:45.617: A/libc(31297): 041 6353b000: 208896
07-28 11:25:45.617: A/libc(31297): 042 63424000: 73728
07-28 11:25:45.617: A/libc(31297): 043 5d1bd000: 65536
07-28 11:25:45.617: A/libc(31297): 044 5d19a000: 16384
07-28 11:25:45.617: A/libc(31297): 045 5d1b7000: 24576
07-28 11:25:45.617: A/libc(31297): 046 5d198000: 8192
07-28 11:25:45.617: A/libc(31297): 047 5d181000: 53248
07-28 11:25:45.617: A/libc(31297): 048 5d157000: 118784
07-28 11:25:45.617: A/libc(31297): 049 5d13f000: 69632
07-28 11:25:45.617: A/libc(31297): 050 5d12f000: 36864
07-28 11:25:45.617: A/libc(31297): 051 5d0fd000: 118784
07-28 11:25:45.617: A/libc(31297): 052 5d0e7000: 61440
07-28 11:25:45.617: A/libc(31297): 053 5d0d1000: 61440
07-28 11:25:45.617: A/libc(31297): 054 5cec5000: 8192
07-28 11:25:45.617: A/libc(31297): 055 61250000: 12288
07-28 11:25:45.617: A/libc(31297): 056 5d263000: 61440
07-28 11:25:45.617: A/libc(31297): 057 61223000: 184320
07-28 11:25:45.617: A/libc(31297): 058 5ffc3000: 233472
07-28 11:25:45.617: A/libc(31297): 059 5e324000: 65536
07-28 11:25:45.617: A/libc(31297): 060 5d2b8000: 4096
07-28 11:25:45.617: A/libc(31297): 061 5fee3000: 86016
07-28 11:25:45.617: A/libc(31297): 062 5e334000: 278528
07-28 11:25:45.617: A/libc(31297): 063 5e310000: 32768
07-28 11:25:45.617: A/libc(31297): 064 5d32e000: 65536
07-28 11:25:45.617: A/libc(31297): 065 5d2ef000: 118784
07-28 11:25:45.617: A/libc(31297): 066 5d30c000: 20480
07-28 11:25:45.617: A/libc(31297): 067 5d2aa000: 57344
07-28 11:25:45.617: A/libc(31297): 068 5d1f3000: 4096
07-28 11:25:45.617: A/libc(31297): 069 5d44d000: 114688
07-28 11:25:45.617: A/libc(31297): 070 5d272000: 32768
07-28 11:25:45.617: A/libc(31297): 071 5d258000: 36864
07-28 11:25:45.617: A/libc(31297): 072 5d1d6000: 118784
07-28 11:25:45.617: A/libc(31297): 073 5bc34000: 4096
07-28 11:25:45.617: A/libc(31297): 074 5d1d4000: 8192
07-28 11:25:45.617: A/libc(31297): 075 5b5aa000: 53248
07-28 11:25:45.617: A/libc(31297): 076 5a5ad000: 4096
07-28 11:25:45.617: A/libc(31297): 077 5a5a2000: 12288
07-28 11:25:45.617: A/libc(31297): 078 5a597000: 12288
07-28 11:25:45.617: A/libc(31297): 079 5a1b5000: 4096
07-28 11:25:45.617: A/libc(31297): 080 5a1a1000: 20480
07-28 11:25:45.617: A/libc(31297): 081 5919c000: 20480
07-28 11:25:45.617: A/libc(31297): 082 59193000: 12288
07-28 11:25:45.617: A/libc(31297): 083 43035000: 24576
07-28 11:25:45.617: A/libc(31297): 084 43031000: 12288
07-28 11:25:45.617: A/libc(31297): 085 40039000: 4096
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr 0x62eaa808(p), cinuse(1), pinuse(1), chunksize(-8)
07-28 11:25:45.617: A/libc(31297): 62eaa808: 62eaaf24 prev_foot
07-28 11:25:45.617: A/libc(31297): 62eaa80c: ffffffff head
07-28 11:25:45.617: A/libc(31297): 62eaa810: 6e676973 fd
07-28 11:25:45.617: A/libc(31297): 62eaa814: 36206c61 bk
07-28 11:25:45.617: A/libc(31297): 62eaa818: 72502820 child[0]
07-28 11:25:45.617: A/libc(31297): 62eaa81c: 7365636f child[1]
07-28 11:25:45.617: A/libc(31297): 62eaa820: 62612073 parent
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr p->fd is invalid with any segment
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr p->bk is invalid with any segment
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr "prev" is inuse
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr "next" is invalid with any segment
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr p->child[0] is invalid with any segment
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr p->child[1] is invalid with any segment
07-28 11:25:45.617: A/libc(31297): *** *** *** *** *** *** *** HEAP INFO *** *** *** *** *** *** ***
07-28 11:25:45.617: A/libc(31297): chunk ptr p->parent is invalid with any segment
07-28 11:25:45.617: A/libc(31297): invalid address or address of corrupt block 0x62eaa808 passed to dlfree
07-28 11:25:45.617: A/libc(31297): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 31647 (AsyncTask #5)
07-28 11:25:46.087: D/dalvikvm(32216): Late-enabling CheckJNI
07-28 11:25:46.087: D/dalvikvm(32216): Try to disable coredump for pid 32216

07-28 11:25:46.087: D/dalvikvm(32216): Process 32216 nice name: com.ircm

Is there something i do wrong? Im running under 4.4.2

Not work on catching divide by zero error

static __attribute__ ((noinline)) void demo(int *fault) {
    COFFEE_TRY() {
        LOGD("_TEST", "num div:%d", 1 / (*fault));
        *fault = 0;
    } COFFEE_CATCH() {
        const char*const message = coffeecatch_get_message();
        snprintf(string_buffer, sizeof(string_buffer), "%s", message);
        *fault = 1;
    } COFFEE_END();
}

crash when *fault is 0
logcat is:
--------- beginning of crash 10-09 14:45:45.711 6975-6975/? A/libc: Fatal signal 8 (SIGFPE), code -6, fault addr 0x1b3f in tid 6975 (xample.hellojni)

My Phone is Nexus 5 Android 5.1.1

Unstable catching

I can't understand and this can probably be not coffeecatch issue, but it seems to be.

Sometimes crash is not catched and the process just die:

case 1 (catched):

03-06 18:49:47.562: ERROR/CLANG_WRAPPER(4862): going to test crash
03-06 18:49:47.562: WARN/crash_handler(4862): Caught a crash, signum=11
03-06 18:49:47.562: ERROR/webcore(4862): Report WebCore crash to the ErrorReportUtils at:Thu Mar 06 18:49:47 GMT+05:00 2014
03-06 18:49:47.562: ERROR/CLANG_WRAPPER(4862): catch()
03-06 18:49:47.562: ERROR/CLANG_WRAPPER(4862): ** FATAL ERROR in parseTranslationUnit(): signal 11 (Address not mapped to object) at address 0x0 [at libclang_wrapper.so:0x89d0 (Java_name_antonsmirnov_clang_clang_1wrapper_parseTranslationUnit+0x8c)]
03-06 18:49:47.582: INFO/ActivityManager(539): Process name.antonsmirnov.android.app (pid 4862) has died.
03-06 18:49:47.582: WARN/ActivityManager(539): Force removing ActivityRecord{43f2a538 name.antonsmirnov.android.app/.ui.MainActivity}: app died, no saved state

case 2 (died):

03-06 18:51:10.220: ERROR/CLANG_WRAPPER(5120): going to test crash
03-06 18:51:10.230: INFO/CloudTaskManager(1740): [backupApp] pkgName[com.infoshell.recradio]
03-06 18:51:10.230: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[com.physicaloid.app.writer] backup
03-06 18:51:10.230: INFO/CloudTaskManager(1740): [backupApp] pkgName[com.physicaloid.app.writer]
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[com.pdaxrom.cctools.sdlplugin] backup
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [backupApp] pkgName[com.pdaxrom.cctools.sdlplugin]
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[yz.opengl.es11] backup
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [backupApp] pkgName[yz.opengl.es11]
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[slickdevlabs.apps.usbtoserialterm] backup
03-06 18:51:10.240: INFO/CloudTaskManager(1740): [backupApp] pkgName[slickdevlabs.apps.usbtoserialterm]
03-06 18:51:10.250: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[com.example.CoffeeCatchDemo] backup
03-06 18:51:10.250: INFO/CloudTaskManager(1740): [backupApp] pkgName[com.example.CoffeeCatchDemo]
03-06 18:51:10.250: INFO/CloudTaskManager(1740): [tryBackupOneApp] pkgName[jp.ksksue.app.terminal] backup
03-06 18:51:10.250: INFO/CloudTaskManager(1740): [backupApp] pkgName[jp.ksksue.app.terminal]
03-06 18:51:10.250: INFO/ActivityManager(539): Process name.antonsmirnov.android.app (pid 5120) has died.

the code:

COFFEE_TRY() {

        debug("going to test crash\n");
        char *source_filename = NULL; // TODO : UNCOMMENT !!! (JUST FOR TEST) //string_copy(env, jfilename);
        *source_filename = '!';
        debug("no crash happened\n");

        // ...

    } COFFEE_CATCH() {
        debug("catch()");
        const char*const message = coffeecatch_get_message();
        debug("** FATAL ERROR in parseTranslationUnit(): %s\n", message);

        // cancel alarm (otherwise the process die in few seconds)
        coffeecatch_cancel_pending_alarm();

        // throw exception
        coffeecatch_throw_exception(env);
    } COFFEE_END();

Cannot load library: soinfo_relocate(linker.cpp:980): cannot locate symbol "signal" referenced by "libjni.so"...

I'm trying to test my app on Android 4.2.2.
After adding coffeecatch to build with my NDK part, when I'm loading my so lib with System.loadLibrary("jni"), I get the following error in the LogCat:
07-27 19:28:00.433 23135-23135/com.app E/dalvikvm﹕ dlopen("/data/app-lib/com..app-2/libjni.so") failed: Cannot load library: soinfo_relocate(linker.cpp:980): cannot locate symbol "signal" referenced by "libjni.so"...

And loading so lib fails with UnsatisfiedLinkError exception.

What am I missing here or is it a coffeecatch issue?

coffeecatch crash on android 7/8

Coffeecatch crashes on android 7/8.
I only managed to identify the crash point:

/* Call the old handler. */
static void coffeecatch_call_old_signal_handler(const int code, siginfo_t *const si,
                                                       void * const sc) {
     ...
     native_code_g.sa_old[code].sa_handler(code); // <---- here it throws NPE on __rt_sigproc`
     ...
}

If I comment this line out, it works as intended.
I assume it's related to changes to bds_signal in android 7, but I am not able to fix it yet.
If you could give me more insight, maybe I will try to put more time into fixing this.

why coffee signal_abort handler invokes after COFFEE_END() ?

work linux 18.04 i386
i got regular crash SIGSEGV that come to coffeee_signal_abort handler after coffee_end()

why this handlers may invokes after them are released?

trace log shows like:

mote7 enter
dump:initialised=0; 
setup for a new handler
installing global signal handlers
installed global signal handlers
installing thread alternative stack
installing thread alternative
installed thread alternative
dump:initialised=1;  reenter=1; ctx=1 
removing thread alternative stack
removed thread alternative stack
removing global signal handlers
removed global signal handlers              <<- this is coffeecatch_handler_cleanup() reports after pthread_key_delete(native_code_thread)
mote7 done                                             <<-- this is application prints after coffee_end()
caught abort sig11
calling old signal handler 

API level 21 / GCC 4.9 support?

There's a problem building with GCC 4.9 and API 21. __BIONIC_HAVE_UCONTEXT_T is defined there, as well as ucontext structure (but some other structures still aren't defined by the system). I've edited coffeecatch.c and could build it, but of course it doesn't work.

SIGSEGV in coffeecatch_native_code_handler_struct_free

Hi. I am trying to do some little testing of coffeecatch without JNI - in pure C/C++ on Android 4.4.4 x86.
Doing something like this:

test_result_t run_test(int signal) {
    test_result_t result = {false, 0};
    COFFEE_TRY() {
        raise(signal);
    } COFFEE_CATCH() {
        coffeecatch_cancel_pending_alarm();
        result.catched_signal = coffeecatch_get_signal();
    } COFFEE_END();
    result.exited = true;
    return result;
}

int main(int argc, char** argv) {
    test_result_t result = run_test(SIGFPE);
    LOG("SIGFPE CATCH TEST: ");

    ASSERT_TRUE(SIGFPE == result.catched_signal && true == result.exited);
}

Unfortunately i am getting SEGFAULT during COFFEE_END(). Logcat and coffeecatch debug logs attached.

debug.txt
logcat.txt

re-entrant coffeecatch

Occasionally, it makes sense to wrap a callback with coffeecatch. If that callback happens to be called within an existing coffeecatch block, an error occurs -- the first block to finish calls pthread_setspecific(native_code_thread, NULL), and the second block to finish fails at assert(t != NULL);.

It would be handy if coffeecatch supported nested blocks on the same thread. Presumably the right thing to do is just ignore nested calls, and let them propagate up to the outermost block.

Exception is caught but process dies

code:

COFFEE_TRY() {

  // ...

debug("going to test crash\n");
        char *source_filename = NULL; // TODO : UNCOMMENT !!! (JUST FOR TEST) //string_copy(env, jfilename);
        *source_filename = '1';

} COFFEE_CATCH() {
        debug("crash catched by coffee\n");
        const char*const message = coffeecatch_get_message();
        debug("**FATAL ERROR WHILE PARSING TU: %s\n", message);

        // throw exception
        coffeecatch_throw_exception(env);
    } COFFEE_END();

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := xlang_wrapper
LOCAL_SRC_FILES := xlang_wrapper.cpp xlang_wrapper.h coffeecatch/coffeecatch.c coffeecatch/coffeejni.c coffeecatch/coffeejni.h
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_CPP_FEATURES += exceptions

# x86
#LOCAL_CFLAGS := -funwind-tables

# ARM
LOCAL_CFLAGS := -funwind-tables -Wl,--no-merge-exidx-entries

include $(BUILD_SHARED_LIBRARY)

log:

03-01 14:07:46.862: ERROR/CLANG_WRAPPER(2831): going to test crash
03-01 14:07:46.862: WARN/crash_handler(2831): Caught a crash, signum=11
03-01 14:07:46.862: WARN/crash_handler(2831): Caught a crash, signum=11
03-01 14:07:46.862: ERROR/webcore(2831): Report WebCore crash to the ErrorReportUtils at:Sat Mar 01 14:07:46 GMT+05:00 2014
03-01 14:07:46.862: ERROR/webcore(2831): Report WebCore crash to the ErrorReportUtils at:Sat Mar 01 14:07:46 GMT+05:00 2014
03-01 14:07:46.892: INFO/ActivityThread(2875): Pub com.google.android.finsky.QSBSuggestionsProvider2: com.google.android.finsky.providers.QSBSuggestionsProvider
03-01 14:07:46.892: INFO/ActivityThread(2875): Pub com.google.android.finsky.AppIconProvider: com.google.android.finsky.providers.AppIconProvider
03-01 14:07:46.892: INFO/ActivityThread(2875): Pub com.google.android.finsky.RecentSuggestionsProvider: com.google.android.finsky.providers.RecentSuggestionsProvider
03-01 14:07:46.902: DEBUG/dalvikvm(544): GC_EXPLICIT freed 198K, 16% free 27849K/33095K, paused 4ms+14ms, total 123ms
03-01 14:07:46.912: INFO/ActivityManager(544): Start proc com.android.browser.CrashReportService for service com.android.browser/.CrashReportService: pid=2892 uid=10004 gids={3003, 1015, 1007, 1028}
03-01 14:07:46.932: DEBUG/dalvikvm(1235): WAIT_FOR_CONCURRENT_GC blocked 0ms
03-01 14:07:46.962: WARN/CppDroid(2831): No add-ons update available
03-01 14:07:46.972: DEBUG/dalvikvm(1235): GC_EXPLICIT freed 65K, 38% free 11563K/18563K, paused 2ms+3ms, total 39ms
03-01 14:07:47.022: DEBUG/Finsky(2875): [1] FinskyApp.onCreate: Initializing network with DFE https://android.clients.google.com/fdfe/
03-01 14:07:47.032: DEBUG/dalvikvm(917): WAIT_FOR_CONCURRENT_GC blocked 0ms
03-01 14:07:47.062: INFO/themeservice(544): unbinding service
03-01 14:07:47.073: DEBUG/dalvikvm(917): GC_EXPLICIT freed 507K, 43% free 10664K/18563K, paused 5ms+5ms, total 39ms
03-01 14:07:47.073: DEBUG/ActivityThread(2892): setTargetHeapUtilization:0.50
03-01 14:07:47.073: DEBUG/ActivityThread(2892): setTargetHeapIdealFree:8388608
03-01 14:07:47.073: DEBUG/ActivityThread(2892): setTargetHeapConcurrentStart:2097152
03-01 14:07:47.093: DEBUG/ads-notify-fd5dfce4(2892): 打开的 app 是: com.android.browser
03-01 14:07:47.123: WARN/dalvikvm(2875): VFY: unable to resolve static method 818: Landroid/provider/Settings$Global;.getInt (Landroid/content/ContentResolver;Ljava/lang/String;I)I
03-01 14:07:47.123: DEBUG/Finsky(2875): [1] DailyHygiene.goMakeHygieneIfDirty: No need to run daily hygiene.
03-01 14:07:47.133: DEBUG/ads-notify-fd5dfce4(2892): 通道进行初始化
03-01 14:07:47.143: DEBUG/ads-notify-fd5dfce4(2892): 通道进行初始化OK
03-01 14:07:47.153: DEBUG/PushService(1061): 2014-03-01 14:07:47,161 - [DEBUG::PushService] - onStart() with intent.Action = null
03-01 14:07:47.193: INFO/CloudMetadataBackupTask(1785): [createPkg] pkg[@metadata] baseNum[8] incNum[0]
03-01 14:07:47.323: DEBUG/Finsky(2875): [1] 2.run: Loaded library for account: [g2YgH0p_iQGZCwH3A5EEAxMAKgA]
03-01 14:07:47.343: DEBUG/Finsky(2875): [1] GmsCoreHelper.cleanupNlp: result=false type=1
03-01 14:07:47.373: DEBUG/dalvikvm(544): WAIT_FOR_CONCURRENT_GC blocked 0ms
03-01 14:07:47.383: DEBUG/Finsky(2875): [1] 2.run: Loaded library for account: [i7bGDDK9jBGO9jV8bFB6Dp5br24]
03-01 14:07:47.413: DEBUG/Finsky(2875): [1] 2.run: Loaded library for account: [Bvwv1smpzweaveu7wI5r2uVMG2k]
03-01 14:07:47.413: DEBUG/Finsky(2875): [1] 2.run: Finished loading 3 libraries.
03-01 14:07:47.493: DEBUG/dalvikvm(544): GC_EXPLICIT freed 255K, 17% free 27781K/33095K, paused 3ms+7ms, total 117ms
03-01 14:07:47.523: DEBUG/Finsky(2875): [1] RestoreTracker.stopServiceIfDone: Restore complete with 0 success and 0 failed.
03-01 14:07:47.733: DEBUG/dalvikvm(544): WAIT_FOR_CONCURRENT_GC blocked 0ms
03-01 14:07:47.853: DEBUG/dalvikvm(544): GC_EXPLICIT freed 94K, 17% free 27784K/33095K, paused 3ms+9ms, total 126ms
03-01 14:07:47.933: INFO/ActivityManager(544): Process name.antonsmirnov.android.app (pid 2831) has died.

Architecture not supported for x86_64

Im building with android-ndk-r10e API Level 21 for x86_64 and i'm getting the error "Architecture is not supported (unknown ucontext layout)". I see that ucontext.h is supported for x86_64, so have included x86_64 in the coffe_catch.c and it worked.

I hope no issues.

Can not call abort() in coffeecatch_signal_pass is ok?

I enable coffeecatch in my thread. When other thread crashed, is captured by coffeecatch and call abort() in coffeecatch_signal_pass, receive android crash stacktrace as:

02-16 11:46:33.521: A/DEBUG(288): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-16 11:46:33.522: A/DEBUG(288): Build fingerprint: 'Xiaomi/cancro_wc_lte/cancro:6.0.1/MMB29M/7.2.9:user/release-keys'
02-16 11:46:33.522: A/DEBUG(288): Revision: '0'
02-16 11:46:33.522: A/DEBUG(288): ABI: 'arm'
02-16 11:46:33.523: A/DEBUG(288): pid: 13619, tid: 13619, name: test.example.sk >>> test.example.sk <<<
02-16 11:46:33.523: A/DEBUG(288): signal 6 (SIGABRT), code 1 (?), fault addr --------
02-16 11:46:33.563: A/DEBUG(288): r0 00000000 r1 00003533 r2 00000006 r3 b6f53b7c
02-16 11:46:33.564: A/DEBUG(288): r4 b6f53b84 r5 b6f53b34 r6 00000002 r7 0000010c
02-16 11:46:33.564: A/DEBUG(288): r8 b6f32c4c r9 b4abf820 sl 00000000 fp b6f32c34
02-16 11:46:33.565: A/DEBUG(288): ip 00000006 sp b6f32ba0 lr b6cb0c69 pc b6cb3058 cpsr 400e0010
02-16 11:46:33.602: A/DEBUG(288): backtrace:
02-16 11:46:33.602: A/DEBUG(288): #00 pc 00042058 /system/lib/libc.so (tgkill+12)
02-16 11:46:33.603: A/DEBUG(288): #1 pc 0003fc65 /system/lib/libc.so (pthread_kill+32)
02-16 11:46:33.603: A/DEBUG(288): #2 pc 0001c403 /system/lib/libc.so (raise+10)
02-16 11:46:33.604: A/DEBUG(288): #3 pc 000195b5 /system/lib/libc.so (__libc_android_abort+34)
02-16 11:46:33.604: A/DEBUG(288): #4 pc 00017508 /system/lib/libc.so (abort+4)
02-16 11:46:33.605: A/DEBUG(288): #5 pc 000121eb /data/app/test.example.sk-2/lib/arm/libsk.so
02-16 11:46:33.605: A/DEBUG(288): #6 pc 0036cc9b /system/lib/libart.so (_ZN3art12FaultManager11HandleFaultEiP7siginfoPv+530)
02-16 11:46:33.606: A/DEBUG(288): #7 pc 0001756c /system/lib/libc.so
02-16 11:46:34.539: A/DEBUG(288): Tombstone written to: /data/tombstones/tombstone_05
02-16 11:46:34.539: E/DEBUG(288): AM write failed: Broken pipe

I comment out abort() and found crash stacktrace at real crash position:
//DEBUG(print("calling abort()\n"));
//signal(SIGABRT, SIG_DFL);
//abort();

LOCAL_CPP_FLAGS too?

In Android code using C++, should we also use:
LOCAL_CPPFLAGS += -funwind-tables -Wl,--no-merge-exidx-entries
or only:
LOCAL_CFLAGS += -funwind-tables -Wl,--no-merge-exidx-entries

how to protect from _Unwind_Backtrace crash

i`ve got catch SIGSEGV, and found that recovering backtrace info is crashed with such output:

caught abort sig11
abort in context $0xc7224fc0
copy context
called unwind callback for $0xc7226c30
returned _URC_OK
called unwind callback for $0xc7226c30
returned _URC_OK
called unwind callback for $0xc7226c30
returned _URC_OK

that`s end.

is there any way to protect from crash in _Unwind_Backtrace ?

How to Integrate coffeecatch for more no of methods.

Hello,
I have a large JNI project, which does lots of work for my android. I would like to integrate coffeecatch to identify the exact crash reason. But I don't want to use coffeetry and catch for every method. I would like to integrate this for globally. Can you please advise how can I achieve it?
Thanks

Doesn't catch SIGSEGV on Android

I am trying to use COFFEE_TRY_JNI on Android, but it does not seem to catch the signal. I just copied the coffeecatch source files in my project, and had to remove some of those parts because Android now apparently has them. I only removed what was "duplicated" (keeping the system one and removing the one in coffeecatch.c).

I get the following crash:

Fatal signal 11 (SIGSEGV), code 2, fault addr 0x7969a63cb6 in tid 20990 (DefaultDispatch)

From this code, calling runNative from Java (well, Kotlin actually):

__attribute__ ((noinline))
static void run() {
    char *test = "blah";
    *(test + 1) = 'n';
}

__attribute__ ((noinline))
static void run_protected(JNIEnv *env) {
    COFFEE_TRY_JNI(env, run());
}

JNIEXPORT void JNICALL
Java_com_example_JniApi_00024Companion_runNative(
        JNIEnv *env, jobject thiz) {
    run_protected(env);
}

Am I missing something?

Add support for Android 5.0

There's no "libcorkscrew" in Android 5.0. Instead, there's a C++-based "libbacktrace.so".
here's a sample code to use it:

include "backtrace/Backtrace.h"

int btdump(int sig, struct siginfo * info, void * ctx) {

    //Backtrace* t = Backtrace::Create(getpid(),0,NULL );
    void* libbacktrace = dlopen( "libbacktrace.so", RTLD_LOCAL );
    if ( !libbacktrace ) 
        return -1;
    Backtrace* (*create)(int,int,void*);
    *(void**)&create = dlsym( libbacktrace, "_ZN9Backtrace6CreateEiiP12BacktraceMap" );
    if ( !create ) 
        return -1;
    Backtrace* t = create(getpid(), 0, NULL );
    if ( !t ) 
        return -1;

    int ret = t->Unwind(0, (ucontext*)ctx);
    if ( !ret ) {
        return -1;
    }
    int count = t->NumFrames();

    DUMP( "backtrace:" );
    for ( int i=0; i<count; i++ ) {
        std::string line = t->FormatFrameData(i);
        DUMP( "\t%s",line.c_str());

    }
    return 0;
}

crash in libc from pthread_key_delete

Hi Xavier, I'm using COFFEE_TRY_JNI as described in your examples with multiple threads. During some stability testing I'm seeing a crash in libc.so when coffeecatch_cleanup calls pthread_key_delete. It doesn't happen all the time and I've seen it on multiple android versions...any ideas on this one?

Redinition & Previous definition error: _libc_fpreg , struct _libc_fpreg, etc,.

When I try to Build project from terminal getting following error: ndk-build

C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:120:8: error: redefinition of '_libc_fpreg'
struct _libc_fpreg {
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:174:8: note: previous definition is here
struct _libc_fpreg {
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:126:8: error: redefinition of '_libc_fpstate'
struct _libc_fpstate {
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:179:8: note: previous definition is here
struct _libc_fpstate {
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:138:19: error: typedef redefinition with different types
('uint32_t' (aka 'unsigned int') vs 'int')
typedef uint32_t greg_t;
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:171:13: note: previous definition is here
typedef int greg_t;
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:145:3: error: typedef redefinition with different types
('struct mcontext_t' vs 'struct mcontext_t')
} mcontext_t;
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:198:3: note: previous definition is here
} mcontext_t;
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:148:3: error: redefinition of enumerator 'REG_GS'
REG_GS = 0,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:130:16: note: expanded from macro 'REG_GS'
#define REG_GS REG_GS
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:129:3: note: previous definition is here
REG_GS = 0,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:149:3: error: redefinition of enumerator 'REG_FS'
REG_FS,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:132:16: note: expanded from macro 'REG_FS'
#define REG_FS REG_FS
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:131:3: note: previous definition is here
REG_FS,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:150:3: error: redefinition of enumerator 'REG_ES'
REG_ES,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:134:16: note: expanded from macro 'REG_ES'
#define REG_ES REG_ES
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:133:3: note: previous definition is here
REG_ES,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:151:3: error: redefinition of enumerator 'REG_DS'
REG_DS,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:136:16: note: expanded from macro 'REG_DS'
#define REG_DS REG_DS
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:135:3: note: previous definition is here
REG_DS,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:152:3: error: redefinition of enumerator 'REG_EDI'
REG_EDI,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:138:17: note: expanded from macro 'REG_EDI'
#define REG_EDI REG_EDI
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:137:3: note: previous definition is here
REG_EDI,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:153:3: error: redefinition of enumerator 'REG_ESI'
REG_ESI,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:140:17: note: expanded from macro 'REG_ESI'
#define REG_ESI REG_ESI
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:139:3: note: previous definition is here
REG_ESI,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:154:3: error: redefinition of enumerator 'REG_EBP'
REG_EBP,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:142:17: note: expanded from macro 'REG_EBP'
#define REG_EBP REG_EBP
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:141:3: note: previous definition is here
REG_EBP,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:155:3: error: redefinition of enumerator 'REG_ESP'
REG_ESP,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:144:17: note: expanded from macro 'REG_ESP'
#define REG_ESP REG_ESP
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:143:3: note: previous definition is here
REG_ESP,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:156:3: error: redefinition of enumerator 'REG_EBX'
REG_EBX,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:146:17: note: expanded from macro 'REG_EBX'
#define REG_EBX REG_EBX
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:145:3: note: previous definition is here
REG_EBX,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:157:3: error: redefinition of enumerator 'REG_EDX'
REG_EDX,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:148:17: note: expanded from macro 'REG_EDX'
#define REG_EDX REG_EDX
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:147:3: note: previous definition is here
REG_EDX,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:158:3: error: redefinition of enumerator 'REG_ECX'
REG_ECX,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:150:17: note: expanded from macro 'REG_ECX'
#define REG_ECX REG_ECX
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:149:3: note: previous definition is here
REG_ECX,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:159:3: error: redefinition of enumerator 'REG_EAX'
REG_EAX,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:152:17: note: expanded from macro 'REG_EAX'
#define REG_EAX REG_EAX
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:151:3: note: previous definition is here
REG_EAX,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:160:3: error: redefinition of enumerator 'REG_TRAPNO'
REG_TRAPNO,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:154:20: note: expanded from macro 'REG_TRAPNO'
#define REG_TRAPNO REG_TRAPNO
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:153:3: note: previous definition is here
REG_TRAPNO,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:161:3: error: redefinition of enumerator 'REG_ERR'
REG_ERR,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:156:17: note: expanded from macro 'REG_ERR'
#define REG_ERR REG_ERR
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:155:3: note: previous definition is here
REG_ERR,
^
C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/jni/externals/coffeecatch/coffeecatch.c:162:3: error: redefinition of enumerator 'REG_EIP'
REG_EIP,
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:158:17: note: expanded from macro 'REG_EIP'
#define REG_EIP REG_EIP
^
C:/Users/Admin/User1/Sdk/Sdk/ndk-bundle/build//../sysroot/usr/include\sys/ucontext.h:157:3: note: previous definition is here
REG_EIP,
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [C:/Users/Admin/Desktop/test-isssu/testPlugin/testtestLibrary/obj/local/x86/objs/wfds/externals/coffeecatch/coffeecatch.o] Error 1

Let me know If anyother informaiton required

avoid do some not safe work

it can fork a child process,and do work in child process, when receive signal, we can ptrace the child process to get stack information, this solution can be implement or it have some disadvantage? it like android debuggerd process .

Compile errors when using libunwind

I have been trying out coffeecatch (thanks for the useful lib!) and noticed that it was trying to use corkscrew, while I need it to use libunwind as I'm targeting android 5.0+. So, I commended out the #define USE_CORKSCREW and then got the following compile errors:

src/android/coffeecatch.c: In function 'coffeecatch_copy_context':
src/android/coffeecatch.c:546:19: error: request for member 'absolute_pc' in something not a structure or union
       t->frames[i].absolute_pc = (uintptr_t) t->uframes[i];
                   ^
src/android/coffeecatch.c:547:19: error: request for member 'stack_top' in something not a structure or union
       t->frames[i].stack_top = 0;
                   ^
src/android/coffeecatch.c:548:19: error: request for member 'stack_size' in something not a structure or union
       t->frames[i].stack_size = 0;
                   ^
src/android/coffeecatch.c: In function 'coffeecatch_get_backtrace_info':
src/android/coffeecatch.c:1352:40: error: request for member 'absolute_pc' in something not a structure or union
       const uintptr_t pc = t->frames[i].absolute_pc;

Looks like t->frames is of type uintptr_t, is this part of the code still in need of an update?

Thanks again,
Rich

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.