skill table crashing?

Posted by Frobozz on Mon 20 Dec 2004 07:57 PM — 13 posts, 39,420 views.

#0
Hi!

I've been trying to debug this for over a week now, I hope someone here can help out a bit. Right now when I try to use the command: sset save skill table, the entire mud goes down. So I went and put bug()'s in the code, and this is what it produced:

sset save skill table
Log: Valens: sset save skill table
Log: [*****] BUG: here?
Saving skill table...
Log: [*****] BUG: Here 2?
Log: [*****] BUG: 3?
Log: [*****] BUG: 8?
Log: [*****] BUG: 9?
Log: [*****] BUG: last

And this is the code:



void save_skill_table()
{
    int x;
    int sn;
    FILE *fpout;

    if ( (fpout=fopen( SKILL_FILE, "w" )) == NULL )
    {
        bug( "Here 1?", 0);
        perror( SKILL_FILE );
        bug( "Cannot open skills.dat for writting", 0 );
        return;
    }
    bug( "Here 2?", 0);
    for ( x = 0; x < top_sn; x++ )
    {
        bug( "3?", 0);
        if ( !skill_table[x]->name || skill_table[x]->name[0] == '\0' )
        bug( "4?", 0);
           break;
        if ( SPELL_FLAG(get_skilltype(sn), SF_DELETED))
        bug( "5?", 0);
           continue;
        fprintf( fpout, "#SKILL\n" );
        bug( "6?", 0);
        fwrite_skill( fpout, skill_table[x] );
        bug( "7", 0);
    }
      bug( "8?", 0);
    fprintf( fpout, "#END\n" );
      bug( "9?", 0);
    fclose( fpout );
      bug( "last", 0);
}


Does anyone see what's wrong with it? Or have a suggestion on how to solve this problem?
Canada #1
Well, it looks like its breaking on the first skill because that skill has no name. Check your skill.dat file and make sure that there are no null skill being written.
#2
First lines of skills.dat



#SKILL
Name         reserved~
Type         Spell
Info         0
Flags        0
Minpos       112
Slot         95
Code         spell_null
Dammsg       ~
Wearoff      ???~
Minlevel     51
End

#SKILL
Name         acid breath~
Type         Spell
Info         5
Flags        0
Target       1
Minpos       110
Slot         200
Mana         20
Rounds       4
Code         spell_acid_breath
Dammsg       blast of acid~
Wearoff      !Acid Breath!~
Minlevel     43
End

#SKILL
Name         animate dead~
Type         Spell
Info         0
Flags        0
Minpos       110
Slot         231
Mana         220
Rounds       12
Code         spell_animate_dead
Dammsg       ~
Wearoff      !Animate Dead!~
Minlevel     42
End

#3
Would the code: spell_null be what you were talking about? Would that be causing the crash?


#SKILL
Name enhanced damage~
Type Skill
Info 0
Flags 0
Minpos 105
Code spell_null
Dammsg ~
Wearoff !Enhanced Damage!~
Minlevel 1
End

#SKILL
Name evasive style~
Type Skill
Info 0
Flags 0
Rounds 4
Code spell_null
Dammsg ~
Wearoff !evasive style!~
Teachers 10340 3004~
Minlevel 1
End
#4
I also added bug()'s into do_sset in skills.c to see what would happen... This is what came out:

Log: Valens: sset save skill table
Log: [*****] BUG: here above arg2, skill
Saving skill table...
Log: [*****] BUG: in skills.c
Log: [*****] BUG: Here 2?
Log: [*****] BUG: 3?
Log: [*****] BUG: 8?
Log: [*****] BUG: 9?
Log: [*****] BUG: last
Log: [*****] BUG: below save_skill_table()



      }
      send_to_char( "Skill being any skill or spell.\n\r",            ch );
      return;
  }

  if ( get_trust(ch) > LEVEL_SUB_IMPLEM
  &&  !str_cmp( arg1, "save" )
  &&  !str_cmp( argument, "table" ) )
    {
      bug( " here above arg2, skill", 0);;
      if ( !str_cmp( arg2, "skill" ) )
      {
          send_to_char( "Saving skill table...\n\r", ch );
      bug( "in skills.c", 0);
          save_skill_table();
      bug( "below save_skill_table()",0);
          save_classes();
          /* save_races(); */
          return;
      bug( "after skills return",0);
      }
      if ( !str_cmp( arg2, "herb" ) )


So it looks like it's going in one great big circle from sset back to save_skill_table, etc... But I dont see the error :(
Canada #5
So this is crashing the mud? Do you get a core, or if not, have you tried booting the mud in GDB to see where the problem.
#6
Perhaps this whole thing has me completely frazzled or.. well.. yeah...

But this is supposedly my core file in ..\smaug\area

[frobozz area]$ ls -lh core*
-rwx--x--x 1 frobozz frobozz 428k Dec 20 17:42 core

After reading the gdb helpfile I have no idea how to run gdb, and then fire up the mud, to watch for that...

Your help here is greatly appreciated.

Thank you!
Canada #7
well, assuming your executable is called "smaug" and your using port <port>, you want to execute the following commands to boot the mud in GDB-


cd area
gdb ../src/smaug
run <port>


This will boot the mud inside GDB. Log in, and recreate the crash. At that time, you can go into GDB and see what command it crashed. To see the order in which this command was called, use BT. You can use commands like "print skill_table" for example to see the memory adress of the first index. Refer to Nick's guide for a much more indepth way to use GDB.

I really suggest, as will most everyone on here to get confortable with GDB, as it is an invaluable tool for coders.
#8
Interesting. Thank you, truly.


This is what happend:



Mon Dec 20 23:26:24 2004 :: Loading Morphs
Mon Dec 20 23:26:24 2004 :: Done.
Mon Dec 20 23:26:24 2004 :: Initializing socket
Mon Dec 20 23:26:24 2004 :: (Name Not Set) ready at address bb7.bet
Mon Dec 20 23:27:08 2004 :: Sock.sinaddr:  68.255.250.237, port 359
Mon Dec 20 23:27:10 2004 :: Preloading player data for: Valens (7K)
Mon Dec 20 23:27:12 2004 :: Loading player data for: Valens (7K)
Mon Dec 20 23:27:12 2004 :: Valens (68.255.250.237) has connected.
Mon Dec 20 23:27:49 2004 :: Log Valens: sset
Mon Dec 20 23:28:41 2004 :: Log Valens: sset fatigue flag delete
Mon Dec 20 23:28:43 2004 :: Log Valens: sset fatigue flag deleted
Mon Dec 20 23:28:48 2004 :: Log Valens: sset save skill table
Mon Dec 20 23:28:48 2004 :: [*****] BUG:  here above arg2, skill
Mon Dec 20 23:28:48 2004 :: [*****] BUG: in skills.c
Mon Dec 20 23:28:48 2004 :: [*****] BUG: hmmm!
Mon Dec 20 23:28:48 2004 :: [*****] BUG: skill_table 2
Mon Dec 20 23:28:48 2004 :: [*****] BUG: skill_table 3

Program received signal SIGSEGV, Segmentation fault.
0x08184d66 in save_skill_table () at tables.c:1960
1960            if ( SPELL_FLAG(get_skilltype(sn), SF_DELETED))

(gdb) bt
#0  0x08184d66 in save_skill_table () at tables.c:1960
#1  0x081657e5 in do_sset (ch=0x8406250, argument=0xbffff370 "table") at skills.c:815
#2  0x08107111 in interpret (ch=0x8406250, argument=0xbffff365 "save skill table") at interp.c:577
#3  0x080c7164 in game_loop () at comm.c:651
#4  0x080c671e in main (argc=2, argv=0xbffffc94) at comm.c:308
#5  0x4003f177 in __libc_start_main (main=0x80c630c <main>, argc=2, ubp_av=0xbffffc94, init=0x80490dc <_init>,
    fini=0x8196970 <_fini>, rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffffc8c) at ../sysdeps/generic/libc-start.c:129
(gdb) fame 0
Undefined command: "fame".  Try "help".
(gdb) frame 0
#0  0x08184d66 in save_skill_table () at tables.c:1960
1960            if ( SPELL_FLAG(get_skilltype(sn), SF_DELETED))
(gdb) frame 1
#1  0x081657e5 in do_sset (ch=0x8406250, argument=0xbffff370 "table") at skills.c:815
815                 save_skill_table();
(gdb) frame 2
#2  0x08107111 in interpret (ch=0x8406250, argument=0xbffff365 "save skill table") at interp.c:577
577         (*cmd->do_fun) ( ch, argument );
(gdb) frame 3
#3  0x080c7164 in game_loop () at comm.c:651
651                                interpret( d->character, cmdline );
(gdb) frame 4
#4  0x080c671e in main (argc=2, argv=0xbffffc94) at comm.c:308
308         game_loop( );
(gdb) frame 5
#5  0x4003f177 in __libc_start_main (main=0x80c630c <main>, argc=2, ubp_av=0xbffffc94, init=0x80490dc <_init>,
    fini=0x8196970 <_fini>, rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffffc8c) at ../sysdeps/generic/libc-start.c:129
129     ../sysdeps/generic/libc-start.c: No such file or directory.
        in ../sysdeps/generic/libc-start.c


Canada #9
From where its crashing, you need to try printing all the variables and see what the values are. SPELL_FLAG is a macro, so look it up in mud.h and see what it does so you can print out everything you need.

For example:
print sn
#10
It was this:

0x08184d66 in save_skill_table () at tables.c:1960
1960 if ( SPELL_FLAG(get_skilltype(sn), SF_DELETED))


get_skilltype(sn) should have been X...

Because well.. I was dumb

Thank you for all your help!
Canada #11
Ah, of course. After dealing with skill code for a while you tend to assume that sn is used for the purpose of x. Guess I need to pay more attention :)
#12
LOL

Nope, pretty sure Im the one that needs to pay more attention!

Thanks :)