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