Repository: dotnet/runtime
File: src/coreclr/debug/daccess/request.cpp (C++)

Code before:
{
    if (addr == 0 || ModuleData == NULL)
        return E_INVALIDARG;

    SOSDacEnter();

    Module* pModule = PTR_Module(TO_TADDR(addr));

    ZeroMemory(ModuleData,sizeof(DacpModuleData));
    ModuleData->Address = addr;
    ModuleData->PEAssembly = addr; // Module address in .NET 9+ - correspondingly, SOS-DAC APIs for PE assemblies expect a module address
    COUNT_T metadataSize = 0;
    if (!pModule->IsReflectionEmit())
    {
        ModuleData->ilBase = TO_CDADDR(dac_cast<TADDR>(pModule->m_baseAddress));
    }

    ModuleData->metadataStart = (CLRDATA_ADDRESS)dac_cast<TADDR>(pModule->GetPEAssembly()->GetLoadedMetadata(&metadataSize));
    ModuleData->metadataSize = (SIZE_T) metadataSize;

    ModuleData->bIsReflection = pModule->IsReflectionEmit();
    ModuleData->bIsPEFile = !pModule->IsReflectionEmit();
    ModuleData->Assembly = HOST_CDADDR(pModule->GetAssembly());
    ModuleData->dwModuleID = 0; // CoreCLR no longer has this concept
    ModuleData->dwModuleIndex = 0; // CoreCLR no longer has this concept
    ModuleData->dwTransientFlags = pModule->m_dwTransientFlags & IS_EDIT_AND_CONTINUE;
    ModuleData->LoaderAllocator = HOST_CDADDR(pModule->m_loaderAllocator);

    EX_TRY
    {
        //
        // In minidump's case, these data structures are not available.
        //
        ModuleData->TypeDefToMethodTableMap = PTR_CDADDR(pModule->m_TypeDefToMethodTableMap.pTable);
        ModuleData->TypeRefToMethodTableMap = PTR_CDADDR(pModule->m_TypeRefToMethodTableMap.pTable);
        ModuleData->MethodDefToDescMap = PTR_CDADDR(pModule->m_MethodDefToDescMap.pTable);
        ModuleData->FieldDefToDescMap = PTR_CDADDR(pModule->m_FieldDefToDescMap.pTable);
        ModuleData->MemberRefToDescMap = PTR_CDADDR(pModule->m_MemberRefMap.pTable);
        ModuleData->ManifestModuleReferencesMap = PTR_CDADDR(pModule->m_ManifestModuleReferencesMap.pTable);

    }
    EX_CATCH
    {
    }
    EX_END_CATCH

    SOSDacLeave();
    return hr;
}

HRESULT

Review comment (suggestion):
```suggestion
    ModuleData->dwTransientFlags = (pModule->m_dwTransientFlags & Module::IS_EDIT_AND_CONTINUE) ? ::IS_EDIT_AND_CONTINUE : 0;
```
Can we make the mapping between the two definitions more explicit? (I am not sure whether my suggestion compiles - just shows the idea.)

Code after:
{
    if (addr == 0 || ModuleData == NULL)
        return E_INVALIDARG;

    SOSDacEnter();

    Module* pModule = PTR_Module(TO_TADDR(addr));

    ZeroMemory(ModuleData,sizeof(DacpModuleData));
    ModuleData->Address = addr;
    ModuleData->PEAssembly = addr; // Module address in .NET 9+ - correspondingly, SOS-DAC APIs for PE assemblies expect a module address
    COUNT_T metadataSize = 0;
    if (!pModule->IsReflectionEmit())
    {
        ModuleData->ilBase = TO_CDADDR(dac_cast<TADDR>(pModule->m_baseAddress));
    }

    ModuleData->metadataStart = (CLRDATA_ADDRESS)dac_cast<TADDR>(pModule->GetPEAssembly()->GetLoadedMetadata(&metadataSize));
    ModuleData->metadataSize = (SIZE_T) metadataSize;

    ModuleData->bIsReflection = pModule->IsReflectionEmit();
    ModuleData->bIsPEFile = !pModule->IsReflectionEmit();
    ModuleData->Assembly = HOST_CDADDR(pModule->GetAssembly());
    ModuleData->dwModuleID = 0; // CoreCLR no longer has this concept
    ModuleData->dwModuleIndex = 0; // CoreCLR no longer has this concept
    ModuleData->dwTransientFlags = (pModule->m_dwTransientFlags & Module::IS_EDIT_AND_CONTINUE) ? DacpModuleData::IsEditAndContinue : 0;
    ModuleData->LoaderAllocator = HOST_CDADDR(pModule->m_loaderAllocator);

    EX_TRY
    {
        //
        // In minidump's case, these data structures are not available.
        //
        ModuleData->TypeDefToMethodTableMap = PTR_CDADDR(pModule->m_TypeDefToMethodTableMap.pTable);
        ModuleData->TypeRefToMethodTableMap = PTR_CDADDR(pModule->m_TypeRefToMethodTableMap.pTable);
        ModuleData->MethodDefToDescMap = PTR_CDADDR(pModule->m_MethodDefToDescMap.pTable);
        ModuleData->FieldDefToDescMap = PTR_CDADDR(pModule->m_FieldDefToDescMap.pTable);
        ModuleData->MemberRefToDescMap = PTR_CDADDR(pModule->m_MemberRefMap.pTable);
        ModuleData->ManifestModuleReferencesMap = PTR_CDADDR(pModule->m_ManifestModuleReferencesMap.pTable);

    }
    EX_CATCH
    {
    }
    EX_END_CATCH

    SOSDacLeave();
    return hr;
}

HRESULT