0

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
...

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Jdeveloper has where user can click on a variable in debugger, right click, evaluate and can change expression/call any method/field to see value
In Eclipse you have a Inspect menu item. While debugging just select a certain portion of the code and click 'Inspect' in the context menu and you will see the result of the expression. Something I use quite often.
0

if you are running in debug mode and has set the debug pointer, then

(top left) debug --> Evaluate expression [Put your expression and run]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.