From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,836e7962fed7281b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-22 19:37:54 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!priapus.visi.com!orange.octanews.net!news-out.visi.com!petbe.visi.com!news.octanews.net!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: debugging tool? Date: 22 Feb 2004 22:34:10 -0500 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1077507273 74101 212.85.156.195 (23 Feb 2004 03:34:33 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Mon, 23 Feb 2004 03:34:33 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:5742 Date: 2004-02-22T22:34:10-05:00 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