Comments (7)
This is a good series of blog posts on how C++ exception handling works:
https://monkeywritescode.blogspot.com/p/c-exceptions-under-hood.html
C++ ABI is here:
https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
from nballerina.
We are going to do #6 initially. This would be at a later stage, when we implement trap
. But it might be worth thinking about now, since we are spending time on panics.
@KavinduZoysa What do you think?
from nballerina.
We are going to do #6 initially. This would be at a later stage, when we implement
trap
. But it might be worth thinking about now, since we are spending time on panics.@KavinduZoysa What do you think?
Yes @jclark, I also agree with that, I will look into this.
from nballerina.
So this is sort of what we were doing before we started looking into backtrace.
to quote llvm-libunwind doc:
The unwinder has two levels of API. The high level APIs are the Unwind* functions which implement functionality required by cxa* exception functions. The low level APIs are the unw* functions which are an interface defined by the old HP libunwind project.
We were looking at the layer below _cxa* functions. One concern with relaying on higher level _cxa* function is that we'll have to ship libcxxabi
. We were able to get the cross language unwinding working even with C. So I don't see this as a strong deciding factor for picking C++.
from nballerina.
This is an interesting doc from Herb Sutter on problems with exception C++ model
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
Summary is here
This proposal aims to marry the best of exceptions and error codes: to allow a function to declare that it throws values of a statically known type, which can then be implemented exactly as efficiently as a return value.
Throwing such values behaves as-if the function returned union{R;E;}+bool where on success the function re- turns the normal return value R and on error the function returns the error value type E, both in the same return channel including using the same registers. The discriminant can use an unused CPU flag or a register.
Makes me wonder whether we should consider a strategy where return (for non-external functions) at the LLVM level is a boolean + a union of the abnormal error value and the normal return value. In that case, the problem turns into constructing a representation of the stacktrace that we can store in an error value to be printed out later.
from nballerina.
@manuranga and I are talking about the same thing, which is the base API defined in the Itanium C++ ABI doc:
https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-abi
from nballerina.
This is a brief summary of how the exceptions are handled in C++.
When an exception is thrown, it will call 2 c++ ABIs(__cxa_allocate_exception and __cxa_throw). Then __cxa_throw calls a couple of _Unwind_ methods to iterate through each stack to find the correct catch. If the correct catch was found, the instruction pointer is set to that place. All pieces of information needed to unwind will be kept under CFI(Call Frame Information). _Unwind_ methods use this CFI to iterate over the stack. To find the correct stack frame there is a function called __gxx_personality_v0. All the information related to exceptions(Type of exception, location of try/catch blocks, where to land) are defined under LSDA(Language-specific Data Area). The __gxx_personality_v0 should have the capability to read LSDA and check whether the given exception can be handled. The __gxx_personality_v0 is called for each stack frame.
I am currently working on investigating how this knowledge can be applied to implement ballerina trap/panic
from nballerina.
Related Issues (20)
- See if we can simply `listFormulaIsEmpty()` with introduction of `undef`
- `SyntaxNode` don't distinguish between exclusive record type without fields and map
- Distinguish `record {| T...; |}` vs `map<T>` in ST and AST HOT 1
- Implement backend support for optional record fields
- Assigning a vararg function to a function value whose type has a fixed number of args is failing
- `testBirCompile` test is failling with 2201.5.0 RC1 HOT 6
- Parsing binary type descriptors with function types is failing
- Invalid record subtype relation HOT 5
- Use property based testing to validate function subtyping and application
- Add support for `never` type
- Add support for object type HOT 1
- Make complement op for function type explicit
- Confusing behaviour around compliment for "sugared" types HOT 1
- Extend BIR to support closures HOT 3
- Implement closures for final values
- Make it possible for older jBallerina versions to use nBallerina for validation HOT 2
- Implement escape analysis for closures
- Type testing with `FunctionConstOperands` fail to compile
- Use exact bit to check function value exactness
- Calculating sub-element address using GEP fails on AArch64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nballerina.