Re: News about dg script and linux problem

From: Peter Ajamian (pajamian@cheapsam.com)
Date: 09/10/99


rama wrote:

> ok i have do the debug session and the response is that
>
> int real_trigger(int vnum)
> {
>   int rnum;
>
>   for (rnum=0; rnum < top_of_trigt; rnum++)
>   {
>     if (trig_index[rnum]->vnum==vnum) break;          <----
>   }
>
>   if (rnum==top_of_trigt) rnum = -1;
>   return (rnum);

run gdb on the core file again (gdb bin/circle lib/core).

in the core use backtrace to see where it crashed.

switch to the first stack frame number that is a part of the circle code (The
command to do so escapes me at the moment, but look through the online help system,
you'll find it, "help" gets you going.

use the print command (it shows you extra info like how many elements an array is
declared for which is quite usefull, to view any relevent data, if the error point
is where you have indicated above then look at the following variables...

top_of_trigt, trig_index (without the array index and no brackets).

make sure that top_of_trigt is not larger than the size of the array, if it's
dynamically allocated then you may have to divide the size of one element into the
total amount of memory that is allocated (I'm not sure about this).  I'm guessing
that you will probably find out that trig_index does not have enough memory
allocated to it.

Also look at the other variables there and look for anything suspicious.

Now for a bit of explanation of what may be happening, it is very doubtfull that
the problem you are seeing now is a bug introduced by Linux, seg faults can often
go unoticed by one compiler while they crash the program in another, this is rather
a difficult to explain (perhaps someone else here can explain it better than I),
but suffice to say that the problem could just as easily have breezed past Linux
and crashed windows if it occurred somewhere else.

Now for a few extra tips to help you find the problem...

I have seen some instances where the declaration for a variable is different in two
different files and where this has caused problems for example...

in file A...

short int myint;


in file B...

extern int myint;

in a 16 bit compiler this will not be a problem because a short int and an int is
the same in a 16 bit compiler, but in a 32 bit compiler they are different, and
this could very well cause a problem like the one you are seeing (if top_of_trigt
is declared differently like this it could cause one file to see top_of_trigt as an
outrageously large number and since this number is used to define the bouds for an
array that array would easily be overflowed by a loop like the one you have.  The
solution to this problem is to make sure that the declaration for the variable is
the same in all files.

A second possibility is that trig_index is not being allocated properly.  A good
idea might be to grep the source to find the place where trig_index is allocated
and look that over carefully to make sure that enough space is being allocated for
it.

There are other possible causes, but those are probably the most common.

Regards,


Peter


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST