blob: 2229de503e11a27dd3c7e0360a08dcca17fd0c9e [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 Schouten6a4939b2017-03-05 19:11:24 +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 Schouten6a4939b2017-03-05 19:11:24 +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 Schouten6a4939b2017-03-05 19:11:24 +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 Schouten6a4939b2017-03-05 19:11:24 +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);
Ed Schouten08032ee2017-02-23 09:13:22 +0000378 bool found_obj = false;
379 bool found_hdr = false;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000380
381 assert(cbdata);
382 assert(cbdata->sects);
383
384 if (cbdata->targetAddr < pinfo->dlpi_addr) {
385 return false;
386 }
387
Viktor Kutuzova28f5b32015-05-06 10:32:28 +0000388#if !defined(Elf_Half)
389 typedef ElfW(Half) Elf_Half;
390#endif
391#if !defined(Elf_Phdr)
392 typedef ElfW(Phdr) Elf_Phdr;
393#endif
394
Ed Schouten6a4939b2017-03-05 19:11:24 +0000395 #if _LIBUNWIND_SUPPORT_DWARF_UNWIND
396 #if !_LIBUNWIND_SUPPORT_DWARF_INDEX
397 #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
398 #endif
399 size_t object_length;
Viktor Kutuzova28f5b32015-05-06 10:32:28 +0000400 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
401 const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i];
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000402 if (phdr->p_type == PT_LOAD) {
403 uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr;
404 uintptr_t end = begin + phdr->p_memsz;
405 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) {
406 cbdata->sects->dso_base = begin;
407 object_length = phdr->p_memsz;
408 found_obj = true;
409 }
410 } else if (phdr->p_type == PT_GNU_EH_FRAME) {
411 EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo;
412 uintptr_t eh_frame_hdr_start = pinfo->dlpi_addr + phdr->p_vaddr;
413 cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
414 cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
415 EHHeaderParser<LocalAddressSpace>::decodeEHHdr(
416 *cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
417 hdrInfo);
418 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
419 found_hdr = true;
420 }
421 }
422
423 if (found_obj && found_hdr) {
424 cbdata->sects->dwarf_section_length = object_length;
425 return true;
426 } else {
427 return false;
428 }
Ed Schouten6a4939b2017-03-05 19:11:24 +0000429 #else // _LIBUNWIND_ARM_EHABI
430 for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
431 const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i];
432 if (phdr->p_type == PT_LOAD) {
433 uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr;
434 uintptr_t end = begin + phdr->p_memsz;
435 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end)
436 found_obj = true;
437 } else if (phdr->p_type == PT_ARM_EXIDX) {
438 uintptr_t exidx_start = pinfo->dlpi_addr + phdr->p_vaddr;
439 cbdata->sects->arm_section = exidx_start;
440 cbdata->sects->arm_section_length = phdr->p_memsz /
441 sizeof(EHTEntry);
442 found_hdr = true;
443 }
444 }
445 return found_obj && found_hdr;
446 #endif
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000447 },
448 &cb_data);
449 return static_cast<bool>(found);
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000450#endif
451
452 return false;
453}
454
455
456inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) {
457#ifdef __APPLE__
458 return checkKeyMgrRegisteredFDEs(targetAddr, *((void**)&fde));
459#else
460 // TO DO: if OS has way to dynamically register FDEs, check that.
461 (void)targetAddr;
462 (void)fde;
463 return false;
464#endif
465}
466
467inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
468 size_t bufLen,
469 unw_word_t *offset) {
470#ifndef _LIBUNWIND_IS_BAREMETAL
471 Dl_info dyldInfo;
472 if (dladdr((void *)addr, &dyldInfo)) {
473 if (dyldInfo.dli_sname != NULL) {
474 snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);
475 *offset = (addr - (pint_t) dyldInfo.dli_saddr);
476 return true;
477 }
478 }
479#endif
480 return false;
481}
482
483
484
485#ifdef UNW_REMOTE
486
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000487/// RemoteAddressSpace is used as a template parameter to UnwindCursor when
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000488/// unwinding a thread in the another process. The other process can be a
489/// different endianness and a different pointer size which is handled by
490/// the P template parameter.
491template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000492class RemoteAddressSpace {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000493public:
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000494 RemoteAddressSpace(task_t task) : fTask(task) {}
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000495
496 typedef typename P::uint_t pint_t;
497
498 uint8_t get8(pint_t addr);
499 uint16_t get16(pint_t addr);
500 uint32_t get32(pint_t addr);
501 uint64_t get64(pint_t addr);
502 pint_t getP(pint_t addr);
503 uint64_t getULEB128(pint_t &addr, pint_t end);
504 int64_t getSLEB128(pint_t &addr, pint_t end);
505 pint_t getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
506 pint_t datarelBase = 0);
507 bool findFunctionName(pint_t addr, char *buf, size_t bufLen,
508 unw_word_t *offset);
509 bool findUnwindSections(pint_t targetAddr, UnwindInfoSections &info);
510 bool findOtherFDE(pint_t targetAddr, pint_t &fde);
511private:
512 void *localCopy(pint_t addr);
513
514 task_t fTask;
515};
516
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000517template <typename P> uint8_t RemoteAddressSpace<P>::get8(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000518 return *((uint8_t *)localCopy(addr));
519}
520
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000521template <typename P> uint16_t RemoteAddressSpace<P>::get16(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000522 return P::E::get16(*(uint16_t *)localCopy(addr));
523}
524
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000525template <typename P> uint32_t RemoteAddressSpace<P>::get32(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000526 return P::E::get32(*(uint32_t *)localCopy(addr));
527}
528
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000529template <typename P> uint64_t RemoteAddressSpace<P>::get64(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000530 return P::E::get64(*(uint64_t *)localCopy(addr));
531}
532
533template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000534typename P::uint_t RemoteAddressSpace<P>::getP(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000535 return P::getP(*(uint64_t *)localCopy(addr));
536}
537
538template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000539uint64_t RemoteAddressSpace<P>::getULEB128(pint_t &addr, pint_t end) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000540 uintptr_t size = (end - addr);
541 LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
542 LocalAddressSpace::pint_t sladdr = laddr;
543 uint64_t result = LocalAddressSpace::getULEB128(laddr, laddr + size);
544 addr += (laddr - sladdr);
545 return result;
546}
547
548template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000549int64_t RemoteAddressSpace<P>::getSLEB128(pint_t &addr, pint_t end) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000550 uintptr_t size = (end - addr);
551 LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
552 LocalAddressSpace::pint_t sladdr = laddr;
553 uint64_t result = LocalAddressSpace::getSLEB128(laddr, laddr + size);
554 addr += (laddr - sladdr);
555 return result;
556}
557
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000558template <typename P> void *RemoteAddressSpace<P>::localCopy(pint_t addr) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000559 // FIX ME
560}
561
562template <typename P>
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000563bool RemoteAddressSpace<P>::findFunctionName(pint_t addr, char *buf,
564 size_t bufLen,
565 unw_word_t *offset) {
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000566 // FIX ME
567}
568
569/// unw_addr_space is the base class that abstract unw_addr_space_t type in
570/// libunwind.h points to.
571struct unw_addr_space {
572 cpu_type_t cpuType;
573 task_t taskPort;
574};
575
576/// unw_addr_space_i386 is the concrete instance that a unw_addr_space_t points
577/// to when examining
578/// a 32-bit intel process.
579struct unw_addr_space_i386 : public unw_addr_space {
580 unw_addr_space_i386(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000581 RemoteAddressSpace<Pointer32<LittleEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000582};
583
584/// unw_addr_space_x86_64 is the concrete instance that a unw_addr_space_t
585/// points to when examining
586/// a 64-bit intel process.
587struct unw_addr_space_x86_64 : public unw_addr_space {
588 unw_addr_space_x86_64(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000589 RemoteAddressSpace<Pointer64<LittleEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000590};
591
592/// unw_addr_space_ppc is the concrete instance that a unw_addr_space_t points
593/// to when examining
594/// a 32-bit PowerPC process.
595struct unw_addr_space_ppc : public unw_addr_space {
596 unw_addr_space_ppc(task_t task) : oas(task) {}
Saleem Abdulrasool66efa8e2017-01-21 16:22:46 +0000597 RemoteAddressSpace<Pointer32<BigEndian>> oas;
Saleem Abdulrasool17552662015-04-24 19:39:17 +0000598};
599
600#endif // UNW_REMOTE
601
602} // namespace libunwind
603
604#endif // __ADDRESSSPACE_HPP__