[cfe-dev] [libc++] debug mode

Christopher Jefferson chris at bubblescope.net
Thu Sep 15 04:01:36 PDT 2011


On 14 Sep 2011, at 20:35, Howard Hinnant wrote:

> A few years back, prior to the open sourcing of libc++, I attempted to create a debug mode.  That first effort had a little bit of good work in it, but was basically still-born.  It is defined under _LIBCPP_DEBUG and doesn't even compile today.
> 
> Lately I've been working on a new debug mode.  It is currently defined under _LIBCPP_DEBUG2.  The plan is that if this experiment is successful, then _LIBCPP_DEBUG2 will be renamed to _LIBCPP_DEBUG, and the original _LIBCPP_DEBUG will either be integrated, or it will disappear.
> 
> The initial check-in for _LIBCPP_DEBUG2 was committed revision 139711.
> ...
> In addition to the database, there is an assert-like macro:
> 
>    _LIBCPP_ASSERT(true/false, "message");
> 
> I decided not to use assert itself as preliminary clients advised me that they would like to turn libc++ debug mode on/off independently of NDEBUG.
> 
> Suggestions concerning debug mode and/or contributions are welcome.

I have often seen interest on a "cheap" debugging mode, which would add checks which were possible without breaking complexity requirements, or "excessive" cost.

For vector I would include in this (as a non-complete list)

check in front(), back() and pop_back() the vector is non-empty.
Check operator[] accesses a valid index.
scribble over memory in destructor (or set to a clearly invalid value, such as vector memory is at (void*)1). Perhaps this last point could/should be implemented by the compiler, or malloc implementation?

I don't know how much code this could share with a larger debugger. obviously the same checks could be left in, but they might be redundant.

Also, I am not 100% sure if people wanted this previously because it would not cause ABI breakage. I would still find it worthwhile, as container debugging modes can get very expensive.

Chris



More information about the cfe-dev mailing list