Reputation: 910
Is it possible to put out a global watch or breakpoint, on no specific variable or line of code, with the aim of identifying the first instance of a value?
I'm debugging on an old java6 web app that does a million calculations between multiple databases and dozens of classes with thousands of lines of code each. I'm not exactly sure which of these dozens of classes are being called within this project containing hundreds of classes.
Let's say I'm looking for where "the dog runs"
appears in the flow of a calculation: Is it possible to listen for the first appearance of that string with the intention of finding what variable will contain the value?
Upvotes: 2
Views: 1762
Reputation: 1774
I do not think that is possible to monitor where a value comes into existence as i think you have asked.
However, you can set "field watchpoints" which are basically expressions like break when x = "the dog runs"
. When i have used these before the program will run very very slowly.
Refer here for details of how to set it: Intellij breakpoints.
Another technique is to start near the top of where you think a value is being set to what you want. Step over each method until you see where the value set to what you are looking for. Then repeat the process inside the method that you saw it change (i.e. this time step into the method where the value changed).
Within this "second level method", you will probably see another call that sets the value you are looking for. So repeat the process again until you find a system call that sets the value (e.g. a read from a database or a regex match etc).
It sounds tedious, but it is a "divide and conquer" method of the form that eliminates a huge chunk of code that doesn't set the value you are looking for into the one method call that does. Then you divide and conquer the inner workings of that method. In practice, it doesn't take long before you narrow it down.
Upvotes: 3