LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1045|回复: 2

gdb中如何执行一个文件中的命令

[复制链接]
发表于 2006-11-2 13:45:06 | 显示全部楼层 |阅读模式
正如大家所知道的,在gdb起来的时候,使用-x选项可以执行一个文件中的所有命令.

但是我现在在gdb调试的中途,想执行一个文件中的命令,该怎么办呢,我尝试过history command, gdbinit和使用变量保存命令,均不能满足我的要求,因为文件中的命令每次是变换的!

请这样用过的朋友告知一下,感谢!
发表于 2006-11-5 20:22:16 | 显示全部楼层
有个比较笨的方法,你可能不喜欢,
也不知道复杂的命令行不行:

看例子:

souldump@BirdSky:~/bin> cat ether            # eher 为保存命令的文件
step
step
step
step
step

souldump@BirdSky:~/bin>
                        

BirdSky:/home/souldump/bin # gdb de
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) b 58
Breakpoint 1 at 0x804881c: file de.c, line 58.
(gdb) run
Starting program: /home/souldump/bin/de
Hi, I get gateway address 10.0.119.254
0:11:bb:3d:e6:ff
The gateway MAC we RETURN is :0:11:bb:3d:e6:ff

Breakpoint 1, main () at de.c:58
58              bind_gateway_mac((struct sockaddr *)&gateway, &hardaddr);
(gdb) shell cat ether    #用鼠标选择,把输出内容复制,然后再粘贴上来就可以了
step
step
step
step
step

(gdb) step
bind_gateway_mac (gwip=0xbfa10ef4, hwp=0xbfa10ee4) at de.c:215
215             sockfd = socket(AF_INET, SOCK_DGRAM, 0);
(gdb) step
216             if (sockfd < 0)
(gdb) step
219             sin = (struct sockaddr *)&arpreq.arp_pa;
(gdb) step
220             memcpy(sin, gwip, sizeof(struct sockaddr));
(gdb) step
221             sin->sa_family = AF_INET;
(gdb)

.........

就是先调用shell显示内容,然后在把显示的内容复制再粘贴到gdb中,
不过不能用快捷键了,CTRL+C是信号了。
你用鼠标好了。要是你的控制台不支持鼠标就没办法了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-11-6 09:42:14 | 显示全部楼层
呵呵,我现在就是这样的办法,每次都是复制很烦,所以想有没有什么办法,比如我在gdbinit中写个runfile.当在debug的时候,(gdb)runfile,就自动的shell cat ether,不用复制了,多么美好啊,呵呵
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表