473,748 Members | 7,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to modify code while debugging it without having to stop and then restart debugger

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

Nov 8 '05 #1
13 2935


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

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

look into reload()

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Nov 8 '05 #2
"python" <d@d.com> writes:
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.


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 "Version 2"
.... f() Version 2 fp() Version 1


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 "explorator y 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.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 8 '05 #3
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$soft can do this using statically type languages like visual basic and csharp.
also, both visualbasic and csharp have goto statements, which i do to not use in final code but can be real handy when
used with the ability to change debugged code on the fly while inside the function being debugged.

for example,
if i am inside a function and there is some an error on a line and that is where the debugger is currently pointing at,
i simple copy and paste the bad code line just below the actual code line.
i fix this copied code line.
then i just turn the bad line into a comment line and the debugger will move the current focus to the next time, which
is the fixed code.

how can such a dynamic language like python not be able to do this.

i have seen functions like exec that can even run dynamically generated text on the fly.

very strange..

any other ideas,

thanks so much,

dave

"python" <d@d.com> wrote in message news:lI******** *********@fe12. lga...
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

Nov 8 '05 #4
Hi Dave,

Currently there is no python debugger (that I know of) that does it,
altough tools are beggining to get to it (another example outside of the
python world is that eclipse already does it for java). If you use the
pdb (that is the command-line debugger that comes along with python),
you can do it, but it would require a considerable effort because you
would have to modify it manually (with reload, assignments, etc.) -- not
really a good thing in my opinion -- and you wouldn't have the easiness
that is provided by visual debuggers.

Now, I'm the developer of pydev (http://pydev.sf.net), that is a plugin
that aims at enabling python development within eclipse (and is already
used a lot in the python community), and I believe that given some time
pydev will reach the functionality you're describing -- as others will
probably do too -- and that's one of the reasons why pydev is being
developed (the current state of tools for editing python still has space
for LOTS of opportunities).

So, making it short... currently you can do it but it is not easy
because tools are still catching up to what python provides (I
personally believe this is because it is so easy to edit python and
understand the code that some people don't look for other alternatives,
and end up just 'accepting' what they have because it is already better
than alternatives -- altough this is only true for some given scenarios).

Cheers,

Fabio

python wrote:
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$soft can do this using statically type languages like visual basic and csharp.
also, both visualbasic and csharp have goto statements, which i do to not use in final code but can be real handy when
used with the ability to change debugged code on the fly while inside the function being debugged.

for example,
if i am inside a function and there is some an error on a line and that is where the debugger is currently pointing at,
i simple copy and paste the bad code line just below the actual code line.
i fix this copied code line.
then i just turn the bad line into a comment line and the debugger will move the current focus to the next time, which
is the fixed code.

how can such a dynamic language like python not be able to do this.

i have seen functions like exec that can even run dynamically generated text on the fly.

very strange..

any other ideas,

thanks so much,

dave

"python" <d@d.com> wrote in message news:lI******** *********@fe12. lga...

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



Nov 9 '05 #5
python wrote:
so how can i use python to debug code and change that code without having to restart the code.


I don't know how well the commercial GUIs, such as Wing IDE
manage to handle debugging. Perhaps that's worth looking into.

It's my impression that debugger support in Python is weaker
than e.g. VB, because Python programmers don't need and use
debuggers so much.

I think there are several reasons for this:
- It's easy to experiment with code in the interactive
interpreter.
- Python programs don't dump. There is rarely a need to put
a breakpoint at some known safe place and single-step from
there until it crashes, and then redo everything, trying to
find at what place before the crash you really had your bug.
You'll almost always get a controlled exception in Python.
- The tracebacks you get when exceptions appear are very
informative, and typically enough to spot the bugs more or
less at once. I debugged python programs I've never seen
before last night and today. There were maybe half a dozen
bugs, and in all cases, the tracebacks showed me exactly what
I needed to do to fix the problems at once.
- Due to Python's expressiveness, typical Python programs are
shorter and simpler than comparable programs written in
other languages. If you have spaghetti code, you really
need to single-step to understand what is going on. Python
code is typically well structured.
- With Python, it's common that people write unit tests
using e.g. the unittest or doctest libraries. With a test
driven approach as described in Extreme Programming, you run
your tests very often, with small changes in the code between
each test run.
- With object-oriented programming, it's easier to structure
your code so that each chunk of code (e.g. method) is
easy to understand. In other words, the divide and conquer
approach to problem solving works better.

I guess another reason is that Microsoft has put a lot of money
into making VB and friends user friendly. These products are
very much geared into accomodating beginners, and a nice looking
GUI has been a very high priority. For an open source tool such
as Python, where the people who drive development are the people
who need to use the tool, being beginner friendly isn't the top
priority (even though Python has succeeded well in that regard
anyway). Aspects such as stability and consistency in semantics
is considered much more important. (VB has a prettier GUI, but
Python is a much prettier language...)
Nov 9 '05 #6
On Tue, 08 Nov 2005 13:38:28 -0500, python wrote:
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.
You write a function:

def myfunct(s):
# input arg s is a string
foo = s*3
bar = s.upper() + foo # LINE 2
blob = foo.lower() + bar
return blob

You enter the debugger and single-step to the marked line LINE 2. Then you
edit the code to this:

def myfunct(n):
# input arg n is an int
foo = n + 1
bar = foo*2 # LINE 2
blob = foo**bar
return blob

What should Python do when you step the debugger, and why is it useful?

as i mentioned even micro$soft can do this using statically type languages like visual basic and csharp.
also, both visualbasic and csharp have goto statements, which i do to not use in final code but can be real handy when
used with the ability to change debugged code on the fly while inside the function being debugged.
Better and better. Yes, I can see how the ability to jump around a
function on the fly would really help you understand how the function is
supposed to work when you take the gotos out.
for example,
if i am inside a function and there is some an error on a line and that is where the debugger is currently pointing at,
i simple copy and paste the bad code line just below the actual code line.
i fix this copied code line.
then i just turn the bad line into a comment line and the debugger will move the current focus to the next time, which
is the fixed code.

how can such a dynamic language like python not be able to do this.


Do you try to ignore the syntax and grammar of the programming language
you are coding in too, or only English?
[snip]
there are several applications that can do this.
in fact, the free version of the visual studio 2005, which is free, have this ability.


Just out of curiosity, how much is the free version of Visual Studio 2005?
--
Steven.

Nov 9 '05 #7
Steven D'Aprano wrote:
On Tue, 08 Nov 2005 13:38:28 -0500, python wrote: [...]
as i mentioned even micro$soft can do this using statically type languages like visual basic and csharp.
also, both visualbasic and csharp have goto statements, which i do to not use in final code but can be real handy when
used with the ability to change debugged code on the fly while inside the function being debugged.

Better and better. Yes, I can see how the ability to jump around a
function on the fly would really help you understand how the function is
supposed to work when you take the gotos out.

I must admit I had been wondering just how far the OP wanted to go in
mangling the code. I suspect that the interesting bit to the OP is
having a visual editor available to alter functions and class
definitions "on the fly" rather than having to completely re-enter the
definition as you would at the interactive interpreter prompt. He or
she'd probably be a bit unhappy about the need to reload() modules too,
I suppose.

for example,
if i am inside a function and there is some an error on a line and that is where the debugger is currently pointing at,
i simple copy and paste the bad code line just below the actual code line.
i fix this copied code line.
then i just turn the bad line into a comment line and the debugger will move the current focus to the next time, which
is the fixed code.

how can such a dynamic language like python not be able to do this.

Do you try to ignore the syntax and grammar of the programming language
you are coding in too, or only English?

That's rather unkind. I'd judge we are plainly dealing with someone who
is working hard to express questions in a foreign language. Funny,
perhaps, but definitely unkind. Take two demerits and smack yourself on
the wrist.
there are several applications that can do this.
in fact, the free version of the visual studio 2005, which is free, have this ability.

Just out of curiosity, how much is the free version of Visual Studio 2005?

I'm not positive, but i think they're currently giving it away.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Nov 9 '05 #8
Steve Holden <st***@holdenwe b.com> writes:
Steven D'Aprano wrote:
On Tue, 08 Nov 2005 13:38:28 -0500, python wrote:

[...]
as i mentioned even micro$soft can do this using statically type languages like visual basic and csharp.
also, both visualbasic and csharp have goto statements, which i do
to not use in final code but can be real handy when used with the
ability to change debugged code on the fly while inside the
function being debugged.

Better and better. Yes, I can see how the ability to jump around a
function on the fly would really help you understand how the function is
supposed to work when you take the gotos out.

I must admit I had been wondering just how far the OP wanted to go in
mangling the code. I suspect that the interesting bit to the OP is
having a visual editor available to alter functions and class
definitions "on the fly" rather than having to completely re-enter the
definition as you would at the interactive interpreter prompt. He or
she'd probably be a bit unhappy about the need to reload() modules
too, I suppose.


In that case, you're using the wrong IDE. I run the Python interpeter
inside of Emacs. I edit my code in another buffer. In the source code
buffer, I hit M-C-x, and the current version of the function I'm
currently editing gets sent to the interpreter. Reload is pretty easy
as well - C-c RETURN, and the module I'm editing gets reloaded.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 9 '05 #9
Steven D'Aprano:
You write a function:

def myfunct(s):
# input arg s is a string
foo = s*3
bar = s.upper() + foo # LINE 2
blob = foo.lower() + bar
return blob

You enter the debugger and single-step to the marked line LINE 2. Then you
edit the code to this:

def myfunct(n):
# input arg n is an int
foo = n + 1
bar = foo*2 # LINE 2
blob = foo**bar
return blob

What should Python do when you step the debugger,
Python should throw the power switch and sulk for at least an hour.
and why is it useful?


Teaches the user who's boss.

Debug time code modification is useful to me in C++ for two reasons.
The first is where there is a simple bug: step, step, step, aah!,
fiddle, step, works! The second is where you want to perturb the code to
produce some unusual situation within a test run: how would the calling
code cope if this code allowed a duplicate element through? fiddle,
step, step, crash! Mmm, that looks like the fault report, maybe there is
another way that duplicates are possible. The first type of change
become permanent parts of the code while the second type are ephemeral.

There are limitations to the technology: if you add too much code it
won't fit in the allocation (which has been padded a bit for debugging
but not much) or the function is being reentered. I'm not sure about all
the limitations and they change between releases but it probably fails
about one time in ten for me. This doesn't stop the session, just leaves
your change unapplied.

Neil
Nov 9 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3269
by: TJ | last post by:
Anyone know how to display process id's (normally found by going to Component Services and switching to applications to 'Status View') in a web page? I'm trying to keep remote users from having to terminal server or use com+ to view the process id's they need for asp debugging (via attaching to a process (remote debugging via dcom and machine debug manager)) Thx in advance,
2
1497
by: orion30 | last post by:
All is in the Object. Is-it possible to modify a window from an another window without having a link Parent To Child ? Thank you
2
1647
by: Baldy | last post by:
Hi All is it possible to modify code at run time? I have a set of constants that change at deployment (from development to deployment server and a few other consts) I have a menu item that prepares the DB for deployment. It does a few other things, re-links tables, tuns of shift key bypass etc. But can I modify the code? do I need to use #if ? thanks
1
1619
by: Dieter Vanderelst | last post by:
Dear all, Could anybody tell me whether there are ways to use an existing DLL file in Python without having access to the source code? I'm trying to find a way to use the image filters available in the Filters-project (http://filters.sourceforge.net/) without having to compile or build the DLL myself, which is according to the authors very hard.
1
9804
by: Primera | last post by:
I have an application that fixes some common problems that prevent the SMS Advanced Client from operating correctly. During this application I need to stop the Windows Management Instrumentation (winmgmt) service, delete the Repository directory, and then restart winmgmt which will then automatically regenerate the Repository directory. Since I am stopping WMI I cannot use System.Management to perform this. I have tried: ...
0
1461
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a .NET component (VC++) with native C++ at it's core. The native C++ code makes a call to SHFileOperation to delete a directory and it's contents. When I host the .NET component in a VB app, and the SHFileOperation delete is called, the application hangs forever unless I have the "Enable Unmanaged code debugging" project setting on. Note the hang only occurs when I'm running the VB app through the debugger. What gives? Thanks...
17
2117
by: Johnny BeGood | last post by:
Hi All, Is there a way to post the contents of a form without having to click on the Submit button, i.e <form method="post" action="http://www.whereever.com/ProcessTheData.php"> <INPUT name="Field1" type="text"> <INPUT name="Field2" type="text"> <INPUT name="Field3" type="text"> <INPUT name="EsendexRecipient" type="text">
1
5664
by: aj | last post by:
A few service stop/start/restart questions on SQL Server 2005 SP2, which I'll call SQLS. It looks as if there are *potentially* 6 ways to start/stop SQLS Services like the engine itself, integration services, reporting service, Agent.. -SQLS Configuration Manager -SQLS Surface Area Configuration (for Services and Connections) -Mgmt Studio Local (on server)
3
2158
by: DR | last post by:
I heard there is some trick to referencing statics in C# CLR stored procedure without having to mark the assembly as unsafe. Does anyone know this? This is usefull as the case of needing a little static shared variable here and there without having to compromise safety in the Sql Server 2005.
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.