cs01 / gdbgui

Browser-based frontend to gdb (gnu debugger). Add breakpoints, view the stack, visualize data structures, and more in C, C++, Go, Rust, and Fortran. Run gdbgui from the terminal and a new tab will open in your browser.
https://gdbgui.com
GNU General Public License v3.0
9.91k stars 499 forks source link

feature/requirements discussion regarding arbitrary plotting #174

Open cs01 opened 6 years ago

cs01 commented 6 years ago
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,

or

or

or

or

FelipeLema commented 6 years ago

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.

cs01 commented 6 years ago

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?

FelipeLema commented 6 years ago

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

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

bbkiwi commented 6 years ago

Hi Chad,

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

thewtex commented 6 years ago

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

cs01 commented 6 years ago

@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 commented 6 years ago

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

bbkiwi commented 6 years ago

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. "

cs01 commented 6 years ago

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

thewtex commented 6 years ago

@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:

cristianjeldes commented 5 years ago

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".

N-Coder commented 2 years ago

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...

ruizhi92 commented 8 months ago

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