[lldb-dev] logging in lldb

Zachary Turner via lldb-dev lldb-dev at lists.llvm.org
Fri Dec 9 07:39:58 PST 2016


On Fri, Dec 9, 2016 at 7:36 AM Zachary Turner <zturner at google.com> wrote:

>
> On Fri, Dec 9, 2016 at 4:00 AM Jason Molenda via Phabricator <
> reviews at reviews.llvm.org> wrote:
>
>
> I'm not thrilled with the formatv reinvention of format specification.
> The printf formatters are a bizarre little invention, but it's a bizarre
> invention that we've all worked with for decades and everyone who works in
> C knows well.  The formatv format specification may be superior, but I
> don't want to see innovation here, I want clarity with the linga franca
> that every C programmer knows.  I think the barrier to adopting something
> non-standard is very high.
>
> While everyone knows it well, somehow it's still complicated enough that
> its usage is riddled with errors.  I can't even count the number of bugs
> I've fixed related to incorrect usage of format specifiers.
>
>
>
> The formatv format specification string seems to explicitly mention the
> ordering of the arguments, like llvm::formatv("{0} {1} {2}", first, second,
> third).  I'm guessing this allows you to print the arguments in different
> order than they appear?  Like  llvm::formatv("{0} {2} {2} {1}", first,
> second, third)?  What's the benefit of this vrs. the uncertainty of which
> arguments are used in different parts of the string (short of counting them
> out by hand)?  If I have a formatv format specification like "{0} {1} {2}
> {3} {4}" and I want to insert an argument between 2 and 3, I need to
> renumber 3 and 4 now?  Or do I do "{0} {1} {2} {5} {3} {4}" and throw my
> argument on to the end?
>
> Either / or would be fine.  BTW, this is not the primary advantage of
> having the arguments be numbered.  The primary advantage is that it allows
> you to print the same argument multiple times without computing it.
> formatv("{0} {0} {0}", 7);   will print "7 7 7".
>

I guess I should elaborate.  The *real* primary advantage is simply not
specifying the format specifier at all.  When you have to match the format
specifier to the type of the argument you've already lost the battle,
because you've introduced a source of programmer error.  And not just a
hypothetical source either, considering the number of bugs I've fixed in
incorrect usage of format specifiers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20161209/9175aa78/attachment.html>


More information about the lldb-dev mailing list