Table of Contents generated with DocToc
This guide covers debugging techniques for both JavaScript and Java code in the FOAM3 project.
The primary tool for debugging JavaScript code is Chrome DevTools. Here are the key features:
Ctrl + Shift + I or F12Cmd + Option + ICmd + P (Mac) or Ctrl + P (Windows/Linux) to quickly search and open files in the Sources paneldebugger; statement in your code// Debugging async code with breakpoints
// Example with custom async function
someAsyncFunction()
.then(result => {
debugger; // Breakpoint will work here
return processResult(result);
})
.catch(error => {
debugger; // Can debug errors
console.error(error);
});
Start the application with debug mode enabled:
./build.sh -d
The -d flag launches the JVM with the JDWP debug agent listening on port 8000. It also passes -g to javac, which includes full debug symbols (source file names, line numbers, and local variable names) in the compiled classes. Without -g, the debugger cannot display local variable values.
To use a different port:
./build.sh -D9005
FOAM3 has two kinds of Java source files:
Hand-written Java files — located under src/ (e.g., src/foam/crypto/hash/Hashable.java). These are regular .java files written by developers.
Generated Java files — located under build/src/java/ (e.g., build/src/java/foam/core/demo/DemoObject.java, generated from src/foam/core/demo/DemoObject.js). These are generated from FOAM .js model definitions during the build. They are recreated on every build and should never be edited directly.
When configuring a debugger, both source directories must be listed so the debugger can resolve breakpoints in both hand-written and generated code. The order matters: src/ should come first so that hand-written files take priority when the same class name exists in both locations.
Install the Extension Pack for Java (includes Debugger for Java)
Create or update .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "FOAM3 Remote Debug",
"request": "attach",
"hostName": "localhost",
"port": 8000,
"projectName": "myproject",
"sourcePaths": [
"${workspaceFolder}/src",
"${workspaceFolder}/build/src/java",
"${workspaceFolder}/foam3/src"
]
}
]
}
Configuration notes:
sourcePaths — Lists directories where the debugger looks for source files. Order matters:
src/ — hand-written Java files (checked first, e.g., src/foam/crypto/hash/Hashable.java)build/src/java/ — FOAM-generated Java files (e.g., build/src/java/foam/core/demo/DemoObject.java)foam3/src/ — FOAM3 framework source (for stepping into framework code)projectName — Must match the project name shown in VS Code’s Java Projects panel (typically the workspace folder name). Replace myproject with your actual project name.port — Must match the debug port used in ./build.sh -d (default 8000)./build.sh -d, then press F5 in VS Code or select Run → Start DebuggingWhen the debugger hits a breakpoint:
myObj.getId())myObj.toString())If the Variables panel is empty at a breakpoint, the code was likely compiled without -g. Rebuild with ./build.sh -d to include debug symbols.
Start the application with ./build.sh -d
FOAM3 Remote Debuglocalhost8000Shift + F9