andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 1 | # Graphical Debugging Aid for Chromium Views |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 3 | ## Introduction |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 4 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 5 | A simple debugging tool exists to help visualize the views tree during |
| 6 | debugging. It consists of 4 components: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 7 | |
Scott Violet | 83d7536 | 2018-05-22 20:25:52 | [diff] [blame] | 8 | 1. The function `views::PrintViewGraph()` (in the file |
| 9 | `ui/views/debug_utils.h`), |
Leonard Grey | 99ade23 | 2018-07-31 14:58:25 | [diff] [blame] | 10 | 1. a custom debugger command |
Tom Anderson | f06ac38 | 2019-04-10 03:49:38 | [diff] [blame] | 11 | - For GDB, see |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 12 | [gdbinit](https://chromium.googlesource.com/chromium/src/+/main/docs/gdbinit.md), |
Leonard Grey | 99ade23 | 2018-07-31 14:58:25 | [diff] [blame] | 13 | - For LLDB, use `tools/lldb/lldb_viewg.py` |
| 14 | - For other debuggers, it should be relatively easy to adapt the |
| 15 | above scripts. |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 16 | 1. the graphViz package (http://www.graphviz.org/ - downloadable for Linux, |
| 17 | Windows and Mac), and |
| 18 | 1. an SVG viewer (_e.g._ Chrome). |
| 19 | |
| 20 | ## Details |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 21 | |
| 22 | To use the tool, |
| 23 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 24 | 1. Make sure you have 'dot' installed (part of graphViz), |
Leonard Grey | 99ade23 | 2018-07-31 14:58:25 | [diff] [blame] | 25 | 1. run gdb/lldb on your build and |
Tom Anderson | f06ac38 | 2019-04-10 03:49:38 | [diff] [blame] | 26 | 1. For GDB see |
John Palmer | 046f987 | 2021-05-24 01:24:56 | [diff] [blame] | 27 | [gdbinit](https://chromium.googlesource.com/chromium/src/+/main/docs/gdbinit.md), |
Leonard Grey | 99ade23 | 2018-07-31 14:58:25 | [diff] [blame] | 28 | 1. For LLDB `command script import tools/lldb/lldb_viewg.py` (this can |
| 29 | be done automatically in `.lldbinit`), |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 30 | 1. stop at any breakpoint inside class `View` (or any derived class), and |
| 31 | 1. type `viewg` at the gdb prompt. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 32 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 33 | This will cause the current view, and any descendants, to be described in a |
| 34 | graph which is stored as `~/state.svg` (Windows users may need to modify the |
| 35 | script slightly to run under CygWin). If `state.svg` is kept open in a browser |
| 36 | window and refreshed each time `viewg` is run, then it provides a graphical |
| 37 | representation of the state of the views hierarchy that is always up to date. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 38 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 39 | It is easy to modify the gdb script to generate PDF in case viewing with evince |
| 40 | (or other PDF viewer) is preferred. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 41 | |
Leonard Grey | 99ade23 | 2018-07-31 14:58:25 | [diff] [blame] | 42 | If you don't use gdb or lldb, you may be able to adapt the script to work with |
| 43 | your favorite debugger. The gdb script invokes |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 44 | |
Scott Violet | 83d7536 | 2018-05-22 20:25:52 | [diff] [blame] | 45 | views::PrintViewGraph(this) |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 46 | |
| 47 | on the current object, returning `std::string`, whose contents must then be |
| 48 | saved to a file in order to be processed by dot. |