Simple API for JDB (Java debugger).
The Java Debugger (JDB) is a simple command-line debugger. The objective of this project is to facilitate the use of this debugger without having to worry about creating a process, redirecting output, among others.
- Add one of the options below to the pom.xml file:
<dependency>
<groupId>io.github.wniemiec-component-java</groupId>
<artifactId>jdb</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>wniemiec.component.java</groupId>
<artifactId>jdb</artifactId>
<version>LATEST</version>
</dependency>
- Run
$ mvn install
- Use it
[...]
import wniemiec.component.java.JDB;
[...]
Path workingDirectory = Path.of(".", "bin").toAbsolutePath().normalize();
Path sourcePath = workingDirectory
.resolve(Path.of("..", "tests"))
.normalize();
List<Path> classpaths = List.of(workingDirectory);
List<Path> sourcePaths = List.of(
workingDirectory.relativize(sourcePath)
);
JDB jdb = new JDB.Builder()
.workingDirectory(workingDirectory)
.classPath(classpaths)
.srcPath(sourcePaths)
.build();
jdb.run().send("stop at api.jdb.testfiles.Calculator : 8")
String line = jdb.read();
// Runs until it reaches the breakpoint on line 8
while (!line.contains("Breakpoint")) {
line = jdb.read();
System.out.println(line);
}
jdb.send("step into"); // Enters the function
line = jdb.read();
System.out.println(line);
[...]
Property | Parameter type | Return type | Description | Default parameter value |
---|---|---|---|---|
run | void |
JDB |
Initializes JDB in a new process | - |
quit | void |
void |
Stops JDB process | - |
forceQuit | void |
void |
Try to stops JDB process immediately | - |
send | command: String |
JDB |
Sends a command to JDB. After calling this method, it is necessary to call read() for JDB to process the command |
- |
send | commands: String... |
void |
Sends a command to JDB. After calling this method, it is necessary to call read() for JDB to process the command |
- |
read | void |
String |
Reads JDB output. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached | - |
readAll | void |
List<String> |
Reads all available JDB output. This method will not block if no output is available | `` |
isReady | void |
boolean |
Checks if there is an output available | - |
waitFor | void |
void |
Causes the current thread to block until JDB is finished | - |
isRunning | void |
boolean |
Checks whether JDB is running | - |
Here are the main commands that can be sent to the debugger using the send method.
Command | Description |
---|---|
stop at <class_name>:<line_number> |
Sets up a breakpoint at a particular line number |
stop in <class_name>:<method_name_or_variable_name> |
Sets up a breakpoint on a particular method or on a particular variable |
clear |
Removes all breakpoints |
exit |
Closes JDB |
run |
The execution stops at the first line of the main method. |
step into |
Step to the next line of the code. If the next line of the code is a function call, then it enters the function by driving the control at the top line of the function. |
step over |
Step to the next line of the code. If the next line is a function call, it executes that function in the background and returns the result. |
cont |
Continues execution of the debugged application after a breakpoint, exception, or step. It will stop only if it passes through a breakpoint. |
Details about each version are documented in the releases section.
See the documentation on how you can contribute to the project here.
Name | Type | Description |
---|---|---|
dist | Directory |
Released versions |
docs | Directory |
Documentation files |
src | Directory |
Source files |