VC ++ 6.0 debugging: Variable observation-watch window skills

Source: Internet
Author: User
Tags win32 error
???????? Next, I will write some tips on the watch window of VC6, which is very helpful for the debugging process. VC6 is very old, and Microsoft does not seem to support it anymore, but many people are still using it. I personally like it very much (relatively vs2003, 2005), which accounts for a small amount of resources. Even though it still has a very strong debugging function, it is really good .?

???????? Next, I will write some tips on the watch window of VC6, which is very helpful for the debugging process. VC6 is very old, and Microsoft does not seem to support it anymore, but many people are still using it. I personally like it very much (relatively vs2003, 2005), which accounts for a small amount of resources. Even though it still has a very strong debugging function, it is really good .?

???????? Next, I will write some tips on the watch window of VC6, which is very helpful for the debugging process. VC6 is very old, and Microsoft does not seem to support it anymore, but many people are still using it. I personally like it very much (relatively vs2003, 2005), which accounts for a small amount of resources. Even though it still has a very strong debugging function, it is really good .?

?????? Well, this is the end of the nonsense. The following code is used to describe it:

# Include?
# Include?

Class? AutoExpand
{
Public:
???? AutoExpand (int? Val ,? Char *? Pval)
???? {
???????? A? =? Val;
???????? P? =? Pval;
????}
Private:
???? Int? A;
???? Char? * P;
};

Class? CantExpand
{
Public:
???? CantExpand (int? Val ,? Char *? Pval)
???? {
???????? A? =? Val;
???????? P? =? Pval;
????}
Private:
???? Int? A;
???? Char? * P;
};


Int? Main (void)
{
???? Int? P [4]? =? {0x31,0x32, 0x33,0x34 };
???? Int? * ?? =? P;
????
???? FILE *? Fp? =? Fopen ("File? Not? Exist ",? "R ");
???? DWORD? DwError? =? GetLastError ();
????
???? AutoExpand AE (10, "abc ");
?? ? CantExpand ce (10, "abc ");

???? Return? 0;
}

??????? The variables in the above Code are described first:

?????? P: an integer array containing four elements, a total of 16 bytes.

?????? A: integer pointer, pointing to array p

????? Fp: File pointer, used to identify the opened "File Not Exist". This File is Not available on my machine.

??? DwError: Get the error code of fopen failure. In general, you can use FormatMessge to format the cause of the error or use the errorlookup tool provided by VC to find the explanation of the error code.

????? AE AND ce: Custom AutoExpand variables and CantExpand variables. Note that the two types only have different type names.

??? The following figure shows the watch window when I debug this program:

On the left is the Locals page of the Context window. All local variables are displayed. On the right side is the Watch window, which is the object I add myself to observe.

Well, first look at the integer array p. We can see that the display p in the Context window only shows the address of the array. After the plus sign is clicked, four Integer Data pieces are displayed. In the right window, I added a p, c. P is followed by ", c". What does it mean? Look at the effect. [0], [1], [2], and [3] under p and c show the ascii characters corresponding to these four integer values. So here is the first tips:

1. In the watch window, add ", c" after the integer variable to display the ASCII characters corresponding to the variable. In fact, you can simply press a number to display it. For example, in the window on the right above, the value of c is 'V '. That is to say, the ASCII character corresponding to 118 is 'V '. Then, what should we know about the ASCII value of a character? As shown in the preceding figure, 'V' and d indicate that the value of the ASCII code corresponding to the 'V' character is 118. 'V', x displays the hexadecimal ASCII value. Except for ", c "?? ", D "?? In addition to ", x", some other parameters can be added. See the appendix below.

Then we can see that variable a. a is a pointer. Look at the window on the left. Even if you click the plus sign to expand it, you only see the first element (49) of the address to which it points ). if you want to view more data, you can view it in the above Memory window, just like me. However, there is only one Memory window. It is troublesome to see the data pointed to by multiple pointers. So it will be displayed in the watch window, a and 4. Do you see the display in my watch window? Therefore, with the second tips:

2. In the watch window, the pointer is regarded as an array. if you add a length after the pointer name, you can view the corresponding data like an array. For example, a and 4 above me. So if a pointer points to a large amount of data, for example, an integer pointer a points to a large memory of 1000 integers, I just want to see the last four data, what should I do? Then (a + 996), 4. Starting from 996th data records, check 4 ~

Next, this tips is my favorite one. When a system function fails to be called during debugging, The GetLastError () function must be added to obtain the returned value. Then, check the corresponding explanation to find out the cause of the error. For example, if the code above is to open a non-existent file, the fopen fails. The error code dwError = 2 is retrieved. The file does not exist. Can the debugger tell me why? Of course you can. What else do I do this! The error code 2 is recorded in dwError, so you only need to check dwError in the watch window and hr in the value column: the system cannot find the specified file! Great! To sum up, the third tip is:

3. Check the error cause in the watch window. You only need to ", hr" on the cheek after the error. For example, my dwError, hr, and 2 can both Display error messages. If you want to see the explanation of an error code, you can simply add ", hr" to it, which is very convenient! It is worth mentioning that the error cause can be viewed even if GetLastError () is not called. After fopen () is called, you can directly tap err in the watch window. hr can also display the cause of the last error. However, I re-installed the OS on my machine, and I haven't installed the vc. Now I still use the bodies before the installation. So there is a problem with the display of err and hr. But there is still a way to deal with it, that is, powerful TIB information. Watch window look at * (unsigned long *) (TIB + 0x34), hr is the same. As for why, it is the GetLastError mechanism.

? There are 2 variables left, AE and ce. The two variables have different types, but all others are the same. Why are the two variables displayed differently in the watch window? AE directly shows the value of the class member, and ce shows a... well, this is the last tips:

4. There is an autoexp. dat file in the msdev/bin directory of the vc installation directory. You can customize the display of data in it. Let's take a look at the preceding section for details. I add a line of AutoExpand = int_val = sz_val = to the end of the file. .

??????? It's too long. Rest!

Http://blog.csdn.net/coding_hello

Appendix:

The following table describes the formats that the debugger can recognize.

Description Format Value Display
D, I Signed decimal integer 0xF000F065 -268373915
U Unsigned decimal integer Zero x 0065 101
O Unsigned octal integers 0xF065 0170145
X, X Hexadecimal integer 61541 (decimal) 0x0000F065
L, h Long or short prefix for d, I, u, o, x, and X 00406042, hx 0x0c22
F Signed floating point 3./2. 1.500000
E Signed scientific notation 3./2. 1.500000e + 000
G Signed floating point or signed scientific notation, whichever is shorter 3./2. 1.5
C Single Character Zero x 0065 101 'E'
S String 0x0012fde8 "Hello world"
Su Unicode string ? "Hello world"
Hr HRESULT or Win32 error code. (The debugger automatically decodes HRESULT, so this specifier is not required in these cases. 0x00000000L S_ OK
Wc Window flag. Zero x 00000040 Wc_defachar char
Wm Windows message numbers Zero x 0010 WM_CLOSE

The following table contains the format symbols used for memory locations.

Symbol Format Display
Ma 64 ASCII characters 0x0012ffac. 4... 0... ". 0 W &....... 1 W &. 0.: W .. 1 .... ".. 1.JO &. 1. 2 .. ".. 1... 0y .... 1
M 16 bytes in hexadecimal format, followed by 16 ASCII characters 0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00. 4... 0... ". 0 W &..
Mb 16 bytes in hexadecimal format, followed by 16 ASCII characters 0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00. 4... 0... ". 0 W &..
Mw 8 characters 0x0012ffac 34B3 00CB 3084 8094 22FF 308A 2657 0000
Md 4 double characters long 0x0012ffac 00CB34B3 80943084 308A22FF 00002657
Mq 2x4 characters long 0x0012ffac 7ffdf00000000000 5f441a790012fdd4
Mu 2-byte character (Unicode) 0x0012fc60 8478 77f4 ffff 0000 0000 0000

You can use a memory location specifier with any calculated value or expression.

Related Article

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.