crash reporter, getting process path in native way on FreeBSD.

This commit is contained in:
David Carlier 2020-01-11 21:23:45 +00:00
parent 1e4b0ccb4e
commit a6aa0aa9eb
2 changed files with 19 additions and 1 deletions

View File

@ -632,6 +632,9 @@ endif()
if(UNIX AND NOT APPLE)
if(USE_LIBBFD)
target_link_libraries(supertuxkart ${LIBBFD_LIBRARIES})
if (CMAKE_SYSTEM_NAME MATCHES "BSD")
target_link_libraries(supertuxkart execinfo)
endif()
endif()
if(USE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")

View File

@ -342,6 +342,10 @@
#include <execinfo.h>
#include <bfd.h>
#if defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif
#include "string_utils.hpp"
namespace CrashReporting
@ -411,7 +415,18 @@
void loadSTKBFD()
{
const char* path = realpath("/proc/self/exe", NULL);
char *path = NULL;
#if defined(__linux__)
path = realpath("/proc/self/exe", NULL);
#elif defined(__FreeBSD__)
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
size_t len = PATH_MAX;
path = (char*)malloc(PATH_MAX+1);
if (sysctl(mib, 4, path, &len, NULL, 0) == -1) {
free((void*)path);
return;
}
#endif
m_stk_bfd = bfd_openr(path, NULL);
free((void*)path);