I investigating .Net Framework JITter compilation results and I want to get programmatically exceptions handlers chain. May be somebody can help me with this investigation?
To make task easier, I debug following code:
class Program
{
static void Main(string[] args) { MethodA(); }
static void MethodA() { MethodB(); }
static void MethodB()
{
try { MethodC(); }
catch (Exception exception) { MethodC(); }
}
static void MethodC() { MethodD(); }
static void MethodD()
{
try { MethodE(); }
catch (Exception exception) { MethodE(); }
}
static void MethodE() { throw new Exception(); }
}
What's found?
- JITter uses standart way to build stack frames (locals,
EBP,EIP, params) - First parameters moves to method via registers (fastcall)
- Where is try-catch-finally ? I have no idea. Really. Method have no any code to deregister last handler from chain.
- Static methods pushes to stack only
EBPandEIP. This means, stack cannot contain chain and chain is out of stack.
What I use: MS Visual Studio 2010, SOS extension for resolving .Net objects and metadata by address. VMMap to understand, what type of memory page by given address and (hehe) MS OneNote to mark memory dump with different colors to mark as resolved (that means, I understand what I found)
I'll be happy to understand where is this chain, but I have no experience to do it.
Important note: CLR don't uses SEH for exceptions (many articles, where authors write about SEH in CLR lies. CLR only wraps SEH to translate its exceptions into CLR types)