gdbgui icon indicating copy to clipboard operation
gdbgui copied to clipboard

feature/requirements discussion regarding arbitrary plotting

Open cs01 opened this issue 6 years ago • 13 comments

Describe the issue

New feature requirements discussion (moved from twitter).

is there a way/tutorial to plot other things (like the 'expresion' tab)? I work with geometry and it'd be neat to view the geometrical representation I'm debugging . I've worked on a gdb.Command that parses polygon points from its gdb.Value repr (let's say it's originally a boost::polygon_data). We take those points, feed them to plotly and write the plot to html file since we have the data as html (probably as an iframe) we might as well render it live in a gdbgui tab (as the 'expression' tab)

There is no way to plot anything else in the expressions tab, so no tutorial exists. But the feature request is not totally clear to me. Could this be distilled further into a requirement for gdbgui to perform? For example,

  • gdbgui should have an input next to each expression to enter an arbitrary URL to display an iframe inline with an expression

or

  • gdbgui should allow for optional streaming data value logging to a file of type (JSON? pickle? some other binary format?)

or

  • gdbgui should provide an input to compute and plot values of gdb variables, for example x * y, where x and y are both gdb variables that could be plotted on their own

or

  • gdbgui should provide a way to define the value used to plot on the x axis, rather than always use data point count on the x axis

or

  • Something else. These examples are not meant to be limiting, just to throw some examples out there. I am interested in what features others might find useful, and more on what you/others have in mind.

cs01 avatar Feb 12 '18 00:02 cs01

Since I was the person to ask, here is more context of what I was asking. I think the fastest way to explain it is with an user case.

Let's say that me, a gdbgui user, wants to add a tab to gdbgui. So, I look in the wiki and there's the following sample code I can extend to my needs. This fiction example code takes an array name, an array size and renders the content of the named array as a html table.

from gdbgui import Tab
import gdb


class ExampleTab(Tab):
    '''This prints an array provided its name and size
    Analog to `(gdb) print *some_array@size`
'''
    tabCounter = 0
    # form fields, picked up and filled auto-magically
    array_name = StringField()
    array_size = UnsignedIntegerField()

    def __init__(self, *args, **kargs):
        self.myTabId = self.__class__.tabCounter
        self.__class__.tabCounter += 1

    def name(self):
        '''This name must be unique among tabs.

        There may be multiple instances of this same tab, so the implementer
        must handle their names'''
        return 'example {0}'.format(self.__class__.tabCounter)

    def _get_array_values(self):
        '''Returns the n=array_size values of array_name as an int list'''
        pointer_to_data = gdb.parse_and_eval(self.array_name)
        return [int(gdb.parse_and_eval('*({array_name)+{i})'.format(
            array_name=str(self.array_name),
            i=i)
            for i in range(0,int(self.array_size))]

    def render(self):
        '''Render the array as a one-column html table'''
        return '<table>{0}</table>'.format(
                '<tr><th>{0}</th></tr>'.join(
                    self._get_array_values()))

Now, I don't know what's the status on this. Maybe some stuff has been already done, but no such API exist.

For me, I would modify it to parse the points of a named boost::polygon_data, give the points to (let's say) plotly and return the generated html in render().

This would be something like the first option @cs01 described, with a little bit of the 4th.

FelipeLema avatar Feb 12 '18 15:02 FelipeLema

I'm afraid I don't have enough users asking for this type of feature to justify it. As a middle ground, I could create a simple button to export data to a file. What do you think?

cs01 avatar Apr 11 '18 00:04 cs01

Sounds ok to me. Feel free of adding decoration to this button.

Leave this issue opened. I'll do the PR to close it.

FelipeLema avatar Apr 11 '18 18:04 FelipeLema

Hi Chad,

Just started to use gdbgui - very nice. Is there an option to plot the values of an array? (as in ddd). Thanks.

bbkiwi avatar Jun 03 '18 05:06 bbkiwi

In addition to plotting, it would we awesome if we could add custom functionality to visualization in-memory image data structures, meshes, etc.

thewtex avatar Aug 28 '18 03:08 thewtex

@bbkiwi you can make an expression for the various elements you want to plot, but you can't choose arbitrary an index and plot it without having watched it

cs01 avatar Aug 28 '18 21:08 cs01

@thewtex could you expand a little more on what you mean? Maybe an example would help me understand more.

cs01 avatar Aug 28 '18 21:08 cs01

Hi, I haven't been using gdbgui lately but at the time I wanted to be able to look at a whole array at once plotting index i vs val[i] like ddd can do. See (https://linuxgazette.net/issue73/mauerer.html) The section starting: Plotting datasets "Data structures are not the only things ddd is capable of drawing: Additional, datasets stored in arrays can be visualised using the well known Gnuplot program as helper. Since the generation of such datasets occurs quite frequently in scientific programs, we will take a look at this convenient feature. "

bbkiwi avatar Aug 28 '18 23:08 bbkiwi

@bbkiwi oh I see, that would be doable in gdbgui, thanks!

cs01 avatar Aug 29 '18 00:08 cs01

@thewtex could you expand a little more on what you mean? Maybe an example would help me understand more.

I develop a library for scientific image analysis and ideally I would like to "pretty print" an image data structure visualizes with this application.

Like @bbkiwi I am also interested in being able to plot custom data structures, etc.

In general, custom GDB pretty printing-like functionality would be fantastic. That is, given a data structure, create your own options for a text representation, or do a visualization in a div. gdbgui is awesome -- this would make it killer. :zap:

thewtex avatar Aug 29 '18 00:08 thewtex

As @FelipeLema explained would be very nice to have a way to implement a widget/htmlcode and be able to add it to gdbgui. I work with a lot of geometry definitions and usually it's needed to debug interactions between shapes. Lately we have been working on visualizers for gdb. It would be useful to add those to gdbgui as a "native visualizer".

cristianjeldes avatar Mar 22 '19 17:03 cristianjeldes

Hey, I work a lot with the Open Graph algorithms and Data structures Framework OGDF and thus also a lot with in-memory representations of graphs. Unfortunately, those are pretty hard to read when you just see the pointers between individual vertex objects (which are usually stored in a custom-made linked list, which makes it even worse). Fortunately, there is a simple method that generates an SVG with a drawing of the graph like here, where that C++ functionality is used in a similar fashion to gdbgui, but from Python / Jupyter Notebooks. It would be super useful to also be able to use this in gdbgui and define customs hooks that can be called for certain gdb.Types to simply get an HTML representation that can be displayed instead / next to the normal display of the object's fields. I basically see a global dict[gdb.Type, Callable[[Any], str]] that can be filled by some plugins that can be loaded at runtime. Whenever a type is visualized that has a mapping in that dict, we call the stored value to obtain an HTML representation and simply copy that into the website. Basically, that's very similar to what custom gdb pretty printers do for plain text. An advanced version of of this could also implement two-way communication similar to what Jupyter Widgets do, also allowing you to visually edit the in-memory values. This might also include generating more complex (historical) plots of variables' values, but that would then be up to whoever writes the respective to-HTML plugin.

If this sounds good to you but isn't on the roadmap yet, I'd be happy to try and come up with an proof-of-concept PR for the simple, non-interactive version of this.

Side note: this would probably also allow fixing the issue with nested (stl) containers mentioned in #155, but might need some deeper digging in how those trees are generated...

N-Coder avatar Dec 22 '21 10:12 N-Coder

Hi, any chance to support the nested STL containers visualization feature?

ruizhi92 avatar Feb 22 '24 08:02 ruizhi92