- 论坛徽章:
- 0
|
1.查看默认的gcc版本
#gcc –v
gcc
version 3.3.2 20030222
2.编写一个简单的程序进行练习
#vi hello.c#includestdio.h>
int main(int argc, char* argv[])
{
printf(“Hello,%s.\n”,argv[1]);
return 0;
}
# gcc –o
hello –g hello.c
# ./hello “daxi”
Hello,daxi.
3.gcc常用命令选项
-c 只编译并生成目标文件。
-g 生成调试信息。
-o FILE 生成制定名称的可执行文件。
-Wall 生成所有警告信息。
4.使用gdb
#gdb
hello
(gdb)b
main
(gdb)r
(gdb)n
(gdb)p
argv[0]
$1 =
0xbffffc67 “/root/hello”
(gdb)q
4.gdb常用命令选项
gdb
progname Start GDB is with an executable program.
r Start your program
under GDB.
b LINENUM Set a breakpoint at line LINENUM in current source file.
b FUNCTION Set a breakpoint at entry to function FUNCTION.
s [COUNT] Continue running
your program until control reaches a different source line
n [COUNT] Continue to the next source line in current stack
frame.
p [EXP] By default value of EXP is printed in a format appropriate to
its data type.
s/n类似VS2005的F11/F10
参考:
http://sources.redhat.com/
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/49865/showart_654355.html |
|