You can see an example of using GDB experiment on the Internet, as shown below:
# Include <stdio. h>
Main ()
{
Char my_string [] = "Hello there ";
My_print (my_string );
My_print2 (my_string );
}
Void my_print (char * string)
{
Printf ("the string is % s/n", string );
}
Void my_print2 (char * string)
{
Char * string2;
Int size, I;
Size = strlen (string );
String2 = (char *) malloc (size + 1 );
For (I = 0; I <size; I ++)
String2 [size-I] = string [I];
String2 [size + 1] = '/0 ';
Printf ("the string printed backward is % s/n", string2 );
}
Whether it's greeting or test, I'll call it test. C.
My Compilation: gcc-O test. c
During warning
Then run:./test
Result;
The string is hello there
The string printed backward is
So I started to use GDB for debugging.
# GDB Test
Gnu gdb 6.8-Debian
Copyright (c) 2008 Free Software Foundation, Inc.
License gplv3 +: gnu gpl Version 3 or later 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 "...
(GDB) file GDB
Load new symbol table from "/home/yaozhangjun/programme/GDB "? (Y or N) y
Reading symbols from/home/yaozhangjun/programme/test... done.
// Output in GDB andGDB
The running results are the same outside.
(GDB) Run
Starting program:/home/yaozhangjun/programme/test
The string is hello there
The string printed backward is
Program exited with code 040.
Then the list is started, but the problem arises. The first list
(GDB) List
1 init. C: no such file or directory.
In init. c
Second List
(GDB) List
1 In init. c
Third list
(GDB) List
1 In init. c
Good guy, nothing.
I searched from the Internet to compile the time-G, and thought it was saved,...
# Gcc-g test-O test. c
GCC: Test: no such file or directory
GCC: no input files
How can this happen?
Previously, GCC-O test-g test. C was required,
Finally met
(GDB) List
1 # include <stdio. h>
2 main ()
3 {
4 char my_string [] = "Hello there ";
5 my_print (my_string );
6 my_print2 (my_string );
7}
8
9 void my_print (char * string)
10 {
I love them.