As tu compilé ton source avec l'option -g pour les informations de débugages ? (-g)
[johand@horus]~/src/c/gdb $cat sigseg.c
#include<stdio.h>
int main (void)
{
int i;
scanf("%d", i); // il manque le &, c'est ce qui fait le segmentation fault
printf("vous avez ecrit %d", i);
return 0;
}
[johand@horus]~/src/c/gdb $gcc -g -o sigseg sigseg.c
[johand@horus]~/src/c/gdb $gdb ./sigseg
GNU gdb 6.7.1-debian
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/i686/cmov/libthread_db.so.1".
(gdb) run
Starting program: /home/johand/src/c/gdb/sigseg
123456
Program received signal SIGSEGV, Segmentation fault.
0xb7dfaebb in _IO_vfscanf () from /lib/i686/cmov/libc.so.6
(gdb) help stack
Examining the stack.
The stack is made up of stack frames. Gdb assigns numbers to stack frames
counting from zero for the innermost (currently executing) frame.
At any time gdb identifies one frame as the "selected" frame.
Variable lookups are done with respect to the selected frame.
When the program being debugged stops, gdb selects the innermost frame.
The commands below can be used to select other frames by number or address.
List of commands:
backtrace -- Print backtrace of all stack frames
bt -- Print backtrace of all stack frames
down -- Select and print stack frame called by this one
frame -- Select and print a stack frame
return -- Make selected stack frame return to its caller
select-frame -- Select a stack frame without printing anything
up -- Select and print stack frame that called this one
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
(gdb) bt
#0 0xb7dfaebb in _IO_vfscanf () from /lib/i686/cmov/libc.so.6
#1 0xb7e04b9b in scanf () from /lib/i686/cmov/libc.so.6
#2 0x080483c8 in main () at sigseg.c:5
(gdb) l
1 #include<stdio.h>
2 int main (void)
3 {
4 int i;
5 scanf("%d", i); // il manque le &, c'est ce qui fait le segmentation fault
6 printf("vous avez ecrit %d", i);
7 return 0;
8 }
9
(gdb)
'btt' pour examiner le stack....
Je ne suis pas spécialiste gdb , mais en utisant l'aide en lgne et ses neurones, on peut prendre la main sur l'outil.
Gates gave you the windows.
GNU gave us the whole house.(Alexandrin)