From owner-freebsd-hackers Sat Jul 17 13:54:59 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from cygnus.rush.net (cygnus.rush.net [209.45.245.133]) by hub.freebsd.org (Postfix) with ESMTP id C184F14C9D for ; Sat, 17 Jul 1999 13:54:55 -0700 (PDT) (envelope-from bright@rush.net) Received: from localhost (bright@localhost) by cygnus.rush.net (8.9.3/8.9.3) with SMTP id RAA27715; Sat, 17 Jul 1999 17:01:52 -0400 (EDT) Date: Sat, 17 Jul 1999 16:01:50 -0500 (EST) From: Alfred Perlstein To: Dag-Erling Smorgrav Cc: hackers@FreeBSD.ORG Subject: Re: Determining the return address In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 17 Jul 1999, Dag-Erling Smorgrav wrote: > 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); ... > > > Is it correct? (empirical evidence suggests it is) Is there any better > way to do it? Will it work on the Alpha? This looks like what you are doing is trying to grab the data on the stack before "log" which is the return address. I doubt this is at all portable and may fail because of optimizations and ABI, such as archs that store the return address in a register... gdb and glibc have some functions to assist in runtime backtraces, perhaps a look there may help? > > BTW, is dladdr() signal-safe? not according to the sigaction man page. -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message