(snip on edit-and-continue)
Seems to me that one could write a C interpreter, or something close
to one, that would allow for the usual abilities of interpreted
languages. Among other things that could make C easier/faster to
debug would be full bounds checking.
I believe various C-like interpreters have been made over the years, but
none have been very popular - basically, if you first decide to use an
interpreted model (and thus get easy equivalents to
"edit-and-continue"), there are better languages for the job. C or
C-like interpreters would only be useful for specifically checking
something you write in C. And in such cases, you can often transplant
the code into a minimal test program, taking a fraction of a second to
compile and run.
But I agree with you that features such as bounds checking could often
be useful in debugging C code. There are quite a lot of related tools,
such as "valgrind", instrumentation functions, libraries with extra
checks, etc. But there is always scope for more. For example, gcc has
a "-fbounds-check" option, but it is only supported for Java and Fortran
(Ada has it automatically, I think). Supporting it for C (or C++, where
exceptions give an obvious choice of how to react to a bounds error)
would be helpful for some types of debugging.
Well, even more, does that change the bugs that need to be found?
Yes, because some bugs are only noticeable when you are optimising. For
example, if you've got code that has aliasing issues, it might run as
you wanted when optimising is disabled, but fail when the compiler takes
advantage of type-based aliasing analysis to produce faster code. It is
for this sort of reason that I normally use a single set of options for
my compiling - with fairly strong optimisation as well as debug
information - rather than having separate "debug" and "release"
configurations. Occasionally I need to reduce optimisation while
identifying weird bugs, but mostly it is constant throughout development.
If it takes one second to start the program from the beginning and
get to the point of the bug, is it really worth edit-and-continue?
For me, when I am debugging I want to be thinking as much as I can
about the program I am working on. What it could possibly be doing
wrong, and how to fix that. If I also have to think about other causes
for bugs, such as having the wrong pointer due to edit-and-continue,
then I can't completely think about the program.
Agreed.
As I wrote, I did years ago use a BASIC system that allowed for
edit and continue. (You could even continue at a different place.)
But later, due to changes in ORVYL, that feature was removed.
I sometimes do things like manually manipulate the program counter from
within the debugger, to get this effect. Most of my work is embedded
systems, and in some systems the "compile, download and run" cycle is
long (the compile is typically quick, but downloading or reprogramming
flash can be slow on some microcontrollers). edit-and-continue might be
useful in such systems - unfortunately, it would be completely
impractical to implement.
They might not be so rare, but in many cases other ways have been
found to get around them.
Fair enough point.