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