LD_DEUBG 调试动态库加载

本文深入探讨了LD_DEBUG环境变量的功能,解释了如何通过设置此变量来调试glibc的loader在动态库加载过程中的行为。详细介绍了变量的不同选项以及它们在调试动态库加载过程中的作用。

我们知道ldd开查看程序依赖的 动态库 已经 为解决的符号。但运行时加载过程去没有办法知道。这就需要用到LD_DEBUG

 

LD_DEBUG 是 glibc 的 loader 为了调试而设置的一个环境变量。

通过设置这个环境变量,可以调试动态库的 加载过程。

设置 LD_DEBUG 环境变量获得更多信息:

$ LD_DEBUG=help ls

Valid options for the LD_DEBUG environment variable are:

libs        display library search paths

reloc       display relocation processing

files       display progress for input file

symbols     display symbol table processing

bindings    display information about symbol binding

versions    display version dependencies

all         all previous options combined

statistics  display relocation statistics

unused      determined unused DSOs

help        display this help message and exit

To direct the debugging output into a file instead of standard output

a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

转载于:https://www.cnblogs.com/napoleon_liu/archive/2011/02/16/1956400.html

DEUBG = -D_DEBUG TARGET1 = rtsp_server TARGET2 = rtsp_pusher TARGET3 = rtsp_h264_file TARGET4 := librtsp_server_gb.a OBJS_PATH = objs #CROSS_COMPILE = CXX = $(CROSS_COMPILE)g++ CC = $(CROSS_COMPILE)gcc STRIP = $(CROSS_COMPILE)strip INC = -I$(shell pwd)/src/ -I$(shell pwd)/src/net -I$(shell pwd)/src/xop -I$(shell pwd)/src/3rdpart -Iexample LIB = #LD_FLAGS = -lrt -pthread -lpthread -ldl -lm $(DEBUG) LD_FLAGS = -lrt -pthread -lpthread -ldl -lm -fPIC CXX_FLAGS = -std=c++11 -O1 -fPIC \ -ffile-prefix-map=$(PWD)=. \ -fdebug-prefix-map=$(PWD)=. O_FLAG = -O1 SRC1 = $(notdir $(wildcard ./src/net/*.cpp)) OBJS1 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC1)) SRC2 = $(notdir $(wildcard ./src/xop/*.cpp)) OBJS2 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC2)) SRC3 = $(notdir $(wildcard ./example/rtsp_server.cpp)) OBJS3 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC3)) SRC4 = $(notdir $(wildcard ./example/rtsp_pusher.cpp)) OBJS4 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC4)) SRC5 = $(notdir $(wildcard ./example/rtsp_h264_file.cpp)) OBJS5 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC5)) SRC6 = $(notdir $(wildcard ./example/RtspServerApp.cpp)) OBJS6 = $(patsubst %.cpp,$(OBJS_PATH)/%.o,$(SRC6)) all: BUILD_DIR $(TARGET1) $(TARGET2) $(TARGET3) $(TARGET4) lib: BUILD_DIR $(TARGET4) install: @mkdir -p ../lib @cp -rf $(TARGET4) ../lib BUILD_DIR: @-mkdir -p $(OBJS_PATH) $(TARGET1) : $(OBJS1) $(OBJS2) $(OBJS3) $(CXX) $^ -o $@ $(CFLAGS) $(LD_FLAGS) $(CXX_FLAGS) $(TARGET2) : $(OBJS1) $(OBJS2) $(OBJS4) $(CXX) $^ -o $@ $(CFLAGS) $(LD_FLAGS) $(CXX_FLAGS) $(TARGET3) : $(OBJS1) $(OBJS2) $(OBJS5) $(CXX) $^ -o $@ $(CFLAGS) $(LD_FLAGS) $(CXX_FLAGS) $(TARGET4) : $(OBJS1) $(OBJS2) $(OBJS6) $(AR) $(ARFLAGS) $@ $^ $(OBJS_PATH)/%.o : ./example/%.cpp $(CXX) -c $< -o $@ $(CXX_FLAGS) $(INC) $(OBJS_PATH)/%.o : ./src/net/%.cpp $(CXX) -c $< -o $@ $(CXX_FLAGS) $(INC) $(OBJS_PATH)/%.o : ./src/xop/%.cpp $(CXX) -c $< -o $@ $(CXX_FLAGS) $(INC) clean: -rm -rf $(OBJS_PATH) $(TARGET1) $(TARGET2) $(TARGET3) $(TARGET4) 优化当前makefile脚本,使其静态库里面没有编译路径存在,提供完整脚本
08-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值