1 /* 2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.debug 6 7 import net.bytebuddy.agent.* 8 import sun.misc.* 9 import java.lang.instrument.* 10 11 @Suppress("unused") 12 internal object AgentPremain { 13 14 @JvmStatic premainnull15 public fun premain(args: String?, instrumentation: Instrumentation) { 16 Installer.premain(args, instrumentation) 17 DebugProbes.install() 18 installSignalHandler() 19 } 20 installSignalHandlernull21 private fun installSignalHandler() { 22 try { 23 Signal.handle(Signal("TRAP")) { // kill -5 24 DebugProbes.dumpCoroutines() 25 } 26 } catch (t: Throwable) { 27 System.err.println("Failed to install signal handler: $t") 28 } 29 } 30 } 31