xxgdb 是 gdb 的一個基于 X Window 系統(tǒng)的圖形界面. xxgdb 包括了命令行版的 gdb 上的所有特性. xxgdb 使你能通過按按鈕來執(zhí)行常用的命令. 設置了斷點的地方也用圖形來顯示.
你能用 gdb 里任何有效的命令行選項來初始化 xxgdb . 此外 xxgdb 也有一些特有的命令行選項, 表 27.2 列出了這些選項.
db_name 指定所用調(diào)試器的名字, 缺省是 gdb.?
db_prompt 指定調(diào)試器提示符, 缺省為 gdb.?
gdbinit 指定初始化 gdb 的命令文件的文件名, 缺省為 .gdbinit.
bigicon 使用大圖標.
你可以在 sunsite.unc.edu FTP 站點用下面的路徑:?
/pub/Linux/devel/lang/c/calls.tar.Z?
來取得 calls , 一些舊版本的 Linux CD-ROM 發(fā)行版里也附帶有. 因為它是一個有用的工具, 我們在這里也介紹一下. 如果你覺得有用的話, 從 BBS, FTP, 或另一張CD-ROM 上弄一個拷貝. calls 調(diào)用 GCC 的預處理器來處理給出的源程序文件, 然后輸出這些文件的里的函數(shù)調(diào)用樹圖.
--
如果函數(shù)并不是向 calls 給出的文件里的, calls 不知道所調(diào)用的函數(shù)來自哪里, 則只顯示函數(shù)的名字:
calls 不對遞歸和靜態(tài)函數(shù)輸出. 遞歸函數(shù)顯示成下面的樣子:
靜態(tài)函數(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 有很多命令行選項來設置不同的輸出格式, 有關這些選項的更多信息請參考 calls 的指南頁. 方法是在命令行上鍵入 calls -h .
calltree與calls類似,初了輸出函數(shù)調(diào)用樹圖外,還有其它詳細的信息。可以從sunsite.unc.edu FTP 站點用下面的路徑?
:/pub/Linux/devel/lang/c/calltree.tar.gz得到calltree.
cproto 讀入 C 源程序文件并自動為每個函數(shù)產(chǎn)生原型申明. 用 cproto 可以在寫程序時為你節(jié)省大量用來定義函數(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] = '';
}?
你將得到下面的輸出:
這個輸出可以重定向到一個定義函數(shù)原型的包含文件里.
indent 實用程序是 Linux 里包含的另一個編程實用工具. 這個工具簡單的說就為你的代碼產(chǎn)生美觀的縮進的格式. indent 也有很多選項來指定如何格式化你的源代碼.這些選項的更多信息請看indent 的指南頁, 在命令行上鍵入 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] = '';
}?
運行 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 并不改變代碼的實質(zhì)內(nèi)容, 而只是改變代碼的外觀. 使它變得更可讀, 這永遠是一件好事.
gprof 是安裝在你的 Linux 系統(tǒng)的 /usr/bin 目錄下的一個程序. 它使你能剖析你的程序從而知道程序的哪一個部分在執(zhí)行時最費時間.
參數(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í)行時間的百分比
seconds (包括此函數(shù)調(diào)用其它函數(shù)花費的時間)
seconds (調(diào)用其它函數(shù)花費的時間不計算在內(nèi))
us/call
us/call 花費的微秒時間
count_sum()函數(shù),所以累計秒數(shù)為0.13.
評論