Skip to main content

pyjdb

Python interface with Java debugger through JDB.

Overview

The JdbProcess uses pexpect to attach to a jdb process and record all the information that is obtained.

For each instruction, we record a dictionary of the following format:

{
  "return": 10000,
  "thread": "main",
  "class.method": "IterPower.iterPower()",
  "method": "iterPower",
  "line": 15,
  "bci": 17,
  "instruction": "return result;"
}

For each instruction, we can also obtain the dictionary of the current method's arguments, as well as all its local variables:

({'base': 10, 'exp': 0}, {'result': 10000})

Example

Let's assume that we have this Java file, IterPower.java:

public class IterPower {
    public static void main(String[] args) {
        // ... parse arguments ...
        System.out.println(iterPower(base, exp));
    }

    public static int iterPower(int base, int exp) {
        int result = 1;
        while (exp > 0) {
            result *= base;
            exp -= 1;
        }
        return result;
    }
}

which has been compiled with debugging information, javac -g IterPower.java. The following is a Python snippet:

import pyjdb
import itertools

p = pyjdb.JdbProcess("IterPower")
p.spawn("10 4")

variables = {}

while True:

    # Try to make an additional step and retrieve local variables
    result = None
    try:
        p.step()
        result = p.locals()
    except pyjdb.EOF:
        break
    if result is None:
        continue

    # Store the values of each variable
    (args, locs) = result
    for (var, val) in itertools.chain(args.items(), locs.items()):
        variables[var] = variables.get(var, list())
        variables[var].append(val)

variables_unique_values = {
    var: list(set(vals)) for (var, vals) in variables.items()
}

print(variables_unique_values)

The snippet will output a trace of the variable values of this program through its execution:

{"args": ["instance of java.lang.String[0] (id=495)"],
 "base": [10],
 "exp": [0, 1, 2, 3, 4],
 "result": [1, 10, 100, 1000, 10000]}

Inspiration

This project was inspired by a talk by Elena Glassman in which she shows how to cluster different implementations of the same solution according to the trace of the internal variables. Her work, which includes OverCode and foobaz, focuses on Python programs. At my home institution, we use Java in our introductory classes. The initial goal of this project was to apply Dr. Glassman's techniques to Java assignments.

There were several ambitious projects related to bringing a Java debugger to Python. These projects highlight how complex an undertaking it is to implement the actual JDWP protocol. This is why in this project, our approach has been to piggy-back on jdb so as to not need to reimplement protocol-level functionality.

  • csuter/pyjdb (abandonned): A Python implementation of the JDWP specifications.

  • soulseekah/pyjdb (abandonned): A jdb replacement with more user-friendly features.

Metadata

Release files for pyjdb 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyjdb 0.0.6
File Size Uploaded
pyjdb-0.0.6.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyjdb 0.0.6
File Interpreter ABI Platform
pyjdb-0.0.6-py2-none-any.whl Python 2 none any Details

Total release size: 21.1 kB

Release files / pyjdb-0.0.6.tar.gz

Download URL pyjdb-0.0.6.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6d8e9d06a4149fe931c4b0b55901360ed5a4d6ca35dc783a757935b156d49b9f
BLAKE2b-256 checksum
How to use checksums
7b6779910b261b2b8b38fb41d1906ec6e7158500cd4cfba547115314a308c827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.15

Release files / pyjdb-0.0.6-py2-none-any.whl

Download URL pyjdb-0.0.6-py2-none-any.whl
Size 12.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
23e9d25b734a769419a88874704ad249ebcdb98e7189cc70d345deb3df0a2929
BLAKE2b-256 checksum
How to use checksums
1b3bc37eca31f6239fdc840b30ed8299e02fb4a6b0efbeaf72f3f1d53e81be93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.15

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page