![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
...using framework 1.0 / 1.1/ 2.0, Mono.Cecil library for introspection I am new to all this fancy smancy IL stuff, so please hold the slaps if this is obvious...and feel free to point me to "good" and "clear" documention if that would answer my question. which IL OpCode represent method calls or object instantiation? I determined Call, Calli, Callivert and NewObj by writing some quick code and using Ildasm.exe to inspect the assembly, but there are over 200 codes. |
#3
| |||
| |||
|
|
kevin wrote: ...using framework 1.0 / 1.1/ 2.0, Mono.Cecil library for introspection I am new to all this fancy smancy IL stuff, so please hold the slaps if this is obvious...and feel free to point me to "good" and "clear" documention if that would answer my question. which IL OpCode represent method calls or object instantiation? I determined Call, Calli, Callivert and NewObj by writing some quick code and using Ildasm.exe to inspect the assembly, but there are over 200 codes. 'callvirt' is typically used by C# for calling both virtual and non-virtual methods. For virtual methods, it's required to get polymorphism, while with non-virtual method it forces a null reference exception if the instance is null. Some other .NET languages (e.g. Delphi for .NET) don't use 'callvirt' for non-virtual methods because calling an instance method on a null instance isn't necessarily an error. 'call' is typically used for calling static methods or forcing non-polymorphic calls, such as when calling the inherited method inside an overridden method: e.g. 'base.Foo();' inside 'override void Foo();'. 'calli' is an indirect call. It's used to call a function pointer on the IL stack. Not frequently required. 'newobj' both allocates an object from the heap and calls its constructor. This information is in partition III of the CLI standard, ECMA-335: http://www.ecma-international.org/pu...s/Ecma-335.htm -- Barry -- http://barrkel.blogspot.com/ |
#4
| |||
| |||
|
|
But if you want to know exactly where in the code those assemblies are being used, I guess you should look at pretty much any instruction that involves a memberref or typeref token. |
#5
| |||
| |||
|
|
"Mattias Sjögren" wrote: But if you want to know exactly where in the code those assemblies are being used, I guess you should look at pretty much any instruction that involves a memberref or typeref token. Mattias, I do indeed what to know when an assembly is used. So are you suggesting that looking for OpCode Call, Calli, Callvirt, NewObj and Throw will not suffice? |
|
Thanks. Kevin |
#6
| |||
| |||
|
|
If you need to know when methods are called, you're pretty well out of luck because they could be called virtually using an interface pointer, then the typeref and methodref wouldn't even be to your assembly. |
#7
| |||
| |||
|
|
Ben wrote If you need to know when methods are called, you're pretty well out of luck because they could be called virtually using an interface pointer, then the typeref and methodref wouldn't even be to your assembly. Please explain what you mean... or better yet give an example. The |
#8
| |||
| |||
|
|
He means that if you're using dynamic dispatch with polymorphism (aka virtual methods), you don't necessarily know at compile time (and thus in the assembly) which actual method will be called. You don't know this because you don't know at compile time the actual type of the instance. Discovering actual type for all instances requires solving the halting problem, i.e. impossible. |
#9
| |||
| |||
|
|
"Barry Kelly" wrote: He means that if you're using dynamic dispatch with polymorphism (aka virtual methods), you don't necessarily know at compile time (and thus in the assembly) which actual method will be called. You don't know this because you don't know at compile time the actual type of the instance. Discovering actual type for all instances requires solving the halting problem, i.e. impossible. So what was old is new again. Late Binding returns... and after I was made to feel ashamed about all that VB6 and ASP code! |
#10
| |||
| |||
|
|
Ben and Berry and Mattias; Thanks for your time and responses gentleman. I learned something over these last couple of days. I hope the holiday (whatever your persuasions) was good to you and yours. "Barry Kelly" wrote: He means that if you're using dynamic dispatch with polymorphism (aka virtual methods), you don't necessarily know at compile time (and thus in the assembly) which actual method will be called. You don't know this because you don't know at compile time the actual type of the instance. Discovering actual type for all instances requires solving the halting problem, i.e. impossible. So what was old is new again. Late Binding returns... and after I was made to feel ashamed about all that VB6 and ASP code! So in conclusion, I can filter my app to only be concerned with NewObj, Throw, Call, Calli and Callvirt, but I should understand that I will run into a few "dead ends". |
|
Kevin |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |