ITPub博客

调试工具dbx

原创 作者:palmlearn 时间:2008-08-14 23:11:33 0 删除 编辑
  1. dbx用途
  2. dbx必要性
  3. dbx启动方法
  4. dbx基本命令
  5. 一个例子
[@more@]

  • dbx用途

l 查找,跟踪,特定,排除程序bug的辅助工具。

l 揭示程序运行期间的动态性质的工具。

  • dbx必要性

l 程序编译正确,生成的执行文件不能达到想定的结果时,利用调试工具可以有效地找出问题点,提高测试效率。

  • dbx启动方法

l dbx program_name

ü program_name进行debug

ü 编译选项 -g 把必要的调试信息符号加入目文件,是必须的。

ü 编译器要用cc gcc 不可

ü : cc -g sample.c -o sample

ü dbx ./sample

  • dbx基本命令

l run

ü 执行程序

l runargs

ü 执行参数设定

l runargs

ü 执行参数清空

l stop at

ü 指定行加断点

l stop in

ü 指定函数加断点

l cont

ü 让程序执行到下一个断点

l rerun

ü 让程序从新执行

l next

ü 让程序执行下一行

l next

ü 执行nnext

l step

ü 让程序执行下一行

ü 下一行如果是函数的话,进入函数

l step

ü 执行 n step

l dump

ü 表示当前所在函数的全部内部变量和值

l display 变量

ü 指定监视变量

ü 变量如果是数组,可以用变量[下标1..下标2]来指定要监视数组成员的范围

ü 每走到一个断点,监视变量就会自动重新表示

l display

ü 表示当前所有监视变量

一个例子

[4:20pm] palmlearn >ls
sample.c
[4:20pm] palmlearn >view *sample.c

"sample.c" [読み取り専用] 50 行、1174 バイト
1 #include
2 #include
3 static char cVar1[4+1];
4 static char cVar2[4+1];
5 static char cVar3[4+1];
6
7 void setVals(char**);
8
9 int main(int argc, char *argv[])
10 {
11 int i;
12 if( argc != 4 )
13 {
14 printf("Usage: sample char1 char2 char3n");
15 return -1;
16 }
17 for(i=0;i 18 {
19 printf("argv[%d] = [%s]n",i,argv[i]);
20 }
21 memset(cVar1,0x00,sizeof(cVar1));
22 memset(cVar2,0x00,sizeof( cVar2));
23 memset(cVar3,0x00,sizeof(cVar3));
24
25 printf("address of cVar1 = [%x]n",&cVar1);
26 printf("address of cVar2 = [%x]n",&cVar2);
27 printf("address of cVar3 = [%x]n",&cVar3);
28
29 printf("--call setVals Start--n");
30 setVals(argv);
31 printf("--call setVals End --n");
32
33 return 0;
34 }
35 void setVals(char* argv[])
36 {
37 strncpy(cVar3,argv[3],sizeof(cVar3));
38 printf("cVar1 = [%s]n",cVar1);
39 printf("cVar2 = [%s]n",cVar2);
40 printf("cVar3 = [%s]n",cVar3);
41 strncpy(cVar2,argv[2],sizeof(cVar2));
42 printf("cVar1 = [%s]n",cVar1);
43 printf("cVar2 = [%s]n",cVar2);
44 printf("cVar3 = [%s]n",cVar3);
45 strncpy(cVar1,argv[1],sizeof(cVar1));
46 printf("cVar1 = [%s]n",cVar1);
47 printf("cVar2 = [%s]n",cVar2);
48 printf("cVar3 = [%s]n",cVar3);
49
50 }
~
:q
[4:20pm] palmlearn >cc -g sample.c -o sample
[4:20pm] palmlearn >dbx sample
sample の読み込み中
ld.so.1 の読み込み中
libc.so.1 の読み込み中
libdl.so.1 の読み込み中
libc_psr.so.1 の読み込み中
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) runargs chr1 chr2 chr3
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) debug
デバッグ: sample chr1 chr2 chr3
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) stop in setVals
(2) stop in setVals
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) stop at 12
(3) stop at "sample.c":12
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) status
(2) stop in setVals
(3) stop at "sample.c":12
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) display cVar3
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) display cVar3[0..4]
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) display cVar2[0..4]
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) display &cVar1
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) display
(1) cVar3
(2) cVar3[0..4]
(3) cVar2[0..4]
(4) &cVar1
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) run
実行中: sample chr1 chr2 chr3
(プロセス id 5904)
main で停止しました 行番号 12 ファイル "sample.c"
12 if( argc != 4 )
cVar3 = ""
cVar3[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
cVar2[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
&cVar1 = 0x20fd8
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) step
main で停止しました 行番号 17 ファイル "sample.c"
17 for(i=0;icVar3 = ""
cVar3[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
cVar2[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
&cVar1 = 0x20fd8
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) cont
argv[0] = [/export/home/palmlearn/sample/sample]
argv[1] = [chr1]
argv[2] = [chr2]
argv[3] = [chr3]
address of cVar1 = [20fd8]
address of cVar2 = [20fdd]
address of cVar3 = [20fe2]
--call setVals Start--
setVals で停止しました 行番号 37 ファイル "sample.c"
37 strncpy(cVar3,argv[3],sizeof(cVar3));
cVar3 = ""
cVar3[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
cVar2[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
&cVar1 = 0x20fd8
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) print &cVar3
&cVar3 = 0x20fe2
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) cont
cVar1 = []
cVar2 = []
cVar3 = [chr3]
cVar1 = []
cVar2 = [chr2]
cVar3 = [chr3]
cVar1 = [chr1]
cVar2 = [chr2]
cVar3 = [chr3]
--call setVals End --

実行完了。終了コードは、0 です
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) debug
デバッグ: sample chr1 chr2 chr3
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) runargs
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) debug
デバッグ: sample
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) run aaaaaaaa bbbbb cccccc
実行中: sample aaaaaaaa bbbbb cccccc
(プロセス id 5908)
main で停止しました 行番号 12 ファイル "sample.c"
12 if( argc != 4 )
cVar3 = ""
cVar3[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
cVar2[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
&cVar1 = 0x20fd8
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) cont
argv[0] = [/export/home/palmlearn/sample/sample]
argv[1] = [aaaaaaaa]
argv[2] = [bbbbb]
argv[3] = [cccccc]
address of cVar1 = [20fd8]
address of cVar2 = [20fdd]
address of cVar3 = [20fe2]
--call setVals Start--
setVals で停止しました 行番号 37 ファイル "sample.c"
37 strncpy(cVar3,argv[3],sizeof(cVar3));
cVar3 = ""
cVar3[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
cVar2[0..4] =
[0] = '
[1] = '
[2] = '
[3] = '
[4] = '
&cVar1 = 0x20fd8
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx) cont
cVar1 = []
cVar2 = []
cVar3 = [ccccc]
cVar1 = []
cVar2 = [bbbbbccccc]
cVar3 = [ccccc]
cVar1 = [aaaaabbbbbccccc]
cVar2 = [bbbbbccccc]
cVar3 = [ccccc]
--call setVals End --

実行完了。終了コードは、0 です
(/opt/SUNWspro/bin/../WS6U2/bin/sparcv9/dbx)

上一篇: 東二摄绘
请登录后发表评论 登录
全部评论

注册时间:2007-12-18

  • 博文量
    11
  • 访问量
    158568