| 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 | 8ed4627 | 2013-10-29 15:44:25 -0700 | [diff] [blame] | 24 |  | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 25 | class BacktraceImpl { | 
 | 26 | public: | 
 | 27 |   virtual ~BacktraceImpl() { } | 
 | 28 |  | 
| Christopher Ferris | a2efd3a | 2014-05-06 15:23:59 -0700 | [diff] [blame] | 29 |   virtual bool Unwind(size_t num_ignore_frames, ucontext_t* ucontext) = 0; | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 30 |  | 
 | 31 |   // The name returned is not demangled, Backtrace::GetFunctionName() | 
 | 32 |   // takes care of demangling the name. | 
 | 33 |   virtual std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) = 0; | 
 | 34 |  | 
 | 35 |   void SetParent(Backtrace* backtrace) { backtrace_obj_ = backtrace; } | 
 | 36 |  | 
| Christopher Ferris | df29061 | 2014-01-22 19:21:07 -0800 | [diff] [blame] | 37 |   inline pid_t Pid() { return backtrace_obj_->Pid(); } | 
 | 38 |   inline pid_t Tid() { return backtrace_obj_->Tid(); } | 
 | 39 |  | 
 | 40 |   inline const backtrace_map_t* FindMap(uintptr_t addr) { | 
 | 41 |     return backtrace_obj_->FindMap(addr); | 
 | 42 |   } | 
 | 43 |   inline std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) { | 
 | 44 |     return backtrace_obj_->GetFunctionName(pc, offset); | 
 | 45 |   } | 
 | 46 |   inline BacktraceMap* GetMap() { return backtrace_obj_->GetMap(); } | 
| Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 47 |  | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 48 | protected: | 
| Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 49 |   inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; } | 
 | 50 |  | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 51 |   Backtrace* backtrace_obj_; | 
 | 52 | }; | 
 | 53 |  | 
 | 54 | class BacktraceCurrent : public Backtrace { | 
 | 55 | public: | 
| Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 56 |   BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map); | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 57 |   virtual ~BacktraceCurrent(); | 
 | 58 |  | 
| Pavel Chupin | c6c194c | 2013-11-21 23:17:20 +0400 | [diff] [blame] | 59 |   bool ReadWord(uintptr_t ptr, word_t* out_value); | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 60 | }; | 
 | 61 |  | 
 | 62 | class BacktracePtrace : public Backtrace { | 
 | 63 | public: | 
| Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 64 |   BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map); | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 65 |   virtual ~BacktracePtrace(); | 
 | 66 |  | 
| Pavel Chupin | c6c194c | 2013-11-21 23:17:20 +0400 | [diff] [blame] | 67 |   bool ReadWord(uintptr_t ptr, word_t* out_value); | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 68 | }; | 
 | 69 |  | 
| Christopher Ferris | 4675682 | 2014-01-14 20:16:30 -0800 | [diff] [blame] | 70 | Backtrace* CreateCurrentObj(BacktraceMap* map); | 
 | 71 | Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map); | 
 | 72 | Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map); | 
| Christopher Ferris | 17e91d4 | 2013-10-21 13:30:52 -0700 | [diff] [blame] | 73 |  | 
| Christopher Ferris | df29061 | 2014-01-22 19:21:07 -0800 | [diff] [blame] | 74 | #endif // _LIBBACKTRACE_BACKTRACE_IMPL_H |