comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: debugging tool?
Date: Sun, 22 Feb 2004 22:17:11 GMT
Date: 2004-02-22T22:17:11+00:00	[thread overview]
Message-ID: <HT9_b.37532$Xp.171149@attbi_s54> (raw)
In-Reply-To: _69_b.69554$KV5.45492@nwrdny01.gnilink.net

> > Is there a tool around that would scan a large program to check for
> > instances of an object being accessed *after* it's been Finalized?
>
> Remember that Ada permits itself to finalize an object more than once.
  I don't mean multiple Finalize calls - that's easy.  I mean accessing an
object *after* it's been finalized.  For instance:
  Main_Object : Main_Object_Type;      -- Controlled type
  Helper_Object : Helper_Object_Type;  -- also Controlled
  procedure Finalize(X : in out Helper_Object_Type) is ...
  procedure Finalize(X : in out Main_Object_Type) is
  begin
    do something that accesses Helper_Object
    other stuff
  end Finalize;
At program termination things are Finalized in the reverse order of their
creation.  So Helper_Object gets Finalized.  Then Main_Object is Finalized
- but that process includes accessing Helper_Object, which has already
been finalized.  Perhaps it contained pointers that were deallocated so
the attempt to use it *after finalization* crashes.  If Helper_Object is
declared *before* Main_Object, all is well.  I recently ran into something
like this where Helper involved a protected object and an attempt to call
the protected object after it had been finalized was not good.  It seems
to me a fairly easy mistake to declare the helper after the main object,
and it seems like a fairly simple minded source code analysis tool could
detect the problem.



  reply	other threads:[~2004-02-22 22:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-21  5:56 debugging tool? tmoran
2004-02-22 21:25 ` Hyman Rosen
2004-02-22 22:17   ` tmoran [this message]
2004-02-22 23:18     ` Stephen Leake
2004-02-23  1:21       ` tmoran
2004-02-23  1:31         ` tmoran
2004-02-23  3:54           ` Stephen Leake
2004-02-23  5:43             ` tmoran
2004-02-23  3:34         ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox