Welcome to TechNet Blogs Sign in | Join | Help

Getting Static and Instance Property Values in MDbg

I've always wondered how to do this and only took the time to figure it out recently - how do you get the values of C# properties, especially if they're static, in MDbg? It was the magic keyword "funceval" and the knowledge of how properties live in IL that answered that question for me. In this particular case, I needed to get the app domain's configuration file. This is what I had to do:

[p#:1, t#:2] mdbg> funceval System.AppDomain.get_CurrentDomain
result = System.AppDomain
        _domainManager=<null>
        _LocalStore=System.Collections.Hashtable.SyncHashtable
        _FusionStore=System.AppDomainSetup
        _SecurityIdentity=<null>
        _Policies=<null>
        AssemblyLoad=<null>
        TypeResolve=<null>
        ResourceResolve=<null>
        AssemblyResolve=<null>
        ReflectionOnlyAssemblyResolve=<null>
        _DefaultContext=System.Runtime.Remoting.Contexts.Context
        _activationContext=<null>
        _applicationIdentity=<null>
        _applicationTrust=<null>
        _DefaultPrincipal=<null>
        _RemotingData=System.Runtime.Remoting.DomainSpecificRemotingData
        _processExit=System.EventHandler
        _domainUnload=System.EventHandler
        _unhandledException=System.UnhandledExceptionEventHandler
        _dummyField=1433136
        _PrincipalPolicy=System.Security.Principal.PrincipalPolicy
        _HasSetPolicy=False
        __identity=<null>
results saved to $result
STOP EvalComplete
IP: 133 @ ... - MAPPING_EXACT
[p#:1, t#:2] mdbg> funceval System.AppDomain.get_SetupInformation $result
result = System.AppDomainSetup
        _Entries=array [16]
        _LoaderOptimization=System.LoaderOptimization
        _AppBase=<null>
        _AppDomainInitializer=<null>
        _AppDomainInitializerArguments=<null>
        _ActivationArguments=<null>
        _ApplicationTrust=<null>
        _ConfigurationBytes=<null>
results saved to $result
STOP EvalComplete
IP: 133 @ ... - MAPPING_EXACT
[p#:1, t#:2] mdbg> funceval System.AppDomainSetup.get_ConfigurationFile $result
result = "C:\Test\Test.exe.config"
results saved to $result
STOP EvalComplete
IP: 133 @ ... - MAPPING_EXACT
[p#:1, t#:2] mdbg>

Clearly, no rocket science. All one needed to know is that a property lives as two methods in IL - get_PropertyName for the getter and set_PropertyName for the setter - and that the object the method is to be executed against (in the case of instance properties) must be provided as the first argument, just like it normally is. I'd love to hear about a better and easier way.

By the way, MDbg ships as a sample with the Whidbey SDK. You can get it at http://www.microsoft.com/downloads/details.aspx?FamilyID=38449A42-6B7A-4E28-80CE-C55645AB1310&displaylang=en.

Published Monday, September 26, 2005 10:41 PM by onhrebic

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker