⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changes between Version 3 and Version 4 of Debugging With LLDB or GDB


Ignore:
Timestamp:
Jun 5, 2026, 4:03:05 PM (34 hours ago)
Author:
darbinyan@apple.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Debugging With LLDB or GDB

    v3 v4  
    1 = Debugging WebKit =
    2 
    3 Use the script `Tools/Scripts/debug-safari`
    4 
    5 = Debugging WebKit2 =
    6 
    7 = Debugging DumpRenderTree =
    8 
    9  1. `build-webkit --debug`
    10  1. `build-dumprendertree --debug`
    11  1. `export DYLD_FRAMEWORK_PATH=/path/to/WebKit/WebKitBuild/Debug`
    12  1. `gdb --args WebKitBuild/Debug/DumpRenderTree /path/to/testfile.html`
    13 
    14 For LLDB, instead invoke using:
    15 
    16 `lldb -f WebKitBuild/Debug/DumpRenderTree -- /path/to/testfile.html`
    17 
    18 = Debugging WebKitTestRunner =
    19 
    20 1. Tools/Scripts/set-webkit-configuration --debug
    21 1. Tools/Scripts/debug-test-runner
    22 1. Inside GDB/LLDB, set breakpoints, then `run /path/to/layout/test.html`.
    23 
    24 = Debugging API Tests =
    25 
    26 To debug a single API test without the wrapper script (here, `AcceptsFirstMouse.WebKit2`):
    27 
    28 `DYLD_FRAMEWORK_PATH=WebKitBuild/Debug lldb -f WebKitBuild/Debug/TestWebKitAPI -- --gtest_filter=AcceptsFirstMouse.WebKit2`
    29 
    30 = Miscellaneous Tips =
    31 
    32 == Shell Aliases ==
    33 
    34 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`
    35 {{{
    36 alias wkd-drt='(echo r; cat) | DYLD_FRAMEWORK_PATH=WebKitBuild/Debug gdb --args WebKitBuild/Debug/DumpRenderTree'
     1{{{#!html
     2<meta http-equiv="refresh" content="0; url=https://docs.webkit.org/Build%20%26%20Debug/DebuggingOnTheCommandLine.html">
     3<p>This page has moved. If you are not redirected,
     4   <a href="https://docs.webkit.org/Build%20%26%20Debug/DebuggingOnTheCommandLine.html">click here</a>.</p>
    375}}}
    38 
    39 == WebKit-specific Scripts ==
    40 
    41 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`.
    42 
    43 == Pretty Printing ==
    44 
    45 With the script in place, we can pretty-print WTF string classes.  So, for example, I can now break in GDB and see:
    46 
    47 {{{
    48 (gdb) p run
    49 $1 = (const WebCore::TextRun &) @0x7fffffffa450: {m_characters = "Plugin Testsa", m_len = 12, m_xpos = 0,
    50   m_padding = 0, m_allowTabs = false, m_rtl = false, m_directionalOverride = false,
    51   m_applyRunRounding = true, m_applyWordRounding = true, m_disableSpacing = false}
    52 }}}
    53 
    54 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.)
    55 
    56 To undo this pretty-printing, pass the `/r` switch to `p`, like so:
    57 
    58 {{{
    59 (gdb) p/r run.m_characters
    60 $2 = (const UChar *) 0x3355130
    61 (gdb) x/12hc run.m_characters
    62 0x3355130:      80 'P'  108 'l' 117 'u' 103 'g' 105 'i' 110 'n' 32 ' '  84 'T'
    63 0x3355140:      101 'e' 115 's' 116 't' 115 's'
    64 }}}
    65 
    66 === Helper Functions ===
    67 
    68 That script also adds a GDB command useful for printing WebKit Node trees.
    69   `printpathtoroot variable_name`
    70 will print the tree of nodes above a `WebCore::Node.`
    71 
    72 
    73 === Troubleshooting: GDB crashes on Linux ===
    74 
    75 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:
    76 
    77 {{{
    78 ulimit -s 65535
    79 }}}