Skip to content

Commit

Permalink
Add option to step with DWARF
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Aug 27, 2013
1 parent 48af7e1 commit bb95a5c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/libunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ extern int unw_get_proc_name(unw_cursor_t*, char*, size_t, unw_word_t*)
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
#endif

extern int unw_init_local_dwarf(unw_cursor_t*, unw_context_t*);


#if UNW_REMOTE
/*
Expand Down
17 changes: 12 additions & 5 deletions src/UnwindCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class UnwindCursor
virtual bool isSignalFrame();
virtual bool getFunctionName(char* buf, size_t bufLen, unw_word_t* offset);
virtual void setInfoBasedOnIPRegister(bool isReturnAddress=false);
virtual void setForceDWARF(bool force);

void operator delete(void* p, size_t size) {}

Expand Down Expand Up @@ -348,7 +349,7 @@ class UnwindCursor
bool mustUseDwarf() const { return false; }
#endif
#else
bool mustUseDwarf() const { R dummy; uint32_t offset; return dwarfWithOffset(dummy, offset); }
bool mustUseDwarf() const { R dummy; uint32_t offset; return fForceDwarf || dwarfWithOffset(dummy, offset); }
#endif

bool dwarfWithOffset(uint32_t& offset) const { R dummy; return dwarfWithOffset(dummy, offset); }
Expand Down Expand Up @@ -391,17 +392,18 @@ class UnwindCursor
compact_unwind_encoding_t dwarfEncoding(Registers_ppc&) const { return 0; }

unw_proc_info_t fInfo;
R fRegisters;
A& fAddressSpace;
bool fUnwindInfoMissing;
bool fIsSignalFrame;
bool fForceDwarf;
R fRegisters;
A& fAddressSpace;
};

typedef UnwindCursor<LocalAddressSpace,Registers_x86> AbstractUnwindCursor;

template <typename A, typename R>
UnwindCursor<A,R>::UnwindCursor(unw_context_t* context, A& as)
: fRegisters(context), fAddressSpace(as), fUnwindInfoMissing(false), fIsSignalFrame(false)
: fUnwindInfoMissing(false), fIsSignalFrame(false), fForceDwarf(false), fRegisters(context), fAddressSpace(as)
{
COMPILE_TIME_ASSERT( sizeof(UnwindCursor<A,R>) < sizeof(unw_cursor_t) );

Expand All @@ -410,7 +412,7 @@ UnwindCursor<A,R>::UnwindCursor(unw_context_t* context, A& as)

template <typename A, typename R>
UnwindCursor<A,R>::UnwindCursor(A& as, thread_t thread)
: fAddressSpace(as), fUnwindInfoMissing(false), fIsSignalFrame(false)
: fUnwindInfoMissing(false), fIsSignalFrame(false), fForceDwarf(false), fAddressSpace(as)
{
bzero(&fInfo, sizeof(fInfo));
// FIXME
Expand Down Expand Up @@ -471,6 +473,11 @@ bool UnwindCursor<A,R>::isSignalFrame()
return fIsSignalFrame;
}

template <typename A, typename R>
void UnwindCursor<A,R>::setForceDWARF(bool force)
{
fForceDwarf = force;
}

template <typename A, typename R>
bool UnwindCursor<A,R>::getInfoFromDwarfSection(pint_t pc, pint_t mh, pint_t ehSectionStart, uint32_t sectionLength, uint32_t sectionOffsetOfFDE)
Expand Down
30 changes: 30 additions & 0 deletions src/libuwind.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,42 @@ EXPORT int unw_init_local(unw_cursor_t* cursor, unw_context_t* context)
// use "placement new" to allocate UnwindCursor in the cursor buffer
#if __i386__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_x86>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_x86>), "libunwind header outdated");
#elif __x86_64__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_x86_64>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_x86_64>), "libunwind header outdated");
#elif __ppc__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_ppc>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_ppc>), "libunwind header outdated");
#endif

AbstractUnwindCursor* co = (AbstractUnwindCursor*)cursor;
co->setInfoBasedOnIPRegister();

return UNW_ESUCCESS;
}


///
/// create a cursor of a thread in this process given 'context' recorded by unw_getcontext()
///
EXPORT int unw_init_local_dwarf(unw_cursor_t* cursor, unw_context_t* context)
{
DEBUG_PRINT_API("unw_init_local(cursor=%p, context=%p)\n", cursor, context);
// use "placement new" to allocate UnwindCursor in the cursor buffer
#if __i386__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_x86>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_x86>), "libunwind header outdated");
#elif __x86_64__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_x86_64>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_x86_64>), "libunwind header outdated");
#elif __ppc__
new ((void*)cursor) UnwindCursor<LocalAddressSpace,Registers_ppc>(context, sThisAddressSpace);
static_assert(sizeof(unw_cursor_t) >= sizeof(UnwindCursor<LocalAddressSpace,Registers_ppc>), "libunwind header outdated");
#endif

AbstractUnwindCursor* co = (AbstractUnwindCursor*)cursor;
co->setForceDWARF(true);
co->setInfoBasedOnIPRegister();

return UNW_ESUCCESS;
Expand Down

0 comments on commit bb95a5c

Please sign in to comment.