tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

using backtrace(3) in libpthread



Hi

I would like to obtain a backtrace using libexecinfo in 
pthread_key_create() and pthread_key_delete(). I installed libexecinfo
from pkgsrc and added the code below at the end of the two functions.

I use snprintf()/syslog() because pthread__errorfunc() has comments
telling this is the way to go to avoid deadlocks.... but I still deadlock. 
Any idea how this should be done?

        {
                void *bt[BT_DEPTH];
                char **btstr;
                int depth; 
                char buf[4096];
                size_t len = 0;
                int j;
 
                len += snprintf(buf + len, sizeof(buf) - len, "*** %s ***\n",
                                __func__);
                depth = backtrace(bt, BT_DEPTH);
                btstr = backtrace_symbols(bt, depth);
                for (j = 0; j < depth; j++) {
                        len += snprintf(buf + len, 
                                        sizeof(buf) - len, "#%d %s\n",
                                        j, btstr[j]);
                }

                syslog(LOG_ERR | LOG_USER, "%s", buf);
        }

-- 
Emmanuel Dreyfus
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index