I am trying to debug an object-oriented application in MATLAB R2011b that I did not write myself. To do this, I want to place a breakpoint in a method in the classdef
. As far as I know, this is allowed. Yet, when I run the application, the breakpoint mysteriously disappears.
I have configured a breakpoint in clear
like so:
dbstop in clear
to see when clear
is being called. Before running the application, I check the presence of the breakpoint with dbstatus:
>> dbstatus
Breakpoint for Processor>Processor.setResult is on line 114.
Breakpoint for inputCompute is on line 30.
Breakpoint is set for m_interpreter>clear.
(The breakpoint in question is the first one in the list.) When I run the application, the breakpoint in the classdef disappears before the first clear is called:
>> rootFunction('configuration')
417 clear('Data');
K>> dbstatus
Breakpoint for inputCompute is on line 30.
Breakpoint is set for m_interpreter>clear.
To determine where the breakpoint gets cleared, I progressively moved a breakpoint closer and closer to the start of the root function, and found the offending line of code:
cd('./configs');
And sure enough -- any invocation of cd
, even indirectly, clears the breakpoints in the classdef
. That means that run
does exactly the same thing. This is infuriating behaviour. Why does MATLAB do this? How do I keep it from doing this?
If the class is only on your path because it's in the current directory, then changing the current directory while the code is running may have unexpected results, including clearing breakpoints.
Use either the Set Path dialog or the addpath
function to add the code's directory to your MATLAB path. This way it can be accessed by MATLAB even if you change the current directory, which should resolve your debugging issues.