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 | |
Christopher Ferris | df29061 | 2014-01-22 19:21:07 -0800 | [diff] [blame] | 17 | #ifndef _LIBBACKTRACE_BACKTRACE_IMPL_H |
| 18 | #define _LIBBACKTRACE_BACKTRACE_IMPL_H |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 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 | df29061 | 2014-01-22 19:21:07 -0800 | [diff] [blame] | 42 | inline pid_t Pid() { return backtrace_obj_->Pid(); } |
| 43 | inline pid_t Tid() { return backtrace_obj_->Tid(); } |
| 44 | |
| 45 | inline const backtrace_map_t* FindMap(uintptr_t addr) { |
| 46 | return backtrace_obj_->FindMap(addr); |
| 47 | } |
| 48 | inline std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) { |
| 49 | return backtrace_obj_->GetFunctionName(pc, offset); |
| 50 | } |
| 51 | inline BacktraceMap* GetMap() { return backtrace_obj_->GetMap(); } |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 52 | |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 53 | protected: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 54 | inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; } |
| 55 | |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 56 | Backtrace* backtrace_obj_; |
| 57 | }; |
| 58 | |
| 59 | class BacktraceCurrent : public Backtrace { |
| 60 | public: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 61 | BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 62 | virtual ~BacktraceCurrent(); |
| 63 | |
| 64 | bool ReadWord(uintptr_t ptr, uint32_t* out_value); |
| 65 | }; |
| 66 | |
| 67 | class BacktracePtrace : public Backtrace { |
| 68 | public: |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 69 | BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 70 | virtual ~BacktracePtrace(); |
| 71 | |
| 72 | bool ReadWord(uintptr_t ptr, uint32_t* out_value); |
| 73 | }; |
| 74 | |
Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 75 | Backtrace* CreateCurrentObj(BacktraceMap* map); |
| 76 | Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map); |
| 77 | Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map); |
Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 78 | |
Christopher Ferris | df29061 | 2014-01-22 19:21:07 -0800 | [diff] [blame] | 79 | #endif // _LIBBACKTRACE_BACKTRACE_IMPL_H |