blob: 6b3894edff0b23ffebaa468a0451ec70f1dfacba [file] [log] [blame]
Elliott Hughes6a144332012-04-03 13:07:11 -07001/*
2 * Copyright (C) 2012 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 ART_SRC_NTH_CALLER_VISITOR_H_
18#define ART_SRC_NTH_CALLER_VISITOR_H_
19
20#include "object.h"
21#include "thread.h"
22
23namespace art {
24
25// Walks up the stack 'n' callers, when used with Thread::WalkStack.
Ian Rogers0399dde2012-06-06 17:09:28 -070026struct NthCallerVisitor : public StackVisitor {
Elliott Hughes08fc03a2012-06-26 17:34:00 -070027 NthCallerVisitor(const ManagedStack* stack, const std::vector<TraceStackFrame>* trace_stack, size_t n)
28 : StackVisitor(stack, trace_stack, NULL), n(n), count(0), caller(NULL) {}
29
Ian Rogers0399dde2012-06-06 17:09:28 -070030 bool VisitFrame() {
TDYa1273f9137d2012-04-08 15:59:19 -070031 DCHECK(caller == NULL);
Elliott Hughes6a144332012-04-03 13:07:11 -070032 if (count++ == n) {
Ian Rogers0399dde2012-06-06 17:09:28 -070033 caller = GetMethod();
Elliott Hughes6a144332012-04-03 13:07:11 -070034 return false;
35 }
36 return true;
37 }
Elliott Hughes08fc03a2012-06-26 17:34:00 -070038
Elliott Hughes6a144332012-04-03 13:07:11 -070039 size_t n;
40 size_t count;
Mathieu Chartier66f19252012-09-18 08:57:04 -070041 AbstractMethod* caller;
Elliott Hughes6a144332012-04-03 13:07:11 -070042};
43
44} // namespace art
45
46#endif // ART_SRC_NTH_CALLER_VISITOR_H_