From 2442b3002aab782add149095560aeb27aa9be7be Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 9 Oct 2024 12:27:41 +0200 Subject: [PATCH] Avoid program_invocation_name which is available only on Linux `program_invocation_name` is defined by the system headers only on Linux, or at least it is not available on FreeBSD. Thus, maintain own global variable that contains the program name. --- Boss/Main.cpp | 3 +++ Util/BacktraceException.hpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Boss/Main.cpp b/Boss/Main.cpp index ff9bf8f7e..cb87b8eda 100644 --- a/Boss/Main.cpp +++ b/Boss/Main.cpp @@ -20,6 +20,8 @@ # include "config.h" #endif +std::string g_argv0{"unknown"}; + namespace Boss { class Main::Impl { @@ -62,6 +64,7 @@ class Main::Impl { { assert(argv.size() >= 1); argv0 = argv[0]; + g_argv0 = argv[0]; if (argv.size() >= 2) { auto argv1 = argv[1]; if (argv1 == "--version" || argv1 == "-V") diff --git a/Util/BacktraceException.hpp b/Util/BacktraceException.hpp index 313efb834..2a6cd38dd 100644 --- a/Util/BacktraceException.hpp +++ b/Util/BacktraceException.hpp @@ -8,6 +8,9 @@ #include #include #include +#include + +extern std::string g_argv0; namespace Util { @@ -80,7 +83,7 @@ class BacktraceException : public T { std::string addr2line(void* addr) const { char cmd[512]; snprintf(cmd, sizeof(cmd), - "addr2line -C -f -p -e %s %p", program_invocation_name, addr); + "addr2line -C -f -p -e %s %p", g_argv0.c_str(), addr); std::array buffer; std::string result;