Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 20 | #include "mirror/abstract_method.h" |
| 21 | #include "stack.h" |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | class Thread; |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 25 | |
| 26 | // Walks up the stack 'n' callers, when used with Thread::WalkStack. |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 27 | struct NthCallerVisitor : public StackVisitor { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 28 | NthCallerVisitor(Thread* thread, size_t n) |
| 29 | : StackVisitor(thread, NULL), n(n), count(0), caller(NULL) {} |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 30 | |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 31 | bool VisitFrame() { |
TDYa127 | 3f9137d | 2012-04-08 15:59:19 -0700 | [diff] [blame] | 32 | DCHECK(caller == NULL); |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 33 | if (count++ == n) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 34 | caller = GetMethod(); |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 35 | return false; |
| 36 | } |
| 37 | return true; |
| 38 | } |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 39 | |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 40 | size_t n; |
| 41 | size_t count; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | mirror::AbstractMethod* caller; |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | } // namespace art |
| 46 | |
| 47 | #endif // ART_SRC_NTH_CALLER_VISITOR_H_ |