Skip to content

Design cDAC level API to expose stack walking #111734

Closed

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
}

Activity

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jan 23, 2025
  2. changed the title [-]Decide on a cDAC level API to expose stack walking.[/-] [+]Design cDAC level API to expose stack walking[/+] on Jan 23, 2025
  3. added and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jan 23, 2025
  4. dotnet-policy-service commented on Jan 23, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @tommcdon
    See info in area-owners.md if you want to be subscribed.

  5. added this to the 10.0.0 milestone on Feb 3, 2025
  6. added
    enhancementProduct code improvement that does NOT require public API changes/additions
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Feb 3, 2025
  7. tommcdon commented on Feb 3, 2025

    @tommcdon
    Member
  8. max-charlamb commented on Mar 5, 2025

    @max-charlamb
    MemberAuthor

    Implemented proposal 2 in #111759. Exposed API is subject to change.

    Closing this issue.

  9. locked and limited conversation to collaborators on Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions