@@ -182,8 +182,8 @@ internal object DebugProbesImpl {
182182 val coroutinesInfoAsJson = ArrayList <String >(size)
183183 for (info in coroutinesInfo) {
184184 val context = info.context
185- val name = context[CoroutineName .Key ]?.name?.toStringWithQuotes ()
186- val dispatcher = context[CoroutineDispatcher .Key ]?.toStringWithQuotes ()
185+ val name = context[CoroutineName .Key ]?.name?.toStringRepr ()
186+ val dispatcher = context[CoroutineDispatcher .Key ]?.toStringRepr ()
187187 coroutinesInfoAsJson.add(
188188 """
189189 {
@@ -219,7 +219,7 @@ internal object DebugProbesImpl {
219219 {
220220 "declaringClass": "${element.className} ",
221221 "methodName": "${element.methodName} ",
222- "fileName": ${element.fileName?.toStringWithQuotes ()} ,
222+ "fileName": ${element.fileName?.toStringRepr ()} ,
223223 "lineNumber": ${element.lineNumber}
224224 }
225225 """ .trimIndent()
@@ -229,7 +229,7 @@ internal object DebugProbesImpl {
229229 return " [${stackTraceElementsInfoAsJson.joinToString()} ]"
230230 }
231231
232- private fun Any.toStringWithQuotes () = " \" $this \" "
232+ private fun Any.toStringRepr () = toString().repr()
233233
234234 /*
235235 * Internal (JVM-public) method used by IDEA debugger as of 1.4-M3.
@@ -590,3 +590,19 @@ internal object DebugProbesImpl {
590590
591591 private val StackTraceElement .isInternalMethod: Boolean get() = className.startsWith(" kotlinx.coroutines" )
592592}
593+
594+ private fun String.repr (): String = buildString {
595+ append(' "' )
596+ for (c in this @repr) {
597+ when (c) {
598+ ' "' -> append(" \\\" " )
599+ ' \\ ' -> append(" \\\\ " )
600+ ' \b ' -> append(" \\ b" )
601+ ' \n ' -> append(" \\ n" )
602+ ' \r ' -> append(" \\ r" )
603+ ' \t ' -> append(" \\ t" )
604+ else -> append(c)
605+ }
606+ }
607+ append(' "' )
608+ }
0 commit comments