feat: allow to obtain the stack trace as a string (#1075)
This commit is contained in:
parent
b24e4d9445
commit
7a807f3805
@ -1736,6 +1736,9 @@ GLOG_EXPORT bool IsFailureSignalHandlerInstalled();
|
||||
GLOG_EXPORT void InstallFailureWriter(void (*writer)(const char* data,
|
||||
size_t size));
|
||||
|
||||
// Dump stack trace as a string.
|
||||
GLOG_EXPORT std::string GetStackTrace();
|
||||
|
||||
} // namespace google
|
||||
|
||||
#endif // GLOG_LOGGING_H
|
||||
|
||||
@ -1705,8 +1705,7 @@ void LogMessage::Init(const char* file, int line, LogSeverity severity,
|
||||
std::snprintf(fileline, sizeof(fileline), "%s:%d", data_->basename_, line);
|
||||
#ifdef HAVE_STACKTRACE
|
||||
if (FLAGS_log_backtrace_at == fileline) {
|
||||
string stacktrace;
|
||||
DumpStackTraceToString(&stacktrace);
|
||||
string stacktrace = GetStackTrace();
|
||||
stream() << " (stacktrace:\n" << stacktrace << ") ";
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -287,12 +287,6 @@ static void MyUserNameInitializer() {
|
||||
}
|
||||
REGISTER_MODULE_INITIALIZER(utilities, MyUserNameInitializer())
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
void DumpStackTraceToString(string* stacktrace) {
|
||||
DumpStackTrace(1, DebugWriteToString, stacktrace);
|
||||
}
|
||||
#endif
|
||||
|
||||
// We use an atomic operation to prevent problems with calling CrashReason
|
||||
// from inside the Mutex implementation (potentially through RAW_CHECK).
|
||||
static std::atomic<const logging::internal::CrashReason*> g_reason{nullptr};
|
||||
@ -323,4 +317,13 @@ void ShutdownGoogleLoggingUtilities() {
|
||||
}
|
||||
|
||||
} // namespace glog_internal_namespace_
|
||||
|
||||
#ifdef HAVE_STACKTRACE
|
||||
std::string GetStackTrace() {
|
||||
std::string stacktrace;
|
||||
DumpStackTrace(1, DebugWriteToString, &stacktrace);
|
||||
return stacktrace;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace google
|
||||
|
||||
@ -162,8 +162,6 @@ const std::string& MyUserName();
|
||||
// (Doesn't modify filepath, contrary to basename() in libgen.h.)
|
||||
const char* const_basename(const char* filepath);
|
||||
|
||||
void DumpStackTraceToString(std::string* stacktrace);
|
||||
|
||||
void SetCrashReason(const logging::internal::CrashReason* r);
|
||||
|
||||
void InitGoogleLoggingUtilities(const char* argv0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user