wiki:Debugging With LLDB or GDB

Debugging WebKit

Use the script Tools/Scripts/debug-safari

Debugging WebKit2

Debugging DumpRenderTree

  1. build-webkit --debug
  2. build-dumprendertree --debug
  3. export DYLD_FRAMEWORK_PATH=/path/to/WebKit/WebKitBuild/Debug
  4. gdb --args WebKitBuild/Debug/DumpRenderTree /path/to/testfile.html

For LLDB, instead invoke using:

lldb -f WebKitBuild/Debug/DumpRenderTree -- /path/to/testfile.html

Debugging WebKitTestRunner

  1. Tools/Scripts/set-webkit-configuration --debug
  2. Tools/Scripts/debug-test-runner
  3. Inside GDB/LLDB, set breakpoints, then run /path/to/layout/test.html.

Debugging API Tests

To debug a single API test without the wrapper script (here, AcceptsFirstMouse.WebKit2):

DYLD_FRAMEWORK_PATH=WebKitBuild/Debug lldb -f WebKitBuild/Debug/TestWebKitAPI -- --gtest_filter=AcceptsFirstMouse.WebKit2

Miscellaneous Tips

Shell Aliases

The following will automate launching and running DRT under GDB with a specific test argument. You can use it like so: wkd-drt path/to/test

alias wkd-drt='(echo r; cat) | DYLD_FRAMEWORK_PATH=WebKitBuild/Debug gdb --args WebKitBuild/Debug/DumpRenderTree'

WebKit-specific Scripts

GDB 7 introduced Python scripting of GDB. Tools/gdb/webkit.py extends GDB with WebKit-specific knowledge. See the top of the file for info on how to add this to your GDB. The LLDB equivalent is located at Tools/lldb/lldb_webkit.py.

Pretty Printing

With the script in place, we can pretty-print WTF string classes. So, for example, I can now break in GDB and see:

(gdb) p run
$1 = (const WebCore::TextRun &) @0x7fffffffa450: {m_characters = "Plugin Testsa", m_len = 12, m_xpos = 0, 
  m_padding = 0, m_allowTabs = false, m_rtl = false, m_directionalOverride = false, 
  m_applyRunRounding = true, m_applyWordRounding = true, m_disableSpacing = false}

Where m_characters is a UChar*. (Note that because it's a raw pointer, we have to guess at the length of the string -- the m_len parameter there is the length this code probably ends up using. When pretty-printing a string object we get the length correct.)

To undo this pretty-printing, pass the /r switch to p, like so:

(gdb) p/r run.m_characters
$2 = (const UChar *) 0x3355130
(gdb) x/12hc run.m_characters
0x3355130:	80 'P'	108 'l'	117 'u'	103 'g'	105 'i'	110 'n'	32 ' '	84 'T'
0x3355140:	101 'e'	115 's'	116 't'	115 's'

Helper Functions

That script also adds a GDB command useful for printing WebKit Node trees.

printpathtoroot variable_name

will print the tree of nodes above a WebCore::Node.

Troubleshooting: GDB crashes on Linux

Ubuntu Karmic has a bug which causes gdb to crash on Linux when WebKit is compiled in debug mode. You can solve the crash by increasing stack size:

ulimit -s 65535
Last modified 3 years ago Last modified on Mar 29, 2014 12:15:31 PM