X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fexternal%2Fprocess-cpp-minimal%2Fsrc%2Fcore%2Fposix%2Fbacktrace.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fexternal%2Fprocess-cpp-minimal%2Fsrc%2Fcore%2Fposix%2Fbacktrace.cpp;h=7a02bbdecc1ff422209ae6b3763bb9f583d92e93;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/external/process-cpp-minimal/src/core/posix/backtrace.cpp b/src/type3_AndroidCloud/anbox-master/external/process-cpp-minimal/src/core/posix/backtrace.cpp new file mode 100644 index 0000000..7a02bbd --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/external/process-cpp-minimal/src/core/posix/backtrace.cpp @@ -0,0 +1,153 @@ +/* + * Copyright © 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authored by: Thomas Voß + */ + +#include "backtrace.h" + +#include + +#include + +namespace bt = core::posix::backtrace; + +namespace impl +{ +std::tuple demangle(const std::string& symbol) +{ + int status = 1; + auto result = abi::__cxa_demangle(symbol.c_str(), + nullptr, + nullptr, + &status); + + if (!result || status != 0) + { + return std::make_tuple(std::string(), false); + } + + std::string s{result}; + ::free(result); + + return std::make_tuple(s, true); +} + +struct Frame : public bt::Frame +{ + struct Symbol : public bt::Frame::Symbol + { + Symbol(const char* symbol) : raw_(symbol) + { + auto first = raw_.find_first_of("("); + auto last = raw_.find_last_of(")"); + + if (first != std::string::npos && last != std::string::npos) + { + auto mangled_symbol = raw_.substr(first+1, + (last-1) - (first+1)); + + auto plus = mangled_symbol.find_first_of("+"); + if (plus != std::string::npos) + mangled_symbol.erase(plus); + + std::tie(demangled_, is_cxx_) = demangle(mangled_symbol); + if (!is_cxx_) + demangled_ = raw_; + } + } + + bool is_cxx() const + { + return is_cxx_; + } + + std::string demangled() const + { + return demangled_; + } + + std::string raw() const + { + return raw_; + } + + std::string raw_; + std::string demangled_; + bool is_cxx_ = false; + }; + + std::size_t depth_; + void* frame_pointer_; + Symbol symbol_; + + Frame(std::size_t depth, void* frame_pointer, const char* symbol) + : depth_(depth), + frame_pointer_(frame_pointer), + symbol_(symbol) + { + } + + std::size_t depth() const + { + return depth_; + } + + virtual void* frame_pointer() const + { + return frame_pointer_; + } + + const Symbol& symbol() const + { + return symbol_; + } +}; +} + +std::shared_ptr bt::Frame::Symbol::for_testing_from_raw_symbol(const char* symbol) +{ + return std::shared_ptr(new impl::Frame::Symbol(symbol)); +} + +void bt::visit_with_handler(const bt::FrameHandler& handler) +{ + static const unsigned int max_frames=64; + void *frames[max_frames]; + + auto frame_count = ::backtrace(frames, max_frames); + auto symbols = ::backtrace_symbols(frames, frame_count); + + struct Scope + { + Scope(char** symbols) : symbols(symbols) + { + } + + ~Scope() + { + ::free(symbols); + } + + char** symbols = nullptr; + } scope{symbols}; + + for (int i = 0; i < frame_count; i++) + { + impl::Frame frame(i, frames[i], symbols[i]); + if (!handler(frame)) + return; + } +}