0

I am implementing logging of error message (It includes information of exception backtrace). I asked similar question how to do this at Reliable way to print exception backtrace in catch handler?. I decided to check out callstacks at x86 and x64 platforms. Result of stack comparisons surprised me. Here is my program:

#include <iostream>
#include <Windows.h>

using namespace std;

struct A
{
};

void foo3()
{
    throw A();
}

void foo2()
{
    foo3(); 
}

void foo1()
{
    foo2();
}

void foo()
{
    try
    {
        foo1();
    }
    catch(...)
    {
        cout << "exception rethrowing" << endl;
        throw;
    }
}
int seh_filter(_EXCEPTION_POINTERS* exception)
{
    cout << "SEH FILTER" << endl;
    return EXCEPTION_EXECUTE_HANDLER;
}

int main(void)
{
    __try
    {
        foo();
    }
    __except(seh_filter(GetExceptionInformation()))
    {
        cout << "SEH catch handler" << endl;
    }
    return 0;
}

I set breakpoint at seh_filter to explore backtrace and ran debug builds. Here is images:

enter image description here It seems like I cannot print full call stack on x64 platform. What's going on? I cannot understand why were callstacks changed so dramatically? I am using msvc2013 on Windows 10.

Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
  • you can print full stack on any platform. but not all functions have ebp-frame (x86) and not all functions have `RUNTIME_FUNCTION` information (x64). so never in general you can view **all** functions – RbMm Feb 26 '18 at 14:04
  • your `fooN()` too simply. not allocate any stack space, etc. use more complex functions – RbMm Feb 26 '18 at 14:06
  • @RbMm, can you please explain, why do functions not essentially have ebp-frame? I cannot understand that phrase. P.S. I gave simplified version of code. This behaviour is reproduced on more complex code (which uses more local variables) – Alex Aparin Feb 26 '18 at 14:08
  • @RbMm, I thought that original mechanics of seh may causes such behaviour. I know that x86 uses frame-based way of exception handling, x64 uses table-based way of exception handling. But I cannot understand how it can change so stacks – Alex Aparin Feb 26 '18 at 14:10
  • *ebp-frame* used only in *x86* code. and not always, depend from optimization. if function not use *ebp-frame* - impossible unwind it stack at all – RbMm Feb 26 '18 at 14:11
  • all what you wrote at all not related to seh. this related to stack walk. and you must know - not always possible view all functions call in stack – RbMm Feb 26 '18 at 14:12

0 Answers0