I had a bug in a long running program that would only show up after like six hours. I couldn’t replicate it in isolation because it had something to do with how state was being maintained. I set a conditional breakpoint right before the crash, inspected the stack, patch the function, and then had it pick back up by reëvaluating the current function call.
Damn thing just worked. It was amazing, and saved me so much time.
> ...inspected the stack, patch the function, and then had it pick back up...
After you edit the live state of the program, how do you translate that into code sitting in source control? Do you save this blob of memory and pass that down through generations?
2. Modify the source code containing the function.
2a. Save the file.
3. Copy function definition to the debugger’s repl, and evaluate it.
4. Resume the system from frame that calls the function.
But yes, you must be diligent about making sure the source files contain the code that is actually running, but that’s not much different than artifact tracking.
Step a): One just evaluates from the sources, while changing them. Once done -> save sources.
Step b): Create a patch file, which changes the image. Such a patch file can be loaded while starting an image, until one decides to save a new image with the changes already loaded.
For example there is a new release for the commercial LispWorks IDE once every one or two years. Users usually get only patch files for bug fixes during the one or two years maintenance. Thus I have a directory for patches to LispWorks, which are loaded when I start the base image.
There are tutorials all over the place however as Smalltalk is a system that, like Lisp, has dialects, they tend to be system specific. Lots of material at http://stephane.ducasse.free.fr/FreeBooks.html .
Just because that feature is available and at one time was desirable (when machines were so slow, that compiling would break the flow), doesn't mean one needs to or should use it today.
https://devblogs.microsoft.com/java/hot-code-replacement-for...
As long as it doesn't change the class signature, you can happily edit-save-replace code, and it jumps to the top of the method you're editing. It's basically instant, so you don't suffer the javac and JVM startup cost.
I don't think I can do the same in more dynamic languages, like Ruby or Python. Or, maybe, my IDEs don't support it (IntelliJ suite).
If I was doing that every day, or even every week, I could see it being a huge advantage to incorporate a solution in the language—but at least for me it just doesn't appear to be an obstacle that often (incidentally my background was initially in game programming, too).
I think this is where the trip up is. In a game, for example, that state is often exceptionally complex and getting everything right back to where you came from is usually only possible running the full game and recreating the same state.
In most cases it’s not hard to narrow down which aspects of state are relevant; you really only need to preserve everything for rare exceedingly subtle/deep bugs, which is a special case not a general usage kinda thing—and yet this feature is often discussed as revolutionary for programming in general.
from ipdb import launch_ipdb_on_exception
with launch_ipdb_on_exception():
foo()
But anyway, let's say I made an error somewhere and the program halts, putting me in the debugger. I can then examine each frame preceding the error. I can see every value going into my functions and jump around in the code generating those values. I change the code, while the debugger is still running, recompile it into the halted program and then pick a frame point right before the error occurred, to test if my changed code solves the problem. If it doesn't, I'll examine some more, perhaps start a second instance of the REPL to experiment a bit, then try another change in my code. All the while, I don't lose state. Once the problem is solved, my program will continue where it was as if the problem never happened.
For something like game programming, where you may be deep in the game and have encountered some rare combination of circumstances, this is simply invaluable.