Home | History | Annotate | Download | only in libbacktrace
      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_IMPL_H
     18 #define _LIBBACKTRACE_BACKTRACE_IMPL_H
     19 
     20 #include <backtrace/Backtrace.h>
     21 #include <backtrace/BacktraceMap.h>
     22 
     23 #include <sys/types.h>
     24 
     25 class BacktraceImpl {
     26 public:
     27   virtual ~BacktraceImpl() { }
     28 
     29   virtual bool Unwind(size_t num_ignore_frames, ucontext_t* ucontext) = 0;
     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 
     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(); }
     47 
     48 protected:
     49   inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; }
     50 
     51   Backtrace* backtrace_obj_;
     52 };
     53 
     54 class BacktraceCurrent : public Backtrace {
     55 public:
     56   BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map);
     57   virtual ~BacktraceCurrent();
     58 
     59   bool ReadWord(uintptr_t ptr, word_t* out_value);
     60 };
     61 
     62 class BacktracePtrace : public Backtrace {
     63 public:
     64   BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map);
     65   virtual ~BacktracePtrace();
     66 
     67   bool ReadWord(uintptr_t ptr, word_t* out_value);
     68 };
     69 
     70 Backtrace* CreateCurrentObj(BacktraceMap* map);
     71 Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map);
     72 Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map);
     73 
     74 #endif // _LIBBACKTRACE_BACKTRACE_IMPL_H
     75