[前][次][番号順一覧][スレッド一覧]

ruby-changes:33505

From: naruse <ko1@a...>
Date: Mon, 14 Apr 2014 19:08:08 +0900 (JST)
Subject: [ruby-changes:33505] naruse:r45586 (trunk): * addr2line.c (main_exe_path): support FreeBSD.

naruse	2014-04-14 19:08:02 +0900 (Mon, 14 Apr 2014)

  New Revision: 45586

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45586

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/addr2line.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45585)
+++ ChangeLog	(revision 45586)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Apr 14 18:05:48 2014  NARUSE, Yui  <naruse@r...>
+
+	* 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.
+
 Mon Apr 14 17:20:10 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* proc.c (umethod_bind): use the ancestor iclass instead of new
Index: addr2line.c
===================================================================
--- addr2line.c	(revision 45585)
+++ addr2line.c	(revision 45586)
@@ -623,6 +623,15 @@ fill_lines(int num_traces, void **traces https://github.com/ruby/ruby/blob/trunk/addr2line.c#L623
 }
 
 #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) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L641
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]