Designing a new general-purpose language

Method invocations/function calls as objects, debugging support

I believe there is some need for method invocations/function calls (depending on what paradigm you are working within) to be programmatically accessible as objects, even in an unmanaged language.  One important reason is debugging support.

Consider the situation where your code is a framework or middle layer that calls client code at the request of other client code.  Sometimes a failure of some kind will occur in your code, not due to a fault in your code, but because the client code didn't follow the rules.  While it is considered good programming practice in managed code to make your code robust against this situation, in unmanaged code, practical experience has shown that 1) this is not always possible, and 2) even when possible, this is not always a good idea because you will often lose valuable debugging information.  Anyway, without getting too far off topic, suffice it to say that for certain types of code, it is not rare for a failure in your code to be the fault of someone else's code.  In such a case, debugging support is a worthwhile nonfunctional requirement.

If you are aware of particular things that client code can do wrong that will make such-and-such a function in your code fail, it can be tremendously helpful, both to support personnel and also to developers of client code, to provide a debugger extension that analyzes the problem and figures out more specifically what is the likely ultimate cause.  This may require looking at local variables in your function, the call stack, or other data specific to the function call.

Published Saturday, August 05, 2006 2:33 AM by hartwil

Comments

 

jmstall said:

What do you mean by "to be programmatically accessible as objects".  Accessible to whom?  
The callstack and locals are already accessible through a debugger / debugging APIs.  Some cases let you use debugging inspection APIs on yourself (unmanaged debugging).  
If the only cases where you'll use this information are assert dialogs and debugger extensions, then the language really doesn't need any direct support for it.
Worst case, you could getaway with just a decent set of libraries (like what .NET has under System.Diagnostics).


September 9, 2006 12:53 AM
 

hartwil said:

Accessible at least to debugging code (whether it lives in the same process or is intended to be loaded into a debugger).  I actually had more written here but it got lost somehow when I made my post.  The point I wanted to make is that symbols for local variables are often unreliable in unmanaged code for various reasons (mostly due to optimization).  This is true even for the current frame, although it is worse for a frame deeper in the stack.  I also think we can expect that the situation will worsen as optimization improves.  For debugging by hand, this is only a nuisance, but it will completely break automated analysis.
One way to fix this would be a semantically richer description of local variables in the symbol file.  However, in my opinion this is going overboard because it would make a lot of extra work for the compiler (and much larger symbol files) for data that for the most part would never be used.  In addition, this only works if you have the symbol file, so it rules out doing this kind of analysis as part of automated crash reporting unless you give the customers your symbols.
What I am suggesting is that the compiler be able to generate code that gets the values of local variables from a stack (and context record if necessary), and only generate it when it is needed.  One possible implementation of this would be for the compiler to flag local variables that are accessed via this mechanism and tell the optimizer that these variables need a dedicated place on the stack.  I see this as a sort of generalization of how local variables can be given as parameters to an exception filter in Windows structured exception handling (I don't actually know how this is done internally by the Microsoft compiler, but something along these lines must happen).
September 14, 2006 10:29 PM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker