Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
return dsl.build()
}

private const val INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME = "idea.debugger.dispatch.port"

@Suppress("unused")
abstract class KFuzzPlugin : Plugin<Project> {
val log = Logging.getLogger(KFuzzPlugin::class.java)!!
Expand Down Expand Up @@ -71,6 +73,7 @@

doFirst {
systemProperties(fuzzConfig.toPropertiesMap())
systemProperties[INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME] = System.getProperty(INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME)
}
useJUnitPlatform {
includeEngines("kotlinx.fuzz")
Expand All @@ -88,6 +91,7 @@
global.regressionEnabled = true
}.build()
systemProperties(regressionConfig.toPropertiesMap())
systemProperties[INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME] = System.getProperty(INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME)
}
useJUnitPlatform {
includeEngines("kotlinx.fuzz")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.io.DataOutputStream
import java.io.InputStream
import java.io.ObjectInputStream
import java.io.OutputStream
import java.lang.management.ManagementFactory
import java.lang.reflect.Method
import java.net.ServerSocket
import java.net.Socket
Expand Down Expand Up @@ -45,8 +44,6 @@ class JazzerEngine(private val config: KFuzzConfig) : KFuzzEngine {
config.exceptionsDir.createDirectories()
}

private fun isDebugMode(): Boolean = ManagementFactory.getRuntimeMXBean().inputArguments.any { it.contains("-agentlib:jdwp") }

private fun getDebugSetup(intellijDebuggerDispatchPort: Int, method: Method): List<String> {
val port = ServerSocket(0).use { it.localPort }
Socket("127.0.0.1", intellijDebuggerDispatchPort).use { socket ->
Expand All @@ -73,12 +70,9 @@ class JazzerEngine(private val config: KFuzzConfig) : KFuzzEngine {
val methodConfig = config.addAnnotationParams(method.getAnnotation(KFuzzTest::class.java))
val propertiesList = methodConfig.toPropertiesMap().map { (property, value) -> "-D$property=$value" }

val debugOptions = if (isDebugMode()) {
val intellijDebuggerDispatchPort = System.getProperty(INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME)!!.toInt()
getDebugSetup(intellijDebuggerDispatchPort, method)
} else {
emptyList()
}
val debugOptions = System.getProperty(INTELLIJ_DEBUGGER_DISPATCH_PORT_VAR_NAME)?.let { port ->
getDebugSetup(port.toInt(), method)
} ?: emptyList()

val exitCode = ProcessBuilder(
javaCommand,
Expand Down
Loading