[Dwarf-discuss] C++ standard integral types and overload resolution

James Cownie jcownie
Mon Apr 18 07:56:31 GMT 2005


Folks,

I'd like to propose a DWARF enhancement to overcome what I believe is a
problem with the current standard.

The Problem
-----------
Consider C++ integer types, on a machine in which sizeof(int) ==
sizeof(long) (say a normal 32 bit machine). (The same problem also
occurs on most 64 bit machines where sizeof (long) == sizeof (long
long)). 

If the debugger is to support calling overloaded C++ functions it must
be able to distinguish calls to these functions :-

   void foo (int);
and 
   void foo (long);

However when types are passed through DWARF to the debugger the only
difference between the fundamental types is their name, since the bit
representation in store of int and long is identical, e.g.

 <1><46e>: Abbrev Number: 4 (DW_TAG_base_type)
     DW_AT_name        : int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)

and 

 <1><455>: Abbrev Number: 2 (DW_TAG_base_type)
     DW_AT_name        : long int	
     DW_AT_byte_size   : 4
     DW_AT_encoding    : 5	(signed)


The problem here is not with the functions (from outside DWARF we can
get the fuction's signature from its mangled name), but with variable
declarations where all we have is the type given in the DWARF.

The problem is that 

  1) The debugger has to rely on the name of the type generated by the
     compiler, which is unpleasant, especially for types like
     "unsigned long long int", for which I think there are twelve
     possible valid names.

  2) If the compiler elides typedefs, so that for
       typedef long foo;
     it emits a base type with the name foo there is no way in which the
     debugger can determine whether foo is really an int or a long
     (because there is no name to use).

Suggested Solution
------------------

We add another attribute which can be used on DW_TAG_base_type DIE which
allows the compiler explicitly to specify the C++ language type being
represented.

Something like

  DW_AT_cplus_true_type  <constant>

where <constant> has one of the values

  DW_true_type_short,
  DW_true_type_int,
  DW_true_type_long,
  DW_true_type_long_long,

  DW_true_type_float,
  DW_true_type_double,
  DW_true_type_long_double,
  DW_true_type_long_long_double

This would also allow for some space saving, since if the compiler emits
the DW_AT_cplus_true_type it need not emit the name string (as the
debugger can construct it from the true type).

The same issue may apply to other languages which permit overloaded
functions ?

(Note that in DWARF-1 there were explicit enumerations for C types, but
those no longer appear in DWARF 3 anywhere).

-- 
-- Jim
--
James Cownie	<jcownie at etnus.com>
Etnus, LLC.     +44 117 9071438
http://www.etnus.com

  




More information about the Dwarf-discuss mailing list