summaryrefslogtreecommitdiff
path: root/addr2line.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-14 10:08:02 (GMT)
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-14 10:08:02 (GMT)
commitc05940a403b4cf2f83e942cfa90bdc2257e08c29 (patch)
tree85c710a040720cdd24f8409a1b1d4e94e8b5c33d /addr2line.c
parent160b67df68655322d09f566914c89e2d3e7cfc05 (diff)
* addr2line.c (main_exe_path): support FreeBSD.
At least sh, csh, tcsh, bash, and zsh sets realpath of the main executable for dladdr, but gdb doesn't. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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