Skip to content

Commit 3923e64

Browse files
authored
Add some guidance for running Java debugger (#436)
1 parent 7466d79 commit 3923e64

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

DEVELOPMENT-GUIDE.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,27 @@ So, when you are in a critical region there are exceedingly few operations you c
191191
Essentially, all you can do is methods which manipulate your critical region until you get out of it.
192192
It is **extremely important** that you do not allocate *any* Java memory (such as creating Java objects, like a Java Exception), call *any* Java methods (which you shouldn't be doing anyway), or take any actions which may block.
193193
It is also **very important** that you don't spend too much time (more than about a millisecond) in a critical region.
194-
If you are concerned that an operation is not reasonably time-bounded, you should probably be sure to release the critical region on a regular basis to ensure the JVM has the opportunity to do needed memory management. (This isn't always achievable when everything is happening within a single atomic cryptographic operation.)
194+
If you are concerned that an operation is not reasonably time-bounded, you should probably be sure to release the critical region on a regular basis to ensure the JVM has the opportunity to do needed memory management. (This isn't always achievable when everything is happening within a single atomic cryptographic operation.)
195+
196+
# Java Debugger Support
197+
Due to ACCP's unconventional build system, IDEs are not able to automatically configure, run, and debug the unit tests.
198+
This is largely because of how we use of Gradle/CMake to run the unit tests via the JUnit CLI which allows us to
199+
incorporate the natively compiled portion of the library. A simple workaround is to use the singleTest task along with
200+
JVM arguments to start a remote Java debugger session. This then allows you to connect and debug your test in the IDE.
201+
202+
```
203+
# 1. Create a new Run/Debug Configuration for "Remote JVM Debug" in IntelliJ or the equivalent for your IDE.
204+
205+
# 2. Launch your test target using the singlelTest target. n.b. Suspend is set to y to break immediately.
206+
TEST_CLASS=com.amazon.corretto.crypto.provider.test.KeyGeneratorTest
207+
./gradlew \
208+
-DTEST_JAVA_ARGS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' \
209+
-DSINGLE_TEST=${TEST_CLASS} \
210+
singleTest
211+
212+
# 3. Wait for the server to start listening.
213+
...
214+
Listening for transport dt_socket at address: 5005
215+
216+
# 4. Set a breakpoint in the IDE and connect to the JVM debug server.
217+
```

build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ task executeCmake(type: Exec) {
363363
if (isExperimentalFips) {
364364
args '-DEXPERIMENTAL_FIPS=ON'
365365
}
366+
366367
if (isFipsSelfTestFailureSkipAbort) {
367368
args '-DFIPS_SELF_TEST_SKIP_ABORT=ON'
368369
}
@@ -371,24 +372,23 @@ task executeCmake(type: Exec) {
371372
args '-DSIGNED_JAR=' + prebuiltJar
372373
println "Using SIGNED_JAR=${prebuiltJar}"
373374
}
374-
375375
if (System.properties['JAVA_HOME'] != null) {
376376
args '-DJAVA_HOME=' + System.properties['JAVA_HOME']
377377
}
378-
379378
if (System.properties['TEST_JAVA_HOME'] != null) {
380379
args '-DTEST_JAVA_HOME=' + System.properties['TEST_JAVA_HOME']
381380
}
382381
if (System.properties['TEST_JAVA_MAJOR_VERSION'] != null) {
383382
args '-DTEST_JAVA_MAJOR_VERSION=' + System.properties['TEST_JAVA_MAJOR_VERSION']
384383
}
384+
if (System.properties['TEST_JAVA_ARGS'] != null) {
385+
args '-DTEST_JAVA_ARGS=' + System.properties['TEST_JAVA_ARGS']
386+
}
385387
if (System.properties['SINGLE_TEST'] != null) {
386388
args '-DSINGLE_TEST=' + System.properties['SINGLE_TEST']
387-
388389
}
389390
if (System.properties['USE_CLANG_TIDY'] != null) {
390391
args '-DUSE_CLANG_TIDY=' + System.properties['USE_CLANG_TIDY']
391-
392392
}
393393
args projectDir
394394
}

0 commit comments

Comments
 (0)