Después de instalar gdb, puede intentar usar gdb para depurar el programa en el terminal. Si tiene dudas sobre la instalación de gdb, consulte la entrada de depuración de gdb (1): instale gdb en Windows / Linux / Ubuntu .
1. Cree o localice el archivo .c que necesita ser depurado
Primero escribe un simple helloworld.c
:
#include<stdio.h>
int main()
{
printf("hello world! \n");
return 0;
}
También puede ubicar el programa .c que necesita depurar y luego comenzar el siguiente paso.
2. Compile el archivo
Que contiene helloworld.c
terminal de entrada de directorio:
gcc -g helloworld.c -o helloworld
A continuación, se puede encontrar en este directorio se hincha en un nombre helloworld
de archivo ejecutable.
3. Inicie la depuración de gdb
En el terminal de la sección anterior, continúe ingresando el nombre del archivo ejecutable del programa a depurar generado por gdb + la sección anterior:
gdb helloworld
Puede encontrar que el terminal ha impreso la siguiente información de registro:
GNU gdb (GDB) 7.12
Copyright (C) 2016 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 "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from helloworld...done.
Luego puede depurar, como la entrada list
, puede ver el siguiente registro:
(gdb) list
1 #include<stdio.h>
2 int main()
3 {
4 printf("hello world! \n");
5 return 0;
6 }
Comience a depurar todo lo que quiera ~