Repository: dotnet/runtime
File: src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp (C++)

Code before:

void MethodContext::dmpGetSpecialCopyHelper(DWORDLONG key, DWORDLONG value)
{
    printf("getSpecialCopyHelper key %016" PRIX64 ", value %016" PRIX64 "", key, value);
}

CORINFO_METHOD_HANDLE MethodContext::repGetSpecialCopyHelper(CORINFO_CLASS_HANDLE type)
{
    DWORDLONG key = CastHandle(type);
    DWORDLONG value = LookupByKeyOrMiss(GetSpecialCopyHelper, key, ": key %016" PRIX64 "", key);
    DEBUG_REP(dmpGetSpecialCopyHelper(key, value));
    return (CORINFO_METHOD_HANDLE)value;
}

void MethodContext::recGetWasmTypeSymbol(CorInfoWasmType* types, size_t typesSize, CORINFO_WASM_TYPE_SYMBOL_HANDLE result)
{
    if (GetWasmTypeSymbol == nullptr)
        GetWasmTypeSymbol = new LightWeightMap<DWORDLONG, DWORDLONG>();

    DWORDLONG key;
    ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
    key = CastPointer(types);

    DWORDLONG value = CastHandle(result);
    GetWasmTypeSymbol->Add(key, value);
    DEBUG_REC(dmpGetWasmTypeSymbol(key, value));
}

void MethodContext::dmpGetWasmTypeSymbol(DWORDLONG key, DWORDLONG value)
{
    printf("getWasmTypeSymbol key %016" PRIX64 ", value %016" PRIX64 "", key, value);
}

CORINFO_WASM_TYPE_SYMBOL_HANDLE MethodContext::repGetWasmTypeSymbol(CorInfoWasmType* types, size_t typesSize)
{
    DWORDLONG key = CastPointer(types);
    DWORDLONG value = LookupByKeyOrMiss(GetWasmTypeSymbol, key, ": key %016" PRIX64 "", key);
    DEBUG_REP(dmpGetWasmTypeSymbol(key, value));
    return (CORINFO_WASM_TYPE_SYMBOL_HANDLE)value;
}

void MethodContext::dmpSigInstHandleMap(DWORD key, DWORDLONG value)
{
    printf("SigInstHandleMap key %u, value %016" PRIX64 "", key, value);
}

int MethodContext::dumpMethodIdentityInfoToBuffer(char* buff, int len, bool ignoreMethodName /* = false */, CORINFO_METHOD_INFO* optInfo /* = nullptr */, unsigned optFlags /* = 0 */)
{
    if (len < METHOD_IDENTITY_INFO_SIZE)
        return -1;


Review comment (suggestion):
This does not look correct to me. It is storing the `CorInfoWasmType*` numerical value in the map, but we need to store its contents.

(I am not sure what is the canonical pattern for this in SPMI, you may have to look around this file to check)

Code after:

void MethodContext::dmpGetSpecialCopyHelper(DWORDLONG key, DWORDLONG value)
{
    printf("getSpecialCopyHelper key %016" PRIX64 ", value %016" PRIX64 "", key, value);
}

CORINFO_METHOD_HANDLE MethodContext::repGetSpecialCopyHelper(CORINFO_CLASS_HANDLE type)
{
    DWORDLONG key = CastHandle(type);
    DWORDLONG value = LookupByKeyOrMiss(GetSpecialCopyHelper, key, ": key %016" PRIX64 "", key);
    DEBUG_REP(dmpGetSpecialCopyHelper(key, value));
    return (CORINFO_METHOD_HANDLE)value;
}

void MethodContext::recGetWasmTypeSymbol(CorInfoWasmType* types, size_t typesSize, CORINFO_WASM_TYPE_SYMBOL_HANDLE result)
{
    if (GetWasmTypeSymbol == nullptr)
        GetWasmTypeSymbol = new LightWeightMap<Agnostic_GetWasmTypeSymbol, DWORDLONG>();

    Agnostic_GetWasmTypeSymbol key;
    ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
    key.types = (DWORD)GetWasmTypeSymbol->AddBuffer((unsigned char*)types, (unsigned)(sizeof(CorInfoWasmType) * typesSize));
    key.typesSize = (DWORD)typesSize;

    DWORDLONG value = CastHandle(result);
    GetWasmTypeSymbol->Add(key, value);
    DEBUG_REC(dmpGetWasmTypeSymbol(key, value));
}

void MethodContext::dmpGetWasmTypeSymbol(const Agnostic_GetWasmTypeSymbol& key, DWORDLONG value)
{
    printf("getWasmTypeSymbol types %u, typesSize %u, value %016" PRIX64 "", key.types, key.typesSize, value);
}

CORINFO_WASM_TYPE_SYMBOL_HANDLE MethodContext::repGetWasmTypeSymbol(CorInfoWasmType* types, size_t typesSize)
{
    AssertMapExistsNoMessage(GetWasmTypeSymbol);

    Agnostic_GetWasmTypeSymbol key;
    ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
    key.types = (DWORD)GetWasmTypeSymbol->Contains((unsigned char*)types, (unsigned)(sizeof(CorInfoWasmType) * typesSize));
    key.typesSize = (DWORD)typesSize;

    DWORDLONG value = LookupByKeyOrMiss(GetWasmTypeSymbol, key, ": types %u, typesSize %u", key.types, key.typesSize);
    DEBUG_REP(dmpGetWasmTypeSymbol(key, value));
    return (CORINFO_WASM_TYPE_SYMBOL_HANDLE)value;
}

void MethodContext::dmpSigInstHandleMap(DWORD key, DWORDLONG value)
{
    printf("SigInstHandleMap key %u, value %016" PRIX64 "", key, value);