Open Quuxplusone opened 11 years ago
Attached examples.c
(130 bytes, application/octet-stream): The two examples (multi-expression if, do-while with line-break)
Presumably you don't want the debugger to stop at each subexpression
while you're single-stepping, otherwise you get into some really
egregious situations like the following...
Supposing the example was something like:
x =
3 * y +
2 * z;
Assigning what would intuitively be the "correct" line to each
operation, and single-stepping through it, we would stop at
line 2 (for 3 * y)
line 3 (for 2 * z)
line 2 (for the +)
line 1 (for the =)
That's a lot of bouncing around for one statement.
And it gets way worse with any optimization that can reorder
those instructions.
If you don't want the debugger to stop at all those places, what is
the advantage to assigning "correct" line numbers to the code generated
for the subexpressions? Did you have some other use for the debug-line
info, other than controlling debugger behavior?
(In reply to comment #1)
> Presumably you don't want the debugger to stop at each subexpression
> while you're single-stepping, otherwise you get into some really
> egregious situations like the following...
>
> Supposing the example was something like:
> x =
> 3 * y +
> 2 * z;
> Assigning what would intuitively be the "correct" line to each
> operation, and single-stepping through it, we would stop at
> line 2 (for 3 * y)
> line 3 (for 2 * z)
> line 2 (for the +)
> line 1 (for the =)
> That's a lot of bouncing around for one statement.
This is an interesting example that I hadn't thought of. This is certainly a
good argument against stopping at every subexpression in the general case.
Not knowing the internals very well: Does this also potentially rule out the
validity of the do-while example in the attached? It seems that that case is
still unusual, as no debug info at all uses the line number of the while
condition.
> Did you have some other use for the debug-line
> info, other than controlling debugger behavior?
In my case, I actually do. I use it to do over-approximate best-effort
matching to the CFG produced by an outside analysis tool. I obviously don't
expect design to match my particular use case, though. I'm most concerned,
then, about those cases that also cause somewhat confusing behavior in a
debugger.
(In reply to comment #2)
> Not knowing the internals very
> well: Does this also potentially rule out the validity of the do-while
> example in the attached? It seems that that case is still unusual, as no
> debug info at all uses the line number of the while condition.
A compiler will pick the location of something associated with the
end of the loop, that's easy for the compiler developer to find
and (in the developer's opinion) not obviously wrong.
Clang decided to use the closing brace, for whatever reason;
an old-ish gcc uses the terminating semicolon. There are reasonable
arguments for other choices, such as the 'while' keyword or the
open-paren or the first expression token after the open-paren.
Whether it's worth changing is mostly based on your opinion of how
likely it is to have the while condition broken up like that, because
that's the only time the actual debugging experience would be affected.
I haven't investigated whether it would be easy to tweak Clang's choice.
examples.c
(130 bytes, application/octet-stream)