Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1830886
  • 博文数量: 241
  • 博客积分: 9862
  • 博客等级: 中将
  • 技术积分: 5206
  • 用 户 组: 普通用户
  • 注册时间: 2005-02-18 23:23
文章分类
文章存档

2011年(14)

2010年(61)

2009年(48)

2008年(118)

我的朋友

分类: LINUX

2010-06-08 17:09:41

缺省情况下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) |
给主人留下些什么吧!~~