Skip to content
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

[Bug] Cannot step into SEH __except handler. #373

Open
DanielJamesCollier opened this issue Dec 17, 2024 · 0 comments
Open

[Bug] Cannot step into SEH __except handler. #373

DanielJamesCollier opened this issue Dec 17, 2024 · 0 comments
Labels
Bug A report of unintended or broken behavior. Debugger Pertains to the debugger.

Comments

@DanielJamesCollier
Copy link

DanielJamesCollier commented Dec 17, 2024

In Visual Studio 2022, if I put a breakpoint inside page_fault_handler(DWORD exception_code) it gets hit after first hitting the ptr[0] = 0; exception.
In Raddbg, if I put a breakpoint inside of page_fault_handler(DWORD exception_code) it never gets hit because I cannot continue after the exception at ptr[0] = 0

Here are two videos showing the problem:
Visual studio working https://www.youtube.com/watch?v=io9ahgyJfM0
Raddbg not working https://www.youtube.com/watch?v=cuCGhRjYJjg

Minimal repo code.
main.c

#include <Windows.h>
#include <stdio.h>

#define PAGE_SIZE 4096  // Assuming typical page size
#define PAGE_LIMIT 2    // Limit to trigger the exception after 2 pages

static void* base_address;

// Exception handler to commit memory pages
int __stdcall page_fault_handler(DWORD exception_code) {
    printf("Page fault detected. Committing a page...\n");
    VirtualAlloc(base_address, PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE);
    return EXCEPTION_CONTINUE_EXECUTION;
}

int main() {
    // Reserve memory for PAGE_LIMIT pages
    base_address = VirtualAlloc(NULL, PAGE_LIMIT * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS);

    __try {
        // Trigger an access violation by writing to uncommitted memory
        volatile char* ptr = (char*)base_address;

        // This write should trigger page_fault_handler(DWORD exception_code).
        // In Visual studio 2022, if I put a breakpoint in the page_fault_handler(DWORD exception_code)
        // function then it gets hit. In Raddbg, I cannot continue past the exception.
        ptr[0] = 0;  
    }
    __except (page_fault_handler(GetExceptionCode())) {
        printf("Exception handler failed to commit page.\n");
        return 1;
    }

    printf("Page successfully committed and written to.\n");
    VirtualFree(base_address, 0, MEM_RELEASE);
    return 0;
}

I try to be as clear as possible in my bug reports so please let me know if there is anything I could add.
Also please let me know if I am simply "holding it wrong".

I am loving the debugger so far, this is just one issue I have hit.

@DanielJamesCollier DanielJamesCollier changed the title Cannot step into SEH __except handler. [Bug] Cannot step into SEH __except handler. Dec 17, 2024
@ryanfleury ryanfleury added Debugger Pertains to the debugger. Bug A report of unintended or broken behavior. labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A report of unintended or broken behavior. Debugger Pertains to the debugger.
Projects
None yet
Development

No branches or pull requests

2 participants