File and line numbers in error messages

ghudson@MIT.EDU ghudson at MIT.EDU
Tue Apr 28 15:37:17 EDT 2009

We had a request from within the MIT krb5 team to optionally include
file and line numbers in error messages.  This is fairly easy to do
with a macro like (relies on a gcc-ism):

#define krb5_set_error_message(ctx, code, fmt, ...) \
  krb5_set_error_message_fl(ctx, code, __FILE__, __LINE__, fmt, ## __VA_ARGS__)

with some appropriate back-end support, producing error messages like:

kinit: get_in_tkt.c: 1503: Client 'blah at ATHENA.MIT.EDU' not found in Kerberos database while getting initial credentials

Obviously, this only helps for code which uses krb5_set_error_message
or krb5int_set_error; code which simply returns an error code will
result in the same cryptic error messages they do today.

We don't want this enabled in production builds; it's not the kind of
error message you want end users to see on a day-to-day basis and it
adds a lot of static strings to the library object files.  So we need
some kind of compile-time flag, either specified through a make-time
option ("make CPPFLAGS=-DBLAH") or a configure-time option
("./configure --enable-blah").

There's a lot of... history in our code base surrounding debug
options, but I don't get the sense that there's any accepted standard
to conform to.  Is there anything I should be aware of before I decide
how this works?

I'm also aware that this feature isn't very useful if no one is really
aware of it, as seems true of a lot of our debugging features.  I'll
probably create a "debugging tips" page in our wiki to help advertise
features like this.

More information about the krbdev mailing list