Is there any (evidently non-portable) way of determining a function instance's return address? I have an idea or two that involves the return address and dladdr(). The code I currently use looks like this:
int log_print(log_t *log, char *fmt, ...) { char date[32], str[MAX_LOG_LINE]; struct iovec iov[10]; Dl_info info; size_t len; va_list ap; int n; len = log_makedate(date, sizeof date); iov[n=0].iov_base = date; iov[n].iov_len = len; if (dladdr(*(((void**)&log)-1), &info) == 0) iov[++n].iov_base = "(unknown)"; else iov[++n].iov_base = (char *)info.dli_sname; iov[n].iov_len = strlen(iov[n].iov_base); iov[++n].iov_base = ": "; iov[n].iov_len = 2; va_start(ap, fmt); len = lvformat(str, sizeof str, fmt, ap); va_end(ap); while (len > 0 && isspace(str[len-1])) --len; iov[++n].iov_base = str; iov[n].iov_len = len; iov[++n].iov_base = "\n"; iov[n].iov_len = 1; return writev(log->fd, iov, ++n); } Is it correct? (empirical evidence suggests it is) Is there any better way to do it? Will it work on the Alpha? BTW, is dladdr() signal-safe? DES -- Dag-Erling Smorgrav - d...@flood.ping.uio.no To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-hackers" in the body of the message