Proposal: Unify printing the function name in panic messages()

Bruce Evans brde at optusnet.com.au
Sat Feb 9 09:27:00 UTC 2013


On Sat, 9 Feb 2013, Christoph Mallon wrote:

> On 07.02.2013 23:12, Andriy Gapon wrote:
>> on 07/02/2013 23:35 Christoph Mallon said the following:
>>> panic("just a message");
>>
>> This seems perfect.
>> Panic without at least a stack trace or preferably a crash dump is practically
>> useless in most cases.  A stack trace already has all the function names.
>> So a function name in a message seems to be redundant.
>
> This is nice in theory, but infeasible in practice.

This is feasible in practice, and needs less churn.  panic() can edit out
duplicates.  The callers can be changed at leisure.

> More than half of the panic() calls include the correct function name in a way or another.

If the function name is correct and is normally formatted as a literal
followed by a colon and a space at the start of the message, then it is
easy to detect and edit out.

If the function name is __func__ and is normally formatted with "%s: "
at the start of the format, then it is only a little harder to detect
and equally easy to edit out.

> I estimate, that another quarter show a wrong name.
> It is hard to get this number mechanically, because, well, the names are wrong.

If the name is wrong, then it is hard to detect the "duplication", either
at runtime or by reading the code.

> So most calls include the name (or try to).
> Having no function name is a minority.
> I plan to correct and unify this hotchpotch.
> Also, if stack traces are disabled, you at least can reliably determine, where the panic came from.

The name should still be printed in the panic message (unless you turn
this off), using the same name lookup as stack tracing uses.  If stack
traces are disabled, then you normally shouldn't disable names in the
panic message.  Disabling them would normally not disable the deduplication,
but deduplication could be controlled by another runtime option.

> Finally, you can turn the names on and off with one central switch.

A runtime switch works much better:
- no code bloat for function names in all cases
- no need to recompile to change the option
- more control at runtime.

Name lookup from the return address is broken for inline functions and
for other optimizations like tail calls, but much more is broken for
stack traces.

Bruce


More information about the freebsd-arch mailing list