Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint on first entry to recursive function

Is it possible to create a breakpoint where the condition is that its the start of the recursive process? In other words, the stack should only have one call to the function.

IE consider this workflow:

Main func -> call recursive func -> hit breakpoint -> continue -> recursively call self -> DONT hit breakpoint -> continue recursion.

like image 979
David says Reinstate Monica Avatar asked Mar 19 '23 22:03

David says Reinstate Monica


2 Answers

Try this:

if(!Thread.currentThread().getStackTrace()[2].getMethodName().equals("this method's name"))
     // breakpoint

The 2 is because getStackTrace will return the actual getStackTrace method as part of the stack, your method name, and THEN the caller method, which we want.

like image 96
DankMemes Avatar answered Mar 31 '23 10:03

DankMemes


I don't this why you want to corrupt your code to achieve this unless you are creating break point programmatically.

Keep the break point inside the recursive function then right click on the break point and select break point properties the enter hit count 1. After hitting the break point first time it going to be disabled.

like image 22
Chandrayya G K Avatar answered Mar 31 '23 11:03

Chandrayya G K