Skip to content

cdac: use debugger-conventional HRESULTs in the data-target adapters #131364

Description

@hoyosjs

The cdac legacy data-target adapters in mscordaccore_universal/Entrypoints.cs return generic HRESULTs where the CoreCLR debugger stack uses more specific ones. The same patterns exist across the ICorDebugDataTarget path (added in #130856) and the ICLRDataTarget/CLRDataCreateInstance path (added in #114812), and were re-flagged in review of #131008. Consolidating the fixes here so they land in one change.

Items to address across both data-target adapter paths (CreateTargetFromCorDebugDataTarget and CLRDataCreateInstanceCore):

  1. Partial ReadVirtual. When ReadVirtual returns success but reads fewer bytes than requested, return CORDBG_E_READVIRTUAL_FAILURE instead of E_FAIL. The CLRDataCreateInstance path currently does not check bytesRead at all - a partial read there can leave a fixed-size header buffer partly uninitialized and cause nondeterministic descriptor parsing. Apply the check consistently.
  2. Write to a read-only target. When the target does not implement ICorDebugMutableDataTarget, the WriteVirtual and SetThreadContext callbacks return E_NOTIMPL, which is ambiguous (method-missing vs. intentionally read-only). Return CORDBG_E_TARGET_READONLY, matching ReadOnlyDataTargetFacade.
  3. ContractDescriptorTarget.TryCreate failure. When TryCreate returns false, the entrypoint surfaces COR_E_INVALIDOPERATION via InvalidOperationException. Return a conventional HRESULT (E_FAIL) instead.

Out of scope: the shimdatatarget.cpp E_INVALIDARG -> E_UNEXPECTED suggestions from #131008 review are moot; those methods were removed.

Note

This issue was authored by GitHub Copilot on behalf of @hoyosjs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions