summaryrefslogtreecommitdiff
path: root/addr2line.c
diff options
context:
space:
mode:
Diffstat (limited to 'addr2line.c')
-rw-r--r--addr2line.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/addr2line.c b/addr2line.c
index 81e5041..38c3d8f 100644
--- a/addr2line.c
+++ b/addr2line.c
@@ -623,6 +623,15 @@ fill_lines(int num_traces, void **traces, int check_debuglink,
}
#define HAVE_MAIN_EXE_PATH
+#if defined(__FreeBSD__)
+# include <sys/sysctl.h>
+#endif
+/* ssize_t main_exe_path(void)
+ *
+ * store the path of the main executable to `binary_filename`,
+ * and returns strlen(binary_filename).
+ * it is NUL terminated.
+ */
#if defined(__linux__)
ssize_t
main_exe_path(void)
@@ -632,6 +641,20 @@ main_exe_path(void)
binary_filename[len] = 0;
return len;
}
+#elif defined(__FreeBSD__)
+ssize_t
+main_exe_path(void)
+{
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+ size_t len = PATH_MAX;
+ int err = sysctl(mib, 4, binary_filename, &len, NULL, 0);
+ if (err) {
+ kprintf("Can't get the path of ruby");
+ return -1;
+ }
+ len--; /* sysctl sets strlen+1 */
+ return len;
+}
#else
#undef HAVE_MAIN_EXE_PATH
#endif