Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 _LIBBACKTRACE_BACKTRACE_H |
| 18 | #define _LIBBACKTRACE_BACKTRACE_H |
| 19 | |
| 20 | #include <backtrace/Backtrace.h> |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 21 | #include <backtrace/BacktraceMap.h> |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 22 | |
| 23 | #include <sys/types.h> |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 24 | #include <log/log.h> |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 25 | |
Christopher Ferris | 8ed4627 | 2013-10-29 15:44:25 -0700 | [diff] [blame] | 26 | // Macro to log the function name along with the warning message. |
| 27 | #define BACK_LOGW(format, ...) \ |
| 28 | ALOGW("%s: " format, __PRETTY_FUNCTION__, ##__VA_ARGS__) |
| 29 | |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 30 | class BacktraceImpl { |
| 31 | public: |
| 32 | virtual ~BacktraceImpl() { } |
| 33 | |
| 34 | virtual bool Unwind(size_t num_ignore_frames) = 0; |
| 35 | |
| 36 | // The name returned is not demangled, Backtrace::GetFunctionName() |
| 37 | // takes care of demangling the name. |
| 38 | virtual std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) = 0; |
| 39 | |
| 40 | void SetParent(Backtrace* backtrace) { backtrace_obj_ = backtrace; } |
| 41 | |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 42 | virtual BacktraceMap* CreateBacktraceMap(pid_t pid) = 0; |
| 43 | |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 44 | protected: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 45 | inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; } |
| 46 | |
| 47 | inline bool BuildMap() { return backtrace_obj_->BuildMap(); } |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 48 | |
| 49 | Backtrace* backtrace_obj_; |
| 50 | }; |
| 51 | |
| 52 | class BacktraceCurrent : public Backtrace { |
| 53 | public: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 54 | BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 55 | virtual ~BacktraceCurrent(); |
| 56 | |
| 57 | bool ReadWord(uintptr_t ptr, uint32_t* out_value); |
| 58 | }; |
| 59 | |
| 60 | class BacktracePtrace : public Backtrace { |
| 61 | public: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 62 | BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 63 | virtual ~BacktracePtrace(); |
| 64 | |
| 65 | bool ReadWord(uintptr_t ptr, uint32_t* out_value); |
| 66 | }; |
| 67 | |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame^] | 68 | Backtrace* CreateCurrentObj(BacktraceMap* map); |
| 69 | Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map); |
| 70 | Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 71 | |
| 72 | #endif // _LIBBACKTRACE_BACKTRACE_H |