2

I'm working with JDI api (Java Debug Interface) and I try to create breakpoint requests for the first line of code of a particular method, but also on all "exit points" of the method (i.e. on all "return ...;").

To create a breakpoint request, I need a Location object (i.e. kind of pointer to executable code)

Getting a Location for the first line of a method is relatively easy :

theTargetMethod.allLineLocations().get(0)

Getting a Location for all "exit point" is more problematic. Simply getting the last line of the method is probably not enough because the method may contains multiple return statements in the middle of the body, and I need to catch those too.

I have considered using a MethodExitRequest but this will generate tons of events that I don't need because they are related to other methods of the class. (so it can do the job, but it generate a huge overhead at runtime).

So my question is : how can we get a Location for all exit point of a method ?

EDIT

Additional information

For my particular use case, I need to create breakpoint requests for a few methods, and it appears that all methods I'm interested in are all returning void, so it may be possible to search the "return void" instruction (b1) in method's bytecode and create a Locations objects based on all indexes of b1 in bytecode.

ben75
  • 29,217
  • 10
  • 88
  • 134

0 Answers0