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

Howard Hinnant hhinnant at apple.com
Fri Sep 16 10:30:54 PDT 2011


On Sep 15, 2011, at 7:01 AM, Christopher Jefferson wrote:

> 
> 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.

Thanks Chris.  I've checked in an experimental implementation of this.

-D_LIBCPP_DEBUG2

gets you the "standard" debugging mode, which includes checking for iterator invalidation.

-D_LIBCPP_DEBUG2=0

gets you "debug lite".  This only checks things that are really cheap such as those you mention.

I've left the door open for:

-D_LIBCPP_DEBUG2=2

which would make even more expensive checks (e.g. check the invariants of a red/black tree).  But that isn't done at this point.

I'm still concentrating only on vector at this point.

Howard





More information about the cfe-dev mailing list