views:

303

answers:

2

In Python, I'm used to being able to start a debugger at any point in the code, then poke around at live objects (call methods, that sort of thing). Is there any way, using NetBeans, to do this?

For example, I'd like to be able to break at the line foo = bar().baz().blamo() and run bar(), bar().baz() and bar().baz().blamo() to see what they do.

In Python, this is what I would do:

...
import pdb; pdb.set_trace()
foo = bar().baz().blamo()

Then it would give me a prompt where I could type things:

(pdb) bar()
... some objet ...
(pdb) bar() + 42
...
+2  A: 

First, set a breakpoint at that line of the code (by clicking in the left margin). Then click "Debug Main Project" (or "Debug single file" in the Debug menu).

Once you hit the breakpoint, you can use the tools in the Debug menu. In particular, "Evaluate Expression" seems to be what you're looking for.

Michael Myers
Great -- thanks a lot.
David Wolever
+1  A: 

In the debugger use the "Watches" view. In there you can add things to "watch", such as variables or expressions.

So if you had a "foo" object you could do things like watch "foo.bar()" and have it call the method.

I am not aware of any Java debuggers that have a real "scratchpad" sort of thing, but there probably is one. The "Watches" is about as close as you can get in Netbeans that I have found.

TofuBeer