blob: d741ef1998a48055b68b4812a53ae4f7fe942101 [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>
21
22#include <sys/types.h>
23
Christopher Ferris8ed46272013-10-29 15:44:25 -070024// Macro to log the function name along with the warning message.
25#define BACK_LOGW(format, ...) \
26 ALOGW("%s: " format, __PRETTY_FUNCTION__, ##__VA_ARGS__)
27
Christopher Ferris17e91d42013-10-21 13:30:52 -070028class BacktraceImpl {
29public:
30 virtual ~BacktraceImpl() { }
31
32 virtual bool Unwind(size_t num_ignore_frames) = 0;
33
34 // The name returned is not demangled, Backtrace::GetFunctionName()
35 // takes care of demangling the name.
36 virtual std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) = 0;
37
38 void SetParent(Backtrace* backtrace) { backtrace_obj_ = backtrace; }
39
40protected:
41 backtrace_t* GetBacktraceData();
42
43 Backtrace* backtrace_obj_;
44};
45
46class BacktraceCurrent : public Backtrace {
47public:
Christopher Ferris98464972014-01-06 19:16:33 -080048 BacktraceCurrent(BacktraceImpl* impl, backtrace_map_info_t* map_info);
Christopher Ferris17e91d42013-10-21 13:30:52 -070049 virtual ~BacktraceCurrent();
50
51 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
52};
53
54class BacktracePtrace : public Backtrace {
55public:
Christopher Ferris98464972014-01-06 19:16:33 -080056 BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, backtrace_map_info_t* map_info);
Christopher Ferris17e91d42013-10-21 13:30:52 -070057 virtual ~BacktracePtrace();
58
59 bool ReadWord(uintptr_t ptr, uint32_t* out_value);
60};
61
Christopher Ferris98464972014-01-06 19:16:33 -080062Backtrace* CreateCurrentObj(backtrace_map_info_t* map_info);
63Backtrace* CreatePtraceObj(pid_t pid, pid_t tid, backtrace_map_info_t* map_info);
64Backtrace* CreateThreadObj(pid_t tid, backtrace_map_info_t* map_info);
Christopher Ferris17e91d42013-10-21 13:30:52 -070065
66#endif // _LIBBACKTRACE_BACKTRACE_H