1

When using gdb to debug there are a couple of ways to automate the actions performed when a break point is hit. This is good for cases where I only have compiled code with debug symbols, not source code. It is also nice when I want to instrument something interactively without relying on code reloading to insert print statements.

Is there a way to do this with the Eclipse debugger and Java code? All I need is a way to print objects and variables and then continue from the breakpoint.

4
  • 1
    Can't you just hover over the object in question and inspect it? There's also a "variables" view for the debug perspective, right for this purpose. You can even change values on the run, within their scope. Commented Jul 6, 2015 at 16:11
  • Yes but doing that manually is slow and tedious when I can automate it. Also, then the history of values is in my head instead of in the console. Commented Jul 6, 2015 at 17:31
  • Then what's the difference with logging? Commented Jul 6, 2015 at 17:40
  • I can "instrument something interactively without relying on code reloading". Commented Jul 6, 2015 at 17:42

1 Answer 1

2

You can inject code using conditional breakpoints.

In this example the breakpoint never suspends because of return false;, but always print the absolut path of a file-variable named "file"! enter image description here

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

2 Comments

Thanks, I did not realize that this could be arbitrary code.
Interesting. Can't wait to try that stuff out!

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.