android bionic log打印,如何让android的bionic中的linker输出调试信息

缺省情况下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了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值