xxgdb 是 gdb 的一個(gè)基于 X Window 系統(tǒng)的圖形界面. xxgdb 包括了命令行版的 gdb 上的所有特性. xxgdb 使你能通過按按鈕來(lái)執(zhí)行常用的命令. 設(shè)置了斷點(diǎn)的地方也用圖形來(lái)顯示.
你能用 gdb 里任何有效的命令行選項(xiàng)來(lái)初始化 xxgdb . 此外 xxgdb 也有一些特有的命令行選項(xiàng), 表 27.2 列出了這些選項(xiàng).
db_name 指定所用調(diào)試器的名字, 缺省是 gdb.?
db_prompt 指定調(diào)試器提示符, 缺省為 gdb.?
gdbinit 指定初始化 gdb 的命令文件的文件名, 缺省為 .gdbinit.
bigicon 使用大圖標(biāo).
你可以在 sunsite.unc.edu FTP 站點(diǎn)用下面的路徑:?
/pub/Linux/devel/lang/c/calls.tar.Z?
來(lái)取得 calls , 一些舊版本的 Linux CD-ROM 發(fā)行版里也附帶有. 因?yàn)樗且粋€(gè)有用的工具, 我們?cè)谶@里也介紹一下. 如果你覺得有用的話, 從 BBS, FTP, 或另一張CD-ROM 上弄一個(gè)拷貝. calls 調(diào)用 GCC 的預(yù)處理器來(lái)處理給出的源程序文件, 然后輸出這些文件的里的函數(shù)調(diào)用樹圖.
--
如果函數(shù)并不是向 calls 給出的文件里的, calls 不知道所調(diào)用的函數(shù)來(lái)自哪里, 則只顯示函數(shù)的名字:
calls 不對(duì)遞歸和靜態(tài)函數(shù)輸出. 遞歸函數(shù)顯示成下面的樣子:
靜態(tài)函數(shù)象這樣顯示:
作為一個(gè)例子, 假設(shè)用 calls 處理下面的程序:
static void my_print2 (char *);
{?
char my_string[] = "hello world!";?
my_print (my_string);?
my_print2 (my_string);?
my_print (my_string);?
}
{?
int i,sum=0;?
for(i=0; i<1000000; i++)?
sum += i;?
}
{?
count_sum();?
("The string is %s ", string);?
}
{?
char *string2;?
int size, i,sum =0;
}?
將產(chǎn)生如下的輸出:
2 main?
3 my_print [hello.c]?
4 count_sum [hello.c]?
5 printf?
6 my_print2 [hello.c]?
7 count_sum?
8 strlen?
9 malloc?
10 printf?
calls 有很多命令行選項(xiàng)來(lái)設(shè)置不同的輸出格式, 有關(guān)這些選項(xiàng)的更多信息請(qǐng)參考 calls 的指南頁(yè). 方法是在命令行上鍵入 calls -h .
calltree與calls類似,初了輸出函數(shù)調(diào)用樹圖外,還有其它詳細(xì)的信息。可以從sunsite.unc.edu FTP 站點(diǎn)用下面的路徑?
:/pub/Linux/devel/lang/c/calltree.tar.gz得到calltree.
cproto 讀入 C 源程序文件并自動(dòng)為每個(gè)函數(shù)產(chǎn)生原型申明. 用 cproto 可以在寫程序時(shí)為你節(jié)省大量用來(lái)定義函數(shù)原型的時(shí)間.?
如果你讓 cproto 處理下面的代碼(cproto hello.c):
static void my_print2 (char *);
{?
char my_string[] = "hello world!";?
my_print (my_string);?
my_print2 (my_string);?
}
{?
printf ("The string is %s ", string);?
}
{?
char *string2;?
int size, i;
string2 = (char *) malloc (size + 1);?
for (i = 0; i < size; i++)?
string2[size -1 - i] = string;?
string2[size] = '';
}?
你將得到下面的輸出:
這個(gè)輸出可以重定向到一個(gè)定義函數(shù)原型的包含文件里.
indent 實(shí)用程序是 Linux 里包含的另一個(gè)編程實(shí)用工具. 這個(gè)工具簡(jiǎn)單的說(shuō)就為你的代碼產(chǎn)生美觀的縮進(jìn)的格式. indent 也有很多選項(xiàng)來(lái)指定如何格式化你的源代碼.這些選項(xiàng)的更多信息請(qǐng)看indent 的指南頁(yè), 在命令行上鍵入 indent -h .
static void my_print2 (char *);
{?
char my_string[] = "hello world!";?
my_print (my_string);?
my_print2 (my_string);?
}
{?
printf ("The string is %s ", string);?
}
{?
char *string2; int size, i;
string2 = (char *) malloc (size + 1);?
for (i = 0; i < size; i++) string2[size -1 - i] = string;?
string2[size] = '';
}?
運(yùn)行 indent 后的 C 代碼:
static void my_print (char *);?
static void my_print2 (char *);?
main ()?
{?
char my_string[] = "hello world!";?
my_print (my_string);?
my_print2 (my_string);?
}?
void?
my_print (char *string)?
{?
printf ("The string is %s ", string);?
}?
void?
my_print2 (char *string)?
{?
char *string2;?
int size, i;?
size = strlen (string);?
string2 = (char *) malloc (size + 1);?
for (i = 0; i < size; i++)?
string2[size - 1 - i] = string;?
string2[size] = '';?
printf ("The string printed backward is %s ", string2);?
}?
indent 并不改變代碼的實(shí)質(zhì)內(nèi)容, 而只是改變代碼的外觀. 使它變得更可讀, 這永遠(yuǎn)是一件好事.
gprof 是安裝在你的 Linux 系統(tǒng)的 /usr/bin 目錄下的一個(gè)程序. 它使你能剖析你的程序從而知道程序的哪一個(gè)部分在執(zhí)行時(shí)最費(fèi)時(shí)間.
參數(shù) program_name 是產(chǎn)生 gmon.out 文件的程序的名字.
static void my_print2 (char *);
{?
char my_string[] = "hello world!";?
my_print (my_string);?
my_print2 (my_string);?
my_print (my_string);?
}
{?
int i,sum=0;?
for(i=0; i<1000000; i++)?
sum += i;?
}
{?
count_sum();?
printf ("The string is %s ", string);?
}
{?
char *string2;?
int size, i,sum =0;
size = strlen (string);?
string2 = (char *) malloc (size + 1);?
for (i = 0; i < size; i++) string2[size -1 - i] = string;?
string2[size] = '';?
for(i=0; i<5000000; i++)?
sum += i;
}?
$ gcc -pg -o hello hello.c?
$ ./hello?
$ gprof hello | more?
將產(chǎn)生以下的輸出?
Flat profile:
% cumulative self self total?
time seconds seconds calls us/call us/call name?
69.23 0.09 0.09 1 90000.00 103333.33 my_print2?
30.77 0.13 0.04 3 13333.33 13333.33 count_sum?
0.00 0.13 0.00 2 0.00 13333.33 my_print
time 執(zhí)行時(shí)間的百分比
seconds (包括此函數(shù)調(diào)用其它函數(shù)花費(fèi)的時(shí)間)
seconds (調(diào)用其它函數(shù)花費(fèi)的時(shí)間不計(jì)算在內(nèi))
us/call
us/call 花費(fèi)的微秒時(shí)間
count_sum()函數(shù),所以累計(jì)秒數(shù)為0.13.
評(píng)論