如何在调试代码时修改代码而不必停止然后重新启动调试器 [英] how to modify code while debugging it without having to stop and then restart debugger

查看:86
本文介绍了如何在调试代码时修改代码而不必停止然后重新启动调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,感谢您阅读本文,


i已成为使用某种形式的基本语言30年的DOS / Windows用户。

i自己并运营一家小型编程公司,有一项功能可以让我保持在windows / basic世界。


虽然我同意它没有很好地发展,它确实有一个很棒的功能到目前为止,我还没有看到任何我知道的任何linux产品的复制。

i是一个很长时间的Windows用户并且有很好的学习新api的方法。

写一些代码然后运行它。

如果有错误,调试器会加载。

然后我就可以搞清楚了什么是错误,只需修改ocde并继续运行代码。

i不必停止代码,修改代码,重新运行代码。

经常错误只会发生在一系列复杂的条件之后,而不必完全停止应用程序是一种非常棒的方式来调试。


t这里有几个应用程序可以做到这一点。

实际上,免费版的visual studio 2005是免费的,具有这种能力。


so如何使用python调试代码并更改代码而无需重新启动代码。


非常感谢,

dave

hello and thanks for reading this,

i have been a dos/windows user using some form of the basic language for 30 years now.
i own and run a small programming company and there is one feature that keeps me in the windows/basic world.

while i will agree that it has not evolved well, it does have one awesome feature that i have yet to see replicated in
any linux product that i know about so far.
i am a long time windows user and have had a great way to learn new api.
to write some code and then run it.
if there is an error, the debugger will load.
then i can figure out what the eror is, just touch up the ocde and continue to run the code.
i do not have to stop the code, modify the code, rerun the code.
often an error will only happen after a complex set of conditions and not have to completely stop the app is a fantastic
way to debug.

there are several applications that can do this.
in fact, the free version of the visual studio 2005, which is free, have this ability.

so how can i use python to debug code and change that code without having to restart the code.

thanks so much,
dave

推荐答案




2005年11月7日星期一16:56,python写道:


On Monday 07 November 2005 16:56, python wrote:

所以如何使用python调试代码并更改代码而无需重启代码。

so how can i use python to debug code and change that code without having
to restart the code.



查看重新加载()


-

James Stroud

加州大学洛杉矶分校基因组学和蛋白质组学研究所

Box 951570

洛杉矶,CA 90095

http:// www。 jamesstroud.com/


" python" < d@d.com>写道:
"python" <d@d.com> writes:
我是一个很长时间的Windows用户,并有一个很好的方式来学习新的API。


还有更好的方法。请参阅下文。

编写一些代码然后运行它。
如果有错误,调试器将加载。
然后我可以弄清楚错误是什么,只是触摸ocde并继续运行代码。
我不必停止代码,修改代码,重新运行代码。
通常只有在复杂的条件之后才会发生错误而不是必须完全停止应用程序是一种梦幻般的调试方式。


是的。它已经存在了几十年。更酷的实现将

设置一个阶段,为您提供一组建议的修复,以及

能够到达调试器。

那么我如何使用python来调试代码并更改代码而无需重新启动代码。
i am a long time windows user and have had a great way to learn new api.
There''s a better way. See below.
to write some code and then run it.
if there is an error, the debugger will load.
then i can figure out what the eror is, just touch up the ocde and continue to run the code.
i do not have to stop the code, modify the code, rerun the code.
often an error will only happen after a complex set of conditions and not have to completely stop the app is a fantastic
way to debug.
Yup. It''s been around for decades. The cooler implementations will
interpose a stage that offers you a set of proposed fixes as well as
the ability to get to the debugger.
so how can i use python to debug code and change that code without having to restart the code.




好​​吧,正如James所说,你可以使用reload。重新加载你的

模块。但总的来说,这种事情在一般情况下,特别是在Python中,并不是很好用。这是一个原因的例子:



Well, as James mentioned, you can use "reload" to reload your
modules. But in general, this kind of thing doesn''t work very well in
OO languages in general, and in Python in particular. Here''s an
example of why:

def f():
.... print" Version 1"

.... fp = f:
def f():
.... print"版本2

.... f()
版本2 fp()
版本1
def f(): .... print "Version 1"
.... fp = f:
def f(): .... print "Version 2"
.... f() Version 2 fp() Version 1




我动态地改变了函数f - 就像你想要的那样 - 但是所有现在对它的引用仍将引用* old *版本的

函数(*)。要做正确的事情,您需要修复旧代码的所有

引用以引用新代码。除非

你的语言有能力捕获代码引用 - 首先

类函数,闭包或对象 - 这不是一个问题。但是,所有这些东西都是Python,而且每一个都会导致这样的问题,比如

。所以你真的不能继续来自调试器的程序;

你需要重新启动它以获得引用代码的所有内容

引用编辑过的代码。


但是,如果重点是学习API,那么在调试器中调整代码比调整代码要好很多。那是在口译员里面测试代码

。使用

BeautifulSoup编写网页抓取软件时,在刮擦序列中编写第一个猜测,然后在调试器中调整它的
就可以了。但是能够在解释器中获得

汤对象,并尝试抓取序列以查看他们直接返回的
甚至更好。在Emacs缓冲区中进行操作意味着

我已经完成了创建刮板的完整日志,因此我可以在需要时重建甚至复杂的序列。


如果你在这个小组中闲逛很长时间,你会听到很多关于

单元测试的信息。这是一个很好的主意,我推荐它高价值
。然而,它总是让我感到震惊,因为它是一种非常以批量为导向的
方法。一种更具互动性的方法是探索式编排,

更接近你所描述的内容,适用于你b
不知道问题空间非常好,或者如果 - 当学习新的

api时 - 你不太了解工具集。 Python是一个很好的

工具。它与你描述的不完全相同,但不同的是

并不一定低劣。


< mike

*)这是一个功能。经典使用是:

oldfoo = foo

def foo(* args,* kwds):

#预处理参数

返回oldfoo(* args,* kwds)


-

Mike Meyer< mw*@mired.org> http://www.mired.org/home/mwm/

独立的WWW / Perforce / FreeBSD / Unix顾问,请发送电子邮件以获取更多信息。



I changed the function f on the fly - just like you want to - but all
the existing references to it will still refer to the *old* version of
the function(*). To do the right thing, you need to fix all the
references to the old code to refer to the new code as well. Unless
your language has some ability to capture a code reference - first
class functions, closures, or objects - that won''t be a problem. But
Python ha all those things, and every one of them causes problems like
this. So you really can''t "continue" your program from the debugger;
you need to restart it to get everything that references code to
reference the edited code.

But if the point is to learn an API, then there''s something a lot
better than tweaking code inside a debugger. That''s testing code
inside the interpreter. When writing web scraping software with
BeautifulSoup, writing the first guess at the scrape sequence and then
tweaking it in the debugger would be ok. But being able to get the
soup object in the interpreter, and try scrape sequences to see what
they return directly is even better. Doing it in an Emacs buffer means
I have a complete log of what I did to create the scrape, so I can
reconstruct even complicated sequences if the need arises.

If you hang out in this group long enough, you''ll hear a lot about
"unit testing". It''s an excellent idea, and I recommend it
highly. However, it''s always struck me as a very batch oriented
approach. A more interactive approach is "exploratory proramming",
which is closer to what you''re describing, and is appropriate when you
don''t know the problem space very well, or if - as when learning a new
api - you don''t know the tool set very well. Python is an excellent
tool for this. It''s not exactly like what you described, but different
isn''t necessarily inferior.

<mike

*) This is a feature. Classic use is:
oldfoo = foo
def foo(*args, *kwds):
# preprocess the arguments
return oldfoo(*args, *kwds)

--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.


感谢迄今为止所有回复的人。

i仍然觉得__very__很难相信我在调试时无法编辑函数内的代码。
我提到的
即使微观
thanks for all that have replied so far.
i still find it __very__ hard to believe that i cannot edit code inside a function while debugging it.
as i mentioned even micro


这篇关于如何在调试代码时修改代码而不必停止然后重新启动调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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