Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Problem for getting static field value in ICorDebugType

$
0
0

Hello,

I am developing a tool (with C#) for analysing full memory dumps of .NET processes by using Microsoft Debugging APIs.
I am trying to find the value of a static field by calling

ICorDebugType::GetStaticFieldValue (
    [in]  mdFieldDef        fieldDef,
    [in]  ICorDebugFrame    *pFrame,
    [out] ICorDebugValue    **ppValue
);

In C# program, I import the COM Component as seen below:

[ComImport, Guid("D613F0BB-ACE1-4C19-BD72-E4C08D5DA7F5"), InterfaceType(1)]
 public interface ICorDebugType
    {
  //the other methods of interface

       [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
       void GetStaticFieldValue([In] uint fieldDef, [In, MarshalAs(UnmanagedType.Interface)] ICorDebugFrame pFrame,
        [MarshalAs(UnmanagedType.Interface)] out ICorDebugValue ppValue);
    }

When I tried to call this method as seen below, I got the exception:
"A field in a class is not available, because the runtime optimized it away. (Exception from HRESULT: 0x80131306)"
 
 SomeFunc(...)
 {
    ICorDebugType type;
    //successfully got type by calling "iCordebugProcess5.GetTypeForTypeID()" method
    ICorDebugFrame frame;
    //successfully got a managed stack frame.
    //the frame is ICorDebugILFrame also.
    ICorDebugValue dbgValue;
   
    //field.MetadataToken is the token of a static field (namely:s_EDILock) inside System.Exception class
    type.GetStaticFieldValue((uint)field.MetadataToken, frame, out dbgValue);
 }
 
The same exception occurs also for the other fields in other classes.
Besides that If I tried with non-static field MetadataToken, I also got the same exception.

The same problem could be observed when I tried to attach a process and getting the value of static field.

Any ideas?
Thanks in advance,

Tolga


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>