proxygen
folly::exception_tracer::StackTraceStack Class Reference

#include <StackTrace.h>

Classes

class  Node
 

Public Member Functions

bool pushCurrent ()
 
bool pop ()
 
bool moveTopFrom (StackTraceStack &other)
 
void clear ()
 
bool empty () const
 
StackTracetop ()
 
StackTracenext (StackTrace *p)
 

Private Member Functions

void checkGuard () const
 

Private Attributes

uintptr_t guard1_
 
Nodetop_
 
uintptr_t guard2_
 

Detailed Description

Definition at line 37 of file StackTrace.h.

Member Function Documentation

void folly::exception_tracer::StackTraceStack::checkGuard ( ) const
inlineprivate

Definition at line 87 of file StackTrace.h.

Referenced by clear(), moveTopFrom(), next(), pop(), pushCurrent(), and top().

87  {
88 #ifndef NDEBUG
89  assert(guard1_ == 0 && guard2_ == 0);
90 #endif
91  }
void folly::exception_tracer::StackTraceStack::clear ( )

Clear the stack.

Definition at line 94 of file StackTrace.cpp.

References checkGuard(), pop(), and top_.

Referenced by getExceptionStackTraceStack().

94  {
95  checkGuard();
96  while (top_) {
97  pop();
98  }
99 }
bool folly::exception_tracer::StackTraceStack::empty ( ) const
inline

Is the stack empty?

Definition at line 69 of file StackTrace.h.

References cpp.ast::next(), and folly::pushmi::top.

69  {
70  return !top_;
71  }
bool folly::exception_tracer::StackTraceStack::moveTopFrom ( StackTraceStack other)

Move the top stack trace from other onto this. Returns true on success, false on failure (other was empty).

Definition at line 81 of file StackTrace.cpp.

References checkGuard(), folly::exception_tracer::StackTraceStack::Node::next, and top_.

Referenced by getExceptionStackTraceStack().

81  {
82  checkGuard();
83  if (!other.top_) {
84  return false;
85  }
86 
87  auto node = other.top_;
88  other.top_ = node->next;
89  node->next = top_;
90  top_ = node;
91  return true;
92 }
StackTrace * folly::exception_tracer::StackTraceStack::next ( StackTrace p)

Return the stack trace following p, or nullptr if p is the bottom of the stack.

Definition at line 106 of file StackTrace.cpp.

References checkGuard(), and folly::exception_tracer::StackTraceStack::Node::next.

Referenced by folly::exception_tracer::getCurrentExceptions().

106  {
107  checkGuard();
108  assert(p);
109  return static_cast<Node*>(p)->next;
110 }
StackTrace * next(StackTrace *p)
Definition: StackTrace.cpp:106
bool folly::exception_tracer::StackTraceStack::pop ( )

Pop the top stack trace from the stack. Returns true on success, false on failure (stack was empty).

Definition at line 69 of file StackTrace.cpp.

References checkGuard(), folly::exception_tracer::StackTraceStack::Node::deallocate(), folly::exception_tracer::StackTraceStack::Node::next, and top_.

Referenced by clear().

69  {
70  checkGuard();
71  if (!top_) {
72  return false;
73  }
74 
75  auto node = top_;
76  top_ = node->next;
77  node->deallocate();
78  return true;
79 }
bool folly::exception_tracer::StackTraceStack::pushCurrent ( )

Push the current stack trace onto the stack. Returns false on failure (not enough memory, getting stack trace failed), true on success.

Definition at line 49 of file StackTrace.cpp.

References folly::exception_tracer::StackTraceStack::Node::allocate(), checkGuard(), folly::symbolizer::getStackTrace(), folly::exception_tracer::kMaxFrames, and top_.

49  {
50  checkGuard();
51  auto node = Node::allocate();
52  if (!node) {
53  // cannot allocate memory
54  return false;
55  }
56 
57  ssize_t n = folly::symbolizer::getStackTrace(node->addresses, kMaxFrames);
58  if (n == -1) {
59  node->deallocate();
60  return false;
61  }
62  node->frameCount = n;
63 
64  node->next = top_;
65  top_ = node;
66  return true;
67 }
constexpr size_t kMaxFrames
Definition: StackTrace.h:26
ssize_t getStackTrace(uintptr_t *addresses, size_t maxAddresses)
Definition: StackTrace.cpp:25
StackTrace * folly::exception_tracer::StackTraceStack::top ( )

Return the top stack trace, or nullptr if the stack is empty.

Definition at line 101 of file StackTrace.cpp.

References checkGuard(), and top_.

Referenced by folly::exception_tracer::getCurrentExceptions().

101  {
102  checkGuard();
103  return top_;
104 }

Member Data Documentation

uintptr_t folly::exception_tracer::StackTraceStack::guard1_
private

Definition at line 94 of file StackTrace.h.

uintptr_t folly::exception_tracer::StackTraceStack::guard2_
private

Definition at line 98 of file StackTrace.h.

Node* folly::exception_tracer::StackTraceStack::top_
private

Definition at line 96 of file StackTrace.h.

Referenced by clear(), moveTopFrom(), pop(), pushCurrent(), and top().


The documentation for this class was generated from the following files: