Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_backtrace method #79

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ struct MemoryToolsService
void
print_backtrace();

/// Returns a backtrace stream for logging.
OSRF_TESTING_TOOLS_CPP_MEMORY_TOOLS_PUBLIC
std::ostringstream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <sstream> at the top of the file for this.

get_backtrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the name get_backtrace; it is unclear what you are getting. How about get_backtrace_stream? Also, I think this method can be const.


/// Returns a stack trace object for introspection.
/**
* Pointer should not be used after MemoryToolsService is out of scope.
Expand Down
16 changes: 16 additions & 0 deletions osrf_testing_tools_cpp/src/memory_tools/memory_tools_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ MemoryToolsService::print_backtrace()
impl_->should_print_backtrace = true;
}


std::ostringstream
MemoryToolsService::get_backtrace()
{
std::ostringstream oss;
#if !defined(_WIN32) && !defined(__ANDROID__)
backward::StackTrace st;
st.load_here(256);
backward::Printer p;
p.print(st, oss);
#else
oss << "backtrace unavailable on Windows and Android\n";
#endif // !defined(_WIN32) && !defined(__ANDROID__)
return oss;
}

StackTrace *
MemoryToolsService::get_stack_trace()
{
Expand Down