Hi,

For those who "secretly" use printf debugging :). I know the
recommended way is to use a debugger and it's not the point of this
discussion.

The other day I was working on the Mac port (with no real possibility
to have a debug build) and I missed a lot a great feature we have in
Qt : qDebug(). I find the usage of printf cumbersome (so is LOG and
dataLog).
QDebug prettify and ease printf based debug workflow. Even in WebKit
using QDebug is pretty handy as very important core types of WebKit
have a Qt representation (e.g. WTF::String can be converted to a
QString). So you can do something like : String string("HELLO");
qDebug()<<string and it just output "HELLO" for you. Much more
efficient (to write ofc) than : fprintf(stderr, "%s\n",
string.utf8().data());
Still today a lot of WebKit core type have no counterpart in Qt (and
will never have) so qDebug pretty much fail (worst case it shows a
pointer address if possible).

I'm also aware of NSLog but it unfortunately only work in objective c files.

Then I thought about adding a dedicated debugging helper for WebKit in
general, not Qt related so it could benefit everyone not just a given
port.

So I propose wtf() and its stream operator.

Usage :

wtf()<<"Hello"<<"World"<<3<<4.53322323; will output : Hello World 3 4.53322

IntRect rect(10, 20, 50, 100);
wtf()<<"Rect"<<rect; will output : Rect IntRect(10,20 50x100)

Vector<String> v;
v.append("3");
v.append("4");
v.append("5");
wtf()<<v; will output : Vector ("3", "4", "5");

These are basic examples but we can really extend it to virtually
anything, like higher level classes.

Here is the bug with a patch attached :

https://bugs.webkit.org/show_bug.cgi?id=90823

wtf() is not meant to stay in a given function/patch. It is for
developers only who wants to debug, we don't want to add overhead in
release build and we do have the LOG macro doing a job similar.

An other alternative could be to extend dataLog to support this
streaming operator case. I'm open to this alternative too.

It's a work in progress but I want to get feedback before I continue
further (adding some stream operator overload for example) and also I
need to make sure it builds on all ports.

Do you think it is useful? Do you think it will ease/make you faster
when debugging when you use printf? Do you want that in WebKit?

I'm open to suggestion and maybe later improvements (such as showing
the line numbers, fct names...). If people think that is useless then
forget about it.

Thanks.

-- 
Alexis Menard (darktears)
Software Engineer
openBossa @ INdT - Instituto Nokia de Tecnologia
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev

Reply via email to