blob: b15eb5c60be5ad9422887fa7c6bca974574b8f79 [file] [log] [blame]
Saleem Abdulrasool17552662015-04-24 19:39:17 +00001//===------------------------- AddressSpace.hpp ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//
9// Abstracts accessing local vs remote address spaces.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef __ADDRESSSPACE_HPP__
14#define __ADDRESSSPACE_HPP__
15
16#include <stdint.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21#ifndef _LIBUNWIND_IS_BAREMETAL
22#include <dlfcn.h>
23#endif
24
25#ifdef __APPLE__
26#include <mach-o/getsect.h>
27namespace libunwind {
28 bool checkKeyMgrRegisteredFDEs(uintptr_t targetAddr, void *&fde);
29}
30#endif
31
32#include "libunwind.h"
33#include "config.h"
34#include "dwarf2.h"
35#include "Registers.hpp"
36
Logan Chien06b0c7a2015-07-19 15:23:10 +000037#if _LIBUNWIND_ARM_EHABI
Ed Schouten6a4939b2017-03-05 19:11:24 +000038#if defined(_LIBUNWIND_IS_BAREMETAL)
39// When statically linked on bare-metal, the symbols for the EH table are looked
40// up without going through the dynamic loader.
Ed Schouten5d3f35b2017-03-07 15:21:57 +000041extern char __exidx_start;
42extern char __exidx_end;
Ed Schouten6a4939b2017-03-05 19:11:24 +000043#else
44#include <link.h>
Saleem Abdulrasool17552662015-04-24 19:39:17 +000045#endif // !defined(_LIBUNWIND_IS_BAREMETAL)
Logan Chien06b0c7a2015-07-19 15:23:10 +000046#endif // _LIBUNWIND_ARM_EHABI
Saleem Abdulrasool17552662015-04-24 19:39:17 +000047
Petr Hosek35d59d52016-10-23 21:48:47 +000048#if defined(__CloudABI__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
49 defined(__linux__) || defined(__NetBSD__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000050#if _LIBUNWIND_SUPPORT_DWARF_UNWIND && _LIBUNWIND_SUPPORT_DWARF_INDEX
51#include <link.h>
Ed Schouten86f3b4b2015-04-29 20:43:44 +000052// Macro for machine-independent access to the ELF program headers. This
53// macro is not available on some systems (e.g., FreeBSD). On these
54// systems the data structures are just called Elf_XXX. Define ElfW()
55// locally.
56#if !defined(ElfW)
57#define ElfW(type) Elf_##type
58#endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +000059#include "EHHeaderParser.hpp"
60#endif
61#endif
62
63namespace libunwind {
64
65/// Used by findUnwindSections() to return info about needed sections.
66struct UnwindInfoSections {
67#if _LIBUNWIND_SUPPORT_DWARF_UNWIND || _LIBUNWIND_SUPPORT_DWARF_INDEX || \
68 _LIBUNWIND_SUPPORT_COMPACT_UNWIND
69 // No dso_base for ARM EHABI.
70 uintptr_t dso_base;
71#endif
72#if _LIBUNWIND_SUPPORT_DWARF_UNWIND
73 uintptr_t dwarf_section;
74 uintptr_t dwarf_section_length;
75#endif
76#if _LIBUNWIND_SUPPORT_DWARF_INDEX
77 uintptr_t dwarf_index_section;
78 uintptr_t dwarf_index_section_length;
79#endif
80#if _LIBUNWIND_SUPPORT_COMPACT_UNWIND
81 uintptr_t compact_unwind_section;
82 uintptr_t compact_unwind_section_length;
83#endif
Logan Chien06b0c7a2015-07-19 15:23:10 +000084#if _LIBUNWIND_ARM_EHABI
Saleem Abdulrasool17552662015-04-24 19:39:17 +000085 uintptr_t arm_section;
86 uintptr_t arm_section_length;
87#endif
88};
89
90
91/// LocalAddressSpace is used as a template parameter to UnwindCursor when
92/// unwinding a thread in the same process. The wrappers compile away,
93/// making local unwinds fast.
94class __attribute__((visibility("hidden"))) LocalAddressSpace {
95public:
96#ifdef __LP64__
97 typedef uint64_t pint_t;
98 typedef int64_t sint_t;
99#else
100 typedef uint32_t pint_t;
101 typedef int32_t sint_t;
102#endif
103 uint8_t get8(pint_t addr) {
104 uint8_t val;
105 memcpy(&val, (void *)addr, sizeof(val));
106 return val;
107 }
108 uint16_t get16(pint_t addr) {
109 uint16_t val;
110 memcpy(&val, (void *)addr, sizeof(val));
111 return val;
112 }
113 uint32_t get32(pint_t addr) {
114 uint32_t val;
115 memcpy(&val, (void *)addr, sizeof(val));
116 return val;
117 }
118 uint64_t get64(pint_t addr) {
119 uint64_t val;
120 memcpy(&val, (void *)addr, sizeof(val));
121 return val;
122 }
123 double getDouble(pint_t addr) {
124 double val;
125 memcpy(&val, (void *)addr, sizeof(val));
126 return val;
127 }
128 v128 getVector(pint_t addr) {
129 v128 val;
130 memcpy(&val, (void *)addr, sizeof(val));
131 return val;
132 }
133 uintptr_t getP(pint_t addr);
134 static uint64_t getULEB128(pint_t &addr, pint_t end);
135 static int64_t getSLEB128(pint_t &addr, pint_t end);
136
137 pint_t getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
138 pint_t datarelBase = 0);
139 bool findFunctionName(pint_t addr, char *buf, size_t bufLen,
140 unw_word_t *offset);
141 bool findUnwindSections(pint_t targetAddr, UnwindInfoSections &info);
142 bool findOtherFDE(pint_t targetAddr, pint_t &fde);
143
144 static LocalAddressSpace sThisAddressSpace;
145};
146
147inline uintptr_t LocalAddressSpace::getP(pint_t addr) {
148#ifdef __LP64__
149 return get64(addr);
150#else
151 return get32(addr);
152#endif
153}
154
155/// Read a ULEB128 into a 64-bit word.
156inline uint64_t LocalAddressSpace::getULEB128(pint_t &addr, pint_t end) {
157 const uint8_t *p = (uint8_t *)addr;
158 const uint8_t *pend = (uint8_t *)end;
159 uint64_t result = 0;
160 int bit = 0;
161 do {
162 uint64_t b;
163
164 if (p == pend)
165 _LIBUNWIND_ABORT("truncated uleb128 expression");
166
167 b = *p & 0x7f;
168
169 if (bit >= 64 || b << bit >> bit != b) {
170 _LIBUNWIND_ABORT("malformed uleb128 expression");
171 } else {
172 result |= b << bit;
173 bit += 7;
174 }
175 } while (*p++ >= 0x80);
176 addr = (pint_t) p;
177 return result;
178}
179
180/// Read a SLEB128 into a 64-bit word.
181inline int64_t LocalAddressSpace::getSLEB128(pint_t &addr, pint_t end) {
182 const uint8_t *p = (uint8_t *)addr;
183 const uint8_t *pend = (uint8_t *)end;
184 int64_t result = 0;
185 int bit = 0;
186 uint8_t byte;
187 do {
188 if (p == pend)
189 _LIBUNWIND_ABORT("truncated sleb128 expression");
190 byte = *p++;
191 result |= ((byte & 0x7f) << bit);
192 bit += 7;
193 } while (byte & 0x80);
194 // sign extend negative numbers
195 if ((byte & 0x40) != 0)
196 result |= (-1LL) << bit;
197 addr = (pint_t) p;
198 return result;
199}
200
201inline LocalAddressSpace::pint_t
202LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
203 pint_t datarelBase) {
204 pint_t startAddr = addr;
205 const uint8_t *p = (uint8_t *)addr;
206 pint_t result;
207
208 // first get value
209 switch (encoding & 0x0F) {
210 case DW_EH_PE_ptr:
211 result = getP(addr);
212 p += sizeof(pint_t);
213 addr = (pint_t) p;
214 break;
215 case DW_EH_PE_uleb128:
216 result = (pint_t)getULEB128(addr, end);
217 break;
218 case DW_EH_PE_udata2:
219 result = get16(addr);
220 p += 2;
221 addr = (pint_t) p;
222 break;
223 case DW_EH_PE_udata4:
224 result = get32(addr);
225 p += 4;
226 addr = (pint_t) p;
227 break;
228 case DW_EH_PE_udata8:
229 result = (pint_t)get64(addr);
230 p += 8;
231 addr = (pint_t) p;
232 break;
233 case DW_EH_PE_sleb128:
234 result = (pint_t)getSLEB128(addr, end);
235 break;
236 case DW_EH_PE_sdata2:
237 // Sign extend from signed 16-bit value.
238 result = (pint_t)(int16_t)get16(addr);
239 p += 2;
240 addr = (pint_t) p;
241 break;
242 case DW_EH_PE_sdata4:
243 // Sign extend from signed 32-bit value.
244 result = (pint_t)(int32_t)get32(addr);
245 p += 4;
246 addr = (pint_t) p;
247 break;
248 case DW_EH_PE_sdata8:
249 result = (pint_t)get64(addr);
250 p += 8;
251 addr = (pint_t) p;
252 break;
253 default:
254 _LIBUNWIND_ABORT("unknown pointer encoding");
255 }
256
257 // then add relative offset
258 switch (encoding & 0x70) {
259 case DW_EH_PE_absptr:
260 // do nothing
261 break;
262 case DW_EH_PE_pcrel:
263 result += startAddr;
264 break;
265 case DW_EH_PE_textrel:
266 _LIBUNWIND_ABORT("DW_EH_PE_textrel pointer encoding not supported");
267 break;
268 case DW_EH_PE_datarel:
269 // DW_EH_PE_datarel is only valid in a few places, so the parameter has a
270 // default value of 0, and we abort in the event that someone calls this
271 // function with a datarelBase of 0 and DW_EH_PE_datarel encoding.
272 if (datarelBase == 0)
273 _LIBUNWIND_ABORT("DW_EH_PE_datarel is invalid with a datarelBase of 0");
274 result += datarelBase;
275 break;
276 case DW_EH_PE_funcrel:
277 _LIBUNWIND_ABORT("DW_EH_PE_funcrel pointer encoding not supported");
278 break;
279 case DW_EH_PE_aligned:
280 _LIBUNWIND_ABORT("DW_EH_PE_aligned pointer encoding not supported");
281 break;
282 default:
283 _LIBUNWIND_ABORT("unknown pointer encoding");
284 break;
285 }
286
287 if (encoding & DW_EH_PE_indirect)
288 result = getP(result);
289
290 return result;
291}
292
293#ifdef __APPLE__
294 struct dyld_unwind_sections
295 {
296 const struct mach_header* mh;
297 const void* dwarf_section;
298 uintptr_t dwarf_section_length;
299 const void* compact_unwind_section;
300 uintptr_t compact_unwind_section_length;
301 };
302 #if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) \
303 && (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1070)) \
304 || defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
305 // In 10.7.0 or later, libSystem.dylib implements this function.
306 extern "C" bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *);
307 #else
Nick Kledzik9c56de12016-10-31 21:04:17 +0000308 // In 10.6.x and earlier, we need to implement this functionality. Note
309 // that this requires a newer version of libmacho (from cctools) than is
310 // present in libSystem on 10.6.x (for getsectiondata).
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000311 static inline bool _dyld_find_unwind_sections(void* addr,
312 dyld_unwind_sections* info) {
313 // Find mach-o image containing address.
314 Dl_info dlinfo;
315 if (!dladdr(addr, &dlinfo))
316 return false;
Nick Kledzik9c56de12016-10-31 21:04:17 +0000317#if __LP64__
318 const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase;
319#else
320 const struct mach_header *mh = (const struct mach_header *)dlinfo.dli_fbase;
321#endif
322
323 // Initialize the return struct
324 info->mh = (const struct mach_header *)mh;
325 info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", &info->dwarf_section_length);
326 info->compact_unwind_section = getsectiondata(mh, "__TEXT", "__unwind_info", &info->compact_unwind_section_length);
327
328 if (!info->dwarf_section) {
329 info->dwarf_section_length = 0;
330 }
331
332 if (!info->compact_unwind_section) {
333 info->compact_unwind_section_length = 0;
334 }
335
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000336 return true;
337 }
338 #endif
339#endif
340
341inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
342 UnwindInfoSections &info) {
343#ifdef __APPLE__
344 dyld_unwind_sections dyldInfo;
345 if (_dyld_find_unwind_sections((void *)targetAddr, &dyldInfo)) {
346 info.dso_base = (uintptr_t)dyldInfo.mh;
347 #if _LIBUNWIND_SUPPORT_DWARF_UNWIND
348 info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section;
349 info.dwarf_section_length = dyldInfo.dwarf_section_length;
350 #endif
351 info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section;
352 info.compact_unwind_section_length = dyldInfo.compact_unwind_section_length;
353 return true;
354 }
Ed Schouten6a4939b2017-03-05 19:11:24 +0000355#elif _LIBUNWIND_ARM_EHABI && defined(_LIBUNWIND_IS_BAREMETAL)
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000356 // Bare metal is statically linked, so no need to ask the dynamic loader
357 info.arm_section = (uintptr_t)(&__exidx_start);
358 info.arm_section_length = (uintptr_t)(&__exidx_end - &__exidx_start);
Ed Maste41bc5a72016-08-30 15:38:10 +0000359 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %X length %x",
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000360 info.arm_section, info.arm_section_length);
361 if (info.arm_section && info.arm_section_length)
362 return true;
Ed Schouten6a4939b2017-03-05 19:11:24 +0000363#elif _LIBUNWIND_ARM_EHABI || _LIBUNWIND_SUPPORT_DWARF_UNWIND
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000364 struct dl_iterate_cb_data {
365 LocalAddressSpace *addressSpace;
366 UnwindInfoSections *sects;
367 uintptr_t targetAddr;
368 };
369
370 dl_iterate_cb_data cb_data = {this, &info, targetAddr};
371 int found = dl_iterate_phdr(
372 [](struct dl_phdr_info *pinfo, size_t, void *data) -> int {
373 auto cbdata = static_cast<dl_iterate_cb_data *>(data);
Ed Schouten08032ee2017-02-23 09:13:22 +0000374 bool found_obj = false;
375 bool found_hdr = false;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000376
377 assert(cbdata);
378 assert(cbdata->sects);
379
380 if (cbdata->targetAddr < pinfo->dlpi_addr) {
381 return false;
382 }
383
Viktor Kutuzova28f5b32015-05-06 10:32:28 +0000384#if !defined(Elf_Half)
385 typedef ElfW(Half) Elf_Half;
386#endif
387#if !defined(Elf_Phdr)
388 typedef ElfW(Phdr) Elf_Phdr;
389#endif
390
Ed Schouten6a4939b2017-03-05 19:11:24 +0000391 #if _LIBUNWIND_SUPPORT_DWARF_UNWIND
392 #if !_LIBUNWIND_SUPPORT_DWARF_INDEX
393 #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
394 #endif
395 size_t object_length;
Viktor Kutuzova28f5b32015-05-06 10:32:28 +0000396 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
397 const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i];
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000398 if (phdr->p_type == PT_LOAD) {
399 uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr;
400 uintptr_t end = begin + phdr->p_memsz;
401 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) {
402 cbdata->sects->dso_base = begin;
403 object_length = phdr->p_memsz;
404 found_obj = true;
405 }
406 } else if (phdr->p_type == PT_GNU_EH_FRAME) {
407 EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo;
408 uintptr_t eh_frame_hdr_start = pinfo->dlpi_addr + phdr->p_vaddr;
409 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
410 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
411 EHHeaderParser<LocalAddressSpace>::decodeEHHdr(
412 *cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
413 hdrInfo);
414 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
415 found_hdr = true;
416 }
417 }
418
419 if (found_obj && found_hdr) {
420 cbdata->sects->dwarf_section_length = object_length;
421 return true;
422 } else {
423 return false;
424 }
Ed Schouten6a4939b2017-03-05 19:11:24 +0000425 #else // _LIBUNWIND_ARM_EHABI
426 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
427 const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i];
428 if (phdr->p_type == PT_LOAD) {
429 uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr;
430 uintptr_t end = begin + phdr->p_memsz;
431 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end)
432 found_obj = true;
433 } else if (phdr->p_type == PT_ARM_EXIDX) {
434 uintptr_t exidx_start = pinfo->dlpi_addr + phdr->p_vaddr;
435 cbdata->sects->arm_section = exidx_start;
Ed Schouten5d3f35b2017-03-07 15:21:57 +0000436 cbdata->sects->arm_section_length = phdr->p_memsz;
Ed Schouten6a4939b2017-03-05 19:11:24 +0000437 found_hdr = true;
438 }
439 }
440 return found_obj && found_hdr;
441 #endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000442 },
443 &cb_data);
444 return static_cast<bool>(found);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000445#endif
446
447 return false;
448}
449
450
451inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) {
452#ifdef __APPLE__
453 return checkKeyMgrRegisteredFDEs(targetAddr, *((void**)&fde));
454#else
455 // TO DO: if OS has way to dynamically register FDEs, check that.
456 (void)targetAddr;
457 (void)fde;
458 return false;
459#endif
460}
461
462inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
463 size_t bufLen,
464 unw_word_t *offset) {
465#ifndef _LIBUNWIND_IS_BAREMETAL
466 Dl_info dyldInfo;
467 if (dladdr((void *)addr, &dyldInfo)) {
468 if (dyldInfo.dli_sname != NULL) {
469 snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
470 *offset = (addr - (pint_t) dyldInfo.dli_saddr);
471 return true;
472 }
473 }
474#endif
475 return false;
476}
477
478
479
480#ifdef UNW_REMOTE
481
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000482/// RemoteAddressSpace is used as a template parameter to UnwindCursor when
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000483/// unwinding a thread in the another process. The other process can be a
484/// different endianness and a different pointer size which is handled by
485/// the P template parameter.
486template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000487class RemoteAddressSpace {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000488public:
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000489 RemoteAddressSpace(task_t task) : fTask(task) {}
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000490
491 typedef typename P::uint_t pint_t;
492
493 uint8_t get8(pint_t addr);
494 uint16_t get16(pint_t addr);
495 uint32_t get32(pint_t addr);
496 uint64_t get64(pint_t addr);
497 pint_t getP(pint_t addr);
498 uint64_t getULEB128(pint_t &addr, pint_t end);
499 int64_t getSLEB128(pint_t &addr, pint_t end);
500 pint_t getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
501 pint_t datarelBase = 0);
502 bool findFunctionName(pint_t addr, char *buf, size_t bufLen,
503 unw_word_t *offset);
504 bool findUnwindSections(pint_t targetAddr, UnwindInfoSections &info);
505 bool findOtherFDE(pint_t targetAddr, pint_t &fde);
506private:
507 void *localCopy(pint_t addr);
508
509 task_t fTask;
510};
511
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000512template <typename P> uint8_t RemoteAddressSpace<P>::get8(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000513 return *((uint8_t *)localCopy(addr));
514}
515
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000516template <typename P> uint16_t RemoteAddressSpace<P>::get16(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000517 return P::E::get16(*(uint16_t *)localCopy(addr));
518}
519
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000520template <typename P> uint32_t RemoteAddressSpace<P>::get32(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000521 return P::E::get32(*(uint32_t *)localCopy(addr));
522}
523
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000524template <typename P> uint64_t RemoteAddressSpace<P>::get64(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000525 return P::E::get64(*(uint64_t *)localCopy(addr));
526}
527
528template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000529typename P::uint_t RemoteAddressSpace<P>::getP(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000530 return P::getP(*(uint64_t *)localCopy(addr));
531}
532
533template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000534uint64_t RemoteAddressSpace<P>::getULEB128(pint_t &addr, pint_t end) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000535 uintptr_t size = (end - addr);
536 LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
537 LocalAddressSpace::pint_t sladdr = laddr;
538 uint64_t result = LocalAddressSpace::getULEB128(laddr, laddr + size);
539 addr += (laddr - sladdr);
540 return result;
541}
542
543template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000544int64_t RemoteAddressSpace<P>::getSLEB128(pint_t &addr, pint_t end) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000545 uintptr_t size = (end - addr);
546 LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
547 LocalAddressSpace::pint_t sladdr = laddr;
548 uint64_t result = LocalAddressSpace::getSLEB128(laddr, laddr + size);
549 addr += (laddr - sladdr);
550 return result;
551}
552
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000553template <typename P> void *RemoteAddressSpace<P>::localCopy(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000554 // FIX ME
555}
556
557template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000558bool RemoteAddressSpace<P>::findFunctionName(pint_t addr, char *buf,
559 size_t bufLen,
560 unw_word_t *offset) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000561 // FIX ME
562}
563
564/// unw_addr_space is the base class that abstract unw_addr_space_t type in
565/// libunwind.h points to.
566struct unw_addr_space {
567 cpu_type_t cpuType;
568 task_t taskPort;
569};
570
571/// unw_addr_space_i386 is the concrete instance that a unw_addr_space_t points
572/// to when examining
573/// a 32-bit intel process.
574struct unw_addr_space_i386 : public unw_addr_space {
575 unw_addr_space_i386(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000576 RemoteAddressSpace<Pointer32<LittleEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000577};
578
579/// unw_addr_space_x86_64 is the concrete instance that a unw_addr_space_t
580/// points to when examining
581/// a 64-bit intel process.
582struct unw_addr_space_x86_64 : public unw_addr_space {
583 unw_addr_space_x86_64(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000584 RemoteAddressSpace<Pointer64<LittleEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000585};
586
587/// unw_addr_space_ppc is the concrete instance that a unw_addr_space_t points
588/// to when examining
589/// a 32-bit PowerPC process.
590struct unw_addr_space_ppc : public unw_addr_space {
591 unw_addr_space_ppc(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000592 RemoteAddressSpace<Pointer32<BigEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000593};
594
595#endif // UNW_REMOTE
596
597} // namespace libunwind
598
599#endif // __ADDRESSSPACE_HPP__