• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // call_stack.h: A call stack comprised of stack frames.
31 //
32 // This class manages a vector of stack frames.  It is used instead of
33 // exposing the vector directly to allow the CallStack to own StackFrame
34 // pointers without having to publicly export the linked_ptr class.  A
35 // CallStack must be composed of pointers instead of objects to allow for
36 // CPU-specific StackFrame subclasses.
37 //
38 // By convention, the stack frame at index 0 is the innermost callee frame,
39 // and the frame at the highest index in a call stack is the outermost
40 // caller.  CallStack only allows stacks to be built by pushing frames,
41 // beginning with the innermost callee frame.
42 //
43 // Author: Mark Mentovai
44 
45 #ifndef GOOGLE_BREAKPAD_PROCESSOR_CALL_STACK_H__
46 #define GOOGLE_BREAKPAD_PROCESSOR_CALL_STACK_H__
47 
48 #include <cstdint>
49 #include <vector>
50 
51 namespace google_breakpad {
52 
53 using std::vector;
54 
55 struct StackFrame;
56 template<typename T> class linked_ptr;
57 
58 class CallStack {
59  public:
CallStack()60   CallStack() { Clear(); }
61   ~CallStack();
62 
63   // Resets the CallStack to its initial empty state
64   void Clear();
65 
frames()66   const vector<StackFrame*>* frames() const { return &frames_; }
67 
68   // Set the TID associated with this call stack.
set_tid(uint32_t tid)69   void set_tid(uint32_t tid) { tid_ = tid; }
70 
tid()71   uint32_t tid() const { return tid_; }
72 
73  private:
74   // Stackwalker is responsible for building the frames_ vector.
75   friend class Stackwalker;
76 
77   // Storage for pushed frames.
78   vector<StackFrame*> frames_;
79 
80   // The TID associated with this call stack. Default to 0 if it's not
81   // available.
82   uint32_t tid_;
83 };
84 
85 }  // namespace google_breakpad
86 
87 #endif  // GOOGLE_BREAKPAD_PROCSSOR_CALL_STACK_H__
88