【 以下文字转载自 InstallBBS 讨论区 】
【 原文由 zhch.bbs@bbs.nju.edu.cn, 所发表 】
发信人: flyriver (飞流直下), 信区: BBSDEV
标 题: [技巧]GDB调试Firebird源代码的方法
发信站: UNIX编程 (2001年10月30日00:35:28 星期二), 站内信件
很久以前写的了, 那时使用的还是 bbsrf 方式的, 呵呵.
bbsd 方式的也差不多, 以后我再说怎么弄了. :-)
1. 修改main.c文件,首先找到main()函数,加上下面这几行代码:
int
main(argc, argv)
int argc ;
char **argv ;
{
char fname[STRLEN];
#ifdef BBS_INFOD
if (strstr( argv[ 0 ], "bbsinfo") != NULL) {
load_sysconf();
bbsinfod_main(argc, argv);
exit( 0 );
}
#endif
#ifdef BBS_GDB
chdir("/home/bbs");
#endif
load_sysconf();
if( argc < 2 || *argv[1] != 'h' ) {
printf( "You cannot execute this program directly.\n" );
.....................
2. 然后修改主Makefile文件(在src目录外面的那个), 分别找到
CFLAGS = -O2 -Wunused -I../include
CSIE_DEF = -DSHOW_IDLE_TIME -DWITHOUT_CHROOT
把他们注释掉,并改为下面的:
#CFLAGS = -O2 -Wunused -I../include # 注视掉原来的
CFLAGS = -ggdb -Wunused -I../include # 加上调试选项
#CSIE_DEF = -DSHOW_IDLE_TIME -DWITHOUT_CHROOT # 注视掉原来的
CSIE_DEF = -DBBS_GDB -DSHOW_IDLE_TIME -DWITHOUT_CHROOT # 定义BBS_GDB宏
3. 重新编译源代码
make clean
make
4. 进行调试
最好切换到root用户,用bbsuser应该也可以的。
# gdb bbs
GNU gdb 19991004
Copyright 1998 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 "i386-redhat-linux"...
(gdb) b main
Breakpoint 1 at 0x8053f8a: file main.c, line 913.
(gdb) r h localhost /dev/pts/2
Starting program: /home/bbs/bin/bbs h localhost /dev/pts/2
Breakpoint 1, main (argc=4, argv=0xbffffba4) at main.c:913
913 chdir("/home/bbs");
(gdb) n
915 load_sysconf();
...........
应该注意run命令是带有参数的,后面的参数会传给bbs程序。h没有什么实际
作用,但却是必须的参数。localhost表示你的来源,/dev/pts/2表示你现在
的pty。
至于gdb怎么使用就需要自己去学习了。:)
river
--
FROM feeling.dhs.org