blob: 31fcaf287d78504dbbcd8a4cab49a90b7219b13a [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
17#ifndef _LIBBACKTRACE_BACKTRACE_H
18#define _LIBBACKTRACE_BACKTRACE_H
19
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 Ferris46756822014-01-14 20:16:30 -080042 virtual BacktraceMap* CreateBacktraceMap(pid_t pid) = 0;
43
Christopher Ferris17e91d42013-10-21 13:30:52 -070044protected:
Christopher Ferris46756822014-01-14 20:16:30 -080045 inline std::vector<backtrace_frame_data_t>* GetFrames() { return &backtrace_obj_->frames_; }
46
47 inline bool BuildMap() { return backtrace_obj_->BuildMap(); }
Christopher Ferris17e91d42013-10-21 13:30:52 -070048
49 Backtrace* backtrace_obj_;
50};
51
52class BacktraceCurrent : public Backtrace {
53public:
Christopher Ferris46756822014-01-14 20:16:30 -080054 BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070055 virtual ~BacktraceCurrent();
56
57 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
58};
59
60class BacktracePtrace : public Backtrace {
61public:
Christopher Ferris46756822014-01-14 20:16:30 -080062 BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070063 virtual ~BacktracePtrace();
64
65 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
66};
67
Christopher Ferris46756822014-01-14 20:16:30 -080068Backtrace* CreateCurrentObj(BacktraceMap* map);
69Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, BacktraceMap* map);
70Backtrace* CreateThreadObj(pid_t tid, BacktraceMap* map);
Christopher Ferris17e91d42013-10-21 13:30:52 -070071
72#endif // _LIBBACKTRACE_BACKTRACE_H