GDB oddity

Posted by Greven on Sun 10 Oct 2004 09:51 PM — 6 posts, 21,457 views.

Canada #0
Working in GDB trying to figure something out, here is the code
                for (timer = ch->first_timer; timer; timer = timer_next)
                {
                        int       sn;
                        timer_next = timer->next;

				        for (sn = 0; sn < top_sn; sn++)
                            if ( *skill_table[sn]->skill_fun == timer->do_fun )
                                break;

                        if ( sn == top_sn )
                            bug("Null skill for fast engineer");

                        if (--timer->count <= 0
                            || (!IS_NPC(ch) && skill_table[sn]->guild == ENGINEERING_ABILITY
                                && IS_SET(ch->pcdata->flags,PCFLAG_FASTENGINEER) ))
                        {
                                if (timer->type == TIMER_DO_FUN)
                                {
                                        int       tempsub;

                                        tempsub = ch->substate;
                                        ch->substate = timer->value;
                                        (timer->do_fun) (ch, "");
                                        if (char_died(ch))
                                                break;
                                        ch->substate = tempsub;
                                }
                                extract_timer(ch, timer);
                        }
                }
Its quite clear that sn is defined, however...
Quote:
(gdb) bt
#0 0x40161ac1 in kill () from /lib/libc.so.6
#1 0x401616eb in raise () from /lib/libc.so.6
#2 0x40163127 in abort () from /lib/libc.so.6
#3 0x080bcde2 in SegVio (signum=11) at comm.c:503
#4 <signal handler called>
#5 0x080e2b04 in violence_update() () at fight.c:262
#6 0x0818b8c4 in update_handler() () at update.c:3148
#7 0x080bd313 in game_loop() () at comm.c:823
#8 0x080bcb6a in main (argc=8, argv=0xbffff1b4) at comm.c:362
#9 0x4014dd06 in __libc_start_main () from /lib/libc.so.6
(gdb) frame 5
#5 0x080e2b04 in violence_update() () at fight.c:262
262 if (--timer->count <= 0
Current language: auto; currently c++
(gdb) print sn
No symbol "sn" in current context.
(gdb)
I would assume that GDB cannot access sn because its of where its defined. Is this normal for GDB, I've never noticed this before.
Amended on Sun 10 Oct 2004 09:53 PM by Greven
USA #1
Hrm. Do 'list' in frame 5. Whats it display?
Canada #2
The actual bug in the code is not the issue, I was just curious as to why it wouldn't print sn.

If your curious though:
257                                                                     break;
258
259                                                     if ( sn == top_sn )
260                                                             bug("Null skill for fast engineer");
261
262                             if (--timer->count <= 0
263                                 || (!IS_NPC(ch) && skill_table[sn]->guild == ENGINEERING_ABILITY
264                                     && IS_SET(ch->pcdata->flags,PCFLAG_FASTENGINEER) ))
265                             {
266                                     if (timer->type == TIMER_DO_FUN)
USA #3
I know. Just wanted to make sure gdb wasn't having troubles, and wouldn't display all the lines. Or if it wasn't in the loop. I think its just the way gdb acts. You'll have to set a breakpoint, probably.
Australia Forum Administrator #4
Quote:

#5 0x080e2b04 in violence_update() () at fight.c:262
262 if (--timer->count <= 0
Current language: auto; currently c++


This puzzles me. You are debugging a .c file but it says the language is c++. This might cause confusion because of C++ name mangling.

Maybe type "set language c" and try again.
Canada #5
Yeah, that was it, I was able print sn, didn't think it would make a difference.

I'm compiling in c++ for the stricter compile rules, thats why its set to c++.