adventuregamestudio / ags

AGS editor and engine source code
Other
696 stars 159 forks source link

Debugger: support step-over and step-out commands #2454

Open ivan-mogilko opened 3 months ago

ivan-mogilko commented 3 months ago

Debugger (Editor) currently supports stepping line by line, strictly following script execution; that results in next break occuring inside nested function calls as well. But that's not always convenient in case of complex scripts.

I propose to add 2 more step commands:

  1. Step-over means that it will not step inside called functions, but wait until next line in the current function is reached. (proposed hotkey is F10)
  2. Step-out means that it will wait until current function returns, and breaks at the next line after its call. (proposed hotkey is Shift+F11)

I suppose this may be implemented either:

ericoporto commented 3 months ago

Supposedly we have

function Bar()
{
  // there is a breakpoint here
}

function Foo()
{
  int a = 2; // debug cursor is here
  Bar();
  int b = 3;
}

A step over would then step over Bar or in this case that we set a breakpoint inside it would stop at that breakpoint (like if we had hit the "continue" like button)?

ivan-mogilko commented 3 months ago

It should break at the next found breakpoint along the execution, whether it's user's breakpoint or one added by another command. Yes, it must be consistent with "continue".

ivan-mogilko commented 3 months ago

In regards to implementation: breaking is currently handled in this function in the engine: https://github.com/adventuregamestudio/ags/blob/de288ad3ec79a8e2726c1617b03837c79c40b126/Engine/debug/debug.cpp#L632-L633

The variables that control behavior are: breakpoints - array of breakpoints break_on_next_script_step - tells to break at next execution step.

I suppose that these may be amended with more instructions. The question is mostly in which conditions to use for making a break.