Debugging WebKit2
Method #1
- Make sure Use WebKit2 for New Windows option is selected in Safari’s Debug
- Open
WebKit2.xcodeproj
and make sure that the WebProcess is set to the Active Executable - Control-click the
WebProcess
executable and choose Get Info - In the Debugging tab, select Wait for next launch/push notification
- Choose Run ► Debug
- A dialog will appear saying: “Waiting for WebProcess to launch…”
- Open
Safari.xcodeproj
Run ► Debug - The WebProcess will break in the debugger, and you’ll probably have to continue at least once before normal execution resumes
You’re now debugging both the UIProcess
and the WebProcess
. Your breakpoints in either should be work accordingly.
Method #2
- Open the Xcode projects for Safari and WebCore (or WebKit2, or whatever)
- From the Safari project, Run
- From the WebCore project, choose Run ► Attach to Process, and choose the
WebProcess
- Let
gdb
do its thing, and Continue
You’re now debugging the WebProcess
. (Note: I've had issues with gdb
using this method.)
Debugging DumpRenderTree
TODO
Debugging WebKitTestRunner
Some code that executes during initialization can be hard to debug with the default way of attaching to the child process. In this situation, the following steps allowed Xcode to attach fairly early:
- Set a breakpoint in the WebCore/WK2 WebProcess code you are interested in.
- Set a breakpoint in
TestInvocation::invoke
. - Start WebKitTestRunner with the desired arguments.
- Hit the breakpoint inside
invoke()
. - Attach to the spawned web process (at the time of writing, named
com.apple.WebKit.WebContent.Development
. - Continue
Miscellaneous Tips
Prevent Safari from complaining about web process hangs when debugging
- Control-click the Safari executable and choose Get Info
- Select the Arguments tab
- Beneath the list Variables to be set in the environment, click the “
✚
” button - Add the following item:
- Name:
DebugInitialDelayForUnresponsiveWebProcess
- Value:
99999999
- Name:
To debug a web process crash on launch:
- Edit
WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm
- Search for
SIGCONT
- Remove the line of code that sends
SIGCONT
to the web process, then build - In Terminal:
- launch
gdb
, then typeattach WebProcess
— OR - in Xcode select Run ► Attach to Process ► Process ID... and type the WebProcess’s process ID
- launch
- Once attached:
- In
gdb
typecontinue«enter»
— OR - In Xcode select Run ► Continue
- In
To debug a web process using Instruments/DTrace:
If you’re having trouble attaching to the WebProcess, try disabling the sandbox:
defaults write com.apple.WebProcess DisableSandbox YES
Last modified
11 years ago
Last modified on Mar 2, 2014, 6:27:19 PM
Note:
See TracWiki
for help on using the wiki.