linux动态库的调试

常规做法的用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也成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值