blob: af014d5adf8293b36ac59e5e2c4464d9db147e34 [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 Ferris46756822014-01-14 20:16:30 -080024#include <log/log.h>
Christopher Ferris17e91d42013-10-21 13:30:52 -070025
Christopher Ferris8ed46272013-10-29 15:44:25 -070026// 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 Ferris17e91d42013-10-21 13:30:52 -070030class BacktraceImpl {
31public:
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 Ferrisdf290612014-01-22 19:21:07 -080042 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 Ferris46756822014-01-14 20:16:30 -080052
Christopher Ferris17e91d42013-10-21 13:30:52 -070053protected:
Christopher Ferris46756822014-01-14 20:16:30 -080054 inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; }
55
Christopher Ferris17e91d42013-10-21 13:30:52 -070056 Backtrace* backtrace_obj_;
57};
58
59class BacktraceCurrent : public Backtrace {
60public:
Christopher Ferris46756822014-01-14 20:16:30 -080061 BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070062 virtual ~BacktraceCurrent();
63
64 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
65};
66
67class BacktracePtrace : public Backtrace {
68public:
Christopher Ferris46756822014-01-14 20:16:30 -080069 BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070070 virtual ~BacktracePtrace();
71
72 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
73};
74
Christopher Ferris46756822014-01-14 20:16:30 -080075Backtrace* CreateCurrentObj(BacktraceMap* map);
76Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map);
77Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070078
Christopher Ferrisdf290612014-01-22 19:21:07 -080079#endif // _LIBBACKTRACE_BACKTRACE_IMPL_H