Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: How to Save Breakpoints?

Subject: How to Save Breakpoints?

From: Le He

Date: 21 Jul, 2008 20:14:05

Message: 1 of 3

Hi,
Whenever my Matlab program is debugged, the previously set
breakpoints disappear. If I debug once again, I have to
reset the breakpoints. How to set the breakpoints just for
once and keep them until I delete them?
Thanks in advance!
lehe

Subject: How to Save Breakpoints?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 Jul, 2008 21:57:13

Message: 2 of 3

In article <g62qmd$ht$1@fred.mathworks.com>, Le He <flylehe@hotmail.com> wrote:
>Whenever my Matlab program is debugged, the previously set
>breakpoints disappear. If I debug once again, I have to
>reset the breakpoints. How to set the breakpoints just for
>once and keep them until I delete them?

help clear

    CLEAR ALL, CLEAR FUN, or CLEAR FUNCTIONS also have the side effect of
    removing debugging breakpoints and reinitializing persistent variables
    since the breakpoints for a function and persistent variables are
    cleared whenever the m-file changes or is cleared.


My guess is that you have a 'clear all' in your routine that you should
get rid of.

If you need to save your breakpoints between matlab sessions,
then you can create a startup.m file (see the doc on 'startup')
which checks for a breakpoint definition file in your
current directory and runs it if it finds it. You can save
your breakpoints with something like,

function savebreakpoints
  s = dbstatus;
  if isempty(s); return; end
  fid = fopen('savedbreakpoints.m','w');
  if fid < 0; return; end
  for K = 1:length(s)
    if ~isempty(s(K).cond)
      fprintf(fid, 'dbstop if %s', s(K).cond);
      fprintf(fid, ' %s', s(K).identifier{:});
      fprintf(fid, '\n');
    else
      fname = s(K).name;
      lines = s(K).line;
      exprs = s(K).expression;
      anons = s(K).anonymous > 0;
      %simplify this function by refusing to deal with @ breakpoints
      lines(anons) = [];
      exprs(anons) = [];
      for L = 1:length(lines)
        if isempty(exprs{L})
          fprintf(fid, 'dbstop in %s at %d\n', fname, lines(L));
        else
          fprintf(fid, 'dbstop in %s at %d if %s\n', fname, lines(L), ...
                       exprs{L} );
        end
      end
    end
  end
  fclose(fid);
end
--
  "Product of a myriad various minds and contending tongues, compact of
  obscure and minute association, a language has its own abundant and
  often recondite laws, in the habitual and summary recognition of
  which scholarship consists." -- Walter Pater

Subject: How to Save Breakpoints?

From: Le He

Date: 22 Jul, 2008 19:44:04

Message: 3 of 3

Thank you so much!
I have read the document of startup but still have a
question: how to check for a breakpoint definition file in
the current directory and runs it if it finds it in
startup.m? Thanks!


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g630np$b98$1@canopus.cc.umanitoba.ca>...
> In article <g62qmd$ht$1@fred.mathworks.com>, Le He
<flylehe@hotmail.com> wrote:
> >Whenever my Matlab program is debugged, the previously
set
> >breakpoints disappear. If I debug once again, I have to
> >reset the breakpoints. How to set the breakpoints just
for
> >once and keep them until I delete them?
>
> help clear
>
> CLEAR ALL, CLEAR FUN, or CLEAR FUNCTIONS also have
the side effect of
> removing debugging breakpoints and reinitializing
persistent variables
> since the breakpoints for a function and persistent
variables are
> cleared whenever the m-file changes or is cleared.
>
>
> My guess is that you have a 'clear all' in your routine
that you should
> get rid of.
>
> If you need to save your breakpoints between matlab
sessions,
> then you can create a startup.m file (see the doc
on 'startup')
> which checks for a breakpoint definition file in your
> current directory and runs it if it finds it. You can save
> your breakpoints with something like,
>
> function savebreakpoints
> s = dbstatus;
> if isempty(s); return; end
> fid = fopen('savedbreakpoints.m','w');
> if fid < 0; return; end
> for K = 1:length(s)
> if ~isempty(s(K).cond)
> fprintf(fid, 'dbstop if %s', s(K).cond);
> fprintf(fid, ' %s', s(K).identifier{:});
> fprintf(fid, '\n');
> else
> fname = s(K).name;
> lines = s(K).line;
> exprs = s(K).expression;
> anons = s(K).anonymous > 0;
> %simplify this function by refusing to deal with @
breakpoints
> lines(anons) = [];
> exprs(anons) = [];
> for L = 1:length(lines)
> if isempty(exprs{L})
> fprintf(fid, 'dbstop in %s at %d\n', fname,
lines(L));
> else
> fprintf(fid, 'dbstop in %s at %d if %s\n',
fname, lines(L), ...
> exprs{L} );
> end
> end
> end
> end
> fclose(fid);
> end
> --
> "Product of a myriad various minds and contending
tongues, compact of
> obscure and minute association, a language has its own
abundant and
> often recondite laws, in the habitual and summary
recognition of
> which scholarship consists." -- Walter
Pater

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
breakpoints set save Le He 21 Jul, 2008 16:15:14
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics