Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
85 views
in Technique[技术] by (71.8m points)

java - Break when a variable is assigned some value

I want jdb (which I'm using via the Eclipse debugger) to break when a variable is assigned some value. I'm not interested in setting a breakpoint at some specific line but rather more generally.

For example, break every time x == null.

Is such a thing achievable?

question from:https://stackoverflow.com/questions/2278447/break-when-a-variable-is-assigned-some-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes - What you need to setup is a 'Conditional Breakpoint' - this gives you the ability to stop the program execution and step through the debugger when a certain state of the application is reached.

So, let's say you want to jump into a particular point in the execution when a certain condition is fulfilled (as per the image attached), you can do this as follows:

  1. Open your debugger perspective and select the 'BreakPoints' tab

  2. Add a new BreakPoint in the code file - at the appropriate place where you would like to observe the program execution

  3. Then go back to the 'Breakpoints' tab, right-click on the newly added entry, and select 'Breakpoint Properties'

  4. Set the condition upon which it should be activated

alt text


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...