Skip to content

Commit

Permalink
stack trace freebsd update. using native api to get the process (face…
Browse files Browse the repository at this point in the history
…book#8144)

Summary:
full name.

Pull Request resolved: facebook#8144

Reviewed By: ajkr

Differential Revision: D27581146

Pulled By: riversand963

fbshipit-source-id: 7d4cbde02a07aa4676e35aeb60c3d6f1f492a3cd
  • Loading branch information
devnexen authored and facebook-github-bot committed Apr 6, 2021
1 parent 96205ba commit 88c8f7a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion port/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,6 +32,10 @@ void* SaveStack(int* /*num_frames*/, int /*first_frames_to_skip*/) {
#include <unistd.h>
#include <cxxabi.h>

#if defined(OS_FREEBSD)
#include <sys/sysctl.h>
#endif

namespace ROCKSDB_NAMESPACE {
namespace port {

Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 88c8f7a

Please sign in to comment.