De
BUG  with
GDB

                                                                                                                                                                << CONTENTS >>

                    Example sessions Debugging with gdb:

                      Sample gdb debugging on core problems and unknown behaviour of application

                      IMPORTANT
                            If your source are using memory related operations using malloc() and free() and you are getting core dumped some reasons. Try to check weather you include #include <stdlib.h> header file in the source.
                            Normally compilation as cc -Ae +DD64 ( IPF 64 bit) or cc +DA2.0W (PA-RISC 64 bit) you will get core dumps when you don't have stdlib head file.

                        A link details problem with sample program..
                        http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=654558
                          

                      sample program debugging
                     
-----------   A sample program   --------------
                              #include <string.h>
                              #include <stdlib.h>

main()
{
        char c;
        c='\0';
        printf("Enter a char:\n");
        scanf("%c",c);
        printf("Char:%c\n",c);
}
                          ----------------------------------------------------

                      Compliation (testing  IPF):
                            # cc -g -o example example.c
                            # ./example
                                Enter a char:
                                c  
                                Memory fault(coredump)

                            >> Started to put printf() lines?? It can not be used.
   
                      Debugging:
# gdb -q example core
Core was generated by `example'.
Program terminated with signal 11, Segmentation fault.
#0  0x60000000c02efd20:0 in string+0x3a0 () from /usr/lib/hpux32/libc.so.1

>> Cause of core "signal 11, Segmentation fault.. (signal 11 SIGSEV)

(gdb) shell file core
core:           ELF-32 core file - IA64 from 'example' - received SIGSEGV

(gdb) bt

#0  0x60000000c02efd20:0 in string+0x3a0 () from /usr/lib/hpux32/libc.so.1
#1  0x60000000c02f3440:0 in T_12_3bdb_cl___doscan_main+0x5b0 ()
   from /usr/lib/hpux32/libc.so.1
#2  0x60000000c02ef1f0:0 in _doscan+0x30 () from /usr/lib/hpux32/libc.so.1
#3  0x60000000c031a500:0 in scanf+0x170 () from /usr/lib/hpux32/libc.so.1
#4  0x4000920:0 in main () at example.c:10

>> stack trace informations which is dumped on core file

(gdb) info frame 4
Stack frame at 0x200000007ffff5d0:
 ip = 0x4000920:0 in main (example.c:10); saved ip 0x60000000c0028cc0:0
 caller of frame at 0x200000007ffff5d0
 source language c.
 Arglist at 0x200000007ffff5d0, args:
 Locals at 0x200000007ffff5d0, Previous frame's sp is 0x0
(gdb) x 0x4000920
0x4000920:0 <main+0xc0>:        0x0808004a
(gdb) x/s 0x4000920
0x4000920:0 <main+0xc0>:         "\b\b"

(gdb) info f 3
Stack frame at 0x200000007ffff5d0:
 ip = 0x60000000c031a500:0 in scanf; saved ip 0x4000920:0
 called by frame at 0x200000007ffff5d0, caller of frame at 0x200000007ffff560
 Arglist at 0x200000007ffff5d0, args:
 Locals at 0x200000007ffff5d0, Previous frame's sp is 0x200000007ffff5d0
 Saved registers:
  gr32 at 0x20000000679ff290, gr33 at 0x20000000679ff298,
  gr34 at 0x20000000679ff2a0, gr35 at 0x20000000679ff2a8,
  gr36 at 0x20000000679ff2b0, gr37 at 0x20000000679ff2b8,
  gr38 at 0x20000000679ff2c0, gr39 at 0x20000000679ff2c8
(gdb) x 0x60000000c031a500
0x60000000c031a500:0 <scanf+0x170>:      "\tp"
(gdb) x/c 0x60000000c031a500
0x60000000c031a500:0 <scanf+0x170>:     9 '\t'

>> 3rd & 4 th frame informations
>> x command used to trace exact address format as char (x/c) string (x/s) or decimal (x/d)
>> use x help or execute help x on gdb prompt


(gdb) info line 10
Line 10 of "example.c" starts at address 0x40008d0:1 <main+0x71>
   and ends at 0x4000920:1 <main+0xc1>.
(gdb) p 0x40008d0
$1 = 67111120
(gdb) x 0x40008d0
0x40008d0:0 <main+0x70>:         "\b\b"
(gdb) list 10
5       main()
6       {
7               char c;
8               c='\0';
9               printf("Enter a char:\n");
10              scanf("%c",c);
11              printf("Char:%c\n",c);
12      }

                        >> Problem occured at line number 10:
                          
        10              scanf("%c",c);
                              >>  It can not work.. Because We have to store the character in the char's address as scanf("%c",&c);
                              >> Edit the example files 10th line as scanf("%c",&c);

                            If you test it now it will work without any problem!!!

   

DEBUGGING EXAMPLES                                                        Muthukumar Kandasamy <[email protected]>                   
Hosted by www.Geocities.ws

1