[debugger] limit sensitive information spoiling during breakpoint variant information collection

* Collect only in monorepo (isInternal is not safe)
* All code goes as an optional attachment

Inspired by feedback:
https://jetbrains.slack.com/archives/C1L34V7H8/p1721978736350929

GitOrigin-RevId: 33a01a9f8231db0dded6830aeb3e51383eda750c
This commit is contained in:
Vladimir Parfinenko
2024-07-26 14:09:45 +00:00
committed by intellij-monorepo-bot
parent 49b5c59c13
commit 2d3ae1afee
@@ -3,9 +3,12 @@ package com.intellij.xdebugger.impl.breakpoints
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.readAction
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.IntelliJProjectUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.VirtualFileManager
@@ -33,7 +36,7 @@ private data class Event(val breakpoint: XLineBreakpoint<*>,
val fileUrl: String, val line: Int,
val kind: EventKind, val time: Long)
internal class BreakpointVariantPriorityTracker(private val coroutineScope: CoroutineScope)
internal class BreakpointVariantPriorityTracker(private val project: Project, private val coroutineScope: CoroutineScope)
: XBreakpointListener<XBreakpoint<*>> {
private val events = ArrayDeque<Event>()
@@ -41,7 +44,8 @@ internal class BreakpointVariantPriorityTracker(private val coroutineScope: Coro
private fun isEnabled(): Boolean =
Registry.`is`("debugger.report.non.default.inline.breakpoint") &&
ApplicationManager.getApplication().let { it.isInternal && !it.isUnitTestMode }
IntelliJProjectUtil.isIntelliJPlatformProject(project) &&
!ApplicationManager.getApplication().isUnitTestMode
init {
coroutineScope.launch {
@@ -153,15 +157,27 @@ internal class BreakpointVariantPriorityTracker(private val coroutineScope: Coro
assert(isEnabled()) // Better to do a double check.
LOG.error("""
|Non-default breakpoint variant was set. Not an error, but we are glad to collect them. Thank you for reporting!
|
|Default variant: ${getDescription(fileUrl, defaultBreakpoint)}
|Expected variant: ${getDescription(fileUrl, expectedBreakpoint)}
|
|Context at $fileUrl:${line + 1}:
|${getFileContext(fileUrl, line)}
|""".trimMargin())
val safeDesc = """
|Default variant: ${getDescription(defaultBreakpoint)}
|Expected variant: ${getDescription(expectedBreakpoint)}
""".trimMargin()
val msg = """
|Non-default breakpoint variant was set. Not an error, but we are glad to collect them. Thank you for reporting!
|If you don't ever want to report this, set registry debugger.report.non.default.inline.breakpoint=false.
|
|$safeDesc
""".trimMargin()
val context = """
|$safeDesc
|
|Default variant text: ${getText(fileUrl, defaultBreakpoint)}
|Expected variant text: ${getText(fileUrl, expectedBreakpoint)}
|
|Context at $fileUrl:${line + 1}:
|${getFileContext(fileUrl, line)}
""".trimMargin()
LOG.error(msg, Attachment("context.txt", context))
}
}
@@ -176,14 +192,15 @@ internal class BreakpointVariantPriorityTracker(private val coroutineScope: Coro
}
@RequiresReadLock
private fun getDescription(fileUrl: String, b: XLineBreakpoint<*>): String {
val kind = b.generalDescription
val text = when (val range = b.highlightRange) {
private fun getDescription(b: XLineBreakpoint<*>): String =
"${b.type.id}, ${b.generalDescription}"
@RequiresReadLock
private fun getText(fileUrl: String, b: XLineBreakpoint<*>): String =
when (val range = b.highlightRange) {
null -> "<whole line>"
else -> readDocument(fileUrl) { it.getText(range) }
}
return "${b.type.id}, $kind: $text"
}
@RequiresReadLock
private fun getFileContext(fileUrl: String, line: Int): String {