Skip to content

Design cDAC level API to expose stack walking #111734

Closed
@max-charlamb

Description

@max-charlamb

Proposal 1

Using opaque IStackWalkHandle and IStackFrameHandle to hold state about the stack walk. These are passed back to the contract to be operated on.

// Each Contract version implements its own opaque handle StackWalkFrameHandle_1 for IStackFrameHandle and IStackWalkHandle etc..
// These are checked when passed in to verify that it is from the write contract version, otherwise an invalid argument exception is thrown
// This allows for flexibility in the handle implementation
//  
// if (uncheckedHandle is not StackWalkHandle_1 stackWalkHandle)
// {
//     throw new InvalidArgumentException();
// }

internal interface IStackFrameHandle { }

internal interface IStackWalkHandle { }

// IStackContext is implemented by each architectures thread context object. 

internal interface IStackContext 
{
    int GetContextSize();
    int GetContextFlags();
    TargetPointer GetIP();
    TargetPointer GetSP();
    bool WriteToBuffer(Span<byte> buffer);
}

internal interface IStackWalk : IContract
{
    // Creates a StackWalk 
    public IStackWalkHandle CreateStackWalk(ThreadData threadData);

    // Moves stackWalkHandle to the next managed frame
    // returns true if successful, false otherwise
    public bool Next(IStackWalkHandle stackWalkHandle);
    public IStackFrameHandle GetFrame(IStackWalkHandle stackWalkHandle);
    public IStackFrameContext GetContext(IStackWalkHandle stackWalkHandle);
    public int GetNumArgs(IStackFrameHandle stackFrameHandle);
    // ... other functions implemented on IXCLRDataFrame
}

Proposal 2

Use a IEnumerable to iterate the frames lazily. This simplifies the API surface with the downside of not being able to interact with a "stack walk" as a whole.
Suggestion by #111759 (comment)

internal interface IStackFrameHandle 
{
}


internal interface IStackWalk : IContract
{
    // Creates a StackWalk 
    public IEnumerable<IStackFrameHandle> CreateStackWalk(ThreadData threadData);

    public IStackFrameContext GetContext(IStackWalkHandle stackWalkHandle);
    public int GetNumArgs(IStackFrameHandle stackFrameHandle);
    // ... other functions implemented on IXCLRDataFrame
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Diagnostics-coreclrenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions