Package cs1302.tracer.trace
Class DebugTraceHelper
java.lang.Object
cs1302.tracer.trace.DebugTraceHelper
A collection of methods that are used to generate a debug trace.
Normative References:
- The Java Debug Interface (JDI) Specification (Java SE 21 Edition,
com.sun.jdi). - Java Platform Debugger Architecture (JPDA) Connection and Invocation Architecture.
- Online Python Tutor (OPT) Trace Event Format v3 Specification (Philip Guo, 2013).
-
Method Summary
Modifier and TypeMethodDescriptiongetValidBreakpointLines(CompilationHelper.CompilationResult compilationResult) Return the set of source lines for the compiled classes that can have breakpoints set.getValidBreakpointLinesByFile(CompilationHelper.CompilationResult compilationResult) Return a mapping of source file relative path to valid breakpoint line numbers.static booleanisMoreSpecific(String newType, String existingType, String runtimeClassFqn) Determines whether a new type candidate is more specific than an existing type string for a given concrete runtime class.static OutputSlicesanitizeDebuggeeStderrSlice(OutputSlice rawStderr) Sanitizes captured standard error bytes in an OutputSlice by removing JVM diagnostic banner prefixes without allocating unnecessary intermediate byte arrays.static ExecutionSnapshottrace(CompilationHelper.CompilationResult compilationResult, com.github.javaparser.ast.CompilationUnit parsedSource) Take a snapshot of a program's execution state just before the main method returns.static ExecutionSnapshottrace(CompilationHelper.CompilationResult compilationResult, com.github.javaparser.ast.CompilationUnit parsedSource, String stdin) Take a snapshot of a program's execution state just before the main method returns with stdin.static Map<Integer, List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource) Take snapshots of a program's execution state at the given breakpoints.static Map<Integer, List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, String stdin) Take snapshots of a program's execution state with stdin using a single parsed source.static Map<Integer, List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources) Take snapshots of a program's execution state using multiple parsed source files.static Map<Integer, List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) Take snapshots of a program's execution state with stdin using multiple parsed source files.static ExecutionSnapshottrace(CompilationHelper.CompilationResult compilationResult, List<com.github.javaparser.ast.CompilationUnit> parsedSources) Take a snapshot of a program's execution state just before the main method returns.static ExecutionSnapshottrace(CompilationHelper.CompilationResult compilationResult, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) Take a snapshot of a program's execution state just before the main method returns with stdin.static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, boolean includeMainExit) Run a program under JDI and capture all snapshots in chronological order.static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, boolean includeMainExit, String stdin) Run a program under JDI and capture all snapshots in chronological order with stdin.static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit) Run a program under JDI and capture all snapshots in chronological order.static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit, String stdin) Run a program under JDI and capture all snapshots in chronological order with stdin.static List<ExecutionSnapshot> traceChronologicalWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit, String stdin) Run a program under JDI and capture snapshots chronologically with BreakpointSpecs.static Map<Integer, List<ExecutionSnapshot>> traceLatest(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources) Captures only the latest state per selected line for non-accumulating CLI output.static Map<Integer, List<ExecutionSnapshot>> traceLatest(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) Captures only the latest state per selected line with stdin.static Map<Integer, List<ExecutionSnapshot>> traceLatestWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources) Captures only the latest state per selected breakpoint specification.static Map<Integer, List<ExecutionSnapshot>> traceLatestWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) Captures only the latest state per selected breakpoint specification with stdin.static Map<Integer, List<ExecutionSnapshot>> traceWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) Take snapshots of a program's execution state with stdin using breakpoint specifications.
-
Method Details
-
trace
public static Map<Integer,List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take snapshots of a program's execution state at the given breakpoints.- Parameters:
compilationResult- A properly filled CompilationResult.breakPoints- The source line numbers to snapshot at.parsedSource- Parsed source code for the compiled program.- Returns:
- A mapping from breakpoint line numbers to a list of execution snapshots.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static Map<Integer,List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take snapshots of a program's execution state with stdin using a single parsed source.- Parameters:
compilationResult- A properly filled CompilationResult.breakPoints- The source line numbers to snapshot at.parsedSource- Parsed source code for the compiled program.stdin- The standard input string.- Returns:
- A mapping from breakpoint line numbers to a list of execution snapshots.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static Map<Integer,List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take snapshots of a program's execution state using multiple parsed source files.- Parameters:
compilationResult- A properly filled CompilationResult.breakPoints- The source line numbers to snapshot at.parsedSources- Parsed source codes for the compiled program.- Returns:
- A mapping from breakpoint line numbers to a list of execution snapshots.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static Map<Integer,List<ExecutionSnapshot>> trace(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take snapshots of a program's execution state with stdin using multiple parsed source files.- Parameters:
compilationResult- A properly filled CompilationResult.breakPoints- The source line numbers to snapshot at.parsedSources- Parsed source codes for the compiled program.stdin- The standard input string.- Returns:
- A mapping from breakpoint line numbers to a list of execution snapshots.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceWithSpecs
public static Map<Integer,List<ExecutionSnapshot>> traceWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take snapshots of a program's execution state with stdin using breakpoint specifications.- Parameters:
compilationResult- A properly filled CompilationResult.specs- The breakpoint specifications to snapshot at.parsedSources- Parsed source codes for the compiled program.stdin- The standard input string.- Returns:
- A mapping from breakpoint line numbers to a list of execution snapshots.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceLatest
public static Map<Integer,List<ExecutionSnapshot>> traceLatest(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources) throws Exception Captures only the latest state per selected line for non-accumulating CLI output.- Parameters:
compilationResult- Compiled program.breakPoints- Selected line numbers.parsedSources- Parsed sources.- Returns:
- Latest snapshot mapping in the existing breakpoint shape.
- Throws:
Exception- On tracing or cleanup failure.
-
traceLatest
public static Map<Integer,List<ExecutionSnapshot>> traceLatest(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) throws Exception Captures only the latest state per selected line with stdin.- Parameters:
compilationResult- Compiled program.breakPoints- Selected line numbers.parsedSources- Parsed sources.stdin- Standard input string.- Returns:
- Latest snapshot mapping in the existing breakpoint shape.
- Throws:
Exception- On tracing or cleanup failure.
-
traceLatestWithSpecs
public static Map<Integer,List<ExecutionSnapshot>> traceLatestWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources) throws Exception Captures only the latest state per selected breakpoint specification.- Parameters:
compilationResult- Compiled program.specs- Selected breakpoint specifications.parsedSources- Parsed sources.- Returns:
- Latest snapshot mapping in the existing breakpoint shape.
- Throws:
Exception- On tracing or cleanup failure.
-
traceLatestWithSpecs
public static Map<Integer,List<ExecutionSnapshot>> traceLatestWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) throws Exception Captures only the latest state per selected breakpoint specification with stdin.- Parameters:
compilationResult- Compiled program.specs- Selected breakpoint specifications.parsedSources- Parsed sources.stdin- Standard input string.- Returns:
- Latest snapshot mapping in the existing breakpoint shape.
- Throws:
Exception- On tracing or cleanup failure.
-
sanitizeDebuggeeStderrSlice
Sanitizes captured standard error bytes in an OutputSlice by removing JVM diagnostic banner prefixes without allocating unnecessary intermediate byte arrays.- Parameters:
rawStderr- Raw stderr OutputSlice.- Returns:
- Sanitized stderr OutputSlice.
-
trace
public static ExecutionSnapshot trace(CompilationHelper.CompilationResult compilationResult, com.github.javaparser.ast.CompilationUnit parsedSource) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take a snapshot of a program's execution state just before the main method returns.- Parameters:
compilationResult- CompilationResult from compilation.parsedSource- Parsed source code.- Returns:
- An execution snapshot taken at the end of the main method.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static ExecutionSnapshot trace(CompilationHelper.CompilationResult compilationResult, com.github.javaparser.ast.CompilationUnit parsedSource, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take a snapshot of a program's execution state just before the main method returns with stdin.- Parameters:
compilationResult- CompilationResult from compilation.parsedSource- Parsed source code.stdin- Standard input string.- Returns:
- An execution snapshot taken at the end of the main method.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static ExecutionSnapshot trace(CompilationHelper.CompilationResult compilationResult, List<com.github.javaparser.ast.CompilationUnit> parsedSources) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take a snapshot of a program's execution state just before the main method returns.- Parameters:
compilationResult- CompilationResult from compilation.parsedSources- Parsed source codes.- Returns:
- An execution snapshot taken at the end of the main method.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
trace
public static ExecutionSnapshot trace(CompilationHelper.CompilationResult compilationResult, List<com.github.javaparser.ast.CompilationUnit> parsedSources, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Take a snapshot of a program's execution state just before the main method returns with stdin.- Parameters:
compilationResult- CompilationResult from compilation.parsedSources- Parsed source codes.stdin- Standard input string.- Returns:
- An execution snapshot taken at the end of the main method.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceChronological
public static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, boolean includeMainExit) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Run a program under JDI and capture all snapshots in chronological order.- Parameters:
compilationResult- CompilationResult from compilation.breakPoints- The collection of line numbers where breakpoints should be placed.parsedSource- Parsed source code for the compiled program.includeMainExit- If true, includes the snapshot when main exits.- Returns:
- A list of execution snapshots in chronological order.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceChronological
public static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, com.github.javaparser.ast.CompilationUnit parsedSource, boolean includeMainExit, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Run a program under JDI and capture all snapshots in chronological order with stdin.- Parameters:
compilationResult- CompilationResult from compilation.breakPoints- The collection of line numbers where breakpoints should be placed.parsedSource- Parsed source code for the compiled program.includeMainExit- If true, includes the snapshot when main exits.stdin- Standard input string.- Returns:
- A list of execution snapshots in chronological order.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceChronological
public static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Run a program under JDI and capture all snapshots in chronological order.- Parameters:
compilationResult- CompilationResult from compilation.breakPoints- The collection of line numbers where breakpoints should be placed.parsedSources- Parsed source codes for the compiled program.includeMainExit- If true, includes the snapshot when main exits.- Returns:
- A list of execution snapshots in chronological order.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceChronological
public static List<ExecutionSnapshot> traceChronological(CompilationHelper.CompilationResult compilationResult, Collection<Integer> breakPoints, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Run a program under JDI and capture all snapshots in chronological order with stdin.- Parameters:
compilationResult- A properly filled CompilationResult.breakPoints- The collection of line numbers where breakpoints should be placed.parsedSources- Parsed source codes for the compiled program.includeMainExit- If true, includes the snapshot when main exits at the end.stdin- Standard input string.- Returns:
- A list of execution snapshots in chronological order.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
traceChronologicalWithSpecs
public static List<ExecutionSnapshot> traceChronologicalWithSpecs(CompilationHelper.CompilationResult compilationResult, Collection<BreakpointSpec> specs, List<com.github.javaparser.ast.CompilationUnit> parsedSources, boolean includeMainExit, String stdin) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, IncompatibleThreadStateException, AbsentInformationException, ClassNotLoadedException Run a program under JDI and capture snapshots chronologically with BreakpointSpecs.- Parameters:
compilationResult- A properly filled CompilationResult.specs- The collection of BreakpointSpecs where breakpoints should be placed.parsedSources- Parsed source codes for the compiled program.includeMainExit- If true, includes the snapshot when main exits at the end.stdin- Standard input string.- Returns:
- A list of execution snapshots in chronological order.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.IncompatibleThreadStateException- If thread state is incompatible.AbsentInformationException- If debug info is missing.ClassNotLoadedException- If class is not loaded.
-
getValidBreakpointLinesByFile
public static Map<String,Set<Integer>> getValidBreakpointLinesByFile(CompilationHelper.CompilationResult compilationResult) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, AbsentInformationException Return a mapping of source file relative path to valid breakpoint line numbers.- Parameters:
compilationResult- The compilation result to inspect.- Returns:
- A map of source file paths to sets of valid line numbers.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.AbsentInformationException- If debug info is missing.
-
getValidBreakpointLines
public static HashSet<Integer> getValidBreakpointLines(CompilationHelper.CompilationResult compilationResult) throws IOException, IllegalConnectorArgumentsException, VMStartException, InterruptedException, AbsentInformationException Return the set of source lines for the compiled classes that can have breakpoints set.- Parameters:
compilationResult- A CompilationResult holding the classes.- Returns:
- A set of valid breakpoint line numbers.
- Throws:
IOException- On I/O error.IllegalConnectorArgumentsException- If JDI connector arguments are invalid.VMStartException- If target VM failed to start.InterruptedException- If thread is interrupted.AbsentInformationException- If debug info is missing.
-
isMoreSpecific
Determines whether a new type candidate is more specific than an existing type string for a given concrete runtime class.- Parameters:
newType- The new type candidate.existingType- The existing type string from objectTypeMap.runtimeClassFqn- The concrete runtime class FQN.- Returns:
- True if newType is more specific.
-