Document directory
- How to debug Win32 programs
How to debug Win32 programs
Method 1: Use the outputdebugstring Function
The function prototype is as follows:
Void outputdebugstring (
Lpctstr lpoutputstring
);
This function outputs information to the system's debuger. You can use the debugview tool to output the result.
Observe. Because the outputdebugstring parameter is a string, we usually want to support variable parameters like printf in actual use. The following method achieves this effect:
Void debugstring (lpctstr lpszformat ,...)
{
Va_list ARGs;
Tchar sztext [1024];
Va_start (ARGs, lpszformat );
Wvsprintf (sztext, lpszformat, argS );
Outputdebugstring (sztext );
Va_end (ARGs );
}
Method 2: Output debugging information to the console
File * stream;
Allocconsole ();
Freopen_s (& stream, "conout $", "W", stdout );
Printf ("Hello, world./N ");
Here allocconsole () is used to open the console, while freopen_s associates the standard output with cosole. "Conout $" is critical.
Implementation of Information printing in wince BSP
Whether in
Wince5.0 is still in wince6.0. We will use the print function when debugging the driver or application. In the driver, we may use debugmsg (..),
Retailmsg (...), and nkdbuplintfw (..). Before using these print functions to debug our program, we need to implement the serial port printing function.
In the BSP of wince, if you want to call debugmsg (..) or retailmsg (..) to print information from the serial port, we must find debug at the oal layer in our BSP. c. Implement the following four functions in this file:
Void oeminitdebugserial (void): Initialize the serial port used to print information
Int oemreaddebugbyte (void): Read a byte from the serial port. If an error occurs, oem_debug_com_error is returned. If no data exists, oem_debug_read_nodata is returned.
Void oemwritedebugbyte (byte ch): Write a byte to the serial port
Void oemwritedebugstring (unsigned short * Str): Write a string to the serial port. This function is actually implemented by calling oemwritedebugbyte.
After the above four functions are implemented, You can debug the program through serial port printing. Generally, these four functions are implemented in debug. C of OAL.
In BSP, we usually use three functions to print: debugmsg, retailmsg, and nkdbuplintfw. A Brief Introduction:
The nkdbuplintfw (...) function is generally used only in oal and can print information directly from the serial port without being affected by the compilation option.
The debugmsg (...) function prints information only after the project is compiled in debug mode. If it is compiled in release mode, the information will not be printed.
The retailmsg (...) function prints debugging information during compilation in debug mode and release mode.
& Quot; build Option & quot; Selected & quot; enable ship
Build & quot;, then the retailmsg function will not print information.