缺省情况下bionic的linker是不会输出调试信息的,因为Linker.c里一开始就写着:
* Do NOT use malloc() and friends or pthread_*() code here.
* Don't use printf() either; it's caused mysterious memory
* corruption in the past.
* The linker runs before we bring up libc and it's easiest
* to make sure it does not depend on any complex libc features
而他的调试信息基本都是printf到stdout的。
所以要改下面几个地方:
1、linker_debug.h中的#define LINKER_DEBUG和#define TRACE_DEBUG都改为1。
2、linker.c中的
#define HOODLUM(name, ret, ...) \
ret name __VA_ARGS__ \
{ \
char errstr[] = "ERROR: " #name " called from the dynamic linker!\n"; \
write(2, errstr, sizeof(errstr)); \
abort(); \
}
HOODLUM(malloc, void *, (size_t size));
HOODLUM(free, void, (void *ptr));
HOODLUM(realloc, void *, (void *ptr, size_t size));
HOODLUM(calloc, void *, (size_t cnt, size_t size));
这一段注释掉。
3、Android.mk中的LOCAL_STATIC_LIBRARIES := libcutils libc_nomalloc改成
LOCAL_STATIC_LIBRARIES := libcutils libc。
原因是bionic的libc的android.mk中的一段话:
# ========================================================
# libc_nomalloc.a
# ========================================================
#
# This is a version of the static C library that does not
# include malloc. It's useful in situations when calling
# the user wants to provide their own malloc implementation,
# or wants to explicitly disallow the use of the use of malloc,
# like the dynamic loader.
所以缺省的linker自己实现了malloc,free,realloc,calloc几个函数(2中说的),调用这几个函数
就输出错误信息然后退出了。
4、重新编译linker,上传到模拟器或实际设备,export DEBUG=3,然后执行命令就看到linker输出的log了。
阅读(5396) | 评论(0) | 转发(0) |