none
how to get arguments in clr profiler RRS feed

  • Question

  • Hi,

    I am using
    GetFunctionEnter3Info() in EnterStub which I have hooked using

    SetEnterLeaveFunctionHooks3WithInfo()

    But the arguments I get are the addresses but not strings, so when I try do a getStringLayout2  from CorProfilerInfo3, I try to convert them into string but fail as the string length I get by dereferencing the length  at the (address + offset) is invalid.

    Please let me know if you have any ideas.

    Thanks

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; background-color: #000000} </style><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Helvetica; background-color: #000000} </style>
    Monday, December 30, 2019 10:44 PM

All replies

  • Hi CPK55,

    According to your description, I have a question to confirm with you.

    What's the type of your application?

    >>But the arguments I get are the addresses but not strings

    Could you provide some related code here?

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 31, 2019 8:18 AM
  • Hi Xingyu,

    Here is the code snippet

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; color: #000000; background-color: #ffffff; min-height: 17.0px} span.Apple-tab-span {white-space:pre} </style>

    PROFILER_STUB EnterStub(FunctionIDOrClientID functionId, COR_PRF_ELT_INFO eltInfo)

    {

        ULONG pcbArgumentInfo = 0;

        COR_PRF_FRAME_INFO frameInfo;

        glbCorProfilerInfo3->GetFunctionEnter3Info(functionId.functionID, eltInfo, &frameInfo, &pcbArgumentInfo, NULL);

        char* pArgumentInfo = new char[pcbArgumentInfo];

        glbCorProfilerInfo3->GetFunctionEnter3Info(functionId.functionID, eltInfo, &frameInfo, &pcbArgumentInfo, (COR_PRF_FUNCTION_ARGUMENT_INFO*)pArgumentInfo);

        COR_PRF_FUNCTION_ARGUMENT_INFO* ptr = (COR_PRF_FUNCTION_ARGUMENT_INFO*)pArgumentInfo;

        for (int i = 0; i < ptr->numRanges; ++i)

        {

            ULONG pStringLengthOffset;

            ULONG pBufferOffset;

           glbCorProfilerInfo3->GetStringLayout2(&pStringLengthOffset, &pBufferOffset);

            //Assume some max string size

            WCHAR tempString[128];

            ObjectID stringOID;

            DWORD stringLength;

            //Assume objectOfInterestPosition as the position of the argument of interest

            memcpy(&stringOID, ((const void*)(ptr->ranges[i].startAddress)), ptr->ranges[i].length);

        

            memcpy(&stringLength, ((const void*)(stringOID + pStringLengthOffset)), sizeof(DWORD));

            printf("\r\n stringlength:%d", stringLength);

    //I see the string length here is wrong, first iteration is 0, second iteration I get really huge value, indicating its not valid.

            memcpy(tempString, ((const void*)(stringOID + pBufferOffset)), stringLength * sizeof(DWORD));

            tempString[stringLength * sizeof(DWORD)] = '\0';

            //tempString will now have the string value at objectOfInterestPosition of the method entered into

        }

    }

    Thursday, January 2, 2020 8:01 PM
  • Here is other relevant code 

    -----

    <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; color: #000000; background-color: #ffffff; min-height: 17.0px} </style>

        DWORD eventMask = COR_PRF_MONITOR_JIT_COMPILATION |

            COR_PRF_MONITOR_ENTERLEAVE |

            COR_PRF_ENABLE_FUNCTION_ARGS |

            COR_PRF_ENABLE_FUNCTION_RETVAL |

            COR_PRF_ENABLE_FRAME_INFO |

            COR_PRF_DISABLE_TRANSPARENCY_CHECKS_UNDER_FULL_TRUST | /* helps the case where this profiler is used on Full CLR */

            COR_PRF_ENABLE_STACK_SNAPSHOT |

            COR_PRF_DISABLE_INLINING;

        auto hr = this->corProfilerInfo->SetEventMask(eventMask);

        hr = this->corProfilerInfo->SetEnterLeaveFunctionHooks3WithInfo(EnterNaked, LeaveNaked, TailcallNaked);

    ------

    void __declspec(naked) EnterNaked(FunctionIDOrClientID functionIDOrClientID, COR_PRF_ELT_INFO eltInfo)

    {

        __asm

        {

            PUSH EAX

            PUSH ECX

            PUSH EDX

            PUSH[ESP + 16]

            CALL EnterStub

            POP EDX

            POP ECX

            POP EAX

            RET 8

        }

    }

    Thursday, January 2, 2020 8:44 PM
  • Hi CPK55,

    Thanks for your feedback.

    Try to change the code in 'memcpy'.

    /* memcpy(&stringLength, ((const void*)(stringOID + pStringLengthOffset)), sizeof(DWORD)); */
    memcpy(&stringLength, ((const void*)((char*)&stringOID + pStringLengthOffset)), sizeof(DWORD));

    Besides, since your code is related to C++, so if this cannot help you solve the problem, I suggest you ask your question in C++ related forums for more help.

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 3, 2020 2:28 AM
  • Thank Xingyu for the reply. I tried the change you suggested, but it did not help. I got -ve length when I tried the change. Will check C++ forum as well.
    Friday, January 3, 2020 9:47 PM