Bug 90823 - Ease printf debugging in WebKit.
Summary: Ease printf debugging in WebKit.
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Alexis Menard (darktears)
URL:
Keywords:
: 110452 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-07-09 14:27 PDT by Alexis Menard (darktears)
Modified: 2013-03-06 12:07 PST (History)
19 users (show)

See Also:


Attachments
Patch (8.91 KB, patch)
2012-07-09 14:29 PDT, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (15.51 KB, patch)
2012-07-10 07:52 PDT, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (15.49 KB, patch)
2012-07-10 08:46 PDT, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (15.52 KB, patch)
2012-07-10 09:45 PDT, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (15.49 KB, patch)
2012-07-10 11:08 PDT, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (18.74 KB, patch)
2012-11-09 05:21 PST, Rafael Brandao
menard: review-
Details | Formatted Diff | Diff
WIP that I have locally. (6.37 KB, text/plain)
2012-11-09 05:28 PST, Alexis Menard (darktears)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexis Menard (darktears) 2012-07-09 14:27:16 PDT
Ease printf debugging in WebKit.
Comment 1 Alexis Menard (darktears) 2012-07-09 14:29:00 PDT
Created attachment 151321 [details]
Patch
Comment 2 Alexis Menard (darktears) 2012-07-09 14:31:02 PDT
(In reply to comment #1)
> Created an attachment (id=151321) [details]
> Patch

Some work in progress/idea.

Obviously need to be finished.
Comment 3 Antonio Gomes 2012-07-09 14:32:25 PDT
see discussion here: https://bugs.webkit.org/show_bug.cgi?id=79176
Comment 4 yosin 2012-07-09 18:22:36 PDT
Comment on attachment 151321 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=151321&action=review

> Source/WTF/wtf/DebugHelpers.h:32
> +#include "windows.h"

<windows.h>?

> Source/WTF/wtf/DebugHelpers.h:61
> +            OutputDebugString((wchar_t*)output.utf8().data());

I think it is better to use OutputDebugStringW(wchar_t* utf16ButNoSurrogate) or converting code page CP_ACP with OutputDebugStringA(char* mbcsStringButNotUTF8)
Comment 5 Alexis Menard (darktears) 2012-07-09 19:10:02 PDT
Comment on attachment 151321 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=151321&action=review

>> Source/WTF/wtf/DebugHelpers.h:32
>> +#include "windows.h"
> 
> <windows.h>?

Well for OutputDebugString. I don't have a Windows machine to test so I would rely on someone else to guide me.
Comment 6 Alexis Menard (darktears) 2012-07-10 07:09:08 PDT
(In reply to comment #5)
> (From update of attachment 151321 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=151321&action=review
> 
> >> Source/WTF/wtf/DebugHelpers.h:32
> >> +#include "windows.h"
> > 
> > <windows.h>?
> 
> Well for OutputDebugString. I don't have a Windows machine to test so I would rely on someone else to guide me.

Ah I just saw, yes of course with <> it's better :)
Comment 7 Alexis Menard (darktears) 2012-07-10 07:52:04 PDT
Created attachment 151461 [details]
Patch
Comment 8 Build Bot 2012-07-10 08:43:46 PDT
Comment on attachment 151461 [details]
Patch

Attachment 151461 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/13183080
Comment 9 Alexis Menard (darktears) 2012-07-10 08:46:31 PDT
Created attachment 151465 [details]
Patch
Comment 10 Build Bot 2012-07-10 09:11:19 PDT
Comment on attachment 151465 [details]
Patch

Attachment 151465 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/13053003
Comment 11 Alexis Menard (darktears) 2012-07-10 09:45:53 PDT
Created attachment 151470 [details]
Patch
Comment 12 WebKit Review Bot 2012-07-10 09:48:58 PDT
Attachment 151470 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WTF/ChangeLog', u'Source/WTF/GNUmak..." exit_code: 1
Source/WTF/wtf/DebugHelpers.h:52:  Missing spaces around <  [whitespace/operators] [3]
Total errors found: 1 in 10 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Alexis Menard (darktears) 2012-07-10 11:08:46 PDT
Created attachment 151489 [details]
Patch
Comment 14 Balazs Kelemen 2012-07-11 02:09:05 PDT
Comment on attachment 151489 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=151489&action=review

My informal comments on the patch. In general I think this is useful stuff.

> Source/WTF/wtf/DebugHelpers.h:76
> +    inline WTFDebug& space()
> +    {
> +        m_stream->m_space = true;
> +        m_stream->buffer.append(' ');
> +        return *this;
> +    }
> +    inline WTFDebug& nospace()
> +    {
> +        m_stream->m_space = false;
> +        return *this;
> +    }
> +    inline WTFDebug& maybeSpace()
> +    {
> +        if (m_stream->m_space)
> +            m_stream->buffer.append(' ');
> +        return *this;
> +    }

It's not clear when is maybeSpace() supposed to be used. Could you give an example?

> Source/WTF/wtf/DebugHelpers.h:145
> +    class Stream : public RefCounted<Stream> {

Why is it refcounted?
Comment 15 Alexis Menard (darktears) 2012-07-11 05:12:43 PDT
Comment on attachment 151489 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=151489&action=review

>> Source/WTF/wtf/DebugHelpers.h:76
>> +    }
> 
> It's not clear when is maybeSpace() supposed to be used. Could you give an example?

All the overload of << use it. And you have the concept with inline WTFDebug& operator<<(WTFDebug debug, const Vector<T>& vector). I set the debug.nospace() in that function, all overloads (depending the template value) which will be used after will have a no space. But the regular case they have a space, that's why the maybeSpace().

>> Source/WTF/wtf/DebugHelpers.h:145
>> +    class Stream : public RefCounted<Stream> {
> 
> Why is it refcounted?

When using the default copy constructor m_stream will not be deep copied.
Comment 16 Hugo Parente Lima 2012-07-30 10:44:04 PDT
Huge discussion on mailing list... on the bug report... so... Any conclusions?

Btw, I'm pro-debug-header-for-printf-style-debug-and-happiness.
Comment 17 Alexis Menard (darktears) 2012-07-31 12:49:33 PDT
(In reply to comment #16)
> Huge discussion on mailing list... on the bug report... so... Any conclusions?
> 
> Btw, I'm pro-debug-header-for-printf-style-debug-and-happiness.

Based on the feedback of webkit-dev I will make another proposal.
Comment 18 Rafael Brandao 2012-11-09 05:21:57 PST
Created attachment 173272 [details]
Patch
Comment 19 Alexis Menard (darktears) 2012-11-09 05:28:02 PST
Created attachment 173274 [details]
WIP that I have locally.
Comment 20 Alexis Menard (darktears) 2012-11-09 05:36:32 PST
Comment on attachment 173272 [details]
Patch

I don't think the flag is needed. It's one file to build so it's fine and you just don't include it if you don't need it. If I recall correctly on the ML it was wtfPrint that people preferred. Also it seems to be a better place on WTF than WebCore. It will not work on Mac also, it seems you need to output in stderr.
Comment 21 Rafael Brandao 2012-11-09 06:06:16 PST
When I have tried to use the << operator over WTF and isolate the world of debuggers like I did in this patch on it (rather than adding in IntRect the way we use debug with it), I've noticed that it would create a cyclic dependency over WTF and WebCore. WTF should not need to use types like WebCore's IntRect on it. Obviously this just happened because I've went into this isolated approach, but this brought my attention to whether we should put this debug after all. I've decided to move to WebCore instead. Is this a bad move?

It's also by purpose that I didn't put space between debugs. I've went into a simplistic approach, the user should be free to print the way he wants to, like: debug(__PRETTY_FUNCTION__, ": ", rect, "\n");

I've decided to put a flag just to avoid breakage or including unnecessary functions over platforms that don't really think it is useful. But for the others that think it can be helpful, then you should pass --debug-helpers on build to enable it.
Comment 22 Rafael Brandao 2012-11-09 06:07:37 PST
(In reply to comment #21)
> When I have tried to use the << operator over WTF and isolate the world of debuggers like I did in this patch on it (rather than adding in IntRect the way we use debug with it), I've noticed that it would create a cyclic dependency over WTF and WebCore. WTF should not need to use types like WebCore's IntRect on it. Obviously this just happened because I've went into this isolated approach, but this brought my attention to whether we should put this debug after all. I've decided to move to WebCore instead. Is this a bad move?
> 
> It's also by purpose that I didn't put space between debugs. I've went into a simplistic approach, the user should be free to print the way he wants to, like: debug(__PRETTY_FUNCTION__, ": ", rect, "\n");
> 
> I've decided to put a flag just to avoid breakage or including unnecessary functions over platforms that don't really think it is useful. But for the others that think it can be helpful, then you should pass --debug-helpers on build to enable it.

s/to whether we should/to where we should
Comment 23 Alexis Menard (darktears) 2012-11-09 06:40:45 PST
(In reply to comment #21)
> When I have tried to use the << operator over WTF and isolate the world of debuggers like I did in this patch on it (rather than adding in IntRect the way we use debug with it), I've noticed that it would create a cyclic dependency over WTF and WebCore. WTF should not need to use types like WebCore's IntRect on it. Obviously this just happened because I've went into this isolated approach, but this brought my attention to whether we should put this debug after all. I've decided to move to WebCore instead. Is this a bad move?
> 

People didn't want << so you should not worry about those.

> It's also by purpose that I didn't put space between debugs. I've went into a simplistic approach, the user should be free to print the way he wants to, like: debug(__PRETTY_FUNCTION__, ": ", rect, "\n");
> 

ok.

> I've decided to put a flag just to avoid breakage or including unnecessary functions over platforms that don't really think it is useful. But for the others that think it can be helpful, then you should pass --debug-helpers on build to enable it.
Comment 24 Benjamin Poulain 2013-02-21 12:28:29 PST
*** Bug 110452 has been marked as a duplicate of this bug. ***
Comment 25 Martin Robinson 2013-03-06 10:59:49 PST
Comment on attachment 173272 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=173272&action=review

> configure.ac:543
> +# check whether to enable DebugHelpers.h support
> +AC_MSG_CHECKING([whether to enable DebugHelpers.h support])
> +AC_ARG_ENABLE(debug_helpers,
> +              AC_HELP_STRING([--enable-debug-helpers],
> +                             [enable support for DebugHelpers.h [default=no]]),
> +              [],[enable_debug_helpers="no"])
> +AC_MSG_RESULT([$enable_debug_helpers])

This change and the change to the makefile shouldn't be necessary. Please see: http://trac.webkit.org/wiki/AddingFeatures
Comment 26 Martin Robinson 2013-03-06 11:01:59 PST
A feature flag for easier printf support? That seems a bit overkill, but I don't know the whole story.
Comment 27 Hugo Parente Lima 2013-03-06 11:15:02 PST
The original idea was to have only a header in WebKit source used by nobody, so when someone want to debug something he just include this header and enjoy the happiness of an ease print-style-debug :-)
Comment 28 Filip Pizlo 2013-03-06 12:07:55 PST
Comment on attachment 173272 [details]
Patch

Have you seen wtf/DataLog and wtf/PrintStream?  Would that do what you want?

In particular you can make any object printable by just implementing WTF::printInternal(PrintStream&, const YourType&)