Add Throwable.getStackTraceAddresses() extension

To allow integration with third-party crash analytic tools.
This commit is contained in:
Svyatoslav Scherbina
2019-09-09 16:45:07 +03:00
committed by SvyatoslavScherbina
parent 931f577db4
commit 47e231efc1
3 changed files with 14 additions and 0 deletions
@@ -34,6 +34,9 @@ public open class Throwable(open val message: String?, open val cause: Throwable
public fun getStackTrace(): Array<String> = stackTraceStrings
internal fun Throwable.getStackTraceAddressesInternal(): List<Long> =
(0 until stackTrace.size).map { index -> stackTrace[index].toLong() }
public fun printStackTrace(): Unit = dumpStackTrace { println(it) }
internal fun dumpStackTrace(): String = buildString {
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
package kotlin.native
public fun Throwable.getStackTraceAddresses(): List<Long> =
this.getStackTraceAddressesInternal()
@@ -52,6 +52,9 @@ internal class NativePtrArray {
@SymbolName("Kotlin_NativePtrArray_set")
external public operator fun set(index: Int, value: NativePtr): Unit
val size: Int
get() = getArrayLength()
@SymbolName("Kotlin_NativePtrArray_getArrayLength")
external private fun getArrayLength(): Int
}