Implemented printing stack trace

This commit is contained in:
dankito 2020-09-01 14:11:25 +02:00
parent 61d9923230
commit b6561debb0
3 changed files with 32 additions and 0 deletions

View File

@ -7,9 +7,13 @@ expect class Thread() {
val current: Thread val current: Thread
fun printCurrentThreadStackTrace()
} }
val threadName: String val threadName: String
fun printStackTrace()
} }

View File

@ -11,6 +11,11 @@ actual class Thread(private val thread: NSThread) {
actual val current: Thread actual val current: Thread
get() = Thread(NSThread.currentThread) 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" ?: "Could not retrieve thread's name"
} }
actual fun printStackTrace() {
println("Stack trace of $threadName")
NSThread.callStackSymbols.forEach { callStackSymbol ->
println(callStackSymbol)
}
}
} }

View File

@ -8,6 +8,11 @@ actual class Thread(private val thread: java.lang.Thread) : java.lang.Thread() {
actual val current: Thread actual val current: Thread
get() = Thread(currentThread()) 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 actual val threadName: String
get() = thread.name get() = thread.name
actual fun printStackTrace() {
println("Stack trace of $threadName")
thread.stackTrace.forEachIndexed { index, stackTraceElement ->
println("[$index] $stackTraceElement")
}
}
} }