Add LLDB command to PrintViewGraph docs
Bug: None Change-Id: Ia919cbafa827280b4fc999085b0cc0281338cc5c Reviewed-on: https://chromium-review.googlesource.com/1150425 Commit-Queue: Leonard Grey <lgrey@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Cr-Commit-Position: refs/heads/master@{#579407}
This commit is contained in:
@ -7,7 +7,11 @@ debugging. It consists of 4 components:
|
||||
|
||||
1. The function `views::PrintViewGraph()` (in the file
|
||||
`ui/views/debug_utils.h`),
|
||||
1. a gdb script file `viewg.gdb` (see below),
|
||||
1. a custom debugger command
|
||||
- For GDB, use `tools/gdb/viewg.gdb`
|
||||
- For LLDB, use `tools/lldb/lldb_viewg.py`
|
||||
- For other debuggers, it should be relatively easy to adapt the
|
||||
above scripts.
|
||||
1. the graphViz package (http://www.graphviz.org/ - downloadable for Linux,
|
||||
Windows and Mac), and
|
||||
1. an SVG viewer (_e.g._ Chrome).
|
||||
@ -17,8 +21,11 @@ debugging. It consists of 4 components:
|
||||
To use the tool,
|
||||
|
||||
1. Make sure you have 'dot' installed (part of graphViz),
|
||||
1. run gdb on your build and
|
||||
1. `source viewg.gdb` (this can be done automatically in `.gdbinit`),
|
||||
1. run gdb/lldb on your build and
|
||||
1. For GDB `source tools/gdb/viewg.gdb` (this can be done automatically
|
||||
in `.gdbinit`),
|
||||
1. For LLDB `command script import tools/lldb/lldb_viewg.py` (this can
|
||||
be done automatically in `.lldbinit`),
|
||||
1. stop at any breakpoint inside class `View` (or any derived class), and
|
||||
1. type `viewg` at the gdb prompt.
|
||||
|
||||
@ -31,32 +38,10 @@ representation of the state of the views hierarchy that is always up to date.
|
||||
It is easy to modify the gdb script to generate PDF in case viewing with evince
|
||||
(or other PDF viewer) is preferred.
|
||||
|
||||
If you don't use gdb, you may be able to adapt the script to work with your
|
||||
favorite debugger. The gdb script invokes
|
||||
If you don't use gdb or lldb, you may be able to adapt the script to work with
|
||||
your favorite debugger. The gdb script invokes
|
||||
|
||||
views::PrintViewGraph(this)
|
||||
|
||||
on the current object, returning `std::string`, whose contents must then be
|
||||
saved to a file in order to be processed by dot.
|
||||
|
||||
## viewg.gdb
|
||||
|
||||
```
|
||||
define viewg
|
||||
if $argc != 0
|
||||
echo Usage: viewg
|
||||
else
|
||||
set pagination off
|
||||
set print elements 0
|
||||
set logging off
|
||||
set logging file ~/state.dot
|
||||
set logging overwrite on
|
||||
set logging redirect on
|
||||
set logging on
|
||||
printf "%s\n", view::PrintViewGraph(this).c_str()
|
||||
set logging off
|
||||
shell dot -Tsvg -o ~/state.svg ~/state.dot
|
||||
set pagination on
|
||||
end
|
||||
end
|
||||
```
|
||||
|
34
tools/gdb/viewg.gdb
Normal file
34
tools/gdb/viewg.gdb
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# Creates a SVG graph of the view hierarchy, when stopped in a
|
||||
# method of an object that inherits from views::View. Requires
|
||||
# graphviz.
|
||||
#
|
||||
# For more info see
|
||||
# chromium/src/+/HEAD/docs/graphical_debugging_aid_chromium_views.md
|
||||
#
|
||||
# To make this command available, add the following to your ~/.lldbinit:
|
||||
# source {Path to SRC Root}/tools/gdbviewg.gdb
|
||||
#
|
||||
# Usage: type `viewg` at the GDB prompt, given the conditions above.
|
||||
|
||||
|
||||
define viewg
|
||||
if $argc != 0
|
||||
echo Usage: viewg
|
||||
else
|
||||
set pagination off
|
||||
set print elements 0
|
||||
set logging off
|
||||
set logging file ~/state.dot
|
||||
set logging overwrite on
|
||||
set logging redirect on
|
||||
set logging on
|
||||
printf "%s\n", view::PrintViewGraph(this).c_str()
|
||||
set logging off
|
||||
shell dot -Tsvg -o ~/state.svg ~/state.dot
|
||||
set pagination on
|
||||
end
|
||||
end
|
47
tools/lldb/lldb_viewg.py
Normal file
47
tools/lldb/lldb_viewg.py
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""
|
||||
Creates a SVG graph of the view hierarchy, when stopped in a
|
||||
method of an object that inherits from views::View. Requires
|
||||
graphviz.
|
||||
|
||||
For more info see
|
||||
chromium/src/+/HEAD/docs/graphical_debugging_aid_chromium_views.md
|
||||
|
||||
To make this command available, add the following to your ~/.lldbinit:
|
||||
command script import {Path to SRC Root}/tools/lldb/lldb_viewg.py
|
||||
|
||||
Usage: type `viewg` at the LLDB prompt, given the conditions above.
|
||||
"""
|
||||
|
||||
import lldb
|
||||
import os
|
||||
|
||||
def view_graph(debugger, command, result, internal_dict):
|
||||
dot = os.path.expanduser("~/state.dot")
|
||||
svg = os.path.splitext(dot)[0] + ".svg"
|
||||
|
||||
process = debugger.GetSelectedTarget().GetProcess()
|
||||
frame = process.GetSelectedThread().GetSelectedFrame()
|
||||
|
||||
cstr_address = frame.EvaluateExpression("views::PrintViewGraph(this).c_str()")
|
||||
if not cstr_address.GetError().Success():
|
||||
return
|
||||
str_size = frame.EvaluateExpression("(size_t)strlen(%s)"
|
||||
% cstr_address.GetValue())
|
||||
if not str_size.GetError().Success():
|
||||
return
|
||||
error = lldb.SBError()
|
||||
dot_str = process.ReadCStringFromMemory(int(cstr_address.GetValue(), 16),
|
||||
str_size.GetValueAsUnsigned(), error)
|
||||
if not error.Success():
|
||||
return
|
||||
|
||||
with open(dot, "w") as f:
|
||||
f.write(dot_str)
|
||||
os.system("dot -Tsvg -o %s %s" % (svg, dot))
|
||||
|
||||
def __lldb_init_module(debugger, internal_dict):
|
||||
debugger.HandleCommand('command script add -f lldb_viewg.view_graph viewg')
|
Reference in New Issue
Block a user