AndroidAdvanceWithGeektime / Chapter06-plus

Hook Thread Sample
105 stars 34 forks source link

打印当前子线程的名字 #3

Closed trycatchx closed 2 years ago

trycatchx commented 3 years ago

如何打印当前子线程的名字?

trycatchx commented 3 years ago

我先这么解决了

void *thr_fn(void *arg){
    char pname[32] = {0};
    prctl(PR_GET_NAME, pname);
    pthread_t tid = -1;
    tid = pthread_self();
    ALOG("stack call name: = %s,tid = %lu", pname,tid);
    return ((void *)0);
}

int pthread_create_hook(pthread_t* thread, const pthread_attr_t* attr,
                            void* (*start_routine) (void *), void* arg) {
    pthread_t new_tid = -1;
    pthread_create(&new_tid, NULL, thr_fn, arg);
    pthread_join(new_tid,NULL);
    printJavaStack();
    int ret =  CALL_PREV(pthread_create_hook, thread, attr, *start_routine, arg);

    return ret;
}