blob: c0b686e3f21d03f4f69df445612400a6bcaf0068 [file] [log] [blame]
Yabin Cui9e402bb2015-09-22 04:46:57 +00001/*
2 * Copyright (C) 2015 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_UNWIND_OFFLINE_H
18#define _LIBBACKTRACE_UNWIND_OFFLINE_H
19
20#include <libunwind.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <ucontext.h>
24
25#include <unordered_map>
26#include <unordered_set>
27
28#include <backtrace/Backtrace.h>
29
30struct Space {
31 uint64_t start;
32 uint64_t end;
33 const uint8_t* data;
34
35 Space() {
36 Clear();
37 }
38
39 void Clear();
40 size_t Read(uint64_t addr, uint8_t* buffer, size_t size);
41};
42
Yabin Cui5d991bc2016-11-15 17:47:09 -080043struct DebugFrameInfo;
Yabin Cui9e402bb2015-09-22 04:46:57 +000044
45class BacktraceOffline : public Backtrace {
46 public:
47 BacktraceOffline(pid_t pid, pid_t tid, BacktraceMap* map, const backtrace_stackinfo_t& stack,
48 bool cache_file)
49 : Backtrace(pid, tid, map),
50 cache_file_(cache_file),
Yabin Cui5d991bc2016-11-15 17:47:09 -080051 context_(nullptr) {
Yabin Cui9e402bb2015-09-22 04:46:57 +000052 stack_space_.start = stack.start;
53 stack_space_.end = stack.end;
54 stack_space_.data = stack.data;
55 }
56
Yabin Cui5d991bc2016-11-15 17:47:09 -080057 virtual ~BacktraceOffline() = default;
Yabin Cui9e402bb2015-09-22 04:46:57 +000058
59 bool Unwind(size_t num_ignore_frames, ucontext_t* context) override;
60
61 bool ReadWord(uintptr_t ptr, word_t* out_value) override;
62
63 size_t Read(uintptr_t addr, uint8_t* buffer, size_t bytes) override;
64
65 bool FindProcInfo(unw_addr_space_t addr_space, uint64_t ip, unw_proc_info_t* proc_info,
66 int need_unwind_info);
67
68 bool ReadReg(size_t reg_index, uint64_t* value);
69
70 protected:
71 std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) override;
72 DebugFrameInfo* GetDebugFrameInFile(const std::string& filename);
73
Yabin Cui9e402bb2015-09-22 04:46:57 +000074 bool cache_file_;
75 ucontext_t* context_;
76 Space eh_frame_hdr_space_;
77 Space eh_frame_space_;
Yabin Cui5d991bc2016-11-15 17:47:09 -080078 Space arm_extab_space_;
79 Space arm_exidx_space_;
Yabin Cui9e402bb2015-09-22 04:46:57 +000080 Space stack_space_;
Yabin Cui9e402bb2015-09-22 04:46:57 +000081};
82
83#endif // _LIBBACKTRACE_BACKTRACE_OFFLINE_H