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`), |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 10 | 1. a gdb script file `viewg.gdb` (see below), |
| 11 | 1. the graphViz package (http://www.graphviz.org/ - downloadable for Linux, |
| 12 | Windows and Mac), and |
| 13 | 1. an SVG viewer (_e.g._ Chrome). |
| 14 | |
| 15 | ## Details |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 16 | |
| 17 | To use the tool, |
| 18 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 19 | 1. Make sure you have 'dot' installed (part of graphViz), |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 20 | 1. run gdb on your build and |
| 21 | 1. `source viewg.gdb` (this can be done automatically in `.gdbinit`), |
| 22 | 1. stop at any breakpoint inside class `View` (or any derived class), and |
| 23 | 1. type `viewg` at the gdb prompt. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 24 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 25 | This will cause the current view, and any descendants, to be described in a |
| 26 | graph which is stored as `~/state.svg` (Windows users may need to modify the |
| 27 | script slightly to run under CygWin). If `state.svg` is kept open in a browser |
| 28 | window and refreshed each time `viewg` is run, then it provides a graphical |
| 29 | representation of the state of the views hierarchy that is always up to date. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 30 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 31 | It is easy to modify the gdb script to generate PDF in case viewing with evince |
| 32 | (or other PDF viewer) is preferred. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 33 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 34 | If you don't use gdb, you may be able to adapt the script to work with your |
| 35 | favorite debugger. The gdb script invokes |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 36 | |
Scott Violet | 83d7536 | 2018-05-22 20:25:52 | [diff] [blame] | 37 | views::PrintViewGraph(this) |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 38 | |
| 39 | on the current object, returning `std::string`, whose contents must then be |
| 40 | saved to a file in order to be processed by dot. |
| 41 | |
| 42 | ## viewg.gdb |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 43 | |
| 44 | ``` |
| 45 | define viewg |
| 46 | if $argc != 0 |
| 47 | echo Usage: viewg |
| 48 | else |
| 49 | set pagination off |
| 50 | set print elements 0 |
| 51 | set logging off |
| 52 | set logging file ~/state.dot |
| 53 | set logging overwrite on |
| 54 | set logging redirect on |
| 55 | set logging on |
Scott Violet | 83d7536 | 2018-05-22 20:25:52 | [diff] [blame] | 56 | printf "%s\n", view::PrintViewGraph(this).c_str() |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 57 | set logging off |
| 58 | shell dot -Tsvg -o ~/state.svg ~/state.dot |
| 59 | set pagination on |
| 60 | end |
| 61 | end |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 62 | ``` |