blob: 61dc832ea3d489933c69b4a0adb8fe41c6219466 [file] [log] [blame]
The Android Open Source Projectcbb10112009-03-03 19:31:44 -08001/*
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>
Jeff Brownea45b012011-10-19 20:32:43 -070024#include <corkscrew/backtrace.h>
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080025
26// ---------------------------------------------------------------------------
27
28namespace android {
29
30class CallStack
31{
32public:
33 enum {
34 MAX_DEPTH = 31
35 };
36
37 CallStack();
Mathias Agopiand34a8ca2013-03-21 17:12:40 -070038 CallStack(const char* logtag, int32_t ignoreDepth=1,
39 int32_t maxDepth=MAX_DEPTH);
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080040 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
Mathias Agopianc974d4d2010-12-10 15:37:48 -080056 void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH);
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080057
Mathias Agopiand34a8ca2013-03-21 17:12:40 -070058 // Dump a stack trace to the log using the supplied logtag
59 void dump(const char* logtag, const char* prefix = 0) const;
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080060
61 // Return a string (possibly very long) containing the complete stack trace
62 String8 toString(const char* prefix = 0) const;
63
64 size_t size() const { return mCount; }
65
66private:
Jeff Brownea45b012011-10-19 20:32:43 -070067 size_t mCount;
68 backtrace_frame_t mStack[MAX_DEPTH];
The Android Open Source Projectcbb10112009-03-03 19:31:44 -080069};
70
71}; // namespace android
72
73
74// ---------------------------------------------------------------------------
75
76#endif // ANDROID_CALLSTACK_H