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