Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force return from function while debugging

I am debugging a program in MATLAB R2016a and would like to return from a sub-function without completing the function. For example, you can write in code:

if(conditionMet)
  return;
end

If the condition is met, it will force the function to end early and continue in the caller code. While I am debugging, I would like to force the function to end early as if I had encountered a return command. When I simply type return while in debug mode, nothing appears to happens. Is there a way to force a function to end early and continue running?

like image 876
David K Avatar asked Mar 10 '17 20:03

David K


People also ask

Can we go back while debugging?

Going to a previously step is not possible in debugging... only option have a new break-point at that point and re-start debugging...

How do I get out of loop while debugging?

Pressing ctrl+R is the correct option but if your break point is on a line which is inside the for loop, then you will have to first remove the break point and then press ctrl+R on the line on which you want the control to land. I faced this issue while debugging.

What is enable Debug mode in VS code?

Switch to the Run and Debug view (Ctrl+Shift+D) and select the create a launch. json file link. VS Code will let you select an "debugger" in order to create a default launch configuration.

How do you Debug a function?

To debug a function which is defined inside another function, single-step through to the end of its definition, and then call debug on its name. If you want to debug a function not starting at the very beginning, use trace(..., at = *) or setBreakpoint .


2 Answers

According to MATLAB Central and Undocumented Matlab, there is an undocumented function feature() that could be used in your case like this:

if feature('IsDebugMode')
   return;
end
like image 105
beaker Avatar answered Oct 16 '22 09:10

beaker


I think it is not possible in general with the current release of Matlab.

If you know at beforehand at which place(s) you potentially want to return from your function while debugging, you can use the following trick.

function yourFunction ()
    breakDebug = false;
    ...
    if breakDebug
        return; % location at which you may break your function during debugging
    end
    ...
    return;
end

By setting breakDebug while debugging, the program will break at your next potentially break location.

like image 41
m7913d Avatar answered Oct 16 '22 10:10

m7913d