How to configure gdb ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmk
    New Member
    • Oct 2006
    • 19

    How to configure gdb ?

    Hi,

    I have implemented strcpy function using arrays. Wantedly i have coded in order to generate segmentation fault. How to debug it using gdb ?

    My code snippet :
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        int i;
        char *dest="murali";
        char *src = "krishna";
        strcpy_temp(dest,src);
        printf("value of dest and src is %s %s\n",*dest,*src);
    }
    
    int strcpy_temp(char *dest, char*src)
    {
        int i=0;
        while(src[i] != '\0')
        {
            dest[i] = src[i];
        }
        return 0;
    }
    After compiling this i got a.out. After executing a.out it got crashed .Now if i give $gdb a.out

    Following is the message displayed.

    [mmk@localhost c]$ gdb a.out
    GNU gdb Red Hat Linux (6.1post-1.20040607.43.0 .1rh)
    Copyright 2004 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 "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so .1".

    (gdb) bt
    No stack.
    (gdb)


    Please suggest me how to proceed. Do I need to modify anything in .gdbinit ?
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    First of all..
    have you compiled your code with -ggdb option,,If not do it.
    Later when you give the command
    'gdb a.out' and you end up with '(gdb)' prompt, you need to tell the gdb explicitly to run a.out by giving command 'run' or 'r' .
    So before back tracing you've to run the executable..

    There is no problem with your gdb installation..

    Comment

    • mmk
      New Member
      • Oct 2006
      • 19

      #3
      Originally posted by ashitpro
      First of all..
      have you compiled your code with -ggdb option,,If not do it.
      Later when you give the command
      'gdb a.out' and you end up with '(gdb)' prompt, you need to tell the gdb explicitly to run a.out by giving command 'run' or 'r' .
      So before back tracing you've to run the executable..

      There is no problem with your gdb installation..
      Hi Ashit,

      Thank you, I got it :).

      Comment

      Working...