blob: 079e20c6962f18d816a300f1b946f6757f492194 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Brown044966a2011-10-19 20:32:43 -070024#include <corkscrew/backtrace.h>
The Android Open Source Project9066cfe2009-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();
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
Mathias Agopianf7d63cf2010-12-10 15:37:48 -080054 void update(int32_t ignoreDepth=1, int32_t maxDepth=MAX_DEPTH);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
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
62 size_t size() const { return mCount; }
63
64private:
Jeff Brown044966a2011-10-19 20:32:43 -070065 size_t mCount;
66 backtrace_frame_t mStack[MAX_DEPTH];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067};
68
69}; // namespace android
70
71
72// ---------------------------------------------------------------------------
73
74#endif // ANDROID_CALLSTACK_H