Eclipse: set breakpoint when value changes

In Eclipse, is it possible to set a breakpoint on a class member anytime it is access, or even better, written to.
For example, below, it would like the debugger to break anytime index changes value.
I can set a breakpoint for every method, but this is not quite what I want.

package breakpointTest;

import javax.swing.JLabel;

public class Breakpoint2Test {

	JLabel label;
	int index;
	
	public Breakpoint2Test() {
	
		label = new JLabel("hello");
		
		index = 1;
		
	}
	
	public JLabel getLabel() {
		return label;
	}


	public void setLabel(JLabel label) {
		this.label = label;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void doSomething() {
		index = 99;
		
	}

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {

		new Breakpoint2Test();
	}
	
}

Open in new window

LVL 1
allelopathAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:
0
allelopathAuthor Commented:
The first link would seem to be what I am looking for, but doesn't seem to work.
I''ve modified the code to test this (below) and added a breakpoint (see attached image).
I would expect it a suspend on the call to changeIndexValue(), but it doesn't.
 
package breakpointTest;

import javax.swing.JLabel;

public class Breakpoint2Test {

	JLabel label;
	int index;
	
	public Breakpoint2Test() {
	
		label = new JLabel("hello");
		
	}
	
	public JLabel getLabel() {
		return label;
	}


	public void setLabel(JLabel label) {
		this.label = label;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void changeIndexValue() {
		index++;;
		
	}

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {

		Breakpoint2Test breakpoint2Test = new Breakpoint2Test();

		breakpoint2Test.changeIndexValue();
	}
	
}

Open in new window

breakpointTest.png
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

for_yanCommented:
I ran it in a different way - first I open normal Java perspective,
then I pouinted cursior on the "index" in declaration "int index"
Then I go to Run menu and select Toggle Watchpoint
It sets WathPoint.
The I go to menu Run-->Debug
It asked me if I'm OK with switching pespective - I said -OK,
It then ran up to the line index++ and higlighteed it

Then I did Run-stepover (after second time it mmoved forward)
and then you can continue debugging.
Let me know if ut works for you this way.

It was really pretty simple, even though before I never used Eclipse for debugging purposes -
I kind of ususally just add System.out.printouts - find it simpler.

So let me know if this works for you

0
allelopathAuthor Commented:
sorry for the delay. I will get to this .
0
allelopathAuthor Commented:
still haven't gotten back to this. I'll close it and ask again if need be.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.