• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_CALLSTACK_H
18 #define ANDROID_CALLSTACK_H
19 
20 #include <stdint.h>
21 #include <sys/types.h>
22 
23 #include <utils/String8.h>
24 #include <corkscrew/backtrace.h>
25 
26 // ---------------------------------------------------------------------------
27 
28 namespace android {
29 
30 class CallStack
31 {
32 public:
33     enum {
34         MAX_DEPTH = 31
35     };
36 
37     CallStack();
38     CallStack(const CallStack& rhs);
39     ~CallStack();
40 
41     CallStack& operator = (const CallStack& rhs);
42 
43     bool operator == (const CallStack& rhs) const;
44     bool operator != (const CallStack& rhs) const;
45     bool operator < (const CallStack& rhs) const;
46     bool operator >= (const CallStack& rhs) const;
47     bool operator > (const CallStack& rhs) const;
48     bool operator <= (const CallStack& rhs) const;
49 
50     const void* operator [] (int index) const;
51 
52     void clear();
53 
54     void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH);
55 
56     // Dump a stack trace to the log
57     void dump(const char* prefix = 0) const;
58 
59     // Return a string (possibly very long) containing the complete stack trace
60     String8 toString(const char* prefix = 0) const;
61 
size()62     size_t size() const { return mCount; }
63 
64 private:
65     size_t mCount;
66     backtrace_frame_t mStack[MAX_DEPTH];
67 };
68 
69 }; // namespace android
70 
71 
72 // ---------------------------------------------------------------------------
73 
74 #endif // ANDROID_CALLSTACK_H
75