vc++6.0 Debugging: Use of Watch Window

Source: Internet
Author: User
Tags win32 error

1#include <stdio.h>2#include <windows.h>3 4 classAutoExpand5 {6  Public:7AutoExpand (intValChar*pval)8     {9A =Val;Tenp =PVal; One     } A Private: -     intA; -     Char*p; the }; - classCantexpand - { -  Public: +Cantexpand (intValChar*pval) -     { +A =Val; Ap =PVal; at     } - Private: -     intA; -     Char*p; - }; -  in intMainvoid) - { to     intp[4] = {0x31,0x32,0x33,0x34}; +     int*a =p; -      thefile* fp = fopen ("File not Exist","R"); *DWORD dwerror =GetLastError (); $     Panax NotoginsengAutoExpand AE (Ten,"ABC"); -Cantexpand CE (Ten,"ABC"); the  +     return 0; A}

The variables that appear in the above code are explained first:

P: is an array of shapes, containing four elements, a total of 16Byte;

A: shaping pointer, pointing to array p;

FP: file pointer, used to identify the open "File not Exist", I do not have this file in the machine;

Dwerror: Gets the error code for fopen failure. In general, you can use FORMATMESSGE to format this error reason or directly with the VC Errorlookup tool to find the explanation of this error code;

AE and CE: are custom autoexpand types of variables and Cantexpand types of variables. Note that the two types only have a different type name.

Let's look at the display of the Watch window when I am debugging this program:

  

, the left side is the locals page of the context window, showing all local variables. On the right is the Watch window, which is the object I added myself to observe.

OK, first look at the shaping array p. We see that the context window display p actually only shows the address of the array, after the dot + number expands, it shows 4 shaping data. And on the right window, I added a p,c. What does it mean to add a ", C" after p? Look at the effect, p,c the following [0],[1],[2],[3] shows the ASCII word Fuha for these 4 shaping values. So here's the first tip:

1.watch window, after shaping the variable, add ", C" to display the corresponding ASCII character of the variable. In fact, you can just tap a number to show it. For example, the corresponding value of 118,c in the right window above is ' V '. That is, 118 corresponds to the ASCII character is ' V '. So, in turn, what do you think about the ASCII value of a character? Look above, ' V ', D is the display character ' V ' corresponding to the decimal ASCII value is 118. ' V ', X displays the corresponding hexadecimal ASCII code value. In addition to the ", C" ", D" ", X", there are some other parameters can be added, see the following schedule.

Then we look at variable a. A is a pointer. Look at the left window, even if you click its + number to expand, you see only the first element of the address it points to (49). If you want to see more data, you can see it in the memory window above, just like me. But there is only one memory window, to see multiple pointers to the data is troublesome, cut to cut. Then show it in the Watch window, a,4, and see the display of my watch window? So, here's a second tip:

2.watch window, the pointer as an array to see, as long as the pointer after the name of a length, you can look at the array to see the corresponding data. Like the a,4 above me. So if a pointer to the data is very large, such as a shape pointer A is a large chunk of memory pointing to a 1000 integer, I just want to see the last 4 data, what? That's (a+996), 4 chant. Starting with the No. 996 data, see 4 ~

The next little trick is my favorite one. When you encounter a system function call failure in debugging, you usually add the GetLastError () function to get the return value, and then check the corresponding explanation to know the cause of the error. For example, the above code to open a nonexistent file, the result fopen failed. Retrieve the error code dwerror=2, a check to know that the file does not exist. Then can you not check, the debugger directly tell me why? Of course, or I'll write this! Just now the error code 2 is recorded in the dwerror, so just look at the Watch window dwerror,hr see the Value column: The system cannot find the file specified! It's cool! To summarize, a third tip:

3. In the Watch window to see the cause of the error, just after the error on the cheek ", hr" on it. For example, DWERROR,HR and 2 on top of me, HR are able to display error messages. Want to see an explanation of the error code, as long as the back add ", hr" easy to fix, very convenient! It is also mentioned here that even if you do not call GetLastError (), you can see the cause of the error. After the fopen () call is complete, tapping err,hr directly in the Watch window can also show the cause of the most recent error. But my machine reinstall the OS, not installed VC, now with the installation of the body. So the display of this err,hr is problematic. However, there is a response to the law, that is the strong TIB information. Watch Window to see * (unsigned long*) (tib+0x34), HR is the same. As for why, that is the mechanism of GetLastError.

There are 2 variables left, AE and CE. The two variable type names are different, but the others are all the same. Why are the two variables displayed differently in the Watch window? AE directly shows the value of the class member, CE shows a ... Well, that's the last tip:

4. There is a autoexp.dat file under the Msdev\bin directory of the VC installation directory. You can customize the display of the data inside. Take a look at the big paragraph in front of it and say it in detail. I just add a line behind the file AutoExpand =int_val=<a,d> sz_val=<p,s>.

Schedule:

The following table describes the format specifiers that are recognized by the debugger.

specifier format value Show
D,i Signed decimal integer 0xf000f065 -268373915
U unsigned decimal integer 0x0065 101
O unsigned octal integer 0xf065 0170145
X,x hexadecimal integer 61541 (decimal) 0x0000F065
L,h Long or short prefixes for D, I, U, O, x, X 00406042,hx 0x0c22
F Signed floating point type 3./2. 1.500000
E Signed Scientific counting method 3./2. 1.500000e+000
G Signed floating-point or signed scientific notation, whichever is shorter 3./2. 1.5
C Single character 0x0065 101 ' E '
S String 0x0012fde8 "Hello World"
Su Unicode string "Hello World"
hr HRESULT or Win32 error code. (The debugger automatically decodes the HRESULT, so this specifier is not required in these cases.) 0x00000000l S_OK
Wc Window class flags. 0x00000040 Wc_defaultchar
Wm Windows message number 0x0010 Wm_close

The following table contains formatting symbols for memory locations.

symbols format Show
Ma 64 ASCII characters 0x0012ffac. 4...0 ... ". 0w&, ... 1w&.0.:w. 1 ...... 1.jo&.1.2 ... ". 1...0y .... 1
M 16 bytes in hexadecimal, followed by 16 ASCII characters 0X0012FFAC B3 CB 94 8A 30 57 26 00 00.4...0 ... " 0w&, ....
Mb 16 bytes in hexadecimal, followed by 16 ASCII characters 0X0012FFAC B3 CB 94 8A 30 57 26 00 00.4...0 ... " 0w&, ....
Mw 8 words 0X0012FFAC 34b3 00CB 3084 8094 22FF 308A 2657 0000
Md 4 Double word lengths 0X0012FFAC 00cb34b3 80943084 308a22ff 00002657
Mq 2 x four times word lengths 0X0012FFAC 7ffdf00000000000 5f441a790012fdd4
Mu 2-byte character (Unicode) 0x0012fc60 8478 77f4 ffff ffff 0000 0000 0000 0000

You can use the memory location descriptor with any value or expression that evaluates to a position.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.