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 | |
| 20 | #include "object.h" |
| 21 | #include "thread.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | // Walks up the stack 'n' callers, when used with Thread::WalkStack. |
| 26 | struct NthCallerVisitor : public Thread::StackVisitor { |
TDYa127 | 05fe3b6 | 2012-04-21 00:28:54 -0700 | [diff] [blame] | 27 | NthCallerVisitor(size_t n) : n(n), count(0), pc(0), caller(NULL) {} |
| 28 | bool VisitFrame(const Frame& f, uintptr_t fpc) { |
TDYa127 | 3f9137d | 2012-04-08 15:59:19 -0700 | [diff] [blame] | 29 | DCHECK(caller == NULL); |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 30 | if (count++ == n) { |
TDYa127 | 3f9137d | 2012-04-08 15:59:19 -0700 | [diff] [blame] | 31 | caller = f.GetMethod(); |
TDYa127 | 05fe3b6 | 2012-04-21 00:28:54 -0700 | [diff] [blame] | 32 | pc = fpc; |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 33 | return false; |
| 34 | } |
| 35 | return true; |
| 36 | } |
| 37 | size_t n; |
| 38 | size_t count; |
TDYa127 | 05fe3b6 | 2012-04-21 00:28:54 -0700 | [diff] [blame] | 39 | uintptr_t pc; |
TDYa127 | 3f9137d | 2012-04-08 15:59:19 -0700 | [diff] [blame] | 40 | Method* caller; |
Elliott Hughes | 6a14433 | 2012-04-03 13:07:11 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | } // namespace art |
| 44 | |
| 45 | #endif // ART_SRC_NTH_CALLER_VISITOR_H_ |