backtrace.c (254689) | backtrace.c (255033) |
---|---|
1/* $NetBSD: backtrace.c,v 1.2 2012/07/09 03:11:59 christos Exp $ */ | 1/* $NetBSD: backtrace.c,v 1.3 2013/08/29 14:58:56 christos Exp $ */ |
2 3/*- 4 * Copyright (c) 2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * --- 14 unchanged lines hidden (view full) --- 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31#include <sys/cdefs.h> | 2 3/*- 4 * Copyright (c) 2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * --- 14 unchanged lines hidden (view full) --- 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31#include <sys/cdefs.h> |
32__RCSID("$NetBSD: backtrace.c,v 1.2 2012/07/09 03:11:59 christos Exp $"); | 32__RCSID("$NetBSD: backtrace.c,v 1.3 2013/08/29 14:58:56 christos Exp $"); |
33 34#include <sys/param.h> 35#include <assert.h> 36#define _WITH_DPRINTF 37#include <stdio.h> 38#include <string.h> 39#include <stdlib.h> 40#include <stdarg.h> --- 5 unchanged lines hidden (view full) --- 46#include <elf.h> 47 48#include "execinfo.h" 49#include "symtab.h" 50 51#ifdef __linux__ 52#define SELF "/proc/self/exe" 53#else | 33 34#include <sys/param.h> 35#include <assert.h> 36#define _WITH_DPRINTF 37#include <stdio.h> 38#include <string.h> 39#include <stdlib.h> 40#include <stdarg.h> --- 5 unchanged lines hidden (view full) --- 46#include <elf.h> 47 48#include "execinfo.h" 49#include "symtab.h" 50 51#ifdef __linux__ 52#define SELF "/proc/self/exe" 53#else |
54#include <sys/sysctl.h> |
|
54#define SELF "/proc/curproc/file" 55#endif 56 | 55#define SELF "/proc/curproc/file" 56#endif 57 |
58static int 59open_self(int flags) 60{ 61 const char *pathname = SELF; 62#ifdef KERN_PROC_PATHNAME 63 static const int name[] = { 64 CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1, 65 }; 66 char path[MAXPATHLEN]; 67 size_t len; 68 69 len = sizeof(path); 70 if (sysctl(name, 4, path, &len, NULL, 0) != -1) 71 pathname = path; 72#endif 73 return open(pathname, flags); 74} 75 76 |
|
57static int __printflike(4, 5) 58rasprintf(char **buf, size_t *bufsiz, size_t offs, const char *fmt, ...) 59{ 60 for (;;) { 61 size_t nbufsiz; 62 char *nbuf; 63 64 if (*buf && offs < *bufsiz) { --- 93 unchanged lines hidden (view full) --- 158backtrace_symbols_fmt(void *const *trace, size_t len, const char *fmt) 159{ 160 161 static const size_t slen = sizeof(char *) + 64; /* estimate */ 162 char *ptr; 163 symtab_t *st; 164 int fd; 165 | 77static int __printflike(4, 5) 78rasprintf(char **buf, size_t *bufsiz, size_t offs, const char *fmt, ...) 79{ 80 for (;;) { 81 size_t nbufsiz; 82 char *nbuf; 83 84 if (*buf && offs < *bufsiz) { --- 93 unchanged lines hidden (view full) --- 178backtrace_symbols_fmt(void *const *trace, size_t len, const char *fmt) 179{ 180 181 static const size_t slen = sizeof(char *) + 64; /* estimate */ 182 char *ptr; 183 symtab_t *st; 184 int fd; 185 |
166 if ((fd = open(SELF, O_RDONLY)) != -1) | 186 if ((fd = open_self(O_RDONLY)) != -1) |
167 st = symtab_create(fd, -1, STT_FUNC); 168 else 169 st = NULL; 170 171 if ((ptr = calloc(len, slen)) == NULL) 172 goto out; 173 174 size_t psize = len * slen; --- 56 unchanged lines hidden --- | 187 st = symtab_create(fd, -1, STT_FUNC); 188 else 189 st = NULL; 190 191 if ((ptr = calloc(len, slen)) == NULL) 192 goto out; 193 194 size_t psize = len * slen; --- 56 unchanged lines hidden --- |