swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Casting an id type to a specific object type?


From: mcmullin
Subject: Re: Casting an id type to a specific object type?
Date: Mon, 17 Mar 1997 09:06:54 -0700 (MST)

On 15 Mar, Jae Chan Oh wrote:
> Ken, Thanks for the kind replies.
> I have tried your suggestions on trapping core dump using respondTo: etc.
> My program gives core dump on even that call as well.. sigh..
> 
> i.e.
>       if ([tgt respondsTo: M(print)] )        <--- bombs right here.
>         [tgt print];
>     else
>         {
>         if ( [tgt isMemberOfClassNamed: "Person"] )
>                 fprintf(stderr,"tgt is a 'Person'!\n");
>         else
>                 fprintf(stderr,"tgt is a nobody!\n");
>         exit(1);
>         }
> tgt is not nil as far as I know. 
> tgt is declard as id.
> gdb command "where" gives the following:
> 
> Program received signal SIGSEGV, Segmentation fault.
> objc_msg_lookup (receiver=0x18, op=0x14c100) at sendmsg.c:115
> sendmsg.c:115: No such file or directory.
> (gdb) where
> #0  objc_msg_lookup (receiver=0x18, op=0x14c100) at sendmsg.c:115
> #1  0x2329c in _i_Person__look (self=0x22b850, _cmd=0x14bec0) at Person.m:335
> #2  0x21b10 in _i_Person__step (self=0x22b850, _cmd=0x14c9cc) at Person.m:49
[...]
> I'm stuck here any suggestions? Sorry for the too much detailed question.
> 
> -Jae


I'm coming in late to this, so I may be muddying the
waters; but I have seen something somewhat similar to
this in the last few days.

I suggest you insert a :

  printf("%x\n", (int *)(*tgt));

immediately before the if, and see what comes out (or,
if you're savvy with gdb, after the crash, move the stack
frame back up to this context and "p *tgt").

You just *might* find that *tgt is 0xffffffff.  I have
found a couple of cases of this recently.  It *seems*
to arise when an object is dropped: i.e., although I
have not checked the zone code, I suspect that when an
object is dropped, its formerly allocated memory is set
to all ffffffff (if Roger is listening, maybe he could
clarify?). Anyway, in my experience, if this is the
case, but an attempt is made to use the object anyway
after it has been dropped (which, of course, is an
absolute no no) then the program crashes within
objc_msg_lookup. On my sparc, it tends to generate
SIGBUS instead of SIGSEGV, but I would expect the exact
exception to be hardware specific anyway.

So what?

Well, if you find your object content *does* appear to
be all ffffffff, it's suggestive that the object tgt is
being dropped (presumably unintentionally) somewhere 
before your attempt to use it; so you can try setting a
watch on *tgt, or inserting addional printf()
statements, or simply studying your code again with
this possibility in mind.

And, of course, if you find that *tgt is *not* all
ffffffff, you should dismiss all the above as totally
irrevelant (;-)

- Cheers,

Barry.


-- 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Barry McMullin, ALife Group,               |    address@hidden |
| Santa Fe Institute, 1399 Hyde Park Road,   |  Voice: +1-505-984-8800 |
| Santa Fe, NM 87501, USA.                   |  FAX:   +1-505-982-0565 |
| http://www.eeng.dcu.ie/~mcmullin           |                         |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




reply via email to

[Prev in Thread] Current Thread [Next in Thread]