MATLAB Community

MATLAB, community & more

Muting breakpoints 11

Posted by admin,

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)


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);

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';
        newExpression = ['false&&(' expression ')'];

Here is the full suite of files:

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


Comments are closed.

11 CommentsOldest to Newest

david s replied on : 1 of 11
nice. though a nice feature would be if it remembered which breakpoints were already disabled before clicking mute, and left them disabled when unmuting.
Ken replied on : 2 of 11
Hi David, Thanks! My original version of dbmute actually did save the breakpoints at the time that you muted them by saving the results of dbstatus. The reason I moved away from that was because breakpoints that you removed *after* pressing mute would reappear when you unmuted, as the saved state was blinding reinstalled. Maybe I could coalesce the two solutions. -Ken
Brett Shoelson replied on : 3 of 11
Very nice, Ken--your code has taken a place of honor on my shortcut bar! One thought: why not post mute/unmute to the MATLAB Central File Exchange? They have "Pick of the Week" written all over them. ;) Brett
Ken replied on : 4 of 11
Glad your finding dbmute and dbunmute useful! I've submitted these to the file exchange -- I'll update the post when they get approved. -Ken
Kieran Parsons replied on : 5 of 11
Nice function. One thing that has been bugging me for a while is that 'clear classes' removes breakpoints. This makes the workflow for debugging classes more of a challenge than necessary. To avoid this I wrote a small function below. I thought I would have to save the breakpoints to file due to the 'clear all' part of 'clear classes', but this seems to work OK. One thing I note is that after I call the new 'clear_classes' function the breakpoints are not visible in the editor even though they do work. Is there an easier way to do this? Are there any likely side-effects of doing this?
function clear_classes()
%CLEAR_CLASSES Clears classes but keeps breakpoints.
% CLEAR_CLASSES() performs a 'clear classes' in the base workspace, but reestablishes the
% breakpoints after the clear operation.
% See also CLEAR.

breakpoints = dbstatus('-completenames');
evalin('base', 'clear classes');
Thanks, Kieran
Ken replied on : 6 of 11
Thanks for the feedback Kieran. I don't think there is a simpler way to do what you're trying to do. The breakpoints not showing up in the Editor is definitely a bug, which I've filed. -Ken
Kieran Parsons replied on : 7 of 11
Thanks Ken. Unfortunately my function does not work in practice very well as I discovered after a bit more testing. If clear_classes is run then the breakpoints are reestablished correctly but do not appear in the editor (as mentioned). Unfortunately this means that if you make changes to the file and then save it they disappear (ie the editor has lost track of them and so removes them on a save). Presumably this is the same or a related bug to why they do not appear, but its impact is more of a problem. I will add an enhancement request that clear classes should not remove breakpoints. Thanks, Kieran
Ken replied on : 8 of 11
Hi Kieran, You could iterate over the results of dbstatus and call dbstop -- I'm sure that will work, as that's what my function does. I've submitted a bug report for the breakpoints disappearing from the Editor. -Ken
Kieran Parsons replied on : 9 of 11
Thanks Ken. I tried that (and a bunch of other things) without success. After a lot of experimenting with dbclear etc and not understanding why things that worked in the command window would not work in a function, I finally realized that you need to add a pause between the 'clear classes' or 'dbclear all' and the dbstop. A pause of 0.01 was sufficient for me to get it to work. I added the enhancement request that clear classes should not remove breakpoints. Thanks, Kieran
Ben replied on : 10 of 11
Hi Ken, In future versions will it be possible to interactively pause and resume execution or resume after errors (such as Ctrl-C)? thanks, Ben
Ken replied on : 11 of 11
Hi Ben, We have an enhancement request to pause execution. Theres no request yet to resume after errors (you can submit on here if you like). -Ken