Débogger avec gdb

moimeme -  
 jenjel -
Bonjour,
je n'arrive pas a comprendre comment utiliser le debogeur gdb...
j'ai regardé sur internet, je suis tombé sur cette page http://www.linux-kheops.com/doc/man/manfr/man-html-0.9/man1/gdb.1.html, mais je n'arrive pas à trouver mes erreurs.

J'ai essayé un programme qui marche, je lui ai rajouté exprès une erreur qui fait un segmentation fault...mais impossible de trouver cette erreur avec gdb...
pourriez vous m'expliquer comment faire ??

voici mon programme:
"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);
return0;
}

Comment trouver l'erreur avec le déboggeur ?? (quand je met run , il dit "failed to read a valid object file image from memory"...)

merci
Configuration: Windows Vista
Internet Explorer 7.0

4 réponses

  1. jisisv Messages postés 3678 Statut Modérateur 936
     
    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.
    1
  2. pibarze Messages postés 39 Statut Membre 12
     
    Dans gdb :
    b main -> pour poser un breakpoint sur la fonction "main"
    run -> pour démarrer le programme. L'exécution s'arrêtera au début de la fonction "main"
    n -> pour avancer d'une ligne
    Taper une touche et entrée puis avec un peu de chance "une segmentation fault" dont tu connaitras la provenance.
    1
  3. jenjel
     
    lorsqu'on fait du bebuggage avec GDB sur pentium, est ce qu'on aurait recours à l'interface JTAG ou pas ?
    0