Skip to content

Debugging Xdstools2 GWT Client Code

Sunil Bhaskarla edited this page Mar 25, 2024 · 14 revisions

How-to Debug Xdstools2 GWT Client Code

Environment and Tool Requirements

  • NIST XDS Toolkit Release 7.11.0 and above requires Java JDK 16+ (Java 8 is no longer supported) (verify that JAVA_HOME and the Project JDK are both set to 16)
  • NIST XDS Toolkit Release from 7.7.0 to 7.10.0 required Java 8 JDK Development Environment, this is no longer supported.
  • IntelliJ (IJ) Ultimate IDE
  • Apache Tomcat 9.0.26
  • Google Chrome Web Browser

This debugging method was not tested in the IntelliJ Community Edition or other IDEs.

Purpose

GWT 2.8.2 is used in Toolkit to support Java 9+ Runtime. In addition, some Toolkit Maven project dependencies (JARs) were updated, like jackson-annotations-2.11.3.jar, but the Jetty web server inside of GWT SuperDevMode startup failed to start. There is no direct way to debug GWT client code through the IntelliJ IDE. In the past, GWT client code breakpoints were set directly from the IDE, but now with these instructions, the place to set breakpoints changes from the IDE to the Chrome Web Browser.

Example of Jetty startup error

70525 INFO  org.eclipse.jetty.server.Server  - jetty-9.2.14.v20151106
Starting Jetty on port 8888
   [WARN] Failed startup of context c.g.g.d.s.j.WebAppContextWithReload@5f078daf{/,file:/C:/Users/sunil/.IntelliJIdea2019.2/system/gwt/sunil_ij.ec5bdfbc/xdstools2.5fed5012/run/www/,STARTING}{C:\Users\sunil\.IntelliJIdea2019.2\system\gwt\sunil_ij.ec5bdfbc\xdstools2.5fed5012\run\www}
MultiException[java.lang.RuntimeException: Error scanning entry module-info.class from jar file:/C:/Users/sunil/.IntelliJIdea2019.2/system/gwt/sunil_ij.ec5bdfbc/xdstools2.5fed5012/run/www/WEB-INF/lib/jackson-annotations-2.11.3.jar, 

Cause:

The cause is documented here, with no official support, but a walk-around. https://github.com/gwtproject/gwt/issues/9606 Update jetty-9.2.14.v20151106 in gwt-dev to more recent version 9.4+ #9606

Source: https://github.com/gwtproject/gwt/issues/9693#issuecomment-816562015: My TL;DR would be: DevMode is deprecated, use CodeServer instead.

Approach: Use CodeServer

Instead of using GWT’s built-in Jetty server, this approach is to use a separate web application server for development mode.

Reference: http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html#use_my_own_server_in_development_mode_instead_of_GWT

Reference: http://www.gwtproject.org/articles/superdevmode.html

Fix

In Xdstools2.gwt.xml Enable or uncomment this line in the "module" section:

<set-property name="compiler.useSourceMaps" value="true"/>

Optional step

In xdstools2\pom.xml

Enable this line if needed
<!-- <style>DETAILED</style> -->

New Run/Debug IntelliJ configurations are required.

In IntelliJ, Create a new GWT Configuration named "Xdstools2 (client only)" Run/Debug configuration

Open 'Edit Run/Debug configurations' dialog, select GWT Configuration, click the Plus icon to Add New Configuration. (IntelliJ Ultimate Edition supports GWT Configuration.)

Settings

Enable Use Super Dev Mode
Module: xdstools2
GWT modules to load: all
VM options: -Xmx768m --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED  --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
Dev Mode parameters: -noserver -war /C:/Users/sunil/myprojects/iheos-toolkit2/xdstools2/target/xdstools2-7.11.0-SNAPSHOT
* Note: This path must match the Tomcat war exploded directory, more on this later.
working directory: none
Environment variables: none
Server: Default
Start page: xdstools2_war_exploded/Xdstools2.html
JRE: Java 16
[uncheck] Open in browser: Chrome option
[check] with JavaScript debugger option

In IntelliJ, Create a new Tomcat Run/Debug configuration

Use a dedicated Tomcat web server directory for XdsToolkit development by creating a new Tomcat Home directory, for example, apache-tomcat-9.0.26_testxdsdev.

Settings

Application server: Tomcat 9.0.26
After launch:
http://localhost:8888/xdstools2_war_exploded/Xdstools2.html
[uncheck] with JavaScript debugger

VM options:
-DEXTERNAL_CACHE=/C:/Users/skb1/ec/xdsdev -DTOOLKIT_PROPERTIES=/C:/Users/skb1/ec/xdsdevtoolkit.properties --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED  --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
* Note: these options will override the default toolkit properties from the build

JRE: Java 16

HTTP Port 8888

Before launch
Build
Build 'xdstools2:war exploded' artifact

The TOOLKIT_PROPERTIES Java system property allows you to point to an external toolkit.properties file instead of using the default toolkit.properties file that is shipped with Toolkit. The default toolkit.properties file is in WEB-INF/classes/toolkit.properties.

In the Configuration Deployment tab, if the Pencil icon is clicked on 'exploded artifact')

You should see C:\Users\sunil\myprojects\iheos-toolkit2\xdstools2\target\xdstools2-7.11.0-SNAPSHOT

Start Your Debuggers

Make sure only the main Maven user build profile is selected in IntelliJ but not Integration-Tests profile or WebUI-Tests profile. Otherwise, IntelliJ build may fail due to errors. In IntelliJ, Click the Debug icon on the Tomcat configuration first, then after it starts up, click Debug on the GWT configuration (Jetty). Note: Use the IntelliJ Services Tab to view Tomcat Console/Log output and Debugger output for the GWT Log output.

After both servers complete the startup, Check the Debug window tool output of Xdstools2 (client only) Notice the print out

The code server is ready at http://127.0.0.1:9876/
Code server started in 11.26 s ms
Dev Mode initialized. Startup URL: 
http://127.0.0.1:8888/Xdstools2.html

Open http://127.0.0.1:9876/ You should see:

GWT Code Server
Drag these two bookmarklets to your browser's bookmark bar:
Dev Mode On Dev Mode Off
Visit a web page that uses one of these modules:
xdstools2
Click "Dev Mode On" to start development mode.

Create a new Dev Mode On bookmark in the Chrome browser bookmarks bar. Note: This is a one-time setup, once the bookmark is made, it not necessary to re-create the bookmark.

This web browser tab should already be open, if not, open:

http://localhost:8888/xdstools2_war_exploded/Xdstools2.html

Click Dev Mode On (bookmark) from the GWT Dev Mode page

You should see

Choose a module to recompile:
• xdstools2: off	Compile

Click Compile

When Recompile is clicked from the Dev Mode on browser shortcut, the following is displayed in the IJ Log and now, the sourcemaps folder should be visible in Chrome Sources navigation tree:

Notice the output displayed in the GWT console:


GET /recompile/xdstools2
   Job gov.nist.toolkit.xdstools2.Xdstools2_1_0
      starting job: gov.nist.toolkit.xdstools2.Xdstools2_1_0
      binding: locale=default
      binding: user.agent=safari
      Compiling module gov.nist.toolkit.xdstools2.Xdstools2
         Unification traversed 67967 fields and methods and 6023 types. 5981 are considered part of the current module and 5981 had all of their fields and methods traversed.
         Warnings in com/google/gwt/emul/java/util/Arrays.java
            [WARN] Line 1782: [unusable-by-js] Type of parameter 'd1' in 'int Arrays.1methodref$compare$Type.compare(long, long)' is not usable by but exposed to JavaScript.
            [WARN] Line 1782: [unusable-by-js] Type of parameter 'd2' in 'int Arrays.1methodref$compare$Type.compare(long, long)' is not usable by but exposed to JavaScript.
         [WARN] Suppress "[unusable-by-js]" warnings by adding a `@SuppressWarnings("unusable-by-js")` annotation to the corresponding member.
         Compiling 1 permutation
            Compiling permutation 0...
            Linking per-type JS with 5960 new/changed types.
            Source Maps Enabled
         Compile of permutations succeeded
         Compilation succeeded -- 26.531s
      Linking into C:\Users\skb1\AppData\Local\Temp\1\gwt-codeserver-4923208501775209484.tmp\gov.nist.toolkit.xdstools2.Xdstools2\compile-2\war\xdstools2; Writing extras to C:\Users\skb1\AppData\Local\Temp\1\gwt-codeserver-4923208501775209484.tmp\gov.nist.toolkit.xdstools2.Xdstools2\compile-2\extras\xdstools2
         Link succeeded
         Linking succeeded -- 1.881s
      28.661s total -- Compile completed

Setting breakpoints

In the Chrome browser tab, Open Chrome Inspector or use keyboard shortcut Ctrl+Shift+I

Navigate to Sources, open xdstools2 (Xdstools2.html)\127.0.0.1:9876

Under this tree node item, you should see

sourcemaps/xdstools2

Open the desired Client code (Java sourcemap) in gov/nist/toolkit.

Set a breakpoint.

Debug.

Screenshot of a breakpoint set in Chrome Web Browser: xdstoolkit-gui-debugging-in-chrome-screenshot-03252024

Tips

Code can be changed in the IntelliJ IDE, and changes can be seen in Chrome simply by refreshing the web page.

You should see a message flash "Compiling xdstools2"

In the source code,

GWT.debugger() can be used to automatically trigger a script execution pause in the Chrome debugger.

GWT.log() can be used to see messages in Chrome console.

Alternative IntelliJ Configurations

GWT Configuration

If GWT Configuration is not available, GWT may be started manually from the command-line (not tested)

TODO

Update for Java 16

C:\Users\sunil\mypkgs\Java\jdk1.8.0_221\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59579,suspend=y,server=n -Xmx768m \
-javaagent:C:\Users\sunil\.IntelliJIdea2019.2\system\groovyHotSwap\gragent.jar -javaagent:C:\Users\sunil\.IntelliJIdea2019.2\system\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2019.2.2\lib\idea_rt.jar" \
com.intellij.rt.execution.CommandLineWrapper C:\Users\sunil\AppData\Local\Temp\1\idea_classpath68821142 com.google.gwt.dev.DevMode -superDevMode \
-noserver -war /C:/Users/sunil/myprojects/iheos-toolkit2/xdstools2/target/xdstools2-7.8.0-SNAPSHOT \
-remoteUI 7902:IntelliJIdea -startupUrl Xdstools2.html gov.nist.toolkit.xdstools2.Xdstools2

Tomcat Server

TODO

Update for Java 16

If the IntelliJ Tomcat Server Configuration option is not available, remote attach to a running Tomcat web server may be used (not tested)

IntelliJ Create new Remote configuration
Settings
Debugger Mode: Attach to remote JVM
Transport: Socket
Host: localhost Port: 4999

Command line arguments for remote JVM (this goes in the setenv.bat):
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4999


In the tomcat\bin\setenv.bat
SET "CATALINA_OPTS=%CATALINA_OPTS% -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:4999"
Clone this wiki locally