Bug 90768

Summary: [WK2][EFL] Facilitate debugging of the Web Process
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, bdakin, dpranke, d-r, gyuyoung.kim, kenneth, mjs, morrita, naginenis, ojan, rniwa, ryuan.choi, tmpsantos, tonikitoo, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 61838    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2012-07-09 03:08:11 PDT
WebKitTestRunner should provide a way to pause the UIProcess on start to allow attaching to the WebProcess with gdb for debugging purposes.

This could be easily achieved via an environment variable.
Comment 1 Chris Dumez 2012-07-09 03:33:42 PDT
I meant the WebProcess, not UIProcess.
Comment 2 Chris Dumez 2012-07-09 04:11:03 PDT
Created attachment 151230 [details]
Patch
Comment 3 Thiago Marcos P. Santos 2012-07-09 05:30:49 PDT
Honestly I like more the approach of adding a mechanism to ProcessLauncherEfl.cpp to wrap the new process around something. What I'm suggesting is similar to the way how it is done in chromium:

http://code.google.com/p/chromium/wiki/LinuxDebugging
Comment 4 Chris Dumez 2012-07-09 10:40:22 PDT
Comment on attachment 151230 [details]
Patch

Ok, I agree with Thiago, I'll implement the "WebProcessCmdPrefix" approach then.
Comment 5 Chris Dumez 2012-07-09 12:30:26 PDT
Created attachment 151298 [details]
Patch

Here is an updated proposal. It is now possible to debug WebProcess using something like:
./Tools/Scripts/run-webkit-tests -2 --efl --webprocess-cmd-prefix="xterm -title WebProcess -e gdb --args" LayoutTests/batterystatus/add-listener-from-callback.html

2 things to keep in mind:
a) This looks like this may introduce a security issue as it is since anyone can mess with the WebProcess loading
b) Should we allow this only in debug mode?
Comment 6 Chris Dumez 2012-07-10 04:20:20 PDT
Created attachment 151435 [details]
Patch

Enable functionality in debug mode only.
Comment 7 Chris Dumez 2012-07-10 05:02:18 PDT
Created attachment 151439 [details]
Patch

Fix compilation error.
Comment 8 Ojan Vafai 2012-07-10 10:39:12 PDT
Comment on attachment 151439 [details]
Patch

The webkitpy changes look good to me. I'd prefer if someone more familiar with WebKit2 reviewed that part though. I don't know the WebKit2 code at all.
Comment 9 Gyuyoung Kim 2012-07-10 23:39:05 PDT
Comment on attachment 151439 [details]
Patch

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

> Source/WebKit2/UIProcess/Launcher/efl/ProcessLauncherEfl.cpp:79
> +            String cmd = m_launchOptions.processCmdPrefix + " " + fullPath + " " + socket;

I would prefer to use string utility function. For example, makeString().
Comment 10 Chris Dumez 2012-07-10 23:56:11 PDT
Created attachment 151614 [details]
Patch

- Use makeString()
- Remove PLATFORM(EFL) #ifdef
Comment 11 Kenneth Rohde Christiansen 2012-07-12 00:05:29 PDT
Comment on attachment 151614 [details]
Patch

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

> Source/WebKit2/ChangeLog:12
> +        for debugging purposes with prefixes such as:
> +        "xterm -title renderer -e gdb --args".

How is this much better than using gdb --args ... and then set follow-fork-mode child ?

> Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py:261
> +    option_group_definitions.append(("EFL-specific Options", [
> +        optparse.make_option("--webprocess-cmd-prefix", type="string",
> +            default=False, help="Prefix used when spawning the Web process (Debug mode only)"),
> +    ]))
> +

I guess Qt could use this as well? or actually all webkit2 ports
Comment 12 Chris Dumez 2012-07-12 00:26:53 PDT
Comment on attachment 151614 [details]
Patch

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

>> Source/WebKit2/ChangeLog:12
>> +        "xterm -title renderer -e gdb --args".
> 
> How is this much better than using gdb --args ... and then set follow-fork-mode child ?

In the gdb case, you can achieve pretty much the same thing with set follow-fork-mode child, indeed. But our approach is more generic, you can for example run valgrind on the Web process.

>> Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py:261
>> +
> 
> I guess Qt could use this as well? or actually all webkit2 ports

Yes, I do believe this would be useful to other ports as well. However, this require some work in their port-specific ProcessLauncher to support it. As a consequence, this is an EFL-specific Option for now. As soon as we bring support for other ports, we can get rid of the "EFL-specific" mention.
Comment 13 Thiago Marcos P. Santos 2012-07-12 02:02:38 PDT
Valgrind can trace children as well but...

In both cases, I still think this is a valid approach because you have much less debugging overhead by ptrace'ing only the WebProcess.

It is specially important to reduce your tracing scope when you are using tools that does CPU sampling.
Comment 14 Chris Dumez 2012-07-12 12:39:41 PDT
@Kenneth: Is it OK to land as it is then?

@Thiago: Good to know. I had no idea Valgrind could follow children. I knew for sure it could not attach to a running process though.
Comment 15 Kenneth Rohde Christiansen 2012-07-12 20:19:29 PDT
sure, go ahead
Comment 16 Gyuyoung Kim 2012-07-12 22:26:02 PDT
Comment on attachment 151614 [details]
Patch

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

> Source/WebKit2/UIProcess/WebProcessProxy.cpp:114
> +        const char* webProcessCmdPrefix = getenv("WEB_PROCESS_CMD_PREFIX");

Could you add an article to WebKit EFL wiki page how to use this environment ?
Comment 17 WebKit Review Bot 2012-07-12 22:39:46 PDT
Comment on attachment 151614 [details]
Patch

Clearing flags on attachment: 151614

Committed r122542: <http://trac.webkit.org/changeset/122542>
Comment 18 WebKit Review Bot 2012-07-12 22:39:53 PDT
All reviewed patches have been landed.  Closing bug.
Comment 19 Chris Dumez 2012-07-12 22:50:34 PDT
(In reply to comment #16)
> (From update of attachment 151614 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=151614&action=review
> 
> > Source/WebKit2/UIProcess/WebProcessProxy.cpp:114
> > +        const char* webProcessCmdPrefix = getenv("WEB_PROCESS_CMD_PREFIX");
> 
> Could you add an article to WebKit EFL wiki page how to use this environment ?

I updated the wiki page:
http://trac.webkit.org/wiki/WebKitEFLLayoutTest#Debuggingcrashes