[LLVMbugs] [Bug 21053] New: _Unwind_Backtrace() can't get past functions with EH.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 24 03:21:11 PDT 2014


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: unassignedclangbugs at nondot.org
          Reporter: asg.msft at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140924/3e6ee3e0/attachment.html>


More information about the llvm-bugs mailing list