Skip to content

Debugging deftype Methods #2453

@cartesian-theatrics

Description

@cartesian-theatrics

The debugger fails when attempting instrument a deftype form. The cause is that the debugger inserts references to to a local variable (cider.nrepl.middleware.debug/STATE__) - binded outside the deftype form - inside the method body. But as stated in the deftype doc, "method bodies are not closures, the local environment includes only the named fields, and those fields can be accessed directly", so not surprisingly it throws with:

Unable to resolve symbol: STATE__ in this context.

There's clearly logic for handling deftype forms in the instrumentation code, but looking at it I'm not sure how it could have ever worked.

In attempting to hack a dirty solution by altering a root var instead of binding a local variable, I was able to instrument the form successfully and begin stepping through the method body, but unfortunately for some reason the :quit command then doesn't work. The eval thread seems to hang.

Steps to reproduce the problem

You can demonstrate by attempting to instrument a deftype form either via. the emacs command or by inserting #debug #dbg in the method body. Also, the cause can be demonstrated easily with:

(let [state 42]
  (deftype Temp [] 
    clojure.lang.IDeref
    (deref [this] state))
  (deref (Temp.)))

I'd be happy to try to patch myself, but haven't yet wrapped my head around the nrepl middleware stuff sufficiently to be able to even really understand the control flow.

CIDER version information

Version: 20180915.645
Commit: baa0430

Lein/Boot version

Leiningen 2.8.1 on Java 1.8.0_181 OpenJDK 64-Bit Server VM

Emacs version

GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2018-05-28

Operating system

Ubuntu 16.01, VM

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions