|
From: <sv...@va...> - 2006-02-10 03:33:19
|
Author: rjwalsh
Date: 2006-02-10 03:33:10 +0000 (Fri, 10 Feb 2006)
New Revision: 5626
Log:
Denestification.
Modified:
trunk/coregrind/m_debuginfo/symtypes.c
Modified: trunk/coregrind/m_debuginfo/symtypes.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/symtypes.c 2006-02-09 23:35:11 UTC (rev 5=
625)
+++ trunk/coregrind/m_debuginfo/symtypes.c 2006-02-10 03:33:10 UTC (rev 5=
626)
@@ -703,10 +703,98 @@
#define MAX_ELEMENTS 5000 /* max number of array elements we scan */
#define MAX_VARS 10000 /* max number of variables total traversed */
=20
+static const Bool memaccount =3D False; /* match creates to frees */
+static const Bool debug =3D False;
+
+/* Add a new variable to the list */
+static Bool newvar(Char *name, SymType *ty, Addr valuep, UInt size,
+ Variable *var, Int *numvars, Int *created,
+ Variable **newlist, Variable **newlistend) {
+ Variable *v;
+
+ /* have we been here before? */
+ if (has_visited(valuep, ty))
+ return False;
+ =20
+ /* are we too deep? */
+ if (var->distance > MAX_PLY)
+ return False;
+
+ /* have we done too much? */
+ if ((*numvars)-- =3D=3D 0)
+ return False;
+
+ if (memaccount)
+ (*created)++;
+ =20
+ v =3D VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(*v));
+
+ if (name)
+ v->name =3D VG_(arena_strdup)(VG_AR_SYMTAB, name);
+ else
+ v->name =3D NULL;
+ v->type =3D ML_(st_basetype)(ty, False);
+ v->valuep =3D valuep;
+ v->size =3D size =3D=3D -1 ? ty->size : size;
+ v->container =3D var;
+ v->distance =3D var->distance + 1;
+ v->next =3D NULL;
+
+ if (*newlist =3D=3D NULL)
+ *newlist =3D *newlistend =3D v;
+ else {
+ (*newlistend)->next =3D v;
+ *newlistend =3D v;
+ }
+ =20
+ if (debug)
+ VG_(printf)(" --> %d: name=3D%s type=3D%p(%s %s) container=3D%p=
&val=3D%p\n",=20
+ v->distance, v->name, v->type, ppkind(v->type->kind),=20
+ v->type->name ? (char *)v->type->name : "",
+ v->container, v->valuep);
+ return True;
+}
+
+static void genstring(Variable *v, Variable *inner, Int *len, Char **ep,
+ Char **sp) {
+ Variable *c =3D v->container;
+
+ if (c !=3D NULL)
+ genstring(c, v, len, ep, sp);
+
+ if (v->name !=3D NULL) {
+ *len =3D VG_(strlen)(v->name);
+ VG_(memcpy)(*ep, v->name, *len);
+ (*ep) +=3D *len;
+ }
+
+ switch(v->type->kind) {
+ case TyPointer:
+ /* pointer-to-structure/union handled specially */
+ if (inner =3D=3D NULL ||
+ !(inner->type->kind =3D=3D TyStruct || inner->type->kind =3D=3D=
TyUnion)) {
+ *--(*sp) =3D '*';
+ *--(*sp) =3D '(';
+ *(*ep)++ =3D ')';
+ }
+ break;
+
+ case TyStruct:
+ case TyUnion:
+ if (c && c->type->kind =3D=3D TyPointer) {
+ *(*ep)++ =3D '-';
+ *(*ep)++ =3D '>';
+ } else
+ *(*ep)++ =3D '.';
+ break;
+
+ default:
+ break;
+ }
+}
+
Char *VG_(describe_addr)(ThreadId tid, Addr addr)
{
- static const Bool debug =3D False;
- static const Bool memaccount =3D False; /* match creates to frees */
Addr eip; /* thread's EIP */
Variable *list; /* worklist */
Variable *keeplist; /* container variables */
@@ -759,57 +847,6 @@
SymType *type =3D var->type;
Bool keep =3D False;
=20
- /* Add a new variable to the list */
- // (the declaration avoids a compiler warning)
- //static void newvar(Char *name, SymType *ty, Addr valuep, UInt size);
- void newvar(Char *name, SymType *ty, Addr valuep, UInt size) {
- Variable *v;
-
- /* have we been here before? */
- if (has_visited(valuep, ty))
- return;
- =20
- /* are we too deep? */
- if (var->distance > MAX_PLY)
- return;
-
- /* have we done too much? */
- if (numvars-- =3D=3D 0)
- return;
-
- if (memaccount)
- created++;
- =20
- v =3D VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(*v));
-
- if (name)
- v->name =3D VG_(arena_strdup)(VG_AR_SYMTAB, name);
- else
- v->name =3D NULL;
- v->type =3D ML_(st_basetype)(ty, False);
- v->valuep =3D valuep;
- v->size =3D size =3D=3D -1 ? ty->size : size;
- v->container =3D var;
- v->distance =3D var->distance + 1;
- v->next =3D NULL;
-
- if (newlist =3D=3D NULL)
- newlist =3D newlistend =3D v;
- else {
- newlistend->next =3D v;
- newlistend =3D v;
- }
- =20
- if (debug)
- VG_(printf)(" --> %d: name=3D%s type=3D%p(%s %s) container=3D=
%p &val=3D%p\n",=20
- v->distance, v->name,=20
- v->type, ppkind(v->type->kind),=20
- v->type->name ? (char *)v->type->name : "",
- v->container, v->valuep);
- keep =3D True;
- return;
- }
-
next =3D var->next;
=20
if (debug)
@@ -847,7 +884,10 @@
VG_(printf)(" %d fields\n", type->u.t_struct.nfield);
for(i =3D 0; i < type->u.t_struct.nfield; i++) {
StField *f =3D &type->u.t_struct.fields[i];
- newvar(f->name, f->type, var->valuep + (f->offset / 8), (f->size=
+ 7) / 8);
+ if(newvar(f->name, f->type, var->valuep + (f->offset / 8),
+ (f->size + 7) / 8, var, &numvars, &created, &ne=
wlist,
+ &newlistend))
+ keep =3D True;
}
break;
}
@@ -901,7 +941,9 @@
for(i =3D min; i <=3D max; i++) {
Char b[10];
VG_(sprintf)(b, "[%d]", i+offset);
- newvar(b, ty, var->valuep + (i * ty->size), -1);
+ if(newvar(b, ty, var->valuep + (i * ty->size), -1, var,
+ &numvars, &created, &newlist, &newlistend))
+ keep =3D True;
}
=20
break;
@@ -912,7 +954,9 @@
/* XXX work out a way of telling whether a pointer is
actually a decayed array, and treat it accordingly */
if (is_valid_addr(var->valuep))
- newvar(NULL, type->u.t_pointer.type, *(Addr *)var->valuep, -1);
+ if(newvar(NULL, type->u.t_pointer.type, *(Addr *)var->valuep,
+ -1, var, &numvars, &created, &newlist, &newlist=
end))
+ keep =3D True;
break;
=20
case TyUnresolved:
@@ -982,67 +1026,26 @@
Char expr[len*2];
Char *sp =3D &expr[len]; /* pointer at start of string */
Char *ep =3D sp; /* pointer at end of string */
- // static void genstring(Variable *v, Variable *inner); // avoid war=
ning
- void genstring(Variable *v, Variable *inner) {
- Variable *c =3D v->container;
+ Bool ptr =3D True;
=20
- if (c !=3D NULL)
- genstring(c, v);
+ /* If the result is already a pointer, just use that as the
+ value, otherwise generate &(...) around the expression. */
+ if (found->container && found->container->type->kind =3D=3D TyP=
ointer) {
+ vg_assert(found->name =3D=3D NULL);
=20
- if (v->name !=3D NULL) {
- len =3D VG_(strlen)(v->name);
- VG_(memcpy)(ep, v->name, len);
- ep +=3D len;
- }
-
- switch(v->type->kind) {
- case TyPointer:
- /* pointer-to-structure/union handled specially */
- if (inner =3D=3D NULL ||
- !(inner->type->kind =3D=3D TyStruct || inner->type->kind =3D=3D TyU=
nion)) {
- *--sp =3D '*';
- *--sp =3D '(';
- *ep++ =3D ')';
- }
- break;
-
- case TyStruct:
- case TyUnion:
- if (c && c->type->kind =3D=3D TyPointer) {
- *ep++ =3D '-';
- *ep++ =3D '>';
- } else
- *ep++ =3D '.';
- break;
-
- default:
- break;
- }
+ found->name =3D found->container->name;
+ found->container->name =3D NULL;
+ found->container =3D found->container->container;
+ } else {
+ bprintf(describe_addr_addbuf, 0, "&(");
+ ptr =3D False;
}
=20
- {
- Bool ptr =3D True;
+ genstring(found, NULL, &len, &ep, &sp);
=20
- /* If the result is already a pointer, just use that as
- the value, otherwise generate &(...) around the
- expression. */
- if (found->container && found->container->type->kind =3D=3D TyPoint=
er) {
- vg_assert(found->name =3D=3D NULL);
+ if (!ptr)
+ *ep++ =3D ')';
=20
- found->name =3D found->container->name;
- found->container->name =3D NULL;
- found->container =3D found->container->container;
- } else {
- bprintf(describe_addr_addbuf, 0, "&(");
- ptr =3D False;
- }
-
- genstring(found, NULL);
-
- if (!ptr)
- *ep++ =3D ')';
- }
-
*ep++ =3D '\0';
=20
bprintf(describe_addr_addbuf, 0, sp);
|