Path: blob/main/contrib/llvm-project/libunwind/src/AddressSpace.hpp
35154 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//7// Abstracts accessing local vs remote address spaces.8//9//===----------------------------------------------------------------------===//1011#ifndef __ADDRESSSPACE_HPP__12#define __ADDRESSSPACE_HPP__1314#include <stdint.h>15#include <stdio.h>16#include <stdlib.h>17#include <string.h>1819#include "libunwind.h"20#include "config.h"21#include "dwarf2.h"22#include "EHHeaderParser.hpp"23#include "Registers.hpp"2425#ifndef _LIBUNWIND_USE_DLADDR26#if !(defined(_LIBUNWIND_IS_BAREMETAL) || defined(_WIN32) || defined(_AIX))27#define _LIBUNWIND_USE_DLADDR 128#else29#define _LIBUNWIND_USE_DLADDR 030#endif31#endif3233#if _LIBUNWIND_USE_DLADDR34#include <dlfcn.h>35#if defined(__ELF__) && defined(_LIBUNWIND_LINK_DL_LIB)36#pragma comment(lib, "dl")37#endif38#endif3940#if defined(_LIBUNWIND_ARM_EHABI)41struct EHABIIndexEntry {42uint32_t functionOffset;43uint32_t data;44};45#endif4647#if defined(_AIX)48namespace libunwind {49char *getFuncNameFromTBTable(uintptr_t pc, uint16_t &NameLen,50unw_word_t *offset);51}52#endif5354#ifdef __APPLE__5556struct dyld_unwind_sections57{58const struct mach_header* mh;59const void* dwarf_section;60uintptr_t dwarf_section_length;61const void* compact_unwind_section;62uintptr_t compact_unwind_section_length;63};6465// In 10.7.0 or later, libSystem.dylib implements this function.66extern "C" bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *);6768namespace libunwind {69bool findDynamicUnwindSections(void *, unw_dynamic_unwind_sections *);70}7172#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)7374// When statically linked on bare-metal, the symbols for the EH table are looked75// up without going through the dynamic loader.7677// The following linker script may be used to produce the necessary sections and symbols.78// Unless the --eh-frame-hdr linker option is provided, the section is not generated79// and does not take space in the output file.80//81// .eh_frame :82// {83// __eh_frame_start = .;84// KEEP(*(.eh_frame))85// __eh_frame_end = .;86// }87//88// .eh_frame_hdr :89// {90// KEEP(*(.eh_frame_hdr))91// }92//93// __eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;94// __eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;9596extern char __eh_frame_start;97extern char __eh_frame_end;9899#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)100extern char __eh_frame_hdr_start;101extern char __eh_frame_hdr_end;102#endif103104#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)105106// When statically linked on bare-metal, the symbols for the EH table are looked107// up without going through the dynamic loader.108extern char __exidx_start;109extern char __exidx_end;110111#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)112113#include <windows.h>114#include <psapi.h>115116#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) || \117defined(_LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX)118119#include <link.h>120121#endif122123namespace libunwind {124125/// Used by findUnwindSections() to return info about needed sections.126struct UnwindInfoSections {127#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) || \128defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND) || \129defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)130// No dso_base for SEH.131uintptr_t dso_base;132#endif133#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)134size_t text_segment_length;135#endif136#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)137uintptr_t dwarf_section;138size_t dwarf_section_length;139#endif140#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)141uintptr_t dwarf_index_section;142size_t dwarf_index_section_length;143#endif144#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)145uintptr_t compact_unwind_section;146size_t compact_unwind_section_length;147#endif148#if defined(_LIBUNWIND_ARM_EHABI)149uintptr_t arm_section;150size_t arm_section_length;151#endif152};153154155/// LocalAddressSpace is used as a template parameter to UnwindCursor when156/// unwinding a thread in the same process. The wrappers compile away,157/// making local unwinds fast.158class _LIBUNWIND_HIDDEN LocalAddressSpace {159public:160typedef uintptr_t pint_t;161typedef intptr_t sint_t;162uint8_t get8(pint_t addr) {163uint8_t val;164memcpy(&val, (void *)addr, sizeof(val));165return val;166}167uint16_t get16(pint_t addr) {168uint16_t val;169memcpy(&val, (void *)addr, sizeof(val));170return val;171}172uint32_t get32(pint_t addr) {173uint32_t val;174memcpy(&val, (void *)addr, sizeof(val));175return val;176}177uint64_t get64(pint_t addr) {178uint64_t val;179memcpy(&val, (void *)addr, sizeof(val));180return val;181}182double getDouble(pint_t addr) {183double val;184memcpy(&val, (void *)addr, sizeof(val));185return val;186}187v128 getVector(pint_t addr) {188v128 val;189memcpy(&val, (void *)addr, sizeof(val));190return val;191}192uintptr_t getP(pint_t addr);193uint64_t getRegister(pint_t addr);194static uint64_t getULEB128(pint_t &addr, pint_t end);195static int64_t getSLEB128(pint_t &addr, pint_t end);196197pint_t getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,198pint_t datarelBase = 0);199bool findFunctionName(pint_t addr, char *buf, size_t bufLen,200unw_word_t *offset);201bool findUnwindSections(pint_t targetAddr, UnwindInfoSections &info);202bool findOtherFDE(pint_t targetAddr, pint_t &fde);203204static LocalAddressSpace sThisAddressSpace;205};206207inline uintptr_t LocalAddressSpace::getP(pint_t addr) {208#if __SIZEOF_POINTER__ == 8209return get64(addr);210#else211return get32(addr);212#endif213}214215inline uint64_t LocalAddressSpace::getRegister(pint_t addr) {216#if __SIZEOF_POINTER__ == 8 || defined(__mips64)217return get64(addr);218#else219return get32(addr);220#endif221}222223/// Read a ULEB128 into a 64-bit word.224inline uint64_t LocalAddressSpace::getULEB128(pint_t &addr, pint_t end) {225const uint8_t *p = (uint8_t *)addr;226const uint8_t *pend = (uint8_t *)end;227uint64_t result = 0;228int bit = 0;229do {230uint64_t b;231232if (p == pend)233_LIBUNWIND_ABORT("truncated uleb128 expression");234235b = *p & 0x7f;236237if (bit >= 64 || b << bit >> bit != b) {238_LIBUNWIND_ABORT("malformed uleb128 expression");239} else {240result |= b << bit;241bit += 7;242}243} while (*p++ >= 0x80);244addr = (pint_t) p;245return result;246}247248/// Read a SLEB128 into a 64-bit word.249inline int64_t LocalAddressSpace::getSLEB128(pint_t &addr, pint_t end) {250const uint8_t *p = (uint8_t *)addr;251const uint8_t *pend = (uint8_t *)end;252uint64_t result = 0;253int bit = 0;254uint8_t byte;255do {256if (p == pend)257_LIBUNWIND_ABORT("truncated sleb128 expression");258byte = *p++;259result |= (uint64_t)(byte & 0x7f) << bit;260bit += 7;261} while (byte & 0x80);262// sign extend negative numbers263if ((byte & 0x40) != 0 && bit < 64)264result |= (-1ULL) << bit;265addr = (pint_t) p;266return (int64_t)result;267}268269inline LocalAddressSpace::pint_t270LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,271pint_t datarelBase) {272pint_t startAddr = addr;273const uint8_t *p = (uint8_t *)addr;274pint_t result;275276// first get value277switch (encoding & 0x0F) {278case DW_EH_PE_ptr:279result = getP(addr);280p += sizeof(pint_t);281addr = (pint_t) p;282break;283case DW_EH_PE_uleb128:284result = (pint_t)getULEB128(addr, end);285break;286case DW_EH_PE_udata2:287result = get16(addr);288p += 2;289addr = (pint_t) p;290break;291case DW_EH_PE_udata4:292result = get32(addr);293p += 4;294addr = (pint_t) p;295break;296case DW_EH_PE_udata8:297result = (pint_t)get64(addr);298p += 8;299addr = (pint_t) p;300break;301case DW_EH_PE_sleb128:302result = (pint_t)getSLEB128(addr, end);303break;304case DW_EH_PE_sdata2:305// Sign extend from signed 16-bit value.306result = (pint_t)(int16_t)get16(addr);307p += 2;308addr = (pint_t) p;309break;310case DW_EH_PE_sdata4:311// Sign extend from signed 32-bit value.312result = (pint_t)(int32_t)get32(addr);313p += 4;314addr = (pint_t) p;315break;316case DW_EH_PE_sdata8:317result = (pint_t)get64(addr);318p += 8;319addr = (pint_t) p;320break;321default:322_LIBUNWIND_ABORT("unknown pointer encoding");323}324325// then add relative offset326switch (encoding & 0x70) {327case DW_EH_PE_absptr:328// do nothing329break;330case DW_EH_PE_pcrel:331result += startAddr;332break;333case DW_EH_PE_textrel:334_LIBUNWIND_ABORT("DW_EH_PE_textrel pointer encoding not supported");335break;336case DW_EH_PE_datarel:337// DW_EH_PE_datarel is only valid in a few places, so the parameter has a338// default value of 0, and we abort in the event that someone calls this339// function with a datarelBase of 0 and DW_EH_PE_datarel encoding.340if (datarelBase == 0)341_LIBUNWIND_ABORT("DW_EH_PE_datarel is invalid with a datarelBase of 0");342result += datarelBase;343break;344case DW_EH_PE_funcrel:345_LIBUNWIND_ABORT("DW_EH_PE_funcrel pointer encoding not supported");346break;347case DW_EH_PE_aligned:348_LIBUNWIND_ABORT("DW_EH_PE_aligned pointer encoding not supported");349break;350default:351_LIBUNWIND_ABORT("unknown pointer encoding");352break;353}354355if (encoding & DW_EH_PE_indirect)356result = getP(result);357358return result;359}360361#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)362363// The ElfW() macro for pointer-size independent ELF header traversal is not364// provided by <link.h> on some systems (e.g., FreeBSD). On these systems the365// data structures are just called Elf_XXX. Define ElfW() locally.366#if !defined(ElfW)367#define ElfW(type) Elf_##type368#endif369#if !defined(Elf_Half)370typedef ElfW(Half) Elf_Half;371#endif372#if !defined(Elf_Phdr)373typedef ElfW(Phdr) Elf_Phdr;374#endif375#if !defined(Elf_Addr)376typedef ElfW(Addr) Elf_Addr;377#endif378379struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {380LocalAddressSpace *addressSpace;381UnwindInfoSections *sects;382uintptr_t targetAddr;383};384385#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)386#include "FrameHeaderCache.hpp"387388// Typically there is one cache per process, but when libunwind is built as a389// hermetic static library, then each shared object may have its own cache.390static FrameHeaderCache TheFrameHeaderCache;391#endif392393static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base,394dl_iterate_cb_data *cbdata) {395if (phdr->p_type == PT_LOAD) {396uintptr_t begin = image_base + phdr->p_vaddr;397uintptr_t end = begin + phdr->p_memsz;398if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) {399cbdata->sects->dso_base = begin;400cbdata->sects->text_segment_length = phdr->p_memsz;401return true;402}403}404return false;405}406407static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,408dl_iterate_cb_data *cbdata) {409#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)410if (phdr->p_type == PT_GNU_EH_FRAME) {411EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo;412uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr;413cbdata->sects->dwarf_index_section = eh_frame_hdr_start;414cbdata->sects->dwarf_index_section_length = phdr->p_memsz;415if (EHHeaderParser<LocalAddressSpace>::decodeEHHdr(416*cbdata->addressSpace, eh_frame_hdr_start,417eh_frame_hdr_start + phdr->p_memsz, hdrInfo)) {418// .eh_frame_hdr records the start of .eh_frame, but not its size.419// Rely on a zero terminator to find the end of the section.420cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;421cbdata->sects->dwarf_section_length = SIZE_MAX;422return true;423}424}425return false;426#elif defined(_LIBUNWIND_ARM_EHABI)427if (phdr->p_type == PT_ARM_EXIDX) {428uintptr_t exidx_start = image_base + phdr->p_vaddr;429cbdata->sects->arm_section = exidx_start;430cbdata->sects->arm_section_length = phdr->p_memsz;431return true;432}433return false;434#else435#error Need one of _LIBUNWIND_SUPPORT_DWARF_INDEX or _LIBUNWIND_ARM_EHABI436#endif437}438439static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo,440size_t pinfo_size, void *data) {441auto cbdata = static_cast<dl_iterate_cb_data *>(data);442if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr)443return 0;444#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)445if (TheFrameHeaderCache.find(pinfo, pinfo_size, data))446return 1;447#else448// Avoid warning about unused variable.449(void)pinfo_size;450#endif451452Elf_Addr image_base = pinfo->dlpi_addr;453454// Most shared objects seen in this callback function likely don't contain the455// target address, so optimize for that. Scan for a matching PT_LOAD segment456// first and bail when it isn't found.457bool found_text = false;458for (Elf_Half i = 0; i < pinfo->dlpi_phnum; ++i) {459if (checkAddrInSegment(&pinfo->dlpi_phdr[i], image_base, cbdata)) {460found_text = true;461break;462}463}464if (!found_text)465return 0;466467// PT_GNU_EH_FRAME and PT_ARM_EXIDX are usually near the end. Iterate468// backward.469bool found_unwind = false;470for (Elf_Half i = pinfo->dlpi_phnum; i > 0; i--) {471const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i - 1];472if (checkForUnwindInfoSegment(phdr, image_base, cbdata)) {473found_unwind = true;474break;475}476}477if (!found_unwind)478return 0;479480#if defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)481TheFrameHeaderCache.add(cbdata->sects);482#endif483return 1;484}485486#endif // defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)487488489inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,490UnwindInfoSections &info) {491#ifdef __APPLE__492dyld_unwind_sections dyldInfo;493if (_dyld_find_unwind_sections((void *)targetAddr, &dyldInfo)) {494info.dso_base = (uintptr_t)dyldInfo.mh;495#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)496info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section;497info.dwarf_section_length = (size_t)dyldInfo.dwarf_section_length;498#endif499info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section;500info.compact_unwind_section_length = (size_t)dyldInfo.compact_unwind_section_length;501return true;502}503504unw_dynamic_unwind_sections dynamicUnwindSectionInfo;505if (findDynamicUnwindSections((void *)targetAddr,506&dynamicUnwindSectionInfo)) {507info.dso_base = dynamicUnwindSectionInfo.dso_base;508#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)509info.dwarf_section = (uintptr_t)dynamicUnwindSectionInfo.dwarf_section;510info.dwarf_section_length = dynamicUnwindSectionInfo.dwarf_section_length;511#endif512info.compact_unwind_section =513(uintptr_t)dynamicUnwindSectionInfo.compact_unwind_section;514info.compact_unwind_section_length =515dynamicUnwindSectionInfo.compact_unwind_section_length;516return true;517}518519#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)520info.dso_base = 0;521// Bare metal is statically linked, so no need to ask the dynamic loader522info.dwarf_section_length = (size_t)(&__eh_frame_end - &__eh_frame_start);523info.dwarf_section = (uintptr_t)(&__eh_frame_start);524_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",525(void *)info.dwarf_section, (void *)info.dwarf_section_length);526#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)527info.dwarf_index_section = (uintptr_t)(&__eh_frame_hdr_start);528info.dwarf_index_section_length = (size_t)(&__eh_frame_hdr_end - &__eh_frame_hdr_start);529_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: index section %p length %p",530(void *)info.dwarf_index_section, (void *)info.dwarf_index_section_length);531#endif532if (info.dwarf_section_length)533return true;534#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)535// Bare metal is statically linked, so no need to ask the dynamic loader536info.arm_section = (uintptr_t)(&__exidx_start);537info.arm_section_length = (size_t)(&__exidx_end - &__exidx_start);538_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",539(void *)info.arm_section, (void *)info.arm_section_length);540if (info.arm_section && info.arm_section_length)541return true;542#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)543HMODULE mods[1024];544HANDLE process = GetCurrentProcess();545DWORD needed;546547if (!EnumProcessModules(process, mods, sizeof(mods), &needed)) {548DWORD err = GetLastError();549_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: EnumProcessModules failed, "550"returned error %d", (int)err);551(void)err;552return false;553}554555for (unsigned i = 0; i < (needed / sizeof(HMODULE)); i++) {556PIMAGE_DOS_HEADER pidh = (PIMAGE_DOS_HEADER)mods[i];557PIMAGE_NT_HEADERS pinh = (PIMAGE_NT_HEADERS)((BYTE *)pidh + pidh->e_lfanew);558PIMAGE_FILE_HEADER pifh = (PIMAGE_FILE_HEADER)&pinh->FileHeader;559PIMAGE_SECTION_HEADER pish = IMAGE_FIRST_SECTION(pinh);560bool found_obj = false;561bool found_hdr = false;562563info.dso_base = (uintptr_t)mods[i];564for (unsigned j = 0; j < pifh->NumberOfSections; j++, pish++) {565uintptr_t begin = pish->VirtualAddress + (uintptr_t)mods[i];566uintptr_t end = begin + pish->Misc.VirtualSize;567if (!strncmp((const char *)pish->Name, ".text",568IMAGE_SIZEOF_SHORT_NAME)) {569if (targetAddr >= begin && targetAddr < end)570found_obj = true;571} else if (!strncmp((const char *)pish->Name, ".eh_frame",572IMAGE_SIZEOF_SHORT_NAME)) {573info.dwarf_section = begin;574info.dwarf_section_length = pish->Misc.VirtualSize;575found_hdr = true;576}577if (found_obj && found_hdr)578return true;579}580}581return false;582#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)583// Don't even bother, since Windows has functions that do all this stuff584// for us.585(void)targetAddr;586(void)info;587return true;588#elif defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)589// The traceback table is used for unwinding.590(void)targetAddr;591(void)info;592return true;593#elif defined(_LIBUNWIND_USE_DL_UNWIND_FIND_EXIDX)594int length = 0;595info.arm_section =596(uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length);597info.arm_section_length = (size_t)length * sizeof(EHABIIndexEntry);598if (info.arm_section && info.arm_section_length)599return true;600#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)601// Use DLFO_STRUCT_HAS_EH_DBASE to determine the existence of602// `_dl_find_object`. Use _LIBUNWIND_SUPPORT_DWARF_INDEX, because libunwind603// support for _dl_find_object on other unwind formats is not implemented,604// yet.605#if defined(DLFO_STRUCT_HAS_EH_DBASE) & defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)606// We expect `_dl_find_object` to return PT_GNU_EH_FRAME.607#if DLFO_EH_SEGMENT_TYPE != PT_GNU_EH_FRAME608#error _dl_find_object retrieves an unexpected section type609#endif610// We look-up `dl_find_object` dynamically at runtime to ensure backwards611// compatibility with earlier version of glibc not yet providing it. On older612// systems, we gracefully fallback to `dl_iterate_phdr`. Cache the pointer613// so we only look it up once. Do manual lock to avoid _cxa_guard_acquire.614static decltype(_dl_find_object) *dlFindObject;615static bool dlFindObjectChecked = false;616if (!dlFindObjectChecked) {617dlFindObject = reinterpret_cast<decltype(_dl_find_object) *>(618dlsym(RTLD_DEFAULT, "_dl_find_object"));619dlFindObjectChecked = true;620}621// Try to find the unwind info using `dl_find_object`622dl_find_object findResult;623if (dlFindObject && dlFindObject((void *)targetAddr, &findResult) == 0) {624if (findResult.dlfo_eh_frame == nullptr) {625// Found an entry for `targetAddr`, but there is no unwind info.626return false;627}628info.dso_base = reinterpret_cast<uintptr_t>(findResult.dlfo_map_start);629info.text_segment_length = static_cast<size_t>(630(char *)findResult.dlfo_map_end - (char *)findResult.dlfo_map_start);631632// Record the start of PT_GNU_EH_FRAME.633info.dwarf_index_section =634reinterpret_cast<uintptr_t>(findResult.dlfo_eh_frame);635// `_dl_find_object` does not give us the size of PT_GNU_EH_FRAME.636// Setting length to `SIZE_MAX` effectively disables all range checks.637info.dwarf_index_section_length = SIZE_MAX;638EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo;639if (!EHHeaderParser<LocalAddressSpace>::decodeEHHdr(640*this, info.dwarf_index_section,641info.dwarf_index_section + info.dwarf_index_section_length,642hdrInfo)) {643return false;644}645// Record the start of the FDE and use SIZE_MAX to indicate that we do646// not know the end address.647info.dwarf_section = hdrInfo.eh_frame_ptr;648info.dwarf_section_length = SIZE_MAX;649return true;650}651#endif652dl_iterate_cb_data cb_data = {this, &info, targetAddr};653int found = dl_iterate_phdr(findUnwindSectionsByPhdr, &cb_data);654return static_cast<bool>(found);655#endif656657return false;658}659660inline bool LocalAddressSpace::findOtherFDE(pint_t targetAddr, pint_t &fde) {661// TO DO: if OS has way to dynamically register FDEs, check that.662(void)targetAddr;663(void)fde;664return false;665}666667inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,668size_t bufLen,669unw_word_t *offset) {670#if _LIBUNWIND_USE_DLADDR671Dl_info dyldInfo;672if (dladdr((void *)addr, &dyldInfo)) {673if (dyldInfo.dli_sname != NULL) {674snprintf(buf, bufLen, "%s", dyldInfo.dli_sname);675*offset = (addr - (pint_t) dyldInfo.dli_saddr);676return true;677}678}679#elif defined(_AIX)680uint16_t nameLen;681char *funcName = getFuncNameFromTBTable(addr, nameLen, offset);682if (funcName != NULL) {683snprintf(buf, bufLen, "%.*s", nameLen, funcName);684return true;685}686#else687(void)addr;688(void)buf;689(void)bufLen;690(void)offset;691#endif692return false;693}694695} // namespace libunwind696697#endif // __ADDRESSSPACE_HPP__698699700