libunwind-devel
[Top][All Lists]
Advanced

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

[Libunwind-devel] crasher.c port for FreeBSD


From: Konstantin Belousov
Subject: [Libunwind-devel] crasher.c port for FreeBSD
Date: Mon, 18 Jun 2012 15:30:25 +0300
User-agent: Mutt/1.4.2.3i

At http://people.freebsd.org/~kib/git/libunwind.git/ branch for-arun,
there are two patches.

cc9aa009f241834029d3e4bd4e8fc59c64879732 fixes the build of test suite
outside the source directory.

e5fb7af91bee45b9fae9272042116bf5253b8b8f ports the crasher program to
FreeBSD.

The diff is below for your convenience. Please apply.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8061b30..5d2015c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -116,8 +116,7 @@ Gtest_trace_SOURCES = Gtest-trace.c ident.c
 Ltest_trace_SOURCES = Ltest-trace.c ident.c
 
 # prevent function inlining
-crasher: crasher.c
-       $(CC) -O0 -o crasher crasher.c
+crasher_CFLAGS=-O0
 
 LIBUNWIND = $(top_builddir)/src/libunwind-$(arch).la
 LIBUNWIND_ptrace = $(top_builddir)/src/libunwind-ptrace.a
diff --git a/tests/crasher.c b/tests/crasher.c
index 65e1b7e..72cd54d 100644
--- a/tests/crasher.c
+++ b/tests/crasher.c
@@ -3,11 +3,17 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <unistd.h>
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#endif
 
 void a(void) __attribute__((noinline));
 void b(int x) __attribute__((noinline));
 
-#ifdef __linux__
+#if defined(__linux__)
 void write_maps(char *fname)
 {
     char buf[512], path[128];
@@ -35,6 +41,48 @@ void write_maps(char *fname)
     fclose(out);
     fclose(maps);
 }
+#elif defined(__FreeBSD__)
+void
+write_maps(char *fname)
+{
+    FILE *out;
+    char *buf, *bp, *eb;
+    struct kinfo_vmentry *kv;
+    int mib[4], error;
+    size_t len;
+
+    out = fopen(fname, "w");
+    if (out == NULL)
+        exit(EXIT_FAILURE);
+
+    len = 0;
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PROC;
+    mib[2] = KERN_PROC_VMMAP;
+    mib[3] = getpid();
+    error = sysctl(mib, 4, NULL, &len, NULL, 0);
+    if (error == -1)
+       exit(EXIT_FAILURE);
+    len = len * 4 / 3;
+    buf = malloc(len);
+    if (buf == NULL)
+       exit(EXIT_FAILURE);
+    error = sysctl(mib, 4, buf, &len, NULL, 0);
+    if (error == -1)
+           exit(EXIT_FAILURE);
+
+    for (bp = buf, eb = buf + len; bp < eb; bp += kv->kve_structsize) {
+        kv = (struct kinfo_vmentry *)(uintptr_t)bp;
+       if (kv->kve_type == KVME_TYPE_VNODE &&
+         (kv->kve_protection & KVME_PROT_EXEC) != 0) {
+           fprintf(out, "0x%jx:%s ", kv->kve_start, kv->kve_path);
+       }
+    }
+
+    fprintf(out, "\n");
+    fclose(out);
+    free(buf);
+}
 #else
 #error Port me
 #endif

Attachment: pgpvwfxXUfkMc.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]