├── plot.png ├── example ├── CMakeLists.txt └── main.cpp ├── .gitignore ├── LICENSE ├── README.md └── src └── vplot.py /plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egladysh/vplot/HEAD/plot.png -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project(vplot_example) 4 | 5 | file(GLOB src *.cpp *.cc *.h) 6 | 7 | set( CMAKE_CXX_FLAGS "-std=c++1y -stdlib=libc++ -g" ) 8 | 9 | add_executable(vplot_example ${src} ) 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | std::cout << "Hi" << std::endl; 8 | 9 | std::vector test_vect; 10 | for (int i = 0; i < 1000; ++i) { 11 | test_vect.push_back(std::cos(static_cast(i)/100.)); 12 | } 13 | 14 | std::vector test_vect1; 15 | for (int i = 0; i < 1000; ++i) { 16 | test_vect1.push_back(0.5*std::cos(static_cast(i)/10.)); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 eg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vplot 2 | 3 | vplot is a python extension for lldb for visualization of C++ containers as [plotly](https://plot.ly/python/) graphs from the debugger. 4 | ![vector graph](/plot.png?raw=true) 5 | 6 | 7 | ## Installation 8 | 9 | The following text assumes that you cloned vplot to ~/vplot. 10 | 11 | ### Install plotly and other dependencies. I use pip. 12 | 13 | ```sh 14 | $ pip install plotly 15 | $ pip install numpy 16 | $ pip install pandas 17 | ``` 18 | 19 | ### Install vplot extension for lldb 20 | 21 | To do that you can enter the following in lldb everytime you start it. 22 | 23 | ``` 24 | (lldb) command script import ~/vplot/src/vplot.py 25 | ``` 26 | 27 | or you can add the line to ~/.lldbinit 28 | 29 | ## vplot commands from lldb 30 | 31 | * Show std::vector variable ```test_vector``` from lldb at a breakpoint. 32 | ``` 33 | (lldb) fr v --summary vplot test_vector 34 | ``` 35 | 36 | * Set the graph color. 37 | ``` 38 | (lldb) vplot color (red|blue|black|green|rgb(r,g,b)) 39 | ``` 40 | 41 | * Clear the graph. 42 | ``` 43 | (lldb) vplot clear 44 | ``` 45 | 46 | ## Example 47 | 48 | To generate the image at the beginning, you can use example. To build it: 49 | 50 | ``` sh 51 | $ cd ~/ 52 | $ mkdir build 53 | $ cd build 54 | $ cmake ../vplot/example 55 | $ make 56 | ``` 57 | 58 | Start debugging: 59 | 60 | ``` sh 61 | $ lldb vplot_example 62 | ``` 63 | 64 | In the debugger: 65 | 66 | ``` 67 | (lldb) br s -f main.cpp -l 14 68 | (lldb) br s -f main.cpp -l 19 69 | (lldb) run 70 | (lldb) fr v --summary vplot test_vect 71 | ``` 72 | You should see the first graph. 73 | 74 | ``` 75 | (lldb) vplot color red 76 | (lldb) cont 77 | (lldb) fr v --summary vplot test_vect1 78 | ``` 79 | The second graph should be in red. 80 | 81 | ## Notes 82 | Only std::vector is supported at this time 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/vplot.py: -------------------------------------------------------------------------------- 1 | import plotly 2 | import plotly.graph_objs as go 3 | import plotly.figure_factory as FF 4 | import numpy as np 5 | import pandas as pd 6 | from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 7 | 8 | import lldb 9 | 10 | color = 'rgb(0,0,0)' 11 | traces=[] 12 | 13 | def vplot_color(command): 14 | global color 15 | switcher = { 16 | "red" : "rgb(230,0,0)", 17 | "black" : "rgb(0,0,0)", 18 | "blue" : "rgb(0,0,230)", 19 | "green" : "rgb(0,230,0)" 20 | } 21 | color = switcher.get(command, command) 22 | print color 23 | 24 | def vplot_clear(): 25 | global traces 26 | traces=[] 27 | 28 | def vplot(debugger, command, result, internal_dict): 29 | t = command.split(' ') 30 | if t[0] == "clear": 31 | vplot_clear() 32 | if t[0] == "color": 33 | vplot_color(t[1]) 34 | 35 | def stdvector_Summary(valobj, dict): 36 | global color 37 | global traces 38 | 39 | vec = np.zeros(shape=(valobj.GetNumChildren(), 2)) 40 | for i in range(valobj.GetNumChildren()): 41 | vec[i] = [i, valobj.GetChildAtIndex(i).GetValue()] 42 | 43 | df = pd.DataFrame(data=vec, columns=['x', 'y'], dtype='float') 44 | 45 | trace1 = go.Scatter( 46 | x=df['x'], y=df['y'], 47 | mode="lines", 48 | line={"color":color} 49 | ) 50 | 51 | traces.append(trace1) 52 | 53 | 54 | layout = go.Layout(title=valobj.GetName() + " (size=" + str(valobj.GetNumChildren()) + ") " + valobj.GetDisplayTypeName()) 55 | 56 | fig = go.Figure(data=traces, layout=layout) 57 | plot(fig) 58 | 59 | return 'size=' + str(valobj.GetNumChildren()) 60 | 61 | 62 | def __lldb_init_module(debugger, dict): 63 | debugger.HandleCommand( 64 | 'type summary add -F ' + __name__ + '.stdvector_Summary -e -x "^(std::__1::)vector<.+>$" -w libcxxx --name vplot') 65 | debugger.HandleCommand('command script add -f ' + __name__ + '.vplot vplot') 66 | 67 | --------------------------------------------------------------------------------