blob: d34ad055a3e2d7e8abff70f6687d77ad1c6f6628 [file] [log] [blame]
Christopher Ferris17e91d42013-10-21 13:30:52 -07001/*
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 Ferrisdf290612014-01-22 19:21:07 -080017#ifndef _LIBBACKTRACE_BACKTRACE_IMPL_H
18#define _LIBBACKTRACE_BACKTRACE_IMPL_H
Christopher Ferris17e91d42013-10-21 13:30:52 -070019
20#include <backtrace/Backtrace.h>
Christopher Ferris46756822014-01-14 20:16:30 -080021#include <backtrace/BacktraceMap.h>
Christopher Ferris17e91d42013-10-21 13:30:52 -070022
23#include <sys/types.h>
Christopher Ferris8ed46272013-10-29 15:44:25 -070024
Christopher Ferris17e91d42013-10-21 13:30:52 -070025class BacktraceImpl {
26public:
27 virtual ~BacktraceImpl() { }
28
Christopher Ferrisa2efd3a2014-05-06 15:23:59 -070029 virtual bool Unwind(size_t num_ignore_frames, ucontext_t* ucontext) = 0;
Christopher Ferris17e91d42013-10-21 13:30:52 -070030
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 Ferrisdf290612014-01-22 19:21:07 -080037 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 Ferris46756822014-01-14 20:16:30 -080047
Christopher Ferris17e91d42013-10-21 13:30:52 -070048protected:
Christopher Ferris46756822014-01-14 20:16:30 -080049 inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; }
50
Christopher Ferris17e91d42013-10-21 13:30:52 -070051 Backtrace* backtrace_obj_;
52};
53
54class BacktraceCurrent : public Backtrace {
55public:
Christopher Ferris46756822014-01-14 20:16:30 -080056 BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070057 virtual ~BacktraceCurrent();
58
Pavel Chupinc6c194c2013-11-21 23:17:20 +040059 bool ReadWord(uintptr_t ptr, word_t* out_value);
Christopher Ferris17e91d42013-10-21 13:30:52 -070060};
61
62class BacktracePtrace : public Backtrace {
63public:
Christopher Ferris46756822014-01-14 20:16:30 -080064 BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070065 virtual ~BacktracePtrace();
66
Pavel Chupinc6c194c2013-11-21 23:17:20 +040067 bool ReadWord(uintptr_t ptr, word_t* out_value);
Christopher Ferris17e91d42013-10-21 13:30:52 -070068};
69
Christopher Ferris46756822014-01-14 20:16:30 -080070Backtrace* CreateCurrentObj(BacktraceMap* map);
71Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map);
72Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070073
Christopher Ferrisdf290612014-01-22 19:21:07 -080074#endif // _LIBBACKTRACE_BACKTRACE_IMPL_H