swarm-support
[Top][All Lists]
Advanced

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

Re: Segmentation Faults after a number of iterations...


From: Marcus G. Daniels
Subject: Re: Segmentation Faults after a number of iterations...
Date: 13 Oct 1999 14:53:20 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "DS" == Darren Schreiber <address@hidden> writes:

DS> So, first question what is a better way of doing this naming?

Here's a robust way to do that:

#import <simtools.h> // initSwarm
#import <defobj.h> // SSTRDUP
#include <misc.h> // sprintf

const char *
makeLabel (int agentID)
{
  char buf[1 + DSIZE (int) + 1];

  sprintf (buf, "C%d", agentID);
  return SSTRDUP (buf);
}

int
main (int argc, const char **argv)
{
  initSwarm (argc, argv);
  
  printf ("`%s'\n", makeLabel (10));
}

/*
Local Variables:
compile-command: "/opt/SDGswarm/2.0.1/bin/libtool-swarm --mode=link gcc -o str 
-g -Wno-import -I/opt/SDGswarm/2.0.1/include -L/opt/SDGswarm/2.0.1/lib str.m 
-lswarm -lobjc"
End:
*/


DS> Second question, if I am dropping dropped things or using dropped things...
DS> how can I find these errors that far down the line?

This first thing to establish is whether it is likely the problem.
One way to do that is to disable drops.  With most Unix systems, you
can define a "void free (void *ptr) { }" function in your model and
it will be called instead of the system version.
Otherwise, start disabling calls to drop. 

For really nasty problems, there are replacement malloc
implementations like dmalloc (http://www.dmalloc.com) and compiler
enhancements like Checker (http://www.gnu.org/software/checker).  I've
used both of these with good results with Swarm, although (especially)
the latter can be very difficult to get configured just right.  You
can get a weak form of this if you put printfs where you allocate and
deallocate things, logging it all to a file, then using associative
arrays in `awk' to compare where things came into existence and when
they leave.  Purify (a commerical package) is probably usable too.

Another approach is to use watchpoints in GDB.  This works pretty well
on Intel machines, because they have hardware support. 

It's a tradeoff.  Get good at using GDB, spend a lot of time getting a
Checker or Purify installation intermingled with Swarm, figure out how
to set up dmalloc (also time consuming, but less so), or just look at
your code and Think Hard.  Most folks probably don't have thousands
and thousands of lines of Swarm code in a single model, and so there is
only so much code to Think Hard about...


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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