diff --git a/ChangeLog b/ChangeLog index 87dce3720d..c752cbe02a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Apr 14 18:05:48 2014 NARUSE, Yui + + * 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 * proc.c (umethod_bind): use the ancestor iclass instead of new diff --git a/addr2line.c b/addr2line.c index 81e504105f..38c3d8fd3c 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 +#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