Example: A Segmentation Violation with GDB Example I took the code for SwarmSugarScape (sss-2.0) and made a change that I expected to cause a seg fault. Note the line I've commented out: - reapAgents { id index, agent; index = [reaperQueue begin: [self getZone]]; while ((agent = [index next])) { [agentList remove: agent]; [agent drop]; } // [reaperQueue removeAll]; return self; } When this runs, the reaperQue never gets cleared out, so after agents have already been dropped, the reapAgents method tries to drop them again, and thus we get a "seg fault" (that's a segmentation fault, son) or, as they call it in windows, a "segmentation violation". They call it that in Windows because Bill Gates likes rhymes. Now look what happens when I run this (this is in MS Windows95). swarm@PAULLAP[/swarmPrograms/sss-2.0] $ sss.exe 0 0 [main] C:\SWARMPROGRAMS\SSS-2.0\SSS.EXE 1014 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION 0 12874 [main] SSS 1014 stackdump: Dumping stack trace to SSS.EXE.stackdump Now I'm going to use gdb to try to find the cause. I'm setting no breakpoints, not doing anything fancy. I'm just going to load it up, then type run, let it crash, and get a backtrace. swarm@PAULLAP[/swarmPrograms/sss-2.0] $ gdb sss.exe GNU gdb 4.17.1 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i586-cygwin32"... (gdb) run Starting program: /swarmPrograms/sss-2.0/sss.exe 7fe90000:/WINDOWS/SYSTEM/COMDLG32.DLL 66300000:/CYGNUS/CYGWIN-B20/H-I586-CYGWIN32/BIN/CYGTK80.DLL bff30000:/WINDOWS/SYSTEM/GDI32.DLL bff60000:/WINDOWS/SYSTEM/USER32.DLL 66000000:/CYGNUS/CYGWIN-B20/H-I586-CYGWIN32/BIN/CYGTCL80.DLL 60540000:/SWARM-2.0.1/BIN/BLT24.DLL 69c40000:/SWARM-2.0.1/BIN/SWARM.DLL bff70000:/WINDOWS/SYSTEM/KERNEL32.DLL bfec0000:/WINDOWS/SYSTEM/ADVAPI32.DLL 61000000:/CYGNUS/CYGWIN-B20/H-I586-CYGWIN32/BIN/CYGWIN1.DLL 641c0000:/SWARM-2.0.1/BIN/OBJC.DLL warning: cYgFFFFFFFF 6107D148 0 10000000:/WINDOWS/SYSTEM/SYNTPFCS.DLL 7c6c0000:/WINDOWS/SYSTEM/WSOCK32.DLL bfc00000:/WINDOWS/SYSTEM/COMCTL32.DLL 7fdc0000:/WINDOWS/SYSTEM/SHELL32.DLL [failed reading symbols from DLL] "/WINDOWS/SYSTEM/SHLWAPI.DLL": error reading line numbers 7cbb0000:/WINDOWS/SYSTEM/URL.DLL Program received signal SIGSEGV, Segmentation fault. 0x641c9fb9 in objc_msg_lookup (receiver=0x4665d70, op=0x407c9c) at \src\Swarm\swarm\libobjc\objc\sarray.h:217 217 \src\Swarm\swarm\libobjc\objc\sarray.h: No such file or directory. (gdb) bt #0 0x641c9fb9 in objc_msg_lookup (receiver=0x4665d70, op=0x407c9c) at \src\Swarm\swarm\libobjc\objc\sarray.h:217 #1 0x403b38 in _i_ModelSwarm__reapAgents (self=0x4633e78, _cmd=0x407b7c) at ModelSwarm.m:203 #2 0x69ce5962 in _i_Object_s__perform_ (self=0x4633e78, _cmd=0x69d6d29c, aSel=0x407b7c) at /src/Swarm/swarm/src/defobj/DefObject.m:664 #3 0x69ccf891 in _i_ActionTo_0___performAction__ (self=0x468a640, _cmd=0x69d711a4, anActivity=0x468c7a0) at /src/Swarm/swarm/src/activity/Action.m:246 #4 0x69cd92ed in _i_Activity_c___run_ (self=0x468c7a0, _cmd=0x69d7118c) at /src/Swarm/swarm/src/activity/XActivity.m:189 #5 0x69cd921a in _i_Activity_c___run_ (self=0x468c898, _cmd=0x69d7118c) at /src/Swarm/swarm/src/activity/XActivity.m:147 #6 0x69cd921a in _i_Activity_c___run_ (self=0x468c6c8, _cmd=0x69d7118c) at /src/Swarm/swarm/src/activity/XActivity.m:147 #7 0x69cd921a in _i_Activity_c___run_ (self=0x468ebe8, _cmd=0x69d7118c) at /src/Swarm/swarm/src/activity/XActivity.m:147 #8 0x69cd921a in _i_Activity_c___run_ (self=0x468b790, _cmd=0x69d71174) at /src/Swarm/swarm/src/activity/XActivity.m:147 #9 0x69cd9133 in _i_Activity_c__run (self=0x468b790, _cmd=0x69d415d8) at /src/Swarm/swarm/src/activity/XActivity.m:76 #10 0x69c544b9 in _i_ControlPanel__startInActivity_ (self=0x463dfa8, _cmd=0x69d41df8, activityID=0x468b790) at /src/Swarm/swarm/src/simtoolsgui/ControlPanel.m:98 #11 0x69c55474 in _i_GUISwarm__go (self=0x4607ea0, _cmd=0x407054) at /src/Swarm/swarm/src/simtoolsgui/GUISwarm.m:49 #12 0x4011b1 in main (argc=1, argv=0x4590d18) at main.m:23 #13 0x610048cc in _size_of_stack_reserve__ () #14 0x61004bad in _size_of_stack_reserve__ () #15 0x406223 in cygwin_crt0 () #16 0x40103d in mainCRTStartup () #17 0xbff88e93 in _libuser32_a_iname () #18 0xbff88d41 in _libuser32_a_iname () #19 0xbff87759 in _libuser32_a_iname () #20 0x8 in ?? () #21 0x6508e200 in ?? () Cannot access memory at address 0x16007004. (gdb) quit As luck would have it, the mistake in my code shows up almost at the top. Look at line #1, where ModelSwarm is seen to be the culprit. Not all backtraces are this easy to read, sometimes you scan all the way to the bottom trying to find your code, and you don't. This usually means you've discovered a bug in the Swarm library itself.