Eclipse debugging: continue to work after return?

I recently started working with Eclipse for Android development. When debugging the code, I noticed one strange behavior (at least compared to Visual Studio): after you press the return statement in the middle of the function, it does not immediately return, but always jumps to the last return statement. For instance:

String getTest(int i){ if (i == 0) return "0"; return "-1"; } 

Given i = 0, after pressing the first return statement, instead of moving from this function, it moves on to the next return statement. However, it returns "0", not "-1". So why this dummy step? It bothers me. Can anyone explain why?

+4
source share
2 answers

This is due to what exactly constitutes a “return” from a function. Although this is platform dependent, return usually matters:

  • Copy return code to well-known register (EAX in x86)
  • Enter the return address from the activation record stack
  • Reset stack pointer (and base pointer)

Only the return value is different from another, the compiler can choose to generate machine code (byte code in the case of java) once and go to it from different places. Eclipse can show this jump.

0
source

This is just a visual thing in the eclipse debugger, where it goes to the end of the function before ending itself, no matter where the return statement was. those.:

 line:1 String method(String i){ line:2 return i; line:3 extra code here... line:4 extra code here... line:5 extra code here... line:6 extra code here... line:7 return "fake return"; line:8 } 

The debugger will always go from line 1 to line 2, then to line 8, and then back to the code that called it in the first place, and it will always return i rather than a "fake return".

hope this helps.

+1
source

Source: https://habr.com/ru/post/1380318/


All Articles