Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

_Unwind_Backtrace() can't get past functions with EH. #21052

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR21053
Status NEW
Importance P normal
Reported by Microsoft Office (asg.msft@gmail.com)
Reported on 2014-09-24 05:21:11 -0700
Last modified on 2014-09-24 06:04:02 -0700
Version 3.4
Hardware PC Windows NT
CC dgregor@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Clang 3.4
Picked up from: From Android r9d NDK.

Description:
First issue:
When the functions don't have try-catch in them the back trace (code given
below which uses _Unwind_Backtrace() and _Unwind_GetIP()) works fine and the IP
gets updated and prints all the functions walking down the stack.

Whereas if any of the functions have a try-catch block, _Unwind_GetIP() can't
get past that function. So it keeps looping around that IP indefinitely.

Second issue: The return code for _Unwind_Backtrace() is _URC_FAILURE.

I'm not sure whether the main trunk clang has the same issue. But Android's
NDK's clang definitely reproduces this. I filed a bug for Android as well.

Compilation command:
clang++.exe -target armv7-none-linux-androideabi -O0 -g -funwind-tables -
fexceptions -fno-omit-frame-pointer  -std=c++11 -c foo.cpp -o foo.o

Sample code: foo.cpp:

#include <unwind.h>

_Unwind_Reason_Code trace_func(struct _Unwind_Context *context, void* arg)
{
   void *ip = (void *)_Unwind_GetIP(context);
   if(nullptr == ip)
       // ip is never nullptr. Further if the context is from a function
       // that has try-catch block, it can't move beyond that frame.
    return _URC_END_OF_STACK;
   else
   return _URC_NO_REASON;
}

void func3()
{
    _Unwind_Backtrace(trace_func, nullptr);
}

void func2() {
    try { func3(); }
    catch(...){}
}
void func1() { func2(); }

int main()
{
    func1();
    return 0;
}

EXPECTED RESULTS:
For the above program I expect the stack back trace to be (of course once I
resolve the symbols with dladdr):
_Unwind_Backtrace
func3()
func2()
func1()
main()
...

ACTUAL RESULTS:
_Unwind_Backtrace
func3()
func2()
func2()
func2()
ad infinitum

When I remove the try-catch though, it works fine and reports the results as in
EXPECTED results above. Please let me know if you need more details.

Thanks.
Quuxplusone commented 10 years ago

This issue seems to be happening only for armv7. And not for i686-none-linux-android.