阅读 35

使用Qt Creator作为Linux IDE,实现Redis源码编译和断点调试

1、相关的Linux和Qt环境搭建,请先看链接,姊妹篇《使用Qt Creator作为Linux IDE,实现Nginx源码编译和断点调试

2、源码准备

使用黄建宏的带中文注释的版本,github.com/huangz1990/…

我们解压源码,先使用gcc编译,主要目的是把deps库编译出来

[root@localhost redis_study]# chmod -R 777 redis-3.0-annotated-unstable
[root@localhost redis_study]# cd redis-3.0-annotated-unstable/
[root@localhost redis-3.0-annotated-unstable]# make
3、和nginx源码不同,redis的结构更复杂,因为nginx的编译结果是单一的执行文件,而redis会生成N多个执行文件:

redis-server

redis-cli

redis-benchmark

redis-check-aof

redis-check-dump

redis-sentinel

所以,我们新建的Qt Creator必须是多个子项目类型:

4、redisQtProject.pro,firecat这里只关注最主要的redis-server和redis-cli两个执行程序

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += \
    redis-server \
    redis-cli
复制代码

common.pri,因为前面已经把deps的库编译好了,这里只需要添加库依赖即可


isEmpty(PREFIX_SRC) {
    PREFIX_SRC = ../../src
}

isEmpty(PREFIX_DEPS) {
    PREFIX_DEPS = ../../deps
}

LIBS = -ldl -lpthread -lcrypt -lpcre -lz
LIBS += "$$PREFIX_DEPS/hiredis/libhiredis.a"
LIBS += "$$PREFIX_DEPS/lua/src/liblua.a"

INCLUDEPATH += \
    #$$PREFIX_SRC/ \
    $$PREFIX_DEPS/hiredis \
    #$$PREFIX_DEPS/hiredis/adapters \
    $$PREFIX_DEPS/jemalloc/include/ \
    $$PREFIX_DEPS/jemalloc/include/jemalloc/internal \
    #$$PREFIX_DEPS/jemalloc/include/msvc_compat \
    $$PREFIX_DEPS/linenoise \
    $$PREFIX_DEPS/lua/src \
    $$PREFIX_DEPS/lua/etc

HEADERS += \
    $$PREFIX_SRC/adlist.h \
    $$PREFIX_SRC/ae.h \
    $$PREFIX_SRC/anet.h \
    $$PREFIX_SRC/asciilogo.h \
    $$PREFIX_SRC/bio.h \
    $$PREFIX_SRC/cluster.h \
    $$PREFIX_SRC/config.h \
    $$PREFIX_SRC/crc64.h \
    $$PREFIX_SRC/dict.h \
    $$PREFIX_SRC/endianconv.h \
    $$PREFIX_SRC/fmacros.h \
    $$PREFIX_SRC/help.h \
    $$PREFIX_SRC/intset.h \
    $$PREFIX_SRC/lzf.h \
    $$PREFIX_SRC/lzfP.h \
    $$PREFIX_SRC/pqsort.h \
    $$PREFIX_SRC/rand.h \
    $$PREFIX_SRC/rdb.h \
    $$PREFIX_SRC/redis.h \
    $$PREFIX_SRC/redisassert.h \
    $$PREFIX_SRC/release.h \
    $$PREFIX_SRC/rio.h \
    $$PREFIX_SRC/sds.h \
    $$PREFIX_SRC/sha1.h \
    $$PREFIX_SRC/slowlog.h \
    $$PREFIX_SRC/solarisfixes.h \
    $$PREFIX_SRC/testhelp.h \
    $$PREFIX_SRC/util.h \
    $$PREFIX_SRC/version.h \
    $$PREFIX_SRC/ziplist.h \
    $$PREFIX_SRC/zipmap.h \
    $$PREFIX_SRC/zmalloc.h \
    $$PREFIX_DEPS/linenoise/linenoise.h
复制代码

redis-server.pro

TARGET = redis-server

include(../common.pri)

SOURCES += \
    $$PREFIX_SRC/adlist.c \
    $$PREFIX_SRC/ae.c \
    $$PREFIX_SRC/ae_epoll.c \
    $$PREFIX_SRC/ae_evport.c \
    $$PREFIX_SRC/ae_kqueue.c \
    $$PREFIX_SRC/ae_select.c \
    $$PREFIX_SRC/anet.c \
    $$PREFIX_SRC/aof.c \
    $$PREFIX_SRC/bio.c \
    $$PREFIX_SRC/bitops.c \
    $$PREFIX_SRC/blocked.c \
    $$PREFIX_SRC/cluster.c \
    $$PREFIX_SRC/config.c \
    $$PREFIX_SRC/crc16.c \
    $$PREFIX_SRC/crc64.c \
    $$PREFIX_SRC/db.c \
    $$PREFIX_SRC/debug.c \
    $$PREFIX_SRC/dict.c \
    $$PREFIX_SRC/endianconv.c \
    $$PREFIX_SRC/hyperloglog.c \
    $$PREFIX_SRC/intset.c \
    $$PREFIX_SRC/lzf_c.c \
    $$PREFIX_SRC/lzf_d.c \
    $$PREFIX_SRC/memtest.c \
    $$PREFIX_SRC/multi.c \
    $$PREFIX_SRC/networking.c \
    $$PREFIX_SRC/notify.c \
    $$PREFIX_SRC/object.c \
    $$PREFIX_SRC/pqsort.c \
    $$PREFIX_SRC/pubsub.c \
    $$PREFIX_SRC/rand.c \
    $$PREFIX_SRC/rdb.c \
    #$$PREFIX_SRC/redis-benchmark.c \
    #$$PREFIX_SRC/redis-check-aof.c \
    #$$PREFIX_SRC/redis-check-dump.c \
    #$$PREFIX_SRC/redis-cli.c \
    #$$PREFIX_SRC/redis.c \
    $$PREFIX_SRC/release.c \
    $$PREFIX_SRC/replication.c \
    $$PREFIX_SRC/rio.c \
    $$PREFIX_SRC/scripting.c \
    $$PREFIX_SRC/sds.c \
    $$PREFIX_SRC/sentinel.c \
    $$PREFIX_SRC/setproctitle.c \
    $$PREFIX_SRC/sha1.c \
    $$PREFIX_SRC/slowlog.c \
    $$PREFIX_SRC/sort.c \
    $$PREFIX_SRC/syncio.c \
    $$PREFIX_SRC/t_hash.c \
    $$PREFIX_SRC/t_list.c \
    $$PREFIX_SRC/t_set.c \
    $$PREFIX_SRC/t_string.c \
    $$PREFIX_SRC/t_zset.c \
    $$PREFIX_SRC/util.c \
    $$PREFIX_SRC/ziplist.c \
    $$PREFIX_SRC/zipmap.c \
    $$PREFIX_SRC/zmalloc.c \
    $$PREFIX_DEPS/linenoise/linenoise.c

SOURCES += \
    $$PREFIX_SRC/redis.c
复制代码

redis-cli.pro文件类似,这里不再赘述。

5、我们终于可以执行断点调试,大功告成!

6、附录:完整的Qt工程源码下载

download.csdn.net/download/li…

 

 

文章分类
代码人生
文章标签