{"id":322,"date":"2009-07-13T10:56:21","date_gmt":"2009-07-13T10:56:21","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2009\/07\/13\/muting-breakpoints\/"},"modified":"2009-07-13T10:57:47","modified_gmt":"2009-07-13T10:57:47","slug":"muting-breakpoints","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2009\/07\/13\/muting-breakpoints\/","title":{"rendered":"Muting breakpoints"},"content":{"rendered":"<p>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. <\/p>\n<p>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 <a href=\"https:\/\/www.mathworks.com\/access\/helpdesk\/help\/releases\/R2009a\/techdoc\/index.html?\/access\/helpdesk\/help\/releases\/R2009a\/techdoc\/ref\/dbstatus.html&https:\/\/www.mathworks.com\/cgi-bin\/texis\/webinator\/search\/?db=MSS&prox=page&rorder=750&rprox=750&rdfreq=500&rwfreq=500&rlead=250&sufs=0&order=r&is_summary_on=1&ResultCount=10&query=dbstatus&submitButtonName=Search\">dbstatus<\/a>.<\/p>\n<p>Here's what <tt>dbmute<\/tt> looks like :<\/p>\n<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #0000FF\">function<\/span> dbmute\r\n<span style=\"color: #228B22\">%dbmute disables all breakpoints currently set in MATLAB.<\/span>\r\n\r\n    <span style=\"color: #228B22\">% iterate over each entry in the result of dbstatus,<\/span>\r\n    <span style=\"color: #228B22\">% and disable each of the breakpoints.<\/span>\r\n    breakpoints = dbstatus(<span style=\"color: #A020F0\">'-completenames'<\/span>);\r\n    <span style=\"color: #0000FF\">for<\/span> i=1 : length(breakpoints)\r\n        muteDbStatusEntry(breakpoints(i));\r\n    <span style=\"color: #0000FF\">end<\/span>\r\n\r\n<span style=\"color: #0000FF\">end<\/span>\r\n\r\n<span style=\"color: #0000FF\">function<\/span> muteDbStatusEntry(dbstatusEntry)\r\n<span style=\"color: #228B22\">%muteDbStatusEntry disables each breapoint in the given entry.<\/span>\r\n    <span style=\"color: #0000FF\">for<\/span> i=1 : length(dbstatusEntry.line)\r\n        file = dbstatusEntry.file;\r\n        line = dbstatusEntry.line(i);\r\n        anonymousIndex = dbstatusEntry.anonymous(i);\r\n        expression = dbstatusEntry.expression{i};\r\n\r\n        lineNumberString = [num2str(line) <span style=\"color: #A020F0\">'@'<\/span> num2str(anonymousIndex)];\r\n        newExpression = createDisabledExpression(expression);\r\n\r\n        dbstop(file, lineNumberString, <span style=\"color: #A020F0\">'if'<\/span>, newExpression);\r\n    <span style=\"color: #0000FF\">end<\/span>\r\n<span style=\"color: #0000FF\">end<\/span>\r\n\r\n<span style=\"color: #0000FF\">function<\/span> newExpression = createDisabledExpression(expression)\r\n<span style=\"color: #228B22\">%createDisabledExpression wraps the given expression in a disabling<\/span>\r\n<span style=\"color: #228B22\">%  expression if necessary.<\/span>\r\n    <span style=\"color: #0000FF\">if<\/span> (isDisabled(expression))\r\n        newExpression = expression;\r\n    <span style=\"color: #0000FF\">elseif<\/span> strcmp(expression, <span style=\"color: #A020F0\">''<\/span>)\r\n        newExpression = <span style=\"color: #A020F0\">'false'<\/span>;\r\n    <span style=\"color: #0000FF\">else<\/span>\r\n        newExpression = [<span style=\"color: #A020F0\">'false&amp;&amp;('<\/span> expression <span style=\"color: #A020F0\">')'<\/span>];\r\n    <span style=\"color: #0000FF\">end<\/span>\r\n<span style=\"color: #0000FF\">end<\/span><\/pre>\n<p><script language=\"JavaScript\"><\/p>\n<p><\/script>\n<\/div>\n<p>Here is the full suite of files:<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/desktop\/ken_orr_mute_breakpoints\/dbmute_dbunmute.zip\">dbmute_dbunmute.zip<\/a><\/p>\n<p>I'd recommend also <a href=\"https:\/\/blogs.mathworks.com\/community\/2007\/03\/29\/shortcuts-for-commonly-used-code\/\">creating shortcuts<\/a> for them so you can quickly access them from the toolbar.<\/p>\n<div align=\"center\">\n<img decoding=\"async\" border=\"0\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/ken_orr_mute_breakpoints\/shortcuts.png\">\n<\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2009\/07\/13\/muting-breakpoints\/\">read more >><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[33,9,7],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/322"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}