[lldb-dev] logging in lldb

Zachary Turner via lldb-dev lldb-dev at lists.llvm.org
Tue Dec 6 10:07:48 PST 2016


Merging the thread over from lldb-commits:



On Tue, Dec 6, 2016 at 9:57 AM Jim Ingham via Phabricator <
reviews at reviews.llvm.org> wrote:

> jingham added a comment.
>
> I not infrequently have some non-trivial code in the "if (log)" block that
> gathers the information that I am then going to print, or loops over
> entities printing them.  Putting more complex code like that inside a macro
> looks awful and is hard to debug.  I don't think that argues for not using
> the macros in the case where you are logging a simple string, but it does
> argue for keeping the old way available.
>
Not arguing against keeping the old way possible, but as an aside,
llvm::formatv() can handle many of these cases pretty nicely.

For starters, it has builtin support for formatting ranges.  So if you're
ever looping over entities formatting them, as long as the entity itself
has a formatter defined, you can simply pass it directly to formatv and it
will do the right thing.  (It has some customization support built in as
well so you can control how to separate items).

Secondly, When you have to do some work to get the value you want to
format, you could either define a custom formatter for the type in
question, and the formatter does all the work, or you could write a
function to return the value you want to format, and call that in the
argument list, as long as the return type has an associated formatter.

I'm sure there will still be cases where you want to use the old method,
but I think this would handle quite a few of them and reduce the amount of
code you have to read / write when dealing with logging code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20161206/022ffa97/attachment.html>


More information about the lldb-dev mailing list