Sources Pipelines Documentation

Allocators  
All Classes Functions Variables
backtrace.ipp
1 #pragma once
2 
3 #include <cerrno>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <stdexcept>
7 
8 #include <execinfo.h>
9 
10 
11 namespace boost { namespace utils {
12 
13 backtrace::backtrace()
14  :
15  locations_()
16 {
17  nptrs_ = ::backtrace(buffer_, BT_BUF_SIZE);
18  locations_ = ::backtrace_symbols(buffer_, nptrs_);
19  if (locations_ == NULL)
20  {
21  auto error = strerror(errno);
22  throw std::runtime_error(error);
23  }
24 }
25 
26 backtrace::~backtrace()
27 {
28  free(locations_);
29 }
30 
31 void backtrace::dump(std::ostream& os) const
32 {
33  for (auto j = 0; j < nptrs_; j++)
34  os << locations_[j] << std::endl;
35 }
36 
37 } }
38 
39 std::ostream& operator<<(std::ostream& os, const boost::utils::backtrace& bt)
40 {
41  bt.dump(os);
42  return os;
43 }
44 
Produces a backtrace of RAII.
Definition: backtrace.hpp:18