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

原文链接: https://www.cnblogs.com/cutepig/archive/2011/09/10/2173208.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    gdb试用(1)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/32076

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午9:20
下一篇 2023年2月8日 上午9:22

相关推荐