This is the mail archive of the mailing list for the Archer 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]

notes on type printing

Today I spent some time looking at a few type-printing examples that
Benjamin Kosnik sent a while back.

gdb often prints the "wrong" information for a type.  I think this
problem has two parts.  First, debuginfo often does not express all
the information we need.  Second, I think we may need to extend
'whatis' or 'ptype' to give the user more control over verbosity.

Consider a simple case:

    namespace ns {
      template<typename T>
      class k {
        T z;

      typedef k<int> td;

    ns::td zardoz;
    ns::k<int> maude;

'whatis' shows funny results:

    (gdb) whatis zardoz
    type = td
    (gdb) whatis maude
    type = ns::k<int>

Here, I think both types should be qualified with 'ns::'.  In the
'zardoz' case, this boils down to missing debug info.  Most of
Benjamin's tests come down to this -- g++ emitting something other
than what the user wrote.

The need for verbosity control needs a somewhat more complicated
test.  I've appended Benjamin's '' for reference.

Here, if you 'start' and then 'ptype functor_type', you will get the

(gdb) ptype functor_type
type = 
    class functor<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, int> {
    std::basic_string<char, std::char_traits<char>, std::allocator<char> > one;
    std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > two;
    int three;

    void operator()();

Now, this is all correct -- just not what the user, IMO, would expect.
For instance, there is no mention of 'vector_type' here (and none in
the debug info anywhere, to my surprise).

'whatis' also gives somewhat unfriendly results -- fully expanding
std::string and std::vector.

By default, I think, ptype and whatis should give what the source
shows -- typedefs in place, defaulted template arguments omitted, etc.
However, on occasion it is nice to see the full expansion.  So, that
is why I think some kind of verbosity control is needed.

I think it may also be handy to have a mode that omits methods from
the type.  I don't know how important this is.

All of this is contingent on g++ emitting usable info, though.
I filed a bug for this:

I can send out Benjamin's other (two) tests if anybody wants them.


#include <string>
#include <utility>
#include <vector>

// 02, more complex types
template<typename T1, typename T2, typename T3>
struct functor
    std::size_t s1 = one.size();
    std::size_t s2 = two.size();
    std::size_t s3 = three;

  T1 one;
  T2 two;
  T3 three;
int main()
  typedef std::vector<std::string>			vector_type;
  typedef functor<std::string, vector_type, int>	functor_type;

  functor_type f;

  return 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]