淡泊明志、宁静致远
A Diamond is just a piece of Coal that did well under Pressure.
使用expect调用gdb实现自动调试程序
使用gdb调试程序时可以设置断点停在某一行、某个函数或者某个条件满足时停下。但是有时想匹配到一个任意的字符串时让程序停止。这个功能gdb中无法实现,但是借助expect可以实现自动化调试,设置好断点,然后让expect来捕获模式串,一旦获取到,即停止expect,控制权返回到gdb。
1
#
!/usr/bin/expect
2
#
####################################################################
3
#
File: Automatically debug program by gdb
4
#
Usage: Specify the expected string
5
#
6
#
Author: houcy
7
#
Date: 2010-01-29
8
#
Plan: Wrap a GUI window to make it user-friendly
9
#
10
#
Copyrights Reserved
11
#
####################################################################
12
13
if
{$argc
<
3
} {
14
send_user
"
Usage: $argv0 spectre netlist pattern1 pattern2
\r\n
"
15
exit
16
}
17
18
set timeout
120
19
set done
1
20
set num 0
21
22
#
get command line param
23
set spectre [lindex $argv 0]
24
set netlist [lindex $argv
1
]
25
26
#
set pattern array
27
for
{set i
2
} { $i
<
$argc } {incr i} {
28
set pattern($i) [lindex $argv $i]
29
puts $pattern($i)
30
}
31
32
#
start gdb process
33
spawn gdb $spectre
34
35
#
for expect debug
36
exp_internal 0
37
38
#
set some breakpoints
39
expect
"
(gdb)
"
{ send
"
b tranDoAnalysis\r
"
}
40
41
#
run program
42
expect
"
(gdb)
"
{ send
"
run $netlist\r
"
}
43
44
#
continue to run
45
expect
"
(gdb)
"
{ send
"
b aiEvaluateEHForSoa\r
"
}
46
expect
"
(gdb)
"
{ send
"
c\r
"
}
47
expect
"
(gdb)
"
{ send
"
b assertExpressionResult::evaluateExprs\r
"
}
48
expect
"
(gdb)
"
{ send
"
c\r
"
}
49
50
#
watch target string, or else continue
51
while
($done) {
52
for
{ set j
2
} { $j
<
$argc } {incr j} {
53
expect
"
$pattern($j)
"
{ send_user
"
Got $pattern($j) here! num=$num\r\n
"
; set done 0 ;
break
}
54
}
55
if
{ $done
==
0 } {
break
;}
56
expect {
57
"
(gdb)
"
{ send
"
c\r
"
; set num [expr $num
+
1
] ; send_user
"
num=$num\r\n
"
}
58
eof { send_user
"
It's the end! Bye!\r\n
"
}
59
timeout { send_user
"
Timeout, please check the reason!\r\n
"
}
60
}
61
}
62
63
#
back to gdb control
64
interact
65
运行程序:
1
bj2amdlnx20
>
.
/
gdb.exp spectre netlist sweepValue
=
1
.e
-
10
expect捕获到模式串,返回到gdb中:
1
(gdb) b assertExpressionResult::evaluateExprs
2
Breakpoint 3 at 0x8b57fe0: file assertInterface.cc, line 2174.
3
(gdb) c
4
Continuing.
5
6
Breakpoint 3, assertExpressionResult::evaluateExprs (sweepValue=1e-10, checklimitSeverity=0, violationDest=4 '\004',
7
Got sweepValue=1e-10 here! num=0
8
(gdb)
posted on 2010-02-02 09:46
挑灯看剑
阅读(1596)
评论(0)
编辑
收藏
引用
所属分类:
工作随笔
只有注册用户
登录
后才能发表评论。
Powered by:
IT博客
Copyright © 挑灯看剑
<
2010年2月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
导航
新随笔
管理
公告
【自我介绍】 08年南开大学硕士毕业 最近关注:算法、Linux、c++、高并发 爱好:滑旱冰、打乒乓球、台球、保龄球
常用链接
我的随笔
我的评论
我参与的随笔
随笔分类
(139)
algorithm(5)
(rss)
Android(4)
(rss)
C/C++(35)
(rss)
Linux内核驱动编程(14)
(rss)
Python(1)
(rss)
嵌入式系统开发(7)
(rss)
工作随笔(26)
(rss)
情感生活(14)
(rss)
数学(1)
(rss)
杂文(2)
(rss)
架构设计/设计模式(15)
(rss)
汇编艺术(3)
(rss)
英语(5)
(rss)
计算机经典书
(rss)
通信技术(7)
(rss)
文章分类
Linux kernel
(rss)
我常去的网站
南开大学bbs
水木BBS
技术博客(都是大牛)
Chris Lattner--LLVM的架构设计师
Hacker site
Marat Fayzullin--英特尔的高级项目经理,Emulator大牛
MVP Tips, Techniques, and Goodies
Vince Huston---设计模式
Walter Bright --D语言发明者、编译器大牛
编译器
技术站点
codeguru
codeproject
Emulator
How to develop your own Boot Loader
linuxsir
Microsoft--vc++ team
netexpert
osdev.org
osdever.net
planet-source-code
rohitab
wiki.osdev
搜索
积分与排名
积分 - 166363
排名 - 36