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?
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.