Allow raw stack traces when symbols have been removed.
Change on 2019/02/13 by antoniocortes
@@ -82,25 +82,34 @@ static jboolean ShouldFilterStackElement(JavaLangStackTraceElement *element) {
return false;
}
-jarray Java_java_lang_Throwable_nativeGetStackTrace(
- JNIEnv *_env_, jclass _cls_, jobject stackState) {
- RawStack *rawStack = stackState;
- NSMutableArray *frames = [NSMutableArray array];
- if (rawStack) {
+static void ProcessRawStack(RawStack *rawStack, NSMutableArray *frames, jboolean applyFilter) {
for (unsigned i = 0; i < rawStack->count_; i++) {
JavaLangStackTraceElement *element =
[[JavaLangStackTraceElement alloc] initWithLong:(jlong)rawStack->frames_[i]];
- if (!ShouldFilterStackElement(element)) {
+ if (!applyFilter || !ShouldFilterStackElement(element)) {
[frames addObject:element];
}
[element release];
}
+}
+
+jarray Java_java_lang_Throwable_nativeGetStackTrace(
+ JNIEnv *_env_, jclass _cls_, jobject stackState) {
+ RawStack *rawStack = stackState;
+ NSMutableArray *frames = [NSMutableArray array];
+ if (rawStack) {
+ ProcessRawStack(rawStack, frames, true);
JavaLangStackTraceElement *element = [frames lastObject];
// Remove initial Method.invoke(), so app's main method is last.
if ([[element getClassName] isEqualToString:@"JavaLangReflectMethod"] &&
[[element getMethodName] isEqualToString:@"invoke"]) {
[frames removeLastObject];
}
+ // If symbols were removed, the stack trace will be empty at this point.
+ // In order to help with debugging, return the raw stack trace.
+ if ([frames count] == 0) {
+ ProcessRawStack(rawStack, frames, false);
+ }
}
return [IOSObjectArray arrayWithNSArray:frames type:JavaLangStackTraceElement_class_()];
}
