This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi, Could you please take look at the attached pretty printer. (also attached: test.cpp debugee example code and used .gdbinit) executed MI commands: -enable-pretty-printing -file-exec-and-symbols /home/niko/kdesvn/build/kdevelop/gdb-pretty-print-issue/test -break-insert -f /home/niko/kdesvn/kdevelop/gdb-pretty-print-issue/test.cpp:30 -exec-run -var-create --thread 1 --frame 0 var3 @ "any" ^done,name="var3",numchild="0",value="{\n static npos = 18446744073709551615, \n _M_dataplus = {\n <std::allocator<char>> = {\n <__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, \n members of std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider: \n _M_p = 0x619028 \"test\"\n }\n}",type="Communication::Detail::Any",thread-id="1",dynamic="1",has_more="0" print any does work correctly: &"print any\n" ~"$1 = \"test\"\n" ^done thanks, Niko
#include <boost/variant.hpp> #include <list> #include <string> namespace Communication { namespace Detail { class Any { public: Any& operator = (const std::string& value) { m_any = value; } boost::variant<int, char, double, std::list< int >, bool, std::string> m_any; }; } } int main() { Communication::Detail::Any any; //hovering the mouse here wouldn't produce a beautiful string on KDevelop any = "test"; exit(0); }
# -*- coding: utf-8 -*- import gdb import itertools import re class AnyPrinter: "Print a Any" def __init__(self, val): self.val = val def to_string(self): encoding = gdb.parameter('target-wide-charset') wich = '%d' % self.val['m_any']['which_'] if wich == '0': return self.val['m_any']['storage_']['data_'].cast(gdb.lookup_type('int')) elif wich == '1': return self.val['m_any']['storage_']['data_'].cast(gdb.lookup_type('char')) elif wich == '2': return self.val['m_any']['storage_']['data_'].cast(gdb.lookup_type('double')) elif wich == '3': return self.val['m_any']['storage_']['data_'].cast(\ gdb.lookup_type('std::list<Communication::Detail::GenericBean, std::allocator<Communication::Detail::GenericBean> >')) elif wich == '4': return self.val['m_any']['storage_']['data_'].cast(gdb.lookup_type('bool')) elif wich == '5': return self.val['m_any']['storage_']['data_'].cast(\ gdb.lookup_type('std::string')) return "Any" def lookup_function (val): "Look-up and return a pretty-printer that can print val." # Get the type. type = val.type # If it points to a reference, get the reference. if type.code == gdb.TYPE_CODE_REF: type = type.target () # Get the unqualified type, stripped of typedefs. type = type.unqualified ().strip_typedefs () # Get the type name. typename = type.tag if typename == None: return None # Iterate over local dictionary of types to determine # if a printer is registered for that type. Return an # instantiation of the printer if found. for function in pretty_printers_dict: if function.search (typename): return pretty_printers_dict[function] (val) # Cannot find a pretty printer. Return None. return None def register_cgb_printers (obj): if obj == None: obj = gdb obj.pretty_printers.append (lookup_function) def build_cgb_dictionary (): pretty_printers_dict[re.compile('^Communication::Detail::Any$')] = lambda val: AnyPrinter(val) pass pretty_printers_dict = {} build_cgb_dictionary ()
Attachment:
.gdbinit
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |