summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Venkatraman2017-04-11 13:22:43 -0500
committerVijay Venkatraman2017-04-11 13:22:43 -0500
commit8f2c28d572e08cb456da05d692e41f978c3776b1 (patch)
treef24d6e2e935760dd877452ad81f8f4c0fc2a97d3 /include
parenta4b40020ef5ae339e19b832f441c26b598f6c4aa (diff)
downloadplatform-system-core-8f2c28d572e08cb456da05d692e41f978c3776b1.tar.gz
platform-system-core-8f2c28d572e08cb456da05d692e41f978c3776b1.tar.xz
platform-system-core-8f2c28d572e08cb456da05d692e41f978c3776b1.zip
Moved include/backtrace to libbacktrace/include
Export libbacktrace_headers Bug: 33241851 Test: Build sailfish Change-Id: Iba310ffc21d17ba542bed954a960ab305037061c
Diffstat (limited to 'include')
l---------include/backtrace1
-rw-r--r--include/backtrace/Backtrace.h176
-rw-r--r--include/backtrace/BacktraceMap.h129
-rw-r--r--include/backtrace/backtrace_constants.h30
4 files changed, 1 insertions, 335 deletions
diff --git a/include/backtrace b/include/backtrace
new file mode 120000
index 000000000..93ce2b1e9
--- /dev/null
+++ b/include/backtrace
@@ -0,0 +1 @@
../libbacktrace/include/backtrace \ No newline at end of file
diff --git a/include/backtrace/Backtrace.h b/include/backtrace/Backtrace.h
deleted file mode 100644
index 4f73a658c..000000000
--- a/include/backtrace/Backtrace.h
+++ /dev/null
@@ -1,176 +0,0 @@
1/*
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 _BACKTRACE_BACKTRACE_H
18#define _BACKTRACE_BACKTRACE_H
19
20#include <inttypes.h>
21#include <stdint.h>
22
23#include <string>
24#include <vector>
25
26#include <backtrace/backtrace_constants.h>
27#include <backtrace/BacktraceMap.h>
28
29#if __LP64__
30#define PRIPTR "016" PRIxPTR
31typedef uint64_t word_t;
32#else
33#define PRIPTR "08" PRIxPTR
34typedef uint32_t word_t;
35#endif
36
37enum BacktraceUnwindError : uint32_t {
38 BACKTRACE_UNWIND_NO_ERROR,
39 // Something failed while trying to perform the setup to begin the unwind.
40 BACKTRACE_UNWIND_ERROR_SETUP_FAILED,
41 // There is no map information to use with the unwind.
42 BACKTRACE_UNWIND_ERROR_MAP_MISSING,
43 // An error occurred that indicates a programming error.
44 BACKTRACE_UNWIND_ERROR_INTERNAL,
45 // The thread to unwind has disappeared before the unwind can begin.
46 BACKTRACE_UNWIND_ERROR_THREAD_DOESNT_EXIST,
47 // The thread to unwind has not responded to a signal in a timely manner.
48 BACKTRACE_UNWIND_ERROR_THREAD_TIMEOUT,
49 // Attempt to do an unsupported operation.
50 BACKTRACE_UNWIND_ERROR_UNSUPPORTED_OPERATION,
51 // Attempt to do an offline unwind without a context.
52 BACKTRACE_UNWIND_ERROR_NO_CONTEXT,
53};
54
55struct backtrace_frame_data_t {
56 size_t num; // The current fame number.
57 uintptr_t pc; // The absolute pc.
58 uintptr_t sp; // The top of the stack.
59 size_t stack_size; // The size of the stack, zero indicate an unknown stack size.
60 backtrace_map_t map; // The map associated with the given pc.
61 std::string func_name; // The function name associated with this pc, NULL if not found.
62 uintptr_t func_offset; // pc relative to the start of the function, only valid if func_name is not NULL.
63};
64
65#if defined(__APPLE__)
66struct __darwin_ucontext;
67typedef __darwin_ucontext ucontext_t;
68#else
69struct ucontext;
70typedef ucontext ucontext_t;
71#endif
72
73struct backtrace_stackinfo_t {
74 uint64_t start;
75 uint64_t end;
76 const uint8_t* data;
77};
78
79class Backtrace {
80public:
81 // Create the correct Backtrace object based on what is to be unwound.
82 // If pid < 0 or equals the current pid, then the Backtrace object
83 // corresponds to the current process.
84 // If pid < 0 or equals the current pid and tid >= 0, then the Backtrace
85 // object corresponds to a thread in the current process.
86 // If pid >= 0 and tid < 0, then the Backtrace object corresponds to a
87 // different process.
88 // Tracing a thread in a different process is not supported.
89 // If map is NULL, then create the map and manage it internally.
90 // If map is not NULL, the map is still owned by the caller.
91 static Backtrace* Create(pid_t pid, pid_t tid, BacktraceMap* map = NULL);
92
93 // Create an offline Backtrace object that can be used to do an unwind without a process
94 // that is still running. If cache_file is set to true, then elf information will be cached
95 // for this call. The cached information survives until the calling process ends. This means
96 // that subsequent calls to create offline Backtrace objects will continue to use the same
97 // cache. It also assumes that the elf files used for each offline unwind are the same.
98 static Backtrace* CreateOffline(pid_t pid, pid_t tid, BacktraceMap* map,
99 const backtrace_stackinfo_t& stack, bool cache_file = false);
100
101 virtual ~Backtrace();
102
103 // Get the current stack trace and store in the backtrace_ structure.
104 virtual bool Unwind(size_t num_ignore_frames, ucontext_t* context = NULL) = 0;
105
106 // Get the function name and offset into the function given the pc.
107 // If the string is empty, then no valid function name was found,
108 // or the pc is not in any valid map.
109 virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset,
110 const backtrace_map_t* map = NULL);
111
112 // Fill in the map data associated with the given pc.
113 virtual void FillInMap(uintptr_t pc, backtrace_map_t* map);
114
115 // Read the data at a specific address.
116 virtual bool ReadWord(uintptr_t ptr, word_t* out_value) = 0;
117
118 // Read arbitrary data from a specific address. If a read request would
119 // span from one map to another, this call only reads up until the end
120 // of the current map.
121 // Returns the total number of bytes actually read.
122 virtual size_t Read(uintptr_t addr, uint8_t* buffer, size_t bytes) = 0;
123
124 // Create a string representing the formatted line of backtrace information
125 // for a single frame.
126 virtual std::string FormatFrameData(size_t frame_num);
127 virtual std::string FormatFrameData(const backtrace_frame_data_t* frame);
128
129 pid_t Pid() const { return pid_; }
130 pid_t Tid() const { return tid_; }
131 size_t NumFrames() const { return frames_.size(); }
132
133 const backtrace_frame_data_t* GetFrame(size_t frame_num) {
134 if (frame_num >= frames_.size()) {
135 return NULL;
136 }
137 return &frames_[frame_num];
138 }
139
140 typedef std::vector<backtrace_frame_data_t>::iterator iterator;
141 iterator begin() { return frames_.begin(); }
142 iterator end() { return frames_.end(); }
143
144 typedef std::vector<backtrace_frame_data_t>::const_iterator const_iterator;
145 const_iterator begin() const { return frames_.begin(); }
146 const_iterator end() const { return frames_.end(); }
147
148 BacktraceMap* GetMap() { return map_; }
149
150 BacktraceUnwindError GetError() { return error_; }
151
152 std::string GetErrorString(BacktraceUnwindError error);
153
154protected:
155 Backtrace(pid_t pid, pid_t tid, BacktraceMap* map);
156
157 // The name returned is not demangled, GetFunctionName() takes care of
158 // demangling the name.
159 virtual std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) = 0;
160
161 virtual bool VerifyReadWordArgs(uintptr_t ptr, word_t* out_value);
162
163 bool BuildMap();
164
165 pid_t pid_;
166 pid_t tid_;
167
168 BacktraceMap* map_;
169 bool map_shared_;
170
171 std::vector<backtrace_frame_data_t> frames_;
172
173 BacktraceUnwindError error_;
174};
175
176#endif // _BACKTRACE_BACKTRACE_H
diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h
deleted file mode 100644
index 8ab0dfabb..000000000
--- a/include/backtrace/BacktraceMap.h
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 * Copyright (C) 2014 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 _BACKTRACE_BACKTRACE_MAP_H
18#define _BACKTRACE_BACKTRACE_MAP_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#ifdef _WIN32
23// MINGW does not define these constants.
24#define PROT_NONE 0
25#define PROT_READ 0x1
26#define PROT_WRITE 0x2
27#define PROT_EXEC 0x4
28#else
29#include <sys/mman.h>
30#endif
31
32#include <deque>
33#include <string>
34#include <vector>
35
36// Special flag to indicate a map is in /dev/. However, a map in
37// /dev/ashmem/... does not set this flag.
38static constexpr int PROT_DEVICE_MAP = 0x8000;
39
40struct backtrace_map_t {
41 uintptr_t start = 0;
42 uintptr_t end = 0;
43 uintptr_t offset = 0;
44 uintptr_t load_base = 0;
45 int flags = 0;
46 std::string name;
47};
48
49class BacktraceMap {
50public:
51 // If uncached is true, then parse the current process map as of the call.
52 // Passing a map created with uncached set to true to Backtrace::Create()
53 // is unsupported.
54 static BacktraceMap* Create(pid_t pid, bool uncached = false);
55
56 static BacktraceMap* Create(pid_t pid, const std::vector<backtrace_map_t>& maps);
57
58 virtual ~BacktraceMap();
59
60 // Fill in the map data structure for the given address.
61 virtual void FillIn(uintptr_t addr, backtrace_map_t* map);
62
63 // The flags returned are the same flags as used by the mmap call.
64 // The values are PROT_*.
65 int GetFlags(uintptr_t pc) {
66 backtrace_map_t map;
67 FillIn(pc, &map);
68 if (IsValid(map)) {
69 return map.flags;
70 }
71 return PROT_NONE;
72 }
73
74 bool IsReadable(uintptr_t pc) { return GetFlags(pc) & PROT_READ; }
75 bool IsWritable(uintptr_t pc) { return GetFlags(pc) & PROT_WRITE; }
76 bool IsExecutable(uintptr_t pc) { return GetFlags(pc) & PROT_EXEC; }
77
78 // In order to use the iterators on this object, a caller must
79 // call the LockIterator and UnlockIterator function to guarantee
80 // that the data does not change while it's being used.
81 virtual void LockIterator() {}
82 virtual void UnlockIterator() {}
83
84 typedef std::deque<backtrace_map_t>::iterator iterator;
85 iterator begin() { return maps_.begin(); }
86 iterator end() { return maps_.end(); }
87
88 typedef std::deque<backtrace_map_t>::const_iterator const_iterator;
89 const_iterator begin() const { return maps_.begin(); }
90 const_iterator end() const { return maps_.end(); }
91
92 virtual bool Build();
93
94 static inline bool IsValid(const backtrace_map_t& map) {
95 return map.end > 0;
96 }
97
98 static uintptr_t GetRelativePc(const backtrace_map_t& map, uintptr_t pc) {
99 if (IsValid(map)) {
100 return pc - map.start + map.load_base;
101 } else {
102 return pc;
103 }
104 }
105
106protected:
107 BacktraceMap(pid_t pid);
108
109 virtual bool ParseLine(const char* line, backtrace_map_t* map);
110
111 std::deque<backtrace_map_t> maps_;
112 pid_t pid_;
113};
114
115class ScopedBacktraceMapIteratorLock {
116public:
117 explicit ScopedBacktraceMapIteratorLock(BacktraceMap* map) : map_(map) {
118 map->LockIterator();
119 }
120
121 ~ScopedBacktraceMapIteratorLock() {
122 map_->UnlockIterator();
123 }
124
125private:
126 BacktraceMap* map_;
127};
128
129#endif // _BACKTRACE_BACKTRACE_MAP_H
diff --git a/include/backtrace/backtrace_constants.h b/include/backtrace/backtrace_constants.h
deleted file mode 100644
index f8c15755f..000000000
--- a/include/backtrace/backtrace_constants.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright (C) 2014 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 _BACKTRACE_BACKTRACE_CONSTANTS_H
18#define _BACKTRACE_BACKTRACE_CONSTANTS_H
19
20// When the pid to be traced is set to this value, then trace the current
21// process. If the tid value is not BACKTRACE_NO_TID, then the specified
22// thread from the current process will be traced.
23#define BACKTRACE_CURRENT_PROCESS -1
24// When the tid to be traced is set to this value, then trace the specified
25// current thread of the specified pid.
26#define BACKTRACE_CURRENT_THREAD -1
27
28#define MAX_BACKTRACE_FRAMES 64
29
30#endif // _BACKTRACE_BACKTRACE_CONSTANTS_H