Skip to content

Commit ce9347d

Browse files
authored
Merge pull request #10 from petrhosek/libunwind-cherry-pick
Libunwind cherry pick
2 parents 38ad31b + b6e414a commit ce9347d

File tree

5 files changed

+20
-250
lines changed

5 files changed

+20
-250
lines changed

libunwind/include/libunwind.h

-26
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,6 @@ extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUN
125125

126126
extern unw_addr_space_t unw_local_addr_space;
127127

128-
#ifdef UNW_REMOTE
129-
/*
130-
* Mac OS X "remote" API for unwinding other processes on same machine
131-
*
132-
*/
133-
extern unw_addr_space_t unw_create_addr_space_for_task(task_t);
134-
extern void unw_destroy_addr_space(unw_addr_space_t);
135-
extern int unw_init_remote_thread(unw_cursor_t *, unw_addr_space_t, thread_t *);
136-
#endif /* UNW_REMOTE */
137-
138-
/*
139-
* traditional libunwind "remote" API
140-
* NOT IMPLEMENTED on Mac OS X
141-
*
142-
* extern int unw_init_remote(unw_cursor_t*, unw_addr_space_t,
143-
* thread_t*);
144-
* extern unw_accessors_t unw_get_accessors(unw_addr_space_t);
145-
* extern unw_addr_space_t unw_create_addr_space(unw_accessors_t, int);
146-
* extern void unw_flush_cache(unw_addr_space_t, unw_word_t,
147-
* unw_word_t);
148-
* extern int unw_set_caching_policy(unw_addr_space_t,
149-
* unw_caching_policy_t);
150-
* extern void _U_dyn_register(unw_dyn_info_t*);
151-
* extern void _U_dyn_cancel(unw_dyn_info_t*);
152-
*/
153-
154128
#ifdef __cplusplus
155129
}
156130
#endif

libunwind/src/AddressSpace.hpp

-132
Original file line numberDiff line numberDiff line change
@@ -601,138 +601,6 @@ inline bool LocalAddressSpace::findFunctionName(pint_t addr, char *buf,
601601
return false;
602602
}
603603

604-
605-
606-
#ifdef UNW_REMOTE
607-
608-
/// RemoteAddressSpace is used as a template parameter to UnwindCursor when
609-
/// unwinding a thread in the another process. The other process can be a
610-
/// different endianness and a different pointer size which is handled by
611-
/// the P template parameter.
612-
template <typename P>
613-
class RemoteAddressSpace {
614-
public:
615-
RemoteAddressSpace(task_t task) : fTask(task) {}
616-
617-
typedef typename P::uint_t pint_t;
618-
619-
uint8_t get8(pint_t addr);
620-
uint16_t get16(pint_t addr);
621-
uint32_t get32(pint_t addr);
622-
uint64_t get64(pint_t addr);
623-
pint_t getP(pint_t addr);
624-
uint64_t getRegister(pint_t addr);
625-
uint64_t getULEB128(pint_t &addr, pint_t end);
626-
int64_t getSLEB128(pint_t &addr, pint_t end);
627-
pint_t getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
628-
pint_t datarelBase = 0);
629-
bool findFunctionName(pint_t addr, char *buf, size_t bufLen,
630-
unw_word_t *offset);
631-
bool findUnwindSections(pint_t targetAddr, UnwindInfoSections &info);
632-
bool findOtherFDE(pint_t targetAddr, pint_t &fde);
633-
private:
634-
void *localCopy(pint_t addr);
635-
636-
task_t fTask;
637-
};
638-
639-
template <typename P> uint8_t RemoteAddressSpace<P>::get8(pint_t addr) {
640-
return *((uint8_t *)localCopy(addr));
641-
}
642-
643-
template <typename P> uint16_t RemoteAddressSpace<P>::get16(pint_t addr) {
644-
return P::E::get16(*(uint16_t *)localCopy(addr));
645-
}
646-
647-
template <typename P> uint32_t RemoteAddressSpace<P>::get32(pint_t addr) {
648-
return P::E::get32(*(uint32_t *)localCopy(addr));
649-
}
650-
651-
template <typename P> uint64_t RemoteAddressSpace<P>::get64(pint_t addr) {
652-
return P::E::get64(*(uint64_t *)localCopy(addr));
653-
}
654-
655-
template <typename P>
656-
typename P::uint_t RemoteAddressSpace<P>::getP(pint_t addr) {
657-
return P::getP(*(uint64_t *)localCopy(addr));
658-
}
659-
660-
template <typename P>
661-
typename P::uint_t OtherAddressSpace<P>::getRegister(pint_t addr) {
662-
return P::getRegister(*(uint64_t *)localCopy(addr));
663-
}
664-
665-
template <typename P>
666-
uint64_t OtherAddressSpace<P>::getULEB128(pint_t &addr, pint_t end) {
667-
uintptr_t size = (end - addr);
668-
LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
669-
LocalAddressSpace::pint_t sladdr = laddr;
670-
uint64_t result = LocalAddressSpace::getULEB128(laddr, laddr + size);
671-
addr += (laddr - sladdr);
672-
return result;
673-
}
674-
675-
template <typename P>
676-
int64_t RemoteAddressSpace<P>::getSLEB128(pint_t &addr, pint_t end) {
677-
uintptr_t size = (end - addr);
678-
LocalAddressSpace::pint_t laddr = (LocalAddressSpace::pint_t) localCopy(addr);
679-
LocalAddressSpace::pint_t sladdr = laddr;
680-
uint64_t result = LocalAddressSpace::getSLEB128(laddr, laddr + size);
681-
addr += (laddr - sladdr);
682-
return result;
683-
}
684-
685-
template <typename P> void *RemoteAddressSpace<P>::localCopy(pint_t addr) {
686-
// FIX ME
687-
}
688-
689-
template <typename P>
690-
bool RemoteAddressSpace<P>::findFunctionName(pint_t addr, char *buf,
691-
size_t bufLen,
692-
unw_word_t *offset) {
693-
// FIX ME
694-
}
695-
696-
/// unw_addr_space is the base class that abstract unw_addr_space_t type in
697-
/// libunwind.h points to.
698-
struct unw_addr_space {
699-
cpu_type_t cpuType;
700-
task_t taskPort;
701-
};
702-
703-
/// unw_addr_space_i386 is the concrete instance that a unw_addr_space_t points
704-
/// to when examining
705-
/// a 32-bit intel process.
706-
struct unw_addr_space_i386 : public unw_addr_space {
707-
unw_addr_space_i386(task_t task) : oas(task) {}
708-
RemoteAddressSpace<Pointer32<LittleEndian>> oas;
709-
};
710-
711-
/// unw_addr_space_x86_64 is the concrete instance that a unw_addr_space_t
712-
/// points to when examining
713-
/// a 64-bit intel process.
714-
struct unw_addr_space_x86_64 : public unw_addr_space {
715-
unw_addr_space_x86_64(task_t task) : oas(task) {}
716-
RemoteAddressSpace<Pointer64<LittleEndian>> oas;
717-
};
718-
719-
/// unw_addr_space_ppc is the concrete instance that a unw_addr_space_t points
720-
/// to when examining
721-
/// a 32-bit PowerPC process.
722-
struct unw_addr_space_ppc : public unw_addr_space {
723-
unw_addr_space_ppc(task_t task) : oas(task) {}
724-
RemoteAddressSpace<Pointer32<BigEndian>> oas;
725-
};
726-
727-
/// unw_addr_space_ppc is the concrete instance that a unw_addr_space_t points
728-
/// to when examining a 64-bit PowerPC process.
729-
struct unw_addr_space_ppc64 : public unw_addr_space {
730-
unw_addr_space_ppc64(task_t task) : oas(task) {}
731-
RemoteAddressSpace<Pointer64<LittleEndian>> oas;
732-
};
733-
734-
#endif // UNW_REMOTE
735-
736604
} // namespace libunwind
737605

738606
#endif // __ADDRESSSPACE_HPP__

libunwind/src/Unwind-seh.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -442,20 +442,23 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
442442
static int
443443
_unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) {
444444
#ifdef _LIBUNWIND_TARGET_X86_64
445-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_x86_64>(
446-
context, LocalAddressSpace::sThisAddressSpace);
445+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_x86_64> *>(cursor))
446+
UnwindCursor<LocalAddressSpace, Registers_x86_64>(
447+
context, LocalAddressSpace::sThisAddressSpace);
447448
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
448449
co->setInfoBasedOnIPRegister();
449450
return UNW_ESUCCESS;
450451
#elif defined(_LIBUNWIND_TARGET_ARM)
451-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm>(
452-
context, LocalAddressSpace::sThisAddressSpace);
452+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm> *>(cursor))
453+
UnwindCursor<LocalAddressSpace, Registers_arm>(
454+
context, LocalAddressSpace::sThisAddressSpace);
453455
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
454456
co->setInfoBasedOnIPRegister();
455457
return UNW_ESUCCESS;
456458
#elif defined(_LIBUNWIND_TARGET_AARCH64)
457-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm64>(
458-
context, LocalAddressSpace::sThisAddressSpace);
459+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm64> *>(cursor))
460+
UnwindCursor<LocalAddressSpace, Registers_arm64>(
461+
context, LocalAddressSpace::sThisAddressSpace);
459462
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
460463
co->setInfoBasedOnIPRegister();
461464
return UNW_ESUCCESS;

libunwind/src/UnwindCursor.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ class UnwindCursor : public AbstractUnwindCursor {
485485
DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }
486486
void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; }
487487

488+
// libunwind does not and should not depend on C++ library which means that we
489+
// need our own defition of inline placement new.
490+
static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
491+
488492
private:
489493

490494
pint_t getLastPC() const { return _dispContext.ControlPc; }
@@ -892,6 +896,10 @@ class UnwindCursor : public AbstractUnwindCursor{
892896
virtual void saveVFPAsX();
893897
#endif
894898

899+
// libunwind does not and should not depend on C++ library which means that we
900+
// need our own defition of inline placement new.
901+
static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
902+
895903
private:
896904

897905
#if defined(_LIBUNWIND_ARM_EHABI)

libunwind/src/libunwind.cpp

+3-86
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#ifndef NDEBUG
1616
#include <cstdlib> // getenv
1717
#endif
18-
#include <new>
19-
#include <algorithm>
2018

2119
#include "libunwind_ext.h"
2220
#include "config.h"
@@ -73,97 +71,16 @@ _LIBUNWIND_EXPORT int unw_init_local(unw_cursor_t *cursor,
7371
# error Architecture not supported
7472
#endif
7573
// Use "placement new" to allocate UnwindCursor in the cursor buffer.
76-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
77-
context, LocalAddressSpace::sThisAddressSpace);
74+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor))
75+
UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
76+
context, LocalAddressSpace::sThisAddressSpace);
7877
#undef REGISTER_KIND
7978
AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
8079
co->setInfoBasedOnIPRegister();
8180

8281
return UNW_ESUCCESS;
8382
}
8483

85-
#ifdef UNW_REMOTE
86-
/// Create a cursor into a thread in another process.
87-
_LIBUNWIND_EXPORT int unw_init_remote_thread(unw_cursor_t *cursor,
88-
unw_addr_space_t as,
89-
void *arg) {
90-
// special case: unw_init_remote(xx, unw_local_addr_space, xx)
91-
if (as == (unw_addr_space_t)&LocalAddressSpace::sThisAddressSpace)
92-
return unw_init_local(cursor, NULL); //FIXME
93-
94-
// use "placement new" to allocate UnwindCursor in the cursor buffer
95-
switch (as->cpuType) {
96-
case CPU_TYPE_I386:
97-
new ((void *)cursor)
98-
UnwindCursor<RemoteAddressSpace<Pointer32<LittleEndian>>,
99-
Registers_x86>(((unw_addr_space_i386 *)as)->oas, arg);
100-
break;
101-
case CPU_TYPE_X86_64:
102-
new ((void *)cursor)
103-
UnwindCursor<RemoteAddressSpace<Pointer64<LittleEndian>>,
104-
Registers_x86_64>(((unw_addr_space_x86_64 *)as)->oas, arg);
105-
break;
106-
case CPU_TYPE_POWERPC:
107-
new ((void *)cursor)
108-
UnwindCursor<RemoteAddressSpace<Pointer32<BigEndian>>,
109-
Registers_ppc>(((unw_addr_space_ppc *)as)->oas, arg);
110-
break;
111-
default:
112-
return UNW_EUNSPEC;
113-
}
114-
return UNW_ESUCCESS;
115-
}
116-
117-
118-
static bool is64bit(task_t task) {
119-
return false; // FIXME
120-
}
121-
122-
/// Create an address_space object for use in examining another task.
123-
_LIBUNWIND_EXPORT unw_addr_space_t unw_create_addr_space_for_task(task_t task) {
124-
#if __i386__
125-
if (is64bit(task)) {
126-
unw_addr_space_x86_64 *as = new unw_addr_space_x86_64(task);
127-
as->taskPort = task;
128-
as->cpuType = CPU_TYPE_X86_64;
129-
//as->oas
130-
} else {
131-
unw_addr_space_i386 *as = new unw_addr_space_i386(task);
132-
as->taskPort = task;
133-
as->cpuType = CPU_TYPE_I386;
134-
//as->oas
135-
}
136-
#else
137-
// FIXME
138-
#endif
139-
}
140-
141-
142-
/// Delete an address_space object.
143-
_LIBUNWIND_EXPORT void unw_destroy_addr_space(unw_addr_space_t asp) {
144-
switch (asp->cpuType) {
145-
#if __i386__ || __x86_64__
146-
case CPU_TYPE_I386: {
147-
unw_addr_space_i386 *as = (unw_addr_space_i386 *)asp;
148-
delete as;
149-
}
150-
break;
151-
case CPU_TYPE_X86_64: {
152-
unw_addr_space_x86_64 *as = (unw_addr_space_x86_64 *)asp;
153-
delete as;
154-
}
155-
break;
156-
#endif
157-
case CPU_TYPE_POWERPC: {
158-
unw_addr_space_ppc *as = (unw_addr_space_ppc *)asp;
159-
delete as;
160-
}
161-
break;
162-
}
163-
}
164-
#endif // UNW_REMOTE
165-
166-
16784
/// Get value of specified register at cursor position in stack frame.
16885
_LIBUNWIND_EXPORT int unw_get_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
16986
unw_word_t *value) {

0 commit comments

Comments
 (0)