Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse conditional breakpoint, break at any string equals

I have a large (legacy) application that I have to make a fix in, with terrible code structure and so much code smell that I'm choking. I can't really figure out where a string in the gui is populated. Therefore it would be nice if i somehow could have an expression/breakpoint once ANY string (I don't know the name of the variable, or where it is) is equal to "foobar" so I can backtrack from there.

So, what am I looking for? :)

like image 973
Viktor Mellgren Avatar asked Feb 12 '26 15:02

Viktor Mellgren


1 Answers

This trick works as long as the string that you want to find isn't hard-coded in any way. If the string was getting passed to the compiler, then this trick may not work.

  1. Ensure you have installed the source-code alongside the JDK.
  2. Open java.lang.String class file. Your IDE should be automatically show the source-code for this class.
  3. Put a breakpoint in the char[] field variable. The variable name may vary for each JDK. On my machine it is private final char value[];.
  4. Put a condition on this breakpoint, e.g.:

    value!=null && value.length==6 && value[0]=='f' && value[1]=='o' && value[2]=='o' ....
    

Please note that the performance will be slower due to this breakpoint.

I have tested this on a simple application that read the string from a file, and the breakpoint is being hit properly when the file is being read into a string.

like image 119
Thariq Nugrohotomo Avatar answered Feb 15 '26 04:02

Thariq Nugrohotomo