# Muting breakpoints

Debugging is an integral part of my workflow. One thing I continually encounter is the need to quickly disable all my breakpoints. After spending time inserting breakpoints at the right places with the right conditions, I sometimes want to quickly mute (disable) all of my breakpoints without actually removing them.

In order to do this, I wrote a couple of scripts, which mute and un-mute your breakpoints. I did this by reinstalling each breakpoint with a disabling expression (e.g. turn 'x==1' into 'false&&(x==1)') . To get all of the breakpoints currently installed in MATLAB, use dbstatus.

Here's what dbmute looks like :

function dbmute
%dbmute disables all breakpoints currently set in MATLAB.

% iterate over each entry in the result of dbstatus,
% and disable each of the breakpoints.
breakpoints = dbstatus('-completenames');
for i=1 : length(breakpoints)
muteDbStatusEntry(breakpoints(i));
end

end

function muteDbStatusEntry(dbstatusEntry)
%muteDbStatusEntry disables each breapoint in the given entry.
for i=1 : length(dbstatusEntry.line)
file = dbstatusEntry.file;
line = dbstatusEntry.line(i);
anonymousIndex = dbstatusEntry.anonymous(i);
expression = dbstatusEntry.expression{i};

lineNumberString = [num2str(line) '@' num2str(anonymousIndex)];
newExpression = createDisabledExpression(expression);

dbstop(file, lineNumberString, 'if', newExpression);
end
end

function newExpression = createDisabledExpression(expression)
%createDisabledExpression wraps the given expression in a disabling
%  expression if necessary.
if (isDisabled(expression))
newExpression = expression;
elseif strcmp(expression, '')
newExpression = 'false';
else
newExpression = ['false&&(' expression ')'];
end
end

Here is the full suite of files:

dbmute_dbunmute.zip

I'd recommend also creating shortcuts for them so you can quickly access them from the toolbar.

|