Do not cache frames inside StackTrace

This commit is contained in:
Ivan Blinkov 2020-06-10 16:30:12 +03:00
parent 90ee4d52f4
commit 6191d33bd9
4 changed files with 10 additions and 29 deletions

View File

@ -223,7 +223,6 @@ public:
DB::readPODBinary(stack_trace, in);
DB::readBinary(thread_num, in);
DB::readBinary(query_id, in);
stack_trace.resetFrames();
/// This allows to receive more signals if failure happens inside onFault function.
/// Example: segfault while symbolizing stack trace.

View File

@ -13,6 +13,7 @@ if (NOT OS_FREEBSD AND NOT SPLIT_SHARED_LIBRARIES AND NOT (OS_DARWIN AND COMPILE
set (SENTRY_BACKEND "none" CACHE STRING "")
set (SENTRY_EXPORT_SYMBOLS OFF CACHE BOOL "")
set (SENTRY_LINK_PTHREAD OFF CACHE BOOL "")
set (SENTRY_PIC OFF CACHE BOOL "")
if (OS_LINUX AND NOT_UNBUNDLED)
set (BUILD_SHARED_LIBS OFF)
endif()

View File

@ -199,12 +199,12 @@ static void symbolize(const void * const * frame_pointers, size_t offset, size_t
for (size_t i = 0; i < offset; ++i)
{
frames.value()[i].virtual_addr = frame_pointers[i];
frames[i].virtual_addr = frame_pointers[i];
}
for (size_t i = offset; i < size; ++i)
{
StackTrace::Frame & current_frame = frames.value()[i];
StackTrace::Frame & current_frame = frames[i];
current_frame.virtual_addr = frame_pointers[i];
const auto * object = symbol_index.findObject(current_frame.virtual_addr);
uintptr_t virtual_offset = object ? uintptr_t(object->address_begin) : 0;
@ -244,7 +244,7 @@ static void symbolize(const void * const * frame_pointers, size_t offset, size_t
#else
for (size_t i = 0; i < size; ++i)
{
frames.value()[i].virtual_addr = frame_pointers[i];
frames[i].virtual_addr = frame_pointers[i];
}
UNUSED(offset);
#endif
@ -309,16 +309,6 @@ const StackTrace::FramePointers & StackTrace::getFramePointers() const
return frame_pointers;
}
const StackTrace::Frames & StackTrace::getFrames() const
{
if (!frames.has_value())
{
frames.emplace();
symbolize(frame_pointers.data(), offset, size, frames);
}
return frames;
}
static void
toStringEveryLineImpl(const StackTrace::Frames & frames, size_t offset, size_t size, std::function<void(const std::string &)> callback)
{
@ -329,7 +319,7 @@ toStringEveryLineImpl(const StackTrace::Frames & frames, size_t offset, size_t s
for (size_t i = offset; i < size; ++i)
{
const StackTrace::Frame & current_frame = frames.value()[i];
const StackTrace::Frame & current_frame = frames[i];
out << i << ". ";
if (current_frame.file.has_value() && current_frame.line.has_value())
@ -356,8 +346,7 @@ toStringEveryLineImpl(const StackTrace::Frames & frames, size_t offset, size_t s
static std::string toStringImpl(const void * const * frame_pointers, size_t offset, size_t size)
{
std::stringstream out;
StackTrace::Frames frames{};
frames.emplace();
StackTrace::Frames frames;
symbolize(frame_pointers, offset, size, frames);
toStringEveryLineImpl(frames, offset, size, [&](const std::string & str) { out << str << '\n'; });
return out.str();
@ -365,12 +354,9 @@ static std::string toStringImpl(const void * const * frame_pointers, size_t offs
void StackTrace::toStringEveryLine(std::function<void(const std::string &)> callback) const
{
toStringEveryLineImpl(getFrames(), offset, size, std::move(callback));
}
void StackTrace::resetFrames()
{
frames.reset();
Frames frames;
symbolize(frame_pointers.data(), offset, size, frames);
toStringEveryLineImpl(frames, offset, size, std::move(callback));
}

View File

@ -36,7 +36,7 @@ public:
};
static constexpr size_t capacity = 32;
using FramePointers = std::array<void *, capacity>;
using Frames = std::optional<std::array<Frame, capacity>>;
using Frames = std::array<Frame, capacity>;
/// Tries to capture stack trace
StackTrace();
@ -51,22 +51,17 @@ public:
size_t getSize() const;
size_t getOffset() const;
const FramePointers & getFramePointers() const;
const Frames & getFrames() const;
std::string toString() const;
static std::string toString(void ** frame_pointers, size_t offset, size_t size);
void toStringEveryLine(std::function<void(const std::string &)> callback) const;
void resetFrames();
protected:
void tryCapture();
size_t size = 0;
size_t offset = 0; /// How many frames to skip while displaying.
FramePointers frame_pointers{};
mutable Frames frames{};
};
std::string signalToErrorMessage(int sig, const siginfo_t & info, const ucontext_t & context);