Shortcircuiting multiple dbquit commands

1 view (last 30 days)
Leo Simon
Leo Simon on 23 Jan 2017
Commented: Walter Roberson on 15 Apr 2020
Many times I find myself in a workspace, making an error, which throws me into debug mode, repeatedly making mistakes while trying to figure out what's going on, and then having to type dbquit, many many times to get myself back to a particular workspace. Is there some way to shortcircuit this process and get back to space I want to be in with a single command? (perhaps for example an undocumented argument to `dbquit` like dbquit('dumb')?) Here's a a really silly example. Suppose the following lines are in a file called dumb.m.
dbstop if error
1
f = @(x) x + y
f(1)
If you run the file dumb, then you'll see the following error:
Undefined function or variable 'y'.
Error in dumb>@(x)x+y
Error in dumb (line 4)
f(1);
and dbstack will return
In dumb>@(x)x+y
In dumb (line 4)
Now, if you do a really stupid thing and type `y` three times, and then decide you want to get back to the workspace `dumb`, you'll need to type `dbquit` several (in fact 4) times, and, to be safe, `dbstack` after each one, to make sure that you haven't gone too far and exited the workspace `dumb`
The obvious answer---don't keep making the same stupid mistake---isn't applicable, since in my actual instances, the mistakes aren't so stupid. Thanks very much for any suggestions.
  7 Comments
Leo Simon
Leo Simon on 15 Apr 2020
Unfortunately dbquit turns out to be too aggressive for my needs, what I need is what you suggested originally, @WalterRoberson, i.e., a command that would take me back just to the workspace where I made the last error. I don't want to quit out of the entire program. I realize this is a harder ask, but it would be tremendously useful.
Walter Roberson
Walter Roberson on 15 Apr 2020
I encountered difficult situation the other day. I was debugging with "dbstop if naninf" inside the ode45 code, with some animatedline() addpoints() inside my objective function, and when drawnow() was hit, something inside the graphics handling system would breakpoint. I would dbcont and it would go right back to breakpoint again, over and over again, I would have to continue numerous tens of time in a row to make any progress. dbquit wasn't enough to solve the issue.
Ah... I just realized that I initialized the animatedline() with nan, nan, so it might have been firing while it was copying those points while adding more points....

Sign in to comment.

Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!