停止并继续执行调试器可能吗? [英] Stop and continue execution from debugger possible?

查看:168
本文介绍了停止并继续执行调试器可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以像ctrl + c那样从调试器停止执行matlab程序,但是可以继续执行(就像你可以说c#)?



如果没有,是否有更好的方法来解决这个问题,而不是试图在您的matlab代码中先发制定断点或dbstop语句?



我想能够中断长时间运行的模拟来查看当前状态,然后继续进行仿真。



我目前使用/考虑的两个选项是


  1. dbstop命令(或(有条件)断点)在代码中。
    缺点是有时候我不想停止模拟几个小时,有时只需要在几秒钟之后停止(而且我不一定会提前知道这一点),而且这并不奏效使用这种方法:如果我设置休息条件每5分钟打破一次,我不能离开matlab运行几个小时没有互动。如果我将条件设置为更高,我必须等待太久才能打到条件。


  2. 包含代码以每隔几秒钟/分钟保存工作空间,并将工作区导入第二个Matlab实例。缺点是这是一个巨大的麻烦,也不一定允许我恢复与保存的工作状态的模拟,然后逐步执行代码几次迭代。


我希望有一个比任何一个更好的解决方案。谢谢任何建议!



编辑:我想我要做的是编写简单的matlab函数,每次迭代检查环境变量或磁盘上的文件,并调用dbstop如果我在这个文件或env中设置了一个标志。这样我可以通过编辑文件来控制断点从外部matlab得到的时间(如果需要的话)。凌乱,但应该工作。

解决方案

这不一定是最好的方法,但您可以模拟基于文件的信号/中断框架。可以通过在长模拟循环中的每隔一段时间检查特定文件的存在来完成。如果是这样,您可以使用键盘命令进入交互模式。



沿着这些行:

  CHECK_EVERY = 10; %#像投票率

tic
i = 1; %#loop counter
while true%#long running loop
if rem(i,CHECK_EVERY)== 0&&&存在('debug.txt','file')
fprintf('%f seconds since last time.\\\
',toc)
keyboard
tic
end

%#...长计算...

i = i + 1;
end

您将像往常一样运行模拟。当你想进入代码时,只需创建一个文件 debug.txt (手动即可),执行将停止,并得到提示:

 自上次以来的2.803095秒。 
K>>

然后,您可以照常检查您的变量...要继续,只需运行 return (不要忘了暂时重命名或删除文件)。为了退出,请使用 dbquit






编辑:只是发生在我身上,而不是检查文件,更容易的解决方案是使用虚拟图形作为标志(只要图形打开,保持运行)。

  hFig = figure; drawow 
while true
如果〜ishandle(hFig)
键盘
hFig = figure; drawow
end

%#...
pause(0.5)
end


Is there any way to stop the execution of a matlab program from the debugger like ctrl+c does, but then being able to continue execution (like you can in say c#)?

If not, is there any better way to workaround this other than trying to pre-emptively set break points or dbstop statements in your matlab code?

I would like to be able to interrupt a long running simulation to look at the current state and then continue the simulation.

The two options I'm currently using/considering are

  1. dbstop commands (or (conditional) breakpoints) in the code. Drawback is that sometimes I don't want to stop the simulation for a few hours, sometimes want to stop after only a few seconds (and I don't necessarily know that in advance) and this doesn't work well with this approach: If I set the break condition to break every 5 minutes, I can't leave matlab running for hours without interaction. If I set the condition to higher, I have to wait too long for the condition to hit.

  2. include code to save the workspace every few seconds/minutes and import the workspace into a second matlab instance. Drawback is that this is a huge hassle and also doesn't necessarily allows me to resume the simulation with the state of the saved workspace then step through the code for a few iterations.

I'm hoping there is a better solution than either of the 2. Thanks for any advice!

Edit: I think what I'm going to do is write simple matlab function that checks an environment variable or a file on disk every iteration and calls dbstop if I set a flag in this file or env. This way I can control when (and if needed which of several) the breakpoint hits from outside matlab by editing the file. Messy, but should work.

解决方案

This is not necessarily the best way, but you could simulate a file-based signal/interrupt framework. It could be done by checking every once in a while inside the long simulation loop for the existence of a specific file. If it does, you enter interactive mode using the keyboard command.

Something along the lines:

CHECK_EVERY = 10;    %# like a polling rate

tic
i = 1;               %# loop counter
while true           %# long running loop
    if rem(i,CHECK_EVERY) == 0 && exist('debug.txt','file')
        fprintf('%f seconds since last time.\n', toc)
        keyboard
        tic
    end

    %# ... long calculations ...    

    i = i + 1;
end

You would run your simulation as usual. When you would like to step in the code, simply create a file debug.txt (manually that is), and the execution will halt and you get the prompt:

2.803095 seconds since last time.
K>> 

You could then inspect your variables as usual... To continue, simply run return (dont forget to temporarily rename or remove the file). In order to exit, use dbquit


EDIT: Just occurred to me, instead of checking for files, an easier solution would be to use a dummy figure as the flag (as long as the figure is open, keep running).

hFig = figure; drawnow
while true
    if ~ishandle(hFig)
        keyboard
        hFig = figure; drawnow
    end

    %# ...
    pause(0.5)
end

这篇关于停止并继续执行调试器可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆