http://llvm.org/bugs/show_bug.cgi?id=21053

            Bug ID: 21053
           Summary: _Unwind_Backtrace() can't get past functions with EH.
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to