diff --git a/src/duckdb/src/common/stacktrace.cpp b/src/duckdb/src/common/stacktrace.cpp index ab73be9f4..7a42b35cf 100644 --- a/src/duckdb/src/common/stacktrace.cpp +++ b/src/duckdb/src/common/stacktrace.cpp @@ -21,7 +21,7 @@ static string UnmangleSymbol(string symbol) { } } for (idx_t i = mangle_start; i < symbol.size(); i++) { - if (StringUtil::CharacterIsSpace(symbol[i])) { + if (StringUtil::CharacterIsSpace(symbol[i]) || symbol[i] == ')' || symbol[i] == '+') { mangle_end = i; break; } @@ -44,6 +44,45 @@ static string UnmangleSymbol(string symbol) { return result; } +static string CleanupStackTrace(string symbol) { +#ifdef __APPLE__ + // structure of frame pointers is [depth] [library] [pointer] [symbol] + // we are only interested in [depth] and [symbol] + + // find the depth + idx_t start; + for (start = 0; start < symbol.size(); start++) { + if (!StringUtil::CharacterIsDigit(symbol[start])) { + break; + } + } + + // now scan forward until we find the frame pointer + idx_t frame_end = symbol.size(); + for (idx_t i = start; i + 1 < symbol.size(); ++i) { + if (symbol[i] == '0' && symbol[i + 1] == 'x') { + idx_t k; + for (k = i + 2; k < symbol.size(); ++k) { + if (!StringUtil::CharacterIsHex(symbol[k])) { + break; + } + } + frame_end = k; + break; + } + } + static constexpr idx_t STACK_TRACE_INDENTATION = 8; + if (frame_end == symbol.size() || start >= STACK_TRACE_INDENTATION) { + // frame pointer not found - just preserve the original frame + return symbol; + } + idx_t space_count = STACK_TRACE_INDENTATION - start; + return symbol.substr(0, start) + string(space_count, ' ') + symbol.substr(frame_end, symbol.size() - frame_end); +#else + return symbol; +#endif +} + string StackTrace::GetStacktracePointers(idx_t max_depth) { string result; auto callstack = unique_ptr(new void *[max_depth]); @@ -68,7 +107,7 @@ string StackTrace::ResolveStacktraceSymbols(const string &pointers) { string result; char **strs = backtrace_symbols(callstack.get(), NumericCast(frame_count)); for (idx_t i = 0; i < frame_count; i++) { - result += UnmangleSymbol(strs[i]); + result += CleanupStackTrace(UnmangleSymbol(strs[i])); result += "\n"; } free(reinterpret_cast(strs)); diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index e191d62d8..fae7a681f 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,5 +1,5 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "4-dev4090" +#define DUCKDB_PATCH_VERSION "4-dev4100" #endif #ifndef DUCKDB_MINOR_VERSION #define DUCKDB_MINOR_VERSION 1 @@ -8,10 +8,10 @@ #define DUCKDB_MAJOR_VERSION 1 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v1.1.4-dev4090" +#define DUCKDB_VERSION "v1.1.4-dev4100" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "41d13ad161" +#define DUCKDB_SOURCE_ID "5705d13dbf" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp"