Author: sewardj
Date: 2008-02-21 13:19:36 +0000 (Thu, 21 Feb 2008)
New Revision: 7432

Log:
Distinguish properly between types that have unknown size and types
that have known zero size.



Modified:
   branches/DATASYMS/coregrind/m_debuginfo/debuginfo.c
   branches/DATASYMS/coregrind/m_debuginfo/priv_tytypes.h
   branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c
   branches/DATASYMS/coregrind/m_debuginfo/storage.c
   branches/DATASYMS/coregrind/m_debuginfo/tytypes.c


Modified: branches/DATASYMS/coregrind/m_debuginfo/debuginfo.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/debuginfo.c 2008-02-21 03:41:23 UTC 
(rev 7431)
+++ branches/DATASYMS/coregrind/m_debuginfo/debuginfo.c 2008-02-21 13:19:36 UTC 
(rev 7432)
@@ -1597,20 +1597,35 @@
                                      RegSummary*   regs,
                                      Addr          data_addr )
 {
-   SizeT    var_szB;
-   GXResult res;
-   Bool     show = False;
+   MaybeUWord muw;
+   SizeT      var_szB;
+   GXResult   res;
+   Bool       show = False;
    vg_assert(var->name);
    vg_assert(var->type);
    vg_assert(var->gexpr);
-   var_szB = ML_(sizeOfType)(var->type);
 
+   /* Figure out how big the variable is. */
+   muw = ML_(sizeOfType)(var->type);
+   /* if this var has a type whose size is unknown, it should never
+      have been added.  ML_(addVar) should have rejected it. */
+   vg_assert(muw.b == True);
+
+   var_szB = muw.w;
+
    if (show) {
       VG_(printf)("VVVV: find loc: %s :: ", var->name );
       ML_(pp_Type_C_ishly)( var->type );
       VG_(printf)("\n");
    }
 
+   /* ignore zero-sized vars; they can never match anything. */
+   if (var_szB == 0) {
+      if (show)
+         VG_(printf)("VVVV: -> Fail (variable is zero sized)\n");
+      return False;
+   }
+
    res = ML_(evaluate_GX)( var->gexpr, var->fbGX, regs );
 
    if (show) {

Modified: branches/DATASYMS/coregrind/m_debuginfo/priv_tytypes.h
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/priv_tytypes.h      2008-02-21 
03:41:23 UTC (rev 7431)
+++ branches/DATASYMS/coregrind/m_debuginfo/priv_tytypes.h      2008-02-21 
13:19:36 UTC (rev 7432)
@@ -149,10 +149,14 @@
    been converted into pointers) */
 void ML_(pp_Type_C_ishly) ( Type* ty );
 
-/* How big is this type?  (post-resolved only) */
+/* How big is this type?  (post-resolved only)  If . b in the
+   returned struct is False, the size is unknown. */
 /* FIXME: check all pointers before dereferencing */
-SizeT ML_(sizeOfType)( Type* ty );
 
+typedef struct { UWord w; Bool b; } MaybeUWord;
+
+MaybeUWord ML_(sizeOfType)( Type* ty );
+
 /* Describe where in the type 'offset' falls.  Caller must
    deallocate the resulting XArray. */
 XArray* /*UChar*/ ML_(describe_type)( /*OUT*/OffT* residual_offset,

Modified: branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c        2008-02-21 
03:41:23 UTC (rev 7431)
+++ branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c        2008-02-21 
13:19:36 UTC (rev 7432)
@@ -996,6 +996,11 @@
                        any */
       UChar* fName; /* declaring file name, or NULL */
       Int    fLine; /* declaring file line number, or zero */
+      /* offset in .debug_info (for debug printing only).  NB:
+         approximate value ONLY!  NOT TO BE RELIED ON.  Is only stored
+         so as to help readers make sense of the debug printed
+         output. */
+      UWord  dioff; 
    }
    TempVar;
 
@@ -1523,6 +1528,7 @@
             tv->fName = fileName;
             tv->fLine = lineNo;
             tv->next  = *tempvars;
+            tv->dioff = saved_die_c_offset - 2; /* NB! NOT EXACT! */
             *tempvars = tv;
          }
          TRACE_D3("  Recording this variable, with %ld PC range(s)\n",
@@ -2558,9 +2564,9 @@
 
    /* We're set up to look at the fields of this DIE.  Hand it off to
       any parser(s) that want to see it.  Since they will in general
-      advance both the DIE and abbrev cursors, remember where their
-      current settings so that we can then back up and do one final
-      pass over the DIE, to print out its contents. */
+      advance both the DIE and abbrev cursors, remember their current
+      settings so that we can then back up and do one final pass over
+      the DIE, to print out its contents. */
 
    start_die_c_offset  = get_position_of_Cursor( c );
    start_abbv_c_offset = get_position_of_Cursor( &abbv );
@@ -3003,6 +3009,8 @@
          } else {
             VG_(printf)("  FrB=none\n");
          }
+         VG_(printf)("  .debug_info offset = <%lx> "
+                     "(or thereabouts; not exact)\n", varp->dioff);
          VG_(printf)("  declared at: %s:%d\n",
                      varp->fName ? varp->fName : (UChar*)"(null)",
                      varp->fLine );

Modified: branches/DATASYMS/coregrind/m_debuginfo/storage.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/storage.c   2008-02-21 03:41:23 UTC 
(rev 7431)
+++ branches/DATASYMS/coregrind/m_debuginfo/storage.c   2008-02-21 13:19:36 UTC 
(rev 7432)
@@ -377,7 +377,7 @@
    vg_assert(di->have_rx_map && di->have_rw_map);
    if (cfsi->base + cfsi->len - 1 < di->rx_map_avma
        || cfsi->base >= di->rx_map_avma + di->rx_map_size) {
-      static Int complaints = 3;
+      static Int complaints = 10;
       if (VG_(clo_trace_cfi) || complaints > 0) {
          complaints--;
          if (VG_(clo_verbosity) > 1) {
@@ -747,12 +747,14 @@
       it.  We will never be able to actually relate a data address to
       a data object with zero size, so there's no point in storing
       info on it. */
-   if (ML_(sizeOfType)(type) == 0) {
-      if (VG_(clo_verbosity) >= 0) {
+   if (ML_(sizeOfType)(type).b != True) {
+      static Int complaints = 10;
+      if (VG_(clo_verbosity) >= 2 && complaints > 0) {
          VG_(message)(Vg_DebugMsg, 
-            "warning: addVar: zero or unknown size (%s)",
+            "warning: addVar: unknown size (%s)",
             name
          );
+         complaints--;
       }
       return;
    }

Modified: branches/DATASYMS/coregrind/m_debuginfo/tytypes.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/tytypes.c   2008-02-21 03:41:23 UTC 
(rev 7431)
+++ branches/DATASYMS/coregrind/m_debuginfo/tytypes.c   2008-02-21 13:19:36 UTC 
(rev 7432)
@@ -352,40 +352,63 @@
 }
 
 
+static MaybeUWord mk_MaybeUWord_Nothing ( void ) {
+   MaybeUWord muw;
+   muw.w = 0;
+   muw.b = False;
+   return muw;
+}
+static MaybeUWord mk_MaybeUWord_Just ( UWord w ) {
+   MaybeUWord muw;
+   muw.w = w;
+   muw.b = True;
+   return muw;
+}
+static MaybeUWord mul_MaybeUWord ( MaybeUWord muw1, MaybeUWord muw2 ) {
+   if (!muw1.b) { vg_assert(muw1.w == 0); return muw1; }
+   if (!muw2.b) { vg_assert(muw2.w == 0); return muw2; }
+   muw1.w *= muw2.w;
+   return muw1;
+}
+
 /* How big is this type?  (post-resolved only) */
 /* FIXME: check all pointers before dereferencing */
-SizeT ML_(sizeOfType)( Type* ty )
+MaybeUWord ML_(sizeOfType)( Type* ty )
 {
-   SizeT eszB;
-   Word  i;
+   Word       i;
+   MaybeUWord eszB;
    switch (ty->tag) {
       case Ty_Base:
          vg_assert(ty->Ty.Base.szB > 0);
-         return ty->Ty.Base.szB;
+         return mk_MaybeUWord_Just( ty->Ty.Base.szB );
       case Ty_Qual:
          return ML_(sizeOfType)( ty->Ty.Qual.typeR );
       case Ty_TyDef:
          if (!ty->Ty.TyDef.typeR)
-            return 0; /*UNKNOWN*/
+            return mk_MaybeUWord_Nothing(); /*UNKNOWN*/
          return ML_(sizeOfType)( ty->Ty.TyDef.typeR );
       case Ty_PorR:
          vg_assert(ty->Ty.PorR.szB == 4 || ty->Ty.PorR.szB == 8);
-         return ty->Ty.PorR.szB;
+         return mk_MaybeUWord_Just( ty->Ty.PorR.szB );
       case Ty_StOrUn:
-         return ty->Ty.StOrUn.szB;
+         return ty->Ty.StOrUn.complete
+                   ? mk_MaybeUWord_Just( ty->Ty.StOrUn.szB )
+                   : mk_MaybeUWord_Nothing();
       case Ty_Enum:
-         return ty->Ty.Enum.szB;
+         return mk_MaybeUWord_Just( ty->Ty.Enum.szB );
       case Ty_Array:
          if (!ty->Ty.Array.typeR)
-            return 0;
+            return mk_MaybeUWord_Nothing(); /*UNKNOWN*/
          eszB = ML_(sizeOfType)( ty->Ty.Array.typeR );
          for (i = 0; i < VG_(sizeXA)( ty->Ty.Array.bounds ); i++) {
             TyBounds* bo
                = *(TyBounds**)VG_(indexXA)(ty->Ty.Array.bounds, i);
             vg_assert(bo);
             if (!(bo->knownL && bo->knownU))
-               return 0;
-            eszB *= (SizeT)( bo->boundU - bo->boundL + 1 );
+               return mk_MaybeUWord_Nothing(); /*UNKNOWN*/
+            eszB = mul_MaybeUWord( 
+                      eszB,
+                      mk_MaybeUWord_Just( bo->boundU - bo->boundL + 1 ));
          }
          return eszB;
       default:
@@ -423,10 +446,11 @@
             goto done;
 
          case Ty_StOrUn: {
-            Word     i;
-            GXResult res;
-            TyField  *field = NULL, *fields;
-            OffT     offMin = 0, offMax1 = 0;
+            Word       i;
+            GXResult   res;
+            MaybeUWord muw;
+            TyField    *field = NULL, *fields;
+            OffT       offMin = 0, offMax1 = 0;
             if (!ty->Ty.StOrUn.isStruct) goto done;
             fields = ty->Ty.StOrUn.fields;
             if ((!fields) || VG_(sizeXA)(fields) == 0) goto done;
@@ -445,8 +469,11 @@
                }
                if (res.kind != GXR_Value)
                   continue;
-               offMin = res.word;
-               offMax1 = offMin + ML_(sizeOfType)( field->typeR );
+               muw = ML_(sizeOfType)( field->typeR );
+               if (muw.b != True)
+                  goto done; /* size of field is unknown (?!) */
+               offMin  = res.word;
+               offMax1 = offMin + muw.w;
                if (offMin == offMax1)
                   continue;
                vg_assert(offMin < offMax1);
@@ -470,8 +497,9 @@
          }
 
          case Ty_Array: {
-            TyBounds* bounds;
-            UWord size, eszB, ix;
+            MaybeUWord muw;
+            TyBounds*  bounds;
+            UWord      size, eszB, ix;
             /* Just deal with the simple, common C-case: 1-D array,
                zero based, known size. */
             if (!(ty->Ty.Array.typeR && ty->Ty.Array.bounds))
@@ -485,7 +513,10 @@
                goto done;
             size = bounds->boundU - bounds->boundL + 1;
             vg_assert(size >= 1);
-            eszB = ML_(sizeOfType)( ty->Ty.Array.typeR );
+            muw = ML_(sizeOfType)( ty->Ty.Array.typeR );
+            if (muw.b != True)
+               goto done; /* size of element type not known */
+            eszB = muw.w;
             if (eszB == 0) goto done;
             ix = offset / eszB;
             VG_(addBytesToXA)( xa, "[", 1 );


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to