1

While using conditional breakpoints in Eclipse, is it possible for one condition code to leave some value in some global variable for the next breakpoint to look at?

Example:

File a.java

118  . . .
119
120  String msg = null;
121
122  if( a == 2 ) {
123      msg = "It is 2";
124  }
125
126  text.setText(msg);
127
128  . . .

TextView.java

3595  @android.view.RemotableViewMethod
3596  public final void setText(CharSequence text) {
3597      setText(text, mBufferType);
3598  }

Conditional Breakpoint code in file a.java line 123

System.out.println("Got it!");
gotIt = true;
return false;

Conditional Breakpoint code in file TextView.java line 3597

if( gotIt ) {
    System.out.println("Setting text after we got it");
}
return false;

It is clear that TextView.setText() might be called a zillion times from many places in the app, but I want to isolate that single time when the code in file a.java was executed and print a message.

ilomambo
  • 8,290
  • 12
  • 57
  • 106
  • 1
    This question makes me feel like I don't understand what a conditional breakpoint is. – pamphlet Apr 02 '14 at 14:07
  • 1
    I don't get it. If you want to isolate that single time when code executes in `a.java` why not set the breakpoint in `a.java`? – Ceiling Gecko Apr 02 '14 at 14:10
  • Or if there's code you want to execute conditionally, use a conditional (i.e. an `if` statement) – pamphlet Apr 02 '14 at 14:10
  • 1
    @pamphlet Read http://www.eclipse-tips.com/tips/29-types-of-breakpoints-in-eclipse#Printpoint for a good explanation – ilomambo Apr 02 '14 at 14:11
  • @CeilingGecko because this is a simple example I made to make the question more readable and clear. Imagine the code under debugging is not a.java but TextView and imagine the code is called a lot of times with many different scenarios and you don't have the time to sit and follow each one manually. – ilomambo Apr 02 '14 at 14:14
  • I see, that's helpful. To be clear, that's not the typical use for conditional breakpoints. – pamphlet Apr 02 '14 at 14:14
  • @pamphlet Hence the "complex breakpoint" part of the question title – ilomambo Apr 02 '14 at 14:15
  • Fair enough. I don't know the answer to your question. But can you add a static global or thread-local to you program and use that? – pamphlet Apr 02 '14 at 14:16
  • Assuming you have access to `a.java` you could discard the first "conditional breakpoint" make the `a` field accessible, and then just perform the `a == 2` check in the TextView.java "conditional breakpoint" instead of `if (gotIt)` – Ceiling Gecko Apr 02 '14 at 14:20
  • Is `gotIt` defined in your program? – pamphlet Apr 02 '14 at 14:27
  • @pamphlet that's what I am trying to do while waiting for an answer. It doesn't seem to work so far, still trying. – ilomambo Apr 02 '14 at 14:28
  • @CeilinGecko You are fixed on the little example I gave, my real code is much more complex orders of magnitude. – ilomambo Apr 02 '14 at 14:29

0 Answers0