Skip to content

Instantly share code, notes, and snippets.

@ChunMinChang
Last active February 4, 2025 00:12
Show Gist options
  • Save ChunMinChang/464d8e338fb6c55f081286ea0aa503f6 to your computer and use it in GitHub Desktop.
Save ChunMinChang/464d8e338fb6c55f081286ea0aa503f6 to your computer and use it in GitHub Desktop.
Debugging gecko with gdb or lldb

Debugging gecko with gdb

Setup gecko-dev/.gdbinit

Suppose the gecko folder is /home/cm/Work/gecko-dev

Add the following lins to your /home/cm/Work/gecko-dev/.gdbinit

add-auto-load-safe-path /home/cm/Work/gecko-dev/build/.gdbinit
add-auto-load-safe-path /home/cm/Work/gecko-dev/toolkit/library/libxul.so-gdb.py

The above settings will ignore the SIGSYS comming constantly. See more here

Setup $HOME/.gdbinit

Add the following lins to your $HOME/.gdbinit

set auto-load local-gdbinit on

add-auto-load-safe-path /home/cm/Work/gecko-dev/.gdbinit

Write your gdb scripts if you need

If you need to do something constantly (e.g., add breakpoints), it's best to make it as a script so it could be performed automatically

For example, you can create a gecko-dev/gdb.script with the following commands:

show auto-load

break dom/media/ChannelMediaResource.cpp:519
break dom/media/MediaCache.cpp:2696

info break

Debugging with GDB

Now, everytime when gdb is run, /home/cm/Work/gecko-dev/.gdbinit would be loaded, and then /home/cm/Work/Work/gecko-dev/build/.gdbinit and its friends would be loaded.

If you have a gdb script named gdb.script and you want to attach to process 8529, you can do

gdb --pid=8529 --command=gdb.script

Debugging gecko with lldb

It's easier to debug gecko with lldb since you don't need to add settings to ignore the SIGSYS signals.

Write your gdb scripts if you need

Similar to what we did for gdb, if you need to do something constantly (e.g., add breakpoints), it's best to make it as a script so it could be performed automatically

you can create a gecko-dev/lldb.script with the following commands:

b AppleDecoderModule::CreateVideoDecoder
b dom/media/platforms/wrappers/MediaChangeMonitor.cpp:204
b dom/media/platforms/agnostic/bytestreams/H265.cpp:99
b HVCCConfig::Parse
b HEVCChangeMonitor::CheckForChange

breakpoint list

Debugging with LLDB

If you want to attach to a process 1234 and load the scripts automatically, you can do

lldb attach -p 1234 --one-line "command source lldb.script"

If you'd like to load the script within lldb, command source is the command you need:

(lldb) command source lldb.script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment