Note that there are some explanatory texts on larger screens.

plurals
  1. POPthread library initialization
    text
    copied!<p>I have created wrappers around the pthread functions using dlopen and dlsym, in order to debug and profile some issues occurring in my application. The profiler passes all of the unit tests. Unfortunately, it appears that I have bypassed some library initialization because getenv now returns null to all input. If I remove the profiler, the proper operation of getenv returns.</p> <p>I believe that the issue is that the compiler has not linked in Libpthread because it does not see any symbols requested from the library at link time. I have looked through the glib source but have not found an obvious run time initialization function that I can load and execute with dlsym.</p> <p>I have stepped into getenv and found that __environ=null with the overrides compiled in. However, environ contains the proper values. __environ has the proper variables after removing the profiler.</p> <p>Also, getenv appears to work with the pthread overrides on Ubuntu 10.04, with glibc 2.11. Unfortunately, upgrading is not an appealing option due to existing product distribution. </p> <p>Linux 2.6.31 Glib 2.5</p> <p>My init code:</p> <pre><code>inline int init_pthreads_debugger(void) { static int recursion=0; if(!real_pthread_create) { // we know that we are single threaded here, because we override pthread_create and // call this function. Therefore, recursion does not have to be guarded. if(recursion) { return 0; } recursion = 1; init_heap(); void * handle = dlopen("libpthread.so.0",RTLD_NOW); real_pthread_cond_timedwait =(real_pthread_cond_timedwait_t)dlsym(handle,"pthread_cond_timedwait"); // more pthread initialization functions here. //do me last to make sure any recursion in dlsym/dlopen is caught real_pthread_create =(real_pthread_create_t)dlsym(handle,"pthread_create"); recursion = 0; } return 1; } //an example override int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t * m, const struct timespec * t) { if(!init_pthreads_debugger()) return 0; //no thread, no sync needed. int ret; int condition_count; ptd_note_unblock((void *)m,&amp;condition_count); ret=real_pthread_cond_timedwait(c,m,t); ptd_note_block((void *)m,&amp;condition_count); return ret; } </code></pre> <p>thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload