diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt index fb41ae07..40d7dea3 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -7,9 +7,13 @@ expect class Thread() { val current: Thread + fun printCurrentThreadStackTrace() + } val threadName: String + fun printStackTrace() + } \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt index 211c3a01..39fb499c 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -11,6 +11,11 @@ actual class Thread(private val thread: NSThread) { actual val current: Thread get() = Thread(NSThread.currentThread) + + actual fun printCurrentThreadStackTrace() { + Thread.current.printStackTrace() + } + } @@ -30,4 +35,13 @@ actual class Thread(private val thread: NSThread) { ?: "Could not retrieve thread's name" } + + actual fun printStackTrace() { + println("Stack trace of $threadName") + + NSThread.callStackSymbols.forEach { callStackSymbol -> + println(callStackSymbol) + } + } + } \ No newline at end of file diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt index c4e9dddc..5940330c 100644 --- a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Thread.kt @@ -8,6 +8,11 @@ actual class Thread(private val thread: java.lang.Thread) : java.lang.Thread() { actual val current: Thread get() = Thread(currentThread()) + + actual fun printCurrentThreadStackTrace() { + Thread.current.printStackTrace() + } + } @@ -17,4 +22,13 @@ actual class Thread(private val thread: java.lang.Thread) : java.lang.Thread() { actual val threadName: String get() = thread.name + + actual fun printStackTrace() { + println("Stack trace of $threadName") + + thread.stackTrace.forEachIndexed { index, stackTraceElement -> + println("[$index] $stackTraceElement") + } + } + } \ No newline at end of file