|
From: <sv...@va...> - 2005-07-21 23:32:55
|
Author: njn
Date: 2005-07-22 00:26:25 +0100 (Fri, 22 Jul 2005)
New Revision: 4225
Log:
Re-institute SegInfo reference counting and deallocation.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_debuginfo/symtab.c
Modified: trunk/coregrind/m_aspacemgr/aspacemgr.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_aspacemgr/aspacemgr.c 2005-07-21 21:26:07 UTC (rev =
4224)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-07-21 23:26:25 UTC (rev =
4225)
@@ -31,7 +31,7 @@
*/
=20
#include "pub_core_basics.h"
-#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :(
+#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr.h :(
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
@@ -168,7 +168,7 @@
=20
vg_assert(name);
=20
- if (0) VG_(printf)("alloc_segname %s\n", name);
+ if (0) VG_(printf)("allocate_segname %s\n", name);
=20
len =3D VG_(strlen)(name);
if (len >=3D VG_MAX_SEGNAMELEN-1) {
@@ -320,6 +320,8 @@
segments_used++;
}
=20
+// Forward declaration
+static void dealloc_seg_memory(Segment *s);
=20
/* Shift segments [i+1 .. segments_used-1] down by one, and decrement
segments_used.=20
@@ -328,8 +330,10 @@
{
Int j;
vg_assert(i >=3D 0 && i < segments_used);
- for (j =3D i+1; j < segments_used; j++)
- segments[j-1] =3D segments[j];
+ dealloc_seg_memory(&segments[i]);
+ for (j =3D i+1; j < segments_used; j++) {
+ segments[j-1] =3D segments[j];
+ }
segments_used--;
vg_assert(segments_used >=3D 0 && segments_used < VG_N_SEGMENTS);
}
@@ -434,8 +438,12 @@
vg_assert(a > segments[r].addr);
delta =3D a - segments[r].addr;
make_space_at(r);
+ =20
segments[r] =3D segments[r+1];
segments[r].len =3D delta;
+ if (segments[r].seginfo)
+ VG_(seginfo_incref)(segments[r].seginfo);
+ =20
segments[r+1].len -=3D delta;
segments[r+1].addr +=3D delta;
segments[r+1].offset +=3D delta;
@@ -527,6 +535,10 @@
s->addr, s->addr+s->len,
s1->addr, s1->addr+s1->len);
s->len +=3D s1->len;
+
+ vg_assert(s->seginfo =3D=3D s1->seginfo);
+ dealloc_seg_memory(s1);
+ =20
continue;
}
if (wr < rd)
@@ -570,36 +582,16 @@
return (p < se && pe > s->addr);
}
=20
-#if 0
-/* 20050228: apparently unused */
-/* Prepare a Segment structure for recycling by freeing everything
- hanging off it. */
-static void recycleseg(Segment *s)
-{
- if (s->flags & SF_CODE)
- VG_(discard_translations)(s->addr, s->len);
-
- if (s->filename !=3D NULL)
- VG_(arena_free)(VG_AR_CORE, (Char *)s->filename);
-
- /* keep the SegInfo, if any - it probably still applies */
-}
-
/* When freeing a Segment, also clean up every one else's ideas of
what was going on in that range of memory */
-static void freeseg(Segment *s)
+static void dealloc_seg_memory(Segment *s)
{
- recycleseg(s);
if (s->seginfo !=3D NULL) {
VG_(seginfo_decref)(s->seginfo, s->addr);
s->seginfo =3D NULL;
}
-
- VG_(SkipNode_Free)(&sk_segments, s);
}
-#endif
=20
-
/* Get rid of any translations arising from s. */
/* Note, this is not really the job of the low level memory manager.
When it comes time to rewrite this subsystem, clean this up. */
@@ -784,7 +776,7 @@
preen_segments();
if (0) show_segments("after map_file_segment");
=20
- /* If this mapping is of the beginning of a file, isn't part of
+ /* If this mapping is at the beginning of a file, isn't part of
Valgrind, is at least readable and seems to contain an object
file, then try reading symbols from it.
=20
@@ -824,21 +816,23 @@
s->seginfo =3D VG_(read_seg_symbols)(s->addr, s->len, s->offset=
,
s->filename);
}
- //else=20
- //if (flags & SF_MMAP) {
- // const SegInfo *info;
- //
- // /* Otherwise see if an existing SegInfo applies to this Segme=
nt */
- // for(info =3D VG_(next_seginfo)(NULL);
- // info !=3D NULL;
- // info =3D VG_(next_seginfo)(info)) {
- // if (VG_(seg_overlaps)(s, VG_(seg_start)(info), VG_(seg_siz=
e)(info)))
- // {
- // s->seginfo =3D (SegInfo *)info;
- // VG_(seginfo_incref)((SegInfo *)info);
- // }
- // }
- //}
+ else if (flags & SF_MMAP)=20
+ {
+ const SegInfo *si;
+ =20
+ /* Otherwise see if an existing SegInfo applies to this Segment=
*/
+ for (si =3D VG_(next_seginfo)(NULL);
+ si !=3D NULL;
+ si =3D VG_(next_seginfo)(si))=20
+ {
+ if (VG_(seg_overlaps)(s, VG_(seginfo_start)(si),=20
+ VG_(seginfo_size)(si)))
+ {
+ s->seginfo =3D (SegInfo *)si;
+ VG_(seginfo_incref)((SegInfo *)si);
+ }
+ }
+ }
}
=20
/* clean up */
Modified: trunk/coregrind/m_debuginfo/symtab.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/symtab.c 2005-07-21 21:26:07 UTC (rev 422=
4)
+++ trunk/coregrind/m_debuginfo/symtab.c 2005-07-21 23:26:25 UTC (rev 422=
5)
@@ -1388,7 +1388,7 @@
if (seg->symtab !=3D NULL)
VG_(seginfo_decref)(seg->symtab, seg->addr);
=20
- VG_(symtab_incref)(si);
+ VG_(seginfo_incref)(si);
seg->symtab =3D si;
=20
if (0)
@@ -1702,6 +1702,7 @@
=20
void VG_(seginfo_decref)(SegInfo *si, Addr start)
{
+ vg_assert(si);
vg_assert(si->ref >=3D 1);
if (--si->ref =3D=3D 0)
unload_symbols(si->start, si->size);
@@ -1709,6 +1710,7 @@
=20
void VG_(seginfo_incref)(SegInfo *si)
{
+ vg_assert(si);
vg_assert(si->ref > 0);
si->ref++;
}
|