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 :
Expand|Select|Wrap|Line Numbers
- #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;
- }
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 ?