Gdb试用(1).
gdb试用(1)
cutepig@ubuntu:/mnt/hgfs/share/testValgrind$ gdb ./test
GNU gdb (GDB) 7.0-ubuntu
Copyright (C) 2009 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".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /mnt/hgfs/share/testValgrind/test...done.
(gdb) list
1 #include <string.h>
2 #include <stdlib.h>
3
4
5 int main(int argc, char *argv[])
6 {
7 char *ptr;
8
9 ptr = (char*) malloc(10);
10 strcpy(ptr, "01234567890");
(gdb) b 9
Breakpoint 1 at 0x804850d: file test.cpp, line 9.
(gdb) r
Starting program: /mnt/hgfs/share/testValgrind/test
Breakpoint 1, main (argc=1, argv=0xbffff524) at test.cpp:9
9 ptr = (char*) malloc(10);
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804850d in main at test.cpp:9
breakpoint already hit 1 time
当前帧能看到的变量
(gdb) info frame
Stack level 0, frame at 0xbffff480:
eip = 0x804850d in main (test.cpp:9); saved eip 0x3bdb56
source language c++.
Arglist at 0xbffff478, args: argc=1, argv=0xbffff524
Locals at 0xbffff478, Previous frame's sp is 0xbffff480
Saved registers:
ebp at 0xbffff478, eip at 0xbffff47c
查看某个变量
(gdb) print argv
$1 = (char **) 0xbffff524
(gdb) whatis argv
type = char **
(gdb)
参考
http://www.study-area.org/cyril/opentools/opentools/x1253.html
- 上一篇 Fltk试用 (1).
- 下一篇 Java性能分析工具