Erik Chen | 5c80c7a | 2019-08-29 22:48:15 | [diff] [blame] | 1 | # Usage of tools/lldb/lldbinit.py |
| 2 | |
| 3 | Usage of Chromium's [lldbinit.py](../tools/lldb/lldbinit.py) is recommended when |
| 4 | debugging with lldb. This is necessary for source-level debugging when |
Erik Chen | 87a677d | 2019-08-29 22:57:22 | [diff] [blame] | 5 | `strip_absolute_paths_from_debug_symbols` is enabled [this is the default]. |
Erik Chen | 5c80c7a | 2019-08-29 22:48:15 | [diff] [blame] | 6 | |
Brett Wilson | 41a7de0 | 2023-04-27 18:56:54 | [diff] [blame] | 7 | If you have not installed LLDB yet, run `sudo apt-get install lldb` to get it. |
Shuran Huang | cb6580fe | 2022-04-21 18:38:20 | [diff] [blame] | 8 | |
Erik Chen | 5c80c7a | 2019-08-29 22:48:15 | [diff] [blame] | 9 | To use, add the following to your `~/.lldbinit` |
| 10 | |
| 11 | ``` |
| 12 | # So that lldbinit.py takes precedence. |
Benjamin Beaudry | bce5e78 | 2022-04-21 01:06:11 | [diff] [blame] | 13 | script sys.path[:0] = ['/<your-path>/chromium/src/tools/lldb'] |
Erik Chen | 5c80c7a | 2019-08-29 22:48:15 | [diff] [blame] | 14 | script import lldbinit |
| 15 | ``` |
Alex Rudenko | b27eaeb | 2020-04-17 07:58:34 | [diff] [blame] | 16 | |
Shuran Huang | cb6580fe | 2022-04-21 18:38:20 | [diff] [blame] | 17 | Make sure the build configurations include `is_debug=true`, this will set `symbol_level=2` by default, which is required if need to view the content of frame-level local variables. |
| 18 | |
Eric Leese | 8a06ac5 | 2025-03-12 18:02:15 | [diff] [blame] | 19 | If you want visualizer support for common pointer, string, and vector types in the Chromium codebase, you can also add the following: |
| 20 | |
| 21 | ``` |
| 22 | script import chromium_visualizers |
| 23 | ``` |
| 24 | |
Alex Rudenko | b27eaeb | 2020-04-17 07:58:34 | [diff] [blame] | 25 | ## How to attach to a process with lldb and start debugging |
| 26 | |
| 27 | - Follow the instructions above to create your `~/.lldbinit` file, don't forget to put the correct path to Chromium source in there. |
| 28 | - Inside of your Chromium checkout, run `lldb out/Default/chrome` (or `out/Debug/chrome`) |
| 29 | - On Mac, most likely, `lldb out/Default/Chromium.app/Contents/MacOS/Chromium` |
| 30 | - Keep lldb running and start Chromium separately with `--no-sandbox` flag: |
| 31 | - On Linux, `out/Default/chrome --no-sandbox` |
| 32 | - On Mac, `out/Default/Chromium.app/Contents/MacOS/Chromium --no-sandbox` |
| 33 | - Note: if you start the process from lldb using `process launch -- --no-sandbox`, you will attach to the main browser process and will not be able to debug tab processes. |
| 34 | - In Chromium, go to Customize and Control Chromium (three dots) -> More Tools -> Task Manager |
| 35 | - Depending on what tab or process you want to debug, note the process ID. |
| 36 | - In the lldb shell: |
| 37 | - Execute `process attach -p PID`. PID is the process ID of the tab (process) you want to debug. |
| 38 | - Note: it might take a while. Once lldb attaches to the process, you will see a message `Process PID stopped` and some stack traces. |
Shuran Huang | cb6580fe | 2022-04-21 18:38:20 | [diff] [blame] | 39 | - If you an error message such as `attach failed: Operation not permitted`, it is probably due to [ptrace Protection](https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection). You can disable this feature using `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`. |
Alex Rudenko | b27eaeb | 2020-04-17 07:58:34 | [diff] [blame] | 40 | - Now you can set breakpoints, for example, `breakpoint set -f inspector_overlay_agent.cc -l 627`. |
| 41 | - Execute `cont` to continue the execution of the process. |
| 42 | - Perform the actions which would trigger the breakpoint. lldb will stop the execution for you to inspect. |
| 43 | - You can pause the execution at any time by pressing Ctrl + C. |
| 44 | - Type `help` to learn more about different lldb commands. |
Shuran Huang | cb6580fe | 2022-04-21 18:38:20 | [diff] [blame] | 45 | - More open-source documentation could be found [here](https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-basics.html#//apple_ref/doc/uid/TP40012917-CH2-SW1). |