From 5aadb58492aeb2f2b5c1aac7c198a50fdc2172b5 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:08:24 -0400 Subject: [PATCH] Don't use POSIX basename --- src/platform/common.hpp | 11 +++++++++++ src/symbols/symbols_with_libdwarf.cpp | 8 +------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/platform/common.hpp b/src/platform/common.hpp index 58efde0..6d5233c 100644 --- a/src/platform/common.hpp +++ b/src/platform/common.hpp @@ -430,6 +430,17 @@ static bool directory_exists(const std::string& path) { #endif } +CPPTRACE_MAYBE_UNUSED +static std::string basename(const std::string& path) { + // Assumes no trailing /'s + auto pos = path.rfind("/"); + if(pos == std::string::npos) { + return path; + } else { + return path.substr(pos + 1); + } +} + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/src/symbols/symbols_with_libdwarf.cpp b/src/symbols/symbols_with_libdwarf.cpp index 6031045..86c21c9 100644 --- a/src/symbols/symbols_with_libdwarf.cpp +++ b/src/symbols/symbols_with_libdwarf.cpp @@ -18,10 +18,6 @@ #include #include -#if IS_APPLE - #include -#endif - // some stuff is based on https://github.com/davea42/libdwarf-addr2line/blob/master/addr2line.c, mainly line handling // then much expanded for symbols and efficiency // dwarf5_ranges and dwarf4_ranges utility functions are taken from there directly, also pc_in_die @@ -1010,9 +1006,7 @@ namespace cpptrace { //char* dir = dirname(obj_path.data()); //std::string dsym = if(directory_exists(obj_path + ".dSYM")) { - std::string obj_path_copy = frame_info.obj_path; - std::string base = basename(const_cast(obj_path_copy.data())); - obj_path += ".dSYM/Contents/Resources/DWARF/" + base; + obj_path += ".dSYM/Contents/Resources/DWARF/" + basename(frame_info.obj_path); } #endif if(trace_dwarf) {