martinmoene / optional-lite

optional lite - A C++17-like optional, a nullable object for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
403 stars 45 forks source link

gdb pretty printer #32

Closed bas524 closed 6 years ago

bas524 commented 6 years ago

for debugging optional-lite I propose this pretty printer

class NonStdOptionalPrinter(SingleObjContainerPrinter):
    "Print a nonstd::optional"

    def __init__ (self, typename, val):
        alternatives = get_template_arg_list(val.type)
        valtype = self._recognize (val.type.template_argument(0))
        self.typename = strip_versioned_namespace(typename)
        self.typename = re.sub('^nonstd::(optional_lite::|)(optional::|)(.*)', 
                                              r'nonstd::\1\3<%s>' % valtype, 
                                              self.typename, 1)
        self.val = val
        self.contained_type = alternatives[0]
        addr = val['contained']['data']['__data'].address
        contained_value = addr.cast(self.contained_type.pointer()).dereference()
        visualizer = gdb.default_visualizer (contained_value)
        super (NonStdOptionalPrinter, self).__init__ (contained_value, visualizer)

    def to_string (self):
        if self.contained_value is None:
            return "%s [no contained value]" % self.typename
        if self.visualizer:
            return "%s containing %s" % (self.typename,
                                         self.visualizer.to_string())
        return self.typename

And don't forget add printer with this code

libstdcxx_printer.add_version('nonstd::optional_lite::',
                                  'optional', NonStdOptionalPrinter)
martinmoene commented 6 years ago

NTS (notes to self):

bas524 commented 6 years ago

Excuse me, but I don't understand, what did you mean? I wrote this printer guided by the rules from gdb. May be you can add this printer as link to readme.md?

martinmoene commented 6 years ago

NTS: note to self.

Plan:

enriqueiglesias commented 6 years ago

I don't understand, what did you mean? I wrote this printer guided by the rules from gdb. May be you can add this printer as link to readme.md? and for the help regarding the printer you can visit the httpst://printertechsupportnumbers.com/blog/how-to-fix-epson-error-code-0xea/ and get the instant help.

martinmoene commented 6 years ago

@enriqueiglesias How would your remark be of help to me?

bas524 commented 6 years ago

@enriqueiglesias How would your remark be of help to me?

I think this is a bot

martinmoene commented 6 years ago

@bas524 it's being bot (rude) in the Dutch sense anyway ;)