svn commit: r279764 - head/sys/vm

Bruce Evans brde at optusnet.com.au
Thu Mar 12 10:05:25 UTC 2015


On Tue, 10 Mar 2015, Gleb Smirnoff wrote:

> On Tue, Mar 10, 2015 at 12:18:13PM +0200, Konstantin Belousov wrote:
> K> On Tue, Mar 10, 2015 at 01:01:41PM +0300, Gleb Smirnoff wrote:
> K> > On Sun, Mar 08, 2015 at 02:13:47AM +0000, Konstantin Belousov wrote:
> K> > K> Author: kib
> K> > K> Date: Sun Mar  8 02:13:46 2015
> K> > K> New Revision: 279764
> K> > K> URL: https://svnweb.freebsd.org/changeset/base/279764
> K> > K>
> K> > K> Log:
> K> > K>   Fix function name in the panic message.
> K> >
> K> > Why not use "%s, __func__" always and never encounter this problem
> K> > in future?
> K>
> K> Because you cannot grep for the panic string when __func__ is used.

It would also be an an obfuscation.

> Grepping for panic string doesn't work in general.

Yes it does.  The string just needs to be reasonably unique.  Even a
mispelled function name is usually unique enough.  Only function names
like f or printf would give too many matches.  __func__ is not unique
enough.  Neither are short format strings like "%d, %d, %d".  Longer
format strings might be unique enough, but are harder to type.

> A panic message
> can report pointers or numbers, which make text not unique. Actually,

Uniqueness is not needed.  Even for a function name you would probably
only type a part of the name that you hope is unique, then examine the
grep output to see if more context is needed.

> the messages that do report extra information are more useful. Also,

I consider them as usually just bloat.  Use a debugger to find more
info.  Unfortunately, not all users can run debuggers, and optimization
is now excessive so it breaks finding variable values.

> if panic string resides in the source code under several levels of
> indentation, it is likely to be split into two lines.

That would be another obfuscation.  Much worse that using __func__.

> But you can always grep for the function name and locate the panic
> or KASSERT in the function manually, which isn't a big deal. And
> if %s, __func__ is used, you will never get to a wrong function.

Better yet, spell all function names as __func__ or "this" in comments
so that they are write-only there too ;-).

Even better yet, spell all function names as __func__ in calls too.
Something like __func__ would work for determining the function to call
only for recursive calls.  __func__ itself doesn't work for that since
it is a string.  Determining the name of a different function is more
difficult.  If I knew C++, I might be able to give an example using
"this".  In C I don't see a better obfuscation (that can be easily
written) than using macros to change hard-to-type function names like
printf to that_there_func_0.  The name of the current function is of
course this_here_func ;-).  To actually be easier to type, change to
names like _0, _1, _2, etc.

Bruce


More information about the svn-src-head mailing list