-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print a backtrace when a signal is caught #8
Comments
https://github.com/KavinduZoysa/test-GCs/tree/div @jclark, could you please review my draft code and give your opinion on this? I took the ballerina source code and llvm IR from @ruvi-d's test cases. To get the line where the division is done to print on the backtrace, I put the debug info(ex : !dbg !4) on Please correct me if this approach is wrong. |
I don’t understand why you are getting a SIGFPE since the .ll code is explicitly checking for a divisor of 0. I must be missing something obvious. |
As per our offline discussion, since I have used |
@jclark, as per suggestions I have written a simple llvm IR by removing the checks for div operation. Since we do not have any branching now, there is not a place to call Please check the new changes and give your opinion. |
@KavinduZoysa The problem with that is that LLVM specified that divide by zero is undefined behavior for "sdiv". Unless we can find a documented, correct way to avoid this, we cannot rely on it. I believe Rust specifies the same behavior for We can also potentially call llvm.trap when we get an overflow (which will I believe cause a signal) and then catch that signal and print a backtrace. Probably the processor can run that faster (which is why UBSan does it that way). |
Yes @jclark, I will check how the rust is handling this. Currently, I am trying to build an example on |
1 similar comment
Yes @jclark, I will check how the rust is handling this. Currently, I am trying to build an example on |
This approach isn't going to work because of #38. |
Ballerina requires that the
/
operator result a panic if its right operand is 0. We could handle this by explicitly testing for 0, before performing the division, but it would be much more efficient if instead we relied on the CPU's ability to generate an exception in this case. In POSIX terms, the CPU exception will turn into a signal (SIGFPE in this case), which the kernel will deliver to the program. Usingsigaction
we can catch this exception and get the address (in siginfo.si_addr) of the instruction that caused CPU exception. We should then be able to use this to print a backtrace.The text was updated successfully, but these errors were encountered: