常规做法的用gdb调试
    
  1)文件列表:   
[root@localhost libketama]# ls -l
总计 200
-rw-r--r-- 1 1000 1000 12659 09-09 12:33 ketama.c
-rw-r--r-- 1 1000 1000 12653 09-09 12:04 ketama.c~
-rw-r--r-- 1 1000 1000  2972 2007-04-11 ketama.h
-rw-r--r-- 1 root root 22340 09-09 12:33 ketama.o
-rw-r--r-- 1 1000 1000  1574 09-09 12:15 ketama_test.c
-rw-r--r-- 1 1000 1000  1566 09-09 12:14 ketama_test.c~
-rwxr-xr-x 1 root root 31793 09-09 12:33 libketama.so
-rw-r--r-- 1 1000 1000   309 09-08 14:36 Makefile
-rw-r--r-- 1 1000 1000   250 2007-04-11 Makefile (复件)
-rw-r--r-- 1 1000 1000 12434 2007-03-30 md5.c
-rw-r--r-- 1 1000 1000  3516 2007-03-30 md5.h
-rw-r--r-- 1 root root 10600 09-09 12:33 md5.o
 
    
  2)Makefile的样子   
[root@localhost libketama]# cat ./Makefile
PREFIX=/usr/local
export LD_LIBRARY_PATH=/usr/local/ketama/libketama
build:
        gcc -g -fPIC -O3 -c md5.c
        gcc -g -fPIC -O3 -c ketama.c

        gcc -g -shared -o libketama.so ketama.o md5.o

install:
        @mkdir -p $(PREFIX)/lib
        @mkdir -p $(PREFIX)/include
        cp libketama.so $(PREFIX)/lib/
        cp ketama.h $(PREFIX)/include/
 
     
  4)设置LD_LIBRARY_PATH环境变量  
    在makefile文件中加入
export LD_LIBRARY_PATH=/usr/local/ketama/libketam/
    如果不如此,可将/usr/lib添加至搜索路径
    
  5)用GDB调试(step   in)   
[root@localhost libketama]# gdb ./run
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) break main
Breakpoint 1 at 0x8048575: file ketama_test.c, line 26.
(gdb) r
Starting program: /usr/local/ketama/libketama/run

Breakpoint 1, main () at ketama_test.c:26
26        ketama_roll( &c, "/usr/local/ketama/ketama.servers" );
(gdb) s  进入动态库
ketama_roll (contptr=0xbfb4e260,
    filename=0x80486d0 "/usr/local/ketama/ketama.servers") at ketama.c:347
347             strcpy( k_error, "" );
(gdb) next
357             key = ftok( filename, 'R' );
(gdb) next
358             if ( key == -1 )
(gdb)
 
    
next 单步调试

不过发现自己安装了Kdgb,习惯了VS调试,用起来比较熟悉,当然ddd也成

Logo

更多推荐