debug 代码之1

debug_writev(iov, sizeof(iov) / sizeof(iov[0]) );


void debug_writev(  struct iovec* vecs, int count ) 
{  
    const char *buf;
    char debug_buf[128];
    int i,offset,len;

    for( ; count>0; count--,vecs++ ){
         buf = (const char *)vecs->iov_base;
         len = vecs->iov_len;
         while( 1 ){
           memset( debug_buf, 0x00, sizeof(debug_buf) );
           offset = 0x00;
           if( len < 16 ){
               for( i=0; i<len; i++ ){
                    offset += sprintf((char *)(debug_buf + offset), "%02X ", *buf++);
               }
               ALOGE("%s", debug_buf);
               break;
           }else{
               for( i=0; i<16; i++ ){
                    offset += sprintf((char *)(debug_buf + offset), "%02X ", *buf++);
               }
               ALOGE("%s", debug_buf); 
               len -= 16;    
           }
         }
    }
}

对于android c++代码 

想要知道函数的调用堆栈,可以使用abort();

函数把自己干死 

但是干死自己的时候 会输出函数的调用堆栈

当然 此法比较low逼

但是 stack.log("callstack");
      //libutilscallstack
     不是什么时候 都好使

比如当 android.bp为 

cc_library_static

时,死活编译过不去的

 #if 0
    char char_buff[12] = {'h','a','h',0}; 
    char *p_char = char_buff;
    void *handle;  
    void (*cosine)(void);  
    char *error;  
    //android:: CallStack   stack;
    void (*cosine1)(char *str,int);  
    LOG(INFO) << "btu_hci_msg_process";
    LOG(INFO) << "p_msg->event = "<< p_msg->event;
    handle = dlopen ("libutilscallstack.so", RTLD_NOW);      
    if (!handle) {          
         LOG(INFO) << "open lib fail";
    }        
    cosine = (void(*)(void))dlsym(handle, "_ZN7android9CallStackC2Ev");      
    if ((error = dlerror()) != NULL)  {          
         LOG(INFO) << "find fun fail4";
    }else{    
         LOG(INFO) << "find fun ok1";
         //cosine();
    }
    cosine1 = (void(*)(char *str,int))dlsym(handle, "_ZN7android9CallStackC2EPKci");      
    if ((error = dlerror()) != NULL)  {          
         LOG(INFO) << "find fun fail4";
    }else{    
         LOG(INFO) << "find fun ok2";
         cosine1(p_char, 1);
    }
    (void)p_char;

    LOG(INFO) << "find fun ok2234";
    dlclose(handle);
    #endif

想着动态库方式调用 CallStack,以上为尝试代码,最终没有成功

能找到方法,c语言找到方法调用就好了,但是c++

暂时还没有想到法子。。。。。。

主要就是 怎么new一个新类出来的问题。。。???

    

    
    //abort();
    //android::CallStack cs("haha");
    //android:: CallStack      stack;    
    //stack.update();    
    //stack.log("callstack");
    //libutilscallstack
    //debug_stamp
      

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值