Skip to content

wniemiec-component-java/jdb

Repository files navigation

JDB

Simple API for JDB (Java debugger).

Coverage status Java compatibility Maven Central release License


❇ Introduction

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.

❓ How to use

  1. Add one of the options below to the pom.xml file:

Using Maven Central (recomended):

<dependency>
  <groupId>io.github.wniemiec-component-java</groupId>
  <artifactId>jdb</artifactId>
  <version>LATEST</version>
</dependency>

Using GitHub Packages:

<dependency>
  <groupId>wniemiec.component.java</groupId>
  <artifactId>jdb</artifactId>
  <version>LATEST</version>
</dependency>
  1. Run
$ mvn install
  1. Use it
[...]

import wniemiec.component.java.JDB;

[...]

Path workingDirectory = Path.of(".", "bin").toAbsolutePath().normalize();
Path sourcePath = workingDirectory
		.resolve(Path.of("..", "tests"))
		.normalize();
List&lt;Path> classpaths = List.of(workingDirectory);
List&lt;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);

[...]

📖 Documentation

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 -

🎮 Commands

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.

🚩 Changelog

Details about each version are documented in the releases section.

🤝 Contribute!

See the documentation on how you can contribute to the project here.

📁 Files

/

Name Type Description
dist Directory Released versions
docs Directory Documentation files
src Directory Source files

See more