Wednesday, December 22, 2010

Visual Studio's pseudo-registers

Tip -
Visual Studio's pseudo-registers

Details -
   Open up the watch window and type in "@err" (without quotes) - This will give you the numeric value of the error code
   Open up the watch window and type in "@err,hr” (without quotes) - To get the useful text right there in the watch window

2. Expanding Pointers
There is an easy way in the watch window to expand pointers however far you want. Simply do the following when you have the pointer in your watch window
       pMyPointer,x
           Where x is any integer value >= 0. Note if x = 0, it behaves like the standard expansion.


 What if you had an array of 100 or even a thousand and you only wanted to look at a portion of it? Well that too is possible.
       (pMyPointer + x),y
           Where x is the offset from the base address you want to seek to. x is any integer value and y again is any integer value >= 0. Note x can be negative.



No smart expansions on custom classes. Whenever you use a certain structs/classes you will often get "smart" expansion in the watch window. The POINT struct is a good example of this. Wouldn't it be nice if we could get the same smart expansions for our own classes? We can, and it turns out to be very simple. There is a file called "autoexp.dat" in Common\MSDev98\Bin. You can open up the file in notepad and instantly see how you can add your own expansions to it. A simple example for a class named Vector3D would be:
; Comment can go here
Vector3D =<m_x>, <m_y>, <m_z>
Then when you place a variable of that type in the watch window you get a nice formatted output without having to expand it out manually.

4.Simple method of timing instructionsThis tip isn't really a solution to some great problem, but is still very useful. Everyone should use profilers to inspect functions and locate bottlenecks in their code but there is a quick and dirty way to see how long instructions or functions take while debugging. We will use another pseudo-register for this. We use the “@clk” register. This is a clock register that is only available in the watch window when debugging. With the use of a clever trick we can get timings for each step we take while debugging. If we put @clk in the watch window chances are it will display a rather large number. Then each time we step over a statement, it will grow in size. We could subtract off the previous clk value and then we'd have our value for that step. However, we know that the watch window gets evaluated from top to bottom so we can use a trick. On one line we will put @clk just like normal. Then on the line directly below that we put "@clk = 0". This will set the register to zero thus resetting it for the next instruction. That's all there is to it. You can use this as a simple way to time things.


Reference         -

Posted By :Ajay Kumar S.

No comments:

Post a Comment