• 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 char* logtag, int32_t ignoreDepth=1,
39             int32_t maxDepth=MAX_DEPTH);
40     CallStack(const CallStack& rhs);
41     ~CallStack();
42 
43     CallStack& operator = (const CallStack& rhs);
44 
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     bool operator > (const CallStack& rhs) const;
50     bool operator <= (const CallStack& rhs) const;
51 
52     const void* operator [] (int index) const;
53 
54     void clear();
55 
56     void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH);
57 
58     // Dump a stack trace to the log using the supplied logtag
59     void dump(const char* logtag, const char* prefix = 0) const;
60 
61     // Return a string (possibly very long) containing the complete stack trace
62     String8 toString(const char* prefix = 0) const;
63 
size()64     size_t size() const { return mCount; }
65 
66 private:
67     size_t mCount;
68     backtrace_frame_t mStack[MAX_DEPTH];
69 };
70 
71 }; // namespace android
72 
73 
74 // ---------------------------------------------------------------------------
75 
76 #endif // ANDROID_CALLSTACK_H
77