From 88c8f7a090186baa41321bf8f14d7ef8f5da5e3c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 6 Apr 2021 00:27:59 -0700 Subject: [PATCH] stack trace freebsd update. using native api to get the process (#8144) Summary: full name. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8144 Reviewed By: ajkr Differential Revision: D27581146 Pulled By: riversand963 fbshipit-source-id: 7d4cbde02a07aa4676e35aeb60c3d6f1f492a3cd --- port/stack_trace.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/port/stack_trace.cc b/port/stack_trace.cc index 00970f9d6..c82da2a20 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -7,7 +7,7 @@ #if defined(ROCKSDB_LITE) || \ !(defined(ROCKSDB_BACKTRACE) || defined(OS_MACOSX)) || defined(CYGWIN) || \ - defined(OS_FREEBSD) || defined(OS_SOLARIS) || defined(OS_WIN) + defined(OS_SOLARIS) || defined(OS_WIN) // noop @@ -32,6 +32,10 @@ void* SaveStack(int* /*num_frames*/, int /*first_frames_to_skip*/) { #include #include +#if defined(OS_FREEBSD) +#include +#endif + namespace ROCKSDB_NAMESPACE { namespace port { @@ -41,6 +45,7 @@ namespace { const char* GetExecutableName() { static char name[1024]; +#if !defined(OS_FREEBSD) char link[1024]; snprintf(link, sizeof(link), "/proc/%d/exe", getpid()); auto read = readlink(link, name, sizeof(name) - 1); @@ -50,6 +55,17 @@ const char* GetExecutableName() { name[read] = 0; return name; } +#else + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t namesz = sizeof(name); + + auto ret = sysctl(mib, 4, name, &namesz, nullptr, 0); + if (-1 == ret) { + return nullptr; + } else { + return name; + } +#endif } void PrintStackTraceLine(const char* symbol, void* frame) {