This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
feature idea: type nicknames
- From: Roland McGrath <roland at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Thu, 2 Jul 2009 17:20:49 -0700 (PDT)
- Subject: feature idea: type nicknames
So, a thing I'm looking at all day and all night today looks like this:
21.9 y 0x0000000000437a0e in talker<elfutils::dwarf_edit, elfutils::dwarf_output>::mismatch(std::_Rb_tree_const_iterator<std::pair<int const, elfutils::dwarf_data::attr_value<elfutils::dwarf_edit, elfutils::dwarf_data::value<elfutils::dwarf_edit> > > >, std::_Rb_tree_const_iterator<std::pair<int const, elfutils::dwarf_data::attr_value<elfutils::dwarf_edit, elfutils::dwarf_data::value<elfutils::dwarf_edit> > > > const&, std::_Rb_tree_const_iterator<std::pair<int const, elfutils::dwarf_data::attr_value<elfutils::dwarf_output, elfutils::dwarf_output::value_wrapper> > >, std::_Rb_tree_const_iterator<std::pair<int const, elfutils::dwarf_data::attr_value<elfutils::dwarf_output, elfutils::dwarf_output::value_wrapper> > > const&)
(At the moment, I'm just talking about the long hoary type names.
But, yes, that is location 9 of breakpoint 21. Breakpoint 5 has 15 locations.)
So, to start with, some of that is STL internals hooey that I, poor lowly
programmer, am not responsible for. This here:
std::_Rb_tree_const_iterator<std::pair<int const, elfutils::dwarf_data::attr_value<elfutils::dwarf_edit, elfutils::dwarf_data::value<elfutils::dwarf_edit> > > >
appears in *my* code nowhere in a form longer than:
std::map<int, elfutils::dwarf_data::attr_value<elfutils::dwarf_edit, elfutils::dwarf_data::value<elfutils::dwarf_edit> > >::const_iterator
Now that is not so short, but let's stick with the STL part for the moment:
std::map<a, b>::const_iterator
Now leaving aside how ugly a and b are to print, that is pretty nice.
What makes sense to me is that the STL pretty printer module can also
have "type name pretty-printers". This would let them match
std::_Rb_tree_const_iterator<...> and pick apart the ... to discern
what proper std::some<...>::const_iterator to call it.
Now let's consider the same thing for my own program. Say I don't
even know Python, but I'm all template-happy with my C++ and I really
do think I know what I'm trying to do, but my eyes are bleeding.
(gdb) whatis it
type = elfutils::dwarf::skipping_wrapper<elfutils::dwarf::debug_info_entry::raw_attributes_type, elfutils::dwarf::attribute, elfutils::dwarf::attribute, elfutils::dwarf::skip_sibling>::const_iterator
(gdb) callthat dieptr
dieptr = elfutils::dwarf::skipping_wrapper<elfutils::dwarf::debug_info_entry::raw_attributes_type, elfutils::dwarf::attribute, elfutils::dwarf::attribute, elfutils::dwarf::skip_sibling>::const_iterator
(gdb) p &it
$27 = (dieptr *) 0x1234567
(gdb) thank you, oh thank you
Labor creates all wealth.
(gdb)
For extra points:
(gdb) whatis it
type = const elfutils::dwarf::skipping_wrapper<elfutils::dwarf::debug_info_entry::raw_attributes_type, elfutils::dwarf::attribute, elfutils::dwarf::attribute, elfutils::dwarf::skip_sibling>::const_iterator &
(gdb) callthat const dieptr &
dieptr = elfutils::dwarf::skipping_wrapper<elfutils::dwarf::debug_info_entry::raw_attributes_type, elfutils::dwarf::attribute, elfutils::dwarf::attribute, elfutils::dwarf::skip_sibling>::const_iterator
(gdb) whatis it
type = const dieptr &
(gdb)
I imagine it might actually be called "set print typename dieptr = it"
or something.
This command idea dovetails with what I think library pretty printers
like STL's should implement somehow anyway.
But the "type-only convenience" variables idea could be another
approach for this casual kind of use:
(gdb) set $dieptr = typeof(it)
(gdb) p &it
$227 = ($dieptr *) 0x1234567
(gdb)
However, having only $names by nature might not be the thing people
like the most.
Getting back to the basic "type-name pretty-printing": I think it
would make sense to have some heuristic defaults along with any
library-specific hooks. Like maybe "shortest public name" among
typedefs all resolving to the same thing, etc.
Thanks,
Roland