tags:

views:

31

answers:

1

Using sos, I can get the method table entry list for a particular class:

!DumpMT -MD 1d3c58
PDB symbol for mscorwks.dll not loaded
EEClass: 001d195c
Module: 001d2f2c
Name: Class1.B
mdToken: 02000005
BaseSize: 0xc
ComponentSize: 0x0
Number of IFaces in IFaceMap: 0
Slots in VTable: 7
--------------------------------------
MethodDesc Table
   Entry MethodDesc      JIT Name
691f6a90   69071248   PreJIT System.Object.ToString()
691f6ab0   69071250   PreJIT System.Object.Equals(System.Object)
691f6b20   69071280   PreJIT System.Object.GetHashCode()
692674c0   690712a4   PreJIT System.Object.Finalize()
001dc088   001d3c34     NONE Class1.B.M()
001dc090   001d3c40     NONE Class1.B.N()
001dc098   001d3c4c      JIT Class1.B..ctor()

But I can't figure out how sos can match up a table entry with a MethodDesc - having a poke around the method table in memory only gives the Entry values, which point to the JIT stub. I can't figure out how you can get the MethodDescs from there. Anyone have any ideas?

A: 

You could get the MethodDesc from the entry for Class1.B..ctor()

!dumpmd poi(001dc098-0x4)

For example here is a sample dumpmt

  0:021> !dumpmt -md poi(0x18e3d90)
EEClass: 012ef6a4
Module: 00d42c5c
Name: LINQPad.UserOptions
mdToken: 02000002  (C:\Documents and Settings\naveen\My Documents\Downloads\LINQPad.exe)
BaseSize: 0x3c
ComponentSize: 0x0
Number of IFaces in IFaceMap: 0
Slots in VTable: 16
--------------------------------------
MethodDesc Table
   Entry MethodDesc      JIT Name
03aa6aa0   03924924   PreJIT System.Object.ToString()
03aa6ac0   0392492c   PreJIT System.Object.Equals(System.Object)
03aa6b30   0392495c   PreJIT System.Object.GetHashCode()
03b17410   03924980   PreJIT System.Object.Finalize()
01321618   00d481ac      JIT LINQPad.UserOptions..ctor()
01321458   00d481c0      JIT LINQPad.UserOptions..cctor()
013214a8   00d48140      JIT LINQPad.UserOptions.get_Instance()
01321580   00d4814c      JIT LINQPad.UserOptions.Load()
01321650   00d48158      JIT LINQPad.UserOptions.Deserialize(System.String)
00d4c249   00d48164     NONE LINQPad.UserOptions.Save()
018c8410   00d48170      JIT LINQPad.UserOptions.get_TabSizeActual()
00d4c251   00d4817c     NONE LINQPad.UserOptions.get_IsVBDefault()
01325ef0   00d48188      JIT LINQPad.UserOptions.GetDefaultCustomSnippetsFolder()
01325e00   00d48194      JIT LINQPad.UserOptions.GetCustomSnippetsFolder(Boolean)
0db83d50   00d481a0      JIT LINQPad.UserOptions.get_ActualEditorBackColor()
01321898   00d481b4      JIT LINQPad.UserOptions.<Deserialize>b__0(System.Reflection.FieldInfo)

And here is reference back to methoddesc from entry using !dumpmd

0:021> !dumpmd poi(01321458-0x4)
Method Name: LINQPad.UserOptions..cctor()
Class: 012ef6a4
MethodTable: 00d4838c
mdToken: 0600000c
Module: 00d42c5c
IsJitted: yes
CodeAddr: 01321458

HTH

Naveen
I want to do it in unsafe code within it's own process space, not using sos in a debug session
thecoop
Do you plan to host CLR? I don't get you about "unsafe code and own process space". The CLR can be disassembled within the debugger.
Naveen
My ulterior motive is to get a type to manipulate its own vtables from unsafe code. What's stored in the type method tables is the address of the JIT stub, and I need to link those up to the address of the method (obtained through a method pointer of a delegate of the method) is pointing to, so I can change it to something else. I know this is extremely evil, but hey :)
thecoop