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

Ruben Van Boxem vanboxem.ruben at gmail.com
Mon Sep 19 00:25:42 PDT 2011


Op 19 sep. 2011 05:13 schreef "M.E. O'Neill" <oneill at cs.hmc.edu> het
volgende:
>
> Howard Hinnant wrote:
> >>> There isn't a lot there yet.  I've tried to get vector working (just
the primary, not vector<bool> so far), and I believe I have done so.  Though
I don't have tests for it yet (I've just been spot checking).  At this point
I'm simply exploring whether the basic design is viable or not.
> >>>
> >>> A major goal of the design of this debug mode is to keep the ABI
stable as debug mode is turned on/off.
>
> Sounds good, but it'd be useful to have a more detailed design document
somewhere so that people can see where you're going and how.
>
> ... and Christopher Jefferson replied:
> >> I have often seen interest on a "cheap" debugging mode, which would add
checks which were possible without breaking complexity requirements, or
"excessive" cost.
>
> Without seeing Howard's design, I don't know how "excessive" the costs of
his design might be, but in principle, you can do some checks like iterator
invalidation very cheaply -- if you have the right design.
>
> This may be obvious (in which case I apologize), it may even be what
Howard has already done (in which case, oops, and, uh, cool), but in case it
isn't, let me outline how:
>
> - For every container, associate a 64-bit tag (a.k.a. version stamp).
>
> - For every iterator, also associate a 64-bit tag.
>
> - When you create a new container, just pick a random 64-bit value.
>
> - When you create an iterator, copy the 64-bit tag from the associated
container.  This represents the container/version the iterator belongs to.
Any access via the iterator checks that the tag of the iterator matches the
tag of the container.  If it doesn't, BANG!
>
> - When iterators are invalidated, generate a new tag for container. (For
speed, you could just increment it, but the important point is that the
value is a new and different one)
>
> This method is probabilistic -- there is a 1 in 18446744073709551616
chance that it won't catch an invalid access, but personally I like those
odds.  It also imposes very very little in runtime overhead -- you can
invalidate N iterators in O(1) time.

Why not just use the cool c++11 random number generators, if performance
would be an issue, time to optimise those ;-) I don't like the idea of
probabilistic odds, especially in hugely iterated and containered program
this would make debugging useless (especially for long-running server-like
programs that would need to be debugged)

Ruben

>
> I've always stored the tag in the containers/iterators, but it should also
work with a database-based scheme.
>
>    M.E.O.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110919/55a9952c/attachment.html>


More information about the cfe-dev mailing list