From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: debugging tool?
Date: 22 Feb 2004 22:34:10 -0500
Date: 2004-02-22T22:34:10-05:00 [thread overview]
Message-ID: <mailman.12.1077507273.327.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <Yzc_b.377591$xy6.1981921@attbi_s02>
tmoran@acm.org writes:
> > Right. So put in a flag Object.Finalized, and check Object.Finalized
> > in _every_ operation on Object. Raise an exception, or silently do
> > nothing, your choice.
> > > Main_Object : Main_Object_Type; -- Controlled type
> > > Helper_Object : Helper_Object_Type; -- also Controlled
> By "Object" here you must mean Main_Object_Type, right? So
> type Main_Object_Type is new Ada.Finalization.Controlled with record
> Helper_Finalized : Boolean
> ...
No, the flag has to go in helper_type; it's the one being finalized
and then accessed.
> That's great for future development, but I'm look for something to
> automatically examine a large body of existing code.
Ok, if you can't change the code, you have a problem :).
But I'm suggesting you only have to change Helper_Type and the
operations on Helper_Type, not everything that uses Helper_Type. Does
that make it easier to do?
> Often Main_Object_Type doesn't know much at all about
> Helper_Object_Type, and may well have been coded long before someone
> added a helper type. (eg, Helper_Type keeps a usage count of
> Main_Object_Type's and does something when they've all gone away.
> Even if Helper_Type is a simple integer, it's questionable to access
> it after it's de-elaborated=finalized).
Hmm. If Helper_Object truly de-elaborated, that means it's gone out of
scope. So if Main_Object is still "accessing" it, it must be thru a
"dangling pointer". So you need a pointer tracker tool.
If Helper_Object is still in scope, any access to it can check a flag
in Helper_Object first.
I've added such a flag to your original example:
with ada.finalization;
package testff1 is
type A is new ada.finalization.controlled with null record;
procedure Finalize(x : in out A);
AA : A;
private
type Helper_Type(id : integer) is new ada.finalization.controlled with record
Finalized : Boolean := False;
end record;
procedure Finalize(x : in out Helper_Type);
procedure dummy(x : in out Helper_Type);
end testff1;
with ada.text_io;
package body testff1 is
Helper : Helper_Type(1);
procedure Finalize(x : in out Helper_Type) is
begin
ada.text_io.put_line("finalize helper" & integer'image(x.id));
X.Finalized := True;
end Finalize;
procedure dummy(x : in out Helper_Type) is
begin
if X.Finalized then
Ada.Text_IO.Put_Line ("attempt to process finalized helper");
else
ada.text_io.put_line("process Helper" & integer'image(x.id));
end if;
end dummy;
procedure Finalize(x : in out A) is
begin
ada.text_io.put_line("finalize A");
dummy(Helper);
end Finalize;
end testff1;
./testff.exe
main
finalize A
process Helper 1
finalize helper 1
finalize A
attempt to process finalized helper
> In general, I'd like a tool (if not the compiler) to catch
> non-obvious errors like this.
That would require full data flow analysis. Better to redesign to
avoid such problems in the first place.
--
-- Stephe
prev parent reply other threads:[~2004-02-23 3:34 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
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 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox