Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Way to drop into debug even if not chosen debug on error?

Subject: Way to drop into debug even if not chosen debug on error?

From: Richard Crozier

Date: 23 Jul, 2011 14:02:09

Message: 1 of 8

Hello,

Is there any way to stop a script or mfile execution that allows you to drop into a debugging session as though you had set 'debug on error' and hit CTRL + C during execution?

Thanks!

Richard

Subject: Way to drop into debug even if not chosen debug on error?

From: Steven_Lord

Date: 25 Jul, 2011 13:34:24

Message: 2 of 8



"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
news:j0ek91$npc$1@newscl01ah.mathworks.com...
> Hello,
>
> Is there any way to stop a script or mfile execution that allows you to
> drop into a debugging session as though you had set 'debug on error' and
> hit CTRL + C during execution?

Use the KEYBOARD function.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Way to drop into debug even if not chosen debug on error?

From: Richard Crozier

Date: 25 Jul, 2011 13:52:07

Message: 3 of 8

Thanks Steven, but I don't think this is what I want. I want to be able to hit some combination of keys that causes execution to stop (like CTRL+C does) but pauses at the current point of code execution as though I had used the command 'dbstop if error' before I started execution, and allows me to investigate what's in memory and look up and down the stack etc. just like you can when debugging.

Specifically I wish to do this when I don't know in advance that my code will lock up, and so haven't known to use the 'keyboard' command, or to set 'dbstop if error'.


"Steven_Lord" <slord@mathworks.com> wrote in message <j0jrd0$62c$1@newscl01ah.mathworks.com>...
>
>
> "Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
> news:j0ek91$npc$1@newscl01ah.mathworks.com...
> > Hello,
> >
> > Is there any way to stop a script or mfile execution that allows you to
> > drop into a debugging session as though you had set 'debug on error' and
> > hit CTRL + C during execution?
>
> Use the KEYBOARD function.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Way to drop into debug even if not chosen debug on error?

From: Steven_Lord

Date: 25 Jul, 2011 14:01:52

Message: 4 of 8



"Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
news:j0jse7$9td$1@newscl01ah.mathworks.com...
> Thanks Steven, but I don't think this is what I want. I want to be able to
> hit some combination of keys that causes execution to stop (like CTRL+C
> does) but pauses at the current point of code execution as though I had
> used the command 'dbstop if error' before I started execution, and allows
> me to investigate what's in memory and look up and down the stack etc.
> just like you can when debugging.
>
> Specifically I wish to do this when I don't know in advance that my code
> will lock up, and so haven't known to use the 'keyboard' command, or to
> set 'dbstop if error'.

There's no such functionality.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Way to drop into debug even if not chosen debug on error?

From: Richard Crozier

Date: 25 Jul, 2011 14:17:08

Message: 5 of 8


OK, that's what I thought, thanks for confirming.


"Steven_Lord" <slord@mathworks.com> wrote in message <j0jt0g$bt2$1@newscl01ah.mathworks.com>...
>
>
> "Richard Crozier" <r.crozier@ed.ac.uk> wrote in message
> news:j0jse7$9td$1@newscl01ah.mathworks.com...
> > Thanks Steven, but I don't think this is what I want. I want to be able to
> > hit some combination of keys that causes execution to stop (like CTRL+C
> > does) but pauses at the current point of code execution as though I had
> > used the command 'dbstop if error' before I started execution, and allows
> > me to investigate what's in memory and look up and down the stack etc.
> > just like you can when debugging.
> >
> > Specifically I wish to do this when I don't know in advance that my code
> > will lock up, and so haven't known to use the 'keyboard' command, or to
> > set 'dbstop if error'.
>
> There's no such functionality.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Way to drop into debug even if not chosen debug on error?

From: Jan Simon

Date: 25 Jul, 2011 23:31:09

Message: 6 of 8

Dear Richard,

> Is there any way to stop a script or mfile execution that allows you to drop into a debugging session as though you had set 'debug on error' and hit CTRL + C during execution?

I do not get the point. If I set "dbstop on error" and run a longer program, I can hit Ctrl-C to stop and the current line is displayed in the editor. Then I can inspect the variables as if an error had occurred. So Ctrl-C is treated as an error.
Do you want something else?

Kind regards, Jan

Subject: Way to drop into debug even if not chosen debug on error?

From: Richard Crozier

Date: 26 Jul, 2011 07:45:10

Message: 7 of 8

"Jan Simon" wrote in message <j0kubt$m4g$1@newscl01ah.mathworks.com>...
> Dear Richard,
>
> > Is there any way to stop a script or mfile execution that allows you to drop into a debugging session as though you had set 'debug on error' and hit CTRL + C during execution?
>
> I do not get the point. If I set "dbstop on error" and run a longer program, I can hit Ctrl-C to stop and the current line is displayed in the editor. Then I can inspect the variables as if an error had occurred. So Ctrl-C is treated as an error.
> Do you want something else?
>
> Kind regards, Jan

Yes I was wondering if there was a way to do what you have just said WITHOUT having set 'dbstop if error' before I started, as sometimes I don't know in advance I want to do this, or have forgotten to set this, and my code locks up at a point which would be difficult to replicate easily without knowing what the values of the variables etc. are.

Subject: Way to drop into debug even if not chosen debug on error?

From: Jan Simon

Date: 26 Jul, 2011 10:20:09

Message: 8 of 8

Dear Richard,

> Yes I was wondering if there was a way to do what you have just said WITHOUT having set 'dbstop if error' before...

You can insert this around lengthy loops:
  dbBackup = dbstatus;
  dbstop('error');
  ... Your function here
  dbstop(dbBackup)

While setting a specific break point disables the JIT acceleration, "dbstop('error')" does not, such that I do not expect severe consequences for the runtime.

I'm used to display a small progressbar with a Cancel button during longer computations. The dialog is closed if the button is pressed and the calculator checks in certain intervals, if the dialog still exists. If not the program returns friendly, but KEYBOARD would be better for your needs.

Kind regards, Jan

Tags for this Thread

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.

Contact us