Skip to content

Commit 62e0f40

Browse files
committed
Introduce Debugger
1 parent 1378e1a commit 62e0f40

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

compiler/test/dotty/tools/debug/DebugTests.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ object DebugTests extends ParallelTesting:
4242
private def verifyDebug(dir: JFile, testSource: TestSource, warnings: Int, reporters: Seq[TestReporter], logger: LoggedRunnable) =
4343
if Properties.testsNoRun then addNoRunWarning()
4444
else
45-
val status = debugMain(testSource.runClassPath)(_.launch())
45+
val status = debugMain(testSource.runClassPath): debuggee =>
46+
val debugger = Debugger(debuggee.jdiPort, maxDuration)
47+
try debuggee.launch()
48+
finally debugger.dispose()
4649
status match
4750
case Success(output) => ()
4851
case Failure(output) =>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dotty.tools.debug
2+
3+
import com.sun.jdi.*
4+
import scala.jdk.CollectionConverters.*
5+
import scala.concurrent.duration.Duration
6+
7+
class Debugger(vm: VirtualMachine, maxDuration: Duration):
8+
export vm.dispose
9+
10+
object Debugger:
11+
// The socket JDI connector
12+
private val connector = Bootstrap.virtualMachineManager
13+
.attachingConnectors
14+
.asScala
15+
.find(_.getClass.getName == "com.sun.tools.jdi.SocketAttachingConnector")
16+
.get
17+
18+
def apply(jdiPort: Int, maxDuration: Duration): Debugger =
19+
val arguments = connector.defaultArguments()
20+
arguments.get("hostname").setValue("localhost")
21+
arguments.get("port").setValue(jdiPort.toString)
22+
arguments.get("timeout").setValue(maxDuration.toMillis.toString)
23+
val vm = connector.attach(arguments)
24+
new Debugger(vm, maxDuration)
25+

0 commit comments

Comments
 (0)